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

Commit 9994f352 authored by Vladimir Komsiyski's avatar Vladimir Komsiyski
Browse files

Per-display WM brightness override.

The brightness overrides are keyed by displayId and passed
directly through DisplayManager to the relevant
OverrideBrightnessStrategy. Keeping the global brightness override
in PowerManager because it's used during boot.

Fix: 288052251
Test: atest
Flag: EXEMPT bugfix

Change-Id: Ic23970b9e7acd9f5edae04b27fe68f679c994d33
parent 08efab93
Loading
Loading
Loading
Loading
+27 −2
Original line number Original line Diff line number Diff line
@@ -470,6 +470,31 @@ public abstract class DisplayManagerInternal {
     */
     */
    public abstract boolean isDisplayReadyForMirroring(int displayId);
    public abstract boolean isDisplayReadyForMirroring(int displayId);



    /**
     * Used by the window manager to override the per-display screen brightness based on the
     * current foreground activity.
     *
     * The key of the array is the displayId. If a displayId is missing from the array, this is
     * equivalent to clearing any existing brightness overrides for that display.
     *
     * This method must only be called by the window manager.
     */
    public abstract void setScreenBrightnessOverrideFromWindowManager(
            SparseArray<DisplayBrightnessOverrideRequest> brightnessOverrides);

    /**
     * Describes a request for overriding the brightness of a single display.
     */
    public static class DisplayBrightnessOverrideRequest {
        // An override of the screen brightness.
        // Set to PowerManager.BRIGHTNESS_INVALID if there's no override.
        public float brightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;

        // Tag used to identify the app window requesting the brightness override.
        public CharSequence tag;
    }

    /**
    /**
     * Describes the requested power state of the display.
     * Describes the requested power state of the display.
     *
     *
@@ -505,11 +530,11 @@ public abstract class DisplayManagerInternal {
        // nearby, turning it off temporarily until the object is moved away.
        // nearby, turning it off temporarily until the object is moved away.
        public boolean useProximitySensor;
        public boolean useProximitySensor;


        // An override of the screen brightness.
        // A global override of the screen brightness, applied to all displays.
        // Set to PowerManager.BRIGHTNESS_INVALID if there's no override.
        // Set to PowerManager.BRIGHTNESS_INVALID if there's no override.
        public float screenBrightnessOverride;
        public float screenBrightnessOverride;


        // Tag used to identify the app window requesting the brightness override.
        // Tag used to identify the reason for the global brightness override.
        public CharSequence screenBrightnessOverrideTag;
        public CharSequence screenBrightnessOverrideTag;


        // An override of the screen auto-brightness adjustment factor in the range -1 (dimmer) to
        // An override of the screen auto-brightness adjustment factor in the range -1 (dimmer) to
+0 −12
Original line number Original line Diff line number Diff line
@@ -97,18 +97,6 @@ public abstract class PowerManagerInternal {
        return wakefulness == WAKEFULNESS_AWAKE || wakefulness == WAKEFULNESS_DREAMING;
        return wakefulness == WAKEFULNESS_AWAKE || wakefulness == WAKEFULNESS_DREAMING;
    }
    }


    /**
     * Used by the window manager to override the screen brightness based on the
     * current foreground activity.
     *
     * This method must only be called by the window manager.
     *
     * @param brightness The overridden brightness, or Float.NaN to disable the override.
     * @param tag Source identifier of the app window that requests the override.
     */
    public abstract void setScreenBrightnessOverrideFromWindowManager(
            float brightness, CharSequence tag);

    /**
    /**
     * Used by the window manager to override the user activity timeout based on the
     * Used by the window manager to override the user activity timeout based on the
     * current foreground activity.  It can only be used to make the timeout shorter
     * current foreground activity.  It can only be used to make the timeout shorter
+17 −0
Original line number Original line Diff line number Diff line
@@ -5282,6 +5282,23 @@ public final class DisplayManagerService extends SystemService {
                    packageName);
                    packageName);
        }
        }


        @Override
        public void setScreenBrightnessOverrideFromWindowManager(
                SparseArray<DisplayBrightnessOverrideRequest> brightnessOverrides) {
            SparseArray<DisplayPowerController> dpcs = new SparseArray<>();
            synchronized (mSyncRoot) {
                for (int i = 0; i < mDisplayPowerControllers.size(); i++) {
                    dpcs.put(mDisplayPowerControllers.keyAt(i),
                            mDisplayPowerControllers.valueAt(i));
                }
            }
            for (int i = 0; i < dpcs.size(); ++i) {
                final int displayId = dpcs.keyAt(i);
                final DisplayPowerController dpc = dpcs.valueAt(i);
                dpc.setBrightnessOverrideRequest(brightnessOverrides.get(displayId));
            }
        }

        @Override
        @Override
        public boolean requestPowerState(int groupId, DisplayPowerRequest request,
        public boolean requestPowerState(int groupId, DisplayPowerRequest request,
                boolean waitForNegativeProximity) {
                boolean waitForNegativeProximity) {
+15 −0
Original line number Original line Diff line number Diff line
@@ -42,6 +42,7 @@ import android.hardware.display.AmbientBrightnessDayStats;
import android.hardware.display.BrightnessChangeEvent;
import android.hardware.display.BrightnessChangeEvent;
import android.hardware.display.BrightnessConfiguration;
import android.hardware.display.BrightnessConfiguration;
import android.hardware.display.BrightnessInfo;
import android.hardware.display.BrightnessInfo;
import android.hardware.display.DisplayManagerInternal;
import android.hardware.display.DisplayManagerInternal.DisplayOffloadSession;
import android.hardware.display.DisplayManagerInternal.DisplayOffloadSession;
import android.hardware.display.DisplayManagerInternal.DisplayPowerCallbacks;
import android.hardware.display.DisplayManagerInternal.DisplayPowerCallbacks;
import android.hardware.display.DisplayManagerInternal.DisplayPowerRequest;
import android.hardware.display.DisplayManagerInternal.DisplayPowerRequest;
@@ -170,6 +171,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    private static final int MSG_OFFLOADING_SCREEN_ON_UNBLOCKED = 18;
    private static final int MSG_OFFLOADING_SCREEN_ON_UNBLOCKED = 18;
    private static final int MSG_SET_STYLUS_BEING_USED = 19;
    private static final int MSG_SET_STYLUS_BEING_USED = 19;
    private static final int MSG_SET_STYLUS_USE_ENDED = 20;
    private static final int MSG_SET_STYLUS_USE_ENDED = 20;
    private static final int MSG_SET_WINDOW_MANAGER_BRIGHTNESS_OVERRIDE = 21;


    private static final int BRIGHTNESS_CHANGE_STATSD_REPORT_INTERVAL_MS = 500;
    private static final int BRIGHTNESS_CHANGE_STATSD_REPORT_INTERVAL_MS = 500;


@@ -850,6 +852,12 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        }
        }
    }
    }


    public void setBrightnessOverrideRequest(
            DisplayManagerInternal.DisplayBrightnessOverrideRequest request) {
        Message msg = mHandler.obtainMessage(MSG_SET_WINDOW_MANAGER_BRIGHTNESS_OVERRIDE, request);
        mHandler.sendMessageAtTime(msg, mClock.uptimeMillis());
    }

    public void setDisplayOffloadSession(DisplayOffloadSession session) {
    public void setDisplayOffloadSession(DisplayOffloadSession session) {
        if (session == mDisplayOffloadSession) {
        if (session == mDisplayOffloadSession) {
            return;
            return;
@@ -3100,6 +3108,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                    updatePowerState();
                    updatePowerState();
                    break;
                    break;


                case MSG_SET_WINDOW_MANAGER_BRIGHTNESS_OVERRIDE:
                    if (mDisplayBrightnessController.updateWindowManagerBrightnessOverride(
                            (DisplayManagerInternal.DisplayBrightnessOverrideRequest) msg.obj)) {
                        updatePowerState();
                    }
                    break;

                case MSG_STOP:
                case MSG_STOP:
                    cleanupHandlerThreadAfterStop();
                    cleanupHandlerThreadAfterStop();
                    break;
                    break;
+14 −0
Original line number Original line Diff line number Diff line
@@ -179,6 +179,20 @@ public final class DisplayBrightnessController {
        }
        }
    }
    }


    /**
     * Updates the brightness override from WindowManager.
     *
     * @param request The request to override the brightness
     * @return whether this request will result in a change of the brightness
     */
    public boolean updateWindowManagerBrightnessOverride(
            DisplayManagerInternal.DisplayBrightnessOverrideRequest request) {
        synchronized (mLock) {
            return mDisplayBrightnessStrategySelector.getOverrideBrightnessStrategy()
                    .updateWindowManagerBrightnessOverride(request);
        }
    }

    /**
    /**
     * Sets the brightness to follow
     * Sets the brightness to follow
     */
     */
Loading