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

Commit 50b8d3f6 authored by Ted Bauer's avatar Ted Bauer
Browse files

Write file on boot when migration flag is enabled.

We are enabling a new flag storage via a server flag, but need to read the value of this flag early in the boot. We're achieving this by writing a file when a server-flag is enabled, in a location that's accessible early in the boot.

Bug: 328444881
Test: adb shell device_config put core_experiments_team_internal com.android.providers.settings.storage_test_mission_1 true && adb shell cat /metadata/aconfig/flags/storage_migration.log
Change-Id: I96eeb6b3cdf0ccf8c0e67f7896a69fbe49684abb
parent 66bf088c
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -60,10 +60,12 @@ import libcore.io.IoUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
@@ -161,6 +163,11 @@ final class SettingsState {
    private static final String APEX_DIR = "/apex";
    private static final String APEX_ACONFIG_PATH_SUFFIX = "/etc/aconfig_flags.pb";

    private static final String STORAGE_MIGRATION_FLAG =
            "core_experiments_team_internal/com.android.providers.settings.storage_test_mission_1";
    private static final String STORAGE_MIGRATION_LOG =
            "/metadata/aconfig/flags/storage_migration.log";

    /**
     * This tag is applied to all aconfig default value-loaded flags.
     */
@@ -1439,6 +1446,20 @@ final class SettingsState {
                    }
                }

                if (name != null && name.equals(STORAGE_MIGRATION_FLAG) && value.equals("true")) {
                    File file = new File(STORAGE_MIGRATION_LOG);
                    if (!file.exists()) {
                        try (BufferedWriter writer =
                                new BufferedWriter(new FileWriter(STORAGE_MIGRATION_LOG))) {
                            final long timestamp = System.currentTimeMillis();
                            String entry = String.format("%d | Log init", timestamp);
                            writer.write(entry);
                        } catch (IOException e) {
                            Slog.e(LOG_TAG, "failed to write storage migration file", e);
                        }
                    }
                }

                mSettings.put(name, new Setting(name, value, defaultValue, packageName, tag,
                        fromSystem, id, isPreservedInRestore));

+7 −0
Original line number Diff line number Diff line
@@ -33,3 +33,10 @@ flag {
    bug: "327383546"
    is_fixed_read_only: true
}

flag {
    name: "storage_test_mission_1"
    namespace: "core_experiments_team_internal"
    description: "If this flag is detected as true on boot, writes a logfile to track storage migration correctness."
    bug: "328444881"
}