1 /* 2 * Copyright (c) 2024 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 DATASHARESERVICE_DATA_PROVIDER_CONFIG_H 16 #define DATASHARESERVICE_DATA_PROVIDER_CONFIG_H 17 18 #include <map> 19 #include <string> 20 21 #include "account/account_delegate.h" 22 #include "bundle_mgr_proxy.h" 23 #include "data_share_profile_config.h" 24 #include "hap_module_info.h" 25 #include "uri_utils.h" 26 27 namespace OHOS::DataShare { 28 using ExtensionAbility = OHOS::AppExecFwk::ExtensionAbilityInfo; 29 class DataProviderConfig { 30 public: 31 DataProviderConfig(const std::string &uri, uint32_t callerTokenId); 32 33 struct ProviderInfo { 34 std::string uri; 35 int32_t currentUserId = -1; 36 int32_t visitedUserId = -1; 37 int32_t appIndex = 0; // appIndex is in [1, 1000], and original app's index is 0 38 std::string bundleName; 39 std::string moduleName; 40 std::string storeName; 41 std::string tableName; 42 std::string readPermission; 43 std::string writePermission; 44 std::string acrossAccountsPermission = "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS"; 45 std::string type = "rdb"; 46 std::string backup; 47 std::string extensionUri; 48 bool isFromExtension = false; 49 bool singleton = false; 50 bool hasExtension = false; 51 bool allowEmptyPermission = false; 52 bool storeMetaDataFromUri = false; 53 AccessCrossMode accessCrossMode = AccessCrossMode::USER_UNDEFINED; 54 std::vector<AllowList> allowLists; 55 }; 56 57 std::pair<int, ProviderInfo> GetProviderInfo(); 58 private: 59 bool GetFromUriPath(); 60 int GetFromProxyData(); 61 int GetFromExtension(); 62 int GetFromDataProperties(const ProfileInfo &profileInfo, const std::string &moduleName); 63 int GetFromExtensionProperties(const ProfileInfo &profileInfo, const std::string &moduleName); 64 void GetMetaDataFromUri(); 65 std::pair<int, BundleConfig> GetBundleInfo(); 66 enum class PATH_PARAM : int32_t { 67 BUNDLE_NAME = 0, 68 MODULE_NAME, 69 STORE_NAME, 70 TABLE_NAME, 71 PARAM_SIZE 72 }; 73 ProviderInfo providerInfo_; 74 UriConfig uriConfig_; 75 static constexpr const char *MODULE_SCOPE = "module"; 76 static constexpr const char *DATA_SHARE_EXTENSION_META = "ohos.extension.dataShare"; 77 static constexpr const char *DATA_SHARE_PROPERTIES_META = "dataProperties"; 78 }; 79 } // namespace OHOS::DataShare 80 #endif 81