Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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.phone; |
| 18 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 19 | import static android.app.NotificationManager.IMPORTANCE_HIGH; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 20 | import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK; |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 21 | import static android.view.Display.DEFAULT_DISPLAY; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 22 | |
| 23 | import static junit.framework.Assert.assertFalse; |
| 24 | import static junit.framework.Assert.assertTrue; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 25 | import static junit.framework.TestCase.fail; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 26 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 27 | import static org.mockito.ArgumentMatchers.any; |
| 28 | import static org.mockito.ArgumentMatchers.anyBoolean; |
| 29 | import static org.mockito.ArgumentMatchers.anyInt; |
| 30 | import static org.mockito.ArgumentMatchers.anyString; |
Lucas Dupin | 311eac8 | 2017-12-11 14:40:07 -0800 | [diff] [blame] | 31 | import static org.mockito.ArgumentMatchers.eq; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 32 | import static org.mockito.Mockito.doAnswer; |
| 33 | import static org.mockito.Mockito.mock; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 34 | import static org.mockito.Mockito.never; |
Lucas Dupin | d510730 | 2018-03-19 15:30:29 -0700 | [diff] [blame] | 35 | import static org.mockito.Mockito.reset; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 36 | import static org.mockito.Mockito.times; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 37 | import static org.mockito.Mockito.verify; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 38 | import static org.mockito.Mockito.when; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 39 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 40 | import android.app.Notification; |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 41 | import android.app.StatusBarManager; |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 42 | import android.app.trust.TrustManager; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 43 | import android.content.Context; |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 44 | import android.hardware.fingerprint.FingerprintManager; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 45 | import android.metrics.LogMaker; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 46 | import android.os.Binder; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 47 | import android.os.Handler; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 48 | import android.os.IPowerManager; |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 49 | import android.os.Looper; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 50 | import android.os.PowerManager; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 51 | import android.os.RemoteException; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 52 | import android.os.UserHandle; |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 53 | import android.service.dreams.IDreamManager; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 54 | import android.service.notification.StatusBarNotification; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 55 | import android.support.test.filters.SmallTest; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 56 | import android.support.test.metricshelper.MetricsAsserts; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 57 | import android.testing.AndroidTestingRunner; |
| 58 | import android.testing.TestableLooper; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 59 | import android.testing.TestableLooper.RunWithLooper; |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 60 | import android.util.SparseArray; |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 61 | import android.view.ViewGroup.LayoutParams; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 62 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 63 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 64 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 65 | import com.android.internal.logging.testing.FakeMetricsLogger; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 66 | import com.android.internal.statusbar.IStatusBarService; |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 67 | import com.android.keyguard.KeyguardUpdateMonitor; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 68 | import com.android.systemui.Dependency; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 69 | import com.android.systemui.ForegroundServiceController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 70 | import com.android.systemui.InitController; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 71 | import com.android.systemui.R; |
Selim Cinek | 9d20bed | 2018-12-26 16:02:34 -0800 | [diff] [blame] | 72 | import com.android.systemui.SystemUIFactory; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 73 | import com.android.systemui.SysuiTestCase; |
Jason Monk | d97204c | 2018-12-21 15:49:04 -0500 | [diff] [blame] | 74 | import com.android.systemui.UiOffloadThread; |
Fabian Kozynski | 1f32cf0 | 2018-10-23 12:23:31 -0400 | [diff] [blame] | 75 | import com.android.systemui.appops.AppOpsController; |
| 76 | import com.android.systemui.appops.AppOpsControllerImpl; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 77 | import com.android.systemui.assist.AssistManager; |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 78 | import com.android.systemui.bubbles.BubbleController; |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 79 | import com.android.systemui.classifier.FalsingManager; |
Lucas Dupin | 988efb2 | 2018-12-04 16:53:58 -0800 | [diff] [blame] | 80 | import com.android.systemui.doze.DozeHost; |
| 81 | import com.android.systemui.doze.DozeLog; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 82 | import com.android.systemui.keyguard.KeyguardViewMediator; |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 83 | import com.android.systemui.keyguard.WakefulnessLifecycle; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 84 | import com.android.systemui.plugins.ActivityStarter.OnDismissAction; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 85 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Jason Monk | 5ecf80c | 2017-07-06 15:28:17 -0400 | [diff] [blame] | 86 | import com.android.systemui.statusbar.CommandQueue; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 87 | import com.android.systemui.statusbar.KeyguardIndicationController; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 88 | import com.android.systemui.statusbar.NavigationBarController; |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 89 | import com.android.systemui.statusbar.NotificationListener; |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 90 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 91 | import com.android.systemui.statusbar.NotificationMediaManager; |
| 92 | import com.android.systemui.statusbar.NotificationPresenter; |
| 93 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 94 | import com.android.systemui.statusbar.NotificationShelf; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 95 | import com.android.systemui.statusbar.NotificationViewHierarchyManager; |
Selim Cinek | 7c6fe5b | 2018-04-09 18:27:13 -0700 | [diff] [blame] | 96 | import com.android.systemui.statusbar.RemoteInputController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 97 | import com.android.systemui.statusbar.StatusBarState; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 98 | import com.android.systemui.statusbar.StatusBarStateControllerImpl; |
Gus Prevas | b43dc65 | 2018-12-20 13:11:45 -0500 | [diff] [blame] | 99 | import com.android.systemui.statusbar.notification.NotificationAlertingManager; |
Gus Prevas | 26bc59b | 2018-12-19 11:26:39 -0500 | [diff] [blame] | 100 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 101 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 102 | import com.android.systemui.statusbar.notification.NotificationFilter; |
| 103 | import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 104 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 105 | import com.android.systemui.statusbar.notification.collection.NotificationData; |
| 106 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 107 | import com.android.systemui.statusbar.notification.logging.NotificationLogger; |
| 108 | import com.android.systemui.statusbar.notification.row.NotificationGutsManager; |
| 109 | import com.android.systemui.statusbar.notification.stack.NotificationListContainer; |
| 110 | import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 111 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 112 | import com.android.systemui.statusbar.policy.KeyguardMonitor; |
| 113 | import com.android.systemui.statusbar.policy.KeyguardMonitorImpl; |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 114 | import com.android.systemui.statusbar.policy.UserSwitcherController; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 115 | |
| 116 | import org.junit.Before; |
| 117 | import org.junit.Test; |
| 118 | import org.junit.runner.RunWith; |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 119 | import org.mockito.Mock; |
| 120 | import org.mockito.MockitoAnnotations; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 121 | |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 122 | import java.io.ByteArrayOutputStream; |
| 123 | import java.io.PrintWriter; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 124 | import java.util.ArrayList; |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 125 | import java.util.Arrays; |
| 126 | import java.util.Collections; |
| 127 | import java.util.HashSet; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 128 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 129 | @SmallTest |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 130 | @RunWith(AndroidTestingRunner.class) |
| 131 | @RunWithLooper |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 132 | public class StatusBarTest extends SysuiTestCase { |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 133 | @Mock private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
| 134 | @Mock private UnlockMethodCache mUnlockMethodCache; |
| 135 | @Mock private KeyguardIndicationController mKeyguardIndicationController; |
| 136 | @Mock private NotificationStackScrollLayout mStackScroller; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 137 | @Mock private HeadsUpManagerPhone mHeadsUpManager; |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 138 | @Mock private NotificationPanelView mNotificationPanelView; |
| 139 | @Mock private IStatusBarService mBarService; |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 140 | @Mock private IDreamManager mDreamManager; |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 141 | @Mock private ScrimController mScrimController; |
Lucas Dupin | 988efb2 | 2018-12-04 16:53:58 -0800 | [diff] [blame] | 142 | @Mock private DozeScrimController mDozeScrimController; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 143 | @Mock private ArrayList<NotificationEntry> mNotificationList; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 144 | @Mock private BiometricUnlockController mBiometricUnlockController; |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 145 | @Mock private NotificationData mNotificationData; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 146 | @Mock |
| 147 | private NotificationInterruptionStateProvider.HeadsUpSuppressor mHeadsUpSuppressor; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 148 | |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 149 | // Mock dependencies: |
| 150 | @Mock private NotificationViewHierarchyManager mViewHierarchyManager; |
| 151 | @Mock private VisualStabilityManager mVisualStabilityManager; |
| 152 | @Mock private NotificationListener mNotificationListener; |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 153 | @Mock private KeyguardViewMediator mKeyguardViewMediator; |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 154 | @Mock private NotificationLockscreenUserManager mLockscreenUserManager; |
Selim Cinek | 7c6fe5b | 2018-04-09 18:27:13 -0700 | [diff] [blame] | 155 | @Mock private NotificationRemoteInputManager mRemoteInputManager; |
| 156 | @Mock private RemoteInputController mRemoteInputController; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 157 | @Mock private StatusBarStateControllerImpl mStatusBarStateController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 158 | @Mock private DeviceProvisionedController mDeviceProvisionedController; |
| 159 | @Mock private NotificationPresenter mNotificationPresenter; |
Gus Prevas | 26bc59b | 2018-12-19 11:26:39 -0500 | [diff] [blame] | 160 | @Mock |
Gus Prevas | 8621bd2 | 2018-12-20 15:04:25 -0500 | [diff] [blame] | 161 | private NotificationEntryListener mEntryListener; |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 162 | @Mock private BubbleController mBubbleController; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 163 | @Mock |
| 164 | private NotificationFilter mNotificationFilter; |
Gus Prevas | b43dc65 | 2018-12-20 13:11:45 -0500 | [diff] [blame] | 165 | @Mock |
| 166 | private NotificationAlertingManager mNotificationAlertingManager; |
Tony Mak | 202f25d | 2019-01-07 14:40:39 +0000 | [diff] [blame] | 167 | @Mock |
| 168 | private NotificationLogger.ExpansionStateLogger mExpansionStateLogger; |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 169 | @Mock |
| 170 | private KeyguardUpdateMonitor mKeyguardUpdateMonitor; |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 171 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 172 | private TestableStatusBar mStatusBar; |
| 173 | private FakeMetricsLogger mMetricsLogger; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 174 | private PowerManager mPowerManager; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 175 | private TestableNotificationEntryManager mEntryManager; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 176 | private TestableNotificationInterruptionStateProvider mNotificationInterruptionStateProvider; |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 177 | private NotificationLogger mNotificationLogger; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 178 | private CommandQueue mCommandQueue; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 179 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 180 | @Before |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 181 | public void setup() throws Exception { |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 182 | MockitoAnnotations.initMocks(this); |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 183 | mDependency.injectMockDependency(AssistManager.class); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 184 | mDependency.injectMockDependency(NotificationGutsManager.class); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 185 | mDependency.injectMockDependency(NotificationMediaManager.class); |
| 186 | mDependency.injectMockDependency(ForegroundServiceController.class); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 187 | mDependency.injectTestDependency(NotificationViewHierarchyManager.class, |
| 188 | mViewHierarchyManager); |
| 189 | mDependency.injectTestDependency(VisualStabilityManager.class, mVisualStabilityManager); |
| 190 | mDependency.injectTestDependency(NotificationListener.class, mNotificationListener); |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 191 | mDependency.injectTestDependency(KeyguardMonitor.class, mock(KeyguardMonitorImpl.class)); |
Fabian Kozynski | 1f32cf0 | 2018-10-23 12:23:31 -0400 | [diff] [blame] | 192 | mDependency.injectTestDependency(AppOpsController.class, mock(AppOpsControllerImpl.class)); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 193 | mDependency.injectTestDependency(StatusBarStateController.class, mStatusBarStateController); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 194 | mDependency.injectTestDependency(DeviceProvisionedController.class, |
| 195 | mDeviceProvisionedController); |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 196 | mDependency.injectMockDependency(BubbleController.class); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 197 | mDependency.injectTestDependency(NotificationFilter.class, mNotificationFilter); |
Gus Prevas | b43dc65 | 2018-12-20 13:11:45 -0500 | [diff] [blame] | 198 | mDependency.injectTestDependency(NotificationAlertingManager.class, |
| 199 | mNotificationAlertingManager); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 200 | |
| 201 | IPowerManager powerManagerService = mock(IPowerManager.class); |
| 202 | mPowerManager = new PowerManager(mContext, powerManagerService, |
| 203 | Handler.createAsync(Looper.myLooper())); |
| 204 | |
| 205 | mNotificationInterruptionStateProvider = |
| 206 | new TestableNotificationInterruptionStateProvider(mContext, mPowerManager, |
| 207 | mDreamManager); |
| 208 | mDependency.injectTestDependency(NotificationInterruptionStateProvider.class, |
| 209 | mNotificationInterruptionStateProvider); |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 210 | mDependency.injectMockDependency(NavigationBarController.class); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 211 | |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 212 | mContext.addMockSystemService(TrustManager.class, mock(TrustManager.class)); |
| 213 | mContext.addMockSystemService(FingerprintManager.class, mock(FingerprintManager.class)); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 214 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 215 | mMetricsLogger = new FakeMetricsLogger(); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 216 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Gus Prevas | 9258646 | 2019-01-04 16:06:12 -0500 | [diff] [blame] | 217 | mEntryManager = new TestableNotificationEntryManager(mContext); |
Jason Monk | d97204c | 2018-12-21 15:49:04 -0500 | [diff] [blame] | 218 | mNotificationLogger = new NotificationLogger(mNotificationListener, |
Tony Mak | 202f25d | 2019-01-07 14:40:39 +0000 | [diff] [blame] | 219 | Dependency.get(UiOffloadThread.class), mEntryManager, mStatusBarStateController, |
| 220 | mExpansionStateLogger); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 221 | mDependency.injectTestDependency(NotificationLogger.class, mNotificationLogger); |
Lucas Dupin | 78c8fed | 2018-12-18 16:41:37 -0800 | [diff] [blame] | 222 | DozeLog.traceDozing(mContext, false /* dozing */); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 223 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 224 | mCommandQueue = mock(CommandQueue.class); |
| 225 | when(mCommandQueue.asBinder()).thenReturn(new Binder()); |
| 226 | mContext.putComponent(CommandQueue.class, mCommandQueue); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 227 | |
| 228 | mContext.setTheme(R.style.Theme_SystemUI_Light); |
| 229 | |
| 230 | when(mStackScroller.generateLayoutParams(any())).thenReturn(new LayoutParams(0, 0)); |
| 231 | when(mNotificationPanelView.getLayoutParams()).thenReturn(new LayoutParams(0, 0)); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 232 | when(powerManagerService.isInteractive()).thenReturn(true); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 233 | when(mStackScroller.getActivatedChild()).thenReturn(null); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 234 | |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 235 | doAnswer(invocation -> { |
| 236 | OnDismissAction onDismissAction = (OnDismissAction) invocation.getArguments()[0]; |
| 237 | onDismissAction.onDismiss(); |
| 238 | return null; |
| 239 | }).when(mStatusBarKeyguardViewManager).dismissWithAction(any(), any(), anyBoolean()); |
| 240 | |
| 241 | doAnswer(invocation -> { |
| 242 | Runnable runnable = (Runnable) invocation.getArguments()[0]; |
| 243 | runnable.run(); |
| 244 | return null; |
| 245 | }).when(mStatusBarKeyguardViewManager).addAfterKeyguardGoneRunnable(any()); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 246 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 247 | mNotificationInterruptionStateProvider.setUpWithPresenter(mNotificationPresenter, |
| 248 | mHeadsUpManager, mHeadsUpSuppressor); |
| 249 | |
Selim Cinek | 7c6fe5b | 2018-04-09 18:27:13 -0700 | [diff] [blame] | 250 | when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 251 | mStatusBar = new TestableStatusBar(mStatusBarKeyguardViewManager, mUnlockMethodCache, |
| 252 | mKeyguardIndicationController, mStackScroller, mHeadsUpManager, |
| 253 | mPowerManager, mNotificationPanelView, mBarService, mNotificationListener, |
| 254 | mNotificationLogger, mVisualStabilityManager, mViewHierarchyManager, |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 255 | mEntryManager, mScrimController, mBiometricUnlockController, |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 256 | mKeyguardViewMediator, mRemoteInputManager, mock(NotificationGroupManager.class), |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 257 | mock(NotificationGroupAlertTransferHelper.class), mock(FalsingManager.class), |
| 258 | mock(StatusBarWindowController.class), mock(NotificationIconAreaController.class), |
Lucas Dupin | 988efb2 | 2018-12-04 16:53:58 -0800 | [diff] [blame] | 259 | mDozeScrimController, mock(NotificationShelf.class), |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 260 | mLockscreenUserManager, mCommandQueue, mNotificationPresenter, |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 261 | mock(BubbleController.class), mock(NavigationBarController.class), |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 262 | mock(AutoHideController.class), mKeyguardUpdateMonitor); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 263 | mStatusBar.mContext = mContext; |
| 264 | mStatusBar.mComponents = mContext.getComponents(); |
Selim Cinek | 9d20bed | 2018-12-26 16:02:34 -0800 | [diff] [blame] | 265 | SystemUIFactory.getInstance().getRootComponent() |
| 266 | .getStatusBarInjector() |
| 267 | .createStatusBar(mStatusBar); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 268 | mStatusBar.putComponent(StatusBar.class, mStatusBar); |
| 269 | Dependency.get(InitController.class).executePostInitTasks(); |
| 270 | mEntryManager.setUpForTest(mock(NotificationPresenter.class), mStackScroller, |
Gus Prevas | 8621bd2 | 2018-12-20 15:04:25 -0500 | [diff] [blame] | 271 | mHeadsUpManager, mNotificationData); |
| 272 | mEntryManager.addNotificationEntryListener(mEntryListener); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 273 | mNotificationLogger.setUpWithContainer(mStackScroller); |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 274 | |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 275 | TestableLooper.get(this).setMessageHandler(m -> { |
| 276 | if (m.getCallback() == mStatusBar.mNotificationLogger.getVisibilityReporter()) { |
| 277 | return false; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 278 | } |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 279 | return true; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 280 | }); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 283 | @Test |
Jason Monk | 5ecf80c | 2017-07-06 15:28:17 -0400 | [diff] [blame] | 284 | public void testSetBouncerShowing_noCrash() { |
| 285 | mStatusBar.mCommandQueue = mock(CommandQueue.class); |
| 286 | mStatusBar.setBouncerShowing(true); |
| 287 | } |
| 288 | |
| 289 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 290 | public void executeRunnableDismissingKeyguard_nullRunnable_showingAndOccluded() { |
| 291 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 292 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(true); |
| 293 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 294 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 295 | } |
| 296 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 297 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 298 | public void executeRunnableDismissingKeyguard_nullRunnable_showing() { |
| 299 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 300 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 301 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 302 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 303 | } |
| 304 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 305 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 306 | public void executeRunnableDismissingKeyguard_nullRunnable_notShowing() { |
| 307 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 308 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 309 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 310 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 313 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 314 | public void lockscreenStateMetrics_notShowing() { |
| 315 | // uninteresting state, except that fingerprint must be non-zero |
| 316 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 317 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 318 | // interesting state |
| 319 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 320 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 321 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(false); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 322 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 323 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 324 | MetricsAsserts.assertHasLog("missing hidden insecure lockscreen log", |
| 325 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 326 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 327 | .setType(MetricsEvent.TYPE_CLOSE) |
| 328 | .setSubtype(0)); |
| 329 | } |
| 330 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 331 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 332 | public void lockscreenStateMetrics_notShowing_secure() { |
| 333 | // uninteresting state, except that fingerprint must be non-zero |
| 334 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 335 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 336 | // interesting state |
| 337 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 338 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 339 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 340 | |
| 341 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 342 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 343 | MetricsAsserts.assertHasLog("missing hidden secure lockscreen log", |
| 344 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 345 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 346 | .setType(MetricsEvent.TYPE_CLOSE) |
| 347 | .setSubtype(1)); |
| 348 | } |
| 349 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 350 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 351 | public void lockscreenStateMetrics_isShowing() { |
| 352 | // uninteresting state, except that fingerprint must be non-zero |
| 353 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 354 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 355 | // interesting state |
| 356 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 357 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 358 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(false); |
| 359 | |
| 360 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 361 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 362 | MetricsAsserts.assertHasLog("missing insecure lockscreen showing", |
| 363 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 364 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 365 | .setType(MetricsEvent.TYPE_OPEN) |
| 366 | .setSubtype(0)); |
| 367 | } |
| 368 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 369 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 370 | public void lockscreenStateMetrics_isShowing_secure() { |
| 371 | // uninteresting state, except that fingerprint must be non-zero |
| 372 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 373 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 374 | // interesting state |
| 375 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 376 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 377 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 378 | |
| 379 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 380 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 381 | MetricsAsserts.assertHasLog("missing secure lockscreen showing log", |
| 382 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 383 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 384 | .setType(MetricsEvent.TYPE_OPEN) |
| 385 | .setSubtype(1)); |
| 386 | } |
| 387 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 388 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 389 | public void lockscreenStateMetrics_isShowingBouncer() { |
| 390 | // uninteresting state, except that fingerprint must be non-zero |
| 391 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 392 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 393 | // interesting state |
| 394 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 395 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); |
| 396 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 397 | |
| 398 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 399 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 400 | MetricsAsserts.assertHasLog("missing bouncer log", |
| 401 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 402 | new LogMaker(MetricsEvent.BOUNCER) |
| 403 | .setType(MetricsEvent.TYPE_OPEN) |
| 404 | .setSubtype(1)); |
| 405 | } |
| 406 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 407 | @Test |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 408 | public void testShouldHeadsUp_nonSuppressedGroupSummary() throws Exception { |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 409 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 410 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 411 | when(mNotificationFilter.shouldFilterOut(any())).thenReturn(false); |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 412 | when(mDreamManager.isDreaming()).thenReturn(false); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 413 | when(mHeadsUpSuppressor.canHeadsUp(any(), any())).thenReturn(true); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 414 | |
| 415 | Notification n = new Notification.Builder(getContext(), "a") |
| 416 | .setGroup("a") |
| 417 | .setGroupSummary(true) |
| 418 | .setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY) |
| 419 | .build(); |
| 420 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 421 | UserHandle.of(0), null, 0); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 422 | NotificationEntry entry = new NotificationEntry(sbn); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 423 | entry.importance = IMPORTANCE_HIGH; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 424 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 425 | assertTrue(mNotificationInterruptionStateProvider.shouldHeadsUp(entry)); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | @Test |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 429 | public void testShouldHeadsUp_suppressedGroupSummary() throws Exception { |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 430 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 431 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 432 | when(mNotificationFilter.shouldFilterOut(any())).thenReturn(false); |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 433 | when(mDreamManager.isDreaming()).thenReturn(false); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 434 | when(mHeadsUpSuppressor.canHeadsUp(any(), any())).thenReturn(true); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 435 | |
| 436 | Notification n = new Notification.Builder(getContext(), "a") |
| 437 | .setGroup("a") |
| 438 | .setGroupSummary(true) |
| 439 | .setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN) |
| 440 | .build(); |
| 441 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 442 | UserHandle.of(0), null, 0); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 443 | NotificationEntry entry = new NotificationEntry(sbn); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 444 | entry.importance = IMPORTANCE_HIGH; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 445 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 446 | assertFalse(mNotificationInterruptionStateProvider.shouldHeadsUp(entry)); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 447 | } |
| 448 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 449 | @Test |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 450 | public void testShouldHeadsUp_suppressedHeadsUp() throws Exception { |
Beverly | 38159ce | 2017-07-13 16:39:24 -0400 | [diff] [blame] | 451 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 452 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 453 | when(mNotificationFilter.shouldFilterOut(any())).thenReturn(false); |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 454 | when(mDreamManager.isDreaming()).thenReturn(false); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 455 | when(mHeadsUpSuppressor.canHeadsUp(any(), any())).thenReturn(true); |
Julia Reynolds | 24653c3 | 2018-03-02 13:16:37 -0500 | [diff] [blame] | 456 | |
| 457 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 458 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 459 | UserHandle.of(0), null, 0); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 460 | NotificationEntry entry = new NotificationEntry(sbn); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 461 | entry.suppressedVisualEffects = SUPPRESSED_EFFECT_PEEK; |
| 462 | entry.importance = IMPORTANCE_HIGH; |
Julia Reynolds | 24653c3 | 2018-03-02 13:16:37 -0500 | [diff] [blame] | 463 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 464 | assertFalse(mNotificationInterruptionStateProvider.shouldHeadsUp(entry)); |
Julia Reynolds | 24653c3 | 2018-03-02 13:16:37 -0500 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | @Test |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 468 | public void testShouldHeadsUp_noSuppressedHeadsUp() throws Exception { |
Julia Reynolds | 24653c3 | 2018-03-02 13:16:37 -0500 | [diff] [blame] | 469 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 470 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 471 | when(mNotificationFilter.shouldFilterOut(any())).thenReturn(false); |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 472 | when(mDreamManager.isDreaming()).thenReturn(false); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 473 | when(mHeadsUpSuppressor.canHeadsUp(any(), any())).thenReturn(true); |
Beverly | 38159ce | 2017-07-13 16:39:24 -0400 | [diff] [blame] | 474 | |
| 475 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 476 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 477 | UserHandle.of(0), null, 0); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 478 | NotificationEntry entry = new NotificationEntry(sbn); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 479 | entry.importance = IMPORTANCE_HIGH; |
Beverly | 38159ce | 2017-07-13 16:39:24 -0400 | [diff] [blame] | 480 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 481 | assertTrue(mNotificationInterruptionStateProvider.shouldHeadsUp(entry)); |
Beverly | 38159ce | 2017-07-13 16:39:24 -0400 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | @Test |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 485 | public void testLogHidden() { |
| 486 | try { |
| 487 | mStatusBar.handleVisibleToUserChanged(false); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 488 | waitForUiOffloadThread(); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 489 | verify(mBarService, times(1)).onPanelHidden(); |
| 490 | verify(mBarService, never()).onPanelRevealed(anyBoolean(), anyInt()); |
| 491 | } catch (RemoteException e) { |
| 492 | fail(); |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | @Test |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 497 | public void testPanelOpenForHeadsUp() { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 498 | when(mDeviceProvisionedController.isDeviceProvisioned()).thenReturn(true); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 499 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); |
| 500 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 501 | when(mNotificationList.size()).thenReturn(5); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 502 | when(mNotificationPresenter.isPresenterFullyCollapsed()).thenReturn(true); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 503 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 504 | |
| 505 | try { |
| 506 | mStatusBar.handleVisibleToUserChanged(true); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 507 | waitForUiOffloadThread(); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 508 | verify(mBarService, never()).onPanelHidden(); |
| 509 | verify(mBarService, times(1)).onPanelRevealed(false, 1); |
| 510 | } catch (RemoteException e) { |
| 511 | fail(); |
| 512 | } |
| 513 | TestableLooper.get(this).processAllMessages(); |
| 514 | } |
| 515 | |
| 516 | @Test |
| 517 | public void testPanelOpenAndClear() { |
| 518 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 519 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 520 | when(mNotificationList.size()).thenReturn(5); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 521 | when(mNotificationPresenter.isPresenterFullyCollapsed()).thenReturn(false); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 522 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 523 | |
| 524 | try { |
| 525 | mStatusBar.handleVisibleToUserChanged(true); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 526 | waitForUiOffloadThread(); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 527 | verify(mBarService, never()).onPanelHidden(); |
| 528 | verify(mBarService, times(1)).onPanelRevealed(true, 5); |
| 529 | } catch (RemoteException e) { |
| 530 | fail(); |
| 531 | } |
| 532 | TestableLooper.get(this).processAllMessages(); |
| 533 | } |
| 534 | |
| 535 | @Test |
| 536 | public void testPanelOpenAndNoClear() { |
| 537 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 538 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 539 | when(mNotificationList.size()).thenReturn(5); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 540 | when(mNotificationPresenter.isPresenterFullyCollapsed()).thenReturn(false); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 541 | mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD); |
| 542 | |
| 543 | try { |
| 544 | mStatusBar.handleVisibleToUserChanged(true); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 545 | waitForUiOffloadThread(); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 546 | verify(mBarService, never()).onPanelHidden(); |
| 547 | verify(mBarService, times(1)).onPanelRevealed(false, 5); |
| 548 | } catch (RemoteException e) { |
| 549 | fail(); |
| 550 | } |
| 551 | TestableLooper.get(this).processAllMessages(); |
| 552 | } |
| 553 | |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 554 | @Test |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 555 | public void testDisableExpandStatusBar() { |
| 556 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 557 | mStatusBar.setUserSetupForTest(true); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 558 | when(mDeviceProvisionedController.isDeviceProvisioned()).thenReturn(true); |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 559 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 560 | when(mCommandQueue.panelsEnabled()).thenReturn(false); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 561 | mStatusBar.disable(DEFAULT_DISPLAY, StatusBarManager.DISABLE_NONE, |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 562 | StatusBarManager.DISABLE2_NOTIFICATION_SHADE, false); |
| 563 | verify(mNotificationPanelView).setQsExpansionEnabled(false); |
| 564 | mStatusBar.animateExpandNotificationsPanel(); |
| 565 | verify(mNotificationPanelView, never()).expand(anyBoolean()); |
| 566 | mStatusBar.animateExpandSettingsPanel(null); |
| 567 | verify(mNotificationPanelView, never()).expand(anyBoolean()); |
| 568 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 569 | when(mCommandQueue.panelsEnabled()).thenReturn(true); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 570 | mStatusBar.disable(DEFAULT_DISPLAY, StatusBarManager.DISABLE_NONE, |
| 571 | StatusBarManager.DISABLE2_NONE, false); |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 572 | verify(mNotificationPanelView).setQsExpansionEnabled(true); |
| 573 | mStatusBar.animateExpandNotificationsPanel(); |
Eugene Susla | 2de6955 | 2018-03-20 13:22:17 -0700 | [diff] [blame] | 574 | verify(mNotificationPanelView).expandWithoutQs(); |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 575 | mStatusBar.animateExpandSettingsPanel(null); |
Eugene Susla | 2de6955 | 2018-03-20 13:22:17 -0700 | [diff] [blame] | 576 | verify(mNotificationPanelView).expandWithQs(); |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | @Test |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 580 | public void testDump_DoesNotCrash() { |
| 581 | mStatusBar.dump(null, new PrintWriter(new ByteArrayOutputStream()), null); |
| 582 | } |
| 583 | |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 584 | @Test |
| 585 | @RunWithLooper(setAsMainLooper = true) |
| 586 | public void testUpdateKeyguardState_DoesNotCrash() { |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 587 | mStatusBar.mState = StatusBarState.KEYGUARD; |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 588 | when(mStatusBar.mLockscreenUserManager.getCurrentProfiles()).thenReturn( |
| 589 | new SparseArray<>()); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 590 | mStatusBar.onStateChanged(StatusBarState.SHADE); |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 591 | } |
| 592 | |
Lucas Dupin | c2e7546 | 2017-12-06 13:59:25 -0800 | [diff] [blame] | 593 | @Test |
| 594 | public void testFingerprintNotification_UpdatesScrims() { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 595 | mStatusBar.notifyBiometricAuthModeChanged(); |
Lucas Dupin | c2e7546 | 2017-12-06 13:59:25 -0800 | [diff] [blame] | 596 | verify(mScrimController).transitionTo(any(), any()); |
| 597 | } |
| 598 | |
Lucas Dupin | 311eac8 | 2017-12-11 14:40:07 -0800 | [diff] [blame] | 599 | @Test |
| 600 | public void testFingerprintUnlock_UpdatesScrims() { |
| 601 | // Simulate unlocking from AoD with fingerprint. |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 602 | when(mBiometricUnlockController.getMode()) |
| 603 | .thenReturn(BiometricUnlockController.MODE_WAKE_AND_UNLOCK); |
Lucas Dupin | 311eac8 | 2017-12-11 14:40:07 -0800 | [diff] [blame] | 604 | mStatusBar.updateScrimController(); |
| 605 | verify(mScrimController).transitionTo(eq(ScrimState.UNLOCKED), any()); |
| 606 | } |
| 607 | |
Lucas Dupin | d510730 | 2018-03-19 15:30:29 -0700 | [diff] [blame] | 608 | @Test |
| 609 | public void testSetOccluded_propagatesToScrimController() { |
| 610 | mStatusBar.setOccluded(true); |
| 611 | verify(mScrimController).setKeyguardOccluded(eq(true)); |
| 612 | |
| 613 | reset(mScrimController); |
| 614 | mStatusBar.setOccluded(false); |
| 615 | verify(mScrimController).setKeyguardOccluded(eq(false)); |
| 616 | } |
| 617 | |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 618 | @Test |
Lucas Dupin | 988efb2 | 2018-12-04 16:53:58 -0800 | [diff] [blame] | 619 | public void testPulseWhileDozing_updatesScrimController() { |
| 620 | mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD); |
| 621 | mStatusBar.showKeyguardImpl(); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 622 | |
Lucas Dupin | 988efb2 | 2018-12-04 16:53:58 -0800 | [diff] [blame] | 623 | // Keep track of callback to be able to stop the pulse |
| 624 | DozeHost.PulseCallback[] pulseCallback = new DozeHost.PulseCallback[1]; |
| 625 | doAnswer(invocation -> { |
| 626 | pulseCallback[0] = invocation.getArgument(0); |
| 627 | return null; |
| 628 | }).when(mDozeScrimController).pulse(any(), anyInt()); |
| 629 | |
| 630 | // Starting a pulse should change the scrim controller to the pulsing state |
| 631 | mStatusBar.mDozeServiceHost.pulseWhileDozing(mock(DozeHost.PulseCallback.class), |
| 632 | DozeLog.PULSE_REASON_NOTIFICATION); |
| 633 | verify(mScrimController).transitionTo(eq(ScrimState.PULSING), any()); |
| 634 | |
| 635 | // Ending a pulse should take it back to keyguard state |
| 636 | pulseCallback[0].onPulseFinished(); |
| 637 | verify(mScrimController).transitionTo(eq(ScrimState.KEYGUARD)); |
| 638 | } |
| 639 | |
| 640 | @Test |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 641 | public void testPulseWhileDozing_notifyAuthInterrupt() { |
| 642 | HashSet<Integer> reasonsWantingAuth = new HashSet<>( |
| 643 | Collections.singletonList(DozeLog.PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN)); |
| 644 | HashSet<Integer> reasonsSkippingAuth = new HashSet<>( |
| 645 | Arrays.asList(DozeLog.PULSE_REASON_INTENT, |
| 646 | DozeLog.PULSE_REASON_NOTIFICATION, |
| 647 | DozeLog.PULSE_REASON_SENSOR_SIGMOTION, |
| 648 | DozeLog.REASON_SENSOR_PICKUP, |
| 649 | DozeLog.REASON_SENSOR_DOUBLE_TAP, |
| 650 | DozeLog.PULSE_REASON_SENSOR_LONG_PRESS, |
| 651 | DozeLog.PULSE_REASON_DOCKING, |
| 652 | DozeLog.REASON_SENSOR_WAKE_UP, |
| 653 | DozeLog.REASON_SENSOR_TAP)); |
| 654 | HashSet<Integer> reasonsThatDontPulse = new HashSet<>( |
| 655 | Arrays.asList(DozeLog.REASON_SENSOR_PICKUP, |
| 656 | DozeLog.REASON_SENSOR_DOUBLE_TAP, |
| 657 | DozeLog.REASON_SENSOR_TAP)); |
| 658 | |
Lucas Dupin | e0516d5 | 2019-02-05 17:54:06 -0500 | [diff] [blame] | 659 | doAnswer(invocation -> { |
| 660 | DozeHost.PulseCallback callback = invocation.getArgument(0); |
| 661 | callback.onPulseStarted(); |
| 662 | return null; |
| 663 | }).when(mDozeScrimController).pulse(any(), anyInt()); |
| 664 | |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 665 | for (int i = 0; i < DozeLog.REASONS; i++) { |
| 666 | reset(mKeyguardUpdateMonitor); |
| 667 | mStatusBar.mDozeServiceHost.pulseWhileDozing(mock(DozeHost.PulseCallback.class), i); |
| 668 | if (reasonsWantingAuth.contains(i)) { |
Lucas Dupin | e0516d5 | 2019-02-05 17:54:06 -0500 | [diff] [blame] | 669 | verify(mKeyguardUpdateMonitor).onAuthInterruptDetected(eq(true)); |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 670 | } else if (reasonsSkippingAuth.contains(i) || reasonsThatDontPulse.contains(i)) { |
Lucas Dupin | e0516d5 | 2019-02-05 17:54:06 -0500 | [diff] [blame] | 671 | verify(mKeyguardUpdateMonitor, never()).onAuthInterruptDetected(eq(true)); |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 672 | } else { |
| 673 | throw new AssertionError("Reason " + i + " isn't specified as wanting or skipping" |
| 674 | + " passive auth. Please consider how this pulse reason should behave."); |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | @Test |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 680 | public void testSetState_changesIsFullScreenUserSwitcherState() { |
| 681 | mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD); |
| 682 | assertFalse(mStatusBar.isFullScreenUserSwitcherState()); |
| 683 | |
| 684 | mStatusBar.setBarStateForTest(StatusBarState.FULLSCREEN_USER_SWITCHER); |
| 685 | assertTrue(mStatusBar.isFullScreenUserSwitcherState()); |
| 686 | } |
| 687 | |
| 688 | @Test |
| 689 | public void testShowKeyguardImplementation_setsState() { |
| 690 | when(mLockscreenUserManager.getCurrentProfiles()).thenReturn(new SparseArray<>()); |
| 691 | |
| 692 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 693 | |
| 694 | // By default, showKeyguardImpl sets state to KEYGUARD. |
| 695 | mStatusBar.showKeyguardImpl(); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 696 | verify(mStatusBarStateController).setState(eq(StatusBarState.KEYGUARD)); |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 697 | |
| 698 | // If useFullscreenUserSwitcher is true, state is set to FULLSCREEN_USER_SWITCHER. |
| 699 | mStatusBar.mUserSwitcherController = mock(UserSwitcherController.class); |
| 700 | when(mStatusBar.mUserSwitcherController.useFullscreenUserSwitcher()).thenReturn(true); |
| 701 | mStatusBar.showKeyguardImpl(); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 702 | verify(mStatusBarStateController).setState(eq(StatusBarState.FULLSCREEN_USER_SWITCHER)); |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Lucas Dupin | 29a07ec | 2018-11-13 16:56:49 -0800 | [diff] [blame] | 705 | @Test |
| 706 | public void testStartStopDozing() { |
| 707 | mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD); |
| 708 | when(mStatusBarStateController.isKeyguardRequested()).thenReturn(true); |
| 709 | |
| 710 | mStatusBar.mDozeServiceHost.startDozing(); |
| 711 | verify(mStatusBarStateController).setIsDozing(eq(true)); |
| 712 | |
| 713 | mStatusBar.mDozeServiceHost.stopDozing(); |
| 714 | verify(mStatusBarStateController).setIsDozing(eq(false)); |
| 715 | } |
| 716 | |
| 717 | @Test |
| 718 | public void testOnStartedWakingUp_isNotDozing() { |
| 719 | mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD); |
| 720 | when(mStatusBarStateController.isKeyguardRequested()).thenReturn(true); |
| 721 | |
| 722 | mStatusBar.mDozeServiceHost.startDozing(); |
| 723 | verify(mStatusBarStateController).setIsDozing(eq(true)); |
| 724 | |
| 725 | mStatusBar.mWakefulnessObserver.onStartedWakingUp(); |
| 726 | verify(mStatusBarStateController).setIsDozing(eq(false)); |
| 727 | } |
| 728 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 729 | static class TestableStatusBar extends StatusBar { |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 730 | public TestableStatusBar(StatusBarKeyguardViewManager man, |
| 731 | UnlockMethodCache unlock, KeyguardIndicationController key, |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 732 | NotificationStackScrollLayout stack, HeadsUpManagerPhone hum, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 733 | PowerManager pm, NotificationPanelView panelView, |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 734 | IStatusBarService barService, NotificationListener notificationListener, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 735 | NotificationLogger notificationLogger, |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 736 | VisualStabilityManager visualStabilityManager, |
| 737 | NotificationViewHierarchyManager viewHierarchyManager, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 738 | TestableNotificationEntryManager entryManager, ScrimController scrimController, |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 739 | BiometricUnlockController biometricUnlockController, |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 740 | KeyguardViewMediator keyguardViewMediator, |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 741 | NotificationRemoteInputManager notificationRemoteInputManager, |
| 742 | NotificationGroupManager notificationGroupManager, |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 743 | NotificationGroupAlertTransferHelper notificationGroupAlertTransferHelper, |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 744 | FalsingManager falsingManager, |
Lucas Dupin | 1a8588d | 2018-08-21 12:18:47 -0700 | [diff] [blame] | 745 | StatusBarWindowController statusBarWindowController, |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 746 | NotificationIconAreaController notificationIconAreaController, |
| 747 | DozeScrimController dozeScrimController, |
| 748 | NotificationShelf notificationShelf, |
| 749 | NotificationLockscreenUserManager notificationLockscreenUserManager, |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 750 | CommandQueue commandQueue, |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 751 | NotificationPresenter notificationPresenter, |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 752 | BubbleController bubbleController, |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 753 | NavigationBarController navBarController, |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 754 | AutoHideController autoHideController, |
| 755 | KeyguardUpdateMonitor keyguardUpdateMonitor) { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 756 | mStatusBarKeyguardViewManager = man; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 757 | mUnlockMethodCache = unlock; |
| 758 | mKeyguardIndicationController = key; |
| 759 | mStackScroller = stack; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 760 | mHeadsUpManager = hum; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 761 | mPowerManager = pm; |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 762 | mNotificationPanel = panelView; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 763 | mBarService = barService; |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 764 | mNotificationListener = notificationListener; |
| 765 | mNotificationLogger = notificationLogger; |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 766 | mWakefulnessLifecycle = createAwakeWakefulnessLifecycle(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 767 | mVisualStabilityManager = visualStabilityManager; |
| 768 | mViewHierarchyManager = viewHierarchyManager; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 769 | mEntryManager = entryManager; |
Lucas Dupin | c2e7546 | 2017-12-06 13:59:25 -0800 | [diff] [blame] | 770 | mScrimController = scrimController; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 771 | mBiometricUnlockController = biometricUnlockController; |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 772 | mKeyguardViewMediator = keyguardViewMediator; |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 773 | mRemoteInputManager = notificationRemoteInputManager; |
| 774 | mGroupManager = notificationGroupManager; |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 775 | mGroupAlertTransferHelper = notificationGroupAlertTransferHelper; |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 776 | mFalsingManager = falsingManager; |
Lucas Dupin | 1a8588d | 2018-08-21 12:18:47 -0700 | [diff] [blame] | 777 | mStatusBarWindowController = statusBarWindowController; |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 778 | mNotificationIconAreaController = notificationIconAreaController; |
| 779 | mDozeScrimController = dozeScrimController; |
| 780 | mNotificationShelf = notificationShelf; |
| 781 | mLockscreenUserManager = notificationLockscreenUserManager; |
| 782 | mCommandQueue = commandQueue; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 783 | mPresenter = notificationPresenter; |
Lucas Dupin | 29a07ec | 2018-11-13 16:56:49 -0800 | [diff] [blame] | 784 | mGestureWakeLock = mock(PowerManager.WakeLock.class); |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 785 | mBubbleController = bubbleController; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 786 | mNavigationBarController = navBarController; |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 787 | mAutoHideController = autoHideController; |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 788 | mKeyguardUpdateMonitor = keyguardUpdateMonitor; |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | private WakefulnessLifecycle createAwakeWakefulnessLifecycle() { |
| 792 | WakefulnessLifecycle wakefulnessLifecycle = new WakefulnessLifecycle(); |
| 793 | wakefulnessLifecycle.dispatchStartedWakingUp(); |
| 794 | wakefulnessLifecycle.dispatchFinishedWakingUp(); |
| 795 | return wakefulnessLifecycle; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 796 | } |
| 797 | |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 798 | @Override |
| 799 | protected void updateTheme() { |
| 800 | // Do nothing for now, until we have more mocking and StatusBar is smaller. |
| 801 | } |
| 802 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 803 | public void setBarStateForTest(int state) { |
| 804 | mState = state; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 805 | } |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 806 | |
| 807 | public void setUserSetupForTest(boolean userSetup) { |
| 808 | mUserSetup = userSetup; |
| 809 | } |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 810 | |
| 811 | } |
| 812 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 813 | public static class TestableNotificationEntryManager extends NotificationEntryManager { |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 814 | |
Gus Prevas | 9258646 | 2019-01-04 16:06:12 -0500 | [diff] [blame] | 815 | public TestableNotificationEntryManager(Context context) { |
Eliot Courtney | 6c313d3 | 2017-12-14 19:57:51 +0900 | [diff] [blame] | 816 | super(context); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | public void setUpForTest(NotificationPresenter presenter, |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 820 | NotificationListContainer listContainer, |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 821 | HeadsUpManagerPhone headsUpManager, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 822 | NotificationData notificationData) { |
Gus Prevas | 8621bd2 | 2018-12-20 15:04:25 -0500 | [diff] [blame] | 823 | super.setUpWithPresenter(presenter, listContainer, headsUpManager); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 824 | mNotificationData = notificationData; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 825 | } |
| 826 | } |
| 827 | |
| 828 | public static class TestableNotificationInterruptionStateProvider extends |
| 829 | NotificationInterruptionStateProvider { |
| 830 | |
| 831 | public TestableNotificationInterruptionStateProvider( |
| 832 | Context context, |
| 833 | PowerManager powerManager, |
| 834 | IDreamManager dreamManager) { |
| 835 | super(context, powerManager, dreamManager); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 836 | mUseHeadsUp = true; |
| 837 | } |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 838 | } |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 839 | } |