1 /*
2 * Copyright (C) 2021-2022 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 #include "profile_info.h"
17
18 #include <algorithm>
19
20 #include "adapter_config.h"
21 #include "interface_profile.h"
22
23 namespace OHOS {
24 namespace bluetooth {
25 const std::vector<ProfileInfo> SupportProfilesInfo::SUPPORT_FILES = {
26 ProfileInfo(PROFILE_NAME_GATT_CLIENT, PROFILE_ID_GATT_CLIENT, BLUETOOTH_UUID_GATT),
27 ProfileInfo(PROFILE_NAME_GATT_SERVER, PROFILE_ID_GATT_SERVER, BLUETOOTH_UUID_GATT),
28 ProfileInfo(PROFILE_NAME_A2DP_SRC, PROFILE_ID_A2DP_SRC, BLUETOOTH_UUID_A2DP_SRC),
29 ProfileInfo(PROFILE_NAME_A2DP_SINK, PROFILE_ID_A2DP_SINK, BLUETOOTH_UUID_A2DP_SINK),
30 ProfileInfo(PROFILE_NAME_AVRCP_CT, PROFILE_ID_AVRCP_CT, BLUETOOTH_UUID_AVRCP_CT),
31 ProfileInfo(PROFILE_NAME_AVRCP_TG, PROFILE_ID_AVRCP_TG, BLUETOOTH_UUID_AVRCP_TG),
32 ProfileInfo(PROFILE_NAME_HFP_AG, PROFILE_ID_HFP_AG, BLUETOOTH_UUID_HFP_AG),
33 ProfileInfo(PROFILE_NAME_HFP_HF, PROFILE_ID_HFP_HF, BLUETOOTH_UUID_HFP_HF),
34 ProfileInfo(PROFILE_NAME_MAP_MCE, PROFILE_ID_MAP_MCE, ""),
35 ProfileInfo(PROFILE_NAME_MAP_MSE, PROFILE_ID_MAP_MSE, ""),
36 ProfileInfo(PROFILE_NAME_PBAP_PCE, PROFILE_ID_PBAP_PCE, BLUETOOTH_UUID_PBAP_PCE),
37 ProfileInfo(PROFILE_NAME_PBAP_PSE, PROFILE_ID_PBAP_PSE, BLUETOOTH_UUID_PBAP_PSE),
38 ProfileInfo(PROFILE_NAME_SPP, PROFILE_ID_SPP, BLUETOOTH_UUID_SPP),
39 ProfileInfo(PROFILE_NAME_DI, PROFILE_ID_DI, BLUETOOTH_UUID_PNP),
40 ProfileInfo(PROFILE_NAME_HID_HOST, PROFILE_ID_HID_HOST, BLUETOOTH_UUID_HID_HOST),
41 ProfileInfo(PROFILE_NAME_PAN, PROFILE_ID_PAN, BLUETOOTH_UUID_PAN),
42 ProfileInfo(PROFILE_NAME_OPP, PROFILE_ID_OPP, BLUETOOTH_UUID_OPP),
43 };
44
GetSupportProfiles()45 const std::vector<ProfileInfo> &SupportProfilesInfo::GetSupportProfiles()
46 {
47 return SUPPORT_FILES;
48 }
49
IdToName(uint32_t id)50 std::string SupportProfilesInfo::IdToName(uint32_t id)
51 {
52 auto it = std::find_if(
53 SUPPORT_FILES.begin(), SUPPORT_FILES.end(), [id](ProfileInfo pInfo) -> bool { return id == pInfo.id_; });
54 if (it != SUPPORT_FILES.end()) {
55 return it->name_;
56 } else {
57 return "";
58 }
59 }
60
GetConfigSupportProfiles(BTTransport transport)61 const std::vector<ProfileInfo> SupportProfilesInfo::GetConfigSupportProfiles(BTTransport transport)
62 {
63 std::vector<ProfileInfo> retProfiles;
64 retProfiles.clear();
65 std::string section = (transport == BTTransport::ADAPTER_BREDR) ? SECTION_CLASSIC_ADAPTER : SECTION_BLE_ADAPTER;
66
67 for (auto &sp : SUPPORT_FILES) {
68 bool value = false;
69 AdapterConfig::GetInstance()->GetValue(section, sp.name_, value);
70 if (value) {
71 retProfiles.push_back(sp);
72 }
73 }
74 return retProfiles;
75 }
76 } // namespace bluetooth
77 } // namespace OHOS