Merge "Deprecate mRequestUpdateCursorAnchorInfoMonitorMode part 2"

This commit is contained in:
TreeHugger Robot
2022-06-22 03:56:27 +00:00
committed by Android (Google) Code Review
2 changed files with 24 additions and 4 deletions

View File

@@ -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;
}
}

View File

@@ -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);
}
}