1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 /**
17 * @addtogroup Bluetooth
18 * @{
19 *
20 * @brief Defines map client instance request object.
21 *
22 */
23
24 /**
25 * @file map_mce_instance_request.cpp
26 *
27 * @brief map instance client instance request file .
28 *
29 */
30
31 #include "map_mce_instance_request.h"
32 #include <codecvt>
33 #include <locale>
34 #include "log.h"
35 #include "map_mce_instance_stm.h"
36 #include "map_mce_mns_server.h"
37
38 namespace OHOS {
39 namespace bluetooth {
MapMceInstanceRequest()40 MapMceInstanceRequest::MapMceInstanceRequest()
41 {
42 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
43 saveFlag_ = false;
44 messageType_ = MAP_MCE_SUPPORTED_MESSAGE_TYPE_ALL;
45 ownerUci_ = "";
46 config_.isUseSrmp = false;
47 config_.srmpCount = 0;
48 const int defaultMaxValue = 100;
49 config_.maxOfGetUnread = defaultMaxValue;
50 }
51
~MapMceInstanceRequest()52 MapMceInstanceRequest::~MapMceInstanceRequest()
53 {
54 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
55 }
56
SetSupportMessageType(int type)57 void MapMceInstanceRequest::SetSupportMessageType(int type)
58 {
59 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
60 messageType_ = type;
61 }
62
GetSupportMessageType() const63 int MapMceInstanceRequest::GetSupportMessageType() const
64 {
65 return messageType_;
66 }
67
SetOwnerUci(const std::string & owner)68 void MapMceInstanceRequest::SetOwnerUci(const std::string &owner)
69 {
70 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
71 ownerUci_ = owner;
72 }
73
GetOwnerUci() const74 std::string MapMceInstanceRequest::GetOwnerUci() const
75 {
76 return ownerUci_;
77 }
78
SaveReq()79 void MapMceInstanceRequest::SaveReq()
80 {
81 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
82 saveFlag_ = true;
83 }
84
MapMessageTypeToIprofileMask(MapMessageType type) const85 int MapMceInstanceRequest::MapMessageTypeToIprofileMask(MapMessageType type) const
86 {
87 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
88 uint8_t mask;
89 switch (type) {
90 case MapMessageType::SMS_GSM:
91 mask = MAP_MCE_SUPPORTED_MESSAGE_TYPE_SMS_GSM;
92 break;
93 case MapMessageType::SMS_CDMA:
94 mask = MAP_MCE_SUPPORTED_MESSAGE_TYPE_SMS_CDMA;
95 break;
96 case MapMessageType::MMS:
97 mask = MAP_MCE_SUPPORTED_MESSAGE_TYPE_MMS;
98 break;
99 case MapMessageType::EMAIL:
100 mask = MAP_MCE_SUPPORTED_MESSAGE_TYPE_EMAIL;
101 break;
102 case MapMessageType::IM:
103 mask = MAP_MCE_SUPPORTED_MESSAGE_TYPE_IM;
104 break;
105 default:
106 mask = MAP_MCE_SUPPORTED_MESSAGE_TYPE_ALL;
107 break;
108 }
109 return int(mask);
110 }
111
IprofileMaskToMapMessageType(int mask) const112 MapMessageType MapMceInstanceRequest::IprofileMaskToMapMessageType(int mask) const
113 {
114 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
115 MapMessageType type;
116
117 switch (mask) {
118 case MAP_MCE_SUPPORTED_MESSAGE_TYPE_SMS_GSM:
119 type = MapMessageType::SMS_GSM;
120 break;
121 case MAP_MCE_SUPPORTED_MESSAGE_TYPE_SMS_CDMA:
122 type = MapMessageType::SMS_CDMA;
123 break;
124 case MAP_MCE_SUPPORTED_MESSAGE_TYPE_MMS:
125 type = MapMessageType::MMS;
126
127 break;
128 case MAP_MCE_SUPPORTED_MESSAGE_TYPE_EMAIL:
129 type = MapMessageType::EMAIL;
130 break;
131 case MAP_MCE_SUPPORTED_MESSAGE_TYPE_IM:
132 type = MapMessageType::IM;
133 break;
134 default:
135 type = MapMessageType::INVALID;
136 break;
137 }
138 return type;
139 }
140
SetRequestConfig(MapMceRequestConfig cfg)141 void MapMceInstanceRequest::SetRequestConfig(MapMceRequestConfig cfg)
142 {
143 LOG_INFO("%{public}s execute,isUseSrmp=%{public}d,srmpCount=%{public}d",
144 __PRETTY_FUNCTION__, cfg.isUseSrmp, cfg.srmpCount);
145 config_ = cfg;
146 }
147
GetRequestConfig() const148 MapMceRequestConfig MapMceInstanceRequest::GetRequestConfig() const
149 {
150 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
151 return config_;
152 }
153
MapMessageTypeToFrameworkMask(MapMessageType type) const154 int MapMceInstanceRequest::MapMessageTypeToFrameworkMask(MapMessageType type) const
155 {
156 uint8_t mask;
157 switch (type) {
158 case MapMessageType::SMS_GSM:
159 mask = ~MAP_FILTER_MESSAGE_MASK_SMS_GSM;
160 break;
161 case MapMessageType::SMS_CDMA:
162 mask = ~MAP_FILTER_MESSAGE_MASK_SMS_CDMA;
163 break;
164 case MapMessageType::MMS:
165 mask = ~MAP_FILTER_MESSAGE_MASK_MMS;
166 break;
167 case MapMessageType::EMAIL:
168 mask = ~MAP_FILTER_MESSAGE_MASK_EMAIL;
169 break;
170 case MapMessageType::IM:
171 mask = ~MAP_FILTER_MESSAGE_MASK_IM;
172 break;
173 default:
174 mask = MAP_FILTER_MESSAGE_MASK_NO_FILTERING;
175 break;
176 }
177 LOG_INFO("%{public}s execute,type=%{public}d,mask=%{public}d", __PRETTY_FUNCTION__, int(type), int(mask));
178 return int(mask);
179 }
180
MapMceRequestSetNotificationFilter(const int mask)181 MapMceRequestSetNotificationFilter::MapMceRequestSetNotificationFilter(const int mask)
182 {
183 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
184 notificationFilterMask_ = mask;
185 }
186
~MapMceRequestSetNotificationFilter()187 MapMceRequestSetNotificationFilter::~MapMceRequestSetNotificationFilter()
188 {
189 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
190 // release memory , if have
191 }
192
GetRequestType()193 MceRequestType MapMceRequestSetNotificationFilter::GetRequestType()
194 {
195 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
196 return MCE_REQUEST_TYPE_SET_NOTIFICATION_FILTER;
197 }
198
SendRequest(ObexMpClient & obexIns)199 int MapMceRequestSetNotificationFilter::SendRequest(ObexMpClient &obexIns)
200 {
201 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
202 int ret;
203
204 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::PUT_FINAL);
205
206 // set header
207 // set Connection ID
208 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
209 // Type is "x-bt/MAP-notification-filter"
210 header->AppendItemType(MCE_HEADER_TYPE_SET_NOTIFICATION_FILTER);
211
212 // Application Parameters
213 uint32_t value = static_cast<uint32_t>(notificationFilterMask_);
214 TlvTriplet paramNotif(MCE_NOTIFICATION_FILTER_MASK, value);
215 ObexTlvParamters appParams;
216 appParams.AppendTlvtriplet(paramNotif);
217 header->AppendItemAppParams(appParams);
218
219 // End body
220 uint8_t emptyBody = 0x30;
221 header->AppendItemEndBody(&emptyBody, 1);
222
223 // send request
224 ret = obexIns.Put(*header);
225 if (ret != BT_NO_ERROR) {
226 LOG_ERROR("%{public}s obex Put error,ret=%{public}d ", __PRETTY_FUNCTION__, ret);
227 }
228 LOG_INFO("%{public}s end,FilterMask_ = 0x%x", __PRETTY_FUNCTION__, notificationFilterMask_);
229 return ret;
230 }
231
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)232 int MapMceRequestSetNotificationFilter::ProcessResponse(
233 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
234 {
235 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
236 retAction.action_ = MapActionType::SET_NOTIFICATION_FILTER;
237 return MCE_RESPONSE_FINISH;
238 }
239
MapMceRequestSetNotificationRegistration(bool on)240 MapMceRequestSetNotificationRegistration::MapMceRequestSetNotificationRegistration(bool on)
241 {
242 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
243 setupValue_ = on;
244 }
245
~MapMceRequestSetNotificationRegistration()246 MapMceRequestSetNotificationRegistration::~MapMceRequestSetNotificationRegistration()
247 {
248 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
249 }
250
GetRequestType()251 MceRequestType MapMceRequestSetNotificationRegistration::GetRequestType()
252 {
253 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
254 return MCE_REQUEST_TYPE_SET_NOTIFICATION_REGIST;
255 }
256
SendRequest(ObexMpClient & obexIns)257 int MapMceRequestSetNotificationRegistration::SendRequest(ObexMpClient &obexIns)
258 {
259 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
260 int ret;
261
262 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::PUT_FINAL);
263
264 // set header
265 // set Connection ID
266 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
267 // Type is "x-bt/MAP-NotificationRegistration"
268 header->AppendItemType(MCE_HEADER_TYPE_SET_NOTIFICATION_REGISTRATION);
269
270 // Application Parameters
271 uint8_t value = setupValue_;
272 TlvTriplet paramNotificationStatus(MCE_NOTIFICATION_STATUS, value);
273 ObexTlvParamters appParams;
274 appParams.AppendTlvtriplet(paramNotificationStatus);
275 header->AppendItemAppParams(appParams);
276
277 // End body
278 uint8_t emptyBody = 0x30;
279 header->AppendItemEndBody(&emptyBody, 1);
280
281 // send request
282 ret = obexIns.Put(*header);
283 if (ret != BT_NO_ERROR) {
284 LOG_ERROR("%{public}s obex Put error,ret=%{public}d ", __PRETTY_FUNCTION__, ret);
285 }
286 LOG_INFO("%{public}s end, value = 0x%x", __PRETTY_FUNCTION__, setupValue_);
287 return ret;
288 }
289
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)290 int MapMceRequestSetNotificationRegistration::ProcessResponse(
291 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
292 {
293 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
294 return MCE_RESPONSE_FINISH_NO_CALLBACK;
295 }
296
MapMceRequestGetMasInstanceInformation(uint8_t instId)297 MapMceRequestGetMasInstanceInformation::MapMceRequestGetMasInstanceInformation(uint8_t instId)
298 {
299 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
300 instanceId_ = instId;
301 }
302
~MapMceRequestGetMasInstanceInformation()303 MapMceRequestGetMasInstanceInformation::~MapMceRequestGetMasInstanceInformation()
304 {
305 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
306 }
307
GetRequestType()308 MceRequestType MapMceRequestGetMasInstanceInformation::GetRequestType()
309 {
310 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
311 return MCE_REQUEST_TYPE_GET_MASINSTANCE;
312 }
313
SendRequest(ObexMpClient & obexIns)314 int MapMceRequestGetMasInstanceInformation::SendRequest(ObexMpClient &obexIns)
315 {
316 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
317 int ret;
318
319 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::GET_FINAL); // GET or GET_FINAL
320
321 // set header
322 // Connection ID
323 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
324 // Type is "x-bt/MASInstanceInformation"
325 header->AppendItemType(MCE_HEADER_TYPE_GET_MAS_INSTANCE_INFORMATION);
326
327 TlvTriplet paramInstance(MCE_MAS_INSTANCEID, instanceId_);
328 ObexTlvParamters appParams;
329 appParams.AppendTlvtriplet(paramInstance);
330 header->AppendItemAppParams(appParams);
331
332 // make writer object
333 std::shared_ptr<ObexBodyObject> writer = std::make_shared<ObexArrayBodyObject>();
334
335 // send request
336 ret = obexIns.Get(*header, writer);
337 if (ret != BT_NO_ERROR) {
338 LOG_ERROR("%{public}s obex Get error,ret=%{public}d ", __PRETTY_FUNCTION__, ret);
339 }
340 LOG_INFO("%{public}s end, instanceId_ = %{public}d", __PRETTY_FUNCTION__, instanceId_);
341 return ret;
342 }
343
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)344 int MapMceRequestGetMasInstanceInformation::ProcessResponse(
345 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
346 {
347 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
348 MasInstanceInformation instancInfo;
349 retAction.action_ = MapActionType::GET_MAS_INSTANCE_INFO;
350 // get response code
351 int rescode = resp.GetFieldCode();
352 if (rescode != uint8_t(ObexRspCode::SUCCESS)) {
353 return MCE_RESPONSE_FINISH_NO_CALLBACK;
354 }
355 // init
356 instancInfo.masInstanceInfoUtf8 = u8"";
357 instancInfo.ownerUciUtf8 = u8"";
358 // OwnerUCI, Text UTF-8
359 auto appParam = resp.GetItemAppParams();
360 if (appParam != nullptr) {
361 auto tlvParam = appParam->GetTlvtriplet(MCE_OWNER_UCI); // OwnerUCI 0X27
362 if (tlvParam != nullptr) {
363 int ownerUciLength = tlvParam->GetLen();
364 const uint8_t *val = tlvParam->GetVal();
365 if ((ownerUciLength != 0) && (val != nullptr)) {
366 std::string tempUci(reinterpret_cast<char *>(const_cast<uint8_t *>(val)), ownerUciLength);
367 instancInfo.ownerUciUtf8 = tempUci;
368 }
369 }
370 }
371 // MASInstanceInformation is a string with the requested user-readable information of the MAS-instance.
372 auto bodyObject = resp.GetExtendBodyObject();
373 uint8_t masInfBuf[MCE_MAX_LENGTH_OF_RESPONSE_BUFFER];
374 size_t masInfBufLen = 1;
375 std::ostringstream masInfStream;
376 while ((masInfBufLen != 0) && (bodyObject != 0)) {
377 masInfBufLen = bodyObject->Read(masInfBuf, MCE_MAX_LENGTH_OF_RESPONSE_BUFFER - 1);
378 if ((masInfBufLen != 0) && (masInfBufLen < MCE_MAX_LENGTH_OF_RESPONSE_BUFFER)) {
379 masInfBuf[masInfBufLen] = 0;
380 masInfStream << (char *)masInfBuf;
381 }
382 }
383 if (masInfStream.str().size() != 0) {
384 instancInfo.masInstanceInfoUtf8 = masInfStream.str();
385 }
386 // Save instance information
387 instancInfo.isValid = true;
388 clientInst.SaveMasInstanceInformation(instancInfo);
389 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
390 return MCE_RESPONSE_FINISH_NO_CALLBACK;
391 }
392
MapMceRequestGetFolderListing(uint16_t listCnt,uint16_t offset)393 MapMceRequestGetFolderListing::MapMceRequestGetFolderListing(uint16_t listCnt, uint16_t offset)
394 {
395 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
396 maxOfListCount_ = listCnt;
397 startOffset_ = offset;
398 }
399
~MapMceRequestGetFolderListing()400 MapMceRequestGetFolderListing::~MapMceRequestGetFolderListing()
401 {
402 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
403 }
404
GetRequestType()405 MceRequestType MapMceRequestGetFolderListing::GetRequestType()
406 {
407 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
408 return MCE_REQUEST_TYPE_GET_FOLDERLISTING;
409 }
410
SendRequest(ObexMpClient & obexIns)411 int MapMceRequestGetFolderListing::SendRequest(ObexMpClient &obexIns)
412 {
413 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
414 int ret;
415
416 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::GET_FINAL);
417
418 // set header
419 // Connection ID
420 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
421 // Type is "x-obex/folder-listing"
422 header->AppendItemType(MCE_HEADER_TYPE_GET_FOLDER_LISTING);
423
424 TlvTriplet paramListCount(MCE_MAX_LIST_COUNT, maxOfListCount_);
425 TlvTriplet paramStartOffset(MCE_LIST_START_OFF_SET, startOffset_);
426 ObexTlvParamters appParams;
427 appParams.AppendTlvtriplet(paramListCount);
428 appParams.AppendTlvtriplet(paramStartOffset);
429 header->AppendItemAppParams(appParams);
430
431 // make writer object
432 std::shared_ptr<ObexBodyObject> writer = std::make_shared<ObexArrayBodyObject>();
433
434 // send request
435 ret = obexIns.Get(*header, writer);
436 if (ret != BT_NO_ERROR) {
437 LOG_ERROR("%{public}s obex Get error,ret=%{public}d ", __PRETTY_FUNCTION__, ret);
438 }
439 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
440 return ret;
441 }
442
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)443 int MapMceRequestGetFolderListing::ProcessResponse(
444 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
445 {
446 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
447 int rescode;
448 int length;
449 retAction.action_ = MapActionType::GET_MAS_INSTANCE_INFO;
450 // get response code
451 rescode = resp.GetFieldCode();
452 if (rescode != uint8_t(ObexRspCode::SUCCESS)) {
453 return MCE_RESPONSE_FINISH_NO_CALLBACK;
454 }
455 // listSize_
456 auto appParam = resp.GetItemAppParams();
457 if (appParam != nullptr) {
458 auto tlvParam = appParam->GetTlvtriplet(MCE_FOLDER_LISTING_SIZE); // OwnerUCI 0X27
459 if (tlvParam != nullptr) {
460 length = tlvParam->GetLen();
461 const uint8_t *val = tlvParam->GetVal();
462 if ((length != 0) && (val != nullptr)) {
463 uint16_t tempVal = *(reinterpret_cast<uint16_t *>(const_cast<uint8_t *>(val)));
464 listSize_ = ((tempVal >> MCE_8BIT) & MCE_16BIT_MASK_LEFT_LOW) |
465 ((tempVal << MCE_8BIT) & MCE_16BIT_MASK_LEFT_HIGH);
466 }
467 }
468 } else {
469 LOG_INFO("%{public}s ItemAppParams nullptr", __PRETTY_FUNCTION__);
470 }
471 // get body
472 auto data = resp.GetExtendBodyObject();
473 uint8_t folderBuf[MCE_MAX_LENGTH_OF_RESPONSE_BUFFER];
474 size_t folderBufLen = 1;
475 std::ostringstream folderStream;
476 while ((folderBufLen != 0) && (data != 0)) {
477 folderBufLen = data->Read(folderBuf, MCE_MAX_LENGTH_OF_RESPONSE_BUFFER - 1);
478 if ((folderBufLen != 0) && (folderBufLen < MCE_MAX_LENGTH_OF_RESPONSE_BUFFER)) {
479 folderBuf[folderBufLen] = 0;
480 folderStream << (char *)folderBuf;
481 }
482 }
483 if (folderStream.str().size() != 0) {
484 folderListingParam_.folderListingStringObject_ = folderStream.str();
485 MceTypesFolderListing folderListing;
486 folderListing.BuildObjectData(folderListingParam_.folderListingStringObject_);
487 folderListingParam_.folderNameList_ = folderListing.GetList();
488 folderListingParam_.version_ = folderListing.GetVersion();
489 }
490 #ifdef MCE_DEBUG_RECEIVE_DATA
491 LOG_INFO("%{public}s folderListing=%{public}s", __PRETTY_FUNCTION__, folderListingParam_.folderListingStringObject_.c_str());
492 #endif
493 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
494 return MCE_RESPONSE_FINISH_NO_CALLBACK;
495 }
496
MapMceRequestSetPath(uint8_t flags,const std::u16string & paths,const std::vector<std::u16string> & pathsList)497 MapMceRequestSetPath::MapMceRequestSetPath(uint8_t flags, const std::u16string &paths,
498 const std::vector<std::u16string> &pathsList)
499 {
500 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
501 pathFlags_ = flags;
502 pathsString_ = paths;
503 pathsList_ = pathsList;
504 }
505
~MapMceRequestSetPath()506 MapMceRequestSetPath::~MapMceRequestSetPath()
507 {
508 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
509 }
510
GetRequestType()511 MceRequestType MapMceRequestSetPath::GetRequestType()
512 {
513 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
514 return MCE_REQUEST_TYPE_SET_PATH;
515 }
516
SendRequest(ObexMpClient & obexIns)517 int MapMceRequestSetPath::SendRequest(ObexMpClient &obexIns)
518 {
519 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
520 int ret;
521
522 if (pathFlags_ == MASSTM_SETPATH_LIST) {
523 // path string list
524 ret = obexIns.SetPath(pathsList_);
525 } else {
526 // normal string path and path up/down
527 ret = obexIns.SetPath(pathFlags_, pathsString_);
528 }
529
530 if (ret != BT_NO_ERROR) {
531 LOG_ERROR("%{public}s obex setpath error", __PRETTY_FUNCTION__);
532 }
533 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
534 return ret;
535 }
536
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)537 int MapMceRequestSetPath::ProcessResponse(
538 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
539 {
540 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
541 return MCE_RESPONSE_FINISH_NO_CALLBACK;
542 }
543
MapMceRequestPushMessage(const IProfileSendMessageParameters & msg)544 MapMceRequestPushMessage::MapMceRequestPushMessage(const IProfileSendMessageParameters &msg)
545 {
546 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
547 messageParam_ = msg;
548 SetSupportMessageType(MapMessageTypeToIprofileMask(messageParam_.bmessage_.type_property));
549 }
550
~MapMceRequestPushMessage()551 MapMceRequestPushMessage::~MapMceRequestPushMessage()
552 {
553 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
554 }
555
GetRequestType()556 MceRequestType MapMceRequestPushMessage::GetRequestType()
557 {
558 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
559 return MCE_REQUEST_TYPE_SEND_MESSAGE;
560 }
561
SendRequest(ObexMpClient & obexIns)562 int MapMceRequestPushMessage::SendRequest(ObexMpClient &obexIns)
563 {
564 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::PUT_FINAL);
565 // set header
566 // set Connection ID
567 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
568 // Type is "x-bt/message"
569 header->AppendItemType(MCE_HEADER_TYPE_MESSAGE);
570 // Name of the Folder
571 header->AppendItemName(messageParam_.bmessage_.folder_property);
572 ObexTlvParamters appParams;
573 if (messageParam_.Transparent != MapOnOffType::INVALID) {
574 TlvTriplet paramTransparent(MCE_TRANSPARENT, uint8_t(messageParam_.Transparent));
575 appParams.AppendTlvtriplet(paramTransparent);
576 }
577 if (messageParam_.Retry != MapOnOffType::INVALID) {
578 TlvTriplet paramRetry(MCE_RETRY, uint8_t(messageParam_.Retry));
579 appParams.AppendTlvtriplet(paramRetry);
580 }
581 TlvTriplet paramCharset(MCE_CHARSET, uint8_t(messageParam_.Charset));
582 appParams.AppendTlvtriplet(paramCharset);
583 if (messageParam_.MessageHandle.size() != 0) {
584 TlvTriplet paramMessageHandle(MCE_MESSAGE_HANDLE,
585 (messageParam_.MessageHandle.size() + 1),
586 (const uint8_t *)messageParam_.MessageHandle.c_str());
587 appParams.AppendTlvtriplet(paramMessageHandle);
588 TlvTriplet paramAttachment(MCE_ATTACHMENT, uint8_t(messageParam_.Attachment));
589 appParams.AppendTlvtriplet(paramAttachment);
590 // This application parameter shall be included if the MessageHandle application parameter is present.
591 TlvTriplet paramModifyText(MCE_MODIFY_TEXT, uint8_t(messageParam_.ModifyText));
592 appParams.AppendTlvtriplet(paramModifyText);
593 }
594 if (messageParam_.ConversationID.size() != 0) {
595 TlvTriplet paramConversationID(MCE_CONVERSATION_ID,
596 messageParam_.ConversationID.size() + 1,
597 (const uint8_t *)messageParam_.ConversationID.c_str());
598 appParams.AppendTlvtriplet(paramConversationID);
599 }
600 header->AppendItemAppParams(appParams);
601 // End body , body is bMessage
602 MceBmessageParamMakeStringObject makeString(messageParam_.bmessage_);
603 std::string msgBody = makeString.GetStringObject();
604 // make writer object
605 std::shared_ptr<ObexBodyObject> read = std::make_shared<ObexArrayBodyObject>();
606 read->Write((const uint8_t *)msgBody.c_str(), msgBody.size());
607 // send request
608 int ret = obexIns.Put(*header, read);
609 LOG_INFO("%{public}s execute end, obex Put ret=%{public}d ", __PRETTY_FUNCTION__, ret);
610 #ifdef MCE_DEBUG_SEND_DATA
611 LOG_INFO("PushMessage,StringObject = %{public}s", msgBody.c_str());
612 #endif
613 return ret;
614 }
615
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)616 int MapMceRequestPushMessage::ProcessResponse(
617 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
618 {
619 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
620 retAction.action_ = MapActionType::SEND_MESSAGE;
621 return MCE_RESPONSE_FINISH;
622 }
623
MapMceRequestGetMessage(const std::u16string & msgHandle,const IProfileGetMessageParameters & para)624 MapMceRequestGetMessage::MapMceRequestGetMessage(
625 const std::u16string &msgHandle, const IProfileGetMessageParameters ¶)
626 {
627 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
628 msgHandle_ = msgHandle;
629 msgPara_ = para;
630 }
631
~MapMceRequestGetMessage()632 MapMceRequestGetMessage::~MapMceRequestGetMessage()
633 {
634 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
635 }
636
GetRequestType()637 MceRequestType MapMceRequestGetMessage::GetRequestType()
638 {
639 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
640 return MCE_REQUEST_TYPE_GET_MESSAGE;
641 }
642
SendRequest(ObexMpClient & obexIns)643 int MapMceRequestGetMessage::SendRequest(ObexMpClient &obexIns)
644 {
645 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
646 int ret;
647 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::GET_FINAL);
648 // set header
649 // Connection ID
650 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
651 // Type is "x-bt/MAP-msg-listing"
652 header->AppendItemType(MCE_HEADER_TYPE_MESSAGE);
653 header->AppendItemName(msgHandle_);
654
655 if (GetRequestConfig().isUseSrmp) {
656 LOG_ERROR("%{public}s warning: srmp only valid in pts test!", __PRETTY_FUNCTION__);
657 header->AppendItemSrmp();
658 }
659
660 // Application Parameters:
661 TlvTriplet paramAttachment(MCE_ATTACHMENT, uint8_t(msgPara_.Attachment));
662 TlvTriplet paramCharset(MCE_CHARSET, uint8_t(msgPara_.Charset));
663 TlvTriplet paramFractionRequest(MCE_FRACTION_REQUEST, uint8_t(msgPara_.FractionRequest));
664 ObexTlvParamters appParams;
665 appParams.AppendTlvtriplet(paramAttachment);
666 appParams.AppendTlvtriplet(paramCharset);
667 appParams.AppendTlvtriplet(paramFractionRequest);
668 header->AppendItemAppParams(appParams);
669 #ifdef MCE_DEBUG_SEND_DATA
670 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
671 std::string utf8Handle = converter.to_bytes(msgHandle_);
672 LOG_INFO("Send GetMessage msgHandle_=%{public}s", utf8Handle.c_str());
673 LOG_INFO("Send GetMessage Attachment=%hhu", msgPara_.Attachment);
674 LOG_INFO("Send GetMessage Charset=%hhu", msgPara_.Charset);
675 LOG_INFO("Send GetMessage FractionRequest=%hhu", msgPara_.FractionRequest);
676 #endif
677 // make writer object
678 std::shared_ptr<ObexBodyObject> writer = std::make_shared<ObexArrayBodyObject>();
679 // send request
680 if (GetRequestConfig().isUseSrmp) {
681 LOG_ERROR("%{public}s warning: srmp only valid in pts test!", __PRETTY_FUNCTION__);
682 ret = obexIns.Get(*header, writer, GetRequestConfig().srmpCount);
683 } else {
684 ret = obexIns.Get(*header, writer);
685 }
686 if (ret != BT_NO_ERROR) {
687 LOG_ERROR("%{public}s obex put error", __PRETTY_FUNCTION__);
688 }
689 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
690 return ret;
691 }
692
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)693 int MapMceRequestGetMessage::ProcessResponse(
694 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
695 {
696 retAction.action_ = MapActionType::GET_MESSAGE;
697 MceTypesBMessage *bmessageData = &retAction.bmessage_;
698 if (resp.GetFieldCode() != uint8_t(ObexRspCode::SUCCESS)) {
699 return MCE_RESPONSE_FINISH;
700 }
701 auto appParam = resp.GetItemAppParams();
702 if (appParam != nullptr) {
703 auto tlvParam1 = appParam->GetTlvtriplet(MCE_FRACTION_DELIVER);
704 if (tlvParam1 != nullptr) {
705 int length = tlvParam1->GetLen();
706 const uint8_t *val1 = tlvParam1->GetVal();
707 uint8_t deliveryType = int(MapFractionDeliverType::INVALID);
708 if ((length != 0) && (val1 != nullptr)) {
709 deliveryType = *val1;
710 }
711 if (deliveryType == 0) {
712 bmessageData->SetFractionDeliver(MapFractionDeliverType::MORE);
713 } else if (deliveryType == 1) {
714 bmessageData->SetFractionDeliver(MapFractionDeliverType::LAST);
715 } else {
716 bmessageData->SetFractionDeliver(MapFractionDeliverType::INVALID);
717 }
718 }
719 }
720 auto msgObject = resp.GetExtendBodyObject();
721 uint8_t msgBuf[MCE_MAX_LENGTH_OF_RESPONSE_BUFFER];
722 size_t bufLen = 1;
723 stream_.clear();
724 while ((bufLen != 0) && (msgObject != 0)) {
725 bufLen = msgObject->Read(msgBuf, MCE_MAX_LENGTH_OF_RESPONSE_BUFFER - 1);
726 if ((bufLen != 0) && (bufLen < MCE_MAX_LENGTH_OF_RESPONSE_BUFFER)) {
727 msgBuf[bufLen] = 0;
728 stream_ << (char *)msgBuf;
729 }
730 }
731 if (stream_.str().size() != 0) {
732 bmessageData->BuildObjectData(stream_.str());
733 }
734 #ifdef MCE_DEBUG_RECEIVE_DATA
735 LOG_INFO("GetMessage msgObject=%{public}s", bmessageData->GetBmessageObject().c_str());
736 #endif
737 if (bmessageData->GetBMessageData().type_property != IprofileMaskToMapMessageType(GetSupportMessageType())) {
738 return MCE_RESPONSE_FINISH_NG;
739 } else {
740 return MCE_RESPONSE_FINISH;
741 }
742 }
743
MapMceRequestGetUreadMessages(MapMessageType type,const IProfileGetMessagesListingParameters & para)744 MapMceRequestGetUreadMessages::MapMceRequestGetUreadMessages(
745 MapMessageType type, const IProfileGetMessagesListingParameters ¶)
746 {
747 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
748 requestPtr_ = nullptr;
749 obexInsBackup_ = nullptr;
750 msgHandleList_.clear();
751 listParam_ = para;
752 listParam_.FilterMessageType = MapMessageTypeToFrameworkMask(type);
753 SetSupportMessageType(MapMessageTypeToIprofileMask(type));
754 }
755
~MapMceRequestGetUreadMessages()756 MapMceRequestGetUreadMessages::~MapMceRequestGetUreadMessages()
757 {
758 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
759 }
760
GetRequestType()761 MceRequestType MapMceRequestGetUreadMessages::GetRequestType()
762 {
763 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
764 return MCE_REQUEST_TYPE_GET_UNREAD_MESSAGES;
765 }
766
SendRequest(ObexMpClient & obexIns)767 int MapMceRequestGetUreadMessages::SendRequest(ObexMpClient &obexIns)
768 {
769 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
770 int ret;
771 MapMceRequestConfig cfg = GetRequestConfig();
772
773 obexInsBackup_ = &obexIns;
774 if (listParam_.MaxListCount > cfg.maxOfGetUnread) {
775 listParam_.MaxListCount = cfg.maxOfGetUnread;
776 }
777 requestPtr_ = std::make_unique<MapMceRequestGetMessagesListing>(listParam_);
778 ret = requestPtr_->SendRequest(obexIns);
779 return ret;
780 }
781
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)782 int MapMceRequestGetUreadMessages::ProcessResponse(
783 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
784 {
785 int ret = MCE_RESPONSE_FINISH_NG;
786 retAction.action_ = MapActionType::GET_UNREAD_MESSAGES;
787 if (requestPtr_ == nullptr) {
788 return ret;
789 }
790 LOG_INFO("%{public}s request type = %{public}d", __PRETTY_FUNCTION__, requestPtr_->GetRequestType());
791 if (requestPtr_->GetRequestType() == MCE_REQUEST_TYPE_GET_MESSAGELISTING) {
792 MapRequestResponseAction ureadAction;
793 requestPtr_->ProcessResponse(clientInst, resp, ureadAction);
794 auto msgOutlineList = ureadAction.messageList_.GetList();
795 for (auto it = msgOutlineList.begin(); it != msgOutlineList.end(); it++) {
796 IProfileMessageOutline msgOutline = *it;
797 if (msgOutline.handle != "") {
798 msgHandleList_.push_back(msgOutline.handle);
799 ret = MCE_RESPONSE_CONTINUE_NO_CALLBACK;
800 }
801 }
802 } else if (requestPtr_->GetRequestType() == MCE_REQUEST_TYPE_GET_MESSAGE) {
803 requestPtr_->ProcessResponse(clientInst, resp, retAction);
804 ret = MCE_RESPONSE_CONTINUE_WITH_CALLBACK;
805 if (msgHandleList_.size() == 0) {
806 ret = MCE_RESPONSE_FINISH; // normal finish
807 }
808 }
809 if (msgHandleList_.size() != 0) {
810 std::string tempStr = msgHandleList_.front();
811 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
812 std::u16string msgHandle = converter.from_bytes(tempStr);
813 msgHandleList_.pop_front();
814 IProfileGetMessageParameters para;
815 para.Attachment = MapAttachmentType::NO; // no Attachment
816 para.Charset = MapCharsetType::UTF_8; // 0 is "native" , 1 is "UTF-8"
817 para.FractionRequest = MapFractionRequestType::FIRST; // 0 is "first" , 1 is "next"
818 requestPtr_ = std::make_unique<MapMceRequestGetMessage>(msgHandle, para);
819 requestPtr_->SetSupportMessageType(GetSupportMessageType());
820 int sendRet = requestPtr_->SendRequest(*obexInsBackup_);
821 if (sendRet != RET_NO_ERROR) {
822 msgHandleList_.clear();
823 ret = MCE_RESPONSE_FINISH_NG;
824 }
825 }
826 return ret;
827 }
828
MapMceRequestUpdateInbox()829 MapMceRequestUpdateInbox::MapMceRequestUpdateInbox()
830 {
831 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
832 }
833
~MapMceRequestUpdateInbox()834 MapMceRequestUpdateInbox::~MapMceRequestUpdateInbox()
835 {
836 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
837 }
838
GetRequestType()839 MceRequestType MapMceRequestUpdateInbox::GetRequestType()
840 {
841 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
842 return MCE_REQUEST_TYPE_UPDATE_INBOX;
843 }
844
SendRequest(ObexMpClient & obexIns)845 int MapMceRequestUpdateInbox::SendRequest(ObexMpClient &obexIns)
846 {
847 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
848 int ret;
849 uint8_t emptyBody = 0x30;
850
851 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::PUT_FINAL);
852
853 // set header
854 // set Connection ID
855 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
856 // Type is “x-bt/MAP-messageUpdate”
857 header->AppendItemType(MCE_HEADER_TYPE_MESSAGE_UPDATE);
858 // End body
859 header->AppendItemEndBody(&emptyBody, 1);
860 // send request
861 ret = obexIns.Put(*header);
862 if (ret != BT_NO_ERROR) {
863 LOG_ERROR("%{public}s obex Put error,ret=%{public}d ", __PRETTY_FUNCTION__, ret);
864 }
865 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
866 return ret;
867 }
868
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)869 int MapMceRequestUpdateInbox::ProcessResponse(
870 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
871 {
872 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
873 retAction.action_ = MapActionType::UPDATE_INBOX;
874 return MCE_RESPONSE_FINISH;
875 }
876
MapMceRequestSetOwnerStatus(const IProfileSetOwnerStatusParameters & para)877 MapMceRequestSetOwnerStatus::MapMceRequestSetOwnerStatus(const IProfileSetOwnerStatusParameters ¶)
878 {
879 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
880 ownerPara_ = para;
881 }
882
~MapMceRequestSetOwnerStatus()883 MapMceRequestSetOwnerStatus::~MapMceRequestSetOwnerStatus()
884 {
885 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
886 }
887
GetRequestType()888 MceRequestType MapMceRequestSetOwnerStatus::GetRequestType()
889 {
890 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
891 return MCE_REQUEST_TYPE_SET_OWNER_STATUS;
892 }
893
SendRequest(ObexMpClient & obexIns)894 int MapMceRequestSetOwnerStatus::SendRequest(ObexMpClient &obexIns)
895 {
896 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
897 int ret;
898
899 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::PUT_FINAL);
900
901 // set header
902 // set Connection ID
903 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
904 // Type is "x-bt/ownerStatus"
905 header->AppendItemType(MCE_HEADER_TYPE_SET_OWNER_STATUS);
906
907 // Application Parameters:
908 ObexTlvParamters appParams;
909
910 TlvTriplet paramApplication(MCE_PRESENCE_AVAILABILITY, ownerPara_.ownerStatus_.PresenceAvailability);
911 if (ownerPara_.ownerStatus_.PresenceText != "") {
912 TlvTriplet paramPresenceText(MCE_PRESENCE_TEXT,
913 ownerPara_.ownerStatus_.PresenceText.size() + 1,
914 (const uint8_t *)ownerPara_.ownerStatus_.PresenceText.c_str());
915 appParams.AppendTlvtriplet(paramPresenceText);
916 }
917 if (ownerPara_.ownerStatus_.LastActivity != "") {
918 TlvTriplet paramLastActivity(MCE_LAST_ACTIVITY,
919 ownerPara_.ownerStatus_.LastActivity.size() + 1,
920 (const uint8_t *)ownerPara_.ownerStatus_.LastActivity.c_str());
921 appParams.AppendTlvtriplet(paramLastActivity);
922 }
923 if (ownerPara_.ConversationID != "") {
924 TlvTriplet paramConversationID(MCE_CONVERSATION_ID,
925 ownerPara_.ConversationID.size() + 1,
926 (const uint8_t *)ownerPara_.ConversationID.c_str());
927 appParams.AppendTlvtriplet(paramConversationID);
928 }
929 TlvTriplet paramChatState(MCE_CHAT_STATE, ownerPara_.ownerStatus_.ChatState);
930
931 appParams.AppendTlvtriplet(paramApplication);
932 appParams.AppendTlvtriplet(paramChatState);
933 header->AppendItemAppParams(appParams);
934
935 // End body
936 uint8_t emptyBody = 0x30;
937 header->AppendItemEndBody(&emptyBody, 1);
938
939 // send request
940 ret = obexIns.Put(*header);
941 if (ret != BT_NO_ERROR) {
942 LOG_ERROR("%{public}s obex Put error,ret=%{public}d ", __PRETTY_FUNCTION__, ret);
943 }
944 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
945 return ret;
946 }
947
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)948 int MapMceRequestSetOwnerStatus::ProcessResponse(
949 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
950 {
951 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
952 retAction.action_ = MapActionType::SET_OWNER_STATUS;
953 return MCE_RESPONSE_FINISH;
954 }
955
MapMceRequestGetOwnerStatus(const std::string & conversationId)956 MapMceRequestGetOwnerStatus::MapMceRequestGetOwnerStatus(const std::string &conversationId)
957 {
958 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
959 ownerConversationId_ = conversationId;
960 }
961
~MapMceRequestGetOwnerStatus()962 MapMceRequestGetOwnerStatus::~MapMceRequestGetOwnerStatus()
963 {
964 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
965 }
966
GetRequestType()967 MceRequestType MapMceRequestGetOwnerStatus::GetRequestType()
968 {
969 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
970 return MCE_REQUEST_TYPE_GET_OWNER_STATUS;
971 }
972
SendRequest(ObexMpClient & obexIns)973 int MapMceRequestGetOwnerStatus::SendRequest(ObexMpClient &obexIns)
974 {
975 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
976 int ret;
977
978 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::GET_FINAL);
979
980 // set header
981 // set Connection ID
982 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
983 // Type is "x-bt/ownerStatus", the string is same as set owner status
984 header->AppendItemType(MCE_HEADER_TYPE_SET_OWNER_STATUS);
985
986 // Application Parameters:
987 if (ownerConversationId_.size() != 0) {
988 TlvTriplet paramConversationID(
989 MCE_CONVERSATION_ID, ownerConversationId_.size(), (const uint8_t *)ownerConversationId_.c_str());
990 ObexTlvParamters appParams;
991 appParams.AppendTlvtriplet(paramConversationID);
992 header->AppendItemAppParams(appParams);
993 }
994
995 // send request
996 ret = obexIns.Get(*header);
997 if (ret != BT_NO_ERROR) {
998 LOG_ERROR("%{public}s obex Put error,ret=%{public}d ", __PRETTY_FUNCTION__, ret);
999 }
1000 LOG_INFO("%{public}s end, ownerConversationId_ = %{public}s", __PRETTY_FUNCTION__, ownerConversationId_.c_str());
1001 return ret;
1002 }
1003
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)1004 int MapMceRequestGetOwnerStatus::ProcessResponse(
1005 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
1006 {
1007 retAction.action_ = MapActionType::GET_OWNER_STATUS;
1008 // get response code
1009 int rescode = resp.GetFieldCode();
1010 if (rescode != uint8_t(ObexRspCode::SUCCESS)) {
1011 return MCE_RESPONSE_FINISH;
1012 }
1013 auto appParam = resp.GetItemAppParams();
1014 if (appParam != nullptr) {
1015 auto tlvParam1 = appParam->GetTlvtriplet(MCE_PRESENCE_AVAILABILITY);
1016 if (tlvParam1 != nullptr) {
1017 int length1 = tlvParam1->GetLen();
1018 const uint8_t *val1 = tlvParam1->GetVal();
1019 if ((length1 != 0) && (val1 != nullptr)) {
1020 retAction.ownerStatus_.PresenceAvailability = *val1;
1021 }
1022 }
1023 auto tlvParam2 = appParam->GetTlvtriplet(MCE_PRESENCE_TEXT);
1024 if (tlvParam2 != nullptr) {
1025 int length2 = tlvParam2->GetLen();
1026 const uint8_t *val2 = tlvParam2->GetVal();
1027 if ((length2 != 0) && (val2 != nullptr)) {
1028 std::string tempPresence(reinterpret_cast<char *>(const_cast<uint8_t *>(val2)), length2);
1029 retAction.ownerStatus_.PresenceText = tempPresence;
1030 }
1031 }
1032 auto tlvParam3 = appParam->GetTlvtriplet(MCE_LAST_ACTIVITY);
1033 if (tlvParam3 != nullptr) {
1034 int length3 = tlvParam3->GetLen();
1035 const uint8_t *val3 = tlvParam3->GetVal();
1036 if ((length3 != 0) && (val3 != nullptr)) {
1037 std::string tempLastAct(reinterpret_cast<char *>(const_cast<uint8_t *>(val3)), length3);
1038 retAction.ownerStatus_.LastActivity = tempLastAct;
1039 }
1040 }
1041 auto tlvParam4 = appParam->GetTlvtriplet(MCE_CHAT_STATE);
1042 if (tlvParam4 != nullptr) {
1043 int length4 = tlvParam4->GetLen();
1044 const uint8_t *val4 = tlvParam4->GetVal();
1045 if ((length4 != 0) && (val4 != nullptr)) {
1046 retAction.ownerStatus_.ChatState = *val4;
1047 }
1048 }
1049 }
1050 return MCE_RESPONSE_FINISH;
1051 }
1052
MapMceRequestSetMessageStatus(const std::u16string & msgHandle,MapStatusIndicatorType statusIndicator,MapStatusValueType statusValue,const std::string & exData)1053 MapMceRequestSetMessageStatus::MapMceRequestSetMessageStatus(const std::u16string &msgHandle,
1054 MapStatusIndicatorType statusIndicator, MapStatusValueType statusValue, const std::string &exData)
1055 {
1056 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1057 msgHandle_ = msgHandle;
1058 msgStatusIndicator_ = uint8_t(statusIndicator);
1059 msgstatusValue_ = uint8_t(statusValue);
1060 extendedData_ = exData;
1061 }
1062
~MapMceRequestSetMessageStatus()1063 MapMceRequestSetMessageStatus::~MapMceRequestSetMessageStatus()
1064 {
1065 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1066 }
1067
GetRequestType()1068 MceRequestType MapMceRequestSetMessageStatus::GetRequestType()
1069 {
1070 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1071 return MCE_REQUEST_TYPE_SET_MESSAGE_STATUS;
1072 }
1073
SendRequest(ObexMpClient & obexIns)1074 int MapMceRequestSetMessageStatus::SendRequest(ObexMpClient &obexIns)
1075 {
1076 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
1077 int ret;
1078
1079 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::PUT_FINAL);
1080
1081 // set header
1082 // set Connection ID
1083 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
1084 // Message Handle
1085 header->AppendItemName(msgHandle_);
1086 // Type is "x-bt/messageStatus"
1087 header->AppendItemType(MCE_HEADER_TYPE_SET_MESSAGE_STATUS);
1088
1089 // Application Parameters:
1090 TlvTriplet paramStatusIndicator(MCE_STATUS_INDICATOR, msgStatusIndicator_);
1091 TlvTriplet paramStatusValue(MCE_STATUS_VALUE, msgstatusValue_);
1092
1093 ObexTlvParamters appParams;
1094 appParams.AppendTlvtriplet(paramStatusIndicator);
1095 appParams.AppendTlvtriplet(paramStatusValue);
1096
1097 // extendedData_ is optional
1098 if (extendedData_ != "") {
1099 TlvTriplet extendedDataParam(
1100 MCE_EXTENDED_DATA, extendedData_.size() + 1, (const uint8_t *)extendedData_.c_str());
1101 appParams.AppendTlvtriplet(extendedDataParam);
1102 }
1103 header->AppendItemAppParams(appParams);
1104 // End body
1105 uint8_t emptyBody = 0x30;
1106 header->AppendItemEndBody(&emptyBody, 1);
1107
1108 // send request
1109 ret = obexIns.Put(*header);
1110 if (ret != BT_NO_ERROR) {
1111 LOG_ERROR("%{public}s obex Put error,ret=%{public}d ", __PRETTY_FUNCTION__, ret);
1112 }
1113 return ret;
1114 }
1115
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)1116 int MapMceRequestSetMessageStatus::ProcessResponse(
1117 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
1118 {
1119 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1120 retAction.action_ = MapActionType::SET_MESSAGE_STATUS;
1121 return MCE_RESPONSE_FINISH;
1122 }
1123
MapMceRequestGetConversationListing(const IProfileGetConversationListingParameters & para)1124 MapMceRequestGetConversationListing::MapMceRequestGetConversationListing(
1125 const IProfileGetConversationListingParameters ¶)
1126
1127 {
1128 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1129 converPara_ = para;
1130 }
1131
~MapMceRequestGetConversationListing()1132 MapMceRequestGetConversationListing::~MapMceRequestGetConversationListing()
1133 {
1134 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1135 }
1136
GetRequestType()1137 MceRequestType MapMceRequestGetConversationListing::GetRequestType()
1138 {
1139 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1140 return MCE_REQUEST_TYPE_GET_CONVERSATION_LISTING;
1141 }
1142
SetAppendParam(ObexTlvParamters & appParams)1143 void MapMceRequestGetConversationListing::SetAppendParam(ObexTlvParamters &appParams)
1144 {
1145 TlvTriplet paramMaxListCount(MCE_MAX_LIST_COUNT, converPara_.MaxListCount);
1146 appParams.AppendTlvtriplet(paramMaxListCount);
1147
1148 TlvTriplet paramListStartOffset(MCE_LIST_START_OFF_SET, converPara_.ListStartOffset);
1149 appParams.AppendTlvtriplet(paramListStartOffset);
1150
1151 if (converPara_.FilterLastActivityBegin.size() != 0) {
1152 TlvTriplet paramFilterBegin(MCE_FILTER_LAST_ACTIVITY_BEGIN,
1153 converPara_.FilterLastActivityBegin.size() + 1,
1154 (const uint8_t *)converPara_.FilterLastActivityBegin.c_str());
1155 appParams.AppendTlvtriplet(paramFilterBegin);
1156 }
1157
1158 if (converPara_.FilterLastActivityEnd.size() != 0) {
1159 TlvTriplet paramFilterEnd(MCE_FILTER_LAST_ACTIVITY_END,
1160 converPara_.FilterLastActivityEnd.size() + 1,
1161 (const uint8_t *)converPara_.FilterLastActivityEnd.c_str());
1162 appParams.AppendTlvtriplet(paramFilterEnd);
1163 }
1164
1165 TlvTriplet paramFilterRead(MCE_FILTER_READ_STATUS, converPara_.FilterReadStatus);
1166 appParams.AppendTlvtriplet(paramFilterRead);
1167
1168 if (converPara_.FilterRecipient.size()) {
1169 TlvTriplet paramFilterRecipient(MCE_FILTER_RECIPIENT,
1170 converPara_.FilterRecipient.size(),
1171 (const uint8_t *)converPara_.FilterRecipient.c_str());
1172 appParams.AppendTlvtriplet(paramFilterRecipient);
1173 }
1174
1175 if (converPara_.ConversationID.size()) {
1176 TlvTriplet paramConversationID(MCE_CONVERSATION_ID,
1177 converPara_.ConversationID.size(),
1178 (const uint8_t *)converPara_.ConversationID.c_str());
1179 appParams.AppendTlvtriplet(paramConversationID);
1180 }
1181
1182 TlvTriplet paramConvMask(MCE_CONV_PARAMETER_MASK, converPara_.ConvParameterMask);
1183 appParams.AppendTlvtriplet(paramConvMask);
1184 }
1185
SendRequest(ObexMpClient & obexIns)1186 int MapMceRequestGetConversationListing::SendRequest(ObexMpClient &obexIns)
1187 {
1188 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
1189 int ret;
1190
1191 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::GET_FINAL);
1192
1193 // set header
1194 // set Connection ID
1195 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
1196 // type is "x-bt/MAP-convo-listing"
1197 header->AppendItemType(MCE_HEADER_TYPE_GET_CONVO_LISTING);
1198
1199 // Application Parameters:
1200 ObexTlvParamters appParams;
1201 SetAppendParam(appParams);
1202
1203 header->AppendItemAppParams(appParams);
1204
1205 // make writer object
1206 std::shared_ptr<ObexBodyObject> writer = std::make_shared<ObexArrayBodyObject>();
1207
1208 // send request
1209 ret = obexIns.Get(*header, writer);
1210 if (ret != BT_NO_ERROR) {
1211 LOG_ERROR("%{public}s obex Put error,ret=%{public}d ", __PRETTY_FUNCTION__, ret);
1212 }
1213 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
1214 return ret;
1215 }
1216
MapMceGetItemAppParams(IProfileConversationListingParamStruct & data,const ObexHeader & resp)1217 void MapMceRequestGetConversationListing::MapMceGetItemAppParams(
1218 IProfileConversationListingParamStruct &data, const ObexHeader &resp)
1219 {
1220 auto appParam = resp.GetItemAppParams();
1221 if (appParam != nullptr) {
1222 auto convListVerCnt =
1223 appParam->GetTlvtriplet(MCE_CONVERSATION_LISTING_VERSION_COUNTER); // 128-bit value in hex string format
1224 if (convListVerCnt != nullptr) {
1225 int convLenth = convListVerCnt->GetLen();
1226 const uint8_t *val1 = convListVerCnt->GetVal();
1227 if ((convLenth != 0) && (val1 != nullptr)) {
1228 std::string tempCounter(reinterpret_cast<char *>(const_cast<uint8_t *>(val1)), convLenth);
1229 data.ConversationListingVersionCounter = tempCounter;
1230 }
1231 }
1232 auto convMseTim = appParam->GetTlvtriplet(MCE_MSE_TIME);
1233 if (convMseTim != nullptr) {
1234 int convMseLen = convMseTim->GetLen();
1235 const uint8_t *val2 = convMseTim->GetVal();
1236 if ((convMseLen != 0) && (val2 != nullptr)) {
1237 std::string tempTime(reinterpret_cast<char *>(const_cast<uint8_t *>(val2)), convMseLen);
1238 data.MseTime = tempTime;
1239 }
1240 }
1241 auto convListSize = appParam->GetTlvtriplet(MCE_LISTING_SIZE);
1242 if (convListSize != nullptr) {
1243 int convListLength = convListSize->GetLen();
1244 const uint8_t *val3 = convListSize->GetVal();
1245 if ((convListLength != 0) && (val3 != nullptr)) {
1246 uint16_t tempVal = *(reinterpret_cast<uint16_t *>(const_cast<uint8_t *>(val3)));
1247 data.ListingSize = ((tempVal >> MCE_8BIT) & MCE_16BIT_MASK_LEFT_LOW) |
1248 ((tempVal << MCE_8BIT) & MCE_16BIT_MASK_LEFT_HIGH);
1249 }
1250 }
1251 auto convDbId = appParam->GetTlvtriplet(MCE_DATABASE_IDENTIFIER);
1252 if (convDbId != nullptr) {
1253 int convDbIdLenth = convDbId->GetLen();
1254 const uint8_t *val4 = convDbId->GetVal();
1255 if ((convDbIdLenth != 0) && (val4 != nullptr)) {
1256 std::string tempDatabase(reinterpret_cast<char *>(const_cast<uint8_t *>(val4)), convDbIdLenth);
1257 data.DatabaseIdentifier = tempDatabase;
1258 }
1259 }
1260 }
1261 }
1262
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)1263 int MapMceRequestGetConversationListing::ProcessResponse(
1264 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
1265 {
1266 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1267 retAction.action_ = MapActionType::GET_CONVERSATION_LISTING;
1268 IProfileConversationListingParamStruct paramData;
1269 int rescode;
1270
1271 // get response code
1272 rescode = resp.GetFieldCode();
1273 if (rescode == uint8_t(ObexRspCode::SUCCESS)) {
1274 MapMceGetItemAppParams(paramData, resp);
1275 // get body
1276 auto convObject = resp.GetExtendBodyObject();
1277 uint8_t convBuf[MCE_MAX_LENGTH_OF_RESPONSE_BUFFER];
1278 size_t bufLen = 1;
1279 std::ostringstream convStream;
1280 while ((bufLen != 0) && (convObject != 0)) {
1281 bufLen = convObject->Read(convBuf, MCE_MAX_LENGTH_OF_RESPONSE_BUFFER - 1);
1282 if ((bufLen != 0) && (bufLen < MCE_MAX_LENGTH_OF_RESPONSE_BUFFER)) {
1283 convBuf[bufLen] = 0;
1284 convStream << (char *)convBuf;
1285 }
1286 }
1287 if (convStream.str().size() != 0) {
1288 retAction.conversationList_.BuildObjectData(paramData, convStream.str());
1289 }
1290 #ifdef MCE_DEBUG_RECEIVE_DATA
1291 LOG_INFO("GetConversationListing list size=%{public}d, strlength=%{public}d, convStream size=%{public}d",
1292 int(retAction.conversationList_.GetList().size()),
1293 int(retAction.conversationList_.GetStringObject().size()),
1294 int(convStream.str().size()));
1295 LOG_INFO("GetConversationListing stringObject=%{public}s", retAction.conversationList_.GetStringObject().c_str());
1296 #endif
1297 }
1298 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
1299 return MCE_RESPONSE_FINISH;
1300 }
1301
MapMceRequestGetMessagesListing(const IProfileGetMessagesListingParameters & para)1302 MapMceRequestGetMessagesListing::MapMceRequestGetMessagesListing(const IProfileGetMessagesListingParameters ¶)
1303
1304 {
1305 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1306 int messagType = MAP_MCE_SUPPORTED_MESSAGE_TYPE_ALL;
1307 msgPara_ = para;
1308
1309 if ((msgPara_.FilterMessageType & MAP_FILTER_MESSAGE_MASK_SMS_GSM) != 0) { // filter out gsm
1310 messagType &= ~MAP_MCE_SUPPORTED_MESSAGE_TYPE_SMS_GSM;
1311 }
1312 if ((msgPara_.FilterMessageType & MAP_FILTER_MESSAGE_MASK_SMS_CDMA) != 0) { // filter out cdma
1313 messagType &= ~MAP_MCE_SUPPORTED_MESSAGE_TYPE_SMS_CDMA;
1314 }
1315 if ((msgPara_.FilterMessageType & MAP_FILTER_MESSAGE_MASK_EMAIL) != 0) { // filter out email
1316 messagType &= ~MAP_MCE_SUPPORTED_MESSAGE_TYPE_EMAIL;
1317 }
1318 if ((msgPara_.FilterMessageType & MAP_FILTER_MESSAGE_MASK_MMS) != 0) { // filter out mms
1319 messagType &= ~MAP_MCE_SUPPORTED_MESSAGE_TYPE_MMS;
1320 }
1321 if ((msgPara_.FilterMessageType & MAP_FILTER_MESSAGE_MASK_IM) != 0) { // filter out im
1322 messagType &= ~MAP_MCE_SUPPORTED_MESSAGE_TYPE_IM;
1323 }
1324 SetSupportMessageType(messagType);
1325 }
1326
~MapMceRequestGetMessagesListing()1327 MapMceRequestGetMessagesListing::~MapMceRequestGetMessagesListing()
1328 {
1329 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1330 }
1331
GetRequestType()1332 MceRequestType MapMceRequestGetMessagesListing::GetRequestType()
1333 {
1334 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1335 return MCE_REQUEST_TYPE_GET_MESSAGELISTING;
1336 }
1337
SendRequestSetAppParamsStep1(ObexTlvParamters & appParams)1338 void MapMceRequestGetMessagesListing::SendRequestSetAppParamsStep1(ObexTlvParamters &appParams)
1339 {
1340 TlvTriplet paramListCount(MCE_MAX_LIST_COUNT, msgPara_.MaxListCount);
1341 appParams.AppendTlvtriplet(paramListCount);
1342
1343 TlvTriplet paramStartOffset(MCE_LIST_START_OFF_SET, msgPara_.ListStartOffset);
1344 appParams.AppendTlvtriplet(paramStartOffset);
1345
1346 TlvTriplet paramSubjectLength(MCE_SUBJECT_LENGTH, msgPara_.SubjectLength);
1347 appParams.AppendTlvtriplet(paramSubjectLength);
1348
1349 TlvTriplet paramParameterMask(MCE_PARAMETER_MASK, msgPara_.ParameterMask);
1350 appParams.AppendTlvtriplet(paramParameterMask);
1351
1352 TlvTriplet paramFilMsgType(MCE_FILTER_MESSAGE_TYPE, msgPara_.FilterMessageType);
1353 appParams.AppendTlvtriplet(paramFilMsgType);
1354
1355 TlvTriplet paramFilterPriority(MCE_FILTER_PRIORITY, msgPara_.FilterPriority);
1356 appParams.AppendTlvtriplet(paramFilterPriority);
1357
1358 TlvTriplet paramFilterRead(MCE_FILTER_READ_STATUS, msgPara_.FilterReadStatus);
1359 appParams.AppendTlvtriplet(paramFilterRead);
1360 }
1361
SendRequestSetAppParamsStep2(ObexTlvParamters & appParams)1362 void MapMceRequestGetMessagesListing::SendRequestSetAppParamsStep2(ObexTlvParamters &appParams)
1363 {
1364 if (msgPara_.FilterPeriodBegin.size() != 0) {
1365 TlvTriplet paramFilBegin(MCE_FILTER_PERIOD_BEGIN,
1366 msgPara_.FilterPeriodBegin.size() + 1,
1367 (const uint8_t *)msgPara_.FilterPeriodBegin.c_str());
1368 appParams.AppendTlvtriplet(paramFilBegin);
1369 }
1370 if (msgPara_.FilterPeriodEnd.size() != 0) {
1371 TlvTriplet paramFilEnd(MCE_FILTER_PERIOD_END,
1372 msgPara_.FilterPeriodEnd.size() + 1,
1373 (const uint8_t *)msgPara_.FilterPeriodEnd.c_str());
1374 appParams.AppendTlvtriplet(paramFilEnd);
1375 }
1376 if (msgPara_.FilterRecipient.size() != 0) {
1377 TlvTriplet paramFilterRecipient(MCE_FILTER_RECIPIENT,
1378 msgPara_.FilterRecipient.size() + 1,
1379 (const uint8_t *)msgPara_.FilterRecipient.c_str());
1380 appParams.AppendTlvtriplet(paramFilterRecipient);
1381 }
1382 if (msgPara_.FilterOriginator.size() != 0) {
1383 TlvTriplet paramOriginat(MCE_FILTER_ORIGINATOR,
1384 msgPara_.FilterOriginator.size() + 1,
1385 (const uint8_t *)msgPara_.FilterOriginator.c_str());
1386 appParams.AppendTlvtriplet(paramOriginat);
1387 }
1388 if (msgPara_.ConversationID.size() != 0) {
1389 TlvTriplet paramConversationID(
1390 MCE_CONVERSATION_ID, msgPara_.ConversationID.size() + 1, (const uint8_t *)msgPara_.ConversationID.c_str());
1391 appParams.AppendTlvtriplet(paramConversationID);
1392 }
1393 if (msgPara_.FilterMessageHandle.size() != 0) {
1394 TlvTriplet paramMsgHandle(MCE_FILTER_MESSAGE_HANDLE,
1395 msgPara_.FilterMessageHandle.size() + 1,
1396 (const uint8_t *)msgPara_.FilterMessageHandle.c_str());
1397 appParams.AppendTlvtriplet(paramMsgHandle);
1398 }
1399 }
1400
SendRequest(ObexMpClient & obexIns)1401 int MapMceRequestGetMessagesListing::SendRequest(ObexMpClient &obexIns)
1402 {
1403 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
1404 int ret;
1405
1406 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::GET_FINAL);
1407
1408 // set header
1409 // Connection ID
1410 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
1411 // Type is "x-bt/MAP-msg-listing"
1412 header->AppendItemType(MCE_HEADER_TYPE_GET_MESSAGE_LISTING);
1413 // folder name
1414 header->AppendItemName(msgPara_.folder);
1415 // Application Parameters:
1416 ObexTlvParamters appParams;
1417
1418 SendRequestSetAppParamsStep1(appParams);
1419 SendRequestSetAppParamsStep2(appParams);
1420
1421 header->AppendItemAppParams(appParams);
1422
1423 #ifdef MCE_DEBUG_SEND_DATA
1424 LOG_INFO("Send "
1425 "GetMessagesListing:MaxListCount=0x%x,ListStartOffset=0x%x,ParameterMask=0x%x,FilterMessageType=0x%x,"
1426 "FilterReadStatus=0x%x",
1427 msgPara_.MaxListCount,
1428 msgPara_.ListStartOffset,
1429 msgPara_.ParameterMask,
1430 msgPara_.FilterMessageType,
1431 msgPara_.FilterReadStatus);
1432 #endif
1433
1434 // make writer object
1435 std::shared_ptr<ObexBodyObject> writer = std::make_shared<ObexArrayBodyObject>();
1436
1437 // send request
1438 ret = obexIns.Get(*header, writer);
1439 if (ret != BT_NO_ERROR) {
1440 LOG_ERROR("%{public}s obex put error", __PRETTY_FUNCTION__);
1441 }
1442 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
1443 return ret;
1444 }
1445
MapMceGetItemAppParams(IProfileMessagesListingParamStruct & data,const ObexHeader & resp)1446 void MapMceRequestGetMessagesListing::MapMceGetItemAppParams(
1447 IProfileMessagesListingParamStruct &data, const ObexHeader &resp)
1448 {
1449 auto appParam = resp.GetItemAppParams();
1450 if (appParam != nullptr) {
1451 auto tlvParam1 = appParam->GetTlvtriplet(MCE_NEW_MESSAGE);
1452 if (tlvParam1 != nullptr) {
1453 int length1 = tlvParam1->GetLen();
1454 const uint8_t *val1 = tlvParam1->GetVal();
1455 if ((length1 != 0) && (val1 != nullptr)) {
1456 data.NewMessage = MapOnOffType(*val1);
1457 }
1458 }
1459 auto msgListTime = appParam->GetTlvtriplet(MCE_MSE_TIME);
1460 if (msgListTime != nullptr) {
1461 int timeLength = msgListTime->GetLen();
1462 const uint8_t *val2 = msgListTime->GetVal();
1463 if ((timeLength != 0) && (val2 != nullptr)) {
1464 std::string tempTime(reinterpret_cast<char *>(const_cast<uint8_t *>(val2)), timeLength);
1465 data.MseTime = tempTime;
1466 }
1467 }
1468 auto msgListSize = appParam->GetTlvtriplet(MCE_LISTING_SIZE);
1469 if (msgListSize != nullptr) {
1470 int length3 = msgListSize->GetLen();
1471 const uint8_t *val3 = msgListSize->GetVal();
1472 if ((length3 != 0) && (val3 != nullptr)) {
1473 uint16_t tempVal = *(reinterpret_cast<uint16_t *>(const_cast<uint8_t *>(val3)));
1474 data.ListingSize = ((tempVal >> MCE_8BIT) & MCE_16BIT_MASK_LEFT_LOW) |
1475 ((tempVal << MCE_8BIT) & MCE_16BIT_MASK_LEFT_HIGH);
1476 }
1477 }
1478 auto msgListDb = appParam->GetTlvtriplet(MCE_DATABASE_IDENTIFIER);
1479 if (msgListDb != nullptr) {
1480 int databaseLength = msgListDb->GetLen();
1481 const uint8_t *val4 = msgListDb->GetVal();
1482 if ((databaseLength != 0) && (val4 != nullptr)) {
1483 std::string tempDatabase(reinterpret_cast<char *>(const_cast<uint8_t *>(val4)), databaseLength);
1484 data.DatabaseIdentifier = tempDatabase;
1485 }
1486 }
1487 auto msgListVerCnt = appParam->GetTlvtriplet(MCE_FOLDER_VERSION_COUNTER);
1488 if (msgListVerCnt != nullptr) {
1489 int folderLength = msgListVerCnt->GetLen();
1490 const uint8_t *val5 = msgListVerCnt->GetVal();
1491 if ((folderLength != 0) && (val5 != nullptr)) {
1492 std::string tempFolderCn(reinterpret_cast<char *>(const_cast<uint8_t *>(val5)), folderLength);
1493 data.FolderVersionCounter = tempFolderCn;
1494 }
1495 }
1496 }
1497 }
1498
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)1499 int MapMceRequestGetMessagesListing::ProcessResponse(
1500 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
1501 {
1502 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1503 retAction.action_ = MapActionType::GET_MESSAGES_LISTING;
1504 IProfileMessagesListingParamStruct rcvData;
1505 // get response code
1506 int rescode = resp.GetFieldCode();
1507 if (rescode == uint8_t(ObexRspCode::SUCCESS)) {
1508 MapMceGetItemAppParams(rcvData, resp);
1509 // get body
1510 auto msgListObject = resp.GetExtendBodyObject();
1511 uint8_t msgListBuf[MCE_MAX_LENGTH_OF_RESPONSE_BUFFER];
1512 size_t msgLBufLen = 1;
1513 stream_.clear();
1514 while ((msgLBufLen != 0) && (msgListObject != 0)) {
1515 msgLBufLen = msgListObject->Read(msgListBuf, MCE_MAX_LENGTH_OF_RESPONSE_BUFFER - 1);
1516 if ((msgLBufLen != 0) && (msgLBufLen < MCE_MAX_LENGTH_OF_RESPONSE_BUFFER)) {
1517 msgListBuf[msgLBufLen] = 0;
1518 stream_ << (char *)msgListBuf;
1519 }
1520 }
1521 if (stream_.str().size() != 0) {
1522 retAction.messageList_.BuildObjectData(rcvData, stream_.str());
1523 }
1524 #ifdef MCE_DEBUG_RECEIVE_DATA
1525 LOG_INFO("GetMessagesListing ListingSize=%{public}d", rcvData.ListingSize);
1526 LOG_INFO("GetMessagesListing stringObject stream length=%{public}d,str obj length=%{public}d, msglist size=%{public}d",
1527 int(stream_.str().size()),
1528 int(retAction.messageList_.GetStringObject().size()),
1529 int(retAction.messageList_.GetList().size()));
1530 LOG_INFO("GetMessagesListing stringObject=%{public}s", retAction.messageList_.GetStringObject().c_str());
1531 #endif
1532 }
1533 if (retAction.messageList_.GetList().size() == 0) {
1534 return MCE_RESPONSE_FINISH_NG;
1535 } else {
1536 return MCE_RESPONSE_FINISH;
1537 }
1538 }
1539 } // namespace bluetooth
1540 } // namespace OHOS
1541