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 : public DelayedSingleton<AppDomainVerifyDataMgr> { 31 DECLARE_DELAYED_SINGLETON(AppDomainVerifyDataMgr); 32 DISALLOW_COPY_AND_MOVE(AppDomainVerifyDataMgr); 33 34 public: 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 insert 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 InsertVerifyStatus(const std::string& bundleName, const VerifyResultInfo& verifyResultInfo); 52 53 /** 54 * @brief udapte the AppDomainVerify status. 55 * @param bundleName Indicates the bundleName. 56 * @param verifyResultInfo Indicates the value to save. 57 * @return Returns true if this function is successfully called; returns false 58 * otherwise. 59 */ 60 bool UpdateVerifyStatus(const std::string& bundleName, const VerifyResultInfo& verifyResultInfo); 61 62 /** 63 * @brief Delete the AppDomainVerify status. 64 * @param bundleName Indicates the bundleName. 65 * @return Returns true if this function is successfully called; returns false 66 * otherwise. 67 */ 68 bool DeleteVerifyStatus(const std::string& bundleName); 69 70 /** 71 * @brief Get all AppDomainVerify status. 72 * @return Returns verifyMap_ const ref 73 * otherwise. 74 */ 75 const std::unordered_map<std::string, VerifyResultInfo>& GetAllVerifyStatus(); 76 bool QueryAssociatedDomains(const std::string& bundleName, std::vector<std::string>& domains); 77 bool QueryAssociatedBundleNames(const std::string& domain, std::vector<std::string>& bundleNames); 78 79 private: 80 bool GetParamKey(const std::string& bundleName, std::string& paramKey); 81 void UpdateVerifyMap(const std::string& bundleName, const VerifyResultInfo& verifyResultInfo); 82 bool InitRdb(); 83 bool LoadAllFromRdb(); 84 bool VerifyResultInfoToDB(const std::string bundleName, const VerifyResultInfo& verifyResultInfo); 85 bool DBToVerifyResultInfo(const std::vector<RdbDataItem>& items, VerifyResultInfo& verifyResultInfo); 86 bool LoadData(); 87 88 private: 89 std::shared_ptr<AppDomainVerifyRdbDataManager> rdbDataManager_ = nullptr; 90 std::mutex verifyMapMutex_; 91 std::shared_ptr<std::unordered_map<std::string, VerifyResultInfo>> verifyMap_ = nullptr; 92 }; 93 } // namespace AppDomainVerify 94 } // namespace OHOS 95 #endif // APP_DOMAIN_VERIFY_DATA_MGR_H