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/BnBluetoothAvrcpTarget.h" 26 #include "android/bluetooth/IBluetoothAvrcpTargetCallback.h" 27 28 #include "service/avrcp_target.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 BluetoothAvrcpTargetBinderServer 39 : public InterfaceWithInstancesBase, 40 public android::bluetooth::BnBluetoothAvrcpTarget, 41 public bluetooth::AvrcpTarget::Delegate { 42 public: 43 explicit BluetoothAvrcpTargetBinderServer(bluetooth::Adapter* adapter); 44 ~BluetoothAvrcpTargetBinderServer() override; 45 46 bool HasInstance(); 47 48 // IBluetoothAvrcpTarget implementation: 49 android::binder::Status Register( 50 const android::sp<android::bluetooth::IBluetoothAvrcpTargetCallback>& 51 callback, 52 bool* _aidl_return) override; 53 android::binder::Status Unregister(int32_t id) override; 54 android::binder::Status UnregisterAll() override; 55 android::binder::Status Enable(bool* _aidl_return) override; 56 android::binder::Status Disable(bool* _aidl_return) override; 57 android::binder::Status GetPlayStatusResponse(const android::String16& addr, 58 int32_t play_status, 59 int32_t song_len, 60 int32_t song_pos, 61 bool* _aidl_return) override; 62 android::binder::Status ListPlayerAppAttrResponse( 63 const android::String16& addr, const std::vector<int32_t>& attrs, 64 bool* _aidl_return) override; 65 android::binder::Status GetPlayerAppValueResponse( 66 const android::String16& addr, 67 const std::vector<android::bluetooth::BluetoothAvrcpIntValue>& values, 68 bool* _aidl_return) override; 69 android::binder::Status GetPlayerAppAttrTextResponse( 70 const android::String16& addr, 71 const std::vector<android::bluetooth::BluetoothAvrcpStringValue>& attrs, 72 bool* _aidl_return) override; 73 android::binder::Status GetPlayerAppValueTextResponse( 74 const android::String16& addr, 75 const std::vector<android::bluetooth::BluetoothAvrcpStringValue>& values, 76 bool* _aidl_return) override; 77 android::binder::Status GetElementAttrResponse( 78 const android::String16& addr, 79 const std::vector<android::bluetooth::BluetoothAvrcpStringValue>& attrs, 80 bool* _aidl_return) override; 81 android::binder::Status SetPlayerAppValueResponse( 82 const android::String16& addr, int32_t rsp_status, 83 bool* _aidl_return) override; 84 android::binder::Status RegisterNotificationResponse( 85 int32_t event_id, int32_t type, 86 const android::bluetooth::BluetoothAvrcpRegisterNotificationResponse& 87 param, 88 bool* _aidl_return) override; 89 android::binder::Status SetVolume(int32_t volume, 90 bool* _aidl_return) override; 91 92 private: 93 // bluetooth::bluetooth::AvrcpTarget::Delegate implementation: 94 void OnGetRemoteFeatures(const std::string& addr, int32_t features) override; 95 void OnGetPlayStatus(const std::string& addr) override; 96 void OnListPlayerAppAttr(const std::string& addr) override; 97 void OnListPlayerAppValues(const std::string& addr, int32_t attr_id) override; 98 void OnGetPlayerAppValue(const std::string& addr, 99 const std::vector<int32_t>& attrs) override; 100 void OnGetPlayerAppAttrsText(const std::string& addr, 101 const std::vector<int32_t>& attrs) override; 102 void OnGetPlayerAppValuesText(const std::string& addr, int32_t attr_id, 103 const std::vector<int32_t>& values) override; 104 void OnSetPlayerAppValue( 105 const std::string& addr, 106 const std::vector<bluetooth::AvrcpIntValue>& values) override; 107 void OnGetElementAttrs(const std::string& addr, 108 const std::vector<int32_t>& attrs) override; 109 void OnRegisterNotification(const std::string& addr, int32_t event_id, 110 uint32_t param) override; 111 void OnVolumeChange(const std::string& addr, int32_t volume, 112 int32_t ctype) override; 113 void OnPassThroughCommand(const std::string& addr, int32_t id, 114 int32_t key_state) override; 115 116 // InterfaceWithInstancesBase override: 117 void OnRegisterInstanceImpl(bluetooth::BLEStatus status, 118 android::sp<IInterface> callback, 119 bluetooth::BluetoothInstance* instance) override; 120 121 android::sp<android::bluetooth::IBluetoothAvrcpTargetCallback> 122 GetAvrcpTargetCallback(); 123 std::shared_ptr<bluetooth::AvrcpTarget> GetAvrcpTarget(); 124 125 bluetooth::Adapter* const adapter_; // weak 126 127 DISALLOW_COPY_AND_ASSIGN(BluetoothAvrcpTargetBinderServer); 128 }; 129 130 } // namespace binder 131 } // namespace ipc 132