Add the callback func for app_enabled/disabled 52/102052/10 accepted/tizen/3.0/common/20161221.180525 accepted/tizen/3.0/ivi/20161221.005136 accepted/tizen/3.0/mobile/20161221.005215 accepted/tizen/3.0/tv/20161221.004937 accepted/tizen/3.0/wearable/20161221.005036 submit/tizen_3.0/20161219.021225
authorMyungki Lee <mk5004.lee@samsung.com>
Fri, 16 Dec 2016 05:38:28 +0000 (14:38 +0900)
committerMyungki Lee <mk5004.lee@samsung.com>
Fri, 16 Dec 2016 05:38:28 +0000 (14:38 +0900)
- Update the app_disabled value of setting db

Change-Id: Ie02ac64bbb93888da67fea589ee59a83dd1f4443
Signed-off-by: Myungki Lee <mk5004.lee@samsung.com>
include/notification_service.h
include/pkgmgr.h
src/notification_service.c
src/pkgmgr.c
src/service_common.c

index a841990..1e9c77d 100755 (executable)
@@ -44,5 +44,6 @@ int notification_load_dnd_allow_exception(GVariant *parameters, GVariant **reply
 int notification_update_dnd_allow_exception(GVariant *parameters, GVariant **reply_body, uid_t uid);
 int notification_send_noti_event(GVariant *parameters, GVariant **reply_body);
 int notification_register_dbus_interface();
+int notification_delete_noti_by_appid(const char *appid, uid_t uid);
 
 /* End of a file */
index 9eb3c32..0ac0524 100755 (executable)
@@ -19,7 +19,9 @@ enum pkgmgr_event_type {
        PKGMGR_EVENT_INSTALL,
        PKGMGR_EVENT_UPDATE,
        PKGMGR_EVENT_UNINSTALL,
-       PKGMGR_EVENT_RECOVER
+       PKGMGR_EVENT_RECOVER,
+       PKGMGR_EVENT_APP_ENABLE,
+       PKGMGR_EVENT_APP_DISABLE,
 };
 
 enum pkgmgr_status {
@@ -27,7 +29,7 @@ enum pkgmgr_status {
        PKGMGR_STATUS_PROCESSING,
        PKGMGR_STATUS_COMMAND,
        PKGMGR_STATUS_END,
-       PKGMGR_STATUS_ERROR
+       PKGMGR_STATUS_ERROR,
 };
 
 extern int pkgmgr_init(void);
index 0720333..2eb857e 100755 (executable)
@@ -1814,6 +1814,50 @@ int notification_send_noti_event(GVariant *parameters, GVariant **reply_body)
        return ret;
 }
 
+HAPI int notification_delete_noti_by_appid(const char *appid, uid_t uid)
+{
+       GVariant *deleted_noti_list;
+       GVariantBuilder *builder;
+       int num_deleted = 0;
+       int *list_deleted = NULL;
+       int ret;
+       int i;
+
+       ret = notification_noti_delete_all(NOTIFICATION_TYPE_NONE, appid, &num_deleted, &list_deleted, uid);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ErrPrint("failed to delete notifications:%d\n", ret);
+               if (list_deleted != NULL)
+                       free(list_deleted);
+               return ret;
+       }
+
+       if (num_deleted > 0) {
+               builder = g_variant_builder_new(G_VARIANT_TYPE("a(i)"));
+
+               for (i = 0; i < num_deleted; i++)
+                       g_variant_builder_add(builder, "(i)", *(list_deleted + i));
+
+               deleted_noti_list = g_variant_new("(a(i)i)", builder, uid);
+               ret = send_notify(deleted_noti_list, "delete_multiple_notify", &_monitoring_hash, PROVIDER_NOTI_INTERFACE_NAME, uid);
+               g_variant_builder_unref(builder);
+               g_variant_unref(deleted_noti_list);
+               if (ret != NOTIFICATION_ERROR_NONE) {
+                       ErrPrint("failed to send notify:%d\n", ret);
+                       return ret;
+               }
+
+               for (i = 0; i < num_deleted; i++) {
+                       ret = __delete_sender_info(*(list_deleted + i), uid);
+                       if (ret != NOTIFICATION_ERROR_NONE)
+                               return ret;
+               }
+
+               free(list_deleted);
+       }
+
+       return ret;
+}
+
 static void _notification_data_init(void)
 {
        int property = 0;
index dc2f2e5..6db76f1 100755 (executable)
@@ -46,6 +46,8 @@ static struct {
        Eina_List *update_event;
        Eina_List *download_event;
        Eina_List *recover_event;
+       Eina_List *app_enable_event;
+       Eina_List *app_disable_event;
 } s_info = {
        .listen_pc = NULL,
        .item_list = NULL,
@@ -55,6 +57,8 @@ static struct {
        .update_event = NULL,
        .download_event = NULL,
        .recover_event = NULL,
+       .app_enable_event = NULL,
+       .app_disable_event = NULL,
 };
 
 struct event_item {
@@ -117,6 +121,28 @@ static inline void invoke_recover_event_handler(uid_t uid, const char *pkgname,
        }
 }
 
+static inline void invoke_app_enable_event_handler(uid_t uid, const char *pkgname, enum pkgmgr_status status, double value)
+{
+       Eina_List *l;
+       struct event_item *item;
+
+       EINA_LIST_FOREACH(s_info.app_enable_event, l, item) {
+               if (item->cb)
+                       item->cb(uid, pkgname, status, value, item->data);
+       }
+}
+
+static inline void invoke_app_disable_event_handler(uid_t uid, const char *pkgname, enum pkgmgr_status status, double value)
+{
+       Eina_List *l;
+       struct event_item *item;
+
+       EINA_LIST_FOREACH(s_info.app_disable_event, l, item) {
+               if (item->cb)
+                       item->cb(uid, pkgname, status, value, item->data);
+       }
+}
+
 static inline void invoke_callback(uid_t uid, const char *pkgname, struct item *item, double value)
 {
        switch (item->type) {
@@ -135,6 +161,12 @@ static inline void invoke_callback(uid_t uid, const char *pkgname, struct item *
        case PKGMGR_EVENT_RECOVER:
                invoke_recover_event_handler(uid, pkgname, item->status, value);
                break;
+       case PKGMGR_EVENT_APP_ENABLE:
+               invoke_app_enable_event_handler(uid, pkgname, item->status, value);
+               break;
+       case PKGMGR_EVENT_APP_DISABLE:
+               invoke_app_disable_event_handler(uid, pkgname, item->status, value);
+               break;
        default:
                ErrPrint("Unknown type: %d\n", item->type);
                break;
@@ -161,6 +193,12 @@ static inline int is_valid_status(struct item *item, const char *status)
        case PKGMGR_EVENT_RECOVER:
                expected_status = "recover";
                break;
+       case PKGMGR_EVENT_APP_ENABLE:
+               expected_status = "app_enable_app";
+               break;
+       case PKGMGR_EVENT_APP_DISABLE:
+               expected_status = "app_disable_app";
+               break;
        default:
                return 0;
        }
@@ -221,6 +259,10 @@ static int start_cb(uid_t uid, const char *pkgname, const char *val, void *data)
                item->type = PKGMGR_EVENT_UPDATE;
        } else if (!strcasecmp(val, "recover")) {
                item->type = PKGMGR_EVENT_RECOVER;
+       } else if (!strcasecmp(val, "enable_app")) {
+               item->type = PKGMGR_EVENT_APP_ENABLE;
+       } else if (!strcasecmp(val, "disable_app")) {
+               item->type = PKGMGR_EVENT_APP_DISABLE;
        } else {
                free(item->pkgname);
                free(item);
@@ -426,7 +468,9 @@ static struct pkgmgr_handler {
        { NULL, NULL },
 };
 
-static int pkgmgr_cb(uid_t target_uid, int req_id, const char *type, const char *pkgname, const char *key, const char *val, const void *pmsg, void *data)
+static int status_cb(uid_t target_uid, int req_id, const char *type,
+               const char *pkgname, const char *key, const char *val,
+               const void *pmsg, void *data)
 {
        register int i;
        int ret;
@@ -445,6 +489,27 @@ static int pkgmgr_cb(uid_t target_uid, int req_id, const char *type, const char
        return SERVICE_COMMON_ERROR_NONE;
 }
 
+static int app_status_cb(uid_t target_uid, int req_id, const char *pkg_type,
+               const char *pkgid, const char *appid, const char *key, const char *val,
+               const void *pmsg, void *data)
+{
+       register int i;
+       int ret;
+
+       for (i = 0; handler[i].key; i++) {
+               if (strcasecmp(key, handler[i].key))
+                       continue;
+
+               ret = handler[i].func(target_uid, appid, val, data);
+               if (ret < 0) {
+                       DbgPrint("REQ[%d], UID[%d], appid[%s], type[%s], key[%s], val[%s], ret = %d\n",
+                                       req_id, target_uid, appid, pkg_type, key, val, ret);
+               }
+       }
+
+       return SERVICE_COMMON_ERROR_NONE;
+}
+
 HAPI int pkgmgr_init(void)
 {
        if (s_info.listen_pc)
@@ -454,7 +519,11 @@ HAPI int pkgmgr_init(void)
        if (!s_info.listen_pc)
                return SERVICE_COMMON_ERROR_FAULT;
 
-       if (pkgmgr_client_listen_status(s_info.listen_pc, pkgmgr_cb, NULL) != PKGMGR_R_OK)
+       /* the pkgmgr api returns an id greater than 1 */
+       if (pkgmgr_client_listen_status(s_info.listen_pc, status_cb, NULL) <= 0)
+               return SERVICE_COMMON_ERROR_FAULT;
+
+       if (pkgmgr_client_listen_app_status(s_info.listen_pc, app_status_cb, NULL) <= 0)
                return SERVICE_COMMON_ERROR_FAULT;
 
        return SERVICE_COMMON_ERROR_NONE;
@@ -493,6 +562,14 @@ HAPI int pkgmgr_fini(void)
                free(item);
        }
 
+       EINA_LIST_FREE(s_info.app_enable_event, item) {
+               free(item);
+       }
+
+       EINA_LIST_FREE(s_info.app_disable_event, item) {
+               free(item);
+       }
+
        EINA_LIST_FREE(s_info.item_list, ctx) {
                free(ctx->pkgname);
                free(ctx->icon);
@@ -531,6 +608,12 @@ HAPI int pkgmgr_add_event_callback(enum pkgmgr_event_type type, int (*cb)(uid_t
        case PKGMGR_EVENT_RECOVER:
                s_info.recover_event = eina_list_prepend(s_info.recover_event, item);
                break;
+       case PKGMGR_EVENT_APP_ENABLE:
+               s_info.app_enable_event = eina_list_prepend(s_info.app_enable_event, item);
+               break;
+       case PKGMGR_EVENT_APP_DISABLE:
+               s_info.app_disable_event = eina_list_prepend(s_info.app_disable_event, item);
+               break;
        default:
                free(item);
                return SERVICE_COMMON_ERROR_INVALID_PARAMETER;
@@ -596,6 +679,26 @@ HAPI void *pkgmgr_del_event_callback(enum pkgmgr_event_type type, int (*cb)(uid_
                        }
                }
                break;
+       case PKGMGR_EVENT_APP_ENABLE:
+               EINA_LIST_FOREACH(s_info.app_enable_event, l, item) {
+                       if (item->cb == cb && item->data == data) {
+                               s_info.app_enable_event = eina_list_remove(s_info.app_enable_event, item);
+                               cbdata = item->data;
+                               free(item);
+                               break;
+                       }
+               }
+               break;
+       case PKGMGR_EVENT_APP_DISABLE:
+               EINA_LIST_FOREACH(s_info.app_disable_event, l, item) {
+                       if (item->cb == cb && item->data == data) {
+                               s_info.app_disable_event = eina_list_remove(s_info.app_disable_event, item);
+                               cbdata = item->data;
+                               free(item);
+                               break;
+                       }
+               }
+               break;
        default:
                ErrPrint("Invalid type\n");
                break;
index 39c3a2a..97da6fe 100755 (executable)
 #include <unistd.h>
 #include <gio/gio.h>
 #include <dlog.h>
-#include <notification.h>
 #include <notification_setting.h>
 #include <notification_setting_internal.h>
+#include <notification_setting_service.h>
 #include <notification_noti.h>
 #include <badge_setting.h>
 #include <badge_setting_service.h>
+#include <package-manager.h>
 
-#include "service_common.h"
 #include "debug.h"
-
 #include "pkgmgr.h"
+#include "service_common.h"
 #include "notification_service.h"
 #include "badge_service.h"
 #ifndef WEARABLE
@@ -461,6 +461,25 @@ static int _package_uninstall_cb(uid_t uid, const char *pkgname, enum pkgmgr_sta
                badge_setting_delete_package_for_uid(pkgname, uid);
                notification_noti_delete_template(pkgname);
        }
+
+       return 0;
+}
+
+static int _app_enabled_cb(uid_t uid, const char *appid, enum pkgmgr_status status, double value, void *data)
+{
+       if (status == PKGMGR_STATUS_END)
+               notification_setting_db_update_app_disabled(appid, false, uid);
+
+       return 0;
+}
+
+static int _app_disabled_cb(uid_t uid, const char *appid, enum pkgmgr_status status, double value, void *data)
+{
+       if (status == PKGMGR_STATUS_END) {
+               notification_delete_noti_by_appid(appid, uid);
+               notification_setting_db_update_app_disabled(appid, true, uid);
+       }
+
        return 0;
 }
 
@@ -470,4 +489,6 @@ void service_common_init(void)
        pkgmgr_add_event_callback(PKGMGR_EVENT_INSTALL, _package_install_cb, NULL);
        pkgmgr_add_event_callback(PKGMGR_EVENT_UPDATE, _package_install_cb, NULL);
        pkgmgr_add_event_callback(PKGMGR_EVENT_UNINSTALL, _package_uninstall_cb, NULL);
+       pkgmgr_add_event_callback(PKGMGR_EVENT_APP_ENABLE, _app_enabled_cb, NULL);
+       pkgmgr_add_event_callback(PKGMGR_EVENT_APP_DISABLE, _app_disabled_cb, NULL);
 }