1 /*
2  * Copyright (C) 2006-2011 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.am;
18 
19 import android.annotation.NonNull;
20 import android.app.ActivityThread;
21 import android.content.ContentResolver;
22 import android.content.Context;
23 import android.database.ContentObserver;
24 import android.net.Uri;
25 import android.os.Bundle;
26 import android.provider.DeviceConfig;
27 import android.provider.Settings;
28 import android.text.TextFlags;
29 import android.widget.WidgetFlags;
30 
31 import com.android.internal.R;
32 import com.android.internal.annotations.VisibleForTesting;
33 
34 import java.util.ArrayList;
35 import java.util.HashMap;
36 import java.util.HashSet;
37 import java.util.List;
38 import java.util.Map;
39 import java.util.Objects;
40 
41 /**
42  * Helper class for watching a set of core settings which the framework
43  * propagates to application processes to avoid multiple lookups and potentially
44  * disk I/O operations. Note: This class assumes that all core settings reside
45  * in {@link Settings.Secure}.
46  */
47 final class CoreSettingsObserver extends ContentObserver {
48     private static final String LOG_TAG = CoreSettingsObserver.class.getSimpleName();
49 
50     private static class DeviceConfigEntry<T> {
51         String namespace;
52         String flag;
53         String coreSettingKey;
54         Class<T> type;
55         T defaultValue;
56 
DeviceConfigEntry(String namespace, String flag, String coreSettingKey, Class<T> type, @NonNull T defaultValue)57         DeviceConfigEntry(String namespace, String flag, String coreSettingKey, Class<T> type,
58                 @NonNull T defaultValue) {
59             this.namespace = namespace;
60             this.flag = flag;
61             this.coreSettingKey = coreSettingKey;
62             this.type = type;
63             this.defaultValue = Objects.requireNonNull(defaultValue);
64         }
65     }
66 
67     // mapping form property name to its type
68     @VisibleForTesting
69     static final Map<String, Class<?>> sSecureSettingToTypeMap = new HashMap<
70             String, Class<?>>();
71     @VisibleForTesting
72     static final Map<String, Class<?>> sSystemSettingToTypeMap = new HashMap<
73             String, Class<?>>();
74     @VisibleForTesting
75     static final Map<String, Class<?>> sGlobalSettingToTypeMap = new HashMap<
76             String, Class<?>>();
77     static final List<DeviceConfigEntry> sDeviceConfigEntries = new ArrayList<DeviceConfigEntry>();
78     static {
sSecureSettingToTypeMap.put(Settings.Secure.LONG_PRESS_TIMEOUT, int.class)79         sSecureSettingToTypeMap.put(Settings.Secure.LONG_PRESS_TIMEOUT, int.class);
sSecureSettingToTypeMap.put(Settings.Secure.MULTI_PRESS_TIMEOUT, int.class)80         sSecureSettingToTypeMap.put(Settings.Secure.MULTI_PRESS_TIMEOUT, int.class);
sSecureSettingToTypeMap.put(Settings.Secure.KEY_REPEAT_TIMEOUT_MS, int.class)81         sSecureSettingToTypeMap.put(Settings.Secure.KEY_REPEAT_TIMEOUT_MS, int.class);
sSecureSettingToTypeMap.put(Settings.Secure.KEY_REPEAT_DELAY_MS, int.class)82         sSecureSettingToTypeMap.put(Settings.Secure.KEY_REPEAT_DELAY_MS, int.class);
sSecureSettingToTypeMap.put(Settings.Secure.STYLUS_POINTER_ICON_ENABLED, int.class)83         sSecureSettingToTypeMap.put(Settings.Secure.STYLUS_POINTER_ICON_ENABLED, int.class);
84         // add other secure settings here...
85 
sSystemSettingToTypeMap.put(Settings.System.TIME_12_24, String.class)86         sSystemSettingToTypeMap.put(Settings.System.TIME_12_24, String.class);
87         // add other system settings here...
88 
sGlobalSettingToTypeMap.put(Settings.Global.DEBUG_VIEW_ATTRIBUTES, int.class)89         sGlobalSettingToTypeMap.put(Settings.Global.DEBUG_VIEW_ATTRIBUTES, int.class);
sGlobalSettingToTypeMap.put( Settings.Global.DEBUG_VIEW_ATTRIBUTES_APPLICATION_PACKAGE, String.class)90         sGlobalSettingToTypeMap.put(
91                 Settings.Global.DEBUG_VIEW_ATTRIBUTES_APPLICATION_PACKAGE, String.class);
sGlobalSettingToTypeMap.put( Settings.Global.ANGLE_DEBUG_PACKAGE, String.class)92         sGlobalSettingToTypeMap.put(
93                 Settings.Global.ANGLE_DEBUG_PACKAGE, String.class);
sGlobalSettingToTypeMap.put( Settings.Global.ANGLE_GL_DRIVER_ALL_ANGLE, int.class)94         sGlobalSettingToTypeMap.put(
95                 Settings.Global.ANGLE_GL_DRIVER_ALL_ANGLE, int.class);
sGlobalSettingToTypeMap.put( Settings.Global.ANGLE_GL_DRIVER_SELECTION_PKGS, String.class)96         sGlobalSettingToTypeMap.put(
97                 Settings.Global.ANGLE_GL_DRIVER_SELECTION_PKGS, String.class);
sGlobalSettingToTypeMap.put( Settings.Global.ANGLE_GL_DRIVER_SELECTION_VALUES, String.class)98         sGlobalSettingToTypeMap.put(
99                 Settings.Global.ANGLE_GL_DRIVER_SELECTION_VALUES, String.class);
sGlobalSettingToTypeMap.put( Settings.Global.ANGLE_EGL_FEATURES, String.class)100         sGlobalSettingToTypeMap.put(
101                 Settings.Global.ANGLE_EGL_FEATURES, String.class);
sGlobalSettingToTypeMap.put( Settings.Global.SHOW_ANGLE_IN_USE_DIALOG_BOX, String.class)102         sGlobalSettingToTypeMap.put(
103                 Settings.Global.SHOW_ANGLE_IN_USE_DIALOG_BOX, String.class);
sGlobalSettingToTypeMap.put(Settings.Global.ENABLE_GPU_DEBUG_LAYERS, int.class)104         sGlobalSettingToTypeMap.put(Settings.Global.ENABLE_GPU_DEBUG_LAYERS, int.class);
sGlobalSettingToTypeMap.put(Settings.Global.GPU_DEBUG_APP, String.class)105         sGlobalSettingToTypeMap.put(Settings.Global.GPU_DEBUG_APP, String.class);
sGlobalSettingToTypeMap.put(Settings.Global.GPU_DEBUG_LAYERS, String.class)106         sGlobalSettingToTypeMap.put(Settings.Global.GPU_DEBUG_LAYERS, String.class);
sGlobalSettingToTypeMap.put(Settings.Global.GPU_DEBUG_LAYERS_GLES, String.class)107         sGlobalSettingToTypeMap.put(Settings.Global.GPU_DEBUG_LAYERS_GLES, String.class);
sGlobalSettingToTypeMap.put(Settings.Global.GPU_DEBUG_LAYER_APP, String.class)108         sGlobalSettingToTypeMap.put(Settings.Global.GPU_DEBUG_LAYER_APP, String.class);
sGlobalSettingToTypeMap.put(Settings.Global.UPDATABLE_DRIVER_ALL_APPS, int.class)109         sGlobalSettingToTypeMap.put(Settings.Global.UPDATABLE_DRIVER_ALL_APPS, int.class);
sGlobalSettingToTypeMap.put( Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_IN_APPS, String.class)110         sGlobalSettingToTypeMap.put(
111                 Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_IN_APPS, String.class);
sGlobalSettingToTypeMap.put( Settings.Global.UPDATABLE_DRIVER_PRERELEASE_OPT_IN_APPS, String.class)112         sGlobalSettingToTypeMap.put(
113                 Settings.Global.UPDATABLE_DRIVER_PRERELEASE_OPT_IN_APPS, String.class);
sGlobalSettingToTypeMap.put( Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_OUT_APPS, String.class)114         sGlobalSettingToTypeMap.put(
115                 Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_OUT_APPS, String.class);
sGlobalSettingToTypeMap.put( Settings.Global.UPDATABLE_DRIVER_PRODUCTION_DENYLIST, String.class)116         sGlobalSettingToTypeMap.put(
117                 Settings.Global.UPDATABLE_DRIVER_PRODUCTION_DENYLIST, String.class);
sGlobalSettingToTypeMap.put( Settings.Global.UPDATABLE_DRIVER_PRODUCTION_ALLOWLIST, String.class)118         sGlobalSettingToTypeMap.put(
119                 Settings.Global.UPDATABLE_DRIVER_PRODUCTION_ALLOWLIST, String.class);
sGlobalSettingToTypeMap.put( Settings.Global.UPDATABLE_DRIVER_PRODUCTION_DENYLISTS, String.class)120         sGlobalSettingToTypeMap.put(
121                 Settings.Global.UPDATABLE_DRIVER_PRODUCTION_DENYLISTS, String.class);
sGlobalSettingToTypeMap.put(Settings.Global.UPDATABLE_DRIVER_SPHAL_LIBRARIES, String.class)122         sGlobalSettingToTypeMap.put(Settings.Global.UPDATABLE_DRIVER_SPHAL_LIBRARIES, String.class);
123         // add other global settings here...
124 
sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>( DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ENABLE_CURSOR_DRAG_FROM_ANYWHERE, WidgetFlags.KEY_ENABLE_CURSOR_DRAG_FROM_ANYWHERE, boolean.class, WidgetFlags.ENABLE_CURSOR_DRAG_FROM_ANYWHERE_DEFAULT))125         sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>(
126                 DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ENABLE_CURSOR_DRAG_FROM_ANYWHERE,
127                 WidgetFlags.KEY_ENABLE_CURSOR_DRAG_FROM_ANYWHERE, boolean.class,
128                 WidgetFlags.ENABLE_CURSOR_DRAG_FROM_ANYWHERE_DEFAULT));
sDeviceConfigEntries.add(new DeviceConfigEntry<Integer>( DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.CURSOR_DRAG_MIN_ANGLE_FROM_VERTICAL, WidgetFlags.KEY_CURSOR_DRAG_MIN_ANGLE_FROM_VERTICAL, int.class, WidgetFlags.CURSOR_DRAG_MIN_ANGLE_FROM_VERTICAL_DEFAULT))129         sDeviceConfigEntries.add(new DeviceConfigEntry<Integer>(
130                 DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.CURSOR_DRAG_MIN_ANGLE_FROM_VERTICAL,
131                 WidgetFlags.KEY_CURSOR_DRAG_MIN_ANGLE_FROM_VERTICAL, int.class,
132                 WidgetFlags.CURSOR_DRAG_MIN_ANGLE_FROM_VERTICAL_DEFAULT));
sDeviceConfigEntries.add(new DeviceConfigEntry<Integer>( DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.FINGER_TO_CURSOR_DISTANCE, WidgetFlags.KEY_FINGER_TO_CURSOR_DISTANCE, int.class, WidgetFlags.FINGER_TO_CURSOR_DISTANCE_DEFAULT))133         sDeviceConfigEntries.add(new DeviceConfigEntry<Integer>(
134                 DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.FINGER_TO_CURSOR_DISTANCE,
135                 WidgetFlags.KEY_FINGER_TO_CURSOR_DISTANCE, int.class,
136                 WidgetFlags.FINGER_TO_CURSOR_DISTANCE_DEFAULT));
sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>( DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ENABLE_INSERTION_HANDLE_GESTURES, WidgetFlags.KEY_ENABLE_INSERTION_HANDLE_GESTURES, boolean.class, WidgetFlags.ENABLE_INSERTION_HANDLE_GESTURES_DEFAULT))137         sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>(
138                 DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ENABLE_INSERTION_HANDLE_GESTURES,
139                 WidgetFlags.KEY_ENABLE_INSERTION_HANDLE_GESTURES, boolean.class,
140                 WidgetFlags.ENABLE_INSERTION_HANDLE_GESTURES_DEFAULT));
sDeviceConfigEntries.add(new DeviceConfigEntry<Integer>( DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.INSERTION_HANDLE_DELTA_HEIGHT, WidgetFlags.KEY_INSERTION_HANDLE_DELTA_HEIGHT, int.class, WidgetFlags.INSERTION_HANDLE_DELTA_HEIGHT_DEFAULT))141         sDeviceConfigEntries.add(new DeviceConfigEntry<Integer>(
142                 DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.INSERTION_HANDLE_DELTA_HEIGHT,
143                 WidgetFlags.KEY_INSERTION_HANDLE_DELTA_HEIGHT, int.class,
144                 WidgetFlags.INSERTION_HANDLE_DELTA_HEIGHT_DEFAULT));
sDeviceConfigEntries.add(new DeviceConfigEntry<Integer>( DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.INSERTION_HANDLE_OPACITY, WidgetFlags.KEY_INSERTION_HANDLE_OPACITY, int.class, WidgetFlags.INSERTION_HANDLE_OPACITY_DEFAULT))145         sDeviceConfigEntries.add(new DeviceConfigEntry<Integer>(
146                 DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.INSERTION_HANDLE_OPACITY,
147                 WidgetFlags.KEY_INSERTION_HANDLE_OPACITY, int.class,
148                 WidgetFlags.INSERTION_HANDLE_OPACITY_DEFAULT));
sDeviceConfigEntries.add(new DeviceConfigEntry<Float>( DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.LINE_SLOP_RATIO, WidgetFlags.KEY_LINE_SLOP_RATIO, float.class, WidgetFlags.LINE_SLOP_RATIO_DEFAULT))149         sDeviceConfigEntries.add(new DeviceConfigEntry<Float>(
150                 DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.LINE_SLOP_RATIO,
151                 WidgetFlags.KEY_LINE_SLOP_RATIO, float.class,
152                 WidgetFlags.LINE_SLOP_RATIO_DEFAULT));
sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>( DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ENABLE_NEW_MAGNIFIER, WidgetFlags.KEY_ENABLE_NEW_MAGNIFIER, boolean.class, WidgetFlags.ENABLE_NEW_MAGNIFIER_DEFAULT))153         sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>(
154                 DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ENABLE_NEW_MAGNIFIER,
155                 WidgetFlags.KEY_ENABLE_NEW_MAGNIFIER, boolean.class,
156                 WidgetFlags.ENABLE_NEW_MAGNIFIER_DEFAULT));
sDeviceConfigEntries.add(new DeviceConfigEntry<Float>( DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.MAGNIFIER_ZOOM_FACTOR, WidgetFlags.KEY_MAGNIFIER_ZOOM_FACTOR, float.class, WidgetFlags.MAGNIFIER_ZOOM_FACTOR_DEFAULT))157         sDeviceConfigEntries.add(new DeviceConfigEntry<Float>(
158                 DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.MAGNIFIER_ZOOM_FACTOR,
159                 WidgetFlags.KEY_MAGNIFIER_ZOOM_FACTOR, float.class,
160                 WidgetFlags.MAGNIFIER_ZOOM_FACTOR_DEFAULT));
sDeviceConfigEntries.add(new DeviceConfigEntry<Float>( DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.MAGNIFIER_ASPECT_RATIO, WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO, float.class, WidgetFlags.MAGNIFIER_ASPECT_RATIO_DEFAULT))161         sDeviceConfigEntries.add(new DeviceConfigEntry<Float>(
162                 DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.MAGNIFIER_ASPECT_RATIO,
163                 WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO, float.class,
164                 WidgetFlags.MAGNIFIER_ASPECT_RATIO_DEFAULT));
165 
sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>( TextFlags.NAMESPACE, TextFlags.ENABLE_NEW_CONTEXT_MENU, TextFlags.KEY_ENABLE_NEW_CONTEXT_MENU, boolean.class, TextFlags.ENABLE_NEW_CONTEXT_MENU_DEFAULT))166         sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>(
167                 TextFlags.NAMESPACE, TextFlags.ENABLE_NEW_CONTEXT_MENU,
168                 TextFlags.KEY_ENABLE_NEW_CONTEXT_MENU, boolean.class,
169                 TextFlags.ENABLE_NEW_CONTEXT_MENU_DEFAULT));
170 
171         // Register all text aconfig flags.
172         for (int i = 0; i < TextFlags.TEXT_ACONFIGS_FLAGS.length; i++) {
173             final String flag = TextFlags.TEXT_ACONFIGS_FLAGS[i];
174             final boolean defaultValue = TextFlags.TEXT_ACONFIG_DEFAULT_VALUE[i];
sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>( TextFlags.NAMESPACE, flag, TextFlags.getKeyForFlag(flag), boolean.class, defaultValue))175             sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>(
176                     TextFlags.NAMESPACE,
177                     flag,
178                     TextFlags.getKeyForFlag(flag),
179                     boolean.class,
180                     defaultValue));
181         }
182         // add other device configs here...
183     }
184     private static volatile boolean sDeviceConfigContextEntriesLoaded = false;
185 
186     private final Bundle mCoreSettings = new Bundle();
187 
188     private final ActivityManagerService mActivityManagerService;
189 
CoreSettingsObserver(ActivityManagerService activityManagerService)190     public CoreSettingsObserver(ActivityManagerService activityManagerService) {
191         super(activityManagerService.mHandler);
192 
193         if (!sDeviceConfigContextEntriesLoaded) {
194             synchronized (sDeviceConfigEntries) {
195                 if (!sDeviceConfigContextEntriesLoaded) {
196                     loadDeviceConfigContextEntries(activityManagerService.mContext);
197                     sDeviceConfigContextEntriesLoaded = true;
198                 }
199             }
200         }
201 
202         mActivityManagerService = activityManagerService;
203         beginObserveCoreSettings();
204         sendCoreSettings();
205     }
206 
loadDeviceConfigContextEntries(Context context)207     private static void loadDeviceConfigContextEntries(Context context) {
208         sDeviceConfigEntries.add(new DeviceConfigEntry<>(
209                 DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ANALOG_CLOCK_SECONDS_HAND_FPS,
210                 WidgetFlags.KEY_ANALOG_CLOCK_SECONDS_HAND_FPS, int.class,
211                 context.getResources()
212                         .getInteger(R.integer.config_defaultAnalogClockSecondsHandFps)));
213     }
214 
getCoreSettingsLocked()215     public Bundle getCoreSettingsLocked() {
216         return (Bundle) mCoreSettings.clone();
217     }
218 
219     @Override
onChange(boolean selfChange)220     public void onChange(boolean selfChange) {
221         synchronized (mActivityManagerService) {
222             sendCoreSettings();
223         }
224     }
225 
sendCoreSettings()226     private void sendCoreSettings() {
227         populateSettings(mCoreSettings, sSecureSettingToTypeMap);
228         populateSettings(mCoreSettings, sSystemSettingToTypeMap);
229         populateSettings(mCoreSettings, sGlobalSettingToTypeMap);
230         populateSettingsFromDeviceConfig();
231         mActivityManagerService.onCoreSettingsChange(mCoreSettings);
232     }
233 
beginObserveCoreSettings()234     private void beginObserveCoreSettings() {
235         for (String setting : sSecureSettingToTypeMap.keySet()) {
236             Uri uri = Settings.Secure.getUriFor(setting);
237             mActivityManagerService.mContext.getContentResolver().registerContentObserver(
238                     uri, false, this);
239         }
240 
241         for (String setting : sSystemSettingToTypeMap.keySet()) {
242             Uri uri = Settings.System.getUriFor(setting);
243             mActivityManagerService.mContext.getContentResolver().registerContentObserver(
244                     uri, false, this);
245         }
246 
247         for (String setting : sGlobalSettingToTypeMap.keySet()) {
248             Uri uri = Settings.Global.getUriFor(setting);
249             mActivityManagerService.mContext.getContentResolver().registerContentObserver(
250                     uri, false, this);
251         }
252 
253         HashSet<String> deviceConfigNamespaces = new HashSet<>();
254         for (DeviceConfigEntry entry : sDeviceConfigEntries) {
255             if (!deviceConfigNamespaces.contains(entry.namespace)) {
256                 DeviceConfig.addOnPropertiesChangedListener(
257                         entry.namespace, ActivityThread.currentApplication().getMainExecutor(),
258                         (DeviceConfig.Properties prop) -> onChange(false));
259                 deviceConfigNamespaces.add(entry.namespace);
260             }
261         }
262     }
263 
264     @VisibleForTesting
populateSettings(Bundle snapshot, Map<String, Class<?>> map)265     void populateSettings(Bundle snapshot, Map<String, Class<?>> map) {
266         final Context context = mActivityManagerService.mContext;
267         final ContentResolver cr = context.getContentResolver();
268         for (Map.Entry<String, Class<?>> entry : map.entrySet()) {
269             String setting = entry.getKey();
270             final String value;
271             if (map == sSecureSettingToTypeMap) {
272                 value = Settings.Secure.getStringForUser(cr, setting, cr.getUserId());
273             } else if (map == sSystemSettingToTypeMap) {
274                 value = Settings.System.getStringForUser(cr, setting, cr.getUserId());
275             } else {
276                 value = Settings.Global.getString(cr, setting);
277             }
278             if (value == null) {
279                 snapshot.remove(setting);
280                 continue;
281             }
282             Class<?> type = entry.getValue();
283             if (type == String.class) {
284                 snapshot.putString(setting, value);
285             } else if (type == int.class) {
286                 snapshot.putInt(setting, Integer.parseInt(value));
287             } else if (type == float.class) {
288                 snapshot.putFloat(setting, Float.parseFloat(value));
289             } else if (type == long.class) {
290                 snapshot.putLong(setting, Long.parseLong(value));
291             }
292         }
293     }
294 
295     @SuppressWarnings("unchecked")
populateSettingsFromDeviceConfig()296     private void populateSettingsFromDeviceConfig() {
297         for (DeviceConfigEntry<?> entry : sDeviceConfigEntries) {
298             if (entry.type == String.class) {
299                 String defaultValue = ((DeviceConfigEntry<String>) entry).defaultValue;
300                 mCoreSettings.putString(entry.coreSettingKey,
301                         DeviceConfig.getString(entry.namespace, entry.flag, defaultValue));
302             } else if (entry.type == int.class) {
303                 int defaultValue = ((DeviceConfigEntry<Integer>) entry).defaultValue;
304                 mCoreSettings.putInt(entry.coreSettingKey,
305                         DeviceConfig.getInt(entry.namespace, entry.flag, defaultValue));
306             } else if (entry.type == float.class) {
307                 float defaultValue = ((DeviceConfigEntry<Float>) entry).defaultValue;
308                 mCoreSettings.putFloat(entry.coreSettingKey,
309                         DeviceConfig.getFloat(entry.namespace, entry.flag, defaultValue));
310             } else if (entry.type == long.class) {
311                 long defaultValue = ((DeviceConfigEntry<Long>) entry).defaultValue;
312                 mCoreSettings.putLong(entry.coreSettingKey,
313                         DeviceConfig.getLong(entry.namespace, entry.flag, defaultValue));
314             } else if (entry.type == boolean.class) {
315                 boolean defaultValue = ((DeviceConfigEntry<Boolean>) entry).defaultValue;
316                 mCoreSettings.putInt(entry.coreSettingKey,
317                         DeviceConfig.getBoolean(entry.namespace, entry.flag, defaultValue) ? 1 : 0);
318             }
319         }
320     }
321 }
322