Map "shell ime" to "shell cmd input_method ime"
This is a follow up CL to my following CLs:
* Use IBinder#shellCommand() for 'adb shell ime' [1]
* Add a shell command to reset selected/enabled IMEs [2]
Previously
adb shell ime <command>
was an alias of
adb shell cmd input_method <command>
With this CL,
adb shell ime <command>
is now an alias of
adb shell cmd input_method ime <command>
This allows us to rename a sub command "reset-ime" to "reset" without
worrying about ambiguity about what will be reset.
Note also that the built-in "dump" command now works only as
shell cmd input_method dump
[1]: I9a2dbbf1d4494addbe22c82e2c416eedc4d585f2
926488d70d09baefee0489537b2915602deaeebf
[2]: I1e27aa1c9edf5d9a6d529c469ad42fd1e42b13b1
cc97ebd031b4d4be6f69e3163c362bce6878baf1
Bug: 70475949
Fixes: 70731324
Test: Manually tested as follows.
1. make -j SoftKeyboard
2. adb install -r $OUT/system/app/SoftKeyboard/SoftKeyboard.apk
3. adb shell ime enable com.example.android.softkeyboard/.SoftKeyboard
4. adb shell ime set com.example.android.softkeyboard/.SoftKeyboard
5. Make sure that SoftKeyboard is enabled and selected
6. adb shell ime reset
7. Make sure that SoftKeyboard is no longer enabled and selected
Change-Id: I2a325dcd6108e357420d47880e4cbd9f81670ec9
diff --git a/cmds/ime/ime b/cmds/ime/ime
index 180dc76..7d2f72f 100755
--- a/cmds/ime/ime
+++ b/cmds/ime/ime
@@ -1,2 +1,2 @@
#!/system/bin/sh
-exec cmd input_method "$@"
+exec cmd input_method ime "$@"
diff --git a/services/core/java/com/android/server/InputMethodManagerService.java b/services/core/java/com/android/server/InputMethodManagerService.java
index 25c3fe4..880e1e4 100644
--- a/services/core/java/com/android/server/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/InputMethodManagerService.java
@@ -35,6 +35,7 @@
import com.android.internal.os.TransferPipe;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.FastXmlSerializer;
+import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.view.IInputContext;
import com.android.internal.view.IInputMethod;
import com.android.internal.view.IInputMethodClient;
@@ -4663,23 +4664,31 @@
@ShellCommandResult
@Override
public int onCommand(@Nullable String cmd) {
- if (cmd == null) {
- return handleDefaultCommands(cmd);
+ // For existing "adb shell ime <command>".
+ 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);
+ default:
+ getOutPrintWriter().println("Unknown command: " + imeCommand);
+ return ShellCommandResult.FAILURE;
+ }
}
- switch (cmd) {
- 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-ime":
- return mService.handleShellCommandResetInputMethod(this);
- default:
- return handleDefaultCommands(cmd);
- }
+
+ return handleDefaultCommands(cmd);
}
@BinderThread
@@ -4691,19 +4700,48 @@
pw.println(" Prints this help text.");
pw.println(" dump [options]");
pw.println(" Synonym of dumpsys.");
- pw.println(" list [-a] [-s]");
- pw.println(" prints all enabled input methods.");
- pw.println(" -a: see all input methods");
- pw.println(" -s: only a single summary line of each");
- pw.println(" enable <ID>");
- pw.println(" allows the given input method ID to be used.");
- pw.println(" disable <ID>");
- pw.println(" disallows the given input method ID to be used.");
- pw.println(" set <ID>");
- pw.println(" switches to the given input method ID.");
- pw.println(" reset-ime");
- pw.println(" reset currently selected/enabled IMEs to the default ones as if");
- pw.println(" the device is initially booted with the current locale.");
+ pw.println(" ime <command> [options]");
+ pw.println(" Manipulate IMEs. Run \"ime help\" for details.");
+ }
+ }
+
+ private void onImeCommandHelp() {
+ try (IndentingPrintWriter pw =
+ new IndentingPrintWriter(getOutPrintWriter(), " ", 100)) {
+ pw.println("ime <command>:");
+ pw.increaseIndent();
+
+ pw.println("list [-a] [-s]");
+ pw.increaseIndent();
+ pw.println("prints all enabled input methods.");
+ pw.increaseIndent();
+ pw.println("-a: see all input methods");
+ pw.println("-s: only a single summary line of each");
+ pw.decreaseIndent();
+ pw.decreaseIndent();
+
+ pw.println("enable <ID>");
+ pw.increaseIndent();
+ pw.println("allows the given input method ID to be used.");
+ pw.decreaseIndent();
+
+ pw.println("disable <ID>");
+ pw.increaseIndent();
+ pw.println("disallows the given input method ID to be used.");
+ pw.decreaseIndent();
+
+ pw.println("set <ID>");
+ pw.increaseIndent();
+ pw.println("switches to the given input method ID.");
+ pw.decreaseIndent();
+
+ pw.println("reset");
+ pw.increaseIndent();
+ pw.println("reset currently selected/enabled IMEs to the default ones as if "
+ + "the device is initially booted with the current locale.");
+ pw.decreaseIndent();
+
+ pw.decreaseIndent();
}
}
}