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

Commit f2fe2cf8 authored by Tom Natan's avatar Tom Natan Committed by Android (Google) Code Review
Browse files

Merge "Re-adopt shell permissions before calling clearOverridesForTest." into sc-dev

parents 8923c654 fe9bb1b2
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);
        }
    }
}