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

Commit a84f5d55 authored by Dennis Shen's avatar Dennis Shen
Browse files

enable read from new storage

Test: atest -c
Change-Id: I2e80b8e5d4ed8b7f7d1f4076d0c09abf79e88904
parent ce42fb15
Loading
Loading
Loading
Loading
+34 −66
Original line number Diff line number Diff line
@@ -259,10 +259,6 @@ use log::{log, LevelFilter, Level};
/// flag provider
pub struct FlagProvider;

static READ_FROM_NEW_STORAGE: LazyLock<bool> = LazyLock::new(|| unsafe {
    Path::new("/metadata/aconfig/boot/enable_only_new_storage").exists()
});

static PACKAGE_OFFSET: LazyLock<Result<Option<u32>, AconfigStorageError>> = LazyLock::new(|| unsafe {
    get_mapped_storage_file("system", StorageFileType::PackageMap)
    .and_then(|package_map| get_package_read_context(&package_map, "com.android.aconfig.test"))
@@ -275,7 +271,6 @@ static FLAG_VAL_MAP: LazyLock<Result<Mmap, AconfigStorageError>> = LazyLock::new

/// flag value cache for disabled_rw
static CACHED_disabled_rw: LazyLock<bool> = LazyLock::new(|| {
    if *READ_FROM_NEW_STORAGE {
    // This will be called multiple times. Subsequent calls after the first are noops.
    logger::init(
        logger::Config::default()
@@ -312,17 +307,10 @@ static CACHED_disabled_rw: LazyLock<bool> = LazyLock::new(|| {
            return false;
        }
    }
    } else {
        flags_rust::GetServerConfigurableFlag(
            "aconfig_flags.aconfig_test",
            "com.android.aconfig.test.disabled_rw",
            "false") == "true"
    }
});

/// flag value cache for disabled_rw_exported
static CACHED_disabled_rw_exported: LazyLock<bool> = LazyLock::new(|| {
    if *READ_FROM_NEW_STORAGE {
        // This will be called multiple times. Subsequent calls after the first are noops.
        logger::init(
            logger::Config::default()
@@ -359,17 +347,10 @@ static CACHED_disabled_rw_exported: LazyLock<bool> = LazyLock::new(|| {
                return false;
            }
        }
    } else {
        flags_rust::GetServerConfigurableFlag(
            "aconfig_flags.aconfig_test",
            "com.android.aconfig.test.disabled_rw_exported",
            "false") == "true"
    }
});

/// flag value cache for disabled_rw_in_other_namespace
static CACHED_disabled_rw_in_other_namespace: LazyLock<bool> = LazyLock::new(|| {
    if *READ_FROM_NEW_STORAGE {
        // This will be called multiple times. Subsequent calls after the first are noops.
        logger::init(
            logger::Config::default()
@@ -406,18 +387,11 @@ static CACHED_disabled_rw_in_other_namespace: LazyLock<bool> = LazyLock::new(||
                return false;
            }
        }
    } else {
        flags_rust::GetServerConfigurableFlag(
            "aconfig_flags.other_namespace",
            "com.android.aconfig.test.disabled_rw_in_other_namespace",
            "false") == "true"
    }
});


/// flag value cache for enabled_rw
static CACHED_enabled_rw: LazyLock<bool> = LazyLock::new(|| {
    if *READ_FROM_NEW_STORAGE {
        // This will be called multiple times. Subsequent calls after the first are noops.
        logger::init(
            logger::Config::default()
@@ -454,12 +428,6 @@ static CACHED_enabled_rw: LazyLock<bool> = LazyLock::new(|| {
                return true;
            }
        }
    } else {
        flags_rust::GetServerConfigurableFlag(
            "aconfig_flags.aconfig_test",
            "com.android.aconfig.test.enabled_rw",
            "true") == "true"
    }
});

impl FlagProvider {
+12 −30
Original line number Diff line number Diff line
@@ -76,17 +76,8 @@ namespace {cpp_namespace} \{
            : boolean_start_index_()
            {{ -endif }}
            , flag_value_file_(nullptr)
            , read_from_new_storage_(false)
            , package_exists_in_storage_(true) \{

            if (access("/metadata/aconfig/boot/enable_only_new_storage", F_OK) == 0) \{
               read_from_new_storage_ = true;
            }

            if (!read_from_new_storage_) \{
               return;
            }

            auto package_map_file = aconfig_storage::get_mapped_file(
                 "{container}",
                 aconfig_storage::StorageFileType::package_map);
@@ -137,7 +128,6 @@ namespace {cpp_namespace} \{
            {{ -if item.readwrite }}
            if (cache_[{item.readwrite_idx}] == -1) \{
            {{ if allow_instrumentation- }}
                if (read_from_new_storage_) \{
                if (!package_exists_in_storage_) \{
                    return {item.default_value};
                }
@@ -151,12 +141,6 @@ namespace {cpp_namespace} \{
                }

                cache_[{item.readwrite_idx}] = *value;
                } else \{
                    cache_[{item.readwrite_idx}] = server_configurable_flags::GetServerConfigurableFlag(
                        "aconfig_flags.{item.device_config_namespace}",
                        "{item.device_config_flag}",
                        "{item.default_value}") == "true";
                }
            {{ -else- }}
                cache_[{item.readwrite_idx}] = server_configurable_flags::GetServerConfigurableFlag(
                    "aconfig_flags.{item.device_config_namespace}",
@@ -183,8 +167,6 @@ namespace {cpp_namespace} \{

        std::unique_ptr<aconfig_storage::MappedStorageFile> flag_value_file_;

        bool read_from_new_storage_;

        bool package_exists_in_storage_;
    {{ -endif }}
    {{ -endif }}
+31 −42
Original line number Diff line number Diff line
@@ -10,10 +10,6 @@ pub struct FlagProvider;

{{ if has_readwrite- }}
{{ if allow_instrumentation }}
static READ_FROM_NEW_STORAGE: LazyLock<bool> = LazyLock::new(|| unsafe \{
    Path::new("/metadata/aconfig/boot/enable_only_new_storage").exists()
});

static PACKAGE_OFFSET: LazyLock<Result<Option<u32>, AconfigStorageError>> = LazyLock::new(|| unsafe \{
    get_mapped_storage_file("{container}", StorageFileType::PackageMap)
    .and_then(|package_map| get_package_read_context(&package_map, "{package}"))
@@ -31,7 +27,6 @@ static FLAG_VAL_MAP: LazyLock<Result<Mmap, AconfigStorageError>> = LazyLock::new
{{ if allow_instrumentation }}
static CACHED_{flag.name}: LazyLock<bool> = LazyLock::new(|| \{

    if *READ_FROM_NEW_STORAGE \{
    // This will be called multiple times. Subsequent calls after the first are noops.
    logger::init(
        logger::Config::default()
@@ -68,12 +63,6 @@ static CACHED_{flag.name}: LazyLock<bool> = LazyLock::new(|| \{
            return {flag.default_value};
        }
    }
    } else \{
        flags_rust::GetServerConfigurableFlag(
            "aconfig_flags.{flag.device_config_namespace}",
            "{flag.device_config_flag}",
            "{flag.default_value}") == "true"
    }

});
{{ else }}