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 22 #include <base/macros.h> 23 24 #include <android/bluetooth/BnBluetoothA2dpSink.h> 25 #include <android/bluetooth/IBluetoothA2dpSinkCallback.h> 26 27 #include "service/a2dp_sink.h" 28 #include "service/ipc/binder/interface_with_instances_base.h" 29 30 namespace bluetooth { 31 class Adapter; 32 } // namespace bluetooth 33 34 namespace ipc { 35 namespace binder { 36 37 class BluetoothA2dpSinkBinderServer 38 : public InterfaceWithInstancesBase, 39 public android::bluetooth::BnBluetoothA2dpSink, 40 public bluetooth::A2dpSink::Delegate { 41 public: 42 explicit BluetoothA2dpSinkBinderServer(bluetooth::Adapter* adapter); 43 ~BluetoothA2dpSinkBinderServer() override = default; 44 45 // IBluetoothA2dpSink implementation: 46 android::binder::Status Register( 47 const android::sp<android::bluetooth::IBluetoothA2dpSinkCallback>& 48 callback, 49 bool* _aidl_return) override; 50 android::binder::Status Enable(bool* _aidl_return) override; 51 android::binder::Status Disable(bool* _aidl_return) override; 52 android::binder::Status Unregister() override; 53 android::binder::Status Connect(const android::String16& device_address, 54 bool* _aidl_return) override; 55 android::binder::Status Disconnect(const android::String16& device_address, 56 bool* _aidl_return) override; 57 android::binder::Status SetAudioFocusState(int state, 58 bool* _aidl_return) override; 59 android::binder::Status SetAudioTrackGain(float gain, 60 bool* _aidl_return) override; 61 62 // bluetooth::bluetooth::A2dpSink::Delegate implementation: 63 void OnConnectionState(const std::string& device_address, int state) override; 64 void OnAudioState(const std::string& device_address, int state) override; 65 void OnAudioConfig(const std::string& device_address, uint32_t sample_rate, 66 uint8_t channel_count) override; 67 68 bool HasInstance(); 69 70 private: 71 android::sp<android::bluetooth::IBluetoothA2dpSinkCallback> 72 GetA2dpSinkCallback(); 73 std::shared_ptr<bluetooth::A2dpSink> GetA2dpSink(); 74 75 // InterfaceWithInstancesBase override: 76 void OnRegisterInstanceImpl(bluetooth::BLEStatus status, 77 android::sp<IInterface> callback, 78 bluetooth::BluetoothInstance* instance) override; 79 80 bluetooth::Adapter* adapter_; // weak 81 82 DISALLOW_COPY_AND_ASSIGN(BluetoothA2dpSinkBinderServer); 83 }; 84 85 } // namespace binder 86 } // namespace ipc 87