From 641a8b422c7852daf0c7584d1dbedda2c849cd43 Mon Sep 17 00:00:00 2001 From: Liahav Eitan Date: Mon, 28 Nov 2022 15:43:14 +0000 Subject: [PATCH] Public API to list all work profile contacts and phones from personal CP2. This change adds a new Contacts.ENTERPRISE_CONTENT_URI and makes the existing Phone.ENTERPRISE_CONTENT_URI public. It also updates terminology in the java doc and resolves inconsistent usage of the terms "work", "corp", "enterprise" and "managed". Test: atest ManagedProfileContactsTest Bug: 240954287 Change-Id: I07db823b4afb5955723967f868f07bac622724e2 --- core/api/current.txt | 2 + core/api/system-current.txt | 4 - core/api/test-current.txt | 4 - .../android/provider/ContactsContract.java | 298 ++++++++++-------- 4 files changed, 163 insertions(+), 145 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index 18d8fc72a40d8..9dd694b568206 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -34805,6 +34805,7 @@ package android.provider { field public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_v2"; field public static final android.net.Uri CONTENT_URI; field public static final android.net.Uri ENTERPRISE_CONTENT_FILTER_URI; + field @NonNull public static final android.net.Uri ENTERPRISE_CONTENT_URI; field public static final String EXTRA_ADDRESS_BOOK_INDEX = "android.provider.extra.ADDRESS_BOOK_INDEX"; field public static final String EXTRA_ADDRESS_BOOK_INDEX_COUNTS = "android.provider.extra.ADDRESS_BOOK_INDEX_COUNTS"; field public static final String EXTRA_ADDRESS_BOOK_INDEX_TITLES = "android.provider.extra.ADDRESS_BOOK_INDEX_TITLES"; @@ -34985,6 +34986,7 @@ package android.provider { field public static final String CONTENT_VCARD_TYPE = "text/x-vcard"; field public static final android.net.Uri CONTENT_VCARD_URI; field public static final android.net.Uri ENTERPRISE_CONTENT_FILTER_URI; + field @NonNull public static final android.net.Uri ENTERPRISE_CONTENT_URI; field public static final String EXTRA_ADDRESS_BOOK_INDEX = "android.provider.extra.ADDRESS_BOOK_INDEX"; field public static final String EXTRA_ADDRESS_BOOK_INDEX_COUNTS = "android.provider.extra.ADDRESS_BOOK_INDEX_COUNTS"; field public static final String EXTRA_ADDRESS_BOOK_INDEX_TITLES = "android.provider.extra.ADDRESS_BOOK_INDEX_TITLES"; diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 7a22e373045d6..639000ea75ce0 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -10356,10 +10356,6 @@ package android.provider { field public static final int ERROR_UNKNOWN = 0; // 0x0 } - public static final class ContactsContract.CommonDataKinds.Phone implements android.provider.ContactsContract.CommonDataKinds.CommonColumns android.provider.ContactsContract.DataColumnsWithJoins { - field @NonNull @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) public static final android.net.Uri ENTERPRISE_CONTENT_URI; - } - @Deprecated public static final class ContactsContract.MetadataSync implements android.provider.BaseColumns android.provider.ContactsContract.MetadataSyncColumns { field @Deprecated public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_metadata"; field @Deprecated public static final String CONTENT_TYPE = "vnd.android.cursor.dir/contact_metadata"; diff --git a/core/api/test-current.txt b/core/api/test-current.txt index ef74a3ef6c205..a749452259270 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -2165,10 +2165,6 @@ package android.provider { field public static final String HIDDEN_COLUMN_PREFIX = "x_"; } - public static final class ContactsContract.CommonDataKinds.Phone implements android.provider.ContactsContract.CommonDataKinds.CommonColumns android.provider.ContactsContract.DataColumnsWithJoins { - field @NonNull @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) public static final android.net.Uri ENTERPRISE_CONTENT_URI; - } - public static final class ContactsContract.PinnedPositions { field public static final String UNDEMOTE_METHOD = "undemote"; } diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java index d50ba8de8fa6b..363d035ea774b 100644 --- a/core/java/android/provider/ContactsContract.java +++ b/core/java/android/provider/ContactsContract.java @@ -435,25 +435,27 @@ public final class ContactsContract { Uri.withAppendedPath(AUTHORITY_URI, "directories"); /** - * URI used for getting all directories from primary and managed profile. - * It supports the same semantics as {@link #CONTENT_URI} and returns the same columns. - * If the device has no managed profile that is linked to the current profile, it behaves - * in the exact same way as {@link #CONTENT_URI}. - * If there is a managed profile linked to the current profile, it will merge - * managed profile and current profile's results and return. - * - * Note: this query returns primary profile results before managed profile results, - * and this order is not affected by sorting parameter. + * URI used for getting all directories from both the calling user and the managed profile + * that is linked to it. + *

+ * It supports the same semantics as {@link #CONTENT_URI} and returns the same columns.
+ * If the device has no managed profile that is linked to the calling user, it behaves + * in the exact same way as {@link #CONTENT_URI}.
+ * If there is a managed profile linked to the calling user, it will return merged results + * from both. + *

+ * Note: this query returns the calling user results before the managed profile results, + * and this order is not affected by the sorting parameter. * */ public static final Uri ENTERPRISE_CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "directories_enterprise"); /** - * Access file provided by remote directory. It allows both personal and work remote - * directory, but not local and invisible diretory. - * - * It's supported only by a few specific places for referring to contact pictures in the + * Access file provided by remote directory. It allows both calling user and managed profile + * remote directory, but not local and invisible directory. + *

+ * It is supported only by a few specific places for referring to contact pictures in the * remote directory. Contact picture URIs, e.g. * {@link PhoneLookup#ENTERPRISE_CONTENT_FILTER_URI}, may contain this kind of URI. * @@ -490,13 +492,13 @@ public final class ContactsContract { public static final long LOCAL_INVISIBLE = 1; /** - * _ID of the work profile default directory, which represents locally stored contacts. + * _ID of the managed profile default directory, which represents locally stored contacts. */ public static final long ENTERPRISE_DEFAULT = Directory.ENTERPRISE_DIRECTORY_ID_BASE + DEFAULT; /** - * _ID of the work profile directory that represents locally stored invisible contacts. + * _ID of the managed profile directory that represents locally stored invisible contacts. */ public static final long ENTERPRISE_LOCAL_INVISIBLE = Directory.ENTERPRISE_DIRECTORY_ID_BASE + LOCAL_INVISIBLE; @@ -557,8 +559,8 @@ public final class ContactsContract { public static final String ACCOUNT_NAME = "accountName"; /** - * Mimimal ID for corp directory returned from - * {@link Directory#CORP_CONTENT_URI}. + * Mimimal ID for managed profile directory returned from + * {@link Directory#ENTERPRISE_CONTENT_URI}. * * @hide */ @@ -1537,12 +1539,42 @@ public final class ContactsContract { public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "contacts"); /** - * Special contacts URI to refer to contacts on the corp profile from the personal - * profile. - * + * URI used for getting all contacts from both the calling user and the managed profile + * that is linked to it. + *

+ * It supports the same semantics as {@link #CONTENT_URI} and returns the same columns.
+ * If the calling user has no managed profile, it behaves in the exact same way as + * {@link #CONTENT_URI}.
+ * If there is a managed profile linked to the calling user, it will return merged results + * from both. + *

+ * Note: this query returns the calling user results before the managed profile results, + * and this order is not affected by the sorting parameter. + *

+ * If a result is from the managed profile, the following changes are made to the data: + *