Optimize InputConnectionProtoDumper a bit

This is a mechanical refactoring CL that has no behavior change.

Currently all the utility methods defined in
InputConnectionProtoDumper return ProtoOutputStream, while the
returned instances will always be converted into byte[] eventually.
With this CL, those utility methods return byte[] instances directly,
which is expected to make it easier for ART/dexpreopt to do more
optimizations such as code inlining because instances of
ProtoOutputStream will no longer be escaped from those methods.

Bug: 192412909
Test: atest CtsInputMethodTestCases
Test: Manually verified that IME tracing still works
Change-Id: I7b24aee5428da312972aa86b8658429b421490f8
This commit is contained in:
Yohei Yukawa
2021-07-09 09:46:47 -07:00
parent 3beeb3e3c7
commit 26b594af10
9 changed files with 47 additions and 43 deletions

View File

@@ -223,7 +223,7 @@ public abstract class AbstractInputMethodService extends WindowProviderService
* @hide
*/
@SuppressWarnings("HiddenAbstractMethod")
public abstract void dumpProtoInternal(ProtoOutputStream proto, ProtoOutputStream icProto);
public abstract void dumpProtoInternal(ProtoOutputStream proto, @Nullable byte[] icProto);
/**
* Implement this to handle {@link android.os.Binder#dump Binder.dump()}

View File

@@ -3415,7 +3415,7 @@ public class InputMethodService extends AbstractInputMethodService {
* @hide
*/
@Override
public final void dumpProtoInternal(ProtoOutputStream proto, ProtoOutputStream icProto) {
public final void dumpProtoInternal(ProtoOutputStream proto, byte[] icProto) {
final long token = proto.start(InputMethodServiceTraceProto.INPUT_METHOD_SERVICE);
mWindow.dumpDebug(proto, SOFT_INPUT_WINDOW);
proto.write(VIEWS_CREATED, mViewsCreated);
@@ -3445,7 +3445,7 @@ public class InputMethodService extends AbstractInputMethodService {
mTmpInsets.dumpDebug(proto, LAST_COMPUTED_INSETS);
proto.write(SETTINGS_OBSERVER, Objects.toString(mSettingsObserver));
if (icProto != null) {
proto.write(INPUT_CONNECTION_CALL, icProto.getBytes());
proto.write(INPUT_CONNECTION_CALL, icProto);
}
proto.end(token);
}

View File

@@ -22,7 +22,6 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Bundle;
import android.os.Handler;
import android.util.proto.ProtoOutputStream;
import android.view.KeyEvent;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.CorrectionInfo;
@@ -93,8 +92,8 @@ final class RemoteInputConnection implements InputConnection {
final AbstractInputMethodService inputMethodService = mInputMethodService.get();
if (inputMethodService != null && ImeTracing.getInstance().isEnabled()) {
ProtoOutputStream icProto = InputConnectionProtoDumper.buildGetTextAfterCursorProto(
length, flags, result);
final byte[] icProto = InputConnectionProtoDumper.buildGetTextAfterCursorProto(length,
flags, result);
ImeTracing.getInstance().triggerServiceDump(TAG + "#getTextAfterCursor",
inputMethodService, icProto);
}
@@ -118,8 +117,8 @@ final class RemoteInputConnection implements InputConnection {
final AbstractInputMethodService inputMethodService = mInputMethodService.get();
if (inputMethodService != null && ImeTracing.getInstance().isEnabled()) {
ProtoOutputStream icProto = InputConnectionProtoDumper.buildGetTextBeforeCursorProto(
length, flags, result);
final byte[] icProto = InputConnectionProtoDumper.buildGetTextBeforeCursorProto(length,
flags, result);
ImeTracing.getInstance().triggerServiceDump(TAG + "#getTextBeforeCursor",
inputMethodService, icProto);
}
@@ -143,7 +142,7 @@ final class RemoteInputConnection implements InputConnection {
final AbstractInputMethodService inputMethodService = mInputMethodService.get();
if (inputMethodService != null && ImeTracing.getInstance().isEnabled()) {
ProtoOutputStream icProto = InputConnectionProtoDumper.buildGetSelectedTextProto(flags,
final byte[] icProto = InputConnectionProtoDumper.buildGetSelectedTextProto(flags,
result);
ImeTracing.getInstance().triggerServiceDump(TAG + "#getSelectedText",
inputMethodService, icProto);
@@ -182,7 +181,7 @@ final class RemoteInputConnection implements InputConnection {
final AbstractInputMethodService inputMethodService = mInputMethodService.get();
if (inputMethodService != null && ImeTracing.getInstance().isEnabled()) {
ProtoOutputStream icProto = InputConnectionProtoDumper.buildGetSurroundingTextProto(
final byte[] icProto = InputConnectionProtoDumper.buildGetSurroundingTextProto(
beforeLength, afterLength, flags, result);
ImeTracing.getInstance().triggerServiceDump(TAG + "#getSurroundingText",
inputMethodService, icProto);
@@ -203,7 +202,7 @@ final class RemoteInputConnection implements InputConnection {
final AbstractInputMethodService inputMethodService = mInputMethodService.get();
if (inputMethodService != null && ImeTracing.getInstance().isEnabled()) {
ProtoOutputStream icProto = InputConnectionProtoDumper.buildGetCursorCapsModeProto(
final byte[] icProto = InputConnectionProtoDumper.buildGetCursorCapsModeProto(
reqModes, result);
ImeTracing.getInstance().triggerServiceDump(TAG + "#getCursorCapsMode",
inputMethodService, icProto);
@@ -224,7 +223,7 @@ final class RemoteInputConnection implements InputConnection {
final AbstractInputMethodService inputMethodService = mInputMethodService.get();
if (inputMethodService != null && ImeTracing.getInstance().isEnabled()) {
ProtoOutputStream icProto = InputConnectionProtoDumper.buildGetExtractedTextProto(
final byte[] icProto = InputConnectionProtoDumper.buildGetExtractedTextProto(
request, flags, result);
ImeTracing.getInstance().triggerServiceDump(TAG + "#getExtractedText",
inputMethodService, icProto);

View File

@@ -3210,7 +3210,7 @@ public final class InputMethodManager {
* @hide
*/
@GuardedBy("mH")
public void dumpDebug(ProtoOutputStream proto, ProtoOutputStream icProto) {
public void dumpDebug(ProtoOutputStream proto, @Nullable byte[] icProto) {
if (mCurrentInputMethodSession == null) {
return;
}
@@ -3236,7 +3236,7 @@ public final class InputMethodManager {
mServedInputConnectionWrapper.dumpDebug(proto, INPUT_CONNECTION);
}
if (icProto != null) {
proto.write(INPUT_CONNECTION_CALL, icProto.getBytes());
proto.write(INPUT_CONNECTION_CALL, icProto);
}
}
}

View File

@@ -104,7 +104,7 @@ public abstract class ImeTracing {
* @param icProto {@link android.view.inputmethod.InputConnection} call data in proto format.
*/
public abstract void triggerClientDump(String where, InputMethodManager immInstance,
ProtoOutputStream icProto);
@Nullable byte[] icProto);
/**
* Starts a proto dump of the currently connected InputMethodService information.
@@ -114,7 +114,7 @@ public abstract class ImeTracing {
* @param icProto {@link android.view.inputmethod.InputConnection} call data in proto format.
*/
public abstract void triggerServiceDump(String where, AbstractInputMethodService service,
ProtoOutputStream icProto);
@Nullable byte[] icProto);
/**
* Starts a proto dump of the InputMethodManagerService information.

View File

@@ -17,6 +17,7 @@
package com.android.internal.inputmethod;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.inputmethodservice.AbstractInputMethodService;
import android.os.RemoteException;
import android.os.ServiceManager.ServiceNotFoundException;
@@ -40,7 +41,7 @@ class ImeTracingClientImpl extends ImeTracing {
@Override
public void triggerClientDump(String where, @NonNull InputMethodManager immInstance,
ProtoOutputStream icProto) {
@Nullable byte[] icProto) {
if (!isEnabled() || !isAvailable()) {
return;
}
@@ -65,7 +66,7 @@ class ImeTracingClientImpl extends ImeTracing {
@Override
public void triggerServiceDump(String where, @NonNull AbstractInputMethodService service,
ProtoOutputStream icProto) {
@Nullable byte[] icProto) {
if (!isEnabled() || !isAvailable()) {
return;
}

View File

@@ -107,13 +107,13 @@ class ImeTracingServerImpl extends ImeTracing {
@Override
public void triggerClientDump(String where, InputMethodManager immInstance,
ProtoOutputStream icProto) {
@Nullable byte[] icProto) {
// Intentionally left empty, this is implemented in ImeTracingClientImpl
}
@Override
public void triggerServiceDump(String where, AbstractInputMethodService service,
ProtoOutputStream icProto) {
@Nullable byte[] icProto) {
// Intentionally left empty, this is implemented in ImeTracingClientImpl
}

View File

@@ -58,10 +58,11 @@ public final class InputConnectionProtoDumper {
* {@link android.view.inputmethod.InputConnection#GET_TEXT_WITH_STYLES}.
* @param result The text after the cursor position; the length of the
* returned text might be less than <var>length</var>.
* @return ProtoOutputStream holding the InputConnectionCallProto data.
* @return Byte-array holding the InputConnectionCallProto data.
*/
public static ProtoOutputStream buildGetTextAfterCursorProto(@IntRange(from = 0) int length,
int flags, @Nullable CharSequence result) {
@NonNull
public static byte[] buildGetTextAfterCursorProto(@IntRange(from = 0) int length, int flags,
@Nullable CharSequence result) {
ProtoOutputStream proto = new ProtoOutputStream();
final long token = proto.start(GET_TEXT_AFTER_CURSOR);
proto.write(GetTextAfterCursor.LENGTH, length);
@@ -72,7 +73,7 @@ public final class InputConnectionProtoDumper {
proto.write(GetTextAfterCursor.RESULT, result.toString());
}
proto.end(token);
return proto;
return proto.getBytes();
}
/**
@@ -85,9 +86,10 @@ public final class InputConnectionProtoDumper {
* {@link android.view.inputmethod.InputConnection#GET_TEXT_WITH_STYLES}.
* @param result The text before the cursor position; the length of the
* returned text might be less than <var>length</var>.
* @return ProtoOutputStream holding the InputConnectionCallProto data.
* @return Byte-array holding the InputConnectionCallProto data.
*/
public static ProtoOutputStream buildGetTextBeforeCursorProto(@IntRange(from = 0) int length,
@NonNull
public static byte[] buildGetTextBeforeCursorProto(@IntRange(from = 0) int length,
int flags, @Nullable CharSequence result) {
ProtoOutputStream proto = new ProtoOutputStream();
final long token = proto.start(GET_TEXT_BEFORE_CURSOR);
@@ -99,7 +101,7 @@ public final class InputConnectionProtoDumper {
proto.write(GetTextBeforeCursor.RESULT, result.toString());
}
proto.end(token);
return proto;
return proto.getBytes();
}
/**
@@ -113,10 +115,10 @@ public final class InputConnectionProtoDumper {
* no text is selected. In {@link android.os.Build.VERSION_CODES#N} and
* later, returns false when the target application does not implement
* this method.
* @return ProtoOutputStream holding the InputConnectionCallProto data.
* @return Byte-array holding the InputConnectionCallProto data.
*/
public static ProtoOutputStream buildGetSelectedTextProto(int flags,
@Nullable CharSequence result) {
@NonNull
public static byte[] buildGetSelectedTextProto(int flags, @Nullable CharSequence result) {
ProtoOutputStream proto = new ProtoOutputStream();
final long token = proto.start(GET_SELECTED_TEXT);
proto.write(GetSelectedText.FLAGS, flags);
@@ -126,7 +128,7 @@ public final class InputConnectionProtoDumper {
proto.write(GetSelectedText.RESULT, result.toString());
}
proto.end(token);
return proto;
return proto.getBytes();
}
/**
@@ -143,11 +145,11 @@ public final class InputConnectionProtoDumper {
* or the editor can't comply with the request for some reason, or the application does not
* implement this method. The length of the returned text might be less than the sum of
* <var>beforeLength</var> and <var>afterLength</var> .
* @return ProtoOutputStream holding the InputConnectionCallProto data.
* @return Byte-array holding the InputConnectionCallProto data.
*/
public static ProtoOutputStream buildGetSurroundingTextProto(@IntRange(from = 0)
int beforeLength, @IntRange(from = 0) int afterLength, int flags,
@Nullable SurroundingText result) {
@NonNull
public static byte[] buildGetSurroundingTextProto(@IntRange(from = 0) int beforeLength,
@IntRange(from = 0) int afterLength, int flags, @Nullable SurroundingText result) {
ProtoOutputStream proto = new ProtoOutputStream();
final long token = proto.start(GET_SURROUNDING_TEXT);
proto.write(GetSurroundingText.BEFORE_LENGTH, beforeLength);
@@ -168,7 +170,7 @@ public final class InputConnectionProtoDumper {
proto.end(token_result);
}
proto.end(token);
return proto;
return proto.getBytes();
}
/**
@@ -179,9 +181,10 @@ public final class InputConnectionProtoDumper {
* {@link android.text.TextUtils#getCapsMode TextUtils.getCapsMode}.
* @param result the caps mode flags that are in effect at the current
* cursor position. See TYPE_TEXT_FLAG_CAPS_* in {@link android.text.InputType}.
* @return ProtoOutputStream holding the InputConnectionCallProto data.
* @return Byte-array holding the InputConnectionCallProto data.
*/
public static ProtoOutputStream buildGetCursorCapsModeProto(int reqModes, int result) {
@NonNull
public static byte[] buildGetCursorCapsModeProto(int reqModes, int result) {
ProtoOutputStream proto = new ProtoOutputStream();
final long token = proto.start(GET_CURSOR_CAPS_MODE);
proto.write(GetCursorCapsMode.REQ_MODES, reqModes);
@@ -189,7 +192,7 @@ public final class InputConnectionProtoDumper {
proto.write(GetCursorCapsMode.RESULT, result);
}
proto.end(token);
return proto;
return proto.getBytes();
}
/**
@@ -206,9 +209,10 @@ public final class InputConnectionProtoDumper {
* extracted text itself, or null if the input connection is no
* longer valid of the editor can't comply with the request for
* some reason.
* @return ProtoOutputStream holding the InputConnectionCallProto data.
* @return Byte-array holding the InputConnectionCallProto data.
*/
public static ProtoOutputStream buildGetExtractedTextProto(@NonNull ExtractedTextRequest
@NonNull
public static byte[] buildGetExtractedTextProto(@NonNull ExtractedTextRequest
request, int flags, @Nullable ExtractedText result) {
ProtoOutputStream proto = new ProtoOutputStream();
final long token = proto.start(GET_EXTRACTED_TEXT);
@@ -225,6 +229,6 @@ public final class InputConnectionProtoDumper {
proto.write(GetExtractedText.RESULT, result.text.toString());
}
proto.end(token);
return proto;
return proto.getBytes();
}
}

View File

@@ -350,7 +350,7 @@ public final class IInputConnectionWrapper extends IInputContext.Stub {
}
void executeMessage(Message msg) {
ProtoOutputStream icProto;
byte[] icProto;
switch (msg.what) {
case DO_GET_TEXT_AFTER_CURSOR: {
Trace.traceBegin(Trace.TRACE_TAG_INPUT, "InputConnection#getTextAfterCursor");