• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "avrcp_ct_service.h"
17 #include "adapter_config.h"
18 #include "avrcp_ct_internal.h"
19 #include "class_creator.h"
20 #include "profile_service_manager.h"
21 
22 namespace OHOS {
23 namespace bluetooth {
AvrcpCtService()24 AvrcpCtService::AvrcpCtService() : utility::Context(PROFILE_NAME_AVRCP_CT, "1.6.2")
25 {
26     HILOGI("enter");
27     /// Need to set the features of the AVRCP CT service.
28     InitFeatures();
29     using namespace std::placeholders;
30     AvrcCtProfile::Observer observer = {
31         std::bind(&AvrcpCtService::OnProfileDisabled, this, BT_SUCCESS),
32         std::bind(&AvrcpCtService::OnConnectionStateChanged, this, _1, _2),
33         std::bind(&AvrcpCtService::OnButtonPressed, this, _1, _2, _3),
34         std::bind(&AvrcpCtService::OnButtonReleased, this, _1, _2, _3),
35         std::bind(&AvrcpCtService::OnGetCapabilities, this, _1, _2, _3, _4),
36         std::bind(&AvrcpCtService::OnGetPlayerAppSettingAttribtues, this, _1, _2, _3),
37         std::bind(&AvrcpCtService::OnGetPlayerAppSettingValues, this, _1, _2, _3, _4),
38         std::bind(&AvrcpCtService::OnGetPlayerAppSettingCurrentValue, this, _1, _2, _3, _4),
39         std::bind(&AvrcpCtService::OnSetPlayerAppSettingCurrentValue, this, _1, _2),
40         std::bind(&AvrcpCtService::OnGetPlayerAppSettingAttributeText, this, _1, _2, _3, _4),
41         std::bind(&AvrcpCtService::OnGetPlayerAppSettingValueText, this, _1, _2, _3, _4),
42         std::bind(&AvrcpCtService::OnGetElementAttributes, this, _1, _2, _3, _4),
43         std::bind(&AvrcpCtService::OnGetPlayStatus, this, _1, _2, _3, _4, _5),
44         std::bind(&AvrcpCtService::OnSetAddressedPlayer, this, _1, _2, _3),
45         std::bind(&AvrcpCtService::OnSetBrowsedPlayer, this, _1, _2, _3, _4, _5, _6),
46         std::bind(&AvrcpCtService::OnChangePath, this, _1, _2, _3, _4),
47         std::bind(&AvrcpCtService::OnGetFolderItems, this, _1, _2, _3, _4, _5, _6, _7),
48         std::bind(&AvrcpCtService::OnGetItemAttributes, this, _1, _2, _3, _4, _5),
49         std::bind(&AvrcpCtService::OnGetTotalNumberOfItems, this, _1, _2, _3, _4, _5),
50         std::bind(&AvrcpCtService::OnPlayItem, this, _1, _2, _3),
51         std::bind(&AvrcpCtService::OnAddToNowPlaying, this, _1, _2, _3),
52         std::bind(&AvrcpCtService::OnSetAbsoluteVolume, this, _1, _2, _3),
53         std::bind(&AvrcpCtService::OnPlaybackStatusChanged, this, _1, _2, _3),
54         std::bind(&AvrcpCtService::OnTrackChanged, this, _1, _2, _3),
55         std::bind(&AvrcpCtService::OnTrackReachedEnd, this, _1, _2),
56         std::bind(&AvrcpCtService::OnTrackReachedStart, this, _1, _2),
57         std::bind(&AvrcpCtService::OnPlaybackPosChanged, this, _1, _2, _3),
58         std::bind(&AvrcpCtService::OnPlayerApplicationSettingChanged, this, _1, _2, _3, _4),
59         std::bind(&AvrcpCtService::OnNowPlayingContentChanged, this, _1, _2),
60         std::bind(&AvrcpCtService::OnAvailablePlayersChanged, this, _1, _2),
61         std::bind(&AvrcpCtService::OnAddressedPlayerChanged, this, _1, _2, _3, _4),
62         std::bind(&AvrcpCtService::OnUidChanged, this, _1, _2, _3),
63         std::bind(&AvrcpCtService::OnVolumeChanged, this, _1, _2, _3),
64     };
65     pfObserver_ = std::make_unique<AvrcCtProfile::Observer>(observer);
66 }
67 
~AvrcpCtService()68 AvrcpCtService::~AvrcpCtService()
69 {
70     HILOGI("enter");
71 
72     SetServiceState(AVRC_CT_SERVICE_STATE_DISABLED);
73 
74     myObserver_ = nullptr;
75 }
76 
GetContext()77 utility::Context *AvrcpCtService::GetContext()
78 {
79     HILOGI("enter");
80 
81     return this;
82 }
83 
InitFeatures()84 void AvrcpCtService::InitFeatures()
85 {
86     HILOGI("enter");
87 
88     features_ |= AVRC_CT_FEATURE_CATEGORY_1;
89     features_ |= AVRC_CT_FEATURE_CATEGORY_2;
90     features_ |= AVRC_CT_FEATURE_BROWSING;
91     features_ |= AVRC_CT_FEATURE_KEY_OPERATION;
92     features_ |= AVRC_CT_FEATURE_ABSOLUTE_VOLUME;
93     features_ |= AVRC_CT_FEATURE_NOTIFY_PLAYBACK_STATUS_CHANGED;
94     features_ |= AVRC_CT_FEATURE_NOTIFY_TRACK_REACHED_END;
95     features_ |= AVRC_CT_FEATURE_NOTIFY_TRACK_REACHED_START;
96     features_ |= AVRC_CT_FEATURE_NOTIFY_PLAYBACK_POSITION_CHANGED;
97     features_ |= AVRC_CT_FEATURE_NOTIFY_PLAYER_SETTING_CHANGED;
98     features_ |= AVRC_CT_FEATURE_NOTIFY_NOW_PLAYING_CONTENT_CHANGED;
99     features_ |= AVRC_CT_FEATURE_NOTIFY_UIDS_CHANGED;
100     features_ |= AVRC_CT_FEATURE_NOTIFY_ABSOLUTE_VOLUME_CHANGED;
101 }
102 
103 /******************************************************************
104  * REGISTER / UNREGISTER OBSERVER                                 *
105  ******************************************************************/
106 
RegisterObserver(IObserver * observer)107 void AvrcpCtService::RegisterObserver(IObserver *observer)
108 {
109     HILOGI("enter");
110 
111     std::lock_guard<std::mutex> lock(mutex_);
112 
113     myObserver_ = observer;
114 }
115 
UnregisterObserver(void)116 void AvrcpCtService::UnregisterObserver(void)
117 {
118     HILOGI("enter");
119 
120     std::lock_guard<std::mutex> lock(mutex_);
121 
122     myObserver_ = nullptr;
123 }
124 
125 /******************************************************************
126  * ENABLE / DISABLE                                               *
127  ******************************************************************/
128 
Enable(void)129 void AvrcpCtService::Enable(void)
130 {
131     HILOGI("enter");
132 
133     if (IsDisabled()) {
134         SetServiceState(AVRC_CT_SERVICE_STATE_ENABLING);
135 
136         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::EnableNative, this));
137     } else {
138         LOG_ERROR("Is not disabled!");
139     }
140 }
141 
Disable(void)142 void AvrcpCtService::Disable(void)
143 {
144     HILOGI("enter");
145 
146     if (IsEnabled()) {
147         SetServiceState(AVRC_CT_SERVICE_STATE_DISABLING);
148         if (profile_ != nullptr) {
149             profile_->SetEnableFlag(false);
150         }
151 
152         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::DisableNative, this));
153     } else {
154         LOG_ERROR("Is not enable!");
155     }
156 }
157 
EnableNative(void)158 void AvrcpCtService::EnableNative(void)
159 {
160     HILOGI("enter");
161 
162     int result = RET_BAD_STATUS;
163 
164     IAdapterConfig *config = AdapterConfig::GetInstance();
165     config->GetValue(SECTION_AVRCP_CT_SERVICE, PROPERTY_MAX_CONNECTED_DEVICES, maxConnection_);
166 
167     do {
168         result = RegisterSecurity();
169         if (result != BT_SUCCESS) {
170             break;
171         }
172         result = RegisterService();
173         if (result != BT_SUCCESS) {
174             break;
175         }
176         result = EnableProfile();
177         if (result != BT_SUCCESS) {
178             break;
179         }
180     } while (false);
181 
182     if (result == BT_SUCCESS) {
183         SetServiceState(AVRC_CT_SERVICE_STATE_ENABLED);
184     } else {
185         SetServiceState(AVRC_CT_SERVICE_STATE_DISABLED);
186     }
187     GetContext()->OnEnable(PROFILE_NAME_AVRCP_CT, IsEnabled());
188     HILOGI("AvrcpCtService:: AVRCP is ENABLED");
189 }
190 
DisableNative(void)191 void AvrcpCtService::DisableNative(void)
192 {
193     HILOGI("enter");
194 
195     if (DisableProfile() != BT_SUCCESS) {
196         OnProfileDisabled(RET_BAD_STATUS);
197     }
198 }
199 
EnableProfile(void)200 int AvrcpCtService::EnableProfile(void)
201 {
202     HILOGI("enter");
203 
204     /// Gets the size of the MTU.
205     int controlMtu = AVRC_CT_DEFAULT_CONTROL_MTU_SIZE;
206     int browseMtu = AVRC_CT_DEFAULT_BROWSE_MTU_SIZE;
207     bool isTgEnabled = false;
208 
209     IAdapterConfig *config = AdapterConfig::GetInstance();
210     config->GetValue(SECTION_AVRCP_CT_SERVICE, PROPERTY_CONTROL_MTU, controlMtu);
211     config->GetValue(SECTION_AVRCP_CT_SERVICE, PROPERTY_BROWSE_MTU, browseMtu);
212     config->GetValue(SECTION_CLASSIC_ADAPTER, PROPERTY_AVRCP_TG_SERVICE, isTgEnabled);
213 
214     profile_ = std::make_unique<AvrcCtProfile>(features_ & AVRC_CT_SDP_ALL_SUPPORTED_FEATURES,
215         AVRC_CT_DEFAULT_BLUETOOTH_SIG_COMPANY_ID,
216         controlMtu,
217         browseMtu,
218         AVRC_CT_DEFAULT_MAX_FRAGMENTS,
219         GetDispatcher(),
220         ChannelEventCallback,
221         ChannelMessageCallback);
222     profile_->RegisterObserver(pfObserver_.get());
223 
224     return profile_->Enable(isTgEnabled);
225 }
226 
DisableProfile(void) const227 int AvrcpCtService::DisableProfile(void) const
228 {
229     HILOGI("enter");
230 
231     return profile_->Disable();
232 }
233 
OnProfileDisabled(int result)234 void AvrcpCtService::OnProfileDisabled(int result)
235 {
236     HILOGI("result: %{public}d", result);
237 
238     SetServiceState(AVRC_CT_SERVICE_STATE_DISABLED);
239 
240     profile_->UnregisterObserver();
241     profile_ = nullptr;
242 
243     result |= UnregisterService();
244     result |= UnregisterSecurity();
245 
246     GetContext()->OnDisable(PROFILE_NAME_AVRCP_CT, result == BT_SUCCESS);
247 }
248 
RegisterSecurity(void)249 int AvrcpCtService::RegisterSecurity(void)
250 {
251     HILOGI("enter");
252 
253     gapManager_ = std::make_unique<AvrcCtGapManager>();
254 
255     return gapManager_->RegisterSecurity();
256 }
257 
UnregisterSecurity(void)258 int AvrcpCtService::UnregisterSecurity(void)
259 {
260     HILOGI("enter");
261 
262     int result = gapManager_->UnregisterSecurity();
263     gapManager_ = nullptr;
264 
265     return result;
266 }
267 
RegisterService(void)268 int AvrcpCtService::RegisterService(void)
269 {
270     HILOGI("enter");
271 
272     sdpManager_ = std::make_unique<AvrcCtSdpManager>(features_ & AVRC_CT_SDP_ALL_SUPPORTED_FEATURES);
273 
274     return sdpManager_->RegisterService();
275 }
276 
UnregisterService(void)277 int AvrcpCtService::UnregisterService(void)
278 {
279     HILOGI("enter");
280 
281     int result = sdpManager_->UnregisterService();
282     sdpManager_ = nullptr;
283 
284     return result;
285 }
286 
IsEnabled(void)287 bool AvrcpCtService::IsEnabled(void)
288 {
289     HILOGI("enter");
290 
291     return (state_ == AVRC_CT_SERVICE_STATE_ENABLED);
292 }
293 
IsDisabled(void)294 bool AvrcpCtService::IsDisabled(void)
295 {
296     HILOGI("enter");
297 
298     return (state_ == AVRC_CT_SERVICE_STATE_DISABLED);
299 }
300 
SetServiceState(uint8_t state)301 void AvrcpCtService::SetServiceState(uint8_t state)
302 {
303     HILOGI("state: %{public}d", state);
304 
305     state_ = state;
306 }
307 
308 /******************************************************************
309  * CONNECTION                                                     *
310  ******************************************************************/
311 
GetConnectedDevices(void)312 std::vector<RawAddress> AvrcpCtService::GetConnectedDevices(void)
313 {
314     HILOGI("enter");
315 
316     std::vector<RawAddress> result;
317 
318     if (IsEnabled()) {
319         result = profile_->GetConnectedDevices();
320     }
321 
322     return result;
323 }
324 
GetDevicesByStates(const std::vector<int> & states)325 std::vector<bluetooth::RawAddress> AvrcpCtService::GetDevicesByStates(const std::vector<int> &states)
326 {
327     HILOGI("enter");
328 
329     std::vector<bluetooth::RawAddress> result;
330 
331     if (IsEnabled()) {
332         result = profile_->GetDevicesByStates(states);
333     }
334 
335     return result;
336 }
337 
GetMaxConnectNum(void)338 int AvrcpCtService::GetMaxConnectNum(void)
339 {
340     HILOGI("enter");
341 
342     int result = 0;
343 
344     if (IsEnabled()) {
345         result = profile_->GetMaxConnectNum();
346     }
347 
348     HILOGI("result: %{public}d", result);
349     return result;
350 }
351 
GetDeviceState(const RawAddress & rawAddr)352 int AvrcpCtService::GetDeviceState(const RawAddress &rawAddr)
353 {
354     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
355 
356     int result = static_cast<int>(BTConnectState::DISCONNECTED);
357 
358     if (IsEnabled()) {
359         result = profile_->GetDeviceState(rawAddr);
360     }
361 
362     HILOGI("result: %{public}d", result);
363     return result;
364 }
365 
Connect(const RawAddress & rawAddr)366 int AvrcpCtService::Connect(const RawAddress &rawAddr)
367 {
368     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
369 
370     int result = RET_BAD_STATUS;
371 
372     do {
373         if (!IsEnabled()) {
374             break;
375         }
376 
377         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::DISCONNECTED)) {
378             break;
379         }
380 
381         if (!CheckConnectionNum()) {
382             break;
383         }
384 
385         RawAddress peerAddr(rawAddr.GetAddress());
386         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::ConnectNative, this, peerAddr));
387         result = BT_SUCCESS;
388     } while (false);
389 
390     return result;
391 }
392 
ConnectNative(RawAddress rawAddr)393 void AvrcpCtService::ConnectNative(RawAddress rawAddr)
394 {
395     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
396 
397     AcceptActiveConnect(rawAddr);
398 }
399 
Disconnect(const RawAddress & rawAddr)400 int AvrcpCtService::Disconnect(const RawAddress &rawAddr)
401 {
402     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
403 
404     int result = RET_BAD_STATUS;
405 
406     do {
407         if (!IsEnabled()) {
408             break;
409         }
410 
411         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
412             break;
413         }
414 
415         RawAddress peerAddr(rawAddr.GetAddress());
416         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::DisconnectNative, this, peerAddr));
417         result = BT_SUCCESS;
418     } while (false);
419 
420     return result;
421 }
422 
DisconnectNative(RawAddress rawAddr)423 void AvrcpCtService::DisconnectNative(RawAddress rawAddr)
424 {
425     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
426 
427     do {
428         if (!IsEnabled()) {
429             break;
430         }
431 
432         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
433             break;
434         }
435 
436         if (profile_->Disconnect(rawAddr) != BT_SUCCESS) {
437             HILOGI("Disconnect Failed! Addr: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
438         }
439     } while (false);
440 }
441 
GetConnectState(void)442 int AvrcpCtService::GetConnectState(void)
443 {
444     HILOGI("enter");
445 
446     int result = PROFILE_STATE_DISCONNECTED;
447 
448     if (IsEnabled()) {
449         result = profile_->GetConnectState();
450     }
451 
452     return result;
453 }
454 
OnConnectionStateChanged(const RawAddress & rawAddr,int state) const455 void AvrcpCtService::OnConnectionStateChanged(const RawAddress &rawAddr, int state) const
456 {
457     HILOGI("Address: %{public}s, state: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), state);
458 
459     if (myObserver_ != nullptr) {
460         myObserver_->OnConnectionStateChanged(rawAddr, state);
461     } else {
462         HILOGI("The observer is not registered!");
463     }
464 }
465 
AcceptActiveConnect(const RawAddress & rawAddr)466 void AvrcpCtService::AcceptActiveConnect(const RawAddress &rawAddr)
467 {
468     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
469 
470     do {
471         if (!IsEnabled()) {
472             break;
473         }
474 
475         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::DISCONNECTED)) {
476             break;
477         }
478 
479         if (profile_->Connect(rawAddr) != BT_SUCCESS) {
480             HILOGI("Connect Failed! Addr: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
481         }
482     } while (false);
483 }
484 
RejectActiveConnect(const RawAddress & rawAddr) const485 void AvrcpCtService::RejectActiveConnect(const RawAddress &rawAddr) const
486 {
487     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
488 }
489 
490 // Parse AVRCP SDP Information
491 // supports browsing || supports advanced control
ParseSDPInformation(const BtAddr * btAddr,const SdpService * serviceArray,uint16_t serviceNum)492 void AvrcpCtService::ParseSDPInformation(
493     const BtAddr *btAddr, const SdpService *serviceArray, uint16_t serviceNum)
494 {
495     HILOGI("serviceNum(%{public}d)\n", serviceNum);
496 
497     uint16_t peerFeatures = 0;
498     uint16_t peerAvrcpVersion = 0;
499 
500     for (int i = 0; i < serviceNum; i++) {
501         HILOGI("uuid16: %{public}4x\n", serviceArray[i].classId->uuid16);
502         if (serviceArray[i].classId->uuid16 == AVRC_CT_AV_REMOTE_CONTROL_TARGET) {
503             peerAvrcpVersion = serviceArray[i].profileDescriptor->versionNumber;
504             HILOGI("peerAvrcpVersion: %{public}x\n", peerAvrcpVersion);
505             if (peerAvrcpVersion >= AVCT_REV_1_4) {
506                 peerFeatures = *(uint16_t*)serviceArray[i].attribute[0].attributeValue;
507                 HILOGI("peerFeatures: %{public}x\n", peerFeatures);
508             }
509         }
510     }
511 }
512 
FindTgService(const RawAddress & rawAddr) const513 int AvrcpCtService::FindTgService(const RawAddress &rawAddr) const
514 {
515     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
516 
517     return sdpManager_->FindTgService(rawAddr, FindTgServiceCallback);
518 }
519 
FindTgServiceCallback(const BtAddr * btAddr,const SdpService * serviceArray,uint16_t serviceNum,void * context)520 void AvrcpCtService::FindTgServiceCallback(
521     const BtAddr *btAddr, const SdpService *serviceArray, uint16_t serviceNum, void *context)
522 {
523     HILOGI("serviceNum: %{public}d", serviceNum);
524 
525     auto servManager = IProfileManager::GetInstance();
526     auto service = static_cast<AvrcpCtService *>(servManager->GetProfileService(PROFILE_NAME_AVRCP_CT));
527     RawAddress rawAddr(RawAddress::ConvertToString(btAddr->addr));
528     if (service != nullptr) {
529         if (serviceNum > 0) {
530             ParseSDPInformation(btAddr, serviceArray, serviceNum);
531             service->GetDispatcher()->PostTask(std::bind(&AvrcpCtService::AcceptActiveConnect, service, rawAddr));
532         } else {
533             service->GetDispatcher()->PostTask(std::bind(&AvrcpCtService::RejectActiveConnect, service, rawAddr));
534         }
535     }
536 }
537 
538 /******************************************************************
539  * BUTTON OPERATION                                               *
540  ******************************************************************/
541 
PressButton(const RawAddress & rawAddr,uint8_t button)542 int AvrcpCtService::PressButton(const RawAddress &rawAddr, uint8_t button)
543 {
544     HILOGI("address: %{public}s, button: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), button);
545 
546     int result = RET_BAD_STATUS;
547 
548     do {
549         if (!IsEnabled()) {
550             break;
551         }
552 
553         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
554             break;
555         }
556 
557         if (profile_->IsPassQueueFull(rawAddr)) {
558             break;
559         }
560 
561         RawAddress peerAddr(rawAddr.GetAddress());
562         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::PressButtonNative, this, peerAddr, button));
563         result = BT_SUCCESS;
564     } while (false);
565 
566     return result;
567 }
568 
PressButtonNative(RawAddress rawAddr,uint8_t button)569 void AvrcpCtService::PressButtonNative(RawAddress rawAddr, uint8_t button)
570 {
571     HILOGI("address: %{public}s, button: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), button);
572 
573     do {
574         if (!IsEnabled()) {
575             break;
576         }
577 
578         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
579             break;
580         }
581 
582         profile_->SendPressButtonCmd(rawAddr, button);
583     } while (false);
584 }
585 
OnButtonPressed(const RawAddress & rawAddr,uint8_t button,int result) const586 void AvrcpCtService::OnButtonPressed(const RawAddress &rawAddr, uint8_t button, int result) const
587 {
588     HILOGI("Address: %{public}s, button: %{public}d, result: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr),
589         button, result);
590 
591     if (myObserver_ != nullptr) {
592         myObserver_->OnPressButton(rawAddr, button, result);
593     } else {
594         HILOGI("The observer[onPressButton] is not registered!");
595     }
596 }
597 
ReleaseButton(const RawAddress & rawAddr,uint8_t button)598 int AvrcpCtService::ReleaseButton(const RawAddress &rawAddr, uint8_t button)
599 {
600     HILOGI("address: %{public}s, button: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), button);
601 
602     int result = RET_BAD_STATUS;
603 
604     do {
605         if (!IsEnabled()) {
606             break;
607         }
608 
609         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
610             break;
611         }
612 
613         if (profile_->IsPassQueueFull(rawAddr)) {
614             break;
615         }
616 
617         RawAddress peerAddr(rawAddr.GetAddress());
618         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::ReleaseButtonNative, this, peerAddr, button));
619         result = BT_SUCCESS;
620     } while (false);
621 
622     return result;
623 }
624 
ReleaseButtonNative(RawAddress rawAddr,uint8_t button)625 void AvrcpCtService::ReleaseButtonNative(RawAddress rawAddr, uint8_t button)
626 {
627     HILOGI("address: %{public}s, button: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), button);
628 
629     do {
630         if (!IsEnabled()) {
631             break;
632         }
633 
634         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
635             break;
636         }
637 
638         profile_->SendReleaseButtonCmd(rawAddr, button);
639     } while (false);
640 }
641 
OnButtonReleased(const RawAddress & rawAddr,uint8_t button,int result) const642 void AvrcpCtService::OnButtonReleased(const RawAddress &rawAddr, uint8_t button, int result) const
643 {
644     HILOGI("Address: %{public}s, button: %{public}d, result: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr),
645         button, result);
646 
647     if (myObserver_ != nullptr) {
648         myObserver_->OnReleaseButton(rawAddr, button, result);
649     } else {
650         HILOGI("The observer[onReleaseButton] is not registered!");
651     }
652 }
653 
654 /******************************************************************
655  * UNIT INFO / SUB UNIT INFO                                      *
656  ******************************************************************/
657 
GetUnitInfo(const RawAddress & rawAddr)658 int AvrcpCtService::GetUnitInfo(const RawAddress &rawAddr)
659 {
660     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
661 
662     int result = RET_BAD_STATUS;
663 
664     do {
665         if (!IsEnabled()) {
666             break;
667         }
668 
669         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
670             break;
671         }
672 
673         if (profile_->IsVendorQueueFull(rawAddr)) {
674             break;
675         }
676 
677         RawAddress peerAddr(rawAddr.GetAddress());
678         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::UnitInfoNative, this, peerAddr));
679         result = BT_SUCCESS;
680     } while (false);
681 
682     return result;
683 }
684 
UnitInfoNative(RawAddress rawAddr)685 void AvrcpCtService::UnitInfoNative(RawAddress rawAddr)
686 {
687     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
688 
689     do {
690         if (!IsEnabled()) {
691             break;
692         }
693 
694         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
695             break;
696         }
697 
698         profile_->SendUnitCmd(rawAddr);
699     } while (false);
700 }
701 
GetSubUnitInfo(const RawAddress & rawAddr)702 int AvrcpCtService::GetSubUnitInfo(const RawAddress &rawAddr)
703 {
704     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
705 
706     int result = RET_BAD_STATUS;
707 
708     do {
709         if (!IsEnabled()) {
710             break;
711         }
712 
713         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
714             break;
715         }
716 
717         if (profile_->IsVendorQueueFull(rawAddr)) {
718             break;
719         }
720 
721         RawAddress peerAddr(rawAddr.GetAddress());
722         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::SubUnitInfoNative, this, peerAddr));
723         result = BT_SUCCESS;
724     } while (false);
725 
726     return result;
727 }
728 
SubUnitInfoNative(RawAddress rawAddr)729 void AvrcpCtService::SubUnitInfoNative(RawAddress rawAddr)
730 {
731     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
732 
733     do {
734         if (!IsEnabled()) {
735             break;
736         }
737 
738         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
739             break;
740         }
741 
742         profile_->SendSubUnitCmd(rawAddr);
743     } while (false);
744 }
745 
746 /******************************************************************
747  * Media Player Selection                                         *
748  ******************************************************************/
749 
SetAddressedPlayer(const RawAddress & rawAddr,uint16_t playerId)750 int AvrcpCtService::SetAddressedPlayer(const RawAddress &rawAddr, uint16_t playerId)
751 {
752     HILOGI("address: %{public}s, playerId: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), playerId);
753 
754     int result = RET_BAD_STATUS;
755 
756     do {
757         if (!IsEnabled()) {
758             break;
759         }
760 
761         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
762             break;
763         }
764 
765         if (profile_->IsVendorQueueFull(rawAddr)) {
766             break;
767         }
768 
769         RawAddress peerAddr(rawAddr.GetAddress());
770         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::SetAddressedPlayerNative, this, peerAddr, playerId));
771         result = BT_SUCCESS;
772     } while (false);
773 
774     return result;
775 }
776 
SetAddressedPlayerNative(RawAddress rawAddr,uint16_t playerId)777 void AvrcpCtService::SetAddressedPlayerNative(RawAddress rawAddr, uint16_t playerId)
778 {
779     HILOGI("address: %{public}s, playerId: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), playerId);
780 
781     do {
782         if (!IsEnabled()) {
783             break;
784         }
785 
786         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
787             break;
788         }
789 
790         profile_->SendSetAddressedPlayerCmd(rawAddr, playerId);
791     } while (false);
792 }
793 
OnSetAddressedPlayer(const RawAddress & rawAddr,int result,int detail) const794 void AvrcpCtService::OnSetAddressedPlayer(const RawAddress &rawAddr, int result, int detail) const
795 {
796     HILOGI("address: %{public}s, result: %{public}d, detail: %{public}d",
797         GET_ENCRYPT_AVRCP_ADDR(rawAddr), result, detail);
798 
799     if (myObserver_ != nullptr) {
800         myObserver_->OnSetAddressedPlayer(rawAddr, result, detail);
801         HILOGI("enter");
802     } else {
803         HILOGI("The observer is not registered!");
804     }
805 }
806 
SetBrowsedPlayer(const RawAddress & rawAddr,uint16_t playerId)807 int AvrcpCtService::SetBrowsedPlayer(const RawAddress &rawAddr, uint16_t playerId)
808 {
809     HILOGI("address: %{public}s, playerId: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), playerId);
810 
811     int result = RET_BAD_STATUS;
812 
813     do {
814         if (!IsEnabled()) {
815             break;
816         }
817 
818         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
819             break;
820         }
821 
822         if (profile_->IsVendorQueueFull(rawAddr)) {
823             break;
824         }
825 
826         if (!profile_->IsBrowsingConnected(rawAddr)) {
827             break;
828         }
829 
830         RawAddress peerAddr(rawAddr.GetAddress());
831         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::SetBrowsedPlayerNative, this, peerAddr, playerId));
832         result = BT_SUCCESS;
833     } while (false);
834 
835     return result;
836 }
837 
SetBrowsedPlayerNative(RawAddress rawAddr,uint16_t playerId)838 void AvrcpCtService::SetBrowsedPlayerNative(RawAddress rawAddr, uint16_t playerId)
839 {
840     HILOGI("address: %{public}s, playerId: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), playerId);
841 
842     do {
843         if (!IsEnabled()) {
844             break;
845         }
846 
847         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
848             break;
849         }
850 
851         profile_->SendSetBrowsedPlayerCmd(rawAddr, playerId);
852     } while (false);
853 }
854 
OnSetBrowsedPlayer(const RawAddress & rawAddr,uint16_t uidCounter,uint32_t numOfItems,const std::vector<std::string> & folderNames,int result,int detail) const855 void AvrcpCtService::OnSetBrowsedPlayer(const RawAddress &rawAddr, uint16_t uidCounter, uint32_t numOfItems,
856     const std::vector<std::string> &folderNames, int result, int detail) const
857 {
858     HILOGI("addr: %{public}s, uidCounter: %{public}hu, numOfItems: %{public}d, folderNames.size: %{public}zu, "
859         "result: %{public}d, detail: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), uidCounter, numOfItems,
860         folderNames.size(), result, detail);
861 
862     if (myObserver_ != nullptr) {
863         myObserver_->OnSetBrowsedPlayer(rawAddr, uidCounter, numOfItems, folderNames, result, detail);
864         HILOGI("enter");
865     } else {
866         HILOGI("The observer is not registered!");
867     }
868 }
869 
870 /******************************************************************
871  * Capabilities                                                   *
872  ******************************************************************/
873 
GetSupportedCompanies(const RawAddress & rawAddr)874 int AvrcpCtService::GetSupportedCompanies(const RawAddress &rawAddr)
875 {
876     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
877 
878     int result = RET_BAD_STATUS;
879 
880     do {
881         if (!IsEnabled()) {
882             break;
883         }
884 
885         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
886             break;
887         }
888 
889         if (profile_->IsVendorQueueFull(rawAddr)) {
890             break;
891         }
892 
893         RawAddress peerAddr(rawAddr.GetAddress());
894         GetDispatcher()->PostTask(
895             std::bind(&AvrcpCtService::GetCapabilitiesNative, this, peerAddr, AVRC_CAPABILITY_COMPANYID));
896         result = BT_SUCCESS;
897     } while (false);
898 
899     return result;
900 }
901 
GetSupportedEvents(const RawAddress & rawAddr)902 int AvrcpCtService::GetSupportedEvents(const RawAddress &rawAddr)
903 {
904     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
905 
906     int result = RET_BAD_STATUS;
907 
908     do {
909         if (!IsEnabled()) {
910             break;
911         }
912 
913         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
914             break;
915         }
916 
917         if (profile_->IsVendorQueueFull(rawAddr)) {
918             break;
919         }
920 
921         RawAddress peerAddr(rawAddr.GetAddress());
922         GetDispatcher()->PostTask(
923             std::bind(&AvrcpCtService::GetCapabilitiesNative, this, peerAddr, AVRC_CAPABILITY_EVENTID));
924         result = BT_SUCCESS;
925     } while (false);
926 
927     return result;
928 }
929 
GetCapabilitiesNative(RawAddress rawAddr,uint8_t capabilityId)930 void AvrcpCtService::GetCapabilitiesNative(RawAddress rawAddr, uint8_t capabilityId)
931 {
932     do {
933         if (!IsEnabled()) {
934             break;
935         }
936 
937         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
938             break;
939         }
940 
941         profile_->SendGetCapabilitiesCmd(rawAddr, capabilityId);
942     } while (false);
943 }
944 
OnGetCapabilities(const RawAddress & rawAddr,const std::vector<uint32_t> & companies,const std::vector<uint8_t> & events,int result) const945 void AvrcpCtService::OnGetCapabilities(const RawAddress &rawAddr, const std::vector<uint32_t> &companies,
946     const std::vector<uint8_t> &events, int result) const
947 {
948     HILOGI("address: %{public}s, companies.size: %{public}zu, events.size: %{public}zu, result: %{public}d",
949         GET_ENCRYPT_AVRCP_ADDR(rawAddr), companies.size(), events.size(), result);
950 
951     if (myObserver_ != nullptr) {
952         myObserver_->OnGetCapabilities(rawAddr, companies, events, result);
953         HILOGI("enter");
954     } else {
955         HILOGI("The observer is not registered!");
956     }
957 }
958 /******************************************************************
959  * PLAYER APPLICATION SETTINGS                                    *
960  ******************************************************************/
961 
GetPlayerAppSettingAttributes(const RawAddress & rawAddr)962 int AvrcpCtService::GetPlayerAppSettingAttributes(const RawAddress &rawAddr)
963 {
964     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
965 
966     int result = RET_BAD_STATUS;
967 
968     do {
969         if (!IsEnabled()) {
970             break;
971         }
972 
973         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
974             break;
975         }
976 
977         if (profile_->IsVendorQueueFull(rawAddr)) {
978             break;
979         }
980 
981         RawAddress peerAddr(rawAddr.GetAddress());
982         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::GetPlayerAppSettingAttributesNative, this, peerAddr));
983         result = BT_SUCCESS;
984     } while (false);
985 
986     return result;
987 }
988 
GetPlayerAppSettingAttributesNative(RawAddress rawAddr)989 void AvrcpCtService::GetPlayerAppSettingAttributesNative(RawAddress rawAddr)
990 {
991     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
992 
993     do {
994         if (!IsEnabled()) {
995             break;
996         }
997 
998         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
999             break;
1000         }
1001 
1002         profile_->SendListPlayerApplicationSettingAttributesCmd(rawAddr);
1003     } while (false);
1004 }
1005 
OnGetPlayerAppSettingAttribtues(const RawAddress & rawAddr,const std::vector<uint8_t> & attributes,int result) const1006 void AvrcpCtService::OnGetPlayerAppSettingAttribtues(
1007     const RawAddress &rawAddr, const std::vector<uint8_t> &attributes, int result) const
1008 {
1009     HILOGI("addr: %{public}s, attribute.size: %{public}zu, result: %{public}d",
1010         GET_ENCRYPT_AVRCP_ADDR(rawAddr), attributes.size(), result);
1011 
1012     if (myObserver_ != nullptr) {
1013         myObserver_->OnGetPlayerAppSettingAttributes(rawAddr, attributes, result);
1014         HILOGI("enter");
1015     } else {
1016         HILOGI("The observer is not registered!");
1017     }
1018 }
1019 
GetPlayerAppSettingValues(const RawAddress & rawAddr,uint8_t attribute)1020 int AvrcpCtService::GetPlayerAppSettingValues(const RawAddress &rawAddr, uint8_t attribute)
1021 {
1022     HILOGI("address: %{public}s, attribute: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), attribute);
1023 
1024     int result = RET_BAD_STATUS;
1025 
1026     do {
1027         if (!IsEnabled()) {
1028             break;
1029         }
1030 
1031         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1032             break;
1033         }
1034 
1035         if (profile_->IsVendorQueueFull(rawAddr)) {
1036             break;
1037         }
1038 
1039         RawAddress peerAddr(rawAddr.GetAddress());
1040         GetDispatcher()->PostTask(
1041             std::bind(&AvrcpCtService::GetPlayerAppSettingValuesNative, this, peerAddr, attribute));
1042         result = BT_SUCCESS;
1043     } while (false);
1044 
1045     return result;
1046 }
1047 
GetPlayerAppSettingValuesNative(RawAddress rawAddr,uint8_t attribute)1048 void AvrcpCtService::GetPlayerAppSettingValuesNative(RawAddress rawAddr, uint8_t attribute)
1049 {
1050     HILOGI("address: %{public}s, attribute: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), attribute);
1051 
1052     do {
1053         if (!IsEnabled()) {
1054             break;
1055         }
1056 
1057         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1058             break;
1059         }
1060 
1061         profile_->SendListPlayerApplicationSettingValuesCmd(rawAddr, attribute);
1062     } while (false);
1063 }
1064 
OnGetPlayerAppSettingValues(const RawAddress & rawAddr,uint8_t attribute,const std::vector<uint8_t> & values,int result) const1065 void AvrcpCtService::OnGetPlayerAppSettingValues(
1066     const RawAddress &rawAddr, uint8_t attribute, const std::vector<uint8_t> &values, int result) const
1067 {
1068     HILOGI("addr: %{public}s, attribute: %{public}d, values.size: %{public}zu, result: %{public}d",
1069         GET_ENCRYPT_AVRCP_ADDR(rawAddr), attribute, values.size(), result);
1070 
1071     if (myObserver_ != nullptr) {
1072         myObserver_->OnGetPlayerAppSettingValues(rawAddr, attribute, values, result);
1073         HILOGI("enter");
1074     } else {
1075         HILOGI("The observer is not registered!");
1076     }
1077 }
1078 
GetPlayerAppSettingCurrentValue(const RawAddress & rawAddr,const std::vector<uint8_t> & attributes)1079 int AvrcpCtService::GetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes)
1080 {
1081     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
1082 
1083     int result = RET_BAD_STATUS;
1084 
1085     do {
1086         if (!IsEnabled()) {
1087             break;
1088         }
1089 
1090         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1091             break;
1092         }
1093 
1094         if (profile_->IsVendorQueueFull(rawAddr)) {
1095             break;
1096         }
1097 
1098         RawAddress peerAddr(rawAddr.GetAddress());
1099         GetDispatcher()->PostTask(
1100             std::bind(&AvrcpCtService::GetPlayerAppSettingCurrentValueNative, this, peerAddr, attributes));
1101         result = BT_SUCCESS;
1102     } while (false);
1103 
1104     return result;
1105 }
1106 
GetPlayerAppSettingCurrentValueNative(RawAddress rawAddr,std::vector<uint8_t> attributes)1107 void AvrcpCtService::GetPlayerAppSettingCurrentValueNative(RawAddress rawAddr, std::vector<uint8_t> attributes)
1108 {
1109     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
1110 
1111     do {
1112         if (!IsEnabled()) {
1113             break;
1114         }
1115 
1116         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1117             break;
1118         }
1119 
1120         profile_->SendGetCurrentPlayerApplicationSettingValueCmd(rawAddr, attributes);
1121     } while (false);
1122 }
1123 
OnGetPlayerAppSettingCurrentValue(const RawAddress & rawAddr,const std::vector<uint8_t> & attributes,const std::vector<uint8_t> & values,int result) const1124 void AvrcpCtService::OnGetPlayerAppSettingCurrentValue(const RawAddress &rawAddr,
1125     const std::vector<uint8_t> &attributes, const std::vector<uint8_t> &values, int result) const
1126 {
1127     HILOGI("addr: %{public}s, attributes.size: %{public}zu, values.size: %{public}zu, result: %{public}d",
1128         GET_ENCRYPT_AVRCP_ADDR(rawAddr), attributes.size(), values.size(), result);
1129 
1130     if (myObserver_ != nullptr) {
1131         myObserver_->OnGetPlayerAppSettingCurrentValue(rawAddr, attributes, values, result);
1132         HILOGI("enter");
1133     } else {
1134         HILOGI("The observer is not registered!");
1135     }
1136 }
1137 
SetPlayerAppSettingCurrentValue(const RawAddress & rawAddr,const std::vector<uint8_t> & attributes,const std::vector<uint8_t> & values)1138 int AvrcpCtService::SetPlayerAppSettingCurrentValue(
1139     const RawAddress &rawAddr, const std::vector<uint8_t> &attributes, const std::vector<uint8_t> &values)
1140 {
1141     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
1142 
1143     int result = RET_BAD_STATUS;
1144 
1145     do {
1146         if (!IsEnabled()) {
1147             break;
1148         }
1149 
1150         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1151             break;
1152         }
1153 
1154         if (profile_->IsVendorQueueFull(rawAddr)) {
1155             break;
1156         }
1157 
1158         RawAddress peerAddr(rawAddr.GetAddress());
1159         GetDispatcher()->PostTask(
1160             std::bind(&AvrcpCtService::SetPlayerAppSettingCurrentValueNative, this, peerAddr, attributes, values));
1161         result = BT_SUCCESS;
1162     } while (false);
1163 
1164     return result;
1165 }
1166 
SetPlayerAppSettingCurrentValueNative(RawAddress rawAddr,std::vector<uint8_t> attributes,std::vector<uint8_t> values)1167 void AvrcpCtService::SetPlayerAppSettingCurrentValueNative(
1168     RawAddress rawAddr, std::vector<uint8_t> attributes, std::vector<uint8_t> values)
1169 {
1170     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
1171 
1172     do {
1173         if (!IsEnabled()) {
1174             break;
1175         }
1176 
1177         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1178             break;
1179         }
1180 
1181         profile_->SendSetPlayerApplicationSettingValueCmd(rawAddr, attributes, values);
1182     } while (false);
1183 }
1184 
OnSetPlayerAppSettingCurrentValue(const RawAddress & rawAddr,int result) const1185 void AvrcpCtService::OnSetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, int result) const
1186 {
1187     HILOGI("address: %{public}s, result: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), result);
1188 
1189     if (myObserver_ != nullptr) {
1190         myObserver_->OnSetPlayerAppSettingCurrentValue(rawAddr, result);
1191         HILOGI("enter");
1192     } else {
1193         HILOGI("The observer is not registered!");
1194     }
1195 }
1196 
GetPlayerAppSettingAttributeText(const RawAddress & rawAddr,const std::vector<uint8_t> & attributes)1197 int AvrcpCtService::GetPlayerAppSettingAttributeText(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes)
1198 {
1199     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
1200 
1201     int result = RET_BAD_STATUS;
1202 
1203     do {
1204         if (!IsEnabled()) {
1205             break;
1206         }
1207 
1208         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1209             break;
1210         }
1211 
1212         if (profile_->IsVendorQueueFull(rawAddr)) {
1213             break;
1214         }
1215 
1216         RawAddress peerAddr(rawAddr.GetAddress());
1217         GetDispatcher()->PostTask(
1218             std::bind(&AvrcpCtService::GetPlayerAppSettingAttributeTextNative, this, peerAddr, attributes));
1219         result = BT_SUCCESS;
1220     } while (false);
1221 
1222     return result;
1223 }
1224 
GetPlayerAppSettingAttributeTextNative(RawAddress rawAddr,std::vector<uint8_t> attributes)1225 void AvrcpCtService::GetPlayerAppSettingAttributeTextNative(RawAddress rawAddr, std::vector<uint8_t> attributes)
1226 {
1227     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
1228 
1229     do {
1230         if (!IsEnabled()) {
1231             break;
1232         }
1233 
1234         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1235             break;
1236         }
1237 
1238         profile_->SendGetPlayerApplicationSettingAttributeTextCmd(rawAddr, attributes);
1239     } while (false);
1240 }
1241 
OnGetPlayerAppSettingAttributeText(const RawAddress & rawAddr,const std::vector<uint8_t> & attributes,const std::vector<std::string> & attrStr,int result) const1242 void AvrcpCtService::OnGetPlayerAppSettingAttributeText(const RawAddress &rawAddr,
1243     const std::vector<uint8_t> &attributes, const std::vector<std::string> &attrStr, int result) const
1244 {
1245     HILOGI("address: %{public}s, result: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), result);
1246 
1247     if (myObserver_ != nullptr) {
1248         myObserver_->OnGetPlayerAppSettingAttributeText(rawAddr, attributes, attrStr, result);
1249     } else {
1250         HILOGI("The observer is not registered!");
1251     }
1252 }
1253 
GetPlayerAppSettingValueText(const RawAddress & rawAddr,uint8_t attributeId,const std::vector<uint8_t> & values)1254 int AvrcpCtService::GetPlayerAppSettingValueText(
1255     const RawAddress &rawAddr, uint8_t attributeId, const std::vector<uint8_t> &values)
1256 {
1257     HILOGI("address: %{public}s, attributeId: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), attributeId);
1258 
1259     int result = RET_BAD_STATUS;
1260 
1261     do {
1262         if (!IsEnabled()) {
1263             break;
1264         }
1265 
1266         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1267             break;
1268         }
1269 
1270         if (profile_->IsVendorQueueFull(rawAddr)) {
1271             break;
1272         }
1273 
1274         RawAddress peerAddr(rawAddr.GetAddress());
1275         GetDispatcher()->PostTask(
1276             std::bind(&AvrcpCtService::GetPlayerAppSettingValueTextNative, this, peerAddr, attributeId, values));
1277         result = BT_SUCCESS;
1278     } while (false);
1279 
1280     return result;
1281 }
1282 
GetPlayerAppSettingValueTextNative(RawAddress rawAddr,uint8_t attributeId,std::vector<uint8_t> values)1283 void AvrcpCtService::GetPlayerAppSettingValueTextNative(
1284     RawAddress rawAddr, uint8_t attributeId, std::vector<uint8_t> values)
1285 {
1286     HILOGI("address: %{public}s, attributeId: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), attributeId);
1287 
1288     do {
1289         if (!IsEnabled()) {
1290             break;
1291         }
1292 
1293         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1294             break;
1295         }
1296 
1297         profile_->SendGetPlayerApplicationSettingValueTextCmd(rawAddr, attributeId, values);
1298     } while (false);
1299 }
1300 
OnGetPlayerAppSettingValueText(const RawAddress & rawAddr,const std::vector<uint8_t> & values,const std::vector<std::string> & valueStr,int result) const1301 void AvrcpCtService::OnGetPlayerAppSettingValueText(const RawAddress &rawAddr, const std::vector<uint8_t> &values,
1302     const std::vector<std::string> &valueStr, int result) const
1303 {
1304     HILOGI("address: %{public}s, result: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), result);
1305 
1306     if (myObserver_ != nullptr) {
1307         myObserver_->OnGetPlayerAppSettingValueText(rawAddr, values, valueStr, result);
1308     } else {
1309         HILOGI("The observer is not registered!");
1310     }
1311 }
1312 
1313 /******************************************************************
1314  * MEDIA INFORMATION                                              *
1315  ******************************************************************/
1316 
GetElementAttributes(const RawAddress & rawAddr,uint64_t identifier,const std::vector<uint32_t> & attributes)1317 int AvrcpCtService::GetElementAttributes(
1318     const RawAddress &rawAddr, uint64_t identifier, const std::vector<uint32_t> &attributes)
1319 {
1320     HILOGI("address: %{public}s, identifier: %{public}llu",
1321         GET_ENCRYPT_AVRCP_ADDR(rawAddr), static_cast<unsigned long long>(identifier));
1322 
1323     int result = RET_BAD_STATUS;
1324     do {
1325         if (!IsEnabled()) {
1326             break;
1327         }
1328 
1329         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1330             break;
1331         }
1332 
1333         if (profile_->IsVendorQueueFull(rawAddr)) {
1334             break;
1335         }
1336 
1337         RawAddress peerAddr(rawAddr.GetAddress());
1338         GetDispatcher()->PostTask(
1339             std::bind(&AvrcpCtService::GetElementAttributesNative, this, peerAddr, identifier, attributes));
1340         result = BT_SUCCESS;
1341     } while (false);
1342 
1343     return result;
1344 }
1345 
GetElementAttributesNative(RawAddress rawAddr,uint64_t identifier,std::vector<uint32_t> attributes)1346 void AvrcpCtService::GetElementAttributesNative(
1347     RawAddress rawAddr, uint64_t identifier, std::vector<uint32_t> attributes)
1348 {
1349     HILOGI("address: %{public}s, identifier: %{public}llu",
1350         GET_ENCRYPT_AVRCP_ADDR(rawAddr), static_cast<unsigned long long>(identifier));
1351 
1352     do {
1353         if (!IsEnabled()) {
1354             break;
1355         }
1356 
1357         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1358             break;
1359         }
1360 
1361         profile_->SendGetElementAttributesCmd(rawAddr, identifier, attributes);
1362     } while (false);
1363 }
1364 
OnGetElementAttributes(const RawAddress & rawAddr,const std::vector<uint32_t> & attributes,const std::vector<std::string> & values,int result) const1365 void AvrcpCtService::OnGetElementAttributes(const RawAddress &rawAddr, const std::vector<uint32_t> &attributes,
1366     const std::vector<std::string> &values, int result) const
1367 {
1368     HILOGI("address: %{public}s, result: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), result);
1369 
1370     if (myObserver_ != nullptr) {
1371         myObserver_->OnGetElementAttributes(rawAddr, attributes, values, result);
1372     } else {
1373         HILOGI("The observer is not registered!");
1374     }
1375 }
1376 
1377 /******************************************************************
1378  * PLAY                                                           *
1379  ******************************************************************/
1380 
GetPlayStatus(const RawAddress & rawAddr)1381 int AvrcpCtService::GetPlayStatus(const RawAddress &rawAddr)
1382 {
1383     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
1384 
1385     int result = RET_BAD_STATUS;
1386     do {
1387         if (!IsEnabled()) {
1388             break;
1389         }
1390 
1391         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1392             break;
1393         }
1394 
1395         if (profile_->IsVendorQueueFull(rawAddr)) {
1396             break;
1397         }
1398 
1399         RawAddress peerAddr(rawAddr.GetAddress());
1400         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::GetPlayStatusNative, this, peerAddr));
1401         result = BT_SUCCESS;
1402     } while (false);
1403 
1404     return result;
1405 }
1406 
GetPlayStatusNative(RawAddress rawAddr)1407 void AvrcpCtService::GetPlayStatusNative(RawAddress rawAddr)
1408 {
1409     HILOGI("address: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
1410 
1411     do {
1412         if (!IsEnabled()) {
1413             break;
1414         }
1415 
1416         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1417             break;
1418         }
1419 
1420         profile_->SendGetPlayStatusCmd(rawAddr);
1421     } while (false);
1422 }
1423 
OnGetPlayStatus(const RawAddress & rawAddr,uint32_t songLength,uint32_t songPosition,uint8_t playStatus,int result) const1424 void AvrcpCtService::OnGetPlayStatus(
1425     const RawAddress &rawAddr, uint32_t songLength, uint32_t songPosition, uint8_t playStatus, int result) const
1426 {
1427     HILOGI("address: %{public}s, songLength: %{public}d, songPosition: %{public}d, playStatus: %{public}d, "
1428         "result: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), songLength, songPosition, playStatus, result);
1429 
1430     if (myObserver_ != nullptr) {
1431         myObserver_->OnGetPlayStatus(rawAddr, songLength, songPosition, playStatus, result);
1432     } else {
1433         HILOGI("The observer is not registered!");
1434     }
1435 }
1436 
PlayItem(const RawAddress & rawAddr,uint8_t scope,uint64_t uid,uint16_t uidCounter)1437 int AvrcpCtService::PlayItem(const RawAddress &rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter)
1438 {
1439     HILOGI("address: %{public}s, scope: %{public}d, uid: %{public}llu, uidCounter: %{public}d",
1440         GET_ENCRYPT_AVRCP_ADDR(rawAddr), scope, static_cast<unsigned long long>(uid), uidCounter);
1441 
1442     int result = RET_BAD_STATUS;
1443 
1444     do {
1445         if (!IsEnabled()) {
1446             break;
1447         }
1448 
1449         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1450             break;
1451         }
1452 
1453         if (profile_->IsVendorQueueFull(rawAddr)) {
1454             break;
1455         }
1456 
1457         RawAddress peerAddr(rawAddr.GetAddress());
1458         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::PlayItemNative, this, peerAddr, scope, uid, uidCounter));
1459         result = BT_SUCCESS;
1460     } while (false);
1461 
1462     return result;
1463 }
1464 
PlayItemNative(RawAddress rawAddr,uint8_t scope,uint64_t uid,uint16_t uidCounter)1465 void AvrcpCtService::PlayItemNative(RawAddress rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter)
1466 {
1467     HILOGI("address: %{public}s, scope: %{public}d, uid: %{public}llu, uidCounter: %{public}d",
1468         GET_ENCRYPT_AVRCP_ADDR(rawAddr), scope, static_cast<unsigned long long>(uid), uidCounter);
1469 
1470     do {
1471         if (!IsEnabled()) {
1472             break;
1473         }
1474 
1475         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1476             break;
1477         }
1478 
1479         profile_->SendPlayItemCmd(rawAddr, scope, uid, uidCounter);
1480     } while (false);
1481 };
1482 
OnPlayItem(const RawAddress & rawAddr,int result,int detail) const1483 void AvrcpCtService::OnPlayItem(const RawAddress &rawAddr, int result, int detail) const
1484 {
1485     HILOGI("address: %{public}s, result: %{public}d, detail: %{public}d",
1486         GET_ENCRYPT_AVRCP_ADDR(rawAddr), result, detail);
1487     if (myObserver_ != nullptr) {
1488         myObserver_->OnPlayItem(rawAddr, result, detail);
1489     } else {
1490         HILOGI("The observer is not registered!");
1491     }
1492 };
1493 
AddToNowPlaying(const RawAddress & rawAddr,uint8_t scope,uint64_t uid,uint16_t uidCounter)1494 int AvrcpCtService::AddToNowPlaying(const RawAddress &rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter)
1495 {
1496     HILOGI("address: %{public}s, scope: %{public}d, uid: %{public}llu, uidCounter: %{public}d",
1497         GET_ENCRYPT_AVRCP_ADDR(rawAddr), scope, static_cast<unsigned long long>(uid), uidCounter);
1498     int result = RET_BAD_STATUS;
1499 
1500     do {
1501         if (!IsEnabled()) {
1502             break;
1503         }
1504 
1505         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1506             break;
1507         }
1508 
1509         if (profile_->IsVendorQueueFull(rawAddr)) {
1510             break;
1511         }
1512 
1513         RawAddress peerAddr(rawAddr.GetAddress());
1514         GetDispatcher()->PostTask(
1515             std::bind(&AvrcpCtService::AddToNowPlayingNative, this, peerAddr, scope, uid, uidCounter));
1516         result = BT_SUCCESS;
1517     } while (false);
1518 
1519     return result;
1520 }
1521 
AddToNowPlayingNative(RawAddress rawAddr,uint8_t scope,uint64_t uid,uint16_t uidCounter)1522 void AvrcpCtService::AddToNowPlayingNative(RawAddress rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter)
1523 {
1524     HILOGI("address: %{public}s, scope: %{public}d, uid: %{public}llu, uidCounter: %{public}d",
1525         GET_ENCRYPT_AVRCP_ADDR(rawAddr), scope, static_cast<unsigned long long>(uid), uidCounter);
1526     do {
1527         if (!IsEnabled()) {
1528             break;
1529         }
1530 
1531         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1532             break;
1533         }
1534 
1535         profile_->SendAddToNowPlayingCmd(rawAddr, scope, uid, uidCounter);
1536     } while (false);
1537 }
1538 
OnAddToNowPlaying(const RawAddress & rawAddr,int result,int detail) const1539 void AvrcpCtService::OnAddToNowPlaying(const RawAddress &rawAddr, int result, int detail) const
1540 {
1541     HILOGI("address: %{public}s, result: %{public}d, detail: %{public}d",
1542         GET_ENCRYPT_AVRCP_ADDR(rawAddr), result, detail);
1543 
1544     if (myObserver_ != nullptr) {
1545         myObserver_->OnAddToNowPlaying(rawAddr, result, detail);
1546     } else {
1547         HILOGI("The observer is not registered!");
1548     }
1549 }
1550 
1551 /******************************************************************
1552  * CONTINUING RESPONSE / ABORT CONTINUING RESPONSE                *
1553  ******************************************************************/
1554 
RequestContinuingResponse(const RawAddress & rawAddr,uint8_t pduId)1555 int AvrcpCtService::RequestContinuingResponse(const RawAddress &rawAddr, uint8_t pduId)
1556 {
1557     HILOGI("address: %{public}s, pduId: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), pduId);
1558     int result = RET_BAD_STATUS;
1559 
1560     do {
1561         if (!IsEnabled()) {
1562             break;
1563         }
1564 
1565         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1566             break;
1567         }
1568 
1569         if (profile_->IsVendorQueueFull(rawAddr)) {
1570             break;
1571         }
1572 
1573         RawAddress peerAddr(rawAddr.GetAddress());
1574         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::RequestContinuingResponseNative, this, peerAddr, pduId));
1575         result = BT_SUCCESS;
1576     } while (false);
1577 
1578     return result;
1579 }
1580 
RequestContinuingResponseNative(RawAddress rawAddr,uint8_t pduId)1581 void AvrcpCtService::RequestContinuingResponseNative(RawAddress rawAddr, uint8_t pduId)
1582 {
1583     HILOGI("address: %{public}s, pduId: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), pduId);
1584 
1585     do {
1586         if (!IsEnabled()) {
1587             break;
1588         }
1589 
1590         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1591             break;
1592         }
1593 
1594         profile_->SendRequestContinuingResponseCmd(rawAddr, pduId);
1595     } while (false);
1596 }
1597 
AbortContinuingResponse(const RawAddress & rawAddr,uint8_t pduId)1598 int AvrcpCtService::AbortContinuingResponse(const RawAddress &rawAddr, uint8_t pduId)
1599 {
1600     HILOGI("address: %{public}s, pduId: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), pduId);
1601 
1602     int result = RET_BAD_STATUS;
1603 
1604     do {
1605         if (!IsEnabled()) {
1606             break;
1607         }
1608 
1609         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1610             break;
1611         }
1612 
1613         if (profile_->IsVendorQueueFull(rawAddr)) {
1614             break;
1615         }
1616 
1617         RawAddress peerAddr(rawAddr.GetAddress());
1618         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::AbortContinuingResponseNative, this, peerAddr, pduId));
1619         result = BT_SUCCESS;
1620     } while (false);
1621 
1622     return result;
1623 }
1624 
AbortContinuingResponseNative(RawAddress rawAddr,uint8_t pduId)1625 void AvrcpCtService::AbortContinuingResponseNative(RawAddress rawAddr, uint8_t pduId)
1626 {
1627     HILOGI("address: %{public}s, pduId: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), pduId);
1628 
1629     do {
1630         if (!IsEnabled()) {
1631             break;
1632         }
1633 
1634         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1635             break;
1636         }
1637 
1638         profile_->SendAbortContinuingResponseCmd(rawAddr, pduId);
1639     } while (false);
1640 }
1641 
1642 /******************************************************************
1643  * OPERATE THE VIRTUAL FILE SYSTEM                                *
1644  ******************************************************************/
1645 
ChangePath(const RawAddress & rawAddr,uint16_t uidCounter,uint8_t direction,uint64_t folderUid)1646 int AvrcpCtService::ChangePath(const RawAddress &rawAddr, uint16_t uidCounter, uint8_t direction, uint64_t folderUid)
1647 {
1648     HILOGI("address: %{public}s, uidCounter: %{public}d, direction: %{public}d, folderUid: %{public}llu",
1649         GET_ENCRYPT_AVRCP_ADDR(rawAddr), uidCounter, direction, static_cast<unsigned long long>(folderUid));
1650     int result = RET_BAD_STATUS;
1651 
1652     do {
1653         if (!IsEnabled()) {
1654             break;
1655         }
1656 
1657         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1658             break;
1659         }
1660 
1661         if (profile_->IsBrowseQueueFull(rawAddr)) {
1662             break;
1663         }
1664 
1665         if (!profile_->IsBrowsingConnected(rawAddr)) {
1666             break;
1667         }
1668         RawAddress peerAddr(rawAddr.GetAddress());
1669         GetDispatcher()->PostTask(
1670             std::bind(&AvrcpCtService::ChangePathNative, this, peerAddr, uidCounter, direction, folderUid));
1671         result = BT_SUCCESS;
1672     } while (false);
1673 
1674     return result;
1675 }
1676 
ChangePathNative(RawAddress rawAddr,uint16_t uidCounter,uint8_t direction,uint64_t folderUid)1677 void AvrcpCtService::ChangePathNative(RawAddress rawAddr, uint16_t uidCounter, uint8_t direction, uint64_t folderUid)
1678 {
1679     HILOGI("address: %{public}s, uidCounter: %{public}d, direction: %{public}d, folderUid: %{public}llu",
1680         GET_ENCRYPT_AVRCP_ADDR(rawAddr), uidCounter, direction, static_cast<unsigned long long>(folderUid));
1681     do {
1682         if (!IsEnabled()) {
1683             break;
1684         }
1685 
1686         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1687             break;
1688         }
1689 
1690         profile_->SendChangePathCmd(rawAddr, uidCounter, direction, folderUid);
1691     } while (false);
1692 }
1693 
OnChangePath(const RawAddress & rawAddr,uint32_t numOfItems,int result,int detail) const1694 void AvrcpCtService::OnChangePath(const RawAddress &rawAddr, uint32_t numOfItems, int result, int detail) const
1695 {
1696     HILOGI("address: %{public}s, numOfItems: %{public}u, result: %{public}d, detail: %{public}d",
1697         GET_ENCRYPT_AVRCP_ADDR(rawAddr), numOfItems, result, detail);
1698 
1699     if (myObserver_ != nullptr) {
1700         myObserver_->OnChangePath(rawAddr, numOfItems, result, detail);
1701     } else {
1702         HILOGI("The observer is not registered!");
1703     }
1704 }
1705 
GetFolderItems(const RawAddress & rawAddr,uint8_t scope,uint32_t startItem,uint32_t endItem,const std::vector<uint32_t> & attributes)1706 int AvrcpCtService::GetFolderItems(const RawAddress &rawAddr, uint8_t scope, uint32_t startItem, uint32_t endItem,
1707     const std::vector<uint32_t> &attributes)
1708 {
1709     HILOGI("address: %{public}s, scope: %{public}d, startItem: %{public}u, endItem: %{public}u",
1710         GET_ENCRYPT_AVRCP_ADDR(rawAddr), scope, startItem, endItem);
1711     int result = RET_BAD_STATUS;
1712 
1713     do {
1714         if (!IsEnabled()) {
1715             break;
1716         }
1717 
1718         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1719             break;
1720         }
1721 
1722         if (profile_->IsBrowseQueueFull(rawAddr)) {
1723             break;
1724         }
1725 
1726         if (!profile_->IsBrowsingConnected(rawAddr)) {
1727             break;
1728         }
1729 
1730         RawAddress peerAddr(rawAddr.GetAddress());
1731         GetDispatcher()->PostTask(
1732             std::bind(&AvrcpCtService::GetFolderItemsNative, this, peerAddr, scope, startItem, endItem, attributes));
1733         result = BT_SUCCESS;
1734     } while (false);
1735 
1736     return result;
1737 }
1738 
GetFolderItemsNative(RawAddress rawAddr,uint8_t scope,uint32_t startItem,uint32_t endItem,std::vector<uint32_t> attributes)1739 void AvrcpCtService::GetFolderItemsNative(
1740     RawAddress rawAddr, uint8_t scope, uint32_t startItem, uint32_t endItem, std::vector<uint32_t> attributes)
1741 {
1742     HILOGI("address: %{public}s, scope: %{public}d, startItem: %{public}u, endItem: %{public}u",
1743         GET_ENCRYPT_AVRCP_ADDR(rawAddr), scope, startItem, endItem);
1744     do {
1745         if (!IsEnabled()) {
1746             break;
1747         }
1748 
1749         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1750             break;
1751         }
1752 
1753         profile_->SendGetFolderItemsCmd(rawAddr, scope, startItem, endItem, attributes);
1754     } while (false);
1755 }
1756 
OnGetFolderItems(const RawAddress & rawAddr,uint8_t scope,uint16_t uidCounter,const std::vector<AvrcMpItem> & mpItems,const std::vector<AvrcMeItem> & meItems,int result,int detail) const1757 void AvrcpCtService::OnGetFolderItems(const RawAddress &rawAddr, uint8_t scope, uint16_t uidCounter,
1758     const std::vector<AvrcMpItem> &mpItems, const std::vector<AvrcMeItem> &meItems, int result, int detail) const
1759 {
1760     HILOGI("address: %{public}s, scope: %{public}d, uidCounter: %{public}d, result: %{public}d, detail: %{public}d",
1761         GET_ENCRYPT_AVRCP_ADDR(rawAddr), scope, uidCounter, result, detail);
1762 
1763     if (myObserver_ != nullptr) {
1764         if (scope == AVRC_MEDIA_SCOPE_PLAYER_LIST) {
1765             myObserver_->OnGetMediaPlayers(rawAddr, uidCounter, mpItems, result, detail);
1766         } else {
1767             myObserver_->OnGetFolderItems(rawAddr, uidCounter, meItems, result, detail);
1768         }
1769     } else {
1770         HILOGI("The observer is not registered!");
1771     }
1772 }
1773 
GetItemAttributes(const RawAddress & rawAddr,uint8_t scope,uint64_t uid,uint16_t uidCounter,const std::vector<uint32_t> & attributes)1774 int AvrcpCtService::GetItemAttributes(const RawAddress &rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter,
1775     const std::vector<uint32_t> &attributes)
1776 {
1777     HILOGI("address: %{public}s, scope: %{public}d, uid: %{public}llu, uidCounter: %{public}d",
1778         GET_ENCRYPT_AVRCP_ADDR(rawAddr), scope, static_cast<unsigned long long>(uid), uidCounter);
1779     int result = RET_BAD_STATUS;
1780 
1781     do {
1782         if (!IsEnabled()) {
1783             break;
1784         }
1785 
1786         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1787             break;
1788         }
1789 
1790         if (profile_->IsBrowseQueueFull(rawAddr)) {
1791             break;
1792         }
1793 
1794         if (!profile_->IsBrowsingConnected(rawAddr)) {
1795             break;
1796         }
1797 
1798         RawAddress peerAddr(rawAddr.GetAddress());
1799         GetDispatcher()->PostTask(
1800             std::bind(&AvrcpCtService::GetItemAttributesNative, this, peerAddr, scope, uid, uidCounter, attributes));
1801         result = BT_SUCCESS;
1802     } while (false);
1803 
1804     return result;
1805 }
1806 
GetItemAttributesNative(RawAddress rawAddr,uint8_t scope,uint64_t uid,uint16_t uidCounter,std::vector<uint32_t> attributes)1807 void AvrcpCtService::GetItemAttributesNative(
1808     RawAddress rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter, std::vector<uint32_t> attributes)
1809 {
1810     HILOGI("address: %{public}s, scope: %{public}d, uid: %{public}llu, uidCounter: %{public}d",
1811         GET_ENCRYPT_AVRCP_ADDR(rawAddr), scope, static_cast<unsigned long long>(uid), uidCounter);
1812     do {
1813         if (!IsEnabled()) {
1814             break;
1815         }
1816 
1817         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1818             break;
1819         }
1820 
1821         profile_->SendGetItemAttributesCmd(rawAddr, scope, uid, uidCounter, attributes);
1822     } while (false);
1823 }
1824 
OnGetItemAttributes(const RawAddress & rawAddr,const std::vector<uint32_t> & attributes,const std::vector<std::string> & values,int result,int detail) const1825 void AvrcpCtService::OnGetItemAttributes(const RawAddress &rawAddr, const std::vector<uint32_t> &attributes,
1826     const std::vector<std::string> &values, int result, int detail) const
1827 {
1828     HILOGI("addr:%{public}s, result:%{public}d, detail:%{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), result, detail);
1829 
1830     if (myObserver_ != nullptr) {
1831         myObserver_->OnGetItemAttributes(rawAddr, attributes, values, result, detail);
1832     } else {
1833         HILOGI("The observer is not registered!");
1834     }
1835 }
1836 
GetTotalNumberOfItems(const RawAddress & rawAddr,uint8_t scope)1837 int AvrcpCtService::GetTotalNumberOfItems(const RawAddress &rawAddr, uint8_t scope)
1838 {
1839     HILOGI("addr:%{public}s, scope:%{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), scope);
1840 
1841     int result = RET_BAD_STATUS;
1842 
1843     do {
1844         if (!IsEnabled()) {
1845             break;
1846         }
1847 
1848         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1849             break;
1850         }
1851 
1852         if (profile_->IsBrowseQueueFull(rawAddr)) {
1853             break;
1854         }
1855 
1856         if (!profile_->IsBrowsingConnected(rawAddr)) {
1857             break;
1858         }
1859 
1860         RawAddress peerAddr(rawAddr.GetAddress());
1861         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::GetTotalNumberOfItemsNative, this, peerAddr, scope));
1862         result = BT_SUCCESS;
1863     } while (false);
1864 
1865     return result;
1866 }
1867 
GetTotalNumberOfItemsNative(RawAddress rawAddr,uint8_t scope)1868 void AvrcpCtService::GetTotalNumberOfItemsNative(RawAddress rawAddr, uint8_t scope)
1869 {
1870     HILOGI("addr:%{public}s, scope:%{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), scope);
1871 
1872     do {
1873         if (!IsEnabled()) {
1874             break;
1875         }
1876 
1877         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1878             break;
1879         }
1880 
1881         profile_->SendGetTotalNumberOfItemsCmd(rawAddr, scope);
1882     } while (false);
1883 }
1884 
OnGetTotalNumberOfItems(const RawAddress & rawAddr,uint16_t uidCounter,uint32_t numOfItems,int result,int detail) const1885 void AvrcpCtService::OnGetTotalNumberOfItems(
1886     const RawAddress &rawAddr, uint16_t uidCounter, uint32_t numOfItems, int result, int detail) const
1887 {
1888     HILOGI("addr:%{public}s, uidCounter:%{public}d, numOfItems:%{public}u, result:%{public}d, detail:%{public}d",
1889         GET_ENCRYPT_AVRCP_ADDR(rawAddr), uidCounter, numOfItems, result, detail);
1890 
1891     if (myObserver_ != nullptr) {
1892         myObserver_->OnGetTotalNumberOfItems(rawAddr, uidCounter, numOfItems, result, detail);
1893     } else {
1894         HILOGI("The observer is not registered!");
1895     }
1896 }
1897 
1898 /******************************************************************
1899  * ABSOLUTE VOLUME                                                *
1900  ******************************************************************/
1901 
SetAbsoluteVolume(const RawAddress & rawAddr,uint8_t volume)1902 int AvrcpCtService::SetAbsoluteVolume(const RawAddress &rawAddr, uint8_t volume)
1903 {
1904     HILOGI("addr: %{public}s, volume: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), volume);
1905 
1906     int result = RET_BAD_STATUS;
1907 
1908     do {
1909         if (!IsEnabled()) {
1910             break;
1911         }
1912 
1913         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1914             break;
1915         }
1916 
1917         if (profile_->IsVendorQueueFull(rawAddr)) {
1918             break;
1919         }
1920 
1921         if (profile_->IsDisableAbsoluteVolume(rawAddr)) {
1922             result = RET_NO_SUPPORT;
1923             break;
1924         }
1925 
1926         RawAddress peerAddr(rawAddr.GetAddress());
1927         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::SetAbsoluteVolumeNative, this, peerAddr, volume));
1928         result = BT_SUCCESS;
1929     } while (false);
1930 
1931     return result;
1932 }
1933 
SetAbsoluteVolumeNative(RawAddress rawAddr,uint8_t volume)1934 void AvrcpCtService::SetAbsoluteVolumeNative(RawAddress rawAddr, uint8_t volume)
1935 {
1936     HILOGI("addr: %{public}s, volume: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), volume);
1937 
1938     do {
1939         if (!IsEnabled()) {
1940             break;
1941         }
1942 
1943         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1944             break;
1945         }
1946 
1947         profile_->SendSetAbsoluteVolumeCmd(rawAddr, volume);
1948     } while (false);
1949 }
1950 
OnSetAbsoluteVolume(const RawAddress & rawAddr,uint8_t volume,int result) const1951 void AvrcpCtService::OnSetAbsoluteVolume(const RawAddress &rawAddr, uint8_t volume, int result) const
1952 {
1953     HILOGI("addr:%{public}s, volume:%{public}d, result:%{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), volume, result);
1954 
1955     if (myObserver_ != nullptr) {
1956         myObserver_->OnSetAbsoluteVolume(rawAddr, volume, result);
1957     } else {
1958         HILOGI("The observer is not registered!");
1959     }
1960 }
1961 
1962 /******************************************************************
1963  * NOTIFICATION                                                   *
1964  ******************************************************************/
1965 
EnableNotification(const RawAddress & rawAddr,const std::vector<uint8_t> & events,uint8_t interval)1966 int AvrcpCtService::EnableNotification(const RawAddress &rawAddr, const std::vector<uint8_t> &events, uint8_t interval)
1967 {
1968     HILOGI("addr: %{public}s, interval: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), interval);
1969 
1970     int result = RET_BAD_STATUS;
1971 
1972     do {
1973         if (!IsEnabled()) {
1974             break;
1975         }
1976 
1977         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
1978             break;
1979         }
1980 
1981         if (profile_->IsVendorQueueFull(rawAddr)) {
1982             break;
1983         }
1984 
1985         RawAddress peerAddr(rawAddr.GetAddress());
1986         GetDispatcher()->PostTask(
1987             std::bind(&AvrcpCtService::EnableNotificationNative, this, peerAddr, events, interval));
1988         result = BT_SUCCESS;
1989     } while (false);
1990 
1991     return result;
1992 }
1993 
DisableNotification(const RawAddress & rawAddr,const std::vector<uint8_t> & events)1994 int AvrcpCtService::DisableNotification(const RawAddress &rawAddr, const std::vector<uint8_t> &events)
1995 {
1996     HILOGI("addr: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
1997 
1998     int result = RET_BAD_STATUS;
1999 
2000     do {
2001         if (!IsEnabled()) {
2002             break;
2003         }
2004 
2005         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
2006             break;
2007         }
2008 
2009         if (profile_->IsVendorQueueFull(rawAddr)) {
2010             break;
2011         }
2012 
2013         RawAddress peerAddr(rawAddr.GetAddress());
2014         GetDispatcher()->PostTask(std::bind(&AvrcpCtService::DisableNotificationNative, this, peerAddr, events));
2015         result = BT_SUCCESS;
2016     } while (false);
2017 
2018     return result;
2019 }
2020 
EnableNotificationNative(RawAddress rawAddr,std::vector<uint8_t> events,uint8_t interval)2021 void AvrcpCtService::EnableNotificationNative(RawAddress rawAddr, std::vector<uint8_t> events, uint8_t interval)
2022 {
2023     HILOGI("addr: %{public}s, interval: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), interval);
2024 
2025     do {
2026         if (!IsEnabled()) {
2027             break;
2028         }
2029 
2030         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
2031             break;
2032         }
2033 
2034         profile_->EnableNotification(rawAddr, events, interval);
2035     } while (false);
2036 }
2037 
DisableNotificationNative(RawAddress rawAddr,std::vector<uint8_t> events)2038 void AvrcpCtService::DisableNotificationNative(RawAddress rawAddr, std::vector<uint8_t> events)
2039 {
2040     HILOGI("addr: %{public}s", GET_ENCRYPT_AVRCP_ADDR(rawAddr));
2041 
2042     do {
2043         if (!IsEnabled()) {
2044             break;
2045         }
2046 
2047         if (GetDeviceState(rawAddr) != static_cast<int>(BTConnectState::CONNECTED)) {
2048             break;
2049         }
2050 
2051         profile_->DisableNotification(rawAddr, events);
2052     } while (false);
2053 }
2054 
OnPlaybackStatusChanged(const RawAddress & rawAddr,uint8_t playStatus,int result) const2055 void AvrcpCtService::OnPlaybackStatusChanged(const RawAddress &rawAddr, uint8_t playStatus, int result) const
2056 {
2057     HILOGI("addr: %{public}s, playStatus: %{public}d, result: %{public}d",
2058         GET_ENCRYPT_AVRCP_ADDR(rawAddr), playStatus, result);
2059 
2060     if (myObserver_ != nullptr) {
2061         myObserver_->OnPlaybackStatusChanged(rawAddr, playStatus, result);
2062     } else {
2063         HILOGI("The observer is not registered!");
2064     }
2065 }
2066 
OnTrackChanged(const RawAddress & rawAddr,uint64_t uid,int result) const2067 void AvrcpCtService::OnTrackChanged(const RawAddress &rawAddr, uint64_t uid, int result) const
2068 {
2069     HILOGI("addr: %{public}s, uid: %{public}jx, result: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), uid, result);
2070 
2071     if (myObserver_ != nullptr) {
2072         myObserver_->OnTrackChanged(rawAddr, uid, result);
2073     } else {
2074         HILOGI("The observer is not registered!");
2075     }
2076 }
2077 
OnTrackReachedEnd(const RawAddress & rawAddr,int result) const2078 void AvrcpCtService::OnTrackReachedEnd(const RawAddress &rawAddr, int result) const
2079 {
2080     HILOGI("addr: %{public}s, result: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), result);
2081 
2082     if (myObserver_ != nullptr) {
2083         myObserver_->OnTrackReachedEnd(rawAddr, result);
2084     } else {
2085         HILOGI("The observer is not registered!");
2086     }
2087 }
2088 
OnTrackReachedStart(const RawAddress & rawAddr,int result) const2089 void AvrcpCtService::OnTrackReachedStart(const RawAddress &rawAddr, int result) const
2090 {
2091     HILOGI("addr: %{public}s, result: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), result);
2092 
2093     if (myObserver_ != nullptr) {
2094         myObserver_->OnTrackReachedStart(rawAddr, result);
2095     } else {
2096         HILOGI("The observer is not registered!");
2097     }
2098 }
2099 
OnPlaybackPosChanged(const RawAddress & rawAddr,uint32_t playbackPos,int result) const2100 void AvrcpCtService::OnPlaybackPosChanged(const RawAddress &rawAddr, uint32_t playbackPos, int result) const
2101 {
2102     HILOGI("addr: %{public}s, playbackPos: %{public}d, result: %{public}d",
2103         GET_ENCRYPT_AVRCP_ADDR(rawAddr), playbackPos, result);
2104 
2105     if (myObserver_ != nullptr) {
2106         myObserver_->OnPlaybackPosChanged(rawAddr, playbackPos, result);
2107     } else {
2108         HILOGI("The observer is not registered!");
2109     }
2110 }
2111 
OnPlayerApplicationSettingChanged(const RawAddress & rawAddr,const std::vector<uint8_t> & attributes,const std::vector<uint8_t> & values,int result) const2112 void AvrcpCtService::OnPlayerApplicationSettingChanged(const RawAddress &rawAddr,
2113     const std::vector<uint8_t> &attributes, const std::vector<uint8_t> &values, int result) const
2114 {
2115     HILOGI("addr: %{public}s, attributes.size: %{public}zu, values.size: %{public}zu, result: %{public}d",
2116         GET_ENCRYPT_AVRCP_ADDR(rawAddr), attributes.size(), values.size(), result);
2117 
2118     if (myObserver_ != nullptr) {
2119         myObserver_->OnPlayerAppSettingChanged(rawAddr, attributes, values, result);
2120     } else {
2121         HILOGI("The observer is not registered!");
2122     }
2123 }
2124 
OnNowPlayingContentChanged(const RawAddress & rawAddr,int result) const2125 void AvrcpCtService::OnNowPlayingContentChanged(const RawAddress &rawAddr, int result) const
2126 {
2127     HILOGI("addr: %{public}s, result: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), result);
2128 
2129     if (myObserver_ != nullptr) {
2130         myObserver_->OnNowPlayingContentChanged(rawAddr, result);
2131     } else {
2132         HILOGI("The observer is not registered!");
2133     }
2134 }
2135 
OnAvailablePlayersChanged(const RawAddress & rawAddr,int result) const2136 void AvrcpCtService::OnAvailablePlayersChanged(const RawAddress &rawAddr, int result) const
2137 {
2138     HILOGI("addr: %{public}s, result: %{public}d", GET_ENCRYPT_AVRCP_ADDR(rawAddr), result);
2139 
2140     if (myObserver_ != nullptr) {
2141         myObserver_->OnAvailablePlayersChanged(rawAddr, result);
2142     } else {
2143         HILOGI("The observer is not registered!");
2144     }
2145 }
2146 
OnAddressedPlayerChanged(const RawAddress & rawAddr,uint16_t playerId,uint16_t uidCounter,int result) const2147 void AvrcpCtService::OnAddressedPlayerChanged(
2148     const RawAddress &rawAddr, uint16_t playerId, uint16_t uidCounter, int result) const
2149 {
2150     HILOGI("addr: %{public}s, playerId: %{public}d, uidCounter: %{public}d, result: %{public}d",
2151         GET_ENCRYPT_AVRCP_ADDR(rawAddr), playerId, uidCounter, result);
2152 
2153     if (myObserver_ != nullptr) {
2154         myObserver_->OnAddressedPlayerChanged(rawAddr, playerId, uidCounter, result);
2155     } else {
2156         HILOGI("The observer is not registered!");
2157     }
2158 }
2159 
OnUidChanged(const RawAddress & rawAddr,uint16_t uidCounter,int result) const2160 void AvrcpCtService::OnUidChanged(const RawAddress &rawAddr, uint16_t uidCounter, int result) const
2161 {
2162     HILOGI("addr: %{public}s, uidCounter: %{public}d, result: %{public}d",
2163         GET_ENCRYPT_AVRCP_ADDR(rawAddr), uidCounter, result);
2164 
2165     if (myObserver_ != nullptr) {
2166         myObserver_->OnUidChanged(rawAddr, uidCounter, result);
2167     } else {
2168         HILOGI("The observer is not registered!");
2169     }
2170 }
2171 
OnVolumeChanged(const RawAddress & rawAddr,uint8_t volume,int result) const2172 void AvrcpCtService::OnVolumeChanged(const RawAddress &rawAddr, uint8_t volume, int result) const
2173 {
2174     HILOGI("addr: %{public}s, volume: %{public}d, result: %{public}d",
2175         GET_ENCRYPT_AVRCP_ADDR(rawAddr), volume, result);
2176 
2177     if (myObserver_ != nullptr) {
2178         myObserver_->OnVolumeChanged(rawAddr, volume, result);
2179     } else {
2180         HILOGI("The observer is not registered!");
2181     }
2182 }
2183 
ProcessChannelEvent(RawAddress rawAddr,uint8_t connectId,uint8_t event,uint16_t result,void * context)2184 void AvrcpCtService::ProcessChannelEvent(
2185     RawAddress rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context)
2186 {
2187     HILOGI("addr: %{public}s, connectId: %{public}d, event: %{public}d, result: %{public}d",
2188         GET_ENCRYPT_AVRCP_ADDR(rawAddr), connectId, event, result);
2189     if (!IsDisabled()) {
2190         profile_->ProcessChannelEvent(rawAddr, connectId, event, result, context);
2191     }
2192 }
2193 
ProcessChannelMessage(uint8_t connectId,uint8_t label,uint8_t crType,uint8_t chType,Packet * pkt,void * context)2194 void AvrcpCtService::ProcessChannelMessage(
2195     uint8_t connectId, uint8_t label, uint8_t crType, uint8_t chType, Packet *pkt, void *context)
2196 {
2197     HILOGI("connectId: %{public}d, label: %{public}d, crType: %{public}d, chType: %{public}d",
2198         connectId, label, crType, chType);
2199 
2200     if (!IsDisabled()) {
2201         profile_->ProcessChannelMessage(connectId, label, crType, chType, pkt, context);
2202     }
2203 }
2204 
ChannelEventCallback(uint8_t connectId,uint8_t event,uint16_t result,const BtAddr * btAddr,void * context)2205 void AvrcpCtService::ChannelEventCallback(
2206     uint8_t connectId, uint8_t event, uint16_t result, const BtAddr *btAddr, void *context)
2207 {
2208     HILOGI("connectId: %{public}d, event: %{public}d, result: %{public}d", connectId, event, result);
2209     auto servManager = IProfileManager::GetInstance();
2210     auto service = static_cast<AvrcpCtService *>(servManager->GetProfileService(PROFILE_NAME_AVRCP_CT));
2211     RawAddress rawAddr(RawAddress::ConvertToString(btAddr->addr));
2212 
2213     if (service != nullptr) {
2214         switch (event) {
2215             case AVCT_CONNECT_IND_EVT:
2216             case AVCT_CONNECT_CFM_EVT:
2217                 if (result != BT_SUCCESS) {
2218                     service->DecConnectionNum();
2219                 }
2220                 break;
2221             case AVCT_DISCONNECT_IND_EVT:
2222             case AVCT_DISCONNECT_CFM_EVT:
2223                 service->DecConnectionNum();
2224                 break;
2225             default:
2226                 break;
2227         }
2228         service->GetDispatcher()->PostTask(
2229             std::bind(&AvrcpCtService::ProcessChannelEvent, service, rawAddr, connectId, event, result, context));
2230     }
2231 }
2232 
ChannelMessageCallback(uint8_t connectId,uint8_t label,uint8_t crType,uint8_t chType,Packet * pkt,void * context)2233 void AvrcpCtService::ChannelMessageCallback(
2234     uint8_t connectId, uint8_t label, uint8_t crType, uint8_t chType, Packet *pkt, void *context)
2235 {
2236     HILOGI("connectId: %{public}d, label: %{public}d, crType: %{public}d, chType: %{public}d",
2237         connectId, label, crType, chType);
2238     if (!crType) {
2239         return;
2240     }
2241     auto servManager = IProfileManager::GetInstance();
2242     auto service = static_cast<AvrcpCtService *>(servManager->GetProfileService(PROFILE_NAME_AVRCP_CT));
2243     auto myPkt = PacketRefMalloc(pkt);
2244 
2245     if (service != nullptr) {
2246         service->GetDispatcher()->PostTask(std::bind(
2247             &AvrcpCtService::ProcessChannelMessage, service, connectId, label, crType, chType, myPkt, context));
2248     }
2249 }
2250 
CheckConnectionNum()2251 bool AvrcpCtService::CheckConnectionNum()
2252 {
2253     if (++currentConn_ > maxConnection_) {
2254         currentConn_ = maxConnection_;
2255         return false;
2256     } else {
2257         return true;
2258     }
2259 }
2260 
2261 REGISTER_CLASS_CREATOR(AvrcpCtService);
2262 }  // namespace bluetooth
2263 }  // namespace OHOS
2264