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

Commit b0608636 authored by Santos Cordon's avatar Santos Cordon
Browse files

Add uniqueId to Virtual Display and pass through to inputflinger (1/2)

This CL adds:
1) Adds uniqueId (protected via system/sig permission) to virtual
displays.
2) Add support for N virtual display viewports into inputflinger.
3) Set the virtual display's viewports in inputflinger if it has the
uniqueId value set to non-null. (a) Moving the new viewport from java to
native inputflinger and (b) adding "uniqueId" value to viewports makes
up the great majority of this change.
4) From the inputflinger side, we also read in a new value from the
input device configuration files called 'touch.displayId'.
5) When touch.displayId and the virtual display's uniqueId match,
inputflinger links the two.

Test: Start VR and ensure that the virtual viewport shows up when running
'adb shell dump input".  Run a VR app, and ensure that the virtual input
device is associated with the new virtual viewport.
Test: com.android.server.display.DisplayManagerServiceTest

Bug: 36051620
Change-Id: Ic2117eb8e19f7f3c59687160591f8bc6692c1f12
Merged-In: Ic2117eb8e19f7f3c59687160591f8bc6692c1f12
parent b4656daf
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -251,6 +251,15 @@ public final class DisplayManager {
     */
    public static final int VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD = 1 << 5;

    /**
     * Virtual display flag: Specifies that the virtual display can be associated with a
     * touchpad device that matches its uniqueId.
     *
     * @see #createVirtualDisplay
     * @hide
     */
    public static final int VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH = 1 << 6;

    /** @hide */
    public DisplayManager(Context context) {
        mContext = context;
@@ -542,16 +551,17 @@ public final class DisplayManager {
    public VirtualDisplay createVirtualDisplay(@NonNull String name,
            int width, int height, int densityDpi, @Nullable Surface surface, int flags,
            @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler) {
        return createVirtualDisplay(null,
                name, width, height, densityDpi, surface, flags, callback, handler);
        return createVirtualDisplay(null /* projection */, name, width, height, densityDpi, surface,
                flags, callback, handler, null /* uniqueId */);
    }

    /** @hide */
    public VirtualDisplay createVirtualDisplay(@Nullable MediaProjection projection,
            @NonNull String name, int width, int height, int densityDpi, @Nullable Surface surface,
            int flags, @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler) {
            int flags, @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler,
            @Nullable String uniqueId) {
        return mGlobal.createVirtualDisplay(mContext, projection,
                name, width, height, densityDpi, surface, flags, callback, handler);
                name, width, height, densityDpi, surface, flags, callback, handler, uniqueId);
    }

    /**
+3 −2
Original line number Diff line number Diff line
@@ -383,7 +383,7 @@ public final class DisplayManagerGlobal {

    public VirtualDisplay createVirtualDisplay(Context context, MediaProjection projection,
            String name, int width, int height, int densityDpi, Surface surface, int flags,
            VirtualDisplay.Callback callback, Handler handler) {
            VirtualDisplay.Callback callback, Handler handler, String uniqueId) {
        if (TextUtils.isEmpty(name)) {
            throw new IllegalArgumentException("name must be non-null and non-empty");
        }
@@ -397,7 +397,8 @@ public final class DisplayManagerGlobal {
        int displayId;
        try {
            displayId = mDm.createVirtualDisplay(callbackWrapper, projectionToken,
                    context.getPackageName(), name, width, height, densityDpi, surface, flags);
                    context.getPackageName(), name, width, height, densityDpi, surface, flags,
                    uniqueId);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
+48 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.hardware.display;

import android.graphics.Rect;
import android.text.TextUtils;

/**
 * Describes how the pixels of physical display device reflects the content of
@@ -52,6 +53,9 @@ public final class DisplayViewport {
    public int deviceWidth;
    public int deviceHeight;

    // The ID used to uniquely identify this display.
    public String uniqueId;

    public void copyFrom(DisplayViewport viewport) {
        valid = viewport.valid;
        displayId = viewport.displayId;
@@ -60,6 +64,49 @@ public final class DisplayViewport {
        physicalFrame.set(viewport.physicalFrame);
        deviceWidth = viewport.deviceWidth;
        deviceHeight = viewport.deviceHeight;
        uniqueId = viewport.uniqueId;
    }

    public DisplayViewport makeCopy() {
        DisplayViewport dv = new DisplayViewport();
        dv.copyFrom(this);
        return dv;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }

        if (!(o instanceof DisplayViewport)) {
            return false;
        }

        DisplayViewport other = (DisplayViewport) o;
        return valid == other.valid &&
              displayId == other.displayId &&
              orientation == other.orientation &&
              logicalFrame.equals(other.logicalFrame) &&
              physicalFrame.equals(other.physicalFrame) &&
              deviceWidth == other.deviceWidth &&
              deviceHeight == other.deviceHeight &&
              TextUtils.equals(uniqueId, other.uniqueId);
    }

    @Override
    public int hashCode() {
      final int prime = 31;
      int result = 1;
      result += prime * result + (valid ? 1 : 0);
      result += prime * result + displayId;
      result += prime * result + orientation;
      result += prime * result + logicalFrame.hashCode();
      result += prime * result + physicalFrame.hashCode();
      result += prime * result + deviceWidth;
      result += prime * result + deviceHeight;
      result += prime * result + uniqueId.hashCode();
      return result;
    }

    // For debugging purposes.
@@ -67,6 +114,7 @@ public final class DisplayViewport {
    public String toString() {
        return "DisplayViewport{valid=" + valid
                + ", displayId=" + displayId
                + ", uniqueId='" + uniqueId + "'"
                + ", orientation=" + orientation
                + ", logicalFrame=" + logicalFrame
                + ", physicalFrame=" + physicalFrame
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ interface IDisplayManager {
    // MediaProjection token for certain combinations of flags.
    int createVirtualDisplay(in IVirtualDisplayCallback callback,
            in IMediaProjection projectionToken, String packageName, String name,
            int width, int height, int densityDpi, in Surface surface, int flags);
            int width, int height, int densityDpi, in Surface surface, int flags, String uniqueId);

    // No permissions required, but must be same Uid as the creator.
    void resizeVirtualDisplay(in IVirtualDisplayCallback token,
+3 −1
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.view.InputEvent;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;

import java.util.List;

/**
 * Input manager local system service interface.
 *
@@ -35,7 +37,7 @@ public abstract class InputManagerInternal {
     * by the input system.  The input system must copy this information to retain it.
     */
    public abstract void setDisplayViewports(DisplayViewport defaultViewport,
            DisplayViewport externalTouchViewport);
            DisplayViewport externalTouchViewport, List<DisplayViewport> virtualTouchViewports);

    /**
     * Called by the power manager to tell the input manager whether it should start
Loading