Merge "Populate BrightnessEvent from AutoBrightnessStrat." into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
fba8087e3f
@@ -366,7 +366,12 @@ public class AutomaticBrightnessController {
|
||||
return getAutomaticScreenBrightness(null);
|
||||
}
|
||||
|
||||
float getAutomaticScreenBrightness(BrightnessEvent brightnessEvent) {
|
||||
/**
|
||||
* @return The current brightness recommendation calculated from the current conditions.
|
||||
* @param brightnessEvent Event object to populate with details about why the specific
|
||||
* brightness was chosen.
|
||||
*/
|
||||
public float getAutomaticScreenBrightness(BrightnessEvent brightnessEvent) {
|
||||
if (brightnessEvent != null) {
|
||||
brightnessEvent.setLux(
|
||||
mAmbientLuxValid ? mAmbientLux : PowerManager.BRIGHTNESS_INVALID_FLOAT);
|
||||
|
||||
@@ -1302,7 +1302,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
||||
int brightnessAdjustmentFlags = 0;
|
||||
if (Float.isNaN(brightnessState)) {
|
||||
if (mAutomaticBrightnessStrategy.isAutoBrightnessEnabled()) {
|
||||
brightnessState = mAutomaticBrightnessStrategy.getAutomaticScreenBrightness();
|
||||
brightnessState = mAutomaticBrightnessStrategy.getAutomaticScreenBrightness(
|
||||
mTempBrightnessEvent);
|
||||
if (BrightnessUtils.isValidBrightnessValue(brightnessState)
|
||||
|| brightnessState == PowerManager.BRIGHTNESS_OFF_FLOAT) {
|
||||
rawBrightnessState = mAutomaticBrightnessController
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.view.Display;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.server.display.AutomaticBrightnessController;
|
||||
import com.android.server.display.brightness.BrightnessEvent;
|
||||
import com.android.server.display.brightness.BrightnessReason;
|
||||
import com.android.server.display.brightness.BrightnessUtils;
|
||||
|
||||
@@ -252,10 +253,12 @@ public class AutomaticBrightnessStrategy {
|
||||
|
||||
/**
|
||||
* Evaluates the target automatic brightness of the associated display.
|
||||
* @param brightnessEvent Event object to populate with details about why the specific
|
||||
* brightness was chosen.
|
||||
*/
|
||||
public float getAutomaticScreenBrightness() {
|
||||
public float getAutomaticScreenBrightness(BrightnessEvent brightnessEvent) {
|
||||
float brightness = (mAutomaticBrightnessController != null)
|
||||
? mAutomaticBrightnessController.getAutomaticScreenBrightness()
|
||||
? mAutomaticBrightnessController.getAutomaticScreenBrightness(brightnessEvent)
|
||||
: PowerManager.BRIGHTNESS_INVALID_FLOAT;
|
||||
adjustAutomaticBrightnessStateIfValid(brightness);
|
||||
return brightness;
|
||||
|
||||
@@ -64,6 +64,7 @@ import com.android.server.ExtendedMockitoRule;
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.am.BatteryStatsService;
|
||||
import com.android.server.display.RampAnimator.DualRampAnimator;
|
||||
import com.android.server.display.brightness.BrightnessEvent;
|
||||
import com.android.server.display.color.ColorDisplayService;
|
||||
import com.android.server.display.layout.Layout;
|
||||
import com.android.server.display.whitebalance.DisplayWhiteBalanceController;
|
||||
@@ -632,8 +633,8 @@ public final class DisplayPowerController2Test {
|
||||
.thenReturn(brightness);
|
||||
dpr.policy = DisplayPowerRequest.POLICY_BRIGHT;
|
||||
when(mHolder.displayPowerState.getScreenState()).thenReturn(Display.STATE_ON);
|
||||
when(mHolder.automaticBrightnessController.getAutomaticScreenBrightness())
|
||||
.thenReturn(PowerManager.BRIGHTNESS_INVALID_FLOAT);
|
||||
when(mHolder.automaticBrightnessController.getAutomaticScreenBrightness(
|
||||
any(BrightnessEvent.class))).thenReturn(PowerManager.BRIGHTNESS_INVALID_FLOAT);
|
||||
|
||||
mHolder.dpc.requestPowerState(dpr, /* waitForNegativeProximity= */ false);
|
||||
advanceTime(1); // Run updatePowerState
|
||||
@@ -667,8 +668,8 @@ public final class DisplayPowerController2Test {
|
||||
.thenReturn(brightness);
|
||||
dpr.policy = DisplayPowerRequest.POLICY_BRIGHT;
|
||||
when(mHolder.displayPowerState.getScreenState()).thenReturn(Display.STATE_ON);
|
||||
when(mHolder.automaticBrightnessController.getAutomaticScreenBrightness())
|
||||
.thenReturn(PowerManager.BRIGHTNESS_INVALID_FLOAT);
|
||||
when(mHolder.automaticBrightnessController.getAutomaticScreenBrightness(
|
||||
any(BrightnessEvent.class))).thenReturn(PowerManager.BRIGHTNESS_INVALID_FLOAT);
|
||||
|
||||
mHolder.dpc.requestPowerState(dpr, /* waitForNegativeProximity= */ false);
|
||||
advanceTime(1); // Run updatePowerState
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.server.display.brightness.strategy;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -40,6 +41,7 @@ import androidx.test.runner.AndroidJUnit4;
|
||||
import com.android.internal.util.test.FakeSettingsProvider;
|
||||
import com.android.internal.util.test.FakeSettingsProviderRule;
|
||||
import com.android.server.display.AutomaticBrightnessController;
|
||||
import com.android.server.display.brightness.BrightnessEvent;
|
||||
import com.android.server.display.brightness.BrightnessReason;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -262,12 +264,13 @@ public class AutomaticBrightnessStrategyTest {
|
||||
float automaticScreenBrightness = 0.3f;
|
||||
AutomaticBrightnessController automaticBrightnessController = mock(
|
||||
AutomaticBrightnessController.class);
|
||||
when(automaticBrightnessController.getAutomaticScreenBrightness()).thenReturn(
|
||||
automaticScreenBrightness);
|
||||
when(automaticBrightnessController.getAutomaticScreenBrightness(any(BrightnessEvent.class)))
|
||||
.thenReturn(automaticScreenBrightness);
|
||||
mAutomaticBrightnessStrategy.setAutomaticBrightnessController(
|
||||
automaticBrightnessController);
|
||||
assertEquals(automaticScreenBrightness,
|
||||
mAutomaticBrightnessStrategy.getAutomaticScreenBrightness(), 0.0f);
|
||||
mAutomaticBrightnessStrategy.getAutomaticScreenBrightness(
|
||||
new BrightnessEvent(DISPLAY_ID)), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user