Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d6f80cec authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

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

Merge "Ensure that DozeSensors can unregister itself." into rvc-dev am: 2adebfde am: c03785f8 am: 5eb9b9ad

Change-Id: I3719548d4ed5213712dd5aae28648fa8f76a2827
parents 42f0b269 5eb9b9ad
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -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} */
+11 −0
Original line number Diff line number Diff line
@@ -164,6 +164,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.
+1 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ public class DozeService extends DreamService
            mPluginManager.removePluginListener(this);
        }
        super.onDestroy();
        mDozeMachine.destroy();
        mDozeMachine = null;
    }

+5 −0
Original line number Diff line number Diff line
@@ -112,6 +112,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");
+7 −0
Original line number Diff line number Diff line
@@ -162,6 +162,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() {