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 PBAP_PSE_VCARD_MANAGER_H 17 #define PBAP_PSE_VCARD_MANAGER_H 18 19 #include <cstdint> 20 #include <cstring> 21 #include <map> 22 #include <vector> 23 #include "../obex/obex_types.h" 24 #include "pbap_pse_app_params.h" 25 26 namespace OHOS { 27 namespace bluetooth { 28 class PbapPseVcardManager { 29 public: 30 struct PhoneBookResult { 31 ObexRspCode rspCode_ {ObexRspCode::SUCCESS}; 32 bool phoneBookSizeOnly_ = false; 33 uint16_t phoneBookSize_ = 0; // VCard size 34 bool newMissedCalls_ = false; 35 uint8_t newMissedCallsSize_ = 0; // New missed calls size 36 std::vector<uint8_t> primaryFolderVersion_ {}; // VCard PrimaryFolderVersion 16 bytes 37 std::vector<uint8_t> secondaryFolderVersion_ {}; // VCard SecondaryFolderVersion 16 bytes 38 std::vector<uint8_t> databaseIdentifier_ {}; // VCard DatabaseIdentifier 16 bytes 39 std::vector<uint8_t> result_ {}; // VCard bytes with utf-8 40 }; 41 static void SetDbFile(const std::string dbFile); 42 virtual ~PbapPseVcardManager() = default; 43 44 static void PullPhoneBook(std::u16string nameWithFolder, const PbapPseAppParams &pbapAppParams, 45 const uint32_t &supportedFeatures, PhoneBookResult &result); 46 static void PullvCardListing(std::u16string currentPath, std::u16string folderName, 47 const PbapPseAppParams &pbapAppParams, const uint32_t &supportedFeatures, PhoneBookResult &result); 48 static void PullvCardEntry(std::u16string currentPath, std::u16string entryId, 49 const PbapPseAppParams &pbapAppParams, const uint32_t &supportedFeatures, PhoneBookResult &result); 50 51 static bool CheckPhoneBookPath(std::u16string path); 52 static bool CheckVcardHandleId(const std::u16string &handleId); 53 static int VcardHandleId2Int(const std::u16string &handleId); 54 static std::vector<std::string> GetIncludeProperties(uint64_t propertySelector); 55 static bool IsSupportedFolderVer(const uint32_t &supportedFeatures); 56 static bool IsSupportedDbVer(const uint32_t &supportedFeatures); 57 static bool IsSupportedXBtUCI(const uint32_t &supportedFeatures); 58 static bool IsSupportedXBtUID(const uint32_t &supportedFeatures); 59 60 private: 61 PbapPseVcardManager() = default; 62 static std::string g_pbapDbFile; 63 static const std::map<std::u16string, std::u16string> VIRTUAL_VCF_FOLDER_MAP; 64 static const std::map<uint64_t, std::string> PROPERTY_MASK_MAP; 65 static const std::map<char16_t, uint8_t> VCARD_HANDLE_CHAR_MAP; 66 }; 67 } // namespace bluetooth 68 } // namespace OHOS 69 #endif // PBAP_PSE_VCARD_MANAGER_H 70