aconfig: add flag type in flag table and remove info byte from value
array
1, add flag type to the flag table. Before flag table only stores the
mapping from (package id, flag name) to (flag id u32). The original
intent is to do bitmasking on the top byte of flag id to indicate flag
type. Now split the flag id u32 to two u16, the first represent flag
type, the second represent flag id. So after the change, the flag table
now shows the following mapping:
(package id, flag name) -> (flag type as u16, flag id as u16)
2, originally we plan to store a info byte together with each flag
value. The info byte is used by storage service damemon to mark up the
flag status, such as if it is accepting server side flag push. After
internal discussion, it is better to just create the info bytes as
another file by storage service damemon. So that the value file is
purely a flag value array.
Bug: b/312243587
test: atest aconfig.test
Change-Id: I7f953076b4269cf786bc23723078290e5ebe10bc
diff --git a/tools/aconfig/src/storage/mod.rs b/tools/aconfig/src/storage/mod.rs
index 76835e0..a28fccd 100644
--- a/tools/aconfig/src/storage/mod.rs
+++ b/tools/aconfig/src/storage/mod.rs
@@ -56,6 +56,8 @@
pub package_id: u32,
pub flag_names: HashSet<&'a str>,
pub boolean_flags: Vec<&'a ProtoParsedFlag>,
+ // offset of the first boolean flag in this flag package with respect to the start of
+ // boolean flag value array in the flag value file
pub boolean_offset: u32,
}
@@ -95,12 +97,11 @@
}
// calculate package flag value start offset, in flag value file, each boolean
- // is stored as two bytes, the first byte will be the flag value. the second
- // byte is flag info byte, which is a bitmask to indicate the status of a flag
+ // is stored as a single byte
let mut boolean_offset = 0;
for p in packages.iter_mut() {
p.boolean_offset = boolean_offset;
- boolean_offset += 2 * p.boolean_flags.len() as u32;
+ boolean_offset += p.boolean_flags.len() as u32;
}
packages
@@ -135,6 +136,13 @@
use super::*;
use crate::Input;
+ /// Read and parse bytes as u16
+ pub fn read_u16_from_bytes(buf: &[u8], head: &mut usize) -> Result<u16> {
+ let val = u16::from_le_bytes(buf[*head..*head + 2].try_into()?);
+ *head += 2;
+ Ok(val)
+ }
+
/// Read and parse bytes as u32
pub fn read_u32_from_bytes(buf: &[u8], head: &mut usize) -> Result<u32> {
let val = u32::from_le_bytes(buf[*head..*head + 4].try_into()?);
@@ -218,13 +226,13 @@
assert!(packages[1].flag_names.contains("enabled_ro"));
assert!(packages[1].flag_names.contains("disabled_ro"));
assert!(packages[1].flag_names.contains("enabled_fixed_ro"));
- assert_eq!(packages[1].boolean_offset, 6);
+ assert_eq!(packages[1].boolean_offset, 3);
assert_eq!(packages[2].package_name, "com.android.aconfig.storage.test_4");
assert_eq!(packages[2].package_id, 2);
assert_eq!(packages[2].flag_names.len(), 2);
assert!(packages[2].flag_names.contains("enabled_ro"));
assert!(packages[2].flag_names.contains("enabled_fixed_ro"));
- assert_eq!(packages[2].boolean_offset, 12);
+ assert_eq!(packages[2].boolean_offset, 6);
}
}