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