blob: ca6c16f91ad80d6e2a7bf1c4dc4db772f853efa1 [file] [log] [blame]
Lucas Dupina3e36272018-08-21 13:22:33 -07001/*
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
wilsonshihe8321942019-10-18 18:39:46 +080014 * limitations under the License.
Lucas Dupina3e36272018-08-21 13:22:33 -070015 */
16
17package com.android.systemui.statusbar.phone;
18
Lucas Dupinf22bf192020-05-11 12:44:31 -070019import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
20import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
21
Lucas Dupina3e36272018-08-21 13:22:33 -070022import static com.google.common.truth.Truth.assertThat;
23
24import static org.mockito.ArgumentMatchers.any;
Lucas Dupinfdbfc542018-09-17 15:56:09 -070025import static org.mockito.ArgumentMatchers.anyInt;
Lucas Dupin1bd84d32020-03-13 17:28:18 -070026import static org.mockito.ArgumentMatchers.eq;
Lucas Dupinf22bf192020-05-11 12:44:31 -070027import static org.mockito.Mockito.clearInvocations;
Lucas Dupina3e36272018-08-21 13:22:33 -070028import static org.mockito.Mockito.reset;
29import static org.mockito.Mockito.verify;
30import static org.mockito.Mockito.when;
31
32import android.app.IActivityManager;
Lucas Dupina3e36272018-08-21 13:22:33 -070033import android.testing.AndroidTestingRunner;
34import android.testing.TestableLooper.RunWithLooper;
Lucas Dupin1bd84d32020-03-13 17:28:18 -070035import android.view.View;
Lucas Dupina3e36272018-08-21 13:22:33 -070036import android.view.WindowManager;
37
Brett Chabot84151d92019-02-27 15:37:59 -080038import androidx.test.filters.SmallTest;
39
Dave Mankoff2aff6c32019-10-14 17:40:37 -040040import com.android.internal.colorextraction.ColorExtractor;
Lucas Dupina3e36272018-08-21 13:22:33 -070041import com.android.systemui.SysuiTestCase;
Dave Mankoff2aff6c32019-10-14 17:40:37 -040042import com.android.systemui.colorextraction.SysuiColorExtractor;
Ned Burnsaaeb44b2020-02-12 23:48:26 -050043import com.android.systemui.dump.DumpManager;
Lucas Dupine25c4872019-07-29 13:51:35 -070044import com.android.systemui.statusbar.SysuiStatusBarStateController;
45import com.android.systemui.statusbar.policy.ConfigurationController;
Lucas Dupina3e36272018-08-21 13:22:33 -070046
47import org.junit.Before;
48import org.junit.Test;
49import org.junit.runner.RunWith;
50import org.mockito.ArgumentCaptor;
Lucas Dupinf22bf192020-05-11 12:44:31 -070051import org.mockito.Captor;
Lucas Dupina3e36272018-08-21 13:22:33 -070052import org.mockito.Mock;
53import org.mockito.MockitoAnnotations;
54
55@RunWith(AndroidTestingRunner.class)
56@RunWithLooper
57@SmallTest
wilsonshihe8321942019-10-18 18:39:46 +080058public class NotificationShadeWindowControllerTest extends SysuiTestCase {
Lucas Dupina3e36272018-08-21 13:22:33 -070059
Dave Mankoff2aff6c32019-10-14 17:40:37 -040060 @Mock private WindowManager mWindowManager;
61 @Mock private DozeParameters mDozeParameters;
wilsonshihf587b632020-02-12 13:16:12 +080062 @Mock private NotificationShadeWindowView mNotificationShadeWindowView;
Dave Mankoff2aff6c32019-10-14 17:40:37 -040063 @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 Burnsaaeb44b2020-02-12 23:48:26 -050069 @Mock private DumpManager mDumpManager;
Lucas Dupinf22bf192020-05-11 12:44:31 -070070 @Captor private ArgumentCaptor<WindowManager.LayoutParams> mLayoutParameters;
Lucas Dupina3e36272018-08-21 13:22:33 -070071
wilsonshihe8321942019-10-18 18:39:46 +080072 private NotificationShadeWindowController mNotificationShadeWindowController;
Lucas Dupina3e36272018-08-21 13:22:33 -070073
74 @Before
75 public void setUp() {
76 MockitoAnnotations.initMocks(this);
77 when(mDozeParameters.getAlwaysOn()).thenReturn(true);
Dave Mankoff2aff6c32019-10-14 17:40:37 -040078 when(mColorExtractor.getNeutralColors()).thenReturn(mGradientColors);
Lucas Dupina3e36272018-08-21 13:22:33 -070079
wilsonshihe8321942019-10-18 18:39:46 +080080 mNotificationShadeWindowController = new NotificationShadeWindowController(mContext,
81 mWindowManager, mActivityManager, mDozeParameters, mStatusBarStateController,
Lucas Dupind73410a2020-02-18 12:54:41 -080082 mConfigurationController, mKeyguardBypassController, mColorExtractor,
Ned Burnsaaeb44b2020-02-12 23:48:26 -050083 mDumpManager);
wilsonshihf587b632020-02-12 13:16:12 +080084 mNotificationShadeWindowController.setNotificationShadeView(mNotificationShadeWindowView);
Heemin Seogafb3dbc2019-11-04 16:05:19 -080085
wilsonshihe8321942019-10-18 18:39:46 +080086 mNotificationShadeWindowController.attach();
Lucas Dupina3e36272018-08-21 13:22:33 -070087 }
88
89 @Test
90 public void testSetDozing_hidesSystemOverlays() {
wilsonshihe8321942019-10-18 18:39:46 +080091 mNotificationShadeWindowController.setDozing(true);
Lucas Dupina3e36272018-08-21 13:22:33 -070092 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. Moltmann66ce2382018-10-09 13:46:11 -070096 & WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Lucas Dupina3e36272018-08-21 13:22:33 -070097 assertThat(flag).isNotEqualTo(0);
98
99 reset(mWindowManager);
wilsonshihe8321942019-10-18 18:39:46 +0800100 mNotificationShadeWindowController.setDozing(false);
Lucas Dupina3e36272018-08-21 13:22:33 -0700101 verify(mWindowManager).updateViewLayout(any(), captor.capture());
102 flag = captor.getValue().privateFlags
Philip P. Moltmann66ce2382018-10-09 13:46:11 -0700103 & WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Lucas Dupina3e36272018-08-21 13:22:33 -0700104 assertThat(flag).isEqualTo(0);
105 }
Lucas Dupinfdbfc542018-09-17 15:56:09 -0700106
107 @Test
108 public void testOnThemeChanged_doesntCrash() {
wilsonshihe8321942019-10-18 18:39:46 +0800109 mNotificationShadeWindowController.onThemeChanged();
Lucas Dupinfdbfc542018-09-17 15:56:09 -0700110 }
111
112 @Test
113 public void testAdd_updatesVisibilityFlags() {
wilsonshihf587b632020-02-12 13:16:12 +0800114 verify(mNotificationShadeWindowView).setSystemUiVisibility(anyInt());
Lucas Dupinfdbfc542018-09-17 15:56:09 -0700115 }
Lucas Dupin42ebe542019-01-22 09:45:09 -0800116
117 @Test
118 public void testSetForcePluginOpen_beforeStatusBarInitialization() {
wilsonshihe8321942019-10-18 18:39:46 +0800119 mNotificationShadeWindowController.setForcePluginOpen(true);
Lucas Dupin42ebe542019-01-22 09:45:09 -0800120 }
Lucas Dupin1bd84d32020-03-13 17:28:18 -0700121
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 Dupinf22bf192020-05-11 12:44:31 -0700130
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 Dupina3e36272018-08-21 13:22:33 -0700172}