summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yohei Yukawa <yukawa@google.com> 2022-10-19 11:34:31 -0700
committer Yohei Yukawa <yukawa@google.com> 2022-10-19 11:34:31 -0700
commit90ce33c31544292275d59368d489d4e73ee2d7c4 (patch)
tree2e8576ce5ebc250d5810ad1cc6bf56778a98d800
parent26b50d8f6f4d1f0f54be8a156a48f9519128d468 (diff)
Introduce StartInputReason.SCHEDULED_CHECK_FOCUS
With this CL, adb shell dumpsys input_method, tells us about whether startInputInner() is triggered by InputMethodManager.DelegateImpl#onScheduledCheckFocus() or InputMethodManager#checkFocus(). Other than that there must be no observable behavior change. Bug: 234882948 Test: presubmit Change-Id: I54ebf1a4e1f749ce265756908ef52fc63f1218e5
-rw-r--r--core/java/android/view/inputmethod/InputMethodManager.java30
-rw-r--r--core/java/com/android/internal/inputmethod/InputMethodDebug.java2
-rw-r--r--core/java/com/android/internal/inputmethod/StartInputReason.java6
3 files changed, 24 insertions, 14 deletions
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index eab3f2de44bf..21b34340a0d1 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -789,7 +789,7 @@ public final class InputMethodManager {
}
}
- if (checkFocusInternal(forceNewFocus, false, viewRootImpl)) {
+ if (checkFocusInternal(forceNewFocus, viewRootImpl)) {
// We need to restart input on the current focus view. This
// should be done in conjunction with telling the system service
// about the window gaining focus, to help make the transition
@@ -826,7 +826,12 @@ public final class InputMethodManager {
@Override
public void onScheduledCheckFocus(@NonNull ViewRootImpl viewRootImpl) {
- checkFocusInternal(false, true, viewRootImpl);
+ if (!checkFocusInternal(false, viewRootImpl)) {
+ return;
+ }
+ startInputOnWindowFocusGainInternal(StartInputReason.SCHEDULED_CHECK_FOCUS,
+ null /* focusedView */, 0 /* startInputFlags */, 0 /* softInputMode */,
+ 0 /* windowFlags */);
}
@Override
@@ -1118,7 +1123,7 @@ public final class InputMethodManager {
if (mCurRootView == null) {
return;
}
- if (!checkFocusInternal(mRestartOnNextWindowFocus, false, mCurRootView)) {
+ if (!checkFocusInternal(mRestartOnNextWindowFocus, mCurRootView)) {
return;
}
final int reason = active ? StartInputReason.ACTIVATED_BY_IMMS
@@ -2338,8 +2343,7 @@ public final class InputMethodManager {
}
/**
- * Called from {@link #checkFocusInternal(boolean, boolean, ViewRootImpl)},
- * {@link #restartInput(View)}, {@link #MSG_BIND} or {@link #MSG_UNBIND}.
+ * Starts an input connection from the served view that gains the window focus.
* Note that this method should *NOT* be called inside of {@code mH} lock to prevent start input
* background thread may blocked by other methods which already inside {@code mH} lock.
*/
@@ -2660,14 +2664,18 @@ public final class InputMethodManager {
}
viewRootImpl = mCurRootView;
}
- checkFocusInternal(false /* forceNewFocus */, true /* startInput */, viewRootImpl);
+ if (!checkFocusInternal(false /* forceNewFocus */, viewRootImpl)) {
+ return;
+ }
+ startInputOnWindowFocusGainInternal(StartInputReason.CHECK_FOCUS,
+ null /* focusedView */,
+ 0 /* startInputFlags */, 0 /* softInputMode */, 0 /* windowFlags */);
}
/**
* Check the next served view if needs to start input.
*/
- private boolean checkFocusInternal(boolean forceNewFocus, boolean startInput,
- ViewRootImpl viewRootImpl) {
+ private boolean checkFocusInternal(boolean forceNewFocus, ViewRootImpl viewRootImpl) {
synchronized (mH) {
if (mCurRootView != viewRootImpl) {
return false;
@@ -2694,12 +2702,6 @@ public final class InputMethodManager {
mServedInputConnection.finishComposingTextFromImm();
}
}
-
- if (startInput) {
- startInputOnWindowFocusGainInternal(StartInputReason.CHECK_FOCUS,
- null /* focusedView */,
- 0 /* startInputFlags */, 0 /* softInputMode */, 0 /* windowFlags */);
- }
return true;
}
diff --git a/core/java/com/android/internal/inputmethod/InputMethodDebug.java b/core/java/com/android/internal/inputmethod/InputMethodDebug.java
index 09c97b39e260..1b4afd6dd39f 100644
--- a/core/java/com/android/internal/inputmethod/InputMethodDebug.java
+++ b/core/java/com/android/internal/inputmethod/InputMethodDebug.java
@@ -49,6 +49,8 @@ public final class InputMethodDebug {
return "WINDOW_FOCUS_GAIN";
case StartInputReason.WINDOW_FOCUS_GAIN_REPORT_ONLY:
return "WINDOW_FOCUS_GAIN_REPORT_ONLY";
+ case StartInputReason.SCHEDULED_CHECK_FOCUS:
+ return "SCHEDULED_CHECK_FOCUS";
case StartInputReason.APP_CALLED_RESTART_INPUT_API:
return "APP_CALLED_RESTART_INPUT_API";
case StartInputReason.CHECK_FOCUS:
diff --git a/core/java/com/android/internal/inputmethod/StartInputReason.java b/core/java/com/android/internal/inputmethod/StartInputReason.java
index 51ed841410d7..733d9751c810 100644
--- a/core/java/com/android/internal/inputmethod/StartInputReason.java
+++ b/core/java/com/android/internal/inputmethod/StartInputReason.java
@@ -31,6 +31,7 @@ import java.lang.annotation.Retention;
StartInputReason.UNSPECIFIED,
StartInputReason.WINDOW_FOCUS_GAIN,
StartInputReason.WINDOW_FOCUS_GAIN_REPORT_ONLY,
+ StartInputReason.SCHEDULED_CHECK_FOCUS,
StartInputReason.APP_CALLED_RESTART_INPUT_API,
StartInputReason.CHECK_FOCUS,
StartInputReason.BOUND_TO_IMMS,
@@ -58,6 +59,11 @@ public @interface StartInputReason {
*/
int WINDOW_FOCUS_GAIN_REPORT_ONLY = 2;
/**
+ * Similar to {@link #CHECK_FOCUS}, but the one scheduled with
+ * {@link android.view.ViewRootImpl#dispatchCheckFocus()}.
+ */
+ int SCHEDULED_CHECK_FOCUS = 3;
+ /**
* {@link android.view.inputmethod.InputMethodManager#restartInput(android.view.View)} is
* either explicitly called by the application or indirectly called by some Framework class
* (e.g. {@link android.widget.EditText}).