1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.systemui.doze; 18 19 import static org.mockito.ArgumentMatchers.anyLong; 20 import static org.mockito.ArgumentMatchers.eq; 21 import static org.mockito.Mockito.clearInvocations; 22 import static org.mockito.Mockito.reset; 23 import static org.mockito.Mockito.verify; 24 import static org.mockito.Mockito.when; 25 26 import android.app.IWallpaperManager; 27 import android.os.RemoteException; 28 29 import androidx.test.filters.SmallTest; 30 31 import com.android.systemui.SysuiTestCase; 32 import com.android.systemui.statusbar.notification.stack.StackStateAnimator; 33 import com.android.systemui.statusbar.phone.BiometricUnlockController; 34 import com.android.systemui.statusbar.phone.DozeParameters; 35 36 import org.junit.Before; 37 import org.junit.Test; 38 import org.junit.runner.RunWith; 39 import org.junit.runners.JUnit4; 40 import org.mockito.Mock; 41 import org.mockito.MockitoAnnotations; 42 43 @RunWith(JUnit4.class) 44 @SmallTest 45 public class DozeWallpaperStateTest extends SysuiTestCase { 46 47 private DozeWallpaperState mDozeWallpaperState; 48 @Mock IWallpaperManager mIWallpaperManager; 49 @Mock BiometricUnlockController mBiometricUnlockController; 50 @Mock DozeParameters mDozeParameters; 51 52 @Before setUp()53 public void setUp() { 54 MockitoAnnotations.initMocks(this); 55 mDozeWallpaperState = new DozeWallpaperState(mIWallpaperManager, mBiometricUnlockController, 56 mDozeParameters); 57 } 58 59 @Test testDreamNotification()60 public void testDreamNotification() throws RemoteException { 61 // Pre-condition 62 when(mDozeParameters.getAlwaysOn()).thenReturn(true); 63 64 mDozeWallpaperState.transitionTo(DozeMachine.State.UNINITIALIZED, 65 DozeMachine.State.DOZE_AOD); 66 verify(mIWallpaperManager).setInAmbientMode(eq(true), anyLong()); 67 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD, DozeMachine.State.FINISH); 68 verify(mIWallpaperManager).setInAmbientMode(eq(false), anyLong()); 69 70 // Make sure we're sending false when AoD is off 71 reset(mDozeParameters); 72 mDozeWallpaperState.transitionTo(DozeMachine.State.FINISH, DozeMachine.State.DOZE_AOD); 73 verify(mIWallpaperManager).setInAmbientMode(eq(false), anyLong()); 74 } 75 76 @Test testAnimates_whenSupported()77 public void testAnimates_whenSupported() throws RemoteException { 78 // Pre-conditions 79 when(mDozeParameters.getDisplayNeedsBlanking()).thenReturn(false); 80 when(mDozeParameters.shouldControlScreenOff()).thenReturn(true); 81 when(mDozeParameters.getAlwaysOn()).thenReturn(true); 82 83 mDozeWallpaperState.transitionTo(DozeMachine.State.UNINITIALIZED, 84 DozeMachine.State.DOZE_AOD); 85 verify(mIWallpaperManager).setInAmbientMode(eq(true), 86 eq((long) StackStateAnimator.ANIMATION_DURATION_WAKEUP)); 87 88 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD, DozeMachine.State.FINISH); 89 verify(mIWallpaperManager).setInAmbientMode(eq(false), 90 eq((long) StackStateAnimator.ANIMATION_DURATION_WAKEUP)); 91 } 92 93 @Test testDoesNotAnimate_whenNotSupported()94 public void testDoesNotAnimate_whenNotSupported() throws RemoteException { 95 // Pre-conditions 96 when(mDozeParameters.getDisplayNeedsBlanking()).thenReturn(true); 97 when(mDozeParameters.getAlwaysOn()).thenReturn(true); 98 when(mDozeParameters.shouldControlScreenOff()).thenReturn(false); 99 100 mDozeWallpaperState.transitionTo(DozeMachine.State.UNINITIALIZED, 101 DozeMachine.State.DOZE_AOD); 102 verify(mIWallpaperManager).setInAmbientMode(eq(true), eq(0L)); 103 104 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD, DozeMachine.State.FINISH); 105 verify(mIWallpaperManager).setInAmbientMode(eq(false), eq(0L)); 106 } 107 108 @Test testDoesNotAnimate_whenWakeAndUnlock()109 public void testDoesNotAnimate_whenWakeAndUnlock() throws RemoteException { 110 // Pre-conditions 111 when(mDozeParameters.getAlwaysOn()).thenReturn(true); 112 when(mBiometricUnlockController.unlockedByWakeAndUnlock()).thenReturn(true); 113 114 mDozeWallpaperState.transitionTo(DozeMachine.State.UNINITIALIZED, 115 DozeMachine.State.DOZE_AOD); 116 clearInvocations(mIWallpaperManager); 117 118 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD, DozeMachine.State.FINISH); 119 verify(mIWallpaperManager).setInAmbientMode(eq(false), eq(0L)); 120 } 121 122 @Test testTransitionTo_requestPulseIsAmbientMode()123 public void testTransitionTo_requestPulseIsAmbientMode() throws RemoteException { 124 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE, 125 DozeMachine.State.DOZE_REQUEST_PULSE); 126 verify(mIWallpaperManager).setInAmbientMode(eq(true), eq(0L)); 127 } 128 129 @Test testTransitionTo_wakeFromPulseIsNotAmbientMode()130 public void testTransitionTo_wakeFromPulseIsNotAmbientMode() throws RemoteException { 131 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD, 132 DozeMachine.State.DOZE_REQUEST_PULSE); 133 reset(mIWallpaperManager); 134 135 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_REQUEST_PULSE, 136 DozeMachine.State.DOZE_PULSING_BRIGHT); 137 verify(mIWallpaperManager).setInAmbientMode(eq(false), anyLong()); 138 } 139 140 @Test testTransitionTo_animatesWhenWakingUpFromPulse()141 public void testTransitionTo_animatesWhenWakingUpFromPulse() throws RemoteException { 142 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_REQUEST_PULSE, 143 DozeMachine.State.DOZE_PULSING); 144 reset(mIWallpaperManager); 145 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_PULSING, 146 DozeMachine.State.FINISH); 147 verify(mIWallpaperManager).setInAmbientMode(eq(false), 148 eq((long) StackStateAnimator.ANIMATION_DURATION_WAKEUP)); 149 } 150 } 151