Merge "Consolidate start new input scenerios" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-07-10 18:42:06 +00:00
committed by Android (Google) Code Review
3 changed files with 40 additions and 40 deletions

View File

@@ -125,11 +125,11 @@ public final class ImeFocusController {
final View viewForWindowFocus = focusedView != null ? focusedView : mViewRootImpl.mView; final View viewForWindowFocus = focusedView != null ? focusedView : mViewRootImpl.mView;
onViewFocusChanged(viewForWindowFocus, true); onViewFocusChanged(viewForWindowFocus, true);
// Skip starting input when the next focused view is same as served view and the served // Starting new input when the next focused view is same as served view but the
// input connection still exists. // editor is not aligned with the same editor or editor is inactive.
final boolean nextFocusIsServedView = mServedView != null && mServedView == focusedView; final boolean nextFocusIsServedView = mServedView != null && mServedView == focusedView;
if (nextFocusIsServedView && immDelegate.isAcceptingText()) { if (nextFocusIsServedView && !immDelegate.isSameEditorAndAcceptingText(focusedView)) {
forceFocus = false; forceFocus = true;
} }
immDelegate.startInputAsyncOnWindowFocusGain(viewForWindowFocus, immDelegate.startInputAsyncOnWindowFocusGain(viewForWindowFocus,
@@ -254,7 +254,7 @@ public final class ImeFocusController {
void setCurrentRootView(ViewRootImpl rootView); void setCurrentRootView(ViewRootImpl rootView);
boolean isCurrentRootView(ViewRootImpl rootView); boolean isCurrentRootView(ViewRootImpl rootView);
boolean isRestartOnNextWindowFocus(boolean reset); boolean isRestartOnNextWindowFocus(boolean reset);
boolean isAcceptingText(); boolean isSameEditorAndAcceptingText(View view);
} }
public View getServedView() { public View getServedView() {

View File

@@ -633,20 +633,21 @@ public final class InputMethodManager {
// we'll just do a window focus gain and call it a day. // we'll just do a window focus gain and call it a day.
try { try {
View servedView = controller.getServedView(); View servedView = controller.getServedView();
boolean nextFocusIsServedView = servedView != null && servedView == focusedView; boolean nextFocusSameEditor = servedView != null && servedView == focusedView
&& isSameEditorAndAcceptingText(focusedView);
if (DEBUG) { if (DEBUG) {
Log.v(TAG, "Reporting focus gain, without startInput" Log.v(TAG, "Reporting focus gain, without startInput"
+ ", nextFocusIsServedView=" + nextFocusIsServedView); + ", nextFocusIsServedView=" + nextFocusSameEditor);
} }
final int startInputReason = final int startInputReason =
nextFocusIsServedView ? WINDOW_FOCUS_GAIN_REPORT_WITH_SAME_EDITOR nextFocusSameEditor ? WINDOW_FOCUS_GAIN_REPORT_WITH_SAME_EDITOR
: WINDOW_FOCUS_GAIN_REPORT_WITHOUT_EDITOR; : WINDOW_FOCUS_GAIN_REPORT_WITHOUT_EDITOR;
mService.startInputOrWindowGainedFocus( mService.startInputOrWindowGainedFocus(
startInputReason, mClient, startInputReason, mClient,
focusedView.getWindowToken(), startInputFlags, softInputMode, focusedView.getWindowToken(), startInputFlags, softInputMode,
windowFlags, windowFlags,
nextFocusIsServedView ? mCurrentTextBoxAttribute : null, null,
nextFocusIsServedView ? mServedInputConnectionWrapper : null, null,
0 /* missingMethodFlags */, 0 /* missingMethodFlags */,
mCurRootView.mContext.getApplicationInfo().targetSdkVersion); mCurRootView.mContext.getApplicationInfo().targetSdkVersion);
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -671,10 +672,6 @@ public final class InputMethodManager {
@Override @Override
public void setCurrentRootView(ViewRootImpl rootView) { public void setCurrentRootView(ViewRootImpl rootView) {
synchronized (mH) { synchronized (mH) {
if (mCurRootView != null) {
// Restart the input when the next window focus state of the root view changed.
mRestartOnNextWindowFocus = true;
}
mCurRootView = rootView; mCurRootView = rootView;
} }
} }
@@ -704,14 +701,33 @@ public final class InputMethodManager {
} }
/** /**
* For {@link ImeFocusController} to check if the currently served view is accepting full * For {@link ImeFocusController} to check if the given focused view aligns with the same
* text edits. * editor and the editor is active to accept the text input.
*
* TODO(b/160968797): Remove this method and move mCurrentTextBoxAttritube to
* ImeFocusController.
* In the long-term, we should make mCurrentTextBoxAtrtribue as per-window base instance,
* so that we we can directly check if the current focused view aligned with the same editor
* in the window without using this checking.
*
* Note that this method is only use for fixing start new input may ignored issue
* (e.g. b/160391516), DO NOT leverage this method to do another check.
*/ */
@Override public boolean isSameEditorAndAcceptingText(View view) {
public boolean isAcceptingText() {
synchronized (mH) { synchronized (mH) {
return mServedInputConnectionWrapper != null if (!hasServedByInputMethodLocked(view) || mCurrentTextBoxAttribute == null) {
&& mServedInputConnectionWrapper.getInputConnection() != null; return false;
}
final EditorInfo ic = mCurrentTextBoxAttribute;
// This sameEditor checking is based on using object hash comparison to check if
// some fields of the current EditorInfo (e.g. autoFillId, OpPackageName) the
// hash code is same as the given focused view.
final boolean sameEditor = view.onCheckIsTextEditor() && view.getId() == ic.fieldId
&& view.getAutofillId() == ic.autofillId
&& view.getContext().getOpPackageName() == ic.packageName;
return sameEditor && mServedInputConnectionWrapper != null
&& mServedInputConnectionWrapper.isActive();
} }
} }
} }

View File

@@ -18,8 +18,6 @@ package com.android.server.inputmethod;
import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY; import static android.view.Display.INVALID_DISPLAY;
import static com.android.internal.inputmethod.StartInputReason.WINDOW_FOCUS_GAIN_REPORT_WITH_SAME_EDITOR;
import static java.lang.annotation.RetentionPolicy.SOURCE; import static java.lang.annotation.RetentionPolicy.SOURCE;
import android.Manifest; import android.Manifest;
@@ -719,11 +717,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
*/ */
int mImeWindowVis; int mImeWindowVis;
/**
* Checks if the client needs to start input.
*/
private boolean mCurClientNeedStartInput = false;
private AlertDialog.Builder mDialogBuilder; private AlertDialog.Builder mDialogBuilder;
private AlertDialog mSwitchingDialog; private AlertDialog mSwitchingDialog;
private IBinder mSwitchingDialogToken = new Binder(); private IBinder mSwitchingDialogToken = new Binder();
@@ -3467,20 +3460,14 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
if (mCurFocusedWindow == windowToken) { if (mCurFocusedWindow == windowToken) {
if (DEBUG) { if (DEBUG) {
Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client
+ " attribute=" + attribute + ", token = " + windowToken); + " attribute=" + attribute + ", token = " + windowToken
+ ", startInputReason="
+ InputMethodDebug.startInputReasonToString(startInputReason));
} }
// Needs to start input when the same window focus gain but not with the same editor, if (attribute != null) {
// or when the current client needs to start input (e.g. when focusing the same
// window after device turned screen on).
if (attribute != null && (startInputReason != WINDOW_FOCUS_GAIN_REPORT_WITH_SAME_EDITOR
|| mCurClientNeedStartInput)) {
if (mIsInteractive) {
mCurClientNeedStartInput = false;
}
return startInputUncheckedLocked(cs, inputContext, missingMethods, return startInputUncheckedLocked(cs, inputContext, missingMethods,
attribute, startInputFlags, startInputReason); attribute, startInputFlags, startInputReason);
} }
return new InputBindResult( return new InputBindResult(
InputBindResult.ResultCode.SUCCESS_REPORT_WINDOW_FOCUS_ONLY, InputBindResult.ResultCode.SUCCESS_REPORT_WINDOW_FOCUS_ONLY,
null, null, null, -1, null); null, null, null, -1, null);
@@ -4459,9 +4446,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
private void handleSetInteractive(final boolean interactive) { private void handleSetInteractive(final boolean interactive) {
synchronized (mMethodMap) { synchronized (mMethodMap) {
mIsInteractive = interactive; mIsInteractive = interactive;
if (!interactive) {
mCurClientNeedStartInput = true;
}
updateSystemUiLocked(interactive ? mImeWindowVis : 0, mBackDisposition); updateSystemUiLocked(interactive ? mImeWindowVis : 0, mBackDisposition);
// Inform the current client of the change in active status // Inform the current client of the change in active status