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 <map> 20 #include <string> 21 #include <vector> 22 23 #include <base/macros.h> 24 25 #include <android/bluetooth/BnBluetoothA2dpSource.h> 26 #include <android/bluetooth/IBluetoothA2dpSourceCallback.h> 27 28 #include "service/a2dp_source.h" 29 #include "service/ipc/binder/interface_with_instances_base.h" 30 31 namespace bluetooth { 32 class Adapter; 33 } // namespace bluetooth 34 35 namespace ipc { 36 namespace binder { 37 38 class BluetoothA2dpSourceBinderServer 39 : public InterfaceWithInstancesBase, 40 public android::bluetooth::BnBluetoothA2dpSource, 41 public bluetooth::A2dpSource::Delegate { 42 public: 43 explicit BluetoothA2dpSourceBinderServer(bluetooth::Adapter* adapter); 44 ~BluetoothA2dpSourceBinderServer() override; 45 46 bool HasInstance(); 47 48 // IBluetoothA2dpSource implementation: 49 android::binder::Status Register( 50 const android::sp<android::bluetooth::IBluetoothA2dpSourceCallback>& 51 callback, 52 bool* _aidl_return) override; 53 android::binder::Status Unregister() override; 54 android::binder::Status Enable( 55 const std::vector<android::bluetooth::BluetoothA2dpCodecConfig>& 56 codec_priorities, 57 bool* _aidl_return) override; 58 android::binder::Status Disable(bool* _aidl_return) override; 59 android::binder::Status Connect(const android::String16& device_address, 60 bool* _aidl_return) override; 61 android::binder::Status Disconnect(const android::String16& device_address, 62 bool* _aidl_return) override; 63 android::binder::Status ConfigCodec( 64 const android::String16& device_address, 65 const std::vector<android::bluetooth::BluetoothA2dpCodecConfig>& 66 codec_preferences, 67 bool* _aidl_return) override; 68 69 private: 70 // bluetooth::bluetooth::A2dpSource::Delegate implementation: 71 void OnConnectionState(const std::string& device_address, int state) override; 72 void OnAudioState(const std::string& device_address, int state) override; 73 void OnAudioConfig( 74 const std::string& device_address, 75 bluetooth::A2dpCodecConfig codec_config, 76 const std::vector<bluetooth::A2dpCodecConfig>& codecs_local_capabilities, 77 const std::vector<bluetooth::A2dpCodecConfig>& 78 codecs_selectable_capabilities) override; 79 80 android::sp<android::bluetooth::IBluetoothA2dpSourceCallback> 81 GetA2dpSourceCallback(); 82 std::shared_ptr<bluetooth::A2dpSource> GetA2dpSource(); 83 84 // InterfaceWithInstancesBase override: 85 void OnRegisterInstanceImpl(bluetooth::BLEStatus status, 86 android::sp<IInterface> callback, 87 bluetooth::BluetoothInstance* instance) override; 88 89 bluetooth::Adapter* const adapter_; // weak 90 91 DISALLOW_COPY_AND_ASSIGN(BluetoothA2dpSourceBinderServer); 92 }; 93 94 } // namespace binder 95 } // namespace ipc 96