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

Commit 9b3bdb26 authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Android (Google) Code Review
Browse files

Merge changes from topic "rm-pointer-tracking-wm" into main

* changes:
  Remove Pointer Tracking in WM: Disable TaskTapPointerEventListener
  Pointer Icon Refactor: Disable mouse position tracking in WM
  Pointer Icon Refactor: Simplify tracking resolved pointer icon
  Pointer Icon Refactor: Use new setPointerIcon API for stylus handwriting
  Pointer Icon Refactor: Allow presentation mode to be set without display
parents 16bd911a 7d1daa11
Loading
Loading
Loading
Loading
+32 −22
Original line number Diff line number Diff line
@@ -826,10 +826,18 @@ public final class ViewRootImpl implements ViewParent,
     * The resolved pointer icon type requested by this window.
     * A null value indicates the resolved pointer icon has not yet been calculated.
     */
    // TODO(b/293587049): Remove pointer icon tracking by type when refactor is complete.
    @Nullable
    private Integer mPointerIconType = null;
    private PointerIcon mCustomPointerIcon = null;

    /**
     * The resolved pointer icon requested by this window.
     * A null value indicates the resolved pointer icon has not yet been calculated.
     */
    @Nullable
    private PointerIcon mResolvedPointerIcon = null;

    /**
     * see {@link #playSoundEffect(int)}
     */
@@ -7410,12 +7418,14 @@ public final class ViewRootImpl implements ViewParent,
                // Other apps or the window manager may change the icon type outside of
                // this app, therefore the icon type has to be reset on enter/exit event.
                mPointerIconType = null;
                mResolvedPointerIcon = null;
            }

            if (action != MotionEvent.ACTION_HOVER_EXIT) {
                // Resolve the pointer icon
                if (!updatePointerIcon(event) && action == MotionEvent.ACTION_HOVER_MOVE) {
                    mPointerIconType = null;
                    mResolvedPointerIcon = null;
                }
            }

@@ -7470,6 +7480,7 @@ public final class ViewRootImpl implements ViewParent,

    private void resetPointerIcon(MotionEvent event) {
        mPointerIconType = null;
        mResolvedPointerIcon = null;
        updatePointerIcon(event);
    }

@@ -7507,6 +7518,21 @@ public final class ViewRootImpl implements ViewParent,
            pointerIcon = mView.onResolvePointerIcon(event, pointerIndex);
        }

        if (enablePointerChoreographer()) {
            if (pointerIcon == null) {
                pointerIcon = PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_NOT_SPECIFIED);
            }
            if (Objects.equals(mResolvedPointerIcon, pointerIcon)) {
                return true;
            }
            mResolvedPointerIcon = pointerIcon;

            InputManagerGlobal.getInstance()
                    .setPointerIcon(pointerIcon, event.getDisplayId(),
                            event.getDeviceId(), event.getPointerId(0), getInputToken());
            return true;
        }

        final int pointerType = (pointerIcon != null) ?
                pointerIcon.getType() : PointerIcon.TYPE_NOT_SPECIFIED;

@@ -7514,35 +7540,19 @@ public final class ViewRootImpl implements ViewParent,
            mPointerIconType = pointerType;
            mCustomPointerIcon = null;
            if (mPointerIconType != PointerIcon.TYPE_CUSTOM) {
                if (enablePointerChoreographer()) {
                    InputManagerGlobal
                            .getInstance()
                            .setPointerIcon(PointerIcon.getSystemIcon(mContext, pointerType),
                                    event.getDisplayId(), event.getDeviceId(),
                                    event.getPointerId(pointerIndex), getInputToken());
                } else {
                InputManagerGlobal
                        .getInstance()
                        .setPointerIconType(pointerType);
                }
                return true;
            }
        }
        if (mPointerIconType == PointerIcon.TYPE_CUSTOM &&
                !pointerIcon.equals(mCustomPointerIcon)) {
            mCustomPointerIcon = pointerIcon;
            if (enablePointerChoreographer()) {
                InputManagerGlobal
                        .getInstance()
                        .setPointerIcon(mCustomPointerIcon,
                                event.getDisplayId(), event.getDeviceId(),
                                event.getPointerId(pointerIndex), getInputToken());
            } else {
            InputManagerGlobal
                    .getInstance()
                    .setCustomPointerIcon(mCustomPointerIcon);
        }
        }
        return true;
    }

+9 −0
Original line number Diff line number Diff line
@@ -218,6 +218,15 @@ void PointerController::setPresentation(Presentation presentation) {

    mLocked.presentation = presentation;

    if (input_flags::enable_pointer_choreographer()) {
        // When pointer choreographer is enabled, the presentation mode is only set once when the
        // PointerController is constructed, before the display viewport is provided.
        // TODO(b/293587049): Clean up the PointerController interface after pointer choreographer
        // is permanently enabled. The presentation can be set in the constructor.
        mCursorController.setStylusHoverMode(presentation == Presentation::STYLUS_HOVER);
        return;
    }

    if (!mCursorController.isViewportValid()) {
        return;
    }
+14 −2
Original line number Diff line number Diff line
@@ -23,7 +23,9 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.UiThread;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManagerInternal;
import android.hardware.input.InputManager;
import android.hardware.input.InputManagerGlobal;
import android.os.Handler;
import android.os.IBinder;
@@ -64,6 +66,7 @@ final class HandwritingModeController {
    private static final int LONG_EVENT_BUFFER_SIZE = EVENT_BUFFER_SIZE * 20;
    private static final long HANDWRITING_DELEGATION_IDLE_TIMEOUT_MS = 3000;

    private final Context mContext;
    // This must be the looper for the UiThread.
    private final Looper mLooper;
    private final InputManagerInternal mInputManagerInternal;
@@ -87,7 +90,9 @@ final class HandwritingModeController {
    private int mCurrentRequestId;

    @AnyThread
    HandwritingModeController(Looper uiThreadLooper, Runnable inkWindowInitRunnable) {
    HandwritingModeController(Context context, Looper uiThreadLooper,
            Runnable inkWindowInitRunnable) {
        mContext = context;
        mLooper = uiThreadLooper;
        mCurrentDisplayId = Display.INVALID_DISPLAY;
        mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
@@ -285,7 +290,14 @@ final class HandwritingModeController {
        mHandwritingSurface.startIntercepting(imePid, imeUid);

        // Unset the pointer icon for the stylus in case the app had set it.
        if (com.android.input.flags.Flags.enablePointerChoreographer()) {
            Objects.requireNonNull(mContext.getSystemService(InputManager.class)).setPointerIcon(
                    PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_NOT_SPECIFIED),
                    downEvent.getDisplayId(), downEvent.getDeviceId(), downEvent.getPointerId(0),
                    mHandwritingSurface.getInputChannel().getToken());
        } else {
            InputManagerGlobal.getInstance().setPointerIconType(PointerIcon.TYPE_NOT_SPECIFIED);
        }

        return new HandwritingSession(mCurrentRequestId, mHandwritingSurface.getInputChannel(),
                mHandwritingBuffer);
+1 −1
Original line number Diff line number Diff line
@@ -1713,7 +1713,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                com.android.internal.R.bool.config_preventImeStartupUnlessTextEditor);
        mNonPreemptibleInputMethods = mRes.getStringArray(
                com.android.internal.R.array.config_nonPreemptibleInputMethods);
        mHwController = new HandwritingModeController(thread.getLooper(),
        mHwController = new HandwritingModeController(mContext, thread.getLooper(),
                new InkWindowInitializer());
        registerDeviceListenerAndCheckStylusSupport();
    }
+25 −6
Original line number Diff line number Diff line
@@ -546,10 +546,12 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
    boolean isDefaultDisplay;

    /** Detect user tapping outside of current focused task bounds .*/
    // TODO(b/315321016): Remove once pointer event detection is removed from WM.
    @VisibleForTesting
    final TaskTapPointerEventListener mTapDetector;

    /** Detect user tapping outside of current focused root task bounds .*/
    // TODO(b/315321016): Remove once pointer event detection is removed from WM.
    private Region mTouchExcludeRegion = new Region();

    /** Save allocating when calculating rects */
@@ -1194,12 +1196,18 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                "PointerEventDispatcher" + mDisplayId, mDisplayId);
        mPointerEventDispatcher = new PointerEventDispatcher(inputChannel);

        if (com.android.input.flags.Flags.removePointerEventTrackingInWm()) {
            mTapDetector = null;
        } else {
            // Tap Listeners are supported for:
            // 1. All physical displays (multi-display).
            // 2. VirtualDisplays on VR, AA (and everything else).
            mTapDetector = new TaskTapPointerEventListener(mWmService, this);
            registerPointerEventListener(mTapDetector);
        }
        if (mWmService.mMousePositionTracker != null) {
            registerPointerEventListener(mWmService.mMousePositionTracker);
        }
        if (mWmService.mAtmService.getRecentTasks() != null) {
            registerPointerEventListener(
                    mWmService.mAtmService.getRecentTasks().getInputListener());
@@ -3265,6 +3273,12 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
    }

    void updateTouchExcludeRegion() {
        if (mTapDetector == null) {
            // The touch exclude region is used to detect the region outside of the focused task
            // so that the tap detector can detect outside touches. Don't calculate the exclude
            // region when the tap detector is disabled.
            return;
        }
        final Task focusedTask = (mFocusedApp != null ? mFocusedApp.getTask() : null);
        if (focusedTask == null) {
            mTouchExcludeRegion.setEmpty();
@@ -3303,6 +3317,11 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
    }

    private void processTaskForTouchExcludeRegion(Task task, Task focusedTask, int delta) {
        if (mTapDetector == null) {
            // The touch exclude region is used to detect the region outside of the focused task
            // so that the tap detector can detect outside touches. Don't calculate the exclude
            // region when the tap detector is disabled.
        }
        final ActivityRecord topVisibleActivity = task.getTopVisibleActivity();

        if (topVisibleActivity == null || !topVisibleActivity.hasContentToDisplay()) {
Loading