summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/inputmethod/HandwritingModeController.java13
-rw-r--r--services/core/java/com/android/server/inputmethod/InputMethodManagerService.java39
2 files changed, 34 insertions, 18 deletions
diff --git a/services/core/java/com/android/server/inputmethod/HandwritingModeController.java b/services/core/java/com/android/server/inputmethod/HandwritingModeController.java
index 79f1a9c90f53..c19cb030ef37 100644
--- a/services/core/java/com/android/server/inputmethod/HandwritingModeController.java
+++ b/services/core/java/com/android/server/inputmethod/HandwritingModeController.java
@@ -55,7 +55,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.OptionalInt;
-import java.util.function.IntConsumer;
// TODO(b/210039666): See if we can make this class thread-safe.
final class HandwritingModeController {
@@ -91,7 +90,6 @@ final class HandwritingModeController {
private boolean mDelegationConnectionlessFlow;
private Runnable mDelegationIdleTimeoutRunnable;
private Handler mDelegationIdleTimeoutHandler;
- private IntConsumer mPointerToolTypeConsumer;
private final Runnable mDiscardDelegationTextRunnable;
private HandwritingEventReceiverSurface mHandwritingSurface;
@@ -99,7 +97,7 @@ final class HandwritingModeController {
@AnyThread
HandwritingModeController(Context context, Looper uiThreadLooper,
- Runnable inkWindowInitRunnable, IntConsumer toolTypeConsumer,
+ Runnable inkWindowInitRunnable,
Runnable discardDelegationTextRunnable) {
mContext = context;
mLooper = uiThreadLooper;
@@ -109,7 +107,6 @@ final class HandwritingModeController {
mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
mCurrentRequestId = 0;
mInkWindowInitRunnable = inkWindowInitRunnable;
- mPointerToolTypeConsumer = toolTypeConsumer;
mDiscardDelegationTextRunnable = discardDelegationTextRunnable;
}
@@ -389,16 +386,10 @@ final class HandwritingModeController {
"Input Event should not be processed when IME has the spy channel.");
}
- if (!(ev instanceof MotionEvent)) {
+ if (!(ev instanceof MotionEvent event)) {
Slog.wtf(TAG, "Received non-motion event in stylus monitor.");
return false;
}
- final MotionEvent event = (MotionEvent) ev;
- if (mPointerToolTypeConsumer != null && event.getAction() == MotionEvent.ACTION_DOWN) {
- int toolType = event.getToolType(event.getActionIndex());
- // notify IME of change in tool type.
- mPointerToolTypeConsumer.accept(toolType);
- }
if (!event.isStylusPointer()) {
return false;
}
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index 7513c40a1f90..5a3055b0e882 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -205,7 +205,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
-import java.util.function.IntConsumer;
import java.util.function.IntFunction;
/**
@@ -1305,12 +1304,9 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
com.android.internal.R.bool.config_preventImeStartupUnlessTextEditor);
mNonPreemptibleInputMethods = mRes.getStringArray(
com.android.internal.R.array.config_nonPreemptibleInputMethods);
- IntConsumer toolTypeConsumer =
- Flags.useHandwritingListenerForTooltype()
- ? toolType -> onUpdateEditorToolType(toolType) : null;
Runnable discardDelegationTextRunnable = () -> discardHandwritingDelegationText();
mHwController = new HandwritingModeController(mContext, thread.getLooper(),
- new InkWindowInitializer(), toolTypeConsumer, discardDelegationTextRunnable);
+ new InkWindowInitializer(), discardDelegationTextRunnable);
registerDeviceListenerAndCheckStylusSupport();
}
}
@@ -3416,8 +3412,10 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
ImeTracker.forLogging().onProgress(statsToken, ImeTracker.PHASE_SERVER_HAS_IME);
mCurStatsToken = null;
- if (lastClickToolType != MotionEvent.TOOL_TYPE_UNKNOWN) {
- curMethod.updateEditorToolType(lastClickToolType);
+ if (Flags.useHandwritingListenerForTooltype()) {
+ maybeReportToolType();
+ } else if (lastClickToolType != MotionEvent.TOOL_TYPE_UNKNOWN) {
+ onUpdateEditorToolType(lastClickToolType);
}
mVisibilityApplier.performShowIme(windowToken, statsToken,
mVisibilityStateComputer.getShowFlagsForInputMethodServiceOnly(),
@@ -3431,6 +3429,29 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
return false;
}
+ @GuardedBy("ImfLock.class")
+ private void maybeReportToolType() {
+ int lastDeviceId = mInputManagerInternal.getLastUsedInputDeviceId();
+ final InputManager im = mContext.getSystemService(InputManager.class);
+ if (im == null) {
+ return;
+ }
+ InputDevice device = im.getInputDevice(lastDeviceId);
+ if (device == null) {
+ return;
+ }
+ int toolType;
+ if (isStylusDevice(device)) {
+ toolType = MotionEvent.TOOL_TYPE_STYLUS;
+ } else if (isFingerDevice(device)) {
+ toolType = MotionEvent.TOOL_TYPE_FINGER;
+ } else {
+ // other toolTypes are irrelevant and reported as unknown.
+ toolType = MotionEvent.TOOL_TYPE_UNKNOWN;
+ }
+ onUpdateEditorToolType(toolType);
+ }
+
@Override
public boolean hideSoftInput(IInputMethodClient client, IBinder windowToken,
@NonNull ImeTracker.Token statsToken, @InputMethodManager.HideFlags int flags,
@@ -4285,6 +4306,10 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
|| inputDevice.supportsSource(InputDevice.SOURCE_BLUETOOTH_STYLUS);
}
+ private static boolean isFingerDevice(InputDevice inputDevice) {
+ return inputDevice.supportsSource(InputDevice.SOURCE_TOUCHSCREEN);
+ }
+
@GuardedBy("ImfLock.class")
private boolean hasSupportedStylusLocked() {
return mStylusIds != null && mStylusIds.size() != 0;