modify msg-service to support dpm feature 87/76487/12 accepted/tizen/common/20160805.125847 accepted/tizen/ivi/20160808.080504 accepted/tizen/mobile/20160808.080428 accepted/tizen/wearable/20160808.080452 submit/tizen/20160805.024428
authorKyeonghun Lee <kh9090.lee@samsung.com>
Fri, 24 Jun 2016 05:37:38 +0000 (14:37 +0900)
committerKyeonghun Lee <kh9090.lee@samsung.com>
Fri, 5 Aug 2016 02:33:32 +0000 (11:33 +0900)
Change-Id: I43a7d5436d57700a56c70cbbdb85bb8a34e2c2d4
Signed-off-by: Kyeonghun Lee <kh9090.lee@samsung.com>
19 files changed:
config/msg-service-db.sql
framework/deliver-handler/MsgDeliverHandler.cpp
framework/main.cpp
framework/storage-handler/MsgStorageManager.cpp
framework/storage-handler/MsgStorageMessage.cpp
framework/submit-handler/MsgSubmitHandler.cpp
framework/transaction-manager/MsgCmdHandlerTransport.cpp
include/common/MsgInternalTypes.h
include/framework/MsgStorageHandler.h
include/mapi/msg_types.h
include/utils/MsgUtilFunction.h
mapi/msg_message.cpp
mapi/msg_storage.cpp
packaging/msg-service.spec
plugin/mms_plugin/MmsPluginMain.cpp
proxy/MsgHandleControl.cpp
utils/CMakeLists.txt
utils/MsgUtilFunction.cpp
utils/MsgUtilStorage.cpp

index a508b79..716d46b 100755 (executable)
@@ -1,4 +1,4 @@
-PRAGMA user_version=1;
+PRAGMA user_version=2;
 
 CREATE TABLE MSG_CONVERSATION_TABLE
 (
@@ -65,6 +65,7 @@ CREATE TABLE MSG_MESSAGE_TABLE
        ATTACHMENT_COUNT INTEGER DEFAULT 0 ,
        SIM_INDEX INTEGER DEFAULT 0 ,
        SIM_IMSI TEXT ,
+       DPM_RESTRICTED INTERGER DEFAULT 0 ,
 
        FOREIGN KEY (CONV_ID) REFERENCES MSG_CONVERSATION_TABLE (CONV_ID) ,
        FOREIGN KEY (FOLDER_ID) REFERENCES MSG_FOLDER_TABLE (FOLDER_ID)
index 268e269..633025a 100755 (executable)
@@ -285,6 +285,13 @@ msg_error_t MsgHandleSMS(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti, bool *bO
 #endif
        }
 
+       if (msg_check_dpm_policy(pMsgInfo->msgType.mainType) == false) {
+               MSG_DEBUG("Messaging is restricted by DPM policy.");
+               pMsgInfo->bRestricted = true;
+               *pSendNoti = false;
+               *bOnlyNoti = false;
+       }
+
        if (pMsgInfo->msgType.subType == MSG_NORMAL_SMS) {
                MSG_DEBUG("Add Normal Message");
                err = MsgStoAddMessage(pMsgInfo, &send_opt);
@@ -578,6 +585,12 @@ msg_error_t MsgHandleMMS(MSG_MESSAGE_INFO_S *pMsgInfo,  bool *pSendNoti)
                        }
                }
 
+               if (msg_check_dpm_policy(pMsgInfo->msgType.mainType) == false) {
+                       MSG_DEBUG("Messaging is restricted by DPM policy.");
+                       pMsgInfo->bRestricted = true;
+                       *pSendNoti = false;
+               }
+
                err = MsgStoAddMessage(pMsgInfo, NULL);
 
                if (err != MSG_SUCCESS) {
index c0550b4..73b6347 100755 (executable)
@@ -33,6 +33,7 @@
 #include "MsgStorageTypes.h"
 #include "MsgCmdHandler.h"
 #include "MsgUtilFile.h"
+#include "MsgUtilFunction.h"
 #include "MsgUtilStorage.h"
 #include "MsgNotificationWrapper.h"
 
@@ -55,6 +56,8 @@ void* InitMsgServer(void*)
 
        MsgInitCallStatusManager();
 
+       msg_init_dpm_policy();
+
        try {
                /* storage handler initialize */
                err = MsgStoInitDB(false);
@@ -150,6 +153,8 @@ int main(void)
 
        MsgDeInitCallStatusManager();
 
+       msg_deinit_dpm_policy();
+
        return 0;
 }
 
index 2c5f9cd..c8e31b1 100755 (executable)
@@ -34,7 +34,7 @@
 #include "MsgPluginManager.h"
 #include "MsgStorageHandler.h"
 
-#define MSG_DB_VERSION 1
+#define MSG_DB_VERSION 2
 
 /*==================================================================================================
                                      VARIABLES
@@ -99,6 +99,25 @@ void MsgUpdateDBtoVer1()
 }
 
 
+void MsgUpdateDBtoVer2()
+{
+       MsgDbHandler *dbHandle = getDbHandle();
+       msg_error_t err = MSG_SUCCESS;
+       char sqlQuery[MAX_QUERY_LEN+1] = {0};
+       snprintf(sqlQuery, sizeof(sqlQuery),
+                       "ALTER TABLE %s "
+                       "ADD (DPM_RESTRICTED INTEGER DEFAULT 0);",
+                       MSGFW_MESSAGE_TABLE_NAME);
+
+       err = dbHandle->execQuery(sqlQuery);
+
+       if (err == MSG_SUCCESS)
+               MSG_SEC_DEBUG("SUCCESS : alter %s.", MSGFW_MESSAGE_TABLE_NAME);
+       else
+               MSG_SEC_DEBUG("FAIL : create %s [%d].", MSGFW_MESSAGE_TABLE_NAME, err);
+}
+
+
 void MsgStoUpdateDBVersion()
 {
        MsgDbHandler *dbHandle = getDbHandle();
@@ -150,6 +169,9 @@ msg_error_t MsgStoDBVerCheck()
        case 0 :
                MsgUpdateDBtoVer1();
                /* no break */
+       case 1 :
+               MsgUpdateDBtoVer2();
+               /* no break */
        default :
                MsgStoUpdateDBVersion();
                /* no break */
index 6886f74..b1275f6 100755 (executable)
@@ -34,6 +34,7 @@
 #include "MsgStorageHandler.h"
 #include "MsgNotificationWrapper.h"
 #include "MsgDevicedWrapper.h"
+#include "MsgTransManager.h"
 
 using namespace std;
 
@@ -135,10 +136,10 @@ msg_error_t MsgStoAddMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pS
        /* Add Message */
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d, %d, %u, %d, %d, %d, %d, %d, %d, %d, %d, ?, '', '', ?, 0, %d, '%s');",
+       snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d, %d, %u, %d, %d, %d, %d, %d, %d, %d, %d, ?, '', '', ?, 0, %d, '%s', %d);",
                        MSGFW_MESSAGE_TABLE_NAME, rowId, convId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType,
                        (unsigned int)pMsg->displayTime, pMsg->dataSize, pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction,
-                       0, pMsg->bBackup, pMsg->sim_idx, imsi);
+                       0, pMsg->bBackup, pMsg->sim_idx, imsi, pMsg->bRestricted);
 
        MSG_DEBUG("QUERY : %s", sqlQuery);
 
@@ -1987,7 +1988,7 @@ msg_error_t MsgStoGetMessage(msg_message_id_t msgId, MSG_MESSAGE_INFO_S *pMsg, M
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, \
                        SUB_TYPE, DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, \
-                       BACKUP, PRIORITY, MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, THUMB_PATH, SIM_INDEX \
+                       BACKUP, PRIORITY, MSG_DIRECTION, DPM_RESTRICTED, SCHEDULED_TIME, SUBJECT, MSG_TEXT, THUMB_PATH, SIM_INDEX \
                        FROM %s WHERE MSG_ID = %d;",
                        MSGFW_MESSAGE_TABLE_NAME, msgId);
 
@@ -2011,8 +2012,9 @@ msg_error_t MsgStoGetMessage(msg_message_id_t msgId, MSG_MESSAGE_INFO_S *pMsg, M
                pMsg->bBackup = dbHandle->columnInt(11);
                pMsg->priority = dbHandle->columnInt(12);
                pMsg->direction = dbHandle->columnInt(13);
+               pMsg->bRestricted = dbHandle->columnInt(14);
 
-               strncpy(pMsg->subject, (char *)dbHandle->columnText(15), MAX_SUBJECT_LEN);
+               strncpy(pMsg->subject, (char *)dbHandle->columnText(16), MAX_SUBJECT_LEN);
 
                /* Temp_File_Handling */
                if (pMsg->msgType.mainType == MSG_SMS_TYPE || pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
@@ -2020,7 +2022,7 @@ msg_error_t MsgStoGetMessage(msg_message_id_t msgId, MSG_MESSAGE_INFO_S *pMsg, M
                                char msgData[pMsg->dataSize+1];
                                memset(msgData, 0x00, sizeof(msgData));
 
-                               strncpy(msgData, (char *)dbHandle->columnText(16), pMsg->dataSize);
+                               strncpy(msgData, (char *)dbHandle->columnText(17), pMsg->dataSize);
 
                                /* Save Message Data into File */
                                char fileName[MSG_FILENAME_LEN_MAX+1];
@@ -2043,7 +2045,7 @@ msg_error_t MsgStoGetMessage(msg_message_id_t msgId, MSG_MESSAGE_INFO_S *pMsg, M
                                pMsg->bTextSms = false;
                        } else {
                                memset(pMsg->msgText, 0x00, sizeof(pMsg->msgText));
-                               strncpy(pMsg->msgText, (char *)dbHandle->columnText(16), pMsg->dataSize);
+                               strncpy(pMsg->msgText, (char *)dbHandle->columnText(17), pMsg->dataSize);
 
                                /* For WAP PUSH SI Message */
                                if (pMsg->msgType.subType == MSG_WAP_SI_SMS) {
@@ -2057,15 +2059,25 @@ msg_error_t MsgStoGetMessage(msg_message_id_t msgId, MSG_MESSAGE_INFO_S *pMsg, M
                        }
                } else {
                        if (dbHandle->columnText(16) != NULL)
-                               strncpy(pMsg->msgText, (char *)dbHandle->columnText(16), MAX_MSG_TEXT_LEN);
+                               strncpy(pMsg->msgText, (char *)dbHandle->columnText(17), MAX_MSG_TEXT_LEN);
                }
 
                /* thumbnail path */
-               if (dbHandle->columnText(17)!= NULL && ((char *)dbHandle->columnText(17))[0] != '\0') {
-                       strncpy(pMsg->thumbPath, (char *)dbHandle->columnText(17), MSG_FILEPATH_LEN_MAX);
+               if (dbHandle->columnText(18)!= NULL && ((char *)dbHandle->columnText(18))[0] != '\0') {
+                       strncpy(pMsg->thumbPath, (char *)dbHandle->columnText(18), MSG_FILEPATH_LEN_MAX);
                        MSG_DEBUG("pMsg->thumbPath : [%s]", pMsg->thumbPath);
                }
-               pMsg->sim_idx = dbHandle->columnInt(18);
+
+               if (pMsg->bRestricted == true) {
+                       pMsg->dataSize = 0;
+                       memset(pMsg->msgData, 0x00, sizeof(pMsg->msgData));
+                       memset(pMsg->msgText, 0x00, sizeof(pMsg->msgText));
+                       memset(pMsg->subject, 0x00, sizeof(pMsg->subject));
+                       memset(pMsg->thumbPath, 0x00, sizeof(pMsg->thumbPath));
+
+               }
+
+               pMsg->sim_idx = dbHandle->columnInt(19);
        } else {
                dbHandle->finalizeQuery();
                MSG_DEBUG("%s", sqlQuery);
@@ -3143,3 +3155,49 @@ msg_error_t MsgStoUpdateIMSI(int sim_idx)
 
        return MSG_SUCCESS;
 }
+
+
+msg_error_t MsgStoUpdateDPMRestrictedStatus(MSG_MAIN_TYPE_T msgType)
+{
+       msg_error_t err = MSG_SUCCESS;
+
+       char sqlQuery[MAX_QUERY_LEN+1];
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       msg_id_list_s msgIdList = {0,};
+       int rowCnt = 0;
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE MAIN_TYPE = %d AND DPM_RESTRICTED = 1;",
+                       MSGFW_MESSAGE_TABLE_NAME, msgType);
+
+       err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
+       if (err != MSG_SUCCESS) {
+               dbHandle->freeTable();
+               return err;
+       }
+
+       msg_message_id_t *msgIds = new msg_message_id_t[rowCnt];
+       for (int i = 0; i < rowCnt; i++) {
+               msgIds[i] = dbHandle->getColumnToInt(i + 1);
+       }
+
+       dbHandle->freeTable();
+
+       msgIdList.nCount = rowCnt;
+       msgIdList.msgIdList = msgIds;
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET DPM_RESTRICTED = 0 WHERE MAIN_TYPE = %d AND DPM_RESTRICTED = 1;",
+                       MSGFW_MESSAGE_TABLE_NAME, msgType);
+
+       err = dbHandle->execQuery(sqlQuery);
+       if (err == MSG_SUCCESS) {
+               MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
+       }
+
+       if (msgIdList.msgIdList)
+               delete [] msgIdList.msgIdList;
+
+       return err;
+}
index d8e7fbe..82d0d20 100755 (executable)
@@ -25,7 +25,7 @@
 #include "MsgPluginManager.h"
 #include "MsgStorageHandler.h"
 #include "MsgSubmitHandler.h"
-
+#include "MsgUtilFunction.h"
 
 
 /*==================================================================================================
@@ -39,6 +39,13 @@ msg_error_t MsgSubmitReq(MSG_REQUEST_INFO_S *pReqInfo, bool bScheduled)
        pReqInfo->reqId = reqId;
        reqId++;
 
+       if (msg_check_dpm_policy(pReqInfo->msgInfo.msgType.mainType) == false) {
+               MSG_DEBUG("Messaging is restricted by DPM policy.");
+               MsgDbHandler *dbHandle = getDbHandle();
+               MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
+               return MSG_ERR_DPM_RESTRICT;
+       }
+
        MSG_DEBUG("==== Msg ID = [%d] ====", pReqInfo->msgInfo.msgId);
        MSG_DEBUG("==== Folder ID = [%d] ====", pReqInfo->msgInfo.folderId);
        MSG_INFO("==== Main Type = [%d] ====", pReqInfo->msgInfo.msgType.mainType);
index ca0549f..c4382cb 100755 (executable)
@@ -523,7 +523,7 @@ int MsgIncomingMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
                }
        } else if (msgInfo.msgPort.valid || (msgInfo.msgType.subType >= MSG_MWI_VOICE_SMS && msgInfo.msgType.subType <= MSG_MWI_OTHER_SMS)) {
                MsgTransactionManager::instance()->broadcastIncomingMsgCB(err, &msgInfo);
-       } else if (msgInfo.folderId == MSG_SPAMBOX_ID) {
+       } else if (msgInfo.folderId == MSG_SPAMBOX_ID || msgInfo.bRestricted == true) {
                MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
        } else if (msgInfo.msgType.subType == MSG_STATUS_REPORT_SMS || msgInfo.msgType.subType == MSG_DELIVERYIND_MMS) {
                MsgTransactionManager::instance()->broadcastReportMsgCB(err, MSG_REPORT_TYPE_DELIVERY, &msgInfo);
index 562fc8f..4d529b9 100755 (executable)
@@ -265,6 +265,7 @@ typedef struct {
        bool                                    bStore;                                                                                 /**< Indicates whether the message is stored or not if it is MWI message. */
        int                                             sim_idx;
        char                                    msgURL[MMS_LOCATION_LEN + 1];
+       bool                                    bRestricted;                                                                    /**< Indicates whether the message is restricted by DPM(Device Policy Manager) or not. */
 } MSG_MESSAGE_INFO_S;
 
 
@@ -298,6 +299,7 @@ typedef struct {
        void                                    *pMmsData;                                                              /**< Indicates the message payload information as a body. default character encoding is UTF-8*/
        size_t                                  mmsDataSize;
        int                                             simIndex;
+       bool                                    bRestricted;                                                    /**< Indicates whether the message is restricted by DPM(Device Policy Manager) or not. */
 } MSG_MESSAGE_HIDDEN_S;
 
 
@@ -351,6 +353,7 @@ typedef struct {
        char                                                                    firstMediaPath[MSG_FILEPATH_LEN_MAX+1]; /**< First Media Path in mms; */
        msg_list_handle_t multipart_list;
        int                                                             simIndex;
+       bool                                                    bRestricted;
 } MSG_CONVERSATION_VIEW_S;
 
 typedef struct {
index ffcdc9b..de9ea56 100755 (executable)
@@ -143,6 +143,7 @@ msg_error_t MsgStoUpdateAllAddress();
 msg_error_t MsgCheckUniqueness(bool bInsert, msg_message_id_t msgId, MSG_UNIQUE_INDEX_S *p_msg);
 #endif
 msg_error_t MsgStoUpdateIMSI(int sim_idx);
+msg_error_t MsgStoUpdateDPMRestrictedStatus(MSG_MAIN_TYPE_T msgType);
 
 #endif /* MSG_STORAGE_HANDLER_H */
 
index 9f7771f..18f5d1a 100755 (executable)
@@ -539,6 +539,7 @@ enum _MSG_MESSAGE_INFO_E_ {
        MSG_MESSAGE_ADDR_LIST_HND,                          /**< Indicates the address information list. */
        MSG_MESSAGE_REPLACE_BOOL,                           /**< Indicates whether the message is replace or not */
        MSG_MESSAGE_SIM_INDEX_INT,                          /**< Indicates the sim index */
+       MSG_MESSAGE_DPM_RESTRICTED_BOOL,                    /**< Indicates whether the message is DPM restricted or not*/
        MSG_MESSAGE_INFO_MAX,                               /**< Placeholder for max value of this enum*/
 };
 
@@ -604,6 +605,7 @@ enum MSG_STRUCT_CONV_INFO_E {
        MSG_CONV_MSG_1ST_MEDIA_PATH_STR,                    /**< Indicates the First Media path of MMS */
        MSG_CONV_MSG_MULTIPART_HND,
        MSG_CONV_MSG_SIM_INDEX_INT,                         /**< Indicates the sim index */
+       MSG_CONV_MSG_DPM_RESTRICTED_BOOL,                       /**< */
 
        MSG_CONV_INFO_MAX                                   /**< Placeholder for max value of this enum */
 };
@@ -1285,6 +1287,7 @@ enum _MSG_ERROR_E {
        MSG_ERR_DB_BUSY = -61,                  /**< DB file locked*/
        MSG_ERR_NOT_SUPPORTED = -63,            /**< Not supported */
        MSG_ERR_NOT_ALLOWED_ZONE = -100,        /**< Not allowed zone */
+       MSG_ERR_DPM_RESTRICT = -200,            /**< DPM restriction */
 };
 
 
index f021ced..a0086a0 100755 (executable)
@@ -162,8 +162,10 @@ msg_error_t msg_aul_svc_set_operation(bundle *bundle_data, const char *operation
 
 msg_error_t msg_aul_svc_set_uri(bundle *bundle_data, char *uri);
 
-/* Dbus function */
-void MsgDbusInit();
-void MsgDbusDeinit();
+void msg_init_dpm_policy();
+
+void msg_deinit_dpm_policy();
+
+bool msg_check_dpm_policy(int type);
 
 #endif /* MSG_UTIL_FUNCTION_H */
index 02ba5e6..1a179da 100755 (executable)
@@ -311,6 +311,9 @@ int msg_message_get_bool_value(void *data, int field, bool *value)
                        *value = false;
                break;
        }
+       case MSG_MESSAGE_DPM_RESTRICTED_BOOL:
+               *value = msg_data->bRestricted;
+               break;
        default:
                ret = MSG_ERR_INVALID_PARAMETER;
                break;
index 6609440..1fe7b36 100755 (executable)
@@ -1661,6 +1661,9 @@ int msg_conv_get_bool(void *data, int field, bool *value)
        case MSG_CONV_MSG_PROTECTED_BOOL:
                *value = pConv->bProtected;
                break;
+       case MSG_CONV_MSG_DPM_RESTRICTED_BOOL:
+               *value = pConv->bRestricted;
+               break;
        default:
                ret = MSG_ERR_INVALID_PARAMETER;
                break;
index 7044403..28fd2f6 100755 (executable)
@@ -38,6 +38,7 @@ BuildRequires: pkgconfig(cynara-creds-socket)
 BuildRequires: pkgconfig(cynara-session)
 BuildRequires: pkgconfig(deviced)
 BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(dpm)
 BuildRequires: pkgconfig(eventsystem)
 BuildRequires: pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(icu-uc)
index f5a1155..25f5d59 100755 (executable)
@@ -18,6 +18,7 @@
 #include "MsgException.h"
 #include "MsgGconfWrapper.h"
 #include "MsgUtilFile.h"
+#include "MsgUtilFunction.h"
 #include "MsgMmsMessage.h"
 #include "MsgSerialize.h"
 #include "MmsPluginDebug.h"
@@ -113,6 +114,11 @@ msg_error_t MmsSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo)
        MSG_BEGIN();
 
        try {
+               if (msg_check_dpm_policy(pReqInfo->msgInfo.msgType.mainType) == false) {
+                       MSG_DEBUG("Messaging is restricted by DPM policy.");
+                       return MSG_ERR_DPM_RESTRICT;
+               }
+
                MmsPluginTransport::instance()->submitRequest(pReqInfo);
        } catch (MsgException& e) {
                MSG_FATAL("%s", e.what());
index 1357ceb..e4a9f5c 100755 (executable)
@@ -323,6 +323,7 @@ void MsgHandle::convertMsgStruct(const MSG_MESSAGE_HIDDEN_S *pSrc, MSG_MESSAGE_I
        }
 
        pDest->sim_idx = pSrc->simIndex;
+       pDest->bRestricted = pSrc->bRestricted;
 
        MSG_END();
 }
@@ -351,6 +352,7 @@ void MsgHandle::convertMsgStruct(const MSG_MESSAGE_INFO_S *pSrc, MSG_MESSAGE_HID
        pDest->priority = pSrc->priority;
        pDest->direction = pSrc->direction;
        pDest->simIndex = pSrc->sim_idx;
+       pDest->bRestricted = pSrc->bRestricted;
 
        /* Set Port Info. */
        pDest->bPortValid = pSrc->msgPort.valid;
index 776bac3..fa9fa46 100755 (executable)
@@ -46,7 +46,7 @@ INCLUDE_DIRECTORIES(
 
 INCLUDE(FindPkgConfig)
 
-SET(PKG_MODULES glib-2.0 vconf dlog libxml-2.0 boost json-glib-1.0 capi-system-info capi-media-thumbnail-util capi-media-image-util aul sqlite3 capi-media-metadata-extractor icu-uc libsystemd-login libsmack csr)
+SET(PKG_MODULES glib-2.0 vconf dlog libxml-2.0 boost json-glib-1.0 capi-system-info capi-media-thumbnail-util capi-media-image-util aul sqlite3 capi-media-metadata-extractor icu-uc libsystemd-login libsmack csr dpm)
 pkg_check_modules(utils_pkgs REQUIRED ${PKG_MODULES})
 
 FOREACH(flag ${utils_pkgs_CFLAGS})
index 4e1a739..4df7ace 100755 (executable)
@@ -14,7 +14,6 @@
  * limitations under the License.
 */
 
-#include <gio/gio.h>
 #include <systemd/sd-login.h>
 
 #include "MsgDebug.h"
@@ -22,6 +21,7 @@
 #include "MsgGconfWrapper.h"
 #include "MsgUtilFile.h"
 #include "MsgUtilFunction.h"
+#include "MsgUtilStorage.h"
 
 #include <system_info.h>
 #include <libintl.h>
@@ -30,6 +30,7 @@
 #include <ctype.h>
 #include <aul.h>
 #include <aul_svc.h>
+#include <dpm/restriction.h>
 
 typedef struct _msg_launch_app_data {
        char *app_id;
@@ -49,7 +50,17 @@ static bool b_feature_support[] = {
                [FEATURE_INDEX_MMS] = false,
 };
 
-int _dbus_owner_id = 0;
+static int dpm_policy_enable[] = {
+               [MSG_UNKNOWN_TYPE] = 0,
+               [MSG_SMS_TYPE] = 1,
+               [MSG_MMS_TYPE] = 1,
+};
+
+device_policy_manager_h dpm_handle = NULL;
+bool is_dpm_init = false;
+int dpm_sms_callback_id = 0;
+int dpm_mms_callback_id = 0;
+
 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
 static int phonenumberMinMatchDigit = -1;
 #endif
@@ -1300,28 +1311,92 @@ msg_error_t msg_aul_svc_set_uri(bundle *bundle_data, char *uri)
 }
 
 
-void MsgDbusInit()
+void dpm_sms_policy_changed_callback(const char* name, const char* object, void *user_data)
+{
+       MSG_INFO("dpm_sms_policy_changed_callback called. name [%s] object [%s]", name, object);
+
+       int ret = 0;
+
+       ret = dpm_restriction_get_messaging_state(dpm_handle, &dpm_policy_enable[MSG_SMS_TYPE - 1]);
+       if (ret != DPM_ERROR_NONE) {
+               MSG_ERR("dpm_restriction_get_messaging_state failed [%d]", ret);
+               return;
+       }
+}
+
+
+void dpm_mms_policy_changed_callback(const char* name, const char* object, void *user_data)
+{
+       MSG_INFO("dpm_mms_policy_changed_callback called. name [%s] object [%s]", name, object);
+
+       int ret = 0;
+
+       ret = dpm_restriction_get_messaging_state(dpm_handle, &dpm_policy_enable[MSG_MMS_TYPE - 1]);
+       if (ret != DPM_ERROR_NONE) {
+               MSG_ERR("dpm_restriction_get_messaging_state failed [%d]", ret);
+               return;
+       }
+}
+
+
+static bool __get_dpm_policy()
 {
-       MSG_DEBUG();
+       int ret = 0;
+
+       ret = dpm_restriction_get_messaging_state(dpm_handle, &dpm_policy_enable[MSG_SMS_TYPE]);
+       if (ret != DPM_ERROR_NONE) {
+               MSG_ERR("dpm_restriction_get_messaging_state failed [%d]", ret);
+               return false;
+       }
+
+       MSG_DEBUG("sms policy [%d]", dpm_policy_enable[MSG_SMS_TYPE]);
+       MSG_DEBUG("mms policy [%d]", dpm_policy_enable[MSG_MMS_TYPE]);
+
+       ret = dpm_add_policy_changed_cb(dpm_handle, "messaging", dpm_sms_policy_changed_callback, NULL, &dpm_sms_callback_id);
+       if (ret != DPM_ERROR_NONE) {
+               MSG_ERR("dpm_add_policy_changed_cb failed [%d]", ret);
+               return false;
+       }
 
-       _dbus_owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
-                                                                       "msg-service.dbus.service",
-                                                                       G_BUS_NAME_OWNER_FLAGS_NONE,
-                                                                       NULL, NULL, NULL,
-                                                                       NULL, NULL);
+       return true;
+}
+
+void msg_init_dpm_policy()
+{
+       MSG_BEGIN();
 
-       if (_dbus_owner_id == 0) {
-               MSG_ERR("g_bus_own_name() error");
+       dpm_handle = dpm_manager_create();
+       if (dpm_handle == NULL) {
+               MSG_ERR("dpm_manager_create() failed");
+               return;
        }
 
-       MSG_DEBUG("owner_id = [%d]", _dbus_owner_id);
+       is_dpm_init = __get_dpm_policy();
+
+       MSG_END();
+}
+
+
+void msg_deinit_dpm_policy()
+{
+       if (dpm_handle)
+               dpm_manager_destroy(dpm_handle);
+
+       if (dpm_sms_callback_id)
+               dpm_remove_policy_changed_cb(dpm_handle, dpm_sms_callback_id);
+
+       if (dpm_mms_callback_id)
+               dpm_remove_policy_changed_cb(dpm_handle, dpm_mms_callback_id);
+
+       is_dpm_init = false;
 }
 
-void MsgDbusDeinit()
+bool msg_check_dpm_policy(int type)
 {
-       MSG_DEBUG();
-       if (_dbus_owner_id)
-               g_bus_unown_name(_dbus_owner_id);
+       if (is_dpm_init == false)
+               msg_init_dpm_policy();
 
-       _dbus_owner_id = 0;
+       return dpm_policy_enable[MSG_SMS_TYPE];
+//     return dpm_policy_enable[type];
 }
+
index 735bb28..aaf1613 100755 (executable)
@@ -85,10 +85,10 @@ unsigned int MsgStoAddMessageTable(MsgDbHandler *pDbHandle, const MSG_MESSAGE_IN
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d, %d, %u, %d, %d, %d, %d, %d, %d, %d, %d, ?, '', '', ?, 0, %d, '%s');",
+       snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d, %d, %u, %d, %d, %d, %d, %d, %d, %d, %d, ?, '', '', ?, 0, %d, '%s', %d);",
                        MSGFW_MESSAGE_TABLE_NAME, msgId, pMsgInfo->threadId, pMsgInfo->folderId, pMsgInfo->storageId, pMsgInfo->msgType.mainType,
                        pMsgInfo->msgType.subType, (unsigned int)pMsgInfo->displayTime, pMsgInfo->dataSize, pMsgInfo->networkStatus, pMsgInfo->bRead, pMsgInfo->bProtected,
-                       pMsgInfo->priority, pMsgInfo->direction, 0, pMsgInfo->bBackup, pMsgInfo->sim_idx, imsi);
+                       pMsgInfo->priority, pMsgInfo->direction, 0, pMsgInfo->bBackup, pMsgInfo->sim_idx, imsi, pMsgInfo->bRestricted);
 
        MSG_DEBUG("QUERY : %s", sqlQuery);
 
@@ -686,7 +686,7 @@ msg_error_t MsgStoUpdateConversation(MsgDbHandler *pDbHandle, msg_thread_id_t co
                snprintf(sqlQuery, sizeof(sqlQuery),
                                "SELECT MAIN_TYPE, SUB_TYPE, MSG_DIRECTION, DISPLAY_TIME, LENGTH(SUBJECT), SUBJECT, MSG_TEXT "
                                "FROM %s "
-                               "WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND SCHEDULED_TIME = 0 ORDER BY DISPLAY_TIME DESC;",
+                               "WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND DPM_RESTRICTED = 0 AND SCHEDULED_TIME = 0 ORDER BY DISPLAY_TIME DESC;",
                                MSGFW_MESSAGE_TABLE_NAME,
                                convId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
 
@@ -697,7 +697,31 @@ msg_error_t MsgStoUpdateConversation(MsgDbHandler *pDbHandle, msg_thread_id_t co
                }
 
                err = pDbHandle->stepQuery();
-               if (err != MSG_ERR_DB_ROW) {
+               if (err == MSG_ERR_DB_DONE) {
+                       pDbHandle->finalizeQuery();
+
+                       memset(sqlQuery, 0x00, MAX_QUERY_LEN);
+                       snprintf(sqlQuery, sizeof(sqlQuery),
+                                       "SELECT MAIN_TYPE, SUB_TYPE, MSG_DIRECTION, DISPLAY_TIME, 0, '', '' "
+                                       "FROM %s "
+                                       "WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND SCHEDULED_TIME = 0 ORDER BY DISPLAY_TIME DESC;",
+                                       MSGFW_MESSAGE_TABLE_NAME,
+                                       convId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
+
+                       err = pDbHandle->prepareQuery(sqlQuery);
+                       if (err != MSG_SUCCESS) {
+                               MSG_DEBUG("Fail to prepareQuery().");
+                               return err;
+                       }
+
+                       err = pDbHandle->stepQuery();
+                       if (err != MSG_ERR_DB_ROW) {
+                               MSG_DEBUG("Fail to stepQuery().");
+                               pDbHandle->finalizeQuery();
+                               return err;
+                       }
+
+               } else if (err != MSG_ERR_DB_ROW) {
                        MSG_DEBUG("Fail to stepQuery().");
                        pDbHandle->finalizeQuery();
                        return err;
@@ -722,7 +746,7 @@ msg_error_t MsgStoUpdateConversation(MsgDbHandler *pDbHandle, msg_thread_id_t co
                tmpSize = strlen(sqlQuery);
 #ifdef MSG_NOTI_INTEGRATION
                snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
-                               "UNREAD_CNT = (SELECT COUNT(MSG_ID) FROM %s WHERE CONV_ID = %d AND (FOLDER_ID = %d OR FOLDER_ID = %d) AND STORAGE_ID = %d AND READ_STATUS = 0), ",
+                               "UNREAD_CNT = (SELECT COUNT(MSG_ID) FROM %s WHERE CONV_ID = %d AND (FOLDER_ID = %d OR FOLDER_ID = %d) AND STORAGE_ID = %d AND READ_STATUS = 0 AND DPM_RESTRICTED = 0), ",
                                MSGFW_MESSAGE_TABLE_NAME, convId, MSG_INBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
 #else
                snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
@@ -1834,7 +1858,7 @@ msg_error_t MsgStoGetConversationViewItem(msg_message_id_t msgId, MSG_CONVERSATI
 
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, SUB_TYPE, \
                        DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, \
-                       MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, ATTACHMENT_COUNT, SIM_INDEX\
+                       MSG_DIRECTION, DPM_RESTRICTED, SCHEDULED_TIME, SUBJECT, MSG_TEXT, ATTACHMENT_COUNT, SIM_INDEX\
                        FROM %s WHERE MSG_ID = %d;",
                        MSGFW_MESSAGE_TABLE_NAME, msgId);
 
@@ -1864,6 +1888,7 @@ msg_error_t MsgStoGetConversationViewItem(msg_message_id_t msgId, MSG_CONVERSATI
        pConv->bRead = dbHandle->getColumnToInt(index++);
        pConv->bProtected = dbHandle->getColumnToInt(index++);
        pConv->direction = dbHandle->getColumnToInt(index++);
+       pConv->bRestricted = dbHandle->getColumnToInt(index++);
        pConv->scheduledTime = (time_t)dbHandle->getColumnToInt(index++);
 
        dbHandle->getColumnToString(index++, MAX_SUBJECT_LEN, pConv->subject);
@@ -1872,6 +1897,12 @@ msg_error_t MsgStoGetConversationViewItem(msg_message_id_t msgId, MSG_CONVERSATI
        /*It does Not need to Get attach count in MSG_MESSAGE_TABLE. see MsgStoGetConversationPreview */
        /*pConv->attachCount = dbHandle->getColumnToInt(index++); */
        index++;
+       if (pConv->bRestricted == true) {
+               pConv->textSize = 0;
+               memset(pConv->subject, 0x00, sizeof(pConv->subject));
+               tmpText[0] = '\0';
+       }
+
        pConv->simIndex = dbHandle->getColumnToInt(index++);
 
        dbHandle->freeTable();
@@ -1930,13 +1961,13 @@ msg_error_t MsgStoGetConversationViewList(msg_thread_id_t threadId, msg_struct_l
 #ifdef MSG_NOTI_INTEGRATION
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, SUB_TYPE, \
                        DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, \
-                       MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, ATTACHMENT_COUNT, SIM_INDEX  \
+                       MSG_DIRECTION, DPM_RESTRICTED, SCHEDULED_TIME, SUBJECT, MSG_TEXT, ATTACHMENT_COUNT, SIM_INDEX  \
                        FROM %s WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d ORDER BY DISPLAY_TIME, MSG_ID ASC;",
                        MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
 #else
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, SUB_TYPE, \
                        DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, \
-                       MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, ATTACHMENT_COUNT \
+                       MSG_DIRECTION, DPM_RESTRICTED, SCHEDULED_TIME, SUBJECT, MSG_TEXT, ATTACHMENT_COUNT \
                        FROM %s WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d ORDER BY DISPLAY_TIME, MSG_ID ASC;",
                        MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
 #endif
@@ -1989,6 +2020,7 @@ msg_error_t MsgStoGetConversationViewList(msg_thread_id_t threadId, msg_struct_l
                pTmp->bRead = dbHandle->getColumnToInt(index++);
                pTmp->bProtected = dbHandle->getColumnToInt(index++);
                pTmp->direction = dbHandle->getColumnToInt(index++);
+               pTmp->bRestricted = dbHandle->getColumnToInt(index++);
                index++; /* This field is reserved. */
 
                dbHandle->getColumnToString(index++, MAX_SUBJECT_LEN, pTmp->subject);
@@ -1997,6 +2029,12 @@ msg_error_t MsgStoGetConversationViewList(msg_thread_id_t threadId, msg_struct_l
                /*It does Not need to Get attach count in MSG_MESSAGE_TABLE. see MsgStoGetConversationPreview */
                /*pTmp->attachCount = dbHandle->getColumnToInt(index++); */
                index++;
+
+               if (pTmp->bRestricted == true) {
+                       pTmp->textSize = 0;
+                       memset(pTmp->subject, 0x00, sizeof(pTmp->subject));
+                       tmpText[i][0] = '\0';
+               }
                pTmp->simIndex = dbHandle->getColumnToInt(index++);
        }
        dbHandle->freeTable();
@@ -2356,25 +2394,29 @@ msg_error_t MsgStoGetMessageList(const MSG_LIST_CONDITION_S *pListCond, msg_stru
 
        if (pListCond->pTextVal != NULL && multipartCnt > 0) {
                memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "FROM %s C, %s B, %s A WHERE A.CONV_ID > 0 AND A.CONV_ID = B.CONV_ID AND ",
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "FROM %s C, %s B, %s A WHERE A.CONV_ID > 0 AND A.CONV_ID = B.CONV_ID ",
                        MSGFW_MMS_MULTIPART_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME);
        } else {
                memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset),        "FROM %s B, %s A WHERE A.CONV_ID > 0 AND A.CONV_ID = B.CONV_ID AND ",
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset),        "FROM %s B, %s A WHERE A.CONV_ID > 0 AND A.CONV_ID = B.CONV_ID ",
                MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME);
        }
 
        strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
 
+       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.DPM_RESTRICTED = 0 ");
+       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+
        /* folder */
        memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
 
        if (pListCond->folderId == MSG_ALLBOX_ID)
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "A.FOLDER_ID > 0 AND A.FOLDER_ID < %d ", MSG_SPAMBOX_ID);
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.FOLDER_ID > 0 AND A.FOLDER_ID < %d ", MSG_SPAMBOX_ID);
        else if (pListCond->folderId == MSG_IOSBOX_ID)
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "A.FOLDER_ID > 0 AND A.FOLDER_ID < %d ", MSG_DRAFT_ID);
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.FOLDER_ID > 0 AND A.FOLDER_ID < %d ", MSG_DRAFT_ID);
        else
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "A.FOLDER_ID = %d ", pListCond->folderId);
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.FOLDER_ID = %d ", pListCond->folderId);
 
        strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
 
@@ -2803,7 +2845,7 @@ msg_error_t MsgStoGetMediaList(const msg_thread_id_t threadId, msg_list_handle_t
        int msgIdCnt = 0;
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE MAIN_TYPE = %d AND CONV_ID = %d;",
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE MAIN_TYPE = %d AND DPM_RESTRICTED = 0 AND CONV_ID = %d;",
                        MSGFW_MESSAGE_TABLE_NAME, MSG_MMS_TYPE, threadId);
 
        MSG_DEBUG("sqlQuery = [%s]", sqlQuery);