Move dumpViewInfo from InputMethodManager to InputMethodDebug

This a preperation CL before refactoring ImeFocusController.

To make dumpviewInfo can also be used in other IME related files
like ImeFocusController.

Also, removed unused method InputMethodDebug#objectToString.

This is just a mechanical refactoring and should not have any behavior
change.

Bug: 244504062
Test: build
Change-Id: I9d1a0c2b06e676e40b0e844edb18e8422a67b0ad
This commit is contained in:
Ming-Shin Lu
2022-09-04 00:28:55 +08:00
parent 4ef90db500
commit 9f3c04e5af
3 changed files with 24 additions and 38 deletions

View File

@@ -181,7 +181,8 @@ public final class ImeFocusController {
if (!view.hasImeFocus() || !view.hasWindowFocus()) {
return;
}
if (DEBUG) Log.d(TAG, "onViewFocusChanged, view=" + view + ", mServedView=" + mServedView);
if (DEBUG) Log.d(TAG, "onViewFocusChanged, view=" + InputMethodDebug.dumpViewInfo(view)
+ ", mServedView=" + InputMethodDebug.dumpViewInfo(mServedView));
// We don't need to track the next served view when the view lost focus here because:
// 1) The current view focus may be cleared temporary when in touch mode, closing input

View File

@@ -1733,7 +1733,7 @@ public final class InputMethodManager {
if (getServedViewLocked() != null) {
if (DEBUG) {
Log.v(TAG, "FINISH INPUT: mServedView="
+ dumpViewInfo(getServedViewLocked()));
+ InputMethodDebug.dumpViewInfo(getServedViewLocked()));
}
setServedViewLocked(null);
mCompletions = null;
@@ -2266,7 +2266,7 @@ public final class InputMethodManager {
// Make sure we have a window token for the served view.
if (DEBUG) {
Log.v(TAG, "Starting input: view=" + dumpViewInfo(view) +
Log.v(TAG, "Starting input: view=" + InputMethodDebug.dumpViewInfo(view) +
" reason=" + InputMethodDebug.startInputReasonToString(startInputReason));
}
if (view == null) {
@@ -2337,9 +2337,9 @@ public final class InputMethodManager {
final View servedView = getServedViewLocked();
if (servedView != view || !mServedConnecting) {
// Something else happened, so abort.
if (DEBUG) Log.v(TAG,
"Starting input: finished by someone else. view=" + dumpViewInfo(view)
+ " servedView=" + dumpViewInfo(servedView)
if (DEBUG) Log.v(TAG, "Starting input: finished by someone else."
+ " view=" + InputMethodDebug.dumpViewInfo(view)
+ " servedView=" + InputMethodDebug.dumpViewInfo(servedView)
+ " mServedConnecting=" + mServedConnecting);
if (mServedInputConnection != null && startInputReason == BOUND_TO_IMMS) {
// This is not an error. Once IME binds (MSG_BIND), InputConnection is fully
@@ -2399,8 +2399,8 @@ public final class InputMethodManager {
mServedInputConnection = servedInputConnection;
if (DEBUG) {
Log.v(TAG, "START INPUT: view=" + dumpViewInfo(view) + " ic="
+ ic + " editorInfo=" + editorInfo + " startInputFlags="
Log.v(TAG, "START INPUT: view=" + InputMethodDebug.dumpViewInfo(view)
+ " ic=" + ic + " editorInfo=" + editorInfo + " startInputFlags="
+ InputMethodDebug.startInputFlagsToString(startInputFlags));
}
@@ -3731,23 +3731,6 @@ public final class InputMethodManager {
return mCurBindState != null ? mCurBindState.mBindSequence : -1;
}
private static String dumpViewInfo(@Nullable final View view) {
if (view == null) {
return "null";
}
final StringBuilder sb = new StringBuilder();
sb.append(view);
sb.append(",focus=" + view.hasFocus());
sb.append(",windowFocus=" + view.hasWindowFocus());
sb.append(",autofillUiShowing=" + isAutofillUIShowing(view));
sb.append(",window=" + view.getWindowToken());
sb.append(",displayId=" + view.getContext().getDisplayId());
sb.append(",temporaryDetach=" + view.isTemporarilyDetached());
sb.append(",hasImeFocus=" + view.hasImeFocus());
return sb.toString();
}
/**
* Checks the args to see if a proto-based ime dump was requested and writes the client side
* ime dump to the given {@link FileDescriptor}.

View File

@@ -16,10 +16,11 @@
package com.android.internal.inputmethod;
import android.annotation.AnyThread;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.view.View;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams.SoftInputModeFlags;
import android.view.autofill.AutofillManager;
import android.view.inputmethod.HandwritingGesture;
import java.util.StringJoiner;
@@ -281,20 +282,21 @@ public final class InputMethodDebug {
}
/**
* Return a fixed size string of the object.
* TODO(b/151575861): Take & return with StringBuilder to make more memory efficient.
* Dumps the given {@link View} related to input method focus state for debugging.
*/
@NonNull
@AnyThread
public static String objToString(Object obj) {
if (obj == null) {
public static String dumpViewInfo(@Nullable View view) {
if (view == null) {
return "null";
}
StringBuilder sb = new StringBuilder(64);
sb.setLength(0);
sb.append(obj.getClass().getName());
sb.append("@");
sb.append(Integer.toHexString(obj.hashCode()));
final StringBuilder sb = new StringBuilder();
sb.append(view);
sb.append(",focus=" + view.hasFocus());
sb.append(",windowFocus=" + view.hasWindowFocus());
sb.append(",window=" + view.getWindowToken());
sb.append(",displayId=" + view.getContext().getDisplayId());
sb.append(",temporaryDetach=" + view.isTemporarilyDetached());
sb.append(",hasImeFocus=" + view.hasImeFocus());
return sb.toString();
}
}