Further simplify FINISH_INPUT_NO_FALLBACK_CONNECTION handling
This CL aims to further simplify what MSG_SET_INTERACTIVE handler needs to do, which was introduced in my previous CL [1]. So redispatching the task to the UI thread is necessary when and only when "interactive" parameter is true. If it's false, we can directly invoke DelegateImpl#finishInputAndReportToIme(). [1]: I0c95d7e70357ac98b336cd1b51a7405ba92a9a6f Bug: 234882948 Test: presubmit Change-Id: I19e14526a094900c80d9c3fc00f576e3a50cafb2
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -740,26 +740,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) {
|
||||
@@ -1202,14 +1182,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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user