• 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 "core_interface.h"
18 
19 #include "btif/include/btif_common.h"
20 #include "btif/include/core_callbacks.h"
21 #include "btif/include/stack_manager.h"
22 
23 namespace {
24 
25 static bluetooth::core::EventCallbacks eventCallbacks = {
26     .invoke_adapter_state_changed_cb = invoke_adapter_state_changed_cb,
27     .invoke_adapter_properties_cb = invoke_adapter_properties_cb,
28     .invoke_remote_device_properties_cb = invoke_remote_device_properties_cb,
29     .invoke_device_found_cb = invoke_device_found_cb,
30     .invoke_discovery_state_changed_cb = invoke_discovery_state_changed_cb,
31     .invoke_pin_request_cb = invoke_pin_request_cb,
32     .invoke_ssp_request_cb = invoke_ssp_request_cb,
33     .invoke_oob_data_request_cb = invoke_oob_data_request_cb,
34     .invoke_bond_state_changed_cb = invoke_bond_state_changed_cb,
35     .invoke_address_consolidate_cb = invoke_address_consolidate_cb,
36     .invoke_le_address_associate_cb = invoke_le_address_associate_cb,
37     .invoke_acl_state_changed_cb = invoke_acl_state_changed_cb,
38     .invoke_thread_evt_cb = invoke_thread_evt_cb,
39     .invoke_energy_info_cb = invoke_energy_info_cb,
40     .invoke_link_quality_report_cb = invoke_link_quality_report_cb};
41 
42 // This interface lets us query for configuration properties of the stack that
43 // could change at runtime
44 struct MockConfigInterface : public bluetooth::core::ConfigInterface {
isA2DPOffloadEnabled__anon718c90070111::MockConfigInterface45   virtual bool isA2DPOffloadEnabled() { return false; }
isAndroidTVDevice__anon718c90070111::MockConfigInterface46   virtual bool isAndroidTVDevice() { return false; }
isRestrictedMode__anon718c90070111::MockConfigInterface47   virtual bool isRestrictedMode() { return false; }
48 };
49 
50 static auto mockConfigInterface = MockConfigInterface{};
51 
52 // This interface lets us communicate with encoders used in profiles
53 struct MockCodecInterface : public bluetooth::core::CodecInterface {
initialize__anon718c90070111::MockCodecInterface54   virtual void initialize(){};
cleanup__anon718c90070111::MockCodecInterface55   virtual void cleanup() {}
56 
encodePacket__anon718c90070111::MockCodecInterface57   virtual uint32_t encodePacket(int16_t* input, uint8_t* output) { return 0; };
decodePacket__anon718c90070111::MockCodecInterface58   virtual bool decodePacket(const uint8_t* i_buf, int16_t* o_buf,
59                             size_t out_len) {
60     return false;
61   };
62 };
63 
64 static auto mockCodecInterface = MockCodecInterface{};
65 
66 struct bluetooth::core::HACK_ProfileInterface HACK_profileInterface = {
67     // HID
68     .btif_hh_connect = nullptr,
69     .btif_hh_virtual_unplug = nullptr,
70     .bta_hh_read_ssr_param = nullptr,
71 
72     // AVDTP
73     .btif_av_set_dynamic_audio_buffer_size = nullptr,
74 
75     // ASHA
76     .GetHearingAidDeviceCount = nullptr,
77 
78     // LE Audio
79     .IsLeAudioClientRunning = nullptr,
80 
81     // AVRCP
82     .AVRC_GetProfileVersion = nullptr,
83 };
84 
85 }  // namespace
86 
InitializeCoreInterface()87 void InitializeCoreInterface() {
88   static auto mockCoreInterface = MockCoreInterface{};
89   stack_manager_get_interface()->init_stack(&mockCoreInterface);
90 }
91 
CleanCoreInterface()92 void CleanCoreInterface() {
93   stack_manager_get_interface()->clean_up_stack([] {});
94 }
95 
MockCoreInterface()96 MockCoreInterface::MockCoreInterface()
97     : bluetooth::core::CoreInterface{&eventCallbacks, &mockConfigInterface,
98                                      &mockCodecInterface,
99                                      &HACK_profileInterface} {};
100 
onBluetoothEnabled()101 void MockCoreInterface::onBluetoothEnabled(){};
102 
toggleProfile(tBTA_SERVICE_ID service_id,bool enable)103 bt_status_t MockCoreInterface::toggleProfile(tBTA_SERVICE_ID service_id,
104                                              bool enable) {
105   return BT_STATUS_SUCCESS;
106 };
107 
removeDeviceFromProfiles(const RawAddress & bd_addr)108 void MockCoreInterface::removeDeviceFromProfiles(const RawAddress& bd_addr){};
109 
onLinkDown(const RawAddress & bd_addr)110 void MockCoreInterface::onLinkDown(const RawAddress& bd_addr){};
111