Only enforce caller is root for special commands
Commands like "adb shell cmd dreams", "adb shell cmd dreams dump", and "adb shell cmd dreams help", should all work. Also, when the other commands are called without being root, print the exception to the PrintWriter instead of to logcat where it may not be noticed. Fix: 272000370 Change-Id: Ida3c9bdb8b54a8897fe8261222f4cb9b1a08e0e4 Test: adb shell cmd dreams help # accepted Test: adb shell cmd dreams start-dreaming # rejected
This commit is contained in:
@@ -39,26 +39,24 @@ 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);
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case "start-dreaming":
|
||||
return startDreaming();
|
||||
case "stop-dreaming":
|
||||
return stopDreaming();
|
||||
default:
|
||||
return super.handleDefaultCommands(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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user