/* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include #include namespace android { namespace aconfigd { /// In memory data structure for storage file locations for each container struct StorageRecord { int version; std::string container; // container name std::string package_map; // package.map on container std::string flag_map; // flag.map on container std::string flag_val; // flag.val on container std::string persist_package_map; // persist package.map (backup copy for OTA) std::string persist_flag_map; // persist flag.map (backup copy for OTA) std::string persist_flag_val; // persist flag.val std::string persist_flag_info; // persist flag.info std::string local_overrides; // local flag overrides pb file std::string boot_flag_val; // boot flag.val std::string boot_flag_info; // boot flag.info std::string digest; // digest of storage files }; /// Mapped files for a container class StorageFiles { public: /// constructor for a new storage file set StorageFiles(const std::string& container, const std::string& package_map, const std::string& flag_map, const std::string& flag_val, const std::string& root_dir, base::Result& status); /// constructor for existing new storage file set StorageFiles(const PersistStorageRecord& pb, const std::string& root_dir); /// destructor ~StorageFiles() = default; /// no copy StorageFiles(const StorageFiles&) = delete; StorageFiles& operator=(const StorageFiles&) = delete; /// move constructor and assignment StorageFiles(StorageFiles&& rhs); StorageFiles& operator=(StorageFiles&& rhs); /// get storage record const StorageRecord& GetStorageRecord() { return storage_record_; } /// has boot copy bool HasBootCopy(); /// return result for package and flag context struct PackageFlagContext { const std::string& package; const std::string& flag; bool package_exists; bool flag_exists; aconfig_storage::FlagValueType value_type; uint32_t flag_index; PackageFlagContext(const std::string& package_name, const std::string& flag_name) : package(package_name) , flag(flag_name) , package_exists(false) , flag_exists(false) , value_type() , flag_index() {} }; /// Find package and flag context base::Result GetPackageFlagContext( const std::string& package, const std::string& flag); /// check if has package base::Result HasPackage(const std::string& package); /// check if has flag base::Result HasFlag(const std::string& package, const std::string& flag); /// get persistent flag attribute base::Result GetFlagAttribute(const PackageFlagContext& context); /// get server flag value base::Result GetServerFlagValue(const PackageFlagContext& context); /// get local flag value base::Result GetLocalFlagValue(const PackageFlagContext& context); /// get boot flag value base::Result GetBootFlagValue(const PackageFlagContext& context); /// get default flag value base::Result GetDefaultFlagValue(const PackageFlagContext& context); /// server flag override, update persistent flag value base::Result SetServerFlagValue(const PackageFlagContext& context, const std::string& flag_value); /// local flag override, update local flag override pb filee base::Result SetLocalFlagValue(const PackageFlagContext& context, const std::string& flag_value); /// set has server override in flag info base::Result SetHasServerOverride(const PackageFlagContext& context, bool has_server_override); /// set has local override in flag info base::Result SetHasLocalOverride(const PackageFlagContext& context, bool has_local_override); /// remove a single flag local override, return if removed base::Result RemoveLocalFlagValue(const PackageFlagContext& context); /// remove all local overrides base::Result RemoveAllLocalFlagValue(); /// strcut for server flag value entries struct ServerOverride { std::string package_name; std::string flag_name; std::string flag_value; }; /// get all current server override base::Result> GetServerFlagValues(); /// remove all persist storage files base::Result RemoveAllPersistFiles(); /// create boot flag value and info files base::Result CreateBootStorageFiles(); /// struct for flag snapshot struct FlagSnapshot { std::string package_name; std::string flag_name; std::string server_flag_value; std::string local_flag_value; std::string boot_flag_value; std::string default_flag_value; bool is_readwrite; bool has_server_override; bool has_local_override; }; /// list a flag base::Result ListFlag(const std::string& package, const std::string& flag); /// list flags base::Result> ListFlags( const std::string& package = ""); private: /// get package map base::Result GetPackageMap(); /// get flag map base::Result GetFlagMap(); /// get default flag val base::Result GetFlagVal(); /// get boot flag val base::Result GetBootFlagVal(); /// get boot flag info base::Result GetBootFlagInfo(); /// get persist flag val base::Result GetPersistFlagVal(); /// get persist flag info base::Result GetPersistFlagInfo(); /// check if flag is read only base::Result IsFlagReadOnly(const PackageFlagContext& context); /// apply local update to boot flag value copy base::Result ApplyLocalOverrideToBootFlagValue(); private: /// container name std::string container_; // storage record for current container StorageRecord storage_record_; /// mapped package map file std::unique_ptr package_map_; /// mapped flag map file std::unique_ptr flag_map_; /// mapped default flag value file std::unique_ptr flag_val_; /// mapped boot flag value file std::unique_ptr boot_flag_val_; /// mapped boot flag info file std::unique_ptr boot_flag_info_; /// mapped persist flag value file std::unique_ptr persist_flag_val_; /// mapped persist flag info file std::unique_ptr persist_flag_info_; }; // class StorageFiles } // namespace aconfigd } // namespace android