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

Commit 8f99bff2 authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Add instrumentation flag to get access to full exteranl storage.

When starting a process under instrumentation using this new
"--no-isolated-storage" flag, the process would be able to see the
full external storage.

Bug: 117229024
Test: adb shell am instrument --no-isolated-storage \
      -e class android.media.cts.EncodeDecodeTest#testEncodeDecodeVideoFromBufferToBuffer720p \
      -w android.media.cts/android.test.InstrumentationTestRunner
Change-Id: I7973b123cf4fc08e8ce2b05bd4c23fa41b1cdcdf
parent 5b3a6a81
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -174,6 +174,8 @@ public class Am extends BaseCommand {
                instrument.noWindowAnimation = true;
            } else if (opt.equals("--no-hidden-api-checks")) {
                instrument.disableHiddenApiChecks = true;
            } else if (opt.equals("--no-isolated-storage")) {
                instrument.disableIsolatedStorage = true;
            } else if (opt.equals("--user")) {
                instrument.userId = parseUserArg(nextArgRequired());
            } else if (opt.equals("--abi")) {
+11 −5
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.commands.am;

import static android.app.ActivityManager.INSTR_FLAG_DISABLE_HIDDEN_API_CHECKS;
import static android.app.ActivityManager.INSTR_FLAG_MOUNT_EXTERNAL_STORAGE_FULL;

import android.app.IActivityManager;
import android.app.IInstrumentationWatcher;
import android.app.Instrumentation;
@@ -74,16 +77,13 @@ public class Instrument {
    String logPath = null;
    public boolean noWindowAnimation = false;
    public boolean disableHiddenApiChecks = false;
    public boolean disableIsolatedStorage = false;
    public String abi = null;
    public int userId = UserHandle.USER_CURRENT;
    public Bundle args = new Bundle();
    // Required
    public String componentNameArg;

    // Disable hidden API checks for the newly started instrumentation.
    // Must be kept in sync with ActivityManagerService.
    private static final int INSTRUMENTATION_FLAG_DISABLE_HIDDEN_API_CHECKS = 1 << 0;

    /**
     * Construct the instrument command runner.
     */
@@ -480,7 +480,13 @@ public class Instrument {
            }

            // Start the instrumentation
            int flags = disableHiddenApiChecks ? INSTRUMENTATION_FLAG_DISABLE_HIDDEN_API_CHECKS : 0;
            int flags = 0;
            if (disableHiddenApiChecks) {
                flags |= INSTR_FLAG_DISABLE_HIDDEN_API_CHECKS;
            }
            if (disableIsolatedStorage) {
                flags |= INSTR_FLAG_MOUNT_EXTERNAL_STORAGE_FULL;
            }
            if (!mAm.startInstrumentation(cn, profileFile, flags, args, watcher, connection, userId,
                        abi)) {
                throw new AndroidException("INSTRUMENTATION_FAILED: " + cn.flattenToString());
+11 −0
Original line number Diff line number Diff line
@@ -137,6 +137,17 @@ public class ActivityManager {
    private static final int FIRST_START_NON_FATAL_ERROR_CODE = 100;
    private static final int LAST_START_NON_FATAL_ERROR_CODE = 199;

    /**
     * Disable hidden API checks for the newly started instrumentation.
     * @hide
     */
    public static final int INSTR_FLAG_DISABLE_HIDDEN_API_CHECKS = 1 << 0;
    /**
     * Mount full external storage for the newly started instrumentation.
     * @hide
     */
    public static final int INSTR_FLAG_MOUNT_EXTERNAL_STORAGE_FULL = 1 << 1;

    static final class UidObserver extends IUidObserver.Stub {
        final OnUidImportanceListener mListener;
        final Context mContext;
+14 −9
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import static android.Manifest.permission.FILTER_EVENTS;
import static android.Manifest.permission.INTERACT_ACROSS_USERS;
import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
import static android.Manifest.permission.REMOVE_TASKS;
import static android.app.ActivityManager.INSTR_FLAG_DISABLE_HIDDEN_API_CHECKS;
import static android.app.ActivityManager.INSTR_FLAG_MOUNT_EXTERNAL_STORAGE_FULL;
import static android.app.ActivityManager.PROCESS_STATE_CACHED_ACTIVITY;
import static android.app.ActivityManager.PROCESS_STATE_LAST_ACTIVITY;
import static android.app.ActivityManagerInternal.ALLOW_FULL_ONLY;
@@ -461,10 +463,6 @@ public class ActivityManagerService extends IActivityManager.Stub
    static final int BROADCAST_FG_TIMEOUT = 10*1000;
    static final int BROADCAST_BG_TIMEOUT = 60*1000;
    // Disable hidden API checks for the newly started instrumentation.
    // Must be kept in sync with Am.
    private static final int INSTRUMENTATION_FLAG_DISABLE_HIDDEN_API_CHECKS = 1 << 0;
    public static final int MY_PID = myPid();
    static final String[] EMPTY_STRING_ARRAY = new String[0];
@@ -7122,13 +7120,13 @@ public class ActivityManagerService extends IActivityManager.Stub
    final ProcessRecord addAppLocked(ApplicationInfo info, String customProcess, boolean isolated,
            String abiOverride) {
        return addAppLocked(info, customProcess, isolated, false /* disableHiddenApiChecks */,
                abiOverride);
                false /* mountExtStorageFull */, abiOverride);
    }
    // TODO: Move to ProcessList?
    @GuardedBy("this")
    final ProcessRecord addAppLocked(ApplicationInfo info, String customProcess, boolean isolated,
            boolean disableHiddenApiChecks, String abiOverride) {
            boolean disableHiddenApiChecks, boolean mountExtStorageFull, String abiOverride) {
        ProcessRecord app;
        if (!isolated) {
            app = getProcessRecordLocked(customProcess != null ? customProcess : info.processName,
@@ -7161,7 +7159,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            mPersistentStartingProcesses.add(app);
            mProcessList.startProcessLocked(app, "added application",
                    customProcess != null ? customProcess : app.processName, disableHiddenApiChecks,
                    abiOverride);
                    mountExtStorageFull, abiOverride);
        }
        return app;
@@ -14687,11 +14685,13 @@ public class ActivityManagerService extends IActivityManager.Stub
            activeInstr.mResultClass = className;
            boolean disableHiddenApiChecks = ai.usesNonSdkApi()
                    || (flags & INSTRUMENTATION_FLAG_DISABLE_HIDDEN_API_CHECKS) != 0;
                    || (flags & INSTR_FLAG_DISABLE_HIDDEN_API_CHECKS) != 0;
            if (disableHiddenApiChecks) {
                enforceCallingPermission(android.Manifest.permission.DISABLE_HIDDEN_API_CHECKS,
                        "disable hidden API checks");
            }
            final boolean mountExtStorageFull = isCallerShell()
                    && (flags & INSTR_FLAG_MOUNT_EXTERNAL_STORAGE_FULL) != 0;
            final long origId = Binder.clearCallingIdentity();
            // Instrumentation can kill and relaunch even persistent processes
@@ -14704,7 +14704,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            }
            ProcessRecord app = addAppLocked(ai, defProcess, false, disableHiddenApiChecks,
                    abiOverride);
                    mountExtStorageFull, abiOverride);
            app.setActiveInstrumentation(activeInstr);
            activeInstr.mFinished = false;
            activeInstr.mRunningProcesses.add(app);
@@ -14717,6 +14717,11 @@ public class ActivityManagerService extends IActivityManager.Stub
        return true;
    }
    private boolean isCallerShell() {
        final int callingUid = Binder.getCallingUid();
        return callingUid == SHELL_UID || callingUid == ROOT_UID;
    }
    /**
     * Report errors that occur while attempting to start Instrumentation.  Always writes the
     * error to the logs, but if somebody is watching, send the report there too.  This enables
+4 −2
Original line number Diff line number Diff line
@@ -17,14 +17,13 @@
package com.android.server.am;

import static android.app.ActivityManagerInternal.ALLOW_FULL_ONLY;
import static android.app.ActivityTaskManager.INVALID_TASK_ID;
import static android.app.ActivityTaskManager.RESIZE_MODE_SYSTEM;
import static android.app.ActivityTaskManager.RESIZE_MODE_USER;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.view.Display.INVALID_DISPLAY;

import static android.app.ActivityTaskManager.INVALID_TASK_ID;

import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.app.ActivityTaskManager;
@@ -2902,6 +2901,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
            pw.println("      --receiver-permission <PERMISSION>: Require receiver to hold permission.");
            pw.println("  instrument [-r] [-e <NAME> <VALUE>] [-p <FILE>] [-w]");
            pw.println("          [--user <USER_ID> | current] [--no-hidden-api-checks]");
            pw.println("          [--no-isolated-storage]");
            pw.println("          [--no-window-animation] [--abi <ABI>] <COMPONENT>");
            pw.println("      Start an Instrumentation.  Typically this target <COMPONENT> is in the");
            pw.println("      form <TEST_PACKAGE>/<RUNNER_CLASS> or only <TEST_PACKAGE> if there");
@@ -2920,6 +2920,8 @@ final class ActivityManagerShellCommand extends ShellCommand {
            pw.println("      --user <USER_ID> | current: Specify user instrumentation runs in;");
            pw.println("          current user if not specified.");
            pw.println("      --no-hidden-api-checks: disable restrictions on use of hidden API.");
            pw.println("      --no-isolated-storage: don't use isolated storage sandbox and ");
            pw.println("          mount full external storage");
            pw.println("      --no-window-animation: turn off window animations while running.");
            pw.println("      --abi <ABI>: Launch the instrumented process with the selected ABI.");
            pw.println("          This assumes that the process supports the selected ABI.");
Loading