• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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 OHOS_WIFI_DATASHARE_UTILS_H
17 #define OHOS_WIFI_DATASHARE_UTILS_H
18 
19 #include <memory>
20 #include <utility>
21 #include <singleton.h>
22 
23 #include "iremote_object.h"
24 #include "datashare_helper.h"
25 #include "datashare_predicates.h"
26 #include "datashare_result_set.h"
27 #include "iservice_registry.h"
28 #include "uri.h"
29 #include "wifi_errcode.h"
30 
31 namespace OHOS {
32 namespace Wifi {
33 namespace {
34 constexpr const char *SETTINGS_DATASHARE_URL_AIRPLANE_MODE =
35     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=airplane_mode";
36 constexpr const char *SETTINGS_DATASHARE_KEY_AIRPLANE_MODE = "settings.telephony.airplanemode";
37 constexpr const char *SETTINGS_DATASHARE_KEY_LOCATION_MODE = "location_switch_enable";
38 
39 #ifndef OHOS_ARCH_LITE
40 constexpr const char *SETTINGS_DATASHARE_URI_CLONE_DATA =
41     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=WifiBackupData";
42 constexpr const char *SETTINGS_DATASHARE_KEY_CLONE_DATA = "WifiBackupData";
43 
44 constexpr const char *SETTINGS_DATASHARE_URI_WIFI_ON =
45     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=wifi_on";
46 constexpr const char *SETTINGS_DATASHARE_KEY_WIFI_ON = "wifi_on";
47 #endif
48 constexpr const char *SETTINGS_DATASHARE_URI_WIFI_ALLOW_SEMI_ACTIVE =
49     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=";
50 constexpr const char *SETTINGS_DATASHARE_KEY_WIFI_ALLOW_SEMI_ACTIVE =
51     "settings.collaboration.multi_device_collaboration_service_switch";
52 }
53 
54 class WifiDataShareHelperUtils : DelayedSingleton<WifiDataShareHelperUtils> {
55 public:
56     /**
57      * @Description : WifiDataShareHelperUtils constructor
58      */
59     WifiDataShareHelperUtils() = default;
60 
61     /**
62      * @Description : WifiDataShareHelperUtils destructor
63      */
64     ~WifiDataShareHelperUtils() = default;
65 
66     /**
67      * @Description : Query function
68      *
69      * @param uri - Querying the database path
70      * @param key - key
71      * @param value - value
72      * @param onlySettingsData - false
73      * @return query error code
74      */
75     ErrCode Query(Uri &uri, const std::string &key, std::string &value, bool onlySettingsData = false);
76 
77     /**
78      * @Description : Insert function
79      *
80      * @param uri - Inserting the database path
81      * @param key - key
82      * @param value - value
83      * @return Insert error code
84      */
85     ErrCode Insert(Uri &uri, const std::string &key, const std::string &value);
86 
87     /**
88      * @Description : Update function
89      *
90      * @param uri - Updateing the database path
91      * @param key - key
92      * @param value - value
93      * @return Update error code
94      */
95     ErrCode Update(Uri &uri, const std::string &key, const std::string &value);
96 
97     /**
98      * @Description : Register observer function
99      *
100      * @param uri - Register observer the database path
101      * @param key - key
102      * @param value - value
103      * @return Register observer error code
104      */
105     ErrCode RegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &observer);
106 
107     /**
108      * @Description : Unregister observer function
109      *
110      * @param uri - Register observer the database path
111      * @param key - key
112      * @param value - value
113      * @return Unregister observer error code
114      */
115     ErrCode UnRegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &observer);
116 
117     std::string GetLoactionDataShareUri();
118 
119 private:
120     std::shared_ptr<DataShare::DataShareHelper> WifiCreateDataShareHelper(bool onlySettingsData = false);
121     void ClearResources(std::shared_ptr<DataShare::DataShareHelper> operatrPtr,
122         std::shared_ptr<DataShare::DataShareResultSet> result);
123 };
124 
125 class IWifiDataShareRemoteBroker : public IRemoteBroker {
126 public:
127     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.wifi.IWifiScan");
128 };
129 
130 }   // namespace Wifi
131 }   // namespace OHOS
132 #endif
133