From 42d5b79db882739368b163f4d5f61546d134cdbb Mon Sep 17 00:00:00 2001 From: Ricky Wai Date: Fri, 27 Mar 2015 14:27:09 +0000 Subject: Remove caller-id check in enterprise phone and raw contacts entities Bug: 19990833 Change-Id: Ibba3a0594262b975b3b4fdd4ebd1fcf1e40ff98a --- src/com/android/providers/contacts/ContactsProvider2.java | 15 ++++++++++----- src/com/android/providers/contacts/util/UserUtils.java | 12 ++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'src') 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); -- cgit v1.1