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; |
| 20 | |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 21 | import static junit.framework.Assert.assertEquals; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 22 | import static junit.framework.Assert.assertFalse; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 23 | import static junit.framework.Assert.assertNotNull; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 24 | import static junit.framework.Assert.assertTrue; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 25 | import static junit.framework.TestCase.fail; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 26 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 27 | import static org.mockito.ArgumentMatchers.any; |
| 28 | import static org.mockito.ArgumentMatchers.anyBoolean; |
| 29 | import static org.mockito.ArgumentMatchers.anyInt; |
| 30 | import static org.mockito.ArgumentMatchers.anyString; |
Lucas Dupin | 311eac8 | 2017-12-11 14:40:07 -0800 | [diff] [blame] | 31 | import static org.mockito.ArgumentMatchers.eq; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 32 | import static org.mockito.Mockito.doAnswer; |
| 33 | import static org.mockito.Mockito.mock; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 34 | import static org.mockito.Mockito.never; |
Lucas Dupin | d510730 | 2018-03-19 15:30:29 -0700 | [diff] [blame] | 35 | import static org.mockito.Mockito.reset; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 36 | import static org.mockito.Mockito.times; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 37 | import static org.mockito.Mockito.verify; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 38 | import static org.mockito.Mockito.when; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 39 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 40 | import android.app.Notification; |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 41 | import android.app.StatusBarManager; |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 42 | import android.app.trust.TrustManager; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 43 | import android.content.Context; |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 44 | import android.content.pm.UserInfo; |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 45 | import android.hardware.fingerprint.FingerprintManager; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 46 | import android.metrics.LogMaker; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 47 | import android.os.Binder; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 48 | import android.os.Handler; |
| 49 | import android.os.HandlerThread; |
| 50 | import android.os.IPowerManager; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 51 | import android.os.PowerManager; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 52 | import android.os.RemoteException; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 53 | import android.os.UserHandle; |
| 54 | import android.service.notification.StatusBarNotification; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 55 | import android.support.test.filters.SmallTest; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 56 | import android.support.test.metricshelper.MetricsAsserts; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 57 | import android.testing.AndroidTestingRunner; |
| 58 | import android.testing.TestableLooper; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 59 | import android.testing.TestableLooper.RunWithLooper; |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 60 | import android.util.SparseArray; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 61 | import android.view.Gravity; |
| 62 | import android.view.View; |
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 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 65 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 66 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 67 | import com.android.internal.logging.testing.FakeMetricsLogger; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 68 | import com.android.internal.statusbar.IStatusBarService; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 69 | import com.android.keyguard.KeyguardHostView.OnDismissAction; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 70 | import com.android.systemui.ForegroundServiceController; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 71 | import com.android.systemui.R; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 72 | import com.android.systemui.SysuiTestCase; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 73 | import com.android.systemui.assist.AssistManager; |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 74 | import com.android.systemui.keyguard.KeyguardViewMediator; |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 75 | import com.android.systemui.classifier.FalsingManager; |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 76 | import com.android.systemui.keyguard.WakefulnessLifecycle; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 77 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 78 | import com.android.systemui.statusbar.ActivatableNotificationView; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 79 | import com.android.systemui.statusbar.AppOpsListener; |
Jason Monk | 5ecf80c | 2017-07-06 15:28:17 -0400 | [diff] [blame] | 80 | import com.android.systemui.statusbar.CommandQueue; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 81 | import com.android.systemui.statusbar.ExpandableNotificationRow; |
| 82 | import com.android.systemui.statusbar.FooterView; |
| 83 | import com.android.systemui.statusbar.FooterViewButton; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 84 | import com.android.systemui.statusbar.KeyguardIndicationController; |
| 85 | import com.android.systemui.statusbar.NotificationData; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 86 | import com.android.systemui.statusbar.NotificationData.Entry; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 87 | import com.android.systemui.statusbar.NotificationEntryManager; |
| 88 | import com.android.systemui.statusbar.NotificationGutsManager; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 89 | import com.android.systemui.statusbar.NotificationListContainer; |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 90 | import com.android.systemui.statusbar.NotificationListener; |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 91 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 92 | import com.android.systemui.statusbar.NotificationLogger; |
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; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 99 | import com.android.systemui.statusbar.StatusBarState; |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 100 | import com.android.systemui.statusbar.notification.ActivityLaunchAnimator; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 101 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 102 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 103 | import com.android.systemui.statusbar.policy.KeyguardMonitor; |
| 104 | import com.android.systemui.statusbar.policy.KeyguardMonitorImpl; |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 105 | import com.android.systemui.statusbar.policy.UserSwitcherController; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 106 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 107 | |
| 108 | import org.junit.Before; |
| 109 | import org.junit.Test; |
| 110 | import org.junit.runner.RunWith; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 111 | import org.mockito.ArgumentCaptor; |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 112 | import org.mockito.Mock; |
| 113 | import org.mockito.MockitoAnnotations; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 114 | |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 115 | import java.io.ByteArrayOutputStream; |
| 116 | import java.io.PrintWriter; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 117 | import java.util.ArrayList; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 118 | import java.util.function.Predicate; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 119 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 120 | @SmallTest |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 121 | @RunWith(AndroidTestingRunner.class) |
| 122 | @RunWithLooper |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 123 | public class StatusBarTest extends SysuiTestCase { |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 124 | @Mock private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
| 125 | @Mock private UnlockMethodCache mUnlockMethodCache; |
| 126 | @Mock private KeyguardIndicationController mKeyguardIndicationController; |
| 127 | @Mock private NotificationStackScrollLayout mStackScroller; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 128 | @Mock private HeadsUpManagerPhone mHeadsUpManager; |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 129 | @Mock private SystemServicesProxy mSystemServicesProxy; |
| 130 | @Mock private NotificationPanelView mNotificationPanelView; |
| 131 | @Mock private IStatusBarService mBarService; |
| 132 | @Mock private ScrimController mScrimController; |
| 133 | @Mock private ArrayList<Entry> mNotificationList; |
| 134 | @Mock private FingerprintUnlockController mFingerprintUnlockController; |
| 135 | @Mock private NotificationData mNotificationData; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 136 | |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 137 | // Mock dependencies: |
| 138 | @Mock private NotificationViewHierarchyManager mViewHierarchyManager; |
| 139 | @Mock private VisualStabilityManager mVisualStabilityManager; |
| 140 | @Mock private NotificationListener mNotificationListener; |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 141 | @Mock private KeyguardViewMediator mKeyguardViewMediator; |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 142 | @Mock private NotificationLockscreenUserManager mLockscreenUserManager; |
Selim Cinek | 7c6fe5b | 2018-04-09 18:27:13 -0700 | [diff] [blame] | 143 | @Mock private NotificationRemoteInputManager mRemoteInputManager; |
| 144 | @Mock private RemoteInputController mRemoteInputController; |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 145 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 146 | private TestableStatusBar mStatusBar; |
| 147 | private FakeMetricsLogger mMetricsLogger; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 148 | private PowerManager mPowerManager; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 149 | private TestableNotificationEntryManager mEntryManager; |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 150 | private NotificationLogger mNotificationLogger; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 151 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 152 | @Before |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 153 | public void setup() throws Exception { |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 154 | MockitoAnnotations.initMocks(this); |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 155 | mDependency.injectMockDependency(AssistManager.class); |
| 156 | mDependency.injectMockDependency(DeviceProvisionedController.class); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 157 | mDependency.injectMockDependency(NotificationGutsManager.class); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 158 | mDependency.injectMockDependency(NotificationMediaManager.class); |
| 159 | mDependency.injectMockDependency(ForegroundServiceController.class); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 160 | mDependency.injectTestDependency(NotificationViewHierarchyManager.class, |
| 161 | mViewHierarchyManager); |
| 162 | mDependency.injectTestDependency(VisualStabilityManager.class, mVisualStabilityManager); |
| 163 | mDependency.injectTestDependency(NotificationListener.class, mNotificationListener); |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 164 | mDependency.injectTestDependency(KeyguardMonitor.class, mock(KeyguardMonitorImpl.class)); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 165 | mDependency.injectTestDependency(AppOpsListener.class, mock(AppOpsListener.class)); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 166 | |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 167 | mContext.addMockSystemService(TrustManager.class, mock(TrustManager.class)); |
| 168 | mContext.addMockSystemService(FingerprintManager.class, mock(FingerprintManager.class)); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 169 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 170 | mMetricsLogger = new FakeMetricsLogger(); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 171 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 172 | mDependency.injectTestDependency(NotificationLogger.class, mNotificationLogger); |
Eugene Susla | 2de6955 | 2018-03-20 13:22:17 -0700 | [diff] [blame] | 173 | mNotificationLogger = new NotificationLogger(); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 174 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 175 | IPowerManager powerManagerService = mock(IPowerManager.class); |
| 176 | HandlerThread handlerThread = new HandlerThread("TestThread"); |
| 177 | handlerThread.start(); |
| 178 | mPowerManager = new PowerManager(mContext, powerManagerService, |
| 179 | new Handler(handlerThread.getLooper())); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 180 | |
| 181 | CommandQueue commandQueue = mock(CommandQueue.class); |
| 182 | when(commandQueue.asBinder()).thenReturn(new Binder()); |
| 183 | mContext.putComponent(CommandQueue.class, commandQueue); |
| 184 | |
| 185 | mContext.setTheme(R.style.Theme_SystemUI_Light); |
| 186 | |
| 187 | when(mStackScroller.generateLayoutParams(any())).thenReturn(new LayoutParams(0, 0)); |
| 188 | when(mNotificationPanelView.getLayoutParams()).thenReturn(new LayoutParams(0, 0)); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 189 | when(powerManagerService.isInteractive()).thenReturn(true); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 190 | when(mStackScroller.getActivatedChild()).thenReturn(null); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 191 | |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 192 | doAnswer(invocation -> { |
| 193 | OnDismissAction onDismissAction = (OnDismissAction) invocation.getArguments()[0]; |
| 194 | onDismissAction.onDismiss(); |
| 195 | return null; |
| 196 | }).when(mStatusBarKeyguardViewManager).dismissWithAction(any(), any(), anyBoolean()); |
| 197 | |
| 198 | doAnswer(invocation -> { |
| 199 | Runnable runnable = (Runnable) invocation.getArguments()[0]; |
| 200 | runnable.run(); |
| 201 | return null; |
| 202 | }).when(mStatusBarKeyguardViewManager).addAfterKeyguardGoneRunnable(any()); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 203 | |
Eliot Courtney | 6c313d3 | 2017-12-14 19:57:51 +0900 | [diff] [blame] | 204 | mEntryManager = new TestableNotificationEntryManager(mSystemServicesProxy, mPowerManager, |
| 205 | mContext); |
Selim Cinek | 7c6fe5b | 2018-04-09 18:27:13 -0700 | [diff] [blame] | 206 | when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 207 | mStatusBar = new TestableStatusBar(mStatusBarKeyguardViewManager, mUnlockMethodCache, |
| 208 | mKeyguardIndicationController, mStackScroller, mHeadsUpManager, |
| 209 | mPowerManager, mNotificationPanelView, mBarService, mNotificationListener, |
| 210 | mNotificationLogger, mVisualStabilityManager, mViewHierarchyManager, |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 211 | mEntryManager, mScrimController, mFingerprintUnlockController, |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 212 | mock(ActivityLaunchAnimator.class), mKeyguardViewMediator, |
Selim Cinek | 7c6fe5b | 2018-04-09 18:27:13 -0700 | [diff] [blame] | 213 | mRemoteInputManager, mock(NotificationGroupManager.class), |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 214 | mock(FalsingManager.class), mock(StatusBarWindowManager.class), |
| 215 | mock(NotificationIconAreaController.class), mock(DozeScrimController.class), |
| 216 | mock(NotificationShelf.class), mLockscreenUserManager, |
| 217 | mock(CommandQueue.class)); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 218 | mStatusBar.mContext = mContext; |
| 219 | mStatusBar.mComponents = mContext.getComponents(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 220 | mEntryManager.setUpForTest(mStatusBar, mStackScroller, mStatusBar, mHeadsUpManager, |
| 221 | mNotificationData); |
Eliot Courtney | 4a96b36 | 2017-12-14 19:38:52 +0900 | [diff] [blame] | 222 | mNotificationLogger.setUpWithEntryManager(mEntryManager, mStackScroller); |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 223 | |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 224 | TestableLooper.get(this).setMessageHandler(m -> { |
| 225 | if (m.getCallback() == mStatusBar.mNotificationLogger.getVisibilityReporter()) { |
| 226 | return false; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 227 | } |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 228 | return true; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 229 | }); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 230 | } |
| 231 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 232 | @Test |
Jason Monk | 5ecf80c | 2017-07-06 15:28:17 -0400 | [diff] [blame] | 233 | public void testSetBouncerShowing_noCrash() { |
| 234 | mStatusBar.mCommandQueue = mock(CommandQueue.class); |
| 235 | mStatusBar.setBouncerShowing(true); |
| 236 | } |
| 237 | |
| 238 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 239 | public void executeRunnableDismissingKeyguard_nullRunnable_showingAndOccluded() { |
| 240 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 241 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(true); |
| 242 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 243 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 246 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 247 | public void executeRunnableDismissingKeyguard_nullRunnable_showing() { |
| 248 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 249 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 250 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 251 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 252 | } |
| 253 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 254 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 255 | public void executeRunnableDismissingKeyguard_nullRunnable_notShowing() { |
| 256 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 257 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 258 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 259 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 260 | } |
| 261 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 262 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 263 | public void lockscreenStateMetrics_notShowing() { |
| 264 | // uninteresting state, except that fingerprint must be non-zero |
| 265 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 266 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 267 | // interesting state |
| 268 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 269 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 270 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(false); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 271 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 272 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 273 | MetricsAsserts.assertHasLog("missing hidden insecure lockscreen log", |
| 274 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 275 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 276 | .setType(MetricsEvent.TYPE_CLOSE) |
| 277 | .setSubtype(0)); |
| 278 | } |
| 279 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 280 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 281 | public void lockscreenStateMetrics_notShowing_secure() { |
| 282 | // uninteresting state, except that fingerprint must be non-zero |
| 283 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 284 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 285 | // interesting state |
| 286 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 287 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 288 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 289 | |
| 290 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 291 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 292 | MetricsAsserts.assertHasLog("missing hidden secure lockscreen log", |
| 293 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 294 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 295 | .setType(MetricsEvent.TYPE_CLOSE) |
| 296 | .setSubtype(1)); |
| 297 | } |
| 298 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 299 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 300 | public void lockscreenStateMetrics_isShowing() { |
| 301 | // uninteresting state, except that fingerprint must be non-zero |
| 302 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 303 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 304 | // interesting state |
| 305 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 306 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 307 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(false); |
| 308 | |
| 309 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 310 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 311 | MetricsAsserts.assertHasLog("missing insecure lockscreen showing", |
| 312 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 313 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 314 | .setType(MetricsEvent.TYPE_OPEN) |
| 315 | .setSubtype(0)); |
| 316 | } |
| 317 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 318 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 319 | public void lockscreenStateMetrics_isShowing_secure() { |
| 320 | // uninteresting state, except that fingerprint must be non-zero |
| 321 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 322 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 323 | // interesting state |
| 324 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 325 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 326 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 327 | |
| 328 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 329 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 330 | MetricsAsserts.assertHasLog("missing secure lockscreen showing log", |
| 331 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 332 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 333 | .setType(MetricsEvent.TYPE_OPEN) |
| 334 | .setSubtype(1)); |
| 335 | } |
| 336 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 337 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 338 | public void lockscreenStateMetrics_isShowingBouncer() { |
| 339 | // uninteresting state, except that fingerprint must be non-zero |
| 340 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 341 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 342 | // interesting state |
| 343 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 344 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); |
| 345 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 346 | |
| 347 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 348 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 349 | MetricsAsserts.assertHasLog("missing bouncer log", |
| 350 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 351 | new LogMaker(MetricsEvent.BOUNCER) |
| 352 | .setType(MetricsEvent.TYPE_OPEN) |
| 353 | .setSubtype(1)); |
| 354 | } |
| 355 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 356 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 357 | public void onActivatedMetrics() { |
| 358 | ActivatableNotificationView view = mock(ActivatableNotificationView.class); |
| 359 | mStatusBar.onActivated(view); |
| 360 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 361 | MetricsAsserts.assertHasLog("missing lockscreen note tap log", |
| 362 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 363 | new LogMaker(MetricsEvent.ACTION_LS_NOTE) |
| 364 | .setType(MetricsEvent.TYPE_ACTION)); |
| 365 | } |
| 366 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 367 | @Test |
| 368 | public void testShouldPeek_nonSuppressedGroupSummary() { |
| 369 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 370 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
Julia Reynolds | 24653c3 | 2018-03-02 13:16:37 -0500 | [diff] [blame] | 371 | when(mNotificationData.shouldSuppressStatusBar(any())).thenReturn(false); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 372 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 373 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 374 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 375 | |
| 376 | Notification n = new Notification.Builder(getContext(), "a") |
| 377 | .setGroup("a") |
| 378 | .setGroupSummary(true) |
| 379 | .setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY) |
| 380 | .build(); |
| 381 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 382 | UserHandle.of(0), null, 0); |
| 383 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 384 | |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 385 | assertTrue(mEntryManager.shouldPeek(entry, sbn)); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | @Test |
| 389 | public void testShouldPeek_suppressedGroupSummary() { |
| 390 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 391 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
Julia Reynolds | 24653c3 | 2018-03-02 13:16:37 -0500 | [diff] [blame] | 392 | when(mNotificationData.shouldSuppressStatusBar(any())).thenReturn(false); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 393 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 394 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 395 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 396 | |
| 397 | Notification n = new Notification.Builder(getContext(), "a") |
| 398 | .setGroup("a") |
| 399 | .setGroupSummary(true) |
| 400 | .setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN) |
| 401 | .build(); |
| 402 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 403 | UserHandle.of(0), null, 0); |
| 404 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 405 | |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 406 | assertFalse(mEntryManager.shouldPeek(entry, sbn)); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 407 | } |
| 408 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 409 | @Test |
Julia Reynolds | 24653c3 | 2018-03-02 13:16:37 -0500 | [diff] [blame] | 410 | public void testShouldPeek_suppressedPeek() { |
Beverly | 38159ce | 2017-07-13 16:39:24 -0400 | [diff] [blame] | 411 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 412 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 413 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 414 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 415 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 416 | |
Julia Reynolds | 24653c3 | 2018-03-02 13:16:37 -0500 | [diff] [blame] | 417 | when(mNotificationData.shouldSuppressPeek(any())).thenReturn(true); |
| 418 | |
| 419 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 420 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 421 | UserHandle.of(0), null, 0); |
| 422 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 423 | |
| 424 | assertFalse(mEntryManager.shouldPeek(entry, sbn)); |
| 425 | } |
| 426 | |
| 427 | @Test |
| 428 | public void testShouldPeek_noSuppressedPeek() { |
| 429 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 430 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 431 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 432 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 433 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 434 | |
| 435 | when(mNotificationData.shouldSuppressPeek(any())).thenReturn(false); |
Beverly | 38159ce | 2017-07-13 16:39:24 -0400 | [diff] [blame] | 436 | |
| 437 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 438 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 439 | UserHandle.of(0), null, 0); |
| 440 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 441 | |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 442 | assertTrue(mEntryManager.shouldPeek(entry, sbn)); |
Beverly | 38159ce | 2017-07-13 16:39:24 -0400 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | @Test |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 446 | public void testLogHidden() { |
| 447 | try { |
| 448 | mStatusBar.handleVisibleToUserChanged(false); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 449 | waitForUiOffloadThread(); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 450 | verify(mBarService, times(1)).onPanelHidden(); |
| 451 | verify(mBarService, never()).onPanelRevealed(anyBoolean(), anyInt()); |
| 452 | } catch (RemoteException e) { |
| 453 | fail(); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | @Test |
| 458 | public void testPanelOpenForPeek() { |
| 459 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); |
| 460 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 461 | when(mNotificationList.size()).thenReturn(5); |
| 462 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(true); |
| 463 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 464 | |
| 465 | try { |
| 466 | mStatusBar.handleVisibleToUserChanged(true); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 467 | waitForUiOffloadThread(); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 468 | verify(mBarService, never()).onPanelHidden(); |
| 469 | verify(mBarService, times(1)).onPanelRevealed(false, 1); |
| 470 | } catch (RemoteException e) { |
| 471 | fail(); |
| 472 | } |
| 473 | TestableLooper.get(this).processAllMessages(); |
| 474 | } |
| 475 | |
| 476 | @Test |
| 477 | public void testPanelOpenAndClear() { |
| 478 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 479 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 480 | when(mNotificationList.size()).thenReturn(5); |
| 481 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(false); |
| 482 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 483 | |
| 484 | try { |
| 485 | mStatusBar.handleVisibleToUserChanged(true); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 486 | waitForUiOffloadThread(); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 487 | verify(mBarService, never()).onPanelHidden(); |
| 488 | verify(mBarService, times(1)).onPanelRevealed(true, 5); |
| 489 | } catch (RemoteException e) { |
| 490 | fail(); |
| 491 | } |
| 492 | TestableLooper.get(this).processAllMessages(); |
| 493 | } |
| 494 | |
| 495 | @Test |
| 496 | public void testPanelOpenAndNoClear() { |
| 497 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 498 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 499 | when(mNotificationList.size()).thenReturn(5); |
| 500 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(false); |
| 501 | mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD); |
| 502 | |
| 503 | try { |
| 504 | mStatusBar.handleVisibleToUserChanged(true); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 505 | waitForUiOffloadThread(); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 506 | verify(mBarService, never()).onPanelHidden(); |
| 507 | verify(mBarService, times(1)).onPanelRevealed(false, 5); |
| 508 | } catch (RemoteException e) { |
| 509 | fail(); |
| 510 | } |
| 511 | TestableLooper.get(this).processAllMessages(); |
| 512 | } |
| 513 | |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 514 | @Test |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 515 | public void testDisableExpandStatusBar() { |
| 516 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 517 | mStatusBar.setUserSetupForTest(true); |
| 518 | when(mStatusBar.isDeviceProvisioned()).thenReturn(true); |
| 519 | |
| 520 | mStatusBar.disable(StatusBarManager.DISABLE_NONE, |
| 521 | StatusBarManager.DISABLE2_NOTIFICATION_SHADE, false); |
| 522 | verify(mNotificationPanelView).setQsExpansionEnabled(false); |
| 523 | mStatusBar.animateExpandNotificationsPanel(); |
| 524 | verify(mNotificationPanelView, never()).expand(anyBoolean()); |
| 525 | mStatusBar.animateExpandSettingsPanel(null); |
| 526 | verify(mNotificationPanelView, never()).expand(anyBoolean()); |
| 527 | |
| 528 | mStatusBar.disable(StatusBarManager.DISABLE_NONE, StatusBarManager.DISABLE2_NONE, false); |
| 529 | verify(mNotificationPanelView).setQsExpansionEnabled(true); |
| 530 | mStatusBar.animateExpandNotificationsPanel(); |
Eugene Susla | 2de6955 | 2018-03-20 13:22:17 -0700 | [diff] [blame] | 531 | verify(mNotificationPanelView).expandWithoutQs(); |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 532 | mStatusBar.animateExpandSettingsPanel(null); |
Eugene Susla | 2de6955 | 2018-03-20 13:22:17 -0700 | [diff] [blame] | 533 | verify(mNotificationPanelView).expandWithQs(); |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | @Test |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 537 | public void testDump_DoesNotCrash() { |
| 538 | mStatusBar.dump(null, new PrintWriter(new ByteArrayOutputStream()), null); |
| 539 | } |
| 540 | |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 541 | @Test |
| 542 | @RunWithLooper(setAsMainLooper = true) |
| 543 | public void testUpdateKeyguardState_DoesNotCrash() { |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 544 | mStatusBar.mState = StatusBarState.KEYGUARD; |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 545 | when(mStatusBar.mLockscreenUserManager.getCurrentProfiles()).thenReturn( |
| 546 | new SparseArray<>()); |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 547 | mStatusBar.updateKeyguardState(false, false); |
| 548 | } |
| 549 | |
Lucas Dupin | c2e7546 | 2017-12-06 13:59:25 -0800 | [diff] [blame] | 550 | @Test |
| 551 | public void testFingerprintNotification_UpdatesScrims() { |
Lucas Dupin | c2e7546 | 2017-12-06 13:59:25 -0800 | [diff] [blame] | 552 | mStatusBar.notifyFpAuthModeChanged(); |
| 553 | verify(mScrimController).transitionTo(any(), any()); |
| 554 | } |
| 555 | |
Lucas Dupin | 311eac8 | 2017-12-11 14:40:07 -0800 | [diff] [blame] | 556 | @Test |
| 557 | public void testFingerprintUnlock_UpdatesScrims() { |
| 558 | // Simulate unlocking from AoD with fingerprint. |
| 559 | when(mFingerprintUnlockController.getMode()) |
| 560 | .thenReturn(FingerprintUnlockController.MODE_WAKE_AND_UNLOCK); |
| 561 | mStatusBar.updateScrimController(); |
| 562 | verify(mScrimController).transitionTo(eq(ScrimState.UNLOCKED), any()); |
| 563 | } |
| 564 | |
Lucas Dupin | d510730 | 2018-03-19 15:30:29 -0700 | [diff] [blame] | 565 | @Test |
| 566 | public void testSetOccluded_propagatesToScrimController() { |
| 567 | mStatusBar.setOccluded(true); |
| 568 | verify(mScrimController).setKeyguardOccluded(eq(true)); |
| 569 | |
| 570 | reset(mScrimController); |
| 571 | mStatusBar.setOccluded(false); |
| 572 | verify(mScrimController).setKeyguardOccluded(eq(false)); |
| 573 | } |
| 574 | |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 575 | @Test |
| 576 | public void testInflateFooterView() { |
| 577 | mStatusBar.reevaluateStyles(); |
| 578 | ArgumentCaptor<FooterView> captor = ArgumentCaptor.forClass(FooterView.class); |
| 579 | verify(mStackScroller).setFooterView(captor.capture()); |
| 580 | |
| 581 | assertNotNull(captor.getValue().findViewById(R.id.manage_text).hasOnClickListeners()); |
| 582 | assertNotNull(captor.getValue().findViewById(R.id.dismiss_text).hasOnClickListeners()); |
| 583 | } |
| 584 | |
| 585 | @Test |
| 586 | public void testUpdateFooter_noNotifications() { |
| 587 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 588 | assertEquals(0, mEntryManager.getNotificationData().getActiveNotifications().size()); |
| 589 | |
| 590 | mStatusBar.updateFooter(); |
| 591 | verify(mStackScroller).updateFooterView(false, false); |
| 592 | } |
| 593 | |
| 594 | @Test |
Selim Cinek | 7c6fe5b | 2018-04-09 18:27:13 -0700 | [diff] [blame] | 595 | public void testUpdateFooter_remoteInput() { |
| 596 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 597 | ArrayList<Entry> entries = new ArrayList<>(); |
| 598 | entries.add(mock(Entry.class)); |
| 599 | when(mNotificationData.getActiveNotifications()).thenReturn(entries); |
| 600 | |
| 601 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class); |
| 602 | when(row.canViewBeDismissed()).thenReturn(true); |
| 603 | when(mStackScroller.getChildCount()).thenReturn(1); |
| 604 | when(mStackScroller.getChildAt(anyInt())).thenReturn(row); |
| 605 | when(mRemoteInputController.isRemoteInputActive()).thenReturn(true); |
| 606 | |
| 607 | mStatusBar.updateFooter(); |
| 608 | verify(mStackScroller).updateFooterView(false, true); |
| 609 | } |
| 610 | |
| 611 | @Test |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 612 | public void testUpdateFooter_oneClearableNotification() { |
| 613 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 614 | ArrayList<Entry> entries = new ArrayList<>(); |
| 615 | entries.add(mock(Entry.class)); |
| 616 | when(mNotificationData.getActiveNotifications()).thenReturn(entries); |
| 617 | |
| 618 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class); |
| 619 | when(row.canViewBeDismissed()).thenReturn(true); |
| 620 | when(mStackScroller.getChildCount()).thenReturn(1); |
| 621 | when(mStackScroller.getChildAt(anyInt())).thenReturn(row); |
| 622 | |
| 623 | mStatusBar.updateFooter(); |
| 624 | verify(mStackScroller).updateFooterView(true, true); |
| 625 | } |
| 626 | |
| 627 | @Test |
| 628 | public void testUpdateFooter_oneNonClearableNotification() { |
| 629 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 630 | ArrayList<Entry> entries = new ArrayList<>(); |
| 631 | entries.add(mock(Entry.class)); |
| 632 | when(mNotificationData.getActiveNotifications()).thenReturn(entries); |
| 633 | |
| 634 | mStatusBar.updateFooter(); |
| 635 | verify(mStackScroller).updateFooterView(true, false); |
| 636 | } |
| 637 | |
| 638 | @Test |
| 639 | public void testUpdateFooter_atEnd() { |
| 640 | // add footer |
| 641 | mStatusBar.reevaluateStyles(); |
| 642 | |
| 643 | // add notification |
| 644 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class); |
| 645 | when(row.isClearable()).thenReturn(true); |
| 646 | mStackScroller.addContainerView(row); |
| 647 | |
| 648 | mStatusBar.onUpdateRowStates(); |
| 649 | |
| 650 | // move footer to end |
| 651 | verify(mStackScroller).changeViewPosition(any(FooterView.class), eq(-1 /* end */)); |
| 652 | } |
| 653 | |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 654 | @Test |
| 655 | public void testSetState_changesIsFullScreenUserSwitcherState() { |
| 656 | mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD); |
| 657 | assertFalse(mStatusBar.isFullScreenUserSwitcherState()); |
| 658 | |
| 659 | mStatusBar.setBarStateForTest(StatusBarState.FULLSCREEN_USER_SWITCHER); |
| 660 | assertTrue(mStatusBar.isFullScreenUserSwitcherState()); |
| 661 | } |
| 662 | |
| 663 | @Test |
| 664 | public void testShowKeyguardImplementation_setsState() { |
| 665 | when(mLockscreenUserManager.getCurrentProfiles()).thenReturn(new SparseArray<>()); |
| 666 | |
| 667 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 668 | |
| 669 | // By default, showKeyguardImpl sets state to KEYGUARD. |
| 670 | mStatusBar.showKeyguardImpl(); |
| 671 | assertTrue(mStatusBar.mState == StatusBarState.KEYGUARD); |
| 672 | |
| 673 | // If useFullscreenUserSwitcher is true, state is set to FULLSCREEN_USER_SWITCHER. |
| 674 | mStatusBar.mUserSwitcherController = mock(UserSwitcherController.class); |
| 675 | when(mStatusBar.mUserSwitcherController.useFullscreenUserSwitcher()).thenReturn(true); |
| 676 | mStatusBar.showKeyguardImpl(); |
| 677 | assertTrue(mStatusBar.mState == StatusBarState.FULLSCREEN_USER_SWITCHER); |
| 678 | } |
| 679 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 680 | static class TestableStatusBar extends StatusBar { |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 681 | public TestableStatusBar(StatusBarKeyguardViewManager man, |
| 682 | UnlockMethodCache unlock, KeyguardIndicationController key, |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 683 | NotificationStackScrollLayout stack, HeadsUpManagerPhone hum, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 684 | PowerManager pm, NotificationPanelView panelView, |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 685 | IStatusBarService barService, NotificationListener notificationListener, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 686 | NotificationLogger notificationLogger, |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 687 | VisualStabilityManager visualStabilityManager, |
| 688 | NotificationViewHierarchyManager viewHierarchyManager, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 689 | TestableNotificationEntryManager entryManager, ScrimController scrimController, |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 690 | FingerprintUnlockController fingerprintUnlockController, |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 691 | ActivityLaunchAnimator launchAnimator, KeyguardViewMediator keyguardViewMediator, |
| 692 | NotificationRemoteInputManager notificationRemoteInputManager, |
| 693 | NotificationGroupManager notificationGroupManager, |
| 694 | FalsingManager falsingManager, |
| 695 | StatusBarWindowManager statusBarWindowManager, |
| 696 | NotificationIconAreaController notificationIconAreaController, |
| 697 | DozeScrimController dozeScrimController, |
| 698 | NotificationShelf notificationShelf, |
| 699 | NotificationLockscreenUserManager notificationLockscreenUserManager, |
| 700 | CommandQueue commandQueue) { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 701 | mStatusBarKeyguardViewManager = man; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 702 | mUnlockMethodCache = unlock; |
| 703 | mKeyguardIndicationController = key; |
| 704 | mStackScroller = stack; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 705 | mHeadsUpManager = hum; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 706 | mPowerManager = pm; |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 707 | mNotificationPanel = panelView; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 708 | mBarService = barService; |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 709 | mNotificationListener = notificationListener; |
| 710 | mNotificationLogger = notificationLogger; |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 711 | mWakefulnessLifecycle = createAwakeWakefulnessLifecycle(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 712 | mVisualStabilityManager = visualStabilityManager; |
| 713 | mViewHierarchyManager = viewHierarchyManager; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 714 | mEntryManager = entryManager; |
Lucas Dupin | c2e7546 | 2017-12-06 13:59:25 -0800 | [diff] [blame] | 715 | mScrimController = scrimController; |
Lucas Dupin | 311eac8 | 2017-12-11 14:40:07 -0800 | [diff] [blame] | 716 | mFingerprintUnlockController = fingerprintUnlockController; |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 717 | mActivityLaunchAnimator = launchAnimator; |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 718 | mKeyguardViewMediator = keyguardViewMediator; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 719 | mClearAllEnabled = true; |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 720 | mRemoteInputManager = notificationRemoteInputManager; |
| 721 | mGroupManager = notificationGroupManager; |
| 722 | mFalsingManager = falsingManager; |
| 723 | mStatusBarWindowManager = statusBarWindowManager; |
| 724 | mNotificationIconAreaController = notificationIconAreaController; |
| 725 | mDozeScrimController = dozeScrimController; |
| 726 | mNotificationShelf = notificationShelf; |
| 727 | mLockscreenUserManager = notificationLockscreenUserManager; |
| 728 | mCommandQueue = commandQueue; |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | private WakefulnessLifecycle createAwakeWakefulnessLifecycle() { |
| 732 | WakefulnessLifecycle wakefulnessLifecycle = new WakefulnessLifecycle(); |
| 733 | wakefulnessLifecycle.dispatchStartedWakingUp(); |
| 734 | wakefulnessLifecycle.dispatchFinishedWakingUp(); |
| 735 | return wakefulnessLifecycle; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 736 | } |
| 737 | |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 738 | @Override |
| 739 | protected void updateTheme() { |
| 740 | // Do nothing for now, until we have more mocking and StatusBar is smaller. |
| 741 | } |
| 742 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 743 | public void setBarStateForTest(int state) { |
| 744 | mState = state; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 745 | } |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 746 | |
| 747 | public void setUserSetupForTest(boolean userSetup) { |
| 748 | mUserSetup = userSetup; |
| 749 | } |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 750 | |
| 751 | } |
| 752 | |
| 753 | private class TestableNotificationEntryManager extends NotificationEntryManager { |
| 754 | |
Eliot Courtney | 6c313d3 | 2017-12-14 19:57:51 +0900 | [diff] [blame] | 755 | public TestableNotificationEntryManager(SystemServicesProxy systemServicesProxy, |
| 756 | PowerManager powerManager, Context context) { |
| 757 | super(context); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 758 | mSystemServicesProxy = systemServicesProxy; |
| 759 | mPowerManager = powerManager; |
| 760 | } |
| 761 | |
| 762 | public void setUpForTest(NotificationPresenter presenter, |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 763 | NotificationListContainer listContainer, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 764 | Callback callback, |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 765 | HeadsUpManagerPhone headsUpManager, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 766 | NotificationData notificationData) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 767 | super.setUpWithPresenter(presenter, listContainer, callback, headsUpManager); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 768 | mNotificationData = notificationData; |
| 769 | mUseHeadsUp = true; |
| 770 | } |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 771 | } |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 772 | } |