Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 494b95d3 authored by Ricky Wai's avatar Ricky Wai
Browse files

Add work contacts directory support in Quick Contacts API

Bug: 25764505

Change-Id: I61f9d13ea03352e3df1686ee4b3bcc43e9a9a760
parent e363121e
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -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,17 +3203,27 @@ 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);
            }
        }
    }

    /**
     * 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.
+1 −1
Original line number Diff line number Diff line
@@ -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);
+7 −2
Original line number Diff line number Diff line
@@ -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);
+15 −1
Original line number Diff line number Diff line
@@ -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;
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -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();