195489c19Sopenharmony_ci/*
295489c19Sopenharmony_ci * Copyright (C) 2021-2022 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#include "bluetooth_a2dp_snk.h"
1695489c19Sopenharmony_ci#include <cstdint>
1795489c19Sopenharmony_ci#include "bluetooth_a2dp_sink_observer_stub.h"
1895489c19Sopenharmony_ci#include "bluetooth_def.h"
1995489c19Sopenharmony_ci#include "bluetooth_host.h"
2095489c19Sopenharmony_ci#include "bluetooth_profile_manager.h"
2195489c19Sopenharmony_ci#include "bluetooth_log.h"
2295489c19Sopenharmony_ci#include "bluetooth_observer_list.h"
2395489c19Sopenharmony_ci#include "bluetooth_remote_device.h"
2495489c19Sopenharmony_ci#include "bluetooth_types.h"
2595489c19Sopenharmony_ci#include "bluetooth_utils.h"
2695489c19Sopenharmony_ci#include "functional"
2795489c19Sopenharmony_ci#include "i_bluetooth_a2dp_sink.h"
2895489c19Sopenharmony_ci#include "i_bluetooth_a2dp_sink_observer.h"
2995489c19Sopenharmony_ci#include "i_bluetooth_host.h"
3095489c19Sopenharmony_ci#include "if_system_ability_manager.h"
3195489c19Sopenharmony_ci#include "iosfwd"
3295489c19Sopenharmony_ci#include "iremote_broker.h"
3395489c19Sopenharmony_ci#include "iremote_object.h"
3495489c19Sopenharmony_ci#include "iservice_registry.h"
3595489c19Sopenharmony_ci#include "list"
3695489c19Sopenharmony_ci#include "memory"
3795489c19Sopenharmony_ci#include "new"
3895489c19Sopenharmony_ci#include "raw_address.h"
3995489c19Sopenharmony_ci#include "refbase.h"
4095489c19Sopenharmony_ci#include "string"
4195489c19Sopenharmony_ci#include "system_ability_definition.h"
4295489c19Sopenharmony_ci#include "vector"
4395489c19Sopenharmony_ci
4495489c19Sopenharmony_cinamespace OHOS {
4595489c19Sopenharmony_cinamespace Bluetooth {
4695489c19Sopenharmony_ciusing namespace OHOS::bluetooth;
4795489c19Sopenharmony_cistd::mutex g_a2dpSnkProxyMutex;
4895489c19Sopenharmony_cistruct A2dpSink::impl {
4995489c19Sopenharmony_ci    impl();
5095489c19Sopenharmony_ci    ~impl();
5195489c19Sopenharmony_ci    BluetoothObserverList<A2dpSinkObserver> observers_;
5295489c19Sopenharmony_ci    class BluetoothA2dpSinkObserverImp;
5395489c19Sopenharmony_ci    sptr<BluetoothA2dpSinkObserverImp> observerImp_ = nullptr;
5495489c19Sopenharmony_ci    int32_t profileRegisterId = 0;
5595489c19Sopenharmony_ci};
5695489c19Sopenharmony_ci
5795489c19Sopenharmony_ciclass A2dpSink::impl::BluetoothA2dpSinkObserverImp : public BluetoothA2dpSinkObserverStub {
5895489c19Sopenharmony_cipublic:
5995489c19Sopenharmony_ci    explicit BluetoothA2dpSinkObserverImp(A2dpSink::impl &a2dpSink) : a2dpSink_(a2dpSink)
6095489c19Sopenharmony_ci    {};
6195489c19Sopenharmony_ci    ~BluetoothA2dpSinkObserverImp() override
6295489c19Sopenharmony_ci    {};
6395489c19Sopenharmony_ci
6495489c19Sopenharmony_ci    void Register(std::shared_ptr<A2dpSinkObserver> &observer)
6595489c19Sopenharmony_ci    {
6695489c19Sopenharmony_ci        HILOGI("enter");
6795489c19Sopenharmony_ci        a2dpSink_.observers_.Register(observer);
6895489c19Sopenharmony_ci    }
6995489c19Sopenharmony_ci
7095489c19Sopenharmony_ci    void Deregister(std::shared_ptr<A2dpSinkObserver> &observer)
7195489c19Sopenharmony_ci    {
7295489c19Sopenharmony_ci        HILOGI("enter");
7395489c19Sopenharmony_ci        a2dpSink_.observers_.Deregister(observer);
7495489c19Sopenharmony_ci    }
7595489c19Sopenharmony_ci
7695489c19Sopenharmony_ci    void OnConnectionStateChanged(const RawAddress &device, int state, int cause) override
7795489c19Sopenharmony_ci    {
7895489c19Sopenharmony_ci        HILOGD("device: %{public}s, state: %{public}d, cause: %{public}d",
7995489c19Sopenharmony_ci            GET_ENCRYPT_RAW_ADDR(device), state, cause);
8095489c19Sopenharmony_ci        a2dpSink_.observers_.ForEach([device, state, cause](std::shared_ptr<A2dpSinkObserver> observer) {
8195489c19Sopenharmony_ci            observer->OnConnectionStateChanged(BluetoothRemoteDevice(device.GetAddress(), 0), state, cause);
8295489c19Sopenharmony_ci        });
8395489c19Sopenharmony_ci    }
8495489c19Sopenharmony_ci
8595489c19Sopenharmony_ciprivate:
8695489c19Sopenharmony_ci    A2dpSink::impl &a2dpSink_;
8795489c19Sopenharmony_ci    BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(BluetoothA2dpSinkObserverImp);
8895489c19Sopenharmony_ci};
8995489c19Sopenharmony_ci
9095489c19Sopenharmony_ciA2dpSink::impl::impl()
9195489c19Sopenharmony_ci{
9295489c19Sopenharmony_ci    observerImp_ = new (std::nothrow) BluetoothA2dpSinkObserverImp(*this);
9395489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG(observerImp_ != nullptr, "observerImp_ is nullptr");
9495489c19Sopenharmony_ci    profileRegisterId = BluetoothProfileManager::GetInstance().RegisterFunc(PROFILE_A2DP_SINK,
9595489c19Sopenharmony_ci        [this](sptr<IRemoteObject> remote) {
9695489c19Sopenharmony_ci        sptr<IBluetoothA2dpSink> proxy = iface_cast<IBluetoothA2dpSink>(remote);
9795489c19Sopenharmony_ci        CHECK_AND_RETURN_LOG(proxy != nullptr, "failed: no proxy");
9895489c19Sopenharmony_ci        proxy->RegisterObserver(observerImp_);
9995489c19Sopenharmony_ci    });
10095489c19Sopenharmony_ci};
10195489c19Sopenharmony_ci
10295489c19Sopenharmony_ciA2dpSink::impl::~impl()
10395489c19Sopenharmony_ci{
10495489c19Sopenharmony_ci    HILOGD("start");
10595489c19Sopenharmony_ci    BluetoothProfileManager::GetInstance().DeregisterFunc(profileRegisterId);
10695489c19Sopenharmony_ci    sptr<IBluetoothA2dpSink> proxy = GetRemoteProxy<IBluetoothA2dpSink>(PROFILE_A2DP_SINK);
10795489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG(proxy != nullptr, "failed: no proxy");
10895489c19Sopenharmony_ci    proxy->DeregisterObserver(observerImp_);
10995489c19Sopenharmony_ci}
11095489c19Sopenharmony_ci
11195489c19Sopenharmony_ciA2dpSink::A2dpSink()
11295489c19Sopenharmony_ci{
11395489c19Sopenharmony_ci    pimpl = std::make_unique<impl>();
11495489c19Sopenharmony_ci    if (!pimpl) {
11595489c19Sopenharmony_ci        HILOGE("fails: no pimpl");
11695489c19Sopenharmony_ci    }
11795489c19Sopenharmony_ci}
11895489c19Sopenharmony_ci
11995489c19Sopenharmony_ciA2dpSink::~A2dpSink()
12095489c19Sopenharmony_ci{
12195489c19Sopenharmony_ci    HILOGD("start");
12295489c19Sopenharmony_ci}
12395489c19Sopenharmony_ci
12495489c19Sopenharmony_civoid A2dpSink::RegisterObserver(std::shared_ptr<A2dpSinkObserver> observer)
12595489c19Sopenharmony_ci{
12695489c19Sopenharmony_ci    HILOGD("enter");
12795489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null.");
12895489c19Sopenharmony_ci    pimpl->observers_.Register(observer);
12995489c19Sopenharmony_ci}
13095489c19Sopenharmony_ci
13195489c19Sopenharmony_civoid A2dpSink::DeregisterObserver(std::shared_ptr<A2dpSinkObserver> observer)
13295489c19Sopenharmony_ci{
13395489c19Sopenharmony_ci    HILOGD("enter");
13495489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null.");
13595489c19Sopenharmony_ci    pimpl->observers_.Deregister(observer);
13695489c19Sopenharmony_ci}
13795489c19Sopenharmony_ci
13895489c19Sopenharmony_ciint A2dpSink::GetDeviceState(const BluetoothRemoteDevice &device) const
13995489c19Sopenharmony_ci{
14095489c19Sopenharmony_ci    HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
14195489c19Sopenharmony_ci    if (!IS_BT_ENABLED()) {
14295489c19Sopenharmony_ci        HILOGE("bluetooth is off.");
14395489c19Sopenharmony_ci        return RET_BAD_STATUS;
14495489c19Sopenharmony_ci    }
14595489c19Sopenharmony_ci    sptr<IBluetoothA2dpSink> proxy = GetRemoteProxy<IBluetoothA2dpSink>(PROFILE_A2DP_SINK);
14695489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "A2dpSink proxy is nullptr");
14795489c19Sopenharmony_ci    if (!device.IsValidBluetoothRemoteDevice()) {
14895489c19Sopenharmony_ci        HILOGE("input parameter error.");
14995489c19Sopenharmony_ci        return RET_BAD_PARAM;
15095489c19Sopenharmony_ci    }
15195489c19Sopenharmony_ci
15295489c19Sopenharmony_ci    return proxy->GetDeviceState(RawAddress(device.GetDeviceAddr()));
15395489c19Sopenharmony_ci}
15495489c19Sopenharmony_ci
15595489c19Sopenharmony_cistd::vector<BluetoothRemoteDevice> A2dpSink::GetDevicesByStates(std::vector<int> states) const
15695489c19Sopenharmony_ci{
15795489c19Sopenharmony_ci    HILOGI("enter");
15895489c19Sopenharmony_ci
15995489c19Sopenharmony_ci    if (!IS_BT_ENABLED()) {
16095489c19Sopenharmony_ci        HILOGE("bluetooth is off.");
16195489c19Sopenharmony_ci        return std::vector<BluetoothRemoteDevice>();
16295489c19Sopenharmony_ci    }
16395489c19Sopenharmony_ci
16495489c19Sopenharmony_ci    sptr<IBluetoothA2dpSink> proxy = GetRemoteProxy<IBluetoothA2dpSink>(PROFILE_A2DP_SINK);
16595489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(proxy != nullptr, std::vector<BluetoothRemoteDevice>(),
16695489c19Sopenharmony_ci        "A2dpSink proxy is nullptr");
16795489c19Sopenharmony_ci
16895489c19Sopenharmony_ci    std::vector<int32_t> convertStates;
16995489c19Sopenharmony_ci    for (auto state : states) {
17095489c19Sopenharmony_ci        convertStates.push_back(static_cast<int32_t>(state));
17195489c19Sopenharmony_ci    }
17295489c19Sopenharmony_ci    std::vector<BluetoothRemoteDevice> devices;
17395489c19Sopenharmony_ci    std::vector<RawAddress> rawAddrs = proxy->GetDevicesByStates(convertStates);
17495489c19Sopenharmony_ci    for (auto rawAddr : rawAddrs) {
17595489c19Sopenharmony_ci        BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
17695489c19Sopenharmony_ci        devices.push_back(device);
17795489c19Sopenharmony_ci    }
17895489c19Sopenharmony_ci    return devices;
17995489c19Sopenharmony_ci}
18095489c19Sopenharmony_ci
18195489c19Sopenharmony_ciint A2dpSink::GetPlayingState(const BluetoothRemoteDevice &device) const
18295489c19Sopenharmony_ci{
18395489c19Sopenharmony_ci    HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
18495489c19Sopenharmony_ci    if (!IS_BT_ENABLED()) {
18595489c19Sopenharmony_ci        HILOGE("bluetooth is off.");
18695489c19Sopenharmony_ci        return RET_BAD_STATUS;
18795489c19Sopenharmony_ci    }
18895489c19Sopenharmony_ci
18995489c19Sopenharmony_ci    sptr<IBluetoothA2dpSink> proxy = GetRemoteProxy<IBluetoothA2dpSink>(PROFILE_A2DP_SINK);
19095489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "A2dpSink proxy is nullptr");
19195489c19Sopenharmony_ci
19295489c19Sopenharmony_ci    if (!device.IsValidBluetoothRemoteDevice()) {
19395489c19Sopenharmony_ci        HILOGE("input parameter error.");
19495489c19Sopenharmony_ci        return RET_BAD_PARAM;
19595489c19Sopenharmony_ci    }
19695489c19Sopenharmony_ci
19795489c19Sopenharmony_ci    int ret = RET_BAD_STATUS;
19895489c19Sopenharmony_ci    proxy->GetPlayingState(RawAddress(device.GetDeviceAddr()), ret);
19995489c19Sopenharmony_ci    return ret;
20095489c19Sopenharmony_ci}
20195489c19Sopenharmony_ci
20295489c19Sopenharmony_ciint A2dpSink::GetPlayingState(const BluetoothRemoteDevice &device, int &state) const
20395489c19Sopenharmony_ci{
20495489c19Sopenharmony_ci    HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
20595489c19Sopenharmony_ci    if (!IS_BT_ENABLED()) {
20695489c19Sopenharmony_ci        HILOGE("bluetooth is off.");
20795489c19Sopenharmony_ci        return RET_BAD_STATUS;
20895489c19Sopenharmony_ci    }
20995489c19Sopenharmony_ci
21095489c19Sopenharmony_ci    sptr<IBluetoothA2dpSink> proxy = GetRemoteProxy<IBluetoothA2dpSink>(PROFILE_A2DP_SINK);
21195489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "A2dpSink proxy is nullptr");
21295489c19Sopenharmony_ci
21395489c19Sopenharmony_ci    if (!device.IsValidBluetoothRemoteDevice()) {
21495489c19Sopenharmony_ci        HILOGE("input parameter error.");
21595489c19Sopenharmony_ci        return RET_BAD_PARAM;
21695489c19Sopenharmony_ci    }
21795489c19Sopenharmony_ci
21895489c19Sopenharmony_ci    return proxy->GetPlayingState(RawAddress(device.GetDeviceAddr()), state);
21995489c19Sopenharmony_ci}
22095489c19Sopenharmony_ci
22195489c19Sopenharmony_cibool A2dpSink::Connect(const BluetoothRemoteDevice &device)
22295489c19Sopenharmony_ci{
22395489c19Sopenharmony_ci    HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
22495489c19Sopenharmony_ci    if (!IS_BT_ENABLED()) {
22595489c19Sopenharmony_ci        HILOGE("bluetooth is off.");
22695489c19Sopenharmony_ci        return false;
22795489c19Sopenharmony_ci    }
22895489c19Sopenharmony_ci
22995489c19Sopenharmony_ci    sptr<IBluetoothA2dpSink> proxy = GetRemoteProxy<IBluetoothA2dpSink>(PROFILE_A2DP_SINK);
23095489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "A2dpSink proxy is nullptr");
23195489c19Sopenharmony_ci
23295489c19Sopenharmony_ci    if (!device.IsValidBluetoothRemoteDevice()) {
23395489c19Sopenharmony_ci        HILOGE("input parameter error.");
23495489c19Sopenharmony_ci        return false;
23595489c19Sopenharmony_ci    }
23695489c19Sopenharmony_ci
23795489c19Sopenharmony_ci    int ret = proxy->Connect(RawAddress(device.GetDeviceAddr()));
23895489c19Sopenharmony_ci    return (ret == RET_NO_ERROR);
23995489c19Sopenharmony_ci}
24095489c19Sopenharmony_ci
24195489c19Sopenharmony_cibool A2dpSink::Disconnect(const BluetoothRemoteDevice &device)
24295489c19Sopenharmony_ci{
24395489c19Sopenharmony_ci    HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
24495489c19Sopenharmony_ci    if (!IS_BT_ENABLED()) {
24595489c19Sopenharmony_ci        HILOGE("bluetooth is off.");
24695489c19Sopenharmony_ci        return false;
24795489c19Sopenharmony_ci    }
24895489c19Sopenharmony_ci
24995489c19Sopenharmony_ci    sptr<IBluetoothA2dpSink> proxy = GetRemoteProxy<IBluetoothA2dpSink>(PROFILE_A2DP_SINK);
25095489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "A2dpSink proxy is nullptr");
25195489c19Sopenharmony_ci
25295489c19Sopenharmony_ci    if (!device.IsValidBluetoothRemoteDevice()) {
25395489c19Sopenharmony_ci        HILOGE("input parameter error.");
25495489c19Sopenharmony_ci        return false;
25595489c19Sopenharmony_ci    }
25695489c19Sopenharmony_ci
25795489c19Sopenharmony_ci    int ret = proxy->Disconnect(RawAddress(device.GetDeviceAddr()));
25895489c19Sopenharmony_ci    return (ret == RET_NO_ERROR);
25995489c19Sopenharmony_ci}
26095489c19Sopenharmony_ci
26195489c19Sopenharmony_ciA2dpSink *A2dpSink::GetProfile()
26295489c19Sopenharmony_ci{
26395489c19Sopenharmony_ci    HILOGI("enter");
26495489c19Sopenharmony_ci#ifdef DTFUZZ_TEST
26595489c19Sopenharmony_ci    static BluetoothNoDestructor<A2dpSink> service;
26695489c19Sopenharmony_ci    return service.get();
26795489c19Sopenharmony_ci#else
26895489c19Sopenharmony_ci    static A2dpSink service;
26995489c19Sopenharmony_ci    return &service;
27095489c19Sopenharmony_ci#endif
27195489c19Sopenharmony_ci}
27295489c19Sopenharmony_ci
27395489c19Sopenharmony_cibool A2dpSink::SetConnectStrategy(const BluetoothRemoteDevice &device, int strategy)
27495489c19Sopenharmony_ci{
27595489c19Sopenharmony_ci    HILOGI("enter, device: %{public}s, strategy: %{public}d", GET_ENCRYPT_ADDR(device), strategy);
27695489c19Sopenharmony_ci    if (!IS_BT_ENABLED()) {
27795489c19Sopenharmony_ci        HILOGE("bluetooth is off.");
27895489c19Sopenharmony_ci        return false;
27995489c19Sopenharmony_ci    }
28095489c19Sopenharmony_ci    sptr<IBluetoothA2dpSink> proxy = GetRemoteProxy<IBluetoothA2dpSink>(PROFILE_A2DP_SINK);
28195489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "A2dpSink proxy is nullptr");
28295489c19Sopenharmony_ci
28395489c19Sopenharmony_ci    if ((!device.IsValidBluetoothRemoteDevice()) ||
28495489c19Sopenharmony_ci        ((strategy != static_cast<int>(BTStrategyType::CONNECTION_ALLOWED)) &&
28595489c19Sopenharmony_ci            (strategy != static_cast<int>(BTStrategyType::CONNECTION_FORBIDDEN)))) {
28695489c19Sopenharmony_ci        HILOGE("input parameter error.");
28795489c19Sopenharmony_ci        return false;
28895489c19Sopenharmony_ci    }
28995489c19Sopenharmony_ci
29095489c19Sopenharmony_ci    int ret = proxy->SetConnectStrategy(RawAddress(device.GetDeviceAddr()), strategy);
29195489c19Sopenharmony_ci    return (ret == RET_NO_ERROR);
29295489c19Sopenharmony_ci}
29395489c19Sopenharmony_ci
29495489c19Sopenharmony_ciint A2dpSink::GetConnectStrategy(const BluetoothRemoteDevice &device) const
29595489c19Sopenharmony_ci{
29695489c19Sopenharmony_ci    HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
29795489c19Sopenharmony_ci    if (!IS_BT_ENABLED()) {
29895489c19Sopenharmony_ci        HILOGE("bluetooth is off.");
29995489c19Sopenharmony_ci        return RET_BAD_STATUS;
30095489c19Sopenharmony_ci    }
30195489c19Sopenharmony_ci    sptr<IBluetoothA2dpSink> proxy = GetRemoteProxy<IBluetoothA2dpSink>(PROFILE_A2DP_SINK);
30295489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(proxy != nullptr, RET_BAD_STATUS, "A2dpSink proxy is nullptr");
30395489c19Sopenharmony_ci
30495489c19Sopenharmony_ci    if (!device.IsValidBluetoothRemoteDevice()) {
30595489c19Sopenharmony_ci        HILOGE("input parameter error.");
30695489c19Sopenharmony_ci        return RET_BAD_PARAM;
30795489c19Sopenharmony_ci    }
30895489c19Sopenharmony_ci
30995489c19Sopenharmony_ci    int ret = proxy->GetConnectStrategy(RawAddress(device.GetDeviceAddr()));
31095489c19Sopenharmony_ci    return ret;
31195489c19Sopenharmony_ci}
31295489c19Sopenharmony_ci
31395489c19Sopenharmony_cibool A2dpSink::SendDelay(const BluetoothRemoteDevice &device, uint16_t delayValue)
31495489c19Sopenharmony_ci{
31595489c19Sopenharmony_ci    HILOGI("enter, device: %{public}s, delayValue: %{public}d", GET_ENCRYPT_ADDR(device), delayValue);
31695489c19Sopenharmony_ci    if (!IS_BT_ENABLED()) {
31795489c19Sopenharmony_ci        HILOGE("bluetooth is off.");
31895489c19Sopenharmony_ci        return false;
31995489c19Sopenharmony_ci    }
32095489c19Sopenharmony_ci    sptr<IBluetoothA2dpSink> proxy = GetRemoteProxy<IBluetoothA2dpSink>(PROFILE_A2DP_SINK);
32195489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(proxy != nullptr, false, "A2dpSink proxy is nullptr");
32295489c19Sopenharmony_ci
32395489c19Sopenharmony_ci    if (!device.IsValidBluetoothRemoteDevice()) {
32495489c19Sopenharmony_ci        HILOGE("input parameter error.");
32595489c19Sopenharmony_ci        return false;
32695489c19Sopenharmony_ci    }
32795489c19Sopenharmony_ci
32895489c19Sopenharmony_ci    int ret = proxy->SendDelay(RawAddress(device.GetDeviceAddr()), (int32_t)delayValue);
32995489c19Sopenharmony_ci    return (ret == RET_NO_ERROR);
33095489c19Sopenharmony_ci}
33195489c19Sopenharmony_ci} // namespace Bluetooth
33295489c19Sopenharmony_ci} // namespace OHOS