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

Commit 451350e7 authored by Dennis Shen's avatar Dennis Shen Committed by Automerger Merge Worker
Browse files

Merge changes from topic "flag_info_read_api" into main am: ccfb4c28

parents b568ddb0 ccfb4c28
Loading
Loading
Loading
Loading
+6 −6
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 = 0,
    IsReadWrite = 1,
    HasOverride = 2,
    IsSticky = 1 << 0,
    IsReadWrite = 1 << 1,
    HasOverride = 1 << 2,
}

/// Flag info node struct
@@ -108,9 +108,9 @@ impl fmt::Debug for FlagInfoNode {
        writeln!(
            f,
            "sticky: {}, readwrite: {}, override: {}",
            self.attributes & (FlagInfoBit::IsSticky as u8),
            self.attributes & (FlagInfoBit::IsReadWrite as u8),
            self.attributes & (FlagInfoBit::HasOverride as u8),
            self.attributes & (FlagInfoBit::IsSticky as u8) != 0,
            self.attributes & (FlagInfoBit::IsReadWrite as u8) != 0,
            self.attributes & (FlagInfoBit::HasOverride as u8) != 0,
        )?;
        Ok(())
    }
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ use std::fs::File;
use std::hash::{Hash, Hasher};
use std::io::Read;

pub use crate::flag_info::{FlagInfoHeader, FlagInfoList, FlagInfoNode};
pub use crate::flag_info::{FlagInfoHeader, FlagInfoList, FlagInfoNode, FlagInfoBit};
pub use crate::flag_table::{FlagTable, FlagTableHeader, FlagTableNode};
pub use crate::flag_value::{FlagValueHeader, FlagValueList};
pub use crate::package_table::{PackageTable, PackageTableHeader, PackageTableNode};
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ rust_test_host {
        "tests/package.map",
        "tests/flag.map",
        "tests/flag.val",
        "tests/flag.info",
    ],
}

+15 −0
Original line number Diff line number Diff line
@@ -54,6 +54,8 @@ static Result<std::string> find_storage_file(
          return entry.flag_map();
        case StorageFileType::flag_val:
          return entry.flag_val();
        case StorageFileType::flag_info:
          return entry.flag_info();
        default:
          return Error() << "Invalid file type " << file_type;
      }
@@ -174,4 +176,17 @@ Result<bool> get_boolean_flag_value(
  }
}

/// Get boolean flag attribute
Result<uint8_t> get_boolean_flag_attribute(
    MappedStorageFile const& file,
    uint32_t offset) {
  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, offset);
  if (info_cxx.query_success) {
    return info_cxx.flag_attribute;
  } else {
    return Error() << info_cxx.error_message;
  }
}
} // namespace aconfig_storage
+17 −2
Original line number Diff line number Diff line
@@ -10,7 +10,8 @@ namespace aconfig_storage {
enum StorageFileType {
  package_map,
  flag_map,
  flag_val
  flag_val,
  flag_info
};

/// Mapped storage file
@@ -76,10 +77,24 @@ android::base::Result<FlagOffset> get_flag_offset(

/// Get boolean flag value
/// \input file: mapped storage file
/// \input offset: the boolean flag value byte offset in the file
/// \input offset: the boolean flag value offset in the file
/// \returns the boolean flag value
android::base::Result<bool> get_boolean_flag_value(
    MappedStorageFile const& file,
    uint32_t offset);

/// Flag info enum, to be consistent with the one defined in src/lib.rs
enum FlagInfoBit {
  IsSticky = 1<<0,
  IsReadWrite = 1<<1,
  HasOverride = 1<<2,
};

/// Get boolean flag attribute
/// \input file: mapped storage file
/// \input offset: the boolean flag info offset in the file
/// \returns the boolean flag attribute
android::base::Result<uint8_t> get_boolean_flag_attribute(
    MappedStorageFile const& file,
    uint32_t offset);
} // namespace aconfig_storage
Loading