1 /*
2  * Copyright 2024 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 
17 #pragma once
18 
19 #include <bluetooth/log.h>
20 
21 #include <cstdint>
22 #include <memory>
23 
24 #include "avrcp_sdp_records.h"
25 
26 namespace bluetooth::avrcp {
27 
28 /**
29  * Service to add AVRCP sdp record for control and target services.
30  * Clients should use the singleton instance to add SDP records for the AVRCP
31  * service. The singleton instance assigns a unique handle for the respective
32  * services. This allows additive updates to the SDP records from different
33  * services.
34  */
35 class AvrcpSdpService {
36 public:
37   /**
38    * Creates an instance of the service. If instance is already created, then
39    * it returns the previous instance.
40    * @return singleton instance of the class.
41    */
42   static std::shared_ptr<AvrcpSdpService> Get();
43 
44   /**
45    * Add the sdp record for the service based on the UUID.
46    * @param add_sdp_record_request request to the add the sdp record.
47    * @param request_id unique request id that needs to be assigned.
48    * @return AVRC_SUCCESS if successful.
49    *         AVRC_FAIL otherwise
50    */
51   uint16_t AddRecord(const AvrcpSdpRecord& add_sdp_record_request, uint16_t& request_id);
52 
53   /**
54    * Enables the cover art dynamically for the Target SDP records. It also sets
55    * the cover art bit in the supported categories. Enabling cover art
56    * dynamically for Control SDP records is not supported yet.
57    * @param service_uuid service uuid for which the cover art needs to be
58    * enabled.
59    * @param cover_art_psm Hanle for the cover art psm.
60    * @param request_id id of the previous request for which cover art needs to be enabled.
61    * @return AVRC_SUCCESS if successful.
62    *         AVRC_FAIL otherwise
63    */
64   uint16_t EnableCovertArt(const uint16_t service_uuid, uint16_t cover_art_psm,
65                            const uint16_t request_id);
66 
67   /**
68    * Dynamically disable the cover art for Control SDP records. It also removes
69    * the cover art bit in the supported categories.
70    * @param service_uuid service UUID for which the cover art needs to be
71    * disabled.
72    * @param request_id id of the previous request for which cover art needs to be disabled.
73    * @return AVRC_SUCCESS if successful.
74    *         AVRC_FAIL otherwise
75    */
76   uint16_t DisableCovertArt(const uint16_t service_uuid, const uint16_t request_id);
77 
78   /**
79    * Removes the entire record for the corresponding service.
80    * @param service_uuid
81    * @param request_id id of the previous request that needs to be removed.
82    * @return AVRC_SUCCESS if successful.
83    *         AVRC_FAIL otherwise
84    */
85   uint16_t RemoveRecord(const uint16_t service_uuid, const uint16_t request_id);
86 
87   ~AvrcpSdpService() = default;
88 
89 private:
90   /**
91    * Helper instance to add the AVRCP Control SDP record for control service.
92    */
93   ControlAvrcSdpRecordHelper control_sdp_record_helper_;
94 
95   /**
96    * Helper instance to add the AVRCP Target SDP record for target service.
97    */
98   TargetAvrcSdpRecordHelper target_sdp_record_helper_;
99 
100   /**
101    * Singleton instance of the class.
102    */
103   static std::shared_ptr<AvrcpSdpService> instance_;
104 };
105 
106 }  // namespace bluetooth::avrcp
107