1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef APP_DOMAIN_VERIFY_DATA_MGR_H 16 #define APP_DOMAIN_VERIFY_DATA_MGR_H 17 18 #include <memory> 19 #include <string> 20 #include <vector> 21 22 #include "app_domain_verify_hilog.h" 23 #include "app_domain_verify_rdb_data_manager.h" 24 #include "inner_verify_status.h" 25 #include "singleton.h" 26 #include "bundle_verify_status_info.h" 27 28 namespace OHOS { 29 namespace AppDomainVerify { 30 class AppDomainVerifyDataMgr { 31 public: 32 AppDomainVerifyDataMgr(); 33 virtual ~AppDomainVerifyDataMgr(); 34 35 /** 36 * @brief Get AppDomainVerify status. 37 * @param bundleName Indicates the bundleName. 38 * @param verifyResultInfo output value. 39 * @return Returns true if this function is successfully called; returns false 40 * otherwise. 41 */ 42 bool GetVerifyStatus(const std::string& bundleName, VerifyResultInfo& verifyResultInfo); 43 44 /** 45 * @brief Save the AppDomainVerify status. 46 * @param bundleName Indicates the bundleName. 47 * @param verifyResultInfo Indicates the value to save. 48 * @return Returns true if this function is successfully called; returns false 49 * otherwise. 50 */ 51 bool SaveVerifyStatus(const std::string& bundleName, const VerifyResultInfo& verifyResultInfo); 52 53 /** 54 * @brief Delete the AppDomainVerify status. 55 * @param bundleName Indicates the bundleName. 56 * @return Returns true if this function is successfully called; returns false 57 * otherwise. 58 */ 59 bool DeleteVerifyStatus(const std::string& bundleName); 60 61 /** 62 * @brief Get all AppDomainVerify status. 63 * @return Returns verifyMap_ const ref 64 * otherwise. 65 */ 66 const std::unordered_map<std::string, VerifyResultInfo>& GetAllVerifyStatus(); 67 bool QueryAssociatedDomains(const std::string& bundleName, std::vector<std::string>& domains); 68 bool QueryAssociatedBundleNames(const std::string& domain, std::vector<std::string>& bundleNames); 69 70 private: 71 bool GetParamKey(const std::string& bundleName, std::string& paramKey); 72 void UpdateVerifyMap(const std::string& bundleName, const VerifyResultInfo& verifyResultInfo); 73 bool InitRdb(); 74 bool LoadAllFromRdb(); 75 bool VerifyResultInfoToDB(const std::string bundleName, const VerifyResultInfo& verifyResultInfo); 76 bool DBToVerifyResultInfo(const std::vector<RdbDataItem>& items, VerifyResultInfo& verifyResultInfo); 77 78 private: 79 std::shared_ptr<AppDomainVerifyRdbDataManager> rdbDataManager_ = nullptr; 80 std::mutex verifyMapMutex_; 81 std::shared_ptr<std::unordered_map<std::string, VerifyResultInfo>> verifyMap_ = nullptr; 82 }; 83 } // namespace AppDomainVerify 84 } // namespace OHOS 85 #endif // APP_DOMAIN_VERIFY_DATA_MGR_H