Add lowstorage_full and create_notification, remove_notification 62/195862/2 accepted/tizen/4.0/unified/20181219.154810 submit/tizen_4.0/20181219.044828
authorlokilee73 <changjoo.lee@samsung.com>
Wed, 19 Dec 2018 03:20:16 +0000 (12:20 +0900)
committerlokilee73 <changjoo.lee@samsung.com>
Wed, 19 Dec 2018 03:31:07 +0000 (12:31 +0900)
1. Add lowstorage_full to inform no space in internal memory
2. Add create_notification() and remove_notification()
   to simplify source code

Change-Id: Ibe40e0e14ad7392638e89aac88c6670b23a77756
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
src/storage/storage.c

index 6bd263128994d01204870a0228380a8028feeccd..ad9b00f885edf3d3a3bacf70308486d45a9169dd 100755 (executable)
@@ -59,6 +59,7 @@
 
 #define LOW_STORAGE_WARNING                    "lowstorage_warning"
 #define LOW_STORAGE_CRITICAL                   "lowstorage_critical"
+#define LOW_STORAGE_FULL                       "lowstorage_full"
 #define LOW_STORAGE_REMOVE                     "lowstorage_remove"
 
 #define INTERNAL_STORAGE_NOTION                        "InternalStorageNotiOn"
@@ -166,7 +167,7 @@ static void memcleanup_send_broadcast(struct storage_config_info *info, enum mem
                        SIGNAL_NEED_CLEANUP, "ss", arr);
 }
 
-static void __noti_cb(void *data, DBusMessage *msg, int err)
+static void _noti_cb(void *data, DBusMessage *msg, int err)
 {
        DBusError r_err;
        int ret, id;
@@ -204,50 +205,71 @@ static int launch_memory_popup(int num, ...)
        return ret;
 }
 
-static int launch_memory_notification(char *type)
+static int remove_notification(void)
 {
+       DBusMessage *msg;
        char *param[1];
        char id_str[16];
-       int ret = 0;
+       int ret;
+
+       snprintf(id_str, sizeof(id_str), "%d", noti_id);
+       param[0] = id_str;
+
+       ret = call_dbus_method_sync(POPUP_BUS_NAME,
+                       POPUP_PATH_NOTI,
+                       POPUP_INTERFACE_NOTI,
+                       INTERNAL_STORAGE_NOTIOFF,
+                       "i",
+                       param,
+                       -1,
+                       &msg);
+       if (ret < 0)
+               _E("Fail to remove noti : %d", noti_id);
+
+       return ret;
+}
+
+static int create_notification(void)
+{
+       int ret;
+
+       ret = call_dbus_method_async(POPUP_BUS_NAME,
+                       POPUP_PATH_NOTI,
+                       POPUP_INTERFACE_NOTI,
+                       INTERNAL_STORAGE_NOTION,
+                       NULL,
+                       NULL,
+                       _noti_cb,
+                       -1,
+                       NULL);
+       if (ret < 0)
+               _E("Fail to create noti");
+
+       return ret;
+}
+
+static int launch_memory_notification(char *type)
+{
+       int ret = -1;
 
        if (!type)
                return -EINVAL;
 
-       if (strncmp(type, INTERNAL_STORAGE_NOTION,
-                               sizeof(INTERNAL_STORAGE_NOTION)) == 0) {
-               ret = call_dbus_method_async(POPUP_BUS_NAME,
-                               POPUP_PATH_NOTI,
-                               POPUP_INTERFACE_NOTI,
-                               type,
-                               NULL,
-                               NULL,
-                               __noti_cb,
-                               -1,
-                               NULL);
-       } else if (strncmp(type, INTERNAL_STORAGE_NOTIOFF,
-                               sizeof(INTERNAL_STORAGE_NOTIOFF)) == 0) {
+       if (!strncmp(type, INTERNAL_STORAGE_NOTION, sizeof(INTERNAL_STORAGE_NOTION))) {
                if (noti_id) {
-                       snprintf(id_str, sizeof(id_str), "%d", noti_id);
-                       param[0] = id_str;
-
-                       ret = call_dbus_method_async(POPUP_BUS_NAME,
-                                       POPUP_PATH_NOTI,
-                                       POPUP_INTERFACE_NOTI,
-                                       type,
-                                       "i",
-                                       param,
-                                       NULL,
-                                       -1,
-                                       NULL);
+                       ret = remove_notification();
                        if (ret < 0)
-                               _E("Fail to remove memory noti : %d", noti_id);
-                       else
-                               noti_id = 0;
+                               return ret;
+                       noti_id = 0;
                }
-       } else {
-               _E("Invalid noti type : %d", type);
-               ret = -1;
-       }
+               ret = create_notification();
+       } else if (!strncmp(type, INTERNAL_STORAGE_NOTIOFF, sizeof(INTERNAL_STORAGE_NOTIOFF))) {
+               if (!noti_id)
+                       return -1;
+
+               ret = remove_notification();
+       } else
+               _E("Invalid noti type : %s", type);
 
        return ret;
 }
@@ -259,7 +281,7 @@ static int process_memory_info(enum memnoti_level level)
        char *popup_value = NULL;
        char *noti_value = NULL;
 
-       if (level != MEMNOTI_LEVEL_WARNING && level != MEMNOTI_LEVEL_CRITICAL && level != MEMNOTI_LEVEL_NORMAL) {
+       if (level < 0 || level > MEMNOTI_LEVEL_NORMAL) {
                _E("level check error : %d", level);
                return 0;
        }
@@ -270,6 +292,9 @@ static int process_memory_info(enum memnoti_level level)
        } else if (level == MEMNOTI_LEVEL_CRITICAL) {
                popup_value = LOW_STORAGE_CRITICAL;
                noti_value = INTERNAL_STORAGE_NOTION;
+       } else if (level == MEMNOTI_LEVEL_FULL) {
+               popup_value = LOW_STORAGE_FULL;
+               noti_value = INTERNAL_STORAGE_NOTION;
        } else if (level == MEMNOTI_LEVEL_NORMAL) {
                popup_value = LOW_STORAGE_REMOVE;
                noti_value = INTERNAL_STORAGE_NOTIOFF;