• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.wm;
18 
19 import static android.view.WindowInsets.Type.navigationBars;
20 import static android.view.WindowInsets.Type.statusBars;
21 
22 import static com.google.common.truth.Truth.assertThat;
23 
24 import android.car.settings.CarSettings;
25 import android.provider.Settings;
26 import android.testing.AndroidTestingRunner;
27 import android.testing.TestableLooper;
28 
29 import androidx.test.filters.SmallTest;
30 
31 import com.android.systemui.SysuiTestCase;
32 
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 
38 @RunWith(AndroidTestingRunner.class)
39 @TestableLooper.RunWithLooper
40 @SmallTest
41 public class BarControlPolicyTest extends SysuiTestCase {
42 
43     private static final String PACKAGE_NAME = "sample.app";
44 
45     @Before
setUp()46     public void setUp() {
47         BarControlPolicy.reset();
48     }
49 
50     @After
tearDown()51     public void tearDown() {
52         Settings.Global.clearProviderForTest();
53     }
54 
55     @Test
reloadFromSetting_notSet_doesNotSetFilters()56     public void reloadFromSetting_notSet_doesNotSetFilters() {
57         BarControlPolicy.reloadFromSetting(mContext);
58 
59         assertThat(BarControlPolicy.sImmersiveStatusFilter).isNull();
60     }
61 
62     @Test
reloadFromSetting_invalidPolicyControlString_doesNotSetFilters()63     public void reloadFromSetting_invalidPolicyControlString_doesNotSetFilters() {
64         String text = "sample text";
65         Settings.Global.putString(
66                 mContext.getContentResolver(),
67                 CarSettings.Global.SYSTEM_BAR_VISIBILITY_OVERRIDE,
68                 text
69         );
70 
71         BarControlPolicy.reloadFromSetting(mContext);
72 
73         assertThat(BarControlPolicy.sImmersiveStatusFilter).isNull();
74     }
75 
76     @Test
reloadFromSetting_validPolicyControlString_setsFilters()77     public void reloadFromSetting_validPolicyControlString_setsFilters() {
78         String text = "immersive.status=" + PACKAGE_NAME;
79         Settings.Global.putString(
80                 mContext.getContentResolver(),
81                 CarSettings.Global.SYSTEM_BAR_VISIBILITY_OVERRIDE,
82                 text
83         );
84 
85         BarControlPolicy.reloadFromSetting(mContext);
86 
87         assertThat(BarControlPolicy.sImmersiveStatusFilter).isNotNull();
88     }
89 
90     @Test
reloadFromSetting_filtersSet_doesNotSetFiltersAgain()91     public void reloadFromSetting_filtersSet_doesNotSetFiltersAgain() {
92         String text = "immersive.status=" + PACKAGE_NAME;
93         Settings.Global.putString(
94                 mContext.getContentResolver(),
95                 CarSettings.Global.SYSTEM_BAR_VISIBILITY_OVERRIDE,
96                 text
97         );
98 
99         BarControlPolicy.reloadFromSetting(mContext);
100 
101         assertThat(BarControlPolicy.reloadFromSetting(mContext)).isFalse();
102     }
103 
104     @Test
getBarVisibilities_policyControlNotSet_showsSystemBars()105     public void getBarVisibilities_policyControlNotSet_showsSystemBars() {
106         int[] visibilities = BarControlPolicy.getBarVisibilities(PACKAGE_NAME);
107 
108         assertThat(visibilities[0]).isEqualTo(statusBars() | navigationBars());
109         assertThat(visibilities[1]).isEqualTo(0);
110     }
111 
112     @Test
getBarVisibilities_immersiveStatusForAppAndMatchingApp_hidesStatusBar()113     public void getBarVisibilities_immersiveStatusForAppAndMatchingApp_hidesStatusBar() {
114         Settings.Global.putString(
115                 mContext.getContentResolver(),
116                 CarSettings.Global.SYSTEM_BAR_VISIBILITY_OVERRIDE,
117                 "immersive.status=" + PACKAGE_NAME);
118         BarControlPolicy.reloadFromSetting(mContext);
119 
120         int[] visibilities = BarControlPolicy.getBarVisibilities(PACKAGE_NAME);
121 
122         assertThat(visibilities[0]).isEqualTo(navigationBars());
123         assertThat(visibilities[1]).isEqualTo(statusBars());
124     }
125 
126     @Test
getBarVisibilities_immersiveStatusForAppAndNonMatchingApp_showsSystemBars()127     public void getBarVisibilities_immersiveStatusForAppAndNonMatchingApp_showsSystemBars() {
128         Settings.Global.putString(
129                 mContext.getContentResolver(),
130                 CarSettings.Global.SYSTEM_BAR_VISIBILITY_OVERRIDE,
131                 "immersive.status=" + PACKAGE_NAME);
132         BarControlPolicy.reloadFromSetting(mContext);
133 
134         int[] visibilities = BarControlPolicy.getBarVisibilities("sample2.app");
135 
136         assertThat(visibilities[0]).isEqualTo(statusBars() | navigationBars());
137         assertThat(visibilities[1]).isEqualTo(0);
138     }
139 
140     @Test
getBarVisibilities_immersiveStatusForAppsAndNonApp_showsSystemBars()141     public void getBarVisibilities_immersiveStatusForAppsAndNonApp_showsSystemBars() {
142         Settings.Global.putString(
143                 mContext.getContentResolver(),
144                 CarSettings.Global.SYSTEM_BAR_VISIBILITY_OVERRIDE,
145                 "immersive.status=apps");
146         BarControlPolicy.reloadFromSetting(mContext);
147 
148         int[] visibilities = BarControlPolicy.getBarVisibilities(PACKAGE_NAME);
149 
150         assertThat(visibilities[0]).isEqualTo(statusBars() | navigationBars());
151         assertThat(visibilities[1]).isEqualTo(0);
152     }
153 
154     @Test
getBarVisibilities_immersiveFullForAppAndMatchingApp_hidesSystemBars()155     public void getBarVisibilities_immersiveFullForAppAndMatchingApp_hidesSystemBars() {
156         Settings.Global.putString(
157                 mContext.getContentResolver(),
158                 CarSettings.Global.SYSTEM_BAR_VISIBILITY_OVERRIDE,
159                 "immersive.full=" + PACKAGE_NAME);
160         BarControlPolicy.reloadFromSetting(mContext);
161 
162         int[] visibilities = BarControlPolicy.getBarVisibilities(PACKAGE_NAME);
163 
164         assertThat(visibilities[0]).isEqualTo(0);
165         assertThat(visibilities[1]).isEqualTo(statusBars() | navigationBars());
166     }
167 
168     @Test
getBarVisibilities_immersiveFullForAppAndNonMatchingApp_showsSystemBars()169     public void getBarVisibilities_immersiveFullForAppAndNonMatchingApp_showsSystemBars() {
170         Settings.Global.putString(
171                 mContext.getContentResolver(),
172                 CarSettings.Global.SYSTEM_BAR_VISIBILITY_OVERRIDE,
173                 "immersive.full=" + PACKAGE_NAME);
174         BarControlPolicy.reloadFromSetting(mContext);
175 
176         int[] visibilities = BarControlPolicy.getBarVisibilities("sample2.app");
177 
178         assertThat(visibilities[0]).isEqualTo(statusBars() | navigationBars());
179         assertThat(visibilities[1]).isEqualTo(0);
180     }
181 
182     @Test
getBarVisibilities_immersiveFullForAppsAndNonApp_showsSystemBars()183     public void getBarVisibilities_immersiveFullForAppsAndNonApp_showsSystemBars() {
184         Settings.Global.putString(
185                 mContext.getContentResolver(),
186                 CarSettings.Global.SYSTEM_BAR_VISIBILITY_OVERRIDE,
187                 "immersive.full=apps");
188         BarControlPolicy.reloadFromSetting(mContext);
189 
190         int[] visibilities = BarControlPolicy.getBarVisibilities(PACKAGE_NAME);
191 
192         assertThat(visibilities[0]).isEqualTo(statusBars() | navigationBars());
193         assertThat(visibilities[1]).isEqualTo(0);
194     }
195 }
196