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

Commit 4e4a9174 authored by petsjonkin's avatar petsjonkin Committed by Oleg Petšjonkin
Browse files

Adding new API to restrict Display modes to specific ids

Part of VRR support for DisplayManager

Allows internal application to request specific display modes

As a part of this CL, extracted ProximitySensorObserver to separate class and added tests

Test: atest SensorObserverTest
Bug: b/309466682
API-Coverage-Bug: b/313916551
Change-Id: I90b6ac36849fa9d0c10857300b9fedaafd04fdad
parent d0fa4222
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -1652,6 +1652,22 @@ public final class DisplayManager {
                callbackWrapper, displayId);
    }

    /**
     * Allows internal application to restrict display modes to specified modeIds
     *
     * @param displayId display that restrictions will be applied to
     * @param modeIds allowed mode ids
     *
     * @hide
     */
    @RequiresPermission("android.permission.RESTRICT_DISPLAY_MODES")
    public void requestDisplayModes(int displayId, @Nullable int[] modeIds) {
        if (modeIds != null && modeIds.length == 0) {
            throw new IllegalArgumentException("requestDisplayModes: modesIds can't be empty");
        }
        mGlobal.requestDisplayModes(displayId, modeIds);
    }

    /**
     * Listens for changes in available display devices.
     */
+17 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.hardware.display.DisplayManager.DisplayListener;
import android.hardware.graphics.common.DisplayDecorationSupport;
import android.media.projection.IMediaProjection;
import android.media.projection.MediaProjection;
import android.os.Binder;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.IBinder;
@@ -138,6 +139,8 @@ public final class DisplayManagerGlobal {

    private int mWifiDisplayScanNestCount;

    private final Binder mToken = new Binder();

    @VisibleForTesting
    public DisplayManagerGlobal(IDisplayManager dm) {
        mDm = dm;
@@ -1182,6 +1185,20 @@ public final class DisplayManagerGlobal {
        }
    }

    /**
     * Sets allowed display mode ids
     *
     * @hide
     */
    @RequiresPermission("android.permission.RESTRICT_DISPLAY_MODES")
    public void requestDisplayModes(int displayId, @Nullable int[] modeIds) {
        try {
            mDm.requestDisplayModes(mToken, displayId, modeIds);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    private final class DisplayManagerCallback extends IDisplayManagerCallback.Stub {
        @Override
        public void onDisplayEvent(int displayId, @DisplayEvent int event) {
+4 −0
Original line number Diff line number Diff line
@@ -235,4 +235,8 @@ interface IDisplayManager {
    // Disable a connected display that is enabled.
    @EnforcePermission("MANAGE_DISPLAYS")
    void disableConnectedDisplay(int displayId);

    // Restricts display modes to specified modeIds.
    @EnforcePermission("RESTRICT_DISPLAY_MODES")
    void requestDisplayModes(in IBinder token, int displayId, in @nullable int[] modeIds);
}
+8 −0
Original line number Diff line number Diff line
@@ -8149,6 +8149,14 @@
    <permission android:name="android.permission.EMERGENCY_INSTALL_PACKAGES"
                android:protectionLevel="signature|privileged"/>

    <!-- Allows internal applications to restrict display modes
       <p>Not for use by third-party applications.
       <p>Protection level: signature
       @hide
    -->
    <permission android:name="android.permission.RESTRICT_DISPLAY_MODES"
        android:protectionLevel="signature" />

    <!-- Attribution for Geofencing service. -->
    <attribution android:tag="GeofencingService" android:label="@string/geofencing_service"/>
    <!-- Attribution for Country Detector. -->
+9 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.Manifest.permission.CAPTURE_SECURE_VIDEO_OUTPUT;
import static android.Manifest.permission.CAPTURE_VIDEO_OUTPUT;
import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
import static android.Manifest.permission.MANAGE_DISPLAYS;
import static android.Manifest.permission.RESTRICT_DISPLAY_MODES;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_CACHED;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_GONE;
import static android.hardware.display.DisplayManager.EventsMask;
@@ -4530,6 +4531,14 @@ public final class DisplayManagerService extends SystemService {
            disableConnectedDisplay_enforcePermission();
            DisplayManagerService.this.enableConnectedDisplay(displayId, false);
        }

        @EnforcePermission(RESTRICT_DISPLAY_MODES)
        @Override // Binder call
        public void requestDisplayModes(IBinder token, int displayId, @Nullable int[] modeIds) {
            requestDisplayModes_enforcePermission();
            DisplayManagerService.this.mDisplayModeDirector.requestDisplayModes(
                    token, displayId, modeIds);
        }
    }

    private static boolean isValidBrightness(float brightness) {
Loading