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

Commit 87793a41 authored by Oleg Petšjonkin's avatar Oleg Petšjonkin Committed by Android (Google) Code Review
Browse files

Merge changes from topic "b/309466682" into main

* changes:
  Adding new SYSTEM_REQUESTED priority to DisplayModeDirector voting
  Adding new API to restrict Display modes to specific ids
parents 1dbe381c 0e4a0aa5
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
@@ -8150,6 +8150,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;
@@ -4531,6 +4532,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