1 /*
2  * Copyright (C) 2024 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.intentresolver.platform
18 
19 import android.content.ContentResolver
20 import android.provider.Settings
21 import javax.inject.Inject
22 
23 object SettingsImpl {
24     /** An implementation of GlobalSettings which forwards to [Settings.Global] */
25     class Global @Inject constructor(private val contentResolver: ContentResolver) :
26         GlobalSettings {
getStringOrNullnull27         override fun getStringOrNull(name: String): String? {
28             return Settings.Global.getString(contentResolver, name)
29         }
30 
putStringnull31         override fun putString(name: String, value: String): Boolean {
32             return Settings.Global.putString(contentResolver, name, value)
33         }
34     }
35 
36     /** An implementation of SecureSettings which forwards to [Settings.Secure] */
37     class Secure @Inject constructor(private val contentResolver: ContentResolver) :
38         SecureSettings {
getStringOrNullnull39         override fun getStringOrNull(name: String): String? {
40             return Settings.Secure.getString(contentResolver, name)
41         }
42 
putStringnull43         override fun putString(name: String, value: String): Boolean {
44             return Settings.Secure.putString(contentResolver, name, value)
45         }
46     }
47 
48     /** An implementation of SystemSettings which forwards to [Settings.System] */
49     class System @Inject constructor(private val contentResolver: ContentResolver) :
50         SystemSettings {
getStringOrNullnull51         override fun getStringOrNull(name: String): String? {
52             return Settings.System.getString(contentResolver, name)
53         }
54 
putStringnull55         override fun putString(name: String, value: String): Boolean {
56             return Settings.System.putString(contentResolver, name, value)
57         }
58     }
59 }
60