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

Commit 52229d8d authored by Dave Mankoff's avatar Dave Mankoff
Browse files

Ensure that DozeSensors can unregister itself.

When DozeService shuts down, we need to ensure that any registered
callbacks in DozeSensors get a chance to remove themselves from the
SensorManager.

Fixes: 155104806
Test: atest SystemUITests
Change-Id: I5126cdb1b65d4db42674722839adb7331091e099
parent cd220824
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -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} */
+11 −0
Original line number Original line Diff line number Diff line
@@ -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.
+1 −0
Original line number Original line Diff line number Diff line
@@ -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;
    }
    }


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