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; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 29 | import static org.mockito.Matchers.any; |
| 30 | import static org.mockito.Matchers.anyBoolean; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 31 | import static org.mockito.Matchers.anyInt; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 32 | import static org.mockito.Matchers.anyString; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 33 | import static org.mockito.Mockito.doAnswer; |
| 34 | import static org.mockito.Mockito.mock; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 35 | import static org.mockito.Mockito.never; |
| 36 | import static org.mockito.Mockito.times; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 37 | import static org.mockito.Mockito.when; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 38 | import static org.mockito.Mockito.verify; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 39 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 40 | import android.app.Notification; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 41 | import android.metrics.LogMaker; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 42 | import android.os.Handler; |
| 43 | import android.os.HandlerThread; |
| 44 | import android.os.IPowerManager; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 45 | import android.os.Message; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 46 | import android.os.PowerManager; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 47 | import android.os.RemoteException; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 48 | import android.os.UserHandle; |
| 49 | import android.service.notification.StatusBarNotification; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 50 | import android.support.test.filters.SmallTest; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 51 | import android.support.test.metricshelper.MetricsAsserts; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 52 | import android.support.test.runner.AndroidJUnit4; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 53 | import android.testing.AndroidTestingRunner; |
| 54 | import android.testing.TestableLooper; |
| 55 | import android.testing.TestableLooper.MessageHandler; |
| 56 | import android.testing.TestableLooper.RunWithLooper; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 57 | import android.util.DisplayMetrics; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 58 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 59 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 60 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 61 | import com.android.internal.logging.testing.FakeMetricsLogger; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 62 | import com.android.internal.statusbar.IStatusBarService; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 63 | import com.android.keyguard.KeyguardHostView.OnDismissAction; |
| 64 | import com.android.systemui.SysuiTestCase; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 65 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 66 | import com.android.systemui.statusbar.ActivatableNotificationView; |
| 67 | import com.android.systemui.statusbar.KeyguardIndicationController; |
| 68 | import com.android.systemui.statusbar.NotificationData; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 69 | import com.android.systemui.statusbar.NotificationData.Entry; |
| 70 | import com.android.systemui.statusbar.StatusBarState; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 71 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 72 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 73 | |
| 74 | import org.junit.Before; |
| 75 | import org.junit.Test; |
| 76 | import org.junit.runner.RunWith; |
| 77 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 78 | import java.util.ArrayList; |
| 79 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 80 | @SmallTest |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 81 | @RunWith(AndroidTestingRunner.class) |
| 82 | @RunWithLooper |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 83 | public class StatusBarTest extends SysuiTestCase { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 84 | |
| 85 | StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 86 | UnlockMethodCache mUnlockMethodCache; |
| 87 | KeyguardIndicationController mKeyguardIndicationController; |
| 88 | NotificationStackScrollLayout mStackScroller; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 89 | TestableStatusBar mStatusBar; |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 90 | FakeMetricsLogger mMetricsLogger; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 91 | HeadsUpManager mHeadsUpManager; |
| 92 | NotificationData mNotificationData; |
| 93 | PowerManager mPowerManager; |
| 94 | SystemServicesProxy mSystemServicesProxy; |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 95 | NotificationPanelView mNotificationPanelView; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 96 | IStatusBarService mBarService; |
| 97 | ArrayList<Entry> mNotificationList; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 98 | private DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
| 99 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 100 | @Before |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 101 | public void setup() throws Exception { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 102 | mStatusBarKeyguardViewManager = mock(StatusBarKeyguardViewManager.class); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 103 | mUnlockMethodCache = mock(UnlockMethodCache.class); |
| 104 | mKeyguardIndicationController = mock(KeyguardIndicationController.class); |
| 105 | mStackScroller = mock(NotificationStackScrollLayout.class); |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 106 | mMetricsLogger = new FakeMetricsLogger(); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 107 | mHeadsUpManager = mock(HeadsUpManager.class); |
| 108 | mNotificationData = mock(NotificationData.class); |
| 109 | mSystemServicesProxy = mock(SystemServicesProxy.class); |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 110 | mNotificationPanelView = mock(NotificationPanelView.class); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 111 | mNotificationList = mock(ArrayList.class); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 112 | IPowerManager powerManagerService = mock(IPowerManager.class); |
| 113 | HandlerThread handlerThread = new HandlerThread("TestThread"); |
| 114 | handlerThread.start(); |
| 115 | mPowerManager = new PowerManager(mContext, powerManagerService, |
| 116 | new Handler(handlerThread.getLooper())); |
| 117 | when(powerManagerService.isInteractive()).thenReturn(true); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 118 | mBarService = mock(IStatusBarService.class); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 119 | |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 120 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 121 | mStatusBar = new TestableStatusBar(mStatusBarKeyguardViewManager, mUnlockMethodCache, |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 122 | mKeyguardIndicationController, mStackScroller, mHeadsUpManager, |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 123 | mNotificationData, mPowerManager, mSystemServicesProxy, mNotificationPanelView, |
| 124 | mBarService); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 125 | doAnswer(invocation -> { |
| 126 | OnDismissAction onDismissAction = (OnDismissAction) invocation.getArguments()[0]; |
| 127 | onDismissAction.onDismiss(); |
| 128 | return null; |
| 129 | }).when(mStatusBarKeyguardViewManager).dismissWithAction(any(), any(), anyBoolean()); |
| 130 | |
| 131 | doAnswer(invocation -> { |
| 132 | Runnable runnable = (Runnable) invocation.getArguments()[0]; |
| 133 | runnable.run(); |
| 134 | return null; |
| 135 | }).when(mStatusBarKeyguardViewManager).addAfterKeyguardGoneRunnable(any()); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 136 | |
| 137 | when(mStackScroller.getActivatedChild()).thenReturn(null); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 138 | TestableLooper.get(this).setMessageHandler(new MessageHandler() { |
| 139 | @Override |
| 140 | public boolean onMessageHandled(Message m) { |
| 141 | if (m.getCallback() == mStatusBar.mVisibilityReporter) { |
| 142 | return false; |
| 143 | } |
| 144 | return true; |
| 145 | } |
| 146 | }); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 149 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 150 | public void executeRunnableDismissingKeyguard_nullRunnable_showingAndOccluded() { |
| 151 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 152 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(true); |
| 153 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 154 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 155 | } |
| 156 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 157 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 158 | public void executeRunnableDismissingKeyguard_nullRunnable_showing() { |
| 159 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 160 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 161 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 162 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 163 | } |
| 164 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 165 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 166 | public void executeRunnableDismissingKeyguard_nullRunnable_notShowing() { |
| 167 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 168 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 169 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 170 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 173 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 174 | public void lockscreenStateMetrics_notShowing() { |
| 175 | // uninteresting state, except that fingerprint must be non-zero |
| 176 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 177 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 178 | // interesting state |
| 179 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 180 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 181 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(false); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 182 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 183 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 184 | MetricsAsserts.assertHasLog("missing hidden insecure lockscreen log", |
| 185 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 186 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 187 | .setType(MetricsEvent.TYPE_CLOSE) |
| 188 | .setSubtype(0)); |
| 189 | } |
| 190 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 191 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 192 | public void lockscreenStateMetrics_notShowing_secure() { |
| 193 | // uninteresting state, except that fingerprint must be non-zero |
| 194 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 195 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 196 | // interesting state |
| 197 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 198 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 199 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 200 | |
| 201 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 202 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 203 | MetricsAsserts.assertHasLog("missing hidden secure lockscreen log", |
| 204 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 205 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 206 | .setType(MetricsEvent.TYPE_CLOSE) |
| 207 | .setSubtype(1)); |
| 208 | } |
| 209 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 210 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 211 | public void lockscreenStateMetrics_isShowing() { |
| 212 | // uninteresting state, except that fingerprint must be non-zero |
| 213 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 214 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 215 | // interesting state |
| 216 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 217 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 218 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(false); |
| 219 | |
| 220 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 221 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 222 | MetricsAsserts.assertHasLog("missing insecure lockscreen showing", |
| 223 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 224 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 225 | .setType(MetricsEvent.TYPE_OPEN) |
| 226 | .setSubtype(0)); |
| 227 | } |
| 228 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 229 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 230 | public void lockscreenStateMetrics_isShowing_secure() { |
| 231 | // uninteresting state, except that fingerprint must be non-zero |
| 232 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 233 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 234 | // interesting state |
| 235 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 236 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 237 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 238 | |
| 239 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 240 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 241 | MetricsAsserts.assertHasLog("missing secure lockscreen showing log", |
| 242 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 243 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 244 | .setType(MetricsEvent.TYPE_OPEN) |
| 245 | .setSubtype(1)); |
| 246 | } |
| 247 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 248 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 249 | public void lockscreenStateMetrics_isShowingBouncer() { |
| 250 | // uninteresting state, except that fingerprint must be non-zero |
| 251 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 252 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 253 | // interesting state |
| 254 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 255 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); |
| 256 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 257 | |
| 258 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 259 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 260 | MetricsAsserts.assertHasLog("missing bouncer log", |
| 261 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 262 | new LogMaker(MetricsEvent.BOUNCER) |
| 263 | .setType(MetricsEvent.TYPE_OPEN) |
| 264 | .setSubtype(1)); |
| 265 | } |
| 266 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 267 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 268 | public void onActivatedMetrics() { |
| 269 | ActivatableNotificationView view = mock(ActivatableNotificationView.class); |
| 270 | mStatusBar.onActivated(view); |
| 271 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 272 | MetricsAsserts.assertHasLog("missing lockscreen note tap log", |
| 273 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 274 | new LogMaker(MetricsEvent.ACTION_LS_NOTE) |
| 275 | .setType(MetricsEvent.TYPE_ACTION)); |
| 276 | } |
| 277 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 278 | @Test |
| 279 | public void testShouldPeek_nonSuppressedGroupSummary() { |
| 280 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 281 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 282 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); |
| 283 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 284 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 285 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 286 | |
| 287 | Notification n = new Notification.Builder(getContext(), "a") |
| 288 | .setGroup("a") |
| 289 | .setGroupSummary(true) |
| 290 | .setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY) |
| 291 | .build(); |
| 292 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 293 | UserHandle.of(0), null, 0); |
| 294 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 295 | |
| 296 | assertTrue(mStatusBar.shouldPeek(entry, sbn)); |
| 297 | } |
| 298 | |
| 299 | @Test |
| 300 | public void testShouldPeek_suppressedGroupSummary() { |
| 301 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 302 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 303 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); |
| 304 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 305 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 306 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 307 | |
| 308 | Notification n = new Notification.Builder(getContext(), "a") |
| 309 | .setGroup("a") |
| 310 | .setGroupSummary(true) |
| 311 | .setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN) |
| 312 | .build(); |
| 313 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 314 | UserHandle.of(0), null, 0); |
| 315 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 316 | |
| 317 | assertFalse(mStatusBar.shouldPeek(entry, sbn)); |
| 318 | } |
| 319 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 320 | @Test |
| 321 | public void testLogHidden() { |
| 322 | try { |
| 323 | mStatusBar.handleVisibleToUserChanged(false); |
| 324 | verify(mBarService, times(1)).onPanelHidden(); |
| 325 | verify(mBarService, never()).onPanelRevealed(anyBoolean(), anyInt()); |
| 326 | } catch (RemoteException e) { |
| 327 | fail(); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | @Test |
| 332 | public void testPanelOpenForPeek() { |
| 333 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); |
| 334 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 335 | when(mNotificationList.size()).thenReturn(5); |
| 336 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(true); |
| 337 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 338 | |
| 339 | try { |
| 340 | mStatusBar.handleVisibleToUserChanged(true); |
| 341 | |
| 342 | verify(mBarService, never()).onPanelHidden(); |
| 343 | verify(mBarService, times(1)).onPanelRevealed(false, 1); |
| 344 | } catch (RemoteException e) { |
| 345 | fail(); |
| 346 | } |
| 347 | TestableLooper.get(this).processAllMessages(); |
| 348 | } |
| 349 | |
| 350 | @Test |
| 351 | public void testPanelOpenAndClear() { |
| 352 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 353 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 354 | when(mNotificationList.size()).thenReturn(5); |
| 355 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(false); |
| 356 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 357 | |
| 358 | try { |
| 359 | mStatusBar.handleVisibleToUserChanged(true); |
| 360 | |
| 361 | verify(mBarService, never()).onPanelHidden(); |
| 362 | verify(mBarService, times(1)).onPanelRevealed(true, 5); |
| 363 | } catch (RemoteException e) { |
| 364 | fail(); |
| 365 | } |
| 366 | TestableLooper.get(this).processAllMessages(); |
| 367 | } |
| 368 | |
| 369 | @Test |
| 370 | public void testPanelOpenAndNoClear() { |
| 371 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 372 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 373 | when(mNotificationList.size()).thenReturn(5); |
| 374 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(false); |
| 375 | mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD); |
| 376 | |
| 377 | try { |
| 378 | mStatusBar.handleVisibleToUserChanged(true); |
| 379 | |
| 380 | verify(mBarService, never()).onPanelHidden(); |
| 381 | verify(mBarService, times(1)).onPanelRevealed(false, 5); |
| 382 | } catch (RemoteException e) { |
| 383 | fail(); |
| 384 | } |
| 385 | TestableLooper.get(this).processAllMessages(); |
| 386 | } |
| 387 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 388 | static class TestableStatusBar extends StatusBar { |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 389 | public TestableStatusBar(StatusBarKeyguardViewManager man, |
| 390 | UnlockMethodCache unlock, KeyguardIndicationController key, |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 391 | NotificationStackScrollLayout stack, HeadsUpManager hum, NotificationData nd, |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 392 | PowerManager pm, SystemServicesProxy ssp, NotificationPanelView panelView, |
| 393 | IStatusBarService barService) { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 394 | mStatusBarKeyguardViewManager = man; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 395 | mUnlockMethodCache = unlock; |
| 396 | mKeyguardIndicationController = key; |
| 397 | mStackScroller = stack; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 398 | mHeadsUpManager = hum; |
| 399 | mNotificationData = nd; |
| 400 | mUseHeadsUp = true; |
| 401 | mPowerManager = pm; |
| 402 | mSystemServicesProxy = ssp; |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 403 | mNotificationPanel = panelView; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 404 | mBarService = barService; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame^] | 407 | public void setBarStateForTest(int state) { |
| 408 | mState = state; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 409 | } |
| 410 | } |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 411 | } |