diff options
3 files changed, 26 insertions, 17 deletions
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java index 47dbf2e..6a472be 100644 --- a/src/com/android/providers/contacts/ContactsProvider2.java +++ b/src/com/android/providers/contacts/ContactsProvider2.java @@ -6388,7 +6388,10 @@ public class ContactsProvider2 extends AbstractContactsProvider break; } case RAW_CONTACT_ENTITIES_CORP: { - final int corpUserId = UserUtils.getCorpUserId(getContext()); + // As it's protected by android.permission.INTERACT_ACROSS_USERS + // already and it is used by Bluetooth application, we do not + // check caller-id policy + final int corpUserId = UserUtils.getCorpUserId(getContext(), false); if (corpUserId < 0) { // No Corp user or policy not allowed, return empty cursor final String[] outputProjection = (projection != null) ? projection @@ -6564,8 +6567,10 @@ public class ContactsProvider2 extends AbstractContactsProvider final Cursor primaryCursor = queryLocal(localUri, projection, selection, selectionArgs, sortOrder, directoryId, null); try { - // TODO: Maybe we want to have a DPM policy for it - final int corpUserId = UserUtils.getCorpUserId(getContext()); + // As it's protected by android.permission.INTERACT_ACROSS_USERS + // already and it is used by Bluetooth application, we do not + // check caller-id policy + final int corpUserId = UserUtils.getCorpUserId(getContext(), false); if (corpUserId < 0) { // No Corp user or policy not allowed return primaryCursor; @@ -6595,7 +6600,7 @@ public class ContactsProvider2 extends AbstractContactsProvider private Cursor queryEnterpriseIfNecessary(Uri localUri, String[] projection, String selection, String[] selectionArgs, String sortOrder, String contactIdColumnName) { - final int corpUserId = UserUtils.getCorpUserId(getContext()); + final int corpUserId = UserUtils.getCorpUserId(getContext(), true); // Step 1. Look at the database on the current profile. if (VERBOSE_LOGGING) { @@ -8159,7 +8164,7 @@ public class ContactsProvider2 extends AbstractContactsProvider throw new IllegalArgumentException( "Photos retrieved by contact ID can only be read."); } - final int corpUserId = UserUtils.getCorpUserId(getContext()); + final int corpUserId = UserUtils.getCorpUserId(getContext(), true); if (corpUserId < 0) { // No corp profile or the currrent profile is not the personal. throw new FileNotFoundException(uri.toString()); diff --git a/src/com/android/providers/contacts/util/UserUtils.java b/src/com/android/providers/contacts/util/UserUtils.java index 74fd2e7..8ae770a 100644 --- a/src/com/android/providers/contacts/util/UserUtils.java +++ b/src/com/android/providers/contacts/util/UserUtils.java @@ -45,10 +45,13 @@ public final class UserUtils { } /** - * @return the user ID of the corp user that is linked to the current user, if any. - * If there's no such user or cross-user contacts access is disallowed by policy, returns -1. + * @param enforceCallerIdCheck True if we want to enforce cross profile + * caller-id device policy. + * @return the user ID of the corp user that is linked to the current user, + * if any. If there's no such user or cross-user contacts access is + * disallowed by policy, returns -1. */ - public static int getCorpUserId(Context context) { + public static int getCorpUserId(Context context, boolean enforceCallerIdCheck) { final UserManager um = getUserManager(context); if (um == null) { Log.e(TAG, "No user manager service found"); @@ -75,7 +78,8 @@ public final class UserUtils { // Check if profile is blocking calling id. // TODO DevicePolicyManager is not mockable -- the constructor is private. // Test it somehow. - if (getDevicePolicyManager(context) + if (enforceCallerIdCheck + && getDevicePolicyManager(context) .getCrossProfileCallerIdDisabled(ui.getUserHandle())) { if (VERBOSE_LOGGING) { Log.v(TAG, "Enterprise caller-id disabled for user " + ui.id); diff --git a/tests/src/com/android/providers/contacts/util/UserUtilsTest.java b/tests/src/com/android/providers/contacts/util/UserUtilsTest.java index 4417ad5..7482ee6 100644 --- a/tests/src/com/android/providers/contacts/util/UserUtilsTest.java +++ b/tests/src/com/android/providers/contacts/util/UserUtilsTest.java @@ -47,37 +47,37 @@ public class UserUtilsTest extends AndroidTestCase { final MockUserManager um = mActor.mockUserManager; // No corp user. Primary only. - assertEquals(-1, UserUtils.getCorpUserId(c)); + assertEquals(-1, UserUtils.getCorpUserId(c, false)); // Primary + corp um.setUsers(MockUserManager.PRIMARY_USER, MockUserManager.CORP_USER); um.myUser = MockUserManager.PRIMARY_USER.id; - assertEquals(MockUserManager.CORP_USER.id, UserUtils.getCorpUserId(c)); + assertEquals(MockUserManager.CORP_USER.id, UserUtils.getCorpUserId(c, false)); um.myUser = MockUserManager.CORP_USER.id; - assertEquals(-1, UserUtils.getCorpUserId(c)); + assertEquals(-1, UserUtils.getCorpUserId(c, false)); // Primary + secondary + corp um.setUsers(MockUserManager.PRIMARY_USER, MockUserManager.SECONDARY_USER, MockUserManager.CORP_USER); um.myUser = MockUserManager.PRIMARY_USER.id; - assertEquals(MockUserManager.CORP_USER.id, UserUtils.getCorpUserId(c)); + assertEquals(MockUserManager.CORP_USER.id, UserUtils.getCorpUserId(c, false)); um.myUser = MockUserManager.CORP_USER.id; - assertEquals(-1, UserUtils.getCorpUserId(c)); + assertEquals(-1, UserUtils.getCorpUserId(c, false)); um.myUser = MockUserManager.SECONDARY_USER.id; - assertEquals(-1, UserUtils.getCorpUserId(c)); + assertEquals(-1, UserUtils.getCorpUserId(c, false)); // Primary + secondary um.setUsers(MockUserManager.PRIMARY_USER, MockUserManager.SECONDARY_USER); um.myUser = MockUserManager.PRIMARY_USER.id; - assertEquals(-1, UserUtils.getCorpUserId(c)); + assertEquals(-1, UserUtils.getCorpUserId(c, false)); um.myUser = MockUserManager.SECONDARY_USER.id; - assertEquals(-1, UserUtils.getCorpUserId(c)); + assertEquals(-1, UserUtils.getCorpUserId(c, false)); } } |