Deprecate mRequestUpdateCursorAnchorInfoMonitorMode part 2
This is the second step towards deprecating
InputMethodManager#mRequestUpdateCursorAnchorInfoMonitorMode,
which was introduced as a minimum implementation to support
CursorAnchorInfo API in EditText [1]
Before this CL, there is a behavior discrepancy in
InputMethodManager#updateCursorAnchorInfo()
handler because mRequestUpdateCursorAnchorInfoMonitorMode has a valid
value when and only when the editor component is EditText.
With this CL, the same behavior will be applied to non-View based
editors.
[1]: I3c6b69bd9d79b199afe68d838f25effa6048e5cc
cf8421df856a5950729ff1d0e73f21d480aa98fb
Bug: 236713697
Test: atest CtsInputMethodTestCases:InputMethodServiceTest#testOnUpdateCursorAnchorInfo
Change-Id: Ib17a05e11b7948c9e468e4efd0497dc1ed2f3559
This commit is contained in:
@@ -2827,8 +2827,8 @@ public final class InputMethodManager {
|
||||
}
|
||||
// If immediate bit is set, we will call updateCursorAnchorInfo() even when the data has
|
||||
// not been changed from the previous call.
|
||||
final boolean isImmediate = (mRequestUpdateCursorAnchorInfoMonitorMode &
|
||||
CURSOR_UPDATE_IMMEDIATE) != 0;
|
||||
final boolean isImmediate = mServedInputConnection != null
|
||||
&& mServedInputConnection.resetHasPendingImmediateCursorAnchorInfoUpdate();
|
||||
if (!isImmediate && Objects.equals(mCursorAnchorInfo, cursorAnchorInfo)) {
|
||||
// TODO: Consider always emitting this message once we have addressed redundant
|
||||
// calls of this method from android.widget.Editor.
|
||||
@@ -2847,8 +2847,6 @@ public final class InputMethodManager {
|
||||
mCurrentInputMethodSession.updateCursorAnchorInfo(cursorAnchorInfo);
|
||||
}
|
||||
mCursorAnchorInfo = cursorAnchorInfo;
|
||||
// Clear immediate bit (if any).
|
||||
mRequestUpdateCursorAnchorInfoMonitorMode &= ~CURSOR_UPDATE_IMMEDIATE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -177,6 +177,8 @@ public final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub
|
||||
private final AtomicBoolean mHasPendingInvalidation = new AtomicBoolean();
|
||||
|
||||
private final AtomicBoolean mIsCursorAnchorInfoMonitoring = new AtomicBoolean(false);
|
||||
private final AtomicBoolean mHasPendingImmediateCursorAnchorInfoUpdate =
|
||||
new AtomicBoolean(false);
|
||||
|
||||
public RemoteInputConnectionImpl(@NonNull Looper looper,
|
||||
@NonNull InputConnection inputConnection,
|
||||
@@ -224,6 +226,23 @@ public final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub
|
||||
return mServedView.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets and resets {@link #mHasPendingImmediateCursorAnchorInfoUpdate}.
|
||||
*
|
||||
* <p>Calling this method resets {@link #mHasPendingImmediateCursorAnchorInfoUpdate}. This
|
||||
* means that the second call of this method returns {@code false} unless the IME requests
|
||||
* {@link android.view.inputmethod.CursorAnchorInfo} again with
|
||||
* {@link InputConnection#CURSOR_UPDATE_IMMEDIATE} flag.</p>
|
||||
*
|
||||
* @return {@code true} if there is any pending request for
|
||||
* {@link android.view.inputmethod.CursorAnchorInfo} with
|
||||
* {@link InputConnection#CURSOR_UPDATE_IMMEDIATE} flag.
|
||||
*/
|
||||
@AnyThread
|
||||
public boolean resetHasPendingImmediateCursorAnchorInfoUpdate() {
|
||||
return mHasPendingImmediateCursorAnchorInfoUpdate.getAndSet(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if there is any active request for
|
||||
* {@link android.view.inputmethod.CursorAnchorInfo} with
|
||||
@@ -1010,6 +1029,8 @@ public final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub
|
||||
// requestCursorUpdates() is not currently supported across displays.
|
||||
return false;
|
||||
}
|
||||
final boolean hasImmediate =
|
||||
(cursorUpdateMode & InputConnection.CURSOR_UPDATE_IMMEDIATE) != 0;
|
||||
final boolean hasMonitoring =
|
||||
(cursorUpdateMode & InputConnection.CURSOR_UPDATE_MONITOR) != 0;
|
||||
boolean result = false;
|
||||
@@ -1020,6 +1041,7 @@ public final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub
|
||||
// TODO(b/199934664): See if we can remove this by providing a default impl.
|
||||
return false;
|
||||
} finally {
|
||||
mHasPendingImmediateCursorAnchorInfoUpdate.set(result && hasImmediate);
|
||||
mIsCursorAnchorInfoMonitoring.set(result && hasMonitoring);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user