1 /*
2  * Copyright (C) 2023 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.provider;
18 
19 import android.content.ContentResolver;
20 import android.content.pm.PackageManager;
21 import android.database.ContentObserver;
22 
23 import android.annotation.NonNull;
24 import android.annotation.Nullable;
25 
26 import java.util.Arrays;
27 import java.util.ArrayList;
28 import java.util.concurrent.Executor;
29 import java.util.HashMap;
30 import java.util.Map;
31 
32 
33 /**
34  * TODO: want to change the package of this class
35  *
36  * @hide
37  */
38 public class SettingsConfigDataStore implements DeviceConfigDataStore {
39     @Override
getAllProperties()40     public @NonNull Map<String, String> getAllProperties() {
41         return Settings.Config.getAllStrings();
42     }
43 
44     @Override
getProperties(@onNull String namespace, @NonNull String... names)45     public @NonNull DeviceConfig.Properties getProperties(@NonNull String namespace,
46             @NonNull String... names) {
47         return new DeviceConfig.Properties(namespace,
48                 Settings.Config.getStrings(namespace, Arrays.asList(names)));
49     }
50 
51     @Override
setProperties(@onNull DeviceConfig.Properties properties)52     public boolean setProperties(@NonNull DeviceConfig.Properties properties)
53             throws DeviceConfig.BadConfigException {
54         return Settings.Config.setStrings(properties.getNamespace(),
55                 properties.getPropertyValues());
56     }
57 
58     @Override
setProperty(@onNull String namespace, @NonNull String name, @Nullable String value, boolean makeDefault)59     public boolean setProperty(@NonNull String namespace, @NonNull String name,
60             @Nullable String value, boolean makeDefault) {
61         return Settings.Config.putString(namespace, name, value, makeDefault);
62     }
63 
64     @Override
deleteProperty(@onNull String namespace, @NonNull String name)65     public boolean deleteProperty(@NonNull String namespace, @NonNull String name) {
66         return Settings.Config.deleteString(namespace, name);
67     }
68 
69     @Override
resetToDefaults(int resetMode, @Nullable String namespace)70     public void resetToDefaults(int resetMode, @Nullable String namespace) {
71         Settings.Config.resetToDefaults(resetMode, namespace);
72     }
73 
74     @Override
setSyncDisabledMode(int syncDisabledMode)75     public void setSyncDisabledMode(int syncDisabledMode) {
76         Settings.Config.setSyncDisabledMode(syncDisabledMode);
77     }
78 
79     @Override
getSyncDisabledMode()80     public int getSyncDisabledMode() {
81         return Settings.Config.getSyncDisabledMode();
82     }
83 
84     @Override
setMonitorCallback(@onNull ContentResolver resolver, @NonNull Executor executor, @NonNull DeviceConfig.MonitorCallback callback)85     public void setMonitorCallback(@NonNull ContentResolver resolver, @NonNull Executor executor,
86             @NonNull DeviceConfig.MonitorCallback callback) {
87         Settings.Config.setMonitorCallback(resolver, executor, callback);
88     }
89 
90     @Override
clearMonitorCallback(@onNull ContentResolver resolver)91     public void clearMonitorCallback(@NonNull ContentResolver resolver) {
92         Settings.Config.clearMonitorCallback(resolver);
93     }
94 
95     @Override
registerContentObserver(@onNull String namespace, boolean notifyForescendants, ContentObserver contentObserver)96     public void registerContentObserver(@NonNull String namespace, boolean notifyForescendants,
97             ContentObserver contentObserver) {
98         Settings.Config.registerContentObserver(namespace, true, contentObserver);
99     }
100 
101     @Override
unregisterContentObserver(@onNull ContentObserver contentObserver)102     public void unregisterContentObserver(@NonNull ContentObserver contentObserver) {
103         Settings.Config.unregisterContentObserver(contentObserver);
104     }
105 }
106