Merge "Pass DisplayDeviceConfig to AutomaticBrightness" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b533ef703b
@@ -200,7 +200,7 @@ class AutomaticBrightnessController {
|
||||
// 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
|
||||
// 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 mPendingForegroundAppPackageName;
|
||||
private @ApplicationInfo.Category int mForegroundAppCategory;
|
||||
@@ -210,6 +210,7 @@ class AutomaticBrightnessController {
|
||||
private PackageManager mPackageManager;
|
||||
private Context mContext;
|
||||
|
||||
private DisplayDeviceConfig mDisplayDeviceConfig;
|
||||
private final Injector mInjector;
|
||||
|
||||
AutomaticBrightnessController(Callbacks callbacks, Looper looper,
|
||||
@@ -218,12 +219,14 @@ class AutomaticBrightnessController {
|
||||
float dozeScaleFactor, int lightSensorRate, int initialLightSensorRate,
|
||||
long brighteningLightDebounceConfig, long darkeningLightDebounceConfig,
|
||||
boolean resetAmbientLuxAfterWarmUpConfig, HysteresisLevels ambientBrightnessThresholds,
|
||||
HysteresisLevels screenBrightnessThresholds, Context context) {
|
||||
HysteresisLevels screenBrightnessThresholds, Context context, DisplayDeviceConfig
|
||||
displayDeviceConfig) {
|
||||
this(new Injector(), callbacks, looper, sensorManager, lightSensor, mapper,
|
||||
lightSensorWarmUpTime, brightnessMin, brightnessMax, dozeScaleFactor,
|
||||
lightSensorRate, initialLightSensorRate, brighteningLightDebounceConfig,
|
||||
darkeningLightDebounceConfig, resetAmbientLuxAfterWarmUpConfig,
|
||||
ambientBrightnessThresholds, screenBrightnessThresholds, context);
|
||||
ambientBrightnessThresholds, screenBrightnessThresholds, context,
|
||||
displayDeviceConfig);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -233,7 +236,8 @@ class AutomaticBrightnessController {
|
||||
float dozeScaleFactor, int lightSensorRate, int initialLightSensorRate,
|
||||
long brighteningLightDebounceConfig, long darkeningLightDebounceConfig,
|
||||
boolean resetAmbientLuxAfterWarmUpConfig, HysteresisLevels ambientBrightnessThresholds,
|
||||
HysteresisLevels screenBrightnessThresholds, Context context) {
|
||||
HysteresisLevels screenBrightnessThresholds, Context context, DisplayDeviceConfig
|
||||
displayDeviceConfig) {
|
||||
mInjector = injector;
|
||||
mContext = context;
|
||||
mCallbacks = callbacks;
|
||||
@@ -260,7 +264,7 @@ class AutomaticBrightnessController {
|
||||
mScreenBrightnessThresholds = screenBrightnessThresholds;
|
||||
mShortTermModelValid = true;
|
||||
mShortTermModelAnchor = -1;
|
||||
|
||||
mDisplayDeviceConfig = displayDeviceConfig;
|
||||
mHandler = new AutomaticBrightnessHandler(looper);
|
||||
mAmbientLightRingBuffer =
|
||||
new AmbientLightRingBuffer(mNormalLightSensorRate, mAmbientLightHorizon);
|
||||
|
||||
@@ -37,6 +37,7 @@ abstract class DisplayDevice {
|
||||
private final DisplayAdapter mDisplayAdapter;
|
||||
private final IBinder mDisplayToken;
|
||||
private final String mUniqueId;
|
||||
private DisplayDeviceConfig mDisplayDeviceConfig;
|
||||
|
||||
// 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.
|
||||
@@ -68,6 +69,16 @@ abstract class DisplayDevice {
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -2476,7 +2476,8 @@ public final class DisplayManagerService extends SystemService {
|
||||
}
|
||||
};
|
||||
mDisplayPowerController = new DisplayPowerController(
|
||||
mContext, callbacks, handler, sensorManager, blanker);
|
||||
mContext, callbacks, handler, sensorManager, blanker,
|
||||
mDisplayDevices.get(Display.DEFAULT_DISPLAY));
|
||||
mSensorManager = sensorManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -161,6 +161,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
||||
// The display blanker.
|
||||
private final DisplayBlanker mBlanker;
|
||||
|
||||
// The display device.
|
||||
private final DisplayDevice mDisplayDevice;
|
||||
|
||||
// Tracker for brightness changes.
|
||||
private final BrightnessTracker mBrightnessTracker;
|
||||
|
||||
@@ -348,11 +351,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
||||
@Nullable
|
||||
private BrightnessConfiguration mBrightnessConfiguration;
|
||||
|
||||
// The last brightness that was set by the user and not temporary. Set to -1 when a brightness
|
||||
// has yet to be recorded.
|
||||
// The last brightness that was set by the user and not temporary. Set to
|
||||
// PowerManager.BRIGHTNESS_INVALID_FLOAT when a brightness has yet to be recorded.
|
||||
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
|
||||
// and should be considered a user interaction.
|
||||
private float mPendingScreenBrightnessSetting;
|
||||
@@ -377,8 +380,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
||||
private float mPendingAutoBrightnessAdjustment;
|
||||
|
||||
// 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
|
||||
// temporary adjustment set.
|
||||
// adjustment slider but hasn't settled on a choice yet. Set to
|
||||
// PowerManager.BRIGHTNESS_INVALID_FLOAT when there's no temporary adjustment set.
|
||||
private float mTemporaryAutoBrightnessAdjustment;
|
||||
|
||||
// Animators.
|
||||
@@ -386,27 +389,29 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
||||
private ObjectAnimator mColorFadeOffAnimator;
|
||||
private RampAnimator<DisplayPowerState> mScreenBrightnessRampAnimator;
|
||||
|
||||
private BrightnessSynchronizer mBrightnessSynchronizer;
|
||||
|
||||
/**
|
||||
* Creates the display power controller.
|
||||
*/
|
||||
public DisplayPowerController(Context context,
|
||||
DisplayPowerCallbacks callbacks, Handler handler,
|
||||
SensorManager sensorManager, DisplayBlanker blanker) {
|
||||
SensorManager sensorManager, DisplayBlanker blanker, DisplayDevice displayDevice) {
|
||||
mHandler = new DisplayControllerHandler(handler.getLooper());
|
||||
mBrightnessTracker = new BrightnessTracker(context, null);
|
||||
mSettingsObserver = new SettingsObserver(mHandler);
|
||||
mCallbacks = callbacks;
|
||||
mBrightnessSynchronizer = new BrightnessSynchronizer(context);
|
||||
mBatteryStats = BatteryStatsService.getService();
|
||||
mSensorManager = sensorManager;
|
||||
mWindowManagerPolicy = LocalServices.getService(WindowManagerPolicy.class);
|
||||
mBlanker = blanker;
|
||||
mContext = context;
|
||||
mDisplayDevice = displayDevice;
|
||||
|
||||
PowerManager pm = context.getSystemService(PowerManager.class);
|
||||
DisplayDeviceConfig displayDeviceConfig = mDisplayDevice.getDisplayDeviceConfig();
|
||||
|
||||
final Resources resources = context.getResources();
|
||||
|
||||
final float screenBrightnessSettingMinimumFloat = clampAbsoluteBrightness(
|
||||
pm.getBrightnessConstraint(PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM));
|
||||
|
||||
@@ -498,7 +503,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
||||
mScreenBrightnessRangeMaximum, dozeScaleFactor, lightSensorRate,
|
||||
initialLightSensorRate, brighteningLightDebounce, darkeningLightDebounce,
|
||||
autoBrightnessResetAmbientLuxAfterWarmUp, ambientBrightnessThresholds,
|
||||
screenBrightnessThresholds, context);
|
||||
screenBrightnessThresholds, context, displayDeviceConfig);
|
||||
} else {
|
||||
mUseSoftwareAutoBrightnessConfig = false;
|
||||
}
|
||||
|
||||
@@ -203,6 +203,8 @@ final class LocalDisplayAdapter extends DisplayAdapter {
|
||||
private Spline mNitsToHalBrightness;
|
||||
private boolean mHalBrightnessSupport;
|
||||
|
||||
private DisplayDeviceConfig mDisplayDeviceConfig;
|
||||
|
||||
LocalDisplayDevice(IBinder displayToken, long physicalDisplayId,
|
||||
SurfaceControl.DisplayInfo info, SurfaceControl.DisplayConfig[] configs,
|
||||
int activeConfigId, SurfaceControl.DesiredDisplayConfigSpecs configSpecs,
|
||||
@@ -224,7 +226,7 @@ final class LocalDisplayAdapter extends DisplayAdapter {
|
||||
mAllmSupported = SurfaceControl.getAutoLowLatencyModeSupport(displayToken);
|
||||
mGameContentTypeSupported = SurfaceControl.getGameContentTypeSupport(displayToken);
|
||||
mHalBrightnessSupport = SurfaceControl.getDisplayBrightnessSupport(displayToken);
|
||||
|
||||
mDisplayDeviceConfig = null;
|
||||
// Defer configuration file loading
|
||||
BackgroundThread.getHandler().sendMessage(PooledLambda.obtainMessage(
|
||||
LocalDisplayDevice::loadDisplayConfigurationBrightnessMapping, this));
|
||||
@@ -373,17 +375,23 @@ final class LocalDisplayAdapter extends DisplayAdapter {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DisplayDeviceConfig getDisplayDeviceConfig() {
|
||||
return mDisplayDeviceConfig;
|
||||
}
|
||||
|
||||
private void loadDisplayConfigurationBrightnessMapping() {
|
||||
Spline nitsToHal = null;
|
||||
Spline sysToNits = null;
|
||||
|
||||
// Load the mapping from nits to HAL brightness range (display-device-config.xml)
|
||||
DisplayDeviceConfig config = DisplayDeviceConfig.create(mPhysicalDisplayId);
|
||||
mDisplayDeviceConfig = config;
|
||||
if (config == null) {
|
||||
return;
|
||||
}
|
||||
final float[] halNits = config.getNits();
|
||||
final float[] halBrightness = config.getBrightness();
|
||||
final float[] halNits = mDisplayDeviceConfig.getNits();
|
||||
final float[] halBrightness = mDisplayDeviceConfig.getBrightness();
|
||||
if (halNits == null || halBrightness == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ public class AutomaticBrightnessControllerTest {
|
||||
@Mock HysteresisLevels mAmbientBrightnessThresholds;
|
||||
@Mock HysteresisLevels mScreenBrightnessThresholds;
|
||||
@Mock Handler mNoopHandler;
|
||||
@Mock DisplayDeviceConfig mDisplayDeviceConfig;
|
||||
|
||||
private static final int LIGHT_SENSOR_WARMUP_TIME = 0;
|
||||
@Before
|
||||
@@ -82,7 +83,8 @@ public class AutomaticBrightnessControllerTest {
|
||||
BRIGHTNESS_MAX_FLOAT, DOZE_SCALE_FACTOR, LIGHT_SENSOR_RATE,
|
||||
INITIAL_LIGHT_SENSOR_RATE, BRIGHTENING_LIGHT_DEBOUNCE_CONFIG,
|
||||
DARKENING_LIGHT_DEBOUNCE_CONFIG, RESET_AMBIENT_LUX_AFTER_WARMUP_CONFIG,
|
||||
mAmbientBrightnessThresholds, mScreenBrightnessThresholds, mContext);
|
||||
mAmbientBrightnessThresholds, mScreenBrightnessThresholds, mContext,
|
||||
mDisplayDeviceConfig);
|
||||
controller.setLoggingEnabled(true);
|
||||
|
||||
// Configure the brightness controller and grab an instance of the sensor listener,
|
||||
|
||||
Reference in New Issue
Block a user