• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <codecvt>
16 #include <string>
17 #include <mutex>
18 #include <memory>
19 
20 #include "bluetooth_map_mce_observer_stub.h"
21 #include "bluetooth_map_mce_proxy.h"
22 #include "bluetooth_raw_address.h"
23 #include "bluetooth_map_mce.h"
24 
25 #include "bt_def.h"
26 #include "bluetooth_host.h"
27 #include "bluetooth_load_system_ability.h"
28 #include "bluetooth_utils.h"
29 #include "bluetooth_remote_device.h"
30 #include "bluetooth_observer_list.h"
31 #include "iservice_registry.h"
32 #include "system_ability_definition.h"
33 #include "i_bluetooth_host.h"
34 using namespace OHOS::bluetooth;
35 
36 namespace OHOS {
37 namespace Bluetooth {
38 /**
39  * @brief make observer for framework
40  */
41 class BluetoothMapMceObserverImpl : public BluetoothMapMceObserverStub {
42 public:
BluetoothMapMceObserverImpl(BluetoothObserverList<MapClientObserver> & observerList)43     BluetoothMapMceObserverImpl(BluetoothObserverList<MapClientObserver> &observerList)
44         : frameworkObserverList_(observerList) {};
45     ~BluetoothMapMceObserverImpl() override = default;
46     void OnConnectionStateChanged(
47         const BluetoothRawAddress &deviceAddress, int state) override;
48     void OnMapActionCompleted(const BluetoothRawAddress &deviceAddress,
49         const BluetoothIProfileMapAction &action, int state) override;
50     void OnMapEventReported(const BluetoothRawAddress &deviceAddress,
51         const BluetoothIProfileMapEventReport &report) override;
52     void OnBmessageCompleted(const BluetoothRawAddress &deviceAddress,
53         const BluetoothIProfileBMessage &bmsg, int state) override;
54     void OnMessagesListingCompleted(const BluetoothRawAddress &deviceAddress,
55         const BluetoothIProfileMessagesListing &listing, int state) override;
56     void OnConversationListingCompleted(
57         const BluetoothRawAddress &deviceAddress,
58         const BluetoothIProfileConversationListing &listing, int state) override;
59 
60 private:
61     MapVcard ConvertVcardToFramewrokFormat(IProfileMapVcard profileVcard);
62     BluetoothObserverList<MapClientObserver> &frameworkObserverList_;
63 };
64 
OnConnectionStateChanged(const BluetoothRawAddress & deviceAddress,int state)65 void BluetoothMapMceObserverImpl::OnConnectionStateChanged(
66     const BluetoothRawAddress &deviceAddress, int state)
67 {
68     BluetoothRemoteDevice remoteDevice(deviceAddress.GetAddress(), 0);
69     frameworkObserverList_.ForEach([remoteDevice, state](std::shared_ptr<MapClientObserver> observer) {
70         observer->OnConnectionStateChanged(remoteDevice, state);
71     });
72 }
73 
OnMapActionCompleted(const BluetoothRawAddress & deviceAddress,const BluetoothIProfileMapAction & action,int state)74 void BluetoothMapMceObserverImpl::OnMapActionCompleted(
75     const BluetoothRawAddress &deviceAddress,
76     const BluetoothIProfileMapAction &action, int state)
77 {
78     BluetoothRemoteDevice remoteDevice(deviceAddress.GetAddress(), 0);
79     MapAction faction;
80     MapExecuteStatus fstate = MapExecuteStatus(state);
81 
82     // convert data
83     faction.action_ = static_cast<OHOS::Bluetooth::MapActionType>(action.action_);
84     faction.supportedFeatures_ = action.supportedFeatures_;
85     faction.ownerStatus_.PresenceAvailability = action.ownerStatus_.PresenceAvailability;
86     faction.ownerStatus_.PresenceText = action.ownerStatus_.PresenceText;
87     faction.ownerStatus_.LastActivity = action.ownerStatus_.LastActivity;
88     faction.ownerStatus_.ChatState = action.ownerStatus_.ChatState;
89 
90     frameworkObserverList_.ForEach([remoteDevice, faction, fstate](std::shared_ptr<MapClientObserver> observer) {
91         observer->OnMapActionCompleted(remoteDevice, faction, fstate);
92     });
93 }
94 
ConvertVcardToFramewrokFormat(IProfileMapVcard profileVcard)95 MapVcard BluetoothMapMceObserverImpl::ConvertVcardToFramewrokFormat(IProfileMapVcard profileVcard)
96 {
97     MapVcard frameworkVcard;
98     frameworkVcard.VERSION = profileVcard.VERSION;    // shall be included
99     frameworkVcard.N = profileVcard.N;                // shall be included
100     frameworkVcard.TEL = profileVcard.TEL;            // may be used
101     frameworkVcard.EMAIL = profileVcard.EMAIL;        // may be used
102     frameworkVcard.X_BT_UID = profileVcard.X_BT_UID;  // bmsg V1.1
103     frameworkVcard.X_BT_UCI = profileVcard.X_BT_UCI;  // bmsg V1.1
104     frameworkVcard.FN = profileVcard.FN;              // vcard 3.0 , shall be included
105     return frameworkVcard;
106 }
107 
OnBmessageCompleted(const BluetoothRawAddress & deviceAddress,const BluetoothIProfileBMessage & bmsg,int state)108 void BluetoothMapMceObserverImpl::OnBmessageCompleted(
109     const BluetoothRawAddress &deviceAddress,
110     const BluetoothIProfileBMessage &bmsg, int state)
111 {
112     BluetoothRemoteDevice remoteDevice(deviceAddress.GetAddress(), 0);
113     MapBMessage fBmsg;
114     MapExecuteStatus fstate = MapExecuteStatus(state);
115 
116     // Bmessage
117     fBmsg.bMessageStringObject_ = bmsg.bMessageStringObject_;
118     IProfileBMessageStruct msg = bmsg.bMessageParam_;
119     fBmsg.FractionDeliver = static_cast<OHOS::Bluetooth::MapFractionDeliverType>(bmsg.FractionDeliver);
120     fBmsg.bMessageParam_.version_property = msg.version_property;
121     fBmsg.bMessageParam_.readstatus_property = static_cast<OHOS::Bluetooth::MapMessageStatus>(msg.readstatus_property);
122     fBmsg.bMessageParam_.type_property = static_cast<OHOS::Bluetooth::MapMessageType>(msg.type_property);
123     fBmsg.bMessageParam_.folder_property = msg.folder_property;
124     fBmsg.bMessageParam_.extendeddata_property = msg.extendeddata_property;
125 
126     IProfileMapVcard profileVcard;
127     MapVcard frameworkVcard;
128     if (msg.originator_.size() == 1) {
129         auto itVcard = msg.originator_.begin();
130         profileVcard = *itVcard;
131         frameworkVcard = ConvertVcardToFramewrokFormat(profileVcard);
132         fBmsg.bMessageParam_.originator_.push_back(frameworkVcard);
133     }
134     for (auto it = msg.envelope_.recipientLevel1_.begin(); it != msg.envelope_.recipientLevel1_.end(); it++) {
135         profileVcard = *it;
136         frameworkVcard = ConvertVcardToFramewrokFormat(profileVcard);
137         fBmsg.bMessageParam_.envelope_.recipientLevel1_.push_back(frameworkVcard);
138     }
139     for (auto it2 = msg.envelope_.recipientLevel2_.begin(); it2 != msg.envelope_.recipientLevel2_.end(); it2++) {
140         profileVcard = *it2;
141         frameworkVcard = ConvertVcardToFramewrokFormat(profileVcard);
142         fBmsg.bMessageParam_.envelope_.recipientLevel2_.push_back(frameworkVcard);
143     }
144     for (auto it3 = msg.envelope_.recipientLevel3_.begin(); it3 != msg.envelope_.recipientLevel3_.end(); it3++) {
145         profileVcard = *it3;
146         frameworkVcard = ConvertVcardToFramewrokFormat(profileVcard);
147         fBmsg.bMessageParam_.envelope_.recipientLevel3_.push_back(frameworkVcard);
148     }
149 
150     fBmsg.bMessageParam_.envelope_.maxLevelOfEnvelope_ = msg.envelope_.maxLevelOfEnvelope_;
151     fBmsg.bMessageParam_.envelope_.msgBody_.bodyPartID = msg.envelope_.msgBody_.bodyPartID;
152     fBmsg.bMessageParam_.envelope_.msgBody_.body_encoding = msg.envelope_.msgBody_.body_encoding;
153     fBmsg.bMessageParam_.envelope_.msgBody_.body_charset = msg.envelope_.msgBody_.body_charset;
154     fBmsg.bMessageParam_.envelope_.msgBody_.body_language = msg.envelope_.msgBody_.body_language;
155     fBmsg.bMessageParam_.envelope_.msgBody_.body_content = msg.envelope_.msgBody_.body_content;
156     fBmsg.bMessageParam_.envelope_.msgBody_.body_content_length = msg.envelope_.msgBody_.body_content_length;
157 
158     frameworkObserverList_.ForEach([remoteDevice, fBmsg, fstate](std::shared_ptr<MapClientObserver> observer) {
159         observer->OnBmessageCompleted(remoteDevice, fBmsg, fstate);
160     });
161 }
162 
OnMessagesListingCompleted(const BluetoothRawAddress & deviceAddress,const BluetoothIProfileMessagesListing & listing,int state)163 void BluetoothMapMceObserverImpl::OnMessagesListingCompleted(
164     const BluetoothRawAddress &deviceAddress,
165     const BluetoothIProfileMessagesListing &listing, int state)
166 {
167     BluetoothRemoteDevice remoteDevice(deviceAddress.GetAddress(), 0);
168     MessagesListing fListing;
169     MapExecuteStatus fstate = MapExecuteStatus(state);
170 
171     // message listing
172     fListing.messagesListingStringObject_ = listing.messagesListingStringObject_;
173     IProfileMessagesListingParamStruct serviceMsgListParam = listing.messagesListingParam_;
174     fListing.messagesListingParam_.NewMessage =
175         static_cast<OHOS::Bluetooth::MapOnOffType>(serviceMsgListParam.NewMessage); // on off
176     fListing.messagesListingParam_.MseTime =
177         serviceMsgListParam.MseTime;  // String with current time basis and UTC-offset of the MSE.
178     fListing.messagesListingParam_.ListingSize = serviceMsgListParam.ListingSize;
179     fListing.messagesListingParam_.DatabaseIdentifier =
180         serviceMsgListParam.DatabaseIdentifier;  // 128-bit value in hex string format,max 32 bytes
181     fListing.messagesListingParam_.FolderVersionCounter =
182         serviceMsgListParam.FolderVersionCounter;  // 128-bit value in hex string format,max 32 bytes
183     fListing.messagesListingParam_.Version = serviceMsgListParam.Version;  // "1.1" or "1.0"
184     IProfileMessageOutline outlineMsg;
185     MessageOutline frameworkMsg;
186     std::vector<IProfileMessageOutline> serviceMsgOutineList = listing.messageOutlineList_;
187     for (auto it = serviceMsgOutineList.begin(); it != serviceMsgOutineList.end(); it++) {
188         outlineMsg = *it;
189         frameworkMsg.handle = outlineMsg.handle;
190         frameworkMsg.subject = outlineMsg.subject;
191         frameworkMsg.datetime = outlineMsg.datetime;
192         frameworkMsg.sender_name = outlineMsg.sender_name;
193         frameworkMsg.sender_addressing = outlineMsg.sender_addressing;
194         frameworkMsg.replyto_addressing = outlineMsg.replyto_addressing;
195         frameworkMsg.recipient_name = outlineMsg.recipient_name;
196         frameworkMsg.recipient_addressing = outlineMsg.recipient_addressing;
197         frameworkMsg.type = (OHOS::Bluetooth::MapMessageType)outlineMsg.type;
198         frameworkMsg.receptionStatus = (OHOS::Bluetooth::MapMsgReceptionStatus)outlineMsg.receptionStatus;
199         frameworkMsg.size = outlineMsg.size;
200         frameworkMsg.attachment_size = outlineMsg.attachment_size;
201         frameworkMsg.text = (OHOS::Bluetooth::MapBoolType)outlineMsg.text;
202         frameworkMsg.read = (OHOS::Bluetooth::MapMessageStatus)outlineMsg.read;
203         frameworkMsg.sent = (OHOS::Bluetooth::MapBoolType)outlineMsg.sent;
204         frameworkMsg.protected_ = (OHOS::Bluetooth::MapBoolType)outlineMsg.protected_;
205         frameworkMsg.priority = (OHOS::Bluetooth::MapBoolType)outlineMsg.priority;
206         frameworkMsg.delivery_status = (OHOS::Bluetooth::MapMsgDeliveryStatus)outlineMsg.delivery_status;
207         frameworkMsg.conversation_id = outlineMsg.conversation_id;
208         frameworkMsg.conversation_name = outlineMsg.conversation_name;
209         frameworkMsg.direction = (OHOS::Bluetooth::MapMsgDirection)outlineMsg.direction;
210         frameworkMsg.attachment_mime_types = outlineMsg.attachment_mime_types;
211         fListing.messageOutlineList_.push_back(frameworkMsg);
212     }
213 
214     frameworkObserverList_.ForEach([remoteDevice, fListing, fstate](std::shared_ptr<MapClientObserver> observer) {
215         observer->OnMessagesListingCompleted(remoteDevice, fListing, fstate);
216     });
217 }
218 
OnConversationListingCompleted(const BluetoothRawAddress & deviceAddress,const BluetoothIProfileConversationListing & listing,int state)219 void BluetoothMapMceObserverImpl::OnConversationListingCompleted(
220     const BluetoothRawAddress &deviceAddress,
221     const BluetoothIProfileConversationListing &listing, int state)
222 {
223     BluetoothRemoteDevice remoteDevice(deviceAddress.GetAddress(), 0);
224     ConversationListing fListing;
225     MapExecuteStatus fstate = MapExecuteStatus(state);
226 
227     // conversationList listing
228     // save the object
229     fListing.conversationListingStringObject_ = listing.conversationListingStringObject_;
230     // save the param
231     IProfileConversationListingParamStruct serviceParamStruct = listing.conversationListingParam_;
232     fListing.conversationListingParam_.ConversationListingVersionCounter =
233         serviceParamStruct.ConversationListingVersionCounter;  // 128-bit value in hex string format(max 32 bytes)
234     fListing.conversationListingParam_.ListingSize = serviceParamStruct.ListingSize;
235     fListing.conversationListingParam_.DatabaseIdentifier =
236         serviceParamStruct.DatabaseIdentifier;  // 128-bit value in hex string format(max 32 bytes)
237     fListing.conversationListingParam_.MseTime =
238         serviceParamStruct.MseTime;  // String with current time basis and UTC-offset of the MSE. See Section 5.5.4
239     fListing.conversationListingParam_.Version = serviceParamStruct.Version;
240     // save the conversation list
241     fListing.conversationOutlineList_.clear();
242     Participant fParticipant;
243     Conversation fConvoOutline;
244     IProfileParticipant serviceParticipant;
245     IProfileConversation serviceOutline;
246     std::vector<IProfileConversation> serviceConvoList = listing.conversationOutlineList_;
247     for (auto it = serviceConvoList.begin(); it != serviceConvoList.end(); it++) {
248         serviceOutline = *it;
249         // set value
250         fConvoOutline.id = serviceOutline.id;
251         fConvoOutline.name = serviceOutline.name;
252         fConvoOutline.last_activity = serviceOutline.last_activity;
253         fConvoOutline.read_status = serviceOutline.read_status;
254         fConvoOutline.version_counter = serviceOutline.version_counter;
255         fConvoOutline.summary = serviceOutline.summary;
256         // init list
257         fConvoOutline.participantList_.clear();
258         for (auto it2 = serviceOutline.participantList_.begin(); it2 != serviceOutline.participantList_.end(); it2++) {
259             serviceParticipant = *it2;
260             fParticipant.uci = serviceParticipant.uci;
261             fParticipant.display_name = serviceParticipant.display_name;
262             fParticipant.chat_state = serviceParticipant.chat_state;
263             fParticipant.last_activity = serviceParticipant.last_activity;
264             fParticipant.x_bt_uid = serviceParticipant.x_bt_uid;
265             fParticipant.name = serviceParticipant.name;
266             fParticipant.presence_availability = serviceParticipant.presence_availability;
267             fParticipant.presence_text = serviceParticipant.presence_text;
268             fParticipant.priority = serviceParticipant.priority;
269             fConvoOutline.participantList_.push_back(fParticipant);
270         }
271         fListing.conversationOutlineList_.push_back(fConvoOutline);
272     }
273 
274     frameworkObserverList_.ForEach([remoteDevice, fListing, fstate](std::shared_ptr<MapClientObserver> observer) {
275         observer->OnConversationListingCompleted(remoteDevice, fListing, fstate);
276     });
277 }
278 
OnMapEventReported(const BluetoothRawAddress & deviceAddress,const BluetoothIProfileMapEventReport & report)279 void BluetoothMapMceObserverImpl::OnMapEventReported(
280     const BluetoothRawAddress &deviceAddress,
281     const BluetoothIProfileMapEventReport &report)
282 {
283     BluetoothRemoteDevice remoteDevice(deviceAddress.GetAddress(), 0);
284     MapEventReport fEventReport;
285 
286     fEventReport.type = report.type;
287     fEventReport.handle = report.handle;
288     fEventReport.folder = report.folder;
289     fEventReport.old_folder = report.old_folder;
290     fEventReport.msg_type = static_cast<OHOS::Bluetooth::MapMessageType>(report.msg_type);
291     fEventReport.datetime = report.datetime;
292     fEventReport.subject = report.subject;
293     fEventReport.sender_name = report.sender_name;
294     fEventReport.priority = static_cast<OHOS::Bluetooth::MapBoolType>(report.priority);
295     fEventReport.conversation_name = report.conversation_name;
296     fEventReport.conversation_id = report.conversation_id;
297     fEventReport.presence_availability = report.presence_availability;
298     fEventReport.presence_text = report.presence_text;
299     fEventReport.last_activity = report.last_activity;
300     fEventReport.chat_state = report.chat_state;
301     fEventReport.read_status = static_cast<OHOS::Bluetooth::MapMessageStatus>(report.read_status);
302     fEventReport.extended_data = report.extended_data;
303     fEventReport.participant_uci = report.participant_uci;
304     fEventReport.contact_uid = report.contact_uid;
305     fEventReport.version = report.version;
306     fEventReport.masInstanceId_ = report.masInstanceId_;
307     fEventReport.eventReportStringObject_ = report.eventReportStringObject_;
308 
309     frameworkObserverList_.ForEach([remoteDevice, fEventReport](std::shared_ptr<MapClientObserver> observer) {
310         observer->OnMapEventReported(remoteDevice, fEventReport);
311     });
312 }
313 
314 struct MapClient::impl {
315     impl();
~implOHOS::Bluetooth::MapClient::impl316     ~impl()
317     {
318         if (proxy_ != nullptr) {
319             proxy_->DeregisterObserver(observerImp_);
320             proxy_->AsObject()->RemoveDeathRecipient(deathRecipient_);
321         }
322     }
323     sptr<IBluetoothMapMce> proxy_;
324     class BluetoothMapMceDeathRecipient;
325     sptr<BluetoothMapMceDeathRecipient> deathRecipient_ = nullptr;
326     std::mutex mutex_;
327     BluetoothObserverList<MapClientObserver> mapClientObserverList_;
328     sptr<BluetoothMapMceObserverImpl> observerImp_ = new BluetoothMapMceObserverImpl(mapClientObserverList_);
329     IProfileMapVcard ConvertVcardToProfileFormat(MapVcard frameVcard);
330     void ConvertEnvelopeToProfileFormat(
331         IProfileSendMessageParameters &iProfileMsg, const MapSendMessageParameters &msg);
332     bool InitMapClientProxy(void);
333 };
334 
335 class MapClient::impl::BluetoothMapMceDeathRecipient final : public IRemoteObject::DeathRecipient {
336 public:
BluetoothMapMceDeathRecipient(MapClient::impl & MapMce)337     explicit BluetoothMapMceDeathRecipient(MapClient::impl &MapMce) : MapMce_(MapMce) {};
338     ~BluetoothMapMceDeathRecipient() final = default;
339     BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(BluetoothMapMceDeathRecipient);
340 
OnRemoteDied(const wptr<IRemoteObject> & remote)341     void OnRemoteDied(const wptr<IRemoteObject> &remote) final
342     {
343         HILOGI("starts");
344         if (!MapMce_.proxy_) {
345             return;
346         }
347         MapMce_.proxy_->DeregisterObserver(MapMce_.observerImp_);
348         MapMce_.proxy_->AsObject()->RemoveDeathRecipient(MapMce_.deathRecipient_);
349         MapMce_.proxy_ = nullptr;
350     }
351 
352 private:
353     MapClient::impl &MapMce_;
354 };
355 
impl()356 MapClient::impl::impl()
357 {
358     if (proxy_) {
359         return;
360     }
361     BluetootLoadSystemAbility::GetInstance().RegisterNotifyMsg(PROFILE_ID_MAP_MCE);
362     if (!BluetootLoadSystemAbility::GetInstance().HasSubscribedBluetoothSystemAbility()) {
363         BluetootLoadSystemAbility::GetInstance().SubScribeBluetoothSystemAbility();
364         return;
365     }
366     InitMapClientProxy();
367 }
368 
InitMapClientProxy(void)369 bool MapClient::impl::InitMapClientProxy(void)
370 {
371     if (proxy_) {
372         return true;
373     }
374     proxy_ = GetRemoteProxy<IBluetoothMapMce>(PROFILE_MAP_MCE);
375     if (!proxy_) {
376         HILOGE("get MapClient proxy_ failed");
377         return false;
378     }
379 
380     if (observerImp_ != nullptr) {
381         proxy_->RegisterObserver(observerImp_);
382     }
383 
384     deathRecipient_ = new BluetoothMapMceDeathRecipient(*this);
385     if (deathRecipient_ != nullptr) {
386         proxy_->AsObject()->AddDeathRecipient(deathRecipient_);
387     }
388     return true;
389 }
390 
GetProfile()391 MapClient *MapClient::GetProfile()
392 {
393     HILOGI("enter");
394     static MapClient mapClient;
395     return &mapClient;
396 }
397 
MapClient()398 MapClient::MapClient() : pimpl(nullptr)
399 {
400     HILOGI("excute");
401     pimpl = std::make_unique<impl>();
402 }
403 
~MapClient()404 MapClient::~MapClient()
405 {
406 }
407 
Init()408 void MapClient::Init()
409 {
410     if (!pimpl) {
411         HILOGE("fails: no pimpl");
412         return;
413     }
414     if (!pimpl->InitMapClientProxy()) {
415         HILOGE("MapClient proxy_ is nullptr");
416         return;
417     }
418 }
419 
RegisterObserver(MapClientObserver & observer)420 void MapClient::RegisterObserver(MapClientObserver &observer)
421 {
422     HILOGI("enter");
423     std::shared_ptr<MapClientObserver> pointer(&observer, [](MapClientObserver *) {});
424     pimpl->mapClientObserverList_.Register(pointer);
425 }
426 
DeregisterObserver(MapClientObserver & observer)427 void MapClient::DeregisterObserver(MapClientObserver &observer)
428 {
429     HILOGI("enter");
430     std::shared_ptr<MapClientObserver> pointer(&observer, [](MapClientObserver *) {});
431     pimpl->mapClientObserverList_.Deregister(pointer);
432 }
433 
Connect(const BluetoothRemoteDevice & device)434 bool MapClient::Connect(const BluetoothRemoteDevice &device)
435 {
436     HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
437     if (!IS_BT_ENABLED()) {
438         HILOGE("bluetooth is off.");
439         return false;
440     }
441 
442     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
443         HILOGE("pimpl or mapClient proxy_ is nullptr");
444         return false;
445     }
446 
447     if (!device.IsValidBluetoothRemoteDevice()) {
448         HILOGE("BluetoothRemoteDevice error");
449         return false;
450     }
451 
452     BluetoothRawAddress rawAddress(device.GetDeviceAddr());
453     int retInt = pimpl->proxy_->Connect(rawAddress);
454     return retInt == RET_NO_ERROR;
455 }
456 
Disconnect(const BluetoothRemoteDevice & device)457 bool MapClient::Disconnect(const BluetoothRemoteDevice &device)
458 {
459     HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
460     if (!IS_BT_ENABLED()) {
461         HILOGE("bluetooth is off.");
462         return false;
463     }
464 
465     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
466         HILOGE("pimpl or mapClient proxy_ is nullptr");
467         return false;
468     }
469 
470     if (!device.IsValidBluetoothRemoteDevice()) {
471         HILOGE("BluetoothRemoteDevice error");
472         return false;
473     }
474 
475     BluetoothRawAddress rawAddress(device.GetDeviceAddr());
476     int retInt = pimpl->proxy_->Disconnect(rawAddress);
477     return retInt == RET_NO_ERROR;
478 }
479 
IsConnected(const BluetoothRemoteDevice & device)480 bool MapClient::IsConnected(const BluetoothRemoteDevice &device)
481 {
482     HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
483     if (!IS_BT_ENABLED()) {
484         HILOGE("bluetooth is off.");
485         return false;
486     }
487 
488     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
489         HILOGE("pimpl or mapClient proxy_ is nullptr");
490         return false;
491     }
492 
493     if (!device.IsValidBluetoothRemoteDevice()) {
494         HILOGE("BluetoothRemoteDevice error");
495         return false;
496     }
497 
498     BluetoothRawAddress rawDevice(device.GetDeviceAddr());
499     return pimpl->proxy_->IsConnected(rawDevice);
500 }
501 
GetConnectedDevices() const502 std::vector<BluetoothRemoteDevice> MapClient::GetConnectedDevices() const
503 {
504     HILOGI("enter");
505     std::vector<BluetoothRemoteDevice> btDeviceList;
506     if (!IS_BT_ENABLED()) {
507         HILOGE("bluetooth is off.");
508         return btDeviceList;
509     }
510 
511     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
512         HILOGE("pimpl or mapClient proxy_ is nullptr");
513         return btDeviceList;
514     }
515 
516     std::vector<BluetoothRawAddress> btDevice;
517     pimpl->proxy_->GetConnectDevices(btDevice);
518     for (auto it = btDevice.begin(); it != btDevice.end(); it++) {
519         btDeviceList.push_back(BluetoothRemoteDevice(it->GetAddress(), 0));
520     }
521     return btDeviceList;
522 }
523 
GetDevicesByStates(const std::vector<int> & statesList) const524 std::vector<BluetoothRemoteDevice> MapClient::GetDevicesByStates(const std::vector<int> &statesList) const
525 {
526     HILOGI("enter");
527     std::vector<BluetoothRemoteDevice> btDeviceList;
528     if (!IS_BT_ENABLED()) {
529         HILOGE("bluetooth is off.");
530         return btDeviceList;
531     }
532 
533     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
534         HILOGE("pimpl or mapClient proxy_ is nullptr");
535         return btDeviceList;
536     }
537 
538     std::vector<BluetoothRawAddress> btDevice;
539     pimpl->proxy_->GetDevicesByStates(statesList, btDevice);
540     for (auto it = btDevice.begin(); it != btDevice.end(); it++) {
541         btDeviceList.push_back(BluetoothRemoteDevice(it->GetAddress(), 0));
542     }
543     return btDeviceList;
544 }
545 
GetConnectionState(const BluetoothRemoteDevice & device) const546 int MapClient::GetConnectionState(const BluetoothRemoteDevice &device) const
547 {
548     HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
549     if (!IS_BT_ENABLED()) {
550         HILOGE("bluetooth is off.");
551         return static_cast<int>(BTConnectState::DISCONNECTED);
552     }
553 
554     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
555         HILOGE("pimpl or mapClient proxy_ is nullptr");
556         return static_cast<int>(BTConnectState::DISCONNECTED);
557     }
558 
559     if (!device.IsValidBluetoothRemoteDevice()) {
560         HILOGE("BluetoothRemoteDevice error");
561         return static_cast<int>(BTConnectState::DISCONNECTED);
562     }
563 
564     BluetoothRawAddress rawDevice(device.GetDeviceAddr());
565     return pimpl->proxy_->GetConnectionState(rawDevice);
566 }
567 
SetConnectionStrategy(const BluetoothRemoteDevice & device,const int strategy)568 bool MapClient::SetConnectionStrategy(const BluetoothRemoteDevice &device, const int strategy)
569 {
570     HILOGI("enter, device: %{public}s, device: %{public}d", GET_ENCRYPT_ADDR(device), strategy);
571     if (!IS_BT_ENABLED()) {
572         HILOGE("bluetooth is off.");
573         return false;
574     }
575 
576     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
577         HILOGE("pimpl or mapClient proxy_ is nullptr");
578         return false;
579     }
580 
581     if (!device.IsValidBluetoothRemoteDevice()) {
582         HILOGE("BluetoothRemoteDevice error");
583         return false;
584     }
585 
586     BluetoothRawAddress rawDevice(device.GetDeviceAddr());
587     int retInt = pimpl->proxy_->SetConnectionStrategy(rawDevice, strategy);
588     return retInt == RET_NO_ERROR;
589 }
590 
GetConnectionStrategy(const BluetoothRemoteDevice & device) const591 int MapClient::GetConnectionStrategy(const BluetoothRemoteDevice &device) const
592 {
593     HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
594     if (!IS_BT_ENABLED()) {
595         HILOGE("bluetooth is off.");
596         return static_cast<int>(BTStrategyType::CONNECTION_FORBIDDEN);
597     }
598 
599     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
600         HILOGE("pimpl or mapClient proxy_ is nullptr");
601         return static_cast<int>(BTStrategyType::CONNECTION_FORBIDDEN);
602     }
603 
604     if (!device.IsValidBluetoothRemoteDevice()) {
605         HILOGE("BluetoothRemoteDevice error");
606         return static_cast<int>(BTStrategyType::CONNECTION_FORBIDDEN);
607     }
608 
609     BluetoothRawAddress rawDevice(device.GetDeviceAddr());
610     return pimpl->proxy_->GetConnectionStrategy(rawDevice);
611 }
612 
GetUnreadMessages(const BluetoothRemoteDevice & device,MapMessageType type,uint8_t max)613 int MapClient::GetUnreadMessages(const BluetoothRemoteDevice &device, MapMessageType type, uint8_t max)
614 {
615     HILOGI("enter, device: %{public}s, max: %{public}d", GET_ENCRYPT_ADDR(device), max);
616     if (!IS_BT_ENABLED()) {
617         HILOGE("bluetooth is off.");
618         return RET_BAD_STATUS;
619     }
620 
621     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
622         HILOGE("pimpl or mapClient proxy_ is nullptr");
623         return RET_BAD_STATUS;
624     }
625 
626     if (!device.IsValidBluetoothRemoteDevice()) {
627         HILOGE("BluetoothRemoteDevice error");
628         return RET_BAD_PARAM;
629     }
630 
631     BluetoothRawAddress rawDevice(device.GetDeviceAddr());
632     return pimpl->proxy_->GetUnreadMessages(rawDevice, (int)type, max);
633 }
634 
GetSupportedFeatures(const BluetoothRemoteDevice & device) const635 int MapClient::GetSupportedFeatures(const BluetoothRemoteDevice &device) const
636 {
637     HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
638     if (!IS_BT_ENABLED()) {
639         HILOGE("bluetooth is off.");
640         return RET_BAD_STATUS;
641     }
642 
643     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
644         HILOGE("pimpl or mapClient proxy_ is nullptr");
645         return RET_BAD_STATUS;
646     }
647 
648     if (!device.IsValidBluetoothRemoteDevice()) {
649         HILOGE("BluetoothRemoteDevice error");
650         return RET_BAD_PARAM;
651     }
652 
653     BluetoothRawAddress rawDevice(device.GetDeviceAddr());
654     return pimpl->proxy_->GetSupportedFeatures(rawDevice);
655 }
656 
657 
ConvertVcardToProfileFormat(MapVcard frameVcard)658 IProfileMapVcard MapClient::impl::ConvertVcardToProfileFormat(MapVcard frameVcard)
659 {
660     HILOGI("enter");
661     IProfileMapVcard serviceVcard;
662     serviceVcard.VERSION = frameVcard.VERSION;    // shall be included
663     serviceVcard.N = frameVcard.N;                // shall be included
664     serviceVcard.TEL = frameVcard.TEL;            // may be used
665     serviceVcard.EMAIL = frameVcard.EMAIL;        // may be used
666     serviceVcard.X_BT_UID = frameVcard.X_BT_UID;  // bmsg V1.1
667     serviceVcard.X_BT_UCI = frameVcard.X_BT_UCI;  // bmsg V1.1
668     serviceVcard.FN = frameVcard.FN;              // vcard 3.0 , shall be included
669     return serviceVcard;
670 }
671 
ConvertEnvelopeToProfileFormat(IProfileSendMessageParameters & iProfileMsg,const MapSendMessageParameters & msg)672 void MapClient::impl::ConvertEnvelopeToProfileFormat(
673     IProfileSendMessageParameters &iProfileMsg, const MapSendMessageParameters &msg)
674 {
675     HILOGI("enter");
676     MapVcard frameVcard;
677     IProfileMapVcard serviceVcard;
678     if (msg.message.originator_.size() == 1) {
679         auto itVcard = msg.message.originator_.begin();
680         frameVcard = *itVcard;
681         serviceVcard = ConvertVcardToProfileFormat(frameVcard);
682         iProfileMsg.bmessage_.originator_.push_back(serviceVcard);
683     }
684     for (auto it = msg.message.envelope_.recipientLevel1_.begin(); it != msg.message.envelope_.recipientLevel1_.end();
685         it++) {
686         frameVcard = *it;
687         serviceVcard = ConvertVcardToProfileFormat(frameVcard);
688         iProfileMsg.bmessage_.envelope_.recipientLevel1_.push_back(serviceVcard);
689     }
690     for (auto it2 = msg.message.envelope_.recipientLevel2_.begin();
691         it2 != msg.message.envelope_.recipientLevel2_.end();
692         it2++) {
693         frameVcard = *it2;
694         serviceVcard = ConvertVcardToProfileFormat(frameVcard);
695         iProfileMsg.bmessage_.envelope_.recipientLevel2_.push_back(serviceVcard);
696     }
697     for (auto it3 = msg.message.envelope_.recipientLevel3_.begin();
698         it3 != msg.message.envelope_.recipientLevel3_.end();
699         it3++) {
700         frameVcard = *it3;
701         serviceVcard = ConvertVcardToProfileFormat(frameVcard);
702         iProfileMsg.bmessage_.envelope_.recipientLevel3_.push_back(serviceVcard);
703     }
704 
705     iProfileMsg.bmessage_.envelope_.maxLevelOfEnvelope_ = msg.message.envelope_.maxLevelOfEnvelope_;
706     iProfileMsg.bmessage_.envelope_.msgBody_.bodyPartID = msg.message.envelope_.msgBody_.bodyPartID;
707     iProfileMsg.bmessage_.envelope_.msgBody_.body_encoding = msg.message.envelope_.msgBody_.body_encoding;
708     iProfileMsg.bmessage_.envelope_.msgBody_.body_charset = msg.message.envelope_.msgBody_.body_charset;
709     iProfileMsg.bmessage_.envelope_.msgBody_.body_language = msg.message.envelope_.msgBody_.body_language;
710     iProfileMsg.bmessage_.envelope_.msgBody_.body_content = msg.message.envelope_.msgBody_.body_content;
711     iProfileMsg.bmessage_.envelope_.msgBody_.body_content_length = msg.message.envelope_.msgBody_.body_content_length;
712 }
713 
SendMessage(const BluetoothRemoteDevice & device,const MapSendMessageParameters & msg)714 int MapClient::SendMessage(const BluetoothRemoteDevice &device, const MapSendMessageParameters &msg)
715 {
716     HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
717     if (!IS_BT_ENABLED()) {
718         HILOGE("bluetooth is off.");
719         return RET_BAD_STATUS;
720     }
721 
722     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
723         HILOGE("pimpl or mapClient proxy_ is nullptr");
724         return RET_BAD_STATUS;
725     }
726 
727     if (!device.IsValidBluetoothRemoteDevice()) {
728         HILOGE("BluetoothRemoteDevice error");
729         return RET_BAD_PARAM;
730     }
731 
732     BluetoothIProfileSendMessageParameters iProfileMsg;
733     iProfileMsg.Charset = static_cast<bluetooth::MapCharsetType>(msg.Charset);
734     iProfileMsg.ConversationID = msg.ConversationID;
735     iProfileMsg.MessageHandle = msg.MessageHandle;
736     iProfileMsg.Attachment = static_cast<bluetooth::MapAttachmentType>(msg.Attachment);
737     iProfileMsg.ModifyText = static_cast<bluetooth::MapModifyTextType>(msg.ModifyText);
738     iProfileMsg.Retry = static_cast<bluetooth::MapOnOffType>(msg.Retry);
739     iProfileMsg.Transparent = static_cast<bluetooth::MapOnOffType>(msg.Transparent);
740     iProfileMsg.bmessage_.version_property = msg.message.version_property;
741     iProfileMsg.bmessage_.readstatus_property =
742         static_cast<bluetooth::MapMessageStatus>(msg.message.readstatus_property);
743     iProfileMsg.bmessage_.type_property = static_cast<bluetooth::MapMessageType>(msg.message.type_property);
744     iProfileMsg.bmessage_.folder_property = msg.message.folder_property;
745     iProfileMsg.bmessage_.extendeddata_property = msg.message.extendeddata_property;
746 
747     pimpl->ConvertEnvelopeToProfileFormat(iProfileMsg, msg);
748     BluetoothRawAddress rawDevice(device.GetDeviceAddr());
749     return pimpl->proxy_->SendMessage(rawDevice, iProfileMsg);
750 }
751 
SetNotificationFilter(const BluetoothRemoteDevice & device,const int mask)752 int MapClient::SetNotificationFilter(const BluetoothRemoteDevice &device, const int mask)
753 {
754     HILOGI("enter, device: %{public}s, mask: %{public}d", GET_ENCRYPT_ADDR(device), mask);
755     if (!IS_BT_ENABLED()) {
756         HILOGE("bluetooth is off.");
757         return RET_BAD_STATUS;
758     }
759 
760     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
761         HILOGE("pimpl or mapClient proxy_ is nullptr");
762         return RET_BAD_STATUS;
763     }
764 
765     if (!device.IsValidBluetoothRemoteDevice()) {
766         HILOGE("BluetoothRemoteDevice error");
767         return RET_BAD_PARAM;
768     }
769 
770     BluetoothRawAddress rawDevice(device.GetDeviceAddr());
771     return pimpl->proxy_->SetNotificationFilter(rawDevice, mask);
772 }
773 
GetMessagesListing(const BluetoothRemoteDevice & device,const GetMessagesListingParameters & para) const774 int MapClient::GetMessagesListing(const BluetoothRemoteDevice &device, const GetMessagesListingParameters &para) const
775 {
776     HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
777     if (!IS_BT_ENABLED()) {
778         HILOGE("bluetooth is off.");
779         return RET_BAD_STATUS;
780     }
781 
782     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
783         HILOGE("pimpl or mapClient proxy_ is nullptr");
784         return RET_BAD_STATUS;
785     }
786 
787     if (!device.IsValidBluetoothRemoteDevice()) {
788         HILOGE("BluetoothRemoteDevice error");
789         return RET_BAD_PARAM;
790     }
791 
792     BluetoothRawAddress rawDevice(device.GetDeviceAddr());
793     BluetoothIProfileGetMessagesListingParameters servicePara;
794     servicePara.folder = para.folder;
795     servicePara.MaxListCount = para.MaxListCount;
796     servicePara.ListStartOffset = para.ListStartOffset;
797     servicePara.SubjectLength = para.SubjectLength;
798     servicePara.ParameterMask = para.ParameterMask;
799     servicePara.FilterMessageType = para.FilterMessageType;
800     servicePara.FilterPeriodBegin = para.FilterPeriodBegin;
801     servicePara.FilterPeriodEnd = para.FilterPeriodEnd;
802     servicePara.FilterReadStatus = para.FilterReadStatus;
803     servicePara.FilterRecipient = para.FilterRecipient;
804     servicePara.FilterOriginator = para.FilterOriginator;
805     servicePara.FilterPriority = para.FilterPriority;
806     servicePara.ConversationID = para.ConversationID;
807     servicePara.FilterMessageHandle = para.FilterMessageHandle;
808 
809     return pimpl->proxy_->GetMessagesListing(rawDevice, servicePara);
810 }
811 
GetMessage(const BluetoothRemoteDevice & device,MapMessageType type,const std::u16string & msgHandle,const GetMessageParameters & para) const812 int MapClient::GetMessage(const BluetoothRemoteDevice &device, MapMessageType type, const std::u16string &msgHandle,
813     const GetMessageParameters &para) const
814 {
815     HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
816     if (!IS_BT_ENABLED()) {
817         HILOGE("bluetooth is off.");
818         return RET_BAD_STATUS;
819     }
820 
821     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
822         HILOGE("pimpl or mapClient proxy_ is nullptr");
823         return RET_BAD_STATUS;
824     }
825 
826     if (!device.IsValidBluetoothRemoteDevice()) {
827         HILOGE("BluetoothRemoteDevice error");
828         return RET_BAD_PARAM;
829     }
830 
831     BluetoothRawAddress rawDevice(device.GetDeviceAddr());
832     BluetoothIProfileGetMessageParameters servicePara;
833     servicePara.Attachment = static_cast<bluetooth::MapAttachmentType>(para.Attachment);
834     servicePara.Charset = static_cast<bluetooth::MapCharsetType>(para.Charset);
835     servicePara.FractionRequest = static_cast<bluetooth::MapFractionRequestType>(para.FractionRequest);
836 
837     return pimpl->proxy_->GetMessage(rawDevice, (int)type, msgHandle, servicePara);
838 }
839 
UpdateInbox(const BluetoothRemoteDevice & device,MapMessageType type)840 int MapClient::UpdateInbox(const BluetoothRemoteDevice &device, MapMessageType type)
841 {
842     HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
843     if (!IS_BT_ENABLED()) {
844         HILOGE("bluetooth is off.");
845         return RET_BAD_STATUS;
846     }
847 
848     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
849         HILOGE("pimpl or mapClient proxy_ is nullptr");
850         return RET_BAD_STATUS;
851     }
852 
853     if (!device.IsValidBluetoothRemoteDevice()) {
854         HILOGE("BluetoothRemoteDevice error");
855         return RET_BAD_PARAM;
856     }
857 
858     BluetoothRawAddress rawDevice(device.GetDeviceAddr());
859     return pimpl->proxy_->UpdateInbox(rawDevice, (int)type);
860 }
861 
GetConversationListing(const BluetoothRemoteDevice & device,const GetConversationListingParameters & para) const862 int MapClient::GetConversationListing(
863     const BluetoothRemoteDevice &device, const GetConversationListingParameters &para) const
864 {
865     HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
866     if (!IS_BT_ENABLED()) {
867         HILOGE("bluetooth is off.");
868         return RET_BAD_STATUS;
869     }
870 
871     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
872         HILOGE("pimpl or mapClient proxy_ is nullptr");
873         return RET_BAD_STATUS;
874     }
875 
876     if (!device.IsValidBluetoothRemoteDevice()) {
877         HILOGE("BluetoothRemoteDevice error");
878         return RET_BAD_PARAM;
879     }
880 
881     BluetoothRawAddress rawDevice(device.GetDeviceAddr());
882     BluetoothIProfileGetConversationListingParameters servicePara;
883     servicePara.MaxListCount = para.MaxListCount;
884     servicePara.ListStartOffset = para.ListStartOffset;
885     servicePara.FilterReadStatus = para.FilterReadStatus;
886     servicePara.FilterRecipient = para.FilterRecipient;
887     servicePara.ConversationID = para.ConversationID;
888     servicePara.FilterLastActivityBegin = para.FilterLastActivityBegin;
889     servicePara.FilterLastActivityEnd = para.FilterLastActivityEnd;
890     servicePara.ConvParameterMask = para.ConvParameterMask;
891 
892     return pimpl->proxy_->GetConversationListing(rawDevice, servicePara);
893 }
894 
SetMessageStatus(const BluetoothRemoteDevice & device,MapMessageType type,const MapSetMessageStatus & msgStatus)895 int MapClient::SetMessageStatus(
896     const BluetoothRemoteDevice &device, MapMessageType type, const MapSetMessageStatus &msgStatus)
897 {
898     HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
899     if (!IS_BT_ENABLED()) {
900         HILOGE("bluetooth is off.");
901         return RET_BAD_STATUS;
902     }
903 
904     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
905         HILOGE("pimpl or mapClient proxy_ is nullptr");
906         return RET_BAD_STATUS;
907     }
908 
909     if (!device.IsValidBluetoothRemoteDevice()) {
910         HILOGE("BluetoothRemoteDevice error");
911         return RET_BAD_PARAM;
912     }
913 
914     BluetoothRawAddress rawDevice(device.GetDeviceAddr());
915     return pimpl->proxy_->SetMessageStatus(rawDevice,
916         (int)type,
917         msgStatus.msgHandle,
918         (int)msgStatus.statusIndicator,
919         (int)msgStatus.statusValue,
920         msgStatus.extendedData);
921 }
922 
SetOwnerStatus(const BluetoothRemoteDevice & device,const SetOwnerStatusParameters & para)923 int MapClient::SetOwnerStatus(const BluetoothRemoteDevice &device, const SetOwnerStatusParameters &para)
924 {
925     HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
926     if (!IS_BT_ENABLED()) {
927         HILOGE("bluetooth is off.");
928         return RET_BAD_STATUS;
929     }
930 
931     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
932         HILOGE("pimpl or mapClient proxy_ is nullptr");
933         return RET_BAD_STATUS;
934     }
935 
936     if (!device.IsValidBluetoothRemoteDevice()) {
937         HILOGE("BluetoothRemoteDevice error");
938         return RET_BAD_PARAM;
939     }
940 
941     BluetoothIProfileSetOwnerStatusParameters servicePara;
942     servicePara.ConversationID = para.conversationId_;
943     servicePara.ownerStatus_.PresenceAvailability = para.ownerStatus_.PresenceAvailability;
944     servicePara.ownerStatus_.PresenceText = para.ownerStatus_.PresenceText;  // utf8
945     servicePara.ownerStatus_.LastActivity = para.ownerStatus_.LastActivity;  // utf8
946     servicePara.ownerStatus_.ChatState = para.ownerStatus_.ChatState;
947 
948     BluetoothRawAddress rawDevice(device.GetDeviceAddr());
949     return pimpl->proxy_->SetOwnerStatus(rawDevice, servicePara);
950 }
951 
GetOwnerStatus(const BluetoothRemoteDevice & device,const std::string & conversationId) const952 int MapClient::GetOwnerStatus(const BluetoothRemoteDevice &device, const std::string &conversationId) const
953 {
954     HILOGI("enter, device: %{public}s, conversationId: %{public}s", GET_ENCRYPT_ADDR(device), conversationId.c_str());
955     if (!IS_BT_ENABLED()) {
956         HILOGE("bluetooth is off.");
957         return RET_BAD_STATUS;
958     }
959 
960     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
961         HILOGE("pimpl or mapClient proxy_ is nullptr");
962         return RET_BAD_STATUS;
963     }
964 
965     if (!device.IsValidBluetoothRemoteDevice()) {
966         HILOGE("BluetoothRemoteDevice error");
967         return RET_BAD_PARAM;
968     }
969 
970     BluetoothRawAddress rawDevice(device.GetDeviceAddr());
971     return pimpl->proxy_->GetOwnerStatus(rawDevice, conversationId);
972 }
973 
GetMasInstanceInfo(const BluetoothRemoteDevice & device) const974 MapMasInstanceInfoList MapClient::GetMasInstanceInfo(const BluetoothRemoteDevice &device) const
975 {
976     HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
977     MapMasInstanceInfoList frameworkMasInfoList;
978     if (!IS_BT_ENABLED()) {
979         HILOGE("bluetooth is off.");
980         return frameworkMasInfoList;
981     }
982 
983     if (pimpl == nullptr || !pimpl->InitMapClientProxy()) {
984         HILOGE("pimpl or mapClient proxy_ is nullptr");
985         return frameworkMasInfoList;
986     }
987 
988     if (!device.IsValidBluetoothRemoteDevice()) {
989         HILOGE("BluetoothRemoteDevice error");
990         return frameworkMasInfoList;
991     }
992     // process
993 
994     BluetoothRawAddress rawDevice(device.GetDeviceAddr());
995     BluetoothIProfileMasInstanceInfoList infoList = pimpl->proxy_->GetMasInstanceInfo(rawDevice);
996     if (infoList.isValid == true) {
997         MapMasInstanceInfo info;
998         frameworkMasInfoList.isValid = true;
999         for (auto it = infoList.masInfoList.begin(); it != infoList.masInfoList.end(); it++) {
1000             info.OwnerUCI = it->OwnerUCI;
1001             info.MASInstanceInformation = it->MASInstanceInformation;
1002             info.supportedMsgTypes_ = it->supportedMsgTypes_;
1003             info.instanceId = it->instanceId;
1004             frameworkMasInfoList.masInfoList.push_back(info);
1005         }
1006     }
1007     return frameworkMasInfoList;
1008 }
1009 }  // namespace Bluetooth
1010 }  // namespace OHOS
1011