• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
26 namespace OHOS {
27 namespace Bluetooth {
28 class BLUETOOTH_API BluetoothRemoteDevice {
29 public:
30     /// common
31     /**
32      * @brief A structor used to create the <b>BluetoothRemoteDevice</b> instance.
33      *
34      * @since 6
35      */
BluetoothRemoteDevice()36     BluetoothRemoteDevice(){};
37     /**
38      * @brief A structor used to create the <b>BluetoothRemoteDevice</b> instance.
39      *
40      * @since 6
41      */
42     BluetoothRemoteDevice(const std::string &addr, const int transport);
43     /**
44      * @brief A destructor used to delete the <b>BluetoothRemoteDevice</b> instance.
45      *
46      * @since 6
47      */
~BluetoothRemoteDevice()48     virtual ~BluetoothRemoteDevice(){};
49 
50     /**
51      * @brief Get phonebook permission for device.
52      *
53      * @return Returns permission grade.
54      *         BTPermissionType::ACCESS_UNKNOWN;
55      *         BTPermissionType::ACCESS_ALLOWED;
56      *         BTPermissionType::ACCESS_FORBIDDEN.
57      * @since 6
58      */
59     int GetPhonebookPermission() const;
60 
61     /**
62      * @brief Set phonebook permission for device.
63      *
64      * @param permission permission grade.
65      *        BTPermissionType::ACCESS_UNKNOWN;
66      *        BTPermissionType::ACCESS_ALLOWED;
67      *        BTPermissionType::ACCESS_FORBIDDEN.
68      * @return Returns <b>true</b> if the operation is successful;
69      *         returns <b>false</b> if the operation fails.
70      * @since 6
71      */
72     bool SetPhonebookPermission(int permission);
73 
74     /**
75      * @brief Get message permission for device.
76      *
77      * @return Returns permission grade.
78      *         BTPermissionType::ACCESS_UNKNOWN;
79      *         BTPermissionType::ACCESS_ALLOWED;
80      *         BTPermissionType::ACCESS_FORBIDDEN.
81      * @since 6
82      */
83     int GetMessagePermission() const;
84 
85     /**
86      * @brief Set message permission for device.
87      *
88      * @param permission permission grade.
89      *        BTPermissionType::ACCESS_UNKNOWN;
90      *        BTPermissionType::ACCESS_ALLOWED;
91      *        BTPermissionType::ACCESS_FORBIDDEN.
92      * @return Returns <b>true</b> if the operation is successful;
93      *         returns <b>false</b> if the operation fails.
94      * @since 6
95      */
96     bool SetMessagePermission(int permission);
97 
98     /**
99      * @brief Get power mode for device.
100      *
101      * @return Returns power mode grade.
102      *         BTPowerMode::MODE_INVALID = 0x00,
103      *         BTPowerMode::MODE_ACTIVE = 0x100,
104      *         BTPowerMode::MODE_SNIFF_LEVEL_LOW = 0x201,
105      *         BTPowerMode::MODE_SNIFF_LEVEL_MID = 0x202,
106      *         BTPowerMode::MODE_SNIFF_LEVEL_HIG = 0x203,
107      * @since 6
108      */
109     int GetPowerMode(void) const;
110 
111     // gap
112 
113     /**
114      * @brief Get device address.
115      *
116      * @return Returns device adress.
117      * @since 6
118      */
GetDeviceAddr()119     std::string GetDeviceAddr() const
120     {
121         return address_;
122     };
123 
124     /**
125      * @brief Get device name.
126      *
127      * @return Returns device name.
128      * @since 6
129      */
130     std::string GetDeviceName() const;
131 
132     /**
133      * @brief Get device name.
134      *
135      * @return Returns device name.
136      * @since 6
137      */
138     int GetDeviceName(std::string &name) const;
139 
140     /**
141      * @brief Get device alias.
142      *
143      * @return Returns device alias.
144      * @since 6
145      */
146     std::string GetDeviceAlias() const;
147 
148     /**
149      * @brief Set device alias.
150      *
151      * @param aliasName Device alias name.
152      * @return Returns <b>true</b> if the operation is successful;
153      *         returns <b>false</b> if the operation fails.
154      * @since 6
155      */
156     bool SetDeviceAlias(const std::string &aliasName);
157 
158     /**
159      * @brief Get device type.
160      *
161      * @return Returns device type.
162      * @since 6
163      */
164     int GetDeviceType() const;
165 
166     /**
167      * @brief Get device battery levele.
168      *
169      * @return Returns device battery levele.
170      * @since 6
171      */
172     int GetDeviceBatteryLevel() const;
173 
174     /**
175      * @brief Get device pair state.
176      *
177      * @return Returns device pair state.
178      * @since 6
179      */
180     int GetPairState() const;
181 
182     /**
183      * @brief Device start pair.
184      *
185      * @return Returns <b>true</b> if the operation is successful;
186      *         returns <b>false</b> if the operation fails.
187      * @since 6
188      */
189     int StartPair();
190 
191     /**
192      * @brief Cancel pair operation.
193      *
194      * @return Returns <b>true</b> if the operation is successful;
195      *         returns <b>false</b> if the operation fails.
196      * @since 6
197      */
198     int CancelPairing();
199 
200     /**
201      * @brief Check if device was bonded from local.
202      *
203      * @return Returns <b>true</b> if device was bonded from local;
204      *         returns <b>false</b> if device was not bonded from local.
205      * @since 6
206      */
207     bool IsBondedFromLocal() const;
208 
209     /**
210      * @brief Check if device acl connected.
211      *
212      * @return Returns <b>true</b> if device acl connected;
213      *         returns <b>false</b> if device does not acl connect.
214      * @since 6
215      */
216     bool IsAclConnected() const;
217 
218     /**
219      * @brief Check if device acl Encrypted.
220      *
221      * @return Returns <b>true</b> if device acl Encrypted;
222      *         returns <b>false</b> if device does not acl Encrypt.
223      * @since 6
224      */
225     bool IsAclEncrypted() const;
226 
227     /**
228      * @brief Get device class.
229      *
230      * @return Returns device class;
231      * @since 6
232      */
233     int GetDeviceClass(int &cod) const;
234 
235     /**
236      * @brief Get device uuids.
237      *
238      * @return Returns device uuids;
239      * @since 6
240      */
241     int GetDeviceUuids(std::vector<std::string> &uuids) const;
242 
243     /**
244      * @brief Set device pair pin.
245      *
246      * @param pin Pin code.
247      * @return Returns <b>true</b> if the operation is successful;
248      *         returns <b>false</b> if the operation fails.
249      * @since 6
250      */
251     int SetDevicePin(const std::string &pin);
252 
253     /**
254      * @brief Set device pairing confirmation.
255      *
256      * @param accept Set gap accept flag.
257      * @return Returns <b>true</b> if the operation is successful;
258      *         returns <b>false</b> if the operation fails.
259      * @since 6
260      */
261     int SetDevicePairingConfirmation(bool accept);
262 
263     /**
264      * @brief Set device pair passkey.
265      *
266      * @param passkey Device passkey.
267      * @param accept Set gap accept flag.
268      * @return Returns <b>true</b> if the operation is successful;
269      *         returns <b>false</b> if the operation fails.
270      * @since 6
271      */
272     bool SetDevicePasskey(int passkey, bool accept);
273 
274     /**
275      * @brief Check device pair request reply.
276      *
277      * @param accept Set gap accept flag.
278      * @return Returns <b>true</b> if the operation is successful;
279      *         returns <b>false</b> if the operation fails.
280      * @since 6
281      */
282     bool PairRequestReply(bool accept);
283 
284     /**
285      * @brief Get device transport type.
286      *
287      * @return Returns device transport type;
288      * @since 6
289      */
290     int GetTransportType() const;
291 
292     // ble
293     /**
294      * @brief Read remote device rssi value.
295      *
296      * @return Returns <b>true</b> if the operation is successful;
297      *         returns <b>false</b> if the operation fails.
298      * @since 6
299      */
300     bool ReadRemoteRssiValue();
301 
302     /**
303      * @brief Check if bluetooth remote device is valid.
304      *
305      * @return Returns <b>true</b> if bluetooth remote device is valid;
306      *         returns <b>false</b> if bluetooth remote device is not valid.
307      * @since 6
308      */
309     bool IsValidBluetoothRemoteDevice() const;
310 
311 private:
312     std::string address_ = "00:00:00:00:00:00";
313     int transport_ = 0;
314 };
315 }  // namespace Bluetooth
316 } // namespace OHOS
317 
318 #endif  // BLUETOOTH_REMOTE_DEVICE_H
319