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 The framework interface and callback function of pbap client are defined. 21 * 22 * @since 6 23 */ 24 25 /** 26 * @file bluetooth_pbap_client.h 27 * 28 * @brief pbap client interface. 29 * 30 * @since 6 31 */ 32 33 #ifndef BLUETOOTH_PBAP_CLIENT_H 34 #define BLUETOOTH_PBAP_CLIENT_H 35 36 #include <memory> 37 #include <string> 38 #include <vector> 39 #include "bluetooth_remote_device.h" 40 #include "bluetooth_types.h" 41 #include "bluetooth_def.h" 42 43 namespace OHOS { 44 namespace Bluetooth { 45 /** 46 * @brief Pbap PullPhoneBook app parameter 47 * 48 * @since 6 49 */ 50 class BLUETOOTH_API PbapPullPhoneBookParam { 51 public: 52 enum { 53 NAME = 1 << 0, 54 PROPERTY_SELECTOR = 1 << 1, 55 FORMAT = 1 << 2, 56 MAX_LIST_COUNT = 1 << 3, 57 LIST_START_OFFSET = 1 << 4, 58 RESET_NEW_MISSED_CALLS = 1 << 5, 59 VCARD_SELECTOR = 1 << 6, 60 VCARD_SELECTOROP = 1 << 7, 61 }; 62 63 public: 64 std::u16string GetName() const; 65 void SetName(const std::u16string &name); 66 uint64_t GetPropertySelector() const; 67 void SetPropertySelector(uint64_t propertySelector); 68 uint8_t GetFormat() const; 69 void SetFormat(uint8_t format); 70 uint16_t GetMaxListCount() const; 71 void SetMaxListCount(uint16_t maxListCount); 72 uint16_t GetListStartOffset() const; 73 void SetListStartOffset(uint16_t listStartOffset); 74 uint8_t GetResetNewMissedCalls() const; 75 void SetResetNewMissedCalls(uint8_t resetNewMissedCalls); 76 uint64_t GetvCardSelector() const; 77 void SetvCardSelector(uint64_t vCardSelector); 78 uint8_t GetvCardSelectorOp() const; 79 void SetvCardSelectorOp(uint8_t vCardSelectorOp); 80 uint64_t GetSpecifiedBitset() const; 81 void SetSpecifiedBitset(uint64_t specifiedBitset); 82 bool IsSpecified(int bitSpecified) const; 83 84 private: 85 std::u16string name_ = u""; 86 uint64_t propertySelector_ = 0ULL; 87 uint8_t format_ = 0; 88 uint16_t maxListCount_ = 0; 89 uint16_t listStartOffset_ = 0; 90 uint8_t resetNewMissedCalls_ = 0; 91 uint64_t vCardSelector_ = 0ULL; 92 uint8_t vCardSelectorOp_ = 0; 93 uint64_t specifiedBitset_ = 0ULL; 94 }; 95 96 /** 97 * @brief Pbap PullvCardListing app parameter 98 * 99 * @since 6 100 */ 101 class BLUETOOTH_API PbapPullvCardListingParam { 102 public: 103 enum { 104 NAME = 1 << 0, 105 ORDER = 1 << 1, 106 SEARCH_VALUE = 1 << 2, 107 SEARCH_PROPERTY = 1 << 3, 108 MAX_LIST_COUNT = 1 << 4, 109 LIST_START_OFFSET = 1 << 5, 110 RESET_NEW_MISSED_CALLS = 1 << 6, 111 VCARD_SELECTOR = 1 << 7, 112 VCARD_SELECTOROP = 1 << 8, 113 }; 114 115 public: 116 std::u16string GetName() const; 117 void SetName(const std::u16string &name); 118 uint8_t GetOrder() const; 119 void SetOrder(uint8_t order); 120 std::string GetSearchValue() const; 121 void SetSearchValue(const std::string &searchValue); 122 uint8_t GetSearchProperty() const; 123 void SetSearchProperty(uint8_t searchProperty); 124 uint16_t GetMaxListCount() const; 125 void SetMaxListCount(uint16_t maxListCount); 126 uint16_t GetListStartOffset() const; 127 void SetListStartOffset(uint16_t listStartOffset); 128 uint8_t GetResetNewMissedCalls() const; 129 void SetResetNewMissedCalls(uint8_t resetNewMissedCalls); 130 uint64_t GetvCardSelector() const; 131 void SetvCardSelector(uint64_t vCardSelector); 132 uint8_t GetvCardSelectorOp() const; 133 void SetvCardSelectorOp(uint8_t vCardSelectorOp); 134 uint64_t GetSpecifiedBitset() const; 135 void SetSpecifiedBitset(uint64_t specifiedBitset); 136 bool IsSpecified(int bitSpecified) const; 137 138 private: 139 std::u16string name_ = u""; 140 uint8_t order_ = 0; 141 std::string searchValue_ = ""; 142 uint8_t searchProperty_ = 0; 143 uint16_t maxListCount_ = 0; 144 uint16_t listStartOffset_ = 0; 145 uint8_t resetNewMissedCalls_ = 0; 146 uint64_t vCardSelector_ = 0ULL; 147 uint8_t vCardSelectorOp_ = 0; 148 uint64_t specifiedBitset_ = 0ULL; 149 }; 150 151 /** 152 * @brief Pbap PullvCardEntry app parameter 153 * 154 * @since 6 155 */ 156 class BLUETOOTH_API PbapPullvCardEntryParam { 157 public: 158 enum { 159 NAME = 1 << 0, 160 PROPERTY_SELECTOR = 1 << 1, 161 FORMAT = 1 << 2, 162 }; 163 164 public: 165 std::u16string GetName() const; 166 void SetName(const std::u16string &name); 167 uint64_t GetPropertySelector() const; 168 void SetPropertySelector(uint64_t propertySelector); 169 uint8_t GetFormat() const; 170 void SetFormat(uint8_t format); 171 uint64_t GetSpecifiedBitset() const; 172 void SetSpecifiedBitset(uint64_t specifiedBitset); 173 bool IsSpecified(int bitSpecified) const; 174 175 private: 176 std::u16string name_ = u""; 177 uint64_t propertySelector_ = 0ULL; 178 uint8_t format_ = 0; 179 uint64_t specifiedBitset_ = 0ULL; 180 }; 181 182 /** 183 * @brief Pbap PhoneBook response data 184 * 185 * @since 6 186 */ 187 class PbapPhoneBookData { 188 public: 189 uint16_t phoneBookSize_ = 0; // VCard size 190 std::vector<uint8_t> primaryFolderVersion_ {}; // VCard PrimaryFolderVersion 16 bytes 191 std::vector<uint8_t> secondaryFolderVersion_ {}; // VCard SecondaryFolderVersion 16 bytes 192 std::vector<uint8_t> databaseIdentifier_ {}; // VCard DatabaseIdentifier 16 bytes 193 std::vector<uint8_t> result_ {}; // VCard bytes with utf-8 194 }; 195 196 /** 197 * @brief obsever for pbap client 198 * when pbap client occur event, call these 199 * @since 6 200 */ 201 class PbapClientObserver { 202 public: 203 /** 204 * @brief Constructor 205 * @details Constructor 206 * @since 6 207 */ 208 PbapClientObserver() = default; 209 210 /** 211 * @brief deconstructor 212 * @details deconstructor 213 * @since 6 214 */ 215 virtual ~PbapClientObserver() = default; 216 217 /** 218 * @brief ConnectionState Changed 219 * 220 * @param device bluetooth address 221 * @param state changed status 222 * @since 6 223 */ OnServiceConnectionStateChanged(const BluetoothRemoteDevice & device,int state)224 virtual void OnServiceConnectionStateChanged(const BluetoothRemoteDevice &device, int state) 225 {} 226 227 /** 228 * @brief connect password input call back 229 * 230 * @details when connect password input call it 231 * @param device remote device 232 * @param description description bytes 233 * @param charset description bytes's chartset 234 * @param fullAccess fullAccess 235 * @since 6 236 */ 237 virtual void OnServicePasswordRequired(const BluetoothRemoteDevice &device, 238 const std::vector<uint8_t> &description, uint8_t charset, bool fullAccess = true) 239 {} 240 241 /** 242 * @brief action completed call back 243 * @details when action completed call it 244 * @param device remote device 245 * @param actionType pbap action type 246 * PBAP_ACTION_PULLPHONEBOOKSIZE 247 * PBAP_ACTION_PULLPHONEBOOK 248 * PBAP_ACTION_SETPHONEBOOK 249 * PBAP_ACTION_PULLVCARDLISTINGSIZE 250 * PBAP_ACTION_PULLVCARDLISTING 251 * PBAP_ACTION_PULLVCARDENTRY 252 * PBAP_ACTION_ABORT 253 * @param result response result 254 * @since 6 255 */ OnActionCompleted(const BluetoothRemoteDevice & device,int respCode,int actionType,const PbapPhoneBookData & result)256 virtual void OnActionCompleted( 257 const BluetoothRemoteDevice &device, int respCode, int actionType, const PbapPhoneBookData &result) 258 {} 259 }; 260 261 /** 262 * @brief pbap client 263 * pbap client 264 * @since 6 265 */ 266 class BLUETOOTH_API PbapClient { 267 public: 268 /** 269 * @brief get PbapClient 270 * @details get PbapClient instance 271 * @return PbapClient instance 272 * @since 6 273 */ 274 static PbapClient *GetProfile(); 275 276 /** 277 * @brief register observer 278 * @details register observer for the service of phone book client 279 * @param observer the pointer that point to a PbapClientObserver 280 * @return void 281 * @since 6 282 */ 283 void RegisterObserver(PbapClientObserver *observer); 284 285 /** 286 * @brief deregister observer 287 * @details deregister observer for the service of phone book client 288 * @param observer the pointer that point to a PbapClientObserver 289 * @return void 290 * @since 6 291 */ 292 void DeregisterObserver(PbapClientObserver *observer); 293 294 /** 295 * @brief get the remote devices 296 * @details get the remote device with the specified states 297 * @param states states 298 * @return std::vector remote devices 299 * @since 6 300 */ 301 std::vector<BluetoothRemoteDevice> GetDevicesByStates(const std::vector<int> &states); 302 303 /** 304 * @brief get connected devices 305 * @details get connected devices 306 * @return std::vector remote devices 307 * @since 6 308 */ 309 std::vector<BluetoothRemoteDevice> GetConnectedDevices(); 310 311 /** 312 * @brief get the state of device 313 * @details get the state with the specified remote device 314 * @param device remote device 315 * @return int 316 * @c not -1 : state of the specified remote device 317 * @c -1 : device is not exist 318 * @since 6 319 */ 320 int GetDeviceState(const BluetoothRemoteDevice &device); 321 322 /** 323 * @brief connect to server 324 * @details connect to phone book server 325 * @param device remote device 326 * @return bool 327 * @c true success 328 * @c false failure 329 * @since 6 330 */ 331 bool Connect(const BluetoothRemoteDevice &device); 332 333 /** 334 * @brief disconnect device 335 * @details disconnect from remote device 336 * @param device remote device 337 * @return bool 338 * @c true success 339 * @c false failure 340 * @since 6 341 */ 342 bool Disconnect(const BluetoothRemoteDevice &device); 343 344 /** 345 * @brief set the strategy of device 346 * @details set the strategy with the specified remote device 347 * @param device remote device 348 * @param strategy specified strategy 349 * @return bool 350 * @c true success 351 * @c false failure 352 * @since 6 353 */ 354 bool SetConnectionStrategy(const BluetoothRemoteDevice &device, int strategy); 355 356 /** 357 * @brief get the strategy of device 358 * @details get the strategy with the specified remote device 359 * @param device remote device 360 * @return int BTStrategyType: 361 * CONNECTION_UNKNOWN 362 * CONNECTION_ALLOWED 363 * CONNECTION_FORBIDDEN 364 * @since 6 365 */ 366 int GetConnectionStrategy(const BluetoothRemoteDevice &device); 367 /** 368 * @brief Set device's password. please call after OnServicePasswordRequired event. 369 * 370 * @param device device 371 * @param password device's password 372 * @param userId device's userId 373 * @return int 374 * @c 0 success 375 * @c -1 failure 376 * @since 6 377 */ 378 int SetDevicePassword( 379 const BluetoothRemoteDevice &device, const std::string &password, const std::string &userId = ""); 380 381 /** 382 * @brief Pull phone book from remote device after connected. 383 * 384 * @param device device 385 * @param param app parameter pbap v1.2.3 386 * @return int 387 * @c 0 success 388 * @c -1 failure 389 * @since 6 390 */ 391 int PullPhoneBook(const BluetoothRemoteDevice &device, const PbapPullPhoneBookParam ¶m); 392 393 /** 394 * @brief Set phone book from remote device after connected. 395 * 396 * @param device device 397 * @param name phone book path 398 * @param flag 399 * @c PBAP_FLAG_GO_TO_ROOT and empty name--to root; 400 * @c PBAP_FLAG_GO_DOWN --go down; 401 * @c PBAP_FLAG_GO_UP --go up 402 * @return int 403 * @c 0 success 404 * @c -1 failure 405 * @since 6 406 */ 407 int SetPhoneBook(const BluetoothRemoteDevice &device, const std::u16string &name, int flag); 408 409 /** 410 * @brief Pull vCard listing from remote device after connected. 411 * 412 * @param device device 413 * @param param app parameter pbap v1.2.3 414 * @return int 415 * @c 0 success 416 * @c -1 failure 417 * @since 6 418 */ 419 int PullvCardListing(const BluetoothRemoteDevice &device, const PbapPullvCardListingParam ¶m); 420 421 /** 422 * @brief Pull vCard entry from remote device after connected. 423 * 424 * @param device device 425 * @param param app parameter pbap v1.2.3 426 * @return int 427 * @c 0 success 428 * @c -1 failure 429 * @since 6 430 */ 431 int PullvCardEntry(const BluetoothRemoteDevice &device, const PbapPullvCardEntryParam ¶m); 432 433 /** 434 * @brief Check if local device is downloading phonebook from remote device. 435 * 436 * @param device device 437 * @return bool true downloading; false not downloading 438 * @since 6 439 */ 440 bool IsDownloading(const BluetoothRemoteDevice &device); 441 442 /** 443 * @brief Abort downloading phonebook from remote device. 444 * 445 * @param device device 446 * @return int 447 * @c 0 success 448 * @c -1 failure 449 * @since 6 450 */ 451 int AbortDownloading(const BluetoothRemoteDevice &device); 452 453 private: 454 /** 455 * @brief constructor 456 * @details constructor 457 */ 458 PbapClient(); 459 460 /** 461 * @brief deconstructor 462 * @details deconstructor 463 */ 464 ~PbapClient(); 465 466 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(PbapClient); 467 BLUETOOTH_DECLARE_IMPL(); 468 }; 469 } // namespace Bluetooth 470 } // namespace OHOS 471 #endif // BLUETOOTH_PBAP_CLIENT_H 472