[TRE-46]Add msg-manager pkg 50/62450/4
authorSangkoo Kim <sangkoo.kim@samsung.com>
Wed, 16 Mar 2016 07:33:22 +0000 (16:33 +0900)
committerSangkoo Kim <sangkoo.kim@samsung.com>
Wed, 16 Mar 2016 07:49:11 +0000 (16:49 +0900)
Change-Id: If95a75be9cf64ebe6b0530d0d112273cb79ceea7
Signed-off-by: Sangkoo Kim <sangkoo.kim@samsung.com>
13 files changed:
CMakeLists.txt
manager/CMakeLists.txt [new file with mode: 0755]
manager/inc/msg-manager-contact.h [new file with mode: 0644]
manager/inc/msg-manager-debug.h [new file with mode: 0755]
manager/inc/msg-manager-notification.h [new file with mode: 0644]
manager/inc/msg-manager.h [new file with mode: 0644]
manager/shared/res/msg-manager.png [new file with mode: 0644]
manager/src/msg-manager-contact.cpp [new file with mode: 0644]
manager/src/msg-manager-notification.cpp [new file with mode: 0644]
manager/src/msg-manager.cpp [new file with mode: 0644]
manager/tizen-manifest.xml [new file with mode: 0644]
msg-manager.manifest [new file with mode: 0755]
packaging/msg-service.spec

index ea1515d..168824d 100755 (executable)
@@ -15,6 +15,7 @@ SET(TRANS-PROXY-LIB msg_transaction_proxy)
 SET(MAPI-LIB msg_mapi)
 SET(SMS-PLUGIN-LIB msg_sms_plugin)
 SET(MMS-PLUGIN-LIB msg_mms_plugin)
+SET(MSG-MGR msg-manager)
 
 IF(_FEATURE_SMS_CDMA)
        ADD_DEFINITIONS("-DFEATURE_SMS_CDMA")
@@ -55,6 +56,9 @@ ELSE(_FEATURE_SMS_CDMA)
 ADD_SUBDIRECTORY(plugin/sms_plugin)
 ENDIF(_FEATURE_SMS_CDMA)
 ADD_SUBDIRECTORY(plugin/mms_plugin)
+IF(NOT _MSG_WEARABLE_PROFILE)
+ADD_SUBDIRECTORY(manager)
+ENDIF()
 
 ##########################################################
 # Install Header Files
diff --git a/manager/CMakeLists.txt b/manager/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..3bf5a2a
--- /dev/null
@@ -0,0 +1,51 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+include(CheckCCompilerFlag)
+
+SET(MSG-MGR-PKGNAME org.tizen.msg-manager)
+
+ADD_DEFINITIONS("-D_FILE_OFFSET_BITS=64")
+
+IF(_WEARABLE_PROFILE)
+        ADD_DEFINITIONS("-DMSG_MGR_WEARABLE_PROFILE")
+ENDIF(_WEARABLE_PROFILE)
+
+SET(CMAKE_SKIP_BUILD_RPATH TRUE)
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+       SET(CMAKE_BUILD_TYPE "Debug")
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
+
+SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -O2 -g -Wall")
+
+SET(MSG-MANAGER-SRCS
+        ${CMAKE_CURRENT_SOURCE_DIR}/src/msg-manager.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/src/msg-manager-contact.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/src/msg-manager-notification.cpp
+)
+
+INCLUDE_DIRECTORIES(
+               ${CMAKE_SOURCE_DIR}/include/mapi
+        ${CMAKE_CURRENT_SOURCE_DIR}/inc/
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(mgr_pkgs REQUIRED glib-2.0 dlog appcore-agent bundle contacts-service2 capi-appfw-application notification)
+INCLUDE_DIRECTORIES(${mgr_pkgs_INCLUDE_DIRS})
+LINK_DIRECTORIES(${mgr_pkgs_LIBRARY_DIRS})
+
+FOREACH(flag ${mgr_pkgs_CXXFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(msg_mgr_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+ADD_EXECUTABLE(${MSG-MGR} ${MSG-MANAGER-SRCS})
+TARGET_LINK_LIBRARIES(${MSG-MGR} ${mgr_pkgs_LDFLAGS} ${MAPI-LIB})
+SET_TARGET_PROPERTIES(${MSG-MGR} PROPERTIES COMPILE_FLAGS "${msg_mgr_CXX_FLAGS}")
+
+INSTALL(TARGETS ${MSG-MGR} DESTINATION ${APP_BINDIR})
+INSTALL(FILES tizen-manifest.xml DESTINATION ${APP_MANIFESTDIR} RENAME ${MSG-MGR-PKGNAME}.xml)
diff --git a/manager/inc/msg-manager-contact.h b/manager/inc/msg-manager-contact.h
new file mode 100644 (file)
index 0000000..232e110
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef __MSG_MGR_CONTACT_H__
+#define __MSG_MGR_CONTACT_H__
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+#include <msg.h>
+#include <contacts.h>
+
+/*==================================================================================================
+                                    DEFINES
+==================================================================================================*/
+#define MAX_CONTACT_TEXT_LEN 100
+
+
+/*==================================================================================================
+                                         STRUCTURES
+==================================================================================================*/
+typedef struct _contactInfo {
+       int msgId;
+       int msgType;
+       int folderId;
+       int simIndex;
+       char msgText[MAX_CONTACT_TEXT_LEN + 1];
+       char subject[MAX_CONTACT_TEXT_LEN + 1];
+       msg_list_handle_t addrList;
+} contactInfo;
+
+
+/*==================================================================================================
+                                     FUNCTION PROTOTYPES
+==================================================================================================*/
+
+int MsgMgrOpenContactSvc();
+int MsgMgrCloseContactSvc();
+void MsgMgrAddPhoneLog(contactInfo *contact_info);
+
+#endif /*__MSG_MGR_CONTACT_H__ */
+
diff --git a/manager/inc/msg-manager-debug.h b/manager/inc/msg-manager-debug.h
new file mode 100755 (executable)
index 0000000..efa321e
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef __MSG_MGR_DEBUG_H__
+#define __MSG_MGR_DEBUG_H__
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+#include <dlog.h>
+
+/*==================================================================================================
+                                    DEFINES
+==================================================================================================*/
+#undef LOG_TAG
+#define LOG_TAG "MSG_MGR"
+
+/*log macros*/
+#define MSG_MGR_BEGIN()\
+       do { \
+               SLOGD(" BEGIN >>>> \n");\
+       } while (0)
+
+#define MSG_MGR_END()\
+       do { \
+               SLOGD(" END   <<<<  \n");\
+       } while (0)
+
+#define MSG_MGR_DEBUG(fmt, ...)\
+       do { \
+               SLOGD(fmt"\n", ##__VA_ARGS__);\
+       } while (0)
+
+#define MSG_MGR_INFO(fmt, ...)\
+       do { \
+               SLOGI("* Info * " fmt "\n", ##__VA_ARGS__);\
+       } while (0)
+
+#define MSG_MGR_WARN(fmt, ...)\
+       do { \
+               SLOGW("* Warning * " fmt "\n", ##__VA_ARGS__);\
+       } while (0)
+
+#define MSG_MGR_ERR(fmt, ...)\
+       do { \
+               SLOGE("* Error * " fmt "\n", ##__VA_ARGS__);\
+       } while (0)
+
+#define MSG_MGR_FATAL(fmt, ...)\
+       do { \
+               SLOGE(" ERROR << " fmt " >>\n", ##__VA_ARGS__);\
+       } while (0)
+
+/*secure log macros*/
+#define MSG_MGR_SEC_DEBUG(fmt, ...)\
+       do { \
+               SECURE_SLOGD(fmt"\n", ##__VA_ARGS__);\
+       } while (0)
+
+#define MSG_MGR_SEC_INFO(fmt, ...)\
+       do { \
+               SECURE_SLOGI("* Info * " fmt"\n", ##__VA_ARGS__);\
+       } while (0)
+
+#define MSG_MGR_SEC_ERR(fmt, ...)\
+       do { \
+               SECURE_LOG(LOG_ERROR, LOG_TAG, "* Error *" fmt "\n", ##__VA_ARGS__);\
+       } while (0)
+
+
+#endif /*__MSG_MGR_DEBUG_H__ */
+
diff --git a/manager/inc/msg-manager-notification.h b/manager/inc/msg-manager-notification.h
new file mode 100644 (file)
index 0000000..d8f1117
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef __MSG_MGR_NOTIFICATION_H__
+#define __MSG_MGR_NOTIFICATION_H__
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+#include <msg.h>
+
+/*==================================================================================================
+                                    DEFINES
+==================================================================================================*/
+
+
+/*==================================================================================================
+                                         STRUCTURES
+==================================================================================================*/
+
+
+/*==================================================================================================
+                                     FUNCTION PROTOTYPES
+==================================================================================================*/
+
+
+#endif /*__MSG_MGR_NOTIFICATION_H__ */
+
diff --git a/manager/inc/msg-manager.h b/manager/inc/msg-manager.h
new file mode 100644 (file)
index 0000000..f11288d
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef __MESSAGE_MANAGER_H__
+#define __MESSAGE_MANAGER_H__
+
+//#include <dlog.h>
+//
+//#ifdef  LOG_TAG
+//#undef  LOG_TAG
+//#endif
+//#define LOG_TAG "MSG_MGR"
+
+
+#endif /* __MESSAGE_MANAGER_H__ */
diff --git a/manager/shared/res/msg-manager.png b/manager/shared/res/msg-manager.png
new file mode 100644 (file)
index 0000000..9765b1b
Binary files /dev/null and b/manager/shared/res/msg-manager.png differ
diff --git a/manager/src/msg-manager-contact.cpp b/manager/src/msg-manager-contact.cpp
new file mode 100644 (file)
index 0000000..b8339ac
--- /dev/null
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+
+#include <stdlib.h>
+#include <stdbool.h>
+#include <glib.h>
+
+#include <msg_storage.h>
+
+#include <msg-manager-contact.h>
+#include <msg-manager-debug.h>
+
+/*==================================================================================================
+                                     VARIABLES
+==================================================================================================*/
+
+static bool isContactSvcConnected = false;
+
+
+/*==================================================================================================
+                                     FUNCTION IMPLEMENTATION
+==================================================================================================*/
+
+int MsgMgrOpenContactSvc()
+{
+       int errCode = CONTACTS_ERROR_NONE;
+
+       if (!isContactSvcConnected) {
+               errCode = contacts_connect();
+
+               if (errCode == CONTACTS_ERROR_NONE) {
+                       MSG_MGR_DEBUG("Connect to Contact Service Success");
+                       isContactSvcConnected = true;
+               } else {
+                       MSG_MGR_DEBUG("Connect to Contact Service Fail [%d]", errCode);
+                       isContactSvcConnected = false;
+                       return -1;
+               }
+       } else {
+               MSG_MGR_DEBUG("Already connected to Contact Service.");
+       }
+       return 0;
+}
+
+
+int MsgMgrCloseContactSvc()
+{
+       int errCode = CONTACTS_ERROR_NONE;
+
+       if (isContactSvcConnected) {
+               errCode = contacts_disconnect();
+
+               if (errCode == CONTACTS_ERROR_NONE) {
+                       MSG_MGR_DEBUG("Disconnect to Contact Service Success");
+                       isContactSvcConnected = false;
+               } else {
+                       MSG_MGR_DEBUG("Disconnect to Contact Service Fail [%d]", errCode);
+                       return -1;
+               }
+       }
+       return 0;
+}
+
+
+void MsgMgrAddPhoneLog(contactInfo *contact_info)
+{
+       int err = 0;
+
+       if ((err = MsgMgrOpenContactSvc()) != 0) {
+               MSG_MGR_DEBUG("MsgMgrOpenContactSvc fail.");
+               return;
+       }
+
+       if (!isContactSvcConnected) {
+               MSG_MGR_DEBUG("Contact Service Not Opened.");
+               return;
+       }
+
+       int addr_cnt = msg_list_length(contact_info->addrList);
+       if (addr_cnt < 1) {
+               MSG_MGR_DEBUG("address count is [%d]", addr_cnt);
+               return;
+       }
+
+       for (int i = 0; i < addr_cnt; i++) {
+               int ret = 0;
+               contacts_record_h plog = NULL;
+               char addressVal[MAX_ADDRESS_VAL_LEN + 1] = {0};
+
+               msg_struct_t addr_data = msg_list_nth_data(contact_info->addrList, i);
+
+               ret = contacts_record_create(_contacts_phone_log._uri, &plog);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       MSG_MGR_DEBUG("contacts_record_create() Error [%d]", ret);
+                       contacts_record_destroy(plog, true);
+                       break;
+               }
+
+               contacts_record_set_int(plog, _contacts_phone_log.sim_slot_no, contact_info->simIndex-1);
+               msg_get_str_value(addr_data, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addressVal, MAX_ADDRESS_VAL_LEN);
+               MSG_MGR_SEC_DEBUG("addressVal : %s", addressVal);
+               contacts_record_set_str(plog, _contacts_phone_log.address, addressVal);
+               contacts_record_set_int(plog, _contacts_phone_log.log_time, (int)time(NULL));
+
+               char strText[MAX_CONTACT_TEXT_LEN + 1];
+               memset(strText, 0x00, sizeof(strText));
+
+               if (contact_info->msgType != MSG_TYPE_MMS && contact_info->msgType != MSG_TYPE_MMS_NOTI && contact_info->msgType != MSG_TYPE_MMS_JAVA) {
+                       strncpy(strText, contact_info->msgText, MAX_CONTACT_TEXT_LEN);
+                       MSG_MGR_SEC_DEBUG("msgText : %s", strText);
+               } else {
+                       if (strlen(contact_info->subject) > 0 || contact_info->msgType == MSG_TYPE_MMS_NOTI) {
+                               strncpy(strText, contact_info->subject, MAX_CONTACT_TEXT_LEN);
+                               MSG_MGR_SEC_DEBUG("subject : %s", strText);
+                       } else {
+                               char *pFileData = NULL;
+                               gsize fileSize = 0;
+
+                               if (contact_info->msgText[0] != '\0' && g_file_get_contents(contact_info->msgText, &pFileData, &fileSize, NULL) == true) {
+                                       if (pFileData)
+                                               strncpy(strText, pFileData, 100);
+                               }
+
+                               if (pFileData)
+                                       g_free(pFileData);
+
+                               MSG_MGR_SEC_DEBUG("msgText : %s", strText);
+                       }
+               }
+
+               contacts_record_set_str(plog, _contacts_phone_log.extra_data2, strText);
+               contacts_record_set_int(plog, _contacts_phone_log.extra_data1, contact_info->msgId);
+
+               if (contact_info->folderId == MSG_INBOX_ID) {
+                       if (contact_info->msgType != MSG_TYPE_MMS && contact_info->msgType != MSG_TYPE_MMS_NOTI && contact_info->msgType != MSG_TYPE_MMS_JAVA)
+                               contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_INCOMING);
+                       else
+                               contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_INCOMING);
+               } else if (contact_info->folderId == MSG_OUTBOX_ID) {
+                       if (contact_info->msgType != MSG_TYPE_MMS && contact_info->msgType != MSG_TYPE_MMS_NOTI && contact_info->msgType != MSG_TYPE_MMS_JAVA)
+                               contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_OUTGOING);
+                       else
+                               contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_OUTGOING);
+               } else if (contact_info->folderId == MSG_SPAMBOX_ID) {
+                       if (contact_info->msgType != MSG_TYPE_MMS && contact_info->msgType != MSG_TYPE_MMS_NOTI && contact_info->msgType != MSG_TYPE_MMS_JAVA)
+                               contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_BLOCKED);
+                       else
+                               contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_BLOCKED);
+               }
+
+               ret = contacts_db_insert_record(plog, NULL);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       MSG_MGR_DEBUG("contacts_db_insert_record() Error [%d]", ret);
+               }
+
+               contacts_record_destroy(plog, true);
+       }
+}
diff --git a/manager/src/msg-manager-notification.cpp b/manager/src/msg-manager-notification.cpp
new file mode 100644 (file)
index 0000000..c406161
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+
+#include <stdlib.h>
+#include <stdbool.h>
+#include <glib.h>
+
+#include <msg_storage.h>
+
+#include <msg-manager-contact.h>
+#include <msg-manager-debug.h>
+
+/*==================================================================================================
+                                     VARIABLES
+==================================================================================================*/
+
+
+
+/*==================================================================================================
+                                     FUNCTION IMPLEMENTATION
+==================================================================================================*/
+
diff --git a/manager/src/msg-manager.cpp b/manager/src/msg-manager.cpp
new file mode 100644 (file)
index 0000000..073e5f1
--- /dev/null
@@ -0,0 +1,270 @@
+#include <stdlib.h>
+#include <glib.h>
+
+#include <msg.h>
+#include <msg_storage.h>
+#include <tizen.h>
+#include <service_app.h>
+#include <app_event.h>
+#include <bundle.h>
+#include <notification_list.h>
+#include <notification_text_domain.h>
+#include <notification_internal.h>
+
+#include "msg-manager.h"
+#include "msg-manager-contact.h"
+#include "msg-manager-debug.h"
+
+
+bool service_app_create(void *data)
+{
+       MSG_MGR_DEBUG("app_create");
+
+       return true;
+}
+
+void service_app_terminate(void *data)
+{
+       // Todo: add your code here.
+       return;
+}
+
+void _incoming_msg_func(app_control_h app_control)
+{
+       MSG_MGR_BEGIN();
+
+       int ret = 0;
+       char *rcv_msg_type = NULL;
+       char *rcv_msg_id = NULL;
+
+       ret = app_control_get_extra_data(app_control, EVENT_KEY_MSG_TYPE, &rcv_msg_type);
+       if (ret != APP_CONTROL_ERROR_NONE || rcv_msg_type == NULL)
+               return;
+
+       MSG_MGR_INFO("rcv_msg_type(%s)", rcv_msg_type);
+       if (g_strcmp0(rcv_msg_type, EVENT_VAL_SMS) != 0)
+               return;
+
+       ret = app_control_get_extra_data(app_control, EVENT_KEY_MSG_ID, &rcv_msg_id);
+       if (ret != APP_CONTROL_ERROR_NONE || rcv_msg_id == NULL)
+               return;
+
+       MSG_MGR_INFO("rcv_msg_id(%s)", rcv_msg_id);
+
+       int msg_err = MSG_SUCCESS;
+       msg_message_id_t msg_id = atoi(rcv_msg_id);
+       msg_handle_t msg_handle = NULL;
+       msg_struct_t msg = NULL;
+       msg_struct_t opt = NULL;
+       contactInfo contact_info = {0,};
+       contact_info.msgId = msg_id;
+
+       msg_err = msg_open_msg_handle(&msg_handle);
+       if (msg_err != MSG_SUCCESS) {
+               MSG_MGR_ERR("msg_open_msg_handle() failed [%d]", msg_err);
+               return;
+       }
+
+       msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+       opt = msg_create_struct(MSG_STRUCT_SENDOPT);
+       msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
+       if (msg_err != MSG_SUCCESS) {
+               MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
+               return;
+       }
+
+       msg_get_int_value(msg, MSG_MESSAGE_TYPE_INT, &contact_info.msgType);
+       msg_get_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, &contact_info.folderId);
+       msg_get_int_value(msg, MSG_MESSAGE_SIM_INDEX_INT, &contact_info.simIndex);
+       msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_HND, (void **)&contact_info.addrList);
+       msg_get_str_value(msg, MSG_MESSAGE_SUBJECT_STR, contact_info.subject, MAX_CONTACT_TEXT_LEN);
+       int msgSize = 0;
+       msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &msgSize);
+       if (msgSize > 0)
+               msg_get_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, contact_info.msgText, MAX_CONTACT_TEXT_LEN);
+
+       if ((contact_info.folderId == MSG_INBOX_ID || contact_info.folderId == MSG_SPAMBOX_ID)) {
+               MsgMgrAddPhoneLog(&contact_info);
+       }
+
+       msg_release_struct(&msg);
+       msg_release_struct(&opt);
+
+#if 0
+       char **db_res = NULL;
+       int row_cnt = 0, col_cnt = 0;
+       msg_err = msg_db_select_with_query(msg_handle, "MSG_ID FROM MSG_MESSAGE_TABLE;", &db_res, &row_cnt, &col_cnt);
+       if (msg_err != MSG_SUCCESS) {
+               MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
+               return;
+       }
+
+       MSG_MGR_DEBUG("row count [%d] col count [%d]", row_cnt, col_cnt);
+       if (db_res == NULL || *db_res == NULL) {
+               MSG_MGR_DEBUG("NULL");
+       } else {
+               for (int i = col_cnt; i < col_cnt * (row_cnt + 1); i++) {
+                       MSG_MGR_DEBUG("db_res[%d] [%s]", i, db_res[i]);
+               }
+       }
+
+       msg_err = msg_db_free(msg_handle, db_res);
+       if (msg_err != MSG_SUCCESS) {
+               MSG_MGR_ERR("msg_db_free() failed [%d]", msg_err);
+               return;
+       }
+#endif
+
+       msg_close_msg_handle(&msg_handle);
+
+       g_free(rcv_msg_type);
+       g_free(rcv_msg_id);
+
+       MSG_MGR_END();
+}
+
+void _outgoing_msg_func(app_control_h app_control)
+{
+       MSG_MGR_BEGIN();
+
+       int ret = 0;
+       char *sent_msg_id = NULL;
+
+       ret = app_control_get_extra_data(app_control, EVENT_KEY_MSG_ID, &sent_msg_id);
+       if (ret != APP_CONTROL_ERROR_NONE || sent_msg_id == NULL)
+               return;
+
+       MSG_MGR_INFO("sent_msg_id(%s)", sent_msg_id);
+
+       int msg_err = MSG_SUCCESS;
+       msg_message_id_t msg_id = atoi(sent_msg_id);
+       msg_handle_t msg_handle = NULL;
+       msg_struct_t msg = NULL;
+       msg_struct_t opt = NULL;
+       contactInfo contact_info = {0,};
+       contact_info.msgId = msg_id;
+
+       msg_err = msg_open_msg_handle(&msg_handle);
+       if (msg_err != MSG_SUCCESS) {
+               MSG_MGR_ERR("msg_open_msg_handle() failed [%d]", msg_err);
+               return;
+       }
+
+       msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+       opt = msg_create_struct(MSG_STRUCT_SENDOPT);
+       msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
+       if (msg_err != MSG_SUCCESS) {
+               MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
+               return;
+       }
+
+       msg_get_int_value(msg, MSG_MESSAGE_TYPE_INT, &contact_info.msgType);
+       msg_get_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, &contact_info.folderId);
+       msg_get_int_value(msg, MSG_MESSAGE_SIM_INDEX_INT, &contact_info.simIndex);
+       msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_HND, (void **)&contact_info.addrList);
+       msg_get_str_value(msg, MSG_MESSAGE_SUBJECT_STR, contact_info.subject, 100);
+       int msgSize = 0;
+       msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &msgSize);
+       if (msgSize > 0)
+               msg_get_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, contact_info.msgText, 100);
+
+       MsgMgrAddPhoneLog(&contact_info);
+
+       msg_release_struct(&msg);
+       msg_release_struct(&opt);
+
+       msg_close_msg_handle(&msg_handle);
+
+       g_free(sent_msg_id);
+
+       MSG_MGR_END();
+}
+
+void _refresh_noti_func(app_control_h app_control)
+{
+
+}
+
+void service_app_control(app_control_h app_control, void *data)
+{
+       MSG_MGR_INFO("service_app_control called");
+
+       //check "launch on event"
+       int ret = 0;
+       const char *incoming_event_uri = "event://tizen.system.event.incoming_msg";
+       const char *outgoing_event_uri = "event://tizen.system.event.outgoing_msg";
+       char *operation = NULL;
+       char *uri = NULL;
+
+       ret = app_control_get_operation(app_control, &operation);
+       if (ret == APP_CONTROL_ERROR_NONE && operation) {
+               if (g_strcmp0(operation, APP_CONTROL_OPERATION_LAUNCH_ON_EVENT) == 0) {
+                       /* launch by system event */
+                       ret = app_control_get_uri(app_control, &uri);
+                       if (ret == APP_CONTROL_ERROR_NONE && uri) {
+                               if (g_strcmp0(uri, incoming_event_uri) == 0) {
+                                       _incoming_msg_func(app_control);
+                               } else if (g_strcmp0(uri, outgoing_event_uri) == 0) {
+                                       _outgoing_msg_func(app_control);
+                               }
+                               g_free(uri);
+                       }
+               } else if (g_strcmp0(operation, APP_CONTROL_OPERATION_DEFAULT) == 0) {
+                       /* launch by default */
+                       char *cmd;
+                       ret = app_control_get_extra_data(app_control, "cmd", &cmd);
+                       if (ret == APP_CONTROL_ERROR_NONE && cmd) {
+                               if (g_strcmp0(cmd, "refresh") == 0)
+                                       _refresh_noti_func(app_control);
+
+                               g_free(cmd);
+                       }
+               }
+
+               g_free(operation);
+       }
+
+       return;
+}
+
+static void
+service_app_lang_changed(app_event_info_h event_info, void *user_data)
+{
+       /*APP_EVENT_LANGUAGE_CHANGED*/
+}
+
+static void
+service_app_region_changed(app_event_info_h event_info, void *user_data)
+{
+       /*APP_EVENT_REGION_FORMAT_CHANGED*/
+}
+
+static void
+service_app_low_battery(app_event_info_h event_info, void *user_data)
+{
+       /*APP_EVENT_LOW_BATTERY*/
+}
+
+static void
+service_app_low_memory(app_event_info_h event_info, void *user_data)
+{
+       /*APP_EVENT_LOW_MEMORY*/
+}
+
+int main(int argc, char* argv[])
+{
+       char ad[50] = {0,};
+       service_app_lifecycle_callback_s event_callback;
+       app_event_handler_h handlers[5] = {NULL, };
+
+       event_callback.create = service_app_create;
+       event_callback.terminate = service_app_terminate;
+       event_callback.app_control = service_app_control;
+
+       service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
+       service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
+       service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
+       service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
+
+       return service_app_main(argc, argv, &event_callback, ad);
+}
diff --git a/manager/tizen-manifest.xml b/manager/tizen-manifest.xml
new file mode 100644 (file)
index 0000000..7b15b0d
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<manifest xmlns="http://tizen.org/ns/packages" api-version="3.0" package="org.tizen.msg-manager" version="1.0.0">
+    <profile name="mobile"/>
+    <service-application appid="org.tizen.msg-manager" auto-restart="false" exec="msg-manager" multiple="false" nodisplay="true" on-boot="false" taskmanage="false" type="capp">
+        <label>msg-manager</label>
+        <icon>msg-manager.png</icon>
+        <app-control>
+            <operation name="http://tizen.org/appcontrol/operation/launch_on_event"/>
+            <uri name="event://tizen.system.event.incoming_msg"/>
+        </app-control>
+    </service-application>
+    <privileges>
+        <privilege>http://tizen.org/privilege/message.read</privilege>
+        <privilege>http://tizen.org/privilege/callhistory.write</privilege>
+    </privileges>
+</manifest>
diff --git a/msg-manager.manifest b/msg-manager.manifest
new file mode 100755 (executable)
index 0000000..2a0cec5
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+  <request>
+    <domain name="_"/>
+  </request>
+</manifest>
index de3267b..1287d34 100755 (executable)
@@ -20,6 +20,7 @@ Requires(postun): systemd
 BuildRequires: cmake
 BuildRequires: libacl-devel
 BuildRequires: pkgconfig(alarm-service)
+BuildRequires: pkgconfig(appcore-agent)
 BuildRequires: pkgconfig(aul)
 BuildRequires: pkgconfig(badge)
 BuildRequires: pkgconfig(bundle)
@@ -50,6 +51,7 @@ BuildRequires: pkgconfig(iniparser)
 BuildRequires: pkgconfig(json-glib-1.0)
 BuildRequires: pkgconfig(lbs-dbus)
 BuildRequires: pkgconfig(libcurl)
+BuildRequires: pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(libxml-2.0)
 BuildRequires: pkgconfig(libwbxml2)
 BuildRequires: pkgconfig(motion)
@@ -112,15 +114,34 @@ Requires(postun): /sbin/ldconfig
 %description -n mms-plugin
 Description: MMS plugin library
 
+%package -n msg-manager
+License:        Apache-2.0
+Summary:        Message manager application
+Requires:       %{name} = %{version}-%{release}
+Group:          Applications
+
+%description -n msg-manager
+Description: Message manager application
+
+%if "%{?profile}" != "wearable"
+%define APP_PREFIX         %{TZ_SYS_RO_APP}/msg-manager
+%define APP_BINDIR         %{APP_PREFIX}/bin
+%define APP_MANIFESTDIR    %{TZ_SYS_RO_PACKAGES}
+%endif
+
 %prep
 %setup -q
 
 %build
 cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \
-        -DLIB_INSTALL_DIR=%{_libdir} \
-        -DTZ_SYS_RO_APP=%TZ_SYS_RO_APP \
-        -DTZ_SYS_DATA=%TZ_SYS_DATA \
-        -DTZ_SYS_DB=%TZ_SYS_DB \
+               -DLIB_INSTALL_DIR=%{_libdir} \
+%if "%{?profile}" != "wearable"
+               -DAPP_MANIFESTDIR=%{APP_MANIFESTDIR}   \
+               -DAPP_BINDIR=%{APP_BINDIR}   \
+%endif
+               -DTZ_SYS_RO_APP=%TZ_SYS_RO_APP \
+               -DTZ_SYS_DATA=%TZ_SYS_DATA \
+               -DTZ_SYS_DB=%TZ_SYS_DB \
 %ifarch i586
 -D_TIZEN_I586_ENABLED:BOOL=ON \
 %else
@@ -232,4 +253,12 @@ chsmack -a "System::Shared" %{TZ_SYS_DATA}/msg-service/msgdata/thumbnails -t
 %license LICENSE.APLv2
 %{_libdir}/libmsg_mms_plugin.so
 
+%if "%{?profile}" != "wearable"
+%files -n msg-manager
+%manifest msg-manager.manifest
+%license LICENSE.APLv2
+%{APP_BINDIR}/msg-manager
+%{APP_MANIFESTDIR}/*.xml
+%endif
+
 %changelog