diff options
author | Alex Kershaw <alexkershaw@google.com> | 2020-03-22 15:26:05 +0000 |
---|---|---|
committer | Alex Kershaw <alexkershaw@google.com> | 2020-03-23 23:59:32 +0000 |
commit | 032359b15d87bd34192d4e4645035e806cf20276 (patch) | |
tree | 21f58b47cf76164b59956f41633c3d160d296c98 /robolectric | |
parent | f4bf93d649353bedee4c448913e6fd8a7afae7a7 (diff) | |
download | robolectric-shadows-032359b15d87bd34192d4e4645035e806cf20276.tar.gz |
Add shadow methods for clearing cross-profile app-ops
Add ShadowCrossProfileAppsTest#clearInteractAcrossProfilesAppOps and
unit tests.
Also add other missing shadow methods. Tests were not added for shadow
changes in ShadowUserManager since it's so out of sync with the
Robolectric source of truth currently that the tests would use different
fields. Unit tests in Robolectric in the Android source tree are not
currently working.
Fixes: 151145623
Test: atest com.android.managedprovisioning.task.CreateManagedProfileTaskRoboTest
Test: robolectric unit tests in Android source are broken but the new
unit tests were tested on the robolectric source of truth
Change-Id: I0e2b00586688a4dcd0d7e20a1cd1e39f6236794c
Diffstat (limited to 'robolectric')
-rw-r--r-- | robolectric/src/test/java/org/robolectric/shadows/ShadowCrossProfileAppsTest.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowCrossProfileAppsTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowCrossProfileAppsTest.java index 6bc47c335..cae91513a 100644 --- a/robolectric/src/test/java/org/robolectric/shadows/ShadowCrossProfileAppsTest.java +++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowCrossProfileAppsTest.java @@ -1,15 +1,23 @@ package org.robolectric.shadows; import static android.Manifest.permission.INTERACT_ACROSS_PROFILES; +import static android.app.AppOpsManager.MODE_ALLOWED; +import static android.app.AppOpsManager.MODE_DEFAULT; import static android.os.Build.VERSION_CODES.P; import static android.os.Build.VERSION_CODES.Q; +import static android.os.Build.VERSION_CODES.R; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.fail; import static org.robolectric.Shadows.shadowOf; import android.app.Application; +import android.app.AppOpsManager; import android.content.ComponentName; +import android.content.Context; +import android.content.pm.ApplicationInfo; import android.content.pm.CrossProfileApps; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.os.Process; import android.os.UserHandle; @@ -28,6 +36,7 @@ public class ShadowCrossProfileAppsTest { private final Application application = ApplicationProvider.getApplicationContext(); private final CrossProfileApps crossProfileApps = application.getSystemService(CrossProfileApps.class); + private final PackageManager packageManager = ((Context) application).getPackageManager(); private final UserHandle userHandle1 = UserHandle.of(10); private final UserHandle userHandle2 = UserHandle.of(11); @@ -339,6 +348,35 @@ public class ShadowCrossProfileAppsTest { assertThat(shadowOf(crossProfileApps).peekNextStartedActivity()).isNull(); } + // BEGIN-INTERNAL + @Test + @Config(minSdk = R) + public void clearInteractAcrossProfilesAppOps_clearsAppOps() { + String testPackage1 = "com.example.testpackage1"; + String testPackage2 = "com.example.testpackage2"; + shadowOf(packageManager).installPackage(buildTestPackageInfo(testPackage1)); + shadowOf(packageManager).installPackage(buildTestPackageInfo(testPackage2)); + shadowOf(crossProfileApps).setInteractAcrossProfilesAppOp(testPackage1, MODE_ALLOWED); + shadowOf(crossProfileApps).setInteractAcrossProfilesAppOp(testPackage2, MODE_ALLOWED); + + shadowOf(crossProfileApps).clearInteractAcrossProfilesAppOps(); + + assertThat(shadowOf(crossProfileApps).getInteractAcrossProfilesAppOp(testPackage1)) + .isEqualTo(MODE_DEFAULT); + assertThat(shadowOf(crossProfileApps).getInteractAcrossProfilesAppOp(testPackage2)) + .isEqualTo(MODE_DEFAULT); + } + + private PackageInfo buildTestPackageInfo(String packageName) { + PackageInfo packageInfo = new PackageInfo(); + packageInfo.packageName = packageName; + packageInfo.applicationInfo = new ApplicationInfo(); + packageInfo.applicationInfo.packageName = packageName; + packageInfo.applicationInfo.name = "test"; + return packageInfo; + } + // END-INTERNAL + private static void assertThrowsSecurityException(Runnable runnable) { assertThrows(SecurityException.class, runnable); } |