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 16 #ifndef RDB_BMS_ADAPTER_PROFILE_INFO_H 17 #define RDB_BMS_ADAPTER_PROFILE_INFO_H 18 19 #include "bundle_info.h" 20 #include "data_properties.h" 21 #include "rdb_visibility.h" 22 #include "resource_manager.h" 23 #include "serializable.h" 24 25 #include <mutex> 26 27 namespace OHOS::RdbBMSAdapter { 28 using namespace OHOS::Global::Resource; 29 struct API_EXPORT Config final : public Serializable { 30 std::string uri = "*"; 31 int crossUserMode = 0; 32 std::string writePermission = ""; 33 std::string readPermission = ""; 34 bool Marshal(json &node) const override; 35 bool Unmarshal(const json &node) override; 36 }; 37 38 struct API_EXPORT ProfileInfo : public Serializable { 39 std::vector<Config> tableConfig; 40 bool Marshal(json &node) const override; 41 bool Unmarshal(const json &node) override; 42 }; 43 44 class API_EXPORT DataShareProfileInfo { 45 public: 46 static bool GetResConfigFile( 47 const AppExecFwk::ExtensionAbilityInfo &extensionInfo, std::vector<std::string> &profileInfos); 48 49 static bool GetDataPropertiesFromProxyDatas(const OHOS::AppExecFwk::ProxyData &proxyData, 50 const std::string &resourcePath, bool isCompressed, DataProperties &dataProperties); 51 52 private: 53 static std::shared_ptr<ResourceManager> InitResMgr(const std::string &resourcePath); 54 static std::vector<std::string> GetResProfileByMetadata(const std::vector<AppExecFwk::Metadata> &metadata, 55 const std::string &resourcePath, bool isCompressed); 56 static std::vector<std::string> GetResProfileByMetadata(const AppExecFwk::Metadata &metadata, 57 const std::string &resourcePath, bool isCompressed); 58 static std::vector<std::string> GetResFromResMgr(const std::string &resName, ResourceManager &resMgr, 59 bool isCompressed); 60 static std::string ReadProfile(const std::string &resPath); 61 static bool IsFileExisted(const std::string &filePath); 62 static std::mutex infosMutex_; 63 }; 64 } // namespace OHOS::RdbBMSAdapter 65 #endif // RDB_BMS_ADAPTER_PROFILE_INFO_H 66