2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FMsg_SmsManagerImpl.cpp
19 * @brief This is the implementation file for the %_SmsManagerImpl class.
21 * This file contains the implementation of the %_SmsManagerImpl class.
25 #include <unique_ptr.h>
27 #include <msg_transport.h>
28 #include <msg_storage.h>
29 #include <dbus/dbus.h>
30 #include <email-api.h>
31 #include <FMsgSmsManager.h>
32 #include <FBaseSysLog.h>
33 #include <FBase_StringConverter.h>
34 #include "FMsg_SmsManagerImpl.h"
35 #include "FMsg_SmsMessageImpl.h"
36 #include "FMsg_SmsEvent.h"
37 #include "FMsg_MsgUtil.h"
38 #include "FMsg_RecipientListImpl.h"
39 #include "FMsg_SmsMmsCallbackHandler.h"
40 #include "FMsg_CbsChannelImpl.h"
43 using namespace Tizen::Base;
44 using namespace Tizen::Messaging;
45 using namespace Tizen::Base::Collection;
47 namespace Tizen { namespace Messaging
50 _SmsManagerImpl::_SmsManagerImpl(void)
51 : __isConstructed(false)
52 , __isCbsSaveEnabled(true)
54 , __pSmsReceiveEvent(null)
55 , __pCbsReceiveEvent(null)
56 , __pEtwsReceiveEvent(null)
57 , __pSmsTriggerEventList(null)
59 , __cbsSettingsHandle(0)
60 , __pCbsListener(null)
61 , __pEtwsListener(null)
65 _SmsManagerImpl::~_SmsManagerImpl(void)
68 if (__pSmsReceiveEvent)
70 delete __pSmsReceiveEvent;
71 __pSmsReceiveEvent = null;
74 if (__pCbsReceiveEvent)
76 delete __pCbsReceiveEvent;
77 __pCbsReceiveEvent = null;
80 if (__pEtwsReceiveEvent)
82 delete __pEtwsReceiveEvent;
83 __pEtwsReceiveEvent = null;
86 if (__pSmsTriggerEventList)
88 if (__pSmsTriggerEventList->GetCount() > 0)
90 __pSmsTriggerEventList->RemoveAll(true);
92 delete __pSmsTriggerEventList;
93 __pSmsTriggerEventList = null;
96 if (_SmsMmsCallbackHandler::GetInstance())
98 _SmsMmsCallbackHandler::GetInstance()->CloseMessageHandle();
99 _SmsMmsCallbackHandler::GetInstance()->CloseCbsSettingsHandle();
102 __isConstructed = false;
106 _SmsManagerImpl::Construct(const ISmsListener& listener)
108 // method return code
109 result r = E_SUCCESS;
110 int err = MSG_SUCCESS;
112 SysAssertf(__isConstructed == false, "_SmsManagerImpl instance is already constructed.");
115 unique_ptr<_SmsEvent> pSmsEvent(new (std::nothrow) _SmsEvent());
116 SysTryReturn(NID_MSG, pSmsEvent != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed.");
118 // event construction
119 r = pSmsEvent->Construct(_SMS_EVENT_TYPE_SMS_SEND_RESULT);
120 SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to construct an instance");
123 r = pSmsEvent->AddListener(listener, true);
124 SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to add a listener");
126 SysTryReturnResult(NID_MSG, _SmsMmsCallbackHandler::GetInstance() != NULL, E_SYSTEM, "Failed to constructSmsMmsCallbackHandler.");
128 // open message handle
129 err = _SmsMmsCallbackHandler::GetInstance()->OpenMessageHandle(__msgHandle);
130 SysLog(NID_MSG, "value of __msgHandle is [%d]", __msgHandle);
132 r = ConvertException(err);
133 SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to open messageHandle.");
135 // check value of msg handle
136 SysTryReturnResult(NID_MSG, __msgHandle > 0, E_SYSTEM, "msgHandle is invalid.");
138 // register sent status callback
139 err = _SmsMmsCallbackHandler::GetInstance()->RegisterMessageCallback();
141 r = ConvertException(err);
142 SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to register sms,mms callback.");
144 // open cbs message handle
145 err = _SmsMmsCallbackHandler::GetInstance()->OpenCbsSettingsHandle(__cbsSettingsHandle);
147 if (err == MSG_ERR_NO_SIM)
150 SysLog(NID_MSG, "Sim card is not present in device"); // even no sim, return sucess so that app will launch sucess
154 r = ConvertException(err);
155 SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to open cbs Settings Handle");
157 // check value of cbs settings handle
158 SysTryReturnResult(NID_MSG, __cbsSettingsHandle > 0, E_SYSTEM, "cbsSettingsHandle is invalid.");
162 r = _SmsMmsCallbackHandler::GetInstance()->LoadCbsSettings();
163 SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to load cbs message settings.");
165 __pSmsEvent = move(pSmsEvent);
166 __isConstructed = true;
172 _SmsManagerImpl::AddSmsEventListener(int port, ISmsEventListener& eventListener)
174 // checking conditions
175 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
176 SysAssertf(__msgHandle > 0, "message handle is invalid.");
178 result r = E_SUCCESS;
179 _SmsEvent* pSmsTriggerEvent = null;
180 int err = MSG_SUCCESS;
182 // check duplications
183 if (__pSmsTriggerEventList)
185 int listSize = __pSmsTriggerEventList->GetCount();
186 for (int i = 0; i < listSize; i++)
188 _SmsEvent* pItem = static_cast <_SmsEvent*>(__pSmsTriggerEventList->GetAt(i));
189 if (pItem->GetPort() == port)
191 r = E_OBJ_ALREADY_EXIST;
192 SysLogException(NID_MSG, r, "[%s] The specific port [%d] is already registered.", GetErrorMessage(r), port);
198 // make an sms trigger event
199 pSmsTriggerEvent = new (std::nothrow) _SmsEvent();
200 SysTryReturn(NID_MSG, pSmsTriggerEvent != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed");
202 // construct an sms trigger event
203 r = pSmsTriggerEvent->Construct(port);
204 SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to construct an instance.", GetErrorMessage(r));
206 // add corresponding listener to the event
207 r = pSmsTriggerEvent->AddListener(eventListener, true);
208 SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to add a listener.", GetErrorMessage(r));
210 // make a list for events
211 if (!__pSmsTriggerEventList)
213 __pSmsTriggerEventList = new (std::nothrow) ArrayList();
214 SysTryReturnResult(NID_MSG, __pSmsTriggerEventList != null, E_OUT_OF_MEMORY, "memory allocation failed.");
216 r = __pSmsTriggerEventList->Construct();
217 SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to construct an instance.", GetErrorMessage(r));
219 // add an event to the list
220 r = __pSmsTriggerEventList->Add(*pSmsTriggerEvent);
221 SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to add a listener.", GetErrorMessage(r));
223 // Register SMS Trigger
224 err = msg_reg_sms_message_callback(__msgHandle, &_SmsMmsCallbackHandler::IncomingSmsMessageCallback, port, (void*) pSmsTriggerEvent);
226 if (err != MSG_SUCCESS)
228 r = __pSmsTriggerEventList->Remove(*pSmsTriggerEvent);
230 SysLogException(NID_MSG, r, "[%s] Failed to register for incoming sms callback.", GetErrorMessage(r));
238 if (pSmsTriggerEvent)
240 delete pSmsTriggerEvent;
247 _SmsManagerImpl::RemoveSmsEventListener(int port, ISmsEventListener& eventListener)
249 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
250 SysAssertf(__msgHandle > 0, "message handle is invalid.");
252 result r = E_SUCCESS;
255 bool isFound = false;
257 // find the SmsTriggerEvent using port
258 if (__pSmsTriggerEventList)
260 listSize = __pSmsTriggerEventList->GetCount();
261 for (int i = 0; i < listSize; i++)
263 _SmsEvent* pItem = static_cast <_SmsEvent*>(__pSmsTriggerEventList->GetAt(i));
264 if (pItem->GetPort() == port)
274 SysTryReturn(NID_MSG, isFound, E_OBJ_NOT_FOUND, r = E_OBJ_NOT_FOUND, "Failed to find the SMS event listener");
276 // remove corresponding event from the list
277 r = __pSmsTriggerEventList->RemoveAt(index, true);
278 SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to remove the event listener");
284 _SmsManagerImpl::AddSmsMessageEventListener(const ISmsMessageEventListener& eventListener)
286 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
287 SysAssertf(__msgHandle > 0, "message handle is invalid.");
289 result r = E_SUCCESS;
290 int err = MSG_SUCCESS;
293 if (!__pSmsReceiveEvent)
295 __pSmsReceiveEvent = new (std::nothrow) _SmsEvent();
296 SysTryReturn(NID_MSG, __pSmsReceiveEvent != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed");
298 r = __pSmsReceiveEvent->Construct(_SMS_EVENT_TYPE_SMS_RECEIVE_RESULT);
299 SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "Failed to construct an instance");
303 r = __pSmsReceiveEvent->AddListener(eventListener, true);
304 SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "Failed to add a listener");
306 err = msg_reg_sms_message_callback(__msgHandle, &_SmsMmsCallbackHandler::IncomingSmsMessageCallback, 0, (void*)
309 r = ConvertException(err);
310 SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to register for incoming sms callback.", GetErrorMessage(r));
312 if (_SmsMmsCallbackHandler::GetInstance())
314 _SmsMmsCallbackHandler::GetInstance()->SetInComingSmsCallback(true);
320 if (__pSmsReceiveEvent)
322 delete __pSmsReceiveEvent;
323 __pSmsReceiveEvent = null;
330 _SmsManagerImpl::RemoveSmsMessageEventListener(const ISmsMessageEventListener& eventListener)
332 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
333 SysAssertf(__msgHandle > 0, "message handle is invalid.");
335 result r = E_SUCCESS;
337 SysTryReturnResult(NID_MSG, __pSmsReceiveEvent != NULL, E_OBJ_NOT_FOUND, "Failed to remove a listener");
339 r = __pSmsReceiveEvent->RemoveListener(eventListener);
340 SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to remove a listener..", GetErrorMessage(r));
342 if (_SmsMmsCallbackHandler::GetInstance())
344 _SmsMmsCallbackHandler::GetInstance()->SetInComingSmsCallback(false);
347 if (__pSmsReceiveEvent)
349 delete __pSmsReceiveEvent;
350 __pSmsReceiveEvent = null;
360 _SmsManagerImpl::GetTotalMessageCount(SmsMessageBoxType type) const
362 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
363 SysAssertf(__msgHandle > 0, "message handle is invalid.");
366 msg_struct_t countInfo = NULL;
367 int err = MSG_SUCCESS;
368 _MSG_FOLDER_ID_E folderType = MSG_ALLBOX_ID;
369 result r = E_SUCCESS;
375 case SMS_MESSAGE_BOX_TYPE_INBOX:
376 folderType = MSG_INBOX_ID;
378 case SMS_MESSAGE_BOX_TYPE_SENTBOX:
379 folderType = MSG_SENTBOX_ID;
381 case SMS_MESSAGE_BOX_TYPE_OUTBOX:
382 folderType = MSG_OUTBOX_ID;
384 case SMS_MESSAGE_BOX_TYPE_ALL:
386 err = msg_count_msg_by_type(__msgHandle, MSG_TYPE_SMS, &msgCount);
388 if (err != MSG_SUCCESS)
390 r = ConvertException(err);
391 SysLogException(NID_MSG, r, "[%s] Failed to get the message count", GetErrorMessage(r));
396 SysLog(NID_MSG, "Total count of messages is [%d]", msgCount);
400 case SMS_MESSAGE_BOX_TYPE_NONE: // impossible case
406 // get the count of corresponding message box
407 countInfo = msg_create_struct(MSG_STRUCT_COUNT_INFO);
408 err = msg_count_message(__msgHandle, folderType, countInfo);
410 if (err != MSG_SUCCESS)
412 r = ConvertException(err);
413 SysLogException(NID_MSG, r, "[%s] Failed to get the message count of the message box (%d)", GetErrorMessage(r), (int) type);
414 msg_release_struct(&countInfo);
419 msg_get_int_value(countInfo, MSG_COUNT_INFO_SMS_INT, &msgCount);
420 msg_release_struct(&countInfo);
421 SysLog(NID_MSG, "Total count of messages is [%d]", msgCount);
426 Tizen::Base::Collection::IList*
427 _SmsManagerImpl::SearchInboxN(const Tizen::Base::String* pKeyword, const Tizen::Base::String* pSenderAddress, int startIndex,
429 int& totalResultCount) const
431 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
432 SysAssertf(__msgHandle > 0, "message handle is invalid.");
434 char* pSearchString = NULL;
435 char* pSenderAddressTemp = NULL;
436 ArrayList* pList = null;
437 int err = MSG_SUCCESS;
438 result r = E_SUCCESS;
439 msg_struct_list_s msgList;
440 msg_struct_t searchCon = NULL;
444 pList = new (std::nothrow) ArrayList();
445 SysTryCatch(NID_MSG, pList != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed");
448 r = pList->Construct();
449 SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "Failed to construct an ArrayList");
452 searchCon = msg_create_struct(MSG_STRUCT_SEARCH_CONDITION);
453 msg_set_int_value(searchCon, MSG_SEARCH_CONDITION_FOLDERID_INT, MSG_INBOX_ID);
454 msg_set_int_value(searchCon, MSG_SEARCH_CONDITION_MSGTYPE_INT, MSG_TYPE_SMS);
459 pSearchString = _StringConverter::CopyToCharArrayN(*pKeyword);
460 SysTryCatch(NID_MSG, pSearchString != null, r = E_OUT_OF_MEMORY, r, "Memory allocation failed.");
461 msg_set_str_value(searchCon, MSG_SEARCH_CONDITION_SEARCH_VALUE_STR, pSearchString, strlen(pSearchString));
467 pSenderAddressTemp = _StringConverter::CopyToCharArrayN(*pSenderAddress);
468 SysTryCatch(NID_MSG, pSenderAddressTemp != null, r = E_OUT_OF_MEMORY, r, "Memory allocation failed.");
469 msg_set_str_value(searchCon, MSG_SEARCH_CONDITION_ADDRESS_VALUE_STR, pSenderAddressTemp, strlen(pSenderAddressTemp));
473 err = msg_search_message(__msgHandle, searchCon, startIndex, count, &msgList);
475 r = ConvertException(err);
476 SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] msg_search_message call failed.", GetErrorMessage(r));
478 totalResultCount = msgList.nCount;
480 SysLog(NID_MSG, "Total Search count of messages is [%d]", totalResultCount);
482 for (int index = 0; index < totalResultCount; index++)
484 // get SmsMessage instance
485 SmsMessage* pSmsMessage = _MsgUtil::ConvertSmsMessageN(SMS_MESSAGE_BOX_TYPE_INBOX, msgList.msg_struct_info[index]);
487 pList->Add(*pSmsMessage);
492 delete[] pSearchString;
493 pSearchString = NULL;
496 if (pSenderAddressTemp)
498 delete[] pSenderAddressTemp;
499 pSenderAddressTemp = NULL;
502 msg_release_struct(&searchCon);
503 msg_release_list_struct(&msgList);
510 delete[] pSearchString;
511 pSearchString = NULL;
514 if (pSenderAddressTemp)
516 delete[] pSenderAddressTemp;
517 pSenderAddressTemp = NULL;
522 if (pList->GetCount() > 0)
524 pList->RemoveAll(true);
530 msg_release_struct(&searchCon);
531 msg_release_list_struct(&msgList);
536 Tizen::Base::Collection::IList*
537 _SmsManagerImpl::SearchMessageBoxN(SmsMessageBoxType type, const Tizen::Base::String* pKeyword, int startIndex, int count,
538 int& totalResultCount) const
540 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
541 SysAssertf(__msgHandle > 0, "message handle is invalid.");
543 result r = E_SUCCESS;
544 int err = MSG_SUCCESS;
545 char* pSearchString = NULL;
546 int folderId = MSG_ALLBOX_ID;
547 ArrayList* pList = NULL;
548 msg_struct_list_s msgList;
549 msg_struct_t searchCon = NULL;
553 pList = new (std::nothrow) ArrayList();
554 SysTryCatch(NID_MSG, pList != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed");
557 r = pList->Construct();
558 SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "Failed to construct an ArrayList");
561 folderId = _MsgUtil::GetMsgFolderId(type);
564 searchCon = msg_create_struct(MSG_STRUCT_SEARCH_CONDITION);
565 msg_set_int_value(searchCon, MSG_SEARCH_CONDITION_FOLDERID_INT, folderId);
566 msg_set_int_value(searchCon, MSG_SEARCH_CONDITION_MSGTYPE_INT, MSG_TYPE_SMS);
571 pSearchString = _StringConverter::CopyToCharArrayN(*pKeyword);
572 SysTryCatch(NID_MSG, pSearchString != null, r = E_OUT_OF_MEMORY, r, "Memory allocation failed.");
573 msg_set_str_value(searchCon, MSG_SEARCH_CONDITION_SEARCH_VALUE_STR, pSearchString, strlen(pSearchString));
577 err = msg_search_message(__msgHandle, searchCon, startIndex, count, &msgList);
579 r = ConvertException(err);
580 SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] msg_search_message call failed.", GetErrorMessage(r));
582 totalResultCount = msgList.nCount;
584 SysLog(NID_MSG, "Total Search count of messages is [%d]", totalResultCount);
586 for (int index = 0; index < totalResultCount; index++)
588 SmsMessage* pSmsMessage = null;
590 if (type == SMS_MESSAGE_BOX_TYPE_ALL)
592 err = msg_get_int_value(msgList.msg_struct_info[index], MSG_MESSAGE_FOLDER_ID_INT, &folderId);
597 pSmsMessage = _MsgUtil::ConvertSmsMessageN(SMS_MESSAGE_BOX_TYPE_INBOX, msgList.msg_struct_info[index]);
601 pSmsMessage = _MsgUtil::ConvertSmsMessageN(SMS_MESSAGE_BOX_TYPE_OUTBOX, msgList.msg_struct_info[index]);
605 pSmsMessage = _MsgUtil::ConvertSmsMessageN(SMS_MESSAGE_BOX_TYPE_SENTBOX, msgList.msg_struct_info[index]);
609 //pSmsMessage = _MsgUtil::ConvertSmsMessageN(SMS_MESSAGE_BOX_TYPE_SENTBOX, msgList.msg_struct_info[index]);
613 //pSmsMessage = _MsgUtil::ConvertSmsMessageN(SMS_MESSAGE_BOX_TYPE_SENTBOX, msgList.msg_struct_info[index]);
617 // add the item to the list
618 pList->Add(*pSmsMessage);
622 pSmsMessage = _MsgUtil::ConvertSmsMessageN(type, msgList.msg_struct_info[index]);
623 pList->Add(*pSmsMessage);
629 delete[] pSearchString;
630 pSearchString = NULL;
633 msg_release_struct(&searchCon);
634 msg_release_list_struct(&msgList);
641 if (pList->GetCount() > 0)
643 pList->RemoveAll(true);
651 delete[] pSearchString;
652 pSearchString = NULL;
655 msg_release_struct(&searchCon);
656 msg_release_list_struct(&msgList);
662 _SmsManagerImpl::GetFullText(int messageId) const
664 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
665 SysAssertf(__msgHandle > 0, "message handle is invalid.");
667 result r = E_SUCCESS;
669 msg_struct_t smsMsg = null;
670 msg_struct_t sendOpt = null;
671 int err = MSG_SUCCESS;
672 char msgText[MAX_MSG_TEXT_LEN];
677 smsMsg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
678 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
679 err = msg_get_message(__msgHandle, messageId, smsMsg, sendOpt);
681 r = ConvertException(err);
684 SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] msg_get_message by messageid failed.", GetErrorMessage(r));
687 err = msg_get_str_value(smsMsg, MSG_MESSAGE_SMS_DATA_STR, msgText, MAX_MSG_TEXT_LEN);
688 SysTryCatch(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, r, "sms get message body failed");
692 SysLog(NID_MSG, "Returned Full Text : [%ls]", fullText.GetPointer());
694 msg_release_struct(&sendOpt);
695 msg_release_struct(&smsMsg);
700 msg_release_struct(&sendOpt);
701 msg_release_struct(&smsMsg);
707 _SmsManagerImpl::Send(const SmsMessage& message, const RecipientList& recipientList, bool saveToSentbox)
709 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
710 SysAssertf(__msgHandle > 0, "message handle is invalid.");
712 result r = E_SUCCESS;
713 int err = MSG_SUCCESS;
715 bool saveMsgToSentbox = saveToSentbox;
717 SysLog(NID_MSG, "sending an sms message");
719 msg_struct_t msgReq = msg_create_struct(MSG_STRUCT_REQUEST_INFO);
720 msg_struct_t msgInfo = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);;
721 msg_struct_t msgSendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
723 msg_set_bool_value(msgSendOpt, MSG_SEND_OPT_SETTING_BOOL, true);
724 msg_set_bool_value(msgSendOpt, MSG_SEND_OPT_DELIVER_REQ_BOOL, false);
725 msg_set_bool_value(msgSendOpt, MSG_SEND_OPT_KEEPCOPY_BOOL, saveMsgToSentbox);
727 err = _MsgUtil::GetSmsMessage(msgInfo, message, recipientList);
729 r = ConvertException(err);
730 SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to generate the SMS message.", GetErrorMessage(r));
732 msg_set_struct_handle(msgReq, MSG_REQUEST_MESSAGE_HND, msgInfo);
733 msg_set_struct_handle(msgReq, MSG_REQUEST_SENDOPT_HND, msgSendOpt);
735 if (err == MSG_SUCCESS)
737 err = msg_sms_send_message(__msgHandle, msgReq);
740 r = ConvertException(err);
744 if (_SmsMmsCallbackHandler::GetInstance())
746 msg_get_int_value(msgReq, MSG_REQUEST_REQUESTID_INT, &msgReqId);
747 r = _SmsMmsCallbackHandler::GetInstance()->AddToMessageMap(msgReqId, _MSG_SMS, __pSmsEvent.get());
755 SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to send the SMS message.", GetErrorMessage(r));
758 msg_release_struct(&msgReq);
759 SysLog(NID_MSG, "sending an sms message success");
764 msg_release_struct(&msgReq);
769 _SmsManagerImpl::SetCbsMessageEventListener(ICbsMessageEventListener* pListener)
771 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
772 SysAssertf(__msgHandle > 0, "message handle is invalid.");
774 result r = E_SUCCESS;
775 int err = MSG_SUCCESS;
779 if (__pCbsReceiveEvent)
781 r = __pCbsReceiveEvent->RemoveListener(*__pCbsListener);
782 SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "Failed to reset the cbs message event listener.");
784 __pCbsListener = null;
790 __pCbsListener = pListener;
793 if (!__pCbsReceiveEvent)
795 __pCbsReceiveEvent = new (std::nothrow) _SmsEvent();
796 SysTryCatch(NID_MSG, __pCbsReceiveEvent != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed");
798 r = __pCbsReceiveEvent->Construct(_SMS_EVENT_TYPE_CBS_RECEIVE_RESULT);
799 SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to construct an cbs listener instance");
803 r = __pCbsReceiveEvent->AddListener(*__pCbsListener, true);
804 SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to add cbs listner");
806 err = msg_reg_cb_message_callback(__msgHandle, &_SmsMmsCallbackHandler::IncomingCbsMessageCallback, __isCbsSaveEnabled, null);
807 r = ConvertException(err);
808 SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to set cbs incoming callback");
812 if (_SmsMmsCallbackHandler::GetInstance())
814 _SmsMmsCallbackHandler::GetInstance()->SetCbsAndEtwsUserEvent(_MSG_CBS, __pCbsReceiveEvent);
825 if (__pCbsReceiveEvent)
827 delete __pCbsReceiveEvent;
828 __pCbsReceiveEvent = null;
830 __pCbsListener = null;
836 _SmsManagerImpl::SetEtwsPrimaryNotificationEventListener(IEtwsPrimaryNotificationEventListener* pListener)
838 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
839 SysAssertf(__msgHandle > 0, "message handle is invalid.");
841 result r = E_SUCCESS;
842 int err = MSG_SUCCESS;
846 if (__pEtwsReceiveEvent)
848 r = __pEtwsReceiveEvent->RemoveListener(*__pEtwsListener);
849 SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "Failed to reset the etws primary notification event listener.");
851 __pEtwsListener = null;
857 __pEtwsListener = pListener;
860 if (!__pEtwsReceiveEvent)
862 __pEtwsReceiveEvent = new (std::nothrow) _SmsEvent();
863 SysTryCatch(NID_MSG, __pEtwsReceiveEvent != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed");
865 r = __pEtwsReceiveEvent->Construct(_SMS_EVENT_TYPE_ETWS_RECEIVE_RESULT);
866 SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM,
867 "Failed to construct an etws primary notification event listener instance");
871 r = __pEtwsReceiveEvent->AddListener(*__pEtwsListener, true);
872 SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to add an etws primary notification event listener.");
874 err = msg_reg_cb_message_callback(__msgHandle, &_SmsMmsCallbackHandler::IncomingCbsMessageCallback, __isCbsSaveEnabled, null);
875 r = ConvertException(err);
876 SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM,"Failed to add an etws primary notification event listener.");
880 if (_SmsMmsCallbackHandler::GetInstance())
882 _SmsMmsCallbackHandler::GetInstance()->SetCbsAndEtwsUserEvent(_MSG_ETWS, __pEtwsReceiveEvent);
893 if (__pEtwsReceiveEvent)
895 delete __pEtwsReceiveEvent;
896 __pEtwsReceiveEvent = null;
898 __pEtwsListener = null;
904 _SmsManagerImpl::SetSavingToCbsBoxEnabled(bool enable)
906 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
907 SysAssertf(__msgHandle > 0, "message handle is invalid.");
908 SysTryReturnResult(NID_MSG, __cbsSettingsHandle != NULL, E_SYSTEM, "Cb handle is null");
910 int err = MSG_SUCCESS;
912 err = msg_reg_cb_message_callback(__msgHandle, &_SmsMmsCallbackHandler::IncomingCbsMessageCallback, enable, null);
913 SysTryReturnResult(NID_MSG, err == MSG_SUCCESS, E_SYSTEM, "Failed to set SavingToCbsBoxEnabled option.");
915 __isCbsSaveEnabled = enable;
921 _SmsManagerImpl::IsCbsEnabled(void) const
923 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
924 SysAssertf(__msgHandle > 0, "message handle is invalid.");
925 SysTryReturn(NID_MSG, __cbsSettingsHandle != NULL, false, E_SYSTEM, "Cb handle is null");
927 bool isCbsEnabled = false;
928 int err = MSG_SUCCESS;
930 err = msg_get_bool_value(__cbsSettingsHandle, MSG_CB_RECEIVE_BOOL, &isCbsEnabled);
931 SysTryReturn(NID_MSG, err == MSG_SUCCESS, false, E_SYSTEM, "Failed to set SavingToCbsBoxEnabled option.");
937 _SmsManagerImpl::SetCbsEnabled(bool enable)
939 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
940 SysAssertf(__msgHandle > 0, "message handle is invalid.");
941 SysTryReturnResult(NID_MSG, __cbsSettingsHandle != NULL, E_SYSTEM, "Cb handle is null");
943 int err = MSG_SUCCESS;
944 result r = E_SUCCESS;
946 err = msg_set_bool_value(__cbsSettingsHandle, MSG_CB_RECEIVE_BOOL, enable);
947 SysTryReturnResult(NID_MSG, err == MSG_SUCCESS, E_SYSTEM, "Failed to set cbs enabled.");
949 r = _SmsMmsCallbackHandler::GetInstance()->SaveCbsSettings();
950 SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "Failed to save cbs settings.");
956 _SmsManagerImpl::AddCbsChannel(int from, int to, Tizen::Base::String& name, bool activate)
958 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
959 SysAssertf(__msgHandle > 0, "message handle is invalid.");
960 SysTryReturnResult(NID_MSG, __cbsSettingsHandle != NULL, E_SYSTEM, "Cb handle is null");
962 result r = E_SUCCESS;
965 r = _SmsMmsCallbackHandler::GetInstance()->GetCbsChannelsCount(count);
966 SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to get CB Channel count.");
968 if (CB_CHANNEL_MAX <= count)
970 return E_ALREADY_SET;
974 r = _SmsMmsCallbackHandler::GetInstance()->AddCbsChannel(from, to, name, activate);
975 SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to add a CB Channel.");
981 _SmsManagerImpl::RemoveCbsChannel(int from, int to)
983 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
984 SysAssertf(__msgHandle > 0, "message handle is invalid.");
985 SysTryReturnResult(NID_MSG, __cbsSettingsHandle != NULL, E_SYSTEM, "Cb handle is null");
987 result r = E_SUCCESS;
990 r = _SmsMmsCallbackHandler::GetInstance()->RemoveCbsChannel(from, to);
991 SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to remove a CB Channel.");
997 _SmsManagerImpl::GetCbsChannelN(int from, int to) const
999 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
1000 SysAssertf(__msgHandle > 0, "message handle is invalid.");
1001 SysTryReturn(NID_MSG, __cbsSettingsHandle != null, null, E_SYSTEM, "Cb handle is null.");
1003 result r = E_SUCCESS;
1007 bool isActive = false;
1009 std::unique_ptr<CbsChannel> pCbsChannel;
1014 r = _SmsMmsCallbackHandler::GetInstance()->SearchCbsChannel(from, to, index);
1015 SysTryReturn(NID_MSG, r == E_SUCCESS, null, r, "Failed to find the cb channel.");
1018 r = _SmsMmsCallbackHandler::GetInstance()->GetCbsChannel(index, fromId, toId, channelName, isActive);
1019 SysTryReturn(NID_MSG, r == E_SUCCESS, null, r, "Failed to get the cb channel.");
1022 pCbsChannel.reset(_CbsChannelImpl::GetCbsChannelN(fromId, toId, channelName));
1026 pCbsChannel->Activate();
1029 return pCbsChannel.release();
1032 Tizen::Base::Collection::IList*
1033 _SmsManagerImpl::GetCbsChannelListN(void)
1035 SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet.");
1036 SysAssertf(__msgHandle > 0, "message handle is invalid.");
1037 SysTryReturn(NID_MSG, __cbsSettingsHandle != null, null, E_SYSTEM, "Cb handle is null.");
1039 result r = E_SUCCESS;
1040 unique_ptr<ArrayList, AllElementsDeleter> pList;
1041 int cbChannelCount = 0;
1044 bool isActive = false;
1046 std::unique_ptr<CbsChannel> pCbsChannel;
1050 pList.reset(new (std::nothrow) ArrayList(SingleObjectDeleter));
1051 SysTryReturn(NID_MSG, pList != null, null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1054 r = pList->Construct();
1055 SysTryReturn(NID_MSG, r == E_SUCCESS, null, r, "Failed to construct array list.");
1057 r = _SmsMmsCallbackHandler::GetInstance()->GetCbsChannelsCount(cbChannelCount);
1058 SysTryReturn(NID_MSG, r == E_SUCCESS, null, r, "Failed to get CB Channel count.");
1060 for (int index = 0; index < cbChannelCount; index++)
1063 r = _SmsMmsCallbackHandler::GetInstance()->GetCbsChannel(index, fromId, toId, channelName, isActive);
1064 SysTryReturn(NID_MSG, r == E_SUCCESS, null, r , "Failed to get the cb channel.");
1066 pCbsChannel.reset(_CbsChannelImpl::GetCbsChannelN(fromId, toId, channelName));
1067 if (pCbsChannel && isActive)
1069 _CbsChannelImpl::GetInstance(*pCbsChannel)->SetCbsChannelState(isActive);
1071 pList->Add(*pCbsChannel);
1075 return pList.release();
1079 _SmsManagerImpl::GetInstance(SmsManager& smsManager)
1081 return smsManager.__pImpl;
1084 const _SmsManagerImpl*
1085 _SmsManagerImpl::GetInstance(const SmsManager& smsManager)
1087 return smsManager.__pImpl;
1091 _SmsManagerImpl::ConvertException(int err) const
1093 result r = E_SUCCESS;
1101 case MSG_ERR_INVALID_PARAMETER:
1102 case MSG_ERR_INVALID_MESSAGE:
1103 case MSG_ERR_NULL_POINTER:
1104 case MSG_ERR_NULL_MESSAGE:
1108 case MSG_ERR_MEMORY_ERROR:
1109 r = E_OUT_OF_MEMORY;
1112 case MSG_ERR_SERVER_NOT_READY:
1113 case MSG_ERR_TRANSPORT_ERROR:
1114 case MSG_ERR_COMMUNICATION_ERROR:
1115 r = E_NETWORK_UNAVAILABLE;
1118 case MSG_ERR_NO_SIM:
1119 r = E_DEVICE_UNAVAILABLE;
1122 case MSG_ERR_PLUGIN_TAPI_FAILED:
1134 } } // Tizen::Messaging