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 |
| 337 | public void testLogHidden() { |
| 338 | try { |
| 339 | mStatusBar.handleVisibleToUserChanged(false); |
| 340 | verify(mBarService, times(1)).onPanelHidden(); |
| 341 | verify(mBarService, never()).onPanelRevealed(anyBoolean(), anyInt()); |
| 342 | } catch (RemoteException e) { |
| 343 | fail(); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | @Test |
| 348 | public void testPanelOpenForPeek() { |
| 349 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); |
| 350 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 351 | when(mNotificationList.size()).thenReturn(5); |
| 352 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(true); |
| 353 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 354 | |
| 355 | try { |
| 356 | mStatusBar.handleVisibleToUserChanged(true); |
| 357 | |
| 358 | verify(mBarService, never()).onPanelHidden(); |
| 359 | verify(mBarService, times(1)).onPanelRevealed(false, 1); |
| 360 | } catch (RemoteException e) { |
| 361 | fail(); |
| 362 | } |
| 363 | TestableLooper.get(this).processAllMessages(); |
| 364 | } |
| 365 | |
| 366 | @Test |
| 367 | public void testPanelOpenAndClear() { |
| 368 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 369 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 370 | when(mNotificationList.size()).thenReturn(5); |
| 371 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(false); |
| 372 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 373 | |
| 374 | try { |
| 375 | mStatusBar.handleVisibleToUserChanged(true); |
| 376 | |
| 377 | verify(mBarService, never()).onPanelHidden(); |
| 378 | verify(mBarService, times(1)).onPanelRevealed(true, 5); |
| 379 | } catch (RemoteException e) { |
| 380 | fail(); |
| 381 | } |
| 382 | TestableLooper.get(this).processAllMessages(); |
| 383 | } |
| 384 | |
| 385 | @Test |
| 386 | public void testPanelOpenAndNoClear() { |
| 387 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 388 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 389 | when(mNotificationList.size()).thenReturn(5); |
| 390 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(false); |
| 391 | mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD); |
| 392 | |
| 393 | try { |
| 394 | mStatusBar.handleVisibleToUserChanged(true); |
| 395 | |
| 396 | verify(mBarService, never()).onPanelHidden(); |
| 397 | verify(mBarService, times(1)).onPanelRevealed(false, 5); |
| 398 | } catch (RemoteException e) { |
| 399 | fail(); |
| 400 | } |
| 401 | TestableLooper.get(this).processAllMessages(); |
| 402 | } |
| 403 | |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 404 | @Test |
| 405 | public void testDump_DoesNotCrash() { |
| 406 | mStatusBar.dump(null, new PrintWriter(new ByteArrayOutputStream()), null); |
| 407 | } |
| 408 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 409 | static class TestableStatusBar extends StatusBar { |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 410 | public TestableStatusBar(StatusBarKeyguardViewManager man, |
| 411 | UnlockMethodCache unlock, KeyguardIndicationController key, |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 412 | NotificationStackScrollLayout stack, HeadsUpManager hum, NotificationData nd, |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 413 | PowerManager pm, SystemServicesProxy ssp, NotificationPanelView panelView, |
| 414 | IStatusBarService barService) { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 415 | mStatusBarKeyguardViewManager = man; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 416 | mUnlockMethodCache = unlock; |
| 417 | mKeyguardIndicationController = key; |
| 418 | mStackScroller = stack; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 419 | mHeadsUpManager = hum; |
| 420 | mNotificationData = nd; |
| 421 | mUseHeadsUp = true; |
| 422 | mPowerManager = pm; |
| 423 | mSystemServicesProxy = ssp; |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 424 | mNotificationPanel = panelView; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 425 | mBarService = barService; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 426 | } |
| 427 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 428 | public void setBarStateForTest(int state) { |
| 429 | mState = state; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 430 | } |
| 431 | } |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 432 | } |