avrcp_service.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2018 The Android Open Source Project
  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. #pragma once
  17. #include <map>
  18. #include <memory>
  19. #include "hardware/avrcp/avrcp.h"
  20. #include "osi/include/properties.h"
  21. #include "profile/avrcp/connection_handler.h"
  22. #include "raw_address.h"
  23. namespace bluetooth {
  24. namespace avrcp {
  25. /**
  26. * AvrcpService is the management interface for AVRCP Target. It handles any
  27. * required thread switching, interface registration, and provides an API
  28. * for connecting and disconnecting devices.
  29. * TODO (apanicke): Instead of providing a service interface implementation,
  30. * have the AvrcpService itself be its interface so we don't have to access
  31. * it indirectly.
  32. */
  33. class AvrcpService : public MediaCallbacks {
  34. public:
  35. /**
  36. * Gets a handle to the AvrcpService
  37. *
  38. * Currently used by A2DP to tell AVRCP to initiate a connection to the
  39. * remote device.
  40. */
  41. static AvrcpService* Get();
  42. /**
  43. * Returns an interface to control this service. The Avrcp::ServiceInterface
  44. * handles all thread switching between the caller thread and the thread the
  45. * service runs on, that way whoever uses the interface doesn't need to be
  46. * aware which thread the service runs on.
  47. */
  48. static ServiceInterface* GetServiceInterface();
  49. void Init(MediaInterface* media_interface, VolumeInterface* volume_interface);
  50. void Cleanup();
  51. void ConnectDevice(const RawAddress& bdaddr);
  52. void DisconnectDevice(const RawAddress& bdaddr);
  53. // Functions inherited from MediaCallbacks in order to receive updates
  54. void SendMediaUpdate(bool track_changed, bool play_state,
  55. bool queue) override;
  56. void SendFolderUpdate(bool available_players, bool addressed_player,
  57. bool queue) override;
  58. void SendActiveDeviceChanged(const RawAddress& address) override;
  59. class ServiceInterfaceImpl : public ServiceInterface {
  60. public:
  61. void Init(MediaInterface* media_interface,
  62. VolumeInterface* volume_interface) override;
  63. bool ConnectDevice(const RawAddress& bdaddr) override;
  64. bool DisconnectDevice(const RawAddress& bdaddr) override;
  65. bool Cleanup() override;
  66. private:
  67. std::mutex service_interface_lock_;
  68. };
  69. static void DebugDump(int fd);
  70. protected:
  71. void DeviceCallback(std::shared_ptr<Device> device);
  72. private:
  73. static AvrcpService* instance_;
  74. static ServiceInterfaceImpl* service_interface_;
  75. MediaInterface* media_interface_ = nullptr;
  76. VolumeInterface* volume_interface_ = nullptr;
  77. ConnectionHandler* connection_handler_;
  78. };
  79. } // namespace avrcp
  80. } // namespace bluetooth
  81. inline bool is_new_avrcp_enabled() {
  82. return osi_property_get_bool("persist.bluetooth.enablenewavrcp", true);
  83. }