blob: e08fe7a13a60d51dd38de1b08f7ea5fbe57370f6 [file] [log] [blame]
Chris Wren65a70c92020-04-02 10:43:46 -04001/*
2 * Copyright (C) 2020 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.globalactions;
18
Matt Pietal50b661a2020-06-17 11:01:54 -040019import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED;
20
Sean Pontd7ff85a2020-05-18 21:47:08 -070021import static com.google.common.truth.Truth.assertThat;
22
Aran Inkcf038272020-03-31 17:48:37 -040023import static junit.framework.Assert.assertEquals;
Aran Inkc58028b2020-06-04 15:33:22 -040024import static junit.framework.Assert.assertTrue;
Aran Inkcf038272020-03-31 17:48:37 -040025
26import static org.mockito.ArgumentMatchers.any;
Sean Pontd7ff85a2020-05-18 21:47:08 -070027import static org.mockito.ArgumentMatchers.anyBoolean;
28import static org.mockito.ArgumentMatchers.anyInt;
Aran Inkcf038272020-03-31 17:48:37 -040029import static org.mockito.Mockito.doReturn;
30import static org.mockito.Mockito.spy;
Chris Wren65a70c92020-04-02 10:43:46 -040031import static org.mockito.Mockito.times;
32import static org.mockito.Mockito.verify;
Fabian Kozynskib6a20372020-04-01 09:36:43 -040033import static org.mockito.Mockito.when;
Chris Wren65a70c92020-04-02 10:43:46 -040034
35import android.app.IActivityManager;
36import android.app.admin.DevicePolicyManager;
37import android.app.trust.TrustManager;
38import android.content.ContentResolver;
Matt Pietal50b661a2020-06-17 11:01:54 -040039import android.content.pm.UserInfo;
Chris Wren65a70c92020-04-02 10:43:46 -040040import android.content.res.Resources;
Sean Pontd7ff85a2020-05-18 21:47:08 -070041import android.graphics.Color;
Chris Wren65a70c92020-04-02 10:43:46 -040042import android.media.AudioManager;
43import android.net.ConnectivityManager;
Matt Pietal677981d2020-04-24 14:38:32 -040044import android.os.Handler;
Matt Pietal50b661a2020-06-17 11:01:54 -040045import android.os.RemoteException;
Chris Wren65a70c92020-04-02 10:43:46 -040046import android.os.UserManager;
47import android.service.dreams.IDreamManager;
48import android.telephony.TelephonyManager;
49import android.testing.AndroidTestingRunner;
50import android.testing.TestableLooper;
Chris Wrenaf4ce8462020-04-06 17:36:10 -040051import android.util.FeatureFlagUtils;
Chris Wren65a70c92020-04-02 10:43:46 -040052import android.view.IWindowManager;
Sean Pontd7ff85a2020-05-18 21:47:08 -070053import android.view.View;
54import android.widget.FrameLayout;
Chris Wren65a70c92020-04-02 10:43:46 -040055
56import androidx.test.filters.SmallTest;
57
Sean Pontd7ff85a2020-05-18 21:47:08 -070058import com.android.internal.colorextraction.ColorExtractor;
Chris Wren65a70c92020-04-02 10:43:46 -040059import com.android.internal.logging.MetricsLogger;
60import com.android.internal.logging.UiEventLogger;
61import com.android.internal.statusbar.IStatusBarService;
62import com.android.internal.widget.LockPatternUtils;
63import com.android.systemui.SysuiTestCase;
64import com.android.systemui.broadcast.BroadcastDispatcher;
65import com.android.systemui.colorextraction.SysuiColorExtractor;
66import com.android.systemui.controls.controller.ControlsController;
Fabian Kozynski137951c2020-05-26 15:13:52 -040067import com.android.systemui.controls.dagger.ControlsComponent;
Chris Wren65a70c92020-04-02 10:43:46 -040068import com.android.systemui.controls.management.ControlsListingController;
69import com.android.systemui.controls.ui.ControlsUiController;
Winson Chung94674542020-05-15 10:35:55 -070070import com.android.systemui.model.SysUiState;
Chris Wren65a70c92020-04-02 10:43:46 -040071import com.android.systemui.plugins.ActivityStarter;
72import com.android.systemui.plugins.GlobalActions;
Sean Pontd7ff85a2020-05-18 21:47:08 -070073import com.android.systemui.plugins.GlobalActionsPanelPlugin;
Matt Pietal96c36952020-05-26 11:14:37 -040074import com.android.systemui.settings.CurrentUserContextTracker;
Chris Wren65a70c92020-04-02 10:43:46 -040075import com.android.systemui.statusbar.NotificationShadeDepthController;
76import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
77import com.android.systemui.statusbar.policy.ConfigurationController;
78import com.android.systemui.statusbar.policy.KeyguardStateController;
Fabian Kozynskib6a20372020-04-01 09:36:43 -040079import com.android.systemui.util.RingerModeLiveData;
80import com.android.systemui.util.RingerModeTracker;
Chris Wren65a70c92020-04-02 10:43:46 -040081
82import org.junit.Before;
83import org.junit.Test;
84import org.junit.runner.RunWith;
85import org.mockito.Mock;
86import org.mockito.MockitoAnnotations;
87
88import java.util.concurrent.Executor;
89
90@SmallTest
91@RunWith(AndroidTestingRunner.class)
Chris Wrenaf4ce8462020-04-06 17:36:10 -040092@TestableLooper.RunWithLooper()
Chris Wren65a70c92020-04-02 10:43:46 -040093public class GlobalActionsDialogTest extends SysuiTestCase {
94 private GlobalActionsDialog mGlobalActionsDialog;
95
96 @Mock private GlobalActions.GlobalActionsManager mWindowManagerFuncs;
97 @Mock private AudioManager mAudioManager;
98 @Mock private IDreamManager mDreamManager;
99 @Mock private DevicePolicyManager mDevicePolicyManager;
100 @Mock private LockPatternUtils mLockPatternUtils;
101 @Mock private BroadcastDispatcher mBroadcastDispatcher;
102 @Mock private ConnectivityManager mConnectivityManager;
103 @Mock private TelephonyManager mTelephonyManager;
104 @Mock private ContentResolver mContentResolver;
105 @Mock private Resources mResources;
106 @Mock private ConfigurationController mConfigurationController;
107 @Mock private ActivityStarter mActivityStarter;
108 @Mock private KeyguardStateController mKeyguardStateController;
109 @Mock private UserManager mUserManager;
110 @Mock private TrustManager mTrustManager;
111 @Mock private IActivityManager mActivityManager;
112 @Mock private MetricsLogger mMetricsLogger;
113 @Mock private NotificationShadeDepthController mDepthController;
114 @Mock private SysuiColorExtractor mColorExtractor;
115 @Mock private IStatusBarService mStatusBarService;
Chris Wren65a70c92020-04-02 10:43:46 -0400116 @Mock private NotificationShadeWindowController mNotificationShadeWindowController;
117 @Mock private ControlsUiController mControlsUiController;
118 @Mock private IWindowManager mWindowManager;
119 @Mock private Executor mBackgroundExecutor;
120 @Mock private ControlsListingController mControlsListingController;
121 @Mock private ControlsController mControlsController;
122 @Mock private UiEventLogger mUiEventLogger;
Fabian Kozynskib6a20372020-04-01 09:36:43 -0400123 @Mock private RingerModeTracker mRingerModeTracker;
124 @Mock private RingerModeLiveData mRingerModeLiveData;
Winson Chung94674542020-05-15 10:35:55 -0700125 @Mock private SysUiState mSysUiState;
Sean Pontd7ff85a2020-05-18 21:47:08 -0700126 @Mock GlobalActionsPanelPlugin mWalletPlugin;
127 @Mock GlobalActionsPanelPlugin.PanelViewController mWalletController;
Matt Pietal677981d2020-04-24 14:38:32 -0400128 @Mock private Handler mHandler;
Matt Pietal96c36952020-05-26 11:14:37 -0400129 @Mock private CurrentUserContextTracker mCurrentUserContextTracker;
Fabian Kozynski137951c2020-05-26 15:13:52 -0400130 private ControlsComponent mControlsComponent;
Chris Wren65a70c92020-04-02 10:43:46 -0400131
132 private TestableLooper mTestableLooper;
133
134 @Before
135 public void setUp() throws Exception {
136 MockitoAnnotations.initMocks(this);
137 mTestableLooper = TestableLooper.get(this);
138 allowTestableLooperAsMainThread();
Fabian Kozynskib6a20372020-04-01 09:36:43 -0400139
140 when(mRingerModeTracker.getRingerMode()).thenReturn(mRingerModeLiveData);
Matt Pietal96c36952020-05-26 11:14:37 -0400141 when(mCurrentUserContextTracker.getCurrentUserContext()).thenReturn(mContext);
Fabian Kozynski137951c2020-05-26 15:13:52 -0400142 mControlsComponent = new ControlsComponent(
143 true,
144 () -> mControlsController,
145 () -> mControlsUiController,
146 () -> mControlsListingController
147 );
148
Chris Wren65a70c92020-04-02 10:43:46 -0400149 mGlobalActionsDialog = new GlobalActionsDialog(mContext,
150 mWindowManagerFuncs,
151 mAudioManager,
152 mDreamManager,
153 mDevicePolicyManager,
154 mLockPatternUtils,
155 mBroadcastDispatcher,
156 mConnectivityManager,
157 mTelephonyManager,
158 mContentResolver,
159 null,
160 mResources,
161 mConfigurationController,
162 mActivityStarter,
163 mKeyguardStateController,
164 mUserManager,
165 mTrustManager,
166 mActivityManager,
167 null,
168 mMetricsLogger,
169 mDepthController,
170 mColorExtractor,
171 mStatusBarService,
Chris Wren65a70c92020-04-02 10:43:46 -0400172 mNotificationShadeWindowController,
Chris Wren65a70c92020-04-02 10:43:46 -0400173 mWindowManager,
174 mBackgroundExecutor,
Fabian Kozynskib6a20372020-04-01 09:36:43 -0400175 mUiEventLogger,
Matt Pietal677981d2020-04-24 14:38:32 -0400176 mRingerModeTracker,
Winson Chung94674542020-05-15 10:35:55 -0700177 mSysUiState,
Matt Pietal96c36952020-05-26 11:14:37 -0400178 mHandler,
Fabian Kozynski137951c2020-05-26 15:13:52 -0400179 mControlsComponent,
Matt Pietal96c36952020-05-26 11:14:37 -0400180 mCurrentUserContextTracker
Chris Wren65a70c92020-04-02 10:43:46 -0400181 );
Chris Wrenaf4ce8462020-04-06 17:36:10 -0400182 mGlobalActionsDialog.setZeroDialogPressDelayForTesting();
Sean Pontd7ff85a2020-05-18 21:47:08 -0700183
184 ColorExtractor.GradientColors backdropColors = new ColorExtractor.GradientColors();
185 backdropColors.setMainColor(Color.BLACK);
186 when(mColorExtractor.getNeutralColors()).thenReturn(backdropColors);
187 when(mSysUiState.setFlag(anyInt(), anyBoolean())).thenReturn(mSysUiState);
Chris Wren65a70c92020-04-02 10:43:46 -0400188 }
Chris Wrenaf4ce8462020-04-06 17:36:10 -0400189
Chris Wren65a70c92020-04-02 10:43:46 -0400190 @Test
Chris Wren9756a002020-05-12 16:46:27 -0400191 public void testShouldLogShow() {
Chris Wren65a70c92020-04-02 10:43:46 -0400192 mGlobalActionsDialog.onShow(null);
Chris Wrenaf4ce8462020-04-06 17:36:10 -0400193 mTestableLooper.processAllMessages();
194 verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_POWER_MENU_OPEN);
195 }
196
197 @Test
Chris Wren9756a002020-05-12 16:46:27 -0400198 public void testShouldLogDismiss() {
199 mGlobalActionsDialog.onDismiss(mGlobalActionsDialog.mDialog);
200 mTestableLooper.processAllMessages();
201 verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_POWER_MENU_CLOSE);
202 }
203
204 @Test
Chris Wrenaf4ce8462020-04-06 17:36:10 -0400205 public void testShouldLogBugreportPress() throws InterruptedException {
206 GlobalActionsDialog.BugReportAction bugReportAction =
207 mGlobalActionsDialog.makeBugReportActionForTesting();
208 bugReportAction.onPress();
209 verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_BUGREPORT_PRESS);
210 }
211
212 @Test
213 public void testShouldLogBugreportLongPress() {
214 GlobalActionsDialog.BugReportAction bugReportAction =
215 mGlobalActionsDialog.makeBugReportActionForTesting();
216 bugReportAction.onLongPress();
217 verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_BUGREPORT_LONG_PRESS);
218 }
219
220 @Test
221 public void testShouldLogEmergencyDialerPress() {
222 GlobalActionsDialog.EmergencyDialerAction emergencyDialerAction =
223 mGlobalActionsDialog.makeEmergencyDialerActionForTesting();
224 emergencyDialerAction.onPress();
225 verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_EMERGENCY_DIALER_PRESS);
226 }
227
228 @Test
229 public void testShouldLogScreenshotPress() {
230 GlobalActionsDialog.ScreenshotAction screenshotAction =
231 mGlobalActionsDialog.makeScreenshotActionForTesting();
232 screenshotAction.onPress();
233 verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_SCREENSHOT_PRESS);
234 }
235
236 @Test
237 public void testShouldLogScreenshotLongPress() {
238 FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS, true);
239 GlobalActionsDialog.ScreenshotAction screenshotAction =
240 mGlobalActionsDialog.makeScreenshotActionForTesting();
241 screenshotAction.onLongPress();
242 verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_SCREENSHOT_LONG_PRESS);
243 }
244
245 private void verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent event) {
246 mTestableLooper.processAllMessages();
Chris Wren65a70c92020-04-02 10:43:46 -0400247 verify(mUiEventLogger, times(1))
Chris Wrenaf4ce8462020-04-06 17:36:10 -0400248 .log(event);
Chris Wren65a70c92020-04-02 10:43:46 -0400249 }
Aran Inkcf038272020-03-31 17:48:37 -0400250
251 @Test
Aran Inkc58028b2020-06-04 15:33:22 -0400252 public void testCreateActionItems_maxThree_noOverflow() {
Aran Inkcf038272020-03-31 17:48:37 -0400253 mGlobalActionsDialog = spy(mGlobalActionsDialog);
254 // allow 3 items to be shown
255 doReturn(3).when(mGlobalActionsDialog).getMaxShownPowerItems();
256 // ensure items are not blocked by keyguard or device provisioning
257 doReturn(true).when(mGlobalActionsDialog).shouldShowAction(any());
258 String[] actions = {
259 GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
260 GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
261 GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
Aran Inkc58028b2020-06-04 15:33:22 -0400262 };
263 doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
264 mGlobalActionsDialog.createActionItems();
265
266 assertEquals(3, mGlobalActionsDialog.mItems.size());
267 assertEquals(0, mGlobalActionsDialog.mOverflowItems.size());
268 assertEquals(0, mGlobalActionsDialog.mPowerItems.size());
269 }
270
271 @Test
272 public void testCreateActionItems_maxThree_condensePower() {
273 mGlobalActionsDialog = spy(mGlobalActionsDialog);
274 // allow 3 items to be shown
275 doReturn(3).when(mGlobalActionsDialog).getMaxShownPowerItems();
276 // ensure items are not blocked by keyguard or device provisioning
277 doReturn(true).when(mGlobalActionsDialog).shouldShowAction(any());
278 // make sure lockdown action will be shown
279 doReturn(true).when(mGlobalActionsDialog).shouldDisplayLockdown(any());
280 String[] actions = {
281 GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
282 GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
283 GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
284 GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
285 };
286 doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
287 mGlobalActionsDialog.createActionItems();
288
289 assertEquals(3, mGlobalActionsDialog.mItems.size());
290 assertEquals(0, mGlobalActionsDialog.mOverflowItems.size());
291 assertEquals(2, mGlobalActionsDialog.mPowerItems.size());
292
293 // PowerOptionsAction should appear immediately after the Emergency action
294
295 GlobalActionsDialog.Action firstItem = mGlobalActionsDialog.mItems.get(0);
296 GlobalActionsDialog.Action secondItem = mGlobalActionsDialog.mItems.get(1);
297
298 assertTrue(firstItem instanceof GlobalActionsDialog.EmergencyAction);
299 assertTrue(secondItem instanceof GlobalActionsDialog.PowerOptionsAction);
300 }
301
302 @Test
303 public void testCreateActionItems_maxThree_condensePower_noEmergency() {
304 mGlobalActionsDialog = spy(mGlobalActionsDialog);
305 // allow 3 items to be shown
306 doReturn(3).when(mGlobalActionsDialog).getMaxShownPowerItems();
307 // make sure lockdown action will be shown
308 doReturn(true).when(mGlobalActionsDialog).shouldDisplayLockdown(any());
309 // ensure items are not blocked by keyguard or device provisioning
310 doReturn(true).when(mGlobalActionsDialog).shouldShowAction(any());
311 String[] actions = {
312 GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
313 GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
Aran Inkcf038272020-03-31 17:48:37 -0400314 GlobalActionsDialog.GLOBAL_ACTION_KEY_SCREENSHOT,
Aran Inkc58028b2020-06-04 15:33:22 -0400315 GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
316 };
317 doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
318 mGlobalActionsDialog.createActionItems();
319
320 assertEquals(3, mGlobalActionsDialog.mItems.size());
321 assertEquals(0, mGlobalActionsDialog.mOverflowItems.size());
322 assertEquals(2, mGlobalActionsDialog.mPowerItems.size());
323
324 // When Emergency isn't used, PowerOptionsAction should be first
325
326 GlobalActionsDialog.Action firstItem = mGlobalActionsDialog.mItems.get(0);
327 GlobalActionsDialog.Action secondItem = mGlobalActionsDialog.mItems.get(1);
328
329 assertTrue(firstItem instanceof GlobalActionsDialog.PowerOptionsAction);
330 assertTrue(secondItem instanceof GlobalActionsDialog.ScreenshotAction);
331 }
332
333 @Test
334 public void testCreateActionItems_maxFour_condensePower() {
335 mGlobalActionsDialog = spy(mGlobalActionsDialog);
336 // allow 3 items to be shown
337 doReturn(4).when(mGlobalActionsDialog).getMaxShownPowerItems();
338 // make sure lockdown action will be shown
339 doReturn(true).when(mGlobalActionsDialog).shouldDisplayLockdown(any());
340 // ensure items are not blocked by keyguard or device provisioning
341 doReturn(true).when(mGlobalActionsDialog).shouldShowAction(any());
342 String[] actions = {
343 GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
344 GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
345 GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
346 GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
347 GlobalActionsDialog.GLOBAL_ACTION_KEY_SCREENSHOT
348 };
349 doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
350 mGlobalActionsDialog.createActionItems();
351
352 assertEquals(4, mGlobalActionsDialog.mItems.size());
353 assertEquals(0, mGlobalActionsDialog.mOverflowItems.size());
354 assertEquals(2, mGlobalActionsDialog.mPowerItems.size());
355
356 // with four items, make sure power still shows up immediately after Emergency
357 GlobalActionsDialog.Action firstItem = mGlobalActionsDialog.mItems.get(0);
358 GlobalActionsDialog.Action secondItem = mGlobalActionsDialog.mItems.get(1);
359
360 assertTrue(firstItem instanceof GlobalActionsDialog.EmergencyAction);
361 assertTrue(secondItem instanceof GlobalActionsDialog.PowerOptionsAction);
362 }
363
364 @Test
365 public void testCreateActionItems_maxThree_doNotCondensePower() {
366 mGlobalActionsDialog = spy(mGlobalActionsDialog);
367 // allow 3 items to be shown
368 doReturn(3).when(mGlobalActionsDialog).getMaxShownPowerItems();
369 // make sure lockdown action will be shown
370 doReturn(true).when(mGlobalActionsDialog).shouldDisplayLockdown(any());
371 // ensure items are not blocked by keyguard or device provisioning
372 doReturn(true).when(mGlobalActionsDialog).shouldShowAction(any());
373 String[] actions = {
374 GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
375 GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
376 GlobalActionsDialog.GLOBAL_ACTION_KEY_SCREENSHOT,
377 GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
Aran Inkcf038272020-03-31 17:48:37 -0400378 };
379 doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
380 mGlobalActionsDialog.createActionItems();
381
382 assertEquals(3, mGlobalActionsDialog.mItems.size());
383 assertEquals(1, mGlobalActionsDialog.mOverflowItems.size());
Aran Inkc58028b2020-06-04 15:33:22 -0400384 assertEquals(0, mGlobalActionsDialog.mPowerItems.size());
Aran Inkcf038272020-03-31 17:48:37 -0400385 }
386
387 @Test
388 public void testCreateActionItems_maxAny() {
389 mGlobalActionsDialog = spy(mGlobalActionsDialog);
390 // allow any number of power menu items to be shown
391 doReturn(Integer.MAX_VALUE).when(mGlobalActionsDialog).getMaxShownPowerItems();
392 // ensure items are not blocked by keyguard or device provisioning
393 doReturn(true).when(mGlobalActionsDialog).shouldShowAction(any());
Aran Inkc58028b2020-06-04 15:33:22 -0400394 // make sure lockdown action will be shown
395 doReturn(true).when(mGlobalActionsDialog).shouldDisplayLockdown(any());
Aran Inkcf038272020-03-31 17:48:37 -0400396 String[] actions = {
397 GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
398 GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
399 GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
Aran Inkc58028b2020-06-04 15:33:22 -0400400 GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
Aran Inkcf038272020-03-31 17:48:37 -0400401 };
402 doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
403 mGlobalActionsDialog.createActionItems();
404
405 assertEquals(4, mGlobalActionsDialog.mItems.size());
406 assertEquals(0, mGlobalActionsDialog.mOverflowItems.size());
407 }
408
409 @Test
410 public void testCreateActionItems_maxThree_itemNotShown() {
411 mGlobalActionsDialog = spy(mGlobalActionsDialog);
412 // allow only 3 items to be shown
413 doReturn(3).when(mGlobalActionsDialog).getMaxShownPowerItems();
Aran Inkc58028b2020-06-04 15:33:22 -0400414 // make sure lockdown action will NOT be shown
415 doReturn(false).when(mGlobalActionsDialog).shouldDisplayLockdown(any());
Aran Inkcf038272020-03-31 17:48:37 -0400416 String[] actions = {
417 GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY,
Aran Inkc58028b2020-06-04 15:33:22 -0400418 // lockdown action not allowed
419 GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN,
Aran Inkcf038272020-03-31 17:48:37 -0400420 GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
421 GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
422 };
423 doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
424 mGlobalActionsDialog.createActionItems();
425
426 assertEquals(3, mGlobalActionsDialog.mItems.size());
427 assertEquals(0, mGlobalActionsDialog.mOverflowItems.size());
428 }
Sean Pontd7ff85a2020-05-18 21:47:08 -0700429
430 @Test
Matt Pietal50b661a2020-06-17 11:01:54 -0400431 public void testShouldShowLockScreenMessage() throws RemoteException {
Sean Pontd7ff85a2020-05-18 21:47:08 -0700432 mGlobalActionsDialog = spy(mGlobalActionsDialog);
433 mGlobalActionsDialog.mDialog = null;
434 when(mKeyguardStateController.isUnlocked()).thenReturn(false);
Matt Pietal50b661a2020-06-17 11:01:54 -0400435 when(mActivityManager.getCurrentUser()).thenReturn(newUserInfo());
436 when(mLockPatternUtils.getStrongAuthForUser(anyInt())).thenReturn(STRONG_AUTH_NOT_REQUIRED);
Sean Pontd7ff85a2020-05-18 21:47:08 -0700437 mGlobalActionsDialog.mShowLockScreenCardsAndControls = false;
438 setupDefaultActions();
439 when(mWalletPlugin.onPanelShown(any(), anyBoolean())).thenReturn(mWalletController);
440 when(mWalletController.getPanelContent()).thenReturn(new FrameLayout(mContext));
441
442 mGlobalActionsDialog.showOrHideDialog(false, true, mWalletPlugin);
443
444 GlobalActionsDialog.ActionsDialog dialog = mGlobalActionsDialog.mDialog;
445 assertThat(dialog).isNotNull();
446 assertThat(dialog.mLockMessageContainer.getVisibility()).isEqualTo(View.VISIBLE);
Sean Pont4e86ce62020-06-12 15:42:36 -0700447
448 // Dismiss the dialog so that it does not pollute other tests
449 mGlobalActionsDialog.showOrHideDialog(false, true, mWalletPlugin);
Sean Pontd7ff85a2020-05-18 21:47:08 -0700450 }
451
452 @Test
Matt Pietal50b661a2020-06-17 11:01:54 -0400453 public void testShouldNotShowLockScreenMessage_whenWalletOrControlsShownOnLockScreen()
454 throws RemoteException {
Sean Pontd7ff85a2020-05-18 21:47:08 -0700455 mGlobalActionsDialog = spy(mGlobalActionsDialog);
456 mGlobalActionsDialog.mDialog = null;
457 when(mKeyguardStateController.isUnlocked()).thenReturn(false);
Matt Pietal50b661a2020-06-17 11:01:54 -0400458 when(mActivityManager.getCurrentUser()).thenReturn(newUserInfo());
459 when(mLockPatternUtils.getStrongAuthForUser(anyInt())).thenReturn(STRONG_AUTH_NOT_REQUIRED);
Sean Pontd7ff85a2020-05-18 21:47:08 -0700460 mGlobalActionsDialog.mShowLockScreenCardsAndControls = true;
461 setupDefaultActions();
462 when(mWalletPlugin.onPanelShown(any(), anyBoolean())).thenReturn(mWalletController);
463 when(mWalletController.getPanelContent()).thenReturn(new FrameLayout(mContext));
464
465 mGlobalActionsDialog.showOrHideDialog(false, true, mWalletPlugin);
466
467 GlobalActionsDialog.ActionsDialog dialog = mGlobalActionsDialog.mDialog;
468 assertThat(dialog).isNotNull();
469 assertThat(dialog.mLockMessageContainer.getVisibility()).isEqualTo(View.GONE);
Sean Pont4e86ce62020-06-12 15:42:36 -0700470
471 // Dismiss the dialog so that it does not pollute other tests
472 mGlobalActionsDialog.showOrHideDialog(false, true, mWalletPlugin);
Sean Pontd7ff85a2020-05-18 21:47:08 -0700473 }
474
475 @Test
Matt Pietal50b661a2020-06-17 11:01:54 -0400476 public void testShouldNotShowLockScreenMessage_whenControlsAndWalletBothDisabled()
477 throws RemoteException {
Sean Pontd7ff85a2020-05-18 21:47:08 -0700478 mGlobalActionsDialog = spy(mGlobalActionsDialog);
479 mGlobalActionsDialog.mDialog = null;
480 when(mKeyguardStateController.isUnlocked()).thenReturn(false);
Matt Pietal50b661a2020-06-17 11:01:54 -0400481
482 when(mActivityManager.getCurrentUser()).thenReturn(newUserInfo());
483 when(mLockPatternUtils.getStrongAuthForUser(anyInt())).thenReturn(STRONG_AUTH_NOT_REQUIRED);
Sean Pontd7ff85a2020-05-18 21:47:08 -0700484 mGlobalActionsDialog.mShowLockScreenCardsAndControls = true;
485 setupDefaultActions();
486 when(mWalletPlugin.onPanelShown(any(), anyBoolean())).thenReturn(mWalletController);
487 when(mWalletController.getPanelContent()).thenReturn(null);
488 when(mControlsUiController.getAvailable()).thenReturn(false);
489
490 mGlobalActionsDialog.showOrHideDialog(false, true, mWalletPlugin);
491
492 GlobalActionsDialog.ActionsDialog dialog = mGlobalActionsDialog.mDialog;
493 assertThat(dialog).isNotNull();
494 assertThat(dialog.mLockMessageContainer.getVisibility()).isEqualTo(View.GONE);
Sean Pont4e86ce62020-06-12 15:42:36 -0700495
496 // Dismiss the dialog so that it does not pollute other tests
497 mGlobalActionsDialog.showOrHideDialog(false, true, mWalletPlugin);
Sean Pontd7ff85a2020-05-18 21:47:08 -0700498 }
499
Matt Pietal50b661a2020-06-17 11:01:54 -0400500 private UserInfo newUserInfo() {
501 return new UserInfo(0, null, null, UserInfo.FLAG_PRIMARY, null);
502 }
503
Sean Pontd7ff85a2020-05-18 21:47:08 -0700504 private void setupDefaultActions() {
505 String[] actions = {
506 GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER,
507 GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART,
508 GlobalActionsDialog.GLOBAL_ACTION_KEY_SCREENSHOT,
509 };
510 doReturn(actions).when(mGlobalActionsDialog).getDefaultActions();
511 }
Chris Wren65a70c92020-04-02 10:43:46 -0400512}