Refactor badge 44/310444/23
authorjh9216.park <jh9216.park@samsung.com>
Mon, 29 Apr 2024 07:13:32 +0000 (03:13 -0400)
committerjh9216.park <jh9216.park@samsung.com>
Wed, 5 Jun 2024 04:50:30 +0000 (00:50 -0400)
 - Use TIDL instead of dbus
 - Use C++ instead of c
 - Add service module using libesd
 - Summary coverage rate:
   lines......: 88.3% (227 of 257 lines)
   functions..: 92.5% (37 of 40 functions)
 - Require
   https://review.tizen.org/gerrit/#/c/platform/core/appfw/data-provider-master/+/309339/

Change-Id: Icb8b62406145668967121d9b3d51aff7a2dfb057
Signed-off-by: jh9216.park <jh9216.park@samsung.com>
43 files changed:
11_badge-add.post [deleted file]
CMakeLists.txt
include/badge_db.h [deleted file]
include/badge_internal.h [deleted file]
include/badge_ipc.h [deleted file]
include/badge_private.h [deleted file]
include/badge_setting.h [deleted file]
include/badge_setting_service.h [deleted file]
include/log_private.h [new file with mode: 0644]
modules/CMakeLists.txt [new file with mode: 0644]
modules/badge/CMakeLists.txt [new file with mode: 0644]
modules/badge/badge.cc [new file with mode: 0644]
modules/badge/badge_module.cc [new file with mode: 0644]
modules/badge/badge_module.hh [new file with mode: 0644]
modules/badge/badge_service.cc [new file with mode: 0644]
modules/badge/badge_service.hh [new file with mode: 0644]
packaging/badge.spec
src/CMakeLists.txt
src/badge.c [deleted file]
src/badge.cc [new file with mode: 0644]
src/badge_db.c [deleted file]
src/badge_error.c [deleted file]
src/badge_internal.c [deleted file]
src/badge_ipc.c [deleted file]
src/badge_setting.c [deleted file]
src/badge_setting_service.c [deleted file]
tests/CMakeLists.txt
tests/integ_tests/CMakeLists.txt [new file with mode: 0644]
tests/integ_tests/src/test_badge.cc [new file with mode: 0644]
tests/integ_tests/src/test_main.cc [moved from tests/mock/package_manager_mock.h with 60% similarity]
tests/mock/aul_mock.cc
tests/mock/aul_mock.h
tests/mock/gio_mock.cc [deleted file]
tests/mock/gio_mock.h [deleted file]
tests/mock/rpc_port_mock.cc [moved from tests/mock/package_manager_mock.cc with 63% similarity]
tests/mock/rpc_port_mock.h [new file with mode: 0644]
tests/unit_tests/CMakeLists.txt
tests/unit_tests/src/test_badge.cc
tests/unit_tests/src/test_main.cc
tidl/badge.tidl [new file with mode: 0755]
tidl/prebuild.sh [new file with mode: 0755]
tool/CMakeLists.txt [deleted file]
tool/badge_init.c [deleted file]

diff --git a/11_badge-add.post b/11_badge-add.post
deleted file mode 100644 (file)
index f535dc4..0000000
+++ /dev/null
@@ -1 +0,0 @@
-badge_init --uid $2
index 50288a3..4af77e2 100644 (file)
@@ -8,8 +8,8 @@ SET(LIBDIR ${LIB_INSTALL_DIR})
 SET(INCLUDEDIR "\${prefix}/include/badge")
 
 ## Compiler flags
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -g -Wall -Werror")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++14 -Wall -Werror")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -g ")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++1")
 SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
 SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
 
@@ -21,6 +21,8 @@ SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Mo
 ## Targets
 SET(TARGET_BADGE "badge")
 SET(TARGET_BADGE_INIT "badge_init")
+SET(TARGET_ESD_MOD_BADGE "esd-mod-badge")
+SET(TARGET_BADGE_INTEGTESTS "badge_integtests")
 
 ENABLE_TESTING()
 SET(TARGET_BADGE_UNIT_TEST "badge_unittests")
@@ -30,21 +32,19 @@ INCLUDE(FindPkgConfig)
 INCLUDE(ApplyPkgConfig)
 
 ## Find all needed packages once
-PKG_CHECK_MODULES(AUL_DEP REQUIRED aul)
 PKG_CHECK_MODULES(DLOG_DEPS REQUIRED dlog)
 PKG_CHECK_MODULES(VCONF_DEPS REQUIRED vconf)
-PKG_CHECK_MODULES(PKGMGR_DEPS REQUIRED capi-appfw-package-manager)
 PKG_CHECK_MODULES(SYSTEM_INFO_DEPS REQUIRED capi-system-info)
-PKG_CHECK_MODULES(DB_UTIL_DEPS REQUIRED db-util)
-PKG_CHECK_MODULES(PLATFORM_CONFIG_DEPS REQUIRED libtzplatform-config)
-PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info)
-PKG_CHECK_MODULES(SMACK_DEPS REQUIRED libsmack)
-PKG_CHECK_MODULES(GLIB_DEPS REQUIRED glib-2.0)
-PKG_CHECK_MODULES(GIO_DEPS REQUIRED gio-2.0)
-PKG_CHECK_MODULES(GOBJECT_DEPS REQUIRED gobject-2.0)
 PKG_CHECK_MODULES(BUNDLE_DEPS REQUIRED bundle)
 PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock)
+PKG_CHECK_MODULES(ESD_DEPS REQUIRED libesd)
+PKG_CHECK_MODULES(TIZEN_DATABASE_DEPS REQUIRED tizen-database)
+PKG_CHECK_MODULES(APP_MANAGER_DEPS REQUIRED capi-appfw-app-manager)
+PKG_CHECK_MODULES(PACKAGE_MANAGER_DEPS REQUIRED capi-appfw-package-manager)
+PKG_CHECK_MODULES(APP_COMMON_DEPS REQUIRED capi-appfw-app-common)
+PKG_CHECK_MODULES(RPC_PORT_DEPS REQUIRED rpc-port)
+PKG_CHECK_MODULES(GLIB_2_DEPS REQUIRED glib-2.0)
 
 ADD_SUBDIRECTORY(src)
-ADD_SUBDIRECTORY(tool)
+ADD_SUBDIRECTORY(modules)
 ADD_SUBDIRECTORY(tests)
diff --git a/include/badge_db.h b/include/badge_db.h
deleted file mode 100644 (file)
index f469574..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2000 - 2017 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 __BADGE_DB_DEF_H__
-#define __BADGE_DB_DEF_H__
-
-#include <stdbool.h>
-#include <sqlite3.h>
-#include <sys/types.h>
-#include <gio/gio.h>
-#include <tzplatform_config.h>
-#include <badge_error.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define BADGE_DB_PATH tzplatform_mkpath(TZ_SYS_DB, ".badge.db")
-#define BADGE_SETTING_DB_TABLE "badge_setting"
-#define BADGE_TABLE_NAME "badge_data"
-#define BADGE_OPTION_TABLE_NAME "badge_option"
-
-int badge_db_insert(const char *pkgname, const char *writable_pkg, const char *caller, uid_t uid);
-int badge_db_delete(const char *pkgname, const char *caller_pkg, uid_t uid, pid_t pid);
-int badge_db_delete_by_pkgname(const char *pkgname, uid_t uid);
-int badge_db_set_count(const char *pkgname, const char *caller_pkg, unsigned int count, uid_t uid, pid_t pid);
-int badge_db_get_count(const char *pkgname, unsigned int *count, uid_t uid);
-int badge_db_set_display_option(const char *pkgname, unsigned int is_display, uid_t uid);
-int badge_db_get_display_option(const char *pkgname, unsigned int *is_display, uid_t uid);
-int badge_db_exec(sqlite3 *db, const char *query, int *num_changes);
-int badge_db_get_list(GList **badge_list, uid_t uid);
-int badge_db_is_existing(const char *pkgname, bool *existing, uid_t uid);
-int badge_db_init();
-
-#ifdef __cplusplus
-       }
-#endif
-
-#endif /* __BADGE_DB_DEF_H__ */
-
diff --git a/include/badge_internal.h b/include/badge_internal.h
deleted file mode 100644 (file)
index 1d9b576..0000000
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * Copyright (c) 2000 - 2017 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 __BADGE_INTERNAL_DEF_H__
-#define __BADGE_INTERNAL_DEF_H__
-
-#include <stdbool.h>
-#include <stdarg.h>
-#include <glib.h>
-#include <sys/types.h>
-
-#include "badge_error.h"
-#include "badge.h"
-
-#ifndef EXPORT_API
-#define EXPORT_API __attribute__ ((visibility("default")))
-#endif
-
-#ifndef DEPRECATED
-#define DEPRECATED __attribute__((deprecated))
-#endif
-
-#define BADGE_ERROR (badge_error_quark())
-GQuark badge_error_quark(void);
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-typedef struct _badge_h badge_h;
-
-typedef struct badge_info {
-       char *pkg;
-       unsigned int badge_count;
-} badge_info_s;
-
-/**
- * @internal
- * @brief Checks whether badge service is ready.
- * @since_tizen 2.3
- * @privlevel public
- * @privilege %http://tizen.org/privilege/notification
- * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
- * @return 1 if badge service is ready, other value if badge service isn't ready
- * @retval BADGE_ERROR_NONE Success
- * @retval BADGE_ERROR_NOT_SUPPORTED Not supported
- * @retval BADGE_ERROR_SERVICE_NOT_READY Service is not ready
- */
-int badge_is_service_ready(void);
-
-/**
- * @internal
- * @brief Adds deferred task. The registered task will be executed when badge service become ready.
- * @since_tizen 2.3
- * @privlevel public
- * @privilege %http://tizen.org/privilege/notification
- * @param[in] badge_add_deferred_task The callback function
- * @param[in] user_data The user data to be passed to the callback function
- * @return #BADGE_ERROR_NONE if success, other value if failure
- * @retval BADGE_ERROR_NONE Success
- * @retval BADGE_ERROR_NOT_SUPPORTED Not supported
- * @retval BADGE_ERROR_PERMISSION_DENIED Permission denied
- * @retval BADGE_ERROR_OUT_OF_MEMORY Out of memory
- * @see #badge_error_e
- * @see badge_is_service_ready()
- */
-int badge_add_deferred_task(
-               void (*badge_add_deferred_task)(void *data), void *user_data);
-
-/**
- * @internal
- * @brief Removes deferred task.
- * @since_tizen 2.3
- * @privlevel public
- * @privilege %http://tizen.org/privilege/notification
- * @param[in] badge_add_deferred_task The callback function
- * @return #BADGE_ERROR_NONE if success, other value if failure
- * @retval BADGE_ERROR_NONE Success
- * @retval BADGE_ERROR_NOT_SUPPORTED Not supported
- * @retval BADGE_ERROR_PERMISSION_DENIED Permission denied
- * @retval BADGE_ERROR_INVALID_PARAMETER Invalid parameter
- * @see #badge_error_e
- * @see badge_is_service_ready()
- */
-int badge_del_deferred_task(
-               void (*badge_add_deferred_task)(void *data));
-
-/**
- * @internal
- * @brief Tests if the badge for the designated application exists or not.
- * @since_tizen 2.3
- * @privlevel public
- * @privilege %http://tizen.org/privilege/notification
- * @param[in] app_id The name of the designated application
- * @param[out] existing The bool value of badge existence status
- * @return #BADGE_ERROR_NONE if success, other value if failure
- * @retval BADGE_ERROR_NONE Success
- * @retval BADGE_ERROR_NOT_SUPPORTED Not supported
- * @retval BADGE_ERROR_PERMISSION_DENIED Permission denied
- * @retval BADGE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval BADGE_ERROR_FROM_DB Error from DB
- * @retval BADGE_ERROR_OUT_OF_MEMORY Out of memory
- * @retval BADGE_ERROR_NOT_EXIST Not exist
- * @retval BADGE_ERROR_SERVICE_NOT_READY Service is not ready
- * @see #badge_error_e
- * @see badge_new()
- * @see badge_remove()
- * @par Sample code:
- * @code
-#include <badge.h>
-...
-{
-       int err = BADGE_ERROR_NONE;
-       bool exist;
-
-       err = badge_is_existing(app_id, &exist);
-       if (err != BADGE_ERROR_NONE) {
-               return;
-       }
-
-}
- * @endcode
- */
-int badge_is_existing(const char *app_id, bool *existing);
-
-char *_badge_get_pkgname_by_pid(void);
-
-int _badge_is_existing(const char *pkgname, bool *existing, uid_t uid);
-
-int _badge_get_list(GList **badge_list, uid_t uid);
-
-int _badge_insert(badge_h *badge, uid_t uid);
-
-int _badge_remove(const char *caller, const char *pkgname, uid_t uid, pid_t pid);
-
-int _badge_remove_by_pkgname(const char *pkgname, uid_t uid);
-
-int _badge_set_count(const char *caller, const char *pkgname,
-                       unsigned int count, uid_t uid, pid_t pid);
-
-int _badge_get_count(const char *pkgname, unsigned int *count, uid_t uid);
-
-int _badge_set_display(const char *pkgname, unsigned int is_display, uid_t uid);
-
-int _badge_get_display(const char *pkgname, unsigned int *is_display, uid_t uid);
-
-int _badge_free(badge_h *badge);
-
-badge_h *_badge_new(const char *pkgname, const char *writable_pkgs,
-               int *err);
-
-char *_badge_pkgs_new(int *err, const char *pkg1, ...);
-
-void badge_changed_cb_call(unsigned int action, const char *pkgname,
-                       unsigned int count, uid_t uid);
-
-/**
- * @internal
- * @brief Creates a badge for the designated package.
- * @details Creates new badge to display.
- * @since_tizen 2.3
- * @privlevel public
- * @privilege %http://tizen.org/privilege/notification
- * @param[in] pkgname The name of the designated package
- * @param[in] writable_pkg The name of package which is authorized to change the badge
- * @return #BADGE_ERROR_NONE if success, other value if failure
- * @retval #BADGE_ERROR_NOT_SUPPORTED Not supported
- * @see #badge_error_e
- * @par Sample code:
- * @code
-#include <badge.h>
-...
-{
-       int err = BADGE_ERROR_NONE;
-
-       err = badge_create("org.tizen.sms", "org.tizen.sms2");
-       if (err != BADGE_ERROR_NONE) {
-               return;
-       }
-
-}
- * @endcode
- */
-int badge_create(const char *pkgname, const char *writable_pkg);
-
-int badge_create_for_uid(const char *pkgname, const char *writable_pkg, uid_t uid);
-
-int badge_new_for_uid(const char *writable_app_id, uid_t uid);
-
-/**
- * @internal
- * @brief Creates a badge for the application specified by the badge_app_id.
- * @details Creates new badge to display.
- * @since_tizen 5.5
- * @privlevel public
- * @privilege %http://tizen.org/privilege/notification
- * @param[in] badge_app_id The id of the application for which the badge will be created. This should be the same package id with the caller application's package id
- * @param[in] writable_app_id The id of the application which is authorized to change the badge
- * @return #BADGE_ERROR_NONE if success, other value if failure
- * @retval #BADGE_ERROR_NONE Success
- * @retval #BADGE_ERROR_PERMISSION_DENIED Permission denied
- * @retval #BADGE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #BADGE_ERROR_IO_ERROR Error from I/O
- * @retval #BADGE_ERROR_SERVICE_NOT_READY Service is not ready
- * @retval #BADGE_ERROR_INVALID_PACKAGE Error while caller package is different with the id of the application badge creates
- * @see #badge_error_e
- * @par Sample code:
- * @code
-#include <badge_internal.h>
-
-{
-       int err = BADGE_ERROR_NONE;
-
-       err = badge_new_for(badge_app_id,app_id);
-       if(err != BADGE_ERROR_NONE) {
-               return;
-       }
-}
- * @endcode
- */
-int badge_new_for(const char *badge_app_id, const char *writable_app_id);
-int badge_new_for_for_uid(const char *badge_app_id, const char *writable_app_id, uid_t uid);
-
-int badge_add_for_uid(const char *badge_app_id, uid_t uid);
-
-int badge_remove_for_uid(const char *app_id, uid_t uid);
-
-int badge_is_existing_for_uid(const char *app_id, bool *existing, uid_t uid);
-
-int badge_foreach_for_uid(badge_foreach_cb callback, void *user_data, uid_t uid);
-
-int badge_set_count_for_uid(const char *app_id, unsigned int count, uid_t uid);
-
-int badge_get_count_for_uid(const char *app_id, unsigned int *count, uid_t uid);
-
-int badge_set_display_for_uid(const char *app_id, unsigned int is_display, uid_t uid);
-
-int badge_get_display_for_uid(const char *app_id, unsigned int *is_display, uid_t uid);
-
-int badge_register_changed_cb_for_uid(badge_change_cb callback, void *data, uid_t uid);
-
-int badge_unregister_changed_cb_for_uid(badge_change_cb callback, uid_t uid);
-
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* __BADGE_INTERNAL_DEF_H__ */
-
diff --git a/include/badge_ipc.h b/include/badge_ipc.h
deleted file mode 100644 (file)
index 84a5291..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 2000 - 2017 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 __BADGE_IPC_H__
-#define __BADGE_IPC_H__
-
-#include <badge.h>
-#include <badge_setting.h>
-#include <sys/types.h>
-#include <glib.h>
-
-#define BADGE_ADDR "/tmp/.badge.service"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct packet;
-
-int badge_ipc_monitor_init(uid_t uid);
-int badge_ipc_monitor_fini(void);
-
-int badge_ipc_request_insert(const char *pkgname, const char *writable_pkg, const char *caller, uid_t uid);
-int badge_ipc_request_delete(const char *pkgname, const char *caller, uid_t uid);
-int badge_ipc_request_set_count(const char *pkgname, const char *caller, int count, uid_t uid);
-int badge_ipc_request_get_count(const char *pkgname, unsigned int *count, uid_t uid);
-int badge_ipc_request_set_display(const char *pkgname, const char *caller, unsigned int display_option, uid_t uid);
-int badge_ipc_request_get_display(const char *pkgname, unsigned int *is_display, uid_t uid);
-
-int badge_ipc_is_master_ready(void);
-int badge_ipc_add_deferred_task(void (*badge_add_deferred_task)(void *data), void *user_data);
-int badge_ipc_del_deferred_task(void (*badge_add_deferred_task)(void *data));
-
-int badge_ipc_request_get_list(badge_foreach_cb callback, void *data, uid_t uid);
-int badge_ipc_request_is_existing(const char *pkgname, bool *existing, uid_t uid);
-
-int badge_ipc_request_update_setting(badge_setting_h setting, uid_t uid);
-int badge_ipc_request_get_setting_by_appid(badge_setting_h *setting, const char *appid, uid_t uid);
-int badge_ipc_init_badge(uid_t uid);
-
-GVariant *badge_ipc_make_gvariant_from_setting(badge_setting_h setting);
-int badge_ipc_make_setting_from_gvariant(badge_setting_h setting, GVariant *variant);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/include/badge_private.h b/include/badge_private.h
deleted file mode 100644 (file)
index c26cca1..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2017 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 __BADGE_PRIVATE_H__
-#define __BADGE_PRIVATE_H__
-
-#include <system_info.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-#define BADGE_FEATURE "http://tizen.org/feature/badge"
-#define CHECK_BADGE_FEATURE() \
-       do { \
-               bool is_supported = false; \
-               if (!system_info_get_platform_bool(BADGE_FEATURE, &is_supported)) { \
-                       if (is_supported == false) { \
-                               LOGE("[%s] feature is disabled", BADGE_FEATURE); \
-                               return BADGE_ERROR_NOT_SUPPORTED; \
-                       } \
-               } \
-       } while (0)
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* __BADGE_PRIVATE_H__ */
diff --git a/include/badge_setting.h b/include/badge_setting.h
deleted file mode 100644 (file)
index 674c8dc..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2016 - 2017 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 __BADGE_SETTING_H__
-#define __BADGE_SETTING_H__
-
-#include <stdbool.h>
-#include <sys/types.h>
-#include "badge_error.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif /*  __cplusplus */
-
-/**
- * @file badge_setting.h
- * @brief This file contains the badge APIs.
- */
-
-/**
- * @addtogroup BADGE_MODULE
- * @{
- */
-
-typedef struct badge_setting *badge_setting_h;
-
-struct badge_setting {
-       char *pkgname;
-       char *appid;
-       int allow_to_display;
-};
-
-int badge_setting_get_pkgname(badge_setting_h setting, char **pkgname);
-int badge_setting_get_appid(badge_setting_h setting, char **appid);
-int badge_setting_set_allow_to_display(badge_setting_h setting, bool value);
-int badge_setting_get_allow_to_display(badge_setting_h setting, bool *value);
-int badge_setting_update_setting(badge_setting_h setting);
-int badge_setting_update_setting_for_uid(badge_setting_h setting, uid_t uid);
-int badge_setting_get_setting_by_appid(badge_setting_h *setting, const char *appid);
-int badge_setting_get_setting_by_appid_for_uid(badge_setting_h *setting, const char *appid, uid_t uid);
-int badge_setting_free_setting(badge_setting_h setting);
-
-/**
- * @}
- */
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* __BADGE_SETTING_H__ */
diff --git a/include/badge_setting_service.h b/include/badge_setting_service.h
deleted file mode 100644 (file)
index af0f0e5..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2016 - 2017 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 __BADGE_SETTING_SERVICE_H__
-#define __BADGE_SETTING_SERVICE_H__
-
-#include <stdbool.h>
-#include <sys/types.h>
-#include "badge_error.h"
-#include "badge_setting.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif /*  __cplusplus */
-
-/**
- * @file badge_setting_service.h
- * @brief This file contains the badge APIs.
- */
-
-/**
- * @addtogroup BADGE_MODULE
- * @{
- */
-
-int badge_db_get_setting_by_appid(const char *appid, badge_setting_h *setting, uid_t uid);
-int badge_db_get_allow_to_display_by_appid(char *appid, int *allow_to_display, uid_t uid);
-int badge_setting_insert_package_for_uid(const char *pkgname, uid_t uid);
-int badge_setting_delete_package_for_uid(const char *pkgname, uid_t uid);
-int badge_setting_refresh_setting_table(uid_t uid);
-int badge_db_update_setting(char *pkgname, char *appid, int allow_to_display, uid_t uid);
-int badge_db_update_app_disabled(const char *app_id, bool disabled, uid_t uid);
-int badge_db_update_pkg_disabled(const char *pkg_id, bool disabled, uid_t uid);
-int badge_setting_is_existed_appid(const char *appid, bool *is_existed, uid_t uid);
-int badge_setting_arrange_tables(uid_t uid);
-
-/**
- * @}
- */
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* __BADGE_SETTING_SERVICE_H__ */
-
diff --git a/include/log_private.h b/include/log_private.h
new file mode 100644 (file)
index 0000000..fd8196b
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2024 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 BADGE_LOG_PRIVATE_H_
+#define BADGE_LOG_PRIVATE_H_
+
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "BADGE"
+
+#undef _E
+#define _E LOGE
+
+#undef _W
+#define _W LOGW
+
+#undef _I
+#define _I LOGI
+
+#undef _D
+#define _D LOGD
+
+#endif  // BADGE_LOG_PRIVATE_H_
diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt
new file mode 100644 (file)
index 0000000..947ec8d
--- /dev/null
@@ -0,0 +1 @@
+ADD_SUBDIRECTORY(badge)
diff --git a/modules/badge/CMakeLists.txt b/modules/badge/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0848380
--- /dev/null
@@ -0,0 +1,22 @@
+REMOVE_DEFINITIONS("-DDB_PATH")\r
+ADD_DEFINITIONS("-DDB_PATH=\"${DB_PATH}\"")\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} ESD_MOD_BADGE_SRCS)\r
+\r
+ADD_LIBRARY(${TARGET_ESD_MOD_BADGE} ${ESD_MOD_BADGE_SRCS})\r
+TARGET_INCLUDE_DIRECTORIES(${TARGET_ESD_MOD_BADGE} PUBLIC\r
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../include)\r
+\r
+TARGET_LINK_LIBRARIES(${TARGET_ESD_MOD_BADGE} PRIVATE ${TARGET_LIB_ESD})\r
+\r
+APPLY_PKG_CONFIG(${TARGET_ESD_MOD_BADGE} PUBLIC\r
+  DLOG_DEPS\r
+  ESD_DEPS\r
+  RPC_PORT_DEPS\r
+  APP_MANAGER_DEPS\r
+  PACKAGE_MANAGER_DEPS\r
+  APP_COMMON_DEPS\r
+  TIZEN_DATABASE_DEPS\r
+)\r
+\r
+INSTALL(TARGETS ${TARGET_ESD_MOD_BADGE} DESTINATION ${ESD_MODULES_DIR}/mod\r
+  COMPONENT RuntimeLibraries)\r
diff --git a/modules/badge/badge.cc b/modules/badge/badge.cc
new file mode 100644 (file)
index 0000000..ea5e09e
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ *
+ * 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 "badge_module.hh"
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+extern "C" EXPORT_API esd::api::IModule* ESD_GET_MODULE() {
+  return new esd::module::BadgeModule();
+}
diff --git a/modules/badge/badge_module.cc b/modules/badge/badge_module.cc
new file mode 100644 (file)
index 0000000..f6970fe
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ *
+ * 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 "badge_module.hh"
+
+#include <rpc-port-internal.h>
+
+#include "log_private.h"
+#include "badge_service.hh"
+
+namespace esd::module {
+
+bool BadgeModule::Startup(api::ToolBox* tools) {
+  int ret = rpc_port_register_proc_info("d::org.tizen.appfw.service.esd",
+      nullptr);
+  if (ret != RPC_PORT_ERROR_NONE) {
+    /* LCOV_EXCL_START */
+    _I("rpc_port_register_proc_info() failed (%d)", ret);
+    /* LCOV_EXCL_STOP */
+  }
+
+  try {
+    badge_.Listen(std::shared_ptr<rpc_stub::Badge::ServiceBase::Factory>(
+        new BadgeService::Factory(badge_)));
+  } catch (const rpc_stub::InvalidIOException& e) {
+    /* LCOV_EXCL_START */
+    _E("InvalidIOException happened");
+    return false;
+    /* LCOV_EXCL_STOP */
+  }
+
+  return true;
+}
+
+void BadgeModule::Shutdown() {
+}
+
+}  //namespace esd::module
diff --git a/modules/badge/badge_module.hh b/modules/badge/badge_module.hh
new file mode 100644 (file)
index 0000000..d45469a
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ *
+ * 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 MODULES_BADGE_BADGE_MODULE_HH_
+#define MODULES_BADGE_BADGE_MODULE_HH_
+
+#include <list>
+#include <memory>
+#include <optional>
+#include <string>
+#include <imodule.hh>
+
+#include "badge_stub.h"
+
+namespace esd::module {
+
+namespace rpc_stub = rpc_port::badge_stub::stub;
+
+class BadgeModule : public api::IModule {
+ public:
+  BadgeModule() = default;
+  virtual ~BadgeModule() = default;
+
+  bool Startup(api::ToolBox* tools) override;
+  void Shutdown() override;
+
+ private:
+  rpc_stub::Badge badge_;
+};
+
+}  // namespace esd::module
+
+#endif  // MODULES_BADGE_BADGE_MODULE_HH_
\ No newline at end of file
diff --git a/modules/badge/badge_service.cc b/modules/badge/badge_service.cc
new file mode 100644 (file)
index 0000000..b24803e
--- /dev/null
@@ -0,0 +1,328 @@
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ *
+ * 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 "badge_service.hh"
+
+#include <unistd.h>
+
+#include "log_private.h"
+
+namespace esd::module {
+
+namespace {
+
+constexpr const char BADGE_DB_PATH[] = DB_PATH;
+bool is_db_corrupted_ = false;
+
+constexpr const char QUERY_CREATE_BADGE_TABLE[] =
+  R"__bg(PRAGMA journal_mode = PERSIST;
+  PRAGMA synchronous = FULL;
+  CREATE TABLE IF NOT EXISTS badge_data (
+    uid INTEGER,
+    pkgname TEXT NOT NULL,
+    writable_pkgs TEXT,
+    badge INTEGER DEFAULT 0,
+    rowid INTEGER PRIMARY KEY AUTOINCREMENT,
+    UNIQUE (uid, pkgname)
+  );
+  CREATE TABLE IF NOT EXISTS badge_option (
+    uid INTEGER,
+    pkgname TEXT NOT NULL,
+    display INTEGER DEFAULT 1,
+    UNIQUE (uid, pkgname)
+  );
+  CREATE TABLE IF NOT EXISTS badge_setting (
+    uid INTEGER,
+    pkgname TEXT NOT NULL,
+    appid TEXT NOT NULL,
+    allow_to_display INTEGER DEFAULT 1,
+    UNIQUE (uid, pkgname, appid)
+);)__bg";
+
+int CheckIntegrityCb(void* pid, int argc, char** argv, char** notUsed) {
+  if (strcmp(argv[0], "ok") != 0) {
+    _E("db integrity result : %s", argv[0]);
+    is_db_corrupted_ = true;
+    return -1;
+  }
+
+  _I("db integrity result : %s", argv[0]);
+  return 0;
+}
+
+void RecoverCorruptedDb() {
+  _I("RecoverCorruptedDb");
+  unlink(BADGE_DB_PATH);
+  try {
+    tizen_base::Database db(BADGE_DB_PATH,
+        SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE);
+    db.OneStepExec({ QUERY_CREATE_BADGE_TABLE });
+  } catch(const tizen_base::DbException& e) {
+    _E("RecoverCorruptedDb failed : %s", e.msg());
+  }
+}
+
+void DbInit() {
+  try {
+    tizen_base::Database db(BADGE_DB_PATH,
+        SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE);
+    db.OneStepExec({ QUERY_CREATE_BADGE_TABLE });
+    int ret = sqlite3_exec(db.GetRaw(), "PRAGMA integrity_check",
+          CheckIntegrityCb, nullptr, nullptr);
+    if (ret != SQLITE_OK || is_db_corrupted_) {
+      throw tizen_base::DbException("Integrity checking failed", ret);
+    }
+  } catch(const tizen_base::DbException& e) {
+    int code = e.code();
+    if (code == SQLITE_CORRUPT || code == SQLITE_NOTADB
+        || is_db_corrupted_) {
+      RecoverCorruptedDb();
+    }
+  }
+}
+
+}
+
+void BadgeService::OnCreate() {
+  DbInit();
+}
+
+void BadgeService::OnTerminate() {
+}
+
+bool BadgeService::IsExist(const tizen_base::Database& db, std::string appid) {
+  auto q = tizen_base::Database::Sql("SELECT count(*) FROM badge_data "
+      "WHERE pkgname = ?")
+      .Bind(appid);
+  auto r = db.Exec(q);
+  if (!r)
+    return false;
+  auto rec = r.GetFirstRecord();
+  if (!rec)
+    return false;
+
+  if (static_cast<int>(rec->Get(0)) > 0)
+    return true;
+
+  return false;
+}
+
+bool BadgeService::IsWritable(const tizen_base::Database& db,
+    const std::string& appid, const std::string& caller) {
+  auto q = tizen_base::Database::Sql("SELECT count(*) FROM badge_data "
+      "WHERE pkgname = ? AND writable_pkgs LIKE ?")
+      .Bind(appid)
+      .Bind("%" + caller + "%");
+  auto r = db.Exec(q);
+  if (!r)
+    return false;
+  auto rec = r.GetFirstRecord();
+  if (!rec)
+    return false;
+
+  if (static_cast<int>(rec->Get(0)) > 0)
+    return true;
+
+  return false;
+}
+
+std::vector<rpc::BadgeInfo> BadgeService::GetList() {
+  std::vector<rpc::BadgeInfo> ret;
+  try {
+    tizen_base::Database db(BADGE_DB_PATH, SQLITE_OPEN_READONLY);
+    auto q = tizen_base::Database::Sql("SELECT pkgname, badge FROM badge_data");
+    for (const auto& i : db.Exec(q)) {
+      ret.emplace_back(static_cast<std::string>(i.Get(0)),
+          static_cast<int>(i.Get(1)));
+    }
+  } catch(...) { /* LCOV_EXCL_LINE */
+    return {}; /* LCOV_EXCL_LINE */
+  }
+
+  return ret;
+}
+
+bool BadgeService::Insert(std::string appid, std::string writable_pkg, std::string caller) {
+  try {
+    tizen_base::Database db(BADGE_DB_PATH, SQLITE_OPEN_READWRITE);
+    if (IsExist(db, appid))
+      return false;
+
+    auto q = tizen_base::Database::Sql("INSERT INTO badge_data "
+        "(pkgname, writable_pkgs, uid) VALUES (?, ?, ?)")
+        .Bind(appid)
+        .Bind(writable_pkg)
+        .Bind(5001);
+    auto r = db.Exec(q);
+    if (!r)
+      return false;
+
+    const auto& services = parent_.GetServices();
+    for (auto& s : services) {
+      auto* ptr = static_cast<BadgeService*>(s.get());
+      ptr->NotifyChangedEvent(rpc::BadgeInfo::Action::Create, appid, 0);
+    }
+  } catch(...) { /* LCOV_EXCL_LINE */
+    return false; /* LCOV_EXCL_LINE */
+  }
+
+  return true;
+}
+
+bool BadgeService::Delete(std::string appid, std::string caller) {
+  try {
+    tizen_base::Database db(BADGE_DB_PATH, SQLITE_OPEN_READWRITE);
+    if (!IsExist(db, appid))
+      return false;
+
+    if (!IsWritable(db, appid, caller))
+      return false;
+
+    auto q = tizen_base::Database::Sql("DELETE FROM badge_data "
+        "WHERE pkgname = ?")
+        .Bind(appid);
+    auto r = db.Exec(q);
+    if (!r)
+      return false;
+
+    const auto& services = parent_.GetServices();
+    for (auto& s : services) {
+      auto* ptr = static_cast<BadgeService*>(s.get());
+      ptr->NotifyChangedEvent(rpc::BadgeInfo::Action::Remove, appid, 0);
+    }
+  } catch (...) { /* LCOV_EXCL_LINE */
+    return false; /* LCOV_EXCL_LINE */
+  }
+
+  return true;
+}
+
+bool BadgeService::SetCount(std::string appid, std::string caller, int count) {
+  try {
+    tizen_base::Database db(BADGE_DB_PATH, SQLITE_OPEN_READWRITE);
+
+    if (!IsExist(db, appid))
+      return false;
+
+    if (!IsWritable(db, appid, caller))
+      return false;
+
+    auto q = tizen_base::Database::Sql("UPDATE badge_data SET badge = ? "
+        "WHERE pkgname = ?")
+        .Bind(count)
+        .Bind(appid);
+    auto r = db.Exec(q);
+    if (!r)
+      return false;
+
+    const auto& services = parent_.GetServices();
+    for (auto& s : services) {
+      auto* ptr = static_cast<BadgeService*>(s.get());
+      ptr->NotifyChangedEvent(rpc::BadgeInfo::Action::Update, appid, count);
+    }
+  } catch(...) { /* LCOV_EXCL_LINE */
+    return false; /* LCOV_EXCL_LINE */
+  }
+
+  return true;
+}
+
+int BadgeService::GetCount(std::string appid) {
+  try {
+    tizen_base::Database db(BADGE_DB_PATH, SQLITE_OPEN_READONLY);
+    if (!IsExist(db, appid))
+      return -1;
+
+    auto q = tizen_base::Database::Sql("SELECT badge FROM badge_data "
+        "WHERE pkgname = ?")
+        .Bind(appid);
+    auto r = db.Exec(q);
+    if (!r)
+      return -1;
+    auto rec = r.GetFirstRecord();
+    if (!rec)
+      return -1;
+    return static_cast<int>(rec->Get(0));
+  } catch(...) { /* LCOV_EXCL_LINE */
+    return -1; /* LCOV_EXCL_LINE */
+  }
+}
+
+bool BadgeService::SetDisplayOption(std::string appid, std::string caller, bool isDisplay) {
+  try {
+    tizen_base::Database db(BADGE_DB_PATH, SQLITE_OPEN_READWRITE);
+    if (!IsExist(db, appid))
+      return false;
+
+    auto q = tizen_base::Database::Sql("INSERT INTO badge_option "
+        "(pkgname, display, uid) VALUES (?, ?, 5001) ")
+        .Bind(appid)
+        .Bind(isDisplay ? 1 : 0);
+    auto r = db.Exec(q);
+    if (!r)
+      return false;
+
+    const auto& services = parent_.GetServices();
+    for (auto& s : services) {
+      auto* ptr = static_cast<BadgeService*>(s.get());
+      ptr->NotifyChangedEvent(rpc::BadgeInfo::Action::ChangedDisplay, appid, 0);
+    }
+  } catch(...) { /* LCOV_EXCL_LINE */
+    return -1; /* LCOV_EXCL_LINE */
+  }
+
+  return true;
+}
+
+bool BadgeService::GetDisplayOption(std::string appid) {
+  try {
+    tizen_base::Database db(BADGE_DB_PATH, SQLITE_OPEN_READONLY);
+    if (!IsExist(db, appid))
+      return false;
+
+    auto q = tizen_base::Database::Sql("SELECT display FROM badge_option "
+        "WHERE pkgname = ?")
+        .Bind(appid);
+    auto r = db.Exec(q);
+    if (!r)
+      return false;
+
+    auto rec = r.GetFirstRecord();
+    if (!rec)
+      return false;
+    return static_cast<int>(rec->Get(0));
+  } catch(...) { /* LCOV_EXCL_LINE */
+    return false; /* LCOV_EXCL_LINE */
+  }
+}
+
+bool BadgeService::Register(std::unique_ptr<rpc_stub::Badge::ChangedCb> cb) {
+  changed_cb_ = std::move(cb);
+  return true;
+}
+
+bool BadgeService::Unregister() {
+  changed_cb_.reset();
+  return true;
+}
+
+void BadgeService::NotifyChangedEvent(rpc::BadgeInfo::Action action,
+    const std::string& appid, int count) {
+  if (!changed_cb_) return;
+  changed_cb_->Invoke(action, appid, count);
+}
+
+} // namespace esd::module
diff --git a/modules/badge/badge_service.hh b/modules/badge/badge_service.hh
new file mode 100644 (file)
index 0000000..827e62d
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ *
+ * 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 MODULES_BADGE_BADGE_SERVICE_HH_
+#define MODULES_BADGE_BADGE_SERVICE_HH_
+
+#include <list>
+#include <memory>
+#include <optional>
+#include <string>
+#include <imodule.hh>
+#include <database.hpp>
+
+#include "badge_stub.h"
+
+namespace esd::module {
+
+namespace rpc_stub = rpc_port::badge_stub::stub;
+namespace rpc = rpc_port::badge_stub;
+
+class BadgeService : public rpc_stub::Badge::ServiceBase {
+ public:
+  class Factory : public rpc_stub::Badge::ServiceBase::Factory {
+   public:
+    Factory(const rpc_stub::Badge& parent) : parent_(parent) {}
+    virtual ~Factory() = default;
+
+    std::unique_ptr<rpc_stub::Badge::ServiceBase>
+        CreateService(std::string sender, std::string instance) {
+      return std::unique_ptr<rpc_stub::Badge::ServiceBase>(new BadgeService(sender, instance, parent_));
+    }
+
+   private:
+    const rpc_stub::Badge& parent_;
+  };
+
+  BadgeService(std::string sender, std::string instance, const rpc_stub::Badge& parent) :
+      rpc_stub::Badge::ServiceBase(sender, instance), parent_(parent) {}
+
+  virtual ~BadgeService() = default;
+
+  void OnCreate() override;
+  void OnTerminate() override;
+
+  std::vector<rpc::BadgeInfo> GetList() override;
+  bool Insert(std::string appid, std::string writable_pkg, std::string caller) override;
+  bool Delete(std::string appid, std::string caller) override;
+  bool SetCount(std::string appid, std::string caller, int count) override;
+  int GetCount(std::string appid) override;
+  bool SetDisplayOption(std::string appid, std::string caller, bool isDisplay) override;
+  bool GetDisplayOption(std::string appid) override;
+  bool Register(std::unique_ptr<rpc_stub::Badge::ChangedCb> cb) override;
+  bool Unregister() override;
+
+  void NotifyChangedEvent(rpc::BadgeInfo::Action action,
+      const std::string& appid, int count);
+
+ private:
+  bool IsExist(const tizen_base::Database& db, std::string appid);
+  bool IsWritable(const tizen_base::Database& db,
+      const std::string& appid, const std::string& caller);
+
+ private:
+  const rpc_stub::Badge& parent_;
+  std::unique_ptr<rpc_stub::Badge::ChangedCb> changed_cb_;
+};
+
+}  // namespace esd::module
+
+#endif  // MODULES_BADGE_BADGE_SERVICE_HH_
\ No newline at end of file
index 7365d67..0a260cc 100644 (file)
@@ -6,17 +6,23 @@ Group:      Applications/Core Applications
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 BuildRequires: pkgconfig(aul)
-BuildRequires: pkgconfig(dbus-1)
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(vconf)
-BuildRequires: pkgconfig(capi-appfw-package-manager)
-BuildRequires: pkgconfig(db-util)
+BuildRequires: pkgconfig(bundle)
 BuildRequires: pkgconfig(libtzplatform-config)
-BuildRequires: pkgconfig(pkgmgr-info)
-BuildRequires: pkgconfig(libsmack)
+BuildRequires: pkgconfig(capi-appfw-package-manager)
 BuildRequires: pkgconfig(capi-system-info)
-BuildRequires: pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(gmock)
+BuildRequires: pkgconfig(rpc-port)
+BuildRequires: pkgconfig(capi-appfw-app-common)
+BuildRequires: pkgconfig(capi-appfw-app-manager)
+BuildRequires: pkgconfig(capi-appfw-package-manager)
+BuildRequires: pkgconfig(libesd)
+BuildRequires: pkgconfig(tizen-database)
+
+BuildRequires: tidl
+
+%define _moddir %{_datadir}/esd
 
 %if 0%{?gcov:1}
 BuildRequires:  lcov
@@ -46,6 +52,13 @@ Requires:   %{name} = %{version}-%{release}
 %description service-devel
 Development files needed to build badge service
 
+%package -n esd-mod-badge
+Summary:    ESD module for badge
+Group:      Application Framework/Service
+
+%description -n esd-mod-badge
+This module is for badge
+
 #################################################
 # badge-unittests
 #################################################
@@ -71,6 +84,11 @@ gcov objects of a Badge library
 
 %prep
 %setup -q
+tidlc -p -l C++ -i ./tidl/badge.tidl -o badge_proxy
+mv badge_proxy.* ./src/
+tidlc -s -l C++ -i ./tidl/badge.tidl -o badge_stub
+mv badge_stub.* ./modules/badge/
+
 
 %build
 %if 0%{?gcov:1}
@@ -85,6 +103,8 @@ LDFLAGS="$LDFLAGS"
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %cmake . \
        -DMAJORVER=${MAJORVER} \
+  -DDB_PATH=%{TZ_SYS_DB}/.badge.db \
+  -DESD_MODULES_DIR=%{_moddir} \
        -DFULLVER=%{version}
 make %{?jobs:-j%jobs}
 
@@ -93,6 +113,10 @@ export LD_LIBRARY_PATH=../../src
 ctest -V
 %if 0%{?gcov:1}
 lcov -c --ignore-errors mismatch,graph,unused --no-external -q -d . -o badge.info
+lcov -r badge.info "_proxy*" -o badge.info
+lcov -r badge.info "_stub*" -o badge.info
+lcov -r badge.info "/unit_tests/*" -o badge.info
+lcov -r badge.info "/mock/*" -o badge.info
 genhtml badge.info -o badge.out
 zip -r badge.zip badge.out
 install -m 0644 badge.zip %{buildroot}%{_datadir}/gcov/badge.zip
@@ -153,27 +177,17 @@ fi
 %license LICENSE
 %{_includedir}/badge/badge.h
 %{_includedir}/badge/badge_error.h
-%{_includedir}/badge/badge_internal.h
-%{_includedir}/badge/badge_setting.h
-%{_includedir}/badge/badge_setting_service.h
-%{_includedir}/badge/badge_ipc.h
-%attr(755,root,root) %{_sysconfdir}/gumd/useradd.d/11_badge-add.post
-%{_bindir}/badge_init
 
 %files devel
 %defattr(-,root,root,-)
 %{_includedir}/badge/badge.h
 %{_includedir}/badge/badge_error.h
-%{_includedir}/badge/badge_internal.h
-%{_includedir}/badge/badge_db.h
-%{_includedir}/badge/badge_setting.h
-%{_includedir}/badge/badge_setting_service.h
-%{_includedir}/badge/badge_ipc.h
 %{_libdir}/pkgconfig/%{name}.pc
 %{_libdir}/libbadge.so
 
 %files unittests
 %{_bindir}/badge_unittests
+%{_bindir}/badge_integtests
 %{_bindir}/tizen-unittests/%{name}/run-unittest.sh
 
 #################################################
@@ -183,4 +197,8 @@ fi
 %files gcov
 %{_datadir}/gcov/*
 %endif
-# End of a file
+
+%files -n esd-mod-badge
+%manifest %{name}.manifest
+%license LICENSE
+%{_moddir}/mod/libesd-mod-badge.so
index 0a55216..3572b2e 100644 (file)
@@ -7,17 +7,11 @@ TARGET_LINK_LIBRARIES(${TARGET_BADGE} ${pkgs_LDFLAGS})
 TARGET_INCLUDE_DIRECTORIES(${TARGET_BADGE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include/)
 
 APPLY_PKG_CONFIG(${TARGET_BADGE} PUBLIC
-  AUL_DEP
   DLOG_DEPS
   VCONF_DEPS
-  PKGMGR_DEPS
   SYSTEM_INFO_DEPS
-  DB_UTIL_DEPS
-  PLATFORM_CONFIG_DEPS
-  PKGMGR_INFO_DEPS
-  SMACK_DEPS
-  GLIB_DEPS
-  GIO_DEPS
+  RPC_PORT_DEPS
+  APP_COMMON_DEPS
 )
 
 CONFIGURE_FILE(../${TARGET_BADGE}.pc.in ../${TARGET_BADGE}.pc @ONLY)
@@ -30,4 +24,4 @@ INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/
                PATTERN "*.h")
 
 INSTALL(TARGETS ${TARGET_BADGE} DESTINATION ${LIB_INSTALL_DIR})
-INSTALL(FILES ${CMAKE_BINARY_DIR}/11_badge-add.post DESTINATION ${SYSCONF_INSTALL_DIR}/gumd/useradd.d/)
+
diff --git a/src/badge.c b/src/badge.c
deleted file mode 100644 (file)
index 77b2739..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (c) 2000 - 2017 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 <stdlib.h>
-#include <stdarg.h>
-#include <unistd.h>
-
-#include <dlog.h>
-
-#include "badge.h"
-#include "badge_error.h"
-#include "badge_internal.h"
-#include "badge_private.h"
-
-EXPORT_API
-int badge_new(const char *writable_app_id)
-{
-       dlog_print(DLOG_WARN, LOG_TAG, "DEPRECATION WARNING: badge_new() is deprecated and will be removed from next release. Use badge_add() instead.");
-       CHECK_BADGE_FEATURE();
-       if (writable_app_id == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       return badge_new_for_uid(writable_app_id, getuid());
-}
-
-EXPORT_API
-int badge_add(const char *badge_app_id)
-{
-       CHECK_BADGE_FEATURE();
-       return badge_add_for_uid(badge_app_id, getuid());
-}
-
-EXPORT_API
-int badge_remove(const char *app_id)
-{
-       CHECK_BADGE_FEATURE();
-       if (app_id == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       return badge_remove_for_uid(app_id, getuid());
-}
-
-EXPORT_API
-int badge_foreach(badge_foreach_cb callback, void *user_data)
-{
-       CHECK_BADGE_FEATURE();
-       if (callback == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       return badge_foreach_for_uid(callback, user_data, getuid());
-}
-
-EXPORT_API
-int badge_set_count(const char *app_id, unsigned int count)
-{
-       CHECK_BADGE_FEATURE();
-       if (app_id == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       return badge_set_count_for_uid(app_id, count, getuid());
-}
-
-EXPORT_API
-int badge_get_count(const char *app_id, unsigned int *count)
-{
-       CHECK_BADGE_FEATURE();
-       if (app_id == NULL || count == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       return badge_get_count_for_uid(app_id, count, getuid());
-}
-
-EXPORT_API
-int badge_set_display(const char *app_id, unsigned int is_display)
-{
-       CHECK_BADGE_FEATURE();
-       if (app_id == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       return badge_set_display_for_uid(app_id, is_display, getuid());
-}
-
-EXPORT_API
-int badge_get_display(const char *app_id, unsigned int *is_display)
-{
-       CHECK_BADGE_FEATURE();
-       if (app_id == NULL || is_display == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       return badge_get_display_for_uid(app_id, is_display, getuid());
-}
-
-EXPORT_API
-int badge_register_changed_cb(badge_change_cb callback, void *data)
-{
-       CHECK_BADGE_FEATURE();
-       if (callback == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       return badge_register_changed_cb_for_uid(callback, data, getuid());
-}
-
-EXPORT_API
-int badge_unregister_changed_cb(badge_change_cb callback)
-{
-       CHECK_BADGE_FEATURE();
-       if (callback == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       return badge_unregister_changed_cb_for_uid(callback, getuid());
-}
diff --git a/src/badge.cc b/src/badge.cc
new file mode 100644 (file)
index 0000000..f651757
--- /dev/null
@@ -0,0 +1,275 @@
+/*
+ * Copyright (c) 2000 - 2017 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 <app_common.h>
+#include <system_info.h>
+
+#include "log_private.h"
+#include "badge.h"
+#include "badge_error.h"
+#include "badge_proxy.h"
+
+#define BADGE_FEATURE "http://tizen.org/feature/badge"
+#define CHECK_BADGE_FEATURE() \
+  do { \
+    bool is_supported = false; \
+    if (!system_info_get_platform_bool(BADGE_FEATURE, &is_supported)) { \
+      if (is_supported == false) { \
+        _E("[%s] feature is disabled", BADGE_FEATURE); \
+        return BADGE_ERROR_NOT_SUPPORTED; \
+      } \
+    } \
+  } while (0)
+
+namespace rpc = rpc_port::badge_proxy;
+namespace rpc_proxy = rpc_port::badge_proxy::proxy;
+
+namespace {
+
+char* sAppid;
+std::unique_ptr<rpc_proxy::Badge> badge_proxy_;
+
+class BadgeConnection : public rpc_proxy::Badge::IEventListener {
+ public:
+  void OnConnected() override {}
+
+  /* LCOV_EXCL_START */
+  void OnDisconnected() override {
+    badge_proxy_.reset();
+  }
+
+  void OnRejected() override {
+    badge_proxy_.reset();
+  }
+  /* LCOV_EXCL_STOP */
+} connection_listener_;
+
+class BadgeChangedCb : public rpc_proxy::Badge::ChangedCb {
+ public:
+  BadgeChangedCb(badge_change_cb callback, void* data)
+      : callback_(callback), data_(data) {}
+
+  void OnReceived(rpc::BadgeInfo::Action action, std::string appid,
+      int count) override {
+    if (!callback_)
+      return;
+    callback_((unsigned int)(action), appid.c_str(), count, data_);
+  }
+
+ private:
+  badge_change_cb callback_;
+  void* data_;
+};
+
+void Connect() {
+  if (!badge_proxy_) {
+    badge_proxy_.reset(new rpc_proxy::Badge(&connection_listener_,
+        "d::org.tizen.appfw.service.esd"));
+    badge_proxy_->Connect(true);
+  }
+
+  if (!sAppid) {
+    app_get_id(&sAppid);
+    if (!sAppid)
+      sAppid = const_cast<char*>("daemon");
+  }
+}
+
+}  // namespace
+
+EXPORT_API int badge_new(const char* writable_app_id) {
+  CHECK_BADGE_FEATURE();
+  if (writable_app_id == nullptr)
+    return BADGE_ERROR_INVALID_PARAMETER;
+
+  try {
+    ::Connect();
+    if (!badge_proxy_->Insert(sAppid, writable_app_id, sAppid))
+      return BADGE_ERROR_IO_ERROR; /* LCOV_EXCL_LINE */
+  } catch(...) { /* LCOV_EXCL_LINE */
+    /* LCOV_EXCL_START */
+    badge_proxy_.reset();
+    return BADGE_ERROR_IO_ERROR;
+    /* LCOV_EXCL_STOP */
+  }
+
+  return BADGE_ERROR_NONE;
+}
+
+EXPORT_API int badge_add(const char* badge_app_id) {
+  CHECK_BADGE_FEATURE();
+  try {
+    ::Connect();
+    if (!badge_proxy_->Insert(badge_app_id, sAppid, sAppid))
+      return BADGE_ERROR_IO_ERROR; /* LCOV_EXCL_LINE */
+  } catch(...) { /* LCOV_EXCL_LINE */
+    /* LCOV_EXCL_START */
+    badge_proxy_.reset();
+    return BADGE_ERROR_IO_ERROR;
+    /* LCOV_EXCL_STOP */
+  }
+
+  return BADGE_ERROR_NONE;
+}
+
+EXPORT_API int badge_remove(const char* app_id) {
+  CHECK_BADGE_FEATURE();
+  try {
+    ::Connect();
+    if (!badge_proxy_->Delete(app_id, sAppid))
+      return BADGE_ERROR_IO_ERROR; /* LCOV_EXCL_LINE */
+  } catch(...) { /* LCOV_EXCL_LINE */
+    /* LCOV_EXCL_START */
+    badge_proxy_.reset();
+    return BADGE_ERROR_IO_ERROR;
+    /* LCOV_EXCL_STOP */
+  }
+
+  return BADGE_ERROR_NONE;
+}
+
+EXPORT_API int badge_foreach(badge_foreach_cb callback, void* user_data) {
+  CHECK_BADGE_FEATURE();
+  if (callback == nullptr)
+    return BADGE_ERROR_INVALID_PARAMETER;
+
+  try {
+    ::Connect();
+    auto info = badge_proxy_->GetList();
+    for (auto& i : info) {
+      if (!callback(i.GetPkgName().c_str(), i.GetCount(), user_data))
+        break;
+    }
+  } catch(...) { /* LCOV_EXCL_LINE */
+    /* LCOV_EXCL_START */
+    badge_proxy_.reset();
+    return BADGE_ERROR_IO_ERROR;
+    /* LCOV_EXCL_STOP */
+  }
+
+  return BADGE_ERROR_NONE;
+}
+
+EXPORT_API int badge_set_count(const char* app_id, unsigned int count) {
+  CHECK_BADGE_FEATURE();
+  if (app_id == nullptr)
+    return BADGE_ERROR_INVALID_PARAMETER;
+  try {
+    ::Connect();
+    if (!badge_proxy_->SetCount(app_id, sAppid, count))
+      return BADGE_ERROR_IO_ERROR; /* LCOV_EXCL_LINE */
+  } catch(...) { /* LCOV_EXCL_LINE */
+    /* LCOV_EXCL_START */
+    badge_proxy_.reset();
+    return BADGE_ERROR_IO_ERROR;
+    /* LCOV_EXCL_STOP */
+  }
+
+  return BADGE_ERROR_NONE;
+}
+
+EXPORT_API int badge_get_count(const char* app_id, unsigned int* count) {
+  CHECK_BADGE_FEATURE();
+  if (app_id == nullptr || count == nullptr)
+    return BADGE_ERROR_INVALID_PARAMETER;
+
+  try {
+    ::Connect();
+    *count = badge_proxy_->GetCount(app_id);
+  } catch(...) { /* LCOV_EXCL_LINE */
+    /* LCOV_EXCL_START */
+    badge_proxy_.reset();
+    return BADGE_ERROR_IO_ERROR;
+    /* LCOV_EXCL_STOP */
+  }
+
+  return BADGE_ERROR_NONE;
+}
+
+EXPORT_API int badge_set_display(const char* app_id, unsigned int is_display) {
+  CHECK_BADGE_FEATURE();
+  if (app_id == nullptr)
+    return BADGE_ERROR_INVALID_PARAMETER;
+  try {
+    ::Connect();
+    if (!badge_proxy_->SetDisplayOption(app_id, sAppid, is_display))
+      return BADGE_ERROR_IO_ERROR; /* LCOV_EXCL_LINE */
+  } catch(...) { /* LCOV_EXCL_LINE */
+    /* LCOV_EXCL_START */
+    badge_proxy_.reset();
+    return BADGE_ERROR_IO_ERROR;
+    /* LCOV_EXCL_STOP */
+  }
+
+  return BADGE_ERROR_NONE;
+}
+
+EXPORT_API int badge_get_display(const char* app_id, unsigned int* is_display) {
+  CHECK_BADGE_FEATURE();
+  if (app_id == nullptr || is_display == nullptr)
+    return BADGE_ERROR_INVALID_PARAMETER;
+
+  try {
+    ::Connect();
+    *is_display = badge_proxy_->GetDisplayOption(app_id) ? 1 : 0;
+  } catch(...) { /* LCOV_EXCL_LINE */
+    /* LCOV_EXCL_START */
+    badge_proxy_.reset();
+    return BADGE_ERROR_IO_ERROR;
+    /* LCOV_EXCL_STOP */
+  }
+
+  return BADGE_ERROR_NONE;
+}
+
+EXPORT_API int badge_register_changed_cb(badge_change_cb callback, void* data) {
+  CHECK_BADGE_FEATURE();
+  if (callback == nullptr)
+    return BADGE_ERROR_INVALID_PARAMETER;
+
+  try {
+    ::Connect();
+    if (!badge_proxy_->Register(std::make_unique<BadgeChangedCb>(callback, data)))
+      return BADGE_ERROR_IO_ERROR; /* LCOV_EXCL_LINE */
+  } catch(...) { /* LCOV_EXCL_LINE */
+    /* LCOV_EXCL_START */
+    badge_proxy_.reset();
+    return BADGE_ERROR_IO_ERROR;
+    /* LCOV_EXCL_STOP */
+  }
+
+  return BADGE_ERROR_NONE;
+}
+
+EXPORT_API int badge_unregister_changed_cb(badge_change_cb callback) {
+  CHECK_BADGE_FEATURE();
+  if (callback == nullptr)
+    return BADGE_ERROR_INVALID_PARAMETER;
+
+  try {
+    ::Connect();
+    if (!badge_proxy_->Unregister())
+      return BADGE_ERROR_IO_ERROR; /* LCOV_EXCL_LINE */
+  } catch(...) { /* LCOV_EXCL_LINE */
+    /* LCOV_EXCL_START */
+    badge_proxy_.reset();
+    return BADGE_ERROR_IO_ERROR;
+    /* LCOV_EXCL_STOP */
+  }
+
+  return BADGE_ERROR_NONE;
+}
diff --git a/src/badge_db.c b/src/badge_db.c
deleted file mode 100644 (file)
index e143ae9..0000000
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * Copyright (c) 2000 - 2017 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 <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <sqlite3.h>
-#include <db-util.h>
-
-#include "badge.h"
-#include "badge_db.h"
-#include "badge_log.h"
-#include "badge_error.h"
-#include "badge_internal.h"
-
-#define CREATE_BADGE_TABLE " \
-PRAGMA journal_mode = PERSIST; \
-PRAGMA synchronous = FULL; \
-CREATE TABLE IF NOT EXISTS badge_data ( \
-       uid INTEGER, \
-       pkgname TEXT NOT NULL, \
-       writable_pkgs TEXT, \
-       badge INTEGER DEFAULT 0, \
-       rowid INTEGER PRIMARY KEY AUTOINCREMENT, \
-       UNIQUE (uid, pkgname) \
-); \
-CREATE TABLE IF NOT EXISTS badge_option ( \
-       uid INTEGER, \
-       pkgname TEXT NOT NULL, \
-       display INTEGER DEFAULT 1, \
-       UNIQUE (uid, pkgname) \
-); \
-CREATE TABLE IF NOT EXISTS badge_setting ( \
-       uid INTEGER, \
-       pkgname TEXT NOT NULL, \
-       appid TEXT NOT NULL, \
-       allow_to_display INTEGER DEFAULT 1, \
-       UNIQUE (uid, pkgname, appid) \
-); "
-
-static bool is_db_corrupted = false;
-
-/* LCOV_EXCL_START */
-static int __check_integrity_cb(void *pid, int argc, char **argv, char **notUsed)
-{
-       if (strcmp(argv[0], "ok") != 0) {
-               ERR("db integrity result : %s", argv[0]);
-               is_db_corrupted = true;
-               return -1;
-       }
-
-       INFO("db integrity result : %s", argv[0]);
-       return 0;
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static int __recover_corrupted_db()
-{
-       int ret = BADGE_ERROR_NONE;
-       int sql_ret;
-       char *errmsg = NULL;
-       sqlite3 *db = NULL;
-
-       INFO("DB is corrupted, start to recover corrupted db");
-       unlink(BADGE_DB_PATH);
-
-       sql_ret = sqlite3_open_v2(BADGE_DB_PATH, &db,
-                                 SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE,
-                                 NULL);
-       if (sql_ret != SQLITE_OK) {
-               ERR("Failed to open badge db[%d]", sql_ret);
-               unlink(BADGE_DB_PATH);
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-       }
-
-       sql_ret = sqlite3_exec(db, CREATE_BADGE_TABLE, NULL, NULL, &errmsg);
-       if (sql_ret != SQLITE_OK) {
-               ERR("Failed to exec query[%d][%s]", sql_ret, errmsg);
-               ret = BADGE_ERROR_FROM_DB;
-       }
-
-out:
-       if (errmsg)
-               sqlite3_free(errmsg);
-
-       if (db)
-               sqlite3_close_v2(db);
-
-       return ret;
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-EXPORT_API int badge_db_init(void)
-{
-       int ret = BADGE_ERROR_NONE;
-       int sql_ret;
-       sqlite3 *db = NULL;
-       char *errmsg = NULL;
-
-       sql_ret = sqlite3_open_v2(BADGE_DB_PATH, &db,
-                       SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
-       if (sql_ret != SQLITE_OK) {
-               ERR("Failed to open badge db[%d]", sql_ret);
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-       }
-
-       sql_ret = sqlite3_exec(db, CREATE_BADGE_TABLE, NULL, NULL, &errmsg);
-       if (sql_ret != SQLITE_OK) {
-               ERR("Failed to exec query[%d][%s]", sql_ret, errmsg);
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-       }
-
-       sql_ret = sqlite3_exec(db, "PRAGMA integrity_check",
-                               __check_integrity_cb, NULL, &errmsg);
-       if (sql_ret != SQLITE_OK || is_db_corrupted) {
-               ERR("Failed to exec query[%d][%s]", sql_ret, errmsg);
-               ret = BADGE_ERROR_FROM_DB;
-       }
-
-out:
-       if (errmsg)
-               sqlite3_free(errmsg);
-       if (db)
-               sqlite3_close_v2(db);
-
-       if (sql_ret == SQLITE_CORRUPT || sql_ret == SQLITE_NOTADB
-                       || is_db_corrupted)
-               ret = __recover_corrupted_db();
-
-       return ret;
-}
-/* LCOV_EXCL_STOP */
-
-EXPORT_API
-int badge_db_is_existing(const char *pkgname, bool *existing, uid_t uid)
-{
-       return _badge_is_existing(pkgname, existing, uid);
-}
-
-EXPORT_API
-int badge_db_get_list(GList **badge_list, uid_t uid)
-{
-       return _badge_get_list(badge_list, uid);
-}
-
-EXPORT_API
-int badge_db_insert(const char *pkgname, const char *writable_pkg, const char *caller, uid_t uid)
-{
-       int err = BADGE_ERROR_NONE;
-       badge_h *badge = NULL;
-       char *pkgs = NULL;
-
-       if (!pkgname) {
-               ERR("package name is NULL");
-               return BADGE_ERROR_INVALID_PARAMETER;
-       }
-
-       pkgs = _badge_pkgs_new(&err, writable_pkg, caller, NULL);
-       if (!pkgs) {
-               ERR("Failed to _badge_pkgs_new [%d]", err);
-               return err;
-       }
-
-       INFO("pkgs : %s", pkgs);
-
-       badge = _badge_new(pkgname, pkgs, &err);
-       if (!badge) {
-               ERR("Failed to _badge_new [%d]", err);
-               free(pkgs);
-               return err;
-       }
-       free(pkgs);
-
-       err = _badge_insert(badge, uid);
-       if (err != BADGE_ERROR_NONE) {
-               ERR("Failed to _badge_insert [%d]", err);
-               _badge_free(badge);
-               return err;
-       }
-
-       _badge_free(badge);
-
-       return BADGE_ERROR_NONE;
-}
-
-EXPORT_API
-int badge_db_delete(const char *pkgname, const char *caller, uid_t uid, pid_t pid)
-{
-       return _badge_remove(caller, pkgname, uid, pid);
-}
-
-EXPORT_API
-int badge_db_delete_by_pkgname(const char *pkgname, uid_t uid)
-{
-       return _badge_remove_by_pkgname(pkgname, uid);
-}
-
-EXPORT_API
-int badge_db_set_count(const char *pkgname, const char *caller, unsigned int count, uid_t uid, pid_t pid)
-{
-       return _badge_set_count(caller, pkgname, count, uid, pid);
-}
-
-EXPORT_API
-int badge_db_get_count(const char *pkgname, unsigned int *count, uid_t uid)
-{
-       return _badge_get_count(pkgname, count, uid);
-}
-
-EXPORT_API
-int badge_db_set_display_option(const char *pkgname, unsigned int is_display, uid_t uid)
-{
-       return _badge_set_display(pkgname, is_display, uid);
-}
-
-EXPORT_API
-int badge_db_get_display_option(const char *pkgname, unsigned int *is_display, uid_t uid)
-{
-       return _badge_get_display(pkgname, is_display, uid);
-}
-
-EXPORT_API
-int badge_db_exec(sqlite3 *db, const char *query, int *num_changes)
-{
-       int ret;
-       sqlite3_stmt *stmt = NULL;
-
-       if (db == NULL || query == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               /* LCOV_EXCL_START */
-               ERR("sqlite3_prepare_v2 failed [%d][%s]", ret,
-                                       sqlite3_errmsg(db));
-               return BADGE_ERROR_FROM_DB;
-               /* LCOV_EXCL_STOP */
-       }
-
-       if (stmt != NULL) {
-               ret = sqlite3_step(stmt);
-               if (ret == SQLITE_OK || ret == SQLITE_DONE) {
-                       if (num_changes != NULL)
-                               *num_changes = sqlite3_changes(db);
-
-                       sqlite3_finalize(stmt);
-               } else {
-                       /* LCOV_EXCL_START */
-                       ERR("sqlite3_step failed [%d][%s]", ret,
-                                       sqlite3_errmsg(db));
-                       sqlite3_finalize(stmt);
-                       return BADGE_ERROR_FROM_DB;
-                       /* LCOV_EXCL_STOP */
-               }
-       } else {
-                       return BADGE_ERROR_FROM_DB;
-       }
-
-       return BADGE_ERROR_NONE;
-}
diff --git a/src/badge_error.c b/src/badge_error.c
deleted file mode 100644 (file)
index 7ffe35e..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2000 - 2017 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 <string.h>
-#include <gio/gio.h>
-#include "badge_error.h"
-
-static const GDBusErrorEntry dbus_error_entries[] = {
-       {BADGE_ERROR_INVALID_PARAMETER, "org.freedesktop.Badge.Error.INVALID_PARAMETER"},
-       {BADGE_ERROR_OUT_OF_MEMORY,     "org.freedesktop.Badge.Error.OUT_OF_MEMORY"},
-       {BADGE_ERROR_IO_ERROR,          "org.freedesktop.Badge.Error.IO_ERROR"},
-       {BADGE_ERROR_PERMISSION_DENIED, "org.freedesktop.Badge.Error.PERMISSION_DENIED"},
-       {BADGE_ERROR_FROM_DB,           "org.freedesktop.Badge.Error.FROM_DB"},
-       {BADGE_ERROR_ALREADY_EXIST,  "org.freedesktop.Badge.Error.ALREADY_EXIST"},
-       {BADGE_ERROR_FROM_DBUS,         "org.freedesktop.Badge.Error.FROM_DBUS"},
-       {BADGE_ERROR_NOT_EXIST,      "org.freedesktop.Badge.Error.NOT_EXIST"},
-       {BADGE_ERROR_SERVICE_NOT_READY, "org.freedesktop.Badge.Error.SERVICE_NOT_READY"},
-       {BADGE_ERROR_INVALID_PACKAGE, "org.freedesktop.Badge.Error.INVALID_PACKAGE"},
-};
-
-#define BADGE_ERROR_QUARK "badge-error-quark"
-
-EXPORT_API GQuark badge_error_quark(void)
-{
-       static volatile gsize quark_volatile = 0;
-       static char *domain_name = NULL;
-
-       /* This is for preventing crash when notification api is used in ui-gadget     */
-       /* ui-gadget libraries can be unloaded when it is needed and the static string */
-       /* parameter to g_dbus_error_register_error_domain may cause crash.             */
-       GQuark quark = g_quark_try_string(BADGE_ERROR_QUARK);
-
-       if (quark == 0) {
-               if (domain_name == NULL)
-                       domain_name = strdup(BADGE_ERROR_QUARK);
-       } else {
-               domain_name = BADGE_ERROR_QUARK;
-       }
-
-       g_dbus_error_register_error_domain(domain_name,
-                       &quark_volatile,
-                       dbus_error_entries,
-                       G_N_ELEMENTS(dbus_error_entries));
-       return (GQuark) quark_volatile;
-}
-
diff --git a/src/badge_internal.c b/src/badge_internal.c
deleted file mode 100644 (file)
index b9c77e4..0000000
+++ /dev/null
@@ -1,1689 +0,0 @@
-/*
- * Copyright (c) 2000 - 2017 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 <string.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <glib.h>
-#include <gio/gio.h>
-#include <aul.h>
-#include <sqlite3.h>
-#include <db-util.h>
-#include <package_manager.h>
-#include <tzplatform_config.h>
-#include <sys/smack.h>
-
-#include "badge_log.h"
-#include "badge_error.h"
-#include "badge_internal.h"
-#include "badge_ipc.h"
-#include "badge_db.h"
-#include "badge_private.h"
-#include "badge_setting_service.h"
-
-#define BADGE_PKGNAME_LEN 512
-
-#define BADGE_CHANGED_NOTI     "badge_changed"
-
-struct _badge_h {
-       char *pkgname;
-       char *writable_pkgs;
-};
-
-struct _badge_cb_data {
-       badge_change_cb callback;
-       void *data;
-};
-
-static GHashTable *_badge_cb_hash = NULL;
-
-static inline unsigned long _get_max_len(void)
-{
-       unsigned long max = 0;
-       long path_max_len = 4096;
-
-#ifdef _PC_PATH_MAX
-       max = (pathconf("/", _PC_PATH_MAX) < 1 ? path_max_len
-                               : pathconf("/", _PC_PATH_MAX));
-#else /* _PC_PATH_MAX */
-       max = path_max_len;
-#endif /* _PC_PATH_MAX */
-       return max;
-}
-
-char *_badge_get_pkgname_by_pid(void)
-{
-       char *pkgname = NULL;
-       int pid = 0;
-       int ret = AUL_R_OK;
-       int fd = 0;
-       unsigned long max = 0;
-
-       pid = getpid();
-       max = _get_max_len();
-       pkgname = malloc(max);
-       if (!pkgname) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc memory");
-               return NULL;
-               /* LCOV_EXCL_STOP */
-       }
-       memset(pkgname, 0x00, max);
-
-       ret = aul_app_get_pkgname_bypid(pid, pkgname, max);
-       if (ret != AUL_R_OK) {
-               fd = open("/proc/self/cmdline", O_RDONLY);
-               if (fd < 0) {
-                       /* LCOV_EXCL_START */
-                       free(pkgname);
-                       return NULL;
-                       /* LCOV_EXCL_STOP */
-               }
-
-               ret = read(fd, pkgname, max - 1);
-               if (ret <= 0) {
-                       /* LCOV_EXCL_START */
-                       close(fd);
-                       free(pkgname);
-                       return NULL;
-                       /* LCOV_EXCL_STOP */
-               }
-
-               close(fd);
-       }
-
-       if (pkgname[0] == '\0') {
-               /* LCOV_EXCL_START */
-               free(pkgname);
-               return NULL;
-               /* LCOV_EXCL_STOP */
-       } else {
-               return pkgname;
-       }
-}
-
-static int _badge_check_data_inserted(const char *pkgname,
-                                       sqlite3 *db, uid_t uid)
-{
-       sqlite3_stmt *stmt = NULL;
-       int count = 0;
-       int result = BADGE_ERROR_NONE;
-       char *sqlbuf = NULL;
-       int sqlret;
-
-       if (!pkgname || !db)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       sqlbuf = sqlite3_mprintf("SELECT count(*) FROM %q WHERE " \
-                        "pkgname = %Q AND uid = %d",
-                        BADGE_TABLE_NAME, pkgname, uid);
-       if (!sqlbuf) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               return BADGE_ERROR_OUT_OF_MEMORY;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sqlret = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL);
-       if (sqlret != SQLITE_OK) {
-               /* LCOV_EXCL_START */
-               ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlret,
-                                       sqlite3_errmsg(db));
-               result = BADGE_ERROR_FROM_DB;
-               goto free_and_return;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sqlret = sqlite3_step(stmt);
-       if (sqlret == SQLITE_ROW)
-               count = sqlite3_column_int(stmt, 0);
-       else
-               count = 0;
-
-       DBG("[%s], DB search result[%d]", sqlbuf, count);
-
-       if (count > 0)
-               result = BADGE_ERROR_ALREADY_EXIST;
-       else
-               result = BADGE_ERROR_NOT_EXIST;
-
-free_and_return:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
-
-       if (stmt)
-               sqlite3_finalize(stmt);
-
-       return result;
-}
-
-static int _badge_check_option_inserted(const char *pkgname,
-                                       sqlite3 *db, uid_t uid)
-{
-       sqlite3_stmt *stmt = NULL;
-       int count = 0;
-       int result = BADGE_ERROR_NONE;
-       char *sqlbuf = NULL;
-       int sqlret;
-
-       if (!pkgname || !db)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       sqlbuf = sqlite3_mprintf("SELECT count(*) FROM %q WHERE " \
-                        "pkgname = %Q AND uid = %d",
-                        BADGE_OPTION_TABLE_NAME, pkgname, uid);
-       if (!sqlbuf) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               return BADGE_ERROR_OUT_OF_MEMORY;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sqlret = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL);
-       if (sqlret != SQLITE_OK) {
-               /* LCOV_EXCL_START */
-               ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlret,
-                                       sqlite3_errmsg(db));
-               result = BADGE_ERROR_FROM_DB;
-               goto free_and_return;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sqlret = sqlite3_step(stmt);
-       if (sqlret == SQLITE_ROW)
-               count = sqlite3_column_int(stmt, 0);
-       else
-               count = 0;
-
-       DBG("[%s], DB search result[%d]", sqlbuf, count);
-
-       if (count > 0)
-               result = BADGE_ERROR_ALREADY_EXIST;
-       else
-               result = BADGE_ERROR_NOT_EXIST;
-
-free_and_return:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
-
-       if (stmt)
-               sqlite3_finalize(stmt);
-
-       return result;
-}
-
-static int _is_same_certinfo(const char *caller, const char *pkgname)
-{
-       int ret = PACKAGE_MANAGER_ERROR_NONE;
-       package_manager_compare_result_type_e compare_result = PACKAGE_MANAGER_COMPARE_MISMATCH;
-
-       if (!caller || !pkgname)
-               return 0;
-
-       ret = package_manager_compare_package_cert_info(pkgname, caller, &compare_result);
-       if (ret == PACKAGE_MANAGER_ERROR_NONE &&
-               compare_result == PACKAGE_MANAGER_COMPARE_MATCH)
-               return 1;
-
-       return 0;
-}
-
-static bool __check_label(pid_t pid)
-{
-#define SMACK_LABEL_LEN 255
-#define COMPARE_LABEL_COUNT 3
-
-       bool ret = false;
-       int i;
-       ssize_t len;
-       char *label = NULL;
-       char check_label[COMPARE_LABEL_COUNT][SMACK_LABEL_LEN+1] = { "System", "System::Privileged", "User"};
-
-       len = smack_new_label_from_process(pid, &label);
-       if (len < 0 || label == NULL)
-               goto out;
-
-       for (i = 0; i < COMPARE_LABEL_COUNT; i++) {
-               if (g_strcmp0(label, check_label[i]) == 0) {
-                       ret = true;
-                       goto out;
-               }
-       }
-
-out:
-       if (label)
-               free(label);
-
-       return ret;
-}
-
-static int _badge_check_writable(const char *caller,
-                       const char *pkgname, sqlite3 *db, uid_t uid, pid_t pid)
-{
-       sqlite3_stmt *stmt = NULL;
-       int count = 0;
-       int result = BADGE_ERROR_NONE;
-       char *sqlbuf = NULL;
-       int sqlret;
-
-       if (!db || !caller || !pkgname)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       if (g_strcmp0(caller, pkgname) == 0)
-               return BADGE_ERROR_NONE;
-
-       if (__check_label(pid) == true)
-               return BADGE_ERROR_NONE;
-
-       /* LCOV_EXCL_START */
-       if (_is_same_certinfo(caller, pkgname) == 1)
-               return BADGE_ERROR_NONE;
-
-       sqlbuf = sqlite3_mprintf("SELECT COUNT(*) FROM %q WHERE " \
-                        "pkgname = %Q AND writable_pkgs LIKE '%%%q%%'" \
-                        "AND uid = %d",
-                        BADGE_TABLE_NAME,
-                        pkgname, caller, uid);
-       if (!sqlbuf) {
-               ERR("Failed to alloc query");
-               return BADGE_ERROR_OUT_OF_MEMORY;
-       }
-
-       sqlret = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL);
-       if (sqlret != SQLITE_OK) {
-               ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlret,
-                                       sqlite3_errmsg(db));
-               result = BADGE_ERROR_FROM_DB;
-               goto free_and_return;
-       }
-
-       sqlret = sqlite3_step(stmt);
-       if (sqlret == SQLITE_ROW)
-               count = sqlite3_column_int(stmt, 0);
-       else
-               count = 0;
-
-       DBG("[%s], DB search result[%d]", sqlbuf, count);
-
-       if (count <= 0)
-               result = BADGE_ERROR_PERMISSION_DENIED;
-
-free_and_return:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
-
-       if (stmt)
-               sqlite3_finalize(stmt);
-
-       return result;
-       /* LCOV_EXCL_STOP */
-}
-
-int _badge_is_existing(const char *pkgname, bool *existing, uid_t uid)
-{
-       sqlite3 *db = NULL;
-       int sqlret;
-       int result = BADGE_ERROR_NONE;
-
-       if (!pkgname || !existing) {
-               /* LCOV_EXCL_START */
-               ERR("pkgname : %s, existing : %p", pkgname, existing);
-               return BADGE_ERROR_INVALID_PARAMETER;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sqlret = db_util_open(BADGE_DB_PATH, &db, 0);
-       if (sqlret != SQLITE_OK || !db) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to db_util_open [%d]", sqlret);
-               if (sqlret == SQLITE_PERM)
-                       return BADGE_ERROR_PERMISSION_DENIED;
-               return BADGE_ERROR_FROM_DB;
-               /* LCOV_EXCL_STOP */
-       }
-
-       result = _badge_check_data_inserted(pkgname, db, uid);
-       if (result == BADGE_ERROR_ALREADY_EXIST) {
-               *existing = TRUE;
-               result = BADGE_ERROR_NONE;
-       } else if (result == BADGE_ERROR_NOT_EXIST) {
-               *existing = FALSE;
-               result = BADGE_ERROR_NONE;
-       }
-
-       sqlret = db_util_close(db);
-       if (sqlret != SQLITE_OK)
-               WARN("Failed to db_util_close [%d]", sqlret); /* LCOV_EXCL_LINE */
-
-       return result;
-}
-
-int _badge_get_list(GList **badge_list, uid_t uid)
-{
-       sqlite3 *db = NULL;
-       int result = BADGE_ERROR_NONE;
-       char *sqlbuf = NULL;
-       sqlite3_stmt *stmt = NULL;
-       int sqlret;
-       const char *pkg;
-       unsigned int badge_count;
-       badge_info_s *badge_info;
-
-       sqlret = db_util_open(BADGE_DB_PATH, &db, 0);
-       if (sqlret != SQLITE_OK || !db) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to db_util_open [%d]", sqlret);
-               return BADGE_ERROR_FROM_DB;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sqlbuf = sqlite3_mprintf("SELECT pkgname, badge FROM %q WHERE uid = %d",
-                               BADGE_TABLE_NAME, uid);
-       if (!sqlbuf) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               result = BADGE_ERROR_OUT_OF_MEMORY;
-               goto free_and_return;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sqlret = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL);
-       if (sqlret != SQLITE_OK) {
-               /* LCOV_EXCL_START */
-               ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlret,
-                                       sqlite3_errmsg(db));
-               result = BADGE_ERROR_FROM_DB;
-               goto free_and_return;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sqlret = sqlite3_step(stmt);
-       if (sqlret == SQLITE_DONE) {
-               INFO("badge db has no data");
-               result = BADGE_ERROR_NOT_EXIST;
-               goto free_and_return;
-       } else if (sqlret != SQLITE_ROW) {
-               ERR("Failed to sqlite3_step [%d]", sqlret);
-               result = BADGE_ERROR_FROM_DB;
-               goto free_and_return;
-       }
-
-       do {
-               pkg = (const char *)sqlite3_column_text(stmt, 0);
-               badge_count = (unsigned int)sqlite3_column_int(stmt, 1);
-               if (pkg) {
-                       badge_info = (badge_info_s *)calloc(sizeof(badge_info_s), 1);
-                       if (badge_info == NULL) {
-                               /* LCOV_EXCL_START */
-                               ERR("alloc badge_info failed");
-                               result = BADGE_ERROR_OUT_OF_MEMORY;
-                               break;
-                               /* LCOV_EXCL_STOP */
-                       }
-                       badge_info->pkg = strdup(pkg);
-                       badge_info->badge_count = badge_count;
-                       *badge_list = g_list_append(*badge_list, badge_info);
-               } else {
-                       /* LCOV_EXCL_START */
-                       ERR("db has invaild data");
-                       result = BADGE_ERROR_FROM_DB;
-                       /* LCOV_EXCL_STOP */
-               }
-       } while (sqlite3_step(stmt) == SQLITE_ROW);
-
-free_and_return:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
-
-       if (stmt)
-               sqlite3_finalize(stmt);
-
-       sqlret = db_util_close(db);
-       if (sqlret != SQLITE_OK)
-               WARN("Failed to db_util_close [%d]", sqlret); /* LCOV_EXCL_LINE */
-
-       return result;
-}
-
-int _badge_insert(badge_h *badge, uid_t uid)
-{
-       sqlite3 *db = NULL;
-       int sqlret;
-       int ret = BADGE_ERROR_NONE;
-       int result = BADGE_ERROR_NONE;
-       char *sqlbuf = NULL;
-       bool is_existed = false;
-
-       if (!badge || !badge->pkgname || !badge->writable_pkgs)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       ret = badge_setting_is_existed_appid(badge->pkgname, &is_existed, uid);
-       if (ret == BADGE_ERROR_NONE && is_existed == false) {
-               result = BADGE_ERROR_INVALID_PACKAGE;
-               goto return_close_db;
-       } else if (ret != BADGE_ERROR_NONE) {
-               ERR("Failed to check existed appid [%d]", ret);
-               result = ret;
-               goto return_close_db;
-       }
-
-       sqlret = db_util_open(BADGE_DB_PATH, &db, 0);
-       if (sqlret != SQLITE_OK || !db) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to db_util_open [%s][%d]", BADGE_DB_PATH, sqlret);
-               return BADGE_ERROR_FROM_DB;
-               /* LCOV_EXCL_STOP */
-       }
-
-       /* Check pkgname & id */
-       ret = _badge_check_data_inserted(badge->pkgname, db, uid);
-       if (ret != BADGE_ERROR_NOT_EXIST) {
-               /* LCOV_EXCL_START */
-               result = ret;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sqlbuf = sqlite3_mprintf("INSERT INTO %q " \
-                       "(pkgname, writable_pkgs, uid) VALUES (%Q, %Q, %d);",
-                        BADGE_TABLE_NAME,
-                        badge->pkgname, badge->writable_pkgs, uid);
-       if (!sqlbuf) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               result = BADGE_ERROR_OUT_OF_MEMORY;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = badge_db_exec(db, sqlbuf, NULL);
-       if (ret != BADGE_ERROR_NONE) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to insert badge[%s], err[%d]",
-                                       badge->pkgname, ret);
-               result = ret;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-       /* inserting badge options */
-       ret = _badge_check_option_inserted(badge->pkgname, db, uid);
-       if (ret != BADGE_ERROR_NOT_EXIST) {
-               result = ret;
-               goto return_close_db;
-       }
-
-       sqlite3_free(sqlbuf);
-
-       sqlbuf = sqlite3_mprintf("INSERT INTO %q " \
-                       "(pkgname, uid) VALUES (%Q, %d);",
-                       BADGE_OPTION_TABLE_NAME,
-                       badge->pkgname, uid);
-       if (!sqlbuf) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               result = BADGE_ERROR_OUT_OF_MEMORY;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = badge_db_exec(db, sqlbuf, NULL);
-       if (ret != BADGE_ERROR_NONE) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to insert badge option[%s], err[%d]",
-                                       badge->pkgname, sqlret);
-               result = ret;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-return_close_db:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
-
-       sqlret = db_util_close(db);
-       if (sqlret != SQLITE_OK)
-               WARN("Failed to db_util_close [%d]", sqlret); /* LCOV_EXCL_LINE */
-
-       return result;
-}
-
-int _badge_remove(const char *caller, const char *pkgname, uid_t uid, pid_t pid)
-{
-       int ret = BADGE_ERROR_NONE;
-       int result = BADGE_ERROR_NONE;
-       sqlite3 *db = NULL;
-       int sqlret;
-       char *sqlbuf = NULL;
-
-       if (!caller || !pkgname)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       sqlret = db_util_open(BADGE_DB_PATH, &db, 0);
-       if (sqlret != SQLITE_OK || !db) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to db_util_open [%d]", sqlret);
-               return BADGE_ERROR_FROM_DB;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = _badge_check_data_inserted(pkgname, db, uid);
-       if (ret != BADGE_ERROR_ALREADY_EXIST) {
-               result = ret;
-               goto return_close_db;
-       }
-
-       ret = _badge_check_writable(caller, pkgname, db, uid, pid);
-       if (ret != BADGE_ERROR_NONE) {
-               result = ret;
-               goto return_close_db;
-       }
-
-       sqlbuf = sqlite3_mprintf("DELETE FROM %q WHERE pkgname = %Q AND uid = %d",
-                        BADGE_TABLE_NAME, pkgname, uid);
-       if (!sqlbuf) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               result = BADGE_ERROR_OUT_OF_MEMORY;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = badge_db_exec(db, sqlbuf, NULL);
-       if (ret != BADGE_ERROR_NONE) {
-               ERR("Failed to remove badge[%s], err[%d]",
-                               pkgname, ret);
-               result = ret;
-               goto return_close_db;
-       }
-
-       /* treating option table */
-       ret = _badge_check_option_inserted(pkgname, db, uid);
-       if (ret != BADGE_ERROR_ALREADY_EXIST) {
-               result = ret;
-               goto return_close_db;
-       }
-
-       sqlite3_free(sqlbuf);
-
-       sqlbuf = sqlite3_mprintf("DELETE FROM %q WHERE pkgname = %Q AND uid = %d",
-                       BADGE_OPTION_TABLE_NAME, pkgname, uid);
-       if (!sqlbuf) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               result = BADGE_ERROR_OUT_OF_MEMORY;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = badge_db_exec(db, sqlbuf, NULL);
-       if (ret != BADGE_ERROR_NONE) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to remove badge option[%s], err[%d]",
-                               pkgname, ret);
-               result = ret;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-return_close_db:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
-
-       sqlret = db_util_close(db);
-       if (sqlret != SQLITE_OK)
-               WARN("Failed to db_util_close [%d]", sqlret); /* LCOV_EXCL_LINE */
-
-       return result;
-}
-
-static int _badge_remove_by_appid(const char *appid, uid_t uid, sqlite3 *db)
-{
-       int ret = BADGE_ERROR_NONE;
-       int result = BADGE_ERROR_NONE;
-       char *sqlbuf = NULL;
-
-       ret = _badge_check_data_inserted(appid, db, uid);
-       if (ret != BADGE_ERROR_ALREADY_EXIST) {
-               result = ret;
-               goto return_close_db;
-       }
-
-       sqlbuf = sqlite3_mprintf("DELETE FROM %q WHERE pkgname = %Q AND uid = %d",
-                        BADGE_TABLE_NAME, appid, uid);
-       if (!sqlbuf) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               result = BADGE_ERROR_OUT_OF_MEMORY;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = badge_db_exec(db, sqlbuf, NULL);
-       if (ret != BADGE_ERROR_NONE) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to remove badge[%s], err[%d]", appid, ret);
-               result = ret;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-       /* treating option table */
-       ret = _badge_check_option_inserted(appid, db, uid);
-       if (ret != BADGE_ERROR_ALREADY_EXIST) {
-               result = ret;
-               goto return_close_db;
-       }
-
-       sqlite3_free(sqlbuf);
-
-       sqlbuf = sqlite3_mprintf("DELETE FROM %q WHERE pkgname = %Q AND uid = %d",
-                       BADGE_OPTION_TABLE_NAME, appid, uid);
-       if (!sqlbuf) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               result = BADGE_ERROR_OUT_OF_MEMORY;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = badge_db_exec(db, sqlbuf, NULL);
-       if (ret != BADGE_ERROR_NONE) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to remove badge option[%s], err[%d]",
-                               appid, ret);
-               result = ret;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-return_close_db:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
-
-       return result;
-}
-
-static bool _get_table_field_data_string(char **table, char **buf, int ucs2, int index)
-{
-       bool ret = false;
-       int sLen = 0;
-       char *pTemp;
-
-       if (table == NULL || buf == NULL || index < 0) {
-               /* LCOV_EXCL_START */
-               ERR("table[%p], buf[%p], index[%d]", table, buf, index);
-               return false;
-               /* LCOV_EXCL_STOP */
-       }
-
-       pTemp = table[index];
-       if (pTemp == NULL) {
-               *buf = NULL; /* LCOV_EXCL_LINE */
-       } else {
-               sLen = strlen(pTemp);
-               if (sLen) {
-                       *buf = (char *)malloc(sLen + 1);
-                       if (*buf == NULL) {
-                               ERR("malloc is failed"); /* LCOV_EXCL_LINE */
-                               goto out;
-                       }
-                       memset(*buf, 0, sLen + 1);
-                       strncpy(*buf, pTemp, sLen + 1);
-               } else {
-                       *buf = NULL; /* LCOV_EXCL_LINE */
-               }
-       }
-
-       ret = true;
-
-out:
-       return ret;
-}
-
-int _badge_remove_by_pkgname(const char *pkgname, uid_t uid)
-{
-       int ret = BADGE_ERROR_NONE;
-       int sql_ret;
-       int row_count = 0;
-       int col_count = 0;
-       int col_index = 0;
-       int index;
-       char *sql_query = NULL;
-       char **query_result = NULL;
-       char *appid = NULL;
-       sqlite3 *db = NULL;
-
-       sql_ret = db_util_open(BADGE_DB_PATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               ERR("Failed db util open [%s][%d]", BADGE_DB_PATH, sql_ret);
-               return BADGE_ERROR_FROM_DB;
-       }
-
-       sql_query = sqlite3_mprintf("SELECT appid FROM %s WHERE pkgname = %Q" \
-                               "AND (uid = %d OR uid = %d) ORDER BY uid DESC;",
-                               BADGE_SETTING_DB_TABLE, pkgname, uid,
-                               tzplatform_getuid(TZ_SYS_GLOBALAPP_USER));
-       if (!sql_query) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sql_ret = sqlite3_get_table(db, sql_query, &query_result, &row_count, &col_count, NULL);
-       if (sql_ret != SQLITE_OK && sql_ret != -1) {
-               /* LCOV_EXCL_START */
-               ERR("sqlite3_get_table failed [%d][%s]", sql_ret,
-                                       sqlite3_errmsg(db));
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       if (!row_count) {
-               DBG("No setting found for [%s]", pkgname);
-               ret = BADGE_ERROR_NOT_EXIST;
-               goto out;
-       }
-
-       col_index = col_count;
-
-       for (index = 0; index < row_count; index++) {
-               _get_table_field_data_string(query_result, &appid, 1, col_index++);
-               if (appid) {
-                       _badge_remove_by_appid(appid, uid, db);
-                       free(appid);
-                       appid = NULL;
-               }
-       }
-
-out:
-       if (query_result)
-               sqlite3_free_table(query_result);
-       if (sql_query)
-               sqlite3_free(sql_query);
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       WARN("Failed to db_util_close");
-       }
-
-       return ret;
-}
-
-int _badge_set_count(const char *caller, const char *pkgname,
-                       unsigned int count, uid_t uid, pid_t pid)
-{
-       int ret = BADGE_ERROR_NONE;
-       int result = BADGE_ERROR_NONE;
-       sqlite3 *db = NULL;
-       char *sqlbuf = NULL;
-       int sqlret;
-
-       if (!caller || !pkgname)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       sqlret = db_util_open(BADGE_DB_PATH, &db, 0);
-       if (sqlret != SQLITE_OK || !db) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to db_util_open [%d]", sqlret);
-               return BADGE_ERROR_FROM_DB;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = _badge_check_data_inserted(pkgname, db, uid);
-       if (ret != BADGE_ERROR_ALREADY_EXIST) {
-               result = ret;
-               goto return_close_db;
-       }
-
-       ret = _badge_check_writable(caller, pkgname, db, uid, pid);
-       if (ret != BADGE_ERROR_NONE) {
-               result = ret;
-               goto return_close_db;
-       }
-
-       sqlbuf = sqlite3_mprintf("UPDATE %q SET badge = %d " \
-                               "WHERE pkgname = %Q AND uid = %d",
-                               BADGE_TABLE_NAME, count, pkgname, uid);
-       if (!sqlbuf) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               result = BADGE_ERROR_OUT_OF_MEMORY;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = badge_db_exec(db, sqlbuf, NULL);
-       if (ret != BADGE_ERROR_NONE) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to set badge[%s] count[%d], err[%d]",
-                               pkgname, count, ret);
-               result = ret;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-return_close_db:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
-
-       sqlret = db_util_close(db);
-       if (sqlret != SQLITE_OK)
-               WARN("Failed to db_util_close [%d]", sqlret); /* LCOV_EXCL_LINE */
-
-       return result;
-}
-
-int _badge_get_count(const char *pkgname, unsigned int *count, uid_t uid)
-{
-       int ret = BADGE_ERROR_NONE;
-       int result = BADGE_ERROR_NONE;
-       sqlite3 *db = NULL;
-       char *sqlbuf = NULL;
-       sqlite3_stmt *stmt = NULL;
-       int sqlret;
-
-       if (!pkgname || !count)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       sqlret = db_util_open(BADGE_DB_PATH, &db, 0);
-       if (sqlret != SQLITE_OK || !db) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to db_util_open [%d]", sqlret);
-               if (sqlret == SQLITE_PERM)
-                       return BADGE_ERROR_PERMISSION_DENIED;
-               else
-                       return BADGE_ERROR_FROM_DB;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = _badge_check_data_inserted(pkgname, db, uid);
-       if (ret != BADGE_ERROR_ALREADY_EXIST) {
-               result = ret;
-               goto return_close_db;
-       }
-
-       sqlbuf = sqlite3_mprintf("SELECT badge FROM %q " \
-                               "WHERE pkgname = %Q AND uid = %d",
-                               BADGE_TABLE_NAME, pkgname, uid);
-       if (!sqlbuf) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               result = BADGE_ERROR_OUT_OF_MEMORY;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sqlret = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL);
-       if (sqlret != SQLITE_OK) {
-               /* LCOV_EXCL_START */
-               ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlret,
-                                       sqlite3_errmsg(db));
-               result = BADGE_ERROR_FROM_DB;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sqlret = sqlite3_step(stmt);
-       if (sqlret == SQLITE_ROW)
-               *count = (unsigned int)sqlite3_column_int(stmt, 0);
-       else
-               *count = (unsigned int)0;
-
-return_close_db:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
-
-       if (stmt)
-               sqlite3_finalize(stmt);
-
-       sqlret = db_util_close(db);
-       if (sqlret != SQLITE_OK)
-               WARN("Failed to db_util_close [%d]", sqlret); /* LCOV_EXCL_LINE */
-
-       return result;
-}
-
-int _badge_set_display(const char *pkgname, unsigned int is_display, uid_t uid)
-{
-       int ret = BADGE_ERROR_NONE;
-       int result = BADGE_ERROR_NONE;
-       sqlite3 *db = NULL;
-       char *sqlbuf = NULL;
-       int sqlret;
-
-       if (!pkgname)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       if (is_display != 0 && is_display != 1)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       sqlret = db_util_open(BADGE_DB_PATH, &db, 0);
-       if (sqlret != SQLITE_OK || !db) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to db_util_open [%d]", sqlret);
-               return BADGE_ERROR_FROM_DB;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = _badge_check_data_inserted(pkgname, db, uid);
-       if (ret != BADGE_ERROR_ALREADY_EXIST) {
-               result = ret;
-               goto return_close_db;
-       }
-
-       ret = _badge_check_option_inserted(pkgname, db, uid);
-       if (ret == BADGE_ERROR_ALREADY_EXIST) {
-               sqlbuf = sqlite3_mprintf("UPDATE %q SET display = %d " \
-                               "WHERE pkgname = %Q AND uid = %d",
-                               BADGE_OPTION_TABLE_NAME, is_display, pkgname, uid);
-               if (!sqlbuf) {
-                       /* LCOV_EXCL_START */
-                       ERR("Failed to alloc query");
-                       result = BADGE_ERROR_OUT_OF_MEMORY;
-                       goto return_close_db;
-                       /* LCOV_EXCL_STOP */
-               }
-
-               ret = badge_db_exec(db, sqlbuf, NULL);
-               if (ret != BADGE_ERROR_NONE) {
-                       /* LCOV_EXCL_START */
-                       ERR("Failed to set badge[%s] option[%d], err[%d]",
-                                       pkgname, is_display, ret);
-                       result = ret;
-                       goto return_close_db;
-                       /* LCOV_EXCL_STOP */
-               }
-
-       } else if (ret == BADGE_ERROR_NOT_EXIST) {
-               sqlbuf = sqlite3_mprintf("INSERT INTO %q " \
-                               "(pkgname, display, uid) VALUES (%Q, %d, %d);",
-                               BADGE_OPTION_TABLE_NAME,
-                               pkgname, is_display, uid);
-               if (!sqlbuf) {
-                       /* LCOV_EXCL_START */
-                       ERR("Failed to alloc query");
-                       result = BADGE_ERROR_OUT_OF_MEMORY;
-                       goto return_close_db;
-                       /* LCOV_EXCL_STOP */
-               }
-
-               ret = badge_db_exec(db, sqlbuf, NULL);
-               if (ret != BADGE_ERROR_NONE) {
-                       /* LCOV_EXCL_START */
-                       ERR("Failed to set badge[%s] option[%d], err[%d]",
-                                       pkgname, is_display, ret);
-                       result = ret;
-                       goto return_close_db;
-                       /* LCOV_EXCL_STOP */
-               }
-       } else {
-               result = ret;
-               goto return_close_db;
-       }
-
-return_close_db:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
-
-       sqlret = db_util_close(db);
-       if (sqlret != SQLITE_OK)
-               WARN("Failed to db_util_close [%d]", sqlret); /* LCOV_EXCL_LINE */
-
-       return result;
-}
-
-int _badge_get_display(const char *pkgname, unsigned int *is_display, uid_t uid)
-{
-       int ret = BADGE_ERROR_NONE;
-       int result = BADGE_ERROR_NONE;
-       sqlite3 *db = NULL;
-       char *sqlbuf = NULL;
-       sqlite3_stmt *stmt = NULL;
-       int sqlret;
-
-       if (!pkgname || !is_display)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       sqlret = db_util_open(BADGE_DB_PATH, &db, 0);
-       if (sqlret != SQLITE_OK || !db) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to db_util_open [%d]", sqlret);
-               if (sqlret == SQLITE_PERM)
-                       return BADGE_ERROR_PERMISSION_DENIED;
-               else
-                       return BADGE_ERROR_FROM_DB;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = _badge_check_option_inserted(pkgname, db, uid);
-       if (ret != BADGE_ERROR_ALREADY_EXIST) {
-               if (ret == BADGE_ERROR_NOT_EXIST)
-                       *is_display = 1;
-
-               result = ret;
-               goto return_close_db;
-       }
-
-       sqlbuf = sqlite3_mprintf("SELECT display FROM %q " \
-                       "WHERE pkgname = %Q AND uid = %d",
-                       BADGE_OPTION_TABLE_NAME, pkgname, uid);
-       if (!sqlbuf) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               result = BADGE_ERROR_OUT_OF_MEMORY;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sqlret = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL);
-       if (sqlret != SQLITE_OK) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to prepare [%d][%s]", sqlret, sqlite3_errmsg(db));
-               result = BADGE_ERROR_FROM_DB;
-               goto return_close_db;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sqlret = sqlite3_step(stmt);
-       if (sqlret == SQLITE_ROW)
-               *is_display = (unsigned int)sqlite3_column_int(stmt, 0);
-       else
-               *is_display = (unsigned int)1;
-
-return_close_db:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
-
-       if (stmt)
-               sqlite3_finalize(stmt);
-
-       sqlret = db_util_close(db);
-       if (sqlret != SQLITE_OK)
-               WARN("Failed to db_util_close [%d]", sqlret); /* LCOV_EXCL_LINE */
-
-       return result;
-}
-
-void badge_changed_cb_call(unsigned int action, const char *pkgname,
-                       unsigned int count, uid_t uid)
-{
-       GList *badge_cb_list = NULL;
-       struct _badge_cb_data *bd = NULL;
-
-       DBG("call badge_change_cb");
-
-       if (_badge_cb_hash == NULL)
-               return;
-
-       badge_cb_list = (GList *)g_hash_table_lookup(_badge_cb_hash, GUINT_TO_POINTER(uid));
-
-       if (badge_cb_list == NULL) {
-               ERR("invalid data");
-               return;
-       }
-
-       badge_cb_list = g_list_first(badge_cb_list);
-
-       for (; badge_cb_list != NULL; badge_cb_list = badge_cb_list->next) {
-               bd = badge_cb_list->data;
-
-               if (bd != NULL && bd->callback != NULL) {
-                       DBG("call badge_change_cb : action %d, pkgname %s, count %d",
-                           action, pkgname, count);
-                       bd->callback(action, pkgname, count, bd->data);
-               }
-       }
-}
-
-static int _badge_changed_monitor_init(uid_t uid)
-{
-       return badge_ipc_monitor_init(uid);
-}
-
-static void _badge_chanaged_monitor_fini(void)
-{
-       badge_ipc_monitor_fini();
-}
-
-static gint _badge_data_compare(gconstpointer a, gconstpointer b)
-{
-       const struct _badge_cb_data *bd = NULL;
-
-       if (!a)
-               return -1;
-       bd = (struct _badge_cb_data *)a;
-
-       if (bd->callback == b)
-               return 0;
-
-       return 1;
-}
-
-static struct _badge_cb_data *__malloc_badge_cb_data(badge_change_cb callback, void *data)
-{
-       struct _badge_cb_data *bd = NULL;
-
-       bd = (struct _badge_cb_data *)malloc(sizeof(struct _badge_cb_data));
-       if (bd == NULL) {
-               /* LCOV_EXCL_START */
-               ERR("Failed malloc badge_cb_data");
-               return NULL;
-               /* LCOV_EXCL_STOP */
-       }
-
-       bd->callback = callback;
-       bd->data = data;
-
-       return bd;
-}
-
-int _badge_free(badge_h *badge)
-{
-       if (!badge)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       if (badge->pkgname)
-               free(badge->pkgname);
-
-       if (badge->writable_pkgs)
-               free(badge->writable_pkgs);
-
-       free(badge);
-
-       return BADGE_ERROR_NONE;
-}
-
-badge_h *_badge_new(const char *pkgname, const char *writable_pkgs,
-               int *err)
-{
-       badge_h *badge = NULL;
-
-       if (!pkgname || !writable_pkgs) {
-               ERR("Invalid parameters");
-               if (err)
-                       *err = BADGE_ERROR_INVALID_PARAMETER;
-               return NULL;
-       }
-
-       badge = (badge_h *)malloc(sizeof(struct _badge_h));
-       if (!badge) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc handle");
-               if (err)
-                       *err = BADGE_ERROR_OUT_OF_MEMORY;
-               return NULL;
-               /* LCOV_EXCL_STOP */
-       }
-
-       badge->pkgname = strdup(pkgname);
-       badge->writable_pkgs = strdup(writable_pkgs);
-       if (err)
-               *err = BADGE_ERROR_NONE;
-
-       return badge;
-}
-
-char *_badge_pkgs_new(int *err, const char *pkg1, ...)
-{
-       char *caller_pkgname = NULL;
-       char *s = NULL;
-       char *result = NULL;
-       char *ptr = NULL;
-       gsize length;
-       va_list args;
-       char *new_pkgs = NULL;
-
-       if (err)
-               *err = BADGE_ERROR_NONE;
-
-       caller_pkgname = _badge_get_pkgname_by_pid();
-       if (!caller_pkgname) {
-               ERR("Failed to get caller pkgname");
-               if (err)
-                       *err = BADGE_ERROR_PERMISSION_DENIED;
-               return NULL;
-       }
-
-       if (!pkg1) {
-               WARN("pkg1 is NULL");
-               return caller_pkgname;
-       }
-
-       length = strlen(pkg1);
-       va_start(args, pkg1);
-       s = va_arg(args, char *);
-       while (s) {
-               length += strlen(s);
-               s = va_arg(args, char *);
-       }
-       va_end(args);
-
-       if (length <= 0) {
-               WARN("length is %zu", length);
-               return caller_pkgname;
-       }
-
-       result = g_new0(char, length + 1); /* 1 for null terminate */
-       if (!result) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc memory");
-               if (err)
-                       *err = BADGE_ERROR_OUT_OF_MEMORY;
-               free(caller_pkgname);
-               return NULL;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ptr = result;
-       ptr = g_stpcpy(ptr, pkg1);
-       va_start(args, pkg1);
-       s = va_arg(args, char *);
-       while (s) {
-               ptr = g_stpcpy(ptr, s);
-               s = va_arg(args, char *);
-       }
-       va_end(args);
-
-       if (g_strstr_len(result, -1, caller_pkgname) == NULL) {
-               new_pkgs = g_strdup_printf("%s%s", caller_pkgname, result);
-               if (!new_pkgs) {
-                       ERR("Failed to alloc memory");
-                       if (err)
-                               *err = BADGE_ERROR_OUT_OF_MEMORY;
-
-                       free(result);
-                       free(caller_pkgname);
-                       return NULL;
-               }
-               free(result);
-               result = new_pkgs;
-       }
-
-       free(caller_pkgname);
-
-       return result;
-}
-
-EXPORT_API
-int badge_create_for_uid(const char *pkgname, const char *writable_pkg, uid_t uid)
-{
-       CHECK_BADGE_FEATURE();
-       char *caller = NULL;
-       int err = BADGE_ERROR_NONE;
-
-       caller = _badge_get_pkgname_by_pid();
-       if (!caller) {
-               ERR("Failed to get caller pkgname");
-               return BADGE_ERROR_PERMISSION_DENIED;
-       }
-
-       err = badge_ipc_request_insert(pkgname, writable_pkg, caller, uid);
-
-       free(caller);
-       return err;
-}
-
-EXPORT_API
-int badge_new_for_uid(const char *writable_app_id, uid_t uid)
-{
-       CHECK_BADGE_FEATURE();
-       char *caller = NULL;
-       int err = BADGE_ERROR_NONE;
-
-       caller = _badge_get_pkgname_by_pid();
-       if (!caller) {
-               ERR("Failed to get caller pkgname");
-               return BADGE_ERROR_PERMISSION_DENIED;
-       }
-
-       err = badge_ipc_request_insert(caller, writable_app_id, caller, uid);
-
-       free(caller);
-       return err;
-}
-
-int badge_new_for_for_uid(const char *badge_app_id, const char *writable_app_id, uid_t uid)
-{
-       CHECK_BADGE_FEATURE();
-       char *caller = NULL;
-       int err = BADGE_ERROR_NONE;
-
-       caller = _badge_get_pkgname_by_pid();
-       if (!caller) {
-               ERR("Failed to get caller pkgname");
-               return BADGE_ERROR_PERMISSION_DENIED;
-       }
-
-       if (badge_app_id == NULL) {
-               badge_app_id = caller;
-       } else {
-               int pkgmgr_ret  = PACKAGE_MANAGER_ERROR_NONE;
-               package_manager_compare_result_type_e compare_result =
-                                               PACKAGE_MANAGER_COMPARE_MISMATCH;
-
-               pkgmgr_ret = package_manager_compare_app_cert_info(badge_app_id,
-                                                       caller, &compare_result);
-
-               if (pkgmgr_ret != PACKAGE_MANAGER_ERROR_NONE ||
-                       compare_result != PACKAGE_MANAGER_COMPARE_MATCH) {
-                       err = BADGE_ERROR_INVALID_PACKAGE;
-                       goto out;
-               }
-       }
-
-       err = badge_ipc_request_insert(badge_app_id, writable_app_id, caller, uid);
-out:
-       if (caller)
-               free(caller);
-       return err;
-}
-
-EXPORT_API
-int badge_new_for(const char *badge_app_id, const char *writable_app_id)
-{
-       CHECK_BADGE_FEATURE();
-       if (writable_app_id == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       return badge_new_for_for_uid(badge_app_id, writable_app_id, getuid());
-}
-
-EXPORT_API
-int badge_add_for_uid(const char *badge_app_id, uid_t uid)
-{
-       CHECK_BADGE_FEATURE();
-       char *caller = NULL;
-       int err = BADGE_ERROR_NONE;
-
-       caller = _badge_get_pkgname_by_pid();
-       if (!caller) {
-               ERR("Failed to get caller pkgname");
-               return BADGE_ERROR_PERMISSION_DENIED;
-       }
-
-       if (badge_app_id == NULL) {
-               badge_app_id = caller;
-       } else {
-               int pkgmgr_ret  = PACKAGE_MANAGER_ERROR_NONE;
-               package_manager_compare_result_type_e compare_result = PACKAGE_MANAGER_COMPARE_MISMATCH;
-
-               pkgmgr_ret = package_manager_compare_app_cert_info(badge_app_id, caller, &compare_result);
-
-               if (pkgmgr_ret != PACKAGE_MANAGER_ERROR_NONE || compare_result != PACKAGE_MANAGER_COMPARE_MATCH) {
-                       err = BADGE_ERROR_INVALID_PACKAGE;
-                       goto out;
-               }
-       }
-
-       err = badge_ipc_request_insert(badge_app_id, caller, caller, uid);
-
-out:
-       if (caller)
-               free(caller);
-       return err;
-}
-
-EXPORT_API
-int badge_remove_for_uid(const char *app_id, uid_t uid)
-{
-       CHECK_BADGE_FEATURE();
-       char *caller = NULL;
-       int result = BADGE_ERROR_NONE;
-
-       caller = _badge_get_pkgname_by_pid();
-       if (!caller) {
-               ERR("Failed to get caller pkgname");
-               result = BADGE_ERROR_PERMISSION_DENIED;
-               goto out;
-       }
-
-       result = badge_ipc_request_delete(app_id, caller, uid);
-
-out:
-       if (caller)
-               free(caller);
-       return result;
-}
-
-EXPORT_API
-int badge_is_existing_for_uid(const char *app_id, bool *existing, uid_t uid)
-{
-       CHECK_BADGE_FEATURE();
-       return badge_ipc_request_is_existing(app_id, existing, uid);
-}
-
-EXPORT_API
-int badge_foreach_for_uid(badge_foreach_cb callback, void *user_data, uid_t uid)
-{
-       CHECK_BADGE_FEATURE();
-       int result = BADGE_ERROR_NONE;
-
-       result = badge_ipc_request_get_list(callback, user_data, uid);
-       if (result == BADGE_ERROR_IO_ERROR)
-               result = BADGE_ERROR_FROM_DB;
-       return result;
-}
-
-EXPORT_API
-int badge_set_count_for_uid(const char *app_id, unsigned int count, uid_t uid)
-{
-       CHECK_BADGE_FEATURE();
-       char *caller = NULL;
-       int result = BADGE_ERROR_NONE;
-
-       DBG("app_id %s, count %d", app_id, count);
-
-       caller = _badge_get_pkgname_by_pid();
-       if (!caller) {
-               ERR("Failed to get caller pkgname");
-               result = BADGE_ERROR_PERMISSION_DENIED;
-               goto out;
-       }
-
-       result = badge_ipc_request_set_count(app_id, caller, count, uid);
-out:
-       if (caller)
-               free(caller);
-       return result;
-}
-
-EXPORT_API
-int badge_get_count_for_uid(const char *app_id, unsigned int *count, uid_t uid)
-{
-       CHECK_BADGE_FEATURE();
-       int result = BADGE_ERROR_NONE;
-
-       result = badge_ipc_request_get_count(app_id, count, uid);
-       if (result == BADGE_ERROR_IO_ERROR)
-               result = BADGE_ERROR_FROM_DB;
-
-       return result;
-}
-
-EXPORT_API
-int badge_set_display_for_uid(const char *app_id, unsigned int is_display, uid_t uid)
-{
-       CHECK_BADGE_FEATURE();
-       char *caller = NULL;
-       int result = BADGE_ERROR_NONE;
-
-       caller = _badge_get_pkgname_by_pid();
-       if (!caller) {
-               ERR("Failed to get caller pkgname");
-               result = BADGE_ERROR_PERMISSION_DENIED;
-               goto out;
-       }
-
-       result = badge_ipc_request_set_display(app_id, caller, is_display, uid);
-
-out:
-       if (caller)
-               free(caller);
-       return result;
-}
-
-EXPORT_API
-int badge_get_display_for_uid(const char *app_id, unsigned int *is_display, uid_t uid)
-{
-       CHECK_BADGE_FEATURE();
-       int result = BADGE_ERROR_NONE;
-
-       result = badge_ipc_request_get_display(app_id, is_display, uid);
-       if (result == BADGE_ERROR_IO_ERROR)
-               result = BADGE_ERROR_FROM_DB;
-
-       return result;
-}
-
-EXPORT_API
-int badge_register_changed_cb_for_uid(badge_change_cb callback, void *data, uid_t uid)
-{
-       CHECK_BADGE_FEATURE();
-       struct _badge_cb_data *bd = NULL;
-       GList *badge_cb_list = NULL;
-       GList *badge_found_list = NULL;
-       int ret;
-
-       if (_badge_cb_hash == NULL)
-               _badge_cb_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
-
-       badge_cb_list = (GList *)g_hash_table_lookup(_badge_cb_hash, GUINT_TO_POINTER(uid));
-
-       if (badge_cb_list == NULL) {
-               bd = __malloc_badge_cb_data(callback, data);
-               if (!bd)
-                       return BADGE_ERROR_OUT_OF_MEMORY;
-
-               badge_cb_list = g_list_append(badge_cb_list, bd);
-               g_hash_table_insert(_badge_cb_hash, GUINT_TO_POINTER(uid), badge_cb_list);
-       } else {
-               badge_found_list = g_list_find_custom(g_list_first(badge_cb_list), (gconstpointer)callback,
-                                                     (GCompareFunc)_badge_data_compare);
-               if (badge_found_list) {
-                       bd = g_list_nth_data(badge_found_list, 0);
-                       bd->data = data;
-               } else {
-                       bd = __malloc_badge_cb_data(callback, data);
-                       if (!bd)
-                               return BADGE_ERROR_OUT_OF_MEMORY;
-                       badge_cb_list = g_list_append(badge_cb_list, bd);
-               }
-       }
-
-       ret = _badge_changed_monitor_init(uid);
-       if (ret == BADGE_ERROR_NONE) {
-               ret = badge_ipc_init_badge(uid);
-               if (ret != BADGE_ERROR_NONE && ret != BADGE_ERROR_NOT_EXIST) {
-                       badge_unregister_changed_cb_for_uid(callback, uid);
-                       return BADGE_ERROR_IO_ERROR;
-               }
-       } else {
-               /* LCOV_EXCL_START */
-               ERR("badge_ipc_monitor_init err [%d]", ret);
-               badge_unregister_changed_cb_for_uid(callback, uid);
-               return ret;
-               /* LCOV_EXCL_STOP */
-       }
-       return BADGE_ERROR_NONE;
-}
-
-EXPORT_API
-int badge_unregister_changed_cb_for_uid(badge_change_cb callback, uid_t uid)
-{
-       CHECK_BADGE_FEATURE();
-       GList *badge_cb_list = NULL;
-       GList *badge_delete_list = NULL;
-       struct _badge_cb_data *bd = NULL;
-
-       if (_badge_cb_hash == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       badge_cb_list = (GList *)g_hash_table_lookup(_badge_cb_hash, GUINT_TO_POINTER(uid));
-
-       if (badge_cb_list == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       badge_delete_list = g_list_find_custom(g_list_first(badge_cb_list), (gconstpointer)callback,
-                                              (GCompareFunc)_badge_data_compare);
-
-       if (badge_delete_list) {
-               bd = g_list_nth_data(badge_delete_list, 0);
-               badge_cb_list = g_list_delete_link(badge_cb_list, badge_delete_list);
-               free(bd);
-       } else {
-               return BADGE_ERROR_INVALID_PARAMETER;
-       }
-
-       if (badge_cb_list == NULL)
-               g_hash_table_steal(_badge_cb_hash, GUINT_TO_POINTER(uid));
-       else
-               g_hash_table_replace(_badge_cb_hash, GUINT_TO_POINTER(uid), badge_cb_list);
-
-       if (g_hash_table_size(_badge_cb_hash) == 0)
-               _badge_chanaged_monitor_fini();
-
-       return BADGE_ERROR_NONE;
-}
-
-EXPORT_API
-int badge_is_service_ready(void)
-{
-       CHECK_BADGE_FEATURE();
-       return badge_ipc_is_master_ready();
-}
-
-EXPORT_API
-int badge_add_deferred_task(
-               void (*badge_add_deferred_task)(void *data), void *user_data)
-{
-       CHECK_BADGE_FEATURE();
-       return badge_ipc_add_deferred_task(badge_add_deferred_task, user_data);
-}
-
-EXPORT_API
-int badge_del_deferred_task(
-               void (*badge_add_deferred_task)(void *data))
-{
-       CHECK_BADGE_FEATURE();
-       return badge_ipc_del_deferred_task(badge_add_deferred_task);
-}
-
-EXPORT_API
-int badge_is_existing(const char *app_id, bool *existing)
-{
-       CHECK_BADGE_FEATURE();
-       if (app_id == NULL || existing == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       return badge_is_existing_for_uid(app_id, existing, getuid());
-}
-
-EXPORT_API
-int badge_create(const char *pkgname, const char *writable_pkg)
-{
-       CHECK_BADGE_FEATURE();
-       if (pkgname == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       return badge_create_for_uid(pkgname, writable_pkg, getuid());
-}
diff --git a/src/badge_ipc.c b/src/badge_ipc.c
deleted file mode 100644 (file)
index 372753e..0000000
+++ /dev/null
@@ -1,865 +0,0 @@
-/*
- * Copyright (c) 2000 - 2017 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 <stdlib.h>
-#include <stdarg.h>
-#include <gio/gio.h>
-#include <unistd.h>
-
-#include <vconf.h>
-
-#include "badge.h"
-#include "badge_log.h"
-#include "badge_error.h"
-#include "badge_internal.h"
-#include "badge_ipc.h"
-#include "badge_setting.h"
-
-#define PROVIDER_BUS_NAME "org.tizen.data_provider_service"
-#define PROVIDER_OBJECT_PATH "/org/tizen/data_provider_service"
-#define PROVIDER_BADGE_INTERFACE_NAME "org.tizen.data_provider_badge_service"
-
-#define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
-#define DBUS_PATH_DBUS "/org/freedesktop/DBus"
-#define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
-
-typedef struct _task_list task_list;
-struct _task_list {
-       task_list *prev;
-       task_list *next;
-
-       void (*task_cb)(void *data);
-       void *data;
-};
-static task_list *g_task_list;
-
-static GDBusConnection *_gdbus_conn = NULL;
-static int monitor_id = 0;
-static int provider_monitor_id = 0;
-static int is_master_started = 0;
-
-static void _do_deferred_task(void);
-
-int badge_ipc_is_master_ready(void)
-{
-       GVariant *result = NULL;
-       GError *err = NULL;
-       gboolean name_exist;
-
-       result = g_dbus_connection_call_sync(
-                       _gdbus_conn,
-                       DBUS_SERVICE_DBUS,
-                       DBUS_PATH_DBUS,
-                       DBUS_INTERFACE_DBUS,
-                       "NameHasOwner",
-                       g_variant_new("(s)", PROVIDER_BUS_NAME),
-                       G_VARIANT_TYPE("(b)"),
-                       G_DBUS_CALL_FLAGS_NONE,
-                       -1,
-                       NULL,
-                       &err);
-
-       if (err || (result == NULL)) {
-               /* LCOV_EXCL_START */
-               if (err) {
-                       ERR("No reply. error [%s]", err->message);
-                       g_error_free(err);
-               }
-               is_master_started = 0;
-               /* LCOV_EXCL_STOP */
-       } else {
-               g_variant_get(result, "(b)", &name_exist);
-
-               if (!name_exist) {
-                       /* LCOV_EXCL_START */
-                       ERR("Name not exist [%s]", PROVIDER_BUS_NAME);
-                       ERR("the master has been stopped");
-                       is_master_started = 0;
-                       /* LCOV_EXCL_STOP */
-               } else {
-                       DBG("the master has been started");
-                       is_master_started = 1;
-               }
-       }
-
-       if (result)
-               g_variant_unref(result);
-
-       return is_master_started;
-}
-
-int badge_ipc_add_deferred_task(
-               void (*badge_add_deferred_task)(void *data),
-               void *user_data)
-{
-       task_list *list;
-       task_list *list_new;
-
-       list_new = (task_list *) malloc(sizeof(task_list));
-       if (list_new == NULL)
-               return BADGE_ERROR_OUT_OF_MEMORY;
-
-       list_new->next = NULL;
-       list_new->prev = NULL;
-
-       list_new->task_cb = badge_add_deferred_task;
-       list_new->data = user_data;
-
-       if (g_task_list == NULL) {
-               g_task_list = list_new;
-       } else {
-               list = g_task_list;
-
-               while (list->next != NULL)
-                       list = list->next;
-
-               list->next = list_new;
-               list_new->prev = list;
-       }
-       return BADGE_ERROR_NONE;
-}
-
-int badge_ipc_del_deferred_task(
-               void (*badge_add_deferred_task)(void *data))
-{
-       task_list *list_del;
-       task_list *list_prev;
-       task_list *list_next;
-
-       list_del = g_task_list;
-
-       if (list_del == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       while (list_del->prev != NULL)
-               list_del = list_del->prev;
-
-       do {
-               if (list_del->task_cb == badge_add_deferred_task) {
-                       list_prev = list_del->prev;
-                       list_next = list_del->next;
-
-                       if (list_prev == NULL)
-                               g_task_list = list_next;
-                       else
-                               list_prev->next = list_next;
-
-                       if (list_next == NULL) {
-                               if (list_prev != NULL)
-                                       list_prev->next = NULL;
-
-                       } else {
-                               list_next->prev = list_prev;
-                       }
-
-                       free(list_del);
-                       return BADGE_ERROR_NONE;
-               }
-               list_del = list_del->next;
-       } while (list_del != NULL);
-
-       return BADGE_ERROR_INVALID_PARAMETER;
-}
-
-/* LCOV_EXCL_START */
-static void _do_deferred_task(void)
-{
-       task_list *list_do;
-       task_list *list_temp;
-
-       if (g_task_list == NULL)
-               return;
-
-       list_do = g_task_list;
-       g_task_list = NULL;
-
-       while (list_do->prev != NULL)
-               list_do = list_do->prev;
-
-       while (list_do != NULL) {
-               if (list_do->task_cb != NULL) {
-                       list_do->task_cb(list_do->data);
-                       DBG("called:%p", list_do->task_cb);
-               }
-               list_temp = list_do->next;
-               free(list_do);
-               list_do = list_temp;
-       }
-}
-/* LCOV_EXCL_STOP */
-
-/*
- * dbus handler implementation
- */
-/* LCOV_EXCL_START */
-static void _insert_badge_notify(GVariant *parameters)
-{
-       char *pkgname = NULL;
-       uid_t uid;
-
-       g_variant_get(parameters, "(&si)", &pkgname, &uid);
-       badge_changed_cb_call(BADGE_ACTION_CREATE, pkgname, 0, uid);
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static void _delete_badge_notify(GVariant *parameters)
-{
-       char *pkgname = NULL;
-       uid_t uid;
-
-       g_variant_get(parameters, "(&si)", &pkgname, &uid);
-       badge_changed_cb_call(BADGE_ACTION_REMOVE, pkgname, 0, uid);
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static void _set_badge_count_notify(GVariant *parameters)
-{
-       char *pkgname = NULL;
-       int count = 0;
-       uid_t uid;
-
-       g_variant_get(parameters, "(&sii)", &pkgname, &count, &uid);
-       badge_changed_cb_call(BADGE_ACTION_UPDATE, pkgname, count, uid);
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static void _set_disp_option_notify(GVariant *parameters)
-{
-       char *pkgname = NULL;
-       int is_display = 0;
-       uid_t uid;
-
-       g_variant_get(parameters, "(&sii)", &pkgname, &is_display, &uid);
-       badge_changed_cb_call(BADGE_ACTION_CHANGED_DISPLAY, pkgname, is_display, uid);
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static void _handle_badge_notify(GDBusConnection *connection,
-               const gchar     *sender_name,
-               const gchar     *object_path,
-               const gchar     *interface_name,
-               const gchar     *signal_name,
-               GVariant        *parameters,
-               gpointer         user_data)
-{
-       DBG("signal_name: %s", signal_name);
-       if (g_strcmp0(signal_name, "insert_badge_notify") == 0)
-               _insert_badge_notify(parameters);
-       else if (g_strcmp0(signal_name, "delete_badge_notify") == 0)
-               _delete_badge_notify(parameters);
-       else if (g_strcmp0(signal_name, "set_badge_count_notify") == 0)
-               _set_badge_count_notify(parameters);
-       else if (g_strcmp0(signal_name, "set_disp_option_notify") == 0)
-               _set_disp_option_notify(parameters);
-}
-/* LCOV_EXCL_STOP */
-
-static int _dbus_init(void)
-{
-       GError *error = NULL;
-
-       if (_gdbus_conn == NULL) {
-               _gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
-               if (_gdbus_conn == NULL) {
-                       /* LCOV_EXCL_START */
-                       if (error != NULL) {
-                               ERR("Failed to get dbus [%s]", error->message);
-                               g_error_free(error);
-                       }
-                       /* LCOV_EXCL_STOP */
-                       return BADGE_ERROR_IO_ERROR;
-               }
-               badge_error_quark();
-       }
-
-       return BADGE_ERROR_NONE;
-}
-
-static int _dbus_signal_init(void)
-{
-       int ret = BADGE_ERROR_NONE;
-       int id;
-
-       if (monitor_id == 0) {
-               DBG("get dbus connection success");
-               id = g_dbus_connection_signal_subscribe(_gdbus_conn,
-                               PROVIDER_BUS_NAME,
-                               PROVIDER_BADGE_INTERFACE_NAME,  /*   interface */
-                               NULL,                           /*   member */
-                               PROVIDER_OBJECT_PATH,           /*   path */
-                               NULL,                           /*   arg0 */
-                               G_DBUS_SIGNAL_FLAGS_NONE,
-                               _handle_badge_notify,
-                               NULL,
-                               NULL);
-
-               DBG("subscribe id : %d", id);
-               if (id == 0) {
-                       /* LCOV_EXCL_START */
-                       ret = BADGE_ERROR_IO_ERROR;
-                       ERR("Failed to _register_noti_dbus_interface");
-                       /* LCOV_EXCL_STOP */
-               } else {
-                       monitor_id = id;
-               }
-       }
-
-       return ret;
-}
-
-/*
- * implement user request
- */
-static int _send_sync_badge(GVariant *body, GDBusMessage **reply, char *cmd)
-{
-       GError *err = NULL;
-       GDBusMessage *msg;
-       int ret = BADGE_ERROR_NONE;
-
-       msg = g_dbus_message_new_method_call(
-                       PROVIDER_BUS_NAME,
-                       PROVIDER_OBJECT_PATH,
-                       PROVIDER_BADGE_INTERFACE_NAME,
-                       cmd);
-       if (!msg) {
-               /* LCOV_EXCL_START */
-               ERR("Can't allocate new method call");
-               if (body)
-                       g_variant_unref(body);
-               return BADGE_ERROR_OUT_OF_MEMORY;
-               /* LCOV_EXCL_STOP */
-       }
-
-       if (body != NULL)
-               g_dbus_message_set_body(msg, body);
-
-       *reply = g_dbus_connection_send_message_with_reply_sync(
-                       _gdbus_conn,
-                       msg,
-                       G_DBUS_SEND_MESSAGE_FLAGS_NONE,
-                       -1,
-                       NULL,
-                       NULL,
-                       &err);
-
-       g_object_unref(msg);
-
-       if (!*reply) {
-               /* LCOV_EXCL_START */
-               ret = BADGE_ERROR_SERVICE_NOT_READY;
-               if (err != NULL) {
-                       ERR("No reply. cmd = %s,  error = %s", cmd, err->message);
-                       if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
-                               ret = BADGE_ERROR_PERMISSION_DENIED;
-                       g_error_free(err);
-               }
-               return ret;
-               /* LCOV_EXCL_STOP */
-       }
-
-       if (g_dbus_message_to_gerror(*reply, &err)) {
-               ret = err->code;
-               ERR("_send_sync_badge cmd = %s, error %s", cmd, err->message);
-               if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
-                       ret = BADGE_ERROR_PERMISSION_DENIED;
-               g_error_free(err);
-               return ret;
-       }
-       DBG("_send_sync_badge done !!");
-       return BADGE_ERROR_NONE;
-}
-
-static int _send_service_register(uid_t uid)
-{
-       GDBusMessage *reply = NULL;
-       int result;
-
-       result = _send_sync_badge(g_variant_new("(i)", uid), &reply, "badge_service_register");
-
-       if (reply)
-               g_object_unref(reply);
-
-       DBG("_send_service_register dones");
-       return result;
-}
-
-static int _ipc_monitor_register(uid_t uid)
-{
-       DBG("register a service");
-
-       return  _send_service_register(uid);
-}
-
-/* LCOV_EXCL_START */
-static void _on_name_appeared(GDBusConnection *connection,
-               const gchar     *name,
-               const gchar     *name_owner,
-               gpointer         user_data)
-{
-       DBG("name appeared : %s", name);
-       is_master_started = 1;
-       _ipc_monitor_register(GPOINTER_TO_INT(user_data));
-
-       _do_deferred_task();
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-static void _on_name_vanished(GDBusConnection *connection,
-               const gchar     *name,
-               gpointer         user_data)
-{
-       DBG("name vanished : %s", name);
-       is_master_started = 0;
-}
-/* LCOV_EXCL_STOP */
-
-int badge_ipc_monitor_init(uid_t uid)
-{
-       DBG("register a service");
-       int ret = BADGE_ERROR_NONE;
-
-       ret = _dbus_init();
-       if (ret != BADGE_ERROR_NONE) {
-               /* LCOV_EXCL_START */
-               ERR("Can't init dbus [%d]", ret);
-               return ret;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = _dbus_signal_init();
-       if (ret != BADGE_ERROR_NONE) {
-               /* LCOV_EXCL_START */
-               ERR("Can't init dbus signal [%d]", ret);
-               return ret;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = _ipc_monitor_register(uid);
-       if (ret != BADGE_ERROR_NONE) {
-               /* LCOV_EXCL_START */
-               ERR("Can't init ipc_monitor_register [%d]", ret);
-               return ret;
-               /* LCOV_EXCL_STOP */
-       }
-
-       if (provider_monitor_id == 0) {
-               provider_monitor_id = g_bus_watch_name_on_connection(
-                               _gdbus_conn,
-                               PROVIDER_BUS_NAME,
-                               G_BUS_NAME_WATCHER_FLAGS_NONE,
-                               _on_name_appeared,
-                               _on_name_vanished,
-                               GINT_TO_POINTER((int)uid),
-                               NULL);
-
-               if (provider_monitor_id == 0) {
-                       /* LCOV_EXCL_START */
-                       ERR("watch on name failed");
-                       g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
-                       monitor_id = 0;
-                       return BADGE_ERROR_IO_ERROR;
-                       /* LCOV_EXCL_STOP */
-               }
-       }
-
-       return ret;
-}
-
-int badge_ipc_monitor_fini(void)
-{
-       if (provider_monitor_id) {
-               g_bus_unwatch_name(provider_monitor_id);
-               provider_monitor_id = 0;
-       }
-
-       if (monitor_id) {
-               g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
-               monitor_id = 0;
-       }
-       return BADGE_ERROR_NONE;
-}
-
-int badge_ipc_request_is_existing(const char *pkgname, bool *existing, uid_t uid)
-{
-       int result;
-       GDBusMessage *reply = NULL;
-       GVariant *body;
-       GVariant *reply_body;
-       int ret_existing;
-
-       result = _dbus_init();
-       if (result != BADGE_ERROR_NONE) {
-               ERR("Can't init dbus [%d]", result);
-               return result;
-       }
-       body = g_variant_new("(si)", pkgname, uid);
-
-       result = _send_sync_badge(body, &reply, "get_badge_existing");
-       if (result == BADGE_ERROR_NONE) {
-               reply_body = g_dbus_message_get_body(reply);
-               g_variant_get(reply_body, "(i)", &ret_existing);
-               *existing = ret_existing;
-       }
-
-       if (reply)
-               g_object_unref(reply);
-
-       DBG("badge_ipc_request_is_existing done [%d]", result);
-       return result;
-}
-
-int badge_ipc_request_get_list(badge_foreach_cb callback, void *data, uid_t uid)
-{
-       GDBusMessage *reply = NULL;
-       int result;
-       GVariant *reply_body;
-       GVariant *iter_body;
-       GVariant *body;
-       GVariantIter *iter;
-       badge_info_s badge;
-
-       result = _dbus_init();
-       if (result != BADGE_ERROR_NONE) {
-               ERR("Can't init dbus [%d]", result);
-               return result;
-       }
-
-       body = g_variant_new("(i)", uid);
-       if (!body) {
-               ERR("Can't create gvariant. Out of memory.");
-               return BADGE_ERROR_OUT_OF_MEMORY;
-       }
-
-       result = _send_sync_badge(body, &reply, "get_list");
-       if (result == BADGE_ERROR_NONE) {
-               reply_body = g_dbus_message_get_body(reply);
-               g_variant_get(reply_body, "(a(v))", &iter);
-               while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
-                       g_variant_get(iter_body, "(&si)", &badge.pkg, &badge.badge_count);
-                       DBG("call calback : %s", badge.pkg);
-                       callback(badge.pkg, badge.badge_count, data);
-               }
-               g_variant_iter_free(iter);
-       }
-
-       if (reply)
-               g_object_unref(reply);
-
-       return result;
-}
-
-int badge_ipc_request_insert(const char *pkgname, const char *writable_pkg, const char *caller, uid_t uid)
-{
-       int result;
-       GDBusMessage *reply = NULL;
-       GVariant *body;
-
-       result = _dbus_init();
-       if (result != BADGE_ERROR_NONE) {
-               ERR("Can't init dbus [%d]", result);
-               return result;
-       }
-
-       body = g_variant_new("(sssi)", pkgname, writable_pkg, caller, uid);
-       if (!body) {
-               ERR("Can't create gvariant. Out of memory.");
-               return BADGE_ERROR_OUT_OF_MEMORY;
-       }
-
-       result = _send_sync_badge(body, &reply, "insert_badge");
-
-       if (reply)
-               g_object_unref(reply);
-
-       DBG("badge_ipc_request_insert done [%d]", result);
-       return result;
-}
-
-int badge_ipc_request_delete(const char *pkgname, const char *caller, uid_t uid)
-{
-       int result;
-       GDBusMessage *reply = NULL;
-       GVariant *body;
-
-       result = _dbus_init();
-       if (result != BADGE_ERROR_NONE) {
-               ERR("Can't init dbus [%d]", result);
-               return result;
-       }
-
-       body = g_variant_new("(ssi)", pkgname, caller, uid);
-       if (!body) {
-               ERR("Can't create gvariant. Out of memory.");
-               return BADGE_ERROR_OUT_OF_MEMORY;
-       }
-
-       result = _send_sync_badge(body, &reply, "delete_badge");
-
-       if (reply)
-               g_object_unref(reply);
-
-       DBG("badge_ipc_request_delete done [%d]", result);
-       return result;
-}
-
-int badge_ipc_request_set_count(const char *pkgname, const char *caller, int count, uid_t uid)
-{
-       int result;
-       GDBusMessage *reply = NULL;
-       GVariant *body;
-
-       result = _dbus_init();
-       if (result != BADGE_ERROR_NONE) {
-               ERR("Can't init dbus [%d]", result);
-               return result;
-       }
-
-       body = g_variant_new("(ssii)", pkgname, caller, count, uid);
-       if (!body) {
-               ERR("Can't create gvariant. Out of memory.");
-               return BADGE_ERROR_OUT_OF_MEMORY;
-       }
-
-       result = _send_sync_badge(body, &reply, "set_badge_count");
-
-       if (reply)
-               g_object_unref(reply);
-
-       DBG("badge_ipc_request_set_count done [%d]", result);
-       return result;
-}
-
-int badge_ipc_request_get_count(const char *pkgname, unsigned int *count, uid_t uid)
-{
-       int result;
-       GDBusMessage *reply = NULL;
-       GVariant *body;
-       GVariant *reply_body;
-       int ret_count;
-
-       result = _dbus_init();
-       if (result != BADGE_ERROR_NONE) {
-               ERR("Can't init dbus [%d]", result);
-               return result;
-       }
-
-       body = g_variant_new("(si)", pkgname, uid);
-       if (!body) {
-               ERR("Can't create gvariant. Out of memory.");
-               return BADGE_ERROR_OUT_OF_MEMORY;
-       }
-
-       result = _send_sync_badge(body, &reply, "get_badge_count");
-       if (result == BADGE_ERROR_NONE) {
-               reply_body = g_dbus_message_get_body(reply);
-               g_variant_get(reply_body, "(i)", &ret_count);
-               *count = ret_count;
-       }
-
-       if (reply)
-               g_object_unref(reply);
-
-       DBG("badge_ipc_request_get_count done [%d]", result);
-       return result;
-}
-
-int badge_ipc_request_set_display(const char *pkgname, const char *caller,
-                                 unsigned int display_option, uid_t uid)
-{
-       int result;
-       GDBusMessage *reply = NULL;
-       GVariant *body;
-
-       result = _dbus_init();
-       if (result != BADGE_ERROR_NONE) {
-               ERR("Can't init dbus [%d]", result);
-               return result;
-       }
-       body = g_variant_new("(ssii)", pkgname, caller, display_option, uid);
-       if (!body) {
-               ERR("Can't create gvariant. Out of memory.");
-               return BADGE_ERROR_OUT_OF_MEMORY;
-       }
-
-       result = _send_sync_badge(body, &reply, "set_disp_option");
-       if (reply)
-               g_object_unref(reply);
-
-       DBG("badge_ipc_request_set_display done [%d]", result);
-       return result;
-}
-
-int badge_ipc_request_get_display(const char *pkgname, unsigned int *is_display, uid_t uid)
-{
-       int result;
-       GDBusMessage *reply = NULL;
-       GVariant *body;
-       GVariant *reply_body;
-       unsigned int ret_is_display;
-
-       result = _dbus_init();
-       if (result != BADGE_ERROR_NONE) {
-               ERR("Can't init dbus [%d]", result);
-               return result;
-       }
-
-       body = g_variant_new("(si)", pkgname, uid);
-       if (!body) {
-               ERR("Can't create gvariant. Out of memory.");
-               return BADGE_ERROR_OUT_OF_MEMORY;
-       }
-
-       result = _send_sync_badge(body, &reply, "get_disp_option");
-       if (result == BADGE_ERROR_NONE) {
-               reply_body = g_dbus_message_get_body(reply);
-               g_variant_get(reply_body, "(i)", &ret_is_display);
-               *is_display = ret_is_display;
-       }
-
-       if (reply)
-               g_object_unref(reply);
-
-       DBG("badge_ipc_request_get_display done [%d]", result);
-       return result;
-}
-
-int badge_ipc_request_update_setting(badge_setting_h setting, uid_t uid)
-{
-       int ret;
-       GDBusMessage *reply = NULL;
-       GVariant *body = NULL;
-
-       ret = _dbus_init();
-       if (ret != BADGE_ERROR_NONE) {
-               ERR("Can't init dbus [%d]", ret);
-               return ret;
-       }
-
-       body = g_variant_new("(ssii)",
-                            setting->pkgname,
-                            setting->appid,
-                            (int)(setting->allow_to_display),
-                            uid);
-
-       ret = _send_sync_badge(body, &reply, "update_badge_setting");
-       if (ret != BADGE_ERROR_NONE)
-               ERR("Failed badge update setting");
-
-       if (reply)
-               g_object_unref(reply);
-
-       return ret;
-}
-
-int badge_ipc_request_get_setting_by_appid(badge_setting_h *setting, const char *appid, uid_t uid)
-{
-       int ret;
-       GDBusMessage *reply = NULL;
-       GVariant *body = NULL;
-       GVariant *reply_body = NULL;
-       GVariant *setting_body = NULL;
-       badge_setting_h result_setting;
-
-       ret = _dbus_init();
-       if (ret != BADGE_ERROR_NONE) {
-               ERR("Can't init dbus [%d]", ret);
-               return ret;
-       }
-
-       body = g_variant_new("(si)", appid, uid);
-
-       ret = _send_sync_badge(body, &reply, "get_setting_by_appid");
-       if (ret == BADGE_ERROR_NONE) {
-               reply_body = g_dbus_message_get_body(reply);
-               g_variant_get(reply_body, "(v)", &setting_body);
-
-               result_setting = (struct badge_setting *)malloc(sizeof(struct badge_setting));
-               if (result_setting == NULL) {
-                       /* LCOV_EXCL_START */
-                       ERR("Failed memory allocation.");
-                       g_object_unref(reply);
-                       return BADGE_ERROR_OUT_OF_MEMORY;
-                       /* LCOV_EXCL_STOP */
-               }
-               badge_ipc_make_setting_from_gvariant(result_setting, setting_body);
-               *setting = result_setting;
-               g_variant_unref(setting_body);
-       }
-
-       if (reply)
-               g_object_ref(reply);
-
-       return ret;
-}
-
-EXPORT_API int badge_ipc_make_setting_from_gvariant(badge_setting_h setting, GVariant *variant)
-{
-       char *pkgname;
-       char *appid;
-       int allow_to_display;
-
-       if (setting == NULL || variant == NULL) {
-               DBG("Invalid Parameter");
-               return BADGE_ERROR_INVALID_PARAMETER;
-       }
-
-       g_variant_get(variant, "(&s&si)", &pkgname, &appid, &allow_to_display);
-
-       setting->pkgname = strdup(pkgname);
-       setting->appid = strdup(appid);
-       setting->allow_to_display = allow_to_display;
-
-       return BADGE_ERROR_NONE;
-}
-
-EXPORT_API GVariant *badge_ipc_make_gvariant_from_setting(badge_setting_h setting)
-{
-       GVariant *body = NULL;
-
-       body = g_variant_new("(ssi)",
-                            setting->pkgname,
-                            setting->appid,
-                            setting->allow_to_display);
-
-       return body;
-}
-
-int badge_ipc_init_badge(uid_t uid)
-{
-       int ret;
-       GDBusMessage *reply = NULL;
-       GVariant *body;
-
-       body = g_variant_new("(i)", uid);
-       if (!body) {
-               ERR("Can't create gvariant.");
-               return BADGE_ERROR_OUT_OF_MEMORY;
-       }
-
-       ret = _send_sync_badge(body, &reply, "init_badge");
-
-       if (reply)
-               g_object_unref(reply);
-
-       DBG("badge_ipc_init_badge done[%d]", ret);
-       return ret;
-}
diff --git a/src/badge_setting.c b/src/badge_setting.c
deleted file mode 100644 (file)
index 51fa016..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (c) 2016 - 2017 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 <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "badge_log.h"
-#include "badge_error.h"
-#include "badge_setting.h"
-#include "badge_ipc.h"
-
-EXPORT_API int badge_setting_get_pkgname(badge_setting_h setting, char **pkgname)
-{
-       if (setting == NULL || pkgname == NULL) {
-               ERR("Invalid Parameter");
-               return BADGE_ERROR_INVALID_PARAMETER;
-       }
-
-       if (setting->pkgname == NULL) {
-               ERR("setting->pkgname is null");
-               return BADGE_ERROR_NOT_EXIST;
-       }
-
-       *pkgname = strdup(setting->pkgname);
-
-       return BADGE_ERROR_NONE;
-}
-
-EXPORT_API int badge_setting_get_appid(badge_setting_h setting, char **appid)
-{
-       if (setting == NULL || appid == NULL) {
-               ERR("Invalid Parameter");
-               return BADGE_ERROR_INVALID_PARAMETER;
-       }
-
-       if (setting->appid == NULL) {
-               ERR("setting->appid is null");
-               return BADGE_ERROR_NOT_EXIST;
-       }
-
-       *appid = strdup(setting->appid);
-
-       return BADGE_ERROR_NONE;
-}
-
-EXPORT_API int badge_setting_set_allow_to_display(badge_setting_h setting, bool value)
-{
-       if (setting == NULL) {
-               ERR("Invalid Parameter");
-               return BADGE_ERROR_INVALID_PARAMETER;
-       }
-
-       setting->allow_to_display = value;
-       return BADGE_ERROR_NONE;
-}
-
-EXPORT_API int badge_setting_get_allow_to_display(badge_setting_h setting, bool *value)
-{
-       if (setting == NULL || value == NULL) {
-               ERR("Invalid Parameter");
-               return BADGE_ERROR_INVALID_PARAMETER;
-       }
-
-       *value = setting->allow_to_display;
-       return BADGE_ERROR_NONE;
-}
-
-EXPORT_API int badge_setting_update_setting_for_uid(badge_setting_h setting, uid_t uid)
-{
-       return badge_ipc_request_update_setting(setting, uid);
-}
-
-EXPORT_API int badge_setting_update_setting(badge_setting_h setting)
-{
-       if (setting == NULL) {
-               ERR("Invalid Parameter");
-               return BADGE_ERROR_INVALID_PARAMETER;
-       }
-       return badge_setting_update_setting_for_uid(setting, getuid());
-}
-
-EXPORT_API int badge_setting_get_setting_by_appid_for_uid(badge_setting_h *setting, const char *appid, uid_t uid)
-{
-       return badge_ipc_request_get_setting_by_appid(setting, appid, uid);
-}
-
-EXPORT_API int badge_setting_get_setting_by_appid(badge_setting_h *setting, const char *appid)
-{
-       if (setting == NULL || appid == NULL) {
-               ERR("Invalid Parameter");
-               return BADGE_ERROR_INVALID_PARAMETER;
-       }
-
-       return badge_setting_get_setting_by_appid_for_uid(setting, appid, getuid());
-}
-
-EXPORT_API int badge_setting_free_setting(badge_setting_h setting)
-{
-       if (setting == NULL) {
-               ERR("Invalid Parameter");
-               return BADGE_ERROR_INVALID_PARAMETER;
-       }
-
-       if (setting->pkgname)
-               free(setting->pkgname);
-       if (setting->appid)
-               free(setting->appid);
-       free(setting);
-       setting = NULL;
-
-       return BADGE_ERROR_NONE;
-}
diff --git a/src/badge_setting_service.c b/src/badge_setting_service.c
deleted file mode 100644 (file)
index 66e7001..0000000
+++ /dev/null
@@ -1,933 +0,0 @@
-/*
- * Copyright (c) 2016 - 2017 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 <sqlite3.h>
-#include <db-util.h>
-#include <gio/gio.h>
-#include <string.h>
-#include <pkgmgr-info.h>
-#include <package_manager.h>
-
-#include "badge_setting.h"
-#include "badge_setting_service.h"
-#include "badge_db.h"
-#include "badge_error.h"
-#include "badge_log.h"
-
-#define BADGE_PRIVILEGE "http://tizen.org/privilege/notification"
-
-#define BAGDE_ALLOW_TO_DISPLAY_BIT 0x1
-#define BAGDE_APP_DISABLE_BIT 0x2
-
-#define BAGDE_APP_ENABLE 0x0
-#define BAGDE_APP_DISABLE 0x2
-
-#define BAGDE_NOT_ALLOW_TO_DISPLAY 0x0
-#define BAGDE_ALLOW_TO_DISPLAY 0x1
-
-typedef struct {
-       uid_t uid;
-       sqlite3 *db;
-} badge_setting_info;
-
-static bool _get_table_field_data_int(char **table, int *buf, int index)
-{
-       if (table == NULL || buf == NULL || index < 0) {
-               /* LCOV_EXCL_START */
-               ERR("table[%p], buf[%p], index[%d]", table, buf, index);
-               return false;
-               /* LCOV_EXCL_STOP */
-       }
-
-       if (table[index] != NULL) {
-               *buf = atoi(table[index]);
-               return true;
-       }
-
-       /* LCOV_EXCL_START */
-       *buf = 0;
-       return false;
-       /* LCOV_EXCL_STOP */
-}
-
-static bool _get_table_field_data_string(char **table, char **buf, int ucs2, int index)
-{
-       bool ret = false;
-       int sLen = 0;
-       char *pTemp;
-
-       if (table == NULL || buf == NULL || index < 0) {
-               /* LCOV_EXCL_START */
-               ERR("table[%p], buf[%p], index[%d]", table, buf, index);
-               return false;
-               /* LCOV_EXCL_STOP */
-       }
-
-       pTemp = table[index];
-       if (pTemp == NULL) {
-               *buf = NULL; /* LCOV_EXCL_LINE */
-       } else {
-               sLen = strlen(pTemp);
-               if (sLen) {
-                       *buf = (char *)malloc(sLen + 1);
-                       if (*buf == NULL) {
-                               ERR("malloc is failed"); /* LCOV_EXCL_LINE */
-                               goto out;
-                       }
-                       memset(*buf, 0, sLen + 1);
-                       strncpy(*buf, pTemp, sLen + 1);
-               } else {
-                       *buf = NULL; /* LCOV_EXCL_LINE */
-               }
-       }
-
-       ret = true;
-
-out:
-       return ret;
-}
-
-EXPORT_API int badge_db_get_setting_by_appid(const char *appid, badge_setting_h *setting, uid_t uid)
-{
-       int ret = BADGE_ERROR_NONE;
-       int sql_ret;
-       int row_count;
-       int col_count;
-       int col_index;
-       char *sql_query = NULL;
-       char **query_result = NULL;
-       badge_setting_h result_setting;
-       sqlite3 *db = NULL;
-       int atd;
-
-       if (appid == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       sql_ret = db_util_open(BADGE_DB_PATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               /* LCOV_EXCL_START */
-               ERR("Failed db util open [%s][%d]", BADGE_DB_PATH, sql_ret);
-               return BADGE_ERROR_FROM_DB;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sql_query = sqlite3_mprintf("SELECT pkgname, appid, allow_to_display FROM %s " \
-                               "WHERE appid = %Q AND (uid = %d OR uid = %d) " \
-                               "ORDER BY uid DESC;",
-                               BADGE_SETTING_DB_TABLE, appid, uid, tzplatform_getuid(TZ_SYS_GLOBALAPP_USER));
-       if (!sql_query) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sql_ret = sqlite3_get_table(db, sql_query, &query_result, &row_count, &col_count, NULL);
-       if (sql_ret != SQLITE_OK && sql_ret != -1) {
-               /* LCOV_EXCL_START */
-               ERR("sqlite3_get_table failed [%d][%s]", sql_ret,
-                                       sqlite3_errmsg(db));
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       if (!row_count) {
-               /* LCOV_EXCL_START */
-               DBG("No setting found for [%s]", appid);
-               ret = BADGE_ERROR_NOT_EXIST;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       result_setting = (struct badge_setting *)malloc(sizeof(struct badge_setting));
-       if (result_setting == NULL) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc setting");
-               ret = BADGE_ERROR_OUT_OF_MEMORY;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       col_index = col_count;
-
-       _get_table_field_data_string(query_result, &(result_setting[0].pkgname), 1, col_index++);
-       _get_table_field_data_string(query_result, &(result_setting[0].appid), 1, col_index++);
-       if (_get_table_field_data_int(query_result, &atd, col_index++)) {
-               if (atd & BAGDE_APP_DISABLE_BIT)
-                       result_setting[0].allow_to_display = BAGDE_NOT_ALLOW_TO_DISPLAY;
-               else if (atd & BAGDE_ALLOW_TO_DISPLAY_BIT)
-                       result_setting[0].allow_to_display = BAGDE_ALLOW_TO_DISPLAY;
-               else
-                       result_setting[0].allow_to_display = BAGDE_NOT_ALLOW_TO_DISPLAY;
-       } else {
-               result_setting[0].allow_to_display = BAGDE_NOT_ALLOW_TO_DISPLAY;
-       }
-
-       *setting = result_setting;
-
-out:
-       if (query_result)
-               sqlite3_free_table(query_result);
-       if (sql_query)
-               sqlite3_free(sql_query);
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       WARN("Failed to db_util_close");
-       }
-
-       return ret;
-}
-
-EXPORT_API int badge_db_update_setting(char *pkgname, char *appid, int allow_to_display, uid_t uid)
-{
-       int ret = BADGE_ERROR_NONE;
-       sqlite3 *db = NULL;
-       char *sqlbuf = NULL;
-       int sql_ret;
-
-       if (pkgname == NULL || appid == NULL) {
-               ERR("Invalid package name or app id");
-               return BADGE_ERROR_INVALID_PARAMETER;
-       }
-
-       sql_ret = db_util_open(BADGE_DB_PATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               /* LCOV_EXCL_START */
-               ERR("db_util_open failed [%s][%d]", BADGE_DB_PATH, sql_ret);
-               return BADGE_ERROR_FROM_DB;
-               /* LCOV_EXCL_STOP */
-       }
-
-       /* Only the first bit is updated.
-               (The first bit indicates allow information, and the second bit indicates app disable information.)
-       */
-       sqlbuf = sqlite3_mprintf("UPDATE %s SET allow_to_display = (allow_to_display & ~%d ) | %d " \
-                               "WHERE pkgname = %Q AND appid = %Q " \
-                               "AND uid = %d;",
-                               BADGE_SETTING_DB_TABLE, BAGDE_ALLOW_TO_DISPLAY_BIT, allow_to_display,
-                               pkgname, appid, uid);
-
-       if (!sqlbuf) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = badge_db_exec(db, sqlbuf, NULL);
-
-out:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       WARN("Failed to db_util_close");
-       }
-
-       return ret;
-}
-
-EXPORT_API int badge_db_get_allow_to_display_by_appid(char *appid, int *allow_to_display, uid_t uid)
-{
-       int ret = BADGE_ERROR_NONE;
-       int sql_ret;
-       int row_count;
-       int col_count;
-       int col_index;
-       char *sql_query = NULL;
-       char **query_result = NULL;
-       sqlite3 *db = NULL;
-       int atd;
-
-       if (appid == NULL)
-               return BADGE_ERROR_INVALID_PARAMETER;
-
-       sql_ret = db_util_open(BADGE_DB_PATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               /* LCOV_EXCL_START */
-               ERR("Failed db util open [%s][%d]", BADGE_DB_PATH, sql_ret);
-               return BADGE_ERROR_FROM_DB;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sql_query = sqlite3_mprintf("SELECT allow_to_display FROM %s WHERE appid = %Q " \
-                               "AND (uid = %d OR uid = %d) ORDER BY uid DESC;",
-                               BADGE_SETTING_DB_TABLE, appid, uid,
-                               tzplatform_getuid(TZ_SYS_GLOBALAPP_USER));
-       if (!sql_query) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sql_ret = sqlite3_get_table(db, sql_query, &query_result, &row_count, &col_count, NULL);
-       if (sql_ret != SQLITE_OK && sql_ret != -1) {
-               /* LCOV_EXCL_START */
-               ERR("sqlite3_get_table failed [%d][%s]", sql_ret,
-                                       sqlite3_errmsg(db));
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       if (!row_count) {
-               /* LCOV_EXCL_START */
-               DBG("No setting found for [%s]", appid);
-               ret = BADGE_ERROR_NOT_EXIST;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       col_index = col_count;
-
-       if (_get_table_field_data_int(query_result, &atd, col_index++)) {
-               if (atd & BAGDE_APP_DISABLE_BIT)
-                       *allow_to_display = BAGDE_NOT_ALLOW_TO_DISPLAY;
-               else if (atd & BAGDE_ALLOW_TO_DISPLAY_BIT)
-                       *allow_to_display = BAGDE_ALLOW_TO_DISPLAY;
-               else
-                       *allow_to_display = BAGDE_NOT_ALLOW_TO_DISPLAY;
-       } else {
-               *allow_to_display = BAGDE_NOT_ALLOW_TO_DISPLAY;
-       }
-
-out:
-       if (query_result)
-               sqlite3_free_table(query_result);
-       if (sql_query)
-               sqlite3_free(sql_query);
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       WARN("Failed to db_util_close");
-       }
-
-       return ret;
-}
-
-EXPORT_API int badge_db_update_app_disabled(const char *app_id, bool disabled, uid_t uid)
-{
-       int ret = BADGE_ERROR_NONE;
-       sqlite3 *db = NULL;
-       char *sqlbuf = NULL;
-       int sql_ret;
-       int num_changes = 0;
-       int flag;
-
-       if (app_id == NULL) {
-               ERR("Invalid app id");
-               return BADGE_ERROR_INVALID_PARAMETER;
-       }
-
-       sql_ret = db_util_open(BADGE_DB_PATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               /* LCOV_EXCL_START */
-               ERR("db_util_open failed [%s][%d]", BADGE_DB_PATH, sql_ret);
-               return BADGE_ERROR_FROM_DB;
-               /* LCOV_EXCL_STOP */
-       }
-
-       if (disabled)
-               flag = BAGDE_APP_DISABLE;
-       else
-               flag = BAGDE_APP_ENABLE;
-
-       /* Only the second bit is updated.
-               (The first bit indicates allow information, and the second bit indicates app disable information.)
-       */
-       sqlbuf = sqlite3_mprintf("UPDATE %s SET allow_to_display = (allow_to_display & ~%d ) | %d " \
-                               "WHERE appid = %Q " \
-                               "AND uid = %d;",
-                               BADGE_SETTING_DB_TABLE, BAGDE_APP_DISABLE_BIT, flag, app_id, uid);
-       if (!sqlbuf) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = badge_db_exec(db, sqlbuf, &num_changes);
-       if (ret == BADGE_ERROR_NONE && num_changes <= 0)
-               ret = BADGE_ERROR_NOT_EXIST;
-
-out:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       WARN("Failed to db_util_close");
-       }
-
-       return ret;
-}
-
-EXPORT_API int badge_db_update_pkg_disabled(const char *pkg_id, bool disabled, uid_t uid)
-{
-       int ret = BADGE_ERROR_NONE;
-       sqlite3 *db = NULL;
-       char *sqlbuf = NULL;
-       int sql_ret;
-       int num_changes = 0;
-       int flag;
-
-       if (pkg_id == NULL) {
-               ERR("Invalid pkg id");
-               return BADGE_ERROR_INVALID_PARAMETER;
-       }
-
-       sql_ret = db_util_open(BADGE_DB_PATH, &db, 0);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               /* LCOV_EXCL_START */
-               ERR("db_util_open failed [%s][%d]", BADGE_DB_PATH, sql_ret);
-               return BADGE_ERROR_FROM_DB;
-               /* LCOV_EXCL_STOP */
-       }
-
-       if (disabled)
-               flag = BAGDE_APP_DISABLE;
-       else
-               flag = BAGDE_APP_ENABLE;
-
-       /* Only the second bit is updated.
-               (The first bit indicates allow information, and the second bit indicates app disable information.)
-       */
-       sqlbuf = sqlite3_mprintf("UPDATE %s SET allow_to_display = (allow_to_display & ~%d ) | %d " \
-                               "WHERE pkgname = %Q AND uid = %d;",
-                               BADGE_SETTING_DB_TABLE, BAGDE_APP_DISABLE_BIT, flag, pkg_id, uid);
-       if (!sqlbuf) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = badge_db_exec(db, sqlbuf, &num_changes);
-       if (ret == BADGE_ERROR_NONE && num_changes <= 0)
-               ret = BADGE_ERROR_NOT_EXIST;
-
-out:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
-       if (db) {
-               sql_ret = db_util_close(db);
-               if (sql_ret != SQLITE_OK)
-                       WARN("Failed to db_util_close");
-       }
-
-       return ret;
-}
-
-EXPORT_API int badge_setting_is_existed_appid(const char *appid, bool *is_existed, uid_t uid)
-{
-       int ret = BADGE_ERROR_NONE;
-       int sqlret;
-       sqlite3 *db = NULL;
-       sqlite3_stmt *stmt = NULL;
-       char *sqlbuf = NULL;
-       int count = 0;
-
-       if (appid == NULL || is_existed == NULL) {
-               ERR("Invalid parameter");
-               return BADGE_ERROR_INVALID_PARAMETER;
-       }
-
-       sqlret = db_util_open(BADGE_DB_PATH, &db, 0);
-       if (sqlret != SQLITE_OK || !db) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to db_util_open [%d]", sqlret);
-               if (sqlret == SQLITE_PERM)
-                       return BADGE_ERROR_PERMISSION_DENIED;
-               return BADGE_ERROR_FROM_DB;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sqlbuf = sqlite3_mprintf("SELECT count(*) FROM %q WHERE " \
-                               "appid = %Q AND uid = %d",
-                               BADGE_SETTING_DB_TABLE, appid, uid);
-       if (!sqlbuf) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to alloc query");
-               ret = BADGE_ERROR_OUT_OF_MEMORY;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sqlret = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL);
-       if (sqlret != SQLITE_OK) {
-               /* LCOV_EXCL_START */
-               ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlret,
-                                       sqlite3_errmsg(db));
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sqlret = sqlite3_step(stmt);
-       if (sqlret == SQLITE_ROW)
-               count = sqlite3_column_int(stmt, 0);
-
-       if (count > 0)
-               *is_existed = true;
-       else
-               *is_existed = false;
-
-out:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
-       if (stmt)
-               sqlite3_finalize(stmt);
-       if (db) {
-               sqlret = db_util_close(db);
-               if (sqlret != SQLITE_OK)
-                       WARN("Failed to db_util_close [%d]", sqlret);
-       }
-
-       return ret;
-}
-
-static bool _is_package_in_setting_table(sqlite3 *db, const char *pkgname, const char* appid, uid_t uid)
-{
-       int sql_ret;
-       bool err = true;
-       char *query = NULL;
-       sqlite3_stmt *stmt = NULL;
-
-       if (appid != NULL)
-               query = sqlite3_mprintf("SELECT appid FROM badge_setting " \
-                               "WHERE uid = %d AND pkgname = %Q AND appid = %Q",
-                               uid, pkgname, appid);
-       else
-               query = sqlite3_mprintf("SELECT pkgname FROM badge_setting " \
-                               "WHERE uid = %d AND pkgname = %Q",
-                               uid, pkgname);
-       if (query == NULL) {
-               /* LCOV_EXCL_START */
-               ERR("Out of Memory");
-               err = false;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       sql_ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
-       if (sql_ret != SQLITE_OK) {
-               ERR("sqlite3_prepare_v2 failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
-               err = false;
-               goto out;
-       }
-
-       sql_ret = sqlite3_step(stmt);
-       if (sql_ret == SQLITE_DONE) {
-               INFO("No matched appid[%s] from pkgname[%s]", pkgname, appid);
-               err = false;
-               goto out;
-       }
-
-       if (sql_ret != SQLITE_OK && sql_ret != SQLITE_ROW) {
-               /* LCOV_EXCL_START */
-               ERR("sqlite3_step failed [%d][%s]", sql_ret,
-                               sqlite3_errmsg(db));
-               err = false;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-out:
-       if (stmt)
-               sqlite3_finalize(stmt);
-       if (query)
-               sqlite3_free(query);
-
-       return err;
-}
-
-static int app_info_callback(const pkgmgrinfo_appinfo_h handle, void *user_data)
-{
-       int ret;
-       int pkgmgr_ret;
-       char *appid = NULL;
-       char *pkgname = NULL;
-       char *query = NULL;
-       badge_setting_info *info = (badge_setting_info *)user_data;
-       sqlite3 *db = info->db;
-
-       pkgmgr_ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
-       if (pkgmgr_ret != PACKAGE_MANAGER_ERROR_NONE) {
-               ERR("pkgmgrinfo_appinfo_get_appid failed [%d]", pkgmgr_ret);
-               goto out;
-       }
-
-       pkgmgr_ret = pkgmgrinfo_appinfo_get_pkgname(handle, &pkgname);
-       if (pkgmgr_ret != PACKAGE_MANAGER_ERROR_NONE) {
-               ERR("pkgmgrinfo_appinfo_get_pkgname failed [%d]", pkgmgr_ret);
-               goto out;
-       }
-
-       if (_is_package_in_setting_table(db, pkgname, appid, info->uid) == true) {
-               INFO("uid[%d] appid[%s] is exist", info->uid, appid);
-               goto out;
-       }
-
-       query = sqlite3_mprintf("INSERT INTO badge_setting " \
-                               "(uid, pkgname, appid) VALUES (%d, %Q, %Q) ",
-                               info->uid, pkgname, appid);
-       if (query == NULL) {
-               ERR("Out of memory");
-               goto out;
-       }
-
-       ret = badge_db_exec(db, query, NULL);
-       if (ret != BADGE_ERROR_NONE) {
-               ERR("DB Error");
-               goto out;
-       }
-
-       INFO("Insert uid[%d] pkgname[%s] appid[%s]", info->uid, pkgname, appid);
-
-out:
-       if (query)
-               sqlite3_free(query);
-
-       return 0;
-}
-
-static int package_info_callback(const pkgmgrinfo_pkginfo_h package_info, void *user_data)
-{
-       char *pkgname = NULL;
-       int pkgmgr_ret = PACKAGE_MANAGER_ERROR_NONE;
-       pkgmgrinfo_appinfo_filter_h handle = NULL;
-       badge_setting_info *info = (badge_setting_info *)user_data;
-
-       pkgmgr_ret = pkgmgrinfo_pkginfo_get_pkgname(package_info, &pkgname);
-       if (pkgmgr_ret != PACKAGE_MANAGER_ERROR_NONE) {
-               ERR("package_info_get_package failed [%d]", pkgmgr_ret);
-               goto out;
-       }
-
-       pkgmgr_ret = pkgmgrinfo_appinfo_filter_create(&handle);
-       if (pkgmgr_ret != PMINFO_R_OK) {
-               /* LCOV_EXCL_START */
-               ERR("pkgmgrinfo_appinfo_filter_create failed [%d]", pkgmgr_ret);
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       pkgmgr_ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_PACKAGE, pkgname);
-       if (pkgmgr_ret != PMINFO_R_OK) {
-               /* LCOV_EXCL_START */
-               ERR("pkgmgrinfo_appinfo_filter_add_string failed [%d]",
-                                       pkgmgr_ret);
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       pkgmgr_ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_NODISPLAY, false);
-       if (pkgmgr_ret != PMINFO_R_OK) {
-               /* LCOV_EXCL_START */
-               ERR("pkgmgrinfo_appinfo_filter_add_bool failed [%d]",
-                                       pkgmgr_ret);
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       pkgmgr_ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_info_callback, info, info->uid);
-       if (pkgmgr_ret != PMINFO_R_OK) {
-               /* LCOV_EXCL_START */
-               ERR("pkgmgrinfo_pkginfo_filter_foreach_appinfo failed [%d]",
-                                       pkgmgr_ret);
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-out:
-       if (handle)
-               pkgmgrinfo_appinfo_filter_destroy(handle);
-
-       return 0;
-}
-
-EXPORT_API int badge_setting_insert_package_for_uid(const char *pkgname, uid_t uid)
-{
-       sqlite3 *db;
-       int ret = BADGE_ERROR_NONE;
-       int sqlite3_ret = SQLITE_OK;
-       int pkgmgr_ret = PACKAGE_MANAGER_ERROR_NONE;
-       badge_setting_info info;
-       pkgmgrinfo_pkginfo_filter_h handle = NULL;
-
-       sqlite3_ret = sqlite3_open_v2(BADGE_DB_PATH, &db, SQLITE_OPEN_READWRITE, NULL);
-       if (sqlite3_ret != SQLITE_OK || db == NULL) {
-               ERR("db_util_open failed [%s][%d]", BADGE_DB_PATH, sqlite3_ret);
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-       }
-
-       sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL);
-
-       pkgmgr_ret = pkgmgrinfo_pkginfo_filter_create(&handle);
-       if (pkgmgr_ret != PMINFO_R_OK) {
-               /* LCOV_EXCL_START */
-               ERR("pkgmgrinfo_pkginfo_filter_create failed [%d]", pkgmgr_ret);
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       pkgmgr_ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
-                       PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE, BADGE_PRIVILEGE);
-       if (pkgmgr_ret != PMINFO_R_OK) {
-               /* LCOV_EXCL_START */
-               ERR("Failed to add string to pkginfo_filter[%d]", pkgmgr_ret);
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       pkgmgr_ret = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgname);
-       if (pkgmgr_ret != PMINFO_R_OK) {
-               /* LCOV_EXCL_START */
-               ERR("pkgmgrinfo_pkginfo_filter_add_string failed [%d]",
-                                       pkgmgr_ret);
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       info.db = db;
-       info.uid = uid;
-       pkgmgr_ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, package_info_callback, &info, uid);
-       if (pkgmgr_ret != PMINFO_R_OK) {
-               /* LCOV_EXCL_START */
-               ERR("pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo failed [%d]",
-                                       pkgmgr_ret);
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-out:
-       if (handle)
-               pkgmgrinfo_pkginfo_filter_destroy(handle);
-       if (db) {
-               if (ret == BADGE_ERROR_NONE)
-                       sqlite3_exec(db, "END;", NULL, NULL, NULL);
-               else
-                       sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL);
-
-               if ((sqlite3_ret = db_util_close(db)) != SQLITE_OK)
-                       WARN("db_util_close failed [%d]", sqlite3_ret);
-       }
-
-       return ret;
-}
-
-EXPORT_API int badge_setting_delete_package_for_uid(const char *pkgname, uid_t uid)
-{
-       int ret = BADGE_ERROR_NONE;
-       int sql_ret;
-       sqlite3 *db = NULL;
-       bool is_package_in_setting_table = false;
-       char *query = NULL;
-
-       sql_ret = sqlite3_open_v2(BADGE_DB_PATH, &db, SQLITE_OPEN_READWRITE, NULL);
-       if (ret != SQLITE_OK || db == NULL) {
-               /* LCOV_EXCL_START */
-               ERR("db_util_open failed [%s][%d]", BADGE_DB_PATH, sql_ret);
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       is_package_in_setting_table = _is_package_in_setting_table(db, pkgname, NULL, uid);
-       if (is_package_in_setting_table == false) {
-               INFO("[%s] is not exist", pkgname);
-               goto out;
-       }
-
-       sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL);
-
-       query = sqlite3_mprintf("DELETE FROM badge_setting " \
-                               "WHERE uid = %d AND pkgname = %Q ",
-                               uid, pkgname);
-       if (query == NULL) {
-               /* LCOV_EXCL_START */
-               ERR("Out of memory");
-               ret = BADGE_ERROR_OUT_OF_MEMORY;
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-       ret = badge_db_exec(db, query, NULL);
-       if (ret != BADGE_ERROR_NONE) {
-               /* LCOV_EXCL_START */
-               ERR("DB Error");
-               goto out;
-               /* LCOV_EXCL_STOP */
-       }
-
-out:
-       if (query)
-               sqlite3_free(query);
-       if (db) {
-               if (ret == BADGE_ERROR_NONE)
-                       sqlite3_exec(db, "END;", NULL, NULL, NULL);
-               else
-                       sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL);
-
-               if ((sql_ret = db_util_close(db)) != SQLITE_OK)
-                       WARN("db_util_close failed [%d]", sql_ret);
-       }
-
-       return ret;
-}
-
-/* LCOV_EXCL_START */
-EXPORT_API int badge_setting_refresh_setting_table(uid_t uid)
-{
-       int ret = BADGE_ERROR_NONE;
-       int sql_ret;
-       int pkgmgr_ret;
-       sqlite3 *db = NULL;
-       badge_setting_info info;
-       pkgmgrinfo_appinfo_filter_h filter = NULL;
-
-       sql_ret = sqlite3_open_v2(BADGE_DB_PATH, &db, SQLITE_OPEN_READWRITE, NULL);
-       if (sql_ret != SQLITE_OK || db == NULL) {
-               ERR("sqlite3_open_v2 fail [%s][%d]", BADGE_DB_PATH, sql_ret);
-               return BADGE_ERROR_FROM_DB;
-       }
-
-       sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL);
-
-       pkgmgr_ret = pkgmgrinfo_appinfo_filter_create(&filter);
-       if (pkgmgr_ret != PMINFO_R_OK) {
-               ERR("pkgmgrinfo_appinfo_filter_create failed [%d]", pkgmgr_ret);
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-       }
-
-       pkgmgr_ret = pkgmgrinfo_appinfo_filter_add_string(filter,
-                       PMINFO_APPINFO_PROP_PRIVILEGE, BADGE_PRIVILEGE);
-       if (pkgmgr_ret != PMINFO_R_OK) {
-               ERR("pkgmgrinfo_appinfo_filter_add_string failed [%d]",
-                                       pkgmgr_ret);
-               goto out;
-       }
-
-       pkgmgr_ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
-                       PMINFO_APPINFO_PROP_APP_NODISPLAY, false);
-       if (pkgmgr_ret != PMINFO_R_OK) {
-               ERR("pkgmgrinfo_appinfo_filter_add_bool failed [%d]",
-                                       pkgmgr_ret);
-               goto out;
-       }
-
-       info.db = db;
-       info.uid = uid;
-       pkgmgr_ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(filter,
-                       app_info_callback, &info, uid);
-       if (pkgmgr_ret != PMINFO_R_OK) {
-               ERR("pkgmgrinfo_appinfo_usr_filter_foreach_appinfo failed [%d]",
-                                       pkgmgr_ret);
-               ret = BADGE_ERROR_FROM_DB;
-               goto out;
-       }
-
-out:
-       if (filter)
-               pkgmgrinfo_appinfo_filter_destroy(filter);
-       if (db) {
-               if (ret == BADGE_ERROR_NONE)
-                       sqlite3_exec(db, "END;", NULL, NULL, NULL);
-               else
-                       sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL);
-               if ((sql_ret = db_util_close(db)) != SQLITE_OK)
-                       WARN("fail to db_util_close [%d]", sql_ret);
-       }
-
-       return ret;
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
-EXPORT_API int badge_setting_arrange_tables(uid_t uid)
-{
-       int ret = BADGE_ERROR_NONE;
-       int sqlret;
-       sqlite3 *db = NULL;
-       char *sqlbuf = NULL;
-
-       sqlret = db_util_open(BADGE_DB_PATH, &db, 0);
-       if (sqlret != SQLITE_OK || !db) {
-               ERR("Failed to db_util_open [%d]", sqlret);
-               if (sqlret == SQLITE_PERM)
-                       return BADGE_ERROR_PERMISSION_DENIED;
-               return BADGE_ERROR_FROM_DB;
-       }
-
-       sqlbuf = sqlite3_mprintf("DELETE FROM %Q WHERE pkgname not in " \
-                               "(SELECT pkgname FROM %Q) AND uid = %d",
-                               BADGE_TABLE_NAME, BADGE_SETTING_DB_TABLE, uid);
-       if (sqlbuf == NULL) {
-               ERR("Failed to alloc query");
-               ret = BADGE_ERROR_OUT_OF_MEMORY;
-               goto out;
-       }
-
-       ret = badge_db_exec(db, sqlbuf, NULL);
-       if (ret != BADGE_ERROR_NONE)
-               goto out;
-
-       if (sqlbuf) {
-               sqlite3_free(sqlbuf);
-               sqlbuf = NULL;
-       }
-
-       sqlbuf = sqlite3_mprintf("DELETE FROM %Q WHERE pkgname not in " \
-                               "(SELECT pkgname FROM %Q) AND uid = %d",
-                               BADGE_OPTION_TABLE_NAME, BADGE_SETTING_DB_TABLE,
-                               uid);
-       if (sqlbuf == NULL) {
-               ERR("Failed to alloc query");
-               ret = BADGE_ERROR_OUT_OF_MEMORY;
-               goto out;
-       }
-
-       ret = badge_db_exec(db, sqlbuf, NULL);
-
-out:
-       if (sqlbuf)
-               sqlite3_free(sqlbuf);
-
-       if (db) {
-               sqlret = db_util_close(db);
-               if (sqlret != SQLITE_OK)
-                       WARN("Failed to db_util_close [%d]", sqlret);
-       }
-
-       return ret;
-}
-/* LCOV_EXCL_STOP */
index c90fac8..afb82c4 100644 (file)
@@ -1 +1,2 @@
 ADD_SUBDIRECTORY(unit_tests)
+ADD_SUBDIRECTORY(integ_tests)
diff --git a/tests/integ_tests/CMakeLists.txt b/tests/integ_tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3eeb833
--- /dev/null
@@ -0,0 +1,27 @@
+REMOVE_DEFINITIONS("-DDB_PATH")\r
+ADD_DEFINITIONS("-DDB_PATH=\"${DB_PATH}\"")\r
+\r
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../include)\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES)\r
+\r
+ADD_EXECUTABLE(${TARGET_BADGE_INTEGTESTS}\r
+       ${SOURCES}\r
+)\r
+\r
+TARGET_LINK_LIBRARIES(${TARGET_BADGE_INTEGTESTS} PUBLIC ${TARGET_BADGE} "-ldl")\r
+SET_TARGET_PROPERTIES(${TARGET_BADGE_INTEGTESTS} PROPERTIES COMPILE_FLAGS "-fPIE")\r
+SET_TARGET_PROPERTIES(${TARGET_BADGE_INTEGTESTS} PROPERTIES LINK_FLAGS "-pie")\r
+\r
+APPLY_PKG_CONFIG(${TARGET_BADGE_INTEGTESTS} PUBLIC\r
+  GLIB_2_DEPS\r
+  GMOCK_DEPS\r
+  SYSTEM_INFO_DEPS\r
+  RPC_PORT_DEPS\r
+  APP_MANAGER_DEPS\r
+  APP_COMMON_DEPS\r
+  TIZEN_DATABASE_DEPS\r
+  DLOG_DEPS\r
+  BUNDLE_DEPS\r
+)\r
+\r
+INSTALL(TARGETS ${TARGET_BADGE_INTEGTESTS} DESTINATION /usr/bin/)\r
diff --git a/tests/integ_tests/src/test_badge.cc b/tests/integ_tests/src/test_badge.cc
new file mode 100644 (file)
index 0000000..54754c9
--- /dev/null
@@ -0,0 +1,263 @@
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ *
+ * 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 <glib.h>
+#include <gtest/gtest.h>
+#include <badge.h>
+#include <database.hpp>
+
+#include <memory>
+
+namespace {
+
+bool DbDeleteAll() {
+  try {
+    tizen_base::Database db(DB_PATH, SQLITE_OPEN_READWRITE);
+    db.OneStepExec({ "DELETE FROM badge_data;" });
+    db.OneStepExec({ "DELETE FROM badge_option;" });
+    db.OneStepExec({ "DELETE FROM badge_setting;" });
+  } catch(const tizen_base::DbException& e) {
+    return false;
+  }
+
+  return true;
+}
+
+}  // namespace
+
+class BadgeTest : public ::testing::Test {
+ public:
+  BadgeTest() {
+  }
+
+  virtual ~BadgeTest() {}
+
+  static void SetUpTestSuite() {
+  }
+
+  static void TearDownTestSuite() {
+  }
+
+  virtual void SetUp() {
+    DbDeleteAll();
+  }
+
+  virtual void TearDown() {
+    DbDeleteAll();
+  }
+};
+
+TEST_F(BadgeTest, badge_new) {
+  int ret = badge_new("testappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+}
+
+TEST_F(BadgeTest, badge_add) {
+  int ret = badge_add("testappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+}
+
+TEST_F(BadgeTest, badge_remove) {
+  int ret = badge_add("testappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+
+  ret = badge_remove("testappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+}
+
+TEST_F(BadgeTest, badge_foreach) {
+  int ret = badge_add("testappid1");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  bool exist = false;
+  ret = badge_foreach([](const char* app_id, unsigned int count,
+      void* user_data) {
+        bool* exist = static_cast<bool*>(user_data);
+        *exist = true;
+        return true;
+      }, &exist);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  EXPECT_TRUE(exist);
+}
+
+TEST_F(BadgeTest, badge_set_count) {
+  int ret = badge_add("myappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+
+  ret = badge_set_count("myappid", 9);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+}
+
+TEST_F(BadgeTest, badge_get_count) {
+  unsigned int count = 0;
+  int ret = badge_add("myappid1");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  ret = badge_set_count("myappid1", 10);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+
+  ret = badge_get_count("myappid1", &count);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  EXPECT_EQ(count, 10);
+}
+
+TEST_F(BadgeTest, badge_set_display) {
+  int ret = badge_add("myappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+
+  ret = badge_set_display("myappid", 1);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+}
+
+TEST_F(BadgeTest, badge_get_display) {
+  unsigned int is_display = 0;
+
+  int ret = badge_add("myappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  ret = badge_set_display("myappid", 1);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+
+  ret = badge_get_display("myappid", &is_display);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  EXPECT_EQ(is_display, 1);
+}
+
+TEST_F(BadgeTest, badge_register_changed_cb) {
+  bool changed = false;
+  static GMainLoop* loop;
+
+  loop = g_main_loop_new(nullptr, FALSE);
+  int ret = badge_register_changed_cb([](unsigned int action,
+      const char* app_id, unsigned int count, void* user_data) {
+    auto* changed = static_cast<bool*>(user_data);
+    *changed = true;
+    g_main_loop_quit(loop);
+  }, &changed);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  ret = badge_add("myappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  g_main_loop_run(loop);
+
+  EXPECT_TRUE(changed);
+  g_main_loop_unref(loop);
+}
+
+TEST_F(BadgeTest, badge_register_changed_cb2) {
+  static GMainLoop* loop;
+  static bool inserted = false;
+  static bool deleted = false;
+
+  loop = g_main_loop_new(nullptr, FALSE);
+  int ret = badge_register_changed_cb([](unsigned int action,
+      const char* app_id, unsigned int count, void* user_data) {
+    switch (action) {
+      case BADGE_ACTION_CREATE:
+        inserted = true;
+        break;
+
+      case BADGE_ACTION_REMOVE:
+        deleted = true;
+        g_main_loop_quit(loop);
+        break;
+
+      default:
+        break;
+    }
+  }, nullptr);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+
+  inserted = false;
+  deleted = false;
+  ret = badge_add("myappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  ret = badge_remove("myappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  g_main_loop_run(loop);
+
+  EXPECT_TRUE(inserted);
+  EXPECT_TRUE(deleted);
+  g_main_loop_unref(loop);
+}
+
+TEST_F(BadgeTest, badge_register_changed_cb3) {
+  static GMainLoop* loop;
+  static bool updated = false;
+
+  loop = g_main_loop_new(nullptr, FALSE);
+  int ret = badge_register_changed_cb([](unsigned int action,
+      const char* app_id, unsigned int count, void* user_data) {
+    switch (action) {
+      case BADGE_ACTION_UPDATE:
+        updated = true;
+        g_main_loop_quit(loop);
+        break;
+
+      default:
+        break;
+    }
+  }, nullptr);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+
+  updated = false;
+  ret = badge_add("myappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  ret = badge_set_count("myappid", 1);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  g_main_loop_run(loop);
+
+  EXPECT_TRUE(updated);
+  g_main_loop_unref(loop);
+}
+
+TEST_F(BadgeTest, badge_register_changed_cb4) {
+  static GMainLoop* loop;
+  static bool changed_disp = false;
+
+  loop = g_main_loop_new(nullptr, FALSE);
+  int ret = badge_register_changed_cb([](unsigned int action,
+      const char* app_id, unsigned int count, void* user_data) {
+    switch (action) {
+      case BADGE_ACTION_CHANGED_DISPLAY:
+        changed_disp = true;
+        g_main_loop_quit(loop);
+        break;
+
+      default:
+        break;
+    }
+  }, nullptr);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+
+  changed_disp = false;
+  ret = badge_add("myappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  ret = badge_set_display("myappid", 1);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  g_main_loop_run(loop);
+
+  EXPECT_TRUE(changed_disp);
+  g_main_loop_unref(loop);
+}
+
+TEST_F(BadgeTest, badge_unregister_changed_cb) {
+  auto cb = [](unsigned int action,
+      const char* app_id, unsigned int count, void* user_data) {
+  };
+
+  int ret = badge_register_changed_cb(cb, nullptr);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+
+  ret = badge_unregister_changed_cb(cb);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+}
similarity index 60%
rename from tests/mock/package_manager_mock.h
rename to tests/integ_tests/src/test_main.cc
index 4552053..c2eb730 100644 (file)
  * limitations under the License.
  */
 
-#ifndef MOCK_PACKAGE_MANAGER_MOCK_H_
-#define MOCK_PACKAGE_MANAGER_MOCK_H_
-
-#include <package_manager.h>
+#include <gtest/gtest.h>
 #include <gmock/gmock.h>
 
-#include "module_mock.h"
-
-class PackageManagerMock : public virtual ModuleMock {
- public:
-  virtual ~PackageManagerMock() {}
+int main(int argc, char** argv) {
+  int ret = -1;
 
-  MOCK_METHOD3(package_manager_compare_app_cert_info, int(const char*, const char*, package_manager_compare_result_type_e*));
-};
+  try {
+    testing::InitGoogleTest(&argc, argv);
+  } catch(...) {
+    std::cout << "Exception occurred" << std::endl;
+  }
 
-#endif  // MOCK_PACKAGE_MANAGER_MOCK_H_
+  try {
+    ret = RUN_ALL_TESTS();
+  } catch (const ::testing::internal::GoogleTestFailureException& e) {
+    ret = -1;
+    std::cout << "GoogleTestFailureException was thrown:" << e.what() << std::endl;
+  }
 
+  return ret;
+}
index 15952dd..717bdf4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 #include "aul_mock.h"
+
 #include "mock_hook.h"
 #include "test_fixture.h"
 
-extern "C" int aul_app_get_pkgname_bypid(int arg0, char* arg1, int arg2) {
-  return MOCK_HOOK_P3(AulMock, aul_app_get_pkgname_bypid, arg0, arg1, arg2);
-}
+extern "C" int aul_svc_get_appid_by_alias_appid(const char* arg0, char** arg1) {
+  return MOCK_HOOK_P2(AulMock, aul_svc_get_appid_by_alias_appid, arg0, arg1);
+}
\ No newline at end of file
index 46bceef..3f04d07 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef MOCK_AUL_MOCK_H_
 #define MOCK_AUL_MOCK_H_
 
-#include <aul.h>
+#include <tizen.h>
 #include <gmock/gmock.h>
 
 #include "module_mock.h"
@@ -26,7 +26,7 @@ class AulMock : public virtual ModuleMock {
  public:
   virtual ~AulMock() {}
 
-  MOCK_METHOD3(aul_app_get_pkgname_bypid, int(int, char*, int));
+  MOCK_METHOD2(aul_svc_get_appid_by_alias_appid, int(const char*, char**));
 };
 
 #endif  // MOCK_AUL_MOCK_H_
diff --git a/tests/mock/gio_mock.cc b/tests/mock/gio_mock.cc
deleted file mode 100644 (file)
index 67f4fde..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
- *
- * 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 <gio/gio.h>
-
-#include "gio_mock.h"
-#include "mock_hook.h"
-#include "test_fixture.h"
-
-extern "C" GDBusConnection* g_bus_get_sync(GBusType type,
-    GCancellable* cancellable, GError** error) {
-  return MOCK_HOOK_P3(GioMock, g_bus_get_sync, type, cancellable, error);
-}
-
-extern "C" GDBusMessage* g_dbus_connection_send_message_with_reply_sync(
-    GDBusConnection* conn, GDBusMessage* msg, GDBusSendMessageFlags flags,
-    gint timeout, volatile guint32* out_serial, GCancellable* cancellable,
-    GError** error) {
-  return MOCK_HOOK_P7(GioMock, g_dbus_connection_send_message_with_reply_sync,
-      conn, msg, flags, timeout, out_serial, cancellable, error);
-}
-
-extern "C" GDBusMessage* g_dbus_message_new_method_call(const gchar* arg0,
-    const gchar* arg1, const gchar* arg2, const gchar* arg3) {
-  return MOCK_HOOK_P4(GioMock, g_dbus_message_new_method_call, arg0, arg1, arg2,
-      arg3);
-}
-
-extern "C" void g_dbus_message_set_body(GDBusMessage* arg0, GVariant* arg1) {
-  return MOCK_HOOK_P2(GioMock, g_dbus_message_set_body, arg0, arg1);
-}
-
-extern "C" GVariant* g_dbus_message_get_body(GDBusMessage* arg0) {
-  return MOCK_HOOK_P1(GioMock, g_dbus_message_get_body, arg0);
-}
-
-extern "C" guint g_dbus_connection_signal_subscribe(GDBusConnection* arg0,
-    const gchar* arg1, const gchar* arg2, const gchar* arg3, const gchar* arg4,
-    const gchar* arg5, GDBusSignalFlags arg6, GDBusSignalCallback arg7,
-    gpointer arg8, GDestroyNotify arg9) {
-  return MOCK_HOOK_P10(GioMock, g_dbus_connection_signal_subscribe,
-      arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
-}
-
-extern "C" void g_dbus_connection_send_message_with_reply(GDBusConnection* arg0,
-    GDBusMessage* arg1, GDBusSendMessageFlags arg2, gint arg3,
-    volatile guint32* arg4, GCancellable* arg5, GAsyncReadyCallback arg6,
-    gpointer arg7) {
-  return MOCK_HOOK_P8(GioMock, g_dbus_connection_send_message_with_reply,
-      arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
-}
-
-extern "C" gboolean g_dbus_message_to_gerror(
-    GDBusMessage* arg0, GError** arg1) {
-  return MOCK_HOOK_P2(GioMock, g_dbus_message_to_gerror,
-      arg0, arg1);
-}
-
-extern "C" guint g_bus_watch_name_on_connection(
-    GDBusConnection* arg0, const gchar* arg1, GBusNameWatcherFlags arg2,
-    GBusNameAppearedCallback arg3, GBusNameVanishedCallback arg4,
-    gpointer arg5, GDestroyNotify arg6) {
-  return MOCK_HOOK_P7(GioMock, g_bus_watch_name_on_connection,
-      arg0, arg1, arg2, arg3, arg4, arg5, arg6);
-}
-
-extern "C" void g_bus_unwatch_name(guint arg0) {
-  return MOCK_HOOK_P1(GioMock, g_bus_unwatch_name, arg0);
-}
-
-extern "C" void g_dbus_connection_signal_unsubscribe(
-    GDBusConnection* arg0, guint arg1) {
-  return MOCK_HOOK_P2(GioMock, g_dbus_connection_signal_unsubscribe,
-      arg0, arg1);
-}
diff --git a/tests/mock/gio_mock.h b/tests/mock/gio_mock.h
deleted file mode 100644 (file)
index 298ce50..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
- *
- * 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 MOCK_GIO_MOCK_H_
-#define MOCK_GIO_MOCK_H_
-
-#include <gio/gio.h>
-#include <gmock/gmock.h>
-
-#include "module_mock.h"
-
-class GioMock : public virtual ModuleMock {
- public:
-  virtual ~GioMock() {}
-
-  MOCK_METHOD3(g_bus_get_sync,
-      GDBusConnection*(GBusType, GCancellable*, GError**));
-  MOCK_METHOD4(g_dbus_message_new_method_call,
-      GDBusMessage*(const gchar*, const gchar*, const gchar*, const gchar*));
-  MOCK_METHOD2(g_dbus_message_set_body, void(GDBusMessage*, GVariant*));
-  MOCK_METHOD1(g_dbus_message_get_body, GVariant*(GDBusMessage*));
-  MOCK_METHOD7(g_dbus_connection_send_message_with_reply_sync,
-      GDBusMessage*(GDBusConnection*, GDBusMessage*, GDBusSendMessageFlags,
-          gint, volatile guint32*, GCancellable*, GError**));
-  MOCK_METHOD10(g_dbus_connection_signal_subscribe,
-      guint(GDBusConnection*, const gchar*, const gchar*, const gchar*,
-          const gchar*, const gchar*, GDBusSignalFlags, GDBusSignalCallback,
-          gpointer, GDestroyNotify));
-  MOCK_METHOD8(g_dbus_connection_send_message_with_reply,
-      void(GDBusConnection*, GDBusMessage*, GDBusSendMessageFlags, gint,
-          volatile guint32*, GCancellable*, GAsyncReadyCallback, gpointer));
-  MOCK_METHOD2(g_dbus_message_to_gerror,
-      gboolean(GDBusMessage*, GError**));
-  MOCK_METHOD7(g_bus_watch_name_on_connection,
-      guint(GDBusConnection*, const gchar*, GBusNameWatcherFlags,
-          GBusNameAppearedCallback, GBusNameVanishedCallback, gpointer,
-          GDestroyNotify));
-  MOCK_METHOD1(g_bus_unwatch_name, void(guint));
-  MOCK_METHOD2(g_dbus_connection_signal_unsubscribe,
-          void(GDBusConnection*, guint));
-};
-
-#endif  // MOCK_GIO_MOCK_H_
similarity index 63%
rename from tests/mock/package_manager_mock.cc
rename to tests/mock/rpc_port_mock.cc
index f49ea96..a15b1d5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  */
 
-#include "package_manager_mock.h"
+#include "rpc_port_mock.h"
+
 #include "mock_hook.h"
 #include "test_fixture.h"
 
-extern "C" int package_manager_compare_app_cert_info(const char* arg0, const char* arg1, package_manager_compare_result_type_e* arg2) {
-  return MOCK_HOOK_P3(PackageManagerMock, package_manager_compare_app_cert_info, arg0, arg1, arg2);
+extern "C" int rpc_port_register_proc_info(const char* arg0, bundle* arg1) {
+  return MOCK_HOOK_P2(RpcPortMock, rpc_port_register_proc_info, arg0, arg1);
 }
 
+extern "C" int rpc_port_stub_listen(rpc_port_stub_h h) {
+  return MOCK_HOOK_P1(RpcPortMock, rpc_port_stub_listen, h);
+}
\ No newline at end of file
diff --git a/tests/mock/rpc_port_mock.h b/tests/mock/rpc_port_mock.h
new file mode 100644 (file)
index 0000000..6c552a9
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ *
+ * 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 MOCK_RPC_PORT_MOCK_H_
+#define MOCK_RPC_PORT_MOCK_H_
+
+#include <rpc-port.h>
+#include <tizen.h>
+#include <bundle.h>
+#include <gmock/gmock.h>
+
+#include "module_mock.h"
+
+class RpcPortMock : public virtual ModuleMock {
+ public:
+  virtual ~RpcPortMock() {}
+
+  MOCK_METHOD2(rpc_port_register_proc_info, int(const char*, bundle*));
+  MOCK_METHOD1(rpc_port_stub_listen, int(rpc_port_stub_h));
+};
+
+#endif  // MOCK_RPC_PORT_MOCK_H_
index 2c95d9b..91ba5ec 100644 (file)
@@ -1,35 +1,39 @@
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src UNIT_TESTS_SRCS)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../mock/ UNIT_TESTS_SRCS)
-ADD_EXECUTABLE(${TARGET_BADGE_UNIT_TEST}
-  ${UNIT_TESTS_SRCS}
-)
+REMOVE_DEFINITIONS("-DDB_PATH")
+ADD_DEFINITIONS("-DDB_PATH=\"badge_test.db\"")
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../src)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../modules/badge)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../mock)
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../modules/badge/ MOD_SOURCES)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../mock MOCK_SOURCES)
 
-TARGET_INCLUDE_DIRECTORIES(${TARGET_BADGE_UNIT_TEST} PUBLIC
-  "${CMAKE_CURRENT_SOURCE_DIR}/../../include"
-  "${CMAKE_CURRENT_SOURCE_DIR}/../mock"
+ADD_EXECUTABLE(${TARGET_BADGE_UNIT_TEST}
+  ${SOURCES}
+  ${MOD_SOURCES}
+  ${MOCK_SOURCES}
 )
 
 APPLY_PKG_CONFIG(${TARGET_BADGE_UNIT_TEST} PUBLIC
-  GLIB_DEPS
+  GLIB_2_DEPS
   GMOCK_DEPS
-  BUNDLE_DEPS
-  GOBJECT_DEPS
   SYSTEM_INFO_DEPS
+  ESD_DEPS
+  RPC_PORT_DEPS
+  APP_MANAGER_DEPS
+  PACKAGE_MANAGER_DEPS
+  APP_COMMON_DEPS
+  TIZEN_DATABASE_DEPS
+  DLOG_DEPS
+  VCONF_DEPS
 )
 
-TARGET_LINK_LIBRARIES(${TARGET_BADGE_UNIT_TEST} PUBLIC ${TARGET_BADGE})
+TARGET_LINK_LIBRARIES(${TARGET_BADGE_UNIT_TEST} PUBLIC ${TARGET_BADGE} "-ldl")
 SET_TARGET_PROPERTIES(${TARGET_BADGE_UNIT_TEST} PROPERTIES COMPILE_FLAGS "-fPIE")
 SET_TARGET_PROPERTIES(${TARGET_BADGE_UNIT_TEST} PROPERTIES LINK_FLAGS "-pie")
 
-SET(TESTDB "badge.db")
-SET(TARGET_TESTDB "badge-test-db")
-ADD_CUSTOM_COMMAND(OUTPUT ${TESTDB}
-  COMMAND sqlite3 ${TESTDB} < data/test.sql
-  COMMENT " Generate test database for ${TARGET_BADGE_UNIT_TEST}"
-)
-ADD_CUSTOM_TARGET(${TARGET_TESTDB} DEPENDS ${TESTDB})
-ADD_DEPENDENCIES(${TARGET_BADGE_UNIT_TEST} ${TARGET_TESTDB})
-
 ADD_TEST(
   NAME ${TARGET_BADGE_UNIT_TEST}
   COMMAND ${TARGET_BADGE_UNIT_TEST}
index df3f84e..94e2195 100644 (file)
  */
 
 #include <stdlib.h>
+#include <glib.h>
 #include <gtest/gtest.h>
-#include <pkgmgrinfo_type.h>
-#include "badge.h"
-#include "badge_db.h"
-#include "badge_internal.h"
-#include "badge_setting.h"
-#include "badge_setting_service.h"
-
+#include <database.hpp>
+#include <imodule.hh>
 #include <memory>
 
-#include "system_info_mock.h"
-#include "gio_mock.h"
 #include "aul_mock.h"
-#include "package_manager_mock.h"
+#include "badge.h"
+#include "rpc_port_mock.h"
+#include "system_info_mock.h"
 #include "test_fixture.h"
 
 using ::testing::_;
@@ -37,841 +33,334 @@ using ::testing::Return;
 using ::testing::SetArgPointee;
 using ::testing::Invoke;
 
+bool DbDeleteAll() {
+  try {
+    tizen_base::Database db(DB_PATH, SQLITE_OPEN_READWRITE);
+    db.OneStepExec({ "DELETE FROM badge_data;" });
+    db.OneStepExec({ "DELETE FROM badge_option;" });
+    db.OneStepExec({ "DELETE FROM badge_setting;" });
+  } catch(const tizen_base::DbException& e) {
+    return false;
+  }
 
-typedef enum {
-  LOG_ID_INVALID = -1,
-  LOG_ID_MAIN,
-  LOG_ID_RADIO,
-  LOG_ID_SYSTEM,
-  LOG_ID_APPS,
-  LOG_ID_KMSG,
-  LOG_ID_SYSLOG,
-  LOG_ID_MAX
-} log_id_t;
-
-extern "C" int __dlog_print(
-  log_id_t log_id, int prio, const char* tag, const char* fmt, ...) {
-  va_list ap;
-  va_start(ap, fmt);
-  vprintf(fmt, ap);
-  va_end(ap);
-  printf("\n");
-
-  return 0;
+  return true;
 }
 
-extern "C" int __dlog_sec_print(
-    log_id_t log_id, int prio, const char* tag, const char* fmt, ...) {
-  va_list ap;
-  va_start(ap, fmt);
-  vprintf(fmt, ap);
-  va_end(ap);
-  printf("\n");
-
-  return 0;
-}
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+extern "C" EXPORT_API esd::api::IModule* ESD_GET_MODULE();
 
 class Mocks : public ::testing::NiceMock<SystemInfoMock>,
-              public ::testing::NiceMock<GioMock>,
-              public ::testing::NiceMock<AulMock>,
-              public ::testing::NiceMock<PackageManagerMock> {};
+              public ::testing::NiceMock<RpcPortMock>,
+              public ::testing::NiceMock<AulMock> {};
+
+std::unique_ptr<esd::api::IModule> module_;
 
 class BadgeTest : public TestFixture {
  public:
-  BadgeTest() : TestFixture(std::make_unique<Mocks>()) {}
+  BadgeTest() : TestFixture(std::make_unique<Mocks>()) {
+    setenv("AUL_APPID", "d::org.tizen.appfw.service.esd", 1);
+  }
+
   virtual ~BadgeTest() {}
 
-  virtual void SetUp() {
-    pkgid_ = const_cast<char*>("mypkgid");
-    pkgid2_ = const_cast<char*>("pkgname");
-    pkgid3_ = const_cast<char*>("pkgname2");
-    conn_ = static_cast<GDBusConnection*>(g_object_new(G_TYPE_OBJECT, NULL));
-    msg_ = static_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL));
-    msg2_ = static_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL));
+  static void SetUpTestSuite() {
+    auto* mod = ESD_GET_MODULE();
+    module_.reset(mod);
+  }
 
+  static void TearDownTestSuite() {
+    module_->Shutdown();
+    module_.reset();
+    unlink(DB_PATH);
   }
 
-  virtual void TearDown() {
+  virtual void SetUp() {
+    ON_CALL(GetMock<AulMock>(), aul_svc_get_appid_by_alias_appid(_, _))
+        .WillByDefault(Return(-1));
+    EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_register_proc_info(_, _))
+        .WillOnce(Return(0));
+    EXPECT_CALL(GetMock<RpcPortMock>(), rpc_port_stub_listen(_))
+        .WillOnce(Return(0));
+    module_->Startup(nullptr);
   }
 
-  char* pkgid_ = nullptr;
-  char* pkgid2_ = nullptr;
-  char* pkgid3_ = nullptr;
-  GDBusConnection* conn_ = nullptr;
-  GDBusMessage* msg_ = nullptr;
-  GDBusMessage* msg2_ = nullptr;
+  virtual void TearDown() {
+    DbDeleteAll();
+  }
 };
 
 TEST_F(BadgeTest, badge_new) {
-  int ret;
   bool is_supported = true;
 
   EXPECT_CALL(GetMock<SystemInfoMock>(),
       system_info_get_platform_bool(_, _)).
       WillRepeatedly(DoAll(SetArgPointee<1>(is_supported),
                             Return(0)));
-
-  EXPECT_CALL(GetMock<AulMock>(),
-      aul_app_get_pkgname_bypid(_, _, _)).
-      WillOnce(DoAll(SetArgPointee<1>(*pkgid_),
-                      Return(0)));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_bus_get_sync(_, _, _)).
-      WillOnce(Return(conn_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_new_method_call(_, _, _, _)).
-      WillOnce(Return(msg_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_connection_send_message_with_reply_sync(
-        _, _, _, _, _, _, _)).
-      WillOnce(Return(msg2_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_to_gerror(_, _)).
-      WillOnce(Return(FALSE));
-
-  ret = badge_new("testappid");
-
-  g_object_unref(conn_);
-
+  int ret = badge_new("testappid");
   EXPECT_EQ(ret, BADGE_ERROR_NONE);
 }
 
 TEST_F(BadgeTest, badge_add) {
-  int ret;
   bool is_supported = true;
-  package_manager_compare_result_type_e comp_ret =
-      PACKAGE_MANAGER_COMPARE_MATCH;
 
   EXPECT_CALL(GetMock<SystemInfoMock>(),
       system_info_get_platform_bool(_, _)).
       WillRepeatedly(DoAll(SetArgPointee<1>(is_supported),
-                Return(0)));
-
-  EXPECT_CALL(GetMock<AulMock>(),
-      aul_app_get_pkgname_bypid(_, _, _)).
-      WillOnce(DoAll(SetArgPointee<1>(*pkgid_),
-                      Return(0)));
-
-  EXPECT_CALL(GetMock<PackageManagerMock>(),
-      package_manager_compare_app_cert_info(_, _, _)).
-      WillOnce(DoAll(SetArgPointee<2>(comp_ret),
-                      Return(0)));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_new_method_call(_, _, _, _)).
-      WillOnce(Return(msg_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_connection_send_message_with_reply_sync(
-        _, _, _, _, _, _, _)).
-      WillOnce(Return(msg2_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_to_gerror(_, _)).
-      WillOnce(Return(FALSE));
-
-  ret = badge_add("myappid");
-
+                            Return(0)));
+  int ret = badge_add("testappid");
   EXPECT_EQ(ret, BADGE_ERROR_NONE);
 }
 
 TEST_F(BadgeTest, badge_remove) {
-  int ret;
   bool is_supported = true;
 
   EXPECT_CALL(GetMock<SystemInfoMock>(),
       system_info_get_platform_bool(_, _)).
       WillRepeatedly(DoAll(SetArgPointee<1>(is_supported),
-                Return(0)));
-
-  EXPECT_CALL(GetMock<AulMock>(),
-      aul_app_get_pkgname_bypid(_, _, _)).
-      WillOnce(DoAll(SetArgPointee<1>(*pkgid_),
-                      Return(0)));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_new_method_call(_, _, _, _)).
-      WillOnce(Return(msg_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_connection_send_message_with_reply_sync(
-        _, _, _, _, _, _, _)).
-      WillOnce(Return(msg2_));
+                            Return(0)));
+  int ret = badge_add("testappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
 
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_to_gerror(_, _)).
-      WillOnce(Return(FALSE));
+  ret = badge_remove("testappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+}
 
-  ret = badge_remove("myappid");
+TEST_F(BadgeTest, badge_foreach) {
+  bool is_supported = true;
 
+  EXPECT_CALL(GetMock<SystemInfoMock>(),
+      system_info_get_platform_bool(_, _)).
+      WillRepeatedly(DoAll(SetArgPointee<1>(is_supported),
+                            Return(0)));
+  int ret = badge_add("testappid1");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  bool exist = false;
+  ret = badge_foreach([](const char* app_id, unsigned int count,
+      void* user_data) {
+        bool* exist = static_cast<bool*>(user_data);
+        *exist = true;
+        return true;
+      }, &exist);
   EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  EXPECT_TRUE(exist);
 }
 
 TEST_F(BadgeTest, badge_set_count) {
-  int ret;
   bool is_supported = true;
 
   EXPECT_CALL(GetMock<SystemInfoMock>(),
       system_info_get_platform_bool(_, _)).
       WillRepeatedly(DoAll(SetArgPointee<1>(is_supported),
                 Return(0)));
-
-  EXPECT_CALL(GetMock<AulMock>(),
-      aul_app_get_pkgname_bypid(_, _, _)).
-      WillOnce(DoAll(SetArgPointee<1>(*pkgid_),
-                      Return(0)));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_new_method_call(_, _, _, _)).
-      WillOnce(Return(msg_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_connection_send_message_with_reply_sync(
-        _, _, _, _, _, _, _)).
-      WillOnce(Return(msg2_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_to_gerror(_, _)).
-      WillOnce(Return(FALSE));
+  int ret = badge_add("myappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
 
   ret = badge_set_count("myappid", 9);
-
   EXPECT_EQ(ret, BADGE_ERROR_NONE);
 }
 
 TEST_F(BadgeTest, badge_get_count) {
-  int ret;
   bool is_supported = true;
   unsigned int count = 0;
-  GVariant* body = g_variant_new("(i)", 3);
 
   EXPECT_CALL(GetMock<SystemInfoMock>(),
       system_info_get_platform_bool(_, _)).
       WillRepeatedly(DoAll(SetArgPointee<1>(is_supported),
                 Return(0)));
+  int ret = badge_add("myappid1");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  ret = badge_set_count("myappid1", 10);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
 
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_new_method_call(_, _, _, _)).
-      WillOnce(Return(msg_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_connection_send_message_with_reply_sync(
-        _, _, _, _, _, _, _)).
-      WillOnce(Return(msg2_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_get_body(_)).
-      WillOnce(Return(body));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_to_gerror(_, _)).
-      WillOnce(Return(FALSE));
-
-  ret = badge_get_count("myappid", &count);
-
-  if (body)
-    g_variant_unref(body);
-
+  ret = badge_get_count("myappid1", &count);
   EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  EXPECT_EQ(count, 10);
 }
 
 TEST_F(BadgeTest, badge_set_display) {
-  int ret;
   bool is_supported = true;
 
   EXPECT_CALL(GetMock<SystemInfoMock>(),
       system_info_get_platform_bool(_, _)).
       WillRepeatedly(DoAll(SetArgPointee<1>(is_supported),
                 Return(0)));
-
-  EXPECT_CALL(GetMock<AulMock>(),
-      aul_app_get_pkgname_bypid(_, _, _)).
-      WillOnce(DoAll(SetArgPointee<1>(*pkgid_),
-                      Return(0)));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_new_method_call(_, _, _, _)).
-      WillOnce(Return(msg_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_connection_send_message_with_reply_sync(
-        _, _, _, _, _, _, _)).
-      WillOnce(Return(msg2_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_to_gerror(_, _)).
-      WillOnce(Return(FALSE));
+  int ret = badge_add("myappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
 
   ret = badge_set_display("myappid", 1);
-
   EXPECT_EQ(ret, BADGE_ERROR_NONE);
 }
 
 TEST_F(BadgeTest, badge_get_display) {
-  int ret;
   bool is_supported = true;
   unsigned int is_display = 0;
-  GVariant* body = g_variant_new("(i)", 1);
 
   EXPECT_CALL(GetMock<SystemInfoMock>(),
       system_info_get_platform_bool(_, _)).
       WillRepeatedly(DoAll(SetArgPointee<1>(is_supported),
                 Return(0)));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_new_method_call(_, _, _, _)).
-      WillOnce(Return(msg_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_connection_send_message_with_reply_sync(
-        _, _, _, _, _, _, _)).
-      WillOnce(Return(msg2_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_get_body(_)).
-      WillOnce(Return(body));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_to_gerror(_, _)).
-      WillOnce(Return(FALSE));
+  int ret = badge_add("myappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  ret = badge_set_display("myappid", 1);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
 
   ret = badge_get_display("myappid", &is_display);
-
-  if (body)
-    g_variant_unref(body);
-
   EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  EXPECT_EQ(is_display, 1);
 }
 
-bool _badge_foreach_cb(
-    const char* app_id, unsigned int count, void* user_data) {
-  return true;
-}
-
-TEST_F(BadgeTest, badge_foreach) {
-  int ret;
+TEST_F(BadgeTest, badge_register_changed_cb) {
   bool is_supported = true;
-  GVariant* body = g_variant_new("(a(v))", NULL);
+  bool changed = false;
+  static GMainLoop* loop;
 
   EXPECT_CALL(GetMock<SystemInfoMock>(),
       system_info_get_platform_bool(_, _)).
       WillRepeatedly(DoAll(SetArgPointee<1>(is_supported),
                 Return(0)));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_new_method_call(_, _, _, _)).
-      WillOnce(Return(msg_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_connection_send_message_with_reply_sync(
-          _, _, _, _, _, _, _)).
-      WillOnce(Return(msg2_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_get_body(_)).
-      WillOnce(Return(body));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_to_gerror(_, _)).
-      WillOnce(Return(FALSE));
-
-  ret = badge_foreach(_badge_foreach_cb, NULL);
-
+  loop = g_main_loop_new(nullptr, FALSE);
+  int ret = badge_register_changed_cb([](unsigned int action,
+      const char* app_id, unsigned int count, void* user_data) {
+    auto* changed = static_cast<bool*>(user_data);
+    *changed = true;
+    g_main_loop_quit(loop);
+  }, &changed);
   EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-void _badge_change_cb(unsigned int action, const char* app_id,
-      unsigned int count, void* user_data) {
-}
-
-guint _signal_subscribe(GDBusConnection* connection, const gchar* sender,
-    const gchar* interface_name, const gchar* member,
-    const gchar* object_path, const gchar* arg0, GDBusSignalFlags flags,
-    GDBusSignalCallback callback, gpointer user_data,
-    GDestroyNotify user_data_free_func) {
+  ret = badge_add("myappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  g_main_loop_run(loop);
 
-  GVariant* parameters = g_variant_new("(si)", "pkgname", 1000);
-  callback(nullptr, "", "", "", "insert_badge_notify", parameters, nullptr);
-  return 99;
+  EXPECT_TRUE(changed);
+  g_main_loop_unref(loop);
 }
 
-TEST_F(BadgeTest, badge_register_changed_cb) {
-  int ret;
+TEST_F(BadgeTest, badge_register_changed_cb2) {
   bool is_supported = true;
-  GDBusMessage* msg3 = static_cast<GDBusMessage*>(
-        g_object_new(G_TYPE_OBJECT, NULL));
-  GDBusMessage* msg4 = static_cast<GDBusMessage*>(
-        g_object_new(G_TYPE_OBJECT, NULL));
+  static GMainLoop* loop;
+  static bool inserted = false;
+  static bool deleted = false;
 
   EXPECT_CALL(GetMock<SystemInfoMock>(),
       system_info_get_platform_bool(_, _)).
       WillRepeatedly(DoAll(SetArgPointee<1>(is_supported),
                 Return(0)));
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_connection_signal_subscribe(
-        _, _, _, _, _, _, _, _, _, _)).
-      WillOnce(Invoke(_signal_subscribe));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_new_method_call(_, _, _, _)).
-      WillOnce(Return(msg_)).
-      WillOnce(Return(msg2_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_connection_send_message_with_reply_sync(
-        _, _, _, _, _, _, _)).
-      WillOnce(Return(msg3)).
-      WillOnce(Return(msg4));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_to_gerror(_, _)).
-      WillRepeatedly(Return(FALSE));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_bus_watch_name_on_connection(
-        _, _, _, _, _, _, _)).
-      WillOnce(Return(88));
-
-  ret = badge_register_changed_cb(_badge_change_cb, NULL);
-
+  loop = g_main_loop_new(nullptr, FALSE);
+  int ret = badge_register_changed_cb([](unsigned int action,
+      const char* app_id, unsigned int count, void* user_data) {
+    switch (action) {
+      case BADGE_ACTION_CREATE:
+        inserted = true;
+        break;
+
+      case BADGE_ACTION_REMOVE:
+        deleted = true;
+        g_main_loop_quit(loop);
+        break;
+
+      default:
+        break;
+    }
+  }, nullptr);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+
+  inserted = false;
+  deleted = false;
+  ret = badge_add("myappid");
   EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  ret = badge_remove("myappid");
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  g_main_loop_run(loop);
+
+  EXPECT_TRUE(inserted);
+  EXPECT_TRUE(deleted);
+  g_main_loop_unref(loop);
 }
 
-TEST_F(BadgeTest, badge_unregister_changed_cb) {
-  int ret;
+TEST_F(BadgeTest, badge_register_changed_cb3) {
   bool is_supported = true;
+  static GMainLoop* loop;
+  static bool updated = false;
 
   EXPECT_CALL(GetMock<SystemInfoMock>(),
       system_info_get_platform_bool(_, _)).
       WillRepeatedly(DoAll(SetArgPointee<1>(is_supported),
                 Return(0)));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_bus_unwatch_name(_)).
-      Times(1);
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_connection_signal_unsubscribe(_, _)).
-      Times(1);
-
-  ret = badge_unregister_changed_cb(_badge_change_cb);
-
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-extern "C" const char* tzplatform_mkpath(
-    enum tzplatform_variable id, const char* path) {
-  return "badge.db";
-}
-
-TEST_F(BadgeTest, badge_db_is_existing) {
-  bool existing;
-  badge_db_init();
-  int ret = badge_db_is_existing("test", &existing, 1000);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-TEST_F(BadgeTest, badge_db_insert) {
-  EXPECT_CALL(GetMock<AulMock>(),
-      aul_app_get_pkgname_bypid(_, _, _)).
-      WillOnce(DoAll(SetArgPointee<1>(*pkgid_),
-                      Return(0)));
-  int ret = badge_db_insert(pkgid3_, "writable_pkg", "caller", 1000);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-TEST_F(BadgeTest, badge_db_get_list) {
-  GList* list = nullptr;
-  int ret = badge_db_get_list(&list, 1000);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-TEST_F(BadgeTest, badge_db_delete) {
-  int ret = badge_db_delete(pkgid2_, "writable_pkgs", 1000, getpid());
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-TEST_F(BadgeTest, badge_db_delete_by_pkgname) {
-  EXPECT_CALL(GetMock<AulMock>(),
-      aul_app_get_pkgname_bypid(_, _, _)).
-      WillOnce(DoAll(SetArgPointee<1>(*pkgid_),
-                      Return(0)));
-  int ret = badge_db_insert(pkgid2_, "writable_pkg", "caller", 1000);
-  ret = badge_db_delete_by_pkgname(pkgid2_, 1000);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-TEST_F(BadgeTest, badge_db_set_count) {
-  int ret = badge_db_set_count(pkgid3_, "caller", 2, 1000, getpid());
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-TEST_F(BadgeTest, badge_db_get_count) {
-  unsigned int cnt;
-  int ret = badge_db_get_count(pkgid3_, &cnt, 1000);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-TEST_F(BadgeTest, badge_db_set_display_option) {
-  int ret = badge_db_set_display_option(pkgid3_, 1, 1000);
+  loop = g_main_loop_new(nullptr, FALSE);
+  int ret = badge_register_changed_cb([](unsigned int action,
+      const char* app_id, unsigned int count, void* user_data) {
+    switch (action) {
+      case BADGE_ACTION_UPDATE:
+        updated = true;
+        g_main_loop_quit(loop);
+        break;
+
+      default:
+        break;
+    }
+  }, nullptr);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+
+  updated = false;
+  ret = badge_add("myappid");
   EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-TEST_F(BadgeTest, badge_db_get_display_option) {
-  unsigned int is_display;
-  int ret = badge_db_get_display_option(pkgid3_, &is_display, 1000);
+  ret = badge_set_count("myappid", 1);
   EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
+  g_main_loop_run(loop);
 
-TEST_F(BadgeTest, badge_create_for_uid) {
-  EXPECT_CALL(GetMock<SystemInfoMock>(),
-      system_info_get_platform_bool(_, _)).
-          WillOnce(DoAll(
-                  SetArgPointee<1>(true),
-                  Return(0)));
-
-  EXPECT_CALL(GetMock<AulMock>(),
-      aul_app_get_pkgname_bypid(_, _, _)).
-      WillOnce(DoAll(SetArgPointee<1>(*pkgid_),
-                      Return(0)));
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_new_method_call(_, _, _, _)).
-      WillOnce(Return(msg_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_connection_send_message_with_reply_sync(
-        _, _, _, _, _, _, _)).
-      WillOnce(Return(msg2_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_to_gerror(_, _)).
-      WillOnce(Return(FALSE));
-  int ret = badge_create_for_uid(pkgid3_, "writable_pkg", 1000);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-TEST_F(BadgeTest, badge_new_for) {
-  EXPECT_CALL(GetMock<SystemInfoMock>(),
-      system_info_get_platform_bool(_, _)).
-          WillRepeatedly(DoAll(
-                  SetArgPointee<1>(true),
-                  Return(0)));
-
-  EXPECT_CALL(GetMock<AulMock>(),
-      aul_app_get_pkgname_bypid(_, _, _)).
-      WillOnce(DoAll(SetArgPointee<1>(*pkgid_),
-                      Return(0)));
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_new_method_call(_, _, _, _)).
-      WillOnce(Return(msg_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_connection_send_message_with_reply_sync(
-        _, _, _, _, _, _, _)).
-      WillOnce(Return(msg2_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_to_gerror(_, _)).
-      WillOnce(Return(FALSE));
-  int ret = badge_new_for(nullptr, "writable_pkg");
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  EXPECT_TRUE(updated);
+  g_main_loop_unref(loop);
 }
 
-extern "C" GVariant* g_dbus_connection_call_sync(
-    GDBusConnection* connection, const gchar* bus_name,
-    const gchar* object_path, const gchar* interface_name,
-    const gchar* method_name, GVariant* parameters,
-    const GVariantType* reply_type, GDBusCallFlags flags,
-    gint timeout_msec, GCancellable* cancellable, GError** error) {
-  return g_variant_new("(b)", 1);
-}
-
-TEST_F(BadgeTest, badge_is_service_ready) {
-  EXPECT_CALL(GetMock<SystemInfoMock>(),
-      system_info_get_platform_bool(_, _)).
-          WillOnce(DoAll(
-                  SetArgPointee<1>(true),
-                  Return(0)));
-
-  int ret = badge_is_service_ready();
-  EXPECT_EQ(ret, 1);
-}
-
-void _deferred_task(void* data) {
-}
-
-TEST_F(BadgeTest, badge_add_deferred_task) {
-  EXPECT_CALL(GetMock<SystemInfoMock>(),
-      system_info_get_platform_bool(_, _)).
-          WillOnce(DoAll(
-                  SetArgPointee<1>(true),
-                  Return(0)));
-  int ret = badge_add_deferred_task(_deferred_task, nullptr);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
+TEST_F(BadgeTest, badge_register_changed_cb4) {
+  bool is_supported = true;
+  static GMainLoop* loop;
+  static bool changed_disp = false;
 
-TEST_F(BadgeTest, badge_del_deferred_task) {
   EXPECT_CALL(GetMock<SystemInfoMock>(),
       system_info_get_platform_bool(_, _)).
-          WillOnce(DoAll(
-                  SetArgPointee<1>(true),
-                  Return(0)));
-  int ret = badge_del_deferred_task(_deferred_task);
+      WillRepeatedly(DoAll(SetArgPointee<1>(is_supported),
+                Return(0)));
+  loop = g_main_loop_new(nullptr, FALSE);
+  int ret = badge_register_changed_cb([](unsigned int action,
+      const char* app_id, unsigned int count, void* user_data) {
+    switch (action) {
+      case BADGE_ACTION_CHANGED_DISPLAY:
+        changed_disp = true;
+        g_main_loop_quit(loop);
+        break;
+
+      default:
+        break;
+    }
+  }, nullptr);
+  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+
+  changed_disp = false;
+  ret = badge_add("myappid");
   EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-TEST_F(BadgeTest, badge_is_existing) {
-  EXPECT_CALL(GetMock<SystemInfoMock>(),
-      system_info_get_platform_bool(_, _)).
-          WillRepeatedly(DoAll(
-                  SetArgPointee<1>(true),
-                  Return(0)));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_new_method_call(_, _, _, _)).
-      WillOnce(Return(msg_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_connection_send_message_with_reply_sync(
-        _, _, _, _, _, _, _)).
-      WillOnce(Return(msg2_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_to_gerror(_, _)).
-      WillOnce(Return(FALSE));
-  bool existing;
-  int ret = badge_is_existing(pkgid3_, &existing);
+  ret = badge_set_display("myappid", 1);
   EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
+  g_main_loop_run(loop);
 
-TEST_F(BadgeTest, badge_create) {
-  EXPECT_CALL(GetMock<SystemInfoMock>(),
-      system_info_get_platform_bool(_, _)).
-          WillRepeatedly(DoAll(
-                  SetArgPointee<1>(true),
-                  Return(0)));
-
-  EXPECT_CALL(GetMock<AulMock>(),
-      aul_app_get_pkgname_bypid(_, _, _)).
-      WillOnce(DoAll(SetArgPointee<1>(*pkgid_),
-                      Return(0)));
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_new_method_call(_, _, _, _)).
-      WillOnce(Return(msg_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_connection_send_message_with_reply_sync(
-        _, _, _, _, _, _, _)).
-      WillOnce(Return(msg2_));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_to_gerror(_, _)).
-      WillOnce(Return(FALSE));
-  int ret = badge_create("pkgname3", "writable");
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
+  EXPECT_TRUE(changed_disp);
+  g_main_loop_unref(loop);
 }
 
-TEST_F(BadgeTest, badge_setting_positive) {
-  badge_setting_h setting;
+TEST_F(BadgeTest, badge_unregister_changed_cb) {
+  bool is_supported = true;
 
   EXPECT_CALL(GetMock<SystemInfoMock>(),
       system_info_get_platform_bool(_, _)).
-      WillRepeatedly(DoAll(SetArgPointee<1>(true),
-                            Return(0)));
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_new_method_call(_, _, _, _)).
-      WillRepeatedly(
-        Invoke([&](const gchar* bus_name, const gchar* obj_path,
-          const gchar* interface_name, const gchar* method_name)
-          -> GDBusMessage* {
-        GDBusMessage* msg =
-            (GDBusMessage*)g_object_new(G_TYPE_OBJECT, nullptr);
-        return msg;
-      }));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_connection_send_message_with_reply_sync(
-        _, _, _, _, _, _, _)).
-      WillRepeatedly(
-        Invoke([&](GDBusConnection* con, GDBusMessage* mesg,
-          GDBusSendMessageFlags flags, gint timeout, volatile guint32* out_serial,
-          GCancellable* cancelable, GError** error)
-          -> GDBusMessage* {
-        GDBusMessage* msg =
-            (GDBusMessage*)g_object_new(G_TYPE_OBJECT, nullptr);
-        return msg;
-      }));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_get_body(_)).
-      WillRepeatedly(
-        Invoke([&](GDBusMessage* message)
-          -> GVariant* {
-          GVariant* reply = g_variant_new("(v)",
-          g_variant_new("(ssi)", pkgid2_, "appid", 1));
-        return reply;
-      }));
-
-  EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_to_gerror(_, _)).
-      WillRepeatedly(Return(FALSE));
-
-  int ret = badge_setting_get_setting_by_appid(&setting, "appid");
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-
-  char* pkgname;
-  ret = badge_setting_get_pkgname(setting, &pkgname);
-  if (pkgname)
-    free(pkgname);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-
-  char* appid;
-  ret = badge_setting_get_appid(setting, &appid);
-  if (appid)
-    free(appid);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-
-  ret = badge_setting_set_allow_to_display(setting, true);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-
-  bool allow;
-  ret = badge_setting_get_allow_to_display(setting, &allow);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-
-  ret = badge_setting_update_setting(setting);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-
-  ret = badge_setting_free_setting(setting);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-TEST_F(BadgeTest, badge_setting_negative) {
-  int ret = badge_setting_get_setting_by_appid(nullptr, nullptr);
-  EXPECT_EQ(ret, BADGE_ERROR_INVALID_PARAMETER);
-
-  char* pkgname;
-  ret = badge_setting_get_pkgname(nullptr, &pkgname);
-  EXPECT_EQ(ret, BADGE_ERROR_INVALID_PARAMETER);
-
-  char* appid;
-  ret = badge_setting_get_appid(nullptr, &appid);
-  EXPECT_EQ(ret, BADGE_ERROR_INVALID_PARAMETER);
-
-  ret = badge_setting_set_allow_to_display(nullptr, true);
-  EXPECT_EQ(ret, BADGE_ERROR_INVALID_PARAMETER);
-
-  bool allow;
-  ret = badge_setting_get_allow_to_display(nullptr, &allow);
-  EXPECT_EQ(ret, BADGE_ERROR_INVALID_PARAMETER);
-
-  ret = badge_setting_update_setting(nullptr);
-  EXPECT_EQ(ret, BADGE_ERROR_INVALID_PARAMETER);
-
-  ret = badge_setting_free_setting(nullptr);
-  EXPECT_EQ(ret, BADGE_ERROR_INVALID_PARAMETER);
-}
-
-TEST_F(BadgeTest, badge_db_get_setting_by_appid) {
-  badge_setting_h setting;
-  int ret = badge_db_get_setting_by_appid(pkgid3_, &setting, 1000);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-  badge_setting_free_setting(setting);
-}
-
-TEST_F(BadgeTest, badge_db_update_setting) {
-  int ret = badge_db_update_setting(pkgid3_, pkgid3_, 1, 1000);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-TEST_F(BadgeTest, badge_db_get_allow_to_display_by_appid) {
-  int allow_to_display;
-  int ret = badge_db_get_allow_to_display_by_appid(
-      pkgid3_, &allow_to_display, 1000);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-TEST_F(BadgeTest, badge_db_update_app_disabled) {
-  int ret = badge_db_update_app_disabled(
-      pkgid3_, true, 1000);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-TEST_F(BadgeTest, badge_db_update_pkg_disabled) {
-  int ret = badge_db_update_pkg_disabled(
-      pkgid3_, true, 1000);
-  EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
-
-extern "C" int pkgmgrinfo_pkginfo_filter_create(
-    pkgmgrinfo_pkginfo_filter_h* handle) {
-  return PMINFO_R_OK;
-}
-
-extern "C" int pkgmgrinfo_pkginfo_filter_add_string(
-    pkgmgrinfo_pkginfo_filter_h handle, const char* property,
-    const char* value) {
-  return PMINFO_R_OK;
-}
-
-extern "C" int pkgmgrinfo_appinfo_filter_add_bool(
-    pkgmgrinfo_appinfo_filter_h handle,
-    const char* property, const bool value) {
-  return PMINFO_R_OK;
-}
-
-extern "C" int pkgmgrinfo_pkginfo_get_pkgname(
-    pkgmgrinfo_pkginfo_h handle, char** pkg_name) {
-  *pkg_name = const_cast<char*>("pkgname");
-  return PMINFO_R_OK;
-}
-
-extern "C" int pkgmgrinfo_appinfo_filter_create(
-    pkgmgrinfo_appinfo_filter_h* handle) {
-  return PMINFO_R_OK;
-}
-
-extern "C" int pkgmgrinfo_appinfo_filter_add_string(
-    pkgmgrinfo_appinfo_filter_h handle, const char* property,
-    const char* value) {
-  return PMINFO_R_OK;
-}
-
-extern "C" int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
-    pkgmgrinfo_pkginfo_filter_h handle,
-    pkgmgrinfo_pkg_list_cb pkg_cb, void* user_data, uid_t uid) {
-  pkg_cb(nullptr, user_data);
-  return PMINFO_R_OK;
-}
-
-extern "C" int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
-    pkgmgrinfo_appinfo_filter_h handle,
-    pkgmgrinfo_app_list_cb app_cb, void* user_data, uid_t uid) {
-
-  return PMINFO_R_OK;
-}
-
-extern "C" int pkgmgrinfo_appinfo_get_appid(
-    pkgmgrinfo_appinfo_h handle, char** appid) {
-  *appid = const_cast<char*>("pkgname");
-  return PMINFO_R_OK;
-}
-
-extern "C" int pkgmgrinfo_appinfo_get_pkgname(
-    pkgmgrinfo_appinfo_h handle, char** pkg_name) {
-  *pkg_name = const_cast<char*>("pkgname");
-  return PMINFO_R_OK;
-}
+      WillRepeatedly(DoAll(SetArgPointee<1>(is_supported),
+                Return(0)));
+  auto cb = [](unsigned int action,
+      const char* app_id, unsigned int count, void* user_data) {
+  };
 
-TEST_F(BadgeTest, badge_setting_insert_package_for_uid) {
-  int ret = badge_setting_insert_package_for_uid(pkgid2_, 1000);
+  int ret = badge_register_changed_cb(cb, nullptr);
   EXPECT_EQ(ret, BADGE_ERROR_NONE);
-}
 
-TEST_F(BadgeTest, badge_setting_delete_package_for_uid) {
-  int ret = badge_setting_delete_package_for_uid(pkgid2_, 1000);
+  ret = badge_unregister_changed_cb(cb);
   EXPECT_EQ(ret, BADGE_ERROR_NONE);
 }
index c2eb730..a4631b3 100644 (file)
 #include <gtest/gtest.h>
 #include <gmock/gmock.h>
 
+//#define LOG_INTERNAL
+
+#ifdef LOG_INTERNAL
+#include <dlog.h>
+
+extern "C" int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...) {
+  printf("%s:", tag);
+  va_list ap;
+  va_start(ap, fmt);
+  vprintf(fmt, ap);
+  va_end(ap);
+  printf("\n");
+
+  return 0;
+}
+#endif
+
 int main(int argc, char** argv) {
   int ret = -1;
 
diff --git a/tidl/badge.tidl b/tidl/badge.tidl
new file mode 100755 (executable)
index 0000000..9f1808a
--- /dev/null
@@ -0,0 +1,29 @@
+protocol 2\r
+\r
+struct BadgeInfo {\r
+  enum Action {\r
+    Create = 0,\r
+    Remove,\r
+    Update,\r
+    ChangedDisplay,\r
+    ServiceReady\r
+  }\r
+\r
+  string PkgName;\r
+  int Count;\r
+}\r
+\r
+[privilege = "http://tizen.org/privilege/notification"]\r
+interface Badge {\r
+  void ChangedCb(BadgeInfo.Action action, string appid, int count) delegate;\r
+\r
+  array<BadgeInfo> GetList();\r
+  bool Insert(string appid, string writable_pkg, string caller);\r
+  bool Delete(string appid, string caller);\r
+  bool SetCount(string appid, string caller, int count);\r
+  int GetCount(string appid);\r
+  bool SetDisplayOption(string appid, string caller, bool isDisplay);\r
+  bool GetDisplayOption(string appid);\r
+  bool Register(ChangedCb cb);\r
+  bool Unregister();\r
+}\r
diff --git a/tidl/prebuild.sh b/tidl/prebuild.sh
new file mode 100755 (executable)
index 0000000..2a4795d
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/bash
+tidlc -p -l C++ -i ./badge.tidl -o badge_proxy
+tidlc -s -l C++ -i ./badge.tidl -o badge_stub
diff --git a/tool/CMakeLists.txt b/tool/CMakeLists.txt
deleted file mode 100644 (file)
index 7b9dae5..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ BADGE_INIT_SRCS)
-ADD_EXECUTABLE(${TARGET_BADGE_INIT}
-  ${BADGE_INIT_SRCS}
-)
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_BADGE_INIT} PUBLIC
-  "${CMAKE_CURRENT_SOURCE_DIR}/../include"
-)
-
-APPLY_PKG_CONFIG(${TARGET_BADGE_INIT} PUBLIC
-  AUL_DEP
-  DLOG_DEPS
-  VCONF_DEPS
-  PKGMGR_DEPS
-  SYSTEM_INFO_DEPS
-  DB_UTIL_DEPS
-  PLATFORM_CONFIG_DEPS
-  PKGMGR_INFO_DEPS
-  SMACK_DEPS
-  GLIB_DEPS
-  GIO_DEPS
-)
-
-
-TARGET_LINK_LIBRARIES(${TARGET_BADGE_INIT} PUBLIC ${TARGET_BADGE})
-SET_TARGET_PROPERTIES(${TARGET_BADGE_INIT} PROPERTIES COMPILE_FLAGS "-fPIE")
-SET_TARGET_PROPERTIES(${TARGET_BADGE_INIT} PROPERTIES LINK_FLAGS "-pie")
-
-INSTALL(TARGETS badge_init DESTINATION bin)
\ No newline at end of file
diff --git a/tool/badge_init.c b/tool/badge_init.c
deleted file mode 100644 (file)
index a6cf681..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 2016 - 2017 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.
- *
- */
-
-#define _GNU_SOURCE
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <errno.h>
-
-#include <badge_setting.h>
-#include <badge_setting_service.h>
-#include <badge_error.h>
-
-#define OWNER_ROOT 0
-
-#ifdef _E
-#undef _E
-#endif
-#define _E(fmt, arg...) fprintf(stderr, "[BADGE_INIT][E][%s,%d] "fmt"\n", \
-                               __func__, __LINE__, ##arg)
-
-static int __is_authorized(void)
-{
-       uid_t uid = getuid();
-
-       if ((uid_t)OWNER_ROOT == uid)
-               return 1;
-       else
-               return 0;
-}
-
-int main(int argc, char *argv[])
-{
-       int ret;
-       uid_t uid = OWNER_ROOT;
-
-       if (!__is_authorized()) {
-               _E("You are not an authorized user!");
-               return -1;
-       }
-
-       if (argc > 2)
-               uid = (uid_t)atoi(argv[2]);
-
-       ret = badge_setting_refresh_setting_table(uid);
-       if (ret != BADGE_ERROR_NONE)
-               _E("badge setting table refresh fail.");
-
-       return ret;
-}