blob: a706368a0880d63feafbf3e14a335f04ac714ea4 [file] [log] [blame]
Adrian Roosef7a4022017-01-19 14:48:35 -08001/*
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
17package com.android.systemui.statusbar.phone;
18
Julia Reynolds30203152017-05-26 13:36:31 -040019import static android.app.NotificationManager.IMPORTANCE_HIGH;
20
21import static junit.framework.Assert.assertFalse;
22import static junit.framework.Assert.assertTrue;
Chris Wren621933f2017-06-14 15:59:03 -040023import static junit.framework.TestCase.fail;
Julia Reynolds30203152017-05-26 13:36:31 -040024
Chris Wren621933f2017-06-14 15:59:03 -040025import static org.mockito.ArgumentMatchers.any;
26import static org.mockito.ArgumentMatchers.anyBoolean;
27import static org.mockito.ArgumentMatchers.anyInt;
28import static org.mockito.ArgumentMatchers.anyString;
Adrian Roosef7a4022017-01-19 14:48:35 -080029import static org.mockito.Matchers.any;
30import static org.mockito.Matchers.anyBoolean;
Chris Wren621933f2017-06-14 15:59:03 -040031import static org.mockito.Matchers.anyInt;
Julia Reynolds30203152017-05-26 13:36:31 -040032import static org.mockito.Matchers.anyString;
Adrian Roosef7a4022017-01-19 14:48:35 -080033import static org.mockito.Mockito.doAnswer;
34import static org.mockito.Mockito.mock;
Chris Wren621933f2017-06-14 15:59:03 -040035import static org.mockito.Mockito.never;
36import static org.mockito.Mockito.times;
Adrian Roosef7a4022017-01-19 14:48:35 -080037import static org.mockito.Mockito.when;
Chris Wren621933f2017-06-14 15:59:03 -040038import static org.mockito.Mockito.verify;
Adrian Roosef7a4022017-01-19 14:48:35 -080039
Julia Reynolds30203152017-05-26 13:36:31 -040040import android.app.Notification;
Jason Monk51305372017-06-22 11:41:08 -040041import android.app.trust.TrustManager;
42import android.hardware.fingerprint.FingerprintManager;
Chris Wren27a52fa2017-02-01 14:21:43 -050043import android.metrics.LogMaker;
Julia Reynolds30203152017-05-26 13:36:31 -040044import android.os.Handler;
45import android.os.HandlerThread;
46import android.os.IPowerManager;
Chris Wren621933f2017-06-14 15:59:03 -040047import android.os.Message;
Julia Reynolds30203152017-05-26 13:36:31 -040048import android.os.PowerManager;
Chris Wren621933f2017-06-14 15:59:03 -040049import android.os.RemoteException;
Julia Reynolds30203152017-05-26 13:36:31 -040050import android.os.UserHandle;
51import android.service.notification.StatusBarNotification;
Adrian Roosef7a4022017-01-19 14:48:35 -080052import android.support.test.filters.SmallTest;
Chris Wren27a52fa2017-02-01 14:21:43 -050053import android.support.test.metricshelper.MetricsAsserts;
Adrian Roosef7a4022017-01-19 14:48:35 -080054import android.support.test.runner.AndroidJUnit4;
Chris Wren621933f2017-06-14 15:59:03 -040055import android.testing.AndroidTestingRunner;
56import android.testing.TestableLooper;
57import android.testing.TestableLooper.MessageHandler;
58import android.testing.TestableLooper.RunWithLooper;
Chris Wren27a52fa2017-02-01 14:21:43 -050059import android.util.DisplayMetrics;
Jason Monk51305372017-06-22 11:41:08 -040060import android.view.ViewGroup.LayoutParams;
Adrian Roosef7a4022017-01-19 14:48:35 -080061
Chris Wrenef319902017-03-07 17:58:31 -050062import com.android.internal.logging.MetricsLogger;
Chris Wren27a52fa2017-02-01 14:21:43 -050063import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Chris Wrenef319902017-03-07 17:58:31 -050064import com.android.internal.logging.testing.FakeMetricsLogger;
Chris Wren621933f2017-06-14 15:59:03 -040065import com.android.internal.statusbar.IStatusBarService;
Adrian Roosef7a4022017-01-19 14:48:35 -080066import com.android.keyguard.KeyguardHostView.OnDismissAction;
67import com.android.systemui.SysuiTestCase;
Adrian Roos6d5ebb72017-08-03 15:10:22 +020068import com.android.systemui.keyguard.WakefulnessLifecycle;
Julia Reynolds30203152017-05-26 13:36:31 -040069import com.android.systemui.recents.misc.SystemServicesProxy;
Chris Wren27a52fa2017-02-01 14:21:43 -050070import com.android.systemui.statusbar.ActivatableNotificationView;
Jason Monk5ecf80c2017-07-06 15:28:17 -040071import com.android.systemui.statusbar.CommandQueue;
Chris Wren27a52fa2017-02-01 14:21:43 -050072import com.android.systemui.statusbar.KeyguardIndicationController;
73import com.android.systemui.statusbar.NotificationData;
Chris Wren621933f2017-06-14 15:59:03 -040074import com.android.systemui.statusbar.NotificationData.Entry;
75import com.android.systemui.statusbar.StatusBarState;
Julia Reynolds30203152017-05-26 13:36:31 -040076import com.android.systemui.statusbar.policy.HeadsUpManager;
Chris Wren27a52fa2017-02-01 14:21:43 -050077import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Adrian Roosef7a4022017-01-19 14:48:35 -080078
79import org.junit.Before;
80import org.junit.Test;
81import org.junit.runner.RunWith;
82
Jason Monk51305372017-06-22 11:41:08 -040083import java.io.ByteArrayOutputStream;
84import java.io.PrintWriter;
Chris Wren621933f2017-06-14 15:59:03 -040085import java.util.ArrayList;
86
Adrian Roos02de4982017-02-11 09:35:54 +010087@SmallTest
Chris Wren621933f2017-06-14 15:59:03 -040088@RunWith(AndroidTestingRunner.class)
89@RunWithLooper
Jason Monk2a6ea9c2017-01-26 11:14:51 -050090public class StatusBarTest extends SysuiTestCase {
Adrian Roosef7a4022017-01-19 14:48:35 -080091
92 StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
Chris Wren27a52fa2017-02-01 14:21:43 -050093 UnlockMethodCache mUnlockMethodCache;
94 KeyguardIndicationController mKeyguardIndicationController;
95 NotificationStackScrollLayout mStackScroller;
Chris Wren621933f2017-06-14 15:59:03 -040096 TestableStatusBar mStatusBar;
Chris Wrenef319902017-03-07 17:58:31 -050097 FakeMetricsLogger mMetricsLogger;
Julia Reynolds30203152017-05-26 13:36:31 -040098 HeadsUpManager mHeadsUpManager;
99 NotificationData mNotificationData;
100 PowerManager mPowerManager;
101 SystemServicesProxy mSystemServicesProxy;
Jorim Jaggifd3b1a12017-06-06 17:04:19 -0700102 NotificationPanelView mNotificationPanelView;
Chris Wren621933f2017-06-14 15:59:03 -0400103 IStatusBarService mBarService;
104 ArrayList<Entry> mNotificationList;
Chris Wren27a52fa2017-02-01 14:21:43 -0500105 private DisplayMetrics mDisplayMetrics = new DisplayMetrics();
106
Adrian Roos02de4982017-02-11 09:35:54 +0100107 @Before
Julia Reynolds30203152017-05-26 13:36:31 -0400108 public void setup() throws Exception {
Jason Monk51305372017-06-22 11:41:08 -0400109 mContext.addMockSystemService(TrustManager.class, mock(TrustManager.class));
110 mContext.addMockSystemService(FingerprintManager.class, mock(FingerprintManager.class));
Adrian Roosef7a4022017-01-19 14:48:35 -0800111 mStatusBarKeyguardViewManager = mock(StatusBarKeyguardViewManager.class);
Chris Wren27a52fa2017-02-01 14:21:43 -0500112 mUnlockMethodCache = mock(UnlockMethodCache.class);
113 mKeyguardIndicationController = mock(KeyguardIndicationController.class);
114 mStackScroller = mock(NotificationStackScrollLayout.class);
Chris Wrenef319902017-03-07 17:58:31 -0500115 mMetricsLogger = new FakeMetricsLogger();
Julia Reynolds30203152017-05-26 13:36:31 -0400116 mHeadsUpManager = mock(HeadsUpManager.class);
117 mNotificationData = mock(NotificationData.class);
118 mSystemServicesProxy = mock(SystemServicesProxy.class);
Jorim Jaggifd3b1a12017-06-06 17:04:19 -0700119 mNotificationPanelView = mock(NotificationPanelView.class);
Jason Monk51305372017-06-22 11:41:08 -0400120 when(mNotificationPanelView.getLayoutParams()).thenReturn(new LayoutParams(0, 0));
Chris Wren621933f2017-06-14 15:59:03 -0400121 mNotificationList = mock(ArrayList.class);
Julia Reynolds30203152017-05-26 13:36:31 -0400122 IPowerManager powerManagerService = mock(IPowerManager.class);
123 HandlerThread handlerThread = new HandlerThread("TestThread");
124 handlerThread.start();
125 mPowerManager = new PowerManager(mContext, powerManagerService,
126 new Handler(handlerThread.getLooper()));
127 when(powerManagerService.isInteractive()).thenReturn(true);
Chris Wren621933f2017-06-14 15:59:03 -0400128 mBarService = mock(IStatusBarService.class);
Julia Reynolds30203152017-05-26 13:36:31 -0400129
Jason Monk8c09ac72017-03-16 11:53:40 -0400130 mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
Chris Wren27a52fa2017-02-01 14:21:43 -0500131 mStatusBar = new TestableStatusBar(mStatusBarKeyguardViewManager, mUnlockMethodCache,
Julia Reynolds30203152017-05-26 13:36:31 -0400132 mKeyguardIndicationController, mStackScroller, mHeadsUpManager,
Chris Wren621933f2017-06-14 15:59:03 -0400133 mNotificationData, mPowerManager, mSystemServicesProxy, mNotificationPanelView,
134 mBarService);
Jason Monk51305372017-06-22 11:41:08 -0400135 mStatusBar.mContext = mContext;
Adrian Roosef7a4022017-01-19 14:48:35 -0800136 doAnswer(invocation -> {
137 OnDismissAction onDismissAction = (OnDismissAction) invocation.getArguments()[0];
138 onDismissAction.onDismiss();
139 return null;
140 }).when(mStatusBarKeyguardViewManager).dismissWithAction(any(), any(), anyBoolean());
141
142 doAnswer(invocation -> {
143 Runnable runnable = (Runnable) invocation.getArguments()[0];
144 runnable.run();
145 return null;
146 }).when(mStatusBarKeyguardViewManager).addAfterKeyguardGoneRunnable(any());
Chris Wren27a52fa2017-02-01 14:21:43 -0500147
148 when(mStackScroller.getActivatedChild()).thenReturn(null);
Chris Wren621933f2017-06-14 15:59:03 -0400149 TestableLooper.get(this).setMessageHandler(new MessageHandler() {
150 @Override
151 public boolean onMessageHandled(Message m) {
152 if (m.getCallback() == mStatusBar.mVisibilityReporter) {
153 return false;
154 }
155 return true;
156 }
157 });
Adrian Roosef7a4022017-01-19 14:48:35 -0800158 }
159
Adrian Roos02de4982017-02-11 09:35:54 +0100160 @Test
Jason Monk5ecf80c2017-07-06 15:28:17 -0400161 public void testSetBouncerShowing_noCrash() {
162 mStatusBar.mCommandQueue = mock(CommandQueue.class);
163 mStatusBar.setBouncerShowing(true);
164 }
165
166 @Test
Adrian Roosef7a4022017-01-19 14:48:35 -0800167 public void executeRunnableDismissingKeyguard_nullRunnable_showingAndOccluded() {
168 when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true);
169 when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(true);
170
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500171 mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false);
Adrian Roosef7a4022017-01-19 14:48:35 -0800172 }
173
Adrian Roos02de4982017-02-11 09:35:54 +0100174 @Test
Adrian Roosef7a4022017-01-19 14:48:35 -0800175 public void executeRunnableDismissingKeyguard_nullRunnable_showing() {
176 when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true);
177 when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false);
178
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500179 mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false);
Adrian Roosef7a4022017-01-19 14:48:35 -0800180 }
181
Adrian Roos02de4982017-02-11 09:35:54 +0100182 @Test
Adrian Roosef7a4022017-01-19 14:48:35 -0800183 public void executeRunnableDismissingKeyguard_nullRunnable_notShowing() {
184 when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false);
185 when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false);
186
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500187 mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false);
Adrian Roosef7a4022017-01-19 14:48:35 -0800188 }
189
Adrian Roos02de4982017-02-11 09:35:54 +0100190 @Test
Chris Wren27a52fa2017-02-01 14:21:43 -0500191 public void lockscreenStateMetrics_notShowing() {
192 // uninteresting state, except that fingerprint must be non-zero
193 when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false);
194 when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true);
195 // interesting state
196 when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false);
197 when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false);
198 when(mUnlockMethodCache.isMethodSecure()).thenReturn(false);
Chris Wren27a52fa2017-02-01 14:21:43 -0500199 mStatusBar.onKeyguardViewManagerStatesUpdated();
200
Chris Wrenef319902017-03-07 17:58:31 -0500201 MetricsAsserts.assertHasLog("missing hidden insecure lockscreen log",
202 mMetricsLogger.getLogs(),
Chris Wren27a52fa2017-02-01 14:21:43 -0500203 new LogMaker(MetricsEvent.LOCKSCREEN)
204 .setType(MetricsEvent.TYPE_CLOSE)
205 .setSubtype(0));
206 }
207
Adrian Roos02de4982017-02-11 09:35:54 +0100208 @Test
Chris Wren27a52fa2017-02-01 14:21:43 -0500209 public void lockscreenStateMetrics_notShowing_secure() {
210 // uninteresting state, except that fingerprint must be non-zero
211 when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false);
212 when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true);
213 // interesting state
214 when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false);
215 when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false);
216 when(mUnlockMethodCache.isMethodSecure()).thenReturn(true);
217
218 mStatusBar.onKeyguardViewManagerStatesUpdated();
219
Chris Wrenef319902017-03-07 17:58:31 -0500220 MetricsAsserts.assertHasLog("missing hidden secure lockscreen log",
221 mMetricsLogger.getLogs(),
Chris Wren27a52fa2017-02-01 14:21:43 -0500222 new LogMaker(MetricsEvent.LOCKSCREEN)
223 .setType(MetricsEvent.TYPE_CLOSE)
224 .setSubtype(1));
225 }
226
Adrian Roos02de4982017-02-11 09:35:54 +0100227 @Test
Chris Wren27a52fa2017-02-01 14:21:43 -0500228 public void lockscreenStateMetrics_isShowing() {
229 // uninteresting state, except that fingerprint must be non-zero
230 when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false);
231 when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true);
232 // interesting state
233 when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true);
234 when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false);
235 when(mUnlockMethodCache.isMethodSecure()).thenReturn(false);
236
237 mStatusBar.onKeyguardViewManagerStatesUpdated();
238
Chris Wrenef319902017-03-07 17:58:31 -0500239 MetricsAsserts.assertHasLog("missing insecure lockscreen showing",
240 mMetricsLogger.getLogs(),
Chris Wren27a52fa2017-02-01 14:21:43 -0500241 new LogMaker(MetricsEvent.LOCKSCREEN)
242 .setType(MetricsEvent.TYPE_OPEN)
243 .setSubtype(0));
244 }
245
Adrian Roos02de4982017-02-11 09:35:54 +0100246 @Test
Chris Wren27a52fa2017-02-01 14:21:43 -0500247 public void lockscreenStateMetrics_isShowing_secure() {
248 // uninteresting state, except that fingerprint must be non-zero
249 when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false);
250 when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true);
251 // interesting state
252 when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true);
253 when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false);
254 when(mUnlockMethodCache.isMethodSecure()).thenReturn(true);
255
256 mStatusBar.onKeyguardViewManagerStatesUpdated();
257
Chris Wrenef319902017-03-07 17:58:31 -0500258 MetricsAsserts.assertHasLog("missing secure lockscreen showing log",
259 mMetricsLogger.getLogs(),
Chris Wren27a52fa2017-02-01 14:21:43 -0500260 new LogMaker(MetricsEvent.LOCKSCREEN)
261 .setType(MetricsEvent.TYPE_OPEN)
262 .setSubtype(1));
263 }
264
Adrian Roos02de4982017-02-11 09:35:54 +0100265 @Test
Chris Wren27a52fa2017-02-01 14:21:43 -0500266 public void lockscreenStateMetrics_isShowingBouncer() {
267 // uninteresting state, except that fingerprint must be non-zero
268 when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false);
269 when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true);
270 // interesting state
271 when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true);
272 when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true);
273 when(mUnlockMethodCache.isMethodSecure()).thenReturn(true);
274
275 mStatusBar.onKeyguardViewManagerStatesUpdated();
276
Chris Wrenef319902017-03-07 17:58:31 -0500277 MetricsAsserts.assertHasLog("missing bouncer log",
278 mMetricsLogger.getLogs(),
Chris Wren27a52fa2017-02-01 14:21:43 -0500279 new LogMaker(MetricsEvent.BOUNCER)
280 .setType(MetricsEvent.TYPE_OPEN)
281 .setSubtype(1));
282 }
283
Adrian Roos02de4982017-02-11 09:35:54 +0100284 @Test
Chris Wren27a52fa2017-02-01 14:21:43 -0500285 public void onActivatedMetrics() {
286 ActivatableNotificationView view = mock(ActivatableNotificationView.class);
287 mStatusBar.onActivated(view);
288
Chris Wrenef319902017-03-07 17:58:31 -0500289 MetricsAsserts.assertHasLog("missing lockscreen note tap log",
290 mMetricsLogger.getLogs(),
Chris Wren27a52fa2017-02-01 14:21:43 -0500291 new LogMaker(MetricsEvent.ACTION_LS_NOTE)
292 .setType(MetricsEvent.TYPE_ACTION));
293 }
294
Julia Reynolds30203152017-05-26 13:36:31 -0400295 @Test
296 public void testShouldPeek_nonSuppressedGroupSummary() {
297 when(mPowerManager.isScreenOn()).thenReturn(true);
298 when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false);
299 when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false);
300 when(mNotificationData.shouldFilterOut(any())).thenReturn(false);
301 when(mSystemServicesProxy.isDreaming()).thenReturn(false);
302 when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH);
303
304 Notification n = new Notification.Builder(getContext(), "a")
305 .setGroup("a")
306 .setGroupSummary(true)
307 .setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY)
308 .build();
309 StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n,
310 UserHandle.of(0), null, 0);
311 NotificationData.Entry entry = new NotificationData.Entry(sbn);
312
313 assertTrue(mStatusBar.shouldPeek(entry, sbn));
314 }
315
316 @Test
317 public void testShouldPeek_suppressedGroupSummary() {
318 when(mPowerManager.isScreenOn()).thenReturn(true);
319 when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false);
320 when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false);
321 when(mNotificationData.shouldFilterOut(any())).thenReturn(false);
322 when(mSystemServicesProxy.isDreaming()).thenReturn(false);
323 when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH);
324
325 Notification n = new Notification.Builder(getContext(), "a")
326 .setGroup("a")
327 .setGroupSummary(true)
328 .setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN)
329 .build();
330 StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n,
331 UserHandle.of(0), null, 0);
332 NotificationData.Entry entry = new NotificationData.Entry(sbn);
333
334 assertFalse(mStatusBar.shouldPeek(entry, sbn));
335 }
336
Chris Wren621933f2017-06-14 15:59:03 -0400337 @Test
Beverly38159ce2017-07-13 16:39:24 -0400338 public void testShouldPeek_suppressedScreenOn_dozing() {
339 when(mPowerManager.isScreenOn()).thenReturn(true);
340 when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false);
341 when(mNotificationData.shouldFilterOut(any())).thenReturn(false);
342 when(mSystemServicesProxy.isDreaming()).thenReturn(false);
343 when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH);
344
345 mStatusBar.mDozing = true;
346 when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(true);
347 when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(false);
348
349 Notification n = new Notification.Builder(getContext(), "a").build();
350 StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n,
351 UserHandle.of(0), null, 0);
352 NotificationData.Entry entry = new NotificationData.Entry(sbn);
353
354 assertTrue(mStatusBar.shouldPeek(entry, sbn));
355 }
356
357 @Test
358 public void testShouldPeek_suppressedScreenOn_noDoze() {
359 when(mPowerManager.isScreenOn()).thenReturn(true);
360 when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false);
361 when(mNotificationData.shouldFilterOut(any())).thenReturn(false);
362 when(mSystemServicesProxy.isDreaming()).thenReturn(false);
363 when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH);
364
365 mStatusBar.mDozing = false;
366 when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(true);
367 when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(false);
368
369 Notification n = new Notification.Builder(getContext(), "a").build();
370 StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n,
371 UserHandle.of(0), null, 0);
372 NotificationData.Entry entry = new NotificationData.Entry(sbn);
373 assertFalse(mStatusBar.shouldPeek(entry, sbn));
374 }
375 @Test
376 public void testShouldPeek_suppressedScreenOff_dozing() {
377 when(mPowerManager.isScreenOn()).thenReturn(true);
378 when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false);
379 when(mNotificationData.shouldFilterOut(any())).thenReturn(false);
380 when(mSystemServicesProxy.isDreaming()).thenReturn(false);
381 when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH);
382
383 mStatusBar.mDozing = true;
384 when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false);
385 when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(true);
386
387 Notification n = new Notification.Builder(getContext(), "a").build();
388 StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n,
389 UserHandle.of(0), null, 0);
390 NotificationData.Entry entry = new NotificationData.Entry(sbn);
391 assertFalse(mStatusBar.shouldPeek(entry, sbn));
392 }
393
394 @Test
395 public void testShouldPeek_suppressedScreenOff_noDoze() {
396 when(mPowerManager.isScreenOn()).thenReturn(true);
397 when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false);
398 when(mNotificationData.shouldFilterOut(any())).thenReturn(false);
399 when(mSystemServicesProxy.isDreaming()).thenReturn(false);
400 when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH);
401
402 mStatusBar.mDozing = false;
403 when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false);
404 when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(true);
405
406 Notification n = new Notification.Builder(getContext(), "a").build();
407 StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n,
408 UserHandle.of(0), null, 0);
409 NotificationData.Entry entry = new NotificationData.Entry(sbn);
410 assertTrue(mStatusBar.shouldPeek(entry, sbn));
411 }
412
413
414 @Test
Chris Wren621933f2017-06-14 15:59:03 -0400415 public void testLogHidden() {
416 try {
417 mStatusBar.handleVisibleToUserChanged(false);
418 verify(mBarService, times(1)).onPanelHidden();
419 verify(mBarService, never()).onPanelRevealed(anyBoolean(), anyInt());
420 } catch (RemoteException e) {
421 fail();
422 }
423 }
424
425 @Test
426 public void testPanelOpenForPeek() {
427 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
428 when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList);
429 when(mNotificationList.size()).thenReturn(5);
430 when(mNotificationPanelView.isFullyCollapsed()).thenReturn(true);
431 mStatusBar.setBarStateForTest(StatusBarState.SHADE);
432
433 try {
434 mStatusBar.handleVisibleToUserChanged(true);
435
436 verify(mBarService, never()).onPanelHidden();
437 verify(mBarService, times(1)).onPanelRevealed(false, 1);
438 } catch (RemoteException e) {
439 fail();
440 }
441 TestableLooper.get(this).processAllMessages();
442 }
443
444 @Test
445 public void testPanelOpenAndClear() {
446 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
447 when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList);
448 when(mNotificationList.size()).thenReturn(5);
449 when(mNotificationPanelView.isFullyCollapsed()).thenReturn(false);
450 mStatusBar.setBarStateForTest(StatusBarState.SHADE);
451
452 try {
453 mStatusBar.handleVisibleToUserChanged(true);
454
455 verify(mBarService, never()).onPanelHidden();
456 verify(mBarService, times(1)).onPanelRevealed(true, 5);
457 } catch (RemoteException e) {
458 fail();
459 }
460 TestableLooper.get(this).processAllMessages();
461 }
462
463 @Test
464 public void testPanelOpenAndNoClear() {
465 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
466 when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList);
467 when(mNotificationList.size()).thenReturn(5);
468 when(mNotificationPanelView.isFullyCollapsed()).thenReturn(false);
469 mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD);
470
471 try {
472 mStatusBar.handleVisibleToUserChanged(true);
473
474 verify(mBarService, never()).onPanelHidden();
475 verify(mBarService, times(1)).onPanelRevealed(false, 5);
476 } catch (RemoteException e) {
477 fail();
478 }
479 TestableLooper.get(this).processAllMessages();
480 }
481
Jason Monk51305372017-06-22 11:41:08 -0400482 @Test
483 public void testDump_DoesNotCrash() {
484 mStatusBar.dump(null, new PrintWriter(new ByteArrayOutputStream()), null);
485 }
486
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500487 static class TestableStatusBar extends StatusBar {
Chris Wren27a52fa2017-02-01 14:21:43 -0500488 public TestableStatusBar(StatusBarKeyguardViewManager man,
489 UnlockMethodCache unlock, KeyguardIndicationController key,
Julia Reynolds30203152017-05-26 13:36:31 -0400490 NotificationStackScrollLayout stack, HeadsUpManager hum, NotificationData nd,
Chris Wren621933f2017-06-14 15:59:03 -0400491 PowerManager pm, SystemServicesProxy ssp, NotificationPanelView panelView,
492 IStatusBarService barService) {
Adrian Roosef7a4022017-01-19 14:48:35 -0800493 mStatusBarKeyguardViewManager = man;
Chris Wren27a52fa2017-02-01 14:21:43 -0500494 mUnlockMethodCache = unlock;
495 mKeyguardIndicationController = key;
496 mStackScroller = stack;
Julia Reynolds30203152017-05-26 13:36:31 -0400497 mHeadsUpManager = hum;
498 mNotificationData = nd;
499 mUseHeadsUp = true;
500 mPowerManager = pm;
501 mSystemServicesProxy = ssp;
Jorim Jaggifd3b1a12017-06-06 17:04:19 -0700502 mNotificationPanel = panelView;
Chris Wren621933f2017-06-14 15:59:03 -0400503 mBarService = barService;
Adrian Roos6d5ebb72017-08-03 15:10:22 +0200504 mWakefulnessLifecycle = createAwakeWakefulnessLifecycle();
505 }
506
507 private WakefulnessLifecycle createAwakeWakefulnessLifecycle() {
508 WakefulnessLifecycle wakefulnessLifecycle = new WakefulnessLifecycle();
509 wakefulnessLifecycle.dispatchStartedWakingUp();
510 wakefulnessLifecycle.dispatchFinishedWakingUp();
511 return wakefulnessLifecycle;
Adrian Roosef7a4022017-01-19 14:48:35 -0800512 }
513
Chris Wren621933f2017-06-14 15:59:03 -0400514 public void setBarStateForTest(int state) {
515 mState = state;
Adrian Roosef7a4022017-01-19 14:48:35 -0800516 }
517 }
Adrian Roos02de4982017-02-11 09:35:54 +0100518}