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; |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 41 | import android.app.trust.TrustManager; |
| 42 | import android.hardware.fingerprint.FingerprintManager; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 43 | import android.metrics.LogMaker; |
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; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 47 | import android.os.Message; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 48 | import android.os.PowerManager; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 49 | import android.os.RemoteException; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 50 | import android.os.UserHandle; |
| 51 | import android.service.notification.StatusBarNotification; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 52 | import android.support.test.filters.SmallTest; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 53 | import android.support.test.metricshelper.MetricsAsserts; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 54 | import android.support.test.runner.AndroidJUnit4; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 55 | import android.testing.AndroidTestingRunner; |
| 56 | import android.testing.TestableLooper; |
| 57 | import android.testing.TestableLooper.MessageHandler; |
| 58 | import android.testing.TestableLooper.RunWithLooper; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 59 | import android.util.DisplayMetrics; |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 60 | import android.view.ViewGroup.LayoutParams; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 61 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 62 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 63 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 64 | import com.android.internal.logging.testing.FakeMetricsLogger; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 65 | import com.android.internal.statusbar.IStatusBarService; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 66 | import com.android.keyguard.KeyguardHostView.OnDismissAction; |
| 67 | import com.android.systemui.SysuiTestCase; |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame^] | 68 | import com.android.systemui.keyguard.WakefulnessLifecycle; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 69 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 70 | import com.android.systemui.statusbar.ActivatableNotificationView; |
Jason Monk | 5ecf80c | 2017-07-06 15:28:17 -0400 | [diff] [blame] | 71 | import com.android.systemui.statusbar.CommandQueue; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 72 | import com.android.systemui.statusbar.KeyguardIndicationController; |
| 73 | import com.android.systemui.statusbar.NotificationData; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 74 | import com.android.systemui.statusbar.NotificationData.Entry; |
| 75 | import com.android.systemui.statusbar.StatusBarState; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 76 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 77 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 78 | |
| 79 | import org.junit.Before; |
| 80 | import org.junit.Test; |
| 81 | import org.junit.runner.RunWith; |
| 82 | |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 83 | import java.io.ByteArrayOutputStream; |
| 84 | import java.io.PrintWriter; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 85 | import java.util.ArrayList; |
| 86 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 87 | @SmallTest |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 88 | @RunWith(AndroidTestingRunner.class) |
| 89 | @RunWithLooper |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 90 | public class StatusBarTest extends SysuiTestCase { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 91 | |
| 92 | StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 93 | UnlockMethodCache mUnlockMethodCache; |
| 94 | KeyguardIndicationController mKeyguardIndicationController; |
| 95 | NotificationStackScrollLayout mStackScroller; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 96 | TestableStatusBar mStatusBar; |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 97 | FakeMetricsLogger mMetricsLogger; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 98 | HeadsUpManager mHeadsUpManager; |
| 99 | NotificationData mNotificationData; |
| 100 | PowerManager mPowerManager; |
| 101 | SystemServicesProxy mSystemServicesProxy; |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 102 | NotificationPanelView mNotificationPanelView; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 103 | IStatusBarService mBarService; |
| 104 | ArrayList<Entry> mNotificationList; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 105 | private DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
| 106 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 107 | @Before |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 108 | public void setup() throws Exception { |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 109 | mContext.addMockSystemService(TrustManager.class, mock(TrustManager.class)); |
| 110 | mContext.addMockSystemService(FingerprintManager.class, mock(FingerprintManager.class)); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 111 | mStatusBarKeyguardViewManager = mock(StatusBarKeyguardViewManager.class); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 112 | mUnlockMethodCache = mock(UnlockMethodCache.class); |
| 113 | mKeyguardIndicationController = mock(KeyguardIndicationController.class); |
| 114 | mStackScroller = mock(NotificationStackScrollLayout.class); |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 115 | mMetricsLogger = new FakeMetricsLogger(); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 116 | mHeadsUpManager = mock(HeadsUpManager.class); |
| 117 | mNotificationData = mock(NotificationData.class); |
| 118 | mSystemServicesProxy = mock(SystemServicesProxy.class); |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 119 | mNotificationPanelView = mock(NotificationPanelView.class); |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 120 | when(mNotificationPanelView.getLayoutParams()).thenReturn(new LayoutParams(0, 0)); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 121 | mNotificationList = mock(ArrayList.class); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 122 | 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 Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 128 | mBarService = mock(IStatusBarService.class); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 129 | |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 130 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 131 | mStatusBar = new TestableStatusBar(mStatusBarKeyguardViewManager, mUnlockMethodCache, |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 132 | mKeyguardIndicationController, mStackScroller, mHeadsUpManager, |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 133 | mNotificationData, mPowerManager, mSystemServicesProxy, mNotificationPanelView, |
| 134 | mBarService); |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 135 | mStatusBar.mContext = mContext; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 136 | 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 Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 147 | |
| 148 | when(mStackScroller.getActivatedChild()).thenReturn(null); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 149 | 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 Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 160 | @Test |
Jason Monk | 5ecf80c | 2017-07-06 15:28:17 -0400 | [diff] [blame] | 161 | public void testSetBouncerShowing_noCrash() { |
| 162 | mStatusBar.mCommandQueue = mock(CommandQueue.class); |
| 163 | mStatusBar.setBouncerShowing(true); |
| 164 | } |
| 165 | |
| 166 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 167 | public void executeRunnableDismissingKeyguard_nullRunnable_showingAndOccluded() { |
| 168 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 169 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(true); |
| 170 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 171 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 172 | } |
| 173 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 174 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 175 | public void executeRunnableDismissingKeyguard_nullRunnable_showing() { |
| 176 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 177 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 178 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 179 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 180 | } |
| 181 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 182 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 183 | public void executeRunnableDismissingKeyguard_nullRunnable_notShowing() { |
| 184 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 185 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 186 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 187 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 188 | } |
| 189 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 190 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 191 | 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 Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 199 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 200 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 201 | MetricsAsserts.assertHasLog("missing hidden insecure lockscreen log", |
| 202 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 203 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 204 | .setType(MetricsEvent.TYPE_CLOSE) |
| 205 | .setSubtype(0)); |
| 206 | } |
| 207 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 208 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 209 | 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 Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 220 | MetricsAsserts.assertHasLog("missing hidden secure lockscreen log", |
| 221 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 222 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 223 | .setType(MetricsEvent.TYPE_CLOSE) |
| 224 | .setSubtype(1)); |
| 225 | } |
| 226 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 227 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 228 | 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 Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 239 | MetricsAsserts.assertHasLog("missing insecure lockscreen showing", |
| 240 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 241 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 242 | .setType(MetricsEvent.TYPE_OPEN) |
| 243 | .setSubtype(0)); |
| 244 | } |
| 245 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 246 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 247 | 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 Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 258 | MetricsAsserts.assertHasLog("missing secure lockscreen showing log", |
| 259 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 260 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 261 | .setType(MetricsEvent.TYPE_OPEN) |
| 262 | .setSubtype(1)); |
| 263 | } |
| 264 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 265 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 266 | 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 Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 277 | MetricsAsserts.assertHasLog("missing bouncer log", |
| 278 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 279 | new LogMaker(MetricsEvent.BOUNCER) |
| 280 | .setType(MetricsEvent.TYPE_OPEN) |
| 281 | .setSubtype(1)); |
| 282 | } |
| 283 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 284 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 285 | public void onActivatedMetrics() { |
| 286 | ActivatableNotificationView view = mock(ActivatableNotificationView.class); |
| 287 | mStatusBar.onActivated(view); |
| 288 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 289 | MetricsAsserts.assertHasLog("missing lockscreen note tap log", |
| 290 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 291 | new LogMaker(MetricsEvent.ACTION_LS_NOTE) |
| 292 | .setType(MetricsEvent.TYPE_ACTION)); |
| 293 | } |
| 294 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 295 | @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 Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 337 | @Test |
Beverly | 38159ce | 2017-07-13 16:39:24 -0400 | [diff] [blame] | 338 | 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 Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 415 | 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 Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 482 | @Test |
| 483 | public void testDump_DoesNotCrash() { |
| 484 | mStatusBar.dump(null, new PrintWriter(new ByteArrayOutputStream()), null); |
| 485 | } |
| 486 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 487 | static class TestableStatusBar extends StatusBar { |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 488 | public TestableStatusBar(StatusBarKeyguardViewManager man, |
| 489 | UnlockMethodCache unlock, KeyguardIndicationController key, |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 490 | NotificationStackScrollLayout stack, HeadsUpManager hum, NotificationData nd, |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 491 | PowerManager pm, SystemServicesProxy ssp, NotificationPanelView panelView, |
| 492 | IStatusBarService barService) { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 493 | mStatusBarKeyguardViewManager = man; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 494 | mUnlockMethodCache = unlock; |
| 495 | mKeyguardIndicationController = key; |
| 496 | mStackScroller = stack; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 497 | mHeadsUpManager = hum; |
| 498 | mNotificationData = nd; |
| 499 | mUseHeadsUp = true; |
| 500 | mPowerManager = pm; |
| 501 | mSystemServicesProxy = ssp; |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 502 | mNotificationPanel = panelView; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 503 | mBarService = barService; |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame^] | 504 | mWakefulnessLifecycle = createAwakeWakefulnessLifecycle(); |
| 505 | } |
| 506 | |
| 507 | private WakefulnessLifecycle createAwakeWakefulnessLifecycle() { |
| 508 | WakefulnessLifecycle wakefulnessLifecycle = new WakefulnessLifecycle(); |
| 509 | wakefulnessLifecycle.dispatchStartedWakingUp(); |
| 510 | wakefulnessLifecycle.dispatchFinishedWakingUp(); |
| 511 | return wakefulnessLifecycle; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 512 | } |
| 513 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 514 | public void setBarStateForTest(int state) { |
| 515 | mState = state; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 516 | } |
| 517 | } |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 518 | } |