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

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

Merge "Adaptive scribe bounds: Adjust touchable region 3/n" into main

parents 1da37826 8567ee7f
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -260,6 +260,15 @@ public final class InputWindowHandle {
        touchableRegionSurfaceControl = new WeakReference<>(bounds);
    }

    /**
     * Resize the window touchable region.
     * @param rect new touchable region rectangle.
     */
    public void setTouchableRegion(Rect rect) {
        touchableRegion.set(rect);
    }


    public void setWindowToken(IBinder iwindow) {
        windowToken = iwindow;
    }
+38 −5
Original line number Diff line number Diff line
@@ -19,13 +19,19 @@ package com.android.server.inputmethod;
import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS;

import android.annotation.NonNull;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.Region;
import android.os.InputConfig;
import android.os.Process;
import android.util.Slog;
import android.view.InputApplicationHandle;
import android.view.InputChannel;
import android.view.InputWindowHandle;
import android.view.SurfaceControl;
import android.view.WindowManager;
import android.view.WindowMetrics;
import android.view.inputmethod.Flags;

import com.android.server.input.InputManagerService;

@@ -39,8 +45,8 @@ final class HandwritingEventReceiverSurface {
    private final SurfaceControl mInputSurface;
    private boolean mIsIntercepting;

    HandwritingEventReceiverSurface(String name, int displayId, @NonNull SurfaceControl sc,
            @NonNull InputChannel inputChannel) {
    HandwritingEventReceiverSurface(Context context, String name, int displayId,
            @NonNull SurfaceControl sc, @NonNull InputChannel inputChannel) {
        mClientChannel = inputChannel;
        mInputSurface = sc;

@@ -59,15 +65,31 @@ final class HandwritingEventReceiverSurface {
                        | InputConfig.SPY
                        | InputConfig.INTERCEPTS_STYLUS;

        Rect bounds = null;
        if (Flags.adaptiveHandwritingBounds()) {
            mWindowHandle.setTouchableRegionCrop(mInputSurface);
            // Default touchable area to getMaximumWindowMetrics()
            WindowMetrics windowMetrics =  context.getSystemService(WindowManager.class)
                    .getMaximumWindowMetrics();
            bounds = windowMetrics.getBounds();
            if (DEBUG) Slog.d(TAG, "initial handwriting touchable bounds: " + bounds);
            mWindowHandle.setTouchableRegion(windowMetrics.getBounds());
        } else {
            // Configure the surface to receive stylus events across the entire display.
            mWindowHandle.replaceTouchableRegionWithCrop(null /* use this surface's bounds */);
        }

        final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
        mWindowHandle.setTrustedOverlay(t, mInputSurface, true);
        t.setInputWindowInfo(mInputSurface, mWindowHandle);
        t.setLayer(mInputSurface, InputManagerService.INPUT_OVERLAY_LAYER_HANDWRITING_SURFACE);
        t.setPosition(mInputSurface, 0, 0);
        if (Flags.adaptiveHandwritingBounds()) {
            // crop to parent surface if null, else bounds.
            t.setCrop(mInputSurface, bounds);
        } else {
            t.setCrop(mInputSurface, null /* crop to parent surface */);
        }
        t.show(mInputSurface);
        t.apply();

@@ -79,12 +101,23 @@ final class HandwritingEventReceiverSurface {
        mWindowHandle.ownerUid = imeUid;
        mWindowHandle.inputConfig &= ~InputConfig.SPY;

        if (Flags.adaptiveHandwritingBounds()) {
            // watch outside touch to finish handwriting.
            mWindowHandle.inputConfig |= InputConfig.WATCH_OUTSIDE_TOUCH;
        }
        new SurfaceControl.Transaction()
                .setInputWindowInfo(mInputSurface, mWindowHandle)
                .apply();
        mIsIntercepting = true;
    }

    void setTouchableRegion(Region touchableRegion) {
        mWindowHandle.touchableRegion.set(touchableRegion);
        new SurfaceControl.Transaction()
                .setInputWindowInfo(mInputSurface, mWindowHandle)
                .apply();
    }

    void setNotTouchable(boolean notTouchable) {
        if (notTouchable) {
            mWindowHandle.inputConfig |= InputConfig.NOT_TOUCHABLE;
+9 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.annotation.UiThread;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManagerInternal;
import android.graphics.Region;
import android.hardware.input.InputManager;
import android.hardware.input.InputManagerGlobal;
import android.os.Handler;
@@ -139,7 +140,7 @@ final class HandwritingModeController {
        }

        mHandwritingSurface = new HandwritingEventReceiverSurface(
                name, displayId, surface, channel);
                mContext, name, displayId, surface, channel);

        // Use a dup of the input channel so that event processing can be paused by disposing the
        // event receiver without causing a fd hangup.
@@ -163,6 +164,13 @@ final class HandwritingModeController {
        mHandwritingSurface.setNotTouchable(notTouchable);
    }

    void setHandwritingTouchableRegion(Region region) {
        if (!getCurrentRequestId().isPresent()) {
            return;
        }
        mHandwritingSurface.setTouchableRegion(region);
    }

    boolean isStylusGestureOngoing() {
        if (mRecordingGestureAfterStylusUp && !mHandwritingBuffer.isEmpty()) {
            // If it is less than AFTER_STYLUS_UP_ALLOW_PERIOD_MS after the stylus up event, return