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