195489c19Sopenharmony_ci/* 295489c19Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd. 395489c19Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 495489c19Sopenharmony_ci * you may not use this file except in compliance with the License. 595489c19Sopenharmony_ci * You may obtain a copy of the License at 695489c19Sopenharmony_ci * 795489c19Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 895489c19Sopenharmony_ci * 995489c19Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1095489c19Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1195489c19Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1295489c19Sopenharmony_ci * See the License for the specific language governing permissions and 1395489c19Sopenharmony_ci * limitations under the License. 1495489c19Sopenharmony_ci */ 1595489c19Sopenharmony_ci 1695489c19Sopenharmony_ci#include <deque> 1795489c19Sopenharmony_ci#include <list> 1895489c19Sopenharmony_ci#include <mutex> 1995489c19Sopenharmony_ci 2095489c19Sopenharmony_ci#include "bluetooth_avrcp_ct.h" 2195489c19Sopenharmony_ci#include "bluetooth_avrcp_ct_observer_stub.h" 2295489c19Sopenharmony_ci#include "bluetooth_def.h" 2395489c19Sopenharmony_ci#include "bluetooth_host.h" 2495489c19Sopenharmony_ci#include "bluetooth_profile_manager.h" 2595489c19Sopenharmony_ci#include "bluetooth_log.h" 2695489c19Sopenharmony_ci#include "bluetooth_utils.h" 2795489c19Sopenharmony_ci#include "bluetooth_observer_list.h" 2895489c19Sopenharmony_ci#include "i_bluetooth_avrcp_ct.h" 2995489c19Sopenharmony_ci#include "iservice_registry.h" 3095489c19Sopenharmony_ci#include "system_ability_definition.h" 3195489c19Sopenharmony_ci 3295489c19Sopenharmony_cinamespace OHOS { 3395489c19Sopenharmony_cinamespace Bluetooth { 3495489c19Sopenharmony_ciusing namespace OHOS::bluetooth; 3595489c19Sopenharmony_cistd::mutex g_avrcpProxyMutex; 3695489c19Sopenharmony_ciAvrcpCtResponse::AvrcpCtResponse(uint8_t type, int resp) : type_(type), resp_(resp) 3795489c19Sopenharmony_ci{ 3895489c19Sopenharmony_ci HILOGI("enter"); 3995489c19Sopenharmony_ci} 4095489c19Sopenharmony_ci 4195489c19Sopenharmony_ciAvrcpCtResponse::~AvrcpCtResponse() 4295489c19Sopenharmony_ci{ 4395489c19Sopenharmony_ci HILOGI("enter"); 4495489c19Sopenharmony_ci} 4595489c19Sopenharmony_ci 4695489c19Sopenharmony_cistruct AvrcpController::impl { 4795489c19Sopenharmony_cipublic: 4895489c19Sopenharmony_ci class ObserverImpl : public BluetoothAvrcpCtObserverStub { 4995489c19Sopenharmony_ci public: 5095489c19Sopenharmony_ci explicit ObserverImpl(AvrcpController::impl *impl) : impl_(impl) 5195489c19Sopenharmony_ci {} 5295489c19Sopenharmony_ci ~ObserverImpl() override = default; 5395489c19Sopenharmony_ci 5495489c19Sopenharmony_ci void OnConnectionStateChanged(const RawAddress &rawAddr, int state, int cause) override 5595489c19Sopenharmony_ci { 5695489c19Sopenharmony_ci HILOGD("enter, address: %{public}s, state: %{public}d, cause: %{public}d", 5795489c19Sopenharmony_ci GET_ENCRYPT_RAW_ADDR(rawAddr), state, cause); 5895489c19Sopenharmony_ci 5995489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 6095489c19Sopenharmony_ci impl_->OnConnectionStateChanged(device, static_cast<int>(state), cause); 6195489c19Sopenharmony_ci 6295489c19Sopenharmony_ci return; 6395489c19Sopenharmony_ci } 6495489c19Sopenharmony_ci 6595489c19Sopenharmony_ci void OnPressButton(const RawAddress &rawAddr, uint8_t button, int result) override 6695489c19Sopenharmony_ci { 6795489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, button: %{public}d, res: %{public}d", 6895489c19Sopenharmony_ci GET_ENCRYPT_RAW_ADDR(rawAddr), button, result); 6995489c19Sopenharmony_ci 7095489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 7195489c19Sopenharmony_ci impl_->OnPressButton(device, static_cast<uint8_t>(button), static_cast<int>(result)); 7295489c19Sopenharmony_ci 7395489c19Sopenharmony_ci return; 7495489c19Sopenharmony_ci } 7595489c19Sopenharmony_ci 7695489c19Sopenharmony_ci void OnReleaseButton(const RawAddress &rawAddr, uint8_t button, int result) override 7795489c19Sopenharmony_ci { 7895489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, button: %{public}d, res: %{public}d", 7995489c19Sopenharmony_ci GET_ENCRYPT_RAW_ADDR(rawAddr), button, result); 8095489c19Sopenharmony_ci 8195489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 8295489c19Sopenharmony_ci impl_->OnReleaseButton(device, static_cast<uint8_t>(button), static_cast<int>(result)); 8395489c19Sopenharmony_ci 8495489c19Sopenharmony_ci return; 8595489c19Sopenharmony_ci } 8695489c19Sopenharmony_ci 8795489c19Sopenharmony_ci void OnSetBrowsedPlayer(const RawAddress &rawAddr, uint16_t uidCounter, 8895489c19Sopenharmony_ci uint32_t numberOfItems, const std::vector<std::string> &folderNames, int result, int detail) override 8995489c19Sopenharmony_ci { 9095489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, res: %{public}d, detail: %{public}d", 9195489c19Sopenharmony_ci GET_ENCRYPT_RAW_ADDR(rawAddr), result, detail); 9295489c19Sopenharmony_ci 9395489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 9495489c19Sopenharmony_ci 9595489c19Sopenharmony_ci impl_->OnSetBrowsedPlayer(device, 9695489c19Sopenharmony_ci static_cast<uint16_t>(uidCounter), 9795489c19Sopenharmony_ci static_cast<uint32_t>(numberOfItems), 9895489c19Sopenharmony_ci folderNames, 9995489c19Sopenharmony_ci result, 10095489c19Sopenharmony_ci detail); 10195489c19Sopenharmony_ci return; 10295489c19Sopenharmony_ci } 10395489c19Sopenharmony_ci 10495489c19Sopenharmony_ci void OnGetCapabilities(const RawAddress &rawAddr, const std::vector<uint32_t> &companies, 10595489c19Sopenharmony_ci const std::vector<uint8_t> &events, int result) override 10695489c19Sopenharmony_ci { 10795489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, res: %{public}d", GET_ENCRYPT_RAW_ADDR(rawAddr), result); 10895489c19Sopenharmony_ci 10995489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 11095489c19Sopenharmony_ci impl_->OnGetCapabilities(device, companies, events, result); 11195489c19Sopenharmony_ci 11295489c19Sopenharmony_ci return; 11395489c19Sopenharmony_ci } 11495489c19Sopenharmony_ci 11595489c19Sopenharmony_ci void OnGetPlayerAppSettingAttributes( 11695489c19Sopenharmony_ci const RawAddress &rawAddr, std::vector<uint8_t> attributes, int result) override 11795489c19Sopenharmony_ci { 11895489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, res: %{public}d", GET_ENCRYPT_RAW_ADDR(rawAddr), result); 11995489c19Sopenharmony_ci 12095489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 12195489c19Sopenharmony_ci 12295489c19Sopenharmony_ci impl_->OnGetPlayerAppSettingAttributes(device, attributes, static_cast<int>(result)); 12395489c19Sopenharmony_ci 12495489c19Sopenharmony_ci return; 12595489c19Sopenharmony_ci } 12695489c19Sopenharmony_ci 12795489c19Sopenharmony_ci void OnGetPlayerAppSettingValues(const RawAddress &rawAddr, 12895489c19Sopenharmony_ci int attribute, const std::vector<uint8_t> &values, int result) override 12995489c19Sopenharmony_ci { 13095489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, attribute: %{public}d, res: %{public}d", 13195489c19Sopenharmony_ci GET_ENCRYPT_RAW_ADDR(rawAddr), attribute, result); 13295489c19Sopenharmony_ci 13395489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 13495489c19Sopenharmony_ci 13595489c19Sopenharmony_ci impl_->OnGetPlayerAppSettingValues( 13695489c19Sopenharmony_ci device, static_cast<uint8_t>(attribute), values, static_cast<int>(result)); 13795489c19Sopenharmony_ci 13895489c19Sopenharmony_ci return; 13995489c19Sopenharmony_ci } 14095489c19Sopenharmony_ci 14195489c19Sopenharmony_ci void OnGetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, const std::vector<uint8_t> attributes, 14295489c19Sopenharmony_ci const std::vector<uint8_t> &values, int result) override 14395489c19Sopenharmony_ci { 14495489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, res: %{public}d", GET_ENCRYPT_RAW_ADDR(rawAddr), result); 14595489c19Sopenharmony_ci 14695489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 14795489c19Sopenharmony_ci 14895489c19Sopenharmony_ci impl_->OnGetPlayerAppSettingCurrentValue(device, attributes, values, static_cast<int>(result)); 14995489c19Sopenharmony_ci 15095489c19Sopenharmony_ci return; 15195489c19Sopenharmony_ci } 15295489c19Sopenharmony_ci 15395489c19Sopenharmony_ci void OnSetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, int result) override 15495489c19Sopenharmony_ci { 15595489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, res: %{public}d", GET_ENCRYPT_RAW_ADDR(rawAddr), result); 15695489c19Sopenharmony_ci 15795489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 15895489c19Sopenharmony_ci 15995489c19Sopenharmony_ci impl_->OnSetPlayerAppSettingCurrentValue(device, static_cast<int>(result)); 16095489c19Sopenharmony_ci 16195489c19Sopenharmony_ci return; 16295489c19Sopenharmony_ci } 16395489c19Sopenharmony_ci 16495489c19Sopenharmony_ci void OnGetPlayerAppSettingAttributeText(const RawAddress &rawAddr, 16595489c19Sopenharmony_ci const std::vector<uint8_t> attribtues, const std::vector<std::string> &attributeName, int result) override 16695489c19Sopenharmony_ci { 16795489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, res: %{public}d", GET_ENCRYPT_RAW_ADDR(rawAddr), result); 16895489c19Sopenharmony_ci 16995489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 17095489c19Sopenharmony_ci 17195489c19Sopenharmony_ci impl_->OnGetPlayerAppSettingAttributeText(device, attribtues, attributeName, static_cast<int>(result)); 17295489c19Sopenharmony_ci 17395489c19Sopenharmony_ci return; 17495489c19Sopenharmony_ci } 17595489c19Sopenharmony_ci 17695489c19Sopenharmony_ci void OnGetPlayerAppSettingValueText(const RawAddress &rawAddr, 17795489c19Sopenharmony_ci const std::vector<uint8_t> &values, const std::vector<std::string> &valueName, int result) override 17895489c19Sopenharmony_ci { 17995489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, res: %{public}d", GET_ENCRYPT_RAW_ADDR(rawAddr), result); 18095489c19Sopenharmony_ci 18195489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 18295489c19Sopenharmony_ci 18395489c19Sopenharmony_ci impl_->OnGetPlayerAppSettingValueText(device, values, valueName, static_cast<int>(result)); 18495489c19Sopenharmony_ci 18595489c19Sopenharmony_ci return; 18695489c19Sopenharmony_ci } 18795489c19Sopenharmony_ci 18895489c19Sopenharmony_ci void OnGetElementAttributes(const RawAddress &rawAddr, 18995489c19Sopenharmony_ci const std::vector<uint32_t> &attribtues, const std::vector<std::string> &valueName, int result) override 19095489c19Sopenharmony_ci { 19195489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, res: %{public}d", GET_ENCRYPT_RAW_ADDR(rawAddr), result); 19295489c19Sopenharmony_ci 19395489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 19495489c19Sopenharmony_ci 19595489c19Sopenharmony_ci impl_->OnGetElementAttributes(device, attribtues, valueName, static_cast<int>(result)); 19695489c19Sopenharmony_ci 19795489c19Sopenharmony_ci return; 19895489c19Sopenharmony_ci } 19995489c19Sopenharmony_ci 20095489c19Sopenharmony_ci void OnGetPlayStatus(const RawAddress &rawAddr, 20195489c19Sopenharmony_ci uint32_t songLength, uint32_t songPosition, uint8_t playStatus, int result) override 20295489c19Sopenharmony_ci { 20395489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, status: %{public}d, res: %{public}d", 20495489c19Sopenharmony_ci GET_ENCRYPT_RAW_ADDR(rawAddr), playStatus, result); 20595489c19Sopenharmony_ci 20695489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 20795489c19Sopenharmony_ci impl_->OnGetPlayStatus(device, 20895489c19Sopenharmony_ci static_cast<uint32_t>(songLength), 20995489c19Sopenharmony_ci static_cast<uint32_t>(songPosition), 21095489c19Sopenharmony_ci static_cast<uint8_t>(playStatus), 21195489c19Sopenharmony_ci static_cast<int>(result)); 21295489c19Sopenharmony_ci 21395489c19Sopenharmony_ci return; 21495489c19Sopenharmony_ci } 21595489c19Sopenharmony_ci 21695489c19Sopenharmony_ci void OnPlayItem(const RawAddress &rawAddr, int status, int result) override 21795489c19Sopenharmony_ci { 21895489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, status: %{public}d, res: %{public}d", 21995489c19Sopenharmony_ci GET_ENCRYPT_RAW_ADDR(rawAddr), status, result); 22095489c19Sopenharmony_ci 22195489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 22295489c19Sopenharmony_ci impl_->OnPlayItem(device, static_cast<int>(status), static_cast<int>(result)); 22395489c19Sopenharmony_ci 22495489c19Sopenharmony_ci return; 22595489c19Sopenharmony_ci } 22695489c19Sopenharmony_ci 22795489c19Sopenharmony_ci void OnGetMediaPlayers(const RawAddress &rawAddr, uint16_t uidCounter, 22895489c19Sopenharmony_ci std::vector<BluetoothAvrcpMpItem> &items, int result, int detail) override 22995489c19Sopenharmony_ci { 23095489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, uidCounter: %{public}d, res: %{public}d, detail: %{public}d", 23195489c19Sopenharmony_ci GET_ENCRYPT_RAW_ADDR(rawAddr), uidCounter, result, detail); 23295489c19Sopenharmony_ci 23395489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 23495489c19Sopenharmony_ci std::vector<AvrcMpItem> myItems; 23595489c19Sopenharmony_ci for (size_t i = 0; i < items.size(); i++) { 23695489c19Sopenharmony_ci AvrcMpItem myItem; 23795489c19Sopenharmony_ci myItem.itemType_ = items.at(i).itemType_; 23895489c19Sopenharmony_ci myItem.playerId_ = items.at(i).playerId_; 23995489c19Sopenharmony_ci myItem.majorType_ = items.at(i).majorType_; 24095489c19Sopenharmony_ci myItem.subType_ = items.at(i).subType_; 24195489c19Sopenharmony_ci myItem.playStatus_ = items.at(i).playStatus_; 24295489c19Sopenharmony_ci myItem.features_ = items.at(i).features_; 24395489c19Sopenharmony_ci myItem.name_ = items.at(i).name_; 24495489c19Sopenharmony_ci myItems.push_back(myItem); 24595489c19Sopenharmony_ci } 24695489c19Sopenharmony_ci 24795489c19Sopenharmony_ci impl_->OnGetMediaPlayers( 24895489c19Sopenharmony_ci device, static_cast<uint32_t>(uidCounter), myItems, static_cast<int>(result), static_cast<int>(detail)); 24995489c19Sopenharmony_ci 25095489c19Sopenharmony_ci return; 25195489c19Sopenharmony_ci } 25295489c19Sopenharmony_ci 25395489c19Sopenharmony_ci void OnGetFolderItems(const RawAddress &rawAddr, uint16_t uidCounter, std::vector<BluetoothAvrcpMeItem> &items, 25495489c19Sopenharmony_ci int result, int detail) override 25595489c19Sopenharmony_ci { 25695489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 25795489c19Sopenharmony_ci std::vector<AvrcMeItem> myItems; 25895489c19Sopenharmony_ci for (size_t i = 0; i < items.size(); i++) { 25995489c19Sopenharmony_ci AvrcMeItem myItem; 26095489c19Sopenharmony_ci myItem.uid_ = items.at(i).uid_; 26195489c19Sopenharmony_ci myItem.type_ = items.at(i).type_; 26295489c19Sopenharmony_ci myItem.playable_ = items.at(i).playable_; 26395489c19Sopenharmony_ci myItem.name_ = items.at(i).name_; 26495489c19Sopenharmony_ci myItem.attributes_ = items.at(i).attributes_; 26595489c19Sopenharmony_ci myItem.values_ = items.at(i).values_; 26695489c19Sopenharmony_ci 26795489c19Sopenharmony_ci myItems.push_back(myItem); 26895489c19Sopenharmony_ci } 26995489c19Sopenharmony_ci impl_->OnGetFolderItems( 27095489c19Sopenharmony_ci device, static_cast<uint32_t>(uidCounter), myItems, static_cast<int>(result), static_cast<int>(detail)); 27195489c19Sopenharmony_ci 27295489c19Sopenharmony_ci return; 27395489c19Sopenharmony_ci } 27495489c19Sopenharmony_ci 27595489c19Sopenharmony_ci void OnGetItemAttributes(const RawAddress &rawAddr, const std::vector<uint32_t> &attribtues, 27695489c19Sopenharmony_ci const std::vector<std::string> &values, int result, int detail) override 27795489c19Sopenharmony_ci { 27895489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, res: %{public}d, detail: %{public}d", 27995489c19Sopenharmony_ci GET_ENCRYPT_RAW_ADDR(rawAddr), result, detail); 28095489c19Sopenharmony_ci 28195489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 28295489c19Sopenharmony_ci 28395489c19Sopenharmony_ci impl_->OnGetItemAttributes(device, attribtues, values, static_cast<int>(result), static_cast<int>(detail)); 28495489c19Sopenharmony_ci 28595489c19Sopenharmony_ci return; 28695489c19Sopenharmony_ci } 28795489c19Sopenharmony_ci 28895489c19Sopenharmony_ci void OnGetTotalNumberOfItems(const RawAddress &rawAddr, uint16_t uidCounter, uint32_t numOfItems, 28995489c19Sopenharmony_ci int result, int detail) override 29095489c19Sopenharmony_ci { 29195489c19Sopenharmony_ci HILOGI("address: %{public}s, uidCounter: %{public}d, numOfItems: %{public}d, res: %{public}d, " 29295489c19Sopenharmony_ci "detail: %{public}d", GET_ENCRYPT_RAW_ADDR(rawAddr), uidCounter, numOfItems, result, detail); 29395489c19Sopenharmony_ci 29495489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 29595489c19Sopenharmony_ci impl_->OnGetTotalNumberOfItems(device, 29695489c19Sopenharmony_ci static_cast<uint32_t>(uidCounter), 29795489c19Sopenharmony_ci static_cast<uint32_t>(numOfItems), 29895489c19Sopenharmony_ci static_cast<uint8_t>(result), 29995489c19Sopenharmony_ci static_cast<int>(detail)); 30095489c19Sopenharmony_ci 30195489c19Sopenharmony_ci return; 30295489c19Sopenharmony_ci } 30395489c19Sopenharmony_ci 30495489c19Sopenharmony_ci void OnSetAbsoluteVolume(const RawAddress &rawAddr, uint8_t volume, int result) override 30595489c19Sopenharmony_ci { 30695489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, volume: %{public}d, res: %{public}d", 30795489c19Sopenharmony_ci GET_ENCRYPT_RAW_ADDR(rawAddr), volume, result); 30895489c19Sopenharmony_ci 30995489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 31095489c19Sopenharmony_ci impl_->OnSetAbsoluteVolume(device, static_cast<uint8_t>(volume), result); 31195489c19Sopenharmony_ci 31295489c19Sopenharmony_ci return; 31395489c19Sopenharmony_ci } 31495489c19Sopenharmony_ci 31595489c19Sopenharmony_ci void OnPlaybackStatusChanged(const RawAddress &rawAddr, uint8_t playStatus, int result) override 31695489c19Sopenharmony_ci { 31795489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, status: %{public}d, res: %{public}d", 31895489c19Sopenharmony_ci GET_ENCRYPT_RAW_ADDR(rawAddr), playStatus, result); 31995489c19Sopenharmony_ci 32095489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 32195489c19Sopenharmony_ci impl_->OnPlaybackStatusChanged(device, static_cast<uint8_t>(playStatus), static_cast<int>(result)); 32295489c19Sopenharmony_ci 32395489c19Sopenharmony_ci return; 32495489c19Sopenharmony_ci } 32595489c19Sopenharmony_ci 32695489c19Sopenharmony_ci void OnTrackChanged(const RawAddress &rawAddr, uint64_t uid, int result) override 32795489c19Sopenharmony_ci { 32895489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, res: %{public}d", GET_ENCRYPT_RAW_ADDR(rawAddr), result); 32995489c19Sopenharmony_ci 33095489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 33195489c19Sopenharmony_ci impl_->OnTrackChanged(device, static_cast<uint64_t>(uid), static_cast<int>(result)); 33295489c19Sopenharmony_ci 33395489c19Sopenharmony_ci return; 33495489c19Sopenharmony_ci } 33595489c19Sopenharmony_ci 33695489c19Sopenharmony_ci void OnTrackReachedEnd(const RawAddress &rawAddr, int result) override 33795489c19Sopenharmony_ci { 33895489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, res: %{public}d", GET_ENCRYPT_RAW_ADDR(rawAddr), result); 33995489c19Sopenharmony_ci 34095489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 34195489c19Sopenharmony_ci impl_->OnTrackReachedEnd(device, static_cast<int>(result)); 34295489c19Sopenharmony_ci 34395489c19Sopenharmony_ci return; 34495489c19Sopenharmony_ci } 34595489c19Sopenharmony_ci 34695489c19Sopenharmony_ci void OnTrackReachedStart(const RawAddress &rawAddr, int result) override 34795489c19Sopenharmony_ci { 34895489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, res: %{public}d", GET_ENCRYPT_RAW_ADDR(rawAddr), result); 34995489c19Sopenharmony_ci 35095489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 35195489c19Sopenharmony_ci impl_->OnTrackReachedStart(device, static_cast<int>(result)); 35295489c19Sopenharmony_ci 35395489c19Sopenharmony_ci return; 35495489c19Sopenharmony_ci } 35595489c19Sopenharmony_ci 35695489c19Sopenharmony_ci void OnPlaybackPosChanged(const RawAddress &rawAddr, uint32_t playbackPos, int result) override 35795489c19Sopenharmony_ci { 35895489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, playbackPos: %{public}d, res: %{public}d", 35995489c19Sopenharmony_ci GET_ENCRYPT_RAW_ADDR(rawAddr), playbackPos, result); 36095489c19Sopenharmony_ci 36195489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 36295489c19Sopenharmony_ci impl_->OnPlaybackPosChanged(device, static_cast<uint32_t>(playbackPos), static_cast<int>(result)); 36395489c19Sopenharmony_ci 36495489c19Sopenharmony_ci return; 36595489c19Sopenharmony_ci } 36695489c19Sopenharmony_ci 36795489c19Sopenharmony_ci void OnPlayerAppSettingChanged(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes, 36895489c19Sopenharmony_ci const std::vector<uint8_t> &values, int result) override 36995489c19Sopenharmony_ci { 37095489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, res: %{public}d", GET_ENCRYPT_RAW_ADDR(rawAddr), result); 37195489c19Sopenharmony_ci 37295489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 37395489c19Sopenharmony_ci impl_->OnPlayerAppSettingChanged(device, attributes, values, static_cast<int>(result)); 37495489c19Sopenharmony_ci 37595489c19Sopenharmony_ci return; 37695489c19Sopenharmony_ci } 37795489c19Sopenharmony_ci 37895489c19Sopenharmony_ci void OnNowPlayingContentChanged(const RawAddress &rawAddr, int result) override 37995489c19Sopenharmony_ci { 38095489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, res: %{public}d", GET_ENCRYPT_RAW_ADDR(rawAddr), result); 38195489c19Sopenharmony_ci 38295489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 38395489c19Sopenharmony_ci impl_->OnNowPlayingContentChanged(device, static_cast<int>(result)); 38495489c19Sopenharmony_ci 38595489c19Sopenharmony_ci return; 38695489c19Sopenharmony_ci } 38795489c19Sopenharmony_ci 38895489c19Sopenharmony_ci void OnAvailablePlayersChanged(const RawAddress &rawAddr, int result) override 38995489c19Sopenharmony_ci { 39095489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, res: %{public}d", GET_ENCRYPT_RAW_ADDR(rawAddr), result); 39195489c19Sopenharmony_ci 39295489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 39395489c19Sopenharmony_ci impl_->OnAvailablePlayersChanged(device, static_cast<int>(result)); 39495489c19Sopenharmony_ci 39595489c19Sopenharmony_ci return; 39695489c19Sopenharmony_ci } 39795489c19Sopenharmony_ci 39895489c19Sopenharmony_ci void OnAddressedPlayerChanged( 39995489c19Sopenharmony_ci const RawAddress &rawAddr, uint16_t playerId, uint16_t uidCounter, int result) override 40095489c19Sopenharmony_ci { 40195489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, playerId: %{public}d, uidCounter: %{public}d, res: %{public}d", 40295489c19Sopenharmony_ci GET_ENCRYPT_RAW_ADDR(rawAddr), playerId, uidCounter, result); 40395489c19Sopenharmony_ci 40495489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 40595489c19Sopenharmony_ci impl_->OnAddressedPlayerChanged( 40695489c19Sopenharmony_ci device, static_cast<uint16_t>(playerId), static_cast<uint16_t>(uidCounter), static_cast<int>(result)); 40795489c19Sopenharmony_ci 40895489c19Sopenharmony_ci return; 40995489c19Sopenharmony_ci } 41095489c19Sopenharmony_ci 41195489c19Sopenharmony_ci void OnUidChanged(const RawAddress &rawAddr, uint16_t uidCounter, int result) override 41295489c19Sopenharmony_ci { 41395489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, uidCounter: %{public}d, res: %{public}d", 41495489c19Sopenharmony_ci GET_ENCRYPT_RAW_ADDR(rawAddr), uidCounter, result); 41595489c19Sopenharmony_ci 41695489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 41795489c19Sopenharmony_ci impl_->OnUidChanged(device, static_cast<uint16_t>(uidCounter), static_cast<int>(result)); 41895489c19Sopenharmony_ci 41995489c19Sopenharmony_ci return; 42095489c19Sopenharmony_ci } 42195489c19Sopenharmony_ci 42295489c19Sopenharmony_ci void OnVolumeChanged(const RawAddress &rawAddr, uint8_t volume, int result) override 42395489c19Sopenharmony_ci { 42495489c19Sopenharmony_ci HILOGI("enter, address: %{public}s, volume: %{public}d, res: %{public}d", 42595489c19Sopenharmony_ci GET_ENCRYPT_RAW_ADDR(rawAddr), volume, result); 42695489c19Sopenharmony_ci 42795489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 42895489c19Sopenharmony_ci impl_->OnVolumeChanged(device, static_cast<uint8_t>(volume), static_cast<int>(result)); 42995489c19Sopenharmony_ci 43095489c19Sopenharmony_ci return; 43195489c19Sopenharmony_ci } 43295489c19Sopenharmony_ci 43395489c19Sopenharmony_ci private: 43495489c19Sopenharmony_ci AvrcpController::impl *impl_; 43595489c19Sopenharmony_ci }; 43695489c19Sopenharmony_ci 43795489c19Sopenharmony_ci impl(); 43895489c19Sopenharmony_ci ~impl() 43995489c19Sopenharmony_ci { 44095489c19Sopenharmony_ci HILOGI("enter"); 44195489c19Sopenharmony_ci BluetoothProfileManager::GetInstance().DeregisterFunc(profileRegisterId); 44295489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 44395489c19Sopenharmony_ci CHECK_AND_RETURN_LOG(proxy != nullptr, "failed: no proxy"); 44495489c19Sopenharmony_ci proxy->UnregisterObserver(observer_); 44595489c19Sopenharmony_ci } 44695489c19Sopenharmony_ci 44795489c19Sopenharmony_ci void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int state, int cause) 44895489c19Sopenharmony_ci { 44995489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, state: %{public}d, cause: %{public}d", 45095489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), state, cause); 45195489c19Sopenharmony_ci 45295489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 45395489c19Sopenharmony_ci 45495489c19Sopenharmony_ci observers_.ForEach([device, state, cause](std::shared_ptr<IObserver> observer) { 45595489c19Sopenharmony_ci observer->OnConnectionStateChanged(device, state, cause); 45695489c19Sopenharmony_ci }); 45795489c19Sopenharmony_ci } 45895489c19Sopenharmony_ci 45995489c19Sopenharmony_ci void OnPressButton(const BluetoothRemoteDevice &device, uint8_t button, int result) 46095489c19Sopenharmony_ci { 46195489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, button: %{public}d, res: %{public}d", 46295489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), button, result); 46395489c19Sopenharmony_ci 46495489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 46595489c19Sopenharmony_ci 46695489c19Sopenharmony_ci observers_.ForEach([device, button, result](std::shared_ptr<IObserver> observer) { 46795489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_PRESS_BUTTON, result); 46895489c19Sopenharmony_ci resp.button_ = std::make_unique<AvrcpCtResponse::Button>(button); 46995489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 47095489c19Sopenharmony_ci }); 47195489c19Sopenharmony_ci } 47295489c19Sopenharmony_ci 47395489c19Sopenharmony_ci void OnReleaseButton(const BluetoothRemoteDevice &device, uint8_t button, int result) 47495489c19Sopenharmony_ci { 47595489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, button: %{public}d, res: %{public}d", 47695489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), button, result); 47795489c19Sopenharmony_ci 47895489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 47995489c19Sopenharmony_ci 48095489c19Sopenharmony_ci observers_.ForEach([device, button, result](std::shared_ptr<IObserver> observer) { 48195489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_RELEASE_BUTTON, result); 48295489c19Sopenharmony_ci resp.button_ = std::make_unique<AvrcpCtResponse::Button>(button); 48395489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 48495489c19Sopenharmony_ci }); 48595489c19Sopenharmony_ci } 48695489c19Sopenharmony_ci 48795489c19Sopenharmony_ci void OnSetBrowsedPlayer(const BluetoothRemoteDevice &device, uint16_t uidCounter, uint32_t numOfItems, 48895489c19Sopenharmony_ci const std::vector<std::string> &folderNames, int result, int detail) 48995489c19Sopenharmony_ci { 49095489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d, detail: %{public}d", 49195489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), result, detail); 49295489c19Sopenharmony_ci 49395489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 49495489c19Sopenharmony_ci 49595489c19Sopenharmony_ci observers_.ForEach([device, result](std::shared_ptr<IObserver> observer) { 49695489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_SET_BROWSED_PLAYER, result); 49795489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 49895489c19Sopenharmony_ci }); 49995489c19Sopenharmony_ci } 50095489c19Sopenharmony_ci 50195489c19Sopenharmony_ci void OnGetCapabilities(const BluetoothRemoteDevice &device, const std::vector<uint32_t> &companies, 50295489c19Sopenharmony_ci const std::vector<uint8_t> &events, int result) 50395489c19Sopenharmony_ci { 50495489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d", GET_ENCRYPT_ADDR(device), result); 50595489c19Sopenharmony_ci 50695489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 50795489c19Sopenharmony_ci 50895489c19Sopenharmony_ci observers_.ForEach([device, companies, events, result](std::shared_ptr<IObserver> observer) { 50995489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_CAPABILITIES, result); 51095489c19Sopenharmony_ci if (companies.size() == 0) { 51195489c19Sopenharmony_ci resp.capabilities_ = std::make_unique<AvrcpCtResponse::Capabilities>(events); 51295489c19Sopenharmony_ci } else { 51395489c19Sopenharmony_ci resp.capabilities_ = std::make_unique<AvrcpCtResponse::Capabilities>(companies); 51495489c19Sopenharmony_ci } 51595489c19Sopenharmony_ci 51695489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 51795489c19Sopenharmony_ci }); 51895489c19Sopenharmony_ci } 51995489c19Sopenharmony_ci 52095489c19Sopenharmony_ci void OnGetPlayerAppSettingAttributes( 52195489c19Sopenharmony_ci const BluetoothRemoteDevice &device, std::vector<uint8_t> attributes, int result) 52295489c19Sopenharmony_ci { 52395489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d", GET_ENCRYPT_ADDR(device), result); 52495489c19Sopenharmony_ci 52595489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 52695489c19Sopenharmony_ci 52795489c19Sopenharmony_ci observers_.ForEach([device, attributes, result](std::shared_ptr<IObserver> observer) { 52895489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_PLAYER_APP_SETTING_ATTRIBUTES, result); 52995489c19Sopenharmony_ci resp.playerAttrs_ = std::make_unique<AvrcpCtResponse::PlayerSettingAttributes>(attributes); 53095489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 53195489c19Sopenharmony_ci }); 53295489c19Sopenharmony_ci } 53395489c19Sopenharmony_ci 53495489c19Sopenharmony_ci void OnGetPlayerAppSettingValues( 53595489c19Sopenharmony_ci const BluetoothRemoteDevice &device, uint8_t attribute, std::vector<uint8_t> values, int result) 53695489c19Sopenharmony_ci { 53795489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d", GET_ENCRYPT_ADDR(device), result); 53895489c19Sopenharmony_ci 53995489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 54095489c19Sopenharmony_ci 54195489c19Sopenharmony_ci observers_.ForEach([device, attribute, values, result](std::shared_ptr<IObserver> observer) { 54295489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_PLAYER_APP_SETTING_VALUES, result); 54395489c19Sopenharmony_ci resp.playerVals_ = std::make_unique<AvrcpCtResponse::PlayerSettingValues>(attribute, values); 54495489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 54595489c19Sopenharmony_ci }); 54695489c19Sopenharmony_ci } 54795489c19Sopenharmony_ci 54895489c19Sopenharmony_ci void OnGetPlayerAppSettingCurrentValue( 54995489c19Sopenharmony_ci const BluetoothRemoteDevice &device, std::vector<uint8_t> attributes, std::vector<uint8_t> values, int result) 55095489c19Sopenharmony_ci { 55195489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d", GET_ENCRYPT_ADDR(device), result); 55295489c19Sopenharmony_ci 55395489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 55495489c19Sopenharmony_ci 55595489c19Sopenharmony_ci observers_.ForEach([device, attributes, values, result](std::shared_ptr<IObserver> observer) { 55695489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_PLAYER_APP_SETTING_CURRENT_VALUE, result); 55795489c19Sopenharmony_ci resp.playerCurVal_ = std::make_unique<AvrcpCtResponse::PlayerSettingCurrentValue>(attributes, values); 55895489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 55995489c19Sopenharmony_ci }); 56095489c19Sopenharmony_ci } 56195489c19Sopenharmony_ci 56295489c19Sopenharmony_ci void OnSetPlayerAppSettingCurrentValue(const BluetoothRemoteDevice &device, int result) 56395489c19Sopenharmony_ci { 56495489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d", GET_ENCRYPT_ADDR(device), result); 56595489c19Sopenharmony_ci 56695489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 56795489c19Sopenharmony_ci 56895489c19Sopenharmony_ci observers_.ForEach([device, result](std::shared_ptr<IObserver> observer) { 56995489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_SET_PLAYER_APP_SETTING_CURRENT_VALUE, result); 57095489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 57195489c19Sopenharmony_ci }); 57295489c19Sopenharmony_ci } 57395489c19Sopenharmony_ci 57495489c19Sopenharmony_ci void OnGetPlayerAppSettingAttributeText(const BluetoothRemoteDevice &device, const std::vector<uint8_t> &attributes, 57595489c19Sopenharmony_ci const std::vector<std::string> &valueName, int result) 57695489c19Sopenharmony_ci { 57795489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d", GET_ENCRYPT_ADDR(device), result); 57895489c19Sopenharmony_ci 57995489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 58095489c19Sopenharmony_ci 58195489c19Sopenharmony_ci observers_.ForEach([device, attributes, valueName, result](std::shared_ptr<IObserver> observer) { 58295489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_PLAYER_APP_SETTING_ATTRIBUTE_TEXT, result); 58395489c19Sopenharmony_ci resp.playerText_ = std::make_unique<AvrcpCtResponse::PlayerGettingText>(attributes, valueName); 58495489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 58595489c19Sopenharmony_ci }); 58695489c19Sopenharmony_ci } 58795489c19Sopenharmony_ci 58895489c19Sopenharmony_ci void OnGetPlayerAppSettingValueText(const BluetoothRemoteDevice &device, const std::vector<uint8_t> &values, 58995489c19Sopenharmony_ci const std::vector<std::string> &valueName, int result) 59095489c19Sopenharmony_ci { 59195489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d", GET_ENCRYPT_ADDR(device), result); 59295489c19Sopenharmony_ci 59395489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 59495489c19Sopenharmony_ci 59595489c19Sopenharmony_ci observers_.ForEach([device, result, values, valueName](std::shared_ptr<IObserver> observer) { 59695489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_PLAYER_APP_SETTING_VALUE_TEXT, result); 59795489c19Sopenharmony_ci resp.playerText_ = std::make_unique<AvrcpCtResponse::PlayerGettingText>(values, valueName); 59895489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 59995489c19Sopenharmony_ci }); 60095489c19Sopenharmony_ci } 60195489c19Sopenharmony_ci 60295489c19Sopenharmony_ci void OnGetElementAttributes(const BluetoothRemoteDevice &device, const std::vector<uint32_t> &attributes, 60395489c19Sopenharmony_ci const std::vector<std::string> &valueName, int result) 60495489c19Sopenharmony_ci { 60595489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d", GET_ENCRYPT_ADDR(device), result); 60695489c19Sopenharmony_ci 60795489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 60895489c19Sopenharmony_ci 60995489c19Sopenharmony_ci observers_.ForEach([device, result, attributes, valueName](std::shared_ptr<IObserver> observer) { 61095489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_ELEMENT_ATTRIBUTES, result); 61195489c19Sopenharmony_ci resp.eleSts_ = std::make_unique<AvrcpCtResponse::ElementAttributes>(attributes, valueName); 61295489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 61395489c19Sopenharmony_ci }); 61495489c19Sopenharmony_ci } 61595489c19Sopenharmony_ci 61695489c19Sopenharmony_ci void OnGetPlayStatus( 61795489c19Sopenharmony_ci const BluetoothRemoteDevice &device, uint32_t songLength, uint32_t songPosition, uint8_t playStatus, int result) 61895489c19Sopenharmony_ci { 61995489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, songLength: %{public}d, songPosition: %{public}d, playStatus: %{public}d," 62095489c19Sopenharmony_ci " res: %{public}d", GET_ENCRYPT_ADDR(device), songLength, songPosition, playStatus, result); 62195489c19Sopenharmony_ci 62295489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 62395489c19Sopenharmony_ci 62495489c19Sopenharmony_ci observers_.ForEach([device, result](std::shared_ptr<IObserver> observer) { 62595489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_PLAY_STATUS, result); 62695489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 62795489c19Sopenharmony_ci }); 62895489c19Sopenharmony_ci } 62995489c19Sopenharmony_ci 63095489c19Sopenharmony_ci void OnPlayItem(const BluetoothRemoteDevice &device, int result, int detail) 63195489c19Sopenharmony_ci { 63295489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d, detail: %{public}d", 63395489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), result, detail); 63495489c19Sopenharmony_ci 63595489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 63695489c19Sopenharmony_ci 63795489c19Sopenharmony_ci observers_.ForEach([device, result](std::shared_ptr<IObserver> observer) { 63895489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_PLAY_ITEM, result); 63995489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 64095489c19Sopenharmony_ci }); 64195489c19Sopenharmony_ci } 64295489c19Sopenharmony_ci 64395489c19Sopenharmony_ci void OnGetMediaPlayers(const BluetoothRemoteDevice &device, uint16_t uidCounter, 64495489c19Sopenharmony_ci const std::vector<AvrcMpItem> &items, int result, int detail) 64595489c19Sopenharmony_ci { 64695489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, uidCounter: %{public}d, res: %{public}d, detail: %{public}d", 64795489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), uidCounter, result, detail); 64895489c19Sopenharmony_ci 64995489c19Sopenharmony_ci std::vector<AvrcpCtResponse::MediaPlayers::MediaPlayer> MediaPlayers; 65095489c19Sopenharmony_ci for (int i = 0; i < static_cast<int>(items.size()); i++) { 65195489c19Sopenharmony_ci AvrcpCtResponse::MediaPlayers::MediaPlayer mediaPlayer; 65295489c19Sopenharmony_ci mediaPlayer.itemType_ = items.at(i).itemType_; 65395489c19Sopenharmony_ci mediaPlayer.playerId_ = items.at(i).playerId_; 65495489c19Sopenharmony_ci mediaPlayer.majorType_ = items.at(i).majorType_; 65595489c19Sopenharmony_ci mediaPlayer.subType_ = items.at(i).subType_; 65695489c19Sopenharmony_ci mediaPlayer.playStatus_ = items.at(i).playStatus_; 65795489c19Sopenharmony_ci mediaPlayer.features_ = items.at(i).features_; 65895489c19Sopenharmony_ci mediaPlayer.name_ = items.at(i).name_; 65995489c19Sopenharmony_ci 66095489c19Sopenharmony_ci MediaPlayers.push_back(mediaPlayer); 66195489c19Sopenharmony_ci } 66295489c19Sopenharmony_ci 66395489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 66495489c19Sopenharmony_ci observers_.ForEach([device, result, MediaPlayers, uidCounter](std::shared_ptr<IObserver> observer) { 66595489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_MEDIA_PLAYER_LIST, result); 66695489c19Sopenharmony_ci resp.mediaPlayers_ = std::make_unique<AvrcpCtResponse::MediaPlayers>(uidCounter, MediaPlayers); 66795489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 66895489c19Sopenharmony_ci }); 66995489c19Sopenharmony_ci } 67095489c19Sopenharmony_ci 67195489c19Sopenharmony_ci void OnGetFolderItems(const BluetoothRemoteDevice &device, uint16_t uidCounter, 67295489c19Sopenharmony_ci const std::vector<AvrcMeItem> &items, int result, int detail) 67395489c19Sopenharmony_ci { 67495489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, uidCounter: %{public}d, res: %{public}d, detail: %{public}d", 67595489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), uidCounter, result, detail); 67695489c19Sopenharmony_ci 67795489c19Sopenharmony_ci std::vector<AvrcpCtResponse::MediaItems::MediaItem> mediaItems; 67895489c19Sopenharmony_ci for (int i = 0; i < static_cast<int>(items.size()); i++) { 67995489c19Sopenharmony_ci AvrcpCtResponse::MediaItems::MediaItem mediaItem; 68095489c19Sopenharmony_ci mediaItem.uid_ = items.at(i).uid_; 68195489c19Sopenharmony_ci mediaItem.type_ = items.at(i).type_; 68295489c19Sopenharmony_ci mediaItem.playable_ = items.at(i).playable_; 68395489c19Sopenharmony_ci mediaItem.name_ = items.at(i).name_; 68495489c19Sopenharmony_ci mediaItem.attributes_ = items.at(i).attributes_; 68595489c19Sopenharmony_ci mediaItem.values_ = items.at(i).values_; 68695489c19Sopenharmony_ci 68795489c19Sopenharmony_ci mediaItems.push_back(mediaItem); 68895489c19Sopenharmony_ci } 68995489c19Sopenharmony_ci 69095489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 69195489c19Sopenharmony_ci observers_.ForEach([device, result, mediaItems, uidCounter](std::shared_ptr<IObserver> observer) { 69295489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_FOLDER_ITEMS, result); 69395489c19Sopenharmony_ci resp.mediaItems_ = std::make_unique<AvrcpCtResponse::MediaItems>(uidCounter, mediaItems); 69495489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 69595489c19Sopenharmony_ci }); 69695489c19Sopenharmony_ci } 69795489c19Sopenharmony_ci 69895489c19Sopenharmony_ci void OnGetItemAttributes(const BluetoothRemoteDevice &device, const std::vector<uint32_t> &attributes, 69995489c19Sopenharmony_ci const std::vector<std::string> &values, int result, int detail) 70095489c19Sopenharmony_ci { 70195489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d, detail: %{public}d", 70295489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), result, detail); 70395489c19Sopenharmony_ci std::vector<AvrcpCtResponse::ItemAttributes::ItemAttribute> itemAttrs; 70495489c19Sopenharmony_ci for (int i = 0; i < static_cast<int>(attributes.size()); i++) { 70595489c19Sopenharmony_ci AvrcpCtResponse::ItemAttributes::ItemAttribute itemAttr; 70695489c19Sopenharmony_ci itemAttr.attribute_ = attributes.at(i); 70795489c19Sopenharmony_ci itemAttr.value_ = values.at(i); 70895489c19Sopenharmony_ci itemAttrs.push_back(itemAttr); 70995489c19Sopenharmony_ci } 71095489c19Sopenharmony_ci 71195489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 71295489c19Sopenharmony_ci observers_.ForEach([device, result, itemAttrs](std::shared_ptr<IObserver> observer) { 71395489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_ITEM_ATTRIBUTES, result); 71495489c19Sopenharmony_ci resp.itemAttrs_ = std::make_unique<AvrcpCtResponse::ItemAttributes>(itemAttrs); 71595489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 71695489c19Sopenharmony_ci }); 71795489c19Sopenharmony_ci } 71895489c19Sopenharmony_ci 71995489c19Sopenharmony_ci void OnGetTotalNumberOfItems( 72095489c19Sopenharmony_ci const BluetoothRemoteDevice &device, uint16_t uidCounter, uint32_t numOfItems, int result, int detail) 72195489c19Sopenharmony_ci { 72295489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d, detail: %{public}d", 72395489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), result, detail); 72495489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 72595489c19Sopenharmony_ci 72695489c19Sopenharmony_ci observers_.ForEach([device, uidCounter, numOfItems, result](std::shared_ptr<IObserver> observer) { 72795489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_TOTAL_NUMBER_OF_ITEMS, result); 72895489c19Sopenharmony_ci resp.totalItems_ = std::make_unique<AvrcpCtResponse::TotalNumberOfItems>(uidCounter, numOfItems); 72995489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 73095489c19Sopenharmony_ci }); 73195489c19Sopenharmony_ci } 73295489c19Sopenharmony_ci 73395489c19Sopenharmony_ci void OnSetAbsoluteVolume(const BluetoothRemoteDevice &device, uint16_t volume, int result) 73495489c19Sopenharmony_ci { 73595489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, volume: %{public}d, res: %{public}d", 73695489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), volume, result); 73795489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 73895489c19Sopenharmony_ci 73995489c19Sopenharmony_ci observers_.ForEach([device, volume, result](std::shared_ptr<IObserver> observer) { 74095489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_SET_ABSOLUTE_VOLUME, result); 74195489c19Sopenharmony_ci resp.absVolume_ = std::make_unique<AvrcpCtResponse::AbsoluteVolume>(volume); 74295489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 74395489c19Sopenharmony_ci }); 74495489c19Sopenharmony_ci } 74595489c19Sopenharmony_ci 74695489c19Sopenharmony_ci void OnPlaybackStatusChanged(const BluetoothRemoteDevice &device, uint8_t playStatus, int result) 74795489c19Sopenharmony_ci { 74895489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, playStatus: %{public}d, res: %{public}d", 74995489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), playStatus, result); 75095489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 75195489c19Sopenharmony_ci 75295489c19Sopenharmony_ci observers_.ForEach([device, playStatus, result](std::shared_ptr<IObserver> observer) { 75395489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_PLAYBACK_STATUS_CHANGED, result); 75495489c19Sopenharmony_ci resp.notify_ = std::make_unique<AvrcpCtResponse::Notification>(playStatus, 0x00); 75595489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 75695489c19Sopenharmony_ci }); 75795489c19Sopenharmony_ci } 75895489c19Sopenharmony_ci 75995489c19Sopenharmony_ci void OnTrackChanged(const BluetoothRemoteDevice &device, uint64_t uid, int result) 76095489c19Sopenharmony_ci { 76195489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d", GET_ENCRYPT_ADDR(device), result); 76295489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 76395489c19Sopenharmony_ci 76495489c19Sopenharmony_ci observers_.ForEach([device, uid, result](std::shared_ptr<IObserver> observer) { 76595489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_TRACK_CHANGED, result); 76695489c19Sopenharmony_ci resp.notify_ = std::make_unique<AvrcpCtResponse::Notification>(uid); 76795489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 76895489c19Sopenharmony_ci }); 76995489c19Sopenharmony_ci } 77095489c19Sopenharmony_ci 77195489c19Sopenharmony_ci void OnTrackReachedEnd(const BluetoothRemoteDevice &device, int result) 77295489c19Sopenharmony_ci { 77395489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d", GET_ENCRYPT_ADDR(device), result); 77495489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 77595489c19Sopenharmony_ci 77695489c19Sopenharmony_ci observers_.ForEach([device, result](std::shared_ptr<IObserver> observer) { 77795489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_TRACK_REACHED_END, result); 77895489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 77995489c19Sopenharmony_ci }); 78095489c19Sopenharmony_ci } 78195489c19Sopenharmony_ci 78295489c19Sopenharmony_ci void OnTrackReachedStart(const BluetoothRemoteDevice &device, int result) 78395489c19Sopenharmony_ci { 78495489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d", GET_ENCRYPT_ADDR(device), result); 78595489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 78695489c19Sopenharmony_ci 78795489c19Sopenharmony_ci observers_.ForEach([device, result](std::shared_ptr<IObserver> observer) { 78895489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_TRACK_REACHED_START, result); 78995489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 79095489c19Sopenharmony_ci }); 79195489c19Sopenharmony_ci } 79295489c19Sopenharmony_ci 79395489c19Sopenharmony_ci void OnPlaybackPosChanged(const BluetoothRemoteDevice &device, uint32_t playbackPos, int result) 79495489c19Sopenharmony_ci { 79595489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, playbackPos: %{public}d, res: %{public}d", 79695489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), playbackPos, result); 79795489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 79895489c19Sopenharmony_ci 79995489c19Sopenharmony_ci observers_.ForEach([device, playbackPos, result](std::shared_ptr<IObserver> observer) { 80095489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_PLAYBACK_POS_CHANGED, result); 80195489c19Sopenharmony_ci resp.notify_ = std::make_unique<AvrcpCtResponse::Notification>(playbackPos); 80295489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 80395489c19Sopenharmony_ci }); 80495489c19Sopenharmony_ci } 80595489c19Sopenharmony_ci 80695489c19Sopenharmony_ci void OnPlayerAppSettingChanged(const BluetoothRemoteDevice &device, const std::vector<uint8_t> &attributes, 80795489c19Sopenharmony_ci const std::vector<uint8_t> &values, int result) 80895489c19Sopenharmony_ci { 80995489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d", GET_ENCRYPT_ADDR(device), result); 81095489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 81195489c19Sopenharmony_ci 81295489c19Sopenharmony_ci observers_.ForEach([device, attributes, values, result](std::shared_ptr<IObserver> observer) { 81395489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_PLAYER_APPLICATION_SETTING_CHANGED, result); 81495489c19Sopenharmony_ci resp.notify_ = std::make_unique<AvrcpCtResponse::Notification>(attributes, values); 81595489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 81695489c19Sopenharmony_ci }); 81795489c19Sopenharmony_ci } 81895489c19Sopenharmony_ci 81995489c19Sopenharmony_ci void OnNowPlayingContentChanged(const BluetoothRemoteDevice &device, int result) 82095489c19Sopenharmony_ci { 82195489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d", GET_ENCRYPT_ADDR(device), result); 82295489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 82395489c19Sopenharmony_ci 82495489c19Sopenharmony_ci observers_.ForEach([device, result](std::shared_ptr<IObserver> observer) { 82595489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_NOW_PLAYING_CONTENT_CHANGED, result); 82695489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 82795489c19Sopenharmony_ci }); 82895489c19Sopenharmony_ci } 82995489c19Sopenharmony_ci 83095489c19Sopenharmony_ci void OnAvailablePlayersChanged(const BluetoothRemoteDevice &device, int result) 83195489c19Sopenharmony_ci { 83295489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, res: %{public}d", GET_ENCRYPT_ADDR(device), result); 83395489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 83495489c19Sopenharmony_ci 83595489c19Sopenharmony_ci observers_.ForEach([device, result](std::shared_ptr<IObserver> observer) { 83695489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_AVAILABLE_PLAYERS_CHANGED, result); 83795489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 83895489c19Sopenharmony_ci }); 83995489c19Sopenharmony_ci } 84095489c19Sopenharmony_ci 84195489c19Sopenharmony_ci void OnAddressedPlayerChanged( 84295489c19Sopenharmony_ci const BluetoothRemoteDevice &device, uint16_t playerId, uint16_t uidCounter, int result) 84395489c19Sopenharmony_ci { 84495489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, playerId: %{public}d, uidCounter: %{public}d, res: %{public}d", 84595489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), playerId, uidCounter, result); 84695489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 84795489c19Sopenharmony_ci 84895489c19Sopenharmony_ci observers_.ForEach([device, uidCounter, result](std::shared_ptr<IObserver> observer) { 84995489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_ADDRESSED_PLAYER_CHANGED, result); 85095489c19Sopenharmony_ci resp.notify_ = std::make_unique<AvrcpCtResponse::Notification>(uidCounter); 85195489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 85295489c19Sopenharmony_ci }); 85395489c19Sopenharmony_ci } 85495489c19Sopenharmony_ci 85595489c19Sopenharmony_ci void OnUidChanged(const BluetoothRemoteDevice &device, uint16_t uidCounter, int result) 85695489c19Sopenharmony_ci { 85795489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, uidCounter: %{public}d, res: %{public}d", 85895489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), uidCounter, result); 85995489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 86095489c19Sopenharmony_ci 86195489c19Sopenharmony_ci observers_.ForEach([device, result, uidCounter](std::shared_ptr<IObserver> observer) { 86295489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_UIDS_CHANGED, result); 86395489c19Sopenharmony_ci resp.notify_ = std::make_unique<AvrcpCtResponse::Notification>(uidCounter); 86495489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 86595489c19Sopenharmony_ci }); 86695489c19Sopenharmony_ci } 86795489c19Sopenharmony_ci 86895489c19Sopenharmony_ci void OnVolumeChanged(const BluetoothRemoteDevice &device, uint8_t volume, int result) 86995489c19Sopenharmony_ci { 87095489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, volume: %{public}d, res: %{public}d", 87195489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), volume, result); 87295489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(observerMutex_); 87395489c19Sopenharmony_ci 87495489c19Sopenharmony_ci observers_.ForEach([device, volume, result](std::shared_ptr<IObserver> observer) { 87595489c19Sopenharmony_ci AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_VOLUME_CHANGED, result); 87695489c19Sopenharmony_ci resp.notify_ = std::make_unique<AvrcpCtResponse::Notification>(0x00, volume); 87795489c19Sopenharmony_ci observer->OnActionCompleted(device, resp); 87895489c19Sopenharmony_ci }); 87995489c19Sopenharmony_ci } 88095489c19Sopenharmony_ci std::mutex observerMutex_; 88195489c19Sopenharmony_ci BluetoothObserverList<AvrcpController::IObserver> observers_; 88295489c19Sopenharmony_ci 88395489c19Sopenharmony_ci sptr<ObserverImpl> observer_; 88495489c19Sopenharmony_ci int32_t profileRegisterId = 0; 88595489c19Sopenharmony_ci}; 88695489c19Sopenharmony_ci 88795489c19Sopenharmony_ciAvrcpController::impl::impl() 88895489c19Sopenharmony_ci{ 88995489c19Sopenharmony_ci observer_ = new (std::nothrow) ObserverImpl(this); 89095489c19Sopenharmony_ci CHECK_AND_RETURN_LOG(observer_ != nullptr, "observer_ is nullptr"); 89195489c19Sopenharmony_ci profileRegisterId = BluetoothProfileManager::GetInstance().RegisterFunc(PROFILE_AVRCP_CT, 89295489c19Sopenharmony_ci [this](sptr<IRemoteObject> remote) { 89395489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = iface_cast<IBluetoothAvrcpCt>(remote); 89495489c19Sopenharmony_ci CHECK_AND_RETURN_LOG(proxy != nullptr, "failed: no proxy"); 89595489c19Sopenharmony_ci proxy->RegisterObserver(observer_); 89695489c19Sopenharmony_ci }); 89795489c19Sopenharmony_ci} 89895489c19Sopenharmony_ci 89995489c19Sopenharmony_ciAvrcpController *AvrcpController::GetProfile(void) 90095489c19Sopenharmony_ci{ 90195489c19Sopenharmony_ci HILOGI("enter"); 90295489c19Sopenharmony_ci#ifdef DTFUZZ_TEST 90395489c19Sopenharmony_ci static BluetoothNoDestructor<AvrcpController> instance; 90495489c19Sopenharmony_ci return instance.get(); 90595489c19Sopenharmony_ci#else 90695489c19Sopenharmony_ci static AvrcpController instance; 90795489c19Sopenharmony_ci return &instance; 90895489c19Sopenharmony_ci#endif 90995489c19Sopenharmony_ci} 91095489c19Sopenharmony_ci 91195489c19Sopenharmony_ci/****************************************************************** 91295489c19Sopenharmony_ci * REGISTER / UNREGISTER OBSERVER * 91395489c19Sopenharmony_ci ******************************************************************/ 91495489c19Sopenharmony_ci 91595489c19Sopenharmony_civoid AvrcpController::RegisterObserver(std::shared_ptr<IObserver> observer) 91695489c19Sopenharmony_ci{ 91795489c19Sopenharmony_ci HILOGD("enter"); 91895489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(pimpl->observerMutex_); 91995489c19Sopenharmony_ci CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); 92095489c19Sopenharmony_ci pimpl->observers_.Register(observer); 92195489c19Sopenharmony_ci} 92295489c19Sopenharmony_ci 92395489c19Sopenharmony_civoid AvrcpController::UnregisterObserver(std::shared_ptr<IObserver> observer) 92495489c19Sopenharmony_ci{ 92595489c19Sopenharmony_ci HILOGD("enter"); 92695489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(pimpl->observerMutex_); 92795489c19Sopenharmony_ci CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); 92895489c19Sopenharmony_ci pimpl->observers_.Deregister(observer); 92995489c19Sopenharmony_ci} 93095489c19Sopenharmony_ci 93195489c19Sopenharmony_ci/****************************************************************** 93295489c19Sopenharmony_ci * CONNECTION * 93395489c19Sopenharmony_ci ******************************************************************/ 93495489c19Sopenharmony_ci 93595489c19Sopenharmony_cistd::vector<BluetoothRemoteDevice> AvrcpController::GetConnectedDevices(void) 93695489c19Sopenharmony_ci{ 93795489c19Sopenharmony_ci HILOGI("enter"); 93895489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 93995489c19Sopenharmony_ci HILOGE("bluetooth is off."); 94095489c19Sopenharmony_ci return std::vector<BluetoothRemoteDevice>(); 94195489c19Sopenharmony_ci } 94295489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 94395489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, 94495489c19Sopenharmony_ci std::vector<BluetoothRemoteDevice>(), "failed: no proxy"); 94595489c19Sopenharmony_ci 94695489c19Sopenharmony_ci std::lock_guard<std::mutex> lock(pimpl->observerMutex_); 94795489c19Sopenharmony_ci std::vector<BluetoothRemoteDevice> devices; 94895489c19Sopenharmony_ci std::vector<RawAddress> rawAddrs = proxy->GetConnectedDevices(); 94995489c19Sopenharmony_ci for (auto rawAddr : rawAddrs) { 95095489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 95195489c19Sopenharmony_ci devices.push_back(device); 95295489c19Sopenharmony_ci } 95395489c19Sopenharmony_ci return devices; 95495489c19Sopenharmony_ci} 95595489c19Sopenharmony_ci 95695489c19Sopenharmony_cistd::vector<BluetoothRemoteDevice> AvrcpController::GetDevicesByStates(const std::vector<int> &states) 95795489c19Sopenharmony_ci{ 95895489c19Sopenharmony_ci HILOGI("enter"); 95995489c19Sopenharmony_ci 96095489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 96195489c19Sopenharmony_ci HILOGE("bluetooth is off."); 96295489c19Sopenharmony_ci return std::vector<BluetoothRemoteDevice>(); 96395489c19Sopenharmony_ci } 96495489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 96595489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, 96695489c19Sopenharmony_ci std::vector<BluetoothRemoteDevice>(), "failed: no proxy"); 96795489c19Sopenharmony_ci 96895489c19Sopenharmony_ci std::vector<BluetoothRemoteDevice> devices; 96995489c19Sopenharmony_ci if (proxy != nullptr) { 97095489c19Sopenharmony_ci std::vector<int32_t> convertStates; 97195489c19Sopenharmony_ci for (auto state : states) { 97295489c19Sopenharmony_ci convertStates.push_back(static_cast<int32_t>(state)); 97395489c19Sopenharmony_ci } 97495489c19Sopenharmony_ci std::vector<RawAddress> rawAddrs = proxy->GetDevicesByStates(convertStates); 97595489c19Sopenharmony_ci for (auto rawAddr : rawAddrs) { 97695489c19Sopenharmony_ci BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR); 97795489c19Sopenharmony_ci devices.push_back(device); 97895489c19Sopenharmony_ci } 97995489c19Sopenharmony_ci } 98095489c19Sopenharmony_ci 98195489c19Sopenharmony_ci return devices; 98295489c19Sopenharmony_ci} 98395489c19Sopenharmony_ci 98495489c19Sopenharmony_ciint AvrcpController::GetDeviceState(const BluetoothRemoteDevice &device) 98595489c19Sopenharmony_ci{ 98695489c19Sopenharmony_ci HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device)); 98795489c19Sopenharmony_ci 98895489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 98995489c19Sopenharmony_ci HILOGE("bluetooth is off."); 99095489c19Sopenharmony_ci return static_cast<int>(BTConnectState::DISCONNECTED); 99195489c19Sopenharmony_ci } 99295489c19Sopenharmony_ci 99395489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 99495489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, 99595489c19Sopenharmony_ci static_cast<int>(BTConnectState::DISCONNECTED), "failed: no proxy"); 99695489c19Sopenharmony_ci 99795489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 99895489c19Sopenharmony_ci return proxy->GetDeviceState(rawAddr); 99995489c19Sopenharmony_ci} 100095489c19Sopenharmony_ci 100195489c19Sopenharmony_cibool AvrcpController::Connect(const BluetoothRemoteDevice &device) 100295489c19Sopenharmony_ci{ 100395489c19Sopenharmony_ci HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device)); 100495489c19Sopenharmony_ci 100595489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 100695489c19Sopenharmony_ci HILOGE("bluetooth is off."); 100795489c19Sopenharmony_ci return false; 100895489c19Sopenharmony_ci } 100995489c19Sopenharmony_ci 101095489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 101195489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "failed: no proxy"); 101295489c19Sopenharmony_ci 101395489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 101495489c19Sopenharmony_ci int result = proxy->Connect(rawAddr); 101595489c19Sopenharmony_ci return result == RET_NO_ERROR; 101695489c19Sopenharmony_ci} 101795489c19Sopenharmony_ci 101895489c19Sopenharmony_cibool AvrcpController::Disconnect(const BluetoothRemoteDevice &device) 101995489c19Sopenharmony_ci{ 102095489c19Sopenharmony_ci HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device)); 102195489c19Sopenharmony_ci 102295489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 102395489c19Sopenharmony_ci HILOGE("bluetooth is off."); 102495489c19Sopenharmony_ci return false; 102595489c19Sopenharmony_ci } 102695489c19Sopenharmony_ci 102795489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 102895489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "failed: no proxy"); 102995489c19Sopenharmony_ci 103095489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 103195489c19Sopenharmony_ci int result = proxy->Disconnect(rawAddr); 103295489c19Sopenharmony_ci return result == RET_NO_ERROR; 103395489c19Sopenharmony_ci} 103495489c19Sopenharmony_ci 103595489c19Sopenharmony_ci/****************************************************************** 103695489c19Sopenharmony_ci * BUTTON OPERATION * 103795489c19Sopenharmony_ci ******************************************************************/ 103895489c19Sopenharmony_ci 103995489c19Sopenharmony_ciint AvrcpController::PressButton(const BluetoothRemoteDevice &device, uint8_t button) 104095489c19Sopenharmony_ci{ 104195489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, button: %{public}d", GET_ENCRYPT_ADDR(device), button); 104295489c19Sopenharmony_ci 104395489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 104495489c19Sopenharmony_ci HILOGE("bluetooth is off."); 104595489c19Sopenharmony_ci return RET_BAD_STATUS; 104695489c19Sopenharmony_ci } 104795489c19Sopenharmony_ci 104895489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 104995489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 105095489c19Sopenharmony_ci 105195489c19Sopenharmony_ci int result = RET_BAD_STATUS; 105295489c19Sopenharmony_ci switch (button) { 105395489c19Sopenharmony_ci case AVRC_KEY_OPERATION_VOLUME_UP: 105495489c19Sopenharmony_ci case AVRC_KEY_OPERATION_VOLUME_DOWN: 105595489c19Sopenharmony_ci case AVRC_KEY_OPERATION_MUTE: 105695489c19Sopenharmony_ci case AVRC_KEY_OPERATION_PLAY: 105795489c19Sopenharmony_ci case AVRC_KEY_OPERATION_STOP: 105895489c19Sopenharmony_ci case AVRC_KEY_OPERATION_PAUSE: 105995489c19Sopenharmony_ci case AVRC_KEY_OPERATION_REWIND: 106095489c19Sopenharmony_ci case AVRC_KEY_OPERATION_FAST_FORWARD: 106195489c19Sopenharmony_ci case AVRC_KEY_OPERATION_FORWARD: 106295489c19Sopenharmony_ci case AVRC_KEY_OPERATION_BACKWARD: { 106395489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 106495489c19Sopenharmony_ci result = proxy->PressButton(rawAddr, static_cast<int32_t>(button)); 106595489c19Sopenharmony_ci break; 106695489c19Sopenharmony_ci } 106795489c19Sopenharmony_ci default: 106895489c19Sopenharmony_ci result = RET_NO_SUPPORT; 106995489c19Sopenharmony_ci if (button >= AVRC_KEY_OPERATION_INVALID) { 107095489c19Sopenharmony_ci result = RET_BAD_PARAM; 107195489c19Sopenharmony_ci } 107295489c19Sopenharmony_ci break; 107395489c19Sopenharmony_ci } 107495489c19Sopenharmony_ci return result; 107595489c19Sopenharmony_ci} 107695489c19Sopenharmony_ci 107795489c19Sopenharmony_ciint AvrcpController::ReleaseButton(const BluetoothRemoteDevice &device, uint8_t button) 107895489c19Sopenharmony_ci{ 107995489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, button: %{public}d", GET_ENCRYPT_ADDR(device), button); 108095489c19Sopenharmony_ci 108195489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 108295489c19Sopenharmony_ci HILOGE("bluetooth is off."); 108395489c19Sopenharmony_ci return RET_BAD_STATUS; 108495489c19Sopenharmony_ci } 108595489c19Sopenharmony_ci 108695489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 108795489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 108895489c19Sopenharmony_ci 108995489c19Sopenharmony_ci int result = RET_BAD_STATUS; 109095489c19Sopenharmony_ci switch (button) { 109195489c19Sopenharmony_ci case AVRC_KEY_OPERATION_VOLUME_UP: 109295489c19Sopenharmony_ci case AVRC_KEY_OPERATION_VOLUME_DOWN: 109395489c19Sopenharmony_ci case AVRC_KEY_OPERATION_MUTE: 109495489c19Sopenharmony_ci case AVRC_KEY_OPERATION_PLAY: 109595489c19Sopenharmony_ci case AVRC_KEY_OPERATION_STOP: 109695489c19Sopenharmony_ci case AVRC_KEY_OPERATION_PAUSE: 109795489c19Sopenharmony_ci case AVRC_KEY_OPERATION_REWIND: 109895489c19Sopenharmony_ci case AVRC_KEY_OPERATION_FAST_FORWARD: 109995489c19Sopenharmony_ci case AVRC_KEY_OPERATION_FORWARD: 110095489c19Sopenharmony_ci case AVRC_KEY_OPERATION_BACKWARD: { 110195489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 110295489c19Sopenharmony_ci result = proxy->ReleaseButton(rawAddr, static_cast<int32_t>(button)); 110395489c19Sopenharmony_ci break; 110495489c19Sopenharmony_ci } 110595489c19Sopenharmony_ci default: 110695489c19Sopenharmony_ci result = RET_NO_SUPPORT; 110795489c19Sopenharmony_ci if (button >= AVRC_KEY_OPERATION_INVALID) { 110895489c19Sopenharmony_ci result = RET_BAD_PARAM; 110995489c19Sopenharmony_ci } 111095489c19Sopenharmony_ci break; 111195489c19Sopenharmony_ci } 111295489c19Sopenharmony_ci return result; 111395489c19Sopenharmony_ci} 111495489c19Sopenharmony_ci 111595489c19Sopenharmony_ci/****************************************************************** 111695489c19Sopenharmony_ci * TEMP UNIT INFO / SUB UNIT INFO * 111795489c19Sopenharmony_ci ******************************************************************/ 111895489c19Sopenharmony_ci 111995489c19Sopenharmony_ciint AvrcpController::GetUnitInfo(const BluetoothRemoteDevice &device) 112095489c19Sopenharmony_ci{ 112195489c19Sopenharmony_ci HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device)); 112295489c19Sopenharmony_ci 112395489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 112495489c19Sopenharmony_ci HILOGE("bluetooth is off."); 112595489c19Sopenharmony_ci return RET_BAD_STATUS; 112695489c19Sopenharmony_ci } 112795489c19Sopenharmony_ci 112895489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 112995489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 113095489c19Sopenharmony_ci 113195489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 113295489c19Sopenharmony_ci return proxy->GetUnitInfo(rawAddr); 113395489c19Sopenharmony_ci} 113495489c19Sopenharmony_ci 113595489c19Sopenharmony_ciint AvrcpController::GetSubUnitInfo(const BluetoothRemoteDevice &device) 113695489c19Sopenharmony_ci{ 113795489c19Sopenharmony_ci HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device)); 113895489c19Sopenharmony_ci 113995489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 114095489c19Sopenharmony_ci HILOGE("bluetooth is off."); 114195489c19Sopenharmony_ci return RET_BAD_STATUS; 114295489c19Sopenharmony_ci } 114395489c19Sopenharmony_ci 114495489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 114595489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 114695489c19Sopenharmony_ci 114795489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 114895489c19Sopenharmony_ci return proxy->GetSubUnitInfo(rawAddr); 114995489c19Sopenharmony_ci} 115095489c19Sopenharmony_ci 115195489c19Sopenharmony_ci/****************************************************************** 115295489c19Sopenharmony_ci * Capabilities * 115395489c19Sopenharmony_ci ******************************************************************/ 115495489c19Sopenharmony_ci 115595489c19Sopenharmony_ciint AvrcpController::GetSupportedCompanies(const BluetoothRemoteDevice &device) 115695489c19Sopenharmony_ci{ 115795489c19Sopenharmony_ci HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device)); 115895489c19Sopenharmony_ci 115995489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 116095489c19Sopenharmony_ci HILOGE("bluetooth is off."); 116195489c19Sopenharmony_ci return RET_BAD_STATUS; 116295489c19Sopenharmony_ci } 116395489c19Sopenharmony_ci 116495489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 116595489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 116695489c19Sopenharmony_ci 116795489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 116895489c19Sopenharmony_ci return proxy->GetSupportedCompanies(rawAddr); 116995489c19Sopenharmony_ci} 117095489c19Sopenharmony_ci 117195489c19Sopenharmony_ciint AvrcpController::GetSupportedEvents(const BluetoothRemoteDevice &device) 117295489c19Sopenharmony_ci{ 117395489c19Sopenharmony_ci HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device)); 117495489c19Sopenharmony_ci 117595489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 117695489c19Sopenharmony_ci HILOGE("bluetooth is off."); 117795489c19Sopenharmony_ci return RET_BAD_STATUS; 117895489c19Sopenharmony_ci } 117995489c19Sopenharmony_ci 118095489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 118195489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 118295489c19Sopenharmony_ci 118395489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 118495489c19Sopenharmony_ci return proxy->GetSupportedEvents(rawAddr); 118595489c19Sopenharmony_ci} 118695489c19Sopenharmony_ci 118795489c19Sopenharmony_ci/****************************************************************** 118895489c19Sopenharmony_ci * PLAYER APPLICATION SETTINGS * 118995489c19Sopenharmony_ci ******************************************************************/ 119095489c19Sopenharmony_ci 119195489c19Sopenharmony_ciint AvrcpController::GetPlayerAppSettingAttributes(const BluetoothRemoteDevice &device) 119295489c19Sopenharmony_ci{ 119395489c19Sopenharmony_ci HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device)); 119495489c19Sopenharmony_ci 119595489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 119695489c19Sopenharmony_ci HILOGE("bluetooth is off."); 119795489c19Sopenharmony_ci return RET_BAD_STATUS; 119895489c19Sopenharmony_ci } 119995489c19Sopenharmony_ci 120095489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 120195489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 120295489c19Sopenharmony_ci 120395489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 120495489c19Sopenharmony_ci return proxy->GetPlayerAppSettingAttributes(rawAddr); 120595489c19Sopenharmony_ci} 120695489c19Sopenharmony_ci 120795489c19Sopenharmony_ciint AvrcpController::GetPlayerAppSettingValues(const BluetoothRemoteDevice &device, uint8_t attribute) 120895489c19Sopenharmony_ci{ 120995489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, attribute: %{public}d", GET_ENCRYPT_ADDR(device), attribute); 121095489c19Sopenharmony_ci 121195489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 121295489c19Sopenharmony_ci HILOGE("bluetooth is off."); 121395489c19Sopenharmony_ci return RET_BAD_STATUS; 121495489c19Sopenharmony_ci } 121595489c19Sopenharmony_ci 121695489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 121795489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 121895489c19Sopenharmony_ci 121995489c19Sopenharmony_ci int result = RET_BAD_STATUS; 122095489c19Sopenharmony_ci do { 122195489c19Sopenharmony_ci if (attribute == AVRC_PLAYER_ATTRIBUTE_ILLEGAL) { 122295489c19Sopenharmony_ci result = RET_BAD_PARAM; 122395489c19Sopenharmony_ci break; 122495489c19Sopenharmony_ci } 122595489c19Sopenharmony_ci if (attribute >= AVRC_PLAYER_ATTRIBUTE_RESERVED_MIN && attribute <= AVRC_PLAYER_ATTRIBUTE_RESERVED_MAX) { 122695489c19Sopenharmony_ci result = RET_BAD_PARAM; 122795489c19Sopenharmony_ci break; 122895489c19Sopenharmony_ci } 122995489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 123095489c19Sopenharmony_ci result = proxy->GetPlayerAppSettingValues(rawAddr, static_cast<int32_t>(attribute)); 123195489c19Sopenharmony_ci } while (false); 123295489c19Sopenharmony_ci 123395489c19Sopenharmony_ci return result; 123495489c19Sopenharmony_ci} 123595489c19Sopenharmony_ci 123695489c19Sopenharmony_ciint AvrcpController::GetPlayerAppSettingCurrentValue( 123795489c19Sopenharmony_ci const BluetoothRemoteDevice &device, const std::vector<uint8_t> &attributes) 123895489c19Sopenharmony_ci{ 123995489c19Sopenharmony_ci HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device)); 124095489c19Sopenharmony_ci 124195489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 124295489c19Sopenharmony_ci HILOGE("bluetooth is off."); 124395489c19Sopenharmony_ci return RET_NO_ERROR; 124495489c19Sopenharmony_ci } 124595489c19Sopenharmony_ci 124695489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 124795489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 124895489c19Sopenharmony_ci 124995489c19Sopenharmony_ci int result = RET_NO_ERROR; 125095489c19Sopenharmony_ci do { 125195489c19Sopenharmony_ci std::vector<int32_t> attrs; 125295489c19Sopenharmony_ci for (auto attribute : attributes) { 125395489c19Sopenharmony_ci if (attribute == AVRC_PLAYER_ATTRIBUTE_ILLEGAL) { 125495489c19Sopenharmony_ci result = RET_BAD_PARAM; 125595489c19Sopenharmony_ci break; 125695489c19Sopenharmony_ci } 125795489c19Sopenharmony_ci if (attribute >= AVRC_PLAYER_ATTRIBUTE_RESERVED_MIN && attribute <= AVRC_PLAYER_ATTRIBUTE_RESERVED_MAX) { 125895489c19Sopenharmony_ci result = RET_BAD_PARAM; 125995489c19Sopenharmony_ci break; 126095489c19Sopenharmony_ci } 126195489c19Sopenharmony_ci attrs.push_back(attribute); 126295489c19Sopenharmony_ci } 126395489c19Sopenharmony_ci if (result != RET_NO_ERROR) { 126495489c19Sopenharmony_ci break; 126595489c19Sopenharmony_ci } 126695489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 126795489c19Sopenharmony_ci result = proxy->GetPlayerAppSettingCurrentValue(rawAddr, attrs); 126895489c19Sopenharmony_ci } while (false); 126995489c19Sopenharmony_ci 127095489c19Sopenharmony_ci return result; 127195489c19Sopenharmony_ci} 127295489c19Sopenharmony_ci 127395489c19Sopenharmony_ciint AvrcpController::SetPlayerAppSettingCurrentValue( 127495489c19Sopenharmony_ci const BluetoothRemoteDevice &device, const std::vector<uint8_t> &attributes, const std::vector<uint8_t> &values) 127595489c19Sopenharmony_ci{ 127695489c19Sopenharmony_ci HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device)); 127795489c19Sopenharmony_ci 127895489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 127995489c19Sopenharmony_ci HILOGE("bluetooth is off."); 128095489c19Sopenharmony_ci return RET_BAD_STATUS; 128195489c19Sopenharmony_ci } 128295489c19Sopenharmony_ci 128395489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 128495489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 128595489c19Sopenharmony_ci 128695489c19Sopenharmony_ci int result = RET_NO_ERROR; 128795489c19Sopenharmony_ci std::vector<int32_t> myAttributes; 128895489c19Sopenharmony_ci std::vector<int32_t> myValues; 128995489c19Sopenharmony_ci do { 129095489c19Sopenharmony_ci if (attributes.size() != values.size()) { 129195489c19Sopenharmony_ci break; 129295489c19Sopenharmony_ci } 129395489c19Sopenharmony_ci for (auto attribute : attributes) { 129495489c19Sopenharmony_ci if (attribute == AVRC_PLAYER_ATTRIBUTE_ILLEGAL) { 129595489c19Sopenharmony_ci result = RET_BAD_PARAM; 129695489c19Sopenharmony_ci break; 129795489c19Sopenharmony_ci } 129895489c19Sopenharmony_ci if (attribute >= AVRC_PLAYER_ATTRIBUTE_RESERVED_MIN && attribute <= AVRC_PLAYER_ATTRIBUTE_RESERVED_MAX) { 129995489c19Sopenharmony_ci result = RET_BAD_PARAM; 130095489c19Sopenharmony_ci break; 130195489c19Sopenharmony_ci } 130295489c19Sopenharmony_ci } 130395489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 130495489c19Sopenharmony_ci for (auto attribute : attributes) { 130595489c19Sopenharmony_ci myAttributes.push_back(static_cast<int32_t>(attribute)); 130695489c19Sopenharmony_ci } 130795489c19Sopenharmony_ci for (auto value : values) { 130895489c19Sopenharmony_ci myValues.push_back(static_cast<int32_t>(value)); 130995489c19Sopenharmony_ci } 131095489c19Sopenharmony_ci if (result != RET_NO_ERROR) { 131195489c19Sopenharmony_ci break; 131295489c19Sopenharmony_ci } 131395489c19Sopenharmony_ci result = proxy->SetPlayerAppSettingCurrentValue(rawAddr, myAttributes, myValues); 131495489c19Sopenharmony_ci } while (false); 131595489c19Sopenharmony_ci 131695489c19Sopenharmony_ci return result; 131795489c19Sopenharmony_ci} 131895489c19Sopenharmony_ci 131995489c19Sopenharmony_ciint AvrcpController::GetPlayerApplicationSettingAttributeText( 132095489c19Sopenharmony_ci const BluetoothRemoteDevice &device, const std::vector<uint8_t> &attributes) 132195489c19Sopenharmony_ci{ 132295489c19Sopenharmony_ci HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device)); 132395489c19Sopenharmony_ci 132495489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 132595489c19Sopenharmony_ci HILOGE("bluetooth is off."); 132695489c19Sopenharmony_ci return RET_BAD_STATUS; 132795489c19Sopenharmony_ci } 132895489c19Sopenharmony_ci 132995489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 133095489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 133195489c19Sopenharmony_ci 133295489c19Sopenharmony_ci int result = RET_BAD_STATUS; 133395489c19Sopenharmony_ci do { 133495489c19Sopenharmony_ci std::vector<int32_t> attrs; 133595489c19Sopenharmony_ci for (auto attribute : attributes) { 133695489c19Sopenharmony_ci if (attribute == AVRC_PLAYER_ATTRIBUTE_ILLEGAL) { 133795489c19Sopenharmony_ci break; 133895489c19Sopenharmony_ci } 133995489c19Sopenharmony_ci if (attribute >= AVRC_PLAYER_ATTRIBUTE_RESERVED_MIN && attribute <= AVRC_PLAYER_ATTRIBUTE_RESERVED_MAX) { 134095489c19Sopenharmony_ci break; 134195489c19Sopenharmony_ci } 134295489c19Sopenharmony_ci attrs.push_back(static_cast<int32_t>(attribute)); 134395489c19Sopenharmony_ci } 134495489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 134595489c19Sopenharmony_ci result = proxy->GetPlayerAppSettingAttributeText(rawAddr, attrs); 134695489c19Sopenharmony_ci } while (false); 134795489c19Sopenharmony_ci 134895489c19Sopenharmony_ci return result; 134995489c19Sopenharmony_ci} 135095489c19Sopenharmony_ci 135195489c19Sopenharmony_ciint AvrcpController::GetPlayerApplicationSettingValueText( 135295489c19Sopenharmony_ci const BluetoothRemoteDevice &device, uint8_t attributeId, const std::vector<uint8_t> &values) 135395489c19Sopenharmony_ci{ 135495489c19Sopenharmony_ci HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device)); 135595489c19Sopenharmony_ci 135695489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 135795489c19Sopenharmony_ci HILOGE("bluetooth is off."); 135895489c19Sopenharmony_ci return RET_BAD_STATUS; 135995489c19Sopenharmony_ci } 136095489c19Sopenharmony_ci 136195489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 136295489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 136395489c19Sopenharmony_ci 136495489c19Sopenharmony_ci int result = RET_BAD_STATUS; 136595489c19Sopenharmony_ci do { 136695489c19Sopenharmony_ci std::vector<int32_t> myValues; 136795489c19Sopenharmony_ci if (attributeId == AVRC_PLAYER_ATTRIBUTE_ILLEGAL) { 136895489c19Sopenharmony_ci result = RET_BAD_PARAM; 136995489c19Sopenharmony_ci break; 137095489c19Sopenharmony_ci } 137195489c19Sopenharmony_ci if (attributeId >= AVRC_PLAYER_ATTRIBUTE_RESERVED_MIN && attributeId <= AVRC_PLAYER_ATTRIBUTE_RESERVED_MAX) { 137295489c19Sopenharmony_ci result = RET_BAD_PARAM; 137395489c19Sopenharmony_ci break; 137495489c19Sopenharmony_ci } 137595489c19Sopenharmony_ci for (auto value : values) { 137695489c19Sopenharmony_ci myValues.push_back(static_cast<int32_t>(value)); 137795489c19Sopenharmony_ci } 137895489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 137995489c19Sopenharmony_ci result = proxy->GetPlayerAppSettingValueText(rawAddr, static_cast<int32_t>(attributeId), myValues); 138095489c19Sopenharmony_ci } while (false); 138195489c19Sopenharmony_ci 138295489c19Sopenharmony_ci return result; 138395489c19Sopenharmony_ci} 138495489c19Sopenharmony_ci 138595489c19Sopenharmony_ci/****************************************************************** 138695489c19Sopenharmony_ci * MEDIA INFORMATION * 138795489c19Sopenharmony_ci ******************************************************************/ 138895489c19Sopenharmony_ci 138995489c19Sopenharmony_ciint AvrcpController::GetElementAttributes(const BluetoothRemoteDevice &device, const std::vector<uint32_t> &attributes) 139095489c19Sopenharmony_ci{ 139195489c19Sopenharmony_ci HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device)); 139295489c19Sopenharmony_ci 139395489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 139495489c19Sopenharmony_ci HILOGE("bluetooth is off."); 139595489c19Sopenharmony_ci return RET_BAD_STATUS; 139695489c19Sopenharmony_ci } 139795489c19Sopenharmony_ci 139895489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 139995489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 140095489c19Sopenharmony_ci 140195489c19Sopenharmony_ci std::vector<int32_t> attrs; 140295489c19Sopenharmony_ci for (auto attribute : attributes) { 140395489c19Sopenharmony_ci attrs.push_back(static_cast<int32_t>(attribute)); 140495489c19Sopenharmony_ci } 140595489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 140695489c19Sopenharmony_ci return proxy->GetElementAttributes(rawAddr, attrs); 140795489c19Sopenharmony_ci} 140895489c19Sopenharmony_ci 140995489c19Sopenharmony_ci/****************************************************************** 141095489c19Sopenharmony_ci * PLAY * 141195489c19Sopenharmony_ci ******************************************************************/ 141295489c19Sopenharmony_ci 141395489c19Sopenharmony_ciint AvrcpController::GetPlayStatus(const BluetoothRemoteDevice &device) 141495489c19Sopenharmony_ci{ 141595489c19Sopenharmony_ci HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device)); 141695489c19Sopenharmony_ci 141795489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 141895489c19Sopenharmony_ci HILOGE("bluetooth is off."); 141995489c19Sopenharmony_ci return RET_BAD_STATUS; 142095489c19Sopenharmony_ci } 142195489c19Sopenharmony_ci 142295489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 142395489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 142495489c19Sopenharmony_ci 142595489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 142695489c19Sopenharmony_ci return proxy->GetPlayStatus(rawAddr); 142795489c19Sopenharmony_ci} 142895489c19Sopenharmony_ci 142995489c19Sopenharmony_ciint AvrcpController::PlayItem(const BluetoothRemoteDevice &device, uint64_t uid, uint16_t uidCounter) 143095489c19Sopenharmony_ci{ 143195489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, uidCounter: %{public}d", GET_ENCRYPT_ADDR(device), uidCounter); 143295489c19Sopenharmony_ci 143395489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 143495489c19Sopenharmony_ci HILOGE("bluetooth is off."); 143595489c19Sopenharmony_ci return RET_BAD_STATUS; 143695489c19Sopenharmony_ci } 143795489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 143895489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 143995489c19Sopenharmony_ci 144095489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 144195489c19Sopenharmony_ci return proxy->PlayItem(rawAddr, 144295489c19Sopenharmony_ci static_cast<int32_t>(AVRC_MEDIA_SCOPE_NOW_PLAYING), 144395489c19Sopenharmony_ci static_cast<int64_t>(uid), 144495489c19Sopenharmony_ci static_cast<int32_t>(uidCounter)); 144595489c19Sopenharmony_ci} 144695489c19Sopenharmony_ci 144795489c19Sopenharmony_ci/****************************************************************** 144895489c19Sopenharmony_ci * OPERATE THE VIRTUAL FILE SYSTEM * 144995489c19Sopenharmony_ci ******************************************************************/ 145095489c19Sopenharmony_ci 145195489c19Sopenharmony_ciint AvrcpController::GetFolderItems( 145295489c19Sopenharmony_ci const BluetoothRemoteDevice &device, uint32_t startItem, uint32_t endItem, const std::vector<uint32_t> &attributes) 145395489c19Sopenharmony_ci{ 145495489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, startItem: %{public}d, endItem: %{public}d", 145595489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), startItem, endItem); 145695489c19Sopenharmony_ci 145795489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 145895489c19Sopenharmony_ci HILOGE("bluetooth is off."); 145995489c19Sopenharmony_ci return RET_BAD_STATUS; 146095489c19Sopenharmony_ci } 146195489c19Sopenharmony_ci 146295489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 146395489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 146495489c19Sopenharmony_ci 146595489c19Sopenharmony_ci int result = RET_NO_ERROR; 146695489c19Sopenharmony_ci do { 146795489c19Sopenharmony_ci if (startItem > endItem) { 146895489c19Sopenharmony_ci result = RET_BAD_PARAM; 146995489c19Sopenharmony_ci break; 147095489c19Sopenharmony_ci } 147195489c19Sopenharmony_ci for (auto attribute : attributes) { 147295489c19Sopenharmony_ci if (attribute <= AVRC_MEDIA_ATTRIBUTE_NOT_USED || attribute >= AVRC_MEDIA_ATTRIBUTE_RESERVED) { 147395489c19Sopenharmony_ci result = RET_BAD_PARAM; 147495489c19Sopenharmony_ci break; 147595489c19Sopenharmony_ci } 147695489c19Sopenharmony_ci } 147795489c19Sopenharmony_ci if (result != RET_NO_ERROR) { 147895489c19Sopenharmony_ci break; 147995489c19Sopenharmony_ci } 148095489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 148195489c19Sopenharmony_ci std::vector<int32_t> attrs; 148295489c19Sopenharmony_ci for (auto attribute : attributes) { 148395489c19Sopenharmony_ci attrs.push_back(static_cast<int32_t>(attribute)); 148495489c19Sopenharmony_ci } 148595489c19Sopenharmony_ci result = proxy->GetFolderItems( 148695489c19Sopenharmony_ci rawAddr, static_cast<int32_t>(startItem), static_cast<int32_t>(endItem), attrs); 148795489c19Sopenharmony_ci } while (false); 148895489c19Sopenharmony_ci 148995489c19Sopenharmony_ci return result; 149095489c19Sopenharmony_ci} 149195489c19Sopenharmony_ci 149295489c19Sopenharmony_ciint AvrcpController::GetMeidaPlayerList(const BluetoothRemoteDevice &device, uint32_t startItem, uint32_t endItem) 149395489c19Sopenharmony_ci{ 149495489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, startItem: %{public}d, endItem: %{public}d", 149595489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), startItem, endItem); 149695489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 149795489c19Sopenharmony_ci HILOGE("bluetooth is off."); 149895489c19Sopenharmony_ci return RET_BAD_STATUS; 149995489c19Sopenharmony_ci } 150095489c19Sopenharmony_ci 150195489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 150295489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 150395489c19Sopenharmony_ci 150495489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 150595489c19Sopenharmony_ci return proxy->GetMeidaPlayerList(rawAddr, static_cast<int32_t>(startItem), static_cast<int32_t>(endItem)); 150695489c19Sopenharmony_ci} 150795489c19Sopenharmony_ci 150895489c19Sopenharmony_ciint AvrcpController::GetTotalNumberOfItems(const BluetoothRemoteDevice &device) 150995489c19Sopenharmony_ci{ 151095489c19Sopenharmony_ci HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device)); 151195489c19Sopenharmony_ci 151295489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 151395489c19Sopenharmony_ci HILOGE("bluetooth is off."); 151495489c19Sopenharmony_ci return RET_BAD_STATUS; 151595489c19Sopenharmony_ci } 151695489c19Sopenharmony_ci 151795489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 151895489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 151995489c19Sopenharmony_ci 152095489c19Sopenharmony_ci uint8_t scope = AVRC_MEDIA_SCOPE_NOW_PLAYING; 152195489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 152295489c19Sopenharmony_ci return proxy->GetTotalNumberOfItems(rawAddr, static_cast<int32_t>(scope)); 152395489c19Sopenharmony_ci} 152495489c19Sopenharmony_ci 152595489c19Sopenharmony_ci/****************************************************************** 152695489c19Sopenharmony_ci * ABSOLUTE VOLUME * 152795489c19Sopenharmony_ci ******************************************************************/ 152895489c19Sopenharmony_ci 152995489c19Sopenharmony_ciint AvrcpController::SetAbsoluteVolume(const BluetoothRemoteDevice &device, uint8_t volume) 153095489c19Sopenharmony_ci{ 153195489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, volume: %{public}d", GET_ENCRYPT_ADDR(device), volume); 153295489c19Sopenharmony_ci 153395489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 153495489c19Sopenharmony_ci HILOGE("bluetooth is off."); 153595489c19Sopenharmony_ci return RET_BAD_STATUS; 153695489c19Sopenharmony_ci } 153795489c19Sopenharmony_ci 153895489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 153995489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 154095489c19Sopenharmony_ci 154195489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 154295489c19Sopenharmony_ci return proxy->SetAbsoluteVolume(rawAddr, static_cast<int32_t>(volume)); 154395489c19Sopenharmony_ci} 154495489c19Sopenharmony_ci 154595489c19Sopenharmony_ci/****************************************************************** 154695489c19Sopenharmony_ci * NOTIFY * 154795489c19Sopenharmony_ci ******************************************************************/ 154895489c19Sopenharmony_ci 154995489c19Sopenharmony_ciint AvrcpController::EnableNotification( 155095489c19Sopenharmony_ci const BluetoothRemoteDevice &device, const std::vector<uint8_t> &events, uint32_t interval) 155195489c19Sopenharmony_ci{ 155295489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, interval: %{public}d", GET_ENCRYPT_ADDR(device), interval); 155395489c19Sopenharmony_ci 155495489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 155595489c19Sopenharmony_ci HILOGE("bluetooth is off."); 155695489c19Sopenharmony_ci return RET_BAD_STATUS; 155795489c19Sopenharmony_ci } 155895489c19Sopenharmony_ci 155995489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 156095489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 156195489c19Sopenharmony_ci 156295489c19Sopenharmony_ci std::vector<int32_t> myEvents; 156395489c19Sopenharmony_ci for (auto event : events) { 156495489c19Sopenharmony_ci myEvents.push_back(static_cast<int32_t>(event)); 156595489c19Sopenharmony_ci } 156695489c19Sopenharmony_ci 156795489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 156895489c19Sopenharmony_ci return proxy->EnableNotification(rawAddr, myEvents, static_cast<int32_t>(interval)); 156995489c19Sopenharmony_ci} 157095489c19Sopenharmony_ci 157195489c19Sopenharmony_ciint AvrcpController::DisableNotification(const BluetoothRemoteDevice &device, const std::vector<uint8_t> &events) 157295489c19Sopenharmony_ci{ 157395489c19Sopenharmony_ci HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device)); 157495489c19Sopenharmony_ci 157595489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 157695489c19Sopenharmony_ci HILOGE("bluetooth is off."); 157795489c19Sopenharmony_ci return RET_BAD_STATUS; 157895489c19Sopenharmony_ci } 157995489c19Sopenharmony_ci 158095489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 158195489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 158295489c19Sopenharmony_ci 158395489c19Sopenharmony_ci std::vector<int32_t> myEvents; 158495489c19Sopenharmony_ci for (auto event : events) { 158595489c19Sopenharmony_ci myEvents.push_back(static_cast<int32_t>(event)); 158695489c19Sopenharmony_ci } 158795489c19Sopenharmony_ci 158895489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 158995489c19Sopenharmony_ci return proxy->DisableNotification(rawAddr, myEvents); 159095489c19Sopenharmony_ci} 159195489c19Sopenharmony_ci 159295489c19Sopenharmony_ci/****************************************************************** 159395489c19Sopenharmony_ci * DO NOT EXPOSE THE INTERFACE * 159495489c19Sopenharmony_ci ******************************************************************/ 159595489c19Sopenharmony_ci 159695489c19Sopenharmony_ciint AvrcpController::SetAddressedPlayer(const BluetoothRemoteDevice &device, uint16_t playerId) 159795489c19Sopenharmony_ci{ 159895489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, playerId: %{public}d", GET_ENCRYPT_ADDR(device), playerId); 159995489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 160095489c19Sopenharmony_ci HILOGE("bluetooth is off."); 160195489c19Sopenharmony_ci return RET_BAD_STATUS; 160295489c19Sopenharmony_ci } 160395489c19Sopenharmony_ci 160495489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 160595489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 160695489c19Sopenharmony_ci 160795489c19Sopenharmony_ci return RET_BAD_STATUS; 160895489c19Sopenharmony_ci} 160995489c19Sopenharmony_ci 161095489c19Sopenharmony_ciint AvrcpController::SetBrowsedPlayer(const BluetoothRemoteDevice &device, uint16_t playerId) 161195489c19Sopenharmony_ci{ 161295489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, playerId: %{public}d", GET_ENCRYPT_ADDR(device), playerId); 161395489c19Sopenharmony_ci 161495489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 161595489c19Sopenharmony_ci HILOGE("bluetooth is off."); 161695489c19Sopenharmony_ci return RET_BAD_STATUS; 161795489c19Sopenharmony_ci } 161895489c19Sopenharmony_ci 161995489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 162095489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 162195489c19Sopenharmony_ci 162295489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 162395489c19Sopenharmony_ci return proxy->SetBrowsedPlayer(rawAddr, (int32_t)playerId); 162495489c19Sopenharmony_ci} 162595489c19Sopenharmony_ci 162695489c19Sopenharmony_ciint AvrcpController::ChangePath( 162795489c19Sopenharmony_ci const BluetoothRemoteDevice &device, uint16_t uidCounter, uint16_t direction, uint64_t folderUid) 162895489c19Sopenharmony_ci{ 162995489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, uidCounter: %{public}d, direction: %{public}d", 163095489c19Sopenharmony_ci GET_ENCRYPT_ADDR(device), uidCounter, direction); 163195489c19Sopenharmony_ci 163295489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 163395489c19Sopenharmony_ci HILOGE("bluetooth is off."); 163495489c19Sopenharmony_ci return RET_BAD_STATUS; 163595489c19Sopenharmony_ci } 163695489c19Sopenharmony_ci 163795489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 163895489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 163995489c19Sopenharmony_ci 164095489c19Sopenharmony_ci return RET_BAD_STATUS; 164195489c19Sopenharmony_ci} 164295489c19Sopenharmony_ci 164395489c19Sopenharmony_ciint AvrcpController::GetItemAttributes( 164495489c19Sopenharmony_ci const BluetoothRemoteDevice &device, uint64_t uid, uint16_t uidCounter, const std::vector<uint32_t> &attributes) 164595489c19Sopenharmony_ci{ 164695489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, uidCounter: %{public}d", GET_ENCRYPT_ADDR(device), uidCounter); 164795489c19Sopenharmony_ci 164895489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 164995489c19Sopenharmony_ci HILOGE("bluetooth is off."); 165095489c19Sopenharmony_ci return RET_BAD_STATUS; 165195489c19Sopenharmony_ci } 165295489c19Sopenharmony_ci 165395489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 165495489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 165595489c19Sopenharmony_ci 165695489c19Sopenharmony_ci std::vector<int32_t> attrs; 165795489c19Sopenharmony_ci for (auto attribute : attributes) { 165895489c19Sopenharmony_ci attrs.push_back(static_cast<int32_t>(attribute)); 165995489c19Sopenharmony_ci } 166095489c19Sopenharmony_ci 166195489c19Sopenharmony_ci BluetoothRawAddress rawAddr(device.GetDeviceAddr()); 166295489c19Sopenharmony_ci return proxy->GetItemAttributes(rawAddr, (int64_t)uid, (int32_t)uidCounter, attrs); 166395489c19Sopenharmony_ci} 166495489c19Sopenharmony_ci 166595489c19Sopenharmony_ciint AvrcpController::RequestContinuingResponse(const BluetoothRemoteDevice &device, uint8_t pduId) 166695489c19Sopenharmony_ci{ 166795489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, pduId: %{public}d", GET_ENCRYPT_ADDR(device), pduId); 166895489c19Sopenharmony_ci 166995489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 167095489c19Sopenharmony_ci HILOGE("bluetooth is off."); 167195489c19Sopenharmony_ci return RET_BAD_STATUS; 167295489c19Sopenharmony_ci } 167395489c19Sopenharmony_ci 167495489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 167595489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 167695489c19Sopenharmony_ci 167795489c19Sopenharmony_ci return RET_BAD_STATUS; 167895489c19Sopenharmony_ci} 167995489c19Sopenharmony_ci 168095489c19Sopenharmony_ciint AvrcpController::AbortContinuingResponse(const BluetoothRemoteDevice &device, uint8_t pduId) 168195489c19Sopenharmony_ci{ 168295489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, pduId: %{public}d", GET_ENCRYPT_ADDR(device), pduId); 168395489c19Sopenharmony_ci 168495489c19Sopenharmony_ci int result = RET_BAD_STATUS; 168595489c19Sopenharmony_ci 168695489c19Sopenharmony_ci return result; 168795489c19Sopenharmony_ci} 168895489c19Sopenharmony_ci 168995489c19Sopenharmony_ciint AvrcpController::AddToNowPlaying(const BluetoothRemoteDevice &device, uint64_t uid, uint16_t uidCounter) 169095489c19Sopenharmony_ci{ 169195489c19Sopenharmony_ci HILOGI("enter, device: %{public}s, uidCounter: %{public}d", GET_ENCRYPT_ADDR(device), uidCounter); 169295489c19Sopenharmony_ci 169395489c19Sopenharmony_ci if (!IS_BT_ENABLED()) { 169495489c19Sopenharmony_ci HILOGE("bluetooth is off."); 169595489c19Sopenharmony_ci return RET_BAD_STATUS; 169695489c19Sopenharmony_ci } 169795489c19Sopenharmony_ci 169895489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 169995489c19Sopenharmony_ci CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "failed: no proxy"); 170095489c19Sopenharmony_ci 170195489c19Sopenharmony_ci return RET_BAD_STATUS; 170295489c19Sopenharmony_ci} 170395489c19Sopenharmony_ci 170495489c19Sopenharmony_ciAvrcpController::AvrcpController(void) 170595489c19Sopenharmony_ci{ 170695489c19Sopenharmony_ci HILOGI("enter"); 170795489c19Sopenharmony_ci 170895489c19Sopenharmony_ci pimpl = std::make_unique<AvrcpController::impl>(); 170995489c19Sopenharmony_ci} 171095489c19Sopenharmony_ci 171195489c19Sopenharmony_ciAvrcpController::~AvrcpController(void) 171295489c19Sopenharmony_ci{ 171395489c19Sopenharmony_ci HILOGI("enter"); 171495489c19Sopenharmony_ci sptr<IBluetoothAvrcpCt> proxy = GetRemoteProxy<IBluetoothAvrcpCt>(PROFILE_AVRCP_CT); 171595489c19Sopenharmony_ci CHECK_AND_RETURN_LOG(proxy != nullptr, "failed: no proxy"); 171695489c19Sopenharmony_ci pimpl = nullptr; 171795489c19Sopenharmony_ci} 171895489c19Sopenharmony_ci 171995489c19Sopenharmony_ci} // namespace Bluetooth 172095489c19Sopenharmony_ci} // namespace OHOS 1721