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 appIndex = 0; // appIndex is in [1, 1000], and original app's index is 0 37 std::string bundleName; 38 std::string moduleName; 39 std::string storeName; 40 std::string tableName; 41 std::string readPermission; 42 std::string writePermission; 43 std::string type = "rdb"; 44 std::string backup; 45 std::string extensionUri; 46 bool singleton = false; 47 bool hasExtension = false; 48 bool allowEmptyPermission = false; 49 bool storeMetaDataFromUri = false; 50 AccessCrossMode accessCrossMode = AccessCrossMode::USER_UNDEFINED; 51 }; 52 53 std::pair<int, ProviderInfo> GetProviderInfo(); 54 private: 55 bool GetFromUriPath(); 56 int GetFromProxyData(); 57 int GetFromExtension(); 58 int GetFromDataProperties(const ProfileInfo &profileInfo, const std::string &moduleName); 59 int GetFromExtensionProperties(const ProfileInfo &profileInfo, const std::string &moduleName); 60 void GetMetaDataFromUri(); 61 std::pair<int, BundleConfig> GetBundleInfo(); 62 enum class PATH_PARAM : int32_t { 63 BUNDLE_NAME = 0, 64 MODULE_NAME, 65 STORE_NAME, 66 TABLE_NAME, 67 PARAM_SIZE 68 }; 69 ProviderInfo providerInfo_; 70 UriConfig uriConfig_; 71 static constexpr const char *MODULE_SCOPE = "module"; 72 static constexpr const char *DATA_SHARE_EXTENSION_META = "ohos.extension.dataShare"; 73 static constexpr const char *DATA_SHARE_PROPERTIES_META = "dataProperties"; 74 }; 75 } // namespace OHOS::DataShare 76 #endif 77