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

Commit 83b1f585 authored by Ted Bauer's avatar Ted Bauer
Browse files

Stage any flag on DeviceConfig writes.

Currently, flags are staged to be on reboot by being written to the
staging namespace. The server-side explicitly writes to the staging
namespace. That means flags can still be toggled immediately locally,
and when the server-side doesn't have staging enabled. A race condition
on the first wifi connection means that sometimes flags can get
immediately toggled. This CL makes all writes stage, even local ones.

Bug: 326598713
Test: atest SettingsStateTest
Change-Id: I9a551843ef710bf074b40cbe581caf075cfafc07
parent 198545c4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ android_test {
        // because this test is not an instrumentation test. (because the target runs in the system process.)
        "SettingsProviderLib",
        "androidx.test.rules",
        "device_config_service_flags_java",
        "flag-junit",
        "junit",
        "libaconfig_java_proto_lite",
+31 −0
Original line number Diff line number Diff line
@@ -357,6 +357,15 @@ final class SettingsState {
        }
    }

    @VisibleForTesting
    @GuardedBy("mLock")
    public void addAconfigDefaultValuesFromMap(
            @NonNull Map<String, Map<String, String>> defaultMap) {
        if (mNamespaceDefaults != null) {
            mNamespaceDefaults.putAll(defaultMap);
        }
    }

    @VisibleForTesting
    @GuardedBy("mLock")
    public static void loadAconfigDefaultValues(byte[] fileContents,
@@ -510,6 +519,28 @@ final class SettingsState {
            return false;
        }

        // Aconfig flags are always boot stable, so we anytime we write one, we staged it to be
        // applied on reboot.
        if (Flags.stageAllAconfigFlags() && mNamespaceDefaults != null) {
            int slashIndex = name.indexOf("/");
            boolean stageFlag = isConfigSettingsKey(mKey)
                    && slashIndex != -1
                    && slashIndex != 0
                    && slashIndex != name.length();

            if (stageFlag) {
                String namespace = name.substring(0, slashIndex);
                String flag = name.substring(slashIndex + 1);

                boolean isAconfig = mNamespaceDefaults.containsKey(namespace)
                        && mNamespaceDefaults.get(namespace).containsKey(name);

                if (isAconfig) {
                    name = "staged/" + namespace + "*" + flag;
                }
            }
        }

        final boolean isNameTooLong = name.length() > SettingsState.MAX_LENGTH_PER_STRING;
        final boolean isValueTooLong =
                value != null && value.length() > SettingsState.MAX_LENGTH_PER_STRING;
+11 −0
Original line number Diff line number Diff line
@@ -14,3 +14,14 @@ flag {
    bug: "311155098"
    is_fixed_read_only: true
}

flag {
    name: "stage_all_aconfig_flags"
    namespace: "core_experiments_team_internal"
    description: "Stage _all_ aconfig flags on writes, even local ones."
    bug: "326598713"
    is_fixed_read_only: true
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+178 −32

File changed.

Preview size limit exceeded, changes collapsed.