Merge "aconfig: Use LazyLock rather than lazy_static" into main am: 36a352cd02
am: 364dca6ca5
Original change: https://android-review.googlesource.com/c/platform/build/+/3252494 Change-Id: Idd38abe84a61b4ab55b13d625df6c1d8c0433abb Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -113,6 +113,7 @@ mod tests {
|
|||||||
use aconfig_storage_read_api::{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context};
|
use aconfig_storage_read_api::{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::sync::LazyLock;
|
||||||
use log::{log, LevelFilter, Level};
|
use log::{log, LevelFilter, Level};
|
||||||
|
|
||||||
static STORAGE_MIGRATION_MARKER_FILE: &str =
|
static STORAGE_MIGRATION_MARKER_FILE: &str =
|
||||||
@@ -123,36 +124,28 @@ static MIGRATION_LOG_TAG: &str = "AconfigTestMission1";
|
|||||||
pub struct FlagProvider;
|
pub struct FlagProvider;
|
||||||
|
|
||||||
/// flag value cache for disabled_rw
|
/// flag value cache for disabled_rw
|
||||||
lazy_static::lazy_static! {
|
static CACHED_disabled_rw: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag(
|
||||||
static ref CACHED_disabled_rw: bool = flags_rust::GetServerConfigurableFlag(
|
|
||||||
"aconfig_flags.aconfig_test",
|
"aconfig_flags.aconfig_test",
|
||||||
"com.android.aconfig.test.disabled_rw",
|
"com.android.aconfig.test.disabled_rw",
|
||||||
"false") == "true";
|
"false") == "true");
|
||||||
}
|
|
||||||
|
|
||||||
/// flag value cache for disabled_rw_exported
|
/// flag value cache for disabled_rw_exported
|
||||||
lazy_static::lazy_static! {
|
static CACHED_disabled_rw_exported: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag(
|
||||||
static ref CACHED_disabled_rw_exported: bool = flags_rust::GetServerConfigurableFlag(
|
|
||||||
"aconfig_flags.aconfig_test",
|
"aconfig_flags.aconfig_test",
|
||||||
"com.android.aconfig.test.disabled_rw_exported",
|
"com.android.aconfig.test.disabled_rw_exported",
|
||||||
"false") == "true";
|
"false") == "true");
|
||||||
}
|
|
||||||
|
|
||||||
/// flag value cache for disabled_rw_in_other_namespace
|
/// flag value cache for disabled_rw_in_other_namespace
|
||||||
lazy_static::lazy_static! {
|
static CACHED_disabled_rw_in_other_namespace: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag(
|
||||||
static ref CACHED_disabled_rw_in_other_namespace: bool = flags_rust::GetServerConfigurableFlag(
|
|
||||||
"aconfig_flags.other_namespace",
|
"aconfig_flags.other_namespace",
|
||||||
"com.android.aconfig.test.disabled_rw_in_other_namespace",
|
"com.android.aconfig.test.disabled_rw_in_other_namespace",
|
||||||
"false") == "true";
|
"false") == "true");
|
||||||
}
|
|
||||||
|
|
||||||
/// flag value cache for enabled_rw
|
/// flag value cache for enabled_rw
|
||||||
lazy_static::lazy_static! {
|
static CACHED_enabled_rw: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag(
|
||||||
static ref CACHED_enabled_rw: bool = flags_rust::GetServerConfigurableFlag(
|
|
||||||
"aconfig_flags.aconfig_test",
|
"aconfig_flags.aconfig_test",
|
||||||
"com.android.aconfig.test.enabled_rw",
|
"com.android.aconfig.test.enabled_rw",
|
||||||
"true") == "true";
|
"true") == "true");
|
||||||
}
|
|
||||||
|
|
||||||
impl FlagProvider {
|
impl FlagProvider {
|
||||||
/// query flag disabled_ro
|
/// query flag disabled_ro
|
||||||
@@ -264,6 +257,7 @@ pub fn enabled_rw() -> bool {
|
|||||||
use aconfig_storage_read_api::{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context};
|
use aconfig_storage_read_api::{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::sync::LazyLock;
|
||||||
use log::{log, LevelFilter, Level};
|
use log::{log, LevelFilter, Level};
|
||||||
|
|
||||||
static STORAGE_MIGRATION_MARKER_FILE: &str =
|
static STORAGE_MIGRATION_MARKER_FILE: &str =
|
||||||
@@ -273,285 +267,276 @@ static MIGRATION_LOG_TAG: &str = "AconfigTestMission1";
|
|||||||
/// flag provider
|
/// flag provider
|
||||||
pub struct FlagProvider;
|
pub struct FlagProvider;
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
static PACKAGE_OFFSET: LazyLock<Result<Option<u32>, AconfigStorageError>> = LazyLock::new(|| unsafe {
|
||||||
static ref PACKAGE_OFFSET: Result<Option<u32>, AconfigStorageError> = unsafe {
|
get_mapped_storage_file("system", StorageFileType::PackageMap)
|
||||||
get_mapped_storage_file("system", StorageFileType::PackageMap)
|
.and_then(|package_map| get_package_read_context(&package_map, "com.android.aconfig.test"))
|
||||||
.and_then(|package_map| get_package_read_context(&package_map, "com.android.aconfig.test"))
|
.map(|context| context.map(|c| c.boolean_start_index))
|
||||||
.map(|context| context.map(|c| c.boolean_start_index))
|
});
|
||||||
};
|
|
||||||
|
|
||||||
static ref FLAG_VAL_MAP: Result<Mmap, AconfigStorageError> = unsafe {
|
static FLAG_VAL_MAP: LazyLock<Result<Mmap, AconfigStorageError>> = LazyLock::new(|| unsafe {
|
||||||
get_mapped_storage_file("system", StorageFileType::FlagVal)
|
get_mapped_storage_file("system", StorageFileType::FlagVal)
|
||||||
};
|
});
|
||||||
}
|
|
||||||
|
|
||||||
/// flag value cache for disabled_rw
|
/// flag value cache for disabled_rw
|
||||||
lazy_static::lazy_static! {
|
static CACHED_disabled_rw: LazyLock<bool> = LazyLock::new(|| {
|
||||||
static ref CACHED_disabled_rw: bool = {
|
let result = flags_rust::GetServerConfigurableFlag(
|
||||||
let result = flags_rust::GetServerConfigurableFlag(
|
"aconfig_flags.aconfig_test",
|
||||||
"aconfig_flags.aconfig_test",
|
"com.android.aconfig.test.disabled_rw",
|
||||||
"com.android.aconfig.test.disabled_rw",
|
"false") == "true";
|
||||||
"false") == "true";
|
|
||||||
|
|
||||||
let use_new_storage_value = flags_rust::GetServerConfigurableFlag(
|
let use_new_storage_value = flags_rust::GetServerConfigurableFlag(
|
||||||
"aconfig_flags.core_experiments_team_internal",
|
"aconfig_flags.core_experiments_team_internal",
|
||||||
"com.android.providers.settings.use_new_storage_value",
|
"com.android.providers.settings.use_new_storage_value",
|
||||||
"false") == "true";
|
"false") == "true";
|
||||||
|
|
||||||
if Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
|
if Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
|
||||||
// This will be called multiple times. Subsequent calls after the first are noops.
|
// This will be called multiple times. Subsequent calls after the first are noops.
|
||||||
logger::init(
|
logger::init(
|
||||||
logger::Config::default()
|
logger::Config::default()
|
||||||
.with_tag_on_device(MIGRATION_LOG_TAG)
|
.with_tag_on_device(MIGRATION_LOG_TAG)
|
||||||
.with_max_level(LevelFilter::Info));
|
.with_max_level(LevelFilter::Info));
|
||||||
|
|
||||||
let aconfig_storage_result = FLAG_VAL_MAP
|
let aconfig_storage_result = FLAG_VAL_MAP
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_err(|err| format!("failed to get flag val map: {err}"))
|
.map_err(|err| format!("failed to get flag val map: {err}"))
|
||||||
.and_then(|flag_val_map| {
|
.and_then(|flag_val_map| {
|
||||||
PACKAGE_OFFSET
|
PACKAGE_OFFSET
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_err(|err| format!("failed to get package read offset: {err}"))
|
.map_err(|err| format!("failed to get package read offset: {err}"))
|
||||||
.and_then(|package_offset| {
|
.and_then(|package_offset| {
|
||||||
match package_offset {
|
match package_offset {
|
||||||
Some(offset) => {
|
Some(offset) => {
|
||||||
get_boolean_flag_value(&flag_val_map, offset + 1)
|
get_boolean_flag_value(&flag_val_map, offset + 1)
|
||||||
.map_err(|err| format!("failed to get flag: {err}"))
|
.map_err(|err| format!("failed to get flag: {err}"))
|
||||||
},
|
},
|
||||||
None => Err("no context found for package 'com.android.aconfig.test'".to_string())
|
None => Err("no context found for package 'com.android.aconfig.test'".to_string())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
match aconfig_storage_result {
|
match aconfig_storage_result {
|
||||||
Ok(storage_result) if storage_result == result => {
|
Ok(storage_result) if storage_result == result => {
|
||||||
if use_new_storage_value {
|
if use_new_storage_value {
|
||||||
return storage_result;
|
return storage_result;
|
||||||
} else {
|
} else {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ok(storage_result) => {
|
Ok(storage_result) => {
|
||||||
log!(Level::Error, "AconfigTestMission1: error: mismatch for flag 'disabled_rw'. Legacy storage was {result}, new storage was {storage_result}");
|
log!(Level::Error, "AconfigTestMission1: error: mismatch for flag 'disabled_rw'. Legacy storage was {result}, new storage was {storage_result}");
|
||||||
if use_new_storage_value {
|
if use_new_storage_value {
|
||||||
return storage_result;
|
return storage_result;
|
||||||
} else {
|
} else {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log!(Level::Error, "AconfigTestMission1: error: {err}");
|
log!(Level::Error, "AconfigTestMission1: error: {err}");
|
||||||
if use_new_storage_value {
|
if use_new_storage_value {
|
||||||
panic!("failed to read flag value: {err}");
|
panic!("failed to read flag value: {err}");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
};
|
});
|
||||||
}
|
|
||||||
|
|
||||||
/// flag value cache for disabled_rw_exported
|
/// flag value cache for disabled_rw_exported
|
||||||
lazy_static::lazy_static! {
|
static CACHED_disabled_rw_exported: LazyLock<bool> = LazyLock::new(|| {
|
||||||
static ref CACHED_disabled_rw_exported: bool = {
|
let result = flags_rust::GetServerConfigurableFlag(
|
||||||
let result = flags_rust::GetServerConfigurableFlag(
|
"aconfig_flags.aconfig_test",
|
||||||
"aconfig_flags.aconfig_test",
|
"com.android.aconfig.test.disabled_rw_exported",
|
||||||
"com.android.aconfig.test.disabled_rw_exported",
|
"false") == "true";
|
||||||
"false") == "true";
|
|
||||||
|
|
||||||
let use_new_storage_value = flags_rust::GetServerConfigurableFlag(
|
let use_new_storage_value = flags_rust::GetServerConfigurableFlag(
|
||||||
"aconfig_flags.core_experiments_team_internal",
|
"aconfig_flags.core_experiments_team_internal",
|
||||||
"com.android.providers.settings.use_new_storage_value",
|
"com.android.providers.settings.use_new_storage_value",
|
||||||
"false") == "true";
|
"false") == "true";
|
||||||
|
|
||||||
if Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
|
if Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
|
||||||
// This will be called multiple times. Subsequent calls after the first are noops.
|
// This will be called multiple times. Subsequent calls after the first are noops.
|
||||||
logger::init(
|
logger::init(
|
||||||
logger::Config::default()
|
logger::Config::default()
|
||||||
.with_tag_on_device(MIGRATION_LOG_TAG)
|
.with_tag_on_device(MIGRATION_LOG_TAG)
|
||||||
.with_max_level(LevelFilter::Info));
|
.with_max_level(LevelFilter::Info));
|
||||||
|
|
||||||
let aconfig_storage_result = FLAG_VAL_MAP
|
let aconfig_storage_result = FLAG_VAL_MAP
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_err(|err| format!("failed to get flag val map: {err}"))
|
.map_err(|err| format!("failed to get flag val map: {err}"))
|
||||||
.and_then(|flag_val_map| {
|
.and_then(|flag_val_map| {
|
||||||
PACKAGE_OFFSET
|
PACKAGE_OFFSET
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_err(|err| format!("failed to get package read offset: {err}"))
|
.map_err(|err| format!("failed to get package read offset: {err}"))
|
||||||
.and_then(|package_offset| {
|
.and_then(|package_offset| {
|
||||||
match package_offset {
|
match package_offset {
|
||||||
Some(offset) => {
|
Some(offset) => {
|
||||||
get_boolean_flag_value(&flag_val_map, offset + 2)
|
get_boolean_flag_value(&flag_val_map, offset + 2)
|
||||||
.map_err(|err| format!("failed to get flag: {err}"))
|
.map_err(|err| format!("failed to get flag: {err}"))
|
||||||
},
|
},
|
||||||
None => Err("no context found for package 'com.android.aconfig.test'".to_string())
|
None => Err("no context found for package 'com.android.aconfig.test'".to_string())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
match aconfig_storage_result {
|
match aconfig_storage_result {
|
||||||
Ok(storage_result) if storage_result == result => {
|
Ok(storage_result) if storage_result == result => {
|
||||||
if use_new_storage_value {
|
if use_new_storage_value {
|
||||||
return storage_result;
|
return storage_result;
|
||||||
} else {
|
} else {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ok(storage_result) => {
|
Ok(storage_result) => {
|
||||||
log!(Level::Error, "AconfigTestMission1: error: mismatch for flag 'disabled_rw_exported'. Legacy storage was {result}, new storage was {storage_result}");
|
log!(Level::Error, "AconfigTestMission1: error: mismatch for flag 'disabled_rw_exported'. Legacy storage was {result}, new storage was {storage_result}");
|
||||||
if use_new_storage_value {
|
if use_new_storage_value {
|
||||||
return storage_result;
|
return storage_result;
|
||||||
} else {
|
} else {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log!(Level::Error, "AconfigTestMission1: error: {err}");
|
log!(Level::Error, "AconfigTestMission1: error: {err}");
|
||||||
if use_new_storage_value {
|
if use_new_storage_value {
|
||||||
panic!("failed to read flag value: {err}");
|
panic!("failed to read flag value: {err}");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
};
|
});
|
||||||
}
|
|
||||||
|
|
||||||
/// flag value cache for disabled_rw_in_other_namespace
|
/// flag value cache for disabled_rw_in_other_namespace
|
||||||
lazy_static::lazy_static! {
|
static CACHED_disabled_rw_in_other_namespace: LazyLock<bool> = LazyLock::new(|| {
|
||||||
static ref CACHED_disabled_rw_in_other_namespace: bool = {
|
let result = flags_rust::GetServerConfigurableFlag(
|
||||||
let result = flags_rust::GetServerConfigurableFlag(
|
"aconfig_flags.other_namespace",
|
||||||
"aconfig_flags.other_namespace",
|
"com.android.aconfig.test.disabled_rw_in_other_namespace",
|
||||||
"com.android.aconfig.test.disabled_rw_in_other_namespace",
|
"false") == "true";
|
||||||
"false") == "true";
|
|
||||||
|
|
||||||
let use_new_storage_value = flags_rust::GetServerConfigurableFlag(
|
let use_new_storage_value = flags_rust::GetServerConfigurableFlag(
|
||||||
"aconfig_flags.core_experiments_team_internal",
|
"aconfig_flags.core_experiments_team_internal",
|
||||||
"com.android.providers.settings.use_new_storage_value",
|
"com.android.providers.settings.use_new_storage_value",
|
||||||
"false") == "true";
|
"false") == "true";
|
||||||
|
|
||||||
if Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
|
if Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
|
||||||
// This will be called multiple times. Subsequent calls after the first are noops.
|
// This will be called multiple times. Subsequent calls after the first are noops.
|
||||||
logger::init(
|
logger::init(
|
||||||
logger::Config::default()
|
logger::Config::default()
|
||||||
.with_tag_on_device(MIGRATION_LOG_TAG)
|
.with_tag_on_device(MIGRATION_LOG_TAG)
|
||||||
.with_max_level(LevelFilter::Info));
|
.with_max_level(LevelFilter::Info));
|
||||||
|
|
||||||
let aconfig_storage_result = FLAG_VAL_MAP
|
let aconfig_storage_result = FLAG_VAL_MAP
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_err(|err| format!("failed to get flag val map: {err}"))
|
.map_err(|err| format!("failed to get flag val map: {err}"))
|
||||||
.and_then(|flag_val_map| {
|
.and_then(|flag_val_map| {
|
||||||
PACKAGE_OFFSET
|
PACKAGE_OFFSET
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_err(|err| format!("failed to get package read offset: {err}"))
|
.map_err(|err| format!("failed to get package read offset: {err}"))
|
||||||
.and_then(|package_offset| {
|
.and_then(|package_offset| {
|
||||||
match package_offset {
|
match package_offset {
|
||||||
Some(offset) => {
|
Some(offset) => {
|
||||||
get_boolean_flag_value(&flag_val_map, offset + 3)
|
get_boolean_flag_value(&flag_val_map, offset + 3)
|
||||||
.map_err(|err| format!("failed to get flag: {err}"))
|
.map_err(|err| format!("failed to get flag: {err}"))
|
||||||
},
|
},
|
||||||
None => Err("no context found for package 'com.android.aconfig.test'".to_string())
|
None => Err("no context found for package 'com.android.aconfig.test'".to_string())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
match aconfig_storage_result {
|
match aconfig_storage_result {
|
||||||
Ok(storage_result) if storage_result == result => {
|
Ok(storage_result) if storage_result == result => {
|
||||||
if use_new_storage_value {
|
if use_new_storage_value {
|
||||||
return storage_result;
|
return storage_result;
|
||||||
} else {
|
} else {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ok(storage_result) => {
|
Ok(storage_result) => {
|
||||||
log!(Level::Error, "AconfigTestMission1: error: mismatch for flag 'disabled_rw_in_other_namespace'. Legacy storage was {result}, new storage was {storage_result}");
|
log!(Level::Error, "AconfigTestMission1: error: mismatch for flag 'disabled_rw_in_other_namespace'. Legacy storage was {result}, new storage was {storage_result}");
|
||||||
if use_new_storage_value {
|
if use_new_storage_value {
|
||||||
return storage_result;
|
return storage_result;
|
||||||
} else {
|
} else {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log!(Level::Error, "AconfigTestMission1: error: {err}");
|
log!(Level::Error, "AconfigTestMission1: error: {err}");
|
||||||
if use_new_storage_value {
|
if use_new_storage_value {
|
||||||
panic!("failed to read flag value: {err}");
|
panic!("failed to read flag value: {err}");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
};
|
});
|
||||||
}
|
|
||||||
|
|
||||||
/// flag value cache for enabled_rw
|
|
||||||
lazy_static::lazy_static! {
|
|
||||||
static ref CACHED_enabled_rw: bool = {
|
|
||||||
let result = flags_rust::GetServerConfigurableFlag(
|
|
||||||
"aconfig_flags.aconfig_test",
|
|
||||||
"com.android.aconfig.test.enabled_rw",
|
|
||||||
"true") == "true";
|
|
||||||
|
|
||||||
let use_new_storage_value = flags_rust::GetServerConfigurableFlag(
|
/// flag value cache for enabled_rw
|
||||||
"aconfig_flags.core_experiments_team_internal",
|
static CACHED_enabled_rw: LazyLock<bool> = LazyLock::new(|| {
|
||||||
"com.android.providers.settings.use_new_storage_value",
|
let result = flags_rust::GetServerConfigurableFlag(
|
||||||
"false") == "true";
|
"aconfig_flags.aconfig_test",
|
||||||
|
"com.android.aconfig.test.enabled_rw",
|
||||||
|
"true") == "true";
|
||||||
|
|
||||||
if Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
|
let use_new_storage_value = flags_rust::GetServerConfigurableFlag(
|
||||||
// This will be called multiple times. Subsequent calls after the first are noops.
|
"aconfig_flags.core_experiments_team_internal",
|
||||||
logger::init(
|
"com.android.providers.settings.use_new_storage_value",
|
||||||
logger::Config::default()
|
"false") == "true";
|
||||||
.with_tag_on_device(MIGRATION_LOG_TAG)
|
|
||||||
.with_max_level(LevelFilter::Info));
|
|
||||||
|
|
||||||
let aconfig_storage_result = FLAG_VAL_MAP
|
if Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() {
|
||||||
.as_ref()
|
// This will be called multiple times. Subsequent calls after the first are noops.
|
||||||
.map_err(|err| format!("failed to get flag val map: {err}"))
|
logger::init(
|
||||||
.and_then(|flag_val_map| {
|
logger::Config::default()
|
||||||
PACKAGE_OFFSET
|
.with_tag_on_device(MIGRATION_LOG_TAG)
|
||||||
.as_ref()
|
.with_max_level(LevelFilter::Info));
|
||||||
.map_err(|err| format!("failed to get package read offset: {err}"))
|
|
||||||
.and_then(|package_offset| {
|
|
||||||
match package_offset {
|
|
||||||
Some(offset) => {
|
|
||||||
get_boolean_flag_value(&flag_val_map, offset + 8)
|
|
||||||
.map_err(|err| format!("failed to get flag: {err}"))
|
|
||||||
},
|
|
||||||
None => Err("no context found for package 'com.android.aconfig.test'".to_string())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
match aconfig_storage_result {
|
let aconfig_storage_result = FLAG_VAL_MAP
|
||||||
Ok(storage_result) if storage_result == result => {
|
.as_ref()
|
||||||
if use_new_storage_value {
|
.map_err(|err| format!("failed to get flag val map: {err}"))
|
||||||
return storage_result;
|
.and_then(|flag_val_map| {
|
||||||
} else {
|
PACKAGE_OFFSET
|
||||||
return result;
|
.as_ref()
|
||||||
}
|
.map_err(|err| format!("failed to get package read offset: {err}"))
|
||||||
},
|
.and_then(|package_offset| {
|
||||||
Ok(storage_result) => {
|
match package_offset {
|
||||||
log!(Level::Error, "AconfigTestMission1: error: mismatch for flag 'enabled_rw'. Legacy storage was {result}, new storage was {storage_result}");
|
Some(offset) => {
|
||||||
if use_new_storage_value {
|
get_boolean_flag_value(&flag_val_map, offset + 8)
|
||||||
return storage_result;
|
.map_err(|err| format!("failed to get flag: {err}"))
|
||||||
} else {
|
},
|
||||||
return result;
|
None => Err("no context found for package 'com.android.aconfig.test'".to_string())
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
Err(err) => {
|
});
|
||||||
log!(Level::Error, "AconfigTestMission1: error: {err}");
|
|
||||||
if use_new_storage_value {
|
match aconfig_storage_result {
|
||||||
panic!("failed to read flag value: {err}");
|
Ok(storage_result) if storage_result == result => {
|
||||||
}
|
if use_new_storage_value {
|
||||||
|
return storage_result;
|
||||||
|
} else {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Ok(storage_result) => {
|
||||||
|
log!(Level::Error, "AconfigTestMission1: error: mismatch for flag 'enabled_rw'. Legacy storage was {result}, new storage was {storage_result}");
|
||||||
|
if use_new_storage_value {
|
||||||
|
return storage_result;
|
||||||
|
} else {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
log!(Level::Error, "AconfigTestMission1: error: {err}");
|
||||||
|
if use_new_storage_value {
|
||||||
|
panic!("failed to read flag value: {err}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
};
|
});
|
||||||
}
|
|
||||||
|
|
||||||
impl FlagProvider {
|
impl FlagProvider {
|
||||||
|
|
||||||
@@ -1215,6 +1200,7 @@ pub fn reset_flags() {
|
|||||||
use aconfig_storage_read_api::{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context};
|
use aconfig_storage_read_api::{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::sync::LazyLock;
|
||||||
use log::{log, LevelFilter, Level};
|
use log::{log, LevelFilter, Level};
|
||||||
|
|
||||||
static STORAGE_MIGRATION_MARKER_FILE: &str =
|
static STORAGE_MIGRATION_MARKER_FILE: &str =
|
||||||
@@ -1225,28 +1211,22 @@ static MIGRATION_LOG_TAG: &str = "AconfigTestMission1";
|
|||||||
pub struct FlagProvider;
|
pub struct FlagProvider;
|
||||||
|
|
||||||
/// flag value cache for disabled_rw_exported
|
/// flag value cache for disabled_rw_exported
|
||||||
lazy_static::lazy_static! {
|
static CACHED_disabled_rw_exported: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag(
|
||||||
static ref CACHED_disabled_rw_exported: bool = flags_rust::GetServerConfigurableFlag(
|
|
||||||
"aconfig_flags.aconfig_test",
|
"aconfig_flags.aconfig_test",
|
||||||
"com.android.aconfig.test.disabled_rw_exported",
|
"com.android.aconfig.test.disabled_rw_exported",
|
||||||
"false") == "true";
|
"false") == "true");
|
||||||
}
|
|
||||||
|
|
||||||
/// flag value cache for enabled_fixed_ro_exported
|
/// flag value cache for enabled_fixed_ro_exported
|
||||||
lazy_static::lazy_static! {
|
static CACHED_enabled_fixed_ro_exported: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag(
|
||||||
static ref CACHED_enabled_fixed_ro_exported: bool = flags_rust::GetServerConfigurableFlag(
|
|
||||||
"aconfig_flags.aconfig_test",
|
"aconfig_flags.aconfig_test",
|
||||||
"com.android.aconfig.test.enabled_fixed_ro_exported",
|
"com.android.aconfig.test.enabled_fixed_ro_exported",
|
||||||
"false") == "true";
|
"false") == "true");
|
||||||
}
|
|
||||||
|
|
||||||
/// flag value cache for enabled_ro_exported
|
/// flag value cache for enabled_ro_exported
|
||||||
lazy_static::lazy_static! {
|
static CACHED_enabled_ro_exported: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag(
|
||||||
static ref CACHED_enabled_ro_exported: bool = flags_rust::GetServerConfigurableFlag(
|
|
||||||
"aconfig_flags.aconfig_test",
|
"aconfig_flags.aconfig_test",
|
||||||
"com.android.aconfig.test.enabled_ro_exported",
|
"com.android.aconfig.test.enabled_ro_exported",
|
||||||
"false") == "true";
|
"false") == "true");
|
||||||
}
|
|
||||||
|
|
||||||
impl FlagProvider {
|
impl FlagProvider {
|
||||||
/// query flag disabled_rw_exported
|
/// query flag disabled_rw_exported
|
||||||
@@ -1292,6 +1272,7 @@ pub fn enabled_ro_exported() -> bool {
|
|||||||
use aconfig_storage_read_api::{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context};
|
use aconfig_storage_read_api::{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::sync::LazyLock;
|
||||||
use log::{log, LevelFilter, Level};
|
use log::{log, LevelFilter, Level};
|
||||||
|
|
||||||
static STORAGE_MIGRATION_MARKER_FILE: &str =
|
static STORAGE_MIGRATION_MARKER_FILE: &str =
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
use aconfig_storage_read_api::\{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context};
|
use aconfig_storage_read_api::\{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::sync::LazyLock;
|
||||||
use log::\{log, LevelFilter, Level};
|
use log::\{log, LevelFilter, Level};
|
||||||
|
|
||||||
static STORAGE_MIGRATION_MARKER_FILE: &str =
|
static STORAGE_MIGRATION_MARKER_FILE: &str =
|
||||||
@@ -13,95 +14,89 @@ pub struct FlagProvider;
|
|||||||
|
|
||||||
{{ if has_readwrite- }}
|
{{ if has_readwrite- }}
|
||||||
{{ if allow_instrumentation }}
|
{{ if allow_instrumentation }}
|
||||||
lazy_static::lazy_static! \{
|
static PACKAGE_OFFSET: LazyLock<Result<Option<u32>, AconfigStorageError>> = LazyLock::new(|| unsafe \{
|
||||||
static ref PACKAGE_OFFSET: Result<Option<u32>, AconfigStorageError> = unsafe \{
|
get_mapped_storage_file("{container}", StorageFileType::PackageMap)
|
||||||
get_mapped_storage_file("{container}", StorageFileType::PackageMap)
|
.and_then(|package_map| get_package_read_context(&package_map, "{package}"))
|
||||||
.and_then(|package_map| get_package_read_context(&package_map, "{package}"))
|
.map(|context| context.map(|c| c.boolean_start_index))
|
||||||
.map(|context| context.map(|c| c.boolean_start_index))
|
});
|
||||||
};
|
|
||||||
|
|
||||||
static ref FLAG_VAL_MAP: Result<Mmap, AconfigStorageError> = unsafe \{
|
static FLAG_VAL_MAP: LazyLock<Result<Mmap, AconfigStorageError>> = LazyLock::new(|| unsafe \{
|
||||||
get_mapped_storage_file("{container}", StorageFileType::FlagVal)
|
get_mapped_storage_file("{container}", StorageFileType::FlagVal)
|
||||||
};
|
});
|
||||||
}
|
|
||||||
{{ -endif }}
|
{{ -endif }}
|
||||||
{{ -for flag in template_flags }}
|
{{ -for flag in template_flags }}
|
||||||
|
|
||||||
{{ -if flag.readwrite }}
|
{{ -if flag.readwrite }}
|
||||||
/// flag value cache for {flag.name}
|
/// flag value cache for {flag.name}
|
||||||
{{ if allow_instrumentation }}
|
{{ if allow_instrumentation }}
|
||||||
lazy_static::lazy_static! \{
|
static CACHED_{flag.name}: LazyLock<bool> = LazyLock::new(|| \{
|
||||||
static ref CACHED_{flag.name}: bool = \{
|
let result = flags_rust::GetServerConfigurableFlag(
|
||||||
let result = flags_rust::GetServerConfigurableFlag(
|
|
||||||
"aconfig_flags.{flag.device_config_namespace}",
|
|
||||||
"{flag.device_config_flag}",
|
|
||||||
"{flag.default_value}") == "true";
|
|
||||||
|
|
||||||
let use_new_storage_value = flags_rust::GetServerConfigurableFlag(
|
|
||||||
"aconfig_flags.core_experiments_team_internal",
|
|
||||||
"com.android.providers.settings.use_new_storage_value",
|
|
||||||
"false") == "true";
|
|
||||||
|
|
||||||
if Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() \{
|
|
||||||
// This will be called multiple times. Subsequent calls after the first are noops.
|
|
||||||
logger::init(
|
|
||||||
logger::Config::default()
|
|
||||||
.with_tag_on_device(MIGRATION_LOG_TAG)
|
|
||||||
.with_max_level(LevelFilter::Info));
|
|
||||||
|
|
||||||
let aconfig_storage_result = FLAG_VAL_MAP
|
|
||||||
.as_ref()
|
|
||||||
.map_err(|err| format!("failed to get flag val map: \{err}"))
|
|
||||||
.and_then(|flag_val_map| \{
|
|
||||||
PACKAGE_OFFSET
|
|
||||||
.as_ref()
|
|
||||||
.map_err(|err| format!("failed to get package read offset: \{err}"))
|
|
||||||
.and_then(|package_offset| \{
|
|
||||||
match package_offset \{
|
|
||||||
Some(offset) => \{
|
|
||||||
get_boolean_flag_value(&flag_val_map, offset + {flag.flag_offset})
|
|
||||||
.map_err(|err| format!("failed to get flag: \{err}"))
|
|
||||||
},
|
|
||||||
None => Err("no context found for package '{package}'".to_string())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
match aconfig_storage_result \{
|
|
||||||
Ok(storage_result) if storage_result == result => \{
|
|
||||||
if use_new_storage_value \{
|
|
||||||
return storage_result;
|
|
||||||
} else \{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Ok(storage_result) => \{
|
|
||||||
log!(Level::Error, "AconfigTestMission1: error: mismatch for flag '{flag.name}'. Legacy storage was \{result}, new storage was \{storage_result}");
|
|
||||||
if use_new_storage_value \{
|
|
||||||
return storage_result;
|
|
||||||
} else \{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(err) => \{
|
|
||||||
log!(Level::Error, "AconfigTestMission1: error: \{err}");
|
|
||||||
if use_new_storage_value \{
|
|
||||||
panic!("failed to read flag value: \{err}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result
|
|
||||||
};
|
|
||||||
}
|
|
||||||
{{ else }}
|
|
||||||
lazy_static::lazy_static! \{
|
|
||||||
static ref CACHED_{flag.name}: bool = flags_rust::GetServerConfigurableFlag(
|
|
||||||
"aconfig_flags.{flag.device_config_namespace}",
|
"aconfig_flags.{flag.device_config_namespace}",
|
||||||
"{flag.device_config_flag}",
|
"{flag.device_config_flag}",
|
||||||
"{flag.default_value}") == "true";
|
"{flag.default_value}") == "true";
|
||||||
}
|
|
||||||
|
let use_new_storage_value = flags_rust::GetServerConfigurableFlag(
|
||||||
|
"aconfig_flags.core_experiments_team_internal",
|
||||||
|
"com.android.providers.settings.use_new_storage_value",
|
||||||
|
"false") == "true";
|
||||||
|
|
||||||
|
if Path::new(STORAGE_MIGRATION_MARKER_FILE).exists() \{
|
||||||
|
// This will be called multiple times. Subsequent calls after the first are noops.
|
||||||
|
logger::init(
|
||||||
|
logger::Config::default()
|
||||||
|
.with_tag_on_device(MIGRATION_LOG_TAG)
|
||||||
|
.with_max_level(LevelFilter::Info));
|
||||||
|
|
||||||
|
let aconfig_storage_result = FLAG_VAL_MAP
|
||||||
|
.as_ref()
|
||||||
|
.map_err(|err| format!("failed to get flag val map: \{err}"))
|
||||||
|
.and_then(|flag_val_map| \{
|
||||||
|
PACKAGE_OFFSET
|
||||||
|
.as_ref()
|
||||||
|
.map_err(|err| format!("failed to get package read offset: \{err}"))
|
||||||
|
.and_then(|package_offset| \{
|
||||||
|
match package_offset \{
|
||||||
|
Some(offset) => \{
|
||||||
|
get_boolean_flag_value(&flag_val_map, offset + {flag.flag_offset})
|
||||||
|
.map_err(|err| format!("failed to get flag: \{err}"))
|
||||||
|
},
|
||||||
|
None => Err("no context found for package '{package}'".to_string())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
match aconfig_storage_result \{
|
||||||
|
Ok(storage_result) if storage_result == result => \{
|
||||||
|
if use_new_storage_value \{
|
||||||
|
return storage_result;
|
||||||
|
} else \{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Ok(storage_result) => \{
|
||||||
|
log!(Level::Error, "AconfigTestMission1: error: mismatch for flag '{flag.name}'. Legacy storage was \{result}, new storage was \{storage_result}");
|
||||||
|
if use_new_storage_value \{
|
||||||
|
return storage_result;
|
||||||
|
} else \{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(err) => \{
|
||||||
|
log!(Level::Error, "AconfigTestMission1: error: \{err}");
|
||||||
|
if use_new_storage_value \{
|
||||||
|
panic!("failed to read flag value: \{err}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
});
|
||||||
|
{{ else }}
|
||||||
|
static CACHED_{flag.name}: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag(
|
||||||
|
"aconfig_flags.{flag.device_config_namespace}",
|
||||||
|
"{flag.device_config_flag}",
|
||||||
|
"{flag.default_value}") == "true");
|
||||||
{{ endif }}
|
{{ endif }}
|
||||||
{{ -endif }}
|
{{ -endif }}
|
||||||
{{ -endfor }}
|
{{ -endfor }}
|
||||||
|
Reference in New Issue
Block a user