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

Commit 4bf7443a authored by David Brazdil's avatar David Brazdil
Browse files

Exempt instrumented processes from hidden API checks

Whitebox tradefed tests always run as an instrumentation of their own
APK or a shim. This patch passes the information about instrumentation
from ActivityManagerService.startInstrumentation() to
startProcessLocked() and starts the process with hidden API checks
disabled if it is instrumented.

Bug: 64382372
Test: cts-tradefed run cts --plan CTS
Change-Id: I0fe53fcb2ea9bec26f31c6c23833c58327973f6a
parent bca6e66c
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -4075,9 +4075,9 @@ public class ActivityManagerService extends IActivityManager.Stub
                runtimeFlags |= Zygote.ONLY_USE_SYSTEM_OAT_FILES;
            }
            if (app.info.isAllowedToUseHiddenApi()) {
                // This app is allowed to use undocumented and private APIs. Set
                // up its runtime with the appropriate flag.
            if (app.info.isAllowedToUseHiddenApi() || app.instr != null) {
                // This app is allowed to use undocumented and private APIs or is
                // being instrumented. Set up its runtime with the appropriate flag.
                runtimeFlags |= Zygote.DISABLE_HIDDEN_API_CHECKS;
            }
@@ -7209,7 +7209,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            handleAppDiedLocked(app, willRestart, allowRestart);
            if (willRestart) {
                removeLruProcessLocked(app);
                addAppLocked(app.info, null, false, null /* ABI override */);
                addAppLocked(app.info, null, false, null /* ABI override */, app.instr);
            }
        } else {
            mRemovedProcesses.add(app);
@@ -12481,7 +12481,8 @@ public class ActivityManagerService extends IActivityManager.Stub
                        .getPersistentApplications(STOCK_PM_FLAGS | matchFlags).getList();
                for (ApplicationInfo app : apps) {
                    if (!"android".equals(app.packageName)) {
                        addAppLocked(app, null, false, null /* ABI override */);
                        addAppLocked(app, null, false, null /* ABI override */,
                                null /* instrumentation */);
                    }
                }
            } catch (RemoteException ex) {
@@ -12694,7 +12695,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    final ProcessRecord addAppLocked(ApplicationInfo info, String customProcess, boolean isolated,
            String abiOverride) {
            String abiOverride, ActiveInstrumentation instrumentation) {
        ProcessRecord app;
        if (!isolated) {
            app = getProcessRecordLocked(customProcess != null ? customProcess : info.processName,
@@ -12723,6 +12724,9 @@ public class ActivityManagerService extends IActivityManager.Stub
            app.persistent = true;
            app.maxAdj = ProcessList.PERSISTENT_PROC_ADJ;
        }
        app.instr = instrumentation;
        if (app.thread == null && mPersistentStartingProcesses.indexOf(app) < 0) {
            mPersistentStartingProcesses.add(app);
            startProcessLocked(app, "added application",
@@ -21531,8 +21535,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                mUsageStatsService.reportEvent(ii.targetPackage, userId,
                        UsageEvents.Event.SYSTEM_INTERACTION);
            }
            ProcessRecord app = addAppLocked(ai, defProcess, false, abiOverride);
            app.instr = activeInstr;
            ProcessRecord app = addAppLocked(ai, defProcess, false, abiOverride, activeInstr);
            activeInstr.mFinished = false;
            activeInstr.mRunningProcesses.add(app);
            if (!mActiveInstrumentation.contains(activeInstr)) {
@@ -24922,7 +24925,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                    mRemovedProcesses.remove(i);
                    if (app.persistent) {
                        addAppLocked(app.info, null, false, null /* ABI override */);
                        addAppLocked(app.info, null, false, null /* ABI override */, app.instr);
                    }
                }
            }