From: pr.jung Date: Mon, 17 Dec 2018 10:50:08 +0000 (+0900) Subject: storage: Add popup and notification as well X-Git-Tag: accepted/tizen/5.0/unified/20181219.063433^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=663b8496576b7761ed4b1ae3a7db7b0eab7e6924;p=platform%2Fcore%2Fsystem%2Fstoraged.git storage: Add popup and notification as well Change-Id: Ide44a71213baa09e4122c61030c4388b03f65e43 Signed-off-by: pr.jung Signed-off-by: lokilee73 --- diff --git a/src/storage/storage.c b/src/storage/storage.c index 545514a..29a9960 100755 --- a/src/storage/storage.c +++ b/src/storage/storage.c @@ -61,6 +61,14 @@ #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) +#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" +#define INTERNAL_STORAGE_NOTIOFF "InternalStorageNotiOff" + enum memnoti_level { MEMNOTI_LEVEL_FULL = 0, MEMNOTI_LEVEL_CRITICAL, @@ -88,6 +96,7 @@ struct storage_config_info { }; static guint memnoti_timer; +static int noti_id; static guint id_booting_done; static guint id_storage_poweroff; @@ -174,7 +183,7 @@ out: } -static void __cb(GVariant *var, void *user_data, GError *err) +static void _popup_cb(GVariant *var, void *user_data, GError *err) { int ret; @@ -207,7 +216,7 @@ static int launch_memory_popup(int num, ...) "PopupLaunch", num, args, - __cb, + _popup_cb, -1, NULL); @@ -216,30 +225,138 @@ static int launch_memory_popup(int num, ...) return ret; } -static int memnoti_popup(enum memnoti_level level) +static void _noti_cb(GVariant *var, void *user_data, GError *err) +{ + int ret; + + if (!var) { + _E("no message [%s]", err->message); + return; + } + + if (!dh_get_param_from_var(var, "(i)", &ret)) { + _E("no message [%s]", g_variant_get_type_string(var)); + goto out; + } + + noti_id = ret; + _D("reply value : %d", ret); + +out: + g_variant_unref(var); +} + +static int remove_notification(void) +{ + const char *param[1]; + char id_str[16]; + int ret; + + snprintf(id_str, sizeof(id_str), "%d", noti_id); + param[0] = id_str; + + ret = dbus_handle_method_sync(POPUP_BUS_NAME, + POPUP_PATH_NOTI, + POPUP_INTERFACE_NOTI, + INTERNAL_STORAGE_NOTIOFF, + "i", + param); + if (ret < 0) + _E("Fail to remove noti : %d", noti_id); + + return ret; +} + +static int create_notification(void) +{ + int ret; + + ret = dbus_handle_method_async_with_reply(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))) { + if (noti_id) { + ret = remove_notification(); + if (ret < 0) + return ret; + noti_id = 0; + } + + 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; +} + +static int process_memory_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 < 0 || 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_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; + } 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); - return launch_memory_popup(2, "_SYSPOPUP_CONTENT_", value); + ret = launch_memory_notification(noti_value); + if (ret < 0) + _E("Fail to launch momory notification : %d", ret); + + return ret; } static void storage_status_broadcast(struct storage_config_info *info, double total, double avail) @@ -280,7 +397,6 @@ static void storage_status_broadcast(struct storage_config_info *info, double to memcleanup_send_broadcast(info, info->current_noti_level, prev_noti_level); } else info->current_noti_level = MEMNOTI_LEVEL_NORMAL; - } static int storage_get_memory_size(const char *path, struct statvfs *s) @@ -326,13 +442,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_memory_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_memory_info(info->current_noti_level); if (ret != 0) info->current_noti_level = MEMNOTI_LEVEL_NORMAL; } @@ -350,7 +472,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;