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

Commit c2f77d14 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Clean up dead bulk compare code" into main

parents be4b4856 79a3d91e
Loading
Loading
Loading
Loading
+0 −69
Original line number Diff line number Diff line
@@ -408,79 +408,10 @@ public class SettingsState {
                        Slog.w(LOG_TAG, "Bulk sync request to acongid failed.");
                    }
                }

                if (Flags.disableBulkCompare()) {
                    return;
                }

                // TOBO(b/312444587): remove the comparison logic after Test Mission 2.
                if (requests == null) {
                    Map<String, AconfigdFlagInfo> aconfigdFlagMap =
                            AconfigdJavaUtils.listFlagsValueInNewStorage(localSocket);
                    compareFlagValueInNewStorage(
                            mAconfigDefaultFlags,
                            aconfigdFlagMap);
                }
            }
        }
    }

    // TODO(b/312444587): remove the comparison logic after Test Mission 2.
    public int compareFlagValueInNewStorage(
            Map<String, AconfigdFlagInfo> defaultFlagMap,
            Map<String, AconfigdFlagInfo> aconfigdFlagMap) {

        // Get all defaults from the default map. The mSettings may not contain
        // all flags, since it only contains updated flags.
        int diffNum = 0;
        for (Map.Entry<String, AconfigdFlagInfo> entry : defaultFlagMap.entrySet()) {
            String key = entry.getKey();
            AconfigdFlagInfo flag = entry.getValue();

            AconfigdFlagInfo aconfigdFlag = aconfigdFlagMap.get(key);
            if (aconfigdFlag == null) {
                Slog.w(LOG_TAG, String.format("Flag %s is missing from aconfigd", key));
                diffNum++;
                continue;
            }
            String diff = flag.dumpDiff(aconfigdFlag);
            if (!diff.isEmpty()) {
                Slog.w(
                        LOG_TAG,
                        String.format(
                                "Flag %s is different in Settings and aconfig: %s", key, diff));
                diffNum++;
            }
        }

        for (String key : aconfigdFlagMap.keySet()) {
            if (defaultFlagMap.containsKey(key)) continue;
            Slog.w(LOG_TAG, String.format("Flag %s is missing from Settings", key));
            diffNum++;
        }

        String compareMarkerName = "aconfigd_marker/compare_diff_num";
        synchronized (mLock) {
            Setting markerSetting = mSettings.get(compareMarkerName);
            if (markerSetting == null) {
                markerSetting =
                        new Setting(
                                compareMarkerName,
                                String.valueOf(diffNum),
                                false,
                                "aconfig",
                                "aconfig");
                mSettings.put(compareMarkerName, markerSetting);
            }
            markerSetting.value = String.valueOf(diffNum);
        }

        if (diffNum == 0) {
            Slog.w(LOG_TAG, "Settings and new storage have same flags.");
        }
        return diffNum;
    }

    @GuardedBy("mLock")
    public int getAllAconfigFlagsFromSettings(
            @NonNull Map<String, AconfigdFlagInfo> flagInfoDefault) {
+0 −10
Original line number Diff line number Diff line
@@ -101,13 +101,3 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}
 No newline at end of file

flag {
    name: "disable_bulk_compare"
    namespace: "core_experiments_team_internal"
    description: "Disable bulk comparison between DeviceConfig and aconfig storage."
    bug: "312444587"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
 No newline at end of file
+0 −81
Original line number Diff line number Diff line
@@ -1303,85 +1303,4 @@ public class SettingsStateTest {
        assertFalse(flag3.getHasServerOverride());
        assertFalse(flag3.getHasLocalOverride());
    }

    @Test
    @RequiresFlagsDisabled(Flags.FLAG_DISABLE_BULK_COMPARE)
    public void testCompareFlagValueInNewStorage() {
                int configKey = SettingsState.makeKey(SettingsState.SETTINGS_TYPE_CONFIG, 0);
        Object lock = new Object();
        SettingsState settingsState =
                new SettingsState(
                        InstrumentationRegistry.getContext(),
                        lock,
                        mSettingsFile,
                        configKey,
                        SettingsState.MAX_BYTES_PER_APP_PACKAGE_UNLIMITED,
                        Looper.getMainLooper());

        AconfigdFlagInfo defaultFlag1 =
                AconfigdFlagInfo.newBuilder()
                        .setPackageName("com.android.flags")
                        .setFlagName("flag1")
                        .setDefaultFlagValue("false")
                        .setServerFlagValue("true")
                        .setHasServerOverride(true)
                        .setIsReadWrite(true)
                        .build();

        AconfigdFlagInfo expectedFlag1 =
                AconfigdFlagInfo.newBuilder()
                        .setPackageName("com.android.flags")
                        .setFlagName("flag1")
                        .setServerFlagValue("true")
                        .setDefaultFlagValue("false")
                        .setHasServerOverride(true)
                        .setIsReadWrite(true)
                        .build();

        Map<String, AconfigdFlagInfo> aconfigdMap = new HashMap<>();
        Map<String, AconfigdFlagInfo> defaultMap = new HashMap<>();

        defaultMap.put("com.android.flags.flag1", defaultFlag1);
        aconfigdMap.put("com.android.flags.flag1", expectedFlag1);

        int ret = settingsState.compareFlagValueInNewStorage(defaultMap, aconfigdMap);
        assertEquals(0, ret);

        String value =
                settingsState.getSettingLocked("aconfigd_marker/compare_diff_num").getValue();
        assertEquals("0", value);

        AconfigdFlagInfo defaultFlag2 =
                AconfigdFlagInfo.newBuilder()
                        .setPackageName("com.android.flags")
                        .setFlagName("flag2")
                        .setDefaultFlagValue("false")
                        .build();
        defaultMap.put("com.android.flags.flag2", defaultFlag2);

        ret = settingsState.compareFlagValueInNewStorage(defaultMap, aconfigdMap);
        // missing from new storage
        assertEquals(1, ret);
        value =
                settingsState.getSettingLocked("aconfigd_marker/compare_diff_num").getValue();
        assertEquals("1", value);

        AconfigdFlagInfo expectedFlag2 =
        AconfigdFlagInfo.newBuilder()
                .setPackageName("com.android.flags")
                .setFlagName("flag2")
                .setServerFlagValue("true")
                .setLocalFlagValue("true")
                .setDefaultFlagValue("false")
                .setHasServerOverride(true)
                .setHasLocalOverride(true)
                .build();
        aconfigdMap.put("com.android.flags.flag2", expectedFlag2);
        ret = settingsState.compareFlagValueInNewStorage(defaultMap, aconfigdMap);
        // skip the server and local value comparison when the flag is read_only
        assertEquals(0, ret);
        value =
                settingsState.getSettingLocked("aconfigd_marker/compare_diff_num").getValue();
        assertEquals("0", value);
    }
}