195489c19Sopenharmony_ci/*
295489c19Sopenharmony_ci * Copyright (C) 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
1695489c19Sopenharmony_ci#include "bluetooth_opp.h"
1795489c19Sopenharmony_ci#include "bluetooth_host.h"
1895489c19Sopenharmony_ci#include "bluetooth_profile_manager.h"
1995489c19Sopenharmony_ci#include "bluetooth_log.h"
2095489c19Sopenharmony_ci#include "bluetooth_observer_list.h"
2195489c19Sopenharmony_ci#include "bluetooth_opp_observer_stub.h"
2295489c19Sopenharmony_ci#include "bluetooth_utils.h"
2395489c19Sopenharmony_ci#include "i_bluetooth_opp.h"
2495489c19Sopenharmony_ci#include "i_bluetooth_host.h"
2595489c19Sopenharmony_ci#include "iservice_registry.h"
2695489c19Sopenharmony_ci#include "system_ability_definition.h"
2795489c19Sopenharmony_ci
2895489c19Sopenharmony_cinamespace OHOS {
2995489c19Sopenharmony_cinamespace Bluetooth {
3095489c19Sopenharmony_ci
3195489c19Sopenharmony_ciBluetoothOppTransferInformation TransferInformation(const BluetoothIOppTransferInformation &other)
3295489c19Sopenharmony_ci{
3395489c19Sopenharmony_ci    BluetoothOppTransferInformation oppTransferinformation;
3495489c19Sopenharmony_ci    oppTransferinformation.SetId(other.GetId());
3595489c19Sopenharmony_ci    oppTransferinformation.SetFileName(other.GetFileName());
3695489c19Sopenharmony_ci    oppTransferinformation.SetFilePath(other.GetFilePath());
3795489c19Sopenharmony_ci    oppTransferinformation.SetMimeType(other.GetFileType());
3895489c19Sopenharmony_ci    oppTransferinformation.SetDeviceName(other.GetDeviceName());
3995489c19Sopenharmony_ci    oppTransferinformation.SetDeviceAddress(other.GetDeviceAddress());
4095489c19Sopenharmony_ci    oppTransferinformation.SetFailedReason(other.GetFailedReason());
4195489c19Sopenharmony_ci    oppTransferinformation.SetStatus(other.GetStatus());
4295489c19Sopenharmony_ci    oppTransferinformation.SetDirection(other.GetDirection());
4395489c19Sopenharmony_ci    oppTransferinformation.SetTimeStamp(other.GetTimeStamp());
4495489c19Sopenharmony_ci    oppTransferinformation.SetCurrentBytes(other.GetCurrentBytes());
4595489c19Sopenharmony_ci    oppTransferinformation.SetTotalBytes(other.GetTotalBytes());
4695489c19Sopenharmony_ci    return oppTransferinformation;
4795489c19Sopenharmony_ci}
4895489c19Sopenharmony_ci
4995489c19Sopenharmony_ciclass BluetoothOppObserverImpl : public BluetoothOppObserverStub {
5095489c19Sopenharmony_cipublic:
5195489c19Sopenharmony_ci    explicit BluetoothOppObserverImpl(BluetoothObserverList<OppObserver> &observers)
5295489c19Sopenharmony_ci        : observers_(observers)
5395489c19Sopenharmony_ci    {}
5495489c19Sopenharmony_ci    ~BluetoothOppObserverImpl() override
5595489c19Sopenharmony_ci    {}
5695489c19Sopenharmony_ci
5795489c19Sopenharmony_ci    void OnReceiveIncomingFileChanged(const BluetoothIOppTransferInformation &transferInformation) override
5895489c19Sopenharmony_ci    {
5995489c19Sopenharmony_ci        BluetoothOppTransferInformation oppTransferinformation = TransferInformation(transferInformation);
6095489c19Sopenharmony_ci        observers_.ForEach([oppTransferinformation](std::shared_ptr<OppObserver> observer) {
6195489c19Sopenharmony_ci            observer->OnReceiveIncomingFileChanged(oppTransferinformation);
6295489c19Sopenharmony_ci        });
6395489c19Sopenharmony_ci        return;
6495489c19Sopenharmony_ci    }
6595489c19Sopenharmony_ci
6695489c19Sopenharmony_ci    void OnTransferStateChanged(const BluetoothIOppTransferInformation &transferInformation) override
6795489c19Sopenharmony_ci    {
6895489c19Sopenharmony_ci        BluetoothOppTransferInformation oppTransferinformation = TransferInformation(transferInformation);
6995489c19Sopenharmony_ci        observers_.ForEach([oppTransferinformation](std::shared_ptr<OppObserver> observer) {
7095489c19Sopenharmony_ci            observer->OnTransferStateChanged(oppTransferinformation);
7195489c19Sopenharmony_ci        });
7295489c19Sopenharmony_ci        return;
7395489c19Sopenharmony_ci    }
7495489c19Sopenharmony_ci
7595489c19Sopenharmony_ciprivate:
7695489c19Sopenharmony_ci    BluetoothObserverList<OppObserver> &observers_;
7795489c19Sopenharmony_ci    BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(BluetoothOppObserverImpl);
7895489c19Sopenharmony_ci};
7995489c19Sopenharmony_ci
8095489c19Sopenharmony_cistruct Opp::impl {
8195489c19Sopenharmony_ci    impl()
8295489c19Sopenharmony_ci    {
8395489c19Sopenharmony_ci        serviceObserverImp_ = new BluetoothOppObserverImpl(observers_);
8495489c19Sopenharmony_ci        profileRegisterId = BluetoothProfileManager::GetInstance().RegisterFunc(PROFILE_OPP_SERVER,
8595489c19Sopenharmony_ci        [this](sptr<IRemoteObject> remote) {
8695489c19Sopenharmony_ci            sptr<IBluetoothOpp> proxy = iface_cast<IBluetoothOpp>(remote);
8795489c19Sopenharmony_ci            CHECK_AND_RETURN_LOG(proxy != nullptr, "failed: no proxy");
8895489c19Sopenharmony_ci            proxy->RegisterObserver(serviceObserverImp_);
8995489c19Sopenharmony_ci        });
9095489c19Sopenharmony_ci    }
9195489c19Sopenharmony_ci    ~impl()
9295489c19Sopenharmony_ci    {
9395489c19Sopenharmony_ci        BluetoothProfileManager::GetInstance().DeregisterFunc(profileRegisterId);
9495489c19Sopenharmony_ci        sptr<IBluetoothOpp> proxy = GetRemoteProxy<IBluetoothOpp>(PROFILE_OPP_SERVER);
9595489c19Sopenharmony_ci        CHECK_AND_RETURN_LOG(proxy != nullptr, "failed: no proxy");
9695489c19Sopenharmony_ci        proxy->DeregisterObserver(serviceObserverImp_);
9795489c19Sopenharmony_ci    }
9895489c19Sopenharmony_ci    void RegisterObserver(std::shared_ptr<OppObserver> &observer)
9995489c19Sopenharmony_ci    {
10095489c19Sopenharmony_ci        HILOGI("enter");
10195489c19Sopenharmony_ci        if (observer) {
10295489c19Sopenharmony_ci            observers_.Register(observer);
10395489c19Sopenharmony_ci        }
10495489c19Sopenharmony_ci    }
10595489c19Sopenharmony_ci    void DeregisterObserver(std::shared_ptr<OppObserver> &observer)
10695489c19Sopenharmony_ci    {
10795489c19Sopenharmony_ci        HILOGI("enter");
10895489c19Sopenharmony_ci        if (observer) {
10995489c19Sopenharmony_ci            observers_.Deregister(observer);
11095489c19Sopenharmony_ci        }
11195489c19Sopenharmony_ci    }
11295489c19Sopenharmony_ci    int32_t profileRegisterId = 0;
11395489c19Sopenharmony_ciprivate:
11495489c19Sopenharmony_ci    BluetoothObserverList<OppObserver> observers_;
11595489c19Sopenharmony_ci    sptr<BluetoothOppObserverImpl> serviceObserverImp_ = nullptr;
11695489c19Sopenharmony_ci};
11795489c19Sopenharmony_ci
11895489c19Sopenharmony_cistd::mutex g_oppProxyMutex;
11995489c19Sopenharmony_ciBluetoothOppTransferInformation::BluetoothOppTransferInformation()
12095489c19Sopenharmony_ci{}
12195489c19Sopenharmony_ci
12295489c19Sopenharmony_ciBluetoothOppTransferInformation::~BluetoothOppTransferInformation()
12395489c19Sopenharmony_ci{}
12495489c19Sopenharmony_ci
12595489c19Sopenharmony_ciint BluetoothOppTransferInformation::GetId() const
12695489c19Sopenharmony_ci{
12795489c19Sopenharmony_ci    return id_;
12895489c19Sopenharmony_ci}
12995489c19Sopenharmony_ci
13095489c19Sopenharmony_cistd::string BluetoothOppTransferInformation::GetFileName() const
13195489c19Sopenharmony_ci{
13295489c19Sopenharmony_ci    return fileName_;
13395489c19Sopenharmony_ci}
13495489c19Sopenharmony_ci
13595489c19Sopenharmony_cistd::string BluetoothOppTransferInformation::GetFilePath() const
13695489c19Sopenharmony_ci{
13795489c19Sopenharmony_ci    return filePath_;
13895489c19Sopenharmony_ci}
13995489c19Sopenharmony_ci
14095489c19Sopenharmony_cistd::string BluetoothOppTransferInformation::GetMimeType() const
14195489c19Sopenharmony_ci{
14295489c19Sopenharmony_ci    return mimeType_;
14395489c19Sopenharmony_ci}
14495489c19Sopenharmony_ci
14595489c19Sopenharmony_cistd::string BluetoothOppTransferInformation::GetDeviceName() const
14695489c19Sopenharmony_ci{
14795489c19Sopenharmony_ci    return deviceName_;
14895489c19Sopenharmony_ci}
14995489c19Sopenharmony_ci
15095489c19Sopenharmony_cistd::string BluetoothOppTransferInformation::GetDeviceAddress() const
15195489c19Sopenharmony_ci{
15295489c19Sopenharmony_ci    return deviceAddress_;
15395489c19Sopenharmony_ci}
15495489c19Sopenharmony_ci
15595489c19Sopenharmony_ciint BluetoothOppTransferInformation::GetDirection() const
15695489c19Sopenharmony_ci{
15795489c19Sopenharmony_ci    return direction_;
15895489c19Sopenharmony_ci}
15995489c19Sopenharmony_ci
16095489c19Sopenharmony_ciint BluetoothOppTransferInformation::GetStatus() const
16195489c19Sopenharmony_ci{
16295489c19Sopenharmony_ci    return status_;
16395489c19Sopenharmony_ci}
16495489c19Sopenharmony_ci
16595489c19Sopenharmony_ciint BluetoothOppTransferInformation::GetFailedReason() const
16695489c19Sopenharmony_ci{
16795489c19Sopenharmony_ci    return failedReason_;
16895489c19Sopenharmony_ci}
16995489c19Sopenharmony_ci
17095489c19Sopenharmony_ciuint64_t BluetoothOppTransferInformation::GetTimeStamp() const
17195489c19Sopenharmony_ci{
17295489c19Sopenharmony_ci    return timeStamp_;
17395489c19Sopenharmony_ci}
17495489c19Sopenharmony_ci
17595489c19Sopenharmony_ciuint64_t BluetoothOppTransferInformation::GetCurrentBytes() const
17695489c19Sopenharmony_ci{
17795489c19Sopenharmony_ci    return currentBytes_;
17895489c19Sopenharmony_ci}
17995489c19Sopenharmony_ci
18095489c19Sopenharmony_ciuint64_t BluetoothOppTransferInformation::GetTotalBytes() const
18195489c19Sopenharmony_ci{
18295489c19Sopenharmony_ci    return totalBytes_;
18395489c19Sopenharmony_ci}
18495489c19Sopenharmony_ci
18595489c19Sopenharmony_civoid BluetoothOppTransferInformation::SetId(int id)
18695489c19Sopenharmony_ci{
18795489c19Sopenharmony_ci    id_ = id;
18895489c19Sopenharmony_ci}
18995489c19Sopenharmony_ci
19095489c19Sopenharmony_civoid BluetoothOppTransferInformation::SetFileName(std::string fileName)
19195489c19Sopenharmony_ci{
19295489c19Sopenharmony_ci    fileName_ = fileName;
19395489c19Sopenharmony_ci}
19495489c19Sopenharmony_ci
19595489c19Sopenharmony_civoid BluetoothOppTransferInformation::SetFilePath(std::string filePath)
19695489c19Sopenharmony_ci{
19795489c19Sopenharmony_ci    filePath_ = filePath;
19895489c19Sopenharmony_ci}
19995489c19Sopenharmony_ci
20095489c19Sopenharmony_civoid BluetoothOppTransferInformation::SetMimeType(std::string mimeType)
20195489c19Sopenharmony_ci{
20295489c19Sopenharmony_ci    mimeType_ = mimeType;
20395489c19Sopenharmony_ci}
20495489c19Sopenharmony_ci
20595489c19Sopenharmony_civoid BluetoothOppTransferInformation::SetDeviceName(std::string deviceName)
20695489c19Sopenharmony_ci{
20795489c19Sopenharmony_ci    deviceName_ = deviceName;
20895489c19Sopenharmony_ci}
20995489c19Sopenharmony_ci
21095489c19Sopenharmony_civoid BluetoothOppTransferInformation::SetDeviceAddress(std::string deviceAddress)
21195489c19Sopenharmony_ci{
21295489c19Sopenharmony_ci    deviceAddress_ = deviceAddress;
21395489c19Sopenharmony_ci}
21495489c19Sopenharmony_ci
21595489c19Sopenharmony_civoid BluetoothOppTransferInformation::SetDirection(int direction)
21695489c19Sopenharmony_ci{
21795489c19Sopenharmony_ci    direction_ = direction;
21895489c19Sopenharmony_ci}
21995489c19Sopenharmony_ci
22095489c19Sopenharmony_civoid BluetoothOppTransferInformation::SetStatus(int status)
22195489c19Sopenharmony_ci{
22295489c19Sopenharmony_ci    status_ = status;
22395489c19Sopenharmony_ci}
22495489c19Sopenharmony_ci
22595489c19Sopenharmony_civoid BluetoothOppTransferInformation::SetFailedReason(int failedReason)
22695489c19Sopenharmony_ci{
22795489c19Sopenharmony_ci    failedReason_ = failedReason;
22895489c19Sopenharmony_ci}
22995489c19Sopenharmony_ci
23095489c19Sopenharmony_civoid BluetoothOppTransferInformation::SetTimeStamp(uint64_t timeStamp)
23195489c19Sopenharmony_ci{
23295489c19Sopenharmony_ci    timeStamp_ = timeStamp;
23395489c19Sopenharmony_ci}
23495489c19Sopenharmony_ci
23595489c19Sopenharmony_civoid BluetoothOppTransferInformation::SetCurrentBytes(uint64_t currentBytes)
23695489c19Sopenharmony_ci{
23795489c19Sopenharmony_ci    currentBytes_ = currentBytes;
23895489c19Sopenharmony_ci}
23995489c19Sopenharmony_ci
24095489c19Sopenharmony_civoid BluetoothOppTransferInformation::SetTotalBytes(uint64_t totalBytes)
24195489c19Sopenharmony_ci{
24295489c19Sopenharmony_ci    totalBytes_ = totalBytes;
24395489c19Sopenharmony_ci}
24495489c19Sopenharmony_ci
24595489c19Sopenharmony_ciOpp::Opp()
24695489c19Sopenharmony_ci{
24795489c19Sopenharmony_ci    pimpl = std::make_unique<impl>();
24895489c19Sopenharmony_ci}
24995489c19Sopenharmony_ci
25095489c19Sopenharmony_ciOpp::~Opp()
25195489c19Sopenharmony_ci{}
25295489c19Sopenharmony_ci
25395489c19Sopenharmony_ciOpp *Opp::GetProfile()
25495489c19Sopenharmony_ci{
25595489c19Sopenharmony_ci#ifdef DTFUZZ_TEST
25695489c19Sopenharmony_ci    static BluetoothNoDestructor<Opp> instance;
25795489c19Sopenharmony_ci    return instance.get();
25895489c19Sopenharmony_ci#else
25995489c19Sopenharmony_ci    static Opp instance;
26095489c19Sopenharmony_ci    return &instance;
26195489c19Sopenharmony_ci#endif
26295489c19Sopenharmony_ci}
26395489c19Sopenharmony_ci
26495489c19Sopenharmony_ciint32_t Opp::GetDevicesByStates(const std::vector<int32_t> &states,
26595489c19Sopenharmony_ci    std::vector<BluetoothRemoteDevice> &result) const
26695489c19Sopenharmony_ci{
26795489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off");
26895489c19Sopenharmony_ci    sptr<IBluetoothOpp> proxy = GetRemoteProxy<IBluetoothOpp>(PROFILE_OPP_SERVER);
26995489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr");
27095489c19Sopenharmony_ci
27195489c19Sopenharmony_ci    std::vector<BluetoothRawAddress> rawAddress {};
27295489c19Sopenharmony_ci    int32_t ret = proxy->GetDevicesByStates(states, rawAddress);
27395489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET((ret == BT_NO_ERROR), ret, "inner error");
27495489c19Sopenharmony_ci
27595489c19Sopenharmony_ci    for (BluetoothRawAddress rawAddr : rawAddress) {
27695489c19Sopenharmony_ci        BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
27795489c19Sopenharmony_ci        result.push_back(device);
27895489c19Sopenharmony_ci    }
27995489c19Sopenharmony_ci    return BT_NO_ERROR;
28095489c19Sopenharmony_ci}
28195489c19Sopenharmony_ci
28295489c19Sopenharmony_ciint32_t Opp::GetDeviceState(const BluetoothRemoteDevice &device, int32_t &state) const
28395489c19Sopenharmony_ci{
28495489c19Sopenharmony_ci    HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
28595489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off");
28695489c19Sopenharmony_ci    sptr<IBluetoothOpp> proxy = GetRemoteProxy<IBluetoothOpp>(PROFILE_OPP_SERVER);
28795489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr");
28895489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(device.IsValidBluetoothRemoteDevice(), BT_ERR_INVALID_PARAM, "device param error");
28995489c19Sopenharmony_ci
29095489c19Sopenharmony_ci    return proxy->GetDeviceState(BluetoothRawAddress(device.GetDeviceAddr()), state);
29195489c19Sopenharmony_ci}
29295489c19Sopenharmony_ci
29395489c19Sopenharmony_ciint32_t Opp::SendFile(std::string device, std::vector<std::string> filePaths,
29495489c19Sopenharmony_ci    std::vector<std::string> mimeTypes, bool& result)
29595489c19Sopenharmony_ci{
29695489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off");
29795489c19Sopenharmony_ci    sptr<IBluetoothOpp> proxy = GetRemoteProxy<IBluetoothOpp>(PROFILE_OPP_SERVER);
29895489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr");
29995489c19Sopenharmony_ci    int ret = proxy->SendFile(device, filePaths, mimeTypes, result);
30095489c19Sopenharmony_ci    HILOGI("send file result is : %{public}d", result);
30195489c19Sopenharmony_ci    return ret;
30295489c19Sopenharmony_ci}
30395489c19Sopenharmony_ci
30495489c19Sopenharmony_ciint32_t Opp::SetIncomingFileConfirmation(bool accept)
30595489c19Sopenharmony_ci{
30695489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off");
30795489c19Sopenharmony_ci
30895489c19Sopenharmony_ci    sptr<IBluetoothOpp> proxy = GetRemoteProxy<IBluetoothOpp>(PROFILE_OPP_SERVER);
30995489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr");
31095489c19Sopenharmony_ci    int ret = proxy->SetIncomingFileConfirmation(accept);
31195489c19Sopenharmony_ci    HILOGI("setIncomingFileConfirmation result is : %{public}d", ret);
31295489c19Sopenharmony_ci    return ret;
31395489c19Sopenharmony_ci}
31495489c19Sopenharmony_ci
31595489c19Sopenharmony_ciint32_t Opp::GetCurrentTransferInformation(BluetoothOppTransferInformation &transferInformation)
31695489c19Sopenharmony_ci{
31795489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off");
31895489c19Sopenharmony_ci    sptr<IBluetoothOpp> proxy = GetRemoteProxy<IBluetoothOpp>(PROFILE_OPP_SERVER);
31995489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr");
32095489c19Sopenharmony_ci
32195489c19Sopenharmony_ci    BluetoothIOppTransferInformation oppInformation;
32295489c19Sopenharmony_ci    int ret = proxy->GetCurrentTransferInformation(oppInformation);
32395489c19Sopenharmony_ci    HILOGI("getCurrentTransferInformation result is : %{public}d", ret);
32495489c19Sopenharmony_ci    if (ret == BT_NO_ERROR) {
32595489c19Sopenharmony_ci        transferInformation = TransferInformation(oppInformation);
32695489c19Sopenharmony_ci    }
32795489c19Sopenharmony_ci    return ret;
32895489c19Sopenharmony_ci}
32995489c19Sopenharmony_ci
33095489c19Sopenharmony_ciint32_t Opp::CancelTransfer(bool &result)
33195489c19Sopenharmony_ci{
33295489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off");
33395489c19Sopenharmony_ci    sptr<IBluetoothOpp> proxy = GetRemoteProxy<IBluetoothOpp>(PROFILE_OPP_SERVER);
33495489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr");
33595489c19Sopenharmony_ci
33695489c19Sopenharmony_ci    int ret = proxy->CancelTransfer(result);
33795489c19Sopenharmony_ci    HILOGI("cancelTransfer result is : %{public}d", ret);
33895489c19Sopenharmony_ci    return ret;
33995489c19Sopenharmony_ci}
34095489c19Sopenharmony_ci
34195489c19Sopenharmony_civoid Opp::RegisterObserver(std::shared_ptr<OppObserver> observer)
34295489c19Sopenharmony_ci{
34395489c19Sopenharmony_ci    HILOGD("enter");
34495489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null.");
34595489c19Sopenharmony_ci    pimpl->RegisterObserver(observer);
34695489c19Sopenharmony_ci}
34795489c19Sopenharmony_ci
34895489c19Sopenharmony_civoid Opp::DeregisterObserver(std::shared_ptr<OppObserver> observer)
34995489c19Sopenharmony_ci{
35095489c19Sopenharmony_ci    HILOGD("enter");
35195489c19Sopenharmony_ci    CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null.");
35295489c19Sopenharmony_ci    pimpl->DeregisterObserver(observer);
35395489c19Sopenharmony_ci}
35495489c19Sopenharmony_ci}  // namespace Bluetooth
35595489c19Sopenharmony_ci}  // namespace OHOS