Debian Codegraph @

core/java/android/provider/DeviceConfig.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2018 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 static android.Manifest.permission.READ_DEVICE_CONFIG;
20 import static android.Manifest.permission.WRITE_DEVICE_CONFIG;
21
22 import android.annotation.CallbackExecutor;
23 import android.annotation.NonNull;
24 import android.annotation.Nullable;
25 import android.annotation.RequiresPermission;
26 import android.annotation.SystemApi;
27 import android.annotation.TestApi;
28 import android.app.ActivityThread;
29 import android.content.ContentResolver;
30 import android.content.Context;
31 import android.content.pm.PackageManager;
32 import android.database.ContentObserver;
33 import android.net.Uri;
34 import android.provider.Settings.Config.SyncDisabledMode;
35 import android.provider.Settings.ResetMode;
36 import android.util.ArrayMap;
37 import android.util.Log;
38 import android.util.Pair;
39
40 import com.android.internal.annotations.GuardedBy;
41 import com.android.internal.util.Preconditions;
42
43 import java.util.Arrays;
44 import java.util.Collections;
45 import java.util.HashMap;
46 import java.util.List;
47 import java.util.Map;
48 import java.util.Set;
49 import java.util.concurrent.Executor;
50
51 /**
52 * Device level configuration parameters which can be tuned by a separate configuration service.
53 * Namespaces that end in "_native" such as {@link #NAMESPACE_NETD_NATIVE} are intended to be used
54 * by native code and should be pushed to system properties to make them accessible.
55 *
56 * @hide
57 */
58 @SystemApi
59 public final class DeviceConfig {
60 /**
61 * The content:// style URL for the config table.
62 *
63 * @hide
64 */
65 public static final Uri CONTENT_URI = Uri.parse("content://" + Settings.AUTHORITY + "/config");
66
67 /**
68 * Namespace for activity manager related features. These features will be applied
69 * immediately upon change.
70 *
71 * @hide
72 */
73 @SystemApi
74 public static final String NAMESPACE_ACTIVITY_MANAGER = "activity_manager";
75
76 /**
77 * Namespace for activity manager, specific to the "component alias" feature. We needed a
78 * different namespace in order to avoid phonetype from resetting it.
79 * @hide
80 */
81 public static final String NAMESPACE_ACTIVITY_MANAGER_COMPONENT_ALIAS = "activity_manager_ca";
82
83 /**
84 * Namespace for all activity manager related features that are used at the native level.
85 * These features are applied at reboot.
86 *
87 * @hide
88 */
89 @SystemApi
90 public static final String NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT =
91 "activity_manager_native_boot";
92
93 /**
94 * Namespace for AlarmManager configurations.
95 *
96 * @hide
97 */
98 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
99 @TestApi
100 public static final String NAMESPACE_ALARM_MANAGER = "alarm_manager";
101
102 /**
103 * Namespace for all app compat related features. These features will be applied
104 * immediately upon change.
105 *
106 * @hide
107 */
108 @SystemApi
109 public static final String NAMESPACE_APP_COMPAT = "app_compat";
110
111 /**
112 * Namespace for all app hibernation related features.
113 * @hide
114 */
115 @SystemApi
116 public static final String NAMESPACE_APP_HIBERNATION = "app_hibernation";
117
118 /**
119 * Namespace for all AppSearch related features.
120 * @hide
121 */
122 @SystemApi
123 public static final String NAMESPACE_APPSEARCH = "appsearch";
124
125 /**
126 * Namespace for app standby configurations.
127 *
128 * @hide
129 */
130 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
131 public static final String NAMESPACE_APP_STANDBY = "app_standby";
132
133 /**
134 * Namespace for AttentionManagerService related features.
135 *
136 * @hide
137 */
138 @SystemApi
139 public static final String NAMESPACE_ATTENTION_MANAGER_SERVICE = "attention_manager_service";
140
141 /**
142 * Namespace for autofill feature that provides suggestions across all apps when
143 * the user interacts with input fields.
144 *
145 * @hide
146 */
147 @SystemApi
148 public static final String NAMESPACE_AUTOFILL = "autofill";
149
150 /**
151 * Namespace for battery saver feature.
152 *
153 * @hide
154 */
155 @SystemApi
156 public static final String NAMESPACE_BATTERY_SAVER = "battery_saver";
157
158 /**
159 * Namespace for blobstore feature that allows apps to share data blobs.
160 *
161 * @hide
162 */
163 @SystemApi
164 public static final String NAMESPACE_BLOBSTORE = "blobstore";
165
166 /**
167 * Namespace for all Bluetooth related features.
168 *
169 * @hide
170 */
171 @SystemApi
172 public static final String NAMESPACE_BLUETOOTH = "bluetooth";
173
174 /**
175 * Namespace for features relating to clipboard.
176 *
177 * @hide
178 */
179 @SystemApi
180 public static final String NAMESPACE_CLIPBOARD = "clipboard";
181
182 /**
183 * Namespace for all networking connectivity related features.
184 *
185 * @hide
186 */
187 @SystemApi
188 public static final String NAMESPACE_CONNECTIVITY = "connectivity";
189
190 /**
191 * Namespace for CaptivePortalLogin module.
192 *
193 * @hide
194 */
195 @SystemApi
196 public static final String NAMESPACE_CAPTIVEPORTALLOGIN = "captive_portal_login";
197
198 /**
199 * Namespace for Tethering module.
200 *
201 * @hide
202 */
203 @SystemApi
204 public static final String NAMESPACE_TETHERING = "tethering";
205
206
207 /**
208 * Namespace for Nearby module.
209 *
210 * @hide
211 */
212 @SystemApi
213 public static final String NAMESPACE_NEARBY = "nearby";
214
215 /**
216 * Namespace for content capture feature used by on-device machine intelligence
217 * to provide suggestions in a privacy-safe manner.
218 *
219 * @hide
220 */
221 @SystemApi
222 public static final String NAMESPACE_CONTENT_CAPTURE = "content_capture";
223
224 /**
225 * Namespace for device idle configurations.
226 *
227 * @hide
228 */
229 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
230 @TestApi
231 public static final String NAMESPACE_DEVICE_IDLE = "device_idle";
232
233 /**
234 * Namespace for how dex runs. The feature requires a reboot to reach a clean state.
235 *
236 * @deprecated No longer used
237 * @hide
238 */
239 @Deprecated
240 @SystemApi
241 public static final String NAMESPACE_DEX_BOOT = "dex_boot";
242
243 /**
244 * Namespace for display manager related features. The names to access the properties in this
245 * namespace should be defined in {@link android.hardware.display.DisplayManager}.
246 *
247 * @hide
248 */
249 @SystemApi
250 public static final String NAMESPACE_DISPLAY_MANAGER = "display_manager";
251
252 /**
253 * Namespace for all Game Driver features.
254 *
255 * @hide
256 */
257 @SystemApi
258 public static final String NAMESPACE_GAME_DRIVER = "game_driver";
259
260 /**
261 * Namespace for all input-related features that are used at the native level.
262 * These features are applied at reboot.
263 *
264 * @hide
265 */
266 @SystemApi
267 public static final String NAMESPACE_INPUT_NATIVE_BOOT = "input_native_boot";
268
269 /**
270 * Namespace for attention-based features provided by on-device machine intelligence.
271 *
272 * @hide
273 */
274 @SystemApi
275 public static final String NAMESPACE_INTELLIGENCE_ATTENTION = "intelligence_attention";
276
277 /**
278 * Definitions for properties related to Content Suggestions.
279 *
280 * @hide
281 */
282 public static final String NAMESPACE_INTELLIGENCE_CONTENT_SUGGESTIONS =
283 "intelligence_content_suggestions";
284
285 /**
286 * Namespace for JobScheduler configurations.
287 * @hide
288 */
289 @TestApi
290 public static final String NAMESPACE_JOB_SCHEDULER = "jobscheduler";
291
292 /**
293 * Namespace for all lmkd related features.
294 *
295 * @hide
296 */
297 @SystemApi
298 public static final String NAMESPACE_LMKD_NATIVE = "lmkd_native";
299
300 /**
301 * Namespace for all location related features.
302 *
303 * @hide
304 */
305 @SystemApi
306 public static final String NAMESPACE_LOCATION = "location";
307
308 /**
309 * Namespace for all media related features.
310 *
311 * @hide
312 */
313 @SystemApi
314 public static final String NAMESPACE_MEDIA = "media";
315
316 /**
317 * Namespace for all media native related features.
318 *
319 * @hide
320 */
321 @SystemApi
322 public static final String NAMESPACE_MEDIA_NATIVE = "media_native";
323
324 /**
325 * Namespace for all Kernel Multi-Gen LRU feature.
326 *
327 * @hide
328 */
329 public static final String NAMESPACE_MGLRU_NATIVE = "mglru_native";
330
331 /**
332 * Namespace for all netd related features.
333 *
334 * @hide
335 */
336 @SystemApi
337 public static final String NAMESPACE_NETD_NATIVE = "netd_native";
338
339 /**
340 * Namespace for all Android NNAPI related features.
341 *
342 * @hide
343 */
344 @SystemApi
345 public static final String NAMESPACE_NNAPI_NATIVE = "nnapi_native";
346
347 /**
348 * Namespace for all OnDevicePersonalization related feature.
349 * @hide
350 */
351 @SystemApi
352 public static final String NAMESPACE_ON_DEVICE_PERSONALIZATION = "on_device_personalization";
353
354 /**
355 * Namespace for features related to the Package Manager Service.
356 *
357 * @hide
358 */
359 @SystemApi
360 public static final String NAMESPACE_PACKAGE_MANAGER_SERVICE = "package_manager_service";
361
362 /**
363 * Namespace for features related to the Profcollect native Service.
364 * These features are applied at reboot.
365 *
366 * @hide
367 */
368 @SystemApi
369 public static final String NAMESPACE_PROFCOLLECT_NATIVE_BOOT = "profcollect_native_boot";
370
371 /**
372 * Namespace for features related to Reboot Readiness detection.
373 *
374 * @hide
375 */
376 @SystemApi
377 public static final String NAMESPACE_REBOOT_READINESS = "reboot_readiness";
378
379 /**
380 * Namespace for Remote Key Provisioning related features.
381 *
382 * @hide
383 */
384 public static final String NAMESPACE_REMOTE_KEY_PROVISIONING_NATIVE =
385 "remote_key_provisioning_native";
386
387 /**
388 * Namespace for Rollback flags that are applied immediately.
389 *
390 * @hide
391 */
392 @SystemApi
393 public static final String NAMESPACE_ROLLBACK = "rollback";
394
395 /**
396 * Namespace for Rollback flags that are applied after a reboot.
397 *
398 * @hide
399 */
400 @SystemApi
401 public static final String NAMESPACE_ROLLBACK_BOOT = "rollback_boot";
402
403 /**
404 * Namespace for Rotation Resolver Manager Service.
405 *
406 * @hide
407 */
408 public static final String NAMESPACE_ROTATION_RESOLVER = "rotation_resolver";
409
410 /**
411 * Namespace for all runtime related features that don't require a reboot to become active.
412 * There are no feature flags using NAMESPACE_RUNTIME.
413 *
414 * @hide
415 */
416 @SystemApi
417 public static final String NAMESPACE_RUNTIME = "runtime";
418
419 /**
420 * Namespace for all runtime related features that require system properties for accessing
421 * the feature flags from C++ or Java language code. One example is the app image startup
422 * cache feature use_app_image_startup_cache.
423 *
424 * @hide
425 */
426 @SystemApi
427 public static final String NAMESPACE_RUNTIME_NATIVE = "runtime_native";
428
429 /**
430 * Namespace for all runtime native boot related features. Boot in this case refers to the
431 * fact that the properties only take affect after rebooting the device.
432 *
433 * @hide
434 */
435 @SystemApi
436 public static final String NAMESPACE_RUNTIME_NATIVE_BOOT = "runtime_native_boot";
437
438 /**
439 * Namespace for system scheduler related features. These features will be applied
440 * immediately upon change.
441 *
442 * @hide
443 */
444 @SystemApi
445 public static final String NAMESPACE_SCHEDULER = "scheduler";
446
447 /**
448 * Namespace for all SdkSandbox related features.
449 * @hide
450 */
451 @SystemApi
452 public static final String NAMESPACE_SDK_SANDBOX = "sdk_sandbox";
453
454 /**
455 * Namespace for settings statistics features.
456 *
457 * @hide
458 */
459 public static final String NAMESPACE_SETTINGS_STATS = "settings_stats";
460
461 /**
462 * Namespace for all statsd java features that can be applied immediately.
463 *
464 * @hide
465 */
466 @SystemApi
467 public static final String NAMESPACE_STATSD_JAVA = "statsd_java";
468
469 /**
470 * Namespace for all statsd java features that are applied on boot.
471 *
472 * @hide
473 */
474 @SystemApi
475 public static final String NAMESPACE_STATSD_JAVA_BOOT = "statsd_java_boot";
476
477 /**
478 * Namespace for all statsd native features that can be applied immediately.
479 *
480 * @hide
481 */
482 @SystemApi
483 public static final String NAMESPACE_STATSD_NATIVE = "statsd_native";
484
485 /**
486 * Namespace for all statsd native features that are applied on boot.
487 *
488 * @hide
489 */
490 @SystemApi
491 public static final String NAMESPACE_STATSD_NATIVE_BOOT = "statsd_native_boot";
492
493 /**
494 * Namespace for storage-related features.
495 *
496 * @deprecated Replace storage namespace with storage_native_boot.
497 * @hide
498 */
499 @Deprecated
500 @SystemApi
501 public static final String NAMESPACE_STORAGE = "storage";
502
503 /**
504 * Namespace for storage-related features, including native and boot.
505 *
506 * @hide
507 */
508 @SystemApi
509 public static final String NAMESPACE_STORAGE_NATIVE_BOOT = "storage_native_boot";
510
511 /**
512 * Namespace for all AdServices related features.
513 * @hide
514 */
515 @SystemApi
516 public static final String NAMESPACE_ADSERVICES = "adservices";
517
518 /**
519 * Namespace for all SurfaceFlinger features that are used at the native level.
520 * These features are applied on boot or after reboot.
521 *
522 * @hide
523 */
524 @SystemApi
525 public static final String NAMESPACE_SURFACE_FLINGER_NATIVE_BOOT =
526 "surface_flinger_native_boot";
527
528 /**
529 * Namespace for swcodec native related features.
530 *
531 * @hide
532 */
533 @SystemApi
534 public static final String NAMESPACE_SWCODEC_NATIVE = "swcodec_native";
535
536
537 /**
538 * Namespace for System UI related features.
539 *
540 * @hide
541 */
542 @SystemApi
543 public static final String NAMESPACE_SYSTEMUI = "systemui";
544
545 /**
546 * Namespace for system time and time zone detection related features / behavior.
547 *
548 * @hide
549 */
550 @SystemApi
551 public static final String NAMESPACE_SYSTEM_TIME = "system_time";
552
553 /**
554 * Namespace for TARE configurations.
555 *
556 * @hide
557 */
558 public static final String NAMESPACE_TARE = "tare";
559
560 /**
561 * Telephony related properties.
562 *
563 * @hide
564 */
565 @SystemApi
566 public static final String NAMESPACE_TELEPHONY = "telephony";
567
568 /**
569 * Namespace for TextClassifier related features.
570 *
571 * @hide
572 * @see android.provider.Settings.Global.TEXT_CLASSIFIER_CONSTANTS
573 */
574 @SystemApi
575 public static final String NAMESPACE_TEXTCLASSIFIER = "textclassifier";
576
577 /**
578 * Namespace for contacts provider related features.
579 *
580 * @hide
581 */
582 public static final String NAMESPACE_CONTACTS_PROVIDER = "contacts_provider";
583
584 /**
585 * Namespace for settings ui related features
586 *
587 * @hide
588 */
589 public static final String NAMESPACE_SETTINGS_UI = "settings_ui";
590
591 /**
592 * Namespace for android related features, i.e. for flags that affect not just a single
593 * component, but the entire system.
594 *
595 * The keys for this namespace are defined in {@link AndroidDeviceConfig}.
596 *
597 * @hide
598 */
599 @TestApi
600 public static final String NAMESPACE_ANDROID = "android";
601
602 /**
603 * Namespace for window manager related features.
604 *
605 * @hide
606 */
607 public static final String NAMESPACE_WINDOW_MANAGER = "window_manager";
608
609 /**
610 * Namespace for window manager features accessible by native code and
611 * loaded once per boot.
612 *
613 * @hide
614 */
615 @SystemApi
616 public static final String NAMESPACE_WINDOW_MANAGER_NATIVE_BOOT = "window_manager_native_boot";
617
618 /**
619 * Definitions for selection toolbar related functions.
620 *
621 * @hide
622 */
623 @TestApi
624 public static final String NAMESPACE_SELECTION_TOOLBAR = "selection_toolbar";
625
626 /**
627 * Definitions for voice interaction related functions.
628 *
629 * @hide
630 */
631 public static final String NAMESPACE_VOICE_INTERACTION = "voice_interaction";
632
633 /**
634 * Namespace for DevicePolicyManager related features.
635 *
636 * @hide
637 */
638 public static final String NAMESPACE_DEVICE_POLICY_MANAGER =
639 "device_policy_manager";
640
641 /**
642 * List of namespaces which can be read without READ_DEVICE_CONFIG permission
643 *
644 * @hide
645 */
646 @NonNull
647 private static final List<String> PUBLIC_NAMESPACES =
648 Arrays.asList(NAMESPACE_TEXTCLASSIFIER, NAMESPACE_RUNTIME, NAMESPACE_STATSD_JAVA,
649 NAMESPACE_STATSD_JAVA_BOOT, NAMESPACE_SELECTION_TOOLBAR, NAMESPACE_AUTOFILL,
650 NAMESPACE_DEVICE_POLICY_MANAGER, NAMESPACE_CONTENT_CAPTURE);
651 /**
652 * Privacy related properties definitions.
653 *
654 * @hide
655 */
656 @SystemApi
657 public static final String NAMESPACE_PRIVACY = "privacy";
658
659 /**
660 * Namespace for biometrics related features
661 *
662 * @hide
663 */
664 @SystemApi
665 public static final String NAMESPACE_BIOMETRICS = "biometrics";
666
667 /**
668 * Permission related properties definitions.
669 *
670 * @hide
671 */
672 @SystemApi
673 public static final String NAMESPACE_PERMISSIONS = "permissions";
674
675 /**
676 * Namespace for ota related features.
677 *
678 * @hide
679 */
680 @SystemApi
681 public static final String NAMESPACE_OTA = "ota";
682
683 /**
684 * Namespace for all widget related features.
685 *
686 * @hide
687 */
688 public static final String NAMESPACE_WIDGET = "widget";
689
690 /**
691 * Namespace for connectivity thermal power manager features.
692 *
693 * @hide
694 */
695 public static final String NAMESPACE_CONNECTIVITY_THERMAL_POWER_MANAGER =
696 "connectivity_thermal_power_manager";
697
698 /**
699 * Namespace for configuration related features.
700 *
701 * @hide
702 */
703 public static final String NAMESPACE_CONFIGURATION = "configuration";
704
705 /**
706 * LatencyTracker properties definitions.
707 *
708 * @hide
709 */
710 public static final String NAMESPACE_LATENCY_TRACKER = "latency_tracker";
711
712 /**
713 * InteractionJankMonitor properties definitions.
714 *
715 * @hide
716 */
717 public static final String NAMESPACE_INTERACTION_JANK_MONITOR = "interaction_jank_monitor";
718
719 /**
720 * Namespace for game overlay related features.
721 *
722 * @hide
723 */
724 public static final String NAMESPACE_GAME_OVERLAY = "game_overlay";
725
726 /**
727 * Namespace for Android Virtualization Framework related features accessible by native code.
728 *
729 * @hide
730 */
731 public static final String NAMESPACE_VIRTUALIZATION_FRAMEWORK_NATIVE =
732 "virtualization_framework_native";
733
734 /**
735 * Namespace for Constrain Display APIs related features.
736 *
737 * @hide
738 */
739 @TestApi
740 public static final String NAMESPACE_CONSTRAIN_DISPLAY_APIS = "constrain_display_apis";
741
742 /**
743 * Namespace for App Compat Overrides related features.
744 *
745 * @hide
746 */
747 @TestApi
748 public static final String NAMESPACE_APP_COMPAT_OVERRIDES = "app_compat_overrides";
749
750 /**
751 * Namespace for all ultra wideband (uwb) related features.
752 *
753 * @hide
754 */
755 @SystemApi
756 public static final String NAMESPACE_UWB = "uwb";
757
758 /**
759 * Namespace for AmbientContextEventManagerService related features.
760 *
761 * @hide
762 */
763 @SystemApi
764 public static final String NAMESPACE_AMBIENT_CONTEXT_MANAGER_SERVICE =
765 "ambient_context_manager_service";
766
767 /**
768 * Namespace for Vendor System Native related features.
769 *
770 * @hide
771 */
772 public static final String NAMESPACE_VENDOR_SYSTEM_NATIVE = "vendor_system_native";
773
774 /**
775 * Namespace for Vendor System Native Boot related features.
776 *
777 * @hide
778 */
779 public static final String NAMESPACE_VENDOR_SYSTEM_NATIVE_BOOT = "vendor_system_native_boot";
780
781 private static final Object sLock = new Object();
782 @GuardedBy("sLock")
783 private static ArrayMap<OnPropertiesChangedListener, Pair<String, Executor>> sListeners =
784 new ArrayMap<>();
785 @GuardedBy("sLock")
786 private static Map<String, Pair<ContentObserver, Integer>> sNamespaces = new HashMap<>();
787 private static final String TAG = "DeviceConfig";
788
789 // Should never be invoked
790 private DeviceConfig() {
791 }
792
793 /**
794 * Look up the value of a property for a particular namespace.
795 *
796 * @param namespace The namespace containing the property to look up.
797 * @param name The name of the property to look up.
798 * @return the corresponding value, or null if not present.
799 * @hide
800 */
801 @SystemApi
802 @RequiresPermission(READ_DEVICE_CONFIG)
803 public static String getProperty(@NonNull String namespace, @NonNull String name) {
804 // Fetch all properties for the namespace at once and cache them in the local process, so we
805 // incur the cost of the IPC less often. Lookups happen much more frequently than updates,
806 // and we want to optimize the former.
807 return getProperties(namespace, name).getString(name, null);
808 }
809
810 /**
811 * Look up the values of multiple properties for a particular namespace. The lookup is atomic,
812 * such that the values of these properties cannot change between the time when the first is
813 * fetched and the time when the last is fetched.
814 * <p>
815 * Each call to {@link #setProperties(Properties)} is also atomic and ensures that either none
816 * or all of the change is picked up here, but never only part of it.
817 *
818 * @param namespace The namespace containing the properties to look up.
819 * @param names The names of properties to look up, or empty to fetch all properties for the
820 * given namespace.
821 * @return {@link Properties} object containing the requested properties. This reflects the
822 * state of these properties at the time of the lookup, and is not updated to reflect any
823 * future changes. The keyset of this Properties object will contain only the intersection
824 * of properties already set and properties requested via the names parameter. Properties
825 * that are already set but were not requested will not be contained here. Properties that
826 * are not set, but were requested will not be contained here either.
827 * @hide
828 */
829 @SystemApi
830 @NonNull
831 @RequiresPermission(READ_DEVICE_CONFIG)
832 public static Properties getProperties(@NonNull String namespace, @NonNull String ... names) {
833 ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
834 return new Properties(namespace,
835 Settings.Config.getStrings(contentResolver, namespace, Arrays.asList(names)));
836 }
837
838 /**
839 * Look up the String value of a property for a particular namespace.
840 *
841 * @param namespace The namespace containing the property to look up.
842 * @param name The name of the property to look up.
843 * @param defaultValue The value to return if the property does not exist or has no non-null
844 * value.
845 * @return the corresponding value, or defaultValue if none exists.
846 * @hide
847 */
848 @SystemApi
849 @RequiresPermission(READ_DEVICE_CONFIG)
850 public static String getString(@NonNull String namespace, @NonNull String name,
851 @Nullable String defaultValue) {
852 String value = getProperty(namespace, name);
853 return value != null ? value : defaultValue;
854 }
855
856 /**
857 * Look up the boolean value of a property for a particular namespace.
858 *
859 * @param namespace The namespace containing the property to look up.
860 * @param name The name of the property to look up.
861 * @param defaultValue The value to return if the property does not exist or has no non-null
862 * value.
863 * @return the corresponding value, or defaultValue if none exists.
864 * @hide
865 */
866 @SystemApi
867 @RequiresPermission(READ_DEVICE_CONFIG)
868 public static boolean getBoolean(@NonNull String namespace, @NonNull String name,
869 boolean defaultValue) {
870 String value = getProperty(namespace, name);
871 return value != null ? Boolean.parseBoolean(value) : defaultValue;
872 }
873
874 /**
875 * Look up the int value of a property for a particular namespace.
876 *
877 * @param namespace The namespace containing the property to look up.
878 * @param name The name of the property to look up.
879 * @param defaultValue The value to return if the property does not exist, has no non-null
880 * value, or fails to parse into an int.
881 * @return the corresponding value, or defaultValue if either none exists or it does not parse.
882 * @hide
883 */
884 @SystemApi
885 @RequiresPermission(READ_DEVICE_CONFIG)
886 public static int getInt(@NonNull String namespace, @NonNull String name, int defaultValue) {
887 String value = getProperty(namespace, name);
888 if (value == null) {
889 return defaultValue;
890 }
891 try {
892 return Integer.parseInt(value);
893 } catch (NumberFormatException e) {
894 Log.e(TAG, "Parsing integer failed for " + namespace + ":" + name);
895 return defaultValue;
896 }
897 }
898
899 /**
900 * Look up the long value of a property for a particular namespace.
901 *
902 * @param namespace The namespace containing the property to look up.
903 * @param name The name of the property to look up.
904 * @param defaultValue The value to return if the property does not exist, has no non-null
905 * value, or fails to parse into a long.
906 * @return the corresponding value, or defaultValue if either none exists or it does not parse.
907 * @hide
908 */
909 @SystemApi
910 @RequiresPermission(READ_DEVICE_CONFIG)
911 public static long getLong(@NonNull String namespace, @NonNull String name, long defaultValue) {
912 String value = getProperty(namespace, name);
913 if (value == null) {
914 return defaultValue;
915 }
916 try {
917 return Long.parseLong(value);
918 } catch (NumberFormatException e) {
919 Log.e(TAG, "Parsing long failed for " + namespace + ":" + name);
920 return defaultValue;
921 }
922 }
923
924 /**
925 * Look up the float value of a property for a particular namespace.
926 *
927 * @param namespace The namespace containing the property to look up.
928 * @param name The name of the property to look up.
929 * @param defaultValue The value to return if the property does not exist, has no non-null
930 * value, or fails to parse into a float.
931 * @return the corresponding value, or defaultValue if either none exists or it does not parse.
932 * @hide
933 */
934 @SystemApi
935 @RequiresPermission(READ_DEVICE_CONFIG)
936 public static float getFloat(@NonNull String namespace, @NonNull String name,
937 float defaultValue) {
938 String value = getProperty(namespace, name);
939 if (value == null) {
940 return defaultValue;
941 }
942 try {
943 return Float.parseFloat(value);
944 } catch (NumberFormatException e) {
945 Log.e(TAG, "Parsing float failed for " + namespace + ":" + name);
946 return defaultValue;
947 }
948 }
949
950 /**
951 * Create a new property with the provided name and value in the provided namespace, or
952 * update the value of such a property if it already exists. The same name can exist in multiple
953 * namespaces and might have different values in any or all namespaces.
954 * <p>
955 * The method takes an argument indicating whether to make the value the default for this
956 * property.
957 * <p>
958 * All properties stored for a particular scope can be reverted to their default values
959 * by passing the namespace to {@link #resetToDefaults(int, String)}.
960 *
961 * @param namespace The namespace containing the property to create or update.
962 * @param name The name of the property to create or update.
963 * @param value The value to store for the property.
964 * @param makeDefault Whether to make the new value the default one.
965 * @return {@code true} if the value was set, {@code false} if the storage implementation throws
966 * errors.
967 * @hide
968 * @see #resetToDefaults(int, String).
969 */
970 @SystemApi
971 @RequiresPermission(WRITE_DEVICE_CONFIG)
972 public static boolean setProperty(@NonNull String namespace, @NonNull String name,
973 @Nullable String value, boolean makeDefault) {
974 ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
975 return Settings.Config.putString(contentResolver, namespace, name, value, makeDefault);
976 }
977
978 /**
979 * Set all of the properties for a specific namespace. Pre-existing properties will be updated
980 * and new properties will be added if necessary. Any pre-existing properties for the specific
981 * namespace which are not part of the provided {@link Properties} object will be deleted from
982 * the namespace. These changes are all applied atomically, such that no calls to read or reset
983 * these properties can happen in the middle of this update.
984 * <p>
985 * Each call to {@link #getProperties(String, String...)} is also atomic and ensures that either
986 * none or all of this update is picked up, but never only part of it.
987 *
988 * @param properties the complete set of properties to set for a specific namespace.
989 * @throws BadConfigException if the provided properties are banned by RescueParty.
990 * @return {@code true} if the values were set, {@code false} otherwise.
991 * @hide
992 */
993 @SystemApi
994 @RequiresPermission(WRITE_DEVICE_CONFIG)
995 public static boolean setProperties(@NonNull Properties properties) throws BadConfigException {
996 ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
997 return Settings.Config.setStrings(contentResolver, properties.getNamespace(),
998 properties.mMap);
999 }
1000
1001 /**
1002 * Delete a property with the provided name and value in the provided namespace
1003 *
1004 * @param namespace The namespace containing the property to delete.
1005 * @param name The name of the property to delete.
1006 * @return {@code true} if the property was deleted or it did not exist in the first place.
1007 * Return {@code false} if the storage implementation throws errors.
1008 * @hide
1009 */
1010 @SystemApi
1011 @RequiresPermission(WRITE_DEVICE_CONFIG)
1012 public static boolean deleteProperty(@NonNull String namespace, @NonNull String name) {
1013 ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
1014 return Settings.Config.deleteString(contentResolver, namespace, name);
1015 }
1016
1017 /**
1018 * Reset properties to their default values by removing the underlying values.
1019 * <p>
1020 * The method accepts an optional namespace parameter. If provided, only properties set within
1021 * that namespace will be reset. Otherwise, all properties will be reset.
1022 * <p>
1023 * Note: This method should only be used by {@link com.android.server.RescueParty}. It was
1024 * designed to be used in the event of boot or crash loops caused by flag changes. It does not
1025 * revert flag values to defaults - instead it removes the property entirely which causes the
1026 * consumer of the flag to use hardcoded defaults upon retrieval.
1027 * <p>
1028 * To clear values for a namespace without removing the underlying properties, construct a
1029 * {@link Properties} object with the caller's namespace and either an empty flag map, or some
1030 * snapshot of flag values. Then use {@link #setProperties(Properties)} to remove all flags
1031 * under the namespace, or set them to the values in the snapshot.
1032 * <p>
1033 * To revert values for testing, one should mock DeviceConfig using
1034 * {@link com.android.server.testables.TestableDeviceConfig} where possible. Otherwise, fallback
1035 * to using {@link #setProperties(Properties)} as outlined above.
1036 *
1037 * @param resetMode The reset mode to use.
1038 * @param namespace Optionally, the specific namespace which resets will be limited to.
1039 * @hide
1040 * @see #setProperty(String, String, String, boolean)
1041 */
1042 @SystemApi
1043 @RequiresPermission(WRITE_DEVICE_CONFIG)
1044 public static void resetToDefaults(@ResetMode int resetMode, @Nullable String namespace) {
1045 ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
1046 Settings.Config.resetToDefaults(contentResolver, resetMode, namespace);
1047 }
1048
1049 /**
1050 * Disables or re-enables bulk modifications ({@link #setProperties(Properties)}) to device
1051 * config values. This is intended for use during tests to prevent a sync operation clearing
1052 * config values which could influence the outcome of the tests, i.e. by changing behavior.
1053 *
1054 * @param syncDisabledMode the mode to use, see {@link Settings.Config#SYNC_DISABLED_MODE_NONE},
1055 * {@link Settings.Config#SYNC_DISABLED_MODE_PERSISTENT} and {@link
1056 * Settings.Config#SYNC_DISABLED_MODE_UNTIL_REBOOT}
1057 *
1058 * @see #getSyncDisabledMode()
1059 * @hide
1060 */
1061 @RequiresPermission(WRITE_DEVICE_CONFIG)
1062 public static void setSyncDisabledMode(@SyncDisabledMode int syncDisabledMode) {
1063 ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
1064 Settings.Config.setSyncDisabledMode(contentResolver, syncDisabledMode);
1065 }
1066
1067 /**
1068 * Returns the current mode of sync disabling.
1069 *
1070 * @see #setSyncDisabledMode(int)
1071 * @hide
1072 */
1073 @RequiresPermission(WRITE_DEVICE_CONFIG)
1074 public static @SyncDisabledMode int getSyncDisabledMode() {
1075 ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
1076 return Settings.Config.getSyncDisabledMode(contentResolver);
1077 }
1078
1079 /**
1080 * Add a listener for property changes.
1081 * <p>
1082 * This listener will be called whenever properties in the specified namespace change. Callbacks
1083 * will be made on the specified executor. Future calls to this method with the same listener
1084 * will replace the old namespace and executor. Remove the listener entirely by calling
1085 * {@link #removeOnPropertiesChangedListener(OnPropertiesChangedListener)}.
1086 *
1087 * @param namespace The namespace containing properties to monitor.
1088 * @param executor The executor which will be used to run callbacks.
1089 * @param onPropertiesChangedListener The listener to add.
1090 * @hide
1091 * @see #removeOnPropertiesChangedListener(OnPropertiesChangedListener)
1092 */
1093 @SystemApi
1094 @RequiresPermission(READ_DEVICE_CONFIG)
1095 public static void addOnPropertiesChangedListener(
1096 @NonNull String namespace,
1097 @NonNull @CallbackExecutor Executor executor,
1098 @NonNull OnPropertiesChangedListener onPropertiesChangedListener) {
1099 enforceReadPermission(ActivityThread.currentApplication().getApplicationContext(),
1100 namespace);
1101 synchronized (sLock) {
1102 Pair<String, Executor> oldNamespace = sListeners.get(onPropertiesChangedListener);
1103 if (oldNamespace == null) {
1104 // Brand new listener, add it to the list.
1105 sListeners.put(onPropertiesChangedListener, new Pair<>(namespace, executor));
1106 incrementNamespace(namespace);
1107 } else if (namespace.equals(oldNamespace.first)) {
1108 // Listener is already registered for this namespace, update executor just in case.
1109 sListeners.put(onPropertiesChangedListener, new Pair<>(namespace, executor));
1110 } else {
1111 // Update this listener from an old namespace to the new one.
1112 decrementNamespace(sListeners.get(onPropertiesChangedListener).first);
1113 sListeners.put(onPropertiesChangedListener, new Pair<>(namespace, executor));
1114 incrementNamespace(namespace);
1115 }
1116 }
1117 }
1118
1119 /**
1120 * Remove a listener for property changes. The listener will receive no further notification of
1121 * property changes.
1122 *
1123 * @param onPropertiesChangedListener The listener to remove.
1124 * @hide
1125 * @see #addOnPropertiesChangedListener(String, Executor, OnPropertiesChangedListener)
1126 */
1127 @SystemApi
1128 public static void removeOnPropertiesChangedListener(
1129 @NonNull OnPropertiesChangedListener onPropertiesChangedListener) {
1130 Preconditions.checkNotNull(onPropertiesChangedListener);
1131 synchronized (sLock) {
1132 if (sListeners.containsKey(onPropertiesChangedListener)) {
1133 decrementNamespace(sListeners.get(onPropertiesChangedListener).first);
1134 sListeners.remove(onPropertiesChangedListener);
1135 }
1136 }
1137 }
1138
1139 private static Uri createNamespaceUri(@NonNull String namespace) {
1140 Preconditions.checkNotNull(namespace);
1141 return CONTENT_URI.buildUpon().appendPath(namespace).build();
1142 }
1143
1144 /**
1145 * Increment the count used to represent the number of listeners subscribed to the given
1146 * namespace. If this is the first (i.e. incrementing from 0 to 1) for the given namespace, a
1147 * ContentObserver is registered.
1148 *
1149 * @param namespace The namespace to increment the count for.
1150 */
1151 @GuardedBy("sLock")
1152 private static void incrementNamespace(@NonNull String namespace) {
1153 Preconditions.checkNotNull(namespace);
1154 Pair<ContentObserver, Integer> namespaceCount = sNamespaces.get(namespace);
1155 if (namespaceCount != null) {
1156 sNamespaces.put(namespace, new Pair<>(namespaceCount.first, namespaceCount.second + 1));
1157 } else {
1158 // This is a new namespace, register a ContentObserver for it.
1159 ContentObserver contentObserver = new ContentObserver(null) {
1160 @Override
1161 public void onChange(boolean selfChange, Uri uri) {
1162 if (uri != null) {
1163 handleChange(uri);
1164 }
1165 }
1166 };
1167 ActivityThread.currentApplication().getContentResolver()
1168 .registerContentObserver(createNamespaceUri(namespace), true, contentObserver);
1169 sNamespaces.put(namespace, new Pair<>(contentObserver, 1));
1170 }
1171 }
1172
1173 /**
1174 * Decrement the count used to represent the number of listeners subscribed to the given
1175 * namespace. If this is the final decrement call (i.e. decrementing from 1 to 0) for the given
1176 * namespace, the ContentObserver that had been tracking it will be removed.
1177 *
1178 * @param namespace The namespace to decrement the count for.
1179 */
1180 @GuardedBy("sLock")
1181 private static void decrementNamespace(@NonNull String namespace) {
1182 Preconditions.checkNotNull(namespace);
1183 Pair<ContentObserver, Integer> namespaceCount = sNamespaces.get(namespace);
1184 if (namespaceCount == null) {
1185 // This namespace is not registered and does not need to be decremented
1186 return;
1187 } else if (namespaceCount.second > 1) {
1188 sNamespaces.put(namespace, new Pair<>(namespaceCount.first, namespaceCount.second - 1));
1189 } else {
1190 // Decrementing a namespace to zero means we no longer need its ContentObserver.
1191 ActivityThread.currentApplication().getContentResolver()
1192 .unregisterContentObserver(namespaceCount.first);
1193 sNamespaces.remove(namespace);
1194 }
1195 }
1196
1197 private static void handleChange(@NonNull Uri uri) {
1198 Preconditions.checkNotNull(uri);
1199 List<String> pathSegments = uri.getPathSegments();
1200 // pathSegments(0) is "config"
1201 final String namespace = pathSegments.get(1);
1202 Properties.Builder propBuilder = new Properties.Builder(namespace);
1203 try {
1204 Properties allProperties = getProperties(namespace);
1205 for (int i = 2; i < pathSegments.size(); ++i) {
1206 String key = pathSegments.get(i);
1207 propBuilder.setString(key, allProperties.getString(key, null));
1208 }
1209 } catch (SecurityException e) {
1210 // Silently failing to not crash binder or listener threads.
1211 Log.e(TAG, "OnPropertyChangedListener update failed: permission violation.");
1212 return;
1213 }
1214 Properties properties = propBuilder.build();
1215
1216 synchronized (sLock) {
1217 for (int i = 0; i < sListeners.size(); i++) {
1218 if (namespace.equals(sListeners.valueAt(i).first)) {
1219 final OnPropertiesChangedListener listener = sListeners.keyAt(i);
1220 sListeners.valueAt(i).second.execute(() -> {
1221 listener.onPropertiesChanged(properties);
1222 });
1223 }
1224 }
1225 }
1226 }
1227
1228 /**
1229 * Enforces READ_DEVICE_CONFIG permission if namespace is not one of public namespaces.
1230 * @hide
1231 */
1232 public static void enforceReadPermission(Context context, String namespace) {
1233 if (context.checkCallingOrSelfPermission(READ_DEVICE_CONFIG)
1234 != PackageManager.PERMISSION_GRANTED) {
1235 if (!PUBLIC_NAMESPACES.contains(namespace)) {
1236 throw new SecurityException("Permission denial: reading from settings requires:"
1237 + READ_DEVICE_CONFIG);
1238 }
1239 }
1240 }
1241
1242 /**
1243 * Returns list of namespaces that can be read without READ_DEVICE_CONFIG_PERMISSION;
1244 * @hide
1245 */
1246 public static @NonNull List<String> getPublicNamespaces() {
1247 return PUBLIC_NAMESPACES;
1248 }
1249
1250 /**
1251 * Interface for monitoring changes to properties. Implementations will receive callbacks when
1252 * properties change, including a {@link Properties} object which contains a single namespace
1253 * and all of the properties which changed for that namespace. This includes properties which
1254 * were added, updated, or deleted. This is not necessarily a complete list of all properties
1255 * belonging to the namespace, as properties which don't change are omitted.
1256 * <p>
1257 * Override {@link #onPropertiesChanged(Properties)} to handle callbacks for changes.
1258 *
1259 * @hide
1260 */
1261 @SystemApi
1262 public interface OnPropertiesChangedListener {
1263 /**
1264 * Called when one or more properties have changed, providing a Properties object with all
1265 * of the changed properties. This object will contain only properties which have changed,
1266 * not the complete set of all properties belonging to the namespace.
1267 *
1268 * @param properties Contains the complete collection of properties which have changed for a
1269 * single namespace. This includes only those which were added, updated,
1270 * or deleted.
1271 */
1272 void onPropertiesChanged(@NonNull Properties properties);
1273 }
1274
1275 /**
1276 * Thrown by {@link #setProperties(Properties)} when a configuration is rejected. This
1277 * happens if RescueParty has identified a bad configuration and reset the namespace.
1278 *
1279 * @hide
1280 */
1281 @SystemApi
1282 public static class BadConfigException extends Exception {}
1283
1284 /**
1285 * A mapping of properties to values, as well as a single namespace which they all belong to.
1286 *
1287 * @hide
1288 */
1289 @SystemApi
1290 public static class Properties {
1291 private final String mNamespace;
1292 private final HashMap<String, String> mMap;
1293 private Set<String> mKeyset;
1294
1295 /**
1296 * Create a mapping of properties to values and the namespace they belong to.
1297 *
1298 * @param namespace The namespace these properties belong to.
1299 * @param keyValueMap A map between property names and property values.
1300 * @hide
1301 */
1302 public Properties(@NonNull String namespace, @Nullable Map<String, String> keyValueMap) {
1303 Preconditions.checkNotNull(namespace);
1304 mNamespace = namespace;
1305 mMap = new HashMap();
1306 if (keyValueMap != null) {
1307 mMap.putAll(keyValueMap);
1308 }
1309 }
1310
1311 /**
1312 * @return the namespace all properties within this instance belong to.
1313 */
1314 @NonNull
1315 public String getNamespace() {
1316 return mNamespace;
1317 }
1318
1319 /**
1320 * @return the non-null set of property names.
1321 */
1322 @NonNull
1323 public Set<String> getKeyset() {
1324 if (mKeyset == null) {
1325 mKeyset = Collections.unmodifiableSet(mMap.keySet());
1326 }
1327 return mKeyset;
1328 }
1329
1330 /**
1331 * Look up the String value of a property.
1332 *
1333 * @param name The name of the property to look up.
1334 * @param defaultValue The value to return if the property has not been defined.
1335 * @return the corresponding value, or defaultValue if none exists.
1336 */
1337 @Nullable
1338 public String getString(@NonNull String name, @Nullable String defaultValue) {
1339 Preconditions.checkNotNull(name);
1340 String value = mMap.get(name);
1341 return value != null ? value : defaultValue;
1342 }
1343
1344 /**
1345 * Look up the boolean value of a property.
1346 *
1347 * @param name The name of the property to look up.
1348 * @param defaultValue The value to return if the property has not been defined.
1349 * @return the corresponding value, or defaultValue if none exists.
1350 */
1351 public boolean getBoolean(@NonNull String name, boolean defaultValue) {
1352 Preconditions.checkNotNull(name);
1353 String value = mMap.get(name);
1354 return value != null ? Boolean.parseBoolean(value) : defaultValue;
1355 }
1356
1357 /**
1358 * Look up the int value of a property.
1359 *
1360 * @param name The name of the property to look up.
1361 * @param defaultValue The value to return if the property has not been defined or fails to
1362 * parse into an int.
1363 * @return the corresponding value, or defaultValue if no valid int is available.
1364 */
1365 public int getInt(@NonNull String name, int defaultValue) {
1366 Preconditions.checkNotNull(name);
1367 String value = mMap.get(name);
1368 if (value == null) {
1369 return defaultValue;
1370 }
1371 try {
1372 return Integer.parseInt(value);
1373 } catch (NumberFormatException e) {
1374 Log.e(TAG, "Parsing int failed for " + name);
1375 return defaultValue;
1376 }
1377 }
1378
1379 /**
1380 * Look up the long value of a property.
1381 *
1382 * @param name The name of the property to look up.
1383 * @param defaultValue The value to return if the property has not been defined. or fails to
1384 * parse into a long.
1385 * @return the corresponding value, or defaultValue if no valid long is available.
1386 */
1387 public long getLong(@NonNull String name, long defaultValue) {
1388 Preconditions.checkNotNull(name);
1389 String value = mMap.get(name);
1390 if (value == null) {
1391 return defaultValue;
1392 }
1393 try {
1394 return Long.parseLong(value);
1395 } catch (NumberFormatException e) {
1396 Log.e(TAG, "Parsing long failed for " + name);
1397 return defaultValue;
1398 }
1399 }
1400
1401 /**
1402 * Look up the int value of a property.
1403 *
1404 * @param name The name of the property to look up.
1405 * @param defaultValue The value to return if the property has not been defined. or fails to
1406 * parse into a float.
1407 * @return the corresponding value, or defaultValue if no valid float is available.
1408 */
1409 public float getFloat(@NonNull String name, float defaultValue) {
1410 Preconditions.checkNotNull(name);
1411 String value = mMap.get(name);
1412 if (value == null) {
1413 return defaultValue;
1414 }
1415 try {
1416 return Float.parseFloat(value);
1417 } catch (NumberFormatException e) {
1418 Log.e(TAG, "Parsing float failed for " + name);
1419 return defaultValue;
1420 }
1421 }
1422
1423 /**
1424 * Builder class for the construction of {@link Properties} objects.
1425 */
1426 public static final class Builder {
1427 @NonNull
1428 private final String mNamespace;
1429 @NonNull
1430 private final Map<String, String> mKeyValues = new HashMap<>();
1431
1432 /**
1433 * Create a new Builders for the specified namespace.
1434 * @param namespace non null namespace.
1435 */
1436 public Builder(@NonNull String namespace) {
1437 mNamespace = namespace;
1438 }
1439
1440 /**
1441 * Add a new property with the specified key and value.
1442 * @param name non null name of the property.
1443 * @param value nullable string value of the property.
1444 * @return this Builder object
1445 */
1446 @NonNull
1447 public Builder setString(@NonNull String name, @Nullable String value) {
1448 mKeyValues.put(name, value);
1449 return this;
1450 }
1451
1452 /**
1453 * Add a new property with the specified key and value.
1454 * @param name non null name of the property.
1455 * @param value nullable string value of the property.
1456 * @return this Builder object
1457 */
1458 @NonNull
1459 public Builder setBoolean(@NonNull String name, boolean value) {
1460 mKeyValues.put(name, Boolean.toString(value));
1461 return this;
1462 }
1463
1464 /**
1465 * Add a new property with the specified key and value.
1466 * @param name non null name of the property.
1467 * @param value int value of the property.
1468 * @return this Builder object
1469 */
1470 @NonNull
1471 public Builder setInt(@NonNull String name, int value) {
1472 mKeyValues.put(name, Integer.toString(value));
1473 return this;
1474 }
1475
1476 /**
1477 * Add a new property with the specified key and value.
1478 * @param name non null name of the property.
1479 * @param value long value of the property.
1480 * @return this Builder object
1481 */
1482 @NonNull
1483 public Builder setLong(@NonNull String name, long value) {
1484 mKeyValues.put(name, Long.toString(value));
1485 return this;
1486 }
1487
1488 /**
1489 * Add a new property with the specified key and value.
1490 * @param name non null name of the property.
1491 * @param value float value of the property.
1492 * @return this Builder object
1493 */
1494 @NonNull
1495 public Builder setFloat(@NonNull String name, float value) {
1496 mKeyValues.put(name, Float.toString(value));
1497 return this;
1498 }
1499
1500 /**
1501 * Create a new {@link Properties} object.
1502 * @return non null Properties.
1503 */
1504 @NonNull
1505 public Properties build() {
1506 return new Properties(mNamespace, mKeyValues);
1507 }
1508 }
1509 }
1510
1511 }