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