From 242bb9f25b210fbfe36a384088221b54b2602b34 Mon Sep 17 00:00:00 2001 From: Pete Varvarezis Date: Wed, 25 Jan 2023 20:44:55 +0000 Subject: Migrate to new package-level profile access checks Replace deprecated API calls with newer methods: getCrossProfileCallerIdDisabled to hasManagedProfileCallerIdAccess getCrossProfileContactsSearchDisabled to hasManagedProfileContactsAccess Prevent querying remote directory when managed profile is suspended Test: atest ManagedProfileContactsTest EnterprisePolicyGuardTest Bug: 264879018 Bug: 265934326 Change-Id: I8a0a07ac149c198ae9e2a61636165299edbceacd --- .../enterprise/EnterprisePolicyGuardTest.java | 42 +++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/src/com/android/providers/contacts/enterprise/EnterprisePolicyGuardTest.java b/tests/src/com/android/providers/contacts/enterprise/EnterprisePolicyGuardTest.java index 9b5fca1a..5aedd8d0 100644 --- a/tests/src/com/android/providers/contacts/enterprise/EnterprisePolicyGuardTest.java +++ b/tests/src/com/android/providers/contacts/enterprise/EnterprisePolicyGuardTest.java @@ -184,6 +184,32 @@ public class EnterprisePolicyGuardTest extends FixedAndroidTestCase { checkCrossProfile(guard, URI_CONTACTS_ID_PHOTO, false); checkCrossProfile(guard, URI_CONTACTS_ID_DISPLAY_PHOTO, false); checkCrossProfile(guard, URI_OTHER, false); + + // ManagedProfile is paused + context = getMockContext(true, true, false); + guard = new EnterprisePolicyGuardTestable(context, true); + checkCrossProfile(guard, appendRemoteDirectoryId(URI_PHONE_LOOKUP), false); + checkCrossProfile(guard, appendRemoteDirectoryId(URI_EMAILS_LOOKUP), false); + checkCrossProfile(guard, appendRemoteDirectoryId(URI_CONTACTS_FILTER), false); + checkCrossProfile(guard, appendRemoteDirectoryId(URI_PHONES_FILTER), false); + checkCrossProfile(guard, appendRemoteDirectoryId(URI_CALLABLES_FILTER), false); + checkCrossProfile(guard, appendRemoteDirectoryId(URI_EMAILS_FILTER), false); + checkCrossProfile(guard, URI_DIRECTORY_FILE, false); + + // Always allow uri with no directory support. + checkCrossProfile(guard, URI_DIRECTORIES, true); + checkCrossProfile(guard, URI_DIRECTORIES_ID, true); + checkCrossProfile(guard, URI_CONTACTS_ID_PHOTO, true); + checkCrossProfile(guard, URI_CONTACTS_ID_DISPLAY_PHOTO, true); + checkCrossProfile(guard, URI_OTHER, false); + + // Always allow uri with no remote directory id. + checkCrossProfile(guard, URI_PHONE_LOOKUP, true); + checkCrossProfile(guard, URI_EMAILS_LOOKUP, true); + checkCrossProfile(guard, URI_CONTACTS_FILTER, true); + checkCrossProfile(guard, URI_PHONES_FILTER, true); + checkCrossProfile(guard, URI_CALLABLES_FILTER, true); + checkCrossProfile(guard, URI_EMAILS_FILTER, true); } public void testCrossProfile_userSettingOff() { @@ -215,6 +241,7 @@ public class EnterprisePolicyGuardTest extends FixedAndroidTestCase { checkCrossProfile(guard, URI_EMAILS_FILTER, true); } + private static Uri appendRemoteDirectoryId(Uri uri) { return appendDirectoryId(uri, REMOTE_DIRECTORY_ID); } @@ -261,11 +288,16 @@ public class EnterprisePolicyGuardTest extends FixedAndroidTestCase { private Context getMockContext(boolean isCallerIdEnabled, boolean isContactsSearchEnabled) { + return getMockContext(isCallerIdEnabled, isContactsSearchEnabled, true); + } + + private Context getMockContext(boolean isCallerIdEnabled, boolean isContactsSearchEnabled, + boolean isManagedProfileEnabled) { DevicePolicyManager mockDpm = mock(DevicePolicyManager.class); - when(mockDpm.getCrossProfileCallerIdDisabled(Matchers.any())) - .thenReturn(!isCallerIdEnabled); - when(mockDpm.getCrossProfileContactsSearchDisabled(Matchers.any())) - .thenReturn(!isContactsSearchEnabled); + when(mockDpm.hasManagedProfileCallerIdAccess(Matchers.any(),Matchers.any())) + .thenReturn(isCallerIdEnabled); + when(mockDpm.hasManagedProfileContactsAccess(Matchers.any(),Matchers.any())) + .thenReturn(isContactsSearchEnabled); List userInfos = MANAGED_USERINFO_LIST; UserManager mockUm = mock(UserManager.class); @@ -273,6 +305,8 @@ public class EnterprisePolicyGuardTest extends FixedAndroidTestCase { when(mockUm.getUsers()).thenReturn(userInfos); when(mockUm.getProfiles(Matchers.anyInt())).thenReturn(userInfos); when(mockUm.getProfileParent(WORK_USER_ID)).thenReturn(CURRENT_USER_INFO); + when(mockUm.isQuietModeEnabled(UserHandle.of(WORK_USER_ID))) + .thenReturn(!isManagedProfileEnabled); PackageManager mockPm = mock(PackageManager.class); when(mockPm.checkPermission(INTERACT_ACROSS_USERS, CALLING_PACKAGE)) -- cgit v1.2.3