• 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 "common/init_flags.h"
22 #include "device/include/esco_parameters.h"
23 #include "osi/include/properties.h"
24 
25 namespace hfp_hal_interface {
26 namespace {
27 bool offload_supported = true;
28 bool offload_enabled = true;
29 std::vector<bt_codec> cached_codecs;
30 }  // namespace
31 
32 // Android implementation only has consts. Initialize CVSD and MSBC to PCM
33 // offloaded defaults.
init()34 void init() {
35   bt_codec cvsd = {
36       .codec = codec::CVSD,
37       .data_path = ESCO_DATA_PATH_PCM,
38   };
39 
40   bt_codec msbc = {
41       .codec = codec::MSBC,
42       .data_path = ESCO_DATA_PATH_PCM,
43   };
44 
45   cached_codecs.clear();
46   cached_codecs.emplace_back(cvsd);
47   cached_codecs.emplace_back(msbc);
48 }
49 
50 // Android statically compiles WBS support.
get_wbs_supported()51 bool get_wbs_supported() { return !DISABLE_WBS; }
52 
get_swb_supported()53 bool get_swb_supported() {
54   return osi_property_get_bool("bluetooth.hfp.swb.supported", false) &&
55          bluetooth::common::init_flags::sco_codec_select_lc3_is_enabled();
56 }
57 
58 // Checks the supported codecs
get_codec_capabilities(uint64_t codecs)59 bt_codecs get_codec_capabilities(uint64_t codecs) {
60   bt_codecs codec_list = {.offload_capable = offload_supported};
61 
62   for (auto c : cached_codecs) {
63     if (c.codec & codecs) {
64       codec_list.codecs.push_back(c);
65     }
66   }
67 
68   return codec_list;
69 }
70 
71 // Check if hardware offload is supported
get_offload_supported()72 bool get_offload_supported() { return offload_supported; }
73 
74 // Check if hardware offload is enabled
get_offload_enabled()75 bool get_offload_enabled() { return offload_supported && offload_enabled; }
76 
77 // Set offload enable/disable
enable_offload(bool enable)78 bool enable_offload(bool enable) {
79   if (!offload_supported) {
80     return false;
81   }
82   offload_enabled = enable;
83   return true;
84 }
85 
86 // On Android, this is a no-op because the settings default to offloaded case.
set_codec_datapath(esco_coding_format_t coding_format)87 void set_codec_datapath(esco_coding_format_t coding_format) {}
88 
89 // No packet size limits on Android since it will be offloaded.
get_packet_size(int codec)90 int get_packet_size(int codec) { return kDefaultPacketSize; }
91 
notify_sco_connection_change(RawAddress device,bool is_connected,int codec)92 void notify_sco_connection_change(RawAddress device, bool is_connected,
93                                   int codec) {
94   // Do nothing since this is handled by Android's audio hidl.
95 }
96 
97 // On Android, this is a no-op because the settings default to work for Android.
update_esco_parameters(enh_esco_params_t * p_parms)98 void update_esco_parameters(enh_esco_params_t* p_parms) {}
99 }  // namespace hfp_hal_interface
100