• 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 constexpr const char *SETTINGS_DATASHARE_KEY_SCANMACINFO_WHITELIST = "location_kit_api_control_white_list";
39 
40 #ifndef OHOS_ARCH_LITE
41 constexpr const char *SETTINGS_DATASHARE_URI_WIFI_ON =
42     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=wifi_on";
43 constexpr const char *SETTINGS_DATASHARE_KEY_WIFI_ON = "wifi_on";
44 #endif
45 constexpr const char *SETTINGS_DATASHARE_URI_WIFI_ALLOW_SEMI_ACTIVE =
46     "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=";
47 constexpr const char *SETTINGS_DATASHARE_KEY_WIFI_ALLOW_SEMI_ACTIVE =
48     "settings.collaboration.multi_device_collaboration_service_switch";
49 }
50 
51 class WifiDataShareHelperUtils {
52 public:
53     /**
54      * @Description : WifiDataShareHelperUtils constructor
55      */
56     WifiDataShareHelperUtils() = default;
57 
58     /**
59      * @Description : WifiDataShareHelperUtils destructor
60      */
61     ~WifiDataShareHelperUtils() = default;
62 
63     /**
64      * @Description : Get the instance of WifiDataShareHelperUtils
65      *
66      * @return WifiDataShareHelperUtils instance
67      */
68     static WifiDataShareHelperUtils &GetInstance();
69 
70     /**
71      * @Description : Check if SettingsData ready
72      *
73      * @return true - datashare ready
74      */
75     bool CheckIfSettingsDataReady();
76 
77     /**
78      * @Description : Query function
79      *
80      * @param uri - Querying the database path
81      * @param key - key
82      * @param value - value
83      * @param onlySettingsData - false
84      * @return query error code
85      */
86     ErrCode Query(Uri &uri, const std::string &key, std::string &value, bool onlySettingsData = false);
87 
88     /**
89      * @Description : Insert function
90      *
91      * @param uri - Inserting the database path
92      * @param key - key
93      * @param value - value
94      * @return Insert error code
95      */
96     ErrCode Insert(Uri &uri, const std::string &key, const std::string &value);
97 
98     /**
99      * @Description : Update function
100      *
101      * @param uri - Updateing the database path
102      * @param key - key
103      * @param value - value
104      * @return Update error code
105      */
106     ErrCode Update(Uri &uri, const std::string &key, const std::string &value);
107 
108     /**
109      * @Description : Register observer function
110      *
111      * @param uri - Register observer the database path
112      * @param key - key
113      * @param value - value
114      * @return Register observer error code
115      */
116     ErrCode RegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &observer);
117 
118     /**
119      * @Description : Unregister observer function
120      *
121      * @param uri - Register observer the database path
122      * @param key - key
123      * @param value - value
124      * @return Unregister observer error code
125      */
126     ErrCode UnRegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &observer);
127 
128     std::string GetLoactionDataShareUri();
129     std::string GetScanMacInfoWhiteListDataShareUri();
130 
131 private:
132     std::shared_ptr<DataShare::DataShareHelper> WifiCreateDataShareHelper(bool onlySettingsData = false);
133     void ClearResources(std::shared_ptr<DataShare::DataShareHelper> operatrPtr,
134         std::shared_ptr<DataShare::DataShareResultSet> result);
135     bool IsDataMgrServiceActive();
136 
137     bool isDataShareReady_ = false;
138 };
139 
140 class IWifiDataShareRemoteBroker : public IRemoteBroker {
141 public:
142     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.wifi.IWifiScan");
143 };
144 
145 }   // namespace Wifi
146 }   // namespace OHOS
147 #endif
148