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