1 /*
2  * Copyright (C) 2021 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 /**
17  * @addtogroup Bluetooth
18  * @{
19  *
20  * @brief Defines classic config functions.
21  *
22  */
23 
24 /**
25  * @file classic_config.h
26  *
27  * @brief Classic config.
28  *
29  */
30 
31 #ifndef CLASSIS_CONFIG_H
32 #define CLASSIS_CONFIG_H
33 
34 #include <mutex>
35 #include <string>
36 
37 #include "adapter_device_config.h"
38 
39 namespace OHOS {
40 namespace bluetooth {
41 /**
42  * @brief Represents classic config.
43  *
44  */
45 class ClassicConfig {
46 public:
47     /**
48      * @brief Get classic config singleton instance pointer.
49      *
50      * @return Returns the singleton instance pointer.
51      */
52     static ClassicConfig &GetInstance();
53 
54     /**
55      * @brief Load config info.
56      *
57      * @return Returns <b>true</b> if the operation is successful;
58      *         returns <b>false</b> if the operation fails.
59      */
60     bool LoadConfigFile() const;
61 
62     /**
63      * @brief Save config.
64      *
65      * @return Returns <b>true</b> if the operation is successful;
66      *         returns <b>false</b> if the operation fails.
67      */
68     bool Save() const;
69 
70     /**
71      * @brief Get security mode.
72      *
73      * @return Returns security mode.
74      */
75     int GetSecurityMode() const;
76 
77     /**
78      * @brief Get local passkey.
79      *
80      * @return Returns local passkey.
81      */
82     std::string GetLocalPasskey() const;
83 
84     /**
85      * @brief Get device Io capability.
86      *
87      * @return Returns device Io capability.
88      */
89     int GetIoCapability() const;
90 
91     /**
92      * @brief Get local device class.
93      *
94      * @return Returns local device class.
95      */
96     int GetLocalDeviceClass() const;
97 
98     /**
99      * @brief Get discoverable timeout.
100      *
101      * @return Returns discoverable timeout.
102      */
103     int GetDiscoverableTimeout() const;
104 
105     /**
106      * @brief Get local name.
107      *
108      * @return Returns local name.
109      */
110     std::string GetLocalName() const;
111 
112     /**
113      * @brief Set local device class.
114      *
115      * @param cod Device cod.
116      * @return Returns <b>true</b> if the operation is successful;
117      *         returns <b>false</b> if the operation fails.
118      */
119     bool SetLocalDeviceClass(int cod) const;
120 
121     /**
122      * @brief Set discoverable timeout.
123      *
124      * @param time Discoverable timeout.
125      * @return Returns <b>true</b> if the operation is successful;
126      *         returns <b>false</b> if the operation fails.
127      */
128     bool SetDiscoverableTimeout(int time) const;
129 
130     /**
131      * @brief Set local name.
132      *
133      * @param name Device name.
134      * @return Returns <b>true</b> if the operation is successful;
135      *         returns <b>false</b> if the operation fails.
136      */
137     bool SetLocalName(const std::string &name) const;
138 
139     /**
140      * @brief Set local address.
141      *
142      * @param addr Device address.
143      * @return Returns <b>true</b> if the operation is successful;
144      *         returns <b>false</b> if the operation fails.
145      */
146     bool SetLocalAddress(const std::string &addr) const;
147 
148     /// Api for get paired device info.
149     /**
150      * @brief Get remote device name.
151      *
152      * @param subSection Device address.
153      * @return Returns remote device name.
154      */
155     std::string GetRemoteName(const std::string &subSection) const;
156 
157     /**
158      * @brief Get remote device alias.
159      *
160      * @param subSection Device address.
161      * @return Returns remote device alias.
162      */
163     std::string GetRemoteAlias(const std::string &subSection) const;
164 
165     /**
166      * @brief Get remote device link key.
167      *
168      * @param subSection Device address.
169      * @return Returns remote device link key.
170      */
171     std::string GetRemoteLinkkey(const std::string &subSection) const;
172 
173     /**
174      * @brief Get remote device type.
175      *
176      * @param subSection Device address.
177      * @return Returns remote device type.
178      */
179     int GetRemoteDeviceType(const std::string &subSection) const;
180 
181     /**
182      * @brief Get remote device link key type.
183      *
184      * @param subSection Device address.
185      * @return Returns remote device link key type.
186      */
187     int GetRemoteLinkkeyType(const std::string &subSection) const;
188 
189     /**
190      * @brief Get remote device class.
191      *
192      * @param subSection Device address.
193      * @return Returns remote device class.
194      */
195     int GetRemoteDeviceClass(const std::string &subSection) const;
196 
197     /**
198      * @brief Get remote device Io capability.
199      *
200      * @param subSection Device address.
201      * @return Returns remote device Io capability.
202      */
203     int GetRemoteDeviceIoCapability(const std::string &subSection) const;
204 
205     /**
206      * @brief Get paired device address list.
207      *
208      * @return Returns paired device address list.
209      */
210     std::vector<std::string> GetPairedAddrList() const;
211 
212     /**
213      * @brief Get remote device pair flag.
214      *
215      * @param subSection Device address.
216      * @return Returns remote device pair flag.
217      */
218     bool GetRemoteDevicePairFlag(const std::string &subSection) const;
219 
220     /**
221      * @brief Get remote device if bond from local.
222      *
223      * @param subSection Device address.
224      * @return Returns remote device if bond from local.
225      */
226     bool GetRemoteDeviceBondFromLocal(const std::string &subSection) const;
227 
228     /**
229      * @brief Set remote device name.
230      *
231      * @param subSection Device address.
232      * @param name Device name.
233      * @return Returns <b>true</b> if the operation is successful;
234      *         returns <b>false</b> if the operation fails.
235      */
236     bool SetRemoteName(const std::string &subSection, const std::string &name) const;
237 
238     /**
239      * @brief Set remote device alias.
240      *
241      * @param subSection Device address.
242      * @param name Device alias.
243      * @return Returns <b>true</b> if the operation is successful;
244      *         returns <b>false</b> if the operation fails.
245      */
246     bool SetRemoteAlias(const std::string &subSection, const std::string &name) const;
247 
248     /**
249      * @brief Set remote device type.
250      *
251      * @param subSection Device address.
252      * @param type Device type.
253      * @return Returns <b>true</b> if the operation is successful;
254      *         returns <b>false</b> if the operation fails.
255      */
256     bool SetRemoteDeviceType(const std::string &subSection, int type) const;
257 
258     /**
259      * @brief Set remote device link key.
260      *
261      * @param subSection Device address.
262      * @param linkKey Link key.
263      * @return Returns <b>true</b> if the operation is successful;
264      *         returns <b>false</b> if the operation fails.
265      */
266     bool SetRemoteLinkkey(const std::string &subSection, const std::string &linkKey) const;
267 
268     /**
269      * @brief Set remote device link key type.
270      *
271      * @param subSection Device address.
272      * @param type Link key type.
273      * @return Returns <b>true</b> if the operation is successful;
274      *         returns <b>false</b> if the operation fails.
275      */
276     bool SetRemoteLinkkeyType(const std::string &subSection, int type) const;
277 
278     /**
279      * @brief Set remote device class.
280      *
281      * @param subSection Device address.
282      * @param cod Device cod.
283      * @return Returns <b>true</b> if the operation is successful;
284      *         returns <b>false</b> if the operation fails.
285      */
286     bool SetRemoteDeviceClass(const std::string &subSection, int cod) const;
287 
288     /**
289      * @brief Set remote device Io capabilityass.
290      *
291      * @param subSection Device address.
292      * @param io Device Io capability.
293      * @return Returns <b>true</b> if the operation is successful;
294      *         returns <b>false</b> if the operation fails.
295      */
296     bool SetRemoteDeviceIoCapability(const std::string &subSection, int io) const;
297 
298     /**
299      * @brief Set remote device pair flag.
300      *
301      * @param subSection Device address.
302      * @param flag Pair flag.
303      * @return Returns <b>true</b> if the operation is successful;
304      *         returns <b>false</b> if the operation fails.
305      */
306     bool SetRemoteDevicePairFlag(const std::string &subSection, bool flag) const;
307 
308     /**
309      * @brief Set remote remote device if bond from local.
310      *
311      * @param subSection Device address.
312      * @param flag Device if bond from local.
313      * @return Returns <b>true</b> if the operation is successful;
314      *         returns <b>false</b> if the operation fails.
315      */
316     bool SetRemoteDeviceBondFromLocal(const std::string &subSection, bool flag) const;
317 
318     /**
319      * @brief Remove paired device.
320      *
321      * @param subSection Device address.
322      * @return Returns <b>true</b> if the operation is successful;
323      *         returns <b>false</b> if the operation fails.
324      */
325     bool RemovePairedDevice(const std::string &subSection) const;
326 
327     /**
328      * @brief Set Remote device uuids.
329      *
330      * @param uuids remote device support uuids.
331      * @return Returns <b>true</b> if the operation is successful;
332      *         returns <b>false</b> if the operation fails.
333      */
334     bool SetRemoteUuids(const std::string &subSection, const std::string &uuids) const;
335 
336     /**
337      * @brief Get remote device uuids.
338      *
339      * @param subSection Device address.
340      * @return Returns remote device uuids.
341      */
342     std::string GetRemoteUuids(const std::string &subSection) const;
343 
344 private:
345     /**
346      * @brief A constructor used to create a <b>ClassicConfig</b> instance.
347      *
348      */
349     ClassicConfig();
350     ClassicConfig(const ClassicConfig &config);
351     ClassicConfig &operator=(const ClassicConfig &config);
352 
353     /**
354      * @brief A destructor used to delete the <b>ClassicConfig</b> instance.
355      *
356      */
357     ~ClassicConfig();
358 
359     IAdapterDeviceConfig *config_ {};
360 };
361 }  // namespace bluetooth
362 }  // namespace OHOS
363 #endif  // CLASSIS_CONFIG_H