Merge "Ensure that DozeSensors can unregister itself." into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-04-27 22:44:11 +00:00
committed by Android (Google) Code Review
5 changed files with 36 additions and 0 deletions

View File

@@ -159,6 +159,15 @@ public class DozeMachine {
mDozeHost = dozeHost;
}
/**
* Clean ourselves up.
*/
public void destroy() {
for (Part part : mParts) {
part.destroy();
}
}
/** Initializes the set of {@link Part}s. Must be called exactly once after construction. */
public void setParts(Part[] parts) {
Preconditions.checkState(mParts == null);
@@ -411,6 +420,9 @@ public class DozeMachine {
/** Dump current state. For debugging only. */
default void dump(PrintWriter pw) {}
/** Give the Part a chance to clean itself up. */
default void destroy() {}
}
/** A wrapper interface for {@link android.service.dreams.DreamService} */

View File

@@ -163,6 +163,17 @@ public class DozeSensors {
});
}
/**
* Unregister any sensors.
*/
public void destroy() {
// Unregisters everything, which is enough to allow gc.
for (TriggerSensor triggerSensor : mSensors) {
triggerSensor.setListening(false);
}
mProximitySensor.pause();
}
/**
* Temporarily disable some sensors to avoid turning on the device while the user is
* turning it off.

View File

@@ -65,6 +65,7 @@ public class DozeService extends DreamService
mPluginManager.removePluginListener(this);
}
super.onDestroy();
mDozeMachine.destroy();
mDozeMachine = null;
}

View File

@@ -111,6 +111,11 @@ public class DozeTriggers implements DozeMachine.Part {
mBroadcastDispatcher = broadcastDispatcher;
}
@Override
public void destroy() {
mDozeSensors.destroy();
}
private void onNotification(Runnable onPulseSuppressedListener) {
if (DozeMachine.DEBUG) {
Log.d(TAG, "requestNotificationPulse");

View File

@@ -158,6 +158,13 @@ public class DozeSensorsTest extends SysuiTestCase {
verify(mTriggerSensor).setListening(eq(false));
}
@Test
public void testDestroy() {
mDozeSensors.destroy();
verify(mTriggerSensor).setListening(false);
}
private class TestableDozeSensors extends DozeSensors {
TestableDozeSensors() {