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 #ifndef BLUETOOTH_REMOTE_DEVICE_H
17 #define BLUETOOTH_REMOTE_DEVICE_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "bluetooth_def.h"
23 #include "bluetooth_types.h"
24 #include "bluetooth_device_class.h"
25 #include "bluetooth_battery_info.h"
26 
27 namespace OHOS {
28 namespace Bluetooth {
29 class BLUETOOTH_API BluetoothRemoteDevice {
30 public:
31     /// common
32     /**
33      * @brief A structor used to create the <b>BluetoothRemoteDevice</b> instance.
34      *
35      * @since 6
36      */
BluetoothRemoteDevice()37     BluetoothRemoteDevice(){};
38     /**
39      * @brief A structor used to create the <b>BluetoothRemoteDevice</b> instance.
40      *
41      * @since 6
42      */
43     BluetoothRemoteDevice(const std::string &addr, const int transport = BT_TRANSPORT_NONE);
44     /**
45      * @brief A destructor used to delete the <b>BluetoothRemoteDevice</b> instance.
46      *
47      * @since 6
48      */
~BluetoothRemoteDevice()49     virtual ~BluetoothRemoteDevice(){};
50 
51     /**
52      * @brief Get phonebook permission for device.
53      *
54      * @return Returns permission grade.
55      *         BTPermissionType::ACCESS_UNKNOWN;
56      *         BTPermissionType::ACCESS_ALLOWED;
57      *         BTPermissionType::ACCESS_FORBIDDEN.
58      * @since 6
59      */
60     int GetPhonebookPermission() const;
61 
62     /**
63      * @brief Set phonebook permission for device.
64      *
65      * @param permission permission grade.
66      *        BTPermissionType::ACCESS_UNKNOWN;
67      *        BTPermissionType::ACCESS_ALLOWED;
68      *        BTPermissionType::ACCESS_FORBIDDEN.
69      * @return Returns <b>true</b> if the operation is successful;
70      *         returns <b>false</b> if the operation fails.
71      * @since 6
72      */
73     bool SetPhonebookPermission(int permission);
74 
75     /**
76      * @brief Get message permission for device.
77      *
78      * @return Returns permission grade.
79      *         BTPermissionType::ACCESS_UNKNOWN;
80      *         BTPermissionType::ACCESS_ALLOWED;
81      *         BTPermissionType::ACCESS_FORBIDDEN.
82      * @since 6
83      */
84     int GetMessagePermission() const;
85 
86     /**
87      * @brief Set message permission for device.
88      *
89      * @param permission permission grade.
90      *        BTPermissionType::ACCESS_UNKNOWN;
91      *        BTPermissionType::ACCESS_ALLOWED;
92      *        BTPermissionType::ACCESS_FORBIDDEN.
93      * @return Returns <b>true</b> if the operation is successful;
94      *         returns <b>false</b> if the operation fails.
95      * @since 6
96      */
97     bool SetMessagePermission(int permission);
98 
99     /**
100      * @brief Get power mode for device.
101      *
102      * @return Returns power mode grade.
103      *         BTPowerMode::MODE_INVALID = 0x00,
104      *         BTPowerMode::MODE_ACTIVE = 0x100,
105      *         BTPowerMode::MODE_SNIFF_LEVEL_LOW = 0x201,
106      *         BTPowerMode::MODE_SNIFF_LEVEL_MID = 0x202,
107      *         BTPowerMode::MODE_SNIFF_LEVEL_HIG = 0x203,
108      * @since 6
109      */
110     int GetPowerMode(void) const;
111 
112     // gap
113 
114     /**
115      * @brief Get device address.
116      *
117      * @return Returns device adress.
118      * @since 6
119      */
GetDeviceAddr()120     std::string GetDeviceAddr() const
121     {
122         return address_;
123     };
124 
125     /**
126      * @brief Get device name.
127      *
128      * @return Returns device name.
129      * @since 6
130      */
131     std::string GetDeviceName() const;
132 
133     /**
134      * @brief Get device name.
135      *
136      * @return Returns device name.
137      * @since 6
138      */
139     int GetDeviceName(std::string &name) const;
140 
141     /**
142      * @brief Get device alias.
143      *
144      * @return Returns device alias.
145      * @since 6
146      */
147     std::string GetDeviceAlias() const;
148 
149     /**
150      * @brief Set device alias.
151      *
152      * @param aliasName Device alias name.
153      * @return Returns <b>BT_NO_ERROR</b> if the operation is successful;
154      *         returns <b>other error code</b> if the operation fails.
155      * @since 6
156      */
157     int32_t SetDeviceAlias(const std::string &aliasName);
158 
159     /**
160      * @brief Get device type.
161      *
162      * @return Returns device type.
163      * @since 6
164      */
165     int GetDeviceType() const;
166 
167     /**
168      * @brief Get device battery levele.
169      *
170      * @param[out] batteryInfo the device battery info.
171      * @return Returns operation code
172      * @since 12
173      */
174     int GetRemoteDeviceBatteryInfo(DeviceBatteryInfo &batteryInfo) const;
175 
176     /**
177      * @brief Get device pair state.
178      *
179      * @return Returns device pair state.
180      * @since 6
181      */
182     int GetPairState(int &pairState) const;
183 
184     /**
185      * @brief Device start pair.
186      *
187      * @return Returns <b>true</b> if the operation is successful;
188      *         returns <b>false</b> if the operation fails.
189      * @since 6
190      */
191     int StartPair();
192 
193     /**
194      * @brief Credible Device start pair.
195      *
196      * @return Returns <b>BT_NO_ERROR</b> if the operation is successful;
197      *         returns <b>Other code</b> if the operation fails.
198      * @since 10
199      */
200     int StartCrediblePair();
201 
202     /**
203      * @brief Cancel pair operation.
204      *
205      * @return Returns <b>true</b> if the operation is successful;
206      *         returns <b>false</b> if the operation fails.
207      * @since 6
208      */
209     int CancelPairing();
210 
211     /**
212      * @brief Check if device was bonded from local.
213      *
214      * @return Returns <b>true</b> if device was bonded from local;
215      *         returns <b>false</b> if device was not bonded from local.
216      * @since 6
217      */
218     bool IsBondedFromLocal() const;
219 
220     /**
221      * @brief Check if device acl connected.
222      *
223      * @return Returns <b>true</b> if device acl connected;
224      *         returns <b>false</b> if device does not acl connect.
225      * @since 6
226      */
227     bool IsAclConnected() const;
228 
229     /**
230      * @brief Check if device acl Encrypted.
231      *
232      * @return Returns <b>true</b> if device acl Encrypted;
233      *         returns <b>false</b> if device does not acl Encrypt.
234      * @since 6
235      */
236     bool IsAclEncrypted() const;
237 
238     /**
239      * @brief Get device class.
240      *
241      * @return Returns device class;
242      * @since 6
243      */
244     int GetDeviceClass(int &cod) const;
245 
246     /**
247      * @brief Get the product id of a remote device.
248      *
249      * @return Returns device product id;
250      * @since 11
251      */
252     int GetDeviceProductId(std::string &prodcutId) const;
253 
254     /**
255      * @brief Get device uuids.
256      *
257      * @return Returns device uuids;
258      * @since 6
259      */
260     int GetDeviceUuids(std::vector<std::string> &uuids) const;
261 
262     /**
263      * @brief Set device pair pin.
264      *
265      * @param pin Pin code.
266      * @return Returns <b>true</b> if the operation is successful;
267      *         returns <b>false</b> if the operation fails.
268      * @since 6
269      */
270     int SetDevicePin(const std::string &pin);
271 
272     /**
273      * @brief Set device pairing confirmation.
274      *
275      * @param accept Set gap accept flag.
276      * @return Returns <b>true</b> if the operation is successful;
277      *         returns <b>false</b> if the operation fails.
278      * @since 6
279      */
280     int SetDevicePairingConfirmation(bool accept);
281 
282     /**
283      * @brief Set device pair passkey.
284      *
285      * @param passkey Device passkey.
286      * @param accept Set gap accept flag.
287      * @return Returns <b>true</b> if the operation is successful;
288      *         returns <b>false</b> if the operation fails.
289      * @since 6
290      */
291     bool SetDevicePasskey(int passkey, bool accept);
292 
293     /**
294      * @brief Check device pair request reply.
295      *
296      * @param accept Set gap accept flag.
297      * @return Returns <b>true</b> if the operation is successful;
298      *         returns <b>false</b> if the operation fails.
299      * @since 6
300      */
301     bool PairRequestReply(bool accept);
302 
303     /**
304      * @brief Get device transport type.
305      *
306      * @return Returns device transport type;
307      * @since 6
308      */
309     int GetTransportType() const;
310 
311     // ble
312     /**
313      * @brief Read remote device rssi value.
314      *
315      * @return Returns <b>true</b> if the operation is successful;
316      *         returns <b>false</b> if the operation fails.
317      * @since 6
318      */
319     bool ReadRemoteRssiValue();
320 
321     /**
322      * @brief Check if bluetooth remote device is valid.
323      *
324      * @return Returns <b>true</b> if bluetooth remote device is valid;
325      *         returns <b>false</b> if bluetooth remote device is not valid.
326      * @since 6
327      */
328     bool IsValidBluetoothRemoteDevice() const;
329 
330     /**
331      * @brief Get the product type of the device, such as headsets, watchs and car.
332      *
333      * @param cod Class of device.
334      * @param majorClass The major class.
335      * @param majorMinorClass The minor class.
336      * @return Returns <b>BT_NO_ERROR</b> if the operation is successful;
337      *         returns <b>Other code</b> if the operation fails.
338      * @since 11
339      */
340     int GetDeviceProductType(int &cod, int &majorClass, int &majorMinorClass) const;
341 
342     /**
343      * @brief Set the product type of the device, such as headsets, watchs and car.
344      *
345      * @param deviceType The type of device.
346      * @return Returns <b>BT_NO_ERROR</b> if the operation is successful;
347      *         returns <b>Other code</b> if the operation fails.
348      * @since 12
349      */
350     int32_t SetDeviceCustomType(int32_t deviceType) const;
351 
352     /**
353      * @brief Get the product type of the device, such as headsets, watchs and car.
354      *
355      * @param deviceType The type of device.
356      * @return Returns <b>BT_NO_ERROR</b> if the operation is successful;
357      *         returns <b>Other code</b> if the operation fails.
358      * @since 12
359      */
360     int32_t GetDeviceCustomType(int32_t &deviceType) const;
361 
362     /**
363      * @brief Get the vendor id of the device.
364      *
365      * @param[out] vendorId The vendor id of device.
366      * @return Returns <b>BT_NO_ERROR</b> if the operation is successful;
367      *         returns <b>Other code</b> if the operation fails.
368      * @since 12
369      */
370     int32_t GetDeviceVendorId(uint16_t &vendorId) const;
371 
372     /**
373      * @brief Get the product id of the device.
374      *
375      * @param[out] productId The product id of device.
376      * @return Returns <b>BT_NO_ERROR</b> if the operation is successful;
377      *         returns <b>Other code</b> if the operation fails.
378      * @since 12
379      */
380     int32_t GetDeviceProductId(uint16_t &productId) const;
381 
382     /**
383      * @brief Get remote device is supported virtual auto connect.
384      *
385      * @param[out] outSupport The remote device configured auto connect value.
386      * @return Returns <b>BT_NO_ERROR</b> if the operation is successful;
387      *         returns <b>Other code</b> if the operation fails.
388      * @since 12
389      */
390     int32_t IsSupportVirtualAutoConnect(bool &outSupport) const;
391 
392     /**
393      * @brief Set remote device auto connect type and business connect type.
394      *
395      * @param connType Auto connect type value.
396      * @param businessType Business connect type value.
397      * @return Returns <b>BT_NO_ERROR</b> if the operation is successful;
398      *         returns <b>Other code</b> if the operation fails.
399      * @since 12
400      */
401     int32_t SetVirtualAutoConnectType(int connType, int businessType) const;
402 
403 private:
404     std::string address_ = "00:00:00:00:00:00";
405     int transport_ = BT_TRANSPORT_NONE;
406 };
407 }  // namespace Bluetooth
408 } // namespace OHOS
409 
410 #endif  // BLUETOOTH_REMOTE_DEVICE_H
411