Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 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 | |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 19 | import static org.mockito.ArgumentMatchers.anyLong; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 20 | import static org.mockito.ArgumentMatchers.eq; |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 21 | import static org.mockito.Mockito.reset; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 22 | import static org.mockito.Mockito.verify; |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 23 | import static org.mockito.Mockito.when; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 24 | |
| 25 | import android.app.IWallpaperManager; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 26 | import android.os.RemoteException; |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 27 | |
| 28 | import androidx.test.filters.SmallTest; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 29 | |
| 30 | import com.android.systemui.SysuiTestCase; |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 31 | import com.android.systemui.statusbar.notification.stack.StackStateAnimator; |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 32 | import com.android.systemui.statusbar.phone.DozeParameters; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 33 | |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 34 | import org.junit.Before; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 35 | import org.junit.Test; |
| 36 | import org.junit.runner.RunWith; |
| 37 | import org.junit.runners.JUnit4; |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 38 | import org.mockito.Mock; |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 39 | import org.mockito.MockitoAnnotations; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 40 | |
| 41 | @RunWith(JUnit4.class) |
| 42 | @SmallTest |
| 43 | public class DozeWallpaperStateTest extends SysuiTestCase { |
| 44 | |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 45 | private DozeWallpaperState mDozeWallpaperState; |
| 46 | @Mock IWallpaperManager mIWallpaperManager; |
| 47 | @Mock DozeParameters mDozeParameters; |
Lucas Dupin | 023d727 | 2019-01-28 14:31:40 -0800 | [diff] [blame] | 48 | @Mock DozeMachine mMachine; |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 49 | |
| 50 | @Before |
| 51 | public void setUp() { |
| 52 | MockitoAnnotations.initMocks(this); |
Lucas Dupin | 023d727 | 2019-01-28 14:31:40 -0800 | [diff] [blame] | 53 | mDozeWallpaperState = new DozeWallpaperState(mMachine, mIWallpaperManager, mDozeParameters); |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 54 | } |
| 55 | |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 56 | @Test |
| 57 | public void testDreamNotification() throws RemoteException { |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 58 | // Pre-condition |
| 59 | when(mDozeParameters.getAlwaysOn()).thenReturn(true); |
| 60 | |
| 61 | mDozeWallpaperState.transitionTo(DozeMachine.State.UNINITIALIZED, |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 62 | DozeMachine.State.DOZE_AOD); |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 63 | verify(mIWallpaperManager).setInAmbientMode(eq(true), anyLong()); |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 64 | mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD, DozeMachine.State.FINISH); |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 65 | verify(mIWallpaperManager).setInAmbientMode(eq(false), anyLong()); |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 66 | |
| 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 Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 70 | verify(mIWallpaperManager).setInAmbientMode(eq(false), anyLong()); |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Test |
| 74 | public void testAnimates_whenSupported() throws RemoteException { |
| 75 | // Pre-conditions |
| 76 | when(mDozeParameters.getDisplayNeedsBlanking()).thenReturn(false); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 77 | when(mDozeParameters.shouldControlScreenOff()).thenReturn(true); |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 78 | when(mDozeParameters.getAlwaysOn()).thenReturn(true); |
| 79 | |
| 80 | mDozeWallpaperState.transitionTo(DozeMachine.State.UNINITIALIZED, |
| 81 | DozeMachine.State.DOZE_AOD); |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 82 | verify(mIWallpaperManager).setInAmbientMode(eq(true), |
| 83 | eq((long) StackStateAnimator.ANIMATION_DURATION_WAKEUP)); |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 84 | |
| 85 | mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD, DozeMachine.State.FINISH); |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 86 | verify(mIWallpaperManager).setInAmbientMode(eq(false), |
| 87 | eq((long) StackStateAnimator.ANIMATION_DURATION_WAKEUP)); |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | @Test |
| 91 | public void testDoesNotAnimate_whenNotSupported() throws RemoteException { |
| 92 | // Pre-conditions |
| 93 | when(mDozeParameters.getDisplayNeedsBlanking()).thenReturn(true); |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 94 | when(mDozeParameters.getAlwaysOn()).thenReturn(true); |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 95 | when(mDozeParameters.shouldControlScreenOff()).thenReturn(false); |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 96 | |
| 97 | mDozeWallpaperState.transitionTo(DozeMachine.State.UNINITIALIZED, |
| 98 | DozeMachine.State.DOZE_AOD); |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 99 | verify(mIWallpaperManager).setInAmbientMode(eq(true), eq(0L)); |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 100 | |
| 101 | mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD, DozeMachine.State.FINISH); |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 102 | verify(mIWallpaperManager).setInAmbientMode(eq(false), eq(0L)); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 103 | } |
Lucas Dupin | 30c7547 | 2018-05-18 12:57:47 -0700 | [diff] [blame] | 104 | |
| 105 | @Test |
| 106 | public void testTransitionTo_requestPulseIsAmbientMode() throws RemoteException { |
| 107 | mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE, |
| 108 | DozeMachine.State.DOZE_REQUEST_PULSE); |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 109 | verify(mIWallpaperManager).setInAmbientMode(eq(true), eq(0L)); |
Lucas Dupin | 30c7547 | 2018-05-18 12:57:47 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Test |
Lucas Dupin | 023d727 | 2019-01-28 14:31:40 -0800 | [diff] [blame] | 113 | public void testTransitionTo_notificationPulseIsAmbientMode() throws RemoteException { |
| 114 | when(mMachine.getPulseReason()).thenReturn(DozeLog.PULSE_REASON_NOTIFICATION); |
Lucas Dupin | 30c7547 | 2018-05-18 12:57:47 -0700 | [diff] [blame] | 115 | mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_REQUEST_PULSE, |
| 116 | DozeMachine.State.DOZE_PULSING); |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 117 | verify(mIWallpaperManager).setInAmbientMode(eq(true), eq(0L)); |
Lucas Dupin | 30c7547 | 2018-05-18 12:57:47 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | @Test |
Lucas Dupin | 023d727 | 2019-01-28 14:31:40 -0800 | [diff] [blame] | 121 | 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 Dupin | 30c7547 | 2018-05-18 12:57:47 -0700 | [diff] [blame] | 133 | public void testTransitionTo_animatesWhenWakingUpFromPulse() throws RemoteException { |
Lucas Dupin | 023d727 | 2019-01-28 14:31:40 -0800 | [diff] [blame] | 134 | when(mMachine.getPulseReason()).thenReturn(DozeLog.PULSE_REASON_NOTIFICATION); |
Lucas Dupin | 30c7547 | 2018-05-18 12:57:47 -0700 | [diff] [blame] | 135 | 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 Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 140 | verify(mIWallpaperManager).setInAmbientMode(eq(false), |
| 141 | eq((long) StackStateAnimator.ANIMATION_DURATION_WAKEUP)); |
Lucas Dupin | 30c7547 | 2018-05-18 12:57:47 -0700 | [diff] [blame] | 142 | } |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 143 | } |