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