• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "btm_sco_hfp_hal.h"
18 
19 #include <vector>
20 
21 #include "device/include/esco_parameters.h"
22 #include "osi/include/properties.h"
23 
24 namespace hfp_hal_interface {
25 namespace {
26 bool offload_supported = true;
27 bool offload_enabled = true;
28 std::vector<bt_codec> cached_codecs;
29 }  // namespace
30 
31 // Android implementation only has consts. Initialize CVSD and MSBC to PCM
32 // offloaded defaults.
init()33 void init() {
34   bt_codec cvsd = {
35           .codec = codec::CVSD,
36           .data_path = ESCO_DATA_PATH_PCM,
37   };
38 
39   bt_codec msbc = {
40           .codec = codec::MSBC,
41           .data_path = ESCO_DATA_PATH_PCM,
42   };
43 
44   cached_codecs.clear();
45   cached_codecs.emplace_back(cvsd);
46   cached_codecs.emplace_back(msbc);
47 }
48 
49 // This is not used in Android.
is_coding_format_supported(esco_coding_format_t)50 bool is_coding_format_supported(esco_coding_format_t /* coding_format */) { return true; }
51 
52 // Android statically compiles WBS support.
get_wbs_supported()53 bool get_wbs_supported() { return true; }
54 
get_swb_supported()55 bool get_swb_supported() { return osi_property_get_bool("bluetooth.hfp.swb.supported", false); }
56 
57 // Checks the supported codecs
get_codec_capabilities(uint64_t codecs)58 bt_codecs get_codec_capabilities(uint64_t codecs) {
59   bt_codecs codec_list = {.offload_capable = offload_supported};
60 
61   for (auto c : cached_codecs) {
62     if (c.codec & codecs) {
63       codec_list.codecs.push_back(c);
64     }
65   }
66 
67   return codec_list;
68 }
69 
70 // Check if hardware offload is supported
get_offload_supported()71 bool get_offload_supported() { return offload_supported; }
72 
73 // Check if hardware offload is enabled
get_offload_enabled()74 bool get_offload_enabled() { return offload_supported && offload_enabled; }
75 
76 // Set offload enable/disable
enable_offload(bool enable)77 bool enable_offload(bool enable) {
78   if (!offload_supported) {
79     return false;
80   }
81   offload_enabled = enable;
82   return true;
83 }
84 
85 // On Android, this is a no-op because the settings default to offloaded case.
set_codec_datapath(tBTA_AG_UUID_CODEC)86 void set_codec_datapath(tBTA_AG_UUID_CODEC /* codec_uuid */) {}
87 
88 // No packet size limits on Android since it will be offloaded.
get_packet_size(int)89 size_t get_packet_size(int /* codec */) { return kDefaultPacketSize; }
90 
notify_sco_connection_change(RawAddress,bool,int)91 void notify_sco_connection_change(RawAddress /* device */, bool /* is_connected */,
92                                   int /* codec */) {
93   // Do nothing since this is handled by Android's audio hidl.
94 }
95 
96 // On Android, this is a no-op because the settings default to work for Android.
update_esco_parameters(enh_esco_params_t *)97 void update_esco_parameters(enh_esco_params_t* /* p_parms */) {}
98 }  // namespace hfp_hal_interface
99