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

Commit 0c4ae957 authored by Jing Ji's avatar Jing Ji Committed by Automerger Merge Worker
Browse files

DO NOT MERGE: Context#startInstrumentation could be started from SHELL only now. am: 2d20bee7

parents 9e9dcb3d 2d20bee7
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -15757,6 +15757,17 @@ public class ActivityManagerService extends IActivityManager.Stub
                reportStartInstrumentationFailureLocked(watcher, className, msg);
                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);
            }
            ActiveInstrumentation activeInstr = new ActiveInstrumentation(this);
            activeInstr.mClass = className;
@@ -15812,6 +15823,29 @@ public class ActivityManagerService extends IActivityManager.Stub
        return true;
    }
    @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;