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

Commit ecfc2e58 authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge "Unregister for posture callback on destroy"

parents 79401519 7ae51035
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -288,7 +288,7 @@ public class DozeSensors {
        for (TriggerSensor triggerSensor : mTriggerSensors) {
            triggerSensor.setListening(false);
        }
        mProximitySensor.pause();
        mProximitySensor.destroy();

        mDevicePostureController.removeCallback(mDevicePostureCallback);
        mAuthController.removeCallback(mAuthControllerCallback);
+1 −0
Original line number Diff line number Diff line
@@ -228,6 +228,7 @@ public class DozeTriggers implements DozeMachine.Part {
    @Override
    public void destroy() {
        mDozeSensors.destroy();
        mProxCheck.destroy();
    }

    private void onNotification(Runnable onPulseSuppressedListener) {
+14 −3
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ class PostureDependentProximitySensor extends ProximitySensorImpl {
    private final ThresholdSensor[] mPostureToPrimaryProxSensorMap;
    private final ThresholdSensor[] mPostureToSecondaryProxSensorMap;

    private final DevicePostureController mDevicePostureController;

    @Inject
    PostureDependentProximitySensor(
            @PrimaryProxSensor ThresholdSensor[] postureToPrimaryProxSensorMap,
@@ -53,15 +55,24 @@ class PostureDependentProximitySensor extends ProximitySensorImpl {
        );
        mPostureToPrimaryProxSensorMap = postureToPrimaryProxSensorMap;
        mPostureToSecondaryProxSensorMap = postureToSecondaryProxSensorMap;
        mDevicePosture = devicePostureController.getDevicePosture();
        devicePostureController.addCallback(mDevicePostureCallback);
        mDevicePostureController = devicePostureController;

        mDevicePosture = mDevicePostureController.getDevicePosture();
        mDevicePostureController.addCallback(mDevicePostureCallback);

        chooseSensors();
    }

    @Override
    public void destroy() {
        super.destroy();
        mDevicePostureController.removeCallback(mDevicePostureCallback);
    }

    private void chooseSensors() {
        if (mDevicePosture >= mPostureToPrimaryProxSensorMap.length
                || mDevicePosture >= mPostureToSecondaryProxSensorMap.length) {
            Log.e("PostureDependentProxSensor",
            Log.e("PostureDependProxSensor",
                    "unsupported devicePosture=" + mDevicePosture);
            return;
        }
+7 −0
Original line number Diff line number Diff line
@@ -73,6 +73,13 @@ public class ProximityCheck implements Runnable {
        }
    }

    /**
     * Cleanup after no longer needed.
     */
    public void destroy() {
        mSensor.destroy();
    }

    private void unregister() {
        mSensor.unregister(mListener);
        mRegistered.set(false);
+6 −0
Original line number Diff line number Diff line
@@ -42,4 +42,10 @@ public interface ProximitySensor extends ThresholdSensor {
     * of what is reported by the primary sensor.
     */
    void setSecondarySafe(boolean safe);

    /**
     * Called when the proximity sensor is no longer needed. All listeners should
     * be unregistered and cleaned up.
     */
    void destroy();
}
Loading