Revoke USE_CUSTOM_VIRTUAL_MACHINE permission in @Before setup()
We have some tests checking that some features are guarded by
USE_CUSTOM_VIRTUAL_MACHINE, and if caller doesn't have the permission
they should get a SecurityException back (e.g.
MicrodroidTests#createVmWithConfigRequiresPermission). Such test will
fail if it is ran by itself, e.g.:
atest com.android.microdroid.test.MicrodroidTests#createVmWithConfigurRequiresPermission
This changes fixes the problem by revoking the permission during the
test setup.
Test: atest com.android.microdroid.test.MicrodroidTests#createVmWithConfigRequiresPermission
Change-Id: I54e907d5907d225b2f412451fd456241ff568e00
diff --git a/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java b/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
index ffb2c11..dc045a1 100644
--- a/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
+++ b/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
@@ -128,6 +128,13 @@
public void setup() {
grantPermission(VirtualMachine.MANAGE_VIRTUAL_MACHINE_PERMISSION);
prepareTestSetup(mProtectedVm);
+ // USE_CUSTOM_VIRTUAL_MACHINE permission has protection level signature|development, meaning
+ // that it will be automatically granted when test apk is installed. We have some tests
+ // checking the behavior when caller doesn't have this permission (e.g.
+ // createVmWithConfigRequiresPermission). Proactively revoke the permission so that such
+ // tests can pass when ran by itself, e.g.:
+ // atest com.android.microdroid.test.MicrodroidTests#createVmWithConfigRequiresPermission
+ revokePermission(VirtualMachine.USE_CUSTOM_VIRTUAL_MACHINE_PERMISSION);
}
@After