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