aconfig: update flag info query api
Currently flag info query api is called get_boolean_flag_attribute, in
this change, we switched it over to a flag value type generic
implementation get_flag_attribute. So in the future we want to add more flag value types, this api can stay the same.
Bug: b/312444587
Test: atest -c
Change-Id: I2b272f3fa3cb1d0edc8b77a44bf37752ffe95925
diff --git a/tools/aconfig/aconfig_storage_read_api/aconfig_storage_read_api.cpp b/tools/aconfig/aconfig_storage_read_api/aconfig_storage_read_api.cpp
index 39f1840..ff2f38e 100644
--- a/tools/aconfig/aconfig_storage_read_api/aconfig_storage_read_api.cpp
+++ b/tools/aconfig/aconfig_storage_read_api/aconfig_storage_read_api.cpp
@@ -106,6 +106,19 @@
} // namespace private internal api
+/// Map from StoredFlagType to FlagValueType
+android::base::Result<FlagValueType> map_to_flag_value_type(
+ StoredFlagType stored_type) {
+ switch (stored_type) {
+ case StoredFlagType::ReadWriteBoolean:
+ case StoredFlagType::ReadOnlyBoolean:
+ case StoredFlagType::FixedReadOnlyBoolean:
+ return FlagValueType::Boolean;
+ default:
+ return Error() << "Unsupported stored flag type";
+ }
+}
+
/// Get mapped storage file
Result<MappedStorageFile> get_mapped_file(
std::string const& container,
@@ -178,12 +191,14 @@
}
/// Get boolean flag attribute
-Result<uint8_t> get_boolean_flag_attribute(
+Result<uint8_t> get_flag_attribute(
MappedStorageFile const& file,
+ FlagValueType value_type,
uint32_t index) {
auto content = rust::Slice<const uint8_t>(
static_cast<uint8_t*>(file.file_ptr), file.file_size);
- auto info_cxx = get_boolean_flag_attribute_cxx(content, index);
+ auto info_cxx = get_flag_attribute_cxx(
+ content, static_cast<uint16_t>(value_type), index);
if (info_cxx.query_success) {
return info_cxx.flag_attribute;
} else {
diff --git a/tools/aconfig/aconfig_storage_read_api/include/aconfig_storage/aconfig_storage_read_api.hpp b/tools/aconfig/aconfig_storage_read_api/include/aconfig_storage/aconfig_storage_read_api.hpp
index 4555207..7c63ef2 100644
--- a/tools/aconfig/aconfig_storage_read_api/include/aconfig_storage/aconfig_storage_read_api.hpp
+++ b/tools/aconfig/aconfig_storage_read_api/include/aconfig_storage/aconfig_storage_read_api.hpp
@@ -37,7 +37,6 @@
HasOverride = 1<<2,
};
-
/// Mapped storage file
struct MappedStorageFile {
void* file_ptr;
@@ -68,6 +67,12 @@
} // namespace private_internal_api
+/// Map from StoredFlagType to FlagValueType
+/// \input stored_type: stored flag type in the storage file
+/// \returns the flag value type enum
+android::base::Result<FlagValueType> map_to_flag_value_type(
+ StoredFlagType stored_type);
+
/// Get mapped storage file
/// \input container: stoarge container name
/// \input file_type: storage file type enum
@@ -110,9 +115,11 @@
/// Get boolean flag attribute
/// \input file: mapped storage file
+/// \input value_type: flag value type
/// \input index: the boolean flag index in the file
/// \returns the boolean flag attribute
-android::base::Result<uint8_t> get_boolean_flag_attribute(
+android::base::Result<uint8_t> get_flag_attribute(
MappedStorageFile const& file,
+ FlagValueType value_type,
uint32_t index);
} // namespace aconfig_storage
diff --git a/tools/aconfig/aconfig_storage_read_api/src/flag_info_query.rs b/tools/aconfig/aconfig_storage_read_api/src/flag_info_query.rs
index 807da97..e593418 100644
--- a/tools/aconfig/aconfig_storage_read_api/src/flag_info_query.rs
+++ b/tools/aconfig/aconfig_storage_read_api/src/flag_info_query.rs
@@ -17,11 +17,15 @@
//! flag value query module defines the flag value file read from mapped bytes
use crate::{AconfigStorageError, FILE_VERSION};
-use aconfig_storage_file::{flag_info::FlagInfoHeader, read_u8_from_bytes};
+use aconfig_storage_file::{flag_info::FlagInfoHeader, read_u8_from_bytes, FlagValueType};
use anyhow::anyhow;
/// Get flag attribute bitfield
-pub fn find_boolean_flag_attribute(buf: &[u8], flag_index: u32) -> Result<u8, AconfigStorageError> {
+pub fn find_flag_attribute(
+ buf: &[u8],
+ flag_type: FlagValueType,
+ flag_index: u32,
+) -> Result<u8, AconfigStorageError> {
let interpreted_header = FlagInfoHeader::from_bytes(buf)?;
if interpreted_header.version > crate::FILE_VERSION {
return Err(AconfigStorageError::HigherStorageFileVersion(anyhow!(
@@ -31,8 +35,11 @@
)));
}
- // Find the byte offset to the flag info, each flag info now takes one byte
- let mut head = (interpreted_header.boolean_flag_offset + flag_index) as usize;
+ // get byte offset to the flag info
+ let mut head = match flag_type {
+ FlagValueType::Boolean => (interpreted_header.boolean_flag_offset + flag_index) as usize,
+ };
+
if head >= interpreted_header.file_size as usize {
return Err(AconfigStorageError::InvalidStorageFileOffset(anyhow!(
"Flag info offset goes beyond the end of the file."
@@ -53,7 +60,8 @@
fn test_is_flag_sticky() {
let flag_info_list = create_test_flag_info_list().into_bytes();
for offset in 0..8 {
- let attribute = find_boolean_flag_attribute(&flag_info_list[..], offset).unwrap();
+ let attribute =
+ find_flag_attribute(&flag_info_list[..], FlagValueType::Boolean, offset).unwrap();
assert_eq!((attribute & FlagInfoBit::IsSticky as u8) != 0u8, false);
}
}
@@ -64,7 +72,8 @@
let flag_info_list = create_test_flag_info_list().into_bytes();
let baseline: Vec<bool> = vec![true, false, true, false, false, false, false, false];
for offset in 0..8 {
- let attribute = find_boolean_flag_attribute(&flag_info_list[..], offset).unwrap();
+ let attribute =
+ find_flag_attribute(&flag_info_list[..], FlagValueType::Boolean, offset).unwrap();
assert_eq!(
(attribute & FlagInfoBit::IsReadWrite as u8) != 0u8,
baseline[offset as usize]
@@ -77,7 +86,8 @@
fn test_flag_has_override() {
let flag_info_list = create_test_flag_info_list().into_bytes();
for offset in 0..8 {
- let attribute = find_boolean_flag_attribute(&flag_info_list[..], offset).unwrap();
+ let attribute =
+ find_flag_attribute(&flag_info_list[..], FlagValueType::Boolean, offset).unwrap();
assert_eq!((attribute & FlagInfoBit::HasOverride as u8) != 0u8, false);
}
}
@@ -86,7 +96,8 @@
// this test point locks down query beyond the end of boolean section
fn test_boolean_out_of_range() {
let flag_info_list = create_test_flag_info_list().into_bytes();
- let error = find_boolean_flag_attribute(&flag_info_list[..], 8).unwrap_err();
+ let error =
+ find_flag_attribute(&flag_info_list[..], FlagValueType::Boolean, 8).unwrap_err();
assert_eq!(
format!("{:?}", error),
"InvalidStorageFileOffset(Flag info offset goes beyond the end of the file.)"
@@ -99,7 +110,7 @@
let mut info_list = create_test_flag_info_list();
info_list.header.version = crate::FILE_VERSION + 1;
let flag_info = info_list.into_bytes();
- let error = find_boolean_flag_attribute(&flag_info[..], 4).unwrap_err();
+ let error = find_flag_attribute(&flag_info[..], FlagValueType::Boolean, 4).unwrap_err();
assert_eq!(
format!("{:?}", error),
format!(
diff --git a/tools/aconfig/aconfig_storage_read_api/src/lib.rs b/tools/aconfig/aconfig_storage_read_api/src/lib.rs
index aa0145f..bc09112 100644
--- a/tools/aconfig/aconfig_storage_read_api/src/lib.rs
+++ b/tools/aconfig/aconfig_storage_read_api/src/lib.rs
@@ -45,12 +45,12 @@
#[cfg(test)]
mod test_utils;
-pub use aconfig_storage_file::{AconfigStorageError, StorageFileType};
+pub use aconfig_storage_file::{AconfigStorageError, FlagValueType, StorageFileType};
pub use flag_table_query::FlagReadContext;
pub use package_table_query::PackageReadContext;
use aconfig_storage_file::{read_u32_from_bytes, FILE_VERSION};
-use flag_info_query::find_boolean_flag_attribute;
+use flag_info_query::find_flag_attribute;
use flag_table_query::find_flag_read_context;
use flag_value_query::find_boolean_flag_value;
use package_table_query::find_package_read_context;
@@ -149,16 +149,21 @@
read_u32_from_bytes(&buffer, &mut head)
}
-/// Get the boolean flag attribute.
+/// Get the flag attribute.
///
/// \input file: mapped flag info file
-/// \input index: boolean flag index
+/// \input flag_type: flag value type
+/// \input flag_index: flag index
///
/// \return
-/// If the provide offset is valid, it returns the boolean flag attribute bitfiled, otherwise it
+/// If the provide offset is valid, it returns the flag attribute bitfiled, otherwise it
/// returns the error message.
-pub fn get_boolean_flag_attribute(file: &Mmap, index: u32) -> Result<u8, AconfigStorageError> {
- find_boolean_flag_attribute(file, index)
+pub fn get_flag_attribute(
+ file: &Mmap,
+ flag_type: FlagValueType,
+ flag_index: u32,
+) -> Result<u8, AconfigStorageError> {
+ find_flag_attribute(file, flag_type, flag_index)
}
// *************************************** //
@@ -201,7 +206,7 @@
}
// Flag info query return for cc interlop
- pub struct BooleanFlagAttributeQueryCXX {
+ pub struct FlagAttributeQueryCXX {
pub query_success: bool,
pub error_message: String,
pub flag_attribute: u8,
@@ -224,10 +229,11 @@
pub fn get_boolean_flag_value_cxx(file: &[u8], offset: u32) -> BooleanFlagValueQueryCXX;
- pub fn get_boolean_flag_attribute_cxx(
+ pub fn get_flag_attribute_cxx(
file: &[u8],
- offset: u32,
- ) -> BooleanFlagAttributeQueryCXX;
+ flag_type: u16,
+ flag_index: u32,
+ ) -> FlagAttributeQueryCXX;
}
}
@@ -312,7 +318,7 @@
}
/// Implement the flag info interlop return type, create from actual flag info api return type
-impl ffi::BooleanFlagAttributeQueryCXX {
+impl ffi::FlagAttributeQueryCXX {
pub(crate) fn new(info_result: Result<u8, AconfigStorageError>) -> Self {
match info_result {
Ok(info) => {
@@ -365,12 +371,18 @@
ffi::BooleanFlagValueQueryCXX::new(find_boolean_flag_value(file, offset))
}
-/// Get boolean flag attribute cc interlop
-pub fn get_boolean_flag_attribute_cxx(
+/// Get flag attribute cc interlop
+pub fn get_flag_attribute_cxx(
file: &[u8],
- offset: u32,
-) -> ffi::BooleanFlagAttributeQueryCXX {
- ffi::BooleanFlagAttributeQueryCXX::new(find_boolean_flag_attribute(file, offset))
+ flag_type: u16,
+ flag_index: u32,
+) -> ffi::FlagAttributeQueryCXX {
+ match FlagValueType::try_from(flag_type) {
+ Ok(value_type) => {
+ ffi::FlagAttributeQueryCXX::new(find_flag_attribute(file, value_type, flag_index))
+ }
+ Err(errmsg) => ffi::FlagAttributeQueryCXX::new(Err(errmsg)),
+ }
}
/// Get storage version number cc interlop
@@ -494,7 +506,8 @@
unsafe { get_mapped_file(&pb_file_path, "mockup", StorageFileType::FlagInfo).unwrap() };
let is_rw: Vec<bool> = vec![true, false, true, false, false, false, false, false];
for (offset, expected_value) in is_rw.into_iter().enumerate() {
- let attribute = get_boolean_flag_attribute(&flag_info_file, offset as u32).unwrap();
+ let attribute =
+ get_flag_attribute(&flag_info_file, FlagValueType::Boolean, offset as u32).unwrap();
assert!((attribute & FlagInfoBit::IsSticky as u8) == 0u8);
assert_eq!((attribute & FlagInfoBit::IsReadWrite as u8) != 0u8, expected_value);
assert!((attribute & FlagInfoBit::HasOverride as u8) == 0u8);
diff --git a/tools/aconfig/aconfig_storage_read_api/tests/storage_read_api_test.cpp b/tools/aconfig/aconfig_storage_read_api/tests/storage_read_api_test.cpp
index 8ed3756..10f71a5 100644
--- a/tools/aconfig/aconfig_storage_read_api/tests/storage_read_api_test.cpp
+++ b/tools/aconfig/aconfig_storage_read_api/tests/storage_read_api_test.cpp
@@ -234,7 +234,7 @@
auto expected_value = std::vector<bool>{
true, false, true, false, false, false, false, false};
for (int index = 0; index < 8; ++index) {
- auto attribute = api::get_boolean_flag_attribute(*mapped_file, index);
+ auto attribute = api::get_flag_attribute(*mapped_file, api::FlagValueType::Boolean, index);
ASSERT_TRUE(attribute.ok());
ASSERT_EQ(*attribute & static_cast<uint8_t>(api::FlagInfoBit::IsSticky), 0);
ASSERT_EQ((*attribute & static_cast<uint8_t>(api::FlagInfoBit::IsReadWrite)) != 0,
@@ -249,7 +249,7 @@
storage_record_pb, "mockup", api::StorageFileType::flag_info);
ASSERT_TRUE(mapped_file.ok());
- auto attribute = api::get_boolean_flag_attribute(*mapped_file, 8);
+ auto attribute = api::get_flag_attribute(*mapped_file, api::FlagValueType::Boolean, 8);
ASSERT_FALSE(attribute.ok());
ASSERT_EQ(attribute.error().message(),
std::string("InvalidStorageFileOffset(Flag info offset goes beyond the end of the file.)"));
diff --git a/tools/aconfig/aconfig_storage_read_api/tests/storage_read_api_test.rs b/tools/aconfig/aconfig_storage_read_api/tests/storage_read_api_test.rs
index bddb396..212f734 100644
--- a/tools/aconfig/aconfig_storage_read_api/tests/storage_read_api_test.rs
+++ b/tools/aconfig/aconfig_storage_read_api/tests/storage_read_api_test.rs
@@ -1,9 +1,9 @@
#[cfg(not(feature = "cargo"))]
mod aconfig_storage_rust_test {
use aconfig_storage_file::protos::storage_record_pb::write_proto_to_temp_file;
- use aconfig_storage_file::{FlagInfoBit, StorageFileType, StoredFlagType};
+ use aconfig_storage_file::{FlagInfoBit, FlagValueType, StorageFileType, StoredFlagType};
use aconfig_storage_read_api::{
- get_boolean_flag_attribute, get_boolean_flag_value, get_flag_read_context,
+ get_boolean_flag_value, get_flag_attribute, get_flag_read_context,
get_package_read_context, get_storage_file_version, mapped_file::get_mapped_file,
PackageReadContext,
};
@@ -190,7 +190,8 @@
unsafe { get_mapped_file(&pb_file_path, "mockup", StorageFileType::FlagInfo).unwrap() };
let is_rw: Vec<bool> = vec![true, false, true, false, false, false, false, false];
for (offset, expected_value) in is_rw.into_iter().enumerate() {
- let attribute = get_boolean_flag_attribute(&flag_info_file, offset as u32).unwrap();
+ let attribute =
+ get_flag_attribute(&flag_info_file, FlagValueType::Boolean, offset as u32).unwrap();
assert!((attribute & FlagInfoBit::IsSticky as u8) == 0u8);
assert_eq!((attribute & FlagInfoBit::IsReadWrite as u8) != 0u8, expected_value);
assert!((attribute & FlagInfoBit::HasOverride as u8) == 0u8);
@@ -205,7 +206,7 @@
// The safety here is ensured as the test process will not write to temp storage file
let flag_info_file =
unsafe { get_mapped_file(&pb_file_path, "mockup", StorageFileType::FlagInfo).unwrap() };
- let err = get_boolean_flag_attribute(&flag_info_file, 8u32).unwrap_err();
+ let err = get_flag_attribute(&flag_info_file, FlagValueType::Boolean, 8u32).unwrap_err();
assert_eq!(
format!("{:?}", err),
"InvalidStorageFileOffset(Flag info offset goes beyond the end of the file.)"
diff --git a/tools/aconfig/aconfig_storage_write_api/src/flag_info_update.rs b/tools/aconfig/aconfig_storage_write_api/src/flag_info_update.rs
index 56e1253..3f38705 100644
--- a/tools/aconfig/aconfig_storage_write_api/src/flag_info_update.rs
+++ b/tools/aconfig/aconfig_storage_write_api/src/flag_info_update.rs
@@ -95,7 +95,7 @@
mod tests {
use super::*;
use aconfig_storage_file::test_utils::create_test_flag_info_list;
- use aconfig_storage_read_api::flag_info_query::find_boolean_flag_attribute;
+ use aconfig_storage_read_api::flag_info_query::find_flag_attribute;
#[test]
// this test point locks down is sticky update
@@ -104,10 +104,10 @@
let mut buf = flag_info_list.into_bytes();
for i in 0..flag_info_list.header.num_flags {
update_flag_is_sticky(&mut buf, FlagValueType::Boolean, i, true).unwrap();
- let attribute = find_boolean_flag_attribute(&buf, i).unwrap();
+ let attribute = find_flag_attribute(&buf, FlagValueType::Boolean, i).unwrap();
assert!((attribute & (FlagInfoBit::IsSticky as u8)) != 0);
update_flag_is_sticky(&mut buf, FlagValueType::Boolean, i, false).unwrap();
- let attribute = find_boolean_flag_attribute(&buf, i).unwrap();
+ let attribute = find_flag_attribute(&buf, FlagValueType::Boolean, i).unwrap();
assert!((attribute & (FlagInfoBit::IsSticky as u8)) == 0);
}
}
@@ -119,10 +119,10 @@
let mut buf = flag_info_list.into_bytes();
for i in 0..flag_info_list.header.num_flags {
update_flag_has_override(&mut buf, FlagValueType::Boolean, i, true).unwrap();
- let attribute = find_boolean_flag_attribute(&buf, i).unwrap();
+ let attribute = find_flag_attribute(&buf, FlagValueType::Boolean, i).unwrap();
assert!((attribute & (FlagInfoBit::HasOverride as u8)) != 0);
update_flag_has_override(&mut buf, FlagValueType::Boolean, i, false).unwrap();
- let attribute = find_boolean_flag_attribute(&buf, i).unwrap();
+ let attribute = find_flag_attribute(&buf, FlagValueType::Boolean, i).unwrap();
assert!((attribute & (FlagInfoBit::HasOverride as u8)) == 0);
}
}
diff --git a/tools/aconfig/aconfig_storage_write_api/src/lib.rs b/tools/aconfig/aconfig_storage_write_api/src/lib.rs
index ee08d16..8b7e459 100644
--- a/tools/aconfig/aconfig_storage_write_api/src/lib.rs
+++ b/tools/aconfig/aconfig_storage_write_api/src/lib.rs
@@ -281,7 +281,7 @@
match crate::flag_info_update::update_flag_is_sticky(file, value_type, offset, value) {
Ok(()) => ffi::FlagIsStickyUpdateCXX {
update_success: true,
- error_message: String::from("")
+ error_message: String::from(""),
},
Err(errmsg) => ffi::FlagIsStickyUpdateCXX {
update_success: false,
@@ -292,7 +292,7 @@
Err(errmsg) => ffi::FlagIsStickyUpdateCXX {
update_success: false,
error_message: format!("{:?}", errmsg),
- }
+ },
}
}
@@ -304,10 +304,11 @@
) -> ffi::FlagHasOverrideUpdateCXX {
match FlagValueType::try_from(flag_type) {
Ok(value_type) => {
- match crate::flag_info_update::update_flag_has_override(file, value_type, offset, value) {
+ match crate::flag_info_update::update_flag_has_override(file, value_type, offset, value)
+ {
Ok(()) => ffi::FlagHasOverrideUpdateCXX {
update_success: true,
- error_message: String::from("")
+ error_message: String::from(""),
},
Err(errmsg) => ffi::FlagHasOverrideUpdateCXX {
update_success: false,
@@ -318,7 +319,7 @@
Err(errmsg) => ffi::FlagHasOverrideUpdateCXX {
update_success: false,
error_message: format!("{:?}", errmsg),
- }
+ },
}
}
@@ -346,7 +347,7 @@
write_bytes_to_temp_file,
};
use aconfig_storage_file::FlagInfoBit;
- use aconfig_storage_read_api::flag_info_query::find_boolean_flag_attribute;
+ use aconfig_storage_read_api::flag_info_query::find_flag_attribute;
use aconfig_storage_read_api::flag_value_query::find_boolean_flag_value;
use std::fs::File;
use std::io::Read;
@@ -402,11 +403,11 @@
}
}
- fn get_flag_attribute_at_offset(file: &str, offset: u32) -> u8 {
+ fn get_flag_attribute_at_offset(file: &str, value_type: FlagValueType, offset: u32) -> u8 {
let mut f = File::open(&file).unwrap();
let mut bytes = Vec::new();
f.read_to_end(&mut bytes).unwrap();
- find_boolean_flag_attribute(&bytes, offset).unwrap()
+ find_flag_attribute(&bytes, value_type, offset).unwrap()
}
#[test]
@@ -442,10 +443,10 @@
.unwrap();
for i in 0..8 {
set_flag_is_sticky(&mut file, FlagValueType::Boolean, i, true).unwrap();
- let attribute = get_flag_attribute_at_offset(&flag_info_path, i);
+ let attribute = get_flag_attribute_at_offset(&flag_info_path, FlagValueType::Boolean, i);
assert!((attribute & (FlagInfoBit::IsSticky as u8)) != 0);
set_flag_is_sticky(&mut file, FlagValueType::Boolean, i, false).unwrap();
- let attribute = get_flag_attribute_at_offset(&flag_info_path, i);
+ let attribute = get_flag_attribute_at_offset(&flag_info_path, FlagValueType::Boolean, i);
assert!((attribute & (FlagInfoBit::IsSticky as u8)) == 0);
}
}
@@ -484,10 +485,10 @@
.unwrap();
for i in 0..8 {
set_flag_has_override(&mut file, FlagValueType::Boolean, i, true).unwrap();
- let attribute = get_flag_attribute_at_offset(&flag_info_path, i);
+ let attribute = get_flag_attribute_at_offset(&flag_info_path, FlagValueType::Boolean, i);
assert!((attribute & (FlagInfoBit::HasOverride as u8)) != 0);
set_flag_has_override(&mut file, FlagValueType::Boolean, i, false).unwrap();
- let attribute = get_flag_attribute_at_offset(&flag_info_path, i);
+ let attribute = get_flag_attribute_at_offset(&flag_info_path, FlagValueType::Boolean, i);
assert!((attribute & (FlagInfoBit::HasOverride as u8)) == 0);
}
}
diff --git a/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.cpp b/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.cpp
index 77664e4..6de3327 100644
--- a/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.cpp
+++ b/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.cpp
@@ -170,7 +170,8 @@
auto ro_mapped_file = api::MappedStorageFile();
ro_mapped_file.file_ptr = mapped_file.file_ptr;
ro_mapped_file.file_size = mapped_file.file_size;
- auto attribute = api::get_boolean_flag_attribute(ro_mapped_file, offset);
+ auto attribute = api::get_flag_attribute(
+ ro_mapped_file, api::FlagValueType::Boolean, offset);
ASSERT_TRUE(attribute.ok());
ASSERT_TRUE(*attribute & api::FlagInfoBit::IsSticky);
@@ -179,7 +180,8 @@
ASSERT_TRUE(update_result.ok());
ro_mapped_file.file_ptr = mapped_file.file_ptr;
ro_mapped_file.file_size = mapped_file.file_size;
- attribute = api::get_boolean_flag_attribute(ro_mapped_file, offset);
+ attribute = api::get_flag_attribute(
+ ro_mapped_file, api::FlagValueType::Boolean, offset);
ASSERT_TRUE(attribute.ok());
ASSERT_FALSE(*attribute & api::FlagInfoBit::IsSticky);
}
@@ -199,7 +201,8 @@
auto ro_mapped_file = api::MappedStorageFile();
ro_mapped_file.file_ptr = mapped_file.file_ptr;
ro_mapped_file.file_size = mapped_file.file_size;
- auto attribute = api::get_boolean_flag_attribute(ro_mapped_file, offset);
+ auto attribute = api::get_flag_attribute(
+ ro_mapped_file, api::FlagValueType::Boolean, offset);
ASSERT_TRUE(attribute.ok());
ASSERT_TRUE(*attribute & api::FlagInfoBit::HasOverride);
@@ -208,7 +211,8 @@
ASSERT_TRUE(update_result.ok());
ro_mapped_file.file_ptr = mapped_file.file_ptr;
ro_mapped_file.file_size = mapped_file.file_size;
- attribute = api::get_boolean_flag_attribute(ro_mapped_file, offset);
+ attribute = api::get_flag_attribute(
+ ro_mapped_file, api::FlagValueType::Boolean, offset);
ASSERT_TRUE(attribute.ok());
ASSERT_FALSE(*attribute & api::FlagInfoBit::HasOverride);
}
diff --git a/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.rs b/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.rs
index f6a9b280..5dd36c4 100644
--- a/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.rs
+++ b/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.rs
@@ -2,7 +2,7 @@
mod aconfig_storage_write_api_test {
use aconfig_storage_file::protos::ProtoStorageFiles;
use aconfig_storage_file::{FlagInfoBit, FlagValueType, StorageFileType};
- use aconfig_storage_read_api::flag_info_query::find_boolean_flag_attribute;
+ use aconfig_storage_read_api::flag_info_query::find_flag_attribute;
use aconfig_storage_read_api::flag_value_query::find_boolean_flag_value;
use aconfig_storage_write_api::{
mapped_file::get_mapped_file, set_boolean_flag_value, set_flag_has_override,
@@ -55,11 +55,11 @@
}
/// Get flag attribute at offset
- fn get_flag_attribute_at_offset(file: &str, offset: u32) -> u8 {
+ fn get_flag_attribute_at_offset(file: &str, value_type: FlagValueType, offset: u32) -> u8 {
let mut f = File::open(file).unwrap();
let mut bytes = Vec::new();
f.read_to_end(&mut bytes).unwrap();
- find_boolean_flag_attribute(&bytes, offset).unwrap()
+ find_flag_attribute(&bytes, value_type, offset).unwrap()
}
#[test]
@@ -107,10 +107,12 @@
};
for i in 0..8 {
set_flag_is_sticky(&mut file, FlagValueType::Boolean, i, true).unwrap();
- let attribute = get_flag_attribute_at_offset(&flag_info_path, i);
+ let attribute =
+ get_flag_attribute_at_offset(&flag_info_path, FlagValueType::Boolean, i);
assert!((attribute & (FlagInfoBit::IsSticky as u8)) != 0);
set_flag_is_sticky(&mut file, FlagValueType::Boolean, i, false).unwrap();
- let attribute = get_flag_attribute_at_offset(&flag_info_path, i);
+ let attribute =
+ get_flag_attribute_at_offset(&flag_info_path, FlagValueType::Boolean, i);
assert!((attribute & (FlagInfoBit::IsSticky as u8)) == 0);
}
}
@@ -133,10 +135,12 @@
};
for i in 0..8 {
set_flag_has_override(&mut file, FlagValueType::Boolean, i, true).unwrap();
- let attribute = get_flag_attribute_at_offset(&flag_info_path, i);
+ let attribute =
+ get_flag_attribute_at_offset(&flag_info_path, FlagValueType::Boolean, i);
assert!((attribute & (FlagInfoBit::HasOverride as u8)) != 0);
set_flag_has_override(&mut file, FlagValueType::Boolean, i, false).unwrap();
- let attribute = get_flag_attribute_at_offset(&flag_info_path, i);
+ let attribute =
+ get_flag_attribute_at_offset(&flag_info_path, FlagValueType::Boolean, i);
assert!((attribute & (FlagInfoBit::HasOverride as u8)) == 0);
}
}