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

Commit cc016b34 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Scribe in IMF: Stylus Spy windows Impl 5/N"

parents 32a66eac 52f33049
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.graphics.PointF;
import android.hardware.display.DisplayViewport;
import android.os.IBinder;
import android.view.InputChannel;
import android.view.InputEvent;

import java.util.List;
@@ -123,4 +124,13 @@ public abstract class InputManagerInternal {
         */
        void notifyLidSwitchChanged(long whenNanos, boolean lidOpen);
    }

    /** Create an {@link InputChannel} that is registered to InputDispatcher. */
    public abstract InputChannel createInputChannel(String inputChannelName);

    /**
     * Pilfer pointers from the input channel with the given token so that ongoing gestures are
     * canceled for all other channels.
     */
    public abstract void pilferPointers(IBinder token);
}
+4 −3
Original line number Diff line number Diff line
@@ -245,7 +245,7 @@ class IInputMethodWrapper extends IInputMethod.Stub
            }
            case DO_START_STYLUS_HANDWRITING: {
                final SomeArgs args = (SomeArgs) msg.obj;
                inputMethod.startStylusHandwriting((InputChannel) args.arg1,
                inputMethod.startStylusHandwriting(msg.arg1, (InputChannel) args.arg1,
                        (List<MotionEvent>) args.arg2);
                args.recycle();
                return;
@@ -393,10 +393,11 @@ class IInputMethodWrapper extends IInputMethod.Stub

    @BinderThread
    @Override
    public void startStylusHandwriting(@NonNull InputChannel channel,
    public void startStylusHandwriting(int requestId, @NonNull InputChannel channel,
            @Nullable List<MotionEvent> stylusEvents)
            throws RemoteException {
        mCaller.executeOrSendMessage(
                mCaller.obtainMessageOO(DO_START_STYLUS_HANDWRITING, channel, stylusEvents));
                mCaller.obtainMessageIOO(DO_START_STYLUS_HANDWRITING, requestId, channel,
                        stylusEvents));
    }
}
+7 −1
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import com.android.internal.policy.PhoneWindow;
final class InkWindow extends PhoneWindow {

    private final WindowManager mWindowManager;
    private boolean mIsViewAdded;

    public InkWindow(@NonNull Context context) {
        super(context);
@@ -47,6 +48,7 @@ final class InkWindow extends PhoneWindow {
        final LayoutParams attrs = getAttributes();
        attrs.layoutInDisplayCutoutMode = LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
        attrs.setFitInsetsTypes(0);
        // TODO(b/210039666): use INPUT_FEATURE_NO_INPUT_CHANNEL once b/216179339 is fixed.
        setAttributes(attrs);
        // Ink window is not touchable with finger.
        addFlags(FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_NO_LIMITS | FLAG_NOT_TOUCHABLE
@@ -66,7 +68,10 @@ final class InkWindow extends PhoneWindow {
            return;
        }
        getDecorView().setVisibility(View.VISIBLE);
        if (!mIsViewAdded) {
            mWindowManager.addView(getDecorView(), getAttributes());
            mIsViewAdded = true;
        }
    }

    /**
@@ -78,6 +83,7 @@ final class InkWindow extends PhoneWindow {
        if (getDecorView() != null) {
            getDecorView().setVisibility(remove ? View.GONE : View.INVISIBLE);
        }
        //TODO(b/210039666): remove window from WM after a delay. Delay amount TBD.
    }

    void setToken(@NonNull IBinder token) {
+38 −9
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.ResultReceiver;
import android.os.SystemClock;
import android.os.SystemProperties;
@@ -95,8 +96,11 @@ import android.util.Log;
import android.util.PrintWriterPrinter;
import android.util.Printer;
import android.util.proto.ProtoOutputStream;
import android.view.BatchedInputEventReceiver.SimpleBatchedInputEventReceiver;
import android.view.Choreographer;
import android.view.Gravity;
import android.view.InputChannel;
import android.view.InputEventReceiver;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -148,6 +152,7 @@ import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.OptionalInt;

/**
 * InputMethodService provides a standard implementation of an InputMethod,
@@ -567,7 +572,8 @@ public class InputMethodService extends AbstractInputMethodService {

    private boolean mAutomotiveHideNavBarForKeyboard;
    private boolean mIsAutomotive;
    private boolean mHandwritingStarted;
    private @NonNull OptionalInt mHandwritingRequestId = OptionalInt.empty();
    private InputEventReceiver mHandwritingEventReceiver;
    private Handler mHandler;
    private boolean mImeSurfaceScheduledForRemoval;
    private ImsConfigurationTracker mConfigTracker = new ImsConfigurationTracker();
@@ -888,7 +894,7 @@ public class InputMethodService extends AbstractInputMethodService {
        @Override
        public void canStartStylusHandwriting(int requestId) {
            if (DEBUG) Log.v(TAG, "canStartStylusHandwriting()");
            if (mHandwritingStarted) {
            if (mHandwritingRequestId.isPresent()) {
                Log.d(TAG, "There is an ongoing Handwriting session. ignoring.");
                return;
            }
@@ -900,6 +906,7 @@ public class InputMethodService extends AbstractInputMethodService {
                mPrivOps.onStylusHandwritingReady(requestId);
            } else {
                Log.i(TAG, "IME is not ready. Can't start Stylus Handwriting");
                // TODO(b/210039666): see if it's valuable to propagate this back to IMM.
            }
        }

@@ -910,20 +917,36 @@ public class InputMethodService extends AbstractInputMethodService {
        @MainThread
        @Override
        public void startStylusHandwriting(
                @NonNull InputChannel channel, @Nullable List<MotionEvent> stylusEvents) {
                int requestId, @NonNull InputChannel channel,
                @NonNull List<MotionEvent> stylusEvents) {
            if (DEBUG) Log.v(TAG, "startStylusHandwriting()");
            if (mHandwritingStarted) {
            Objects.requireNonNull(channel);
            Objects.requireNonNull(stylusEvents);

            if (mHandwritingRequestId.isPresent()) {
                return;
            }

            mHandwritingStarted = true;
            mHandwritingRequestId = OptionalInt.of(requestId);
            mShowInputRequested = false;

            mInkWindow.show();
            // TODO: deliver previous @param stylusEvents
            // TODO: create spy receiver for @param channel

            // deliver previous @param stylusEvents
            stylusEvents.forEach(mInkWindow.getDecorView()::dispatchTouchEvent);
            // create receiver for channel
            mHandwritingEventReceiver = new SimpleBatchedInputEventReceiver(
                    channel,
                    Looper.getMainLooper(), Choreographer.getInstance(),
                    event -> {
                        if (!(event instanceof MotionEvent)) {
                            return false;
                        }
                        return mInkWindow.getDecorView().dispatchTouchEvent((MotionEvent) event);
                    });
        }


        /**
         * {@inheritDoc}
         */
@@ -2358,12 +2381,18 @@ public class InputMethodService extends AbstractInputMethodService {
        if (mInkWindow == null) {
            return;
        }
        if (!mHandwritingStarted) {
        if (!mHandwritingRequestId.isPresent()) {
            return;
        }

        mHandwritingStarted = false;
        final int requestId = mHandwritingRequestId.getAsInt();
        mHandwritingRequestId = OptionalInt.empty();

        mHandwritingEventReceiver.dispose();
        mHandwritingEventReceiver = null;
        mInkWindow.hide(false /* remove */);

        mPrivOps.finishStylusHandwriting(requestId);
        onFinishStylusHandwriting();
    }

+1 −1
Original line number Diff line number Diff line
@@ -405,7 +405,7 @@ public interface InputMethod {
     * @hide
     */
    default void startStylusHandwriting(
            @NonNull InputChannel channel, @Nullable List<MotionEvent> events) {
            int requestId, @NonNull InputChannel channel, @Nullable List<MotionEvent> events) {
        // intentionally empty
    }

Loading