#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,
};
static guint memnoti_timer;
+static int noti_id;
static struct storage_config_info storage_internal_info = {
.mem_id = MEMORY_INTERNAL,
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;
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)
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;
}
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;