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