aconfig: remove read api lib's dependency on libbase and liblog

Bug: b/321077378
Test: atest -c
Change-Id: I0bc7780de2123021e1cc9f7a29ca3f7dabebcd40
This commit is contained in:
Dennis Shen
2024-05-23 01:53:29 +00:00
parent 7b09e95c89
commit a0624828b2
7 changed files with 113 additions and 59 deletions

View File

@@ -10,32 +10,31 @@
#include "aconfig_storage/lib.rs.h"
#include "aconfig_storage/aconfig_storage_write_api.hpp"
using namespace android::base;
namespace aconfig_storage {
/// Map a storage file
Result<MutableMappedStorageFile*> map_mutable_storage_file(std::string const& file) {
android::base::Result<MutableMappedStorageFile*> map_mutable_storage_file(
std::string const& file) {
struct stat file_stat;
if (stat(file.c_str(), &file_stat) < 0) {
return ErrnoError() << "stat failed";
return android::base::ErrnoError() << "stat failed";
}
if ((file_stat.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) == 0) {
return Error() << "cannot map nonwriteable file";
return android::base::Error() << "cannot map nonwriteable file";
}
size_t file_size = file_stat.st_size;
const int fd = open(file.c_str(), O_RDWR | O_NOFOLLOW | O_CLOEXEC);
if (fd == -1) {
return ErrnoError() << "failed to open " << file;
return android::base::ErrnoError() << "failed to open " << file;
};
void* const map_result =
mmap(nullptr, file_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (map_result == MAP_FAILED) {
return ErrnoError() << "mmap failed";
return android::base::ErrnoError() << "mmap failed";
}
auto mapped_file = new MutableMappedStorageFile();
@@ -46,7 +45,7 @@ Result<MutableMappedStorageFile*> map_mutable_storage_file(std::string const& fi
}
/// Set boolean flag value
Result<void> set_boolean_flag_value(
android::base::Result<void> set_boolean_flag_value(
const MutableMappedStorageFile& file,
uint32_t offset,
bool value) {
@@ -54,13 +53,13 @@ Result<void> set_boolean_flag_value(
static_cast<uint8_t*>(file.file_ptr), file.file_size);
auto update_cxx = update_boolean_flag_value_cxx(content, offset, value);
if (!update_cxx.update_success) {
return Error() << std::string(update_cxx.error_message.c_str());
return android::base::Error() << update_cxx.error_message.c_str();
}
return {};
}
/// Set if flag has server override
Result<void> set_flag_has_server_override(
android::base::Result<void> set_flag_has_server_override(
const MutableMappedStorageFile& file,
FlagValueType value_type,
uint32_t offset,
@@ -70,13 +69,13 @@ Result<void> set_flag_has_server_override(
auto update_cxx = update_flag_has_server_override_cxx(
content, static_cast<uint16_t>(value_type), offset, value);
if (!update_cxx.update_success) {
return Error() << std::string(update_cxx.error_message.c_str());
return android::base::Error() << update_cxx.error_message.c_str();
}
return {};
}
/// Set if flag has local override
Result<void> set_flag_has_local_override(
android::base::Result<void> set_flag_has_local_override(
const MutableMappedStorageFile& file,
FlagValueType value_type,
uint32_t offset,
@@ -86,12 +85,12 @@ Result<void> set_flag_has_local_override(
auto update_cxx = update_flag_has_local_override_cxx(
content, static_cast<uint16_t>(value_type), offset, value);
if (!update_cxx.update_success) {
return Error() << std::string(update_cxx.error_message.c_str());
return android::base::Error() << update_cxx.error_message.c_str();
}
return {};
}
Result<void> create_flag_info(
android::base::Result<void> create_flag_info(
std::string const& package_map,
std::string const& flag_map,
std::string const& flag_info_out) {

View File

@@ -6,7 +6,6 @@
#include <android-base/result.h>
#include <aconfig_storage/aconfig_storage_read_api.hpp>
using namespace android::base;
namespace aconfig_storage {
@@ -14,24 +13,24 @@ namespace aconfig_storage {
struct MutableMappedStorageFile : MappedStorageFile {};
/// Map a storage file
Result<MutableMappedStorageFile*> map_mutable_storage_file(
android::base::Result<MutableMappedStorageFile*> map_mutable_storage_file(
std::string const& file);
/// Set boolean flag value
Result<void> set_boolean_flag_value(
android::base::Result<void> set_boolean_flag_value(
const MutableMappedStorageFile& file,
uint32_t offset,
bool value);
/// Set if flag has server override
Result<void> set_flag_has_server_override(
android::base::Result<void> set_flag_has_server_override(
const MutableMappedStorageFile& file,
FlagValueType value_type,
uint32_t offset,
bool value);
/// Set if flag has local override
Result<void> set_flag_has_local_override(
android::base::Result<void> set_flag_has_local_override(
const MutableMappedStorageFile& file,
FlagValueType value_type,
uint32_t offset,
@@ -41,7 +40,7 @@ Result<void> set_flag_has_local_override(
/// \input package_map: package map file
/// \input flag_map: flag map file
/// \input flag_info_out: flag info file to be created
Result<void> create_flag_info(
android::base::Result<void> create_flag_info(
std::string const& package_map,
std::string const& flag_map,
std::string const& flag_info_out);