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