Merge "Pass DisplayDeviceConfig to AutomaticBrightness" into rvc-dev

This commit is contained in:
Fiona Campbell
2020-04-06 18:03:51 +00:00
committed by Android (Google) Code Review
6 changed files with 50 additions and 19 deletions

View File

@@ -200,7 +200,7 @@ class AutomaticBrightnessController {
// Context-sensitive brightness configurations require keeping track of the foreground app's // Context-sensitive brightness configurations require keeping track of the foreground app's
// package name and category, which is done by registering a TaskStackListener to call back to // package name and category, which is done by registering a TaskStackListener to call back to
// us onTaskStackChanged, and then using the ActivityTaskManager to get the foreground app's // us onTaskStackChanged, and then using the ActivityTaskManager to get the foreground app's
// package namd and PackageManager to get its category (so might as well cache them). // package name and PackageManager to get its category (so might as well cache them).
private String mForegroundAppPackageName; private String mForegroundAppPackageName;
private String mPendingForegroundAppPackageName; private String mPendingForegroundAppPackageName;
private @ApplicationInfo.Category int mForegroundAppCategory; private @ApplicationInfo.Category int mForegroundAppCategory;
@@ -210,6 +210,7 @@ class AutomaticBrightnessController {
private PackageManager mPackageManager; private PackageManager mPackageManager;
private Context mContext; private Context mContext;
private DisplayDeviceConfig mDisplayDeviceConfig;
private final Injector mInjector; private final Injector mInjector;
AutomaticBrightnessController(Callbacks callbacks, Looper looper, AutomaticBrightnessController(Callbacks callbacks, Looper looper,
@@ -218,12 +219,14 @@ class AutomaticBrightnessController {
float dozeScaleFactor, int lightSensorRate, int initialLightSensorRate, float dozeScaleFactor, int lightSensorRate, int initialLightSensorRate,
long brighteningLightDebounceConfig, long darkeningLightDebounceConfig, long brighteningLightDebounceConfig, long darkeningLightDebounceConfig,
boolean resetAmbientLuxAfterWarmUpConfig, HysteresisLevels ambientBrightnessThresholds, boolean resetAmbientLuxAfterWarmUpConfig, HysteresisLevels ambientBrightnessThresholds,
HysteresisLevels screenBrightnessThresholds, Context context) { HysteresisLevels screenBrightnessThresholds, Context context, DisplayDeviceConfig
displayDeviceConfig) {
this(new Injector(), callbacks, looper, sensorManager, lightSensor, mapper, this(new Injector(), callbacks, looper, sensorManager, lightSensor, mapper,
lightSensorWarmUpTime, brightnessMin, brightnessMax, dozeScaleFactor, lightSensorWarmUpTime, brightnessMin, brightnessMax, dozeScaleFactor,
lightSensorRate, initialLightSensorRate, brighteningLightDebounceConfig, lightSensorRate, initialLightSensorRate, brighteningLightDebounceConfig,
darkeningLightDebounceConfig, resetAmbientLuxAfterWarmUpConfig, darkeningLightDebounceConfig, resetAmbientLuxAfterWarmUpConfig,
ambientBrightnessThresholds, screenBrightnessThresholds, context); ambientBrightnessThresholds, screenBrightnessThresholds, context,
displayDeviceConfig);
} }
@VisibleForTesting @VisibleForTesting
@@ -233,7 +236,8 @@ class AutomaticBrightnessController {
float dozeScaleFactor, int lightSensorRate, int initialLightSensorRate, float dozeScaleFactor, int lightSensorRate, int initialLightSensorRate,
long brighteningLightDebounceConfig, long darkeningLightDebounceConfig, long brighteningLightDebounceConfig, long darkeningLightDebounceConfig,
boolean resetAmbientLuxAfterWarmUpConfig, HysteresisLevels ambientBrightnessThresholds, boolean resetAmbientLuxAfterWarmUpConfig, HysteresisLevels ambientBrightnessThresholds,
HysteresisLevels screenBrightnessThresholds, Context context) { HysteresisLevels screenBrightnessThresholds, Context context, DisplayDeviceConfig
displayDeviceConfig) {
mInjector = injector; mInjector = injector;
mContext = context; mContext = context;
mCallbacks = callbacks; mCallbacks = callbacks;
@@ -260,7 +264,7 @@ class AutomaticBrightnessController {
mScreenBrightnessThresholds = screenBrightnessThresholds; mScreenBrightnessThresholds = screenBrightnessThresholds;
mShortTermModelValid = true; mShortTermModelValid = true;
mShortTermModelAnchor = -1; mShortTermModelAnchor = -1;
mDisplayDeviceConfig = displayDeviceConfig;
mHandler = new AutomaticBrightnessHandler(looper); mHandler = new AutomaticBrightnessHandler(looper);
mAmbientLightRingBuffer = mAmbientLightRingBuffer =
new AmbientLightRingBuffer(mNormalLightSensorRate, mAmbientLightHorizon); new AmbientLightRingBuffer(mNormalLightSensorRate, mAmbientLightHorizon);

View File

@@ -37,6 +37,7 @@ abstract class DisplayDevice {
private final DisplayAdapter mDisplayAdapter; private final DisplayAdapter mDisplayAdapter;
private final IBinder mDisplayToken; private final IBinder mDisplayToken;
private final String mUniqueId; private final String mUniqueId;
private DisplayDeviceConfig mDisplayDeviceConfig;
// The display device does not manage these properties itself, they are set by // The display device does not manage these properties itself, they are set by
// the display manager service. The display device shouldn't really be looking at these. // the display manager service. The display device shouldn't really be looking at these.
@@ -68,6 +69,16 @@ abstract class DisplayDevice {
return mDisplayAdapter; return mDisplayAdapter;
} }
/*
* Gets the DisplayDeviceConfig for this DisplayDevice.
* Returns null for this device but is overridden in LocalDisplayDevice.
*
* @return The DisplayDeviceConfig.
*/
public DisplayDeviceConfig getDisplayDeviceConfig() {
return mDisplayDeviceConfig;
}
/** /**
* Gets the Surface Flinger display token for this display. * Gets the Surface Flinger display token for this display.
* *

View File

@@ -2476,7 +2476,8 @@ public final class DisplayManagerService extends SystemService {
} }
}; };
mDisplayPowerController = new DisplayPowerController( mDisplayPowerController = new DisplayPowerController(
mContext, callbacks, handler, sensorManager, blanker); mContext, callbacks, handler, sensorManager, blanker,
mDisplayDevices.get(Display.DEFAULT_DISPLAY));
mSensorManager = sensorManager; mSensorManager = sensorManager;
} }

View File

@@ -161,6 +161,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
// The display blanker. // The display blanker.
private final DisplayBlanker mBlanker; private final DisplayBlanker mBlanker;
// The display device.
private final DisplayDevice mDisplayDevice;
// Tracker for brightness changes. // Tracker for brightness changes.
private final BrightnessTracker mBrightnessTracker; private final BrightnessTracker mBrightnessTracker;
@@ -348,11 +351,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
@Nullable @Nullable
private BrightnessConfiguration mBrightnessConfiguration; private BrightnessConfiguration mBrightnessConfiguration;
// The last brightness that was set by the user and not temporary. Set to -1 when a brightness // The last brightness that was set by the user and not temporary. Set to
// has yet to be recorded. // PowerManager.BRIGHTNESS_INVALID_FLOAT when a brightness has yet to be recorded.
private float mLastUserSetScreenBrightness; private float mLastUserSetScreenBrightness;
// The screen brightenss setting has changed but not taken effect yet. If this is different // The screen brightness setting has changed but not taken effect yet. If this is different
// from the current screen brightness setting then this is coming from something other than us // from the current screen brightness setting then this is coming from something other than us
// and should be considered a user interaction. // and should be considered a user interaction.
private float mPendingScreenBrightnessSetting; private float mPendingScreenBrightnessSetting;
@@ -377,8 +380,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
private float mPendingAutoBrightnessAdjustment; private float mPendingAutoBrightnessAdjustment;
// The temporary auto brightness adjustment. Typically set when a user is interacting with the // The temporary auto brightness adjustment. Typically set when a user is interacting with the
// adjustment slider but hasn't settled on a choice yet. Set to Float.NaN when there's no // adjustment slider but hasn't settled on a choice yet. Set to
// temporary adjustment set. // PowerManager.BRIGHTNESS_INVALID_FLOAT when there's no temporary adjustment set.
private float mTemporaryAutoBrightnessAdjustment; private float mTemporaryAutoBrightnessAdjustment;
// Animators. // Animators.
@@ -386,27 +389,29 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
private ObjectAnimator mColorFadeOffAnimator; private ObjectAnimator mColorFadeOffAnimator;
private RampAnimator<DisplayPowerState> mScreenBrightnessRampAnimator; private RampAnimator<DisplayPowerState> mScreenBrightnessRampAnimator;
private BrightnessSynchronizer mBrightnessSynchronizer;
/** /**
* Creates the display power controller. * Creates the display power controller.
*/ */
public DisplayPowerController(Context context, public DisplayPowerController(Context context,
DisplayPowerCallbacks callbacks, Handler handler, DisplayPowerCallbacks callbacks, Handler handler,
SensorManager sensorManager, DisplayBlanker blanker) { SensorManager sensorManager, DisplayBlanker blanker, DisplayDevice displayDevice) {
mHandler = new DisplayControllerHandler(handler.getLooper()); mHandler = new DisplayControllerHandler(handler.getLooper());
mBrightnessTracker = new BrightnessTracker(context, null); mBrightnessTracker = new BrightnessTracker(context, null);
mSettingsObserver = new SettingsObserver(mHandler); mSettingsObserver = new SettingsObserver(mHandler);
mCallbacks = callbacks; mCallbacks = callbacks;
mBrightnessSynchronizer = new BrightnessSynchronizer(context);
mBatteryStats = BatteryStatsService.getService(); mBatteryStats = BatteryStatsService.getService();
mSensorManager = sensorManager; mSensorManager = sensorManager;
mWindowManagerPolicy = LocalServices.getService(WindowManagerPolicy.class); mWindowManagerPolicy = LocalServices.getService(WindowManagerPolicy.class);
mBlanker = blanker; mBlanker = blanker;
mContext = context; mContext = context;
mDisplayDevice = displayDevice;
PowerManager pm = context.getSystemService(PowerManager.class); PowerManager pm = context.getSystemService(PowerManager.class);
DisplayDeviceConfig displayDeviceConfig = mDisplayDevice.getDisplayDeviceConfig();
final Resources resources = context.getResources(); final Resources resources = context.getResources();
final float screenBrightnessSettingMinimumFloat = clampAbsoluteBrightness( final float screenBrightnessSettingMinimumFloat = clampAbsoluteBrightness(
pm.getBrightnessConstraint(PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM)); pm.getBrightnessConstraint(PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM));
@@ -498,7 +503,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
mScreenBrightnessRangeMaximum, dozeScaleFactor, lightSensorRate, mScreenBrightnessRangeMaximum, dozeScaleFactor, lightSensorRate,
initialLightSensorRate, brighteningLightDebounce, darkeningLightDebounce, initialLightSensorRate, brighteningLightDebounce, darkeningLightDebounce,
autoBrightnessResetAmbientLuxAfterWarmUp, ambientBrightnessThresholds, autoBrightnessResetAmbientLuxAfterWarmUp, ambientBrightnessThresholds,
screenBrightnessThresholds, context); screenBrightnessThresholds, context, displayDeviceConfig);
} else { } else {
mUseSoftwareAutoBrightnessConfig = false; mUseSoftwareAutoBrightnessConfig = false;
} }

View File

@@ -203,6 +203,8 @@ final class LocalDisplayAdapter extends DisplayAdapter {
private Spline mNitsToHalBrightness; private Spline mNitsToHalBrightness;
private boolean mHalBrightnessSupport; private boolean mHalBrightnessSupport;
private DisplayDeviceConfig mDisplayDeviceConfig;
LocalDisplayDevice(IBinder displayToken, long physicalDisplayId, LocalDisplayDevice(IBinder displayToken, long physicalDisplayId,
SurfaceControl.DisplayInfo info, SurfaceControl.DisplayConfig[] configs, SurfaceControl.DisplayInfo info, SurfaceControl.DisplayConfig[] configs,
int activeConfigId, SurfaceControl.DesiredDisplayConfigSpecs configSpecs, int activeConfigId, SurfaceControl.DesiredDisplayConfigSpecs configSpecs,
@@ -224,7 +226,7 @@ final class LocalDisplayAdapter extends DisplayAdapter {
mAllmSupported = SurfaceControl.getAutoLowLatencyModeSupport(displayToken); mAllmSupported = SurfaceControl.getAutoLowLatencyModeSupport(displayToken);
mGameContentTypeSupported = SurfaceControl.getGameContentTypeSupport(displayToken); mGameContentTypeSupported = SurfaceControl.getGameContentTypeSupport(displayToken);
mHalBrightnessSupport = SurfaceControl.getDisplayBrightnessSupport(displayToken); mHalBrightnessSupport = SurfaceControl.getDisplayBrightnessSupport(displayToken);
mDisplayDeviceConfig = null;
// Defer configuration file loading // Defer configuration file loading
BackgroundThread.getHandler().sendMessage(PooledLambda.obtainMessage( BackgroundThread.getHandler().sendMessage(PooledLambda.obtainMessage(
LocalDisplayDevice::loadDisplayConfigurationBrightnessMapping, this)); LocalDisplayDevice::loadDisplayConfigurationBrightnessMapping, this));
@@ -373,17 +375,23 @@ final class LocalDisplayAdapter extends DisplayAdapter {
return true; return true;
} }
@Override
public DisplayDeviceConfig getDisplayDeviceConfig() {
return mDisplayDeviceConfig;
}
private void loadDisplayConfigurationBrightnessMapping() { private void loadDisplayConfigurationBrightnessMapping() {
Spline nitsToHal = null; Spline nitsToHal = null;
Spline sysToNits = null; Spline sysToNits = null;
// Load the mapping from nits to HAL brightness range (display-device-config.xml) // Load the mapping from nits to HAL brightness range (display-device-config.xml)
DisplayDeviceConfig config = DisplayDeviceConfig.create(mPhysicalDisplayId); DisplayDeviceConfig config = DisplayDeviceConfig.create(mPhysicalDisplayId);
mDisplayDeviceConfig = config;
if (config == null) { if (config == null) {
return; return;
} }
final float[] halNits = config.getNits(); final float[] halNits = mDisplayDeviceConfig.getNits();
final float[] halBrightness = config.getBrightness(); final float[] halBrightness = mDisplayDeviceConfig.getBrightness();
if (halNits == null || halBrightness == null) { if (halNits == null || halBrightness == null) {
return; return;
} }

View File

@@ -60,6 +60,7 @@ public class AutomaticBrightnessControllerTest {
@Mock HysteresisLevels mAmbientBrightnessThresholds; @Mock HysteresisLevels mAmbientBrightnessThresholds;
@Mock HysteresisLevels mScreenBrightnessThresholds; @Mock HysteresisLevels mScreenBrightnessThresholds;
@Mock Handler mNoopHandler; @Mock Handler mNoopHandler;
@Mock DisplayDeviceConfig mDisplayDeviceConfig;
private static final int LIGHT_SENSOR_WARMUP_TIME = 0; private static final int LIGHT_SENSOR_WARMUP_TIME = 0;
@Before @Before
@@ -82,7 +83,8 @@ public class AutomaticBrightnessControllerTest {
BRIGHTNESS_MAX_FLOAT, DOZE_SCALE_FACTOR, LIGHT_SENSOR_RATE, BRIGHTNESS_MAX_FLOAT, DOZE_SCALE_FACTOR, LIGHT_SENSOR_RATE,
INITIAL_LIGHT_SENSOR_RATE, BRIGHTENING_LIGHT_DEBOUNCE_CONFIG, INITIAL_LIGHT_SENSOR_RATE, BRIGHTENING_LIGHT_DEBOUNCE_CONFIG,
DARKENING_LIGHT_DEBOUNCE_CONFIG, RESET_AMBIENT_LUX_AFTER_WARMUP_CONFIG, DARKENING_LIGHT_DEBOUNCE_CONFIG, RESET_AMBIENT_LUX_AFTER_WARMUP_CONFIG,
mAmbientBrightnessThresholds, mScreenBrightnessThresholds, mContext); mAmbientBrightnessThresholds, mScreenBrightnessThresholds, mContext,
mDisplayDeviceConfig);
controller.setLoggingEnabled(true); controller.setLoggingEnabled(true);
// Configure the brightness controller and grab an instance of the sensor listener, // Configure the brightness controller and grab an instance of the sensor listener,