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