• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 android.car.hiddenapitest;
18 
19 import static com.google.common.truth.Truth.assertWithMessage;
20 
21 import android.annotation.UserIdInt;
22 import android.car.extendedapitest.testbase.CarApiTestBase;
23 import android.car.settings.CarSettings;
24 import android.content.ContentResolver;
25 import android.os.UserHandle;
26 import android.provider.Settings;
27 import android.util.Log;
28 
29 import androidx.test.filters.SmallTest;
30 
31 import org.junit.Test;
32 
33 import java.util.HashMap;
34 import java.util.Iterator;
35 import java.util.Map;
36 
37 @SmallTest
38 public final class CarSettingsTest extends CarApiTestBase {
39 
40     private static final String TAG = CarSettingsTest.class.getSimpleName();
41     private static final String SCOPE_GLOBAL = "Global";
42     private static final String SCOPE_SECURE = "Secure";
43 
44     private final HashMap<String, String> mSettings = new HashMap<>();
45     private final @UserIdInt int mUserId = UserHandle.USER_CURRENT;
46 
47     private final ContentResolver mContentResolver;
48 
CarSettingsTest()49     public CarSettingsTest() throws Exception {
50         mContentResolver = getContext().getContentResolver();
51     }
52 
53     @Test
testCarSettingsNames()54     public void testCarSettingsNames() throws Exception {
55         loadSettingNames();
56 
57         boolean isAllSettingsReadable = checkAllSettingsReadable();
58 
59         assertWithMessage("car settings readable").that(isAllSettingsReadable).isTrue();
60     }
61 
loadSettingNames()62     private void loadSettingNames() {
63         mSettings.put(CarSettings.Global.DEFAULT_USER_RESTRICTIONS_SET, SCOPE_GLOBAL);
64         mSettings.put(CarSettings.Global.SYSTEM_BAR_VISIBILITY_OVERRIDE, SCOPE_GLOBAL);
65         mSettings.put(CarSettings.Global.DISABLE_INSTRUMENTATION_SERVICE, SCOPE_GLOBAL);
66         mSettings.put(CarSettings.Global.ENABLE_USER_SWITCH_DEVELOPER_MESSAGE, SCOPE_GLOBAL);
67         mSettings.put(CarSettings.Global.LAST_ACTIVE_USER_ID, SCOPE_GLOBAL);
68         mSettings.put(CarSettings.Global.LAST_ACTIVE_PERSISTENT_USER_ID, SCOPE_GLOBAL);
69         mSettings.put(CarSettings.Secure.KEY_AUDIO_FOCUS_NAVIGATION_REJECTED_DURING_CALL,
70                 SCOPE_SECURE);
71         mSettings.put(CarSettings.Secure.KEY_AUDIO_PERSIST_VOLUME_GROUP_MUTE_STATES, SCOPE_SECURE);
72         mSettings.put(CarSettings.Secure.KEY_ENABLE_INITIAL_NOTICE_SCREEN_TO_USER, SCOPE_SECURE);
73         mSettings.put(CarSettings.Secure.KEY_SETUP_WIZARD_IN_PROGRESS, SCOPE_SECURE);
74 
75         mSettings.put(CarSettings.Secure.KEY_BLUETOOTH_DEVICES, SCOPE_SECURE);
76     }
77 
checkAllSettingsReadable()78     private boolean checkAllSettingsReadable() throws Exception {
79         Iterator<Map.Entry<String, String>> settingEntrys = mSettings.entrySet().iterator();
80         while (settingEntrys.hasNext()) {
81             Map.Entry<String, String> entry = settingEntrys.next();
82             String name = entry.getKey();
83             String scope = entry.getValue();
84             switch (scope) {
85                 case SCOPE_GLOBAL:
86                     Settings.Global.getString(mContentResolver, name);
87                     break;
88                 case SCOPE_SECURE:
89                     Settings.Secure.getStringForUser(mContentResolver, name, mUserId);
90                     break;
91                 default:
92                     Log.e(TAG, "unsupported scope: " + scope);
93                     return false;
94             }
95         }
96         return true;
97     }
98 }
99