diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index b5a1ebde14f6e..690d2498a243e 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -888,6 +888,7 @@ public final class ActivityThread extends ClientTransactionHandler ApplicationInfo appInfo; String sdkSandboxClientAppVolumeUuid; String sdkSandboxClientAppPackage; + boolean isSdkInSandbox; @UnsupportedAppUsage List providers; ComponentName instrumentationName; @@ -1169,19 +1170,34 @@ public final class ActivityThread extends ClientTransactionHandler } @Override - public final void bindApplication(String processName, ApplicationInfo appInfo, - String sdkSandboxClientAppVolumeUuid, String sdkSandboxClientAppPackage, - ProviderInfoList providerList, ComponentName instrumentationName, - ProfilerInfo profilerInfo, Bundle instrumentationArgs, + public final void bindApplication( + String processName, + ApplicationInfo appInfo, + String sdkSandboxClientAppVolumeUuid, + String sdkSandboxClientAppPackage, + boolean isSdkInSandbox, + ProviderInfoList providerList, + ComponentName instrumentationName, + ProfilerInfo profilerInfo, + Bundle instrumentationArgs, IInstrumentationWatcher instrumentationWatcher, - IUiAutomationConnection instrumentationUiConnection, int debugMode, - boolean enableBinderTracking, boolean trackAllocation, - boolean isRestrictedBackupMode, boolean persistent, Configuration config, - CompatibilityInfo compatInfo, Map services, Bundle coreSettings, - String buildSerial, AutofillOptions autofillOptions, - ContentCaptureOptions contentCaptureOptions, long[] disabledCompatChanges, + IUiAutomationConnection instrumentationUiConnection, + int debugMode, + boolean enableBinderTracking, + boolean trackAllocation, + boolean isRestrictedBackupMode, + boolean persistent, + Configuration config, + CompatibilityInfo compatInfo, + Map services, + Bundle coreSettings, + String buildSerial, + AutofillOptions autofillOptions, + ContentCaptureOptions contentCaptureOptions, + long[] disabledCompatChanges, SharedMemory serializedSystemFontMap, - long startRequestedElapsedTime, long startRequestedUptime) { + long startRequestedElapsedTime, + long startRequestedUptime) { if (services != null) { if (false) { // Test code to make sure the app could see the passed-in services. @@ -1215,6 +1231,7 @@ public final class ActivityThread extends ClientTransactionHandler data.appInfo = appInfo; data.sdkSandboxClientAppVolumeUuid = sdkSandboxClientAppVolumeUuid; data.sdkSandboxClientAppPackage = sdkSandboxClientAppPackage; + data.isSdkInSandbox = isSdkInSandbox; data.providers = providerList.getList(); data.instrumentationName = instrumentationName; data.instrumentationArgs = instrumentationArgs; @@ -7213,8 +7230,14 @@ public final class ActivityThread extends ClientTransactionHandler // The test context's op package name == the target app's op package name, because // the app ops manager checks the op package name against the real calling UID, // which is what the target package name is associated with. - final ContextImpl instrContext = ContextImpl.createAppContext(this, pi, - appContext.getOpPackageName()); + // In the case of instrumenting an sdk running in the sdk sandbox, appContext refers + // to the context of the sdk running in the sandbox. Since the sandbox does not have + // access to data outside the sandbox, we require the instrContext to point to the + // sdk in the sandbox as well, and not to the test context. + final ContextImpl instrContext = + (data.isSdkInSandbox) + ? appContext + : ContextImpl.createAppContext(this, pi, appContext.getOpPackageName()); try { final ClassLoader cl = instrContext.getClassLoader(); diff --git a/core/java/android/app/IApplicationThread.aidl b/core/java/android/app/IApplicationThread.aidl index 6b5f6b03028e0..75d8c1012e274 100644 --- a/core/java/android/app/IApplicationThread.aidl +++ b/core/java/android/app/IApplicationThread.aidl @@ -78,6 +78,7 @@ oneway interface IApplicationThread { void scheduleStopService(IBinder token); void bindApplication(in String packageName, in ApplicationInfo info, in String sdkSandboxClientAppVolumeUuid, in String sdkSandboxClientAppPackage, + in boolean isSdkInSandbox, in ProviderInfoList providerList, in ComponentName testName, in ProfilerInfo profilerInfo, in Bundle testArguments, IInstrumentationWatcher testWatcher, IUiAutomationConnection uiAutomationConnection, diff --git a/services/core/java/com/android/server/am/ActiveInstrumentation.java b/services/core/java/com/android/server/am/ActiveInstrumentation.java index 61ccf11ff73ea..49685b95cd662 100644 --- a/services/core/java/com/android/server/am/ActiveInstrumentation.java +++ b/services/core/java/com/android/server/am/ActiveInstrumentation.java @@ -40,6 +40,9 @@ class ActiveInstrumentation { // The application being instrumented ApplicationInfo mTargetInfo; + // Whether the application is instrumented as an sdk running in the sdk_sandbox. + boolean mIsSdkInSandbox; + // Where to save profiling String mProfileFile; diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 848abb541eabe..349361bc08b90 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -4655,6 +4655,7 @@ public class ActivityManagerService extends IActivityManager.Stub } else if (instr2 != null) { thread.bindApplication(processName, appInfo, app.sdkSandboxClientAppVolumeUuid, app.sdkSandboxClientAppPackage, + instr2.mIsSdkInSandbox, providerList, instr2.mClass, profilerInfo, instr2.mArguments, @@ -4671,6 +4672,7 @@ public class ActivityManagerService extends IActivityManager.Stub } else { thread.bindApplication(processName, appInfo, app.sdkSandboxClientAppVolumeUuid, app.sdkSandboxClientAppPackage, + /* isSdkInSandbox= */ false, providerList, null, profilerInfo, null, null, null, testMode, mBinderTransactionTrackingEnabled, enableTrackAllocation, isRestrictedBackupMode || !normalMode, app.isPersistent(), @@ -15436,6 +15438,7 @@ public class ActivityManagerService extends IActivityManager.Stub activeInstr.mClass = className; activeInstr.mTargetProcesses = new String[]{sdkSandboxInfo.processName}; activeInstr.mTargetInfo = sdkSandboxInfo; + activeInstr.mIsSdkInSandbox = isSdkInSandbox; activeInstr.mProfileFile = profileFile; activeInstr.mArguments = arguments; activeInstr.mWatcher = watcher; @@ -15452,7 +15455,6 @@ public class ActivityManagerService extends IActivityManager.Stub sandboxManagerLocal.notifyInstrumentationStarted( sdkSandboxClientAppInfo.packageName, sdkSandboxClientAppInfo.uid); synchronized (mProcLock) { - int sdkSandboxUid = Process.toSdkSandboxUid(sdkSandboxClientAppInfo.uid); // Kill the package sdk sandbox process belong to. At this point sdk sandbox is // already killed. forceStopPackageLocked( @@ -15471,7 +15473,7 @@ public class ActivityManagerService extends IActivityManager.Stub sdkSandboxInfo.processName, /* isolated= */ false, /* isSdkSandbox= */ true, - sdkSandboxUid, + sdkSandboxInfo.uid, sdkSandboxClientAppInfo.packageName, disableHiddenApiChecks, disableTestApiChecks, diff --git a/services/tests/mockingservicestests/src/com/android/server/am/AsyncProcessStartTest.java b/services/tests/mockingservicestests/src/com/android/server/am/AsyncProcessStartTest.java index 7c5d96ec5f5ab..70ee4f451546a 100644 --- a/services/tests/mockingservicestests/src/com/android/server/am/AsyncProcessStartTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/am/AsyncProcessStartTest.java @@ -200,7 +200,7 @@ public class AsyncProcessStartTest { return null; }).when(thread).bindApplication( any(), any(), - any(), any(), + any(), any(), anyBoolean(), any(), any(), any(), any(), any(), @@ -260,7 +260,7 @@ public class AsyncProcessStartTest { /* expectedStartSeq */ 0, /* procAttached */ false); app.getThread().bindApplication(PACKAGE, appInfo, - null, null, + null, null, false, null, null, null, null,