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

Commit 8a8aaa59 authored by Sandro's avatar Sandro
Browse files

Add parameter to instrument tests for running sdk-in-sandbox

Sandbox-instrumented tests should allow two possible modes, either (1)
running the whole test as a sandbox, or (2) running a test as an sdk
inside the sandbox. Currently only mode (1) is supported. This CL
introduces an instrumentation parameter to support case (2).

Bug: 271270588
Test: I tested the two modes as follows:
 mode (1): atest CtsSdkSandboxInprocessTests
 mode (2): atest CtsSensorRatePermissionTestCases -- --enable-optional-parameterization --enable-parameterized-modules --module-parameter run_on_sdk_sandbox
Change-Id: I820f14a960eef4fc3d613107f73dee80aacbb9d0
parent a3a8c17b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -193,6 +193,9 @@ public class Am extends BaseCommand {
                instrument.alwaysCheckSignature = true;
            } else if (opt.equals("--instrument-sdk-sandbox")) {
                instrument.instrumentSdkSandbox = true;
            } else if (opt.equals("--instrument-sdk-in-sandbox")) {
                instrument.instrumentSdkSandbox = true;
                instrument.instrumentSdkInSandbox = true;
            } else {
                System.err.println("Error: Unknown option: " + opt);
                return;
+5 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.app.ActivityManager.INSTR_FLAG_ALWAYS_CHECK_SIGNATURE;
import static android.app.ActivityManager.INSTR_FLAG_DISABLE_HIDDEN_API_CHECKS;
import static android.app.ActivityManager.INSTR_FLAG_DISABLE_ISOLATED_STORAGE;
import static android.app.ActivityManager.INSTR_FLAG_DISABLE_TEST_API_CHECKS;
import static android.app.ActivityManager.INSTR_FLAG_INSTRUMENT_SDK_IN_SANDBOX;
import static android.app.ActivityManager.INSTR_FLAG_INSTRUMENT_SDK_SANDBOX;
import static android.app.ActivityManager.INSTR_FLAG_NO_RESTART;

@@ -99,6 +100,7 @@ public class Instrument {
    public String componentNameArg;
    public boolean alwaysCheckSignature = false;
    public boolean instrumentSdkSandbox = false;
    public boolean instrumentSdkInSandbox = false;

    /**
     * Construct the instrument command runner.
@@ -530,6 +532,9 @@ public class Instrument {
            if (instrumentSdkSandbox) {
                flags |= INSTR_FLAG_INSTRUMENT_SDK_SANDBOX;
            }
            if (instrumentSdkInSandbox) {
                flags |= INSTR_FLAG_INSTRUMENT_SDK_IN_SANDBOX;
            }
            if (!mAm.startInstrumentation(cn, profileFile, flags, args, watcher, connection, userId,
                        abi)) {
                throw new AndroidException("INSTRUMENTATION_FAILED: " + cn.flattenToString());
+5 −0
Original line number Diff line number Diff line
@@ -192,6 +192,11 @@ public class ActivityManager {
     * @hide
     */
    public static final int INSTR_FLAG_INSTRUMENT_SDK_SANDBOX = 1 << 5;
    /**
     * Instrument an Sdk Sandbox process corresponding to an Sdk running inside the sandbox.
     * @hide
     */
    public static final int INSTR_FLAG_INSTRUMENT_SDK_IN_SANDBOX = 1 << 6;

    static final class UidObserver extends IUidObserver.Stub {
        final OnUidImportanceListener mListener;
+5 −3
Original line number Diff line number Diff line
@@ -15470,7 +15470,8 @@ public class ActivityManagerService extends IActivityManager.Stub
                        ai,
                        noRestart,
                        disableHiddenApiChecks,
                        disableTestApiChecks);
                        disableTestApiChecks,
                        (flags & ActivityManager.INSTR_FLAG_INSTRUMENT_SDK_IN_SANDBOX) != 0);
            }
            ActiveInstrumentation activeInstr = new ActiveInstrumentation(this);
@@ -15567,7 +15568,8 @@ public class ActivityManagerService extends IActivityManager.Stub
            ApplicationInfo sdkSandboxClientAppInfo,
            boolean noRestart,
            boolean disableHiddenApiChecks,
            boolean disableTestApiChecks) {
            boolean disableTestApiChecks,
            boolean isSdkInSandbox) {
        if (noRestart) {
            reportStartInstrumentationFailureLocked(
@@ -15589,7 +15591,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        try {
            sdkSandboxInfo =
                    sandboxManagerLocal.getSdkSandboxApplicationInfoForInstrumentation(
                            sdkSandboxClientAppInfo, userId);
                            sdkSandboxClientAppInfo, userId, isSdkInSandbox);
        } catch (NameNotFoundException e) {
            reportStartInstrumentationFailureLocked(
                    watcher, className, "Can't find SdkSandbox package");