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/BnBluetoothAvrcpControl.h" 25 #include "android/bluetooth/IBluetoothAvrcpControlCallback.h" 26 27 #include "service/avrcp_control.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 BluetoothAvrcpControlBinderServer 38 : public InterfaceWithInstancesBase, 39 public android::bluetooth::BnBluetoothAvrcpControl, 40 public bluetooth::AvrcpControl::Delegate { 41 public: 42 explicit BluetoothAvrcpControlBinderServer(bluetooth::Adapter* adapter); 43 ~BluetoothAvrcpControlBinderServer() override = default; 44 45 // IBluetoothAvrcpControl implementation: 46 android::binder::Status Register( 47 const android::sp<::android::bluetooth::IBluetoothAvrcpControlCallback>& 48 callback, 49 bool* _aidl_return) override; 50 android::binder::Status Unregister(int32_t id) override; 51 android::binder::Status UnregisterAll() override; 52 android::binder::Status Enable(int32_t id, bool* _aidl_return) override; 53 android::binder::Status Disable(int32_t id, bool* _aidl_return) override; 54 android::binder::Status SendPassThroughCommand( 55 int32_t id, const android::String16& device_address, int32_t key_code, 56 bool key_pressed, bool* _aidl_return) override; 57 android::binder::Status SetAbsVolumeResponse( 58 int32_t id, const android::String16& device_address, int32_t abs_vol, 59 int32_t label, bool* _aidl_return) override; 60 android::binder::Status RegisterForAbsVolumeCallbackResponse( 61 int32_t id, const android::String16& device_address, 62 int32_t response_type, int32_t abs_vol, int32_t label, 63 bool* _aidl_return) override; 64 65 private: 66 // bluetooth::bluetooth::AvrcpControl::Delegate implementation: 67 void OnConnectionState(bool rc_connect, bool bt_connect, 68 const std::string& device_address) override; 69 void OnTrackChanged(const std::string& device_address, 70 const bluetooth::AvrcpMediaAttr& attr) override; 71 void OnSetAbsVolumeRequest(const std::string& device_address, int32_t abs_vol, 72 int32_t label) override; 73 void OnRegisterForAbsVolumeCallbackRequest(const std::string& device_address, 74 int32_t label) override; 75 76 // InterfaceWithInstancesBase override: 77 void OnRegisterInstanceImpl(bluetooth::BLEStatus status, 78 android::sp<IInterface> callback, 79 bluetooth::BluetoothInstance* instance) override; 80 81 std::shared_ptr<bluetooth::AvrcpControl> GetAvrcpControl(int id); 82 83 bluetooth::Adapter* adapter_; // weak 84 85 DISALLOW_COPY_AND_ASSIGN(BluetoothAvrcpControlBinderServer); 86 }; 87 88 } // namespace binder 89 } // namespace ipc 90