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_t.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_le_test_mode_cb = invoke_le_test_mode_cb,
40 .invoke_energy_info_cb = invoke_energy_info_cb,
41 .invoke_link_quality_report_cb = invoke_link_quality_report_cb,
42 .invoke_key_missing_cb = invoke_key_missing_cb,
43 .invoke_encryption_change_cb = invoke_encryption_change_cb};
44
45 // This interface lets us query for configuration properties of the stack that
46 // could change at runtime
47 struct MockConfigInterface : public bluetooth::core::ConfigInterface {
isA2DPOffloadEnabled__anon3d1d4e980111::MockConfigInterface48 virtual bool isA2DPOffloadEnabled() { return false; }
isAndroidTVDevice__anon3d1d4e980111::MockConfigInterface49 virtual bool isAndroidTVDevice() { return false; }
isRestrictedMode__anon3d1d4e980111::MockConfigInterface50 virtual bool isRestrictedMode() { return false; }
51 };
52
53 static auto mockConfigInterface = MockConfigInterface{};
54
55 // This interface lets us communicate with encoders used in profiles
56 struct MockMsbcCodecInterface : public bluetooth::core::CodecInterface {
initialize__anon3d1d4e980111::MockMsbcCodecInterface57 virtual void initialize() {}
cleanup__anon3d1d4e980111::MockMsbcCodecInterface58 virtual void cleanup() {}
59
encodePacket__anon3d1d4e980111::MockMsbcCodecInterface60 virtual uint32_t encodePacket(int16_t* /* input */, uint8_t* /* output */) { return 0; }
decodePacket__anon3d1d4e980111::MockMsbcCodecInterface61 virtual bool decodePacket(const uint8_t* /* i_buf */, int16_t* /* o_buf */,
62 size_t /* out_len */) {
63 return false;
64 }
65 };
66
67 struct MockLc3CodecInterface : public bluetooth::core::CodecInterface {
initialize__anon3d1d4e980111::MockLc3CodecInterface68 virtual void initialize() {}
cleanup__anon3d1d4e980111::MockLc3CodecInterface69 virtual void cleanup() {}
70
encodePacket__anon3d1d4e980111::MockLc3CodecInterface71 virtual uint32_t encodePacket(int16_t* /* input */, uint8_t* /* output */) { return 0; }
decodePacket__anon3d1d4e980111::MockLc3CodecInterface72 virtual bool decodePacket(const uint8_t* /* i_buf */, int16_t* /* o_buf */,
73 size_t /* out_len */) {
74 return false;
75 }
76 };
77
78 static auto mockMsbcCodecInterface = MockMsbcCodecInterface{};
79 static auto mockLc3CodecInterface = MockLc3CodecInterface{};
80
81 struct bluetooth::core::HACK_ProfileInterface HACK_profileInterface = {
82 // HID
83 .btif_hh_virtual_unplug = nullptr,
84 .bta_hh_read_ssr_param = nullptr,
85
86 // AVDTP
87 .btif_av_set_dynamic_audio_buffer_size = nullptr,
88
89 // ASHA
90 .GetHearingAidDeviceCount = nullptr,
91
92 // LE Audio
93 .IsLeAudioClientRunning = nullptr,
94
95 // AVRCP
96 .AVRC_GetProfileVersion = nullptr,
97 };
98
99 } // namespace
100
InitializeCoreInterface()101 void InitializeCoreInterface() {
102 static auto mockCoreInterface = MockCoreInterface{};
103 stack_manager_get_interface()->init_stack(&mockCoreInterface);
104 }
105
CleanCoreInterface()106 void CleanCoreInterface() {
107 stack_manager_get_interface()->clean_up_stack([] {});
108 }
109
MockCoreInterface()110 MockCoreInterface::MockCoreInterface()
111 : bluetooth::core::CoreInterface{&eventCallbacks, &mockConfigInterface, &mockMsbcCodecInterface,
112 &mockLc3CodecInterface, &HACK_profileInterface} {}
113
onBluetoothEnabled()114 void MockCoreInterface::onBluetoothEnabled() {}
115
toggleProfile(tBTA_SERVICE_ID,bool)116 bt_status_t MockCoreInterface::toggleProfile(tBTA_SERVICE_ID /* service_id */, bool /* enable */) {
117 return BT_STATUS_SUCCESS;
118 }
119
removeDeviceFromProfiles(const RawAddress &)120 void MockCoreInterface::removeDeviceFromProfiles(const RawAddress& /* bd_addr */) {}
121
onLinkDown(const RawAddress &,tBT_TRANSPORT)122 void MockCoreInterface::onLinkDown(const RawAddress& /* bd_addr */, tBT_TRANSPORT /* transport */) {
123 }
124