OSDN Git Service

Exempt instrumented processes from hidden API checks
authorDavid Brazdil <dbrazdil@google.com>
Tue, 6 Feb 2018 20:55:47 +0000 (20:55 +0000)
committerDavid Brazdil <dbrazdil@google.com>
Wed, 7 Feb 2018 00:13:48 +0000 (00:13 +0000)
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

services/core/java/com/android/server/am/ActivityManagerService.java

index a6c4fc9..1101b6a 100644 (file)
@@ -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);
                     }
                 }
             }