1 /* 2 * Copyright (C) 2022 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.server.audio; 18 19 import android.content.ContentResolver; 20 import android.provider.Settings; 21 22 /** 23 * Adapter for methods that read and write settings in android.provider.Settings. 24 */ 25 public class SettingsAdapter { getDefaultAdapter()26 public static SettingsAdapter getDefaultAdapter() { 27 return new SettingsAdapter(); 28 } 29 30 /** 31 * Wrapper methods for Settings.Global 32 */ 33 34 /** Wraps {@link Settings.Global#getInt(ContentResolver, String, int)} */ getGlobalInt(ContentResolver cr, String name, int def)35 public int getGlobalInt(ContentResolver cr, String name, int def) { 36 return Settings.Global.getInt(cr, name, def); 37 } 38 39 /** Wraps {@link Settings.Global#getString(ContentResolver, String)} */ getGlobalString(ContentResolver resolver, String name)40 public String getGlobalString(ContentResolver resolver, String name) { 41 return Settings.Global.getString(resolver, name); 42 } 43 44 /** Wraps {@link Settings.Global#putInt(ContentResolver, String, int)} */ putGlobalInt(ContentResolver cr, String name, int value)45 public boolean putGlobalInt(ContentResolver cr, String name, int value) { 46 return Settings.Global.putInt(cr, name, value); 47 } 48 49 /** Wraps {@link Settings.Global#putString(ContentResolver, String, String)} */ putGlobalString(ContentResolver resolver, String name, String value)50 public boolean putGlobalString(ContentResolver resolver, String name, String value) { 51 return Settings.Global.putString(resolver, name, value); 52 } 53 54 /** 55 * Wrapper methods for Settings.System 56 */ 57 58 /** Wraps {@link Settings.System#getIntForUser(ContentResolver, String, int, int)} */ getSystemIntForUser(ContentResolver cr, String name, int def, int userHandle)59 public int getSystemIntForUser(ContentResolver cr, String name, int def, int userHandle) { 60 return Settings.System.getIntForUser(cr, name, def, userHandle); 61 } 62 63 /** Wraps {@link Settings.System#putIntForUser(ContentResolver, String, int, int)} */ putSystemIntForUser(ContentResolver cr, String name, int value, int userHandle)64 public boolean putSystemIntForUser(ContentResolver cr, String name, int value, int userHandle) { 65 return Settings.System.putIntForUser(cr, name, value, userHandle); 66 } 67 68 /** 69 * Wrapper methods for Settings.Secure 70 */ 71 72 /** Wraps {@link Settings.Secure#getIntForUser(ContentResolver, String, int, int)} */ getSecureIntForUser(ContentResolver cr, String name, int def, int userHandle)73 public int getSecureIntForUser(ContentResolver cr, String name, int def, int userHandle) { 74 return Settings.Secure.getIntForUser(cr, name, def, userHandle); 75 } 76 77 /** Wraps {@link Settings.Secure#getStringForUser(ContentResolver, String, int)} */ getSecureStringForUser(ContentResolver resolver, String name, int userHandle)78 public String getSecureStringForUser(ContentResolver resolver, String name, int userHandle) { 79 return Settings.Secure.getStringForUser(resolver, name, userHandle); 80 } 81 82 /** Wraps {@link Settings.Secure#putIntForUser(ContentResolver, String, int, int)} */ putSecureIntForUser(ContentResolver cr, String name, int value, int userHandle)83 public boolean putSecureIntForUser(ContentResolver cr, String name, int value, int userHandle) { 84 return Settings.Secure.putIntForUser(cr, name, value, userHandle); 85 } 86 87 /** Wraps {@link Settings.Secure#putStringForUser(ContentResolver, String, String, int)} */ putSecureStringForUser(ContentResolver cr, String name, String value, int userHandle)88 public boolean putSecureStringForUser(ContentResolver cr, String name, String value, 89 int userHandle) { 90 return Settings.Secure.putStringForUser(cr, name, value, userHandle); 91 } 92 } 93