Sent Fail notification disappears from notification panel if launching email app 34/96734/1
authorSan Cho <san.cho@samsung.com>
Tue, 24 May 2016 06:55:52 +0000 (15:55 +0900)
committerintae jeon <intae.jeon@samsung.com>
Thu, 10 Nov 2016 05:04:49 +0000 (21:04 -0800)
[Problem] "Sent Fail" notification disappears from notification panel if launching email app
[Cause & Measure] Cause: emcore_clear_notification() is called if email app is launched, then email-service removes all notification unconditionally.
Measure: set noti type when inserting notification, and classify the sent fail notification when emcore_clear_notification is called.

Change-Id: I6ddd96ff6259356160ccc4e733fba7cc22190105
Signed-off-by: intae, jeon <intae.jeon@samsung.com>
(cherry picked from commit e4f45b7ba6f4edd4094ac937b61abbaf2b70d1f1)

email-common-use/include/email-internal-types.h
email-core/email-core-account.c
email-core/email-core-utils.c
email-core/email-storage/email-storage.c
email-core/include/email-core-utils.h

index a009db3..176762f 100755 (executable)
@@ -45,6 +45,15 @@ extern "C"
 #endif
 
 /* ----------------------------------------------------------------------------- */
+/* notification type */
+#define __NOTI_NEW_MAIL_SINGLE "NEW_MAIL_SINGLE"
+#define __NOTI_NEW_MAIL_MULTI "NEW_MAIL_MULTI"
+#define __NOTI_SENT "SENT"
+#define __NOTI_SENDING "SENDING"
+#define __NOTI_SENT_FAIL "SENT_FAIL"
+
+
+/* ----------------------------------------------------------------------------- */
 /*  Feature definitions */
 /* #define __FEATURE_USING_ACCOUNT_SVC_FOR_ACCOUNT_MANAGEMENT__ */
 #define __FEATURE_USING_ACCOUNT_SVC_FOR_SYNC_STATUS__
index cd049e3..74a164f 100755 (executable)
@@ -532,7 +532,7 @@ INTERNAL_FUNC int emcore_delete_account(char *multi_user_name, int account_id, i
        }
 
        emcore_display_unread_in_badge(multi_user_name);
-       emcore_delete_notification_by_account(multi_user_name, account_id, true);
+       emcore_delete_notification_by_account(multi_user_name, account_id, true, true);
 
        ret = true;
 
index 885e7fb..ad92011 100755 (executable)
@@ -48,7 +48,6 @@
 #include <regex.h>
 #include <pthread.h>
 #include <notification.h>
-#include <notification_type.h>
 #include <notification_internal.h>
 #include <notification_text_domain.h>
 #include <badge.h>
@@ -59,6 +58,7 @@
 #endif /* __FEATURE_USE_DRM_API__ */
 #include <storage.h>
 #include <bundle.h>
+#include <bundle_internal.h>
 #include <curl/curl.h>
 #include <contacts.h>
 #include <contacts_internal.h>
@@ -1551,6 +1551,8 @@ INTERNAL_FUNC int emcore_add_notification(char *multi_user_name, int account_id,
                app_control_add_extra_data(service, "MAIL_ID", buf);
                snprintf(buf, sizeof(buf), "%d", p_mail_data->mailbox_id);
                app_control_add_extra_data(service, "MAILBOX_ID", buf);
+               snprintf(buf, sizeof(buf), "%s", __NOTI_NEW_MAIL_SINGLE);
+               app_control_add_extra_data(service, "NOTI_TYPE", buf);
                app_control_set_app_id(service, NATIVE_EMAIL_APPLICATION_PKG);
 
                app_control_to_bundle(service, &b);
@@ -1572,6 +1574,8 @@ INTERNAL_FUNC int emcore_add_notification(char *multi_user_name, int account_id,
                app_control_add_extra_data(service, "RUN_TYPE", buf);
                snprintf(buf, sizeof(buf), "%d", account_id);
                app_control_add_extra_data(service, "ACCOUNT_ID", buf);
+               snprintf(buf, sizeof(buf), "%s", __NOTI_NEW_MAIL_MULTI);
+               app_control_add_extra_data(service, "NOTI_TYPE", buf);
 
                if (unseen > EMAIL_NOTI_MAX_MAIL_ID)
                    unseen = EMAIL_NOTI_MAX_MAIL_ID;
@@ -1711,7 +1715,7 @@ INTERNAL_FUNC int emcore_add_notification_for_send(char *multi_user_name, int ac
        }
 
        /* Delete the previous noti */
-       emcore_delete_notification_by_account(multi_user_name, account_id, true);
+       emcore_delete_notification_by_account(multi_user_name, account_id, true, true);
        if (g_sending_noti_handle) {
                if ((noti_err = notification_free(g_sending_noti_handle)) != NOTIFICATION_ERROR_NONE)
                        err = EMAIL_ERROR_NOTI;
@@ -1759,6 +1763,17 @@ INTERNAL_FUNC int emcore_add_notification_for_send(char *multi_user_name, int ac
        app_control_add_extra_data(service, "MAIL_ID", buf);
        snprintf(buf, sizeof(buf), "%d", p_mail_data->mailbox_id);
        app_control_add_extra_data(service, "MAILBOX_ID", buf);
+       snprintf(buf, sizeof(buf), "%d", sending_error);
+       app_control_add_extra_data(service, "SENDING_ERROR", buf);
+       if (sending_error == EMAIL_ERROR_NONE) {
+               if (action == EMAIL_ACTION_SEND_MAIL)
+                       snprintf(buf, sizeof(buf), "%s", __NOTI_SENT);
+               else if (action == EMAIL_ACTION_SENDING_MAIL)
+                       snprintf(buf, sizeof(buf), "%s", __NOTI_SENDING);
+       } else {
+               snprintf(buf, sizeof(buf), "%s", __NOTI_SENT_FAIL);
+       }
+       app_control_add_extra_data(service, "NOTI_TYPE", buf);
        app_control_set_app_id(service, NATIVE_EMAIL_APPLICATION_PKG);
 
        app_control_to_bundle(service, &b);
@@ -3336,13 +3351,13 @@ INTERNAL_FUNC int emcore_clear_notifications(char *multi_user_name, int account_
                        goto FINISH_OFF;
                }
 
-               for (i = 0; i < account_count; i++) {
-                       error_code = emcore_delete_notification_by_account(multi_user_name, account_list[i].account_id, true);
+               for(i = 0; i < account_count; i++) {
+                       error_code = emcore_delete_notification_by_account(multi_user_name, account_list[i].account_id, true, false);
                        if (error_code != EMAIL_ERROR_NONE)
                                EM_DEBUG_EXCEPTION("emcore_delete_notification_by_account failed");
                }
        } else {
-               error_code = emcore_delete_notification_by_account(multi_user_name, account_id, true);
+               error_code = emcore_delete_notification_by_account(multi_user_name, account_id, true, false);
                if (error_code != EMAIL_ERROR_NONE)
                        EM_DEBUG_EXCEPTION("emcore_delete_notification_by_account failed");
        }
@@ -3364,31 +3379,83 @@ FINISH_OFF:
 
 #define EAS_EXECUTABLE_PATH "/usr/bin/eas-engine"
 
-INTERNAL_FUNC int emcore_delete_notification_by_account(char *multi_user_name, int account_id, int with_noti_tray)
+INTERNAL_FUNC int emcore_delete_notification_by_account(char *multi_user_name, int account_id, int with_noti_tray, int is_delete_sent_fail_noti)
 {
-       EM_DEBUG_FUNC_BEGIN("account_id [%d]", account_id);
+       EM_DEBUG_FUNC_BEGIN("account_id [%d], with_noti_tray [%d], is_delete_sent_fail_noti: [%d]", account_id, with_noti_tray, is_delete_sent_fail_noti);
        int error_code = EMAIL_ERROR_NONE;
-       int private_id = 0;
-       char vconf_private_id[MAX_PATH] = {0, };
 
-       SNPRINTF(vconf_private_id, sizeof(vconf_private_id), "%s/%d", VCONF_KEY_NOTI_PRIVATE_ID, account_id);
-       if (vconf_get_int(vconf_private_id, &private_id) != 0) {
-               EM_DEBUG_EXCEPTION("vconf_get_int failed");
-       }
 #ifdef __FEATURE_NOTIFICATION_ENABLE__
        notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+    notification_h noti = NULL;
+       notification_h noti_to_be_deleted = NULL;
+       notification_list_h noti_list = NULL;
+       notification_list_h head_noti_list = NULL;
+       bundle *noti_args = NULL;
 
-       if ((noti_err = notification_delete_by_priv_id(NATIVE_EMAIL_APPLICATION_PKG, NOTIFICATION_TYPE_NOTI, private_id)) != NOTIFICATION_ERROR_NONE) {
-               EM_DEBUG_EXCEPTION("notification_delete_by_priv_id failed [%d]", noti_err);
+       noti_err = notification_get_list(NOTIFICATION_TYPE_NONE, -1, &noti_list);
+       if (noti_err != NOTIFICATION_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("notification_get_list failed: [%d]", noti_err);
                error_code = EMAIL_ERROR_NOTI;
+               goto FINISH_OFF;
        }
 
-       if (with_noti_tray) {
-               if ((noti_err = notification_delete_by_priv_id(NATIVE_EMAIL_APPLICATION_PKG, NOTIFICATION_TYPE_ONGOING, private_id)) != NOTIFICATION_ERROR_NONE) {
-                       EM_DEBUG_EXCEPTION("notification_delete_by_priv_id failed [%d]", noti_err);
-                       error_code = EMAIL_ERROR_NOTI;
+       while (noti_list != NULL) {
+               noti = notification_list_get_data(noti_list);
+               noti_err = notification_get_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &noti_args);
+               if (!noti_args) {
+                       noti_err = notification_get_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH, NULL, &noti_args);
+                       if (!noti_args) {
+                               noti_list = notification_list_get_next(noti_list);
+                               continue;
+                       }
+               }
+
+               const char *account_id_str = bundle_get_val(noti_args, "ACCOUNT_ID");
+               const char *noti_type_str = bundle_get_val(noti_args, "NOTI_TYPE");
+               if (!account_id_str || !noti_type_str) {
+                       noti_list = notification_list_get_next(noti_list);
+                       continue;
+               }
+               EM_DEBUG_LOG("account_id_str: [%s]", account_id_str);
+               EM_DEBUG_LOG("noti_type_str: [%s]", noti_type_str);
+               // noti_type_str: NEW_MAIL_SINGLE, NEW_MAIL_MULTI, SENT, SENT_FAIL, SENDING
+               if (account_id_str && (atoi(account_id_str) == account_id)) {
+                       if (!g_strcmp0(noti_type_str, __NOTI_NEW_MAIL_SINGLE) ||
+                                       !g_strcmp0(noti_type_str, __NOTI_NEW_MAIL_MULTI) ||
+                                       !g_strcmp0(noti_type_str, __NOTI_SENT)) {
+                               // normal notification
+                               noti_to_be_deleted = noti;
+                       } else if (with_noti_tray && !g_strcmp0(noti_type_str, __NOTI_SENDING)) {
+                               // sending ongoing notification
+                               noti_to_be_deleted = noti;
+                       } else if (!g_strcmp0(noti_type_str, __NOTI_SENT_FAIL)) {
+                               // sent failed notification
+                               if (is_delete_sent_fail_noti) {
+                                       noti_to_be_deleted = noti;
+                               } else {
+                                       const char *error_str = bundle_get_val(noti_args, "SENDING_ERROR");
+                                       EM_DEBUG_LOG("There is a notification for sending error, not clear this notification [%s].", error_str);
+                               }
+                       }
+               }
+
+               if (noti_to_be_deleted) {
+                       noti_list = notification_list_remove(noti_list, noti_to_be_deleted);
+                       notification_delete(noti_to_be_deleted);
+                       noti_to_be_deleted = NULL;
+                       // maintain head pointer for free
+                       head_noti_list = notification_list_get_head(head_noti_list);
+               } else {
+                       // maintain head pointer for free
+                       head_noti_list = notification_list_get_head(head_noti_list);
+                       noti_list = notification_list_get_next(noti_list);
                }
+               noti_args = NULL;
        }
+
+FINISH_OFF:
+       if (head_noti_list)
+               notification_free_list(head_noti_list);
 #endif /* __FEATURE_NOTIFICATION_ENABLE__ */
        EM_DEBUG_FUNC_END();
        return error_code;
index ff45094..250fe2a 100755 (executable)
@@ -11332,6 +11332,7 @@ INTERNAL_FUNC int emstorage_free_attachment(emstorage_attachment_tbl_t** attachm
 
 INTERNAL_FUNC int emstorage_begin_transaction(char *multi_user_name, void *d1, void *d2, int *err_code)
 {
+       EM_DEBUG_FUNC_BEGIN();
        EM_PROFILE_BEGIN(emStorageBeginTransaction);
        int ret = true;
 
index 33c8663..ae4aa0e 100755 (executable)
@@ -110,7 +110,7 @@ INTERNAL_FUNC int emcore_add_notification(char *multi_user_name, int account_id,
 INTERNAL_FUNC int emcore_add_notification_for_send(char *multi_user_name, int account_id, int mail_id, email_action_t action, int sending_error, unsigned long display);
 INTERNAL_FUNC void emcore_update_notification_for_send(int account_id, int mail_id, double progress);
 INTERNAL_FUNC int emcore_delete_notification_for_read_mail(int mail_id);
-INTERNAL_FUNC int emcore_delete_notification_by_account(char *multi_user_name, int account_id, int with_noti_tray);
+INTERNAL_FUNC int emcore_delete_notification_by_account(char *multi_user_name, int account_id, int with_noti_tray, int is_delete_sent_fail_noti);
 
 INTERNAL_FUNC int emcore_show_user_message(char *multi_user_name, int id, email_action_t action, int error);