blob: 9eb94f4aed72e1285c63b9b1a3b575be80d3ab1a [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;
27import android.support.test.filters.SmallTest;
28
29import com.android.systemui.SysuiTestCase;
Lucas Dupin4c8c3272018-11-06 17:47:48 -080030import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
Lucas Dupin660d5732017-12-19 10:05:19 -080031import com.android.systemui.statusbar.phone.DozeParameters;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070032
Lucas Dupin660d5732017-12-19 10:05:19 -080033import org.junit.Before;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070034import org.junit.Test;
35import org.junit.runner.RunWith;
36import org.junit.runners.JUnit4;
Lucas Dupin660d5732017-12-19 10:05:19 -080037import org.mockito.Mock;
Lucas Dupin660d5732017-12-19 10:05:19 -080038import org.mockito.MockitoAnnotations;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070039
40@RunWith(JUnit4.class)
41@SmallTest
42public class DozeWallpaperStateTest extends SysuiTestCase {
43
Lucas Dupin660d5732017-12-19 10:05:19 -080044 private DozeWallpaperState mDozeWallpaperState;
45 @Mock IWallpaperManager mIWallpaperManager;
46 @Mock DozeParameters mDozeParameters;
Lucas Dupin023d7272019-01-28 14:31:40 -080047 @Mock DozeMachine mMachine;
Lucas Dupin660d5732017-12-19 10:05:19 -080048
49 @Before
50 public void setUp() {
51 MockitoAnnotations.initMocks(this);
Lucas Dupin023d7272019-01-28 14:31:40 -080052 mDozeWallpaperState = new DozeWallpaperState(mMachine, mIWallpaperManager, mDozeParameters);
Lucas Dupin660d5732017-12-19 10:05:19 -080053 }
54
Lucas Dupin7517b5d2017-08-22 12:51:25 -070055 @Test
56 public void testDreamNotification() throws RemoteException {
Lucas Dupin660d5732017-12-19 10:05:19 -080057 // Pre-condition
58 when(mDozeParameters.getAlwaysOn()).thenReturn(true);
59
60 mDozeWallpaperState.transitionTo(DozeMachine.State.UNINITIALIZED,
Lucas Dupin7517b5d2017-08-22 12:51:25 -070061 DozeMachine.State.DOZE_AOD);
Lucas Dupin4c8c3272018-11-06 17:47:48 -080062 verify(mIWallpaperManager).setInAmbientMode(eq(true), anyLong());
Lucas Dupin660d5732017-12-19 10:05:19 -080063 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD, DozeMachine.State.FINISH);
Lucas Dupin4c8c3272018-11-06 17:47:48 -080064 verify(mIWallpaperManager).setInAmbientMode(eq(false), anyLong());
Lucas Dupin660d5732017-12-19 10:05:19 -080065
66 // Make sure we're sending false when AoD is off
67 reset(mDozeParameters);
68 mDozeWallpaperState.transitionTo(DozeMachine.State.FINISH, DozeMachine.State.DOZE_AOD);
Lucas Dupin4c8c3272018-11-06 17:47:48 -080069 verify(mIWallpaperManager).setInAmbientMode(eq(false), anyLong());
Lucas Dupin660d5732017-12-19 10:05:19 -080070 }
71
72 @Test
73 public void testAnimates_whenSupported() throws RemoteException {
74 // Pre-conditions
75 when(mDozeParameters.getDisplayNeedsBlanking()).thenReturn(false);
Lucas Dupin16cfe452018-02-08 13:14:50 -080076 when(mDozeParameters.shouldControlScreenOff()).thenReturn(true);
Lucas Dupin660d5732017-12-19 10:05:19 -080077 when(mDozeParameters.getAlwaysOn()).thenReturn(true);
78
79 mDozeWallpaperState.transitionTo(DozeMachine.State.UNINITIALIZED,
80 DozeMachine.State.DOZE_AOD);
Lucas Dupin4c8c3272018-11-06 17:47:48 -080081 verify(mIWallpaperManager).setInAmbientMode(eq(true),
82 eq((long) StackStateAnimator.ANIMATION_DURATION_WAKEUP));
Lucas Dupin660d5732017-12-19 10:05:19 -080083
84 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD, DozeMachine.State.FINISH);
Lucas Dupin4c8c3272018-11-06 17:47:48 -080085 verify(mIWallpaperManager).setInAmbientMode(eq(false),
86 eq((long) StackStateAnimator.ANIMATION_DURATION_WAKEUP));
Lucas Dupin660d5732017-12-19 10:05:19 -080087 }
88
89 @Test
90 public void testDoesNotAnimate_whenNotSupported() throws RemoteException {
91 // Pre-conditions
92 when(mDozeParameters.getDisplayNeedsBlanking()).thenReturn(true);
Lucas Dupin660d5732017-12-19 10:05:19 -080093 when(mDozeParameters.getAlwaysOn()).thenReturn(true);
Lucas Dupin16cfe452018-02-08 13:14:50 -080094 when(mDozeParameters.shouldControlScreenOff()).thenReturn(false);
Lucas Dupin660d5732017-12-19 10:05:19 -080095
96 mDozeWallpaperState.transitionTo(DozeMachine.State.UNINITIALIZED,
97 DozeMachine.State.DOZE_AOD);
Lucas Dupin4c8c3272018-11-06 17:47:48 -080098 verify(mIWallpaperManager).setInAmbientMode(eq(true), eq(0L));
Lucas Dupin660d5732017-12-19 10:05:19 -080099
100 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD, DozeMachine.State.FINISH);
Lucas Dupin4c8c3272018-11-06 17:47:48 -0800101 verify(mIWallpaperManager).setInAmbientMode(eq(false), eq(0L));
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700102 }
Lucas Dupin30c75472018-05-18 12:57:47 -0700103
104 @Test
105 public void testTransitionTo_requestPulseIsAmbientMode() throws RemoteException {
106 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE,
107 DozeMachine.State.DOZE_REQUEST_PULSE);
Lucas Dupin4c8c3272018-11-06 17:47:48 -0800108 verify(mIWallpaperManager).setInAmbientMode(eq(true), eq(0L));
Lucas Dupin30c75472018-05-18 12:57:47 -0700109 }
110
111 @Test
Lucas Dupin023d7272019-01-28 14:31:40 -0800112 public void testTransitionTo_notificationPulseIsAmbientMode() throws RemoteException {
113 when(mMachine.getPulseReason()).thenReturn(DozeLog.PULSE_REASON_NOTIFICATION);
Lucas Dupin30c75472018-05-18 12:57:47 -0700114 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_REQUEST_PULSE,
115 DozeMachine.State.DOZE_PULSING);
Lucas Dupin4c8c3272018-11-06 17:47:48 -0800116 verify(mIWallpaperManager).setInAmbientMode(eq(true), eq(0L));
Lucas Dupin30c75472018-05-18 12:57:47 -0700117 }
118
119 @Test
Lucas Dupin023d7272019-01-28 14:31:40 -0800120 public void testTransitionTo_wakeFromPulseIsNotAmbientMode() throws RemoteException {
121 when(mMachine.getPulseReason()).thenReturn(DozeLog.PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN);
122 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD,
123 DozeMachine.State.DOZE_REQUEST_PULSE);
124 reset(mIWallpaperManager);
125
126 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_REQUEST_PULSE,
127 DozeMachine.State.DOZE_PULSING);
128 verify(mIWallpaperManager).setInAmbientMode(eq(false), anyLong());
129 }
130
131 @Test
Lucas Dupin30c75472018-05-18 12:57:47 -0700132 public void testTransitionTo_animatesWhenWakingUpFromPulse() throws RemoteException {
Lucas Dupin023d7272019-01-28 14:31:40 -0800133 when(mMachine.getPulseReason()).thenReturn(DozeLog.PULSE_REASON_NOTIFICATION);
Lucas Dupin30c75472018-05-18 12:57:47 -0700134 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_REQUEST_PULSE,
135 DozeMachine.State.DOZE_PULSING);
136 reset(mIWallpaperManager);
137 mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_PULSING,
138 DozeMachine.State.FINISH);
Lucas Dupin4c8c3272018-11-06 17:47:48 -0800139 verify(mIWallpaperManager).setInAmbientMode(eq(false),
140 eq((long) StackStateAnimator.ANIMATION_DURATION_WAKEUP));
Lucas Dupin30c75472018-05-18 12:57:47 -0700141 }
Lucas Dupin7517b5d2017-08-22 12:51:25 -0700142}