Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe9bb1b2 authored by tomnatan's avatar tomnatan Committed by Tom Natan
Browse files

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
parent 01ab7bcd
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -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);
        }
    }
}