Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17be664a authored by Taran Singh's avatar Taran Singh Committed by Android (Google) Code Review
Browse files

Merge "More accurate editorTooltype from handwriting receiver" into main

parents 6ed790f2 2d2bbe4c
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -127,6 +127,7 @@ import android.view.inputmethod.CursorAnchorInfo;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.Flags;
import android.view.inputmethod.ImeTracker;
import android.view.inputmethod.InlineSuggestionsRequest;
import android.view.inputmethod.InlineSuggestionsResponse;
@@ -388,6 +389,9 @@ public class InputMethodService extends AbstractInputMethodService {
    private long mStylusHwSessionsTimeout = STYLUS_HANDWRITING_IDLE_TIMEOUT_MS;
    private Runnable mStylusWindowIdleTimeoutRunnable;
    private long mStylusWindowIdleTimeoutForTest;
    /** Tracks last {@link MotionEvent#getToolType(int)} used for {@link MotionEvent#ACTION_DOWN}.
     **/
    private int mLastUsedToolType;

    /**
     * Returns whether {@link InputMethodService} is responsible for rendering the back button and
@@ -1005,7 +1009,7 @@ public class InputMethodService extends AbstractInputMethodService {
         */
        @Override
        public void updateEditorToolType(@ToolType int toolType) {
            onUpdateEditorToolType(toolType);
            updateEditorToolTypeInternal(toolType);
        }

        /**
@@ -1249,6 +1253,14 @@ public class InputMethodService extends AbstractInputMethodService {
        rootView.setSystemGestureExclusionRects(exclusionRects);
    }

    private void updateEditorToolTypeInternal(int toolType) {
        if (Flags.useHandwritingListenerForTooltype()) {
            mLastUsedToolType = toolType;
            mInputEditorInfo.setInitialToolType(toolType);
        }
        onUpdateEditorToolType(toolType);
    }

    /**
     * Concrete implementation of
     * {@link AbstractInputMethodService.AbstractInputMethodSessionImpl} that provides
@@ -3110,6 +3122,9 @@ public class InputMethodService extends AbstractInputMethodService {
                null /* icProto */);
        mInputStarted = true;
        mStartedInputConnection = ic;
        if (Flags.useHandwritingListenerForTooltype()) {
            editorInfo.setInitialToolType(mLastUsedToolType);
        }
        mInputEditorInfo = editorInfo;
        initialize();
        mInlineSuggestionSessionController.notifyOnStartInput(
@@ -3354,6 +3369,10 @@ public class InputMethodService extends AbstractInputMethodService {
     *         had not seen the event at all.
     */
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (Flags.useHandwritingListenerForTooltype()) {
            // any KeyEvent keyDown should reset last toolType.
            updateEditorToolTypeInternal(MotionEvent.TOOL_TYPE_UNKNOWN);
        }
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            final ExtractEditText eet = getExtractEditTextIfVisible();
            if (eet != null && eet.handleBackInTextActionModeIfNeeded(event)) {
+9 −0
Original line number Diff line number Diff line
@@ -38,3 +38,12 @@ flag {
    description: "Feature flag for supporting stylus handwriting delegation from RemoteViews on the home screen"
    bug: "279959705"
}

flag {
    name: "use_handwriting_listener_for_tooltype"
    namespace: "input_method"
    description: "Feature flag for using handwriting spy for determining pointer toolType."
    bug: "309554999"
    is_fixed_read_only: true
}
+9 −2
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ 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 {
@@ -84,14 +85,14 @@ final class HandwritingModeController {
    private boolean mDelegatorFromDefaultHomePackage;
    private Runnable mDelegationIdleTimeoutRunnable;
    private Handler mDelegationIdleTimeoutHandler;

    private IntConsumer mPointerToolTypeConsumer;
    private HandwritingEventReceiverSurface mHandwritingSurface;

    private int mCurrentRequestId;

    @AnyThread
    HandwritingModeController(Context context, Looper uiThreadLooper,
            Runnable inkWindowInitRunnable) {
            Runnable inkWindowInitRunnable, IntConsumer toolTypeConsumer) {
        mContext = context;
        mLooper = uiThreadLooper;
        mCurrentDisplayId = Display.INVALID_DISPLAY;
@@ -100,6 +101,7 @@ final class HandwritingModeController {
        mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
        mCurrentRequestId = 0;
        mInkWindowInitRunnable = inkWindowInitRunnable;
        mPointerToolTypeConsumer = toolTypeConsumer;
    }

    /**
@@ -355,6 +357,11 @@ final class HandwritingModeController {
            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;
        }
+17 −2
Original line number Diff line number Diff line
@@ -124,6 +124,7 @@ import android.view.WindowManager.DisplayImePolicy;
import android.view.WindowManager.LayoutParams;
import android.view.WindowManager.LayoutParams.SoftInputModeFlags;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.Flags;
import android.view.inputmethod.ImeTracker;
import android.view.inputmethod.InputBinding;
import android.view.inputmethod.InputConnection;
@@ -206,6 +207,7 @@ import java.util.WeakHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.IntConsumer;

/**
 * This class provides a system service that manages input methods.
@@ -1713,8 +1715,11 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                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;
        mHwController = new HandwritingModeController(mContext, thread.getLooper(),
                new InkWindowInitializer());
                new InkWindowInitializer(), toolTypeConsumer);
        registerDeviceListenerAndCheckStylusSupport();
    }

@@ -1735,6 +1740,15 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        }
    }

    private void onUpdateEditorToolType(int toolType) {
        synchronized (ImfLock.class) {
            IInputMethodInvoker curMethod = getCurMethodLocked();
            if (curMethod != null) {
                curMethod.updateEditorToolType(toolType);
            }
        }
    }

    @GuardedBy("ImfLock.class")
    private void resetDefaultImeLocked(Context context) {
        // Do not reset the default (current) IME when it is a 3rd-party IME
@@ -3525,7 +3539,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            ImeTracker.forLogging().onProgress(statsToken, ImeTracker.PHASE_SERVER_HAS_IME);
            mCurStatsToken = null;

            if (lastClickToolType != MotionEvent.TOOL_TYPE_UNKNOWN) {
            if (!Flags.useHandwritingListenerForTooltype()
                    && lastClickToolType != MotionEvent.TOOL_TYPE_UNKNOWN) {
                curMethod.updateEditorToolType(lastClickToolType);
            }
            mVisibilityApplier.performShowIme(windowToken, statsToken,