From c59ba280cf7b16faf3c9a6c7557bee376cd373b7 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Wed, 24 Feb 2021 11:24:49 -0800 Subject: [PATCH] Simplify IMMS#onCommandWithSystemIdentity() This is mechanical refacotring. There should be no developer-observable behavior change. This is a preparation to fix Bug 180765389. Bug: 180765389 Test: "adb shell ime" still shows help. Test: "adb shell ime help" still works. Test: "adb shell ime list" still works. Test: "adb shell cmd input_method" still shows help. Test: "adb shell cmd input_method dump" still works. Test: "adb shell cmd input_method help" still works. Test: "adb shell cmd input_method ime list" still works. Change-Id: I2fb5d9d84d9e51890e432e996ca294778d507362 --- .../InputMethodManagerService.java | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 0754df0e6b9f5..d448618508739 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -5412,37 +5412,36 @@ public class InputMethodManagerService extends IInputMethodManager.Stub @BinderThread @ShellCommandResult private int onCommandWithSystemIdentity(@Nullable String cmd) { - if ("get-last-switch-user-id".equals(cmd)) { - return mService.getLastSwitchUserId(this); - } - - // For existing "adb shell ime ". - if ("ime".equals(cmd)) { - final String imeCommand = getNextArg(); - if (imeCommand == null || "help".equals(imeCommand) || "-h".equals(imeCommand)) { - onImeCommandHelp(); - return ShellCommandResult.SUCCESS; - } - switch (imeCommand) { - case "list": - return mService.handleShellCommandListInputMethods(this); - case "enable": - return mService.handleShellCommandEnableDisableInputMethod(this, true); - case "disable": - return mService.handleShellCommandEnableDisableInputMethod(this, false); - case "set": - return mService.handleShellCommandSetInputMethod(this); - case "reset": - return mService.handleShellCommandResetInputMethod(this); - case "tracing": - return mService.handleShellCommandTraceInputMethod(this); - default: - getOutPrintWriter().println("Unknown command: " + imeCommand); - return ShellCommandResult.FAILURE; + switch (TextUtils.emptyIfNull(cmd)) { + case "get-last-switch-user-id": + return mService.getLastSwitchUserId(this); + case "ime": { // For "adb shell ime ". + final String imeCommand = TextUtils.emptyIfNull(getNextArg()); + switch (imeCommand) { + case "": + case "-h": + case "help": + return onImeCommandHelp(); + case "list": + return mService.handleShellCommandListInputMethods(this); + case "enable": + return mService.handleShellCommandEnableDisableInputMethod(this, true); + case "disable": + return mService.handleShellCommandEnableDisableInputMethod(this, false); + case "set": + return mService.handleShellCommandSetInputMethod(this); + case "reset": + return mService.handleShellCommandResetInputMethod(this); + case "tracing": + return mService.handleShellCommandTraceInputMethod(this); + default: + getOutPrintWriter().println("Unknown command: " + imeCommand); + return ShellCommandResult.FAILURE; + } } + default: + return handleDefaultCommands(cmd); } - - return handleDefaultCommands(cmd); } @BinderThread @@ -5459,7 +5458,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } - private void onImeCommandHelp() { + @BinderThread + @ShellCommandResult + private int onImeCommandHelp() { try (IndentingPrintWriter pw = new IndentingPrintWriter(getOutPrintWriter(), " ", 100)) { pw.println("ime :"); @@ -5514,6 +5515,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub pw.decreaseIndent(); } + return ShellCommandResult.SUCCESS; } }