adjust log level
[platform/core/messaging/msg-service.git] / utils / MsgUtilFunction.cpp
index 42281f5..0174373 100755 (executable)
  * limitations under the License.
 */
 
+#include <systemd/sd-login.h>
+
 #include "MsgDebug.h"
 #include "MsgContact.h"
+#include "MsgGconfWrapper.h"
+#include "MsgUtilFile.h"
 #include "MsgUtilFunction.h"
+#include "MsgUtilStorage.h"
 
 #include <system_info.h>
+#include <libintl.h>
+#include <locale.h>
+#include <vconf.h>
+#include <ctype.h>
+#include <aul.h>
+#include <aul_svc.h>
+#include <gio/gio.h>
+
+typedef struct _msg_launch_app_data {
+       char *app_id;
+       bundle *bundle_data;
+} msg_launch_app_data;
+
+#define DEFAULT_MIN_MATCH_DIGIT 8
+
+#define SYSPOPUP_BUS_NAME "org.tizen.DevicePolicyManager"
+#define SYSPOPUP_OBJECT_PATH "/org/tizen/DevicePolicyManager/Syspopup"
+#define SYSPOPUP_INTERFACE "org.tizen.DevicePolicyManager.Syspopup"
+#define SYSPOPUP_METHOD_SHOW "show"
+
+enum _FEATURE_INDEX_E {
+       FEATURE_INDEX_SMS = 0,
+       FEATURE_INDEX_MMS = 1,
+};
+
+static bool b_feature_cache_flag = false;
+static bool b_feature_support[] = {
+               [FEATURE_INDEX_SMS] = false,
+               [FEATURE_INDEX_MMS] = false,
+};
+
+static int dpm_policy_enable[] = {
+               [MSG_UNKNOWN_TYPE] = 0,
+               [MSG_SMS_TYPE] = 1,
+               [MSG_MMS_TYPE] = 1,
+};
+
+#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+static int phonenumberMinMatchDigit = -1;
+#endif
 
-bool b_feature_check_flag = false;
-bool b_feature_telephony = false;
-bool b_feature_telephony_mms = false;
+pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER;
 
- /*==================================================================================================
+/*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
 
@@ -32,27 +75,50 @@ bool MsgCheckFeatureSupport(const char *feature_name)
 {
        bool result = false;
 
-       if (b_feature_check_flag == false) {
-               system_info_get_platform_bool(MSG_TELEPHONY_FEATURE, &b_feature_telephony);
-               system_info_get_platform_bool(MSG_TELEPHONY_MMS_FEATURE, &b_feature_telephony_mms);
-               MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_FEATURE, b_feature_telephony);
-               MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_MMS_FEATURE, b_feature_telephony_mms);
+       if (b_feature_cache_flag == false) {
+               if (system_info_get_platform_bool(MSG_TELEPHONY_SMS_FEATURE, &b_feature_support[FEATURE_INDEX_SMS]) != SYSTEM_INFO_ERROR_NONE)
+                       MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_SMS_FEATURE);
+
+               if (system_info_get_platform_bool(MSG_TELEPHONY_MMS_FEATURE, &b_feature_support[FEATURE_INDEX_MMS]) != SYSTEM_INFO_ERROR_NONE)
+                       MSG_WARN("fail to system_info_get_platform_bool [%s]", MSG_TELEPHONY_MMS_FEATURE);
 
-               b_feature_check_flag = true;
+               MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_SMS_FEATURE, b_feature_support[FEATURE_INDEX_SMS]);
+               MSG_INFO("[%s] feature is [%d]", MSG_TELEPHONY_MMS_FEATURE, b_feature_support[FEATURE_INDEX_MMS]);
+
+               b_feature_cache_flag = true;
        }
 
-       if (!g_strcmp0(feature_name, MSG_TELEPHONY_FEATURE)) {
-               result = b_feature_telephony;
+       if (!g_strcmp0(feature_name, MSG_TELEPHONY_SMS_FEATURE)) {
+               result = b_feature_support[FEATURE_INDEX_SMS];
        } else if (!g_strcmp0(feature_name, MSG_TELEPHONY_MMS_FEATURE)) {
-               result = b_feature_telephony_mms;
-       } else {
-               result = false;
+               result = b_feature_support[FEATURE_INDEX_MMS];
        }
 
        return result;
 }
 
-// Encoders
+
+int MsgContactGetMinMatchDigit()
+{
+#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+       if (phonenumberMinMatchDigit <= 0) {
+               if (MsgSettingGetInt(VCONFKEY_CONTACTS_SVC_PHONENUMBER_MIN_MATCH_DIGIT, &phonenumberMinMatchDigit) != MSG_SUCCESS) {
+                       MSG_INFO("MsgSettingGetInt() is failed");
+               }
+               MSG_DEBUG("phonenumberMinMatchDigit [%d]", phonenumberMinMatchDigit);
+
+               if (phonenumberMinMatchDigit < 1) {
+                       phonenumberMinMatchDigit = DEFAULT_MIN_MATCH_DIGIT;
+               }
+       }
+
+       return phonenumberMinMatchDigit;
+#else
+       return DEFAULT_MIN_MATCH_DIGIT;
+#endif
+}
+
+/* Encoders */
 int MsgEncodeCountInfo(MSG_COUNT_INFO_S *pCountInfo, char **ppDest)
 {
        int dataSize = 0;
@@ -83,8 +149,7 @@ int MsgEncodeRecipientList(MSG_RECIPIENTS_LIST_S *pRecipientList, char **ppDest)
        memcpy(p, &count, sizeof(int));
        p = (void*)((char*)p + sizeof(int));
 
-       for (int i = 0; i < count; i++)
-       {
+       for (int i = 0; i < count; i++) {
                memcpy(p, &(pRecipientList->recipientAddr[i]), sizeof(MSG_ADDRESS_INFO_S));
                p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
        }
@@ -191,8 +256,7 @@ int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest)
 
        msg_struct_s *folder_info = NULL;
 
-       for (int i = 0; i < count; i++)
-       {
+       for (int i = 0; i < count; i++) {
                folder_info = (msg_struct_s *)pFolderList->msg_struct_info[i];
                memcpy(p, folder_info->data, sizeof(MSG_FOLDER_INFO_S));
                p = (void*)((char*)p + sizeof(MSG_FOLDER_INFO_S));
@@ -218,8 +282,7 @@ int MsgEncodeFilterList(msg_struct_list_s *pFilterList, char **ppDest)
 
        msg_struct_s *filter_info = NULL;
 
-       for (int i = 0; i < count; i++)
-       {
+       for (int i = 0; i < count; i++) {
                filter_info = (msg_struct_s *)pFilterList->msg_struct_info[i];
                memcpy(p, filter_info->data, sizeof(MSG_FILTER_S));
                p = (void*)((char*)p + sizeof(MSG_FILTER_S));
@@ -245,22 +308,6 @@ int MsgEncodeFilterFlag(bool *pSetFlag, char **ppDest)
 }
 
 
-int MsgEncodeMsgType(MSG_MESSAGE_TYPE_S *pMsgType, char **ppDest)
-{
-       int dataSize = 0;
-
-       dataSize = (sizeof(MSG_MESSAGE_TYPE_S));
-
-       *ppDest = (char*)new char[dataSize];
-
-       void* p = (void*)*ppDest;
-
-       memcpy(p, pMsgType, dataSize);
-
-       return dataSize;
-}
-
-
 int MsgEncodeThreadViewList(msg_struct_list_s *pThreadViewList, char **ppDest)
 {
        int count = 0, dataSize = 0;
@@ -278,8 +325,7 @@ int MsgEncodeThreadViewList(msg_struct_list_s *pThreadViewList, char **ppDest)
 
        msg_struct_s *thread_info = NULL;
 
-       for (int i = 0; i < count; i++)
-       {
+       for (int i = 0; i < count; i++) {
                thread_info = (msg_struct_s *)pThreadViewList->msg_struct_info[i];
                memcpy(p, thread_info->data, sizeof(MSG_THREAD_VIEW_S));
                p = (void*)((char*)p + sizeof(MSG_THREAD_VIEW_S));
@@ -304,8 +350,7 @@ int MsgEncodeConversationViewList(msg_struct_list_s *pConvViewList, char **ppDes
        memcpy(p, &count, sizeof(int));
        p = (void*)((char*)p + sizeof(int));
 
-       for (int i = 0; i < count; i++)
-       {
+       for (int i = 0; i < count; i++) {
                memcpy(p, &(pConvViewList->msg_struct_info[i]), sizeof(msg_struct_list_s));
                p = (void*)((char*)p + sizeof(msg_struct_list_s));
        }
@@ -402,6 +447,25 @@ int MsgEncodeStorageChangeData(const msg_storage_change_type_t storageChangeType
 }
 
 
+int MsgEncodeThreadChangeData(const msg_storage_change_type_t storageChangeType, const msg_thread_id_t threadId, char **ppDest)
+{
+       int dataSize = 0;
+
+       dataSize = sizeof(msg_storage_change_type_t) + sizeof(msg_thread_id_t);
+
+       *ppDest = (char*)new char[dataSize];
+
+       void* p = (void*)*ppDest;
+
+       memcpy(p, &storageChangeType, sizeof(msg_storage_change_type_t));
+       p = (void*)((char*)p + sizeof(msg_storage_change_type_t));
+
+       memcpy(p, &threadId, sizeof(msg_thread_id_t));
+
+       return dataSize;
+}
+
+
 int MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
 {
        int dataSize = 0;
@@ -443,7 +507,7 @@ int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, ch
 
        memcpy(p, &count, sizeof(int));
 
-       p = (void*)((int)p + sizeof(int));
+       p = (void*)((char*)p + sizeof(int));
 
        memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count);
 
@@ -485,8 +549,7 @@ int MsgEncodeThreadInfo(MSG_THREAD_VIEW_S *pThreadInfo, char **ppDest)
 }
 
 
-
-// Decoders
+/* Decoders */
 void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId)
 {
        memcpy(pMsgId, pSrc, sizeof(msg_message_id_t));
@@ -516,7 +579,7 @@ void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo)
        pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
        memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
 
-       for (int i=0; i<pMsgInfo->nAddressCnt; i++) {
+       for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
                memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
        }
 }
@@ -532,14 +595,13 @@ void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_I
 
        pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S);
 
-
        if(pMsgInfo->nAddressCnt > 0) {
                pMsgInfo->addressList = NULL;
 
                pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
                memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
 
-               for (int i=0; i<pMsgInfo->nAddressCnt; i++) {
+               for (int i = 0; i < pMsgInfo->nAddressCnt; i++) {
                        memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
                }
        }
@@ -553,13 +615,12 @@ void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
        memcpy(&count, pSrc, sizeof(int));
        pSrc = pSrc + sizeof(int);
 
-       pRecipientList->recipientCnt= count;
+       pRecipientList->recipientCnt = count;
        pRecipientList->recipientAddr = (MSG_ADDRESS_INFO_S*)new char[sizeof(MSG_ADDRESS_INFO_S)*count];
 
        MSG_ADDRESS_INFO_S* pInfoTmp = pRecipientList->recipientAddr;
 
-       for (int i = 0; i < count; i++)
-       {
+       for (int i = 0; i < count; i++) {
                memcpy(pInfoTmp, pSrc, sizeof(MSG_ADDRESS_INFO_S));
                pSrc = pSrc + sizeof(MSG_ADDRESS_INFO_S);
                pInfoTmp++;
@@ -574,15 +635,16 @@ void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
        memcpy(&count, pSrc, sizeof(int));
        pSrc = pSrc + sizeof(int);
 
-       if( count > 0 )
-       {
+       if( count > 0 ) {
                pFolderList->nCount = count;
                pFolderList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(msg_struct_t));
-
+               if (pFolderList->msg_struct_info == NULL) {
+                       pFolderList->nCount = 0;
+                       return;
+               }
                msg_struct_s *pInfoTmp = NULL;
 
-               for (int i = 0; i < count; i++)
-               {
+               for (int i = 0; i < count; i++) {
                        pFolderList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
                        pInfoTmp = (msg_struct_s *)pFolderList->msg_struct_info[i];
                        pInfoTmp->type = MSG_STRUCT_FOLDER_INFO;
@@ -590,9 +652,7 @@ void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
                        memcpy(pInfoTmp->data, pSrc, sizeof(MSG_FOLDER_INFO_S));
                        pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S);
                }
-       }
-       else if ( count == 0 )
-       {
+       } else if ( count == 0 ) {
                pFolderList->nCount = count;
                pFolderList->msg_struct_info = NULL;
        }
@@ -606,15 +666,18 @@ void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
        memcpy(&count, pSrc, sizeof(int));
        pSrc = pSrc + sizeof(int);
 
-       if( count > 0 )
-       {
+       if( count > 0 ) {
                pFilterList->nCount = count;
                pFilterList->msg_struct_info = (msg_struct_t *)calloc(count, sizeof(MSG_FILTER_S *));
 
+               if (pFilterList->msg_struct_info == NULL) {
+                       pFilterList->nCount = 0;
+                       return;
+               }
+
                msg_struct_s *pStructTmp = NULL;
 
-               for (int i = 0; i < count; i++)
-               {
+               for (int i = 0; i < count; i++) {
                        pFilterList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
                        pStructTmp = (msg_struct_s *)pFilterList->msg_struct_info[i];
                        pStructTmp->type = MSG_STRUCT_FILTER;
@@ -622,13 +685,10 @@ void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
                        memcpy(pStructTmp->data, pSrc, sizeof(MSG_FILTER_S));
                        pSrc = pSrc + sizeof(MSG_FILTER_S);
                }
-       }
-       else if ( count == 0 )
-       {
+       } else if ( count == 0 ) {
                pFilterList->nCount = count;
                pFilterList->msg_struct_info = NULL;
        }
-
 }
 
 
@@ -689,7 +749,6 @@ void MsgDecodeReportStatus(char *pSrc,  msg_struct_list_s *report_list)
 
        msg_struct_t *report_status =  (msg_struct_t *)new char[sizeof(msg_struct_t)*count];
        for (int i = 0; i < count; i++) {
-
                msg_struct_s *report_status_item = new msg_struct_s;
                report_status_item->type = MSG_STRUCT_REPORT_STATUS_INFO;
                report_status_item->data = new MSG_REPORT_STATUS_INFO_S;
@@ -721,7 +780,7 @@ void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo)
        memcpy(pThreadInfo, pSrc, sizeof(MSG_THREAD_VIEW_S));
 }
 
-// Event Encoder
+/* Event Encoder */
 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent)
 {
        MSG_EVENT_S* pMsgEvent = NULL;
@@ -781,7 +840,6 @@ int msg_verify_email(const char *raw)
        }
 
        for (int i = 0; raw[i]; i++) {
-
                if (raw[i] == '@') {
                        onlyNum = false;
 
@@ -821,14 +879,12 @@ char* msg_clean_country_code(char *src)
 {
        int ret = 1;
 
-       switch (src[ret++]-'0')
-       {
+       switch (src[ret++]-'0') {
                case 1:
                case 7:
                        break;
                case 2:
-                       switch (src[ret++]-'0')
-                       {
+                       switch (src[ret++]-'0') {
                                case 0:
                                case 7:
                                        break;
@@ -848,8 +904,7 @@ char* msg_clean_country_code(char *src)
                        }
                        break;
                case 3:
-                       switch (src[ret++]-'0')
-                       {
+                       switch (src[ret++]-'0') {
                                case 0:
                                case 1:
                                case 2:
@@ -869,8 +924,7 @@ char* msg_clean_country_code(char *src)
                        }
                        break;
                case 4:
-                       switch (src[ret++]-'0')
-                       {
+                       switch (src[ret++]-'0') {
                                case 0:
                                case 1:
                                case 3:
@@ -890,8 +944,7 @@ char* msg_clean_country_code(char *src)
                        }
                        break;
                case 5:
-                       switch (src[ret++]-'0')
-                       {
+                       switch (src[ret++]-'0') {
                                case 1:
                                case 2:
                                case 3:
@@ -911,8 +964,7 @@ char* msg_clean_country_code(char *src)
                        }
                        break;
                case 6:
-                       switch (src[ret++]-'0')
-                       {
+                       switch (src[ret++]-'0') {
                                case 0:
                                case 1:
                                case 2:
@@ -932,8 +984,7 @@ char* msg_clean_country_code(char *src)
                        }
                        break;
                case 8:
-                       switch (src[ret++]-'0')
-                       {
+                       switch (src[ret++]-'0') {
                                case 1:
                                case 2:
                                case 4:
@@ -953,8 +1004,7 @@ char* msg_clean_country_code(char *src)
                        }
                        break;
                case 9:
-                       switch (src[ret++]-'0')
-                       {
+                       switch (src[ret++]-'0') {
                                case 0:
                                case 1:
                                case 2:
@@ -1000,6 +1050,28 @@ char* msg_normalize_number(char *src)
 }
 
 
+char *getTranslateText(const char *pkg_name, const char *locale_dir, const char *text)
+{
+       char *notiMsg = NULL;
+       char *lang = NULL;
+
+       lang = vconf_get_str(VCONFKEY_LANGSET);
+
+       setlocale(LC_MESSAGES, lang);
+
+       bindtextdomain(pkg_name, locale_dir);
+
+       notiMsg = dgettext(pkg_name, text);
+
+       if (lang) {
+               free(lang);
+               lang = NULL;
+       }
+
+       return g_strdup(notiMsg);
+}
+
+
 msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
 {
        char sql[128];
@@ -1013,26 +1085,12 @@ msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
        else
                strncpy(order, "DESC", 5);
 
-       //contacts-service is not used for gear
-#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
-       int nameOrder = MsgGetContactNameOrder();
-#else
-       int nameOrder = 0;
-#endif // MSG_CONTACTS_SERVICE_NOT_SUPPORTED
-
-       switch (pSortRule->sortType)
-       {
+       switch (pSortRule->sortType) {
                case MSG_SORT_BY_DISPLAY_FROM :
-                       if (nameOrder == 0)
-                               snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
-                       else
-                               snprintf(sql, sizeof(sql), "ORDER BY B.LAST_NAME %s, B.FIRST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
+                       snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
                        break;
                case MSG_SORT_BY_DISPLAY_TO :
-                       if (nameOrder == 0)
-                               snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
-                       else
-                               snprintf(sql, sizeof(sql), "ORDER BY B.LAST_NAME %s, B.FIRST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
+                       snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
                        break;
                case MSG_SORT_BY_DISPLAY_TIME :
                        snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
@@ -1047,10 +1105,7 @@ msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
                        snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
                        break;
                case MSG_SORT_BY_THREAD_NAME :
-                       if (nameOrder == 0)
-                               snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
-                       else
-                               snprintf(sql, sizeof(sql), "ORDER BY LAST_NAME %s, FIRST_NAME %s;", order, order);
+                       snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
                        break;
                case MSG_SORT_BY_THREAD_DATE :
                        snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
@@ -1075,3 +1130,266 @@ bool msg_is_valid_email(char *pAddress)
                return false;
        return true;
 }
+
+msg_error_t msg_write_text_to_msg_info(MSG_MESSAGE_INFO_S *pMsgInfo, char *text)
+{
+       if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
+               pMsgInfo->bTextSms = false;
+
+               /* Save Message Data into File */
+               char fileName[MSG_FILENAME_LEN_MAX+1];
+               memset(fileName, 0x00, sizeof(fileName));
+
+               if(MsgCreateFileName(fileName) == false) {
+                       MSG_DEBUG("MsgCreateFileName error");
+                       return MSG_ERR_STORAGE_ERROR;
+               }
+
+               MSG_SEC_DEBUG("Save text into file : size[%d] name[%s]", pMsgInfo->dataSize, fileName);
+
+               if (MsgWriteIpcFile(fileName, text, pMsgInfo->dataSize) == false) {
+                       MSG_DEBUG("MsgWriteIpcFile error");
+                       return MSG_ERR_STORAGE_ERROR;
+               }
+
+               memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
+               strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
+       } else {
+               pMsgInfo->bTextSms = true;
+
+               memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
+               memcpy(pMsgInfo->msgText, text, pMsgInfo->dataSize);
+       }
+
+       return MSG_SUCCESS;
+}
+
+/* change illegal filename character to '_' */
+void msg_replace_available_file_name(char *fileName)
+{
+       int idx = 0;
+       int len = 0;
+       bool is_converted = false;
+
+       if (fileName) {
+               len = strlen(fileName);
+
+               while (fileName[idx] != 0) {
+                       if (idx >= len) {
+                               MSG_WARN("idx : %d, len : %d", idx, len);
+                               break;
+                       }
+
+                       if (fileName[idx] == '\\' || fileName[idx] == '/' || fileName[idx] == '?' || fileName[idx] == '%' || fileName[idx] == '*' ||
+                               fileName[idx] == ':' || fileName[idx] == '|' || fileName[idx] == '"' || fileName[idx] == '<' || fileName[idx] == '>') {
+                               fileName[idx++] = '_';
+                               is_converted = true;
+                       } else {
+                               idx++;
+                       }
+               }
+       }
+
+       if (is_converted)
+               MSG_SEC_DEBUG("converted filename : [%s]", fileName);
+}
+
+/* change character ' ' to '_' */
+void msg_replace_space_char(char *pszText)
+{
+       if (!pszText) {
+               MSG_ERR("pszText is NULL");
+               return;
+       }
+
+       char *spaceCharPtr = strchr(pszText, ' ');
+
+       while (spaceCharPtr) {
+               *spaceCharPtr = '_';
+               spaceCharPtr = strchr(pszText, ' ');
+       }
+}
+
+/* change non-ascii character to underscore */
+gchar * msg_replace_non_ascii_char(const gchar *pszText, gunichar replacementChar)
+{
+       if (!pszText) {
+               MSG_ERR(" msg_replace_non_ascii_char error : pszText is NULL");
+               return NULL;
+       }
+       gchar *res;
+       gsize result_len = 0;
+       const gchar *p;
+       result_len = g_utf8_strlen(pszText, -1) + 1; /* +1 for malloc of non-terminating chracter */
+       res = (gchar *)g_malloc (result_len * sizeof (gchar));
+       int i = 0;
+       for (p = pszText, i = 0; *p != '\0'; p = g_utf8_next_char(p), i++) {
+               res[i] = isascii(g_utf8_get_char(p)) ? *p : replacementChar;
+       }
+       res[i] = '\0';
+       return res;
+}
+
+
+static int __find_login_user(uid_t *uid)
+{
+       uid_t *uids = NULL;
+
+       int uids_len = sd_get_active_uids(&uids);
+       if (uids == NULL)
+               return -1;
+
+       if (uids_len != 1) {
+               free(uids);
+               return -1;
+       }
+
+       *uid = uids[0];
+
+       free(uids);
+       return 0;
+}
+
+
+uid_t msg_get_login_user()
+{
+       uid_t uid = -1;
+
+       if (__find_login_user(&uid) < 0) {
+               MSG_WARN("Cannot find login user");
+       }
+
+       MSG_DEBUG("login user id [%d]", uid);
+
+       return uid;
+}
+
+
+void* _msg_launch_app(void *data)
+{
+       pthread_mutex_lock(&mx);
+       if (data) {
+               msg_launch_app_data *ad = (msg_launch_app_data *)data;
+               int ret = aul_launch_app_for_uid(ad->app_id, ad->bundle_data, msg_get_login_user());
+               if (ret <= 0) {
+                       MSG_ERR("aul_launch_app_for_uid() is failed : %d", ret);
+               }
+
+               g_free(ad->app_id);
+               bundle_free(ad->bundle_data);
+               g_free(ad);
+       }
+       pthread_mutex_unlock(&mx);
+
+       return NULL;
+}
+
+msg_error_t msg_launch_app(const char *app_id, bundle *bundle_data)
+{
+       msg_launch_app_data *data = (msg_launch_app_data *)calloc(1, sizeof(msg_launch_app_data));
+       if (data == NULL) {
+               MSG_ERR("Memory alloc failed!");
+               return MSG_ERR_MEMORY_ERROR;
+       }
+
+       data->app_id = g_strdup(app_id);
+       data->bundle_data = bundle_dup(bundle_data);
+       pthread_t thd;
+
+       if (pthread_create(&thd, NULL, &_msg_launch_app, data) < 0) {
+               MSG_ERR("pthread_create() error");
+       }
+
+       pthread_detach(thd);
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t msg_aul_svc_set_operation(bundle *bundle_data, const char *operation)
+{
+       int ret = aul_svc_set_operation(bundle_data, operation);
+       if (ret < 0) {
+               MSG_ERR("aul_svc_set_operation() is failed : %d", ret);
+               return MSG_ERR_UNKNOWN;
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t msg_aul_svc_set_uri(bundle *bundle_data, char *uri)
+{
+       int ret = aul_svc_set_uri(bundle_data, uri);
+       if (ret < 0) {
+               MSG_ERR("aul_svc_set_uri() is failed : %d", ret);
+               return MSG_ERR_UNKNOWN;
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+void msg_set_dpm_policy(int type, int state)
+{
+       dpm_policy_enable[type] = state;
+}
+
+
+bool msg_check_dpm_policy(int type)
+{
+       return dpm_policy_enable[MSG_SMS_TYPE];
+//     return dpm_policy_enable[type];
+}
+
+
+void msg_syspopup_message(bool is_sending)
+{
+       MSG_INFO("popup toast for dpm restriction. is_sending [%d]", is_sending);
+
+       GDBusConnection *connection = NULL;
+       GDBusProxy *dbus_proxy = NULL;
+       GVariant *result = NULL;
+       GError *error = NULL;
+
+       connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (error) {
+               MSG_ERR("Connecting to system bus failed: %s\n", error->message);
+               goto _DBUS_ERROR;
+       }
+
+       dbus_proxy = g_dbus_proxy_new_sync(connection, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                                                               SYSPOPUP_BUS_NAME, SYSPOPUP_OBJECT_PATH, SYSPOPUP_INTERFACE, NULL, &error);
+       if (error) {
+               MSG_ERR("Connecting to proxy failed: %s\n", error->message);
+               goto _DBUS_ERROR;
+       }
+
+       result = g_dbus_proxy_call_sync(dbus_proxy, SYSPOPUP_METHOD_SHOW,
+                                                       g_variant_new("(s)", is_sending ? "message-sending" : "message-retrieving"),
+                                                       G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (error) {
+               MSG_ERR("invoking proxy call failed: %s\n", error->message);
+               goto _DBUS_ERROR;
+       }
+
+_DBUS_ERROR:
+       if (error) {
+               g_error_free(error);
+               error = NULL;
+       }
+
+       if (connection) {
+               g_object_unref(connection);
+               connection = NULL;
+       }
+
+       if (dbus_proxy) {
+               g_object_unref(dbus_proxy);
+               dbus_proxy = NULL;
+       }
+
+       if (result) {
+               g_object_unref(result);
+               result = NULL;
+       }
+}