1 /*
2  * Copyright (C) 2023-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 
16 #ifndef NET_DATASHARE_UTILS_H
17 #define NET_DATASHARE_UTILS_H
18 
19 #include <functional>
20 #include <map>
21 #include <memory>
22 #include <utility>
23 
24 #include "datashare_helper.h"
25 #include "datashare_predicates.h"
26 #include "datashare_result_set.h"
27 #include "datashare_values_bucket.h"
28 #include "iservice_registry.h"
29 #include "system_ability_definition.h"
30 #include "uri.h"
31 
32 namespace OHOS {
33 namespace NetManagerStandard {
34 namespace {
35 constexpr const char *AIRPLANE_MODE_URI =
36     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=airplane_mode";
37 constexpr const char *GLOBAL_PROXY_HOST_URI =
38     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=global_proxy_host";
39 constexpr const char *GLOBAL_PROXY_PORT_URI =
40     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=global_proxy_port";
41 constexpr const char *GLOBAL_PROXY_EXCLUSIONS_URI =
42     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=global_proxy_exclusions";
43 
44 constexpr const char *KEY_AIRPLANE_MODE = "settings.telephony.airplanemode";
45 constexpr const char *KEY_GLOBAL_PROXY_HOST = "settings.netmanager.proxy_host";
46 constexpr const char *KEY_GLOBAL_PROXY_PORT = "settings.netmanager.proxy_port";
47 constexpr const char *KEY_GLOBAL_PROXY_EXCLUSIONS = "settings.netmanager.proxy_exclusions";
48 } // namespace
49 
50 class NetDataShareHelperUtils final {
51 public:
52     NetDataShareHelperUtils();
53     ~NetDataShareHelperUtils() = default;
54     int32_t Query(Uri &uri, const std::string &key, std::string &value);
55     int32_t Insert(Uri &uri, const std::string &key, const std::string &value);
56     int32_t Update(Uri &uri, const std::string &key, const std::string &value);
57     int32_t Delete(Uri &uri, const std::string &key);
58     int32_t RegisterObserver(const Uri &uri, const std::function<void()> &onChange);
59     int32_t UnregisterObserver(const Uri &uri, int32_t callbackId);
60 
61 private:
62     std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper();
63     std::map<int32_t, sptr<AAFwk::IDataAbilityObserver>> callbacks_;
64 };
65 } // namespace NetManagerStandard
66 } // namespace OHOS
67 #endif // NET_DATASHARE_UTILS_H