diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2020-05-21 16:25:25 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-05-21 16:25:25 +0000 |
commit | 5d6cf38cd13a5ac3ac788ce7a7fafb10bee8a4d1 (patch) | |
tree | a725e4c3988427bb63a13d17c9a6e4fd31aaa55f /services/robotests | |
parent | 4586885a638a7c866126b247164d4c950cbef214 (diff) | |
parent | e6a81b38d61972bbc1c37f191874e8a50a4fb9e8 (diff) |
Merge "Prevent DPCs from requesting INTERACT_ACROSS_PROFILES" into rvc-dev
Diffstat (limited to 'services/robotests')
-rw-r--r-- | services/robotests/src/com/android/server/pm/CrossProfileAppsServiceImplRoboTest.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/services/robotests/src/com/android/server/pm/CrossProfileAppsServiceImplRoboTest.java b/services/robotests/src/com/android/server/pm/CrossProfileAppsServiceImplRoboTest.java index d78dad55e181..715404194a28 100644 --- a/services/robotests/src/com/android/server/pm/CrossProfileAppsServiceImplRoboTest.java +++ b/services/robotests/src/com/android/server/pm/CrossProfileAppsServiceImplRoboTest.java @@ -37,7 +37,9 @@ import android.annotation.UserIdInt; import android.app.ActivityManagerInternal; import android.app.AppOpsManager; import android.app.AppOpsManager.Mode; +import android.app.admin.DevicePolicyManager; import android.app.admin.DevicePolicyManagerInternal; +import android.content.ComponentName; import android.content.ContextWrapper; import android.content.Intent; import android.content.pm.ActivityInfo; @@ -97,6 +99,7 @@ public class CrossProfileAppsServiceImplRoboTest { private static final int WORK_PROFILE_USER_ID = 10; private static final int WORK_PROFILE_UID = 3333; private static final int OTHER_PROFILE_WITHOUT_CROSS_PROFILE_APP_USER_ID = 20; + private static final int OUTSIDE_PROFILE_GROUP_USER_ID = 30; private final ContextWrapper mContext = ApplicationProvider.getApplicationContext(); private final UserManager mUserManager = mContext.getSystemService(UserManager.class); @@ -226,6 +229,7 @@ public class CrossProfileAppsServiceImplRoboTest { PERSONAL_PROFILE_USER_ID, WORK_PROFILE_USER_ID, OTHER_PROFILE_WITHOUT_CROSS_PROFILE_APP_USER_ID); + shadowUserManager.addProfileIds(OUTSIDE_PROFILE_GROUP_USER_ID); } @Before @@ -504,6 +508,36 @@ public class CrossProfileAppsServiceImplRoboTest { } @Test + public void canUserAttemptToConfigureInteractAcrossProfiles_profileOwnerWorkProfile_returnsFalse() { + when(mDevicePolicyManagerInternal.getProfileOwnerAsUser(WORK_PROFILE_USER_ID)) + .thenReturn(buildCrossProfileComponentName()); + assertThat(mCrossProfileAppsServiceImpl + .canUserAttemptToConfigureInteractAcrossProfiles(CROSS_PROFILE_APP_PACKAGE_NAME)) + .isFalse(); + } + + @Test + public void canUserAttemptToConfigureInteractAcrossProfiles_profileOwnerOtherProfile_returnsFalse() { + // Normally, the DPC would not be a profile owner of the personal profile, but for the + // purposes of this test, it is just a profile owner of any profile within the profile + // group. + when(mDevicePolicyManagerInternal.getProfileOwnerAsUser(PERSONAL_PROFILE_USER_ID)) + .thenReturn(buildCrossProfileComponentName()); + assertThat(mCrossProfileAppsServiceImpl + .canUserAttemptToConfigureInteractAcrossProfiles(CROSS_PROFILE_APP_PACKAGE_NAME)) + .isFalse(); + } + + @Test + public void canUserAttemptToConfigureInteractAcrossProfiles_profileOwnerOutsideProfileGroup_returnsTrue() { + when(mDevicePolicyManagerInternal.getProfileOwnerAsUser(OUTSIDE_PROFILE_GROUP_USER_ID)) + .thenReturn(buildCrossProfileComponentName()); + assertThat(mCrossProfileAppsServiceImpl + .canUserAttemptToConfigureInteractAcrossProfiles(CROSS_PROFILE_APP_PACKAGE_NAME)) + .isTrue(); + } + + @Test public void canUserAttemptToConfigureInteractAcrossProfiles_returnsTrue() { assertThat(mCrossProfileAppsServiceImpl .canUserAttemptToConfigureInteractAcrossProfiles(CROSS_PROFILE_APP_PACKAGE_NAME)) @@ -607,6 +641,10 @@ public class CrossProfileAppsServiceImplRoboTest { .hideAsParsed()).hideAsFinal()); } + private ComponentName buildCrossProfileComponentName() { + return new ComponentName(CROSS_PROFILE_APP_PACKAGE_NAME, "testClassName"); + } + private class TestInjector implements CrossProfileAppsServiceImpl.Injector { @Override |