Merge "Further simplify FINISH_INPUT_NO_FALLBACK_CONNECTION handling"

This commit is contained in:
Yohei Yukawa
2022-10-17 19:01:19 +00:00
committed by Android (Google) Code Review
2 changed files with 21 additions and 38 deletions

View File

@@ -132,22 +132,16 @@ public final class ImeFocusController {
}
/**
* To handle the lifecycle of the input connection when the device interactivity state changed.
* (i.e. Calling IMS#onFinishInput when the device screen-off and Calling IMS#onStartInput
* when the device screen-on again).
* Calling IMS#onStartInput when the device screen-on again).
*/
@UiThread
public void onInteractiveChanged(boolean interactive) {
public void onInteractive() {
final InputMethodManagerDelegate immDelegate = getImmDelegate();
if (!immDelegate.isCurrentRootView(mViewRootImpl)) {
return;
}
if (interactive) {
final View focusedView = mViewRootImpl.mView.findFocus();
onViewFocusChanged(focusedView, focusedView != null);
} else {
mDelegate.finishInputAndReportToIme();
}
final View focusedView = mViewRootImpl.mView.findFocus();
onViewFocusChanged(focusedView, focusedView != null);
}
/**
@@ -186,7 +180,6 @@ public final class ImeFocusController {
void onViewDetachedFromWindow(View view, ViewRootImpl viewRootImpl);
void onWindowDismissed(ViewRootImpl viewRootImpl);
void finishInputAndReportToIme();
boolean isCurrentRootView(ViewRootImpl rootView);
}

View File

@@ -741,26 +741,6 @@ public final class InputMethodManager {
private final class DelegateImpl implements
ImeFocusController.InputMethodManagerDelegate {
/**
* Used by {@link ImeFocusController} to finish input connection and callback
* {@link InputMethodService#onFinishInput()}.
*
* This method is especially for when ImeFocusController received device screen-off event to
* ensure the entire finish input connection and the connection lifecycle callback to
* IME can be done for security concern.
*/
@Override
public void finishInputAndReportToIme() {
synchronized (mH) {
finishInputLocked();
if (isImeSessionAvailableLocked()) {
mCurBindState.mImeSession.finishInput();
}
forAccessibilitySessionsLocked(
IAccessibilityInputMethodSessionInvoker::finishInput);
}
}
@Override
public void onPreWindowGainedFocus(ViewRootImpl viewRootImpl) {
synchronized (mH) {
@@ -1203,14 +1183,24 @@ public final class InputMethodManager {
mActive = interactive;
mFullscreenMode = fullscreen;
// Report active state to ImeFocusController to handle IME input
// connection lifecycle callback when it allowed.
final ImeFocusController controller = getFocusController();
final View rootView = mCurRootView != null ? mCurRootView.getView() : null;
if (controller == null || rootView == null) {
return;
if (interactive) {
// Report active state to ImeFocusController to handle IME input
// connection lifecycle callback when it allowed.
final ImeFocusController controller = getFocusController();
final View rootView =
mCurRootView != null ? mCurRootView.getView() : null;
if (controller == null || rootView == null) {
return;
}
rootView.post(controller::onInteractive);
} else {
finishInputLocked();
if (isImeSessionAvailableLocked()) {
mCurBindState.mImeSession.finishInput();
}
forAccessibilitySessionsLocked(
IAccessibilityInputMethodSessionInvoker::finishInput);
}
rootView.post(() -> controller.onInteractiveChanged(interactive));
}
return;
}