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

Commit 08742fd1 authored by Dennis Shen's avatar Dennis Shen Committed by Android (Google) Code Review
Browse files

Merge "sync staged flags over to system properties" into main

parents c8f659f2 534972c7
Loading
Loading
Loading
Loading
+49 −1
Original line number Diff line number Diff line
@@ -163,9 +163,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;
@@ -261,6 +264,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) {
@@ -331,6 +350,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]".