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 |
e.min | 30d3651 | 2018-03-29 10:06:21 +0900 | [diff] [blame^] | 446 | public void testPeek_disabledStatusBar() { |
| 447 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 448 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 449 | UserHandle.of(0), null, 0); |
| 450 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 451 | mStatusBar.disable(StatusBarManager.DISABLE_EXPAND, 0, false /* animate */); |
| 452 | |
| 453 | assertFalse("The panel shouldn't allow peek while disabled", |
| 454 | mStatusBar.shouldPeek(entry, sbn)); |
| 455 | } |
| 456 | |
| 457 | @Test |
| 458 | public void testPeek_disabledNotificationShade() { |
| 459 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 460 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 461 | UserHandle.of(0), null, 0); |
| 462 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 463 | mStatusBar.disable(0, StatusBarManager.DISABLE2_NOTIFICATION_SHADE, false /* animate */); |
| 464 | |
| 465 | assertFalse("The panel shouldn't allow peek while notitifcation shade disabled", |
| 466 | mStatusBar.shouldPeek(entry, sbn)); |
| 467 | } |
| 468 | |
| 469 | @Test |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 470 | public void testLogHidden() { |
| 471 | try { |
| 472 | mStatusBar.handleVisibleToUserChanged(false); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 473 | waitForUiOffloadThread(); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 474 | verify(mBarService, times(1)).onPanelHidden(); |
| 475 | verify(mBarService, never()).onPanelRevealed(anyBoolean(), anyInt()); |
| 476 | } catch (RemoteException e) { |
| 477 | fail(); |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | @Test |
| 482 | public void testPanelOpenForPeek() { |
| 483 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); |
| 484 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 485 | when(mNotificationList.size()).thenReturn(5); |
| 486 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(true); |
| 487 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 488 | |
| 489 | try { |
| 490 | mStatusBar.handleVisibleToUserChanged(true); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 491 | waitForUiOffloadThread(); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 492 | verify(mBarService, never()).onPanelHidden(); |
| 493 | verify(mBarService, times(1)).onPanelRevealed(false, 1); |
| 494 | } catch (RemoteException e) { |
| 495 | fail(); |
| 496 | } |
| 497 | TestableLooper.get(this).processAllMessages(); |
| 498 | } |
| 499 | |
| 500 | @Test |
| 501 | public void testPanelOpenAndClear() { |
| 502 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 503 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 504 | when(mNotificationList.size()).thenReturn(5); |
| 505 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(false); |
| 506 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 507 | |
| 508 | try { |
| 509 | mStatusBar.handleVisibleToUserChanged(true); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 510 | waitForUiOffloadThread(); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 511 | verify(mBarService, never()).onPanelHidden(); |
| 512 | verify(mBarService, times(1)).onPanelRevealed(true, 5); |
| 513 | } catch (RemoteException e) { |
| 514 | fail(); |
| 515 | } |
| 516 | TestableLooper.get(this).processAllMessages(); |
| 517 | } |
| 518 | |
| 519 | @Test |
| 520 | public void testPanelOpenAndNoClear() { |
| 521 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 522 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 523 | when(mNotificationList.size()).thenReturn(5); |
| 524 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(false); |
| 525 | mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD); |
| 526 | |
| 527 | try { |
| 528 | mStatusBar.handleVisibleToUserChanged(true); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 529 | waitForUiOffloadThread(); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 530 | verify(mBarService, never()).onPanelHidden(); |
| 531 | verify(mBarService, times(1)).onPanelRevealed(false, 5); |
| 532 | } catch (RemoteException e) { |
| 533 | fail(); |
| 534 | } |
| 535 | TestableLooper.get(this).processAllMessages(); |
| 536 | } |
| 537 | |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 538 | @Test |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 539 | public void testDisableExpandStatusBar() { |
| 540 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 541 | mStatusBar.setUserSetupForTest(true); |
| 542 | when(mStatusBar.isDeviceProvisioned()).thenReturn(true); |
| 543 | |
| 544 | mStatusBar.disable(StatusBarManager.DISABLE_NONE, |
| 545 | StatusBarManager.DISABLE2_NOTIFICATION_SHADE, false); |
| 546 | verify(mNotificationPanelView).setQsExpansionEnabled(false); |
| 547 | mStatusBar.animateExpandNotificationsPanel(); |
| 548 | verify(mNotificationPanelView, never()).expand(anyBoolean()); |
| 549 | mStatusBar.animateExpandSettingsPanel(null); |
| 550 | verify(mNotificationPanelView, never()).expand(anyBoolean()); |
| 551 | |
| 552 | mStatusBar.disable(StatusBarManager.DISABLE_NONE, StatusBarManager.DISABLE2_NONE, false); |
| 553 | verify(mNotificationPanelView).setQsExpansionEnabled(true); |
| 554 | mStatusBar.animateExpandNotificationsPanel(); |
Eugene Susla | 2de6955 | 2018-03-20 13:22:17 -0700 | [diff] [blame] | 555 | verify(mNotificationPanelView).expandWithoutQs(); |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 556 | mStatusBar.animateExpandSettingsPanel(null); |
Eugene Susla | 2de6955 | 2018-03-20 13:22:17 -0700 | [diff] [blame] | 557 | verify(mNotificationPanelView).expandWithQs(); |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | @Test |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 561 | public void testDump_DoesNotCrash() { |
| 562 | mStatusBar.dump(null, new PrintWriter(new ByteArrayOutputStream()), null); |
| 563 | } |
| 564 | |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 565 | @Test |
| 566 | @RunWithLooper(setAsMainLooper = true) |
| 567 | public void testUpdateKeyguardState_DoesNotCrash() { |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 568 | mStatusBar.mState = StatusBarState.KEYGUARD; |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 569 | when(mStatusBar.mLockscreenUserManager.getCurrentProfiles()).thenReturn( |
| 570 | new SparseArray<>()); |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 571 | mStatusBar.updateKeyguardState(false, false); |
| 572 | } |
| 573 | |
Lucas Dupin | c2e7546 | 2017-12-06 13:59:25 -0800 | [diff] [blame] | 574 | @Test |
| 575 | public void testFingerprintNotification_UpdatesScrims() { |
Lucas Dupin | c2e7546 | 2017-12-06 13:59:25 -0800 | [diff] [blame] | 576 | mStatusBar.notifyFpAuthModeChanged(); |
| 577 | verify(mScrimController).transitionTo(any(), any()); |
| 578 | } |
| 579 | |
Lucas Dupin | 311eac8 | 2017-12-11 14:40:07 -0800 | [diff] [blame] | 580 | @Test |
| 581 | public void testFingerprintUnlock_UpdatesScrims() { |
| 582 | // Simulate unlocking from AoD with fingerprint. |
| 583 | when(mFingerprintUnlockController.getMode()) |
| 584 | .thenReturn(FingerprintUnlockController.MODE_WAKE_AND_UNLOCK); |
| 585 | mStatusBar.updateScrimController(); |
| 586 | verify(mScrimController).transitionTo(eq(ScrimState.UNLOCKED), any()); |
| 587 | } |
| 588 | |
Lucas Dupin | d510730 | 2018-03-19 15:30:29 -0700 | [diff] [blame] | 589 | @Test |
| 590 | public void testSetOccluded_propagatesToScrimController() { |
| 591 | mStatusBar.setOccluded(true); |
| 592 | verify(mScrimController).setKeyguardOccluded(eq(true)); |
| 593 | |
| 594 | reset(mScrimController); |
| 595 | mStatusBar.setOccluded(false); |
| 596 | verify(mScrimController).setKeyguardOccluded(eq(false)); |
| 597 | } |
| 598 | |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 599 | @Test |
| 600 | public void testInflateFooterView() { |
| 601 | mStatusBar.reevaluateStyles(); |
| 602 | ArgumentCaptor<FooterView> captor = ArgumentCaptor.forClass(FooterView.class); |
| 603 | verify(mStackScroller).setFooterView(captor.capture()); |
| 604 | |
| 605 | assertNotNull(captor.getValue().findViewById(R.id.manage_text).hasOnClickListeners()); |
| 606 | assertNotNull(captor.getValue().findViewById(R.id.dismiss_text).hasOnClickListeners()); |
| 607 | } |
| 608 | |
| 609 | @Test |
| 610 | public void testUpdateFooter_noNotifications() { |
| 611 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 612 | assertEquals(0, mEntryManager.getNotificationData().getActiveNotifications().size()); |
| 613 | |
| 614 | mStatusBar.updateFooter(); |
| 615 | verify(mStackScroller).updateFooterView(false, false); |
| 616 | } |
| 617 | |
| 618 | @Test |
Selim Cinek | 7c6fe5b | 2018-04-09 18:27:13 -0700 | [diff] [blame] | 619 | public void testUpdateFooter_remoteInput() { |
| 620 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 621 | ArrayList<Entry> entries = new ArrayList<>(); |
| 622 | entries.add(mock(Entry.class)); |
| 623 | when(mNotificationData.getActiveNotifications()).thenReturn(entries); |
| 624 | |
| 625 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class); |
| 626 | when(row.canViewBeDismissed()).thenReturn(true); |
| 627 | when(mStackScroller.getChildCount()).thenReturn(1); |
| 628 | when(mStackScroller.getChildAt(anyInt())).thenReturn(row); |
| 629 | when(mRemoteInputController.isRemoteInputActive()).thenReturn(true); |
| 630 | |
| 631 | mStatusBar.updateFooter(); |
| 632 | verify(mStackScroller).updateFooterView(false, true); |
| 633 | } |
| 634 | |
| 635 | @Test |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 636 | public void testUpdateFooter_oneClearableNotification() { |
| 637 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 638 | ArrayList<Entry> entries = new ArrayList<>(); |
| 639 | entries.add(mock(Entry.class)); |
| 640 | when(mNotificationData.getActiveNotifications()).thenReturn(entries); |
| 641 | |
| 642 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class); |
| 643 | when(row.canViewBeDismissed()).thenReturn(true); |
| 644 | when(mStackScroller.getChildCount()).thenReturn(1); |
| 645 | when(mStackScroller.getChildAt(anyInt())).thenReturn(row); |
| 646 | |
| 647 | mStatusBar.updateFooter(); |
| 648 | verify(mStackScroller).updateFooterView(true, true); |
| 649 | } |
| 650 | |
| 651 | @Test |
| 652 | public void testUpdateFooter_oneNonClearableNotification() { |
| 653 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 654 | ArrayList<Entry> entries = new ArrayList<>(); |
| 655 | entries.add(mock(Entry.class)); |
| 656 | when(mNotificationData.getActiveNotifications()).thenReturn(entries); |
| 657 | |
| 658 | mStatusBar.updateFooter(); |
| 659 | verify(mStackScroller).updateFooterView(true, false); |
| 660 | } |
| 661 | |
| 662 | @Test |
| 663 | public void testUpdateFooter_atEnd() { |
| 664 | // add footer |
| 665 | mStatusBar.reevaluateStyles(); |
| 666 | |
| 667 | // add notification |
| 668 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class); |
| 669 | when(row.isClearable()).thenReturn(true); |
| 670 | mStackScroller.addContainerView(row); |
| 671 | |
| 672 | mStatusBar.onUpdateRowStates(); |
| 673 | |
| 674 | // move footer to end |
| 675 | verify(mStackScroller).changeViewPosition(any(FooterView.class), eq(-1 /* end */)); |
| 676 | } |
| 677 | |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 678 | @Test |
| 679 | public void testSetState_changesIsFullScreenUserSwitcherState() { |
| 680 | mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD); |
| 681 | assertFalse(mStatusBar.isFullScreenUserSwitcherState()); |
| 682 | |
| 683 | mStatusBar.setBarStateForTest(StatusBarState.FULLSCREEN_USER_SWITCHER); |
| 684 | assertTrue(mStatusBar.isFullScreenUserSwitcherState()); |
| 685 | } |
| 686 | |
| 687 | @Test |
| 688 | public void testShowKeyguardImplementation_setsState() { |
| 689 | when(mLockscreenUserManager.getCurrentProfiles()).thenReturn(new SparseArray<>()); |
| 690 | |
| 691 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 692 | |
| 693 | // By default, showKeyguardImpl sets state to KEYGUARD. |
| 694 | mStatusBar.showKeyguardImpl(); |
| 695 | assertTrue(mStatusBar.mState == StatusBarState.KEYGUARD); |
| 696 | |
| 697 | // If useFullscreenUserSwitcher is true, state is set to FULLSCREEN_USER_SWITCHER. |
| 698 | mStatusBar.mUserSwitcherController = mock(UserSwitcherController.class); |
| 699 | when(mStatusBar.mUserSwitcherController.useFullscreenUserSwitcher()).thenReturn(true); |
| 700 | mStatusBar.showKeyguardImpl(); |
| 701 | assertTrue(mStatusBar.mState == StatusBarState.FULLSCREEN_USER_SWITCHER); |
| 702 | } |
| 703 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 704 | static class TestableStatusBar extends StatusBar { |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 705 | public TestableStatusBar(StatusBarKeyguardViewManager man, |
| 706 | UnlockMethodCache unlock, KeyguardIndicationController key, |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 707 | NotificationStackScrollLayout stack, HeadsUpManagerPhone hum, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 708 | PowerManager pm, NotificationPanelView panelView, |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 709 | IStatusBarService barService, NotificationListener notificationListener, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 710 | NotificationLogger notificationLogger, |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 711 | VisualStabilityManager visualStabilityManager, |
| 712 | NotificationViewHierarchyManager viewHierarchyManager, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 713 | TestableNotificationEntryManager entryManager, ScrimController scrimController, |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 714 | FingerprintUnlockController fingerprintUnlockController, |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 715 | ActivityLaunchAnimator launchAnimator, KeyguardViewMediator keyguardViewMediator, |
| 716 | NotificationRemoteInputManager notificationRemoteInputManager, |
| 717 | NotificationGroupManager notificationGroupManager, |
| 718 | FalsingManager falsingManager, |
| 719 | StatusBarWindowManager statusBarWindowManager, |
| 720 | NotificationIconAreaController notificationIconAreaController, |
| 721 | DozeScrimController dozeScrimController, |
| 722 | NotificationShelf notificationShelf, |
| 723 | NotificationLockscreenUserManager notificationLockscreenUserManager, |
| 724 | CommandQueue commandQueue) { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 725 | mStatusBarKeyguardViewManager = man; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 726 | mUnlockMethodCache = unlock; |
| 727 | mKeyguardIndicationController = key; |
| 728 | mStackScroller = stack; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 729 | mHeadsUpManager = hum; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 730 | mPowerManager = pm; |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 731 | mNotificationPanel = panelView; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 732 | mBarService = barService; |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 733 | mNotificationListener = notificationListener; |
| 734 | mNotificationLogger = notificationLogger; |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 735 | mWakefulnessLifecycle = createAwakeWakefulnessLifecycle(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 736 | mVisualStabilityManager = visualStabilityManager; |
| 737 | mViewHierarchyManager = viewHierarchyManager; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 738 | mEntryManager = entryManager; |
Lucas Dupin | c2e7546 | 2017-12-06 13:59:25 -0800 | [diff] [blame] | 739 | mScrimController = scrimController; |
Lucas Dupin | 311eac8 | 2017-12-11 14:40:07 -0800 | [diff] [blame] | 740 | mFingerprintUnlockController = fingerprintUnlockController; |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 741 | mActivityLaunchAnimator = launchAnimator; |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 742 | mKeyguardViewMediator = keyguardViewMediator; |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 743 | mClearAllEnabled = true; |
jovanak | 5f6dc61 | 2018-03-27 11:59:22 -0700 | [diff] [blame] | 744 | mRemoteInputManager = notificationRemoteInputManager; |
| 745 | mGroupManager = notificationGroupManager; |
| 746 | mFalsingManager = falsingManager; |
| 747 | mStatusBarWindowManager = statusBarWindowManager; |
| 748 | mNotificationIconAreaController = notificationIconAreaController; |
| 749 | mDozeScrimController = dozeScrimController; |
| 750 | mNotificationShelf = notificationShelf; |
| 751 | mLockscreenUserManager = notificationLockscreenUserManager; |
| 752 | mCommandQueue = commandQueue; |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | private WakefulnessLifecycle createAwakeWakefulnessLifecycle() { |
| 756 | WakefulnessLifecycle wakefulnessLifecycle = new WakefulnessLifecycle(); |
| 757 | wakefulnessLifecycle.dispatchStartedWakingUp(); |
| 758 | wakefulnessLifecycle.dispatchFinishedWakingUp(); |
| 759 | return wakefulnessLifecycle; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 760 | } |
| 761 | |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 762 | @Override |
| 763 | protected void updateTheme() { |
| 764 | // Do nothing for now, until we have more mocking and StatusBar is smaller. |
| 765 | } |
| 766 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 767 | public void setBarStateForTest(int state) { |
| 768 | mState = state; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 769 | } |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 770 | |
| 771 | public void setUserSetupForTest(boolean userSetup) { |
| 772 | mUserSetup = userSetup; |
| 773 | } |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 774 | |
| 775 | } |
| 776 | |
| 777 | private class TestableNotificationEntryManager extends NotificationEntryManager { |
| 778 | |
Eliot Courtney | 6c313d3 | 2017-12-14 19:57:51 +0900 | [diff] [blame] | 779 | public TestableNotificationEntryManager(SystemServicesProxy systemServicesProxy, |
| 780 | PowerManager powerManager, Context context) { |
| 781 | super(context); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 782 | mSystemServicesProxy = systemServicesProxy; |
| 783 | mPowerManager = powerManager; |
| 784 | } |
| 785 | |
| 786 | public void setUpForTest(NotificationPresenter presenter, |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 787 | NotificationListContainer listContainer, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 788 | Callback callback, |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 789 | HeadsUpManagerPhone headsUpManager, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 790 | NotificationData notificationData) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 791 | super.setUpWithPresenter(presenter, listContainer, callback, headsUpManager); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 792 | mNotificationData = notificationData; |
| 793 | mUseHeadsUp = true; |
| 794 | } |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 795 | } |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 796 | } |