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

Commit 5f1f29a9 authored by Mathew Inwood's avatar Mathew Inwood
Browse files

Enforce permission when disabling API checks.

Add a new internal permission required to disable hidden API checks using
"am instrument". Grant this permission to the shell.

Test: $ adb shell am instrument --no-hidden-api-checks mypackage/.MainInstrumentation
Bug: 64382372

Change-Id: I193dba412560f17810ad0c67c733a1eec15fa7b7
parent 8182e354
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -3943,6 +3943,11 @@
    <permission android:name="android.permission.OPEN_APPLICATION_DETAILS_OPEN_BY_DEFAULT_PAGE"
                android:protectionLevel="signature" />

    <!-- Allows hidden API checks to be disabled when starting a process.
         @hide <p>Not for use by third-party applications. -->
    <permission android:name="android.permission.DISABLE_HIDDEN_API_CHECKS"
                android:protectionLevel="signature" />

    <application android:process="system"
                 android:persistent="true"
                 android:hasCode="false"
+1 −0
Original line number Diff line number Diff line
@@ -130,6 +130,7 @@
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.SET_TIME" />
    <uses-permission android:name="android.permission.SET_TIME_ZONE" />
    <uses-permission android:name="android.permission.DISABLE_HIDDEN_API_CHECKS" />
    <!-- Permission needed to rename bugreport notifications (so they're not shown as Shell) -->
    <uses-permission android:name="android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME" />
    <!-- Permission needed to hold a wakelock in dumpstate.cpp (drop_root_user()) -->
+7 −3
Original line number Diff line number Diff line
@@ -22063,6 +22063,13 @@ public class ActivityManagerService extends IActivityManager.Stub
            activeInstr.mUiAutomationConnection = uiAutomationConnection;
            activeInstr.mResultClass = className;
            boolean disableHiddenApiChecks =
                    (flags & INSTRUMENTATION_FLAG_DISABLE_HIDDEN_API_CHECKS) != 0;
            if (disableHiddenApiChecks) {
                enforceCallingPermission(android.Manifest.permission.DISABLE_HIDDEN_API_CHECKS,
                        "disable hidden API checks");
            }
            final long origId = Binder.clearCallingIdentity();
            // Instrumentation can kill and relaunch even persistent processes
            forceStopPackageLocked(ii.targetPackage, -1, true, false, true, true, false, userId,
@@ -22072,9 +22079,6 @@ public class ActivityManagerService extends IActivityManager.Stub
                mUsageStatsService.reportEvent(ii.targetPackage, userId,
                        UsageEvents.Event.SYSTEM_INTERACTION);
            }
            boolean disableHiddenApiChecks =
                    (flags & INSTRUMENTATION_FLAG_DISABLE_HIDDEN_API_CHECKS) != 0;
            // TODO: Temporary whitelist of packages which need to be exempt from hidden API
            //       checks. Remove this as soon as the testing infrastructure allows to set
            //       the flag in AndroidTest.xml.