blob: 22f50d0fb591205397478ea7274f7e5d6df3bc45 [file] [log] [blame]
Bartosz Fabianowski5f045002016-12-01 10:36:18 +01001/*
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
17package com.android.systemui.statusbar;
18
Lucas Dupinff6628d2018-10-15 10:12:37 -070019import static com.google.common.truth.Truth.assertThat;
20
Adrian Roosc1b50322017-02-27 21:07:58 +010021import static org.junit.Assert.assertFalse;
22import static org.junit.Assert.assertTrue;
Lucas Dupin8e2fd012019-04-25 16:40:54 -070023import static org.mockito.ArgumentMatchers.any;
Haining Chenc06c4812020-01-13 20:38:53 -080024import static org.mockito.ArgumentMatchers.anyBoolean;
Lucas Dupin0df60fe2019-04-23 10:19:27 -070025import static org.mockito.ArgumentMatchers.anyInt;
26import static org.mockito.ArgumentMatchers.eq;
Lucas Dupin9131b282019-11-19 16:25:03 -080027import static org.mockito.Mockito.clearInvocations;
Jeff DeCewa87cddb2020-06-12 12:13:52 -040028import static org.mockito.Mockito.doNothing;
Jason Monk3cfedd72016-12-09 09:31:37 -050029import static org.mockito.Mockito.mock;
Lucas Dupin9131b282019-11-19 16:25:03 -080030import static org.mockito.Mockito.never;
Jason Monk3cfedd72016-12-09 09:31:37 -050031import static org.mockito.Mockito.reset;
Lucas Dupin8e2fd012019-04-25 16:40:54 -070032import static org.mockito.Mockito.times;
Jason Monk3cfedd72016-12-09 09:31:37 -050033import static org.mockito.Mockito.verify;
Jeff DeCewa87cddb2020-06-12 12:13:52 -040034import static org.mockito.Mockito.verifyNoMoreInteractions;
Jason Monk3cfedd72016-12-09 09:31:37 -050035import static org.mockito.Mockito.when;
36
Adrian Roosc1b50322017-02-27 21:07:58 +010037import android.app.Instrumentation;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +010038import android.app.admin.DevicePolicyManager;
39import android.app.trust.TrustManager;
Jeff DeCewa87cddb2020-06-12 12:13:52 -040040import android.content.BroadcastReceiver;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +010041import android.content.Context;
Jeff DeCewa87cddb2020-06-12 12:13:52 -040042import android.content.Intent;
Lucas Dupinff6628d2018-10-15 10:12:37 -070043import android.graphics.Color;
Lucas Dupin85ea4202019-11-04 16:01:51 -080044import android.hardware.biometrics.BiometricSourceType;
45import android.hardware.face.FaceManager;
Jason Monk3cfedd72016-12-09 09:31:37 -050046import android.hardware.fingerprint.FingerprintManager;
Lucas Dupin9131b282019-11-19 16:25:03 -080047import android.os.BatteryManager;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +010048import android.os.Looper;
Lucas Dupin9131b282019-11-19 16:25:03 -080049import android.os.RemoteException;
Lucas Dupin85ea4202019-11-04 16:01:51 -080050import android.os.UserManager;
Jeff DeCewa87cddb2020-06-12 12:13:52 -040051import android.view.View;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +010052import android.view.ViewGroup;
53
Brett Chabot84151d92019-02-27 15:37:59 -080054import androidx.test.InstrumentationRegistry;
55import androidx.test.filters.SmallTest;
56import androidx.test.runner.AndroidJUnit4;
57
Lucas Dupin9131b282019-11-19 16:25:03 -080058import com.android.internal.app.IBatteryStats;
Lucas Dupin8e2fd012019-04-25 16:40:54 -070059import com.android.keyguard.KeyguardUpdateMonitor;
Jeff DeCewa87cddb2020-06-12 12:13:52 -040060import com.android.keyguard.KeyguardUpdateMonitorCallback;
Jerry Chang6a8fb022019-11-15 06:52:54 +080061import com.android.settingslib.Utils;
Raff Tsaif4ea5622019-06-26 16:15:21 +080062import com.android.settingslib.fuelgauge.BatteryStatus;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +010063import com.android.systemui.R;
64import com.android.systemui.SysuiTestCase;
Jeff DeCewa87cddb2020-06-12 12:13:52 -040065import com.android.systemui.broadcast.BroadcastDispatcher;
Jerry Chang6a8fb022019-11-15 06:52:54 +080066import com.android.systemui.dock.DockManager;
Lucas Dupin8e2fd012019-04-25 16:40:54 -070067import com.android.systemui.plugins.statusbar.StatusBarStateController;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +010068import com.android.systemui.statusbar.phone.KeyguardIndicationTextView;
Jeff DeCewa87cddb2020-06-12 12:13:52 -040069import com.android.systemui.statusbar.phone.LockIcon;
Lucas Dupin85ea4202019-11-04 16:01:51 -080070import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
Lucas Dupinc8f16e82019-09-17 18:24:50 -040071import com.android.systemui.statusbar.policy.KeyguardStateController;
Adrian Roosc1b50322017-02-27 21:07:58 +010072import com.android.systemui.util.wakelock.WakeLockFake;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +010073
74import org.junit.Before;
75import org.junit.Test;
76import org.junit.runner.RunWith;
Lucas Dupin0df60fe2019-04-23 10:19:27 -070077import org.mockito.ArgumentCaptor;
Jerry Chang6a8fb022019-11-15 06:52:54 +080078import org.mockito.Captor;
Lucas Dupinff6628d2018-10-15 10:12:37 -070079import org.mockito.Mock;
80import org.mockito.MockitoAnnotations;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +010081
82@SmallTest
83@RunWith(AndroidJUnit4.class)
84public class KeyguardIndicationControllerTest extends SysuiTestCase {
85
Jeff DeCewa87cddb2020-06-12 12:13:52 -040086 private static final String ORGANIZATION_NAME = "organization";
87
88 private String mDisclosureWithOrganization;
89
Lucas Dupinff6628d2018-10-15 10:12:37 -070090 @Mock
91 private DevicePolicyManager mDevicePolicyManager;
92 @Mock
93 private ViewGroup mIndicationArea;
94 @Mock
Lucas Dupinc8f16e82019-09-17 18:24:50 -040095 private KeyguardStateController mKeyguardStateController;
Lucas Dupin8e2fd012019-04-25 16:40:54 -070096 @Mock
Jeff DeCewa87cddb2020-06-12 12:13:52 -040097 private KeyguardIndicationTextView mDisclosure;
98 @Mock
99 private BroadcastDispatcher mBroadcastDispatcher;
100 @Mock
101 private LockIcon mLockIcon;
102 @Mock
Lucas Dupin8e2fd012019-04-25 16:40:54 -0700103 private StatusBarStateController mStatusBarStateController;
104 @Mock
105 private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
Lucas Dupin85ea4202019-11-04 16:01:51 -0800106 @Mock
107 private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
108 @Mock
109 private UserManager mUserManager;
Jerry Chang6a8fb022019-11-15 06:52:54 +0800110 @Mock
Lucas Dupin9131b282019-11-19 16:25:03 -0800111 private IBatteryStats mIBatteryStats;
112 @Mock
Jerry Chang6a8fb022019-11-15 06:52:54 +0800113 private DockManager mDockManager;
114 @Captor
115 private ArgumentCaptor<DockManager.AlignmentStateListener> mAlignmentListener;
Lucas Dupinff6628d2018-10-15 10:12:37 -0700116 private KeyguardIndicationTextView mTextView;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100117
118 private KeyguardIndicationController mController;
Dave Mankoffc0d9a7d2020-02-27 17:15:52 -0500119 private WakeLockFake.Builder mWakeLockBuilder;
Adrian Roosc1b50322017-02-27 21:07:58 +0100120 private WakeLockFake mWakeLock;
121 private Instrumentation mInstrumentation;
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100122
123 @Before
124 public void setUp() throws Exception {
Lucas Dupinff6628d2018-10-15 10:12:37 -0700125 MockitoAnnotations.initMocks(this);
Adrian Roosc1b50322017-02-27 21:07:58 +0100126 mInstrumentation = InstrumentationRegistry.getInstrumentation();
Lucas Dupinff6628d2018-10-15 10:12:37 -0700127 mTextView = new KeyguardIndicationTextView(mContext);
Adrian Roosc1b50322017-02-27 21:07:58 +0100128
Jason Monk3cfedd72016-12-09 09:31:37 -0500129 mContext.addMockSystemService(Context.DEVICE_POLICY_SERVICE, mDevicePolicyManager);
Lucas Dupin85ea4202019-11-04 16:01:51 -0800130 mContext.addMockSystemService(UserManager.class, mUserManager);
Jason Monk3cfedd72016-12-09 09:31:37 -0500131 mContext.addMockSystemService(Context.TRUST_SERVICE, mock(TrustManager.class));
132 mContext.addMockSystemService(Context.FINGERPRINT_SERVICE, mock(FingerprintManager.class));
Jeff DeCewa87cddb2020-06-12 12:13:52 -0400133 mDisclosureWithOrganization = mContext.getString(R.string.do_disclosure_with_name,
134 ORGANIZATION_NAME);
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100135
Haining Chenc06c4812020-01-13 20:38:53 -0800136 when(mKeyguardUpdateMonitor.isUnlockingWithBiometricAllowed(anyBoolean())).thenReturn(true);
Lucas Dupin85ea4202019-11-04 16:01:51 -0800137 when(mKeyguardUpdateMonitor.isScreenOn()).thenReturn(true);
138 when(mKeyguardUpdateMonitor.isUserUnlocked(anyInt())).thenReturn(true);
Jeff DeCewa87cddb2020-06-12 12:13:52 -0400139
140 when(mIndicationArea.findViewById(R.id.keyguard_indication_enterprise_disclosure))
141 .thenReturn(mDisclosure);
Lucas Dupinff6628d2018-10-15 10:12:37 -0700142 when(mIndicationArea.findViewById(R.id.keyguard_indication_text)).thenReturn(mTextView);
Jeff DeCewa87cddb2020-06-12 12:13:52 -0400143 when(mDisclosure.getAlpha()).thenReturn(1f);
Adrian Roosc1b50322017-02-27 21:07:58 +0100144
145 mWakeLock = new WakeLockFake();
Dave Mankoffc0d9a7d2020-02-27 17:15:52 -0500146 mWakeLockBuilder = new WakeLockFake.Builder(mContext);
147 mWakeLockBuilder.setWakeLock(mWakeLock);
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100148 }
149
150 private void createController() {
151 if (Looper.myLooper() == null) {
152 Looper.prepare();
153 }
Dave Mankoffc0d9a7d2020-02-27 17:15:52 -0500154
155 mController = new KeyguardIndicationController(mContext, mWakeLockBuilder,
Jerry Chang6a8fb022019-11-15 06:52:54 +0800156 mKeyguardStateController, mStatusBarStateController, mKeyguardUpdateMonitor,
Jeff DeCewa87cddb2020-06-12 12:13:52 -0400157 mDockManager, mBroadcastDispatcher, mDevicePolicyManager, mIBatteryStats);
Dave Mankoffc0d9a7d2020-02-27 17:15:52 -0500158 mController.setIndicationArea(mIndicationArea);
Lucas Dupin85ea4202019-11-04 16:01:51 -0800159 mController.setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager);
Lucas Dupin9131b282019-11-19 16:25:03 -0800160 clearInvocations(mIBatteryStats);
Jeff DeCewa87cddb2020-06-12 12:13:52 -0400161 verify(mDisclosure).getAlpha();
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100162 }
163
164 @Test
Jerry Chang6a8fb022019-11-15 06:52:54 +0800165 public void createController_addsAlignmentListener() {
166 createController();
167
168 verify(mDockManager).addAlignmentStateListener(
169 any(DockManager.AlignmentStateListener.class));
170 }
171
172 @Test
173 public void onAlignmentStateChanged_showsSlowChargingIndication() {
Wilson Wu0e727132019-12-26 16:17:56 +0800174 mInstrumentation.runOnMainSync(() -> {
175 createController();
176 verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture());
177 mController.setVisible(true);
Jerry Chang6a8fb022019-11-15 06:52:54 +0800178
Wilson Wu0e727132019-12-26 16:17:56 +0800179 mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_POOR);
180 });
181 mInstrumentation.waitForIdleSync();
Jerry Chang6a8fb022019-11-15 06:52:54 +0800182
183 assertThat(mTextView.getText()).isEqualTo(
184 mContext.getResources().getString(R.string.dock_alignment_slow_charging));
185 assertThat(mTextView.getCurrentTextColor()).isEqualTo(
186 Utils.getColorError(mContext).getDefaultColor());
187 }
188
189 @Test
190 public void onAlignmentStateChanged_showsNotChargingIndication() {
Wilson Wu0e727132019-12-26 16:17:56 +0800191 mInstrumentation.runOnMainSync(() -> {
192 createController();
193 verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture());
194 mController.setVisible(true);
Jerry Chang6a8fb022019-11-15 06:52:54 +0800195
Wilson Wu0e727132019-12-26 16:17:56 +0800196 mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_TERRIBLE);
197 });
198 mInstrumentation.waitForIdleSync();
Jerry Chang6a8fb022019-11-15 06:52:54 +0800199
200 assertThat(mTextView.getText()).isEqualTo(
201 mContext.getResources().getString(R.string.dock_alignment_not_charging));
202 assertThat(mTextView.getCurrentTextColor()).isEqualTo(
203 Utils.getColorError(mContext).getDefaultColor());
204 }
205
206 @Test
207 public void onAlignmentStateChanged_whileDozing_showsSlowChargingIndication() {
Wilson Wu0e727132019-12-26 16:17:56 +0800208 mInstrumentation.runOnMainSync(() -> {
209 createController();
210 verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture());
211 mController.setVisible(true);
212 mController.setDozing(true);
Jerry Chang6a8fb022019-11-15 06:52:54 +0800213
Wilson Wu0e727132019-12-26 16:17:56 +0800214 mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_POOR);
215 });
216 mInstrumentation.waitForIdleSync();
Jerry Chang6a8fb022019-11-15 06:52:54 +0800217
218 assertThat(mTextView.getText()).isEqualTo(
219 mContext.getResources().getString(R.string.dock_alignment_slow_charging));
Lucas Dupin5567b892020-04-16 14:05:35 -0700220 assertThat(mTextView.getCurrentTextColor()).isEqualTo(
Wilson Wubb51d092020-04-21 16:00:59 +0800221 mContext.getColor(R.color.misalignment_text_color));
Jerry Chang6a8fb022019-11-15 06:52:54 +0800222 }
223
224 @Test
225 public void onAlignmentStateChanged_whileDozing_showsNotChargingIndication() {
Wilson Wu0e727132019-12-26 16:17:56 +0800226 mInstrumentation.runOnMainSync(() -> {
227 createController();
228 verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture());
229 mController.setVisible(true);
230 mController.setDozing(true);
Jerry Chang6a8fb022019-11-15 06:52:54 +0800231
Wilson Wu0e727132019-12-26 16:17:56 +0800232 mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_TERRIBLE);
233 });
234 mInstrumentation.waitForIdleSync();
Jerry Chang6a8fb022019-11-15 06:52:54 +0800235
236 assertThat(mTextView.getText()).isEqualTo(
237 mContext.getResources().getString(R.string.dock_alignment_not_charging));
Lucas Dupin5567b892020-04-16 14:05:35 -0700238 assertThat(mTextView.getCurrentTextColor()).isEqualTo(
Wilson Wubb51d092020-04-21 16:00:59 +0800239 mContext.getColor(R.color.misalignment_text_color));
Jerry Chang6a8fb022019-11-15 06:52:54 +0800240 }
241
242 @Test
Jeff DeCewa87cddb2020-06-12 12:13:52 -0400243 public void disclosure_unmanaged() {
244 when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false);
245 createController();
246
247 verify(mDisclosure).setVisibility(View.GONE);
248 verifyNoMoreInteractions(mDisclosure);
249 }
250
251 @Test
252 public void disclosure_managedNoOwnerName() {
253 when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
254 when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
255 createController();
256
257 verify(mDisclosure).setVisibility(View.VISIBLE);
258 verify(mDisclosure).switchIndication(R.string.do_disclosure_generic);
259 verifyNoMoreInteractions(mDisclosure);
260 }
261
262 @Test
263 public void disclosure_hiddenWhenDozing() {
264 when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
265 when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
266 createController();
267
268 mController.setVisible(true);
269 mController.onDozeAmountChanged(1, 1);
270 mController.setDozing(true);
271
272 verify(mDisclosure).setVisibility(View.VISIBLE);
273 verify(mDisclosure).setAlpha(0f);
274 verify(mDisclosure).switchIndication(R.string.do_disclosure_generic);
275 verifyNoMoreInteractions(mDisclosure);
276 }
277
278 @Test
279 public void disclosure_visibleWhenDozing() {
280 when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
281 when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
282 createController();
283
284 mController.setVisible(true);
285 mController.onDozeAmountChanged(0, 0);
286 mController.setDozing(false);
287
288 verify(mDisclosure).setVisibility(View.VISIBLE);
289 verify(mDisclosure).setAlpha(1f);
290 verify(mDisclosure).switchIndication(R.string.do_disclosure_generic);
291 verifyNoMoreInteractions(mDisclosure);
292 }
293
294 @Test
295 public void disclosure_managedOwnerName() {
296 when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
297 when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME);
298 createController();
299
300 verify(mDisclosure).setVisibility(View.VISIBLE);
301 verify(mDisclosure).switchIndication(mDisclosureWithOrganization);
302 verifyNoMoreInteractions(mDisclosure);
303 }
304
305 @Test
306 public void disclosure_updateOnTheFly() {
307 ArgumentCaptor<BroadcastReceiver> receiver = ArgumentCaptor.forClass(
308 BroadcastReceiver.class);
309 doNothing().when(mBroadcastDispatcher).registerReceiver(receiver.capture(), any());
310
311 when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false);
312 createController();
313
314 final KeyguardUpdateMonitorCallback monitor = mController.getKeyguardCallback();
315 reset(mDisclosure);
316
317 when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
318 when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
319 receiver.getValue().onReceive(mContext, new Intent());
320
321 verify(mDisclosure).setVisibility(View.VISIBLE);
322 verify(mDisclosure).switchIndication(R.string.do_disclosure_generic);
323 verifyNoMoreInteractions(mDisclosure);
324 reset(mDisclosure);
325
326 when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
327 when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME);
328 receiver.getValue().onReceive(mContext, new Intent());
329
330 verify(mDisclosure).setVisibility(View.VISIBLE);
331 verify(mDisclosure).switchIndication(mDisclosureWithOrganization);
332 verifyNoMoreInteractions(mDisclosure);
333 reset(mDisclosure);
334
335 when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false);
336 receiver.getValue().onReceive(mContext, new Intent());
337
338 verify(mDisclosure).setVisibility(View.GONE);
339 verifyNoMoreInteractions(mDisclosure);
340 }
341
342 @Test
Adrian Roosc1b50322017-02-27 21:07:58 +0100343 public void transientIndication_holdsWakeLock_whenDozing() {
344 createController();
345
346 mController.setDozing(true);
347 mController.showTransientIndication("Test");
348
349 assertTrue(mWakeLock.isHeld());
350 }
351
352 @Test
353 public void transientIndication_releasesWakeLock_afterHiding() {
354 createController();
355
356 mController.setDozing(true);
357 mController.showTransientIndication("Test");
358 mController.hideTransientIndication();
359
360 assertFalse(mWakeLock.isHeld());
361 }
362
363 @Test
364 public void transientIndication_releasesWakeLock_afterHidingDelayed() throws Throwable {
365 mInstrumentation.runOnMainSync(() -> {
366 createController();
367
368 mController.setDozing(true);
369 mController.showTransientIndication("Test");
370 mController.hideTransientIndicationDelayed(0);
371 });
372 mInstrumentation.waitForIdleSync();
373
Adrian Roosaf45b602017-03-14 13:10:25 -0700374 Boolean[] held = new Boolean[1];
Adrian Roosc1b50322017-02-27 21:07:58 +0100375 mInstrumentation.runOnMainSync(() -> {
376 held[0] = mWakeLock.isHeld();
Adrian Roosc1b50322017-02-27 21:07:58 +0100377 });
Adrian Roosaf45b602017-03-14 13:10:25 -0700378 assertFalse("WakeLock expected: RELEASED, was: HELD", held[0]);
Adrian Roosc1b50322017-02-27 21:07:58 +0100379 }
Lucas Dupinff6628d2018-10-15 10:12:37 -0700380
381 @Test
382 public void transientIndication_visibleWhenDozing() {
383 createController();
384
385 mController.setVisible(true);
386 mController.showTransientIndication("Test");
387 mController.setDozing(true);
388
389 assertThat(mTextView.getText()).isEqualTo("Test");
390 assertThat(mTextView.getCurrentTextColor()).isEqualTo(Color.WHITE);
391 assertThat(mTextView.getAlpha()).isEqualTo(1f);
392 }
Lucas Dupin0df60fe2019-04-23 10:19:27 -0700393
394 @Test
Lucas Dupin85ea4202019-11-04 16:01:51 -0800395 public void transientIndication_visibleWhenDozing_unlessSwipeUp_fromHelp() {
396 createController();
397 String message = "A message";
398
399 mController.setVisible(true);
400 mController.getKeyguardCallback().onBiometricHelp(
401 KeyguardUpdateMonitor.BIOMETRIC_HELP_FACE_NOT_RECOGNIZED, message,
402 BiometricSourceType.FACE);
403 assertThat(mTextView.getText()).isEqualTo(message);
404 mController.setDozing(true);
405
406 assertThat(mTextView.getText()).isNotEqualTo(message);
407 }
408
409 @Test
410 public void transientIndication_visibleWhenDozing_unlessSwipeUp_fromError() {
411 createController();
412 String message = mContext.getString(R.string.keyguard_unlock);
413
414 mController.setVisible(true);
415 mController.getKeyguardCallback().onBiometricError(FaceManager.FACE_ERROR_TIMEOUT,
416 "A message", BiometricSourceType.FACE);
417
418 assertThat(mTextView.getText()).isEqualTo(message);
419 mController.setDozing(true);
420
421 assertThat(mTextView.getText()).isNotEqualTo(message);
422 }
423
424 @Test
425 public void transientIndication_swipeUpToRetry() {
426 createController();
427 String message = mContext.getString(R.string.keyguard_retry);
428 when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true);
429
430 mController.setVisible(true);
431 mController.getKeyguardCallback().onBiometricError(FaceManager.FACE_ERROR_TIMEOUT,
432 "A message", BiometricSourceType.FACE);
433
434 verify(mStatusBarKeyguardViewManager).showBouncerMessage(eq(message), any());
435 }
436
437 @Test
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400438 public void updateMonitor_listenerUpdatesIndication() {
Lucas Dupin8e2fd012019-04-25 16:40:54 -0700439 createController();
440 String restingIndication = "Resting indication";
Lucas Dupin85ea4202019-11-04 16:01:51 -0800441 reset(mKeyguardUpdateMonitor);
Lucas Dupin6c6d5732019-08-27 17:36:05 -0700442
Lucas Dupin8e2fd012019-04-25 16:40:54 -0700443 mController.setVisible(true);
Lucas Dupin6c6d5732019-08-27 17:36:05 -0700444 assertThat(mTextView.getText()).isEqualTo(
445 mContext.getString(com.android.internal.R.string.lockscreen_storage_locked));
446
447 when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true);
448 when(mKeyguardUpdateMonitor.isUserUnlocked(anyInt())).thenReturn(true);
449 mController.setRestingIndication(restingIndication);
Lucas Dupin8e2fd012019-04-25 16:40:54 -0700450 assertThat(mTextView.getText()).isEqualTo(mController.getTrustGrantedIndication());
451
452 reset(mKeyguardUpdateMonitor);
Lucas Dupin6c6d5732019-08-27 17:36:05 -0700453 when(mKeyguardUpdateMonitor.isUserUnlocked(anyInt())).thenReturn(true);
Lucas Dupin8e2fd012019-04-25 16:40:54 -0700454 when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(false);
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400455 mController.onUnlockedChanged();
Lucas Dupin8e2fd012019-04-25 16:40:54 -0700456 assertThat(mTextView.getText()).isEqualTo(restingIndication);
457 }
458
459 @Test
Lucas Dupin9131b282019-11-19 16:25:03 -0800460 public void onRefreshBatteryInfo_computesChargingTime() throws RemoteException {
461 createController();
462 BatteryStatus status = new BatteryStatus(BatteryManager.BATTERY_STATUS_CHARGING,
463 80 /* level */, BatteryManager.BATTERY_PLUGGED_WIRELESS, 100 /* health */,
464 0 /* maxChargingWattage */);
465
466 mController.getKeyguardCallback().onRefreshBatteryInfo(status);
467 verify(mIBatteryStats).computeChargeTimeRemaining();
468 }
469
470 @Test
471 public void onRefreshBatteryInfo_computesChargingTime_onlyWhenCharging()
472 throws RemoteException {
473 createController();
474 BatteryStatus status = new BatteryStatus(BatteryManager.BATTERY_STATUS_CHARGING,
475 80 /* level */, 0 /* plugged */, 100 /* health */,
476 0 /* maxChargingWattage */);
477
478 mController.getKeyguardCallback().onRefreshBatteryInfo(status);
479 verify(mIBatteryStats, never()).computeChargeTimeRemaining();
480 }
481
482 /**
483 * Regression test.
484 * We should not make calls to the system_process when updating the doze state.
485 */
486 @Test
487 public void setDozing_noIBatteryCalls() throws RemoteException {
488 createController();
489 mController.setVisible(true);
490 mController.setDozing(true);
491 mController.setDozing(false);
492 verify(mIBatteryStats, never()).computeChargeTimeRemaining();
493 }
494
495 @Test
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400496 public void updateMonitor_listener() {
Lucas Dupin8e2fd012019-04-25 16:40:54 -0700497 createController();
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400498 verify(mKeyguardStateController).addCallback(eq(mController));
Lucas Dupin8e2fd012019-04-25 16:40:54 -0700499 verify(mStatusBarStateController).addCallback(eq(mController));
500 verify(mKeyguardUpdateMonitor, times(2)).registerCallback(any());
Lucas Dupin8e2fd012019-04-25 16:40:54 -0700501 }
Scott Warner778db332020-01-21 09:45:56 -0500502
503 @Test
504 public void unlockMethodCache_listenerUpdatesPluggedIndication() {
505 createController();
506 when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true);
507 mController.setPowerPluggedIn(true);
508 mController.setVisible(true);
509 String powerIndication = mController.computePowerIndication();
510 String pluggedIndication = mContext.getString(R.string.keyguard_indication_trust_unlocked);
511 pluggedIndication = mContext.getString(
512 R.string.keyguard_indication_trust_unlocked_plugged_in,
513 pluggedIndication, powerIndication);
514 assertThat(mTextView.getText()).isEqualTo(pluggedIndication);
515 }
Bartosz Fabianowski5f045002016-12-01 10:36:18 +0100516}