Merge "Don't trust DozeState onScreenState changes" into rvc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
697711df74
@@ -430,8 +430,12 @@ public class DozeMachine {
|
|||||||
/** Give the Part a chance to clean itself up. */
|
/** Give the Part a chance to clean itself up. */
|
||||||
default void destroy() {}
|
default void destroy() {}
|
||||||
|
|
||||||
/** Alerts that the screenstate is being changed. */
|
/**
|
||||||
default void onScreenState(int state) {}
|
* Alerts that the screenstate is being changed.
|
||||||
|
* Note: This may be called from within a call to transitionTo, so local DozeState may not
|
||||||
|
* be accurate nor match with the new displayState.
|
||||||
|
*/
|
||||||
|
default void onScreenState(int displayState) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A wrapper interface for {@link android.service.dreams.DreamService} */
|
/** A wrapper interface for {@link android.service.dreams.DreamService} */
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
|
|||||||
* --ei brightness_bucket 1}
|
* --ei brightness_bucket 1}
|
||||||
*/
|
*/
|
||||||
private int mDebugBrightnessBucket = -1;
|
private int mDebugBrightnessBucket = -1;
|
||||||
private DozeMachine.State mState;
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public DozeScreenBrightness(Context context, DozeMachine.Service service,
|
public DozeScreenBrightness(Context context, DozeMachine.Service service,
|
||||||
@@ -109,7 +108,6 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transitionTo(DozeMachine.State oldState, DozeMachine.State newState) {
|
public void transitionTo(DozeMachine.State oldState, DozeMachine.State newState) {
|
||||||
mState = newState;
|
|
||||||
switch (newState) {
|
switch (newState) {
|
||||||
case INITIALIZED:
|
case INITIALIZED:
|
||||||
case DOZE:
|
case DOZE:
|
||||||
@@ -127,10 +125,7 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScreenState(int state) {
|
public void onScreenState(int state) {
|
||||||
if (!mScreenOff
|
if (state == Display.STATE_DOZE || state == Display.STATE_DOZE_SUSPEND) {
|
||||||
&& (mState == DozeMachine.State.DOZE_AOD
|
|
||||||
|| mState == DozeMachine.State.DOZE_AOD_DOCKED)
|
|
||||||
&& (state == Display.STATE_DOZE || state == Display.STATE_DOZE_SUSPEND)) {
|
|
||||||
setLightSensorEnabled(true);
|
setLightSensorEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
setLightSensorEnabled(false);
|
setLightSensorEnabled(false);
|
||||||
|
|||||||
@@ -103,8 +103,6 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAod_usesLightSensor() {
|
public void testAod_usesLightSensor() {
|
||||||
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
|
||||||
mScreen.transitionTo(INITIALIZED, DOZE_AOD);
|
|
||||||
mScreen.onScreenState(Display.STATE_DOZE);
|
mScreen.onScreenState(Display.STATE_DOZE);
|
||||||
|
|
||||||
mSensor.sendSensorEvent(3);
|
mSensor.sendSensorEvent(3);
|
||||||
@@ -114,8 +112,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAod_usesDebugValue() throws Exception {
|
public void testAod_usesDebugValue() throws Exception {
|
||||||
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
mScreen.onScreenState(Display.STATE_DOZE);
|
||||||
mScreen.transitionTo(INITIALIZED, DOZE_AOD);
|
|
||||||
|
|
||||||
Intent intent = new Intent(DozeScreenBrightness.ACTION_AOD_BRIGHTNESS);
|
Intent intent = new Intent(DozeScreenBrightness.ACTION_AOD_BRIGHTNESS);
|
||||||
intent.putExtra(DozeScreenBrightness.BRIGHTNESS_BUCKET, 1);
|
intent.putExtra(DozeScreenBrightness.BRIGHTNESS_BUCKET, 1);
|
||||||
@@ -166,20 +163,30 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDozingAfterPulsing_pausesLightSensor() throws Exception {
|
public void testScreenOffAfterPulsing_pausesLightSensor() throws Exception {
|
||||||
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
||||||
mScreen.transitionTo(INITIALIZED, DOZE);
|
mScreen.transitionTo(INITIALIZED, DOZE);
|
||||||
mScreen.transitionTo(DOZE, DOZE_REQUEST_PULSE);
|
mScreen.transitionTo(DOZE, DOZE_REQUEST_PULSE);
|
||||||
mScreen.transitionTo(DOZE_REQUEST_PULSE, DOZE_PULSING);
|
mScreen.transitionTo(DOZE_REQUEST_PULSE, DOZE_PULSING);
|
||||||
mScreen.transitionTo(DOZE_PULSING, DOZE_PULSE_DONE);
|
mScreen.transitionTo(DOZE_PULSING, DOZE_PULSE_DONE);
|
||||||
mScreen.transitionTo(DOZE_PULSE_DONE, DOZE);
|
mScreen.transitionTo(DOZE_PULSE_DONE, DOZE);
|
||||||
mScreen.onScreenState(Display.STATE_DOZE);
|
|
||||||
|
|
||||||
mSensor.sendSensorEvent(1);
|
mSensor.sendSensorEvent(1);
|
||||||
|
|
||||||
assertEquals(DEFAULT_BRIGHTNESS, mServiceFake.screenBrightness);
|
assertEquals(DEFAULT_BRIGHTNESS, mServiceFake.screenBrightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnScreenStateSetBeforeTransition_stillRegistersSensor() {
|
||||||
|
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
||||||
|
mScreen.onScreenState(Display.STATE_DOZE);
|
||||||
|
mScreen.transitionTo(INITIALIZED, DOZE_AOD);
|
||||||
|
|
||||||
|
mSensor.sendSensorEvent(1);
|
||||||
|
|
||||||
|
assertEquals(1, mServiceFake.screenBrightness);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullSensor() throws Exception {
|
public void testNullSensor() throws Exception {
|
||||||
mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager,
|
mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager,
|
||||||
@@ -191,12 +198,15 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
|||||||
mScreen.transitionTo(INITIALIZED, DOZE_AOD);
|
mScreen.transitionTo(INITIALIZED, DOZE_AOD);
|
||||||
mScreen.transitionTo(DOZE_AOD, DOZE_AOD_PAUSING);
|
mScreen.transitionTo(DOZE_AOD, DOZE_AOD_PAUSING);
|
||||||
mScreen.transitionTo(DOZE_AOD_PAUSING, DOZE_AOD_PAUSED);
|
mScreen.transitionTo(DOZE_AOD_PAUSING, DOZE_AOD_PAUSED);
|
||||||
|
mScreen.onScreenState(Display.STATE_DOZE);
|
||||||
|
mScreen.onScreenState(Display.STATE_OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoBrightnessDeliveredAfterFinish() throws Exception {
|
public void testNoBrightnessDeliveredAfterFinish() throws Exception {
|
||||||
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
||||||
mScreen.transitionTo(INITIALIZED, DOZE_AOD);
|
mScreen.transitionTo(INITIALIZED, DOZE_AOD);
|
||||||
|
mScreen.onScreenState(Display.STATE_DOZE);
|
||||||
mScreen.transitionTo(DOZE_AOD, FINISH);
|
mScreen.transitionTo(DOZE_AOD, FINISH);
|
||||||
|
|
||||||
mSensor.sendSensorEvent(1);
|
mSensor.sendSensorEvent(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user