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; |
Lucas Dupin | 311eac8 | 2017-12-11 14:40:07 -0800 | [diff] [blame] | 29 | import static org.mockito.ArgumentMatchers.eq; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 30 | import static org.mockito.Mockito.doAnswer; |
| 31 | import static org.mockito.Mockito.mock; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 32 | import static org.mockito.Mockito.never; |
| 33 | import static org.mockito.Mockito.times; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 34 | import static org.mockito.Mockito.verify; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 35 | import static org.mockito.Mockito.when; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 36 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 37 | import android.app.Notification; |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 38 | import android.app.StatusBarManager; |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 39 | import android.app.trust.TrustManager; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 40 | import android.content.Context; |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 41 | import android.hardware.fingerprint.FingerprintManager; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 42 | import android.metrics.LogMaker; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 43 | import android.os.Binder; |
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; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 47 | import android.os.PowerManager; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 48 | import android.os.RemoteException; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 49 | import android.os.UserHandle; |
| 50 | import android.service.notification.StatusBarNotification; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 51 | import android.support.test.filters.SmallTest; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 52 | import android.support.test.metricshelper.MetricsAsserts; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 53 | import android.testing.AndroidTestingRunner; |
| 54 | import android.testing.TestableLooper; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 55 | import android.testing.TestableLooper.RunWithLooper; |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 56 | import android.util.SparseArray; |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 57 | import android.view.ViewGroup.LayoutParams; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 58 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 59 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 60 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 61 | import com.android.internal.logging.testing.FakeMetricsLogger; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 62 | import com.android.internal.statusbar.IStatusBarService; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 63 | import com.android.keyguard.KeyguardHostView.OnDismissAction; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 64 | import com.android.systemui.ForegroundServiceController; |
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; |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 67 | import com.android.systemui.UiOffloadThread; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 68 | import com.android.systemui.assist.AssistManager; |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 69 | import com.android.systemui.keyguard.WakefulnessLifecycle; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 70 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 71 | import com.android.systemui.statusbar.ActivatableNotificationView; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame^] | 72 | import com.android.systemui.statusbar.AppOpsListener; |
Jason Monk | 5ecf80c | 2017-07-06 15:28:17 -0400 | [diff] [blame] | 73 | import com.android.systemui.statusbar.CommandQueue; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 74 | import com.android.systemui.statusbar.KeyguardIndicationController; |
| 75 | import com.android.systemui.statusbar.NotificationData; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 76 | import com.android.systemui.statusbar.NotificationData.Entry; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 77 | import com.android.systemui.statusbar.NotificationEntryManager; |
| 78 | import com.android.systemui.statusbar.NotificationGutsManager; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 79 | import com.android.systemui.statusbar.NotificationListContainer; |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 80 | import com.android.systemui.statusbar.NotificationListener; |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 81 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 82 | import com.android.systemui.statusbar.NotificationLogger; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 83 | import com.android.systemui.statusbar.NotificationMediaManager; |
| 84 | import com.android.systemui.statusbar.NotificationPresenter; |
| 85 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 86 | import com.android.systemui.statusbar.NotificationViewHierarchyManager; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 87 | import com.android.systemui.statusbar.StatusBarState; |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 88 | import com.android.systemui.statusbar.notification.ActivityLaunchAnimator; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 89 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 90 | import com.android.systemui.statusbar.phone.HeadsUpManagerPhone; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 91 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 92 | import com.android.systemui.statusbar.policy.KeyguardMonitor; |
| 93 | import com.android.systemui.statusbar.policy.KeyguardMonitorImpl; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 94 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 95 | |
| 96 | import org.junit.Before; |
| 97 | import org.junit.Test; |
| 98 | import org.junit.runner.RunWith; |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 99 | import org.mockito.Mock; |
| 100 | import org.mockito.MockitoAnnotations; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 101 | |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 102 | import java.io.ByteArrayOutputStream; |
| 103 | import java.io.PrintWriter; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 104 | import java.util.ArrayList; |
| 105 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 106 | @SmallTest |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 107 | @RunWith(AndroidTestingRunner.class) |
| 108 | @RunWithLooper |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 109 | public class StatusBarTest extends SysuiTestCase { |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 110 | @Mock private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
| 111 | @Mock private UnlockMethodCache mUnlockMethodCache; |
| 112 | @Mock private KeyguardIndicationController mKeyguardIndicationController; |
| 113 | @Mock private NotificationStackScrollLayout mStackScroller; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 114 | @Mock private HeadsUpManagerPhone mHeadsUpManager; |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 115 | @Mock private SystemServicesProxy mSystemServicesProxy; |
| 116 | @Mock private NotificationPanelView mNotificationPanelView; |
| 117 | @Mock private IStatusBarService mBarService; |
| 118 | @Mock private ScrimController mScrimController; |
| 119 | @Mock private ArrayList<Entry> mNotificationList; |
| 120 | @Mock private FingerprintUnlockController mFingerprintUnlockController; |
| 121 | @Mock private NotificationData mNotificationData; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 122 | |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 123 | // Mock dependencies: |
| 124 | @Mock private NotificationViewHierarchyManager mViewHierarchyManager; |
| 125 | @Mock private VisualStabilityManager mVisualStabilityManager; |
| 126 | @Mock private NotificationListener mNotificationListener; |
| 127 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 128 | private TestableStatusBar mStatusBar; |
| 129 | private FakeMetricsLogger mMetricsLogger; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 130 | private PowerManager mPowerManager; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 131 | private TestableNotificationEntryManager mEntryManager; |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 132 | private NotificationLogger mNotificationLogger; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 133 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 134 | @Before |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 135 | public void setup() throws Exception { |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 136 | MockitoAnnotations.initMocks(this); |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 137 | mDependency.injectMockDependency(AssistManager.class); |
| 138 | mDependency.injectMockDependency(DeviceProvisionedController.class); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 139 | mDependency.injectMockDependency(NotificationGroupManager.class); |
| 140 | mDependency.injectMockDependency(NotificationGutsManager.class); |
| 141 | mDependency.injectMockDependency(NotificationRemoteInputManager.class); |
| 142 | mDependency.injectMockDependency(NotificationMediaManager.class); |
| 143 | mDependency.injectMockDependency(ForegroundServiceController.class); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 144 | mDependency.injectTestDependency(NotificationViewHierarchyManager.class, |
| 145 | mViewHierarchyManager); |
| 146 | mDependency.injectTestDependency(VisualStabilityManager.class, mVisualStabilityManager); |
| 147 | mDependency.injectTestDependency(NotificationListener.class, mNotificationListener); |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 148 | mDependency.injectTestDependency(KeyguardMonitor.class, mock(KeyguardMonitorImpl.class)); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame^] | 149 | mDependency.injectTestDependency(AppOpsListener.class, mock(AppOpsListener.class)); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 150 | |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 151 | mContext.addMockSystemService(TrustManager.class, mock(TrustManager.class)); |
| 152 | mContext.addMockSystemService(FingerprintManager.class, mock(FingerprintManager.class)); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 153 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 154 | mMetricsLogger = new FakeMetricsLogger(); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 155 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Eliot Courtney | 6c313d3 | 2017-12-14 19:57:51 +0900 | [diff] [blame] | 156 | mNotificationLogger = new NotificationLogger(); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 157 | mDependency.injectTestDependency(NotificationLogger.class, mNotificationLogger); |
| 158 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 159 | IPowerManager powerManagerService = mock(IPowerManager.class); |
| 160 | HandlerThread handlerThread = new HandlerThread("TestThread"); |
| 161 | handlerThread.start(); |
| 162 | mPowerManager = new PowerManager(mContext, powerManagerService, |
| 163 | new Handler(handlerThread.getLooper())); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 164 | |
| 165 | CommandQueue commandQueue = mock(CommandQueue.class); |
| 166 | when(commandQueue.asBinder()).thenReturn(new Binder()); |
| 167 | mContext.putComponent(CommandQueue.class, commandQueue); |
| 168 | |
| 169 | mContext.setTheme(R.style.Theme_SystemUI_Light); |
| 170 | |
| 171 | when(mStackScroller.generateLayoutParams(any())).thenReturn(new LayoutParams(0, 0)); |
| 172 | when(mNotificationPanelView.getLayoutParams()).thenReturn(new LayoutParams(0, 0)); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 173 | when(powerManagerService.isInteractive()).thenReturn(true); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 174 | when(mStackScroller.getActivatedChild()).thenReturn(null); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 175 | |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 176 | doAnswer(invocation -> { |
| 177 | OnDismissAction onDismissAction = (OnDismissAction) invocation.getArguments()[0]; |
| 178 | onDismissAction.onDismiss(); |
| 179 | return null; |
| 180 | }).when(mStatusBarKeyguardViewManager).dismissWithAction(any(), any(), anyBoolean()); |
| 181 | |
| 182 | doAnswer(invocation -> { |
| 183 | Runnable runnable = (Runnable) invocation.getArguments()[0]; |
| 184 | runnable.run(); |
| 185 | return null; |
| 186 | }).when(mStatusBarKeyguardViewManager).addAfterKeyguardGoneRunnable(any()); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 187 | |
Eliot Courtney | 6c313d3 | 2017-12-14 19:57:51 +0900 | [diff] [blame] | 188 | mEntryManager = new TestableNotificationEntryManager(mSystemServicesProxy, mPowerManager, |
| 189 | mContext); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 190 | mStatusBar = new TestableStatusBar(mStatusBarKeyguardViewManager, mUnlockMethodCache, |
| 191 | mKeyguardIndicationController, mStackScroller, mHeadsUpManager, |
| 192 | mPowerManager, mNotificationPanelView, mBarService, mNotificationListener, |
| 193 | mNotificationLogger, mVisualStabilityManager, mViewHierarchyManager, |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 194 | mEntryManager, mScrimController, mFingerprintUnlockController, |
| 195 | mock(ActivityLaunchAnimator.class)); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 196 | mStatusBar.mContext = mContext; |
| 197 | mStatusBar.mComponents = mContext.getComponents(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 198 | mEntryManager.setUpForTest(mStatusBar, mStackScroller, mStatusBar, mHeadsUpManager, |
| 199 | mNotificationData); |
Eliot Courtney | 4a96b36 | 2017-12-14 19:38:52 +0900 | [diff] [blame] | 200 | mNotificationLogger.setUpWithEntryManager(mEntryManager, mStackScroller); |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 201 | |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 202 | TestableLooper.get(this).setMessageHandler(m -> { |
| 203 | if (m.getCallback() == mStatusBar.mNotificationLogger.getVisibilityReporter()) { |
| 204 | return false; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 205 | } |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 206 | return true; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 207 | }); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 208 | } |
| 209 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 210 | @Test |
Jason Monk | 5ecf80c | 2017-07-06 15:28:17 -0400 | [diff] [blame] | 211 | public void testSetBouncerShowing_noCrash() { |
| 212 | mStatusBar.mCommandQueue = mock(CommandQueue.class); |
| 213 | mStatusBar.setBouncerShowing(true); |
| 214 | } |
| 215 | |
| 216 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 217 | public void executeRunnableDismissingKeyguard_nullRunnable_showingAndOccluded() { |
| 218 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 219 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(true); |
| 220 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 221 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 222 | } |
| 223 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 224 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 225 | public void executeRunnableDismissingKeyguard_nullRunnable_showing() { |
| 226 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 227 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 228 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 229 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 230 | } |
| 231 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 232 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 233 | public void executeRunnableDismissingKeyguard_nullRunnable_notShowing() { |
| 234 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 235 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 236 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 237 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 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_notShowing() { |
| 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(false); |
| 247 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 248 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(false); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 249 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 250 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 251 | MetricsAsserts.assertHasLog("missing hidden insecure lockscreen log", |
| 252 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 253 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 254 | .setType(MetricsEvent.TYPE_CLOSE) |
| 255 | .setSubtype(0)); |
| 256 | } |
| 257 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 258 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 259 | public void lockscreenStateMetrics_notShowing_secure() { |
| 260 | // uninteresting state, except that fingerprint must be non-zero |
| 261 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 262 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 263 | // interesting state |
| 264 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 265 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 266 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 267 | |
| 268 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 269 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 270 | MetricsAsserts.assertHasLog("missing hidden secure lockscreen log", |
| 271 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 272 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 273 | .setType(MetricsEvent.TYPE_CLOSE) |
| 274 | .setSubtype(1)); |
| 275 | } |
| 276 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 277 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 278 | public void lockscreenStateMetrics_isShowing() { |
| 279 | // uninteresting state, except that fingerprint must be non-zero |
| 280 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 281 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 282 | // interesting state |
| 283 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 284 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 285 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(false); |
| 286 | |
| 287 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 288 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 289 | MetricsAsserts.assertHasLog("missing insecure lockscreen showing", |
| 290 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 291 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 292 | .setType(MetricsEvent.TYPE_OPEN) |
| 293 | .setSubtype(0)); |
| 294 | } |
| 295 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 296 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 297 | public void lockscreenStateMetrics_isShowing_secure() { |
| 298 | // uninteresting state, except that fingerprint must be non-zero |
| 299 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 300 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 301 | // interesting state |
| 302 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 303 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 304 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 305 | |
| 306 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 307 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 308 | MetricsAsserts.assertHasLog("missing secure lockscreen showing log", |
| 309 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 310 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 311 | .setType(MetricsEvent.TYPE_OPEN) |
| 312 | .setSubtype(1)); |
| 313 | } |
| 314 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 315 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 316 | public void lockscreenStateMetrics_isShowingBouncer() { |
| 317 | // uninteresting state, except that fingerprint must be non-zero |
| 318 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 319 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 320 | // interesting state |
| 321 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 322 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); |
| 323 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 324 | |
| 325 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 326 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 327 | MetricsAsserts.assertHasLog("missing bouncer log", |
| 328 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 329 | new LogMaker(MetricsEvent.BOUNCER) |
| 330 | .setType(MetricsEvent.TYPE_OPEN) |
| 331 | .setSubtype(1)); |
| 332 | } |
| 333 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 334 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 335 | public void onActivatedMetrics() { |
| 336 | ActivatableNotificationView view = mock(ActivatableNotificationView.class); |
| 337 | mStatusBar.onActivated(view); |
| 338 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame] | 339 | MetricsAsserts.assertHasLog("missing lockscreen note tap log", |
| 340 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 341 | new LogMaker(MetricsEvent.ACTION_LS_NOTE) |
| 342 | .setType(MetricsEvent.TYPE_ACTION)); |
| 343 | } |
| 344 | |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 345 | @Test |
| 346 | public void testShouldPeek_nonSuppressedGroupSummary() { |
| 347 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 348 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 349 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); |
| 350 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 351 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 352 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 353 | |
| 354 | Notification n = new Notification.Builder(getContext(), "a") |
| 355 | .setGroup("a") |
| 356 | .setGroupSummary(true) |
| 357 | .setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY) |
| 358 | .build(); |
| 359 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 360 | UserHandle.of(0), null, 0); |
| 361 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 362 | |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 363 | assertTrue(mEntryManager.shouldPeek(entry, sbn)); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | @Test |
| 367 | public void testShouldPeek_suppressedGroupSummary() { |
| 368 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 369 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 370 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); |
| 371 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 372 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 373 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 374 | |
| 375 | Notification n = new Notification.Builder(getContext(), "a") |
| 376 | .setGroup("a") |
| 377 | .setGroupSummary(true) |
| 378 | .setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN) |
| 379 | .build(); |
| 380 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 381 | UserHandle.of(0), null, 0); |
| 382 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 383 | |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 384 | assertFalse(mEntryManager.shouldPeek(entry, sbn)); |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 385 | } |
| 386 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 387 | @Test |
Beverly | 38159ce | 2017-07-13 16:39:24 -0400 | [diff] [blame] | 388 | public void testShouldPeek_suppressedScreenOn_dozing() { |
| 389 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 390 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 391 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 392 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 393 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 394 | |
| 395 | mStatusBar.mDozing = true; |
| 396 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(true); |
| 397 | when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(false); |
| 398 | |
| 399 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 400 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 401 | UserHandle.of(0), null, 0); |
| 402 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 403 | |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 404 | assertTrue(mEntryManager.shouldPeek(entry, sbn)); |
Beverly | 38159ce | 2017-07-13 16:39:24 -0400 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | @Test |
| 408 | public void testShouldPeek_suppressedScreenOn_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(true); |
| 417 | when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(false); |
| 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); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 423 | assertFalse(mEntryManager.shouldPeek(entry, sbn)); |
Beverly | 38159ce | 2017-07-13 16:39:24 -0400 | [diff] [blame] | 424 | } |
| 425 | @Test |
| 426 | public void testShouldPeek_suppressedScreenOff_dozing() { |
| 427 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 428 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 429 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 430 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 431 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 432 | |
| 433 | mStatusBar.mDozing = true; |
| 434 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); |
| 435 | when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(true); |
| 436 | |
| 437 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 438 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 439 | UserHandle.of(0), null, 0); |
| 440 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 441 | assertFalse(mEntryManager.shouldPeek(entry, sbn)); |
Beverly | 38159ce | 2017-07-13 16:39:24 -0400 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | @Test |
| 445 | public void testShouldPeek_suppressedScreenOff_noDoze() { |
| 446 | when(mPowerManager.isScreenOn()).thenReturn(true); |
| 447 | when(mHeadsUpManager.isSnoozed(anyString())).thenReturn(false); |
| 448 | when(mNotificationData.shouldFilterOut(any())).thenReturn(false); |
| 449 | when(mSystemServicesProxy.isDreaming()).thenReturn(false); |
| 450 | when(mNotificationData.getImportance(any())).thenReturn(IMPORTANCE_HIGH); |
| 451 | |
| 452 | mStatusBar.mDozing = false; |
| 453 | when(mNotificationData.shouldSuppressScreenOn(any())).thenReturn(false); |
| 454 | when(mNotificationData.shouldSuppressScreenOff(any())).thenReturn(true); |
| 455 | |
| 456 | Notification n = new Notification.Builder(getContext(), "a").build(); |
| 457 | StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, |
| 458 | UserHandle.of(0), null, 0); |
| 459 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 460 | assertTrue(mEntryManager.shouldPeek(entry, sbn)); |
Beverly | 38159ce | 2017-07-13 16:39:24 -0400 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | |
| 464 | @Test |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 465 | public void testLogHidden() { |
| 466 | try { |
| 467 | mStatusBar.handleVisibleToUserChanged(false); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 468 | waitForUiOffloadThread(); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 469 | verify(mBarService, times(1)).onPanelHidden(); |
| 470 | verify(mBarService, never()).onPanelRevealed(anyBoolean(), anyInt()); |
| 471 | } catch (RemoteException e) { |
| 472 | fail(); |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | @Test |
| 477 | public void testPanelOpenForPeek() { |
| 478 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); |
| 479 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 480 | when(mNotificationList.size()).thenReturn(5); |
| 481 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(true); |
| 482 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 483 | |
| 484 | try { |
| 485 | mStatusBar.handleVisibleToUserChanged(true); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 486 | waitForUiOffloadThread(); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 487 | verify(mBarService, never()).onPanelHidden(); |
| 488 | verify(mBarService, times(1)).onPanelRevealed(false, 1); |
| 489 | } catch (RemoteException e) { |
| 490 | fail(); |
| 491 | } |
| 492 | TestableLooper.get(this).processAllMessages(); |
| 493 | } |
| 494 | |
| 495 | @Test |
| 496 | public void testPanelOpenAndClear() { |
| 497 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 498 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 499 | when(mNotificationList.size()).thenReturn(5); |
| 500 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(false); |
| 501 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 502 | |
| 503 | try { |
| 504 | mStatusBar.handleVisibleToUserChanged(true); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 505 | waitForUiOffloadThread(); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 506 | verify(mBarService, never()).onPanelHidden(); |
| 507 | verify(mBarService, times(1)).onPanelRevealed(true, 5); |
| 508 | } catch (RemoteException e) { |
| 509 | fail(); |
| 510 | } |
| 511 | TestableLooper.get(this).processAllMessages(); |
| 512 | } |
| 513 | |
| 514 | @Test |
| 515 | public void testPanelOpenAndNoClear() { |
| 516 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 517 | when(mNotificationData.getActiveNotifications()).thenReturn(mNotificationList); |
| 518 | when(mNotificationList.size()).thenReturn(5); |
| 519 | when(mNotificationPanelView.isFullyCollapsed()).thenReturn(false); |
| 520 | mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD); |
| 521 | |
| 522 | try { |
| 523 | mStatusBar.handleVisibleToUserChanged(true); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 524 | waitForUiOffloadThread(); |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 525 | verify(mBarService, never()).onPanelHidden(); |
| 526 | verify(mBarService, times(1)).onPanelRevealed(false, 5); |
| 527 | } catch (RemoteException e) { |
| 528 | fail(); |
| 529 | } |
| 530 | TestableLooper.get(this).processAllMessages(); |
| 531 | } |
| 532 | |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 533 | @Test |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 534 | public void testDisableExpandStatusBar() { |
| 535 | mStatusBar.setBarStateForTest(StatusBarState.SHADE); |
| 536 | mStatusBar.setUserSetupForTest(true); |
| 537 | when(mStatusBar.isDeviceProvisioned()).thenReturn(true); |
| 538 | |
| 539 | mStatusBar.disable(StatusBarManager.DISABLE_NONE, |
| 540 | StatusBarManager.DISABLE2_NOTIFICATION_SHADE, false); |
| 541 | verify(mNotificationPanelView).setQsExpansionEnabled(false); |
| 542 | mStatusBar.animateExpandNotificationsPanel(); |
| 543 | verify(mNotificationPanelView, never()).expand(anyBoolean()); |
| 544 | mStatusBar.animateExpandSettingsPanel(null); |
| 545 | verify(mNotificationPanelView, never()).expand(anyBoolean()); |
| 546 | |
| 547 | mStatusBar.disable(StatusBarManager.DISABLE_NONE, StatusBarManager.DISABLE2_NONE, false); |
| 548 | verify(mNotificationPanelView).setQsExpansionEnabled(true); |
| 549 | mStatusBar.animateExpandNotificationsPanel(); |
| 550 | verify(mNotificationPanelView).expand(anyBoolean()); |
| 551 | mStatusBar.animateExpandSettingsPanel(null); |
| 552 | verify(mNotificationPanelView).expand(anyBoolean()); |
| 553 | } |
| 554 | |
| 555 | @Test |
Jason Monk | 5130537 | 2017-06-22 11:41:08 -0400 | [diff] [blame] | 556 | public void testDump_DoesNotCrash() { |
| 557 | mStatusBar.dump(null, new PrintWriter(new ByteArrayOutputStream()), null); |
| 558 | } |
| 559 | |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 560 | @Test |
| 561 | @RunWithLooper(setAsMainLooper = true) |
| 562 | public void testUpdateKeyguardState_DoesNotCrash() { |
| 563 | mStatusBar.mStatusBarWindow = mock(StatusBarWindowView.class); |
| 564 | mStatusBar.mState = StatusBarState.KEYGUARD; |
| 565 | mStatusBar.mDozeScrimController = mock(DozeScrimController.class); |
| 566 | mStatusBar.mNotificationIconAreaController = mock(NotificationIconAreaController.class); |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 567 | mStatusBar.mLockscreenUserManager = mock(NotificationLockscreenUserManager.class); |
| 568 | when(mStatusBar.mLockscreenUserManager.getCurrentProfiles()).thenReturn( |
| 569 | new SparseArray<>()); |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 570 | mStatusBar.updateKeyguardState(false, false); |
| 571 | } |
| 572 | |
Lucas Dupin | c2e7546 | 2017-12-06 13:59:25 -0800 | [diff] [blame] | 573 | @Test |
| 574 | public void testFingerprintNotification_UpdatesScrims() { |
| 575 | mStatusBar.mStatusBarWindowManager = mock(StatusBarWindowManager.class); |
Lucas Dupin | c2e7546 | 2017-12-06 13:59:25 -0800 | [diff] [blame] | 576 | mStatusBar.mDozeScrimController = mock(DozeScrimController.class); |
| 577 | mStatusBar.notifyFpAuthModeChanged(); |
| 578 | verify(mScrimController).transitionTo(any(), any()); |
| 579 | } |
| 580 | |
Lucas Dupin | 311eac8 | 2017-12-11 14:40:07 -0800 | [diff] [blame] | 581 | @Test |
| 582 | public void testFingerprintUnlock_UpdatesScrims() { |
| 583 | // Simulate unlocking from AoD with fingerprint. |
| 584 | when(mFingerprintUnlockController.getMode()) |
| 585 | .thenReturn(FingerprintUnlockController.MODE_WAKE_AND_UNLOCK); |
| 586 | mStatusBar.updateScrimController(); |
| 587 | verify(mScrimController).transitionTo(eq(ScrimState.UNLOCKED), any()); |
| 588 | } |
| 589 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 590 | static class TestableStatusBar extends StatusBar { |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 591 | public TestableStatusBar(StatusBarKeyguardViewManager man, |
| 592 | UnlockMethodCache unlock, KeyguardIndicationController key, |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 593 | NotificationStackScrollLayout stack, HeadsUpManagerPhone hum, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 594 | PowerManager pm, NotificationPanelView panelView, |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 595 | IStatusBarService barService, NotificationListener notificationListener, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 596 | NotificationLogger notificationLogger, |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 597 | VisualStabilityManager visualStabilityManager, |
| 598 | NotificationViewHierarchyManager viewHierarchyManager, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 599 | TestableNotificationEntryManager entryManager, ScrimController scrimController, |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 600 | FingerprintUnlockController fingerprintUnlockController, |
| 601 | ActivityLaunchAnimator launchAnimator) { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 602 | mStatusBarKeyguardViewManager = man; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 603 | mUnlockMethodCache = unlock; |
| 604 | mKeyguardIndicationController = key; |
| 605 | mStackScroller = stack; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 606 | mHeadsUpManager = hum; |
Julia Reynolds | 3020315 | 2017-05-26 13:36:31 -0400 | [diff] [blame] | 607 | mPowerManager = pm; |
Jorim Jaggi | fd3b1a1 | 2017-06-06 17:04:19 -0700 | [diff] [blame] | 608 | mNotificationPanel = panelView; |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 609 | mBarService = barService; |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 610 | mNotificationListener = notificationListener; |
| 611 | mNotificationLogger = notificationLogger; |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 612 | mWakefulnessLifecycle = createAwakeWakefulnessLifecycle(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 613 | mVisualStabilityManager = visualStabilityManager; |
| 614 | mViewHierarchyManager = viewHierarchyManager; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 615 | mEntryManager = entryManager; |
Lucas Dupin | c2e7546 | 2017-12-06 13:59:25 -0800 | [diff] [blame] | 616 | mScrimController = scrimController; |
Lucas Dupin | 311eac8 | 2017-12-11 14:40:07 -0800 | [diff] [blame] | 617 | mFingerprintUnlockController = fingerprintUnlockController; |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 618 | mActivityLaunchAnimator = launchAnimator; |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | private WakefulnessLifecycle createAwakeWakefulnessLifecycle() { |
| 622 | WakefulnessLifecycle wakefulnessLifecycle = new WakefulnessLifecycle(); |
| 623 | wakefulnessLifecycle.dispatchStartedWakingUp(); |
| 624 | wakefulnessLifecycle.dispatchFinishedWakingUp(); |
| 625 | return wakefulnessLifecycle; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 626 | } |
| 627 | |
Jason Monk | 9c4faa8 | 2017-08-15 09:32:27 -0400 | [diff] [blame] | 628 | @Override |
| 629 | protected void updateTheme() { |
| 630 | // Do nothing for now, until we have more mocking and StatusBar is smaller. |
| 631 | } |
| 632 | |
Chris Wren | 621933f | 2017-06-14 15:59:03 -0400 | [diff] [blame] | 633 | public void setBarStateForTest(int state) { |
| 634 | mState = state; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 635 | } |
Charles He | 2eda242 | 2017-09-24 17:55:21 +0100 | [diff] [blame] | 636 | |
| 637 | public void setUserSetupForTest(boolean userSetup) { |
| 638 | mUserSetup = userSetup; |
| 639 | } |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 640 | |
| 641 | } |
| 642 | |
| 643 | private class TestableNotificationEntryManager extends NotificationEntryManager { |
| 644 | |
Eliot Courtney | 6c313d3 | 2017-12-14 19:57:51 +0900 | [diff] [blame] | 645 | public TestableNotificationEntryManager(SystemServicesProxy systemServicesProxy, |
| 646 | PowerManager powerManager, Context context) { |
| 647 | super(context); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 648 | mSystemServicesProxy = systemServicesProxy; |
| 649 | mPowerManager = powerManager; |
| 650 | } |
| 651 | |
| 652 | public void setUpForTest(NotificationPresenter presenter, |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 653 | NotificationListContainer listContainer, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 654 | Callback callback, |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 655 | HeadsUpManagerPhone headsUpManager, |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 656 | NotificationData notificationData) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 657 | super.setUpWithPresenter(presenter, listContainer, callback, headsUpManager); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 658 | mNotificationData = notificationData; |
| 659 | mUseHeadsUp = true; |
| 660 | } |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 661 | } |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 662 | } |