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.car.test.ApiCheckerRule.Builder; 24 import android.content.ContentResolver; 25 import android.os.UserHandle; 26 import android.provider.Settings; 27 import android.test.suitebuilder.annotation.SmallTest; 28 import android.util.Log; 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 // TODO(b/242350638): add missing annotations, remove (on child bug of 242350638) 53 @Override configApiCheckerRule(Builder builder)54 protected void configApiCheckerRule(Builder builder) { 55 Log.w(TAG, "Disabling API requirements check"); 56 builder.disableAnnotationsCheck(); 57 } 58 59 @Test testCarSettingsNames()60 public void testCarSettingsNames() throws Exception { 61 loadSettingNames(); 62 63 boolean isAllSettingsReadable = checkAllSettingsReadable(); 64 65 assertWithMessage("car settings readable").that(isAllSettingsReadable).isTrue(); 66 } 67 loadSettingNames()68 private void loadSettingNames() { 69 mSettings.put(CarSettings.Global.DEFAULT_USER_RESTRICTIONS_SET, SCOPE_GLOBAL); 70 mSettings.put(CarSettings.Global.SYSTEM_BAR_VISIBILITY_OVERRIDE, SCOPE_GLOBAL); 71 mSettings.put(CarSettings.Global.DISABLE_INSTRUMENTATION_SERVICE, SCOPE_GLOBAL); 72 mSettings.put(CarSettings.Global.ENABLE_USER_SWITCH_DEVELOPER_MESSAGE, SCOPE_GLOBAL); 73 mSettings.put(CarSettings.Global.LAST_ACTIVE_USER_ID, SCOPE_GLOBAL); 74 mSettings.put(CarSettings.Global.LAST_ACTIVE_PERSISTENT_USER_ID, SCOPE_GLOBAL); 75 mSettings.put(CarSettings.Secure.KEY_AUDIO_FOCUS_NAVIGATION_REJECTED_DURING_CALL, 76 SCOPE_SECURE); 77 mSettings.put(CarSettings.Secure.KEY_AUDIO_PERSIST_VOLUME_GROUP_MUTE_STATES, SCOPE_SECURE); 78 mSettings.put(CarSettings.Secure.KEY_ENABLE_INITIAL_NOTICE_SCREEN_TO_USER, SCOPE_SECURE); 79 mSettings.put(CarSettings.Secure.KEY_SETUP_WIZARD_IN_PROGRESS, SCOPE_SECURE); 80 81 mSettings.put(CarSettings.Secure.KEY_BLUETOOTH_DEVICES, SCOPE_SECURE); 82 } 83 checkAllSettingsReadable()84 private boolean checkAllSettingsReadable() throws Exception { 85 Iterator<Map.Entry<String, String>> settingEntrys = mSettings.entrySet().iterator(); 86 while (settingEntrys.hasNext()) { 87 Map.Entry<String, String> entry = settingEntrys.next(); 88 String name = entry.getKey(); 89 String scope = entry.getValue(); 90 switch (scope) { 91 case SCOPE_GLOBAL: 92 Settings.Global.getString(mContentResolver, name); 93 break; 94 case SCOPE_SECURE: 95 Settings.Secure.getStringForUser(mContentResolver, name, mUserId); 96 break; 97 default: 98 Log.e(TAG, "unsupported scope: " + scope); 99 return false; 100 } 101 } 102 return true; 103 } 104 } 105