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