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

Commit 59579fdc authored by Sandro's avatar Sandro
Browse files

Modify instr and app context for sdk-in-sandbox instrumented tests

Currently, test instrumentation running with the sdk-in-sandbox flag
returns the following
 * getTargetContext() -> sdk-in-sanbdox context,
 * getContext() -> test context.

When running a sdk-in-sandbox instrumented test, we only care about the
sdk-in-sandbox context. With this cl, test instrumentation running with
the sdk-in-sandbox flag returns
 * getTargetContext() -> sdk-in-sandbox context,
 * getContext() -> sdk-in-sandbox context.

The following link shows a diff of the two contexts before (left) and
after (right) this change
go/sdk-instrumentation-contexts-diff

Bug: 271270588
Test: atest CtsSdkSandboxInprocessTests
Change-Id: I4007392b6422b15755ce6e0c0262a00fd8067882
parent d3548350
Loading
Loading
Loading
Loading
+36 −13
Original line number Diff line number Diff line
@@ -888,6 +888,7 @@ public final class ActivityThread extends ClientTransactionHandler
        ApplicationInfo appInfo;
        String sdkSandboxClientAppVolumeUuid;
        String sdkSandboxClientAppPackage;
        boolean isSdkInSandbox;
        @UnsupportedAppUsage
        List<ProviderInfo> 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();
+1 −0
Original line number Diff line number Diff line
@@ -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,
+3 −0
Original line number Diff line number Diff line
@@ -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;

+4 −2
Original line number Diff line number Diff line
@@ -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,
+2 −2
Original line number Diff line number Diff line
@@ -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,