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

Commit 418d02ed authored by Robin Lee's avatar Robin Lee Committed by Android (Google) Code Review
Browse files

Merge "Only enforce caller is root for special commands" into udc-dev

parents abe2b54b fe58d1c2
Loading
Loading
Loading
Loading
+20 −16
Original line number Diff line number Diff line
@@ -39,27 +39,25 @@ public class DreamShellCommand extends ShellCommand {

    @Override
    public int onCommand(String cmd) {
        final int callingUid = Binder.getCallingUid();
        if (callingUid != Process.ROOT_UID) {
            Slog.e(TAG, "Must be root before calling Dream shell commands");
            return -1;
        }

        if (TextUtils.isEmpty(cmd)) {
            return super.handleDefaultCommands(cmd);
        }
        if (DEBUG) {
            Slog.d(TAG, "onCommand:" + cmd);
        }

        try {
            switch (cmd) {
                case "start-dreaming":
                    enforceCallerIsRoot();
                    return startDreaming();
                case "stop-dreaming":
                    enforceCallerIsRoot();
                    return stopDreaming();
                default:
                    return super.handleDefaultCommands(cmd);
            }
        } catch (SecurityException e) {
            getOutPrintWriter().println(e);
            return -1;
        }
    }

    private int startDreaming() {
@@ -72,6 +70,12 @@ public class DreamShellCommand extends ShellCommand {
        return 0;
    }

    private void enforceCallerIsRoot() {
        if (Binder.getCallingUid() != Process.ROOT_UID) {
            throw new SecurityException("Must be root to call Dream shell commands");
        }
    }

    @Override
    public void onHelp() {
        PrintWriter pw = getOutPrintWriter();