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;
* @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);
}
}
/**
+ * 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>
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);
* @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);
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)
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;
}
}
@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();