blob: beba905279aa17811291f2111ca5543393387a1a [file] [log] [blame]
Lucas Dupin7517b5d2017-08-22 12:51:25 -07001/*
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
17package com.android.systemui.doze;
18
Lucas Dupin4c8c3272018-11-06 17:47:48 -080019import static org.mockito.ArgumentMatchers.anyLong;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070020import static org.mockito.ArgumentMatchers.eq;
Lucas Dupin660d5732017-12-19 10:05:19 -080021import static org.mockito.Mockito.reset;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070022import static org.mockito.Mockito.verify;
Lucas Dupin660d5732017-12-19 10:05:19 -080023import static org.mockito.Mockito.when;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070024
25import android.app.IWallpaperManager;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070026import android.os.RemoteException;
Brett Chabot84151d92019-02-27 15:37:59 -080027
28import androidx.test.filters.SmallTest;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070029
30import com.android.systemui.SysuiTestCase;
Lucas Dupin4c8c3272018-11-06 17:47:48 -080031import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
Lucas Dupin660d5732017-12-19 10:05:19 -080032import com.android.systemui.statusbar.phone.DozeParameters;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070033
Lucas Dupin660d5732017-12-19 10:05:19 -080034import org.junit.Before;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070035import org.junit.Test;
36import org.junit.runner.RunWith;
37import org.junit.runners.JUnit4;
Lucas Dupin660d5732017-12-19 10:05:19 -080038import org.mockito.Mock;
Lucas Dupin660d5732017-12-19 10:05:19 -080039import org.mockito.MockitoAnnotations;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070040
41@RunWith(JUnit4.class)
42@SmallTest
43public class DozeWallpaperStateTest extends SysuiTestCase {
44
Lucas Dupin660d5732017-12-19 10:05:19 -080045 private DozeWallpaperState mDozeWallpaperState;
46 @Mock IWallpaperManager mIWallpaperManager;
47 @Mock DozeParameters mDozeParameters;
Lucas Dupin023d7272019-01-28 14:31:40 -080048 @Mock DozeMachine mMachine;
Lucas Dupin660d5732017-12-19 10:05:19 -080049
50 @Before
51 public void setUp() {
52 MockitoAnnotations.initMocks(this);
Lucas Dupin023d7272019-01-28 14:31:40 -080053 mDozeWallpaperState = new DozeWallpaperState(mMachine, mIWallpaperManager, mDozeParameters);
Lucas Dupin660d5732017-12-19 10:05:19 -080054 }
55
Lucas Dupin7517b5d2017-08-22 12:51:25 -070056 @Test
57 public void testDreamNotification() throws RemoteException {
Lucas Dupin660d5732017-12-19 10:05:19 -080058 // Pre-condition
59 when(mDozeParameters.getAlwaysOn()).thenReturn(true);
60
61 mDozeWallpaperState.transitionTo(DozeMachine.State.UNINITIALIZED,
Lucas Dupin7517b5d2017-08-22 12:51:25 -070062 DozeMachine.State.DOZE_AOD);
Lucas Dupin4c8c3272018-11-06 17:47:48 -080063 verify(mIWallpaperManager).setInAmbientMode(eq(true), anyLong());
Lucas Dupin660d5732017-12-19 10:05:19 -080064 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD, DozeMachine.State.FINISH);
Lucas Dupin4c8c3272018-11-06 17:47:48 -080065 verify(mIWallpaperManager).setInAmbientMode(eq(false), anyLong());
Lucas Dupin660d5732017-12-19 10:05:19 -080066
67 // Make sure we're sending false when AoD is off
68 reset(mDozeParameters);
69 mDozeWallpaperState.transitionTo(DozeMachine.State.FINISH, DozeMachine.State.DOZE_AOD);
Lucas Dupin4c8c3272018-11-06 17:47:48 -080070 verify(mIWallpaperManager).setInAmbientMode(eq(false), anyLong());
Lucas Dupin660d5732017-12-19 10:05:19 -080071 }
72
73 @Test
74 public void testAnimates_whenSupported() throws RemoteException {
75 // Pre-conditions
76 when(mDozeParameters.getDisplayNeedsBlanking()).thenReturn(false);
Lucas Dupin16cfe452018-02-08 13:14:50 -080077 when(mDozeParameters.shouldControlScreenOff()).thenReturn(true);
Lucas Dupin660d5732017-12-19 10:05:19 -080078 when(mDozeParameters.getAlwaysOn()).thenReturn(true);
79
80 mDozeWallpaperState.transitionTo(DozeMachine.State.UNINITIALIZED,
81 DozeMachine.State.DOZE_AOD);
Lucas Dupin4c8c3272018-11-06 17:47:48 -080082 verify(mIWallpaperManager).setInAmbientMode(eq(true),
83 eq((long) StackStateAnimator.ANIMATION_DURATION_WAKEUP));
Lucas Dupin660d5732017-12-19 10:05:19 -080084
85 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD, DozeMachine.State.FINISH);
Lucas Dupin4c8c3272018-11-06 17:47:48 -080086 verify(mIWallpaperManager).setInAmbientMode(eq(false),
87 eq((long) StackStateAnimator.ANIMATION_DURATION_WAKEUP));
Lucas Dupin660d5732017-12-19 10:05:19 -080088 }
89
90 @Test
91 public void testDoesNotAnimate_whenNotSupported() throws RemoteException {
92 // Pre-conditions
93 when(mDozeParameters.getDisplayNeedsBlanking()).thenReturn(true);
Lucas Dupin660d5732017-12-19 10:05:19 -080094 when(mDozeParameters.getAlwaysOn()).thenReturn(true);
Lucas Dupin16cfe452018-02-08 13:14:50 -080095 when(mDozeParameters.shouldControlScreenOff()).thenReturn(false);
Lucas Dupin660d5732017-12-19 10:05:19 -080096
97 mDozeWallpaperState.transitionTo(DozeMachine.State.UNINITIALIZED,
98 DozeMachine.State.DOZE_AOD);
Lucas Dupin4c8c3272018-11-06 17:47:48 -080099 verify(mIWallpaperManager).setInAmbientMode(eq(true), eq(0L));
Lucas Dupin660d5732017-12-19 10:05:19 -0800100
101 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD, DozeMachine.State.FINISH);
Lucas Dupin4c8c3272018-11-06 17:47:48 -0800102 verify(mIWallpaperManager).setInAmbientMode(eq(false), eq(0L));
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700103 }
Lucas Dupin30c75472018-05-18 12:57:47 -0700104
105 @Test
106 public void testTransitionTo_requestPulseIsAmbientMode() throws RemoteException {
107 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE,
108 DozeMachine.State.DOZE_REQUEST_PULSE);
Lucas Dupin4c8c3272018-11-06 17:47:48 -0800109 verify(mIWallpaperManager).setInAmbientMode(eq(true), eq(0L));
Lucas Dupin30c75472018-05-18 12:57:47 -0700110 }
111
112 @Test
Lucas Dupin023d7272019-01-28 14:31:40 -0800113 public void testTransitionTo_notificationPulseIsAmbientMode() throws RemoteException {
114 when(mMachine.getPulseReason()).thenReturn(DozeLog.PULSE_REASON_NOTIFICATION);
Lucas Dupin30c75472018-05-18 12:57:47 -0700115 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_REQUEST_PULSE,
116 DozeMachine.State.DOZE_PULSING);
Lucas Dupin4c8c3272018-11-06 17:47:48 -0800117 verify(mIWallpaperManager).setInAmbientMode(eq(true), eq(0L));
Lucas Dupin30c75472018-05-18 12:57:47 -0700118 }
119
120 @Test
Lucas Dupin023d7272019-01-28 14:31:40 -0800121 public void testTransitionTo_wakeFromPulseIsNotAmbientMode() throws RemoteException {
122 when(mMachine.getPulseReason()).thenReturn(DozeLog.PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN);
123 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD,
124 DozeMachine.State.DOZE_REQUEST_PULSE);
125 reset(mIWallpaperManager);
126
127 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_REQUEST_PULSE,
128 DozeMachine.State.DOZE_PULSING);
129 verify(mIWallpaperManager).setInAmbientMode(eq(false), anyLong());
130 }
131
132 @Test
Lucas Dupin30c75472018-05-18 12:57:47 -0700133 public void testTransitionTo_animatesWhenWakingUpFromPulse() throws RemoteException {
Lucas Dupin023d7272019-01-28 14:31:40 -0800134 when(mMachine.getPulseReason()).thenReturn(DozeLog.PULSE_REASON_NOTIFICATION);
Lucas Dupin30c75472018-05-18 12:57:47 -0700135 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_REQUEST_PULSE,
136 DozeMachine.State.DOZE_PULSING);
137 reset(mIWallpaperManager);
138 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_PULSING,
139 DozeMachine.State.FINISH);
Lucas Dupin4c8c3272018-11-06 17:47:48 -0800140 verify(mIWallpaperManager).setInAmbientMode(eq(false),
141 eq((long) StackStateAnimator.ANIMATION_DURATION_WAKEUP));
Lucas Dupin30c75472018-05-18 12:57:47 -0700142 }
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700143}