diff options
author | Alex Kershaw <alexkershaw@google.com> | 2020-03-21 22:17:52 +0000 |
---|---|---|
committer | Alex Kershaw <alexkershaw@google.com> | 2020-03-25 18:21:19 +0000 |
commit | ec19b8d07519c3ffab2088dd40f8fdaf10d073c4 (patch) | |
tree | 1a726dc39a1f9afac0724c1e18d50d0a17d73289 /services/robotests | |
parent | 0ccefbe94b6519faa12fa7c25f85bfc446f575b9 (diff) |
Add hidden API to clear all cross-profile app-ops
Reset the INTERACT_ACROSS_PROFILES app-op for all apps on the device
when creating a new work profile. This ensures that user grants for
previous work profiles (perhaps with a different admin) are not saved
and also not restored with backup-and-restore.
Also, clear the shared preference storing which oem-whitelisted apps the
user has granted. This ensures that the user sees them all again
during work profile provisioning.
Fixes: 151145623
Test: atest com.android.managedprovisioning.task.CreateManagedProfileTaskRoboTest
Change-Id: I5f5c5aea1c36bd17a74c02e1b6fa9b4047f15003
Diffstat (limited to 'services/robotests')
-rw-r--r-- | services/robotests/src/com/android/server/pm/CrossProfileAppsServiceImplRoboTest.java | 18 |
1 files changed, 18 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 acdb68142178..138f9829c088 100644 --- a/services/robotests/src/com/android/server/pm/CrossProfileAppsServiceImplRoboTest.java +++ b/services/robotests/src/com/android/server/pm/CrossProfileAppsServiceImplRoboTest.java @@ -17,6 +17,7 @@ package com.android.server.pm; import static android.app.AppOpsManager.MODE_ALLOWED; +import static android.app.AppOpsManager.MODE_DEFAULT; import static android.app.AppOpsManager.OP_INTERACT_ACROSS_PROFILES; import static android.content.Intent.FLAG_RECEIVER_FOREGROUND; import static android.content.Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND; @@ -104,6 +105,7 @@ public class CrossProfileAppsServiceImplRoboTest { private final CrossProfileAppsServiceImpl mCrossProfileAppsServiceImpl = new CrossProfileAppsServiceImpl(mContext, mInjector); private final Map<UserHandle, Set<Intent>> mSentUserBroadcasts = new HashMap<>(); + private final Map<Integer, List<ApplicationInfo>> installedApplications = new HashMap<>(); @Mock private PackageManagerInternal mPackageManagerInternal; @Mock private IPackageManager mIPackageManager; @@ -112,12 +114,18 @@ public class CrossProfileAppsServiceImplRoboTest { @Before public void initializeMocks() throws Exception { MockitoAnnotations.initMocks(this); + initializeInstalledApplicationsMock(); mockCrossProfileAppInstalledAndEnabledOnEachProfile(); mockCrossProfileAppRequestsInteractAcrossProfiles(); mockCrossProfileAppRegistersBroadcastReceiver(); mockCrossProfileAppWhitelisted(); } + private void initializeInstalledApplicationsMock() { + when(mPackageManagerInternal.getInstalledApplications(anyInt(), anyInt(), eq(CALLING_UID))) + .thenAnswer(invocation -> installedApplications.get(invocation.getArgument(1))); + } + private void mockCrossProfileAppInstalledAndEnabledOnEachProfile() { // They are enabled by default, so we simply have to ensure that a package info with an // application info is returned. @@ -138,11 +146,14 @@ public class CrossProfileAppsServiceImplRoboTest { when(mPackageManagerInternal.getPackage(uid)) .thenReturn(((ParsedPackage) PackageImpl.forTesting(CROSS_PROFILE_APP_PACKAGE_NAME) .hideAsParsed()).hideAsFinal()); + installedApplications.putIfAbsent(userId, new ArrayList<>()); + installedApplications.get(userId).add(packageInfo.applicationInfo); } private PackageInfo buildTestPackageInfo() { PackageInfo packageInfo = new PackageInfo(); packageInfo.applicationInfo = new ApplicationInfo(); + packageInfo.applicationInfo.packageName = CROSS_PROFILE_APP_PACKAGE_NAME; return packageInfo; } @@ -451,6 +462,13 @@ public class CrossProfileAppsServiceImplRoboTest { .isTrue(); } + @Test + public void clearInteractAcrossProfilesAppOps() { + explicitlySetInteractAcrossProfilesAppOp(MODE_ALLOWED); + mCrossProfileAppsServiceImpl.clearInteractAcrossProfilesAppOps(); + assertThat(getCrossProfileAppOp()).isEqualTo(MODE_DEFAULT); + } + private void explicitlySetInteractAcrossProfilesAppOp(@Mode int mode) { explicitlySetInteractAcrossProfilesAppOp(PERSONAL_PROFILE_UID, mode); } |