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