Skip to content

Commit

Permalink
DeviceConfig: Change setProperties behavior
Browse files Browse the repository at this point in the history
Change-Id: I7cf1574f423c7362e6a7c9d8a002e4b20e5e7f87
  • Loading branch information
jhenrique09 authored and basamaryan committed Aug 11, 2023
1 parent 3d820cb commit 85c1ac6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 31 deletions.
10 changes: 3 additions & 7 deletions core/java/android/provider/DeviceConfig.java
Expand Up @@ -981,14 +981,10 @@ public static boolean setProperty(@NonNull String namespace, @NonNull String nam
@SystemApi
@RequiresPermission(WRITE_DEVICE_CONFIG)
public static boolean setProperties(@NonNull Properties properties) throws BadConfigException {
Map<String, String> keyValuesFiltered =
DeviceConfigUtils.filterDeviceConfigs(properties.getNamespace(), properties.mMap);
if (keyValuesFiltered.size() == 0){
return true;
}
ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
boolean result = Settings.Config.setStrings(contentResolver, properties.getNamespace(),
keyValuesFiltered);
properties.mMap);
DeviceConfigUtils.setDefaultProperties(contentResolver, properties.getNamespace(), null);
return result;
}

Expand Down Expand Up @@ -1041,7 +1037,7 @@ public static boolean deleteProperty(@NonNull String namespace, @NonNull String
public static void resetToDefaults(@ResetMode int resetMode, @Nullable String namespace) {
ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
Settings.Config.resetToDefaults(contentResolver, resetMode, namespace);
DeviceConfigUtils.setDefaultProperties(contentResolver);
DeviceConfigUtils.setDefaultProperties(contentResolver, null, null);
}

/**
Expand Down
33 changes: 10 additions & 23 deletions core/java/com/android/internal/util/custom/DeviceConfigUtils.java
Expand Up @@ -58,29 +58,7 @@ public static boolean shouldDenyDeviceConfigControl(String namespace, String pro
return false;
}

public static Map<String, String> filterDeviceConfigs(String namespace, Map<String, String> keyValues) {
if (DEBUG) Log.d(TAG, "filterDeviceConfigs, namespace=" + namespace + ", properties=[" + String.join(",", keyValues.keySet()) + "]");
Map<String, String> keyValuesNew = new HashMap();
for (Map.Entry<String, String> entry : keyValues.entrySet()) {
keyValuesNew.put(entry.getKey(), entry.getValue());
}
for (String p : getDeviceConfigsOverride()) {
String[] kv = p.split("=");
String fullKey = kv[0];
String[] nsKey = fullKey.split("/");
if (nsKey[0] == namespace){
String key = nsKey[1];
String value = "";
if (kv.length > 1) {
value = kv[1];
}
keyValuesNew.put(key, value);
}
}
return keyValuesNew;
}

public static void setDefaultProperties(ContentResolver contentResolver) {
public static void setDefaultProperties(ContentResolver contentResolver, String filterNamespace, String filterProperty) {
if (DEBUG) Log.d(TAG, "setDefaultProperties");
for (String p : getDeviceConfigsOverride()) {
String[] kv = p.split("=");
Expand All @@ -89,6 +67,15 @@ public static void setDefaultProperties(ContentResolver contentResolver) {

String namespace = nsKey[0];
String key = nsKey[1];

if (filterNamespace != null && filterNamespace == namespace){
continue;
}

if (filterProperty != null && filterProperty == key){
continue;
}

String value = "";
if (kv.length > 1) {
value = kv[1];
Expand Down
Expand Up @@ -28,7 +28,7 @@ public void onStart() {
@Override
public void onBootPhase(int phase) {
if (phase == PHASE_BOOT_COMPLETED) {
DeviceConfigUtils.setDefaultProperties(mContext.getContentResolver());
DeviceConfigUtils.setDefaultProperties(mContext.getContentResolver(), null, null);
}
}
}

0 comments on commit 85c1ac6

Please sign in to comment.