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_SUCCESS) {
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_SUCCESS) {
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_SUCCESS) {
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_SUCCESS) {
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",
492 __PRETTY_FUNCTION__, folderListingParam_.folderListingStringObject_.c_str());
493 #endif
494 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
495 return MCE_RESPONSE_FINISH_NO_CALLBACK;
496 }
497
MapMceRequestSetPath(uint8_t flags,const std::u16string & paths,const std::vector<std::u16string> & pathsList)498 MapMceRequestSetPath::MapMceRequestSetPath(uint8_t flags, const std::u16string &paths,
499 const std::vector<std::u16string> &pathsList)
500 {
501 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
502 pathFlags_ = flags;
503 pathsString_ = paths;
504 pathsList_ = pathsList;
505 }
506
~MapMceRequestSetPath()507 MapMceRequestSetPath::~MapMceRequestSetPath()
508 {
509 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
510 }
511
GetRequestType()512 MceRequestType MapMceRequestSetPath::GetRequestType()
513 {
514 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
515 return MCE_REQUEST_TYPE_SET_PATH;
516 }
517
SendRequest(ObexMpClient & obexIns)518 int MapMceRequestSetPath::SendRequest(ObexMpClient &obexIns)
519 {
520 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
521 int ret;
522
523 if (pathFlags_ == MASSTM_SETPATH_LIST) {
524 // path string list
525 ret = obexIns.SetPath(pathsList_);
526 } else {
527 // normal string path and path up/down
528 ret = obexIns.SetPath(pathFlags_, pathsString_);
529 }
530
531 if (ret != BT_SUCCESS) {
532 LOG_ERROR("%{public}s obex setpath error", __PRETTY_FUNCTION__);
533 }
534 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
535 return ret;
536 }
537
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)538 int MapMceRequestSetPath::ProcessResponse(
539 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
540 {
541 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
542 return MCE_RESPONSE_FINISH_NO_CALLBACK;
543 }
544
MapMceRequestPushMessage(const IProfileSendMessageParameters & msg)545 MapMceRequestPushMessage::MapMceRequestPushMessage(const IProfileSendMessageParameters &msg)
546 {
547 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
548 messageParam_ = msg;
549 SetSupportMessageType(MapMessageTypeToIprofileMask(messageParam_.bmessage_.type_property));
550 }
551
~MapMceRequestPushMessage()552 MapMceRequestPushMessage::~MapMceRequestPushMessage()
553 {
554 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
555 }
556
GetRequestType()557 MceRequestType MapMceRequestPushMessage::GetRequestType()
558 {
559 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
560 return MCE_REQUEST_TYPE_SEND_MESSAGE;
561 }
562
SendRequest(ObexMpClient & obexIns)563 int MapMceRequestPushMessage::SendRequest(ObexMpClient &obexIns)
564 {
565 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::PUT_FINAL);
566 // set header
567 // set Connection ID
568 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
569 // Type is "x-bt/message"
570 header->AppendItemType(MCE_HEADER_TYPE_MESSAGE);
571 // Name of the Folder
572 header->AppendItemName(messageParam_.bmessage_.folder_property);
573 ObexTlvParamters appParams;
574 if (messageParam_.Transparent != MapOnOffType::INVALID) {
575 TlvTriplet paramTransparent(MCE_TRANSPARENT, uint8_t(messageParam_.Transparent));
576 appParams.AppendTlvtriplet(paramTransparent);
577 }
578 if (messageParam_.Retry != MapOnOffType::INVALID) {
579 TlvTriplet paramRetry(MCE_RETRY, uint8_t(messageParam_.Retry));
580 appParams.AppendTlvtriplet(paramRetry);
581 }
582 TlvTriplet paramCharset(MCE_CHARSET, uint8_t(messageParam_.Charset));
583 appParams.AppendTlvtriplet(paramCharset);
584 if (messageParam_.MessageHandle.size() != 0) {
585 TlvTriplet paramMessageHandle(MCE_MESSAGE_HANDLE,
586 (messageParam_.MessageHandle.size() + 1),
587 (const uint8_t *)messageParam_.MessageHandle.c_str());
588 appParams.AppendTlvtriplet(paramMessageHandle);
589 TlvTriplet paramAttachment(MCE_ATTACHMENT, uint8_t(messageParam_.Attachment));
590 appParams.AppendTlvtriplet(paramAttachment);
591 // This application parameter shall be included if the MessageHandle application parameter is present.
592 TlvTriplet paramModifyText(MCE_MODIFY_TEXT, uint8_t(messageParam_.ModifyText));
593 appParams.AppendTlvtriplet(paramModifyText);
594 }
595 if (messageParam_.ConversationID.size() != 0) {
596 TlvTriplet paramConversationID(MCE_CONVERSATION_ID,
597 messageParam_.ConversationID.size() + 1,
598 (const uint8_t *)messageParam_.ConversationID.c_str());
599 appParams.AppendTlvtriplet(paramConversationID);
600 }
601 header->AppendItemAppParams(appParams);
602 // End body , body is bMessage
603 MceBmessageParamMakeStringObject makeString(messageParam_.bmessage_);
604 std::string msgBody = makeString.GetStringObject();
605 // make writer object
606 std::shared_ptr<ObexBodyObject> read = std::make_shared<ObexArrayBodyObject>();
607 read->Write((const uint8_t *)msgBody.c_str(), msgBody.size());
608 // send request
609 int ret = obexIns.Put(*header, read);
610 LOG_INFO("%{public}s execute end, obex Put ret=%{public}d ", __PRETTY_FUNCTION__, ret);
611 #ifdef MCE_DEBUG_SEND_DATA
612 LOG_INFO("PushMessage,StringObject = %{public}s", msgBody.c_str());
613 #endif
614 return ret;
615 }
616
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)617 int MapMceRequestPushMessage::ProcessResponse(
618 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
619 {
620 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
621 retAction.action_ = MapActionType::SEND_MESSAGE;
622 return MCE_RESPONSE_FINISH;
623 }
624
MapMceRequestGetMessage(const std::u16string & msgHandle,const IProfileGetMessageParameters & para)625 MapMceRequestGetMessage::MapMceRequestGetMessage(
626 const std::u16string &msgHandle, const IProfileGetMessageParameters ¶)
627 {
628 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
629 msgHandle_ = msgHandle;
630 msgPara_ = para;
631 }
632
~MapMceRequestGetMessage()633 MapMceRequestGetMessage::~MapMceRequestGetMessage()
634 {
635 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
636 }
637
GetRequestType()638 MceRequestType MapMceRequestGetMessage::GetRequestType()
639 {
640 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
641 return MCE_REQUEST_TYPE_GET_MESSAGE;
642 }
643
SendRequest(ObexMpClient & obexIns)644 int MapMceRequestGetMessage::SendRequest(ObexMpClient &obexIns)
645 {
646 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
647 int ret;
648 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::GET_FINAL);
649 // set header
650 // Connection ID
651 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
652 // Type is "x-bt/MAP-msg-listing"
653 header->AppendItemType(MCE_HEADER_TYPE_MESSAGE);
654 header->AppendItemName(msgHandle_);
655
656 if (GetRequestConfig().isUseSrmp) {
657 LOG_ERROR("%{public}s warning: srmp only valid in pts test!", __PRETTY_FUNCTION__);
658 header->AppendItemSrmp();
659 }
660
661 // Application Parameters:
662 TlvTriplet paramAttachment(MCE_ATTACHMENT, uint8_t(msgPara_.Attachment));
663 TlvTriplet paramCharset(MCE_CHARSET, uint8_t(msgPara_.Charset));
664 TlvTriplet paramFractionRequest(MCE_FRACTION_REQUEST, uint8_t(msgPara_.FractionRequest));
665 ObexTlvParamters appParams;
666 appParams.AppendTlvtriplet(paramAttachment);
667 appParams.AppendTlvtriplet(paramCharset);
668 appParams.AppendTlvtriplet(paramFractionRequest);
669 header->AppendItemAppParams(appParams);
670 #ifdef MCE_DEBUG_SEND_DATA
671 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
672 std::string utf8Handle = converter.to_bytes(msgHandle_);
673 LOG_INFO("Send GetMessage msgHandle_=%{public}s", utf8Handle.c_str());
674 LOG_INFO("Send GetMessage Attachment=%hhu", msgPara_.Attachment);
675 LOG_INFO("Send GetMessage Charset=%hhu", msgPara_.Charset);
676 LOG_INFO("Send GetMessage FractionRequest=%hhu", msgPara_.FractionRequest);
677 #endif
678 // make writer object
679 std::shared_ptr<ObexBodyObject> writer = std::make_shared<ObexArrayBodyObject>();
680 // send request
681 if (GetRequestConfig().isUseSrmp) {
682 LOG_ERROR("%{public}s warning: srmp only valid in pts test!", __PRETTY_FUNCTION__);
683 ret = obexIns.Get(*header, writer, GetRequestConfig().srmpCount);
684 } else {
685 ret = obexIns.Get(*header, writer);
686 }
687 if (ret != BT_SUCCESS) {
688 LOG_ERROR("%{public}s obex put error", __PRETTY_FUNCTION__);
689 }
690 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
691 return ret;
692 }
693
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)694 int MapMceRequestGetMessage::ProcessResponse(
695 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
696 {
697 retAction.action_ = MapActionType::GET_MESSAGE;
698 MceTypesBMessage *bmessageData = &retAction.bmessage_;
699 if (resp.GetFieldCode() != uint8_t(ObexRspCode::SUCCESS)) {
700 return MCE_RESPONSE_FINISH;
701 }
702 auto appParam = resp.GetItemAppParams();
703 if (appParam != nullptr) {
704 auto tlvParam1 = appParam->GetTlvtriplet(MCE_FRACTION_DELIVER);
705 if (tlvParam1 != nullptr) {
706 int length = tlvParam1->GetLen();
707 const uint8_t *val1 = tlvParam1->GetVal();
708 uint8_t deliveryType = int(MapFractionDeliverType::INVALID);
709 if ((length != 0) && (val1 != nullptr)) {
710 deliveryType = *val1;
711 }
712 if (deliveryType == 0) {
713 bmessageData->SetFractionDeliver(MapFractionDeliverType::MORE);
714 } else if (deliveryType == 1) {
715 bmessageData->SetFractionDeliver(MapFractionDeliverType::LAST);
716 } else {
717 bmessageData->SetFractionDeliver(MapFractionDeliverType::INVALID);
718 }
719 }
720 }
721 auto msgObject = resp.GetExtendBodyObject();
722 uint8_t msgBuf[MCE_MAX_LENGTH_OF_RESPONSE_BUFFER];
723 size_t bufLen = 1;
724 stream_.clear();
725 while ((bufLen != 0) && (msgObject != 0)) {
726 bufLen = msgObject->Read(msgBuf, MCE_MAX_LENGTH_OF_RESPONSE_BUFFER - 1);
727 if ((bufLen != 0) && (bufLen < MCE_MAX_LENGTH_OF_RESPONSE_BUFFER)) {
728 msgBuf[bufLen] = 0;
729 stream_ << (char *)msgBuf;
730 }
731 }
732 if (stream_.str().size() != 0) {
733 bmessageData->BuildObjectData(stream_.str());
734 }
735 #ifdef MCE_DEBUG_RECEIVE_DATA
736 LOG_INFO("GetMessage msgObject=%{public}s", bmessageData->GetBmessageObject().c_str());
737 #endif
738 if (bmessageData->GetBMessageData().type_property != IprofileMaskToMapMessageType(GetSupportMessageType())) {
739 return MCE_RESPONSE_FINISH_NG;
740 } else {
741 return MCE_RESPONSE_FINISH;
742 }
743 }
744
MapMceRequestGetUreadMessages(MapMessageType type,const IProfileGetMessagesListingParameters & para)745 MapMceRequestGetUreadMessages::MapMceRequestGetUreadMessages(
746 MapMessageType type, const IProfileGetMessagesListingParameters ¶)
747 {
748 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
749 requestPtr_ = nullptr;
750 obexInsBackup_ = nullptr;
751 msgHandleList_.clear();
752 listParam_ = para;
753 listParam_.FilterMessageType = MapMessageTypeToFrameworkMask(type);
754 SetSupportMessageType(MapMessageTypeToIprofileMask(type));
755 }
756
~MapMceRequestGetUreadMessages()757 MapMceRequestGetUreadMessages::~MapMceRequestGetUreadMessages()
758 {
759 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
760 }
761
GetRequestType()762 MceRequestType MapMceRequestGetUreadMessages::GetRequestType()
763 {
764 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
765 return MCE_REQUEST_TYPE_GET_UNREAD_MESSAGES;
766 }
767
SendRequest(ObexMpClient & obexIns)768 int MapMceRequestGetUreadMessages::SendRequest(ObexMpClient &obexIns)
769 {
770 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
771 int ret;
772 MapMceRequestConfig cfg = GetRequestConfig();
773
774 obexInsBackup_ = &obexIns;
775 if (listParam_.MaxListCount > cfg.maxOfGetUnread) {
776 listParam_.MaxListCount = cfg.maxOfGetUnread;
777 }
778 requestPtr_ = std::make_unique<MapMceRequestGetMessagesListing>(listParam_);
779 ret = requestPtr_->SendRequest(obexIns);
780 return ret;
781 }
782
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)783 int MapMceRequestGetUreadMessages::ProcessResponse(
784 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
785 {
786 int ret = MCE_RESPONSE_FINISH_NG;
787 retAction.action_ = MapActionType::GET_UNREAD_MESSAGES;
788 if (requestPtr_ == nullptr) {
789 return ret;
790 }
791 LOG_INFO("%{public}s request type = %{public}d", __PRETTY_FUNCTION__, requestPtr_->GetRequestType());
792 if (requestPtr_->GetRequestType() == MCE_REQUEST_TYPE_GET_MESSAGELISTING) {
793 MapRequestResponseAction ureadAction;
794 requestPtr_->ProcessResponse(clientInst, resp, ureadAction);
795 auto msgOutlineList = ureadAction.messageList_.GetList();
796 for (auto it = msgOutlineList.begin(); it != msgOutlineList.end(); it++) {
797 IProfileMessageOutline msgOutline = *it;
798 if (msgOutline.handle != "") {
799 msgHandleList_.push_back(msgOutline.handle);
800 ret = MCE_RESPONSE_CONTINUE_NO_CALLBACK;
801 }
802 }
803 } else if (requestPtr_->GetRequestType() == MCE_REQUEST_TYPE_GET_MESSAGE) {
804 requestPtr_->ProcessResponse(clientInst, resp, retAction);
805 ret = MCE_RESPONSE_CONTINUE_WITH_CALLBACK;
806 if (msgHandleList_.size() == 0) {
807 ret = MCE_RESPONSE_FINISH; // normal finish
808 }
809 }
810 if (msgHandleList_.size() != 0) {
811 std::string tempStr = msgHandleList_.front();
812 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
813 std::u16string msgHandle = converter.from_bytes(tempStr);
814 msgHandleList_.pop_front();
815 IProfileGetMessageParameters para;
816 para.Attachment = MapAttachmentType::NO; // no Attachment
817 para.Charset = MapCharsetType::UTF_8; // 0 is "native" , 1 is "UTF-8"
818 para.FractionRequest = MapFractionRequestType::FIRST; // 0 is "first" , 1 is "next"
819 requestPtr_ = std::make_unique<MapMceRequestGetMessage>(msgHandle, para);
820 requestPtr_->SetSupportMessageType(GetSupportMessageType());
821 int sendRet = requestPtr_->SendRequest(*obexInsBackup_);
822 if (sendRet != BT_SUCCESS) {
823 msgHandleList_.clear();
824 ret = MCE_RESPONSE_FINISH_NG;
825 }
826 }
827 return ret;
828 }
829
MapMceRequestUpdateInbox()830 MapMceRequestUpdateInbox::MapMceRequestUpdateInbox()
831 {
832 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
833 }
834
~MapMceRequestUpdateInbox()835 MapMceRequestUpdateInbox::~MapMceRequestUpdateInbox()
836 {
837 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
838 }
839
GetRequestType()840 MceRequestType MapMceRequestUpdateInbox::GetRequestType()
841 {
842 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
843 return MCE_REQUEST_TYPE_UPDATE_INBOX;
844 }
845
SendRequest(ObexMpClient & obexIns)846 int MapMceRequestUpdateInbox::SendRequest(ObexMpClient &obexIns)
847 {
848 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
849 int ret;
850 uint8_t emptyBody = 0x30;
851
852 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::PUT_FINAL);
853
854 // set header
855 // set Connection ID
856 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
857 // Type is “x-bt/MAP-messageUpdate”
858 header->AppendItemType(MCE_HEADER_TYPE_MESSAGE_UPDATE);
859 // End body
860 header->AppendItemEndBody(&emptyBody, 1);
861 // send request
862 ret = obexIns.Put(*header);
863 if (ret != BT_SUCCESS) {
864 LOG_ERROR("%{public}s obex Put error,ret=%{public}d ", __PRETTY_FUNCTION__, ret);
865 }
866 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
867 return ret;
868 }
869
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)870 int MapMceRequestUpdateInbox::ProcessResponse(
871 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
872 {
873 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
874 retAction.action_ = MapActionType::UPDATE_INBOX;
875 return MCE_RESPONSE_FINISH;
876 }
877
MapMceRequestSetOwnerStatus(const IProfileSetOwnerStatusParameters & para)878 MapMceRequestSetOwnerStatus::MapMceRequestSetOwnerStatus(const IProfileSetOwnerStatusParameters ¶)
879 {
880 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
881 ownerPara_ = para;
882 }
883
~MapMceRequestSetOwnerStatus()884 MapMceRequestSetOwnerStatus::~MapMceRequestSetOwnerStatus()
885 {
886 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
887 }
888
GetRequestType()889 MceRequestType MapMceRequestSetOwnerStatus::GetRequestType()
890 {
891 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
892 return MCE_REQUEST_TYPE_SET_OWNER_STATUS;
893 }
894
SendRequest(ObexMpClient & obexIns)895 int MapMceRequestSetOwnerStatus::SendRequest(ObexMpClient &obexIns)
896 {
897 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
898 int ret;
899
900 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::PUT_FINAL);
901
902 // set header
903 // set Connection ID
904 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
905 // Type is "x-bt/ownerStatus"
906 header->AppendItemType(MCE_HEADER_TYPE_SET_OWNER_STATUS);
907
908 // Application Parameters:
909 ObexTlvParamters appParams;
910
911 TlvTriplet paramApplication(MCE_PRESENCE_AVAILABILITY, ownerPara_.ownerStatus_.PresenceAvailability);
912 if (ownerPara_.ownerStatus_.PresenceText != "") {
913 TlvTriplet paramPresenceText(MCE_PRESENCE_TEXT,
914 ownerPara_.ownerStatus_.PresenceText.size() + 1,
915 (const uint8_t *)ownerPara_.ownerStatus_.PresenceText.c_str());
916 appParams.AppendTlvtriplet(paramPresenceText);
917 }
918 if (ownerPara_.ownerStatus_.LastActivity != "") {
919 TlvTriplet paramLastActivity(MCE_LAST_ACTIVITY,
920 ownerPara_.ownerStatus_.LastActivity.size() + 1,
921 (const uint8_t *)ownerPara_.ownerStatus_.LastActivity.c_str());
922 appParams.AppendTlvtriplet(paramLastActivity);
923 }
924 if (ownerPara_.ConversationID != "") {
925 TlvTriplet paramConversationID(MCE_CONVERSATION_ID,
926 ownerPara_.ConversationID.size() + 1,
927 (const uint8_t *)ownerPara_.ConversationID.c_str());
928 appParams.AppendTlvtriplet(paramConversationID);
929 }
930 TlvTriplet paramChatState(MCE_CHAT_STATE, ownerPara_.ownerStatus_.ChatState);
931
932 appParams.AppendTlvtriplet(paramApplication);
933 appParams.AppendTlvtriplet(paramChatState);
934 header->AppendItemAppParams(appParams);
935
936 // End body
937 uint8_t emptyBody = 0x30;
938 header->AppendItemEndBody(&emptyBody, 1);
939
940 // send request
941 ret = obexIns.Put(*header);
942 if (ret != BT_SUCCESS) {
943 LOG_ERROR("%{public}s obex Put error,ret=%{public}d ", __PRETTY_FUNCTION__, ret);
944 }
945 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
946 return ret;
947 }
948
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)949 int MapMceRequestSetOwnerStatus::ProcessResponse(
950 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
951 {
952 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
953 retAction.action_ = MapActionType::SET_OWNER_STATUS;
954 return MCE_RESPONSE_FINISH;
955 }
956
MapMceRequestGetOwnerStatus(const std::string & conversationId)957 MapMceRequestGetOwnerStatus::MapMceRequestGetOwnerStatus(const std::string &conversationId)
958 {
959 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
960 ownerConversationId_ = conversationId;
961 }
962
~MapMceRequestGetOwnerStatus()963 MapMceRequestGetOwnerStatus::~MapMceRequestGetOwnerStatus()
964 {
965 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
966 }
967
GetRequestType()968 MceRequestType MapMceRequestGetOwnerStatus::GetRequestType()
969 {
970 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
971 return MCE_REQUEST_TYPE_GET_OWNER_STATUS;
972 }
973
SendRequest(ObexMpClient & obexIns)974 int MapMceRequestGetOwnerStatus::SendRequest(ObexMpClient &obexIns)
975 {
976 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
977 int ret;
978
979 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::GET_FINAL);
980
981 // set header
982 // set Connection ID
983 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
984 // Type is "x-bt/ownerStatus", the string is same as set owner status
985 header->AppendItemType(MCE_HEADER_TYPE_SET_OWNER_STATUS);
986
987 // Application Parameters:
988 if (ownerConversationId_.size() != 0) {
989 TlvTriplet paramConversationID(
990 MCE_CONVERSATION_ID, ownerConversationId_.size(), (const uint8_t *)ownerConversationId_.c_str());
991 ObexTlvParamters appParams;
992 appParams.AppendTlvtriplet(paramConversationID);
993 header->AppendItemAppParams(appParams);
994 }
995
996 // send request
997 ret = obexIns.Get(*header);
998 if (ret != BT_SUCCESS) {
999 LOG_ERROR("%{public}s obex Put error,ret=%{public}d ", __PRETTY_FUNCTION__, ret);
1000 }
1001 LOG_INFO("%{public}s end, ownerConversationId_ = %{public}s", __PRETTY_FUNCTION__, ownerConversationId_.c_str());
1002 return ret;
1003 }
1004
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)1005 int MapMceRequestGetOwnerStatus::ProcessResponse(
1006 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
1007 {
1008 retAction.action_ = MapActionType::GET_OWNER_STATUS;
1009 // get response code
1010 int rescode = resp.GetFieldCode();
1011 if (rescode != uint8_t(ObexRspCode::SUCCESS)) {
1012 return MCE_RESPONSE_FINISH;
1013 }
1014 auto appParam = resp.GetItemAppParams();
1015 if (appParam != nullptr) {
1016 auto tlvParam1 = appParam->GetTlvtriplet(MCE_PRESENCE_AVAILABILITY);
1017 if (tlvParam1 != nullptr) {
1018 int length1 = tlvParam1->GetLen();
1019 const uint8_t *val1 = tlvParam1->GetVal();
1020 if ((length1 != 0) && (val1 != nullptr)) {
1021 retAction.ownerStatus_.PresenceAvailability = *val1;
1022 }
1023 }
1024 auto tlvParam2 = appParam->GetTlvtriplet(MCE_PRESENCE_TEXT);
1025 if (tlvParam2 != nullptr) {
1026 int length2 = tlvParam2->GetLen();
1027 const uint8_t *val2 = tlvParam2->GetVal();
1028 if ((length2 != 0) && (val2 != nullptr)) {
1029 std::string tempPresence(reinterpret_cast<char *>(const_cast<uint8_t *>(val2)), length2);
1030 retAction.ownerStatus_.PresenceText = tempPresence;
1031 }
1032 }
1033 auto tlvParam3 = appParam->GetTlvtriplet(MCE_LAST_ACTIVITY);
1034 if (tlvParam3 != nullptr) {
1035 int length3 = tlvParam3->GetLen();
1036 const uint8_t *val3 = tlvParam3->GetVal();
1037 if ((length3 != 0) && (val3 != nullptr)) {
1038 std::string tempLastAct(reinterpret_cast<char *>(const_cast<uint8_t *>(val3)), length3);
1039 retAction.ownerStatus_.LastActivity = tempLastAct;
1040 }
1041 }
1042 auto tlvParam4 = appParam->GetTlvtriplet(MCE_CHAT_STATE);
1043 if (tlvParam4 != nullptr) {
1044 int length4 = tlvParam4->GetLen();
1045 const uint8_t *val4 = tlvParam4->GetVal();
1046 if ((length4 != 0) && (val4 != nullptr)) {
1047 retAction.ownerStatus_.ChatState = *val4;
1048 }
1049 }
1050 }
1051 return MCE_RESPONSE_FINISH;
1052 }
1053
MapMceRequestSetMessageStatus(const std::u16string & msgHandle,MapStatusIndicatorType statusIndicator,MapStatusValueType statusValue,const std::string & exData)1054 MapMceRequestSetMessageStatus::MapMceRequestSetMessageStatus(const std::u16string &msgHandle,
1055 MapStatusIndicatorType statusIndicator, MapStatusValueType statusValue, const std::string &exData)
1056 {
1057 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1058 msgHandle_ = msgHandle;
1059 msgStatusIndicator_ = uint8_t(statusIndicator);
1060 msgstatusValue_ = uint8_t(statusValue);
1061 extendedData_ = exData;
1062 }
1063
~MapMceRequestSetMessageStatus()1064 MapMceRequestSetMessageStatus::~MapMceRequestSetMessageStatus()
1065 {
1066 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1067 }
1068
GetRequestType()1069 MceRequestType MapMceRequestSetMessageStatus::GetRequestType()
1070 {
1071 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1072 return MCE_REQUEST_TYPE_SET_MESSAGE_STATUS;
1073 }
1074
SendRequest(ObexMpClient & obexIns)1075 int MapMceRequestSetMessageStatus::SendRequest(ObexMpClient &obexIns)
1076 {
1077 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
1078 int ret;
1079
1080 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::PUT_FINAL);
1081
1082 // set header
1083 // set Connection ID
1084 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
1085 // Message Handle
1086 header->AppendItemName(msgHandle_);
1087 // Type is "x-bt/messageStatus"
1088 header->AppendItemType(MCE_HEADER_TYPE_SET_MESSAGE_STATUS);
1089
1090 // Application Parameters:
1091 TlvTriplet paramStatusIndicator(MCE_STATUS_INDICATOR, msgStatusIndicator_);
1092 TlvTriplet paramStatusValue(MCE_STATUS_VALUE, msgstatusValue_);
1093
1094 ObexTlvParamters appParams;
1095 appParams.AppendTlvtriplet(paramStatusIndicator);
1096 appParams.AppendTlvtriplet(paramStatusValue);
1097
1098 // extendedData_ is optional
1099 if (extendedData_ != "") {
1100 TlvTriplet extendedDataParam(
1101 MCE_EXTENDED_DATA, extendedData_.size() + 1, (const uint8_t *)extendedData_.c_str());
1102 appParams.AppendTlvtriplet(extendedDataParam);
1103 }
1104 header->AppendItemAppParams(appParams);
1105 // End body
1106 uint8_t emptyBody = 0x30;
1107 header->AppendItemEndBody(&emptyBody, 1);
1108
1109 // send request
1110 ret = obexIns.Put(*header);
1111 if (ret != BT_SUCCESS) {
1112 LOG_ERROR("%{public}s obex Put error,ret=%{public}d ", __PRETTY_FUNCTION__, ret);
1113 }
1114 return ret;
1115 }
1116
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)1117 int MapMceRequestSetMessageStatus::ProcessResponse(
1118 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
1119 {
1120 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1121 retAction.action_ = MapActionType::SET_MESSAGE_STATUS;
1122 return MCE_RESPONSE_FINISH;
1123 }
1124
MapMceRequestGetConversationListing(const IProfileGetConversationListingParameters & para)1125 MapMceRequestGetConversationListing::MapMceRequestGetConversationListing(
1126 const IProfileGetConversationListingParameters ¶)
1127
1128 {
1129 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1130 converPara_ = para;
1131 }
1132
~MapMceRequestGetConversationListing()1133 MapMceRequestGetConversationListing::~MapMceRequestGetConversationListing()
1134 {
1135 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1136 }
1137
GetRequestType()1138 MceRequestType MapMceRequestGetConversationListing::GetRequestType()
1139 {
1140 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1141 return MCE_REQUEST_TYPE_GET_CONVERSATION_LISTING;
1142 }
1143
SetAppendParam(ObexTlvParamters & appParams)1144 void MapMceRequestGetConversationListing::SetAppendParam(ObexTlvParamters &appParams)
1145 {
1146 TlvTriplet paramMaxListCount(MCE_MAX_LIST_COUNT, converPara_.MaxListCount);
1147 appParams.AppendTlvtriplet(paramMaxListCount);
1148
1149 TlvTriplet paramListStartOffset(MCE_LIST_START_OFF_SET, converPara_.ListStartOffset);
1150 appParams.AppendTlvtriplet(paramListStartOffset);
1151
1152 if (converPara_.FilterLastActivityBegin.size() != 0) {
1153 TlvTriplet paramFilterBegin(MCE_FILTER_LAST_ACTIVITY_BEGIN,
1154 converPara_.FilterLastActivityBegin.size() + 1,
1155 (const uint8_t *)converPara_.FilterLastActivityBegin.c_str());
1156 appParams.AppendTlvtriplet(paramFilterBegin);
1157 }
1158
1159 if (converPara_.FilterLastActivityEnd.size() != 0) {
1160 TlvTriplet paramFilterEnd(MCE_FILTER_LAST_ACTIVITY_END,
1161 converPara_.FilterLastActivityEnd.size() + 1,
1162 (const uint8_t *)converPara_.FilterLastActivityEnd.c_str());
1163 appParams.AppendTlvtriplet(paramFilterEnd);
1164 }
1165
1166 TlvTriplet paramFilterRead(MCE_FILTER_READ_STATUS, converPara_.FilterReadStatus);
1167 appParams.AppendTlvtriplet(paramFilterRead);
1168
1169 if (converPara_.FilterRecipient.size()) {
1170 TlvTriplet paramFilterRecipient(MCE_FILTER_RECIPIENT,
1171 converPara_.FilterRecipient.size(),
1172 (const uint8_t *)converPara_.FilterRecipient.c_str());
1173 appParams.AppendTlvtriplet(paramFilterRecipient);
1174 }
1175
1176 if (converPara_.ConversationID.size()) {
1177 TlvTriplet paramConversationID(MCE_CONVERSATION_ID,
1178 converPara_.ConversationID.size(),
1179 (const uint8_t *)converPara_.ConversationID.c_str());
1180 appParams.AppendTlvtriplet(paramConversationID);
1181 }
1182
1183 TlvTriplet paramConvMask(MCE_CONV_PARAMETER_MASK, converPara_.ConvParameterMask);
1184 appParams.AppendTlvtriplet(paramConvMask);
1185 }
1186
SendRequest(ObexMpClient & obexIns)1187 int MapMceRequestGetConversationListing::SendRequest(ObexMpClient &obexIns)
1188 {
1189 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
1190 int ret;
1191
1192 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::GET_FINAL);
1193
1194 // set header
1195 // set Connection ID
1196 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
1197 // type is "x-bt/MAP-convo-listing"
1198 header->AppendItemType(MCE_HEADER_TYPE_GET_CONVO_LISTING);
1199
1200 // Application Parameters:
1201 ObexTlvParamters appParams;
1202 SetAppendParam(appParams);
1203
1204 header->AppendItemAppParams(appParams);
1205
1206 // make writer object
1207 std::shared_ptr<ObexBodyObject> writer = std::make_shared<ObexArrayBodyObject>();
1208
1209 // send request
1210 ret = obexIns.Get(*header, writer);
1211 if (ret != BT_SUCCESS) {
1212 LOG_ERROR("%{public}s obex Put error,ret=%{public}d ", __PRETTY_FUNCTION__, ret);
1213 }
1214 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
1215 return ret;
1216 }
1217
MapMceGetItemAppParams(IProfileConversationListingParamStruct & data,const ObexHeader & resp)1218 void MapMceRequestGetConversationListing::MapMceGetItemAppParams(
1219 IProfileConversationListingParamStruct &data, const ObexHeader &resp)
1220 {
1221 auto appParam = resp.GetItemAppParams();
1222 if (appParam != nullptr) {
1223 auto convListVerCnt =
1224 appParam->GetTlvtriplet(MCE_CONVERSATION_LISTING_VERSION_COUNTER); // 128-bit value in hex string format
1225 if (convListVerCnt != nullptr) {
1226 int convLenth = convListVerCnt->GetLen();
1227 const uint8_t *val1 = convListVerCnt->GetVal();
1228 if ((convLenth != 0) && (val1 != nullptr)) {
1229 std::string tempCounter(reinterpret_cast<char *>(const_cast<uint8_t *>(val1)), convLenth);
1230 data.ConversationListingVersionCounter = tempCounter;
1231 }
1232 }
1233 auto convMseTim = appParam->GetTlvtriplet(MCE_MSE_TIME);
1234 if (convMseTim != nullptr) {
1235 int convMseLen = convMseTim->GetLen();
1236 const uint8_t *val2 = convMseTim->GetVal();
1237 if ((convMseLen != 0) && (val2 != nullptr)) {
1238 std::string tempTime(reinterpret_cast<char *>(const_cast<uint8_t *>(val2)), convMseLen);
1239 data.MseTime = tempTime;
1240 }
1241 }
1242 auto convListSize = appParam->GetTlvtriplet(MCE_LISTING_SIZE);
1243 if (convListSize != nullptr) {
1244 int convListLength = convListSize->GetLen();
1245 const uint8_t *val3 = convListSize->GetVal();
1246 if ((convListLength != 0) && (val3 != nullptr)) {
1247 uint16_t tempVal = *(reinterpret_cast<uint16_t *>(const_cast<uint8_t *>(val3)));
1248 data.ListingSize = ((tempVal >> MCE_8BIT) & MCE_16BIT_MASK_LEFT_LOW) |
1249 ((tempVal << MCE_8BIT) & MCE_16BIT_MASK_LEFT_HIGH);
1250 }
1251 }
1252 auto convDbId = appParam->GetTlvtriplet(MCE_DATABASE_IDENTIFIER);
1253 if (convDbId != nullptr) {
1254 int convDbIdLenth = convDbId->GetLen();
1255 const uint8_t *val4 = convDbId->GetVal();
1256 if ((convDbIdLenth != 0) && (val4 != nullptr)) {
1257 std::string tempDatabase(reinterpret_cast<char *>(const_cast<uint8_t *>(val4)), convDbIdLenth);
1258 data.DatabaseIdentifier = tempDatabase;
1259 }
1260 }
1261 }
1262 }
1263
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)1264 int MapMceRequestGetConversationListing::ProcessResponse(
1265 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
1266 {
1267 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1268 retAction.action_ = MapActionType::GET_CONVERSATION_LISTING;
1269 IProfileConversationListingParamStruct paramData;
1270 int rescode;
1271
1272 // get response code
1273 rescode = resp.GetFieldCode();
1274 if (rescode == uint8_t(ObexRspCode::SUCCESS)) {
1275 MapMceGetItemAppParams(paramData, resp);
1276 // get body
1277 auto convObject = resp.GetExtendBodyObject();
1278 uint8_t convBuf[MCE_MAX_LENGTH_OF_RESPONSE_BUFFER];
1279 size_t bufLen = 1;
1280 std::ostringstream convStream;
1281 while ((bufLen != 0) && (convObject != 0)) {
1282 bufLen = convObject->Read(convBuf, MCE_MAX_LENGTH_OF_RESPONSE_BUFFER - 1);
1283 if ((bufLen != 0) && (bufLen < MCE_MAX_LENGTH_OF_RESPONSE_BUFFER)) {
1284 convBuf[bufLen] = 0;
1285 convStream << (char *)convBuf;
1286 }
1287 }
1288 if (convStream.str().size() != 0) {
1289 retAction.conversationList_.BuildObjectData(paramData, convStream.str());
1290 }
1291 #ifdef MCE_DEBUG_RECEIVE_DATA
1292 LOG_INFO("GetConversationListing list size=%{public}d, strlength=%{public}d, convStream size=%{public}d",
1293 int(retAction.conversationList_.GetList().size()),
1294 int(retAction.conversationList_.GetStringObject().size()),
1295 int(convStream.str().size()));
1296 LOG_INFO("GetConversationListing stringObject=%{public}s",
1297 retAction.conversationList_.GetStringObject().c_str());
1298 #endif
1299 }
1300 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
1301 return MCE_RESPONSE_FINISH;
1302 }
1303
MapMceRequestGetMessagesListing(const IProfileGetMessagesListingParameters & para)1304 MapMceRequestGetMessagesListing::MapMceRequestGetMessagesListing(const IProfileGetMessagesListingParameters ¶)
1305
1306 {
1307 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1308 int messagType = MAP_MCE_SUPPORTED_MESSAGE_TYPE_ALL;
1309 msgPara_ = para;
1310
1311 if ((msgPara_.FilterMessageType & MAP_FILTER_MESSAGE_MASK_SMS_GSM) != 0) { // filter out gsm
1312 messagType &= ~MAP_MCE_SUPPORTED_MESSAGE_TYPE_SMS_GSM;
1313 }
1314 if ((msgPara_.FilterMessageType & MAP_FILTER_MESSAGE_MASK_SMS_CDMA) != 0) { // filter out cdma
1315 messagType &= ~MAP_MCE_SUPPORTED_MESSAGE_TYPE_SMS_CDMA;
1316 }
1317 if ((msgPara_.FilterMessageType & MAP_FILTER_MESSAGE_MASK_EMAIL) != 0) { // filter out email
1318 messagType &= ~MAP_MCE_SUPPORTED_MESSAGE_TYPE_EMAIL;
1319 }
1320 if ((msgPara_.FilterMessageType & MAP_FILTER_MESSAGE_MASK_MMS) != 0) { // filter out mms
1321 messagType &= ~MAP_MCE_SUPPORTED_MESSAGE_TYPE_MMS;
1322 }
1323 if ((msgPara_.FilterMessageType & MAP_FILTER_MESSAGE_MASK_IM) != 0) { // filter out im
1324 messagType &= ~MAP_MCE_SUPPORTED_MESSAGE_TYPE_IM;
1325 }
1326 SetSupportMessageType(messagType);
1327 }
1328
~MapMceRequestGetMessagesListing()1329 MapMceRequestGetMessagesListing::~MapMceRequestGetMessagesListing()
1330 {
1331 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1332 }
1333
GetRequestType()1334 MceRequestType MapMceRequestGetMessagesListing::GetRequestType()
1335 {
1336 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1337 return MCE_REQUEST_TYPE_GET_MESSAGELISTING;
1338 }
1339
SendRequestSetAppParamsStep1(ObexTlvParamters & appParams)1340 void MapMceRequestGetMessagesListing::SendRequestSetAppParamsStep1(ObexTlvParamters &appParams)
1341 {
1342 TlvTriplet paramListCount(MCE_MAX_LIST_COUNT, msgPara_.MaxListCount);
1343 appParams.AppendTlvtriplet(paramListCount);
1344
1345 TlvTriplet paramStartOffset(MCE_LIST_START_OFF_SET, msgPara_.ListStartOffset);
1346 appParams.AppendTlvtriplet(paramStartOffset);
1347
1348 TlvTriplet paramSubjectLength(MCE_SUBJECT_LENGTH, msgPara_.SubjectLength);
1349 appParams.AppendTlvtriplet(paramSubjectLength);
1350
1351 TlvTriplet paramParameterMask(MCE_PARAMETER_MASK, msgPara_.ParameterMask);
1352 appParams.AppendTlvtriplet(paramParameterMask);
1353
1354 TlvTriplet paramFilMsgType(MCE_FILTER_MESSAGE_TYPE, msgPara_.FilterMessageType);
1355 appParams.AppendTlvtriplet(paramFilMsgType);
1356
1357 TlvTriplet paramFilterPriority(MCE_FILTER_PRIORITY, msgPara_.FilterPriority);
1358 appParams.AppendTlvtriplet(paramFilterPriority);
1359
1360 TlvTriplet paramFilterRead(MCE_FILTER_READ_STATUS, msgPara_.FilterReadStatus);
1361 appParams.AppendTlvtriplet(paramFilterRead);
1362 }
1363
SendRequestSetAppParamsStep2(ObexTlvParamters & appParams)1364 void MapMceRequestGetMessagesListing::SendRequestSetAppParamsStep2(ObexTlvParamters &appParams)
1365 {
1366 if (msgPara_.FilterPeriodBegin.size() != 0) {
1367 TlvTriplet paramFilBegin(MCE_FILTER_PERIOD_BEGIN,
1368 msgPara_.FilterPeriodBegin.size() + 1,
1369 (const uint8_t *)msgPara_.FilterPeriodBegin.c_str());
1370 appParams.AppendTlvtriplet(paramFilBegin);
1371 }
1372 if (msgPara_.FilterPeriodEnd.size() != 0) {
1373 TlvTriplet paramFilEnd(MCE_FILTER_PERIOD_END,
1374 msgPara_.FilterPeriodEnd.size() + 1,
1375 (const uint8_t *)msgPara_.FilterPeriodEnd.c_str());
1376 appParams.AppendTlvtriplet(paramFilEnd);
1377 }
1378 if (msgPara_.FilterRecipient.size() != 0) {
1379 TlvTriplet paramFilterRecipient(MCE_FILTER_RECIPIENT,
1380 msgPara_.FilterRecipient.size() + 1,
1381 (const uint8_t *)msgPara_.FilterRecipient.c_str());
1382 appParams.AppendTlvtriplet(paramFilterRecipient);
1383 }
1384 if (msgPara_.FilterOriginator.size() != 0) {
1385 TlvTriplet paramOriginat(MCE_FILTER_ORIGINATOR,
1386 msgPara_.FilterOriginator.size() + 1,
1387 (const uint8_t *)msgPara_.FilterOriginator.c_str());
1388 appParams.AppendTlvtriplet(paramOriginat);
1389 }
1390 if (msgPara_.ConversationID.size() != 0) {
1391 TlvTriplet paramConversationID(
1392 MCE_CONVERSATION_ID, msgPara_.ConversationID.size() + 1, (const uint8_t *)msgPara_.ConversationID.c_str());
1393 appParams.AppendTlvtriplet(paramConversationID);
1394 }
1395 if (msgPara_.FilterMessageHandle.size() != 0) {
1396 TlvTriplet paramMsgHandle(MCE_FILTER_MESSAGE_HANDLE,
1397 msgPara_.FilterMessageHandle.size() + 1,
1398 (const uint8_t *)msgPara_.FilterMessageHandle.c_str());
1399 appParams.AppendTlvtriplet(paramMsgHandle);
1400 }
1401 }
1402
SendRequest(ObexMpClient & obexIns)1403 int MapMceRequestGetMessagesListing::SendRequest(ObexMpClient &obexIns)
1404 {
1405 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
1406 int ret;
1407
1408 std::unique_ptr<ObexHeader> header = ObexHeader::CreateRequest(ObexOpeId::GET_FINAL);
1409
1410 // set header
1411 // Connection ID
1412 header->AppendItemConnectionId(obexIns.GetClientSession().GetConnectId());
1413 // Type is "x-bt/MAP-msg-listing"
1414 header->AppendItemType(MCE_HEADER_TYPE_GET_MESSAGE_LISTING);
1415 // folder name
1416 header->AppendItemName(msgPara_.folder);
1417 // Application Parameters:
1418 ObexTlvParamters appParams;
1419
1420 SendRequestSetAppParamsStep1(appParams);
1421 SendRequestSetAppParamsStep2(appParams);
1422
1423 header->AppendItemAppParams(appParams);
1424
1425 #ifdef MCE_DEBUG_SEND_DATA
1426 LOG_INFO("Send "
1427 "GetMessagesListing:MaxListCount=0x%x,ListStartOffset=0x%x,ParameterMask=0x%x,FilterMessageType=0x%x,"
1428 "FilterReadStatus=0x%x",
1429 msgPara_.MaxListCount,
1430 msgPara_.ListStartOffset,
1431 msgPara_.ParameterMask,
1432 msgPara_.FilterMessageType,
1433 msgPara_.FilterReadStatus);
1434 #endif
1435
1436 // make writer object
1437 std::shared_ptr<ObexBodyObject> writer = std::make_shared<ObexArrayBodyObject>();
1438
1439 // send request
1440 ret = obexIns.Get(*header, writer);
1441 if (ret != BT_SUCCESS) {
1442 LOG_ERROR("%{public}s obex put error", __PRETTY_FUNCTION__);
1443 }
1444 LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
1445 return ret;
1446 }
1447
MapMceGetItemAppParams(IProfileMessagesListingParamStruct & data,const ObexHeader & resp)1448 void MapMceRequestGetMessagesListing::MapMceGetItemAppParams(
1449 IProfileMessagesListingParamStruct &data, const ObexHeader &resp)
1450 {
1451 auto appParam = resp.GetItemAppParams();
1452 if (appParam != nullptr) {
1453 auto tlvParam1 = appParam->GetTlvtriplet(MCE_NEW_MESSAGE);
1454 if (tlvParam1 != nullptr) {
1455 int length1 = tlvParam1->GetLen();
1456 const uint8_t *val1 = tlvParam1->GetVal();
1457 if ((length1 != 0) && (val1 != nullptr)) {
1458 data.NewMessage = MapOnOffType(*val1);
1459 }
1460 }
1461 auto msgListTime = appParam->GetTlvtriplet(MCE_MSE_TIME);
1462 if (msgListTime != nullptr) {
1463 int timeLength = msgListTime->GetLen();
1464 const uint8_t *val2 = msgListTime->GetVal();
1465 if ((timeLength != 0) && (val2 != nullptr)) {
1466 std::string tempTime(reinterpret_cast<char *>(const_cast<uint8_t *>(val2)), timeLength);
1467 data.MseTime = tempTime;
1468 }
1469 }
1470 auto msgListSize = appParam->GetTlvtriplet(MCE_LISTING_SIZE);
1471 if (msgListSize != nullptr) {
1472 int length3 = msgListSize->GetLen();
1473 const uint8_t *val3 = msgListSize->GetVal();
1474 if ((length3 != 0) && (val3 != nullptr)) {
1475 uint16_t tempVal = *(reinterpret_cast<uint16_t *>(const_cast<uint8_t *>(val3)));
1476 data.ListingSize = ((tempVal >> MCE_8BIT) & MCE_16BIT_MASK_LEFT_LOW) |
1477 ((tempVal << MCE_8BIT) & MCE_16BIT_MASK_LEFT_HIGH);
1478 }
1479 }
1480 auto msgListDb = appParam->GetTlvtriplet(MCE_DATABASE_IDENTIFIER);
1481 if (msgListDb != nullptr) {
1482 int databaseLength = msgListDb->GetLen();
1483 const uint8_t *val4 = msgListDb->GetVal();
1484 if ((databaseLength != 0) && (val4 != nullptr)) {
1485 std::string tempDatabase(reinterpret_cast<char *>(const_cast<uint8_t *>(val4)), databaseLength);
1486 data.DatabaseIdentifier = tempDatabase;
1487 }
1488 }
1489 auto msgListVerCnt = appParam->GetTlvtriplet(MCE_FOLDER_VERSION_COUNTER);
1490 if (msgListVerCnt != nullptr) {
1491 int folderLength = msgListVerCnt->GetLen();
1492 const uint8_t *val5 = msgListVerCnt->GetVal();
1493 if ((folderLength != 0) && (val5 != nullptr)) {
1494 std::string tempFolderCn(reinterpret_cast<char *>(const_cast<uint8_t *>(val5)), folderLength);
1495 data.FolderVersionCounter = tempFolderCn;
1496 }
1497 }
1498 }
1499 }
1500
ProcessResponse(MapMceInstanceClient & clientInst,const ObexHeader & resp,MapRequestResponseAction & retAction)1501 int MapMceRequestGetMessagesListing::ProcessResponse(
1502 MapMceInstanceClient &clientInst, const ObexHeader &resp, MapRequestResponseAction &retAction)
1503 {
1504 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1505 retAction.action_ = MapActionType::GET_MESSAGES_LISTING;
1506 IProfileMessagesListingParamStruct rcvData;
1507 // get response code
1508 int rescode = resp.GetFieldCode();
1509 if (rescode == uint8_t(ObexRspCode::SUCCESS)) {
1510 MapMceGetItemAppParams(rcvData, resp);
1511 // get body
1512 auto msgListObject = resp.GetExtendBodyObject();
1513 uint8_t msgListBuf[MCE_MAX_LENGTH_OF_RESPONSE_BUFFER];
1514 size_t msgLBufLen = 1;
1515 stream_.clear();
1516 while ((msgLBufLen != 0) && (msgListObject != 0)) {
1517 msgLBufLen = msgListObject->Read(msgListBuf, MCE_MAX_LENGTH_OF_RESPONSE_BUFFER - 1);
1518 if ((msgLBufLen != 0) && (msgLBufLen < MCE_MAX_LENGTH_OF_RESPONSE_BUFFER)) {
1519 msgListBuf[msgLBufLen] = 0;
1520 stream_ << (char *)msgListBuf;
1521 }
1522 }
1523 if (stream_.str().size() != 0) {
1524 retAction.messageList_.BuildObjectData(rcvData, stream_.str());
1525 }
1526 #ifdef MCE_DEBUG_RECEIVE_DATA
1527 LOG_INFO("GetMessagesListing ListingSize=%{public}d", rcvData.ListingSize);
1528 LOG_INFO("GetMessagesListing stringObject stream length=%{public}d,str obj "
1529 "length=%{public}d, msglist size=%{public}d",
1530 int(stream_.str().size()),
1531 int(retAction.messageList_.GetStringObject().size()),
1532 int(retAction.messageList_.GetList().size()));
1533 LOG_INFO("GetMessagesListing stringObject=%{public}s", retAction.messageList_.GetStringObject().c_str());
1534 #endif
1535 }
1536 if (retAction.messageList_.GetList().size() == 0) {
1537 return MCE_RESPONSE_FINISH_NG;
1538 } else {
1539 return MCE_RESPONSE_FINISH;
1540 }
1541 }
1542 } // namespace bluetooth
1543 } // namespace OHOS
1544