Re-adopt shell permissions before calling clearOverridesForTest.
This is done because some tests might drop shell permissions during mTestStatement.evaluate() and therefore platformCompat#clearOverridesForTest would fail without re-adopting the shell permissions. In addition we now drop shell permissions before calling mTestStatement.evaluate() so that the test would only have the permission it enables. Test: Existing tests pass. Fix: 182178917 Change-Id: I93566906430d3aadaac256026bf300d7811538f1
This commit is contained in:
@@ -94,17 +94,16 @@ public class PlatformCompatChangeRule extends CoreCompatChangeRule {
|
||||
if (platformCompat == null) {
|
||||
throw new IllegalStateException("Could not get IPlatformCompat service!");
|
||||
}
|
||||
uiAutomation.adoptShellPermissionIdentity(
|
||||
Manifest.permission.LOG_COMPAT_CHANGE,
|
||||
Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG,
|
||||
Manifest.permission.READ_COMPAT_CHANGE_CONFIG);
|
||||
adoptShellPermissions(uiAutomation);
|
||||
Compatibility.setOverrides(mConfig);
|
||||
try {
|
||||
platformCompat.setOverridesForTest(new CompatibilityChangeConfig(mConfig),
|
||||
packageName);
|
||||
try {
|
||||
uiAutomation.dropShellPermissionIdentity();
|
||||
mTestStatement.evaluate();
|
||||
} finally {
|
||||
adoptShellPermissions(uiAutomation);
|
||||
platformCompat.clearOverridesForTest(packageName);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
@@ -114,5 +113,12 @@ public class PlatformCompatChangeRule extends CoreCompatChangeRule {
|
||||
Compatibility.clearOverrides();
|
||||
}
|
||||
}
|
||||
|
||||
private static void adoptShellPermissions(UiAutomation uiAutomation) {
|
||||
uiAutomation.adoptShellPermissionIdentity(
|
||||
Manifest.permission.LOG_COMPAT_CHANGE,
|
||||
Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG,
|
||||
Manifest.permission.READ_COMPAT_CHANGE_CONFIG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user