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

Commit 3240b9d6 authored by Ambrus Weisz's avatar Ambrus Weisz Committed by Vladimir Komsiyski
Browse files

Virtual input config API consistency.

Remove inPixels from getWidth and getHeight of VirtualTouchScreenConfig
to make it consistent with VirtualTouchpadNavigationConfig.

Bug: 262887146
Test: atest VirtualDeviceManagerServiceTest

Change-Id: If74622d99265de0134b6cbedde1f2ca40302b883
parent 901d619f
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -4902,17 +4902,15 @@ package android.hardware.input {
  public final class VirtualTouchscreenConfig extends android.hardware.input.VirtualInputDeviceConfig implements android.os.Parcelable {
    method public int describeContents();
    method public int getHeightInPixels();
    method public int getWidthInPixels();
    method public int getHeight();
    method public int getWidth();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.hardware.input.VirtualTouchscreenConfig> CREATOR;
  }
  public static final class VirtualTouchscreenConfig.Builder extends android.hardware.input.VirtualInputDeviceConfig.Builder<android.hardware.input.VirtualTouchscreenConfig.Builder> {
    ctor public VirtualTouchscreenConfig.Builder();
    ctor public VirtualTouchscreenConfig.Builder(@IntRange(from=1) int, @IntRange(from=1) int);
    method @NonNull public android.hardware.input.VirtualTouchscreenConfig build();
    method @NonNull public android.hardware.input.VirtualTouchscreenConfig.Builder setHeightInPixels(int);
    method @NonNull public android.hardware.input.VirtualTouchscreenConfig.Builder setWidthInPixels(int);
  }
}
+1 −3
Original line number Diff line number Diff line
@@ -775,13 +775,11 @@ public final class VirtualDeviceManager {
            final Point size = new Point();
            display.getDisplay().getSize(size);
            VirtualTouchscreenConfig touchscreenConfig =
                    new VirtualTouchscreenConfig.Builder()
                    new VirtualTouchscreenConfig.Builder(size.x, size.y)
                            .setVendorId(vendorId)
                            .setProductId(productId)
                            .setInputDeviceName(inputDeviceName)
                            .setAssociatedDisplayId(display.getDisplay().getDisplayId())
                            .setWidthInPixels(size.x)
                            .setHeightInPixels(size.y)
                            .build();
            return createVirtualTouchscreen(touchscreenConfig);
        }
+8 −3
Original line number Diff line number Diff line
@@ -88,12 +88,17 @@ public final class VirtualNavigationTouchpadConfig extends VirtualInputDeviceCon
     * Builder for creating a {@link VirtualNavigationTouchpadConfig}.
     */
    public static final class Builder extends VirtualInputDeviceConfig.Builder<Builder> {

        private final int mHeight;
        private final int mWidth;

        public Builder(@IntRange(from = 1) int touchpadHeight,
                @IntRange(from = 1) int touchpadWidth) {
        /**
         * Creates a new instance for the given dimensions of the {@link VirtualNavigationTouchpad}.
         *
         * @param touchpadWidth The width of the touchpad.
         * @param touchpadHeight The height of the touchpad.
         */
        public Builder(@IntRange(from = 1) int touchpadWidth,
                @IntRange(from = 1) int touchpadHeight) {
            if (touchpadHeight <= 0 || touchpadWidth <= 0) {
                throw new IllegalArgumentException(
                        "Cannot create a virtual navigation touchpad, touchpad dimensions must be "
+37 −32
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.hardware.input;

import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.os.Parcel;
@@ -29,31 +30,31 @@ import android.os.Parcelable;
@SystemApi
public final class VirtualTouchscreenConfig extends VirtualInputDeviceConfig implements Parcelable {

    /** The touchscreen width in pixels. */
    private final int mWidthInPixels;
    /** The touchscreen height in pixels. */
    private final int mHeightInPixels;
    /** The touchscreen width. */
    private final int mWidth;
    /** The touchscreen height. */
    private final int mHeight;

    private VirtualTouchscreenConfig(@NonNull Builder builder) {
        super(builder);
        mWidthInPixels = builder.mWidthInPixels;
        mHeightInPixels = builder.mHeightInPixels;
        mWidth = builder.mWidth;
        mHeight = builder.mHeight;
    }

    private VirtualTouchscreenConfig(@NonNull Parcel in) {
        super(in);
        mWidthInPixels = in.readInt();
        mHeightInPixels = in.readInt();
        mWidth = in.readInt();
        mHeight = in.readInt();
    }

    /** Returns the touchscreen width in pixels. */
    public int getWidthInPixels() {
        return mWidthInPixels;
    /** Returns the touchscreen width. */
    public int getWidth() {
        return mWidth;
    }

    /** Returns the touchscreen height in pixels. */
    public int getHeightInPixels() {
        return mHeightInPixels;
    /** Returns the touchscreen height. */
    public int getHeight() {
        return mHeight;
    }

    @Override
@@ -64,8 +65,8 @@ public final class VirtualTouchscreenConfig extends VirtualInputDeviceConfig imp
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeInt(mWidthInPixels);
        dest.writeInt(mHeightInPixels);
        dest.writeInt(mWidth);
        dest.writeInt(mHeight);
    }

    @NonNull
@@ -86,25 +87,29 @@ public final class VirtualTouchscreenConfig extends VirtualInputDeviceConfig imp
     * Builder for creating a {@link VirtualTouchscreenConfig}.
     */
    public static final class Builder extends VirtualInputDeviceConfig.Builder<Builder> {
        private int mWidthInPixels;
        private int mHeightInPixels;
        private int mWidth;
        private int mHeight;

        /**
         * @see VirtualTouchscreenConfig#getWidthInPixels().
         * Creates a new instance for the given dimensions of the {@link VirtualTouchscreen}.
         *
         * <p>The dimensions are not pixels but in the touchscreens raw coordinate space. They do
         * not necessarily have to correspond to the display size or aspect ratio. In this case the
         * framework will handle the scaling appropriately.
         *
         * @param touchscreenWidth The width of the touchscreen.
         * @param touchscreenHeight The height of the touchscreen.
         */
        @NonNull
        public Builder setWidthInPixels(int widthInPixels) {
            mWidthInPixels = widthInPixels;
            return this;
        public Builder(@IntRange(from = 1) int touchscreenWidth,
                @IntRange(from = 1) int touchscreenHeight) {
            if (touchscreenHeight <= 0 || touchscreenWidth <= 0) {
                throw new IllegalArgumentException(
                        "Cannot create a virtual touchscreen, touchscreen dimensions must be "
                                + "positive. Got: (" + touchscreenHeight + ", "
                                + touchscreenWidth + ")");
            }

        /**
         * @see VirtualTouchscreenConfig#getHeightInPixels().
         */
        @NonNull
        public Builder setHeightInPixels(int heightInPixels) {
            mHeightInPixels = heightInPixels;
            return this;
            mHeight = touchscreenHeight;
            mWidth = touchscreenWidth;
        }

        /**
+5 −5
Original line number Diff line number Diff line
@@ -497,19 +497,19 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
                                + "this virtual device");
            }
        }
        int screenHeightPixels = config.getHeightInPixels();
        int screenWidthPixels = config.getWidthInPixels();
        if (screenHeightPixels <= 0 || screenWidthPixels <= 0) {
        int screenHeight = config.getHeight();
        int screenWidth = config.getWidth();
        if (screenHeight <= 0 || screenWidth <= 0) {
            throw new IllegalArgumentException(
                    "Cannot create a virtual touchscreen, screen dimensions must be positive. Got: "
                            + "(" + screenWidthPixels + ", " + screenHeightPixels + ")");
                            + "(" + screenWidth + ", " + screenHeight + ")");
        }

        final long ident = Binder.clearCallingIdentity();
        try {
            mInputController.createTouchscreen(config.getInputDeviceName(), config.getVendorId(),
                    config.getProductId(), deviceToken, config.getAssociatedDisplayId(),
                    screenHeightPixels, screenWidthPixels);
                    screenHeight, screenWidth);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
Loading