Merge "Scribe in IMF: Automatically sub to CAI w/ Stylus 4/N"

This commit is contained in:
Taran Singh
2022-01-25 16:01:35 +00:00
committed by Android (Google) Code Review
2 changed files with 51 additions and 19 deletions

View File

@@ -18,6 +18,8 @@ package android.view.inputmethod;
import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
import static android.Manifest.permission.WRITE_SECURE_SETTINGS;
import static android.view.inputmethod.InputConnection.CURSOR_UPDATE_IMMEDIATE;
import static android.view.inputmethod.InputConnection.CURSOR_UPDATE_MONITOR;
import static android.view.inputmethod.InputMethodEditorTraceProto.InputMethodClientsTraceProto.ClientSideProto.DISPLAY_ID;
import static android.view.inputmethod.InputMethodEditorTraceProto.InputMethodClientsTraceProto.ClientSideProto.EDITOR_INFO;
import static android.view.inputmethod.InputMethodEditorTraceProto.InputMethodClientsTraceProto.ClientSideProto.IME_INSETS_SOURCE_CONSUMER;
@@ -1793,6 +1795,14 @@ public final class InputMethodManager {
Log.w(TAG, "Ignoring startStylusHandwriting: View's window does not have focus.");
return;
}
if (mServedInputConnection != null && getDelegate().hasActiveConnection(view)) {
// TODO (b/210039666): optimize CURSOR_UPDATE_IMMEDIATE.
// TODO (b/215533103): Introduce new modes in requestCursorUpdates().
// TODO (b/210039666): Pipe IME displayId from InputBindResult and use it here.
// instead of mDisplayId.
mServedInputConnection.requestCursorUpdatesFromImm(
CURSOR_UPDATE_IMMEDIATE | CURSOR_UPDATE_MONITOR, mDisplayId);
}
try {
mService.startStylusHandwriting(mClient);
@@ -2419,9 +2429,9 @@ public final class InputMethodManager {
public boolean isCursorAnchorInfoEnabled() {
synchronized (mH) {
final boolean isImmediate = (mRequestUpdateCursorAnchorInfoMonitorMode &
InputConnection.CURSOR_UPDATE_IMMEDIATE) != 0;
CURSOR_UPDATE_IMMEDIATE) != 0;
final boolean isMonitoring = (mRequestUpdateCursorAnchorInfoMonitorMode &
InputConnection.CURSOR_UPDATE_MONITOR) != 0;
CURSOR_UPDATE_MONITOR) != 0;
return isImmediate || isMonitoring;
}
}
@@ -2493,7 +2503,7 @@ 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 &
InputConnection.CURSOR_UPDATE_IMMEDIATE) != 0;
CURSOR_UPDATE_IMMEDIATE) != 0;
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.
@@ -2507,7 +2517,7 @@ public final class InputMethodManager {
mCurrentInputMethodSession.updateCursorAnchorInfo(cursorAnchorInfo);
mCursorAnchorInfo = cursorAnchorInfo;
// Clear immediate bit (if any).
mRequestUpdateCursorAnchorInfoMonitorMode &= ~InputConnection.CURSOR_UPDATE_IMMEDIATE;
mRequestUpdateCursorAnchorInfoMonitorMode &= ~CURSOR_UPDATE_IMMEDIATE;
}
}

View File

@@ -932,6 +932,24 @@ public final class RemoteInputConnectionImpl extends IInputContext.Stub {
});
}
/**
* Dispatches {@link InputConnection#requestCursorUpdates(int)}.
*
* <p>This method is intended to be called only from {@link InputMethodManager}.</p>
* @param cursorUpdateMode the mode for {@link InputConnection#requestCursorUpdates(int)}
* @param imeDisplayId displayId on which IME is displayed.
*/
@Dispatching(cancellable = true)
public void requestCursorUpdatesFromImm(int cursorUpdateMode, int imeDisplayId) {
final int currentSessionId = mCurrentSessionId.get();
dispatchWithTracing("requestCursorUpdatesFromImm", () -> {
if (currentSessionId != mCurrentSessionId.get()) {
return; // cancelled
}
requestCursorUpdatesInternal(cursorUpdateMode, imeDisplayId);
});
}
@Dispatching(cancellable = true)
@Override
public void requestCursorUpdates(InputConnectionCommandHeader header, int cursorUpdateMode,
@@ -940,24 +958,28 @@ public final class RemoteInputConnectionImpl extends IInputContext.Stub {
if (header.mSessionId != mCurrentSessionId.get()) {
return false; // cancelled
}
final InputConnection ic = getInputConnection();
if (ic == null || !isActive()) {
Log.w(TAG, "requestCursorAnchorInfo on inactive InputConnection");
return false;
}
if (mParentInputMethodManager.getDisplayId() != imeDisplayId) {
// requestCursorUpdates() is not currently supported across displays.
return false;
}
try {
return ic.requestCursorUpdates(cursorUpdateMode);
} catch (AbstractMethodError ignored) {
// TODO(b/199934664): See if we can remove this by providing a default impl.
return false;
}
return requestCursorUpdatesInternal(cursorUpdateMode, imeDisplayId);
});
}
private boolean requestCursorUpdatesInternal(int cursorUpdateMode, int imeDisplayId) {
final InputConnection ic = getInputConnection();
if (ic == null || !isActive()) {
Log.w(TAG, "requestCursorAnchorInfo on inactive InputConnection");
return false;
}
if (mParentInputMethodManager.getDisplayId() != imeDisplayId) {
// requestCursorUpdates() is not currently supported across displays.
return false;
}
try {
return ic.requestCursorUpdates(cursorUpdateMode);
} catch (AbstractMethodError ignored) {
// TODO(b/199934664): See if we can remove this by providing a default impl.
return false;
}
}
@Dispatching(cancellable = true)
@Override
public void commitContent(InputConnectionCommandHeader header,