Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 14 | * limitations under the License. |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
Lucas Dupin | f22bf19 | 2020-05-11 12:44:31 -0700 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
| 20 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 21 | |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 22 | import static com.google.common.truth.Truth.assertThat; |
| 23 | |
| 24 | import static org.mockito.ArgumentMatchers.any; |
Lucas Dupin | fdbfc54 | 2018-09-17 15:56:09 -0700 | [diff] [blame] | 25 | import static org.mockito.ArgumentMatchers.anyInt; |
Lucas Dupin | 1bd84d3 | 2020-03-13 17:28:18 -0700 | [diff] [blame] | 26 | import static org.mockito.ArgumentMatchers.eq; |
Lucas Dupin | f22bf19 | 2020-05-11 12:44:31 -0700 | [diff] [blame] | 27 | import static org.mockito.Mockito.clearInvocations; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 28 | import static org.mockito.Mockito.reset; |
| 29 | import static org.mockito.Mockito.verify; |
| 30 | import static org.mockito.Mockito.when; |
| 31 | |
| 32 | import android.app.IActivityManager; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 33 | import android.testing.AndroidTestingRunner; |
| 34 | import android.testing.TestableLooper.RunWithLooper; |
Lucas Dupin | 1bd84d3 | 2020-03-13 17:28:18 -0700 | [diff] [blame] | 35 | import android.view.View; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 36 | import android.view.WindowManager; |
| 37 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 38 | import androidx.test.filters.SmallTest; |
| 39 | |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 40 | import com.android.internal.colorextraction.ColorExtractor; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 41 | import com.android.systemui.SysuiTestCase; |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 42 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 43 | import com.android.systemui.dump.DumpManager; |
Lucas Dupin | e25c487 | 2019-07-29 13:51:35 -0700 | [diff] [blame] | 44 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
| 45 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 46 | |
| 47 | import org.junit.Before; |
| 48 | import org.junit.Test; |
| 49 | import org.junit.runner.RunWith; |
| 50 | import org.mockito.ArgumentCaptor; |
Lucas Dupin | f22bf19 | 2020-05-11 12:44:31 -0700 | [diff] [blame] | 51 | import org.mockito.Captor; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 52 | import org.mockito.Mock; |
| 53 | import org.mockito.MockitoAnnotations; |
| 54 | |
| 55 | @RunWith(AndroidTestingRunner.class) |
| 56 | @RunWithLooper |
| 57 | @SmallTest |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 58 | public class NotificationShadeWindowControllerTest extends SysuiTestCase { |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 59 | |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 60 | @Mock private WindowManager mWindowManager; |
| 61 | @Mock private DozeParameters mDozeParameters; |
wilsonshih | f587b63 | 2020-02-12 13:16:12 +0800 | [diff] [blame] | 62 | @Mock private NotificationShadeWindowView mNotificationShadeWindowView; |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 63 | @Mock private IActivityManager mActivityManager; |
| 64 | @Mock private SysuiStatusBarStateController mStatusBarStateController; |
| 65 | @Mock private ConfigurationController mConfigurationController; |
| 66 | @Mock private KeyguardBypassController mKeyguardBypassController; |
| 67 | @Mock private SysuiColorExtractor mColorExtractor; |
| 68 | @Mock ColorExtractor.GradientColors mGradientColors; |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 69 | @Mock private DumpManager mDumpManager; |
Lucas Dupin | f22bf19 | 2020-05-11 12:44:31 -0700 | [diff] [blame] | 70 | @Captor private ArgumentCaptor<WindowManager.LayoutParams> mLayoutParameters; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 71 | |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 72 | private NotificationShadeWindowController mNotificationShadeWindowController; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 73 | |
| 74 | @Before |
| 75 | public void setUp() { |
| 76 | MockitoAnnotations.initMocks(this); |
| 77 | when(mDozeParameters.getAlwaysOn()).thenReturn(true); |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 78 | when(mColorExtractor.getNeutralColors()).thenReturn(mGradientColors); |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 79 | |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 80 | mNotificationShadeWindowController = new NotificationShadeWindowController(mContext, |
| 81 | mWindowManager, mActivityManager, mDozeParameters, mStatusBarStateController, |
Lucas Dupin | d73410a | 2020-02-18 12:54:41 -0800 | [diff] [blame] | 82 | mConfigurationController, mKeyguardBypassController, mColorExtractor, |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 83 | mDumpManager); |
wilsonshih | f587b63 | 2020-02-12 13:16:12 +0800 | [diff] [blame] | 84 | mNotificationShadeWindowController.setNotificationShadeView(mNotificationShadeWindowView); |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 85 | |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 86 | mNotificationShadeWindowController.attach(); |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Test |
| 90 | public void testSetDozing_hidesSystemOverlays() { |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 91 | mNotificationShadeWindowController.setDozing(true); |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 92 | ArgumentCaptor<WindowManager.LayoutParams> captor = |
| 93 | ArgumentCaptor.forClass(WindowManager.LayoutParams.class); |
| 94 | verify(mWindowManager).updateViewLayout(any(), captor.capture()); |
| 95 | int flag = captor.getValue().privateFlags |
Philip P. Moltmann | 66ce238 | 2018-10-09 13:46:11 -0700 | [diff] [blame] | 96 | & WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 97 | assertThat(flag).isNotEqualTo(0); |
| 98 | |
| 99 | reset(mWindowManager); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 100 | mNotificationShadeWindowController.setDozing(false); |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 101 | verify(mWindowManager).updateViewLayout(any(), captor.capture()); |
| 102 | flag = captor.getValue().privateFlags |
Philip P. Moltmann | 66ce238 | 2018-10-09 13:46:11 -0700 | [diff] [blame] | 103 | & WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 104 | assertThat(flag).isEqualTo(0); |
| 105 | } |
Lucas Dupin | fdbfc54 | 2018-09-17 15:56:09 -0700 | [diff] [blame] | 106 | |
| 107 | @Test |
| 108 | public void testOnThemeChanged_doesntCrash() { |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 109 | mNotificationShadeWindowController.onThemeChanged(); |
Lucas Dupin | fdbfc54 | 2018-09-17 15:56:09 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Test |
| 113 | public void testAdd_updatesVisibilityFlags() { |
wilsonshih | f587b63 | 2020-02-12 13:16:12 +0800 | [diff] [blame] | 114 | verify(mNotificationShadeWindowView).setSystemUiVisibility(anyInt()); |
Lucas Dupin | fdbfc54 | 2018-09-17 15:56:09 -0700 | [diff] [blame] | 115 | } |
Lucas Dupin | 42ebe54 | 2019-01-22 09:45:09 -0800 | [diff] [blame] | 116 | |
| 117 | @Test |
| 118 | public void testSetForcePluginOpen_beforeStatusBarInitialization() { |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 119 | mNotificationShadeWindowController.setForcePluginOpen(true); |
Lucas Dupin | 42ebe54 | 2019-01-22 09:45:09 -0800 | [diff] [blame] | 120 | } |
Lucas Dupin | 1bd84d3 | 2020-03-13 17:28:18 -0700 | [diff] [blame] | 121 | |
| 122 | @Test |
| 123 | public void setBackgroundBlurRadius_expandedWithBlurs() { |
| 124 | mNotificationShadeWindowController.setBackgroundBlurRadius(10); |
| 125 | verify(mNotificationShadeWindowView).setVisibility(eq(View.VISIBLE)); |
| 126 | |
| 127 | mNotificationShadeWindowController.setBackgroundBlurRadius(0); |
| 128 | verify(mNotificationShadeWindowView).setVisibility(eq(View.INVISIBLE)); |
| 129 | } |
Lucas Dupin | f22bf19 | 2020-05-11 12:44:31 -0700 | [diff] [blame] | 130 | |
| 131 | @Test |
| 132 | public void setBouncerShowing_isFocusable_whenNeedsInput() { |
| 133 | mNotificationShadeWindowController.setKeyguardNeedsInput(true); |
| 134 | clearInvocations(mWindowManager); |
| 135 | mNotificationShadeWindowController.setBouncerShowing(true); |
| 136 | |
| 137 | verify(mWindowManager).updateViewLayout(any(), mLayoutParameters.capture()); |
| 138 | assertThat((mLayoutParameters.getValue().flags & FLAG_NOT_FOCUSABLE) == 0).isTrue(); |
| 139 | assertThat((mLayoutParameters.getValue().flags & FLAG_ALT_FOCUSABLE_IM) == 0).isTrue(); |
| 140 | } |
| 141 | |
| 142 | @Test |
| 143 | public void setKeyguardShowing_focusable_notAltFocusable_whenNeedsInput() { |
| 144 | mNotificationShadeWindowController.setKeyguardShowing(true); |
| 145 | clearInvocations(mWindowManager); |
| 146 | mNotificationShadeWindowController.setKeyguardNeedsInput(true); |
| 147 | |
| 148 | verify(mWindowManager).updateViewLayout(any(), mLayoutParameters.capture()); |
| 149 | assertThat((mLayoutParameters.getValue().flags & FLAG_NOT_FOCUSABLE) == 0).isTrue(); |
| 150 | assertThat((mLayoutParameters.getValue().flags & FLAG_ALT_FOCUSABLE_IM) == 0).isTrue(); |
| 151 | } |
| 152 | |
| 153 | @Test |
| 154 | public void setPanelExpanded_notFocusable_altFocusable_whenPanelIsOpen() { |
| 155 | mNotificationShadeWindowController.setPanelExpanded(true); |
| 156 | clearInvocations(mWindowManager); |
| 157 | mNotificationShadeWindowController.setNotificationShadeFocusable(true); |
| 158 | |
| 159 | verify(mWindowManager).updateViewLayout(any(), mLayoutParameters.capture()); |
| 160 | assertThat((mLayoutParameters.getValue().flags & FLAG_NOT_FOCUSABLE) == 0).isTrue(); |
| 161 | assertThat((mLayoutParameters.getValue().flags & FLAG_ALT_FOCUSABLE_IM) != 0).isTrue(); |
| 162 | } |
| 163 | |
| 164 | @Test |
| 165 | public void setKeyguardShowing_notFocusable_byDefault() { |
| 166 | mNotificationShadeWindowController.setKeyguardShowing(false); |
| 167 | |
| 168 | verify(mWindowManager).updateViewLayout(any(), mLayoutParameters.capture()); |
| 169 | assertThat((mLayoutParameters.getValue().flags & FLAG_NOT_FOCUSABLE) != 0).isTrue(); |
| 170 | assertThat((mLayoutParameters.getValue().flags & FLAG_ALT_FOCUSABLE_IM) == 0).isTrue(); |
| 171 | } |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 172 | } |