Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 com.android.systemui.doze.DozeMachine.State.DOZE; |
| 20 | import static com.android.systemui.doze.DozeMachine.State.DOZE_AOD; |
Jerry Chang | ae4dc4b | 2019-10-16 18:45:03 +0800 | [diff] [blame] | 21 | import static com.android.systemui.doze.DozeMachine.State.DOZE_AOD_DOCKED; |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 22 | import static com.android.systemui.doze.DozeMachine.State.DOZE_PULSE_DONE; |
| 23 | import static com.android.systemui.doze.DozeMachine.State.DOZE_PULSING; |
| 24 | import static com.android.systemui.doze.DozeMachine.State.DOZE_REQUEST_PULSE; |
| 25 | import static com.android.systemui.doze.DozeMachine.State.FINISH; |
| 26 | import static com.android.systemui.doze.DozeMachine.State.INITIALIZED; |
| 27 | import static com.android.systemui.doze.DozeMachine.State.UNINITIALIZED; |
| 28 | |
| 29 | import static org.junit.Assert.assertEquals; |
| 30 | import static org.junit.Assert.assertFalse; |
| 31 | import static org.junit.Assert.assertTrue; |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 32 | import static org.mockito.ArgumentMatchers.any; |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 33 | import static org.mockito.ArgumentMatchers.anyInt; |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 34 | import static org.mockito.ArgumentMatchers.eq; |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 35 | import static org.mockito.Mockito.doAnswer; |
| 36 | import static org.mockito.Mockito.mock; |
| 37 | import static org.mockito.Mockito.never; |
| 38 | import static org.mockito.Mockito.reset; |
| 39 | import static org.mockito.Mockito.verify; |
| 40 | import static org.mockito.Mockito.when; |
| 41 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 42 | import android.hardware.display.AmbientDisplayConfiguration; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 43 | import android.testing.AndroidTestingRunner; |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 44 | import android.testing.UiThreadTest; |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 45 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 46 | import androidx.test.filters.SmallTest; |
| 47 | |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 48 | import com.android.systemui.SysuiTestCase; |
Jerry Chang | ae4dc4b | 2019-10-16 18:45:03 +0800 | [diff] [blame] | 49 | import com.android.systemui.dock.DockManager; |
Lucas Dupin | 737b851 | 2019-08-09 10:35:34 -0700 | [diff] [blame] | 50 | import com.android.systemui.keyguard.WakefulnessLifecycle; |
Lucas Dupin | bd7366d | 2019-09-25 13:39:21 -0700 | [diff] [blame] | 51 | import com.android.systemui.statusbar.policy.BatteryController; |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 52 | import com.android.systemui.util.wakelock.WakeLockFake; |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 53 | |
| 54 | import org.junit.Before; |
| 55 | import org.junit.Test; |
| 56 | import org.junit.runner.RunWith; |
Lucas Dupin | 737b851 | 2019-08-09 10:35:34 -0700 | [diff] [blame] | 57 | import org.mockito.Mock; |
| 58 | import org.mockito.MockitoAnnotations; |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 59 | |
| 60 | @SmallTest |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 61 | @RunWith(AndroidTestingRunner.class) |
Jason Monk | ba36432 | 2017-03-06 11:19:20 -0500 | [diff] [blame] | 62 | @UiThreadTest |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 63 | public class DozeMachineTest extends SysuiTestCase { |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 64 | |
| 65 | DozeMachine mMachine; |
| 66 | |
Lucas Dupin | 737b851 | 2019-08-09 10:35:34 -0700 | [diff] [blame] | 67 | @Mock |
| 68 | private WakefulnessLifecycle mWakefulnessLifecycle; |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 69 | @Mock |
| 70 | private DozeLog mDozeLog; |
Jerry Chang | ae4dc4b | 2019-10-16 18:45:03 +0800 | [diff] [blame] | 71 | @Mock private DockManager mDockManager; |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 72 | private DozeServiceFake mServiceFake; |
| 73 | private WakeLockFake mWakeLockFake; |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 74 | private AmbientDisplayConfiguration mConfigMock; |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 75 | private DozeMachine.Part mPartMock; |
| 76 | |
| 77 | @Before |
| 78 | public void setUp() { |
Lucas Dupin | 737b851 | 2019-08-09 10:35:34 -0700 | [diff] [blame] | 79 | MockitoAnnotations.initMocks(this); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 80 | mServiceFake = new DozeServiceFake(); |
| 81 | mWakeLockFake = new WakeLockFake(); |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 82 | mConfigMock = mock(AmbientDisplayConfiguration.class); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 83 | mPartMock = mock(DozeMachine.Part.class); |
Jerry Chang | ae4dc4b | 2019-10-16 18:45:03 +0800 | [diff] [blame] | 84 | when(mDockManager.isDocked()).thenReturn(false); |
| 85 | when(mDockManager.isHidden()).thenReturn(false); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 86 | |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 87 | mMachine = new DozeMachine(mServiceFake, mConfigMock, mWakeLockFake, |
Jerry Chang | ae4dc4b | 2019-10-16 18:45:03 +0800 | [diff] [blame] | 88 | mWakefulnessLifecycle, mock(BatteryController.class), mDozeLog, mDockManager); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 89 | mMachine.setParts(new DozeMachine.Part[]{mPartMock}); |
| 90 | } |
| 91 | |
| 92 | @Test |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 93 | public void testInitialize_initializesParts() { |
| 94 | mMachine.requestState(INITIALIZED); |
| 95 | |
| 96 | verify(mPartMock).transitionTo(UNINITIALIZED, INITIALIZED); |
| 97 | } |
| 98 | |
| 99 | @Test |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 100 | public void testInitialize_goesToDoze() { |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 101 | when(mConfigMock.alwaysOnEnabled(anyInt())).thenReturn(false); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 102 | |
| 103 | mMachine.requestState(INITIALIZED); |
| 104 | |
| 105 | verify(mPartMock).transitionTo(INITIALIZED, DOZE); |
| 106 | assertEquals(DOZE, mMachine.getState()); |
| 107 | } |
| 108 | |
| 109 | @Test |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 110 | public void testInitialize_goesToAod() { |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 111 | when(mConfigMock.alwaysOnEnabled(anyInt())).thenReturn(true); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 112 | |
| 113 | mMachine.requestState(INITIALIZED); |
| 114 | |
| 115 | verify(mPartMock).transitionTo(INITIALIZED, DOZE_AOD); |
| 116 | assertEquals(DOZE_AOD, mMachine.getState()); |
| 117 | } |
| 118 | |
| 119 | @Test |
Jerry Chang | ae4dc4b | 2019-10-16 18:45:03 +0800 | [diff] [blame] | 120 | public void testInitialize_afterDocked_goesToDockedAod() { |
| 121 | when(mDockManager.isDocked()).thenReturn(true); |
| 122 | |
| 123 | mMachine.requestState(INITIALIZED); |
| 124 | |
| 125 | verify(mPartMock).transitionTo(INITIALIZED, DOZE_AOD_DOCKED); |
| 126 | assertEquals(DOZE_AOD_DOCKED, mMachine.getState()); |
| 127 | } |
| 128 | |
| 129 | @Test |
| 130 | public void testInitialize_afterDockPaused_goesToDoze() { |
| 131 | when(mConfigMock.alwaysOnEnabled(anyInt())).thenReturn(true); |
| 132 | when(mDockManager.isDocked()).thenReturn(true); |
| 133 | when(mDockManager.isHidden()).thenReturn(true); |
| 134 | |
| 135 | mMachine.requestState(INITIALIZED); |
| 136 | |
| 137 | verify(mPartMock).transitionTo(INITIALIZED, DOZE); |
| 138 | assertEquals(DOZE, mMachine.getState()); |
| 139 | } |
| 140 | |
| 141 | @Test |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 142 | public void testPulseDone_goesToDoze() { |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 143 | when(mConfigMock.alwaysOnEnabled(anyInt())).thenReturn(false); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 144 | mMachine.requestState(INITIALIZED); |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 145 | mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 146 | mMachine.requestState(DOZE_PULSING); |
| 147 | |
| 148 | mMachine.requestState(DOZE_PULSE_DONE); |
| 149 | |
| 150 | verify(mPartMock).transitionTo(DOZE_PULSE_DONE, DOZE); |
| 151 | assertEquals(DOZE, mMachine.getState()); |
| 152 | } |
| 153 | |
| 154 | @Test |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 155 | public void testPulseDone_goesToAoD() { |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 156 | when(mConfigMock.alwaysOnEnabled(anyInt())).thenReturn(true); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 157 | mMachine.requestState(INITIALIZED); |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 158 | mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 159 | mMachine.requestState(DOZE_PULSING); |
| 160 | |
| 161 | mMachine.requestState(DOZE_PULSE_DONE); |
| 162 | |
| 163 | verify(mPartMock).transitionTo(DOZE_PULSE_DONE, DOZE_AOD); |
| 164 | assertEquals(DOZE_AOD, mMachine.getState()); |
| 165 | } |
| 166 | |
| 167 | @Test |
Jerry Chang | ae4dc4b | 2019-10-16 18:45:03 +0800 | [diff] [blame] | 168 | public void testPulseDone_afterDocked_goesToDockedAoD() { |
| 169 | when(mDockManager.isDocked()).thenReturn(true); |
| 170 | mMachine.requestState(INITIALIZED); |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 171 | mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); |
Jerry Chang | ae4dc4b | 2019-10-16 18:45:03 +0800 | [diff] [blame] | 172 | mMachine.requestState(DOZE_PULSING); |
| 173 | |
| 174 | mMachine.requestState(DOZE_PULSE_DONE); |
| 175 | |
| 176 | verify(mPartMock).transitionTo(DOZE_PULSE_DONE, DOZE_AOD_DOCKED); |
| 177 | assertEquals(DOZE_AOD_DOCKED, mMachine.getState()); |
| 178 | } |
| 179 | |
| 180 | @Test |
| 181 | public void testPulseDone_afterDockPaused_goesToDoze() { |
| 182 | when(mConfigMock.alwaysOnEnabled(anyInt())).thenReturn(true); |
| 183 | when(mDockManager.isDocked()).thenReturn(true); |
| 184 | when(mDockManager.isHidden()).thenReturn(true); |
| 185 | mMachine.requestState(INITIALIZED); |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 186 | mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); |
Jerry Chang | ae4dc4b | 2019-10-16 18:45:03 +0800 | [diff] [blame] | 187 | mMachine.requestState(DOZE_PULSING); |
| 188 | |
| 189 | mMachine.requestState(DOZE_PULSE_DONE); |
| 190 | |
| 191 | verify(mPartMock).transitionTo(DOZE_PULSE_DONE, DOZE); |
| 192 | assertEquals(DOZE, mMachine.getState()); |
| 193 | } |
| 194 | |
| 195 | @Test |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 196 | public void testFinished_staysFinished() { |
| 197 | mMachine.requestState(INITIALIZED); |
| 198 | mMachine.requestState(FINISH); |
| 199 | reset(mPartMock); |
| 200 | |
| 201 | mMachine.requestState(DOZE); |
| 202 | |
| 203 | verify(mPartMock, never()).transitionTo(any(), any()); |
| 204 | assertEquals(FINISH, mMachine.getState()); |
| 205 | } |
| 206 | |
| 207 | @Test |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 208 | public void testFinish_finishesService() { |
| 209 | mMachine.requestState(INITIALIZED); |
| 210 | |
| 211 | mMachine.requestState(FINISH); |
| 212 | |
| 213 | assertTrue(mServiceFake.finished); |
| 214 | } |
| 215 | |
| 216 | @Test |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 217 | public void testWakeLock_heldInTransition() { |
| 218 | doAnswer((inv) -> { |
| 219 | assertTrue(mWakeLockFake.isHeld()); |
| 220 | return null; |
| 221 | }).when(mPartMock).transitionTo(any(), any()); |
| 222 | |
| 223 | mMachine.requestState(INITIALIZED); |
| 224 | } |
| 225 | |
| 226 | @Test |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 227 | public void testWakeLock_heldInPulseStates() { |
| 228 | mMachine.requestState(INITIALIZED); |
| 229 | |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 230 | mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 231 | assertTrue(mWakeLockFake.isHeld()); |
| 232 | |
| 233 | mMachine.requestState(DOZE_PULSING); |
| 234 | assertTrue(mWakeLockFake.isHeld()); |
| 235 | } |
| 236 | |
| 237 | @Test |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 238 | public void testWakeLock_notHeldInDozeStates() { |
| 239 | mMachine.requestState(INITIALIZED); |
| 240 | |
| 241 | mMachine.requestState(DOZE); |
| 242 | assertFalse(mWakeLockFake.isHeld()); |
| 243 | |
| 244 | mMachine.requestState(DOZE_AOD); |
| 245 | assertFalse(mWakeLockFake.isHeld()); |
| 246 | } |
| 247 | |
| 248 | @Test |
Adrian Roos | ae0c5e8 | 2016-11-16 19:56:19 -0800 | [diff] [blame] | 249 | public void testWakeLock_releasedAfterPulse() { |
| 250 | mMachine.requestState(INITIALIZED); |
| 251 | |
| 252 | mMachine.requestState(DOZE); |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 253 | mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); |
Adrian Roos | ae0c5e8 | 2016-11-16 19:56:19 -0800 | [diff] [blame] | 254 | mMachine.requestState(DOZE_PULSING); |
| 255 | mMachine.requestState(DOZE_PULSE_DONE); |
| 256 | |
| 257 | assertFalse(mWakeLockFake.isHeld()); |
| 258 | } |
| 259 | |
| 260 | @Test |
Adrian Roos | b84dc18 | 2016-12-02 09:01:09 -0800 | [diff] [blame] | 261 | public void testPulseDuringPulse_doesntCrash() { |
| 262 | mMachine.requestState(INITIALIZED); |
| 263 | |
| 264 | mMachine.requestState(DOZE); |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 265 | mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); |
Adrian Roos | b84dc18 | 2016-12-02 09:01:09 -0800 | [diff] [blame] | 266 | mMachine.requestState(DOZE_PULSING); |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 267 | mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); |
Adrian Roos | b84dc18 | 2016-12-02 09:01:09 -0800 | [diff] [blame] | 268 | mMachine.requestState(DOZE_PULSE_DONE); |
| 269 | } |
| 270 | |
| 271 | @Test |
Adrian Roos | cd139a6 | 2016-12-16 12:23:51 -0800 | [diff] [blame] | 272 | public void testSuppressingPulse_doesntCrash() { |
| 273 | mMachine.requestState(INITIALIZED); |
| 274 | |
| 275 | mMachine.requestState(DOZE); |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 276 | mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); |
Adrian Roos | cd139a6 | 2016-12-16 12:23:51 -0800 | [diff] [blame] | 277 | mMachine.requestState(DOZE_PULSE_DONE); |
| 278 | } |
| 279 | |
| 280 | @Test |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 281 | public void testTransitions_canRequestTransitions() { |
| 282 | mMachine.requestState(INITIALIZED); |
| 283 | mMachine.requestState(DOZE); |
| 284 | doAnswer(inv -> { |
| 285 | mMachine.requestState(DOZE_PULSING); |
| 286 | return null; |
| 287 | }).when(mPartMock).transitionTo(any(), eq(DOZE_REQUEST_PULSE)); |
| 288 | |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 289 | mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 290 | |
| 291 | assertEquals(DOZE_PULSING, mMachine.getState()); |
| 292 | } |
Adrian Roos | 4fb1f51 | 2017-02-14 14:01:32 +0100 | [diff] [blame] | 293 | |
| 294 | @Test |
Adrian Roos | d7b9d10 | 2017-04-28 15:42:58 -0700 | [diff] [blame] | 295 | public void testPulseReason_getMatchesRequest() { |
| 296 | mMachine.requestState(INITIALIZED); |
| 297 | mMachine.requestState(DOZE); |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 298 | mMachine.requestPulse(DozeLog.REASON_SENSOR_DOUBLE_TAP); |
Adrian Roos | d7b9d10 | 2017-04-28 15:42:58 -0700 | [diff] [blame] | 299 | |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 300 | assertEquals(DozeLog.REASON_SENSOR_DOUBLE_TAP, mMachine.getPulseReason()); |
Adrian Roos | d7b9d10 | 2017-04-28 15:42:58 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | @Test |
| 304 | public void testPulseReason_getFromTransition() { |
| 305 | mMachine.requestState(INITIALIZED); |
| 306 | mMachine.requestState(DOZE); |
| 307 | doAnswer(inv -> { |
| 308 | DozeMachine.State newState = inv.getArgument(1); |
| 309 | if (newState == DOZE_REQUEST_PULSE |
| 310 | || newState == DOZE_PULSING |
| 311 | || newState == DOZE_PULSE_DONE) { |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 312 | assertEquals(DozeLog.PULSE_REASON_NOTIFICATION, mMachine.getPulseReason()); |
Adrian Roos | d7b9d10 | 2017-04-28 15:42:58 -0700 | [diff] [blame] | 313 | } else { |
| 314 | assertTrue("unexpected state " + newState, |
| 315 | newState == DOZE || newState == DOZE_AOD); |
| 316 | } |
| 317 | return null; |
| 318 | }).when(mPartMock).transitionTo(any(), any()); |
| 319 | |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 320 | mMachine.requestPulse(DozeLog.PULSE_REASON_NOTIFICATION); |
Adrian Roos | d7b9d10 | 2017-04-28 15:42:58 -0700 | [diff] [blame] | 321 | mMachine.requestState(DOZE_PULSING); |
| 322 | mMachine.requestState(DOZE_PULSE_DONE); |
| 323 | } |
| 324 | |
| 325 | @Test |
Adrian Roos | 4fb1f51 | 2017-02-14 14:01:32 +0100 | [diff] [blame] | 326 | public void testWakeUp_wakesUp() { |
| 327 | mMachine.wakeUp(); |
| 328 | |
| 329 | assertTrue(mServiceFake.requestedWakeup); |
| 330 | } |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 331 | } |