Merge "Add --no-test-api-acces to am instrument." am: 188abff5b2

am: 5c8ed7f6e7

Change-Id: I6b9f9634df7925a85bd837ba0868cd96b5087757
This commit is contained in:
satayev
2019-11-12 10:53:34 -08:00
committed by android-build-merger
5 changed files with 21 additions and 5 deletions

View File

@@ -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-test-api-checks")) {
instrument.disableTestApiChecks = true;
} else if (opt.equals("--no-isolated-storage")) {
instrument.disableIsolatedStorage = true;
} else if (opt.equals("--user")) {

View File

@@ -17,6 +17,7 @@
package com.android.commands.am;
import static android.app.ActivityManager.INSTR_FLAG_DISABLE_HIDDEN_API_CHECKS;
import static android.app.ActivityManager.INSTR_FLAG_DISABLE_TEST_API_CHECKS;
import static android.app.ActivityManager.INSTR_FLAG_MOUNT_EXTERNAL_STORAGE_FULL;
import android.app.IActivityManager;
@@ -85,6 +86,7 @@ public class Instrument {
String logPath = null;
public boolean noWindowAnimation = false;
public boolean disableHiddenApiChecks = false;
public boolean disableTestApiChecks = false;
public boolean disableIsolatedStorage = false;
public String abi = null;
public int userId = UserHandle.USER_CURRENT;
@@ -506,6 +508,9 @@ public class Instrument {
if (disableHiddenApiChecks) {
flags |= INSTR_FLAG_DISABLE_HIDDEN_API_CHECKS;
}
if (disableTestApiChecks) {
flags |= INSTR_FLAG_DISABLE_TEST_API_CHECKS;
}
if (disableIsolatedStorage) {
flags |= INSTR_FLAG_MOUNT_EXTERNAL_STORAGE_FULL;
}

View File

@@ -153,6 +153,12 @@ public class ActivityManager {
*/
public static final int INSTR_FLAG_MOUNT_EXTERNAL_STORAGE_FULL = 1 << 1;
/**
* Disable test API access for the newly started instrumentation.
* @hide
*/
public static final int INSTR_FLAG_DISABLE_TEST_API_CHECKS = 1 << 2;
static final class UidObserver extends IUidObserver.Stub {
final OnUidImportanceListener mListener;
final Context mContext;

View File

@@ -24,6 +24,7 @@ import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
import static android.Manifest.permission.REMOVE_TASKS;
import static android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND;
import static android.app.ActivityManager.INSTR_FLAG_DISABLE_HIDDEN_API_CHECKS;
import static android.app.ActivityManager.INSTR_FLAG_DISABLE_TEST_API_CHECKS;
import static android.app.ActivityManager.INSTR_FLAG_MOUNT_EXTERNAL_STORAGE_FULL;
import static android.app.ActivityManager.PROCESS_STATE_LAST_ACTIVITY;
import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
@@ -15796,13 +15797,12 @@ public class ActivityManagerService extends IActivityManager.Stub
boolean disableHiddenApiChecks = ai.usesNonSdkApi()
|| (flags & INSTR_FLAG_DISABLE_HIDDEN_API_CHECKS) != 0;
if (disableHiddenApiChecks) {
boolean disableTestApiChecks = disableHiddenApiChecks
|| (flags & INSTR_FLAG_DISABLE_TEST_API_CHECKS) != 0;
if (disableHiddenApiChecks || disableTestApiChecks) {
enforceCallingPermission(android.Manifest.permission.DISABLE_HIDDEN_API_CHECKS,
"disable hidden API checks");
}
// Allow instrumented processes access to test APIs.
// TODO(satayev): make this configurable via testing framework.
boolean disableTestApiChecks = true;
final boolean mountExtStorageFull = isCallerShell()
&& (flags & INSTR_FLAG_MOUNT_EXTERNAL_STORAGE_FULL) != 0;

View File

@@ -3032,7 +3032,8 @@ final class ActivityManagerShellCommand extends ShellCommand {
pw.println(" specified then send to all users.");
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(" [--user <USER_ID> | current]");
pw.println(" [--no-hidden-api-checks [--no-test-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");
@@ -3052,6 +3053,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-test-api-checks: disable restrictions to test APIs, if hidden");
pw.println(" API checks are enabled.");
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.");