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