Loading services/core/java/com/android/server/inputmethod/HandwritingModeController.java +2 −11 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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; Loading @@ -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; Loading @@ -109,7 +107,6 @@ final class HandwritingModeController { mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class); mCurrentRequestId = 0; mInkWindowInitRunnable = inkWindowInitRunnable; mPointerToolTypeConsumer = toolTypeConsumer; mDiscardDelegationTextRunnable = discardDelegationTextRunnable; } Loading Loading @@ -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; } Loading services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +32 −7 Original line number Diff line number Diff line Loading @@ -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; /** Loading Loading @@ -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(); } } Loading Loading @@ -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(), Loading @@ -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, Loading Loading @@ -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; Loading Loading
services/core/java/com/android/server/inputmethod/HandwritingModeController.java +2 −11 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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; Loading @@ -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; Loading @@ -109,7 +107,6 @@ final class HandwritingModeController { mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class); mCurrentRequestId = 0; mInkWindowInitRunnable = inkWindowInitRunnable; mPointerToolTypeConsumer = toolTypeConsumer; mDiscardDelegationTextRunnable = discardDelegationTextRunnable; } Loading Loading @@ -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; } Loading
services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +32 −7 Original line number Diff line number Diff line Loading @@ -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; /** Loading Loading @@ -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(); } } Loading Loading @@ -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(), Loading @@ -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, Loading Loading @@ -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; Loading