diff options
5 files changed, 38 insertions, 8 deletions
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index 0fdf3d3693c3..5c22ed579dc4 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -40,6 +40,7 @@ import android.os.ServiceManager; import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; +import android.provider.ContactsContract.Directory; import android.security.Credentials; import android.service.restrictions.RestrictionsReceiver; import android.util.Log; @@ -3202,11 +3203,11 @@ public class DevicePolicyManager { * @hide */ public void startManagedQuickContact(String actualLookupKey, long actualContactId, - Intent originalIntent) { + long directoryId, Intent originalIntent) { if (mService != null) { try { mService.startManagedQuickContact( - actualLookupKey, actualContactId, originalIntent); + actualLookupKey, actualContactId, directoryId, originalIntent); } catch (RemoteException e) { Log.w(TAG, "Failed talking with device policy service", e); } @@ -3214,6 +3215,16 @@ public class DevicePolicyManager { } /** + * Start Quick Contact on the managed profile for the current user, if the policy allows. + * @hide + */ + public void startManagedQuickContact(String actualLookupKey, long actualContactId, + Intent originalIntent) { + startManagedQuickContact(actualLookupKey, actualContactId, Directory.DEFAULT, + originalIntent); + } + + /** * Called by a profile owner of a managed profile to set whether bluetooth * devices can access enterprise contacts. * <p> diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl index ccaa8cb82170..b638060f77b6 100644 --- a/core/java/android/app/admin/IDevicePolicyManager.aidl +++ b/core/java/android/app/admin/IDevicePolicyManager.aidl @@ -191,7 +191,7 @@ interface IDevicePolicyManager { void setCrossProfileCallerIdDisabled(in ComponentName who, boolean disabled); boolean getCrossProfileCallerIdDisabled(in ComponentName who); boolean getCrossProfileCallerIdDisabledForUser(int userId); - void startManagedQuickContact(String lookupKey, long contactId, in Intent originalIntent); + void startManagedQuickContact(String lookupKey, long contactId, long directoryId, in Intent originalIntent); void setBluetoothContactSharingDisabled(in ComponentName who, boolean disabled); boolean getBluetoothContactSharingDisabled(in ComponentName who); diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java index 11ed5626d48b..5a48c504aa27 100644 --- a/core/java/android/provider/ContactsContract.java +++ b/core/java/android/provider/ContactsContract.java @@ -8352,10 +8352,15 @@ public final class ContactsContract { * @hide */ public static Intent rebuildManagedQuickContactsIntent(String lookupKey, long contactId, - Intent originalIntent) { + long directoryId, Intent originalIntent) { final Intent intent = new Intent(ACTION_QUICK_CONTACT); // Rebuild the URI from a lookup key and a contact ID. - intent.setData(Contacts.getLookupUri(contactId, lookupKey)); + Uri uri = Contacts.getLookupUri(contactId, lookupKey); + if (uri != null && directoryId != Directory.DEFAULT) { + uri = uri.buildUpon().appendQueryParameter( + ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId)).build(); + } + intent.setData(uri); // Copy flags and always set NEW_TASK because it won't have a parent activity. intent.setFlags(originalIntent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); diff --git a/core/java/android/provider/ContactsInternal.java b/core/java/android/provider/ContactsInternal.java index 059a6039d5b6..36ef52d6c39b 100644 --- a/core/java/android/provider/ContactsInternal.java +++ b/core/java/android/provider/ContactsInternal.java @@ -91,6 +91,10 @@ public class ContactsInternal { final List<String> pathSegments = uri.getPathSegments(); final long contactId = ContentUris.parseId(uri); final String lookupKey = pathSegments.get(2); + final String directoryIdStr = uri.getQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY); + final long directoryId = (directoryIdStr == null) + ? ContactsContract.Directory.ENTERPRISE_DIRECTORY_ID_BASE + : Long.parseLong(directoryIdStr); // See if it has a corp lookupkey. if (TextUtils.isEmpty(lookupKey) @@ -99,14 +103,24 @@ public class ContactsInternal { return false; // It's not a corp lookup key. } + if (!ContactsContract.Contacts.isEnterpriseContactId(contactId)) { + throw new IllegalArgumentException("Invalid enterprise contact id: " + contactId); + } + if (!ContactsContract.Directory.isEnterpriseDirectoryId(directoryId)) { + throw new IllegalArgumentException("Invalid enterprise directory id: " + directoryId); + } + // Launch Quick Contact on the managed profile, if the policy allows. final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class); final String actualLookupKey = lookupKey.substring( ContactsContract.Contacts.ENTERPRISE_CONTACT_LOOKUP_PREFIX.length()); final long actualContactId = (contactId - ContactsContract.Contacts.ENTERPRISE_CONTACT_ID_BASE); + final long actualDirectoryId = (directoryId + - ContactsContract.Directory.ENTERPRISE_DIRECTORY_ID_BASE); - dpm.startManagedQuickContact(actualLookupKey, actualContactId, originalIntent); + dpm.startManagedQuickContact(actualLookupKey, actualContactId, actualDirectoryId, + originalIntent); return true; } } diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index bf7c745a546e..e344343d0753 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -5918,9 +5918,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void startManagedQuickContact(String actualLookupKey, long actualContactId, - Intent originalIntent) { + long actualDirectoryId, Intent originalIntent) { final Intent intent = QuickContact.rebuildManagedQuickContactsIntent( - actualLookupKey, actualContactId, originalIntent); + actualLookupKey, actualContactId, actualDirectoryId, originalIntent); final int callingUserId = UserHandle.getCallingUserId(); final long ident = mInjector.binderClearCallingIdentity(); |