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