Merge "Extract out IMM.DelegateImpl#checkFocus()"

This commit is contained in:
TreeHugger Robot
2022-10-18 01:05:11 +00:00
committed by Android (Google) Code Review

View File

@@ -835,39 +835,7 @@ public final class InputMethodManager {
@Override
public boolean checkFocus(boolean forceNewFocus, boolean startInput,
ViewRootImpl viewRootImpl) {
synchronized (mH) {
if (mCurRootView != viewRootImpl) {
return false;
}
if (mServedView == mNextServedView && !forceNewFocus) {
return false;
}
if (DEBUG) {
Log.v(TAG, "checkFocus: view=" + mServedView
+ " next=" + mNextServedView
+ " force=" + forceNewFocus
+ " package="
+ (mServedView != null ? mServedView.getContext().getPackageName()
: "<none>"));
}
// Close the connection when no next served view coming.
if (mNextServedView == null) {
finishInputLocked();
closeCurrentInput();
return false;
}
mServedView = mNextServedView;
if (mServedInputConnection != null) {
mServedInputConnection.finishComposingTextFromImm();
}
}
if (startInput) {
startInputOnWindowFocusGainInternal(StartInputReason.CHECK_FOCUS,
null /* focusedView */,
0 /* startInputFlags */, 0 /* softInputMode */, 0 /* windowFlags */);
}
return true;
return checkFocusInternal(forceNewFocus, startInput, viewRootImpl);
}
@Override
@@ -2371,8 +2339,8 @@ public final class InputMethodManager {
}
/**
* Called when {@link DelegateImpl#checkFocus}, {@link #restartInput(View)},
* {@link #MSG_BIND} or {@link #MSG_UNBIND}.
* Called from {@link #checkFocusInternal(boolean, boolean, ViewRootImpl)},
* {@link #restartInput(View)}, {@link #MSG_BIND} or {@link #MSG_UNBIND}.
* 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.
*/
@@ -2693,6 +2661,43 @@ public final class InputMethodManager {
}
}
private boolean checkFocusInternal(boolean forceNewFocus, boolean startInput,
ViewRootImpl viewRootImpl) {
synchronized (mH) {
if (mCurRootView != viewRootImpl) {
return false;
}
if (mServedView == mNextServedView && !forceNewFocus) {
return false;
}
if (DEBUG) {
Log.v(TAG, "checkFocus: view=" + mServedView
+ " next=" + mNextServedView
+ " force=" + forceNewFocus
+ " package="
+ (mServedView != null ? mServedView.getContext().getPackageName()
: "<none>"));
}
// Close the connection when no next served view coming.
if (mNextServedView == null) {
finishInputLocked();
closeCurrentInput();
return false;
}
mServedView = mNextServedView;
if (mServedInputConnection != null) {
mServedInputConnection.finishComposingTextFromImm();
}
}
if (startInput) {
startInputOnWindowFocusGainInternal(StartInputReason.CHECK_FOCUS,
null /* focusedView */,
0 /* startInputFlags */, 0 /* softInputMode */, 0 /* windowFlags */);
}
return true;
}
@UiThread
private void onViewFocusChangedInternal(@Nullable View view, boolean hasFocus) {
if (view == null || view.isTemporarilyDetached()) {