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

Commit 6f4c6929 authored by Dennis Shen's avatar Dennis Shen
Browse files

aconfig: update flag info storage file

previously we store three bits per flag: is sticky, is read write, has
override. so when a local override arrives, is sticky bit as well has
override bit are set to true. this becomes problematic when the local
override is removed. we are not sure if we should remove has override
bit as well (server override could still be in place).

therefore restructuring the flag info for each flag into new three bits:
is read write, has server override and has local override. so now server
override and local override bits are independent from each other.

Bug: b/312444587
Test: atest -c
Change-Id: I03b2bb7312480773236c95f2b39f2589fee41924
parent b24b46d4
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -91,9 +91,9 @@ impl FlagInfoHeader {
/// bit field for flag info
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum FlagInfoBit {
    IsSticky = 1 << 0,
    HasServerOverride = 1 << 0,
    IsReadWrite = 1 << 1,
    HasOverride = 1 << 2,
    HasLocalOverride = 1 << 2,
}

/// Flag info node struct
@@ -107,10 +107,10 @@ impl fmt::Debug for FlagInfoNode {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        writeln!(
            f,
            "sticky: {}, readwrite: {}, override: {}",
            self.attributes & (FlagInfoBit::IsSticky as u8) != 0,
            "readwrite: {}, server override: {}, local override: {}",
            self.attributes & (FlagInfoBit::IsReadWrite as u8) != 0,
            self.attributes & (FlagInfoBit::HasOverride as u8) != 0,
            self.attributes & (FlagInfoBit::HasServerOverride as u8) != 0,
            self.attributes & (FlagInfoBit::HasLocalOverride as u8) != 0,
        )?;
        Ok(())
    }
+2 −2
Original line number Diff line number Diff line
@@ -32,9 +32,9 @@ enum FlagValueType {
/// Flag info enum, to be consistent with the one defined in
/// aconfig_storage_file/src/flag_info.rs
enum FlagInfoBit {
  IsSticky = 1<<0,
  HasServerOverride = 1<<0,
  IsReadWrite = 1<<1,
  HasOverride = 1<<2,
  HasLocalOverride = 1<<2,
};

/// Mapped storage file
+4 −4
Original line number Diff line number Diff line
@@ -56,13 +56,13 @@ mod tests {
    use aconfig_storage_file::{test_utils::create_test_flag_info_list, FlagInfoBit};

    #[test]
    // this test point locks down query if flag is sticky
    // this test point locks down query if flag has server override
    fn test_is_flag_sticky() {
        let flag_info_list = create_test_flag_info_list().into_bytes();
        for offset in 0..8 {
            let attribute =
                find_flag_attribute(&flag_info_list[..], FlagValueType::Boolean, offset).unwrap();
            assert_eq!((attribute & FlagInfoBit::IsSticky as u8) != 0u8, false);
            assert_eq!((attribute & FlagInfoBit::HasServerOverride as u8) != 0u8, false);
        }
    }

@@ -82,13 +82,13 @@ mod tests {
    }

    #[test]
    // this test point locks down query if flag has override
    // this test point locks down query if flag has local override
    fn test_flag_has_override() {
        let flag_info_list = create_test_flag_info_list().into_bytes();
        for offset in 0..8 {
            let attribute =
                find_flag_attribute(&flag_info_list[..], FlagValueType::Boolean, offset).unwrap();
            assert_eq!((attribute & FlagInfoBit::HasOverride as u8) != 0u8, false);
            assert_eq!((attribute & FlagInfoBit::HasLocalOverride as u8) != 0u8, false);
        }
    }

+2 −2
Original line number Diff line number Diff line
@@ -508,9 +508,9 @@ files {{
        for (offset, expected_value) in is_rw.into_iter().enumerate() {
            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);
            assert!((attribute & FlagInfoBit::HasServerOverride as u8) == 0u8);
            assert!((attribute & FlagInfoBit::HasLocalOverride as u8) == 0u8);
        }
    }

+2 −2
Original line number Diff line number Diff line
@@ -236,10 +236,10 @@ TEST_F(AconfigStorageTest, test_boolean_flag_info_query) {
  for (int index = 0; index < 8; ++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::HasServerOverride), 0);
    ASSERT_EQ((*attribute & static_cast<uint8_t>(api::FlagInfoBit::IsReadWrite)) != 0,
              expected_value[index]);
    ASSERT_EQ(*attribute & static_cast<uint8_t>(api::FlagInfoBit::HasOverride), 0);
    ASSERT_EQ(*attribute & static_cast<uint8_t>(api::FlagInfoBit::HasLocalOverride), 0);
  }
}

Loading