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

Commit b0f1fe88 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou Committed by Android (Google) Code Review
Browse files

Merge "New VerifiedInputEvent api"

parents f0ac5e88 cf07528a
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -18115,6 +18115,7 @@ package android.hardware.input {
    method public int[] getInputDeviceIds();
    method public void registerInputDeviceListener(android.hardware.input.InputManager.InputDeviceListener, android.os.Handler);
    method public void unregisterInputDeviceListener(android.hardware.input.InputManager.InputDeviceListener);
    method @Nullable public android.view.VerifiedInputEvent verifyInputEvent(@NonNull android.view.InputEvent);
    field public static final String ACTION_QUERY_KEYBOARD_LAYOUTS = "android.hardware.input.action.QUERY_KEYBOARD_LAYOUTS";
    field public static final String META_DATA_KEYBOARD_LAYOUTS = "android.hardware.input.metadata.KEYBOARD_LAYOUTS";
  }
@@ -53401,6 +53402,38 @@ package android.view {
    method public void recycle();
  }
  public abstract class VerifiedInputEvent implements android.os.Parcelable {
    method public int describeContents();
    method public int getDeviceId();
    method public int getDisplayId();
    method public long getEventTimeNanos();
    method public int getSource();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.view.VerifiedInputEvent> CREATOR;
  }
  public final class VerifiedKeyEvent extends android.view.VerifiedInputEvent implements android.os.Parcelable {
    method public int getAction();
    method public long getDownTimeNanos();
    method @Nullable public Boolean getFlag(int);
    method public int getKeyCode();
    method public int getMetaState();
    method public int getRepeatCount();
    method public int getScanCode();
    field @NonNull public static final android.os.Parcelable.Creator<android.view.VerifiedKeyEvent> CREATOR;
  }
  public final class VerifiedMotionEvent extends android.view.VerifiedInputEvent implements android.os.Parcelable {
    method public int getActionMasked();
    method public int getButtonState();
    method public long getDownTimeNanos();
    method @Nullable public Boolean getFlag(int);
    method public int getMetaState();
    method public float getRawX();
    method public float getRawY();
    field @NonNull public static final android.os.Parcelable.Creator<android.view.VerifiedMotionEvent> CREATOR;
  }
  @UiThread public class View implements android.view.accessibility.AccessibilityEventSource android.graphics.drawable.Drawable.Callback android.view.KeyEvent.Callback {
    ctor public View(android.content.Context);
    ctor public View(android.content.Context, @Nullable android.util.AttributeSet);
+3 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.view.InputDevice;
import android.view.InputEvent;
import android.view.InputMonitor;
import android.view.PointerIcon;
import android.view.VerifiedInputEvent;

/** @hide */
interface IInputManager {
@@ -50,6 +51,8 @@ interface IInputManager {
    @UnsupportedAppUsage
    boolean injectInputEvent(in InputEvent ev, int mode);

    VerifiedInputEvent verifyInputEvent(in InputEvent ev);

    // Calibrate input device position
    TouchCalibration getTouchCalibrationForInputDevice(String inputDeviceDescriptor, int rotation);
    void setTouchCalibrationForInputDevice(String inputDeviceDescriptor, int rotation,
+23 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.hardware.input;
import android.annotation.CallbackExecutor;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemService;
@@ -46,6 +47,7 @@ import android.view.InputEvent;
import android.view.InputMonitor;
import android.view.MotionEvent;
import android.view.PointerIcon;
import android.view.VerifiedInputEvent;

import com.android.internal.os.SomeArgs;

@@ -908,6 +910,27 @@ public final class InputManager {
        }
    }

    /**
     * Verify the details of an {@link android.view.InputEvent} that came from the system.
     * If the event did not come from the system, or its details could not be verified, then this
     * will return {@code null}. Receiving {@code null} does not mean that the event did not
     * originate from the system, just that we were unable to verify it. This can
     * happen for a number of reasons during normal operation.
     *
     * @param event The {@link android.view.InputEvent} to check
     *
     * @return {@link android.view.VerifiedInputEvent}, which is a subset of the provided
     * {@link android.view.InputEvent}
     *         {@code null} if the event could not be verified.
     */
    public @Nullable VerifiedInputEvent verifyInputEvent(@NonNull InputEvent event) {
        try {
            return mIm.verifyInputEvent(event);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * Changes the mouse pointer's icon shape into the specified id.
     *
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view;

parcelable VerifiedInputEvent;
+162 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view;

import static java.lang.annotation.RetentionPolicy.SOURCE;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SuppressLint;
import android.os.Parcel;
import android.os.Parcelable;

import java.lang.annotation.Retention;


/**
 * Base class for verified events.
 * Verified events contain the subset of an InputEvent that the system can verify.
 * Data contained inside VerifiedInputEvent's should be considered trusted and contain only
 * the original event data that first came from the system.
 *
 * @see android.hardware.input.InputManager#verifyInputEvent(InputEvent)
 */
@SuppressLint("ParcelNotFinal")
public abstract class VerifiedInputEvent implements Parcelable {
    private static final String TAG = "VerifiedInputEvent";

    /** @hide */
    protected static final int VERIFIED_KEY = 1;
    /** @hide */
    protected static final int VERIFIED_MOTION = 2;

    /** @hide */
    @Retention(SOURCE)
    @IntDef(prefix = "VERIFIED", value = {VERIFIED_KEY, VERIFIED_MOTION})
    public @interface VerifiedInputEventType {};

    @VerifiedInputEventType
    private int mType;

    private int mDeviceId;
    private long mEventTimeNanos;
    private int mSource;
    private int mDisplayId;

    /** @hide */
    protected VerifiedInputEvent(int type, int deviceId, long eventTimeNanos, int source,
            int displayId) {
        mType = type;
        mDeviceId = deviceId;
        mEventTimeNanos = eventTimeNanos;
        mSource = source;
        mDisplayId = displayId;
    }
    /** @hide */
    protected VerifiedInputEvent(@NonNull Parcel in, int expectedType) {
        mType = in.readInt();
        if (mType != expectedType) {
            throw new IllegalArgumentException("Unexpected input event type token in parcel.");
        }
        mDeviceId = in.readInt();
        mEventTimeNanos = in.readLong();
        mSource = in.readInt();
        mDisplayId = in.readInt();
    }

    /**
     * Get the id of the device that generated this event.
     *
     * @see InputEvent#getDeviceId()
     */
    public int getDeviceId() {
        return mDeviceId;
    }

    /**
     * Get the time this event occurred, in the {@link android.os.SystemClock#uptimeMillis()}
     * time base.
     *
     * @see InputEvent#getEventTime()
     * @see KeyEvent#getEventTimeNano()
     * @see MotionEvent#getEventTimeNano()
     */
    @SuppressLint("MethodNameUnits")
    public long getEventTimeNanos() {
        return mEventTimeNanos;
    }

    /**
     * Get the source of the event.
     *
     * @see InputEvent#getSource()
     */
    public int getSource() {
        return mSource;
    }

    /**
     * Get the display id that is associated with this event.
     *
     * @see Display#getDisplayId()
     */
    public int getDisplayId() {
        return mDisplayId;
    }

    /** {@inheritDoc} */
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeInt(mType);
        dest.writeInt(mDeviceId);
        dest.writeLong(mEventTimeNanos);
        dest.writeInt(mSource);
        dest.writeInt(mDisplayId);
    }

    /** {@inheritDoc} */
    @Override
    public int describeContents() {
        return 0;
    }

    private static int peekInt(@NonNull Parcel parcel) {
        final int initialDataPosition = parcel.dataPosition();
        int data = parcel.readInt();
        parcel.setDataPosition(initialDataPosition);
        return data;
    }

    public static final @NonNull Parcelable.Creator<VerifiedInputEvent> CREATOR =
            new Parcelable.Creator<VerifiedInputEvent>() {
        @Override
        public VerifiedInputEvent[] newArray(int size) {
            return new VerifiedInputEvent[size];
        }

        @Override
        public VerifiedInputEvent createFromParcel(@NonNull Parcel in) {
            final int type = peekInt(in);
            if (type == VERIFIED_KEY) {
                return VerifiedKeyEvent.CREATOR.createFromParcel(in);
            } else if (type == VERIFIED_MOTION) {
                return VerifiedMotionEvent.CREATOR.createFromParcel(in);
            }
            throw new IllegalArgumentException("Unexpected input event type in parcel.");
        }
    };
}
Loading