blob: 5320ecd46d62c3b19c46653b1a2778feda24760d [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
19import static com.google.common.truth.Truth.assertThat;
20
21import static org.mockito.ArgumentMatchers.any;
Lucas Dupinfdbfc542018-09-17 15:56:09 -070022import static org.mockito.ArgumentMatchers.anyInt;
Lucas Dupin1bd84d32020-03-13 17:28:18 -070023import static org.mockito.ArgumentMatchers.eq;
Lucas Dupina3e36272018-08-21 13:22:33 -070024import static org.mockito.Mockito.reset;
25import static org.mockito.Mockito.verify;
26import static org.mockito.Mockito.when;
27
28import android.app.IActivityManager;
Lucas Dupina3e36272018-08-21 13:22:33 -070029import android.testing.AndroidTestingRunner;
30import android.testing.TestableLooper.RunWithLooper;
Lucas Dupin1bd84d32020-03-13 17:28:18 -070031import android.view.View;
Lucas Dupina3e36272018-08-21 13:22:33 -070032import android.view.WindowManager;
33
Brett Chabot84151d92019-02-27 15:37:59 -080034import androidx.test.filters.SmallTest;
35
Dave Mankoff2aff6c32019-10-14 17:40:37 -040036import com.android.internal.colorextraction.ColorExtractor;
Lucas Dupina3e36272018-08-21 13:22:33 -070037import com.android.systemui.SysuiTestCase;
Dave Mankoff2aff6c32019-10-14 17:40:37 -040038import com.android.systemui.colorextraction.SysuiColorExtractor;
Ned Burnsaaeb44b2020-02-12 23:48:26 -050039import com.android.systemui.dump.DumpManager;
Lucas Dupine25c4872019-07-29 13:51:35 -070040import com.android.systemui.statusbar.SysuiStatusBarStateController;
41import com.android.systemui.statusbar.policy.ConfigurationController;
Lucas Dupina3e36272018-08-21 13:22:33 -070042
43import org.junit.Before;
44import org.junit.Test;
45import org.junit.runner.RunWith;
46import org.mockito.ArgumentCaptor;
Lucas Dupina3e36272018-08-21 13:22:33 -070047import org.mockito.Mock;
48import org.mockito.MockitoAnnotations;
49
50@RunWith(AndroidTestingRunner.class)
51@RunWithLooper
52@SmallTest
wilsonshihe8321942019-10-18 18:39:46 +080053public class NotificationShadeWindowControllerTest extends SysuiTestCase {
Lucas Dupina3e36272018-08-21 13:22:33 -070054
Dave Mankoff2aff6c32019-10-14 17:40:37 -040055 @Mock private WindowManager mWindowManager;
56 @Mock private DozeParameters mDozeParameters;
wilsonshihf587b632020-02-12 13:16:12 +080057 @Mock private NotificationShadeWindowView mNotificationShadeWindowView;
Dave Mankoff2aff6c32019-10-14 17:40:37 -040058 @Mock private IActivityManager mActivityManager;
59 @Mock private SysuiStatusBarStateController mStatusBarStateController;
60 @Mock private ConfigurationController mConfigurationController;
61 @Mock private KeyguardBypassController mKeyguardBypassController;
62 @Mock private SysuiColorExtractor mColorExtractor;
63 @Mock ColorExtractor.GradientColors mGradientColors;
Ned Burnsaaeb44b2020-02-12 23:48:26 -050064 @Mock private DumpManager mDumpManager;
Lucas Dupina3e36272018-08-21 13:22:33 -070065
wilsonshihe8321942019-10-18 18:39:46 +080066 private NotificationShadeWindowController mNotificationShadeWindowController;
Lucas Dupina3e36272018-08-21 13:22:33 -070067
68 @Before
69 public void setUp() {
70 MockitoAnnotations.initMocks(this);
71 when(mDozeParameters.getAlwaysOn()).thenReturn(true);
Dave Mankoff2aff6c32019-10-14 17:40:37 -040072 when(mColorExtractor.getNeutralColors()).thenReturn(mGradientColors);
Lucas Dupina3e36272018-08-21 13:22:33 -070073
wilsonshihe8321942019-10-18 18:39:46 +080074 mNotificationShadeWindowController = new NotificationShadeWindowController(mContext,
75 mWindowManager, mActivityManager, mDozeParameters, mStatusBarStateController,
Lucas Dupind73410a2020-02-18 12:54:41 -080076 mConfigurationController, mKeyguardBypassController, mColorExtractor,
Ned Burnsaaeb44b2020-02-12 23:48:26 -050077 mDumpManager);
wilsonshihf587b632020-02-12 13:16:12 +080078 mNotificationShadeWindowController.setNotificationShadeView(mNotificationShadeWindowView);
Heemin Seogafb3dbc2019-11-04 16:05:19 -080079
wilsonshihe8321942019-10-18 18:39:46 +080080 mNotificationShadeWindowController.attach();
Lucas Dupina3e36272018-08-21 13:22:33 -070081 }
82
83 @Test
84 public void testSetDozing_hidesSystemOverlays() {
wilsonshihe8321942019-10-18 18:39:46 +080085 mNotificationShadeWindowController.setDozing(true);
Lucas Dupina3e36272018-08-21 13:22:33 -070086 ArgumentCaptor<WindowManager.LayoutParams> captor =
87 ArgumentCaptor.forClass(WindowManager.LayoutParams.class);
88 verify(mWindowManager).updateViewLayout(any(), captor.capture());
89 int flag = captor.getValue().privateFlags
Philip P. Moltmann66ce2382018-10-09 13:46:11 -070090 & WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Lucas Dupina3e36272018-08-21 13:22:33 -070091 assertThat(flag).isNotEqualTo(0);
92
93 reset(mWindowManager);
wilsonshihe8321942019-10-18 18:39:46 +080094 mNotificationShadeWindowController.setDozing(false);
Lucas Dupina3e36272018-08-21 13:22:33 -070095 verify(mWindowManager).updateViewLayout(any(), captor.capture());
96 flag = captor.getValue().privateFlags
Philip P. Moltmann66ce2382018-10-09 13:46:11 -070097 & WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Lucas Dupina3e36272018-08-21 13:22:33 -070098 assertThat(flag).isEqualTo(0);
99 }
Lucas Dupinfdbfc542018-09-17 15:56:09 -0700100
101 @Test
102 public void testOnThemeChanged_doesntCrash() {
wilsonshihe8321942019-10-18 18:39:46 +0800103 mNotificationShadeWindowController.onThemeChanged();
Lucas Dupinfdbfc542018-09-17 15:56:09 -0700104 }
105
106 @Test
107 public void testAdd_updatesVisibilityFlags() {
wilsonshihf587b632020-02-12 13:16:12 +0800108 verify(mNotificationShadeWindowView).setSystemUiVisibility(anyInt());
Lucas Dupinfdbfc542018-09-17 15:56:09 -0700109 }
Lucas Dupin42ebe542019-01-22 09:45:09 -0800110
111 @Test
112 public void testSetForcePluginOpen_beforeStatusBarInitialization() {
wilsonshihe8321942019-10-18 18:39:46 +0800113 mNotificationShadeWindowController.setForcePluginOpen(true);
Lucas Dupin42ebe542019-01-22 09:45:09 -0800114 }
Lucas Dupin1bd84d32020-03-13 17:28:18 -0700115
116 @Test
117 public void setBackgroundBlurRadius_expandedWithBlurs() {
118 mNotificationShadeWindowController.setBackgroundBlurRadius(10);
119 verify(mNotificationShadeWindowView).setVisibility(eq(View.VISIBLE));
120
121 mNotificationShadeWindowController.setBackgroundBlurRadius(0);
122 verify(mNotificationShadeWindowView).setVisibility(eq(View.INVISIBLE));
123 }
Lucas Dupina3e36272018-08-21 13:22:33 -0700124}