Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [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.statusbar; |
| 18 | |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 19 | import static android.content.pm.UserInfo.FLAG_MANAGED_PROFILE; |
| 20 | |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 21 | import static com.google.common.truth.Truth.assertThat; |
| 22 | |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 23 | import static org.junit.Assert.assertFalse; |
| 24 | import static org.junit.Assert.assertTrue; |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 25 | import static org.mockito.ArgumentMatchers.any; |
Haining Chen | c06c481 | 2020-01-13 20:38:53 -0800 | [diff] [blame] | 26 | import static org.mockito.ArgumentMatchers.anyBoolean; |
Lucas Dupin | 0df60fe | 2019-04-23 10:19:27 -0700 | [diff] [blame] | 27 | import static org.mockito.ArgumentMatchers.anyInt; |
| 28 | import static org.mockito.ArgumentMatchers.eq; |
Lucas Dupin | 9131b28 | 2019-11-19 16:25:03 -0800 | [diff] [blame] | 29 | import static org.mockito.Mockito.clearInvocations; |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 30 | import static org.mockito.Mockito.doNothing; |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 31 | import static org.mockito.Mockito.mock; |
Lucas Dupin | 9131b28 | 2019-11-19 16:25:03 -0800 | [diff] [blame] | 32 | import static org.mockito.Mockito.never; |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 33 | import static org.mockito.Mockito.reset; |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 34 | import static org.mockito.Mockito.times; |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 35 | import static org.mockito.Mockito.verify; |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 36 | import static org.mockito.Mockito.verifyNoMoreInteractions; |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 37 | import static org.mockito.Mockito.when; |
| 38 | |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 39 | import android.app.Instrumentation; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 40 | import android.app.admin.DevicePolicyManager; |
| 41 | import android.app.trust.TrustManager; |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 42 | import android.content.BroadcastReceiver; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 43 | import android.content.Context; |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 44 | import android.content.Intent; |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 45 | import android.content.pm.UserInfo; |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 46 | import android.graphics.Color; |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 47 | import android.hardware.biometrics.BiometricSourceType; |
| 48 | import android.hardware.face.FaceManager; |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 49 | import android.hardware.fingerprint.FingerprintManager; |
Lucas Dupin | 9131b28 | 2019-11-19 16:25:03 -0800 | [diff] [blame] | 50 | import android.os.BatteryManager; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 51 | import android.os.Looper; |
Lucas Dupin | 9131b28 | 2019-11-19 16:25:03 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 53 | import android.os.UserManager; |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 54 | import android.view.View; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 55 | import android.view.ViewGroup; |
| 56 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 57 | import androidx.test.InstrumentationRegistry; |
| 58 | import androidx.test.filters.SmallTest; |
| 59 | import androidx.test.runner.AndroidJUnit4; |
| 60 | |
Lucas Dupin | 9131b28 | 2019-11-19 16:25:03 -0800 | [diff] [blame] | 61 | import com.android.internal.app.IBatteryStats; |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 62 | import com.android.keyguard.KeyguardUpdateMonitor; |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 63 | import com.android.keyguard.KeyguardUpdateMonitorCallback; |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 64 | import com.android.settingslib.Utils; |
Raff Tsai | f4ea562 | 2019-06-26 16:15:21 +0800 | [diff] [blame] | 65 | import com.android.settingslib.fuelgauge.BatteryStatus; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 66 | import com.android.systemui.R; |
| 67 | import com.android.systemui.SysuiTestCase; |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 68 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 69 | import com.android.systemui.dock.DockManager; |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 70 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 71 | import com.android.systemui.statusbar.phone.KeyguardIndicationTextView; |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 72 | import com.android.systemui.statusbar.phone.LockIcon; |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 73 | import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 74 | import com.android.systemui.statusbar.policy.KeyguardStateController; |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 75 | import com.android.systemui.util.wakelock.WakeLockFake; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 76 | |
| 77 | import org.junit.Before; |
| 78 | import org.junit.Test; |
| 79 | import org.junit.runner.RunWith; |
Lucas Dupin | 0df60fe | 2019-04-23 10:19:27 -0700 | [diff] [blame] | 80 | import org.mockito.ArgumentCaptor; |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 81 | import org.mockito.Captor; |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 82 | import org.mockito.Mock; |
| 83 | import org.mockito.MockitoAnnotations; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 84 | |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 85 | import java.util.Collections; |
| 86 | |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 87 | @SmallTest |
| 88 | @RunWith(AndroidJUnit4.class) |
| 89 | public class KeyguardIndicationControllerTest extends SysuiTestCase { |
| 90 | |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 91 | private static final String ORGANIZATION_NAME = "organization"; |
| 92 | |
| 93 | private String mDisclosureWithOrganization; |
| 94 | |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 95 | @Mock |
| 96 | private DevicePolicyManager mDevicePolicyManager; |
| 97 | @Mock |
| 98 | private ViewGroup mIndicationArea; |
| 99 | @Mock |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 100 | private KeyguardStateController mKeyguardStateController; |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 101 | @Mock |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 102 | private KeyguardIndicationTextView mDisclosure; |
| 103 | @Mock |
| 104 | private BroadcastDispatcher mBroadcastDispatcher; |
| 105 | @Mock |
| 106 | private LockIcon mLockIcon; |
| 107 | @Mock |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 108 | private StatusBarStateController mStatusBarStateController; |
| 109 | @Mock |
| 110 | private KeyguardUpdateMonitor mKeyguardUpdateMonitor; |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 111 | @Mock |
| 112 | private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
| 113 | @Mock |
| 114 | private UserManager mUserManager; |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 115 | @Mock |
Lucas Dupin | 9131b28 | 2019-11-19 16:25:03 -0800 | [diff] [blame] | 116 | private IBatteryStats mIBatteryStats; |
| 117 | @Mock |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 118 | private DockManager mDockManager; |
| 119 | @Captor |
| 120 | private ArgumentCaptor<DockManager.AlignmentStateListener> mAlignmentListener; |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 121 | private KeyguardIndicationTextView mTextView; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 122 | |
| 123 | private KeyguardIndicationController mController; |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 124 | private WakeLockFake.Builder mWakeLockBuilder; |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 125 | private WakeLockFake mWakeLock; |
| 126 | private Instrumentation mInstrumentation; |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 127 | |
| 128 | @Before |
| 129 | public void setUp() throws Exception { |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 130 | MockitoAnnotations.initMocks(this); |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 131 | mInstrumentation = InstrumentationRegistry.getInstrumentation(); |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 132 | mTextView = new KeyguardIndicationTextView(mContext); |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 133 | |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 134 | mContext.addMockSystemService(Context.DEVICE_POLICY_SERVICE, mDevicePolicyManager); |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 135 | mContext.addMockSystemService(UserManager.class, mUserManager); |
Jason Monk | 3cfedd7 | 2016-12-09 09:31:37 -0500 | [diff] [blame] | 136 | mContext.addMockSystemService(Context.TRUST_SERVICE, mock(TrustManager.class)); |
| 137 | mContext.addMockSystemService(Context.FINGERPRINT_SERVICE, mock(FingerprintManager.class)); |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 138 | mDisclosureWithOrganization = mContext.getString(R.string.do_disclosure_with_name, |
| 139 | ORGANIZATION_NAME); |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 140 | |
Haining Chen | c06c481 | 2020-01-13 20:38:53 -0800 | [diff] [blame] | 141 | when(mKeyguardUpdateMonitor.isUnlockingWithBiometricAllowed(anyBoolean())).thenReturn(true); |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 142 | when(mKeyguardUpdateMonitor.isScreenOn()).thenReturn(true); |
| 143 | when(mKeyguardUpdateMonitor.isUserUnlocked(anyInt())).thenReturn(true); |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 144 | |
| 145 | when(mIndicationArea.findViewById(R.id.keyguard_indication_enterprise_disclosure)) |
| 146 | .thenReturn(mDisclosure); |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 147 | when(mIndicationArea.findViewById(R.id.keyguard_indication_text)).thenReturn(mTextView); |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 148 | when(mDisclosure.getAlpha()).thenReturn(1f); |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 149 | |
| 150 | mWakeLock = new WakeLockFake(); |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 151 | mWakeLockBuilder = new WakeLockFake.Builder(mContext); |
| 152 | mWakeLockBuilder.setWakeLock(mWakeLock); |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | private void createController() { |
| 156 | if (Looper.myLooper() == null) { |
| 157 | Looper.prepare(); |
| 158 | } |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 159 | |
| 160 | mController = new KeyguardIndicationController(mContext, mWakeLockBuilder, |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 161 | mKeyguardStateController, mStatusBarStateController, mKeyguardUpdateMonitor, |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 162 | mDockManager, mBroadcastDispatcher, mDevicePolicyManager, mIBatteryStats, |
| 163 | mUserManager); |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 164 | mController.setIndicationArea(mIndicationArea); |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 165 | mController.setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager); |
Lucas Dupin | 9131b28 | 2019-11-19 16:25:03 -0800 | [diff] [blame] | 166 | clearInvocations(mIBatteryStats); |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 167 | verify(mDisclosure).getAlpha(); |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | @Test |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 171 | public void createController_addsAlignmentListener() { |
| 172 | createController(); |
| 173 | |
| 174 | verify(mDockManager).addAlignmentStateListener( |
| 175 | any(DockManager.AlignmentStateListener.class)); |
| 176 | } |
| 177 | |
| 178 | @Test |
| 179 | public void onAlignmentStateChanged_showsSlowChargingIndication() { |
Wilson Wu | 0e72713 | 2019-12-26 16:17:56 +0800 | [diff] [blame] | 180 | mInstrumentation.runOnMainSync(() -> { |
| 181 | createController(); |
| 182 | verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture()); |
| 183 | mController.setVisible(true); |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 184 | |
Wilson Wu | 0e72713 | 2019-12-26 16:17:56 +0800 | [diff] [blame] | 185 | mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_POOR); |
| 186 | }); |
| 187 | mInstrumentation.waitForIdleSync(); |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 188 | |
| 189 | assertThat(mTextView.getText()).isEqualTo( |
| 190 | mContext.getResources().getString(R.string.dock_alignment_slow_charging)); |
| 191 | assertThat(mTextView.getCurrentTextColor()).isEqualTo( |
| 192 | Utils.getColorError(mContext).getDefaultColor()); |
| 193 | } |
| 194 | |
| 195 | @Test |
| 196 | public void onAlignmentStateChanged_showsNotChargingIndication() { |
Wilson Wu | 0e72713 | 2019-12-26 16:17:56 +0800 | [diff] [blame] | 197 | mInstrumentation.runOnMainSync(() -> { |
| 198 | createController(); |
| 199 | verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture()); |
| 200 | mController.setVisible(true); |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 201 | |
Wilson Wu | 0e72713 | 2019-12-26 16:17:56 +0800 | [diff] [blame] | 202 | mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_TERRIBLE); |
| 203 | }); |
| 204 | mInstrumentation.waitForIdleSync(); |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 205 | |
| 206 | assertThat(mTextView.getText()).isEqualTo( |
| 207 | mContext.getResources().getString(R.string.dock_alignment_not_charging)); |
| 208 | assertThat(mTextView.getCurrentTextColor()).isEqualTo( |
| 209 | Utils.getColorError(mContext).getDefaultColor()); |
| 210 | } |
| 211 | |
| 212 | @Test |
| 213 | public void onAlignmentStateChanged_whileDozing_showsSlowChargingIndication() { |
Wilson Wu | 0e72713 | 2019-12-26 16:17:56 +0800 | [diff] [blame] | 214 | mInstrumentation.runOnMainSync(() -> { |
| 215 | createController(); |
| 216 | verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture()); |
| 217 | mController.setVisible(true); |
| 218 | mController.setDozing(true); |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 219 | |
Wilson Wu | 0e72713 | 2019-12-26 16:17:56 +0800 | [diff] [blame] | 220 | mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_POOR); |
| 221 | }); |
| 222 | mInstrumentation.waitForIdleSync(); |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 223 | |
| 224 | assertThat(mTextView.getText()).isEqualTo( |
| 225 | mContext.getResources().getString(R.string.dock_alignment_slow_charging)); |
Lucas Dupin | 5567b89 | 2020-04-16 14:05:35 -0700 | [diff] [blame] | 226 | assertThat(mTextView.getCurrentTextColor()).isEqualTo( |
Wilson Wu | bb51d09 | 2020-04-21 16:00:59 +0800 | [diff] [blame] | 227 | mContext.getColor(R.color.misalignment_text_color)); |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | @Test |
| 231 | public void onAlignmentStateChanged_whileDozing_showsNotChargingIndication() { |
Wilson Wu | 0e72713 | 2019-12-26 16:17:56 +0800 | [diff] [blame] | 232 | mInstrumentation.runOnMainSync(() -> { |
| 233 | createController(); |
| 234 | verify(mDockManager).addAlignmentStateListener(mAlignmentListener.capture()); |
| 235 | mController.setVisible(true); |
| 236 | mController.setDozing(true); |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 237 | |
Wilson Wu | 0e72713 | 2019-12-26 16:17:56 +0800 | [diff] [blame] | 238 | mAlignmentListener.getValue().onAlignmentStateChanged(DockManager.ALIGN_STATE_TERRIBLE); |
| 239 | }); |
| 240 | mInstrumentation.waitForIdleSync(); |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 241 | |
| 242 | assertThat(mTextView.getText()).isEqualTo( |
| 243 | mContext.getResources().getString(R.string.dock_alignment_not_charging)); |
Lucas Dupin | 5567b89 | 2020-04-16 14:05:35 -0700 | [diff] [blame] | 244 | assertThat(mTextView.getCurrentTextColor()).isEqualTo( |
Wilson Wu | bb51d09 | 2020-04-21 16:00:59 +0800 | [diff] [blame] | 245 | mContext.getColor(R.color.misalignment_text_color)); |
Jerry Chang | 6a8fb02 | 2019-11-15 06:52:54 +0800 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | @Test |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 249 | public void disclosure_unmanaged() { |
| 250 | when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false); |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 251 | when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(false); |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 252 | createController(); |
| 253 | |
| 254 | verify(mDisclosure).setVisibility(View.GONE); |
| 255 | verifyNoMoreInteractions(mDisclosure); |
| 256 | } |
| 257 | |
| 258 | @Test |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 259 | public void disclosure_deviceOwner_noOwnerName() { |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 260 | when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true); |
| 261 | when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null); |
| 262 | createController(); |
| 263 | |
| 264 | verify(mDisclosure).setVisibility(View.VISIBLE); |
| 265 | verify(mDisclosure).switchIndication(R.string.do_disclosure_generic); |
| 266 | verifyNoMoreInteractions(mDisclosure); |
| 267 | } |
| 268 | |
| 269 | @Test |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 270 | public void disclosure_orgOwnedDeviceWithManagedProfile_noOwnerName() { |
| 271 | when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(true); |
| 272 | when(mUserManager.getProfiles(anyInt())).thenReturn(Collections.singletonList( |
| 273 | new UserInfo(10, /* name */ null, /* flags */ FLAG_MANAGED_PROFILE))); |
| 274 | when(mDevicePolicyManager.getOrganizationNameForUser(eq(10))).thenReturn(null); |
| 275 | createController(); |
| 276 | |
| 277 | verify(mDisclosure).setVisibility(View.VISIBLE); |
| 278 | verify(mDisclosure).switchIndication(R.string.do_disclosure_generic); |
| 279 | verifyNoMoreInteractions(mDisclosure); |
| 280 | } |
| 281 | |
| 282 | @Test |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 283 | public void disclosure_hiddenWhenDozing() { |
| 284 | when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true); |
| 285 | when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null); |
| 286 | createController(); |
| 287 | |
| 288 | mController.setVisible(true); |
| 289 | mController.onDozeAmountChanged(1, 1); |
| 290 | mController.setDozing(true); |
| 291 | |
| 292 | verify(mDisclosure).setVisibility(View.VISIBLE); |
| 293 | verify(mDisclosure).setAlpha(0f); |
| 294 | verify(mDisclosure).switchIndication(R.string.do_disclosure_generic); |
| 295 | verifyNoMoreInteractions(mDisclosure); |
| 296 | } |
| 297 | |
| 298 | @Test |
| 299 | public void disclosure_visibleWhenDozing() { |
| 300 | when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true); |
| 301 | when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null); |
| 302 | createController(); |
| 303 | |
| 304 | mController.setVisible(true); |
| 305 | mController.onDozeAmountChanged(0, 0); |
| 306 | mController.setDozing(false); |
| 307 | |
| 308 | verify(mDisclosure).setVisibility(View.VISIBLE); |
| 309 | verify(mDisclosure).setAlpha(1f); |
| 310 | verify(mDisclosure).switchIndication(R.string.do_disclosure_generic); |
| 311 | verifyNoMoreInteractions(mDisclosure); |
| 312 | } |
| 313 | |
| 314 | @Test |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 315 | public void disclosure_deviceOwner_withOwnerName() { |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 316 | when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true); |
| 317 | when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME); |
| 318 | createController(); |
| 319 | |
| 320 | verify(mDisclosure).setVisibility(View.VISIBLE); |
| 321 | verify(mDisclosure).switchIndication(mDisclosureWithOrganization); |
| 322 | verifyNoMoreInteractions(mDisclosure); |
| 323 | } |
| 324 | |
| 325 | @Test |
arangelov | c00bd0c | 2020-06-19 17:13:59 +0100 | [diff] [blame] | 326 | public void disclosure_orgOwnedDeviceWithManagedProfile_withOwnerName() { |
| 327 | when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(true); |
| 328 | when(mUserManager.getProfiles(anyInt())).thenReturn(Collections.singletonList( |
| 329 | new UserInfo(10, /* name */ null, FLAG_MANAGED_PROFILE))); |
| 330 | when(mDevicePolicyManager.getOrganizationNameForUser(eq(10))).thenReturn(ORGANIZATION_NAME); |
| 331 | createController(); |
| 332 | |
| 333 | verify(mDisclosure).setVisibility(View.VISIBLE); |
| 334 | verify(mDisclosure).switchIndication(mDisclosureWithOrganization); |
| 335 | verifyNoMoreInteractions(mDisclosure); |
| 336 | } |
| 337 | |
| 338 | @Test |
Jeff DeCew | a87cddb | 2020-06-12 12:13:52 -0400 | [diff] [blame] | 339 | public void disclosure_updateOnTheFly() { |
| 340 | ArgumentCaptor<BroadcastReceiver> receiver = ArgumentCaptor.forClass( |
| 341 | BroadcastReceiver.class); |
| 342 | doNothing().when(mBroadcastDispatcher).registerReceiver(receiver.capture(), any()); |
| 343 | |
| 344 | when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false); |
| 345 | createController(); |
| 346 | |
| 347 | final KeyguardUpdateMonitorCallback monitor = mController.getKeyguardCallback(); |
| 348 | reset(mDisclosure); |
| 349 | |
| 350 | when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true); |
| 351 | when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null); |
| 352 | receiver.getValue().onReceive(mContext, new Intent()); |
| 353 | |
| 354 | verify(mDisclosure).setVisibility(View.VISIBLE); |
| 355 | verify(mDisclosure).switchIndication(R.string.do_disclosure_generic); |
| 356 | verifyNoMoreInteractions(mDisclosure); |
| 357 | reset(mDisclosure); |
| 358 | |
| 359 | when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true); |
| 360 | when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME); |
| 361 | receiver.getValue().onReceive(mContext, new Intent()); |
| 362 | |
| 363 | verify(mDisclosure).setVisibility(View.VISIBLE); |
| 364 | verify(mDisclosure).switchIndication(mDisclosureWithOrganization); |
| 365 | verifyNoMoreInteractions(mDisclosure); |
| 366 | reset(mDisclosure); |
| 367 | |
| 368 | when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false); |
| 369 | receiver.getValue().onReceive(mContext, new Intent()); |
| 370 | |
| 371 | verify(mDisclosure).setVisibility(View.GONE); |
| 372 | verifyNoMoreInteractions(mDisclosure); |
| 373 | } |
| 374 | |
| 375 | @Test |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 376 | public void transientIndication_holdsWakeLock_whenDozing() { |
| 377 | createController(); |
| 378 | |
| 379 | mController.setDozing(true); |
| 380 | mController.showTransientIndication("Test"); |
| 381 | |
| 382 | assertTrue(mWakeLock.isHeld()); |
| 383 | } |
| 384 | |
| 385 | @Test |
| 386 | public void transientIndication_releasesWakeLock_afterHiding() { |
| 387 | createController(); |
| 388 | |
| 389 | mController.setDozing(true); |
| 390 | mController.showTransientIndication("Test"); |
| 391 | mController.hideTransientIndication(); |
| 392 | |
| 393 | assertFalse(mWakeLock.isHeld()); |
| 394 | } |
| 395 | |
| 396 | @Test |
| 397 | public void transientIndication_releasesWakeLock_afterHidingDelayed() throws Throwable { |
| 398 | mInstrumentation.runOnMainSync(() -> { |
| 399 | createController(); |
| 400 | |
| 401 | mController.setDozing(true); |
| 402 | mController.showTransientIndication("Test"); |
| 403 | mController.hideTransientIndicationDelayed(0); |
| 404 | }); |
| 405 | mInstrumentation.waitForIdleSync(); |
| 406 | |
Adrian Roos | af45b60 | 2017-03-14 13:10:25 -0700 | [diff] [blame] | 407 | Boolean[] held = new Boolean[1]; |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 408 | mInstrumentation.runOnMainSync(() -> { |
| 409 | held[0] = mWakeLock.isHeld(); |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 410 | }); |
Adrian Roos | af45b60 | 2017-03-14 13:10:25 -0700 | [diff] [blame] | 411 | assertFalse("WakeLock expected: RELEASED, was: HELD", held[0]); |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 412 | } |
Lucas Dupin | ff6628d | 2018-10-15 10:12:37 -0700 | [diff] [blame] | 413 | |
| 414 | @Test |
| 415 | public void transientIndication_visibleWhenDozing() { |
| 416 | createController(); |
| 417 | |
| 418 | mController.setVisible(true); |
| 419 | mController.showTransientIndication("Test"); |
| 420 | mController.setDozing(true); |
| 421 | |
| 422 | assertThat(mTextView.getText()).isEqualTo("Test"); |
| 423 | assertThat(mTextView.getCurrentTextColor()).isEqualTo(Color.WHITE); |
| 424 | assertThat(mTextView.getAlpha()).isEqualTo(1f); |
| 425 | } |
Lucas Dupin | 0df60fe | 2019-04-23 10:19:27 -0700 | [diff] [blame] | 426 | |
| 427 | @Test |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 428 | public void transientIndication_visibleWhenDozing_unlessSwipeUp_fromHelp() { |
| 429 | createController(); |
| 430 | String message = "A message"; |
| 431 | |
| 432 | mController.setVisible(true); |
| 433 | mController.getKeyguardCallback().onBiometricHelp( |
| 434 | KeyguardUpdateMonitor.BIOMETRIC_HELP_FACE_NOT_RECOGNIZED, message, |
| 435 | BiometricSourceType.FACE); |
| 436 | assertThat(mTextView.getText()).isEqualTo(message); |
| 437 | mController.setDozing(true); |
| 438 | |
| 439 | assertThat(mTextView.getText()).isNotEqualTo(message); |
| 440 | } |
| 441 | |
| 442 | @Test |
| 443 | public void transientIndication_visibleWhenDozing_unlessSwipeUp_fromError() { |
| 444 | createController(); |
| 445 | String message = mContext.getString(R.string.keyguard_unlock); |
| 446 | |
| 447 | mController.setVisible(true); |
| 448 | mController.getKeyguardCallback().onBiometricError(FaceManager.FACE_ERROR_TIMEOUT, |
| 449 | "A message", BiometricSourceType.FACE); |
| 450 | |
| 451 | assertThat(mTextView.getText()).isEqualTo(message); |
| 452 | mController.setDozing(true); |
| 453 | |
| 454 | assertThat(mTextView.getText()).isNotEqualTo(message); |
| 455 | } |
| 456 | |
| 457 | @Test |
| 458 | public void transientIndication_swipeUpToRetry() { |
| 459 | createController(); |
| 460 | String message = mContext.getString(R.string.keyguard_retry); |
| 461 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); |
| 462 | |
| 463 | mController.setVisible(true); |
| 464 | mController.getKeyguardCallback().onBiometricError(FaceManager.FACE_ERROR_TIMEOUT, |
| 465 | "A message", BiometricSourceType.FACE); |
| 466 | |
| 467 | verify(mStatusBarKeyguardViewManager).showBouncerMessage(eq(message), any()); |
| 468 | } |
| 469 | |
| 470 | @Test |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 471 | public void updateMonitor_listenerUpdatesIndication() { |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 472 | createController(); |
| 473 | String restingIndication = "Resting indication"; |
Lucas Dupin | 85ea420 | 2019-11-04 16:01:51 -0800 | [diff] [blame] | 474 | reset(mKeyguardUpdateMonitor); |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 475 | |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 476 | mController.setVisible(true); |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 477 | assertThat(mTextView.getText()).isEqualTo( |
| 478 | mContext.getString(com.android.internal.R.string.lockscreen_storage_locked)); |
| 479 | |
| 480 | when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true); |
| 481 | when(mKeyguardUpdateMonitor.isUserUnlocked(anyInt())).thenReturn(true); |
| 482 | mController.setRestingIndication(restingIndication); |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 483 | assertThat(mTextView.getText()).isEqualTo(mController.getTrustGrantedIndication()); |
| 484 | |
| 485 | reset(mKeyguardUpdateMonitor); |
Lucas Dupin | 6c6d573 | 2019-08-27 17:36:05 -0700 | [diff] [blame] | 486 | when(mKeyguardUpdateMonitor.isUserUnlocked(anyInt())).thenReturn(true); |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 487 | when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(false); |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 488 | mController.onUnlockedChanged(); |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 489 | assertThat(mTextView.getText()).isEqualTo(restingIndication); |
| 490 | } |
| 491 | |
| 492 | @Test |
Lucas Dupin | 9131b28 | 2019-11-19 16:25:03 -0800 | [diff] [blame] | 493 | public void onRefreshBatteryInfo_computesChargingTime() throws RemoteException { |
| 494 | createController(); |
| 495 | BatteryStatus status = new BatteryStatus(BatteryManager.BATTERY_STATUS_CHARGING, |
| 496 | 80 /* level */, BatteryManager.BATTERY_PLUGGED_WIRELESS, 100 /* health */, |
| 497 | 0 /* maxChargingWattage */); |
| 498 | |
| 499 | mController.getKeyguardCallback().onRefreshBatteryInfo(status); |
| 500 | verify(mIBatteryStats).computeChargeTimeRemaining(); |
| 501 | } |
| 502 | |
| 503 | @Test |
| 504 | public void onRefreshBatteryInfo_computesChargingTime_onlyWhenCharging() |
| 505 | throws RemoteException { |
| 506 | createController(); |
| 507 | BatteryStatus status = new BatteryStatus(BatteryManager.BATTERY_STATUS_CHARGING, |
| 508 | 80 /* level */, 0 /* plugged */, 100 /* health */, |
| 509 | 0 /* maxChargingWattage */); |
| 510 | |
| 511 | mController.getKeyguardCallback().onRefreshBatteryInfo(status); |
| 512 | verify(mIBatteryStats, never()).computeChargeTimeRemaining(); |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * Regression test. |
| 517 | * We should not make calls to the system_process when updating the doze state. |
| 518 | */ |
| 519 | @Test |
| 520 | public void setDozing_noIBatteryCalls() throws RemoteException { |
| 521 | createController(); |
| 522 | mController.setVisible(true); |
| 523 | mController.setDozing(true); |
| 524 | mController.setDozing(false); |
| 525 | verify(mIBatteryStats, never()).computeChargeTimeRemaining(); |
| 526 | } |
| 527 | |
| 528 | @Test |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 529 | public void updateMonitor_listener() { |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 530 | createController(); |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 531 | verify(mKeyguardStateController).addCallback(eq(mController)); |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 532 | verify(mStatusBarStateController).addCallback(eq(mController)); |
| 533 | verify(mKeyguardUpdateMonitor, times(2)).registerCallback(any()); |
Lucas Dupin | 8e2fd01 | 2019-04-25 16:40:54 -0700 | [diff] [blame] | 534 | } |
Scott Warner | 778db33 | 2020-01-21 09:45:56 -0500 | [diff] [blame] | 535 | |
| 536 | @Test |
| 537 | public void unlockMethodCache_listenerUpdatesPluggedIndication() { |
| 538 | createController(); |
| 539 | when(mKeyguardUpdateMonitor.getUserHasTrust(anyInt())).thenReturn(true); |
| 540 | mController.setPowerPluggedIn(true); |
| 541 | mController.setVisible(true); |
| 542 | String powerIndication = mController.computePowerIndication(); |
| 543 | String pluggedIndication = mContext.getString(R.string.keyguard_indication_trust_unlocked); |
| 544 | pluggedIndication = mContext.getString( |
| 545 | R.string.keyguard_indication_trust_unlocked_plugged_in, |
| 546 | pluggedIndication, powerIndication); |
| 547 | assertThat(mTextView.getText()).isEqualTo(pluggedIndication); |
| 548 | } |
Bartosz Fabianowski | 5f04500 | 2016-12-01 10:36:18 +0100 | [diff] [blame] | 549 | } |