From: Kyeonghun Lee Date: Fri, 19 Aug 2016 09:11:49 +0000 (+0900) Subject: resolve TSAM-6816: update DB after DPM state changed X-Git-Tag: submit/tizen/20160824.005642~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=461cc9992d5883552891b6aead696a41aa1baed2;p=platform%2Fcore%2Fmessaging%2Fmsg-service.git resolve TSAM-6816: update DB after DPM state changed Change-Id: If4984536dd8f79bb06d401f2716b0e5420adfc07 Signed-off-by: Kyeonghun Lee --- diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index 1fc04c9..1405300 100755 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -131,6 +131,7 @@ INSTALL(TARGETS ${TRANS-MANAGER-LIB} DESTINATION ${LIBDIR} COMPONENT RuntimeLibr SET(MAIN-SRCS ${CMAKE_SOURCE_DIR}/framework/main.cpp + ${CMAKE_SOURCE_DIR}/framework/MsgDPMUtils.cpp ) INCLUDE_DIRECTORIES( @@ -142,7 +143,7 @@ INCLUDE_DIRECTORIES( ) INCLUDE(FindPkgConfig) -pkg_check_modules(main_pkgs REQUIRED glib-2.0 dlog vconf) +pkg_check_modules(main_pkgs REQUIRED glib-2.0 dlog vconf dpm) FOREACH(flag ${main_pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/framework/MsgDPMUtils.cpp b/framework/MsgDPMUtils.cpp new file mode 100644 index 0000000..8441e73 --- /dev/null +++ b/framework/MsgDPMUtils.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2014 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 "MsgDebug.h" +#include "MsgStorageHandler.h" +#include "MsgUtilFunction.h" +#include "MsgDPMUtils.h" + +#include + +device_policy_manager_h dpm_handle = NULL; +int dpm_sms_callback_id = 0; +int dpm_mms_callback_id = 0; + +/*================================================================================================== + FUNCTION IMPLEMENTATION +==================================================================================================*/ + +static 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; + int state = 0; + + ret = dpm_restriction_get_messaging_state(dpm_handle, &state); + if (ret != DPM_ERROR_NONE) { + MSG_ERR("dpm_restriction_get_messaging_state failed [%d]", ret); + return; + } + + msg_set_dpm_policy(MSG_SMS_TYPE, state); + + if (state == 1) { + MsgStoUpdateDPMRestrictedStatus(MSG_SMS_TYPE); + /* temporal */ + MsgStoUpdateDPMRestrictedStatus(MSG_MMS_TYPE); + } +} + +#if 0 +static 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; + int state = 0; + + ret = dpm_restriction_get_messaging_state(dpm_handle, &dpm_policy_enable[MSG_MMS_TYPE]); + if (ret != DPM_ERROR_NONE) { + MSG_ERR("dpm_restriction_get_messaging_state failed [%d]", ret); + return; + } + + msg_set_dpm_policy(MSG_MMS_TYPE, state); + + if (state == 1) + MsgStoUpdateDPMRestrictedStatus(MSG_MMS_TYPE); +} +#endif + +void __get_dpm_policy() +{ + int ret = 0; + int state = 0; + + ret = dpm_restriction_get_messaging_state(dpm_handle, &state); + if (ret != DPM_ERROR_NONE) { + MSG_ERR("dpm_restriction_get_messaging_state failed [%d]", ret); + return; + } + + MSG_DEBUG("sms policy [%d]", state); + msg_set_dpm_policy(MSG_SMS_TYPE, state); +// 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; + } +} + +void msg_init_dpm_policy() +{ + MSG_BEGIN(); + + int cnt = 5; + while (cnt--) { + dpm_handle = dpm_manager_create(); + if (dpm_handle == NULL) { + MSG_ERR("dpm_manager_create() failed"); + } else { + MSG_DEBUG("dpm_manager_create() success"); + __get_dpm_policy(); + break; + } + + sleep(1); + } + + 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); +} + diff --git a/framework/main.cpp b/framework/main.cpp index 73b6347..e33bec5 100755 --- a/framework/main.cpp +++ b/framework/main.cpp @@ -18,6 +18,7 @@ INCLUDE FILES ==================================================================================================*/ #include "MsgCallStatusManager.h" +#include "MsgDPMUtils.h" #include "MsgDebug.h" #include "MsgException.h" #include "MsgContact.h" @@ -33,7 +34,6 @@ #include "MsgStorageTypes.h" #include "MsgCmdHandler.h" #include "MsgUtilFile.h" -#include "MsgUtilFunction.h" #include "MsgUtilStorage.h" #include "MsgNotificationWrapper.h" diff --git a/framework/storage-handler/MsgStorageMessage.cpp b/framework/storage-handler/MsgStorageMessage.cpp index b1275f6..f063392 100755 --- a/framework/storage-handler/MsgStorageMessage.cpp +++ b/framework/storage-handler/MsgStorageMessage.cpp @@ -3193,6 +3193,7 @@ msg_error_t MsgStoUpdateDPMRestrictedStatus(MSG_MAIN_TYPE_T msgType) err = dbHandle->execQuery(sqlQuery); if (err == MSG_SUCCESS) { + MsgStoUpdateAllAddress(); MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_UPDATE, &msgIdList); } diff --git a/include/framework/MsgDPMUtils.h b/include/framework/MsgDPMUtils.h new file mode 100644 index 0000000..05eae28 --- /dev/null +++ b/include/framework/MsgDPMUtils.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2014 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_DPM_UTILS_H +#define MSG_DPM_UTILS_H + +/*================================================================================================== + INCLUDE FILES +==================================================================================================*/ +#include "MsgInternalTypes.h" + + +/*================================================================================================== + FUNCTION PROTOTYPES +==================================================================================================*/ + +void msg_init_dpm_policy(); +void msg_deinit_dpm_policy(); + +#endif /* MSG_DPM_UTILS_H */ diff --git a/include/utils/MsgUtilFunction.h b/include/utils/MsgUtilFunction.h index a0086a0..f5656f1 100755 --- a/include/utils/MsgUtilFunction.h +++ b/include/utils/MsgUtilFunction.h @@ -162,9 +162,7 @@ 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); -void msg_init_dpm_policy(); - -void msg_deinit_dpm_policy(); +void msg_set_dpm_policy(int type, int state); bool msg_check_dpm_policy(int type); diff --git a/plugin/mms_plugin/CMakeLists.txt b/plugin/mms_plugin/CMakeLists.txt index 2c48923..fb6b1ad 100755 --- a/plugin/mms_plugin/CMakeLists.txt +++ b/plugin/mms_plugin/CMakeLists.txt @@ -34,7 +34,6 @@ SET(MMS-PLUGIN-SRCS INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/include/common - ${CMAKE_SOURCE_DIR}/include/framework ${CMAKE_SOURCE_DIR}/include/utils ${CMAKE_SOURCE_DIR}/include/externals ${CMAKE_SOURCE_DIR}/include/mapi diff --git a/plugin/mms_plugin/MmsPluginInternal.cpp b/plugin/mms_plugin/MmsPluginInternal.cpp index ca89aaf..d6e00d8 100755 --- a/plugin/mms_plugin/MmsPluginInternal.cpp +++ b/plugin/mms_plugin/MmsPluginInternal.cpp @@ -24,7 +24,6 @@ #include "MsgSettingTypes.h" #include "MsgMmsMessage.h" #include "MsgGconfWrapper.h" -#include "MsgStorageHandler.h" #include "MsgSerialize.h" #include "MsgSpamFilter.h" #include "MsgUtilMime.h" diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index fa9fa46..c20bbaa 100755 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -39,14 +39,13 @@ SET(UTILS-SRCS INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/include/mapi ${CMAKE_SOURCE_DIR}/include/common - ${CMAKE_SOURCE_DIR}/include/framework ${CMAKE_SOURCE_DIR}/include/utils ${CMAKE_SOURCE_DIR}/vobject-engine/include ) 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 dpm) +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) pkg_check_modules(utils_pkgs REQUIRED ${PKG_MODULES}) FOREACH(flag ${utils_pkgs_CFLAGS}) diff --git a/utils/MsgUtilFunction.cpp b/utils/MsgUtilFunction.cpp index 4df7ace..fc6fd6f 100755 --- a/utils/MsgUtilFunction.cpp +++ b/utils/MsgUtilFunction.cpp @@ -30,7 +30,6 @@ #include #include #include -#include typedef struct _msg_launch_app_data { char *app_id; @@ -56,11 +55,6 @@ static int dpm_policy_enable[] = { [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 @@ -1311,91 +1305,14 @@ msg_error_t msg_aul_svc_set_uri(bundle *bundle_data, char *uri) } -void dpm_sms_policy_changed_callback(const char* name, const char* object, void *user_data) +void msg_set_dpm_policy(int type, int state) { - 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; - } + dpm_policy_enable[type] = state; } -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() -{ - 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; - } - - return true; -} - -void msg_init_dpm_policy() -{ - MSG_BEGIN(); - - dpm_handle = dpm_manager_create(); - if (dpm_handle == NULL) { - MSG_ERR("dpm_manager_create() failed"); - return; - } - - 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; -} - bool msg_check_dpm_policy(int type) { - if (is_dpm_init == false) - msg_init_dpm_policy(); - return dpm_policy_enable[MSG_SMS_TYPE]; // return dpm_policy_enable[type]; }