storage: Add popup and notification as well 51/195551/3 accepted/tizen/4.0/unified/20181218.152337 submit/tizen_4.0/20181217.090814
authorpr.jung <pr.jung@samsung.com>
Fri, 14 Dec 2018 06:31:14 +0000 (15:31 +0900)
committerlokilee73 <changjoo.lee@samsung.com>
Mon, 17 Dec 2018 09:01:30 +0000 (18:01 +0900)
Add popup remove, when internal storage becomes normal from warning or critical.
In addition, add notification as well to give memory information to users.

Change-Id: I77551bdeb3c66ad23726f32a96ac52e4b926962d
Signed-off-by: pr.jung <pr.jung@samsung.com>
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
src/shared/dbus_macro.h
src/storage/storage.c

index af7ea0c06f86ef3eb2101b9a36a84a780e29830b..d6fa0821a86ecbe06b53e7d1db65fc46895593a0 100755 (executable)
@@ -98,6 +98,9 @@
 #define POPUP_PATH_SYSTEM                   POPUP_OBJECT_PATH"/System"
 #define POPUP_INTERFACE_SYSTEM              POPUP_INTERFACE_NAME".System"
 
+#define POPUP_PATH_NOTI                     POPUP_OBJECT_PATH"/Noti"
+#define POPUP_INTERFACE_NOTI                POPUP_INTERFACE_NAME".Noti"
+
 /* ODE */
 #define POPUP_METHOD_LAUNCH                 "PopupLaunch"
 #define POPUP_KEY_CONTENT                   "_SYSPOPUP_CONTENT_"
index d6c91a4e09c29a2a3cd6e4fdbbcd17a6cfa75e61..8846274b4f9acc85cee6f6c787a935dcfccf9a2c 100755 (executable)
 
 #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
 
+#define LOW_STORAGE_WARNING                    "lowstorage_warning"
+#define LOW_STORAGE_CRITICAL                   "lowstorage_critical"
+#define LOW_STORAGE_REMOVE                     "lowstorage_remove"
+
+#define INTERNAL_STORAGE_NOTION                        "InternalStorageNotiOn"
+#define INTERNAL_STORAGE_NOTIOFF               "InternalStorageNotiOff"
+
 enum memnoti_level {
        MEMNOTI_LEVEL_FULL = 0,
        MEMNOTI_LEVEL_CRITICAL,
@@ -84,6 +91,7 @@ struct storage_config_info {
 };
 
 static guint memnoti_timer;
+static int noti_id;
 
 static struct storage_config_info storage_internal_info = {
        .mem_id             = MEMORY_INTERNAL,
@@ -158,6 +166,26 @@ 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)
+{
+       DBusError r_err;
+       int ret, id;
+
+       if (!msg)
+               return;
+
+       dbus_error_init(&r_err);
+       ret = dbus_message_get_args(msg, &r_err, DBUS_TYPE_INT32, &id, DBUS_TYPE_INVALID);
+       if (!ret) {
+               _E("no message [%s:%s]", r_err.name, r_err.message);
+               dbus_error_free(&r_err);
+               return;
+       }
+
+       noti_id = id;
+       _D("Inserted memory noti : %d", noti_id);
+}
+
 static int launch_memory_popup(int num, ...)
 {
        int ret;
@@ -176,30 +204,95 @@ static int launch_memory_popup(int num, ...)
        return ret;
 }
 
-static int memnoti_popup(enum memnoti_level level)
+static int launch_memory_notification(char *type)
+{
+       char *param[1];
+       char id_str[16];
+       int ret = 0;
+
+       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 (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);
+                       if (ret < 0)
+                               _E("Fail to remove memory noti : %d", noti_id);
+                       else
+                               noti_id = 0;
+               }
+       } else {
+               _E("Invalid noti type : %d", type);
+               ret = -1;
+       }
+
+       return ret;
+}
+
+static int process_momory_info(enum memnoti_level level)
 {
        int ret = -1;
        int val = -1;
-       char *value = NULL;
+       char *popup_value = NULL;
+       char *noti_value = NULL;
 
-       if (level != MEMNOTI_LEVEL_WARNING && level != MEMNOTI_LEVEL_CRITICAL) {
+       if (level != MEMNOTI_LEVEL_WARNING && level != MEMNOTI_LEVEL_CRITICAL && level != MEMNOTI_LEVEL_NORMAL) {
                _E("level check error : %d", level);
                return 0;
        }
 
-       if (level == MEMNOTI_LEVEL_WARNING)
-               value = "lowstorage_warning";
-       else if (level == MEMNOTI_LEVEL_CRITICAL)
-               value = "lowstorage_critical";
+       if (level == MEMNOTI_LEVEL_WARNING) {
+               popup_value = LOW_STORAGE_WARNING;
+               noti_value = INTERNAL_STORAGE_NOTION;
+       } else if (level == MEMNOTI_LEVEL_CRITICAL) {
+               popup_value = LOW_STORAGE_CRITICAL;
+               noti_value = INTERNAL_STORAGE_NOTION;
+       } else if (level == MEMNOTI_LEVEL_NORMAL) {
+               popup_value = LOW_STORAGE_REMOVE;
+               noti_value = INTERNAL_STORAGE_NOTIOFF;
+       }
 
        ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &val);
        if (val == 0 || ret != 0)
                return -1;
 
-       if (!value)
+       if (!popup_value && !noti_value) {
+               _E("Invalid memnoti level : %d", level);
                return 0;
+       }
+
+       ret = launch_memory_popup(2, "_SYSPOPUP_CONTENT_", popup_value);
+       if (ret < 0)
+               _E("Fail to launch momory popup : %d", ret);
+
+       ret = launch_memory_notification(noti_value);
+       if (ret < 0)
+               _E("Fail to launch momory notification : %d", ret);
 
-       return launch_memory_popup(2, "_SYSPOPUP_CONTENT_", value);
+       return ret;
 }
 
 static void storage_status_broadcast(struct storage_config_info *info, double total, double avail)
@@ -296,13 +389,19 @@ static void init_storage_config_info(const char *path, struct storage_config_inf
                path, dTotal, dAvail, (dAvail*100/dTotal), info->warning_level, info->critical_level, info->full_level);
 }
 
-static void check_internal_storage_popup(struct storage_config_info *info)
+static void check_internal_storage(struct storage_config_info *info)
 {
        static enum memnoti_level old = MEMNOTI_LEVEL_NORMAL;
        int ret;
 
        if (info->current_noti_level < MEMNOTI_LEVEL_NORMAL && info->current_noti_level < old) {
-               ret = memnoti_popup(info->current_noti_level);
+               ret = process_momory_info(info->current_noti_level);
+               if (ret != 0)
+                       info->current_noti_level = MEMNOTI_LEVEL_NORMAL;
+       }
+
+       if (info->current_noti_level == MEMNOTI_LEVEL_NORMAL && info->current_noti_level > old) {
+               ret = process_momory_info(info->current_noti_level);
                if (ret != 0)
                        info->current_noti_level = MEMNOTI_LEVEL_NORMAL;
        }
@@ -320,7 +419,7 @@ static gboolean check_storage_status(gpointer data)
        dTotal = (double)s.f_frsize * s.f_blocks;
        dAvail = (double)s.f_bsize * s.f_bavail;
        storage_status_broadcast(&storage_internal_info, dTotal, dAvail);
-       check_internal_storage_popup(&storage_internal_info);
+       check_internal_storage(&storage_internal_info);
        /* check tmp */
        storage_get_memory_size(MEMORY_STATUS_TMP_PATH, &s);
        dTotal = (double)s.f_frsize * s.f_blocks;