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 | |
| 19 | import static org.mockito.Matchers.any; |
| 20 | import static org.mockito.Matchers.anyBoolean; |
| 21 | import static org.mockito.Mockito.doAnswer; |
| 22 | import static org.mockito.Mockito.mock; |
| 23 | import static org.mockito.Mockito.when; |
| 24 | |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 25 | import android.metrics.LogMaker; |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 26 | import android.support.test.filters.FlakyTest; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 27 | import android.support.test.filters.SmallTest; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 28 | import android.support.test.metricshelper.MetricsAsserts; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 29 | import android.support.test.runner.AndroidJUnit4; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 30 | import android.util.DisplayMetrics; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 31 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame^] | 32 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 33 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame^] | 34 | import com.android.internal.logging.testing.FakeMetricsLogger; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 35 | import com.android.keyguard.KeyguardHostView.OnDismissAction; |
| 36 | import com.android.systemui.SysuiTestCase; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 37 | import com.android.systemui.statusbar.ActivatableNotificationView; |
| 38 | import com.android.systemui.statusbar.KeyguardIndicationController; |
| 39 | import com.android.systemui.statusbar.NotificationData; |
| 40 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 41 | |
| 42 | import org.junit.Before; |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 43 | import org.junit.Ignore; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 44 | import org.junit.Test; |
| 45 | import org.junit.runner.RunWith; |
| 46 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 47 | @SmallTest |
| 48 | @RunWith(AndroidJUnit4.class) |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 49 | public class StatusBarTest extends SysuiTestCase { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 50 | |
| 51 | StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 52 | UnlockMethodCache mUnlockMethodCache; |
| 53 | KeyguardIndicationController mKeyguardIndicationController; |
| 54 | NotificationStackScrollLayout mStackScroller; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 55 | StatusBar mStatusBar; |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame^] | 56 | FakeMetricsLogger mMetricsLogger; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 57 | |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 58 | private DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
| 59 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 60 | @Before |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 61 | public void setup() { |
| 62 | mStatusBarKeyguardViewManager = mock(StatusBarKeyguardViewManager.class); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 63 | mUnlockMethodCache = mock(UnlockMethodCache.class); |
| 64 | mKeyguardIndicationController = mock(KeyguardIndicationController.class); |
| 65 | mStackScroller = mock(NotificationStackScrollLayout.class); |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame^] | 66 | mMetricsLogger = new FakeMetricsLogger(); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 67 | mStatusBar = new TestableStatusBar(mStatusBarKeyguardViewManager, mUnlockMethodCache, |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame^] | 68 | mKeyguardIndicationController, mStackScroller, mMetricsLogger); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 69 | |
| 70 | doAnswer(invocation -> { |
| 71 | OnDismissAction onDismissAction = (OnDismissAction) invocation.getArguments()[0]; |
| 72 | onDismissAction.onDismiss(); |
| 73 | return null; |
| 74 | }).when(mStatusBarKeyguardViewManager).dismissWithAction(any(), any(), anyBoolean()); |
| 75 | |
| 76 | doAnswer(invocation -> { |
| 77 | Runnable runnable = (Runnable) invocation.getArguments()[0]; |
| 78 | runnable.run(); |
| 79 | return null; |
| 80 | }).when(mStatusBarKeyguardViewManager).addAfterKeyguardGoneRunnable(any()); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 81 | |
| 82 | when(mStackScroller.getActivatedChild()).thenReturn(null); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 85 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 86 | public void executeRunnableDismissingKeyguard_nullRunnable_showingAndOccluded() { |
| 87 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 88 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(true); |
| 89 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 90 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 91 | } |
| 92 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 93 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 94 | public void executeRunnableDismissingKeyguard_nullRunnable_showing() { |
| 95 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 96 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 97 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 98 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 101 | @Test |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 102 | public void executeRunnableDismissingKeyguard_nullRunnable_notShowing() { |
| 103 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 104 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 105 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 106 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 109 | @Ignore("flaky test") |
| 110 | @FlakyTest |
| 111 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 112 | public void lockscreenStateMetrics_notShowing() { |
| 113 | // uninteresting state, except that fingerprint must be non-zero |
| 114 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 115 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 116 | // interesting state |
| 117 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 118 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 119 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(false); |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 120 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 121 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame^] | 122 | MetricsAsserts.assertHasLog("missing hidden insecure lockscreen log", |
| 123 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 124 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 125 | .setType(MetricsEvent.TYPE_CLOSE) |
| 126 | .setSubtype(0)); |
| 127 | } |
| 128 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 129 | @Ignore("flaky test") |
| 130 | @FlakyTest |
| 131 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 132 | public void lockscreenStateMetrics_notShowing_secure() { |
| 133 | // uninteresting state, except that fingerprint must be non-zero |
| 134 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 135 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 136 | // interesting state |
| 137 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 138 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 139 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 140 | |
| 141 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 142 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame^] | 143 | MetricsAsserts.assertHasLog("missing hidden secure lockscreen log", |
| 144 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 145 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 146 | .setType(MetricsEvent.TYPE_CLOSE) |
| 147 | .setSubtype(1)); |
| 148 | } |
| 149 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 150 | @Ignore("flaky test") |
| 151 | @FlakyTest |
| 152 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 153 | public void lockscreenStateMetrics_isShowing() { |
| 154 | // uninteresting state, except that fingerprint must be non-zero |
| 155 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 156 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 157 | // interesting state |
| 158 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 159 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 160 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(false); |
| 161 | |
| 162 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 163 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame^] | 164 | MetricsAsserts.assertHasLog("missing insecure lockscreen showing", |
| 165 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 166 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 167 | .setType(MetricsEvent.TYPE_OPEN) |
| 168 | .setSubtype(0)); |
| 169 | } |
| 170 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 171 | @Ignore("flaky test") |
| 172 | @FlakyTest |
| 173 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 174 | public void lockscreenStateMetrics_isShowing_secure() { |
| 175 | // uninteresting state, except that fingerprint must be non-zero |
| 176 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 177 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 178 | // interesting state |
| 179 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 180 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); |
| 181 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 182 | |
| 183 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 184 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame^] | 185 | MetricsAsserts.assertHasLog("missing secure lockscreen showing log", |
| 186 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 187 | new LogMaker(MetricsEvent.LOCKSCREEN) |
| 188 | .setType(MetricsEvent.TYPE_OPEN) |
| 189 | .setSubtype(1)); |
| 190 | } |
| 191 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 192 | @Ignore("flaky test") |
| 193 | @FlakyTest |
| 194 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 195 | public void lockscreenStateMetrics_isShowingBouncer() { |
| 196 | // uninteresting state, except that fingerprint must be non-zero |
| 197 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 198 | when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); |
| 199 | // interesting state |
| 200 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 201 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); |
| 202 | when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); |
| 203 | |
| 204 | mStatusBar.onKeyguardViewManagerStatesUpdated(); |
| 205 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame^] | 206 | MetricsAsserts.assertHasLog("missing bouncer log", |
| 207 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 208 | new LogMaker(MetricsEvent.BOUNCER) |
| 209 | .setType(MetricsEvent.TYPE_OPEN) |
| 210 | .setSubtype(1)); |
| 211 | } |
| 212 | |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 213 | @Ignore("flaky test") |
| 214 | @FlakyTest |
| 215 | @Test |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 216 | public void onActivatedMetrics() { |
| 217 | ActivatableNotificationView view = mock(ActivatableNotificationView.class); |
| 218 | mStatusBar.onActivated(view); |
| 219 | |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame^] | 220 | MetricsAsserts.assertHasLog("missing lockscreen note tap log", |
| 221 | mMetricsLogger.getLogs(), |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 222 | new LogMaker(MetricsEvent.ACTION_LS_NOTE) |
| 223 | .setType(MetricsEvent.TYPE_ACTION)); |
| 224 | } |
| 225 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 226 | static class TestableStatusBar extends StatusBar { |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 227 | public TestableStatusBar(StatusBarKeyguardViewManager man, |
| 228 | UnlockMethodCache unlock, KeyguardIndicationController key, |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame^] | 229 | NotificationStackScrollLayout stack, MetricsLogger logger) { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 230 | mStatusBarKeyguardViewManager = man; |
Chris Wren | 27a52fa | 2017-02-01 14:21:43 -0500 | [diff] [blame] | 231 | mUnlockMethodCache = unlock; |
| 232 | mKeyguardIndicationController = key; |
| 233 | mStackScroller = stack; |
Chris Wren | ef31990 | 2017-03-07 17:58:31 -0500 | [diff] [blame^] | 234 | mMetricsLogger = logger; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | @Override |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 238 | protected H createHandler() { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 239 | return null; |
| 240 | } |
| 241 | } |
Adrian Roos | 02de498 | 2017-02-11 09:35:54 +0100 | [diff] [blame] | 242 | } |