1 // 2 // Copyright (C) 2017 Google, Inc. 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 #pragma once 18 19 #include <base/macros.h> 20 #include <base/observer_list.h> 21 22 #include "service/hal/bluetooth_av_interface.h" 23 24 namespace bluetooth { 25 namespace hal { 26 27 class FakeBluetoothAvInterface : public BluetoothAvInterface { 28 public: 29 // Handles HAL Bluetooth A2DP sink API calls for testing. Test code can 30 // provide a fake or mock implementation of this and all calls will be routed 31 // to it. 32 class TestA2dpSinkHandler { 33 public: 34 virtual bt_status_t Connect(RawAddress bda) = 0; 35 virtual bt_status_t Disconnect(RawAddress bda) = 0; 36 virtual void SetAudioFocusState(int focus_state) = 0; 37 virtual void SetAudioTrackGain(float gain) = 0; 38 39 protected: 40 virtual ~TestA2dpSinkHandler() = default; 41 }; 42 43 // Constructs the fake with the given handlers. Implementations can 44 // provide their own handlers or simply pass "nullptr" for the default 45 // behavior in which BT_STATUS_FAIL will be returned from all calls. 46 FakeBluetoothAvInterface( 47 std::shared_ptr<TestA2dpSinkHandler> a2dp_sink_handler); 48 ~FakeBluetoothAvInterface(); 49 50 // The methods below can be used to notify observers with certain events and 51 // given parameters. 52 53 // A2DP sink callbacks 54 void NotifyConnectionState(const RawAddress& bda, 55 btav_connection_state_t state); 56 void NotifyAudioState(const RawAddress& bda, btav_audio_state_t state); 57 void NotifyAudioConfig(const RawAddress& bda, uint32_t sample_rate, 58 uint8_t channel_count); 59 60 // BluetoothAvInterface overrides: 61 bool A2dpSourceEnable( 62 std::vector<btav_a2dp_codec_config_t> codec_priorities) override; 63 void A2dpSourceDisable() override; 64 bool A2dpSinkEnable() override; 65 void A2dpSinkDisable() override; 66 void AddA2dpSourceObserver(A2dpSourceObserver* observer) override; 67 void RemoveA2dpSourceObserver(A2dpSourceObserver* observer) override; 68 void AddA2dpSinkObserver(A2dpSinkObserver* observer) override; 69 void RemoveA2dpSinkObserver(A2dpSinkObserver* observer) override; 70 const btav_source_interface_t* GetA2dpSourceHALInterface() override; 71 const btav_sink_interface_t* GetA2dpSinkHALInterface() override; 72 73 private: 74 base::ObserverList<A2dpSourceObserver> a2dp_source_observers_; 75 base::ObserverList<A2dpSinkObserver> a2dp_sink_observers_; 76 std::shared_ptr<TestA2dpSinkHandler> scanner_handler_; 77 78 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothAvInterface); 79 }; 80 81 } // namespace hal 82 } // namespace bluetooth 83