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