• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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.ranging;
18 
19 import android.content.Context;
20 import android.os.Handler;
21 import android.provider.DeviceConfig;
22 
23 import com.android.uwb.resources.R;
24 
25 /**
26  * This class allows getting all configurable flags from DeviceConfig.
27  */
28 public class DeviceConfigFacade {
29     private final Context mContext;
30 
31     // Cached values of fields updated via updateDeviceConfigFlags()
32     private String[] mTechnologyPreferenceList;
33     private int mRttRangingRequestDelay;
34 
DeviceConfigFacade(Handler handler, Context context)35     public DeviceConfigFacade(Handler handler, Context context) {
36         mContext = context;
37         updateDeviceConfigFlags();
38         DeviceConfig.addOnPropertiesChangedListener(
39                 DeviceConfig.NAMESPACE_UWB,
40                 command -> handler.post(command),
41                 properties -> {
42                     updateDeviceConfigFlags();
43                 });
44     }
45 
46     // device config override with array is not natively supported, so read the value as a comma
47     // separated string.
getDeviceConfigStringArray(String name, String[] defaultValue)48     private static String[] getDeviceConfigStringArray(String name, String[] defaultValue) {
49         String value = DeviceConfig.getString(DeviceConfig.NAMESPACE_UWB, name, null);
50         if (value == null) {
51             return defaultValue;
52         }
53         return value.split(" , ");
54     }
55 
updateDeviceConfigFlags()56     private void updateDeviceConfigFlags() {
57         mTechnologyPreferenceList = getDeviceConfigStringArray(
58                 "technology_preference_list",
59                 mContext.getResources().getStringArray(R.array.technology_preference_list)
60         );
61         mRttRangingRequestDelay = DeviceConfig.getInt(DeviceConfig.NAMESPACE_UWB,
62                 "rtt_ranging_request_delay",
63                 mContext.getResources().getInteger(R.integer.rtt_ranging_request_delay));
64     }
65 
getTechnologyPreferenceList()66     public String[] getTechnologyPreferenceList() {
67         return mTechnologyPreferenceList;
68     }
69 
getRttRangingRequestDelay()70     public int getRttRangingRequestDelay() {
71         return mRttRangingRequestDelay;
72     }
73 }
74