Inline ImeTracing#onShellCommand()

This is a preparation to add new command:

  adb shell cmd ime tracing save-for-bugreport

which is to be an important piece of functionality to get rid of an
unintentional behavior change (Bug 177462676).

Anyway this CL itself is still a mechanical refactoring hence there
should be no observable behavior change.

Bug: 177462676
Test: "adb shell cmd input_method tracing start" works.
Test: "adb shell cmd input_method tracing stop" works.
Test: "adb shell ime tracing start" still works.
Test: "adb shell ime tracing stop" still works.
Test: "adb shell ime list" still works.
Change-Id: I972f287bddda962dd42d4dd5226cb8b42e759121
This commit is contained in:
Yohei Yukawa
2021-03-10 16:54:54 -08:00
parent 167dea1218
commit 11919f5d83
4 changed files with 17 additions and 42 deletions

View File

@@ -23,7 +23,6 @@ import android.inputmethodservice.AbstractInputMethodService;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.ShellCommand;
import android.util.Log;
import android.util.proto.ProtoOutputStream;
import android.view.inputmethod.InputMethodManager;
@@ -103,12 +102,6 @@ public abstract class ImeTracing {
*/
public abstract void addToBuffer(ProtoOutputStream proto, int source);
/**
* @param shell The shell command to process
* @return {@code 0} if the command was successfully processed, {@code -1} otherwise
*/
public abstract int onShellCommand(ShellCommand shell);
/**
* Starts a proto dump of the client side information.
*

View File

@@ -20,7 +20,6 @@ import android.annotation.NonNull;
import android.inputmethodservice.AbstractInputMethodService;
import android.os.RemoteException;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.ShellCommand;
import android.util.Log;
import android.util.proto.ProtoOutputStream;
import android.view.inputmethod.InputMethodManager;
@@ -44,11 +43,6 @@ class ImeTracingClientImpl extends ImeTracing {
public void addToBuffer(ProtoOutputStream proto, int source) {
}
@Override
public int onShellCommand(ShellCommand shell) {
return -1;
}
@Override
public void triggerClientDump(String where, @NonNull InputMethodManager immInstance,
ProtoOutputStream icProto) {

View File

@@ -22,7 +22,6 @@ import android.annotation.Nullable;
import android.inputmethodservice.AbstractInputMethodService;
import android.os.RemoteException;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.ShellCommand;
import android.util.Log;
import android.util.proto.ProtoOutputStream;
import android.view.inputmethod.InputMethodEditorTraceProto.InputMethodClientsTraceFileProto;
@@ -106,32 +105,6 @@ class ImeTracingServerImpl extends ImeTracing {
}
}
/**
* Responds to a shell command of the format "adb shell cmd input_method ime tracing <command>"
*
* @param shell The shell command to process
* @return {@code 0} if the command was valid and successfully processed, {@code -1} otherwise
*/
@Override
public int onShellCommand(ShellCommand shell) {
PrintWriter pw = shell.getOutPrintWriter();
String cmd = shell.getNextArgRequired();
switch (cmd) {
case "start":
startTrace(pw);
return 0;
case "stop":
stopTrace(pw);
return 0;
default:
pw.println("Unknown command: " + cmd);
pw.println("Input method trace options:");
pw.println(" start: Start tracing");
pw.println(" stop: Stop tracing");
return -1;
}
}
@Override
public void triggerClientDump(String where, InputMethodManager immInstance,
ProtoOutputStream icProto) {

View File

@@ -5838,7 +5838,22 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
@BinderThread
@ShellCommandResult
private int handleShellCommandTraceInputMethod(@NonNull ShellCommand shellCommand) {
int result = ImeTracing.getInstance().onShellCommand(shellCommand);
final String cmd = shellCommand.getNextArgRequired();
final PrintWriter pw = shellCommand.getOutPrintWriter();
switch (cmd) {
case "start":
ImeTracing.getInstance().getInstance().startTrace(pw);
break;
case "stop":
ImeTracing.getInstance().stopTrace(pw);
break;
default:
pw.println("Unknown command: " + cmd);
pw.println("Input method trace options:");
pw.println(" start: Start tracing");
pw.println(" stop: Stop tracing");
return ShellCommandResult.FAILURE;
}
boolean isImeTraceEnabled = ImeTracing.getInstance().isEnabled();
ArrayMap<IBinder, ClientState> clients;
synchronized (mMethodMap) {
@@ -5854,7 +5869,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
}
}
}
return result;
return ShellCommandResult.SUCCESS;
}
/**