Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.globalactions; |
| 18 | |
Matt Pietal | 50b661a | 2020-06-17 11:01:54 -0400 | [diff] [blame] | 19 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED; |
| 20 | |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 21 | import static com.google.common.truth.Truth.assertThat; |
| 22 | |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 23 | import static junit.framework.Assert.assertEquals; |
Aran Ink | c58028b | 2020-06-04 15:33:22 -0400 | [diff] [blame] | 24 | import static junit.framework.Assert.assertTrue; |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 25 | |
| 26 | import static org.mockito.ArgumentMatchers.any; |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 27 | import static org.mockito.ArgumentMatchers.anyBoolean; |
| 28 | import static org.mockito.ArgumentMatchers.anyInt; |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 29 | import static org.mockito.Mockito.doReturn; |
| 30 | import static org.mockito.Mockito.spy; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 31 | import static org.mockito.Mockito.times; |
| 32 | import static org.mockito.Mockito.verify; |
Fabian Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 33 | import static org.mockito.Mockito.when; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 34 | |
| 35 | import android.app.IActivityManager; |
| 36 | import android.app.admin.DevicePolicyManager; |
| 37 | import android.app.trust.TrustManager; |
| 38 | import android.content.ContentResolver; |
Matt Pietal | 50b661a | 2020-06-17 11:01:54 -0400 | [diff] [blame] | 39 | import android.content.pm.UserInfo; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 40 | import android.content.res.Resources; |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 41 | import android.graphics.Color; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 42 | import android.media.AudioManager; |
| 43 | import android.net.ConnectivityManager; |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 44 | import android.os.Handler; |
Matt Pietal | 50b661a | 2020-06-17 11:01:54 -0400 | [diff] [blame] | 45 | import android.os.RemoteException; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 46 | import android.os.UserManager; |
| 47 | import android.service.dreams.IDreamManager; |
| 48 | import android.telephony.TelephonyManager; |
| 49 | import android.testing.AndroidTestingRunner; |
| 50 | import android.testing.TestableLooper; |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 51 | import android.util.FeatureFlagUtils; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 52 | import android.view.IWindowManager; |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 53 | import android.view.View; |
| 54 | import android.widget.FrameLayout; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 55 | |
| 56 | import androidx.test.filters.SmallTest; |
| 57 | |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 58 | import com.android.internal.colorextraction.ColorExtractor; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 59 | import com.android.internal.logging.MetricsLogger; |
| 60 | import com.android.internal.logging.UiEventLogger; |
| 61 | import com.android.internal.statusbar.IStatusBarService; |
| 62 | import com.android.internal.widget.LockPatternUtils; |
| 63 | import com.android.systemui.SysuiTestCase; |
| 64 | import com.android.systemui.broadcast.BroadcastDispatcher; |
| 65 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
| 66 | import com.android.systemui.controls.controller.ControlsController; |
Fabian Kozynski | 137951c | 2020-05-26 15:13:52 -0400 | [diff] [blame] | 67 | import com.android.systemui.controls.dagger.ControlsComponent; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 68 | import com.android.systemui.controls.management.ControlsListingController; |
| 69 | import com.android.systemui.controls.ui.ControlsUiController; |
Winson Chung | 9467454 | 2020-05-15 10:35:55 -0700 | [diff] [blame] | 70 | import com.android.systemui.model.SysUiState; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 71 | import com.android.systemui.plugins.ActivityStarter; |
| 72 | import com.android.systemui.plugins.GlobalActions; |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 73 | import com.android.systemui.plugins.GlobalActionsPanelPlugin; |
Matt Pietal | 96c3695 | 2020-05-26 11:14:37 -0400 | [diff] [blame] | 74 | import com.android.systemui.settings.CurrentUserContextTracker; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 75 | import com.android.systemui.statusbar.NotificationShadeDepthController; |
| 76 | import com.android.systemui.statusbar.phone.NotificationShadeWindowController; |
| 77 | import com.android.systemui.statusbar.policy.ConfigurationController; |
| 78 | import com.android.systemui.statusbar.policy.KeyguardStateController; |
Fabian Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 79 | import com.android.systemui.util.RingerModeLiveData; |
| 80 | import com.android.systemui.util.RingerModeTracker; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 81 | |
| 82 | import org.junit.Before; |
| 83 | import org.junit.Test; |
| 84 | import org.junit.runner.RunWith; |
| 85 | import org.mockito.Mock; |
| 86 | import org.mockito.MockitoAnnotations; |
| 87 | |
| 88 | import java.util.concurrent.Executor; |
| 89 | |
| 90 | @SmallTest |
| 91 | @RunWith(AndroidTestingRunner.class) |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 92 | @TestableLooper.RunWithLooper() |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 93 | public 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 Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 116 | @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 Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 123 | @Mock private RingerModeTracker mRingerModeTracker; |
| 124 | @Mock private RingerModeLiveData mRingerModeLiveData; |
Winson Chung | 9467454 | 2020-05-15 10:35:55 -0700 | [diff] [blame] | 125 | @Mock private SysUiState mSysUiState; |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 126 | @Mock GlobalActionsPanelPlugin mWalletPlugin; |
| 127 | @Mock GlobalActionsPanelPlugin.PanelViewController mWalletController; |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 128 | @Mock private Handler mHandler; |
Matt Pietal | 96c3695 | 2020-05-26 11:14:37 -0400 | [diff] [blame] | 129 | @Mock private CurrentUserContextTracker mCurrentUserContextTracker; |
Fabian Kozynski | 137951c | 2020-05-26 15:13:52 -0400 | [diff] [blame] | 130 | private ControlsComponent mControlsComponent; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 131 | |
| 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 Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 139 | |
| 140 | when(mRingerModeTracker.getRingerMode()).thenReturn(mRingerModeLiveData); |
Matt Pietal | 96c3695 | 2020-05-26 11:14:37 -0400 | [diff] [blame] | 141 | when(mCurrentUserContextTracker.getCurrentUserContext()).thenReturn(mContext); |
Fabian Kozynski | 137951c | 2020-05-26 15:13:52 -0400 | [diff] [blame] | 142 | mControlsComponent = new ControlsComponent( |
| 143 | true, |
| 144 | () -> mControlsController, |
| 145 | () -> mControlsUiController, |
| 146 | () -> mControlsListingController |
| 147 | ); |
| 148 | |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 149 | 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 Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 172 | mNotificationShadeWindowController, |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 173 | mWindowManager, |
| 174 | mBackgroundExecutor, |
Fabian Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 175 | mUiEventLogger, |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 176 | mRingerModeTracker, |
Winson Chung | 9467454 | 2020-05-15 10:35:55 -0700 | [diff] [blame] | 177 | mSysUiState, |
Matt Pietal | 96c3695 | 2020-05-26 11:14:37 -0400 | [diff] [blame] | 178 | mHandler, |
Fabian Kozynski | 137951c | 2020-05-26 15:13:52 -0400 | [diff] [blame] | 179 | mControlsComponent, |
Matt Pietal | 96c3695 | 2020-05-26 11:14:37 -0400 | [diff] [blame] | 180 | mCurrentUserContextTracker |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 181 | ); |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 182 | mGlobalActionsDialog.setZeroDialogPressDelayForTesting(); |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 183 | |
| 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 Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 188 | } |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 189 | |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 190 | @Test |
Chris Wren | 9756a00 | 2020-05-12 16:46:27 -0400 | [diff] [blame] | 191 | public void testShouldLogShow() { |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 192 | mGlobalActionsDialog.onShow(null); |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 193 | mTestableLooper.processAllMessages(); |
| 194 | verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_POWER_MENU_OPEN); |
| 195 | } |
| 196 | |
| 197 | @Test |
Chris Wren | 9756a00 | 2020-05-12 16:46:27 -0400 | [diff] [blame] | 198 | public void testShouldLogDismiss() { |
| 199 | mGlobalActionsDialog.onDismiss(mGlobalActionsDialog.mDialog); |
| 200 | mTestableLooper.processAllMessages(); |
| 201 | verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_POWER_MENU_CLOSE); |
| 202 | } |
| 203 | |
| 204 | @Test |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 205 | 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 Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 247 | verify(mUiEventLogger, times(1)) |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 248 | .log(event); |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 249 | } |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 250 | |
| 251 | @Test |
Aran Ink | c58028b | 2020-06-04 15:33:22 -0400 | [diff] [blame] | 252 | public void testCreateActionItems_maxThree_noOverflow() { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 253 | 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 Ink | c58028b | 2020-06-04 15:33:22 -0400 | [diff] [blame] | 262 | }; |
| 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 Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 314 | GlobalActionsDialog.GLOBAL_ACTION_KEY_SCREENSHOT, |
Aran Ink | c58028b | 2020-06-04 15:33:22 -0400 | [diff] [blame] | 315 | 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 Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 378 | }; |
| 379 | doReturn(actions).when(mGlobalActionsDialog).getDefaultActions(); |
| 380 | mGlobalActionsDialog.createActionItems(); |
| 381 | |
| 382 | assertEquals(3, mGlobalActionsDialog.mItems.size()); |
| 383 | assertEquals(1, mGlobalActionsDialog.mOverflowItems.size()); |
Aran Ink | c58028b | 2020-06-04 15:33:22 -0400 | [diff] [blame] | 384 | assertEquals(0, mGlobalActionsDialog.mPowerItems.size()); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 385 | } |
| 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 Ink | c58028b | 2020-06-04 15:33:22 -0400 | [diff] [blame] | 394 | // make sure lockdown action will be shown |
| 395 | doReturn(true).when(mGlobalActionsDialog).shouldDisplayLockdown(any()); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 396 | String[] actions = { |
| 397 | GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY, |
| 398 | GlobalActionsDialog.GLOBAL_ACTION_KEY_POWER, |
| 399 | GlobalActionsDialog.GLOBAL_ACTION_KEY_RESTART, |
Aran Ink | c58028b | 2020-06-04 15:33:22 -0400 | [diff] [blame] | 400 | GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN, |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 401 | }; |
| 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 Ink | c58028b | 2020-06-04 15:33:22 -0400 | [diff] [blame] | 414 | // make sure lockdown action will NOT be shown |
| 415 | doReturn(false).when(mGlobalActionsDialog).shouldDisplayLockdown(any()); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 416 | String[] actions = { |
| 417 | GlobalActionsDialog.GLOBAL_ACTION_KEY_EMERGENCY, |
Aran Ink | c58028b | 2020-06-04 15:33:22 -0400 | [diff] [blame] | 418 | // lockdown action not allowed |
| 419 | GlobalActionsDialog.GLOBAL_ACTION_KEY_LOCKDOWN, |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 420 | 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 Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 429 | |
| 430 | @Test |
Matt Pietal | 50b661a | 2020-06-17 11:01:54 -0400 | [diff] [blame] | 431 | public void testShouldShowLockScreenMessage() throws RemoteException { |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 432 | mGlobalActionsDialog = spy(mGlobalActionsDialog); |
| 433 | mGlobalActionsDialog.mDialog = null; |
| 434 | when(mKeyguardStateController.isUnlocked()).thenReturn(false); |
Matt Pietal | 50b661a | 2020-06-17 11:01:54 -0400 | [diff] [blame] | 435 | when(mActivityManager.getCurrentUser()).thenReturn(newUserInfo()); |
| 436 | when(mLockPatternUtils.getStrongAuthForUser(anyInt())).thenReturn(STRONG_AUTH_NOT_REQUIRED); |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 437 | 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 Pont | 4e86ce6 | 2020-06-12 15:42:36 -0700 | [diff] [blame] | 447 | |
| 448 | // Dismiss the dialog so that it does not pollute other tests |
| 449 | mGlobalActionsDialog.showOrHideDialog(false, true, mWalletPlugin); |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | @Test |
Matt Pietal | 50b661a | 2020-06-17 11:01:54 -0400 | [diff] [blame] | 453 | public void testShouldNotShowLockScreenMessage_whenWalletOrControlsShownOnLockScreen() |
| 454 | throws RemoteException { |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 455 | mGlobalActionsDialog = spy(mGlobalActionsDialog); |
| 456 | mGlobalActionsDialog.mDialog = null; |
| 457 | when(mKeyguardStateController.isUnlocked()).thenReturn(false); |
Matt Pietal | 50b661a | 2020-06-17 11:01:54 -0400 | [diff] [blame] | 458 | when(mActivityManager.getCurrentUser()).thenReturn(newUserInfo()); |
| 459 | when(mLockPatternUtils.getStrongAuthForUser(anyInt())).thenReturn(STRONG_AUTH_NOT_REQUIRED); |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 460 | 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 Pont | 4e86ce6 | 2020-06-12 15:42:36 -0700 | [diff] [blame] | 470 | |
| 471 | // Dismiss the dialog so that it does not pollute other tests |
| 472 | mGlobalActionsDialog.showOrHideDialog(false, true, mWalletPlugin); |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | @Test |
Matt Pietal | 50b661a | 2020-06-17 11:01:54 -0400 | [diff] [blame] | 476 | public void testShouldNotShowLockScreenMessage_whenControlsAndWalletBothDisabled() |
| 477 | throws RemoteException { |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 478 | mGlobalActionsDialog = spy(mGlobalActionsDialog); |
| 479 | mGlobalActionsDialog.mDialog = null; |
| 480 | when(mKeyguardStateController.isUnlocked()).thenReturn(false); |
Matt Pietal | 50b661a | 2020-06-17 11:01:54 -0400 | [diff] [blame] | 481 | |
| 482 | when(mActivityManager.getCurrentUser()).thenReturn(newUserInfo()); |
| 483 | when(mLockPatternUtils.getStrongAuthForUser(anyInt())).thenReturn(STRONG_AUTH_NOT_REQUIRED); |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 484 | 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 Pont | 4e86ce6 | 2020-06-12 15:42:36 -0700 | [diff] [blame] | 495 | |
| 496 | // Dismiss the dialog so that it does not pollute other tests |
| 497 | mGlobalActionsDialog.showOrHideDialog(false, true, mWalletPlugin); |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Matt Pietal | 50b661a | 2020-06-17 11:01:54 -0400 | [diff] [blame] | 500 | private UserInfo newUserInfo() { |
| 501 | return new UserInfo(0, null, null, UserInfo.FLAG_PRIMARY, null); |
| 502 | } |
| 503 | |
Sean Pont | d7ff85a | 2020-05-18 21:47:08 -0700 | [diff] [blame] | 504 | 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 Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 512 | } |