-
-########################### low memory ###########################
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(lowmem-popup C)
-
-SET(PACKAGE ${PROJECT_NAME})
-
-SET(SRCS ${CMAKE_SOURCE_DIR}/lowmem-popup/src/lowmem.c
- ${CMAKE_SOURCE_DIR}/share/src/common.c)
-
-IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
- SET(CMAKE_BUILD_TYPE "Release")
-ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
-MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
-
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lowmem-popup/src)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/share/src)
-INCLUDE_DIRECTORIES(/usr/include/svi)
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED appcore-efl elementary syspopup ecore-evas deviced dlog)
-
-FOREACH(flag ${pkgs_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag} -g -I/usr/include/elementary-0 ")
-ENDFOREACH(flag)
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
-SET(CMAKE_C_FLAGS_RELEASE "-O2")
-
-FIND_PROGRAM(UNAME NAMES uname)
-EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
-IF("${ARCH}" STREQUAL "arm")
- ADD_DEFINITIONS("-DTARGET")
- MESSAGE("add -DTARGET")
-ENDIF("${ARCH}" STREQUAL "arm")
-
-ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
-ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE}\"")
-ADD_DEFINITIONS("-DSLP_DEBUG")
-
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
-
-ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-lsvi")
-
-ADD_CUSTOM_TARGET(lowmem.edj
- COMMAND edje_cc -id ${CMAKE_SOURCE_DIR}/edcs/icons
- ${CMAKE_SOURCE_DIR}/edcs/lowmem.edc ${CMAKE_BINARY_DIR}/${PROJECT_NAME}/lowmem.edj
- DEPENDS ${CMAKE_SOURCE_DIR}/edcs/lowmem.edc
-)
-ADD_DEPENDENCIES(${PROJECT_NAME} lowmem.edj)
-
-INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/apps/org.tizen.lowmem-syspopup/bin)
-INSTALL(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}/lowmem.edj DESTINATION /usr/apps/org.tizen.lowmem-syspopup/res/edje/lowmem)
-
-# install desktop file & icon
-SET(PREFIX ${CMAKE_INSTALL_PREFIX})
-
-# install manifest xml file
-INSTALL(FILES ${CMAKE_SOURCE_DIR}/data/org.tizen.lowmem-syspopup.xml DESTINATION /usr/share/packages/)
-
-# instatll rule file
-INSTALL(FILES ${CMAKE_SOURCE_DIR}/org.tizen.lowmem-syspopup.rule DESTINATION /opt/etc/smack/accesses.d)
-
-################################# End ##############################################
+ADD_SUBDIRECTORY(src)
#include <stdio.h>
-#include <utilX.h>
-#include <svi.h>
#include <Elementary.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "common.h"
-#define APPLICATION_BG 1
-#define INDICATOR_HEIGHT (38) /* the case of 480*800 */
-#define NEW_INDI
-
-#define PROCESS_NOTI_ACT 0
-#define LOWMEM_NOTI_ACT 1
#define LOWMEM_LEVEL_WARNING "warning"
#define LOWMEM_LEVEL_CRITICAL "critical"
-#define EDJ_PATH PREFIX"/apps/org.tizen.lowmem-syspopup/res/edje/lowmem"
-#define EDJ_NAME EDJ_PATH"/lowmem.edj"
-
-#define MAX_PROCESS_NAME 100
-
-static int lowmem_option = -1;
-
-static const char *process_name = NULL;
-static const char *memnoti_level = NULL;
-static const char *memnoti_size = NULL;
-
-int myterm(bundle *b, void *data)
-{
- return 0;
-}
-
-int mytimeout(bundle *b, void *data)
-{
- return 0;
-}
-
-syspopup_handler handler = {
- .def_term_fn = myterm,
- .def_timeout_fn = mytimeout
-};
-
-struct text_part {
- char *part;
- char *msgid;
-};
+#define BUF_MAX 512
-/* Cleanup objects to avoid mem-leak */
-void lowmem_cleanup(struct appdata *ad)
+void lowmem_ok_clicked(void *data, Evas_Object *obj, void *event_info)
{
- if (ad == NULL)
- return;
-
- if (ad->popup)
- evas_object_del(ad->popup);
- if (ad->layout_main)
- evas_object_del(ad->layout_main);
-}
-
-/* Background clicked noti */
-void bg_clicked_cb(void *data, Evas_Object * obj, void *event_info)
-{
- _D("system-popup : In BG Noti ");
- fflush(stdout);
+ _I("OK clicked");
+ object_cleanup(data);
popup_terminate();
}
-void lowmem_clicked_cb(void *data, Evas * e, Evas_Object * obj,
- void *event_info)
-{
- _D("system-popup : Screen clicked ");
- fflush(stdout);
- popup_terminate();
-}
+static int load_low_storage_popup(struct appdata *ad, char *level)
+{
+ char *content;
+ if (!ad || !level)
+ return -EINVAL;
+
+ if (!strncmp(LOWMEM_LEVEL_WARNING, level, strlen(LOWMEM_LEVEL_WARNING)))
+ content = _("IDS_DAV_BODY_LOW_MEMORY_LEFT_ORANGE");
+ else if (!strncmp(LOWMEM_LEVEL_CRITICAL, level, strlen(LOWMEM_LEVEL_CRITICAL)))
+ content = _("IDS_COM_POP_NOT_ENOUGH_MEMORY");
+ else
+ content = _("IDS_COM_POP_NOT_ENOUGH_MEMORY");
+
+ ad->popup = load_normal_popup(ad,
+ NULL,
+ content,
+ dgettext("sys_string","IDS_COM_SK_OK"),
+ lowmem_ok_clicked,
+ NULL, NULL);
+ if (!(ad->popup)) {
+ _E("FAIL: load_normal_popup()");
+ return -ENOMEM;
+ }
-/* Create indicator bar */
-int lowmem_create_indicator(struct appdata *ad)
-{
- elm_win_indicator_mode_set(ad->win_main, ELM_WIN_INDICATOR_HIDE);
return 0;
}
-static int lowmem_svi_play(void)
+static int load_low_memory_popup(struct appdata *ad, char *process_name)
{
- int r = 0;
- int handle = 0;
- r = svi_init(&handle); //Initialize SVI
+ char text[BUF_MAX];
+ char content[BUF_MAX];
+ char *subtext1, *subtext2;
- if ( r != SVI_SUCCESS ) {
- _E("Cannot initialize SVI.");
- return 0;
- } else {
- r = svi_play(handle, SVI_VIB_OPERATION_LOWBATT, SVI_SND_OPERATION_LOWBATT);
- if (r != SVI_SUCCESS) {
- _E("Cannot play sound or vibration.");
- }
- r = svi_fini(handle); //Finalize SVI
- if (r != SVI_SUCCESS) {
- _E("Cannot close SVI.");
- return 0;
- }
- }
- return 1;
-}
+ if (!ad || !process_name)
+ return -EINVAL;
-void lowmem_timeout_func(void *data)
-{
- _D(" System-popup : In Lowmem timeout");
+ subtext1 = _("IDS_IDLE_POP_PS_CLOSED");
+ subtext2 = _("IDS_COM_POP_NOT_ENOUGH_MEMORY");
+ snprintf(text, sizeof(text), subtext1, process_name);
- /* Cleanup */
- lowmem_cleanup(data);
+ snprintf(content, sizeof(content), "%s %s", subtext2, text);
- /* Now get lost */
- popup_terminate();
-}
-
-/* Basic popup widget */
-int lowmem_create_and_show_basic_popup(struct appdata *ad)
-{
- Evas_Object *btn1;
-
- /* Initialization */
- char *note = (char *)malloc(MAX_PROCESS_NAME * (sizeof(char)));
- char note_buf[MAX_PROCESS_NAME] = {0, };
- char *text;
- char *title;
-
- if (!note) {
- _E("System-popup : can not malloc ");
- return -1;
- }
-
- title = _("IDS_IDLE_BODY_LOW_MEMORY");
-
- if (lowmem_option == PROCESS_NOTI_ACT) {
- _D("System-popup : process name is %s ", process_name);
- text = _("IDS_IDLE_POP_PS_CLOSED");
- snprintf(note_buf, MAX_PROCESS_NAME, text, process_name);
- snprintf(note, MAX_PROCESS_NAME, "%s %s", _("IDS_COM_POP_NOT_ENOUGH_MEMORY"), note_buf);
- } else if (lowmem_option == LOWMEM_NOTI_ACT) {
- char *p;
- _D("System-popup : lowmem noti is %s ", memnoti_level);
-
- if (strncmp(memnoti_level, LOWMEM_LEVEL_WARNING,
- strlen(LOWMEM_LEVEL_WARNING)) == 0) {
- p = _("IDS_DAV_BODY_LOW_MEMORY_LEFT_ORANGE");
- } else {
- p = _("IDS_COM_POP_NOT_ENOUGH_MEMORY");
- }
- snprintf(note, MAX_PROCESS_NAME, "%s", p);
+ ad->popup = load_normal_popup(ad,
+ _("IDS_IDLE_BODY_LOW_MEMORY"),
+ content,
+ dgettext("sys_string","IDS_COM_SK_OK"),
+ lowmem_ok_clicked,
+ NULL, NULL);
+ if (!(ad->popup)) {
+ _E("FAIL: load_normal_popup()");
+ return -ENOMEM;
}
- /* Add notify */
- /* No need to give main window, it will create internally */
- ad->popup = elm_popup_add(ad->win_main);
- evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
- EVAS_HINT_EXPAND);
- elm_object_style_set(ad->popup, "transparent");
- elm_popup_timeout_set(ad->layout_main, 3);
- elm_object_text_set(ad->popup, note);
- elm_object_part_text_set(ad->popup, "title,text", title);
-
- btn1 = elm_button_add(ad->popup);
- elm_object_text_set(btn1, _("IDS_COM_SK_OK"));
- elm_object_part_content_set(ad->popup, "button1", btn1);
- elm_object_style_set(btn1, "popup_button/default");
- evas_object_smart_callback_add(btn1, "clicked", bg_clicked_cb, ad);
-
- Ecore_X_Window xwin;
- xwin = elm_win_xwindow_get(ad->popup);
- ecore_x_netwm_window_type_set(xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
- evas_object_show(ad->popup);
-
- free(note);
-
return 0;
}
-int lowmem_start(void *data)
-{
- struct appdata *ad = data;
- int ret_val = 0;
-
- /* Create and show popup */
- ret_val = lowmem_create_and_show_basic_popup(ad);
- if (ret_val != 0)
- return -1;
-
- /* Play vibration */
- lowmem_svi_play();
-
- /* Change LCD brightness */
-// ret_val = display_change_state(LCD_NORMAL);
- if (ret_val != 0)
- return -1;
-
- return 0;
-}
-
-/* App init */
int app_create(void *data)
{
Evas_Object *win;
struct appdata *ad = data;
int ret;
- /* create window */
+ ad->handler.def_term_fn = NULL;
+ ad->handler.def_timeout_fn = NULL;
+
win = create_win(PACKAGE);
if (win == NULL)
return -1;
}
-/* Terminate noti handler */
static int app_terminate(void *data)
{
struct appdata *ad = data;
- if (ad->layout_main)
- evas_object_del(ad->layout_main);
-
- if (ad->win_main)
- evas_object_del(ad->win_main);
+ release_evas_object(&(ad->win_main));
return 0;
}
-/* Pause/background */
static int app_pause(void *data)
{
return 0;
}
-/* Resume */
static int app_resume(void *data)
{
return 0;
}
-
-/* Reset */
static int app_reset(bundle *b, void *data)
{
struct appdata *ad = data;
int ret;
+ char *level, *process_name;
if (syspopup_has_popup(b)) {
syspopup_reset(b);
return 0;
}
- ret = syspopup_create(b, &handler, ad->win_main, ad);
+
+ ret = syspopup_create(b, &(ad->handler), ad->win_main, ad);
if (ret < 0) {
_E("Failed to create popup(%d)", ret);
return ret;
}
+
evas_object_show(ad->win_main);
- memnoti_level = bundle_get_val(b, "_MEM_NOTI_");
- if (memnoti_level != NULL) {
- lowmem_option = LOWMEM_NOTI_ACT;
- memnoti_size = bundle_get_val(b, "_MEM_SIZE_");
- goto LOWMEM_START;
+ level = (char *)bundle_get_val(b, "_MEM_NOTI_");
+ if (level) {
+ ret = load_low_storage_popup(ad, level);
+ goto out;
}
- process_name = bundle_get_val(b, "_APP_NAME_");
- if (process_name == NULL)
- process_name = "unknown_app";
- lowmem_option = PROCESS_NOTI_ACT;
+ process_name = (char *)bundle_get_val(b, "_APP_NAME_");
+ if (!process_name)
+ process_name = "Unknown app";
+ ret = load_low_memory_popup(ad, process_name);
+out:
+ if (ret < 0)
+ popup_terminate();
-LOWMEM_START:
- /* Start Main UI */
- lowmem_start((void *)ad);
- return 0;
+ return ret;
}
int main(int argc, char *argv[])
{
struct appdata ad;
- /* App life cycle management */
struct appcore_ops ops = {
.create = app_create,
.terminate = app_terminate,
memset(&ad, 0x0, sizeof(struct appdata));
ops.data = &ad;
- //deviced_conf_set_mempolicy(OOM_IGNORE);
-
return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
}