Unregister Touch Sensors for DOZE_AOD_DOCKED
DOZE_AOD_DOCKED should not have screen based trigger sensors enabled. In fact, it can end up in inconsistent states currently. When first entering it, the sensors are not enabled. But if the screen then turns off (in a dark room) and then back on, the sensors are left on from the prior state. This change ensures that, when we ask to turn off touch based sensors, they actually turn off. Fixes: 172412913 Test: manual Change-Id: I86f800cb75fee9f2d7e60655af4803e616a68fb2
This commit is contained in:
@@ -34,6 +34,7 @@ import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.IndentingPrintWriter;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
|
||||
@@ -79,6 +80,7 @@ public class DozeSensors {
|
||||
private long mDebounceFrom;
|
||||
private boolean mSettingRegistered;
|
||||
private boolean mListening;
|
||||
private boolean mListeningTouchScreenSensors;
|
||||
|
||||
@VisibleForTesting
|
||||
public enum DozeSensorsUiEvent implements UiEventLogger.UiEventEnum {
|
||||
@@ -232,22 +234,25 @@ public class DozeSensors {
|
||||
/**
|
||||
* If sensors should be registered and sending signals.
|
||||
*/
|
||||
public void setListening(boolean listen) {
|
||||
if (mListening == listen) {
|
||||
public void setListening(boolean listen, boolean includeTouchScreenSensors) {
|
||||
if (mListening == listen && mListeningTouchScreenSensors == includeTouchScreenSensors) {
|
||||
return;
|
||||
}
|
||||
mListening = listen;
|
||||
mListeningTouchScreenSensors = includeTouchScreenSensors;
|
||||
updateListening();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers/unregisters sensors based on internal state.
|
||||
*/
|
||||
public void updateListening() {
|
||||
private void updateListening() {
|
||||
boolean anyListening = false;
|
||||
for (TriggerSensor s : mSensors) {
|
||||
s.setListening(mListening);
|
||||
if (mListening) {
|
||||
boolean listen = mListening
|
||||
&& (!s.mRequiresTouchscreen || mListeningTouchScreenSensors);
|
||||
s.setListening(listen);
|
||||
if (listen) {
|
||||
anyListening = true;
|
||||
}
|
||||
}
|
||||
@@ -319,10 +324,14 @@ public class DozeSensors {
|
||||
|
||||
/** Dump current state */
|
||||
public void dump(PrintWriter pw) {
|
||||
pw.println("mListening=" + mListening);
|
||||
pw.println("mListeningTouchScreenSensors=" + mListeningTouchScreenSensors);
|
||||
IndentingPrintWriter idpw = new IndentingPrintWriter(pw);
|
||||
idpw.increaseIndent();
|
||||
for (TriggerSensor s : mSensors) {
|
||||
pw.println(" Sensor: " + s.toString());
|
||||
idpw.println("Sensor: " + s.toString());
|
||||
}
|
||||
pw.println(" ProxSensor: " + mProximitySensor.toString());
|
||||
idpw.println("ProxSensor: " + mProximitySensor.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.metrics.LogMaker;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
import android.text.format.Formatter;
|
||||
import android.util.IndentingPrintWriter;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
|
||||
@@ -434,15 +435,12 @@ public class DozeTriggers implements DozeMachine.Part {
|
||||
break;
|
||||
case DOZE_PULSE_DONE:
|
||||
mDozeSensors.requestTemporaryDisable();
|
||||
// A pulse will temporarily disable sensors that require a touch screen.
|
||||
// Let's make sure that they are re-enabled when the pulse is over.
|
||||
mDozeSensors.updateListening();
|
||||
break;
|
||||
case FINISH:
|
||||
mBroadcastReceiver.unregister(mBroadcastDispatcher);
|
||||
mDozeHost.removeCallback(mHostCallback);
|
||||
mDockManager.removeListener(mDockEventListener);
|
||||
mDozeSensors.setListening(false);
|
||||
mDozeSensors.setListening(false, false);
|
||||
mDozeSensors.setProxListening(false);
|
||||
mWantSensors = false;
|
||||
mWantProx = false;
|
||||
@@ -450,20 +448,16 @@ public class DozeTriggers implements DozeMachine.Part {
|
||||
break;
|
||||
default:
|
||||
}
|
||||
mDozeSensors.setListening(mWantSensors, mWantTouchScreenSensors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScreenState(int state) {
|
||||
mDozeSensors.onScreenState(state);
|
||||
if (state == Display.STATE_DOZE || state == Display.STATE_DOZE_SUSPEND
|
||||
|| state == Display.STATE_OFF) {
|
||||
mDozeSensors.setProxListening(mWantProx);
|
||||
mDozeSensors.setListening(mWantSensors);
|
||||
mDozeSensors.setTouchscreenSensorsListening(mWantTouchScreenSensors);
|
||||
} else {
|
||||
mDozeSensors.setProxListening(false);
|
||||
mDozeSensors.setListening(mWantSensors);
|
||||
}
|
||||
mDozeSensors.setProxListening(mWantProx && (state == Display.STATE_DOZE
|
||||
|| state == Display.STATE_DOZE_SUSPEND
|
||||
|| state == Display.STATE_OFF));
|
||||
mDozeSensors.setListening(mWantSensors, mWantTouchScreenSensors);
|
||||
}
|
||||
|
||||
private void checkTriggersAtInit() {
|
||||
@@ -539,7 +533,9 @@ public class DozeTriggers implements DozeMachine.Part {
|
||||
|
||||
pw.println(" pulsePending=" + mPulsePending);
|
||||
pw.println("DozeSensors:");
|
||||
mDozeSensors.dump(pw);
|
||||
IndentingPrintWriter idpw = new IndentingPrintWriter(pw);
|
||||
idpw.increaseIndent();
|
||||
mDozeSensors.dump(idpw);
|
||||
}
|
||||
|
||||
private class TriggerReceiver extends BroadcastReceiver {
|
||||
|
||||
@@ -31,7 +31,6 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.database.ContentObserver;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.display.AmbientDisplayConfiguration;
|
||||
@@ -64,8 +63,6 @@ import java.util.function.Consumer;
|
||||
@SmallTest
|
||||
public class DozeSensorsTest extends SysuiTestCase {
|
||||
|
||||
@Mock
|
||||
private AlarmManager mAlarmManager;
|
||||
@Mock
|
||||
private AsyncSensorManager mSensorManager;
|
||||
@Mock
|
||||
@@ -79,8 +76,6 @@ public class DozeSensorsTest extends SysuiTestCase {
|
||||
@Mock
|
||||
private Consumer<Boolean> mProxCallback;
|
||||
@Mock
|
||||
private AlwaysOnDisplayPolicy mAlwaysOnDisplayPolicy;
|
||||
@Mock
|
||||
private TriggerSensor mTriggerSensor;
|
||||
@Mock
|
||||
private DozeLog mDozeLog;
|
||||
@@ -115,7 +110,7 @@ public class DozeSensorsTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void testSensorDebounce() {
|
||||
mDozeSensors.setListening(true);
|
||||
mDozeSensors.setListening(true, true);
|
||||
|
||||
mWakeLockScreenListener.onSensorChanged(mock(SensorManagerPlugin.SensorEvent.class));
|
||||
mTestableLooper.processAllMessages();
|
||||
@@ -133,7 +128,7 @@ public class DozeSensorsTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testSetListening_firstTrue_registerSettingsObserver() {
|
||||
verify(mSensorManager, never()).registerListener(any(), any(Sensor.class), anyInt());
|
||||
mDozeSensors.setListening(true);
|
||||
mDozeSensors.setListening(true, true);
|
||||
|
||||
verify(mTriggerSensor).registerSettingsObserver(any(ContentObserver.class));
|
||||
}
|
||||
@@ -141,8 +136,8 @@ public class DozeSensorsTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testSetListening_twiceTrue_onlyRegisterSettingsObserverOnce() {
|
||||
verify(mSensorManager, never()).registerListener(any(), any(Sensor.class), anyInt());
|
||||
mDozeSensors.setListening(true);
|
||||
mDozeSensors.setListening(true);
|
||||
mDozeSensors.setListening(true, true);
|
||||
mDozeSensors.setListening(true, true);
|
||||
|
||||
verify(mTriggerSensor, times(1)).registerSettingsObserver(any(ContentObserver.class));
|
||||
}
|
||||
|
||||
@@ -154,6 +154,7 @@ public class DozeTriggersTest extends SysuiTestCase {
|
||||
|
||||
clearInvocations(mSensors);
|
||||
mTriggers.transitionTo(DozeMachine.State.DOZE_PULSING, DozeMachine.State.DOZE_PULSE_DONE);
|
||||
mTriggers.transitionTo(DozeMachine.State.DOZE_PULSE_DONE, DozeMachine.State.DOZE_AOD);
|
||||
waitForSensorManager();
|
||||
verify(mSensors).requestTriggerSensor(any(), eq(mTapSensor));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user