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