summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Lin <danny@kdrag0n.dev>2022-03-08 20:58:50 -0800
committerDanny Lin <danny@kdrag0n.dev>2022-03-22 19:50:38 -0700
commit8b089a43a28b02c7576f90a94830edfed617e876 (patch)
tree6fafdc73909bcd9b50a5acf7c26c2db4693928c5
parent7485abbf9e34e90ce74e854e6077395fe4f8725c (diff)
Add soft config type for user-persistent settingsHEADuminekotachibana-mr1tachibanasugisawa-mr1
Some device configs, such as the location indicator flag, can easily be reused for user-facing settings rather than adding a new setting and hook it up. To accommodate such cases, add a new "soft" config type where configs are only set on boot if they don't already have a value. This allows provisioning an initial value while allowing user choices to persist after that.
-rw-r--r--res/values/config.xml5
-rw-r--r--src/org/protonaosp/deviceconfig/BootReceiver.java13
2 files changed, 14 insertions, 4 deletions
diff --git a/res/values/config.xml b/res/values/config.xml
index 88ac362..d33f44e 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -15,6 +15,11 @@
limitations under the License.
-->
<resources>
+ <!-- Configs for all devices. Provisioned on every boot. -->
<string-array name="configs_base" />
+ <!-- Configs for all devices. Only provisioned if not already set. -->
+ <string-array name="configs_base_soft" />
+
+ <!-- Device-specific configs, for overlaying in device trees. Provisioned on every boot. -->
<string-array name="configs_device" />
</resources>
diff --git a/src/org/protonaosp/deviceconfig/BootReceiver.java b/src/org/protonaosp/deviceconfig/BootReceiver.java
index 12ee2d2..d241ff3 100644
--- a/src/org/protonaosp/deviceconfig/BootReceiver.java
+++ b/src/org/protonaosp/deviceconfig/BootReceiver.java
@@ -34,11 +34,13 @@ public class BootReceiver extends BroadcastReceiver {
}
private void updateDefaultConfigs(Context context) {
- updateConfig(context, R.array.configs_base);
- updateConfig(context, R.array.configs_device);
+ updateConfig(context, R.array.configs_base, false);
+ updateConfig(context, R.array.configs_base_soft, true);
+
+ updateConfig(context, R.array.configs_device, false);
}
- private void updateConfig(Context context, int configArray) {
+ private void updateConfig(Context context, int configArray, boolean isSoft) {
// Set current properties
String[] rawProperties = context.getResources().getStringArray(configArray);
for (String property : rawProperties) {
@@ -54,7 +56,10 @@ public class BootReceiver extends BroadcastReceiver {
value = kv[1];
}
- DeviceConfig.setProperty(namespace, key, value, false);
+ // Skip soft configs that already have values
+ if (!isSoft || DeviceConfig.getString(namespace, key, null) == null) {
+ DeviceConfig.setProperty(namespace, key, value, false);
+ }
}
}
}