• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 NET_DATASHARE_UTILS_H
17 #define NET_DATASHARE_UTILS_H
18 
19 #include <memory>
20 #include <utility>
21 
22 #include "datashare_helper.h"
23 #include "datashare_predicates.h"
24 #include "datashare_result_set.h"
25 #include "datashare_values_bucket.h"
26 #include "iservice_registry.h"
27 #include "system_ability_definition.h"
28 #include "uri.h"
29 
30 namespace OHOS {
31 namespace NetManagerStandard {
32 namespace {
33 constexpr const char *AIRPLANE_MODE_URI =
34     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=airplane_mode";
35 constexpr const char *GLOBAL_PROXY_HOST_URI =
36     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=global_proxy_host";
37 constexpr const char *GLOBAL_PROXY_PORT_URI =
38     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=global_proxy_port";
39 constexpr const char *GLOBAL_PROXY_EXCLUSIONS_URI =
40     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=global_proxy_exclusions";
41 constexpr const char *PAC_URL_URI =
42     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=pac_url";
43 
44 constexpr const char *USER_URI_PATTERN = "##USERID##";
45 constexpr const char *USER_PROXY_HOST_URI =
46     "datashare:///com.ohos.settingsdata/entry/settingsdata/"
47     "USER_SETTINGSDATA_##USERID##?Proxy=true&key=global_proxy_host";
48 constexpr const char *USER_PROXY_PORT_URI =
49     "datashare:///com.ohos.settingsdata/entry/settingsdata/"
50     "USER_SETTINGSDATA_##USERID##?Proxy=true&key=global_proxy_port";
51 constexpr const char *USER_PROXY_EXCLUSIONS_URI =
52     "datashare:///com.ohos.settingsdata/entry/settingsdata/"
53     "USER_SETTINGSDATA_##USERID##?Proxy=true&key=global_proxy_exclusions";
54 
55 constexpr const char *KEY_AIRPLANE_MODE = "settings.telephony.airplanemode";
56 constexpr const char *KEY_GLOBAL_PROXY_HOST = "settings.netmanager.proxy_host";
57 constexpr const char *KEY_GLOBAL_PROXY_PORT = "settings.netmanager.proxy_port";
58 constexpr const char *KEY_GLOBAL_PROXY_EXCLUSIONS = "settings.netmanager.proxy_exclusions";
59 constexpr const char *KEY_PAC_URL = "settings.netmanager.pac_url";
60 } // namespace
61 
62 class NetDataShareHelperUtils final {
63 public:
64     NetDataShareHelperUtils();
65     ~NetDataShareHelperUtils() = default;
66     int32_t Query(Uri &uri, const std::string &key, std::string &value);
67     int32_t Insert(Uri &uri, const std::string &key, const std::string &value);
68     int32_t Update(Uri &uri, const std::string &key, const std::string &value);
69 
70 private:
71     std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper();
72 };
73 } // namespace NetManagerStandard
74 } // namespace OHOS
75 #endif // NET_DATASHARE_UTILS_H
76