Merge "Ensure that DozeSensors can unregister itself." into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2adebfdea1
@@ -159,6 +159,15 @@ public class DozeMachine {
|
|||||||
mDozeHost = dozeHost;
|
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. */
|
/** Initializes the set of {@link Part}s. Must be called exactly once after construction. */
|
||||||
public void setParts(Part[] parts) {
|
public void setParts(Part[] parts) {
|
||||||
Preconditions.checkState(mParts == null);
|
Preconditions.checkState(mParts == null);
|
||||||
@@ -411,6 +420,9 @@ public class DozeMachine {
|
|||||||
|
|
||||||
/** Dump current state. For debugging only. */
|
/** Dump current state. For debugging only. */
|
||||||
default void dump(PrintWriter pw) {}
|
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} */
|
/** A wrapper interface for {@link android.service.dreams.DreamService} */
|
||||||
|
|||||||
@@ -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
|
* Temporarily disable some sensors to avoid turning on the device while the user is
|
||||||
* turning it off.
|
* turning it off.
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ public class DozeService extends DreamService
|
|||||||
mPluginManager.removePluginListener(this);
|
mPluginManager.removePluginListener(this);
|
||||||
}
|
}
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
mDozeMachine.destroy();
|
||||||
mDozeMachine = null;
|
mDozeMachine = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,6 +111,11 @@ public class DozeTriggers implements DozeMachine.Part {
|
|||||||
mBroadcastDispatcher = broadcastDispatcher;
|
mBroadcastDispatcher = broadcastDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
mDozeSensors.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
private void onNotification(Runnable onPulseSuppressedListener) {
|
private void onNotification(Runnable onPulseSuppressedListener) {
|
||||||
if (DozeMachine.DEBUG) {
|
if (DozeMachine.DEBUG) {
|
||||||
Log.d(TAG, "requestNotificationPulse");
|
Log.d(TAG, "requestNotificationPulse");
|
||||||
|
|||||||
@@ -158,6 +158,13 @@ public class DozeSensorsTest extends SysuiTestCase {
|
|||||||
verify(mTriggerSensor).setListening(eq(false));
|
verify(mTriggerSensor).setListening(eq(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDestroy() {
|
||||||
|
mDozeSensors.destroy();
|
||||||
|
|
||||||
|
verify(mTriggerSensor).setListening(false);
|
||||||
|
}
|
||||||
|
|
||||||
private class TestableDozeSensors extends DozeSensors {
|
private class TestableDozeSensors extends DozeSensors {
|
||||||
|
|
||||||
TestableDozeSensors() {
|
TestableDozeSensors() {
|
||||||
|
|||||||
Reference in New Issue
Block a user