Loading packages/SystemUI/src/com/android/systemui/doze/DozeLog.java +30 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; Loading packages/SystemUI/src/com/android/systemui/doze/DozeMachine.java +1 −1 Original line number Diff line number Diff line Loading @@ -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. */ Loading packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java +8 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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; } Loading @@ -204,6 +209,7 @@ public class DozeTriggers implements DozeMachine.Part { } // avoid pulsing in pockets if (result == RESULT_NEAR) { mPulsePending = false; return; } Loading @@ -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); Loading packages/SystemUI/tests/src/com/android/systemui/doze/DozeConfigurationUtil.java 0 → 100644 +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); } }); } } packages/SystemUI/tests/src/com/android/systemui/doze/DozeHostFake.java 0 → 100644 +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
packages/SystemUI/src/com/android/systemui/doze/DozeLog.java +30 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; Loading
packages/SystemUI/src/com/android/systemui/doze/DozeMachine.java +1 −1 Original line number Diff line number Diff line Loading @@ -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. */ Loading
packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java +8 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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; } Loading @@ -204,6 +209,7 @@ public class DozeTriggers implements DozeMachine.Part { } // avoid pulsing in pockets if (result == RESULT_NEAR) { mPulsePending = false; return; } Loading @@ -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); Loading
packages/SystemUI/tests/src/com/android/systemui/doze/DozeConfigurationUtil.java 0 → 100644 +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); } }); } }
packages/SystemUI/tests/src/com/android/systemui/doze/DozeHostFake.java 0 → 100644 +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; } }