aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPete Varvarezis <varpete@google.com>2023-01-25 20:44:55 +0000
committerPete Varvarezis <varpete@google.com>2023-02-02 06:54:43 +0000
commit242bb9f25b210fbfe36a384088221b54b2602b34 (patch)
treee9d20a752dd3704f42eabf7b445d32caba2c8ed9 /tests
parentb915bb73ad6905bf339f5fcf8d47a8f487b0f889 (diff)
downloadContactsProvider-242bb9f25b210fbfe36a384088221b54b2602b34.tar.gz
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
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/providers/contacts/enterprise/EnterprisePolicyGuardTest.java42
1 files changed, 38 insertions, 4 deletions
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.<UserHandle>any()))
- .thenReturn(!isCallerIdEnabled);
- when(mockDpm.getCrossProfileContactsSearchDisabled(Matchers.<UserHandle>any()))
- .thenReturn(!isContactsSearchEnabled);
+ when(mockDpm.hasManagedProfileCallerIdAccess(Matchers.any(),Matchers.any()))
+ .thenReturn(isCallerIdEnabled);
+ when(mockDpm.hasManagedProfileContactsAccess(Matchers.any(),Matchers.any()))
+ .thenReturn(isContactsSearchEnabled);
List<UserInfo> 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))