summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Nikita Ioffe <ioffe@google.com> 2022-02-09 14:36:36 +0000
committer Nikita Ioffe <ioffe@google.com> 2022-02-16 17:32:36 +0000
commit0b977ecd0538a369ee6232a6a0b6d0df73c8a8c6 (patch)
tree137889edd2f67ca3af4f49e70e6a1f67cdacfba9
parent504bbf12c78f0a26b301c219aac68b2d4639bb86 (diff)
Add a flag to always do the cert signature check
Right now signature check is unconditionally bypassed on debuggable builds, which makes things a little bit confusing - instrumentation will succeed on debuggable build, but fail on the user build. Bug: 209061624 Test: adb shell am --always-check-signature com.android.tests.supplemental.process/androidx.test.runner.AndroidJUnitRunner Change-Id: I66d6331156d4503e147141872cbe73a9330ea701
-rw-r--r--cmds/am/src/com/android/commands/am/Am.java2
-rw-r--r--cmds/am/src/com/android/commands/am/Instrument.java5
-rw-r--r--core/java/android/app/ActivityManager.java6
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java15
4 files changed, 23 insertions, 5 deletions
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java
index 9564dde7fe06..c5410a082322 100644
--- a/cmds/am/src/com/android/commands/am/Am.java
+++ b/cmds/am/src/com/android/commands/am/Am.java
@@ -189,6 +189,8 @@ public class Am extends BaseCommand {
instrument.abi = nextArgRequired();
} else if (opt.equals("--no-restart")) {
instrument.noRestart = true;
+ } else if (opt.equals("--always-check-signature")) {
+ instrument.alwaysCheckSignature = true;
} else {
System.err.println("Error: Unknown option: " + opt);
return;
diff --git a/cmds/am/src/com/android/commands/am/Instrument.java b/cmds/am/src/com/android/commands/am/Instrument.java
index 0b439df403e0..a0562d964954 100644
--- a/cmds/am/src/com/android/commands/am/Instrument.java
+++ b/cmds/am/src/com/android/commands/am/Instrument.java
@@ -16,6 +16,7 @@
package com.android.commands.am;
+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;
@@ -95,6 +96,7 @@ public class Instrument {
public Bundle args = new Bundle();
// Required
public String componentNameArg;
+ public boolean alwaysCheckSignature = false;
/**
* Construct the instrument command runner.
@@ -519,6 +521,9 @@ public class Instrument {
if (noRestart) {
flags |= INSTR_FLAG_NO_RESTART;
}
+ if (alwaysCheckSignature) {
+ flags |= INSTR_FLAG_ALWAYS_CHECK_SIGNATURE;
+ }
if (!mAm.startInstrumentation(cn, profileFile, flags, args, watcher, connection, userId,
abi)) {
throw new AndroidException("INSTRUMENTATION_FAILED: " + cn.flattenToString());
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index 89dd9ef5d9c6..9f1510526bae 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -179,6 +179,12 @@ public class ActivityManager {
* @hide
*/
public static final int INSTR_FLAG_NO_RESTART = 1 << 3;
+ /**
+ * Force the check that instrumentation and the target package are signed with the same
+ * certificate even if {@link Build#IS_DEBUGGABLE} is {@code true}.
+ * @hide
+ */
+ public static final int INSTR_FLAG_ALWAYS_CHECK_SIGNATURE = 1 << 4;
static final class UidObserver extends IUidObserver.Stub {
final OnUidImportanceListener mListener;
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 6c39a114e48a..ff9f389949a5 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -24,6 +24,7 @@ import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
import static android.Manifest.permission.MANAGE_ACTIVITY_TASKS;
import static android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND;
import static android.Manifest.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND;
+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;
@@ -14339,14 +14340,18 @@ public class ActivityManagerService extends IActivityManager.Stub
return false;
}
- if (!Build.IS_DEBUGGABLE) {
- int match = mContext.getPackageManager().checkSignatures(
- ii.targetPackage, ii.packageName);
- if (match < 0 && match != PackageManager.SIGNATURE_FIRST_NOT_SIGNED) {
+ int match = mContext.getPackageManager().checkSignatures(
+ ii.targetPackage, ii.packageName);
+ if (match < 0 && match != PackageManager.SIGNATURE_FIRST_NOT_SIGNED) {
+ if (Build.IS_DEBUGGABLE && (flags & INSTR_FLAG_ALWAYS_CHECK_SIGNATURE) == 0) {
+ Slog.w(TAG, "Instrumentation test " + ii.packageName
+ + " doesn't have a signature matching the target " + ii.targetPackage
+ + ", which would not be allowed on the production Android builds");
+ } else {
String msg = "Permission Denial: starting instrumentation "
+ className + " from pid="
+ Binder.getCallingPid()
- + ", uid=" + Binder.getCallingPid()
+ + ", uid=" + Binder.getCallingUid()
+ " not allowed because package " + ii.packageName
+ " does not have a signature matching the target "
+ ii.targetPackage;