summaryrefslogtreecommitdiff
path: root/cmds/ime
diff options
context:
space:
mode:
authorYohei Yukawa <yukawa@google.com>2017-12-11 17:24:55 -0800
committerYohei Yukawa <yukawa@google.com>2017-12-11 17:24:55 -0800
commit926488d70d09baefee0489537b2915602deaeebf (patch)
tree548bc371294ce32cb39d83159f4b98dfee983440 /cmds/ime
parent7a46c28d4571e037e26a28ea8e2a01312d916d47 (diff)
Use IBinder#shellCommand() for 'adb shell ime'
This is a preparation CL to add a new command to 'adb shell ime'. Currently 'ime' command is written in Java language that relies directly on the internal Binder IPC interface IInputMethodManager. This is not ideal because: 1. We have to keep maintaining IInputMethodManager methods used only by the 'ime' command. 2. Adding new options to the 'ime' command is tedious when it requires new methods in IInputMethodManager. With this CL, all features of 'ime' command are re-implemented inside InputMethodManagerService (IMMS) on top of Binder's "shell command" feature [1]. Like 'am' command was gone recently [2], now 'ime' command is also a simple shell wrapper to forward options to 'cmd input_method', which allows us to 1) reduce the code duplication and 2) give non-zero status code when the command fails with Java exception. [1]: I76518ea6719d1d08a8ad8722a059c7f5fd86813a 9461b6f91f37fd32207da1bd734d9ea9629eb8e5 [2]: Ia8187196af597046fd2e7092dbf19ce1dc1ea457 1704e3cf0c445512f0a9644485dd3449e874556b Bug: 70475949 Test: adb shell ime Test: adb shell ime help Test: adb shell ime dump Test: adb shell ime list -a Test: adb shell cmd input_method Test: adb shell cmd input_method help Test: adb shell cmd input_method dump Test: adb shell cmd input_method list -a Change-Id: I9a2dbbf1d4494addbe22c82e2c416eedc4d585f2
Diffstat (limited to 'cmds/ime')
-rw-r--r--cmds/ime/Android.mk7
-rwxr-xr-xcmds/ime/ime8
-rw-r--r--cmds/ime/src/com/android/commands/ime/Ime.java248
3 files changed, 1 insertions, 262 deletions
diff --git a/cmds/ime/Android.mk b/cmds/ime/Android.mk
index 6803fc01154c..ca608e8c2c34 100644
--- a/cmds/ime/Android.mk
+++ b/cmds/ime/Android.mk
@@ -3,14 +3,7 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := $(call all-subdir-java-files)
-LOCAL_MODULE := imelib
-LOCAL_MODULE_STEM := ime
-include $(BUILD_JAVA_LIBRARY)
-
-include $(CLEAR_VARS)
LOCAL_MODULE := ime
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_SRC_FILES := ime
-LOCAL_REQUIRED_MODULES := imelib
include $(BUILD_PREBUILT)
diff --git a/cmds/ime/ime b/cmds/ime/ime
index 1a1fdd96da6e..180dc761055b 100755
--- a/cmds/ime/ime
+++ b/cmds/ime/ime
@@ -1,8 +1,2 @@
#!/system/bin/sh
-# Script to start "pm" on the device, which has a very rudimentary
-# shell.
-#
-base=/system
-export CLASSPATH=$base/framework/ime.jar
-exec app_process $base/bin com.android.commands.ime.Ime "$@"
-
+exec cmd input_method "$@"
diff --git a/cmds/ime/src/com/android/commands/ime/Ime.java b/cmds/ime/src/com/android/commands/ime/Ime.java
deleted file mode 100644
index 72a0af6c2d99..000000000000
--- a/cmds/ime/src/com/android/commands/ime/Ime.java
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.commands.ime;
-
-import com.android.internal.view.IInputMethodManager;
-
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.util.PrintStreamPrinter;
-import android.util.Printer;
-import android.view.inputmethod.InputMethodInfo;
-
-import java.util.List;
-
-public final class Ime {
- IInputMethodManager mImm;
-
- private String[] mArgs;
- private int mNextArg;
- private String mCurArgData;
-
- private static final String IMM_NOT_RUNNING_ERR =
- "Error: Could not access the Input Method Manager. Is the system running?";
-
- public static void main(String[] args) {
- new Ime().run(args);
- }
-
- public void run(String[] args) {
- if (args.length < 1) {
- showUsage();
- return;
- }
-
- mImm = IInputMethodManager.Stub.asInterface(ServiceManager.getService("input_method"));
- if (mImm == null) {
- System.err.println(IMM_NOT_RUNNING_ERR);
- return;
- }
-
- mArgs = args;
- String op = args[0];
- mNextArg = 1;
-
- if ("list".equals(op)) {
- runList();
- return;
- }
-
- if ("enable".equals(op)) {
- runSetEnabled(true);
- return;
- }
-
- if ("disable".equals(op)) {
- runSetEnabled(false);
- return;
- }
-
- if ("set".equals(op)) {
- runSet();
- return;
- }
-
- if (op != null) {
- System.err.println("Error: unknown command '" + op + "'");
- }
- showUsage();
- }
-
- /**
- * Execute the list sub-command.
- */
- private void runList() {
- String opt;
- boolean all = false;
- boolean brief = false;
- while ((opt=nextOption()) != null) {
- if (opt.equals("-a")) {
- all = true;
- } else if (opt.equals("-s")) {
- brief = true;
- } else {
- System.err.println("Error: Unknown option: " + opt);
- showUsage();
- return;
- }
- }
-
-
- List<InputMethodInfo> methods;
- if (!all) {
- try {
- methods = mImm.getEnabledInputMethodList();
- } catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(IMM_NOT_RUNNING_ERR);
- return;
- }
- } else {
- try {
- methods = mImm.getInputMethodList();
- } catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(IMM_NOT_RUNNING_ERR);
- return;
- }
- }
-
- if (methods != null) {
- Printer pr = new PrintStreamPrinter(System.out);
- for (int i=0; i<methods.size(); i++) {
- InputMethodInfo imi = methods.get(i);
- if (brief) {
- System.out.println(imi.getId());
- } else {
- System.out.println(imi.getId() + ":");
- imi.dump(pr, " ");
- }
- }
- }
- }
-
- private void runSetEnabled(boolean state) {
- String id = nextArg();
- if (id == null) {
- System.err.println("Error: no input method ID specified");
- showUsage();
- return;
- }
-
- try {
- boolean res = mImm.setInputMethodEnabled(id, state);
- if (state) {
- System.out.println("Input method " + id + ": "
- + (res ? "already enabled" : "now enabled"));
- } else {
- System.out.println("Input method " + id + ": "
- + (res ? "now disabled" : "already disabled"));
- }
- } catch (IllegalArgumentException e) {
- System.err.println("Error: " + e.getMessage());
- return;
- } catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(IMM_NOT_RUNNING_ERR);
- return;
- }
- }
-
- private void runSet() {
- String id = nextArg();
- if (id == null) {
- System.err.println("Error: no input method ID specified");
- showUsage();
- return;
- }
-
- try {
- mImm.setInputMethod(null, id);
- System.out.println("Input method " + id + " selected");
- } catch (IllegalArgumentException e) {
- System.err.println("Error: " + e.getMessage());
- return;
- } catch (RemoteException e) {
- System.err.println(e.toString());
- System.err.println(IMM_NOT_RUNNING_ERR);
- return;
- }
- }
-
- private String nextOption() {
- if (mNextArg >= mArgs.length) {
- return null;
- }
- String arg = mArgs[mNextArg];
- if (!arg.startsWith("-")) {
- return null;
- }
- mNextArg++;
- if (arg.equals("--")) {
- return null;
- }
- if (arg.length() > 1 && arg.charAt(1) != '-') {
- if (arg.length() > 2) {
- mCurArgData = arg.substring(2);
- return arg.substring(0, 2);
- } else {
- mCurArgData = null;
- return arg;
- }
- }
- mCurArgData = null;
- return arg;
- }
-
- private String nextOptionData() {
- if (mCurArgData != null) {
- return mCurArgData;
- }
- if (mNextArg >= mArgs.length) {
- return null;
- }
- String data = mArgs[mNextArg];
- mNextArg++;
- return data;
- }
-
- private String nextArg() {
- if (mNextArg >= mArgs.length) {
- return null;
- }
- String arg = mArgs[mNextArg];
- mNextArg++;
- return arg;
- }
-
- private static void showUsage() {
- System.err.println("usage: ime list [-a] [-s]");
- System.err.println(" ime enable ID");
- System.err.println(" ime disable ID");
- System.err.println(" ime set ID");
- System.err.println("");
- System.err.println("The list command prints all enabled input methods. Use");
- System.err.println("the -a option to see all input methods. Use");
- System.err.println("the -s option to see only a single summary line of each.");
- System.err.println("");
- System.err.println("The enable command allows the given input method ID to be used.");
- System.err.println("");
- System.err.println("The disable command disallows the given input method ID from use.");
- System.err.println("");
- System.err.println("The set command switches to the given input method ID.");
- }
-}