Skip to content
Snippets Groups Projects
Commit 5dde2255 authored by Jing Ji's avatar Jing Ji Committed by Android (Google) Code Review
Browse files

Merge "DO NOT MERGE: Context#startInstrumentation could be started from SHELL...

Merge "DO NOT MERGE: Context#startInstrumentation could be started from SHELL only now." into tm-dev
parents 8862ff7f 0bf31e3e
No related branches found
No related tags found
No related merge requests found
......@@ -14605,6 +14605,17 @@ public class ActivityManagerService extends IActivityManager.Stub
throw new SecurityException(msg);
}
}
if (!Build.IS_DEBUGGABLE && callingUid != ROOT_UID && callingUid != SHELL_UID
&& callingUid != SYSTEM_UID && !hasActiveInstrumentationLocked(callingPid)) {
// If it's not debug build and not called from root/shell/system uid, reject it.
final String msg = "Permission Denial: instrumentation test "
+ className + " from pid=" + callingPid + ", uid=" + callingUid
+ ", pkgName=" + getPackageNameByPid(callingPid)
+ " not allowed because it's not started from SHELL";
Slog.wtfQuiet(TAG, msg);
reportStartInstrumentationFailureLocked(watcher, className, msg);
throw new SecurityException(msg);
}
 
boolean disableHiddenApiChecks = ai.usesNonSdkApi()
|| (flags & INSTR_FLAG_DISABLE_HIDDEN_API_CHECKS) != 0;
......@@ -14827,6 +14838,29 @@ public class ActivityManagerService extends IActivityManager.Stub
}
}
 
@GuardedBy("this")
private boolean hasActiveInstrumentationLocked(int pid) {
if (pid == 0) {
return false;
}
synchronized (mPidsSelfLocked) {
ProcessRecord process = mPidsSelfLocked.get(pid);
return process != null && process.getActiveInstrumentation() != null;
}
}
private String getPackageNameByPid(int pid) {
synchronized (mPidsSelfLocked) {
final ProcessRecord app = mPidsSelfLocked.get(pid);
if (app != null && app.info != null) {
return app.info.packageName;
}
return null;
}
}
private boolean isCallerShell() {
final int callingUid = Binder.getCallingUid();
return callingUid == SHELL_UID || callingUid == ROOT_UID;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment