Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 534972c7 authored by Dennis Shen's avatar Dennis Shen
Browse files

sync staged flags over to system properties

Bug: b/300111812
Change-Id: Ied6c10cd390d18daabacfdb8a452f31e0e5e16ef
parent cab68154
Loading
Loading
Loading
Loading
+49 −1
Original line number Diff line number Diff line
@@ -159,9 +159,12 @@ public class SettingsToPropertiesMapper {
        "wear_system_health",
        "wear_systems",
        "window_surfaces",
        "windowing_frontend"
        "windowing_frontend",
    };

    public static final String NAMESPACE_REBOOT_STAGING = "staged";
    public static final String NAMESPACE_REBOOT_STAGING_DELIMITER = "*";

    private final String[] mGlobalSettings;

    private final String[] mDeviceConfigScopes;
@@ -257,6 +260,22 @@ public class SettingsToPropertiesMapper {
                        }
                    });
        }

        // add sys prop sync callback for staged flag values
        DeviceConfig.addOnPropertiesChangedListener(
            NAMESPACE_REBOOT_STAGING,
            AsyncTask.THREAD_POOL_EXECUTOR,
            (DeviceConfig.Properties properties) -> {
              String scope = properties.getNamespace();
              for (String key : properties.getKeyset()) {
                String aconfigPropertyName = makeAconfigFlagStagedPropertyName(key);
                if (aconfigPropertyName == null) {
                    log("unable to construct system property for " + scope + "/" + key);
                    return;
                }
                setProperty(aconfigPropertyName, properties.getString(key, null));
              }
            });
    }

    public static SettingsToPropertiesMapper start(ContentResolver contentResolver) {
@@ -327,6 +346,35 @@ public class SettingsToPropertiesMapper {
        return propertyName;
    }

    /**
     * system property name constructing rule for staged aconfig flags, the flag name
     * is in the form of [namespace]*[actual flag name], we should push the following
     * to system properties
     * "next_boot.[actual sys prop name]".
     * If the name contains invalid characters or substrings for system property name,
     * will return null.
     * @param flagName
     * @return
     */
    @VisibleForTesting
    static String makeAconfigFlagStagedPropertyName(String flagName) {
        int idx = flagName.indexOf(NAMESPACE_REBOOT_STAGING_DELIMITER);
        if (idx == -1 || idx == flagName.length() - 1 || idx == 0) {
            log("invalid staged flag: " + flagName);
            return null;
        }

        String propertyName = "next_boot." + makeAconfigFlagPropertyName(
                flagName.substring(0, idx), flagName.substring(idx+1));

        if (!propertyName.matches(SYSTEM_PROPERTY_VALID_CHARACTERS_REGEX)
                || propertyName.contains(SYSTEM_PROPERTY_INVALID_SUBSTRING)) {
            return null;
        }

        return propertyName;
    }

    /**
     * system property name constructing rule for aconfig flags:
     * "persist.device_config.aconfig_flags.[category_name].[flag_name]".