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; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 68 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 69 | import com.android.systemui.statusbar.ActivatableNotificationView; |
Jason Monk | 5ecf80c | 2017-07-06 15:28:17 -0400 | [diff] [blame] | 70 | import com.android.systemui.statusbar.CommandQueue; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 71 | import com.android.systemui.statusbar.KeyguardIndicationController; |
| 72 | import com.android.systemui.statusbar.NotificationData; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 73 | import com.android.systemui.statusbar.NotificationData.Entry; |
| 74 | import com.android.systemui.statusbar.StatusBarState; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 75 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 76 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 77 | |
| 78 | import org.junit.Before; |
| 79 | import org.junit.Test; |
| 80 | import org.junit.runner.RunWith; |
| 81 | |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 82 | import java.io.ByteArrayOutputStream; |
| 83 | import java.io.PrintWriter; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 84 | import java.util.ArrayList; |
| 85 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 86 | @SmallTest |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 87 | @RunWith(AndroidTestingRunner.class) |
| 88 | @RunWithLooper |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 89 | public class StatusBarTest extends SysuiTestCase { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 90 | |
| 91 | StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 92 | UnlockMethodCache mUnlockMethodCache; |
| 93 | KeyguardIndicationController mKeyguardIndicationController; |
| 94 | NotificationStackScrollLayout mStackScroller; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 95 | TestableStatusBar mStatusBar; |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 96 | FakeMetricsLogger mMetricsLogger; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 97 | HeadsUpManager mHeadsUpManager; |
| 98 | NotificationData mNotificationData; |
| 99 | PowerManager mPowerManager; |
| 100 | SystemServicesProxy mSystemServicesProxy; |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 101 | NotificationPanelView mNotificationPanelView; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 102 | IStatusBarService mBarService; |
| 103 | ArrayList<Entry> mNotificationList; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 104 | private DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
| 105 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 106 | @Before |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 107 | public void setup() throws Exception { |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 108 | mContext.addMockSystemService(TrustManager.class, mock(TrustManager.class)); |
| 109 | mContext.addMockSystemService(FingerprintManager.class, mock(FingerprintManager.class)); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 110 | mStatusBarKeyguardViewManager = mock(StatusBarKeyguardViewManager.class); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 111 | mUnlockMethodCache = mock(UnlockMethodCache.class); |
| 112 | mKeyguardIndicationController = mock(KeyguardIndicationController.class); |
| 113 | mStackScroller = mock(NotificationStackScrollLayout.class); |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 114 | mMetricsLogger = new FakeMetricsLogger(); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 115 | mHeadsUpManager = mock(HeadsUpManager.class); |
| 116 | mNotificationData = mock(NotificationData.class); |
| 117 | mSystemServicesProxy = mock(SystemServicesProxy.class); |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 118 | mNotificationPanelView = mock(NotificationPanelView.class); |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 119 | when(mNotificationPanelView.getLayoutParams()).thenReturn(new LayoutParams(0, 0)); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 120 | mNotificationList = mock(ArrayList.class); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 121 | IPowerManager powerManagerService = mock(IPowerManager.class); |
| 122 | HandlerThread handlerThread = new HandlerThread("TestThread"); |
| 123 | handlerThread.start(); |
| 124 | mPowerManager = new PowerManager(mContext, powerManagerService, |
| 125 | new Handler(handlerThread.getLooper())); |
| 126 | when(powerManagerService.isInteractive()).thenReturn(true); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 127 | mBarService = mock(IStatusBarService.class); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 128 | |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 129 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 130 | mStatusBar = new TestableStatusBar(mStatusBarKeyguardViewManager, mUnlockMethodCache, |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 131 | mKeyguardIndicationController, mStackScroller, mHeadsUpManager, |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 132 | mNotificationData, mPowerManager, mSystemServicesProxy, mNotificationPanelView, |
| 133 | mBarService); |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 134 | mStatusBar.mContext = mContext; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 135 | doAnswer(invocation -> { |
| 136 | OnDismissAction onDismissAction = (OnDismissAction) invocation.getArguments()[0]; |
| 137 | onDismissAction.onDismiss(); |
| 138 | return null; |
| 139 | }).when(mStatusBarKeyguardViewManager).dismissWithAction(any(), any(), anyBoolean()); |
| 140 | |
| 141 | doAnswer(invocation -> { |
| 142 | Runnable runnable = (Runnable) invocation.getArguments()[0]; |
| 143 | runnable.run(); |
| 144 | return null; |
| 145 | }).when(mStatusBarKeyguardViewManager).addAfterKeyguardGoneRunnable(any()); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 146 | |
| 147 | when(mStackScroller.getActivatedChild()).thenReturn(null); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 148 | TestableLooper.get(this).setMessageHandler(new MessageHandler() { |
| 149 | @Override |
| 150 | public boolean onMessageHandled(Message m) { |
| 151 | if (m.getCallback() == mStatusBar.mVisibilityReporter) { |
| 152 | return false; |
| 153 | } |
| 154 | return true; |
| 155 | } |
| 156 | }); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 157 | } |
| 158 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 159 | @Test |
Jason Monk | 5ecf80c | 2017-07-06 15:28:17 -0400 | [diff] [blame] | 160 | public void testSetBouncerShowing_noCrash() { |
| 161 | mStatusBar.mCommandQueue = mock(CommandQueue.class); |
| 162 | mStatusBar.setBouncerShowing(true); |
| 163 | } |
| 164 | |
| 165 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 166 | public void executeRunnableDismissingKeyguard_nullRunnable_showingAndOccluded() { |
| 167 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 168 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(true); |
| 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 |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 174 | public void executeRunnableDismissingKeyguard_nullRunnable_showing() { |
| 175 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 176 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 177 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 178 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 181 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 182 | public void executeRunnableDismissingKeyguard_nullRunnable_notShowing() { |
| 183 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 184 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 185 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 186 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 187 | } |
| 188 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 189 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 190 | public void lockscreenStateMetrics_notShowing() { |
| 191 | // uninteresting state, except that fingerprint must be non-zero |
| 192 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 193 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 194 | // interesting state |
| 195 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 196 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 197 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(false); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 198 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 199 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 200 | MetricsAsserts.assertHasLog("missing hidden insecure lockscreen log", |
| 201 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 202 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 203 | .setType(MetricsEvent.TYPE_CLOSE) |
| 204 | .setSubtype(0)); |
| 205 | } |
| 206 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 207 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 208 | public void lockscreenStateMetrics_notShowing_secure() { |
| 209 | // uninteresting state, except that fingerprint must be non-zero |
| 210 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 211 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 212 | // interesting state |
| 213 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 214 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 215 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 216 | |
| 217 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 218 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 219 | MetricsAsserts.assertHasLog("missing hidden secure lockscreen log", |
| 220 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 221 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 222 | .setType(MetricsEvent.TYPE_CLOSE) |
| 223 | .setSubtype(1)); |
| 224 | } |
| 225 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 226 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 227 | public void lockscreenStateMetrics_isShowing() { |
| 228 | // uninteresting state, except that fingerprint must be non-zero |
| 229 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 230 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 231 | // interesting state |
| 232 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 233 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 234 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(false); |
| 235 | |
| 236 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 237 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 238 | MetricsAsserts.assertHasLog("missing insecure lockscreen showing", |
| 239 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 240 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 241 | .setType(MetricsEvent.TYPE_OPEN) |
| 242 | .setSubtype(0)); |
| 243 | } |
| 244 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 245 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 246 | public void lockscreenStateMetrics_isShowing_secure() { |
| 247 | // uninteresting state, except that fingerprint must be non-zero |
| 248 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 249 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 250 | // interesting state |
| 251 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 252 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 253 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 254 | |
| 255 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 256 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 257 | MetricsAsserts.assertHasLog("missing secure lockscreen showing log", |
| 258 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 259 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 260 | .setType(MetricsEvent.TYPE_OPEN) |
| 261 | .setSubtype(1)); |
| 262 | } |
| 263 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 264 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 265 | public void lockscreenStateMetrics_isShowingBouncer() { |
| 266 | // uninteresting state, except that fingerprint must be non-zero |
| 267 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 268 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 269 | // interesting state |
| 270 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 271 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); |
| 272 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 273 | |
| 274 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 275 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 276 | MetricsAsserts.assertHasLog("missing bouncer log", |
| 277 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 278 | new LogMaker(MetricsEvent.BOUNCER) |
| 279 | .setType(MetricsEvent.TYPE_OPEN) |
| 280 | .setSubtype(1)); |
| 281 | } |
| 282 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 283 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 284 | public void onActivatedMetrics() { |
| 285 | ActivatableNotificationView view = mock(ActivatableNotificationView.class); |
| 286 | mStatusBar.onActivated(view); |
| 287 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 288 | MetricsAsserts.assertHasLog("missing lockscreen note tap log", |
| 289 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 290 | new LogMaker(MetricsEvent.ACTION_LS_NOTE) |
| 291 | .setType(MetricsEvent.TYPE_ACTION)); |
| 292 | } |
| 293 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 294 | @Test |
| 295 | public void testShouldPeek_nonSuppressedGroupSummary() { |
| 296 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 297 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 298 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); |
| 299 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 300 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 301 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 302 | |
| 303 | Notification n = new Notification.Builder(getContext(), "a") |
| 304 | .setGroup("a") |
| 305 | .setGroupSummary(true) |
| 306 | .setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY) |
| 307 | .build(); |
| 308 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 309 | UserHandle.of(0), null, 0); |
| 310 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 311 | |
| 312 | assertTrue(mStatusBar.shouldPeek(entry, sbn)); |
| 313 | } |
| 314 | |
| 315 | @Test |
| 316 | public void testShouldPeek_suppressedGroupSummary() { |
| 317 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 318 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 319 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); |
| 320 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 321 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 322 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 323 | |
| 324 | Notification n = new Notification.Builder(getContext(), "a") |
| 325 | .setGroup("a") |
| 326 | .setGroupSummary(true) |
| 327 | .setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN) |
| 328 | .build(); |
| 329 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 330 | UserHandle.of(0), null, 0); |
| 331 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 332 | |
| 333 | assertFalse(mStatusBar.shouldPeek(entry, sbn)); |
| 334 | } |
| 335 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 336 | @Test |
Beverly | 38159ce | 2017-07-13 16:39:24 -0400 | [diff] [blame^] | 337 | public void testShouldPeek_suppressedScreenOn_dozing() { |
| 338 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 339 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 340 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 341 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 342 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 343 | |
| 344 | mStatusBar.mDozing = true; |
| 345 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(true); |
| 346 | when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(false); |
| 347 | |
| 348 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 349 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 350 | UserHandle.of(0), null, 0); |
| 351 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 352 | |
| 353 | assertTrue(mStatusBar.shouldPeek(entry, sbn)); |
| 354 | } |
| 355 | |
| 356 | @Test |
| 357 | public void testShouldPeek_suppressedScreenOn_noDoze() { |
| 358 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 359 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 360 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 361 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 362 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 363 | |
| 364 | mStatusBar.mDozing = false; |
| 365 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(true); |
| 366 | when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(false); |
| 367 | |
| 368 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 369 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 370 | UserHandle.of(0), null, 0); |
| 371 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 372 | assertFalse(mStatusBar.shouldPeek(entry, sbn)); |
| 373 | } |
| 374 | @Test |
| 375 | public void testShouldPeek_suppressedScreenOff_dozing() { |
| 376 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 377 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 378 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 379 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 380 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 381 | |
| 382 | mStatusBar.mDozing = true; |
| 383 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); |
| 384 | when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(true); |
| 385 | |
| 386 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 387 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 388 | UserHandle.of(0), null, 0); |
| 389 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 390 | assertFalse(mStatusBar.shouldPeek(entry, sbn)); |
| 391 | } |
| 392 | |
| 393 | @Test |
| 394 | public void testShouldPeek_suppressedScreenOff_noDoze() { |
| 395 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 396 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 397 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 398 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 399 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 400 | |
| 401 | mStatusBar.mDozing = false; |
| 402 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); |
| 403 | when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(true); |
| 404 | |
| 405 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 406 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 407 | UserHandle.of(0), null, 0); |
| 408 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 409 | assertTrue(mStatusBar.shouldPeek(entry, sbn)); |
| 410 | } |
| 411 | |
| 412 | |
| 413 | @Test |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 414 | public void testLogHidden() { |
| 415 | try { |
| 416 | mStatusBar.handleVisibleToUserChanged(false); |
| 417 | verify(mBarService, times(1)).onPanelHidden(); |
| 418 | verify(mBarService, never()).onPanelRevealed(anyBoolean(), anyInt()); |
| 419 | } catch (RemoteException e) { |
| 420 | fail(); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | @Test |
| 425 | public void testPanelOpenForPeek() { |
| 426 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); |
| 427 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 428 | when(mNotificationList.size()).thenReturn(5); |
| 429 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(true); |
| 430 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 431 | |
| 432 | try { |
| 433 | mStatusBar.handleVisibleToUserChanged(true); |
| 434 | |
| 435 | verify(mBarService, never()).onPanelHidden(); |
| 436 | verify(mBarService, times(1)).onPanelRevealed(false, 1); |
| 437 | } catch (RemoteException e) { |
| 438 | fail(); |
| 439 | } |
| 440 | TestableLooper.get(this).processAllMessages(); |
| 441 | } |
| 442 | |
| 443 | @Test |
| 444 | public void testPanelOpenAndClear() { |
| 445 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 446 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 447 | when(mNotificationList.size()).thenReturn(5); |
| 448 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(false); |
| 449 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 450 | |
| 451 | try { |
| 452 | mStatusBar.handleVisibleToUserChanged(true); |
| 453 | |
| 454 | verify(mBarService, never()).onPanelHidden(); |
| 455 | verify(mBarService, times(1)).onPanelRevealed(true, 5); |
| 456 | } catch (RemoteException e) { |
| 457 | fail(); |
| 458 | } |
| 459 | TestableLooper.get(this).processAllMessages(); |
| 460 | } |
| 461 | |
| 462 | @Test |
| 463 | public void testPanelOpenAndNoClear() { |
| 464 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 465 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 466 | when(mNotificationList.size()).thenReturn(5); |
| 467 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(false); |
| 468 | mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD); |
| 469 | |
| 470 | try { |
| 471 | mStatusBar.handleVisibleToUserChanged(true); |
| 472 | |
| 473 | verify(mBarService, never()).onPanelHidden(); |
| 474 | verify(mBarService, times(1)).onPanelRevealed(false, 5); |
| 475 | } catch (RemoteException e) { |
| 476 | fail(); |
| 477 | } |
| 478 | TestableLooper.get(this).processAllMessages(); |
| 479 | } |
| 480 | |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 481 | @Test |
| 482 | public void testDump_DoesNotCrash() { |
| 483 | mStatusBar.dump(null, new PrintWriter(new ByteArrayOutputStream()), null); |
| 484 | } |
| 485 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 486 | static class TestableStatusBar extends StatusBar { |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 487 | public TestableStatusBar(StatusBarKeyguardViewManager man, |
| 488 | UnlockMethodCache unlock, KeyguardIndicationController key, |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 489 | NotificationStackScrollLayout stack, HeadsUpManager hum, NotificationData nd, |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 490 | PowerManager pm, SystemServicesProxy ssp, NotificationPanelView panelView, |
| 491 | IStatusBarService barService) { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 492 | mStatusBarKeyguardViewManager = man; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 493 | mUnlockMethodCache = unlock; |
| 494 | mKeyguardIndicationController = key; |
| 495 | mStackScroller = stack; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 496 | mHeadsUpManager = hum; |
| 497 | mNotificationData = nd; |
| 498 | mUseHeadsUp = true; |
| 499 | mPowerManager = pm; |
| 500 | mSystemServicesProxy = ssp; |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 501 | mNotificationPanel = panelView; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 502 | mBarService = barService; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 503 | } |
| 504 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 505 | public void setBarStateForTest(int state) { |
| 506 | mState = state; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 507 | } |
| 508 | } |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 509 | } |