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 singleton = false; 49 bool hasExtension = false; 50 bool allowEmptyPermission = false; 51 bool storeMetaDataFromUri = false; 52 AccessCrossMode accessCrossMode = AccessCrossMode::USER_UNDEFINED; 53 }; 54 55 std::pair<int, ProviderInfo> GetProviderInfo(); 56 private: 57 bool GetFromUriPath(); 58 int GetFromProxyData(); 59 int GetFromExtension(); 60 int GetFromDataProperties(const ProfileInfo &profileInfo, const std::string &moduleName); 61 int GetFromExtensionProperties(const ProfileInfo &profileInfo, const std::string &moduleName); 62 void GetMetaDataFromUri(); 63 std::pair<int, BundleConfig> GetBundleInfo(); 64 enum class PATH_PARAM : int32_t { 65 BUNDLE_NAME = 0, 66 MODULE_NAME, 67 STORE_NAME, 68 TABLE_NAME, 69 PARAM_SIZE 70 }; 71 ProviderInfo providerInfo_; 72 UriConfig uriConfig_; 73 static constexpr const char *MODULE_SCOPE = "module"; 74 static constexpr const char *DATA_SHARE_EXTENSION_META = "ohos.extension.dataShare"; 75 static constexpr const char *DATA_SHARE_PROPERTIES_META = "dataProperties"; 76 }; 77 } // namespace OHOS::DataShare 78 #endif 79