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

Commit d32b366a authored by Adrian Roos's avatar Adrian Roos
Browse files

AOD: Proximity check doze triggers

Adds a proximity check to doze triggers that fire
while AOD is enabled.

Bug: 62484520
Test: manual
Change-Id: I5c0e8ccec1e470be6722dade06b2e8f174943512
parent 889d326e
Loading
Loading
Loading
Loading
+41 −31
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@ import com.android.systemui.util.Assert;
import com.android.systemui.util.wakelock.WakeLock;
import com.android.systemui.util.wakelock.WakeLock;


import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.function.IntConsumer;


/**
/**
 * Handles triggers for ambient state changes.
 * Handles triggers for ambient state changes.
@@ -98,18 +99,44 @@ public class DozeTriggers implements DozeMachine.Part {
        requestPulse(DozeLog.PULSE_REASON_NOTIFICATION, false /* performedProxCheck */);
        requestPulse(DozeLog.PULSE_REASON_NOTIFICATION, false /* performedProxCheck */);
    }
    }


    private void proximityCheckThenCall(IntConsumer callback,
            boolean alreadyPerformedProxCheck,
            int pulseReason) {
        if (alreadyPerformedProxCheck) {
            callback.accept(ProximityCheck.RESULT_NOT_CHECKED);
        } else {
            final long start = SystemClock.uptimeMillis();
            new ProximityCheck() {
                @Override
                public void onProximityResult(int result) {
                    final long end = SystemClock.uptimeMillis();
                    DozeLog.traceProximityResult(mContext, result == RESULT_NEAR,
                            end - start, pulseReason);
                    callback.accept(result);
                }
            }.check();
        }
    }

    private void onSensor(int pulseReason, boolean sensorPerformedProxCheck,
    private void onSensor(int pulseReason, boolean sensorPerformedProxCheck,
            float screenX, float screenY) {
            float screenX, float screenY) {
        boolean isDoubleTap = pulseReason == DozeLog.PULSE_REASON_SENSOR_DOUBLE_TAP;
        boolean isDoubleTap = pulseReason == DozeLog.PULSE_REASON_SENSOR_DOUBLE_TAP;
        boolean isPickup = pulseReason == DozeLog.PULSE_REASON_SENSOR_PICKUP;
        boolean isPickup = pulseReason == DozeLog.PULSE_REASON_SENSOR_PICKUP;


        if (mConfig.alwaysOnEnabled(UserHandle.USER_CURRENT)) {
        if (mConfig.alwaysOnEnabled(UserHandle.USER_CURRENT)) {
            proximityCheckThenCall((result) -> {
                if (result == ProximityCheck.RESULT_NEAR) {
                    // In pocket, drop event.
                    return;
                }
                if (isDoubleTap) {
                if (isDoubleTap) {
                    mDozeHost.onDoubleTap(screenX, screenY);
                    mDozeHost.onDoubleTap(screenX, screenY);
                    mMachine.wakeUp();
                    mMachine.wakeUp();
                } else {
                } else {
                    mDozeHost.extendPulse();
                    mDozeHost.extendPulse();
                }
                }
            }, sensorPerformedProxCheck, pulseReason);
            return;
        } else {
        } else {
            requestPulse(pulseReason, sensorPerformedProxCheck);
            requestPulse(pulseReason, sensorPerformedProxCheck);
        }
        }
@@ -199,33 +226,15 @@ public class DozeTriggers implements DozeMachine.Part {
        }
        }


        mPulsePending = true;
        mPulsePending = true;
        if (!mDozeParameters.getProxCheckBeforePulse() || performedProxCheck) {
        proximityCheckThenCall((result) -> {
            // skip proximity check
            if (result == ProximityCheck.RESULT_NEAR) {
            continuePulseRequest(reason);
                // in pocket, abort pulse
            return;
        }

        final long start = SystemClock.uptimeMillis();
        new ProximityCheck() {
            @Override
            public void onProximityResult(int result) {
                final long end = SystemClock.uptimeMillis();
                DozeLog.traceProximityResult(mContext, result == RESULT_NEAR,
                        end - start, reason);
                if (performedProxCheck) {
                    // we already continued
                    return;
                }
                // avoid pulsing in pockets
                if (result == RESULT_NEAR) {
                mPulsePending = false;
                mPulsePending = false;
                    return;
            } else {
                }
                // not in pocket, continue pulsing

                // not in-pocket, continue pulsing
                continuePulseRequest(reason);
                continuePulseRequest(reason);
            }
            }
        }.check();
        }, !mDozeParameters.getProxCheckBeforePulse() || performedProxCheck, reason);
    }
    }


    private boolean canPulse() {
    private boolean canPulse() {
@@ -259,6 +268,7 @@ public class DozeTriggers implements DozeMachine.Part {
        protected static final int RESULT_UNKNOWN = 0;
        protected static final int RESULT_UNKNOWN = 0;
        protected static final int RESULT_NEAR = 1;
        protected static final int RESULT_NEAR = 1;
        protected static final int RESULT_FAR = 2;
        protected static final int RESULT_FAR = 2;
        protected static final int RESULT_NOT_CHECKED = 3;


        private boolean mRegistered;
        private boolean mRegistered;
        private boolean mFinished;
        private boolean mFinished;