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.Mockito.doAnswer; |
| 30 | import static org.mockito.Mockito.mock; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 31 | import static org.mockito.Mockito.never; |
| 32 | import static org.mockito.Mockito.times; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 33 | import static org.mockito.Mockito.verify; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 34 | import static org.mockito.Mockito.when; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 35 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 36 | import android.app.Notification; |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 37 | import android.app.StatusBarManager; |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 38 | import android.app.trust.TrustManager; |
| 39 | import android.hardware.fingerprint.FingerprintManager; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 40 | import android.metrics.LogMaker; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 41 | import android.os.Binder; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 42 | import android.os.Handler; |
| 43 | import android.os.HandlerThread; |
| 44 | import android.os.IPowerManager; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 45 | import android.os.Message; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 46 | import android.os.PowerManager; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 47 | import android.os.RemoteException; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 48 | import android.os.UserHandle; |
| 49 | import android.service.notification.StatusBarNotification; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 50 | import android.support.test.filters.SmallTest; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 51 | import android.support.test.metricshelper.MetricsAsserts; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 52 | import android.testing.AndroidTestingRunner; |
| 53 | import android.testing.TestableLooper; |
| 54 | import android.testing.TestableLooper.MessageHandler; |
| 55 | import android.testing.TestableLooper.RunWithLooper; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 56 | import android.util.DisplayMetrics; |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame^] | 57 | import android.util.SparseArray; |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 58 | import android.view.ViewGroup.LayoutParams; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 59 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 60 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 61 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 62 | import com.android.internal.logging.testing.FakeMetricsLogger; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 63 | import com.android.internal.statusbar.IStatusBarService; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 64 | import com.android.keyguard.KeyguardHostView.OnDismissAction; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 65 | import com.android.systemui.R; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 66 | import com.android.systemui.SysuiTestCase; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 67 | import com.android.systemui.assist.AssistManager; |
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; |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame^] | 75 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 76 | import com.android.systemui.statusbar.StatusBarState; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 77 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 78 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 79 | import com.android.systemui.statusbar.policy.KeyguardMonitor; |
| 80 | import com.android.systemui.statusbar.policy.KeyguardMonitorImpl; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 81 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 82 | |
| 83 | import org.junit.Before; |
| 84 | import org.junit.Test; |
| 85 | import org.junit.runner.RunWith; |
| 86 | |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 87 | import java.io.ByteArrayOutputStream; |
| 88 | import java.io.PrintWriter; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 89 | import java.util.ArrayList; |
| 90 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 91 | @SmallTest |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 92 | @RunWith(AndroidTestingRunner.class) |
| 93 | @RunWithLooper |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 94 | public class StatusBarTest extends SysuiTestCase { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 95 | |
| 96 | StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 97 | UnlockMethodCache mUnlockMethodCache; |
| 98 | KeyguardIndicationController mKeyguardIndicationController; |
| 99 | NotificationStackScrollLayout mStackScroller; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 100 | TestableStatusBar mStatusBar; |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 101 | FakeMetricsLogger mMetricsLogger; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 102 | HeadsUpManager mHeadsUpManager; |
| 103 | NotificationData mNotificationData; |
| 104 | PowerManager mPowerManager; |
| 105 | SystemServicesProxy mSystemServicesProxy; |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 106 | NotificationPanelView mNotificationPanelView; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 107 | IStatusBarService mBarService; |
| 108 | ArrayList<Entry> mNotificationList; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 109 | private DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
| 110 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 111 | @Before |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 112 | public void setup() throws Exception { |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 113 | mContext.setTheme(R.style.Theme_SystemUI_Light); |
| 114 | mDependency.injectMockDependency(AssistManager.class); |
| 115 | mDependency.injectMockDependency(DeviceProvisionedController.class); |
| 116 | mDependency.injectTestDependency(KeyguardMonitor.class, mock(KeyguardMonitorImpl.class)); |
| 117 | CommandQueue commandQueue = mock(CommandQueue.class); |
| 118 | when(commandQueue.asBinder()).thenReturn(new Binder()); |
| 119 | mContext.putComponent(CommandQueue.class, commandQueue); |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 120 | mContext.addMockSystemService(TrustManager.class, mock(TrustManager.class)); |
| 121 | mContext.addMockSystemService(FingerprintManager.class, mock(FingerprintManager.class)); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 122 | mStatusBarKeyguardViewManager = mock(StatusBarKeyguardViewManager.class); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 123 | mUnlockMethodCache = mock(UnlockMethodCache.class); |
| 124 | mKeyguardIndicationController = mock(KeyguardIndicationController.class); |
| 125 | mStackScroller = mock(NotificationStackScrollLayout.class); |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 126 | when(mStackScroller.generateLayoutParams(any())).thenReturn(new LayoutParams(0, 0)); |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 127 | mMetricsLogger = new FakeMetricsLogger(); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 128 | mHeadsUpManager = mock(HeadsUpManager.class); |
| 129 | mNotificationData = mock(NotificationData.class); |
| 130 | mSystemServicesProxy = mock(SystemServicesProxy.class); |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 131 | mNotificationPanelView = mock(NotificationPanelView.class); |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 132 | when(mNotificationPanelView.getLayoutParams()).thenReturn(new LayoutParams(0, 0)); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 133 | mNotificationList = mock(ArrayList.class); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 134 | IPowerManager powerManagerService = mock(IPowerManager.class); |
| 135 | HandlerThread handlerThread = new HandlerThread("TestThread"); |
| 136 | handlerThread.start(); |
| 137 | mPowerManager = new PowerManager(mContext, powerManagerService, |
| 138 | new Handler(handlerThread.getLooper())); |
| 139 | when(powerManagerService.isInteractive()).thenReturn(true); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 140 | mBarService = mock(IStatusBarService.class); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 141 | |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 142 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 143 | mStatusBar = new TestableStatusBar(mStatusBarKeyguardViewManager, mUnlockMethodCache, |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 144 | mKeyguardIndicationController, mStackScroller, mHeadsUpManager, |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 145 | mNotificationData, mPowerManager, mSystemServicesProxy, mNotificationPanelView, |
| 146 | mBarService); |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 147 | mStatusBar.mContext = mContext; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 148 | mStatusBar.mComponents = mContext.getComponents(); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 149 | doAnswer(invocation -> { |
| 150 | OnDismissAction onDismissAction = (OnDismissAction) invocation.getArguments()[0]; |
| 151 | onDismissAction.onDismiss(); |
| 152 | return null; |
| 153 | }).when(mStatusBarKeyguardViewManager).dismissWithAction(any(), any(), anyBoolean()); |
| 154 | |
| 155 | doAnswer(invocation -> { |
| 156 | Runnable runnable = (Runnable) invocation.getArguments()[0]; |
| 157 | runnable.run(); |
| 158 | return null; |
| 159 | }).when(mStatusBarKeyguardViewManager).addAfterKeyguardGoneRunnable(any()); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 160 | |
| 161 | when(mStackScroller.getActivatedChild()).thenReturn(null); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 162 | TestableLooper.get(this).setMessageHandler(new MessageHandler() { |
| 163 | @Override |
| 164 | public boolean onMessageHandled(Message m) { |
| 165 | if (m.getCallback() == mStatusBar.mVisibilityReporter) { |
| 166 | return false; |
| 167 | } |
| 168 | return true; |
| 169 | } |
| 170 | }); |
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 |
Jason Monk | 5ecf80c | 2017-07-06 15:28:17 -0400 | [diff] [blame] | 174 | public void testSetBouncerShowing_noCrash() { |
| 175 | mStatusBar.mCommandQueue = mock(CommandQueue.class); |
| 176 | mStatusBar.setBouncerShowing(true); |
| 177 | } |
| 178 | |
| 179 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 180 | public void executeRunnableDismissingKeyguard_nullRunnable_showingAndOccluded() { |
| 181 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 182 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(true); |
| 183 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 184 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 187 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 188 | public void executeRunnableDismissingKeyguard_nullRunnable_showing() { |
| 189 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 190 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 191 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 192 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 193 | } |
| 194 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 195 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 196 | public void executeRunnableDismissingKeyguard_nullRunnable_notShowing() { |
| 197 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 198 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 199 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 200 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 203 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 204 | public void lockscreenStateMetrics_notShowing() { |
| 205 | // uninteresting state, except that fingerprint must be non-zero |
| 206 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 207 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 208 | // interesting state |
| 209 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 210 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 211 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(false); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 212 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 213 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 214 | MetricsAsserts.assertHasLog("missing hidden insecure lockscreen log", |
| 215 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 216 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 217 | .setType(MetricsEvent.TYPE_CLOSE) |
| 218 | .setSubtype(0)); |
| 219 | } |
| 220 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 221 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 222 | public void lockscreenStateMetrics_notShowing_secure() { |
| 223 | // uninteresting state, except that fingerprint must be non-zero |
| 224 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 225 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 226 | // interesting state |
| 227 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 228 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 229 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 230 | |
| 231 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 232 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 233 | MetricsAsserts.assertHasLog("missing hidden secure lockscreen log", |
| 234 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 235 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 236 | .setType(MetricsEvent.TYPE_CLOSE) |
| 237 | .setSubtype(1)); |
| 238 | } |
| 239 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 240 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 241 | public void lockscreenStateMetrics_isShowing() { |
| 242 | // uninteresting state, except that fingerprint must be non-zero |
| 243 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 244 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 245 | // interesting state |
| 246 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 247 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 248 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(false); |
| 249 | |
| 250 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 251 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 252 | MetricsAsserts.assertHasLog("missing insecure lockscreen showing", |
| 253 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 254 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 255 | .setType(MetricsEvent.TYPE_OPEN) |
| 256 | .setSubtype(0)); |
| 257 | } |
| 258 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 259 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 260 | public void lockscreenStateMetrics_isShowing_secure() { |
| 261 | // uninteresting state, except that fingerprint must be non-zero |
| 262 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 263 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 264 | // interesting state |
| 265 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 266 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 267 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 268 | |
| 269 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 270 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 271 | MetricsAsserts.assertHasLog("missing secure lockscreen showing log", |
| 272 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 273 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 274 | .setType(MetricsEvent.TYPE_OPEN) |
| 275 | .setSubtype(1)); |
| 276 | } |
| 277 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 278 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 279 | public void lockscreenStateMetrics_isShowingBouncer() { |
| 280 | // uninteresting state, except that fingerprint must be non-zero |
| 281 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 282 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 283 | // interesting state |
| 284 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 285 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); |
| 286 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 287 | |
| 288 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 289 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 290 | MetricsAsserts.assertHasLog("missing bouncer log", |
| 291 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 292 | new LogMaker(MetricsEvent.BOUNCER) |
| 293 | .setType(MetricsEvent.TYPE_OPEN) |
| 294 | .setSubtype(1)); |
| 295 | } |
| 296 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 297 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 298 | public void onActivatedMetrics() { |
| 299 | ActivatableNotificationView view = mock(ActivatableNotificationView.class); |
| 300 | mStatusBar.onActivated(view); |
| 301 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 302 | MetricsAsserts.assertHasLog("missing lockscreen note tap log", |
| 303 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 304 | new LogMaker(MetricsEvent.ACTION_LS_NOTE) |
| 305 | .setType(MetricsEvent.TYPE_ACTION)); |
| 306 | } |
| 307 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 308 | @Test |
| 309 | public void testShouldPeek_nonSuppressedGroupSummary() { |
| 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_SUMMARY) |
| 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 | assertTrue(mStatusBar.shouldPeek(entry, sbn)); |
| 327 | } |
| 328 | |
| 329 | @Test |
| 330 | public void testShouldPeek_suppressedGroupSummary() { |
| 331 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 332 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 333 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); |
| 334 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 335 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 336 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 337 | |
| 338 | Notification n = new Notification.Builder(getContext(), "a") |
| 339 | .setGroup("a") |
| 340 | .setGroupSummary(true) |
| 341 | .setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN) |
| 342 | .build(); |
| 343 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 344 | UserHandle.of(0), null, 0); |
| 345 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 346 | |
| 347 | assertFalse(mStatusBar.shouldPeek(entry, sbn)); |
| 348 | } |
| 349 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 350 | @Test |
Beverly | 38159ce | 2017-07-13 16:39:24 -0400 | [diff] [blame] | 351 | public void testShouldPeek_suppressedScreenOn_dozing() { |
| 352 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 353 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 354 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 355 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 356 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 357 | |
| 358 | mStatusBar.mDozing = true; |
| 359 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(true); |
| 360 | when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(false); |
| 361 | |
| 362 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 363 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 364 | UserHandle.of(0), null, 0); |
| 365 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 366 | |
| 367 | assertTrue(mStatusBar.shouldPeek(entry, sbn)); |
| 368 | } |
| 369 | |
| 370 | @Test |
| 371 | public void testShouldPeek_suppressedScreenOn_noDoze() { |
| 372 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 373 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 374 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 375 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 376 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 377 | |
| 378 | mStatusBar.mDozing = false; |
| 379 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(true); |
| 380 | when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(false); |
| 381 | |
| 382 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 383 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 384 | UserHandle.of(0), null, 0); |
| 385 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 386 | assertFalse(mStatusBar.shouldPeek(entry, sbn)); |
| 387 | } |
| 388 | @Test |
| 389 | public void testShouldPeek_suppressedScreenOff_dozing() { |
| 390 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 391 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 392 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 393 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 394 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 395 | |
| 396 | mStatusBar.mDozing = true; |
| 397 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); |
| 398 | when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(true); |
| 399 | |
| 400 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 401 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 402 | UserHandle.of(0), null, 0); |
| 403 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 404 | assertFalse(mStatusBar.shouldPeek(entry, sbn)); |
| 405 | } |
| 406 | |
| 407 | @Test |
| 408 | public void testShouldPeek_suppressedScreenOff_noDoze() { |
| 409 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 410 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 411 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 412 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 413 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 414 | |
| 415 | mStatusBar.mDozing = false; |
| 416 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); |
| 417 | when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(true); |
| 418 | |
| 419 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 420 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 421 | UserHandle.of(0), null, 0); |
| 422 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 423 | assertTrue(mStatusBar.shouldPeek(entry, sbn)); |
| 424 | } |
| 425 | |
| 426 | |
| 427 | @Test |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 428 | public void testLogHidden() { |
| 429 | try { |
| 430 | mStatusBar.handleVisibleToUserChanged(false); |
| 431 | verify(mBarService, times(1)).onPanelHidden(); |
| 432 | verify(mBarService, never()).onPanelRevealed(anyBoolean(), anyInt()); |
| 433 | } catch (RemoteException e) { |
| 434 | fail(); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | @Test |
| 439 | public void testPanelOpenForPeek() { |
| 440 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); |
| 441 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 442 | when(mNotificationList.size()).thenReturn(5); |
| 443 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(true); |
| 444 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 445 | |
| 446 | try { |
| 447 | mStatusBar.handleVisibleToUserChanged(true); |
| 448 | |
| 449 | verify(mBarService, never()).onPanelHidden(); |
| 450 | verify(mBarService, times(1)).onPanelRevealed(false, 1); |
| 451 | } catch (RemoteException e) { |
| 452 | fail(); |
| 453 | } |
| 454 | TestableLooper.get(this).processAllMessages(); |
| 455 | } |
| 456 | |
| 457 | @Test |
| 458 | public void testPanelOpenAndClear() { |
| 459 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 460 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 461 | when(mNotificationList.size()).thenReturn(5); |
| 462 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(false); |
| 463 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 464 | |
| 465 | try { |
| 466 | mStatusBar.handleVisibleToUserChanged(true); |
| 467 | |
| 468 | verify(mBarService, never()).onPanelHidden(); |
| 469 | verify(mBarService, times(1)).onPanelRevealed(true, 5); |
| 470 | } catch (RemoteException e) { |
| 471 | fail(); |
| 472 | } |
| 473 | TestableLooper.get(this).processAllMessages(); |
| 474 | } |
| 475 | |
| 476 | @Test |
| 477 | public void testPanelOpenAndNoClear() { |
| 478 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 479 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 480 | when(mNotificationList.size()).thenReturn(5); |
| 481 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(false); |
| 482 | mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD); |
| 483 | |
| 484 | try { |
| 485 | mStatusBar.handleVisibleToUserChanged(true); |
| 486 | |
| 487 | verify(mBarService, never()).onPanelHidden(); |
| 488 | verify(mBarService, times(1)).onPanelRevealed(false, 5); |
| 489 | } catch (RemoteException e) { |
| 490 | fail(); |
| 491 | } |
| 492 | TestableLooper.get(this).processAllMessages(); |
| 493 | } |
| 494 | |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 495 | @Test |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 496 | public void testDisableExpandStatusBar() { |
| 497 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 498 | mStatusBar.setUserSetupForTest(true); |
| 499 | when(mStatusBar.isDeviceProvisioned()).thenReturn(true); |
| 500 | |
| 501 | mStatusBar.disable(StatusBarManager.DISABLE_NONE, |
| 502 | StatusBarManager.DISABLE2_NOTIFICATION_SHADE, false); |
| 503 | verify(mNotificationPanelView).setQsExpansionEnabled(false); |
| 504 | mStatusBar.animateExpandNotificationsPanel(); |
| 505 | verify(mNotificationPanelView, never()).expand(anyBoolean()); |
| 506 | mStatusBar.animateExpandSettingsPanel(null); |
| 507 | verify(mNotificationPanelView, never()).expand(anyBoolean()); |
| 508 | |
| 509 | mStatusBar.disable(StatusBarManager.DISABLE_NONE, StatusBarManager.DISABLE2_NONE, false); |
| 510 | verify(mNotificationPanelView).setQsExpansionEnabled(true); |
| 511 | mStatusBar.animateExpandNotificationsPanel(); |
| 512 | verify(mNotificationPanelView).expand(anyBoolean()); |
| 513 | mStatusBar.animateExpandSettingsPanel(null); |
| 514 | verify(mNotificationPanelView).expand(anyBoolean()); |
| 515 | } |
| 516 | |
| 517 | @Test |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 518 | public void testDump_DoesNotCrash() { |
| 519 | mStatusBar.dump(null, new PrintWriter(new ByteArrayOutputStream()), null); |
| 520 | } |
| 521 | |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 522 | @Test |
| 523 | @RunWithLooper(setAsMainLooper = true) |
| 524 | public void testUpdateKeyguardState_DoesNotCrash() { |
| 525 | mStatusBar.mStatusBarWindow = mock(StatusBarWindowView.class); |
| 526 | mStatusBar.mState = StatusBarState.KEYGUARD; |
| 527 | mStatusBar.mDozeScrimController = mock(DozeScrimController.class); |
| 528 | mStatusBar.mNotificationIconAreaController = mock(NotificationIconAreaController.class); |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame^] | 529 | mStatusBar.mLockscreenUserManager = mock(NotificationLockscreenUserManager.class); |
| 530 | when(mStatusBar.mLockscreenUserManager.getCurrentProfiles()).thenReturn( |
| 531 | new SparseArray<>()); |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 532 | mStatusBar.updateKeyguardState(false, false); |
| 533 | } |
| 534 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 535 | static class TestableStatusBar extends StatusBar { |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 536 | public TestableStatusBar(StatusBarKeyguardViewManager man, |
| 537 | UnlockMethodCache unlock, KeyguardIndicationController key, |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 538 | NotificationStackScrollLayout stack, HeadsUpManager hum, NotificationData nd, |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 539 | PowerManager pm, SystemServicesProxy ssp, NotificationPanelView panelView, |
| 540 | IStatusBarService barService) { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 541 | mStatusBarKeyguardViewManager = man; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 542 | mUnlockMethodCache = unlock; |
| 543 | mKeyguardIndicationController = key; |
| 544 | mStackScroller = stack; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 545 | mHeadsUpManager = hum; |
| 546 | mNotificationData = nd; |
| 547 | mUseHeadsUp = true; |
| 548 | mPowerManager = pm; |
| 549 | mSystemServicesProxy = ssp; |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 550 | mNotificationPanel = panelView; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 551 | mBarService = barService; |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 552 | mWakefulnessLifecycle = createAwakeWakefulnessLifecycle(); |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 553 | mScrimController = mock(ScrimController.class); |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | private WakefulnessLifecycle createAwakeWakefulnessLifecycle() { |
| 557 | WakefulnessLifecycle wakefulnessLifecycle = new WakefulnessLifecycle(); |
| 558 | wakefulnessLifecycle.dispatchStartedWakingUp(); |
| 559 | wakefulnessLifecycle.dispatchFinishedWakingUp(); |
| 560 | return wakefulnessLifecycle; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 561 | } |
| 562 | |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 563 | @Override |
| 564 | protected void updateTheme() { |
| 565 | // Do nothing for now, until we have more mocking and StatusBar is smaller. |
| 566 | } |
| 567 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 568 | public void setBarStateForTest(int state) { |
| 569 | mState = state; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 570 | } |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 571 | |
| 572 | public void setUserSetupForTest(boolean userSetup) { |
| 573 | mUserSetup = userSetup; |
| 574 | } |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 575 | } |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame^] | 576 | } |