Loading core/java/com/android/internal/display/BrightnessSynchronizer.java +5 −96 Original line number Diff line number Diff line Loading @@ -16,14 +16,10 @@ package com.android.internal.display; import static android.Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS; import android.annotation.RequiresPermission; import android.annotation.SuppressLint; import android.content.ContentResolver; import android.content.Context; import android.database.ContentObserver; import android.hardware.display.BrightnessInfo; import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager.DisplayListener; import android.net.Uri; Loading Loading @@ -75,22 +71,16 @@ public class BrightnessSynchronizer { private BrightnessUpdate mCurrentUpdate; private BrightnessUpdate mPendingUpdate; // Feature flag that will eventually be removed private final boolean mIntRangeUserPerceptionEnabled; public BrightnessSynchronizer(Context context, Looper looper, boolean intRangeUserPerceptionEnabled) { this(context, looper, SystemClock::uptimeMillis, intRangeUserPerceptionEnabled); public BrightnessSynchronizer(Context context, Looper looper) { this(context, looper, SystemClock::uptimeMillis); } @VisibleForTesting public BrightnessSynchronizer(Context context, Looper looper, Clock clock, boolean intRangeUserPerceptionEnabled) { public BrightnessSynchronizer(Context context, Looper looper, Clock clock) { mContext = context; mClock = clock; mBrightnessSyncObserver = new BrightnessSyncObserver(); mHandler = new BrightnessSynchronizerHandler(looper); mIntRangeUserPerceptionEnabled = intRangeUserPerceptionEnabled; } /** Loading Loading @@ -140,7 +130,6 @@ public class BrightnessSynchronizer { pw.println(" mLatestFloatBrightness=" + mLatestFloatBrightness); pw.println(" mCurrentUpdate=" + mCurrentUpdate); pw.println(" mPendingUpdate=" + mPendingUpdate); pw.println(" mIntRangeUserPerceptionEnabled=" + mIntRangeUserPerceptionEnabled); } /** Loading Loading @@ -297,78 +286,6 @@ public class BrightnessSynchronizer { } } /** * Converts between the int brightness setting and the float brightness system. The int * brightness setting is between 0-255 and matches the brightness slider - e.g. 128 is 50% on * the slider. Accounts for special values such as OFF and invalid values. Accounts for * brightness limits; the maximum value here represents the max value allowed on the slider. */ @RequiresPermission(CONTROL_DISPLAY_BRIGHTNESS) public static float brightnessIntSettingToFloat(Context context, int brightnessInt) { if (brightnessInt == PowerManager.BRIGHTNESS_OFF) { return PowerManager.BRIGHTNESS_OFF_FLOAT; } else if (brightnessInt == PowerManager.BRIGHTNESS_INVALID) { return PowerManager.BRIGHTNESS_INVALID_FLOAT; } else { final float minInt = PowerManager.BRIGHTNESS_OFF + 1; final float maxInt = PowerManager.BRIGHTNESS_ON; // Normalize to the range [0, 1] float userPerceptionBrightness = MathUtils.norm(minInt, maxInt, brightnessInt); // Convert from user-perception to linear scale float linearBrightness = BrightnessUtils.convertGammaToLinear(userPerceptionBrightness); // Interpolate to the range [0, currentlyAllowedMax] final Display display = context.getDisplay(); if (display == null) { return PowerManager.BRIGHTNESS_INVALID_FLOAT; } final BrightnessInfo info = display.getBrightnessInfo(); if (info == null) { return PowerManager.BRIGHTNESS_INVALID_FLOAT; } return MathUtils.lerp(info.brightnessMinimum, info.brightnessMaximum, linearBrightness); } } /** * Translates specified value from the float brightness system to the setting int brightness * system. The value returned is between 0-255 and matches the brightness slider - e.g. 128 is * 50% on the slider. Accounts for special values such as OFF and invalid values. Accounts for * brightness limits; the maximum value here represents the max value currently allowed on * the slider. */ @RequiresPermission(CONTROL_DISPLAY_BRIGHTNESS) public static int brightnessFloatToIntSetting(Context context, float brightnessFloat) { if (floatEquals(brightnessFloat, PowerManager.BRIGHTNESS_OFF_FLOAT)) { return PowerManager.BRIGHTNESS_OFF; } else if (Float.isNaN(brightnessFloat)) { return PowerManager.BRIGHTNESS_INVALID; } else { // Normalize to the range [0, 1] final Display display = context.getDisplay(); if (display == null) { return PowerManager.BRIGHTNESS_INVALID; } final BrightnessInfo info = display.getBrightnessInfo(); if (info == null) { return PowerManager.BRIGHTNESS_INVALID; } float linearBrightness = MathUtils.norm(info.brightnessMinimum, info.brightnessMaximum, brightnessFloat); // Convert from linear to user-perception scale float userPerceptionBrightness = BrightnessUtils.convertLinearToGamma(linearBrightness); // Interpolate to the range [0, 255] final float minInt = PowerManager.BRIGHTNESS_OFF + 1; final float maxInt = PowerManager.BRIGHTNESS_ON; float intBrightness = MathUtils.lerp(minInt, maxInt, userPerceptionBrightness); return Math.round(intBrightness); } } /** * Encapsulates a brightness change event and contains logic for synchronizing the appropriate * settings for the specified brightness change. Loading Loading @@ -508,24 +425,16 @@ public class BrightnessSynchronizer { if (mSourceType == TYPE_INT) { return (int) mBrightness; } if (mIntRangeUserPerceptionEnabled) { return brightnessFloatToIntSetting(mContext, mBrightness); } else { return brightnessFloatToInt(mBrightness); } } @SuppressLint("AndroidFrameworkRequiresPermission") private float getBrightnessAsFloat() { if (mSourceType == TYPE_FLOAT) { return mBrightness; } if (mIntRangeUserPerceptionEnabled) { return brightnessIntSettingToFloat(mContext, (int) mBrightness); } else { return brightnessIntToFloat((int) mBrightness); } } private String toStringLabel(int type, float brightness) { return (type == TYPE_INT) ? ((int) brightness) + "(i)" Loading services/core/java/com/android/server/display/DisplayManagerService.java +1 −2 Original line number Diff line number Diff line Loading @@ -654,8 +654,7 @@ public final class DisplayManagerService extends SystemService { mDisplayDeviceRepo, new LogicalDisplayListener(), mSyncRoot, mHandler, mFlags); mDisplayModeDirector = new DisplayModeDirector( context, mHandler, mFlags, mDisplayDeviceConfigProvider); mBrightnessSynchronizer = new BrightnessSynchronizer(mContext, displayThreadLooper, mFlags.isBrightnessIntRangeUserPerceptionEnabled()); mBrightnessSynchronizer = new BrightnessSynchronizer(mContext, displayThreadLooper); Resources resources = mContext.getResources(); mDefaultDisplayDefaultColorMode = mContext.getResources().getInteger( com.android.internal.R.integer.config_defaultDisplayDefaultColorMode); Loading services/core/java/com/android/server/display/DisplayPowerController.java +1 −3 Original line number Diff line number Diff line Loading @@ -2848,9 +2848,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call if (mBatteryStats != null) { try { // TODO(brightnessfloat): change BatteryStats to use float int brightnessInt = mFlags.isBrightnessIntRangeUserPerceptionEnabled() ? BrightnessSynchronizer.brightnessFloatToIntSetting(mContext, brightness) : BrightnessSynchronizer.brightnessFloatToInt(brightness); int brightnessInt = BrightnessSynchronizer.brightnessFloatToInt(brightness); mBatteryStats.noteScreenBrightness(mDisplayId, brightnessInt); } catch (RemoteException e) { // same process Loading services/core/java/com/android/server/display/feature/DisplayManagerFlags.java +0 −9 Original line number Diff line number Diff line Loading @@ -85,10 +85,6 @@ public class DisplayManagerFlags { com.android.graphics.surfaceflinger.flags.Flags::syncedResolutionSwitch ); private final FlagState mBrightnessIntRangeUserPerceptionFlagState = new FlagState( Flags.FLAG_BRIGHTNESS_INT_RANGE_USER_PERCEPTION, Flags::brightnessIntRangeUserPerception); private final FlagState mResolutionBackupRestore = new FlagState( Flags.FLAG_RESOLUTION_BACKUP_RESTORE, Flags::resolutionBackupRestore); Loading Loading @@ -341,10 +337,6 @@ public class DisplayManagerFlags { return mSyncedResolutionSwitch.isEnabled(); } public boolean isBrightnessIntRangeUserPerceptionEnabled() { return mBrightnessIntRangeUserPerceptionFlagState.isEnabled(); } public boolean isResolutionBackupRestoreEnabled() { return mResolutionBackupRestore.isEnabled(); } Loading Loading @@ -577,7 +569,6 @@ public class DisplayManagerFlags { pw.println(" " + mSmallAreaDetectionFlagState); pw.println(" " + mDisplayConfigErrorHalFlagState); pw.println(" " + mSyncedResolutionSwitch); pw.println(" " + mBrightnessIntRangeUserPerceptionFlagState); pw.println(" " + mBrightnessWearBedtimeModeClamperFlagState); pw.println(" " + mAutoBrightnessModesFlagState); pw.println(" " + mFastHdrTransitions); Loading services/core/java/com/android/server/display/feature/display_flags.aconfig +0 −8 Original line number Diff line number Diff line Loading @@ -107,14 +107,6 @@ flag { is_fixed_read_only: true } flag { name: "brightness_int_range_user_perception" namespace: "display_manager" description: "Feature flag for converting the brightness integer range to the user perception scale" bug: "319236956" is_fixed_read_only: true } flag { name: "enable_vsync_low_power_vote" namespace: "display_manager" Loading Loading
core/java/com/android/internal/display/BrightnessSynchronizer.java +5 −96 Original line number Diff line number Diff line Loading @@ -16,14 +16,10 @@ package com.android.internal.display; import static android.Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS; import android.annotation.RequiresPermission; import android.annotation.SuppressLint; import android.content.ContentResolver; import android.content.Context; import android.database.ContentObserver; import android.hardware.display.BrightnessInfo; import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager.DisplayListener; import android.net.Uri; Loading Loading @@ -75,22 +71,16 @@ public class BrightnessSynchronizer { private BrightnessUpdate mCurrentUpdate; private BrightnessUpdate mPendingUpdate; // Feature flag that will eventually be removed private final boolean mIntRangeUserPerceptionEnabled; public BrightnessSynchronizer(Context context, Looper looper, boolean intRangeUserPerceptionEnabled) { this(context, looper, SystemClock::uptimeMillis, intRangeUserPerceptionEnabled); public BrightnessSynchronizer(Context context, Looper looper) { this(context, looper, SystemClock::uptimeMillis); } @VisibleForTesting public BrightnessSynchronizer(Context context, Looper looper, Clock clock, boolean intRangeUserPerceptionEnabled) { public BrightnessSynchronizer(Context context, Looper looper, Clock clock) { mContext = context; mClock = clock; mBrightnessSyncObserver = new BrightnessSyncObserver(); mHandler = new BrightnessSynchronizerHandler(looper); mIntRangeUserPerceptionEnabled = intRangeUserPerceptionEnabled; } /** Loading Loading @@ -140,7 +130,6 @@ public class BrightnessSynchronizer { pw.println(" mLatestFloatBrightness=" + mLatestFloatBrightness); pw.println(" mCurrentUpdate=" + mCurrentUpdate); pw.println(" mPendingUpdate=" + mPendingUpdate); pw.println(" mIntRangeUserPerceptionEnabled=" + mIntRangeUserPerceptionEnabled); } /** Loading Loading @@ -297,78 +286,6 @@ public class BrightnessSynchronizer { } } /** * Converts between the int brightness setting and the float brightness system. The int * brightness setting is between 0-255 and matches the brightness slider - e.g. 128 is 50% on * the slider. Accounts for special values such as OFF and invalid values. Accounts for * brightness limits; the maximum value here represents the max value allowed on the slider. */ @RequiresPermission(CONTROL_DISPLAY_BRIGHTNESS) public static float brightnessIntSettingToFloat(Context context, int brightnessInt) { if (brightnessInt == PowerManager.BRIGHTNESS_OFF) { return PowerManager.BRIGHTNESS_OFF_FLOAT; } else if (brightnessInt == PowerManager.BRIGHTNESS_INVALID) { return PowerManager.BRIGHTNESS_INVALID_FLOAT; } else { final float minInt = PowerManager.BRIGHTNESS_OFF + 1; final float maxInt = PowerManager.BRIGHTNESS_ON; // Normalize to the range [0, 1] float userPerceptionBrightness = MathUtils.norm(minInt, maxInt, brightnessInt); // Convert from user-perception to linear scale float linearBrightness = BrightnessUtils.convertGammaToLinear(userPerceptionBrightness); // Interpolate to the range [0, currentlyAllowedMax] final Display display = context.getDisplay(); if (display == null) { return PowerManager.BRIGHTNESS_INVALID_FLOAT; } final BrightnessInfo info = display.getBrightnessInfo(); if (info == null) { return PowerManager.BRIGHTNESS_INVALID_FLOAT; } return MathUtils.lerp(info.brightnessMinimum, info.brightnessMaximum, linearBrightness); } } /** * Translates specified value from the float brightness system to the setting int brightness * system. The value returned is between 0-255 and matches the brightness slider - e.g. 128 is * 50% on the slider. Accounts for special values such as OFF and invalid values. Accounts for * brightness limits; the maximum value here represents the max value currently allowed on * the slider. */ @RequiresPermission(CONTROL_DISPLAY_BRIGHTNESS) public static int brightnessFloatToIntSetting(Context context, float brightnessFloat) { if (floatEquals(brightnessFloat, PowerManager.BRIGHTNESS_OFF_FLOAT)) { return PowerManager.BRIGHTNESS_OFF; } else if (Float.isNaN(brightnessFloat)) { return PowerManager.BRIGHTNESS_INVALID; } else { // Normalize to the range [0, 1] final Display display = context.getDisplay(); if (display == null) { return PowerManager.BRIGHTNESS_INVALID; } final BrightnessInfo info = display.getBrightnessInfo(); if (info == null) { return PowerManager.BRIGHTNESS_INVALID; } float linearBrightness = MathUtils.norm(info.brightnessMinimum, info.brightnessMaximum, brightnessFloat); // Convert from linear to user-perception scale float userPerceptionBrightness = BrightnessUtils.convertLinearToGamma(linearBrightness); // Interpolate to the range [0, 255] final float minInt = PowerManager.BRIGHTNESS_OFF + 1; final float maxInt = PowerManager.BRIGHTNESS_ON; float intBrightness = MathUtils.lerp(minInt, maxInt, userPerceptionBrightness); return Math.round(intBrightness); } } /** * Encapsulates a brightness change event and contains logic for synchronizing the appropriate * settings for the specified brightness change. Loading Loading @@ -508,24 +425,16 @@ public class BrightnessSynchronizer { if (mSourceType == TYPE_INT) { return (int) mBrightness; } if (mIntRangeUserPerceptionEnabled) { return brightnessFloatToIntSetting(mContext, mBrightness); } else { return brightnessFloatToInt(mBrightness); } } @SuppressLint("AndroidFrameworkRequiresPermission") private float getBrightnessAsFloat() { if (mSourceType == TYPE_FLOAT) { return mBrightness; } if (mIntRangeUserPerceptionEnabled) { return brightnessIntSettingToFloat(mContext, (int) mBrightness); } else { return brightnessIntToFloat((int) mBrightness); } } private String toStringLabel(int type, float brightness) { return (type == TYPE_INT) ? ((int) brightness) + "(i)" Loading
services/core/java/com/android/server/display/DisplayManagerService.java +1 −2 Original line number Diff line number Diff line Loading @@ -654,8 +654,7 @@ public final class DisplayManagerService extends SystemService { mDisplayDeviceRepo, new LogicalDisplayListener(), mSyncRoot, mHandler, mFlags); mDisplayModeDirector = new DisplayModeDirector( context, mHandler, mFlags, mDisplayDeviceConfigProvider); mBrightnessSynchronizer = new BrightnessSynchronizer(mContext, displayThreadLooper, mFlags.isBrightnessIntRangeUserPerceptionEnabled()); mBrightnessSynchronizer = new BrightnessSynchronizer(mContext, displayThreadLooper); Resources resources = mContext.getResources(); mDefaultDisplayDefaultColorMode = mContext.getResources().getInteger( com.android.internal.R.integer.config_defaultDisplayDefaultColorMode); Loading
services/core/java/com/android/server/display/DisplayPowerController.java +1 −3 Original line number Diff line number Diff line Loading @@ -2848,9 +2848,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call if (mBatteryStats != null) { try { // TODO(brightnessfloat): change BatteryStats to use float int brightnessInt = mFlags.isBrightnessIntRangeUserPerceptionEnabled() ? BrightnessSynchronizer.brightnessFloatToIntSetting(mContext, brightness) : BrightnessSynchronizer.brightnessFloatToInt(brightness); int brightnessInt = BrightnessSynchronizer.brightnessFloatToInt(brightness); mBatteryStats.noteScreenBrightness(mDisplayId, brightnessInt); } catch (RemoteException e) { // same process Loading
services/core/java/com/android/server/display/feature/DisplayManagerFlags.java +0 −9 Original line number Diff line number Diff line Loading @@ -85,10 +85,6 @@ public class DisplayManagerFlags { com.android.graphics.surfaceflinger.flags.Flags::syncedResolutionSwitch ); private final FlagState mBrightnessIntRangeUserPerceptionFlagState = new FlagState( Flags.FLAG_BRIGHTNESS_INT_RANGE_USER_PERCEPTION, Flags::brightnessIntRangeUserPerception); private final FlagState mResolutionBackupRestore = new FlagState( Flags.FLAG_RESOLUTION_BACKUP_RESTORE, Flags::resolutionBackupRestore); Loading Loading @@ -341,10 +337,6 @@ public class DisplayManagerFlags { return mSyncedResolutionSwitch.isEnabled(); } public boolean isBrightnessIntRangeUserPerceptionEnabled() { return mBrightnessIntRangeUserPerceptionFlagState.isEnabled(); } public boolean isResolutionBackupRestoreEnabled() { return mResolutionBackupRestore.isEnabled(); } Loading Loading @@ -577,7 +569,6 @@ public class DisplayManagerFlags { pw.println(" " + mSmallAreaDetectionFlagState); pw.println(" " + mDisplayConfigErrorHalFlagState); pw.println(" " + mSyncedResolutionSwitch); pw.println(" " + mBrightnessIntRangeUserPerceptionFlagState); pw.println(" " + mBrightnessWearBedtimeModeClamperFlagState); pw.println(" " + mAutoBrightnessModesFlagState); pw.println(" " + mFastHdrTransitions); Loading
services/core/java/com/android/server/display/feature/display_flags.aconfig +0 −8 Original line number Diff line number Diff line Loading @@ -107,14 +107,6 @@ flag { is_fixed_read_only: true } flag { name: "brightness_int_range_user_perception" namespace: "display_manager" description: "Feature flag for converting the brightness integer range to the user perception scale" bug: "319236956" is_fixed_read_only: true } flag { name: "enable_vsync_low_power_vote" namespace: "display_manager" Loading