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