Loading core/java/android/hardware/display/BrightnessInfo.java +16 −6 Original line number Diff line number Diff line Loading @@ -57,11 +57,14 @@ public final class BrightnessInfo implements Parcelable { */ public static final int HIGH_BRIGHTNESS_MODE_HDR = 2; @IntDef(prefix = {"BRIGHTNESS_MAX_REASON_"}, value = { @IntDef( prefix = {"BRIGHTNESS_MAX_REASON_"}, value = { BRIGHTNESS_MAX_REASON_NONE, BRIGHTNESS_MAX_REASON_THERMAL, BRIGHTNESS_MAX_REASON_POWER_IC, BRIGHTNESS_MAX_REASON_WEAR_BEDTIME_MODE BRIGHTNESS_MAX_REASON_WEAR_BEDTIME_MODE, BRIGHTNESS_MAX_REASON_MODES }) @Retention(RetentionPolicy.SOURCE) public @interface BrightnessMaxReason {} Loading @@ -86,6 +89,11 @@ public final class BrightnessInfo implements Parcelable { */ public static final int BRIGHTNESS_MAX_REASON_WEAR_BEDTIME_MODE = 3; /** * Maximum brightness is restricted by {@link android.app.NotificationManager} for quiet modes */ public static final int BRIGHTNESS_MAX_REASON_MODES = 4; /** Brightness */ public final float brightness; Loading Loading @@ -169,6 +177,8 @@ public final class BrightnessInfo implements Parcelable { return "power IC"; case BRIGHTNESS_MAX_REASON_WEAR_BEDTIME_MODE: return "wear bedtime"; case BRIGHTNESS_MAX_REASON_MODES: return "modes"; } return "invalid"; } Loading core/java/android/hardware/display/DisplayManagerInternal.java +16 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.hardware.display; import android.annotation.FloatRange; import android.annotation.IntDef; import android.annotation.Nullable; import android.companion.virtual.IVirtualDevice; Loading Loading @@ -282,6 +283,21 @@ public abstract class DisplayManagerInternal { */ public abstract void persistBrightnessTrackerState(); /** * Sets a maximum brightness cap for the display. * * <p>A cap of {@code 1f} will remove the cap. * * @param displayId id of the display to cap the maximum brightness for * @param cap the brightness cap between {@code 0f} and {@code 1f} * @param reason reason for capping brightness. Using the same reason again for a display * replaces the previous cap */ public abstract void setBrightnessCap( int displayId, @FloatRange(from = 0f, to = 1f) float cap, @BrightnessInfo.BrightnessMaxReason int reason); /** * Notifies the display manager that resource overlays have changed. */ Loading services/core/java/com/android/server/display/DisplayManagerService.java +15 −2 Original line number Diff line number Diff line Loading @@ -16,11 +16,11 @@ package com.android.server.display; import static android.Manifest.permission.ACCESS_COMPUTER_CONTROL; import static android.Manifest.permission.ADD_ALWAYS_UNLOCKED_DISPLAY; import static android.Manifest.permission.ADD_TRUSTED_DISPLAY; import static android.Manifest.permission.CAPTURE_SECURE_VIDEO_OUTPUT; import static android.Manifest.permission.CAPTURE_VIDEO_OUTPUT; import static android.Manifest.permission.ACCESS_COMPUTER_CONTROL; import static android.Manifest.permission.CONFIGURE_WIFI_DISPLAY; import static android.Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS; import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; Loading @@ -32,7 +32,6 @@ import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_CACHE import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_GONE; import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE; import static android.hardware.display.DisplayManager.BRIGHTNESS_UNIT_PERCENTAGE; import static android.hardware.display.DisplayManagerGlobal.InternalEventFlag; import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_ALWAYS_UNLOCKED; import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR; import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD; Loading @@ -47,6 +46,7 @@ import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_SHOUL import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_STEAL_TOP_FOCUS_DISABLED; import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_TRUSTED; import static android.hardware.display.DisplayManagerGlobal.DisplayEvent; import static android.hardware.display.DisplayManagerGlobal.InternalEventFlag; import static android.hardware.display.DisplayViewport.VIEWPORT_EXTERNAL; import static android.hardware.display.DisplayViewport.VIEWPORT_INTERNAL; import static android.hardware.display.DisplayViewport.VIEWPORT_VIRTUAL; Loading @@ -68,6 +68,7 @@ import static com.android.server.display.layout.Layout.Display.POSITION_REAR; import android.Manifest; import android.annotation.EnforcePermission; import android.annotation.FloatRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; Loading Loading @@ -6018,6 +6019,18 @@ public final class DisplayManagerService extends SystemService { } } @Override public void setBrightnessCap( int displayId, @FloatRange(from = 0f, to = 1f) float cap, @BrightnessInfo.BrightnessMaxReason int reason) { synchronized (mSyncRoot) { if (mDisplayPowerControllers.contains(displayId)) { mDisplayPowerControllers.get(displayId).setBrightnessCap(cap, reason); } } } @Override public void onOverlayChanged() { synchronized (mSyncRoot) { Loading services/core/java/com/android/server/display/DisplayPowerController.java +11 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static com.android.server.display.config.DisplayBrightnessMappingConfig.a import android.animation.Animator; import android.animation.ObjectAnimator; import android.annotation.FloatRange; import android.annotation.Nullable; import android.annotation.SuppressLint; import android.annotation.UserIdInt; Loading Loading @@ -3029,6 +3030,16 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } } /** * Set the brightness cap for this display. If present, this will replace the previously known * value of the cap for the provided {@link BrightnessInfo.BrightnessMaxReason} */ public void setBrightnessCap( @FloatRange(from = 0f, to = 1f) float cap, @BrightnessInfo.BrightnessMaxReason int reason) { mBrightnessClamperController.setBrightnessCap(cap, reason); } private final class DisplayControllerHandler extends Handler { DisplayControllerHandler(Looper looper) { super(looper, null, true /*async*/); Loading services/core/java/com/android/server/display/brightness/clamper/BrightnessClamperController.java +45 −14 Original line number Diff line number Diff line Loading @@ -16,8 +16,10 @@ package com.android.server.display.brightness.clamper; import static android.service.notification.Flags.applyBrightnessClampingForModes; import static android.view.Display.STATE_ON; import android.annotation.FloatRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.Context; Loading @@ -31,6 +33,7 @@ import android.os.PowerManager; import android.provider.DeviceConfig; import android.provider.DeviceConfigInterface; import android.util.IndentingPrintWriter; import android.util.Log; import android.util.Spline; import android.view.Display; Loading Loading @@ -72,6 +75,7 @@ public class BrightnessClamperController { private final List<DeviceConfigListener> mDeviceConfigListeners = new ArrayList<>(); private ModifiersAggregatedState mModifiersAggregatedState = new ModifiersAggregatedState(); @Nullable private ExternalBrightnessModifier mExternalBrightnessModifier; private final DeviceConfig.OnPropertiesChangedListener mOnPropertiesChangedListener; Loading Loading @@ -114,7 +118,8 @@ public class BrightnessClamperController { mModifiers = injector.getModifiers(flags, context, handler, clamperChangeListenerInternal, data, currentBrightness); mModifiers.forEach(m -> { mModifiers.forEach( m -> { if (m instanceof DisplayDeviceDataListener l) { mDisplayDeviceDataListeners.add(l); } Loading @@ -127,6 +132,14 @@ public class BrightnessClamperController { if (m instanceof DeviceConfigListener l) { mDeviceConfigListeners.add(l); } if (applyBrightnessClampingForModes() && m instanceof ExternalBrightnessModifier l) { if (mExternalBrightnessModifier != null) { throw new IllegalStateException( "Cannot have more than one external brightness cap modifier"); } mExternalBrightnessModifier = l; } }); mOnPropertiesChangedListener = properties -> { mDeviceConfigListeners.forEach(DeviceConfigListener::onDeviceConfigChanged); Loading Loading @@ -251,6 +264,21 @@ public class BrightnessClamperController { } } /** Replaces the brightness cap for the provided {@link BrightnessInfo.BrightnessMaxReason} */ public void setBrightnessCap( @FloatRange(from = 0f, to = 1f) float cap, @BrightnessInfo.BrightnessMaxReason int reason) { if (!applyBrightnessClampingForModes()) { return; } if (mExternalBrightnessModifier != null) { mExternalBrightnessModifier.setBrightnessCap(cap, reason); } else { Log.e(TAG, "Unable to set brightness cap"); } } /** * Clampers change listener */ Loading @@ -276,6 +304,9 @@ public class BrightnessClamperController { modifiers.add(new BrightnessWearBedtimeModeModifier(handler, context, listener, data)); } if (applyBrightnessClampingForModes()) { modifiers.add(new ExternalBrightnessModifier(handler, listener)); } if (flags.isPowerThrottlingClamperEnabled()) { // Check if power-throttling config is present. PowerThrottlingConfigData configData = data.getPowerThrottlingConfigData(); Loading Loading
core/java/android/hardware/display/BrightnessInfo.java +16 −6 Original line number Diff line number Diff line Loading @@ -57,11 +57,14 @@ public final class BrightnessInfo implements Parcelable { */ public static final int HIGH_BRIGHTNESS_MODE_HDR = 2; @IntDef(prefix = {"BRIGHTNESS_MAX_REASON_"}, value = { @IntDef( prefix = {"BRIGHTNESS_MAX_REASON_"}, value = { BRIGHTNESS_MAX_REASON_NONE, BRIGHTNESS_MAX_REASON_THERMAL, BRIGHTNESS_MAX_REASON_POWER_IC, BRIGHTNESS_MAX_REASON_WEAR_BEDTIME_MODE BRIGHTNESS_MAX_REASON_WEAR_BEDTIME_MODE, BRIGHTNESS_MAX_REASON_MODES }) @Retention(RetentionPolicy.SOURCE) public @interface BrightnessMaxReason {} Loading @@ -86,6 +89,11 @@ public final class BrightnessInfo implements Parcelable { */ public static final int BRIGHTNESS_MAX_REASON_WEAR_BEDTIME_MODE = 3; /** * Maximum brightness is restricted by {@link android.app.NotificationManager} for quiet modes */ public static final int BRIGHTNESS_MAX_REASON_MODES = 4; /** Brightness */ public final float brightness; Loading Loading @@ -169,6 +177,8 @@ public final class BrightnessInfo implements Parcelable { return "power IC"; case BRIGHTNESS_MAX_REASON_WEAR_BEDTIME_MODE: return "wear bedtime"; case BRIGHTNESS_MAX_REASON_MODES: return "modes"; } return "invalid"; } Loading
core/java/android/hardware/display/DisplayManagerInternal.java +16 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.hardware.display; import android.annotation.FloatRange; import android.annotation.IntDef; import android.annotation.Nullable; import android.companion.virtual.IVirtualDevice; Loading Loading @@ -282,6 +283,21 @@ public abstract class DisplayManagerInternal { */ public abstract void persistBrightnessTrackerState(); /** * Sets a maximum brightness cap for the display. * * <p>A cap of {@code 1f} will remove the cap. * * @param displayId id of the display to cap the maximum brightness for * @param cap the brightness cap between {@code 0f} and {@code 1f} * @param reason reason for capping brightness. Using the same reason again for a display * replaces the previous cap */ public abstract void setBrightnessCap( int displayId, @FloatRange(from = 0f, to = 1f) float cap, @BrightnessInfo.BrightnessMaxReason int reason); /** * Notifies the display manager that resource overlays have changed. */ Loading
services/core/java/com/android/server/display/DisplayManagerService.java +15 −2 Original line number Diff line number Diff line Loading @@ -16,11 +16,11 @@ package com.android.server.display; import static android.Manifest.permission.ACCESS_COMPUTER_CONTROL; import static android.Manifest.permission.ADD_ALWAYS_UNLOCKED_DISPLAY; import static android.Manifest.permission.ADD_TRUSTED_DISPLAY; import static android.Manifest.permission.CAPTURE_SECURE_VIDEO_OUTPUT; import static android.Manifest.permission.CAPTURE_VIDEO_OUTPUT; import static android.Manifest.permission.ACCESS_COMPUTER_CONTROL; import static android.Manifest.permission.CONFIGURE_WIFI_DISPLAY; import static android.Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS; import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; Loading @@ -32,7 +32,6 @@ import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_CACHE import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_GONE; import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE; import static android.hardware.display.DisplayManager.BRIGHTNESS_UNIT_PERCENTAGE; import static android.hardware.display.DisplayManagerGlobal.InternalEventFlag; import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_ALWAYS_UNLOCKED; import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR; import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD; Loading @@ -47,6 +46,7 @@ import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_SHOUL import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_STEAL_TOP_FOCUS_DISABLED; import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_TRUSTED; import static android.hardware.display.DisplayManagerGlobal.DisplayEvent; import static android.hardware.display.DisplayManagerGlobal.InternalEventFlag; import static android.hardware.display.DisplayViewport.VIEWPORT_EXTERNAL; import static android.hardware.display.DisplayViewport.VIEWPORT_INTERNAL; import static android.hardware.display.DisplayViewport.VIEWPORT_VIRTUAL; Loading @@ -68,6 +68,7 @@ import static com.android.server.display.layout.Layout.Display.POSITION_REAR; import android.Manifest; import android.annotation.EnforcePermission; import android.annotation.FloatRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; Loading Loading @@ -6018,6 +6019,18 @@ public final class DisplayManagerService extends SystemService { } } @Override public void setBrightnessCap( int displayId, @FloatRange(from = 0f, to = 1f) float cap, @BrightnessInfo.BrightnessMaxReason int reason) { synchronized (mSyncRoot) { if (mDisplayPowerControllers.contains(displayId)) { mDisplayPowerControllers.get(displayId).setBrightnessCap(cap, reason); } } } @Override public void onOverlayChanged() { synchronized (mSyncRoot) { Loading
services/core/java/com/android/server/display/DisplayPowerController.java +11 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static com.android.server.display.config.DisplayBrightnessMappingConfig.a import android.animation.Animator; import android.animation.ObjectAnimator; import android.annotation.FloatRange; import android.annotation.Nullable; import android.annotation.SuppressLint; import android.annotation.UserIdInt; Loading Loading @@ -3029,6 +3030,16 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } } /** * Set the brightness cap for this display. If present, this will replace the previously known * value of the cap for the provided {@link BrightnessInfo.BrightnessMaxReason} */ public void setBrightnessCap( @FloatRange(from = 0f, to = 1f) float cap, @BrightnessInfo.BrightnessMaxReason int reason) { mBrightnessClamperController.setBrightnessCap(cap, reason); } private final class DisplayControllerHandler extends Handler { DisplayControllerHandler(Looper looper) { super(looper, null, true /*async*/); Loading
services/core/java/com/android/server/display/brightness/clamper/BrightnessClamperController.java +45 −14 Original line number Diff line number Diff line Loading @@ -16,8 +16,10 @@ package com.android.server.display.brightness.clamper; import static android.service.notification.Flags.applyBrightnessClampingForModes; import static android.view.Display.STATE_ON; import android.annotation.FloatRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.Context; Loading @@ -31,6 +33,7 @@ import android.os.PowerManager; import android.provider.DeviceConfig; import android.provider.DeviceConfigInterface; import android.util.IndentingPrintWriter; import android.util.Log; import android.util.Spline; import android.view.Display; Loading Loading @@ -72,6 +75,7 @@ public class BrightnessClamperController { private final List<DeviceConfigListener> mDeviceConfigListeners = new ArrayList<>(); private ModifiersAggregatedState mModifiersAggregatedState = new ModifiersAggregatedState(); @Nullable private ExternalBrightnessModifier mExternalBrightnessModifier; private final DeviceConfig.OnPropertiesChangedListener mOnPropertiesChangedListener; Loading Loading @@ -114,7 +118,8 @@ public class BrightnessClamperController { mModifiers = injector.getModifiers(flags, context, handler, clamperChangeListenerInternal, data, currentBrightness); mModifiers.forEach(m -> { mModifiers.forEach( m -> { if (m instanceof DisplayDeviceDataListener l) { mDisplayDeviceDataListeners.add(l); } Loading @@ -127,6 +132,14 @@ public class BrightnessClamperController { if (m instanceof DeviceConfigListener l) { mDeviceConfigListeners.add(l); } if (applyBrightnessClampingForModes() && m instanceof ExternalBrightnessModifier l) { if (mExternalBrightnessModifier != null) { throw new IllegalStateException( "Cannot have more than one external brightness cap modifier"); } mExternalBrightnessModifier = l; } }); mOnPropertiesChangedListener = properties -> { mDeviceConfigListeners.forEach(DeviceConfigListener::onDeviceConfigChanged); Loading Loading @@ -251,6 +264,21 @@ public class BrightnessClamperController { } } /** Replaces the brightness cap for the provided {@link BrightnessInfo.BrightnessMaxReason} */ public void setBrightnessCap( @FloatRange(from = 0f, to = 1f) float cap, @BrightnessInfo.BrightnessMaxReason int reason) { if (!applyBrightnessClampingForModes()) { return; } if (mExternalBrightnessModifier != null) { mExternalBrightnessModifier.setBrightnessCap(cap, reason); } else { Log.e(TAG, "Unable to set brightness cap"); } } /** * Clampers change listener */ Loading @@ -276,6 +304,9 @@ public class BrightnessClamperController { modifiers.add(new BrightnessWearBedtimeModeModifier(handler, context, listener, data)); } if (applyBrightnessClampingForModes()) { modifiers.add(new ExternalBrightnessModifier(handler, listener)); } if (flags.isPowerThrottlingClamperEnabled()) { // Check if power-throttling config is present. PowerThrottlingConfigData configData = data.getPowerThrottlingConfigData(); Loading