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

Commit 8bb17575 authored by Adrian Roos's avatar Adrian Roos Committed by android-build-merger
Browse files

Merge "AOD: Fix broken triggers after failed prox check" into oc-dev am: 017f5df1

am: 06c68a68

Change-Id: Ifbcaaf8d580e5c55016040e9bdc5afd27ebcefd6
parents 824e7a5c 06c68a68
Loading
Loading
Loading
Loading
+30 −1
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ public class DozeLog {
    public static final int PULSE_REASON_SENSOR_PICKUP = 3;
    public static final int PULSE_REASON_SENSOR_DOUBLE_TAP = 4;

    private static boolean sRegisterKeyguardCallback = true;

    private static long[] sTimes;
    private static String[] sMessages;
    private static int sPosition;
@@ -103,10 +105,12 @@ public class DozeLog {
                    sProxStats[i][1] = new SummaryStats();
                }
                log("init");
                if (sRegisterKeyguardCallback) {
                    KeyguardUpdateMonitor.getInstance(context).registerCallback(sKeyguardCallback);
                }
            }
        }
    }

    public static void traceDozing(Context context, boolean dozing) {
        if (!ENABLED) return;
@@ -218,6 +222,31 @@ public class DozeLog {
        if (DEBUG) Log.d(TAG, msg);
    }

    public static void tracePulseDropped(Context context, boolean pulsePending,
            DozeMachine.State state, boolean blocked) {
        if (!ENABLED) return;
        init(context);
        log("pulseDropped pulsePending=" + pulsePending + " state="
                + state + " blocked=" + blocked);
    }

    public static void tracePulseCanceledByProx(Context context) {
        if (!ENABLED) return;
        init(context);
        log("pulseCanceledByProx");
    }

    public static void setRegisterKeyguardCallback(boolean registerKeyguardCallback) {
        if (!ENABLED) return;
        synchronized (DozeLog.class) {
            if (sRegisterKeyguardCallback != registerKeyguardCallback && sMessages != null) {
                throw new IllegalStateException("Cannot change setRegisterKeyguardCallback "
                        + "after init()");
            }
            sRegisterKeyguardCallback = registerKeyguardCallback;
        }
    }

    private static class SummaryStats {
        private int mCount;

+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ public class DozeMachine {
    static final String TAG = "DozeMachine";
    static final boolean DEBUG = DozeService.DEBUG;

    enum State {
    public enum State {
        /** Default state. Transition to INITIALIZED to get Doze going. */
        UNINITIALIZED,
        /** Doze components are set up. Followed by transition to DOZE or DOZE_AOD. */
+8 −0
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ public class DozeTriggers implements DozeMachine.Part {
        DozeMachine.State state = mMachine.getState();
        if (near && state == DozeMachine.State.DOZE_PULSING) {
            if (DEBUG) Log.i(TAG, "Prox NEAR, ending pulse");
            DozeLog.tracePulseCanceledByProx(mContext);
            mMachine.requestState(DozeMachine.State.DOZE_PULSE_DONE);
        }
        if (far && state == DozeMachine.State.DOZE_AOD_PAUSED) {
@@ -181,6 +182,10 @@ public class DozeTriggers implements DozeMachine.Part {
        Assert.isMainThread();
        mDozeHost.extendPulse();
        if (mPulsePending || !mAllowPulseTriggers || !canPulse()) {
            if (mAllowPulseTriggers) {
                DozeLog.tracePulseDropped(mContext, mPulsePending, mMachine.getState(),
                        mDozeHost.isPulsingBlocked());
            }
            return;
        }

@@ -204,6 +209,7 @@ public class DozeTriggers implements DozeMachine.Part {
                }
                // avoid pulsing in pockets
                if (result == RESULT_NEAR) {
                    mPulsePending = false;
                    return;
                }

@@ -221,6 +227,8 @@ public class DozeTriggers implements DozeMachine.Part {
    private void continuePulseRequest(int reason) {
        mPulsePending = false;
        if (mDozeHost.isPulsingBlocked() || !canPulse()) {
            DozeLog.tracePulseDropped(mContext, mPulsePending, mMachine.getState(),
                    mDozeHost.isPulsingBlocked());
            return;
        }
        mMachine.requestState(DozeMachine.State.DOZE_REQUEST_PULSE);
+70 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.doze;

import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;

import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.systemui.statusbar.phone.DozeParameters;

import org.mockito.Answers;
import org.mockito.MockSettings;

public class DozeConfigurationUtil {
    public static DozeParameters createMockParameters() {
        boolean[] doneHolder = new boolean[1];
        DozeParameters params = mock(DozeParameters.class, noDefaultAnswer(doneHolder));

        when(params.getPulseOnSigMotion()).thenReturn(false);
        when(params.getSensorsWakeUpFully()).thenReturn(false);
        when(params.getPickupVibrationThreshold()).thenReturn(0);
        when(params.getProxCheckBeforePulse()).thenReturn(true);
        when(params.getPickupSubtypePerformsProxCheck(anyInt())).thenReturn(true);

        doneHolder[0] = true;
        return params;
    }

    public static AmbientDisplayConfiguration createMockConfig() {
        boolean[] doneHolder = new boolean[1];
        AmbientDisplayConfiguration config = mock(AmbientDisplayConfiguration.class,
                noDefaultAnswer(doneHolder));
        when(config.pulseOnDoubleTapEnabled(anyInt())).thenReturn(false);
        when(config.pulseOnPickupEnabled(anyInt())).thenReturn(false);
        when(config.pulseOnNotificationEnabled(anyInt())).thenReturn(true);

        when(config.doubleTapSensorType()).thenReturn(null);
        when(config.pulseOnPickupAvailable()).thenReturn(false);

        doneHolder[0] = true;
        return config;
    }

    private static MockSettings noDefaultAnswer(boolean[] setupDoneHolder) {
        return withSettings().defaultAnswer((i) -> {
            if (setupDoneHolder[0]) {
                throw new IllegalArgumentException("not defined");
            } else {
                return Answers.RETURNS_DEFAULTS.answer(i);
            }
        });
    }

}
+84 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.doze;

import android.annotation.NonNull;
import android.app.PendingIntent;

/**
 * A rudimentary fake for DozeHost.
 */
class DozeHostFake implements DozeHost {
    Callback callback;
    private boolean pulseAborted;
    private boolean pulseExtended;

    @Override
    public void addCallback(@NonNull Callback callback) {
        this.callback = callback;
    }

    @Override
    public void removeCallback(@NonNull Callback callback) {
        this.callback = null;
    }

    @Override
    public void startDozing() {
        throw new RuntimeException("not implemented");
    }

    @Override
    public void pulseWhileDozing(@NonNull PulseCallback callback, int reason) {
        throw new RuntimeException("not implemented");
    }

    @Override
    public void stopDozing() {
        throw new RuntimeException("not implemented");
    }

    @Override
    public void dozeTimeTick() {
        throw new RuntimeException("not implemented");
    }

    @Override
    public boolean isPowerSaveActive() {
        return false;
    }

    @Override
    public boolean isPulsingBlocked() {
        return false;
    }

    @Override
    public void startPendingIntentDismissingKeyguard(PendingIntent intent) {
        throw new RuntimeException("not implemented");
    }

    @Override
    public void abortPulsing() {
        pulseAborted = true;
    }

    @Override
    public void extendPulse() {
        pulseExtended = true;
    }
}
Loading