From 18111bc32a68b22e516797570a1ef9445ce3ffcb Mon Sep 17 00:00:00 2001 From: Taeyoung Kim Date: Tue, 28 Jan 2014 21:27:44 +0900 Subject: [PATCH] Remove Unnecessary codes of low memory popup Signed-off-by: Taeyoung Kim Change-Id: I53d46e037aaca0b79172675f368ab5416710f691 --- lowmem-popup/CMakeLists.txt | 11 +- lowmem-popup/src/lowmem.c | 309 +++++++++++++++++++------------------------- lowmem-popup/src/lowmem.h | 24 +--- 3 files changed, 144 insertions(+), 200 deletions(-) diff --git a/lowmem-popup/CMakeLists.txt b/lowmem-popup/CMakeLists.txt index 16503c5..727186d 100755 --- a/lowmem-popup/CMakeLists.txt +++ b/lowmem-popup/CMakeLists.txt @@ -3,7 +3,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(lowmem-popup C) -SET(SRCS ${CMAKE_SOURCE_DIR}/lowmem-popup/src/lowmem.c) +SET(SRCS ${CMAKE_SOURCE_DIR}/lowmem-popup/src/lowmem.c + ${CMAKE_SOURCE_DIR}/share/common.c) IF("${CMAKE_BUILD_TYPE}" STREQUAL "") SET(CMAKE_BUILD_TYPE "Release") @@ -12,9 +13,11 @@ MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lowmem-popup) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/share) +INCLUDE_DIRECTORIES(/usr/include/svi) INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED appcore-efl elementary devman devman_haptic mm-sound sysman syspopup ecore-evas) +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 ") @@ -37,10 +40,10 @@ ADD_DEFINITIONS("-DSLP_DEBUG") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-lsvi") ADD_CUSTOM_TARGET(lowmem.edj - COMMAND edje_cc -id ${CMAKE_SOURCE_DIR}/../images + 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 ) diff --git a/lowmem-popup/src/lowmem.c b/lowmem-popup/src/lowmem.c index 0eac5dd..6c410cf 100755 --- a/lowmem-popup/src/lowmem.c +++ b/lowmem-popup/src/lowmem.c @@ -1,5 +1,7 @@ /* - * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * system-popup + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,19 +14,22 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * */ #include #include #include -#include -#include -#include -#include #include "lowmem.h" #include #include +#include +#include +//#include +//#include +#include +#include "common.h" #define APPLICATION_BG 1 #define INDICATOR_HEIGHT (38) /* the case of 480*800 */ @@ -35,9 +40,16 @@ #include #endif /* ACCT_PROF */ -static const char *process_name = NULL; +#define PROCESS_NOTI_ACT 0 +#define LOWMEM_NOTI_ACT 1 +#define LOWMEM_LEVEL_WARNING "warning" +#define LOWMEM_LEVEL_CRITICAL "critical" -#include +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) { @@ -59,71 +71,19 @@ struct text_part { char *msgid; }; -static struct text_part main_txt[] = { - {"txt_title", N_("Low memory popup"),}, - {"txt_mesg", N_(""),}, -}; - -static Eina_Bool exit_idler_cb(void *data) -{ - elm_exit(); - return ECORE_CALLBACK_CANCEL; -} - -void popup_terminate(void) -{ - if (ecore_idler_add(exit_idler_cb, NULL)) - return; - - exit_idler_cb(NULL); -} - /* App Life cycle funtions */ static void win_del(void *data, Evas_Object *obj, void *event) { popup_terminate(); } -/* Quit */ -static void main_quit_cb(void *data, Evas_Object *obj, const char *emission, - const char *source) -{ - popup_terminate(); -} - -/* Update text font */ -static void update_ts(Evas_Object *eo, struct text_part *tp, int size) -{ - int i; - - if (eo == NULL || tp == NULL || size < 0) - return; - - for (i = 0; i < size; i++) { - if (tp[i].part && tp[i].msgid) - edje_object_part_text_set(eo, tp[i].part, - _(tp[i].msgid)); - } -} - -/* Language changed noti handler */ -static int lang_changed(void *data) -{ - struct appdata *ad = data; - - if (ad->layout_main == NULL) - return 0; - - update_ts(elm_layout_edje_get(ad->layout_main), main_txt, - sizeof(main_txt) / sizeof(main_txt[0])); - return 0; -} - /* Create main window */ static Evas_Object *create_win(const char *name) { Evas_Object *eo; + Ecore_X_Window xwin; int w, h; + unsigned int val = 1; eo = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC); if (eo) { @@ -135,91 +95,12 @@ static Evas_Object *create_win(const char *name) &h); evas_object_resize(eo, w, h); } + xwin = elm_win_xwindow_get(eo); + ecore_x_window_prop_card32_set(xwin, ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL, &val, 1); return eo; } -/* Read from EDJ file */ -static Evas_Object *load_edj(Evas_Object * parent, const char *file, - const char *group) -{ - Evas_Object *eo; - int r; - - eo = elm_layout_add(parent); - if (eo) { - r = elm_layout_file_set(eo, file, group); - if (!r) { - evas_object_del(eo); - return NULL; - } - - evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, - EVAS_HINT_EXPAND); - } - - return eo; -} - -/* 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); - - 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 = 0; - - if (syspopup_has_popup(b)) { - syspopup_reset(b); - } else { - ret = syspopup_create(b, &handler, ad->win_main, ad); - evas_object_show(ad->win_main); - process_name = bundle_get_val(b, "_APP_NAME_"); - if (process_name == NULL) - process_name = "unknown_app"; - - /* Start Main UI */ - lowmem_start((void *)ad); - } - - return 0; -} - -/* Customized print */ -void system_print(const char *format, ...) -{ - /* Un-comment return to disable logs */ - va_list args; - va_start(args, format); - vfprintf(stderr, format, args); - va_end(args); -} - /* Cleanup objects to avoid mem-leak */ void lowmem_cleanup(struct appdata *ad) { @@ -233,9 +114,9 @@ void lowmem_cleanup(struct appdata *ad) } /* Background clicked noti */ -void bg_clicked_cb(void *data, Evas * e, Evas_Object * obj, void *event_info) +void bg_clicked_cb(void *data, Evas_Object * obj, void *event_info) { - system_print("\n system-popup : In BG Noti \n"); + _D("system-popup : In BG Noti "); fflush(stdout); popup_terminate(); } @@ -243,7 +124,7 @@ void bg_clicked_cb(void *data, Evas * e, Evas_Object * obj, void *event_info) void lowmem_clicked_cb(void *data, Evas * e, Evas_Object * obj, void *event_info) { - system_print("\n system-popup : Screen clicked \n"); + _D("system-popup : Screen clicked "); fflush(stdout); popup_terminate(); } @@ -255,30 +136,32 @@ int lowmem_create_indicator(struct appdata *ad) return 0; } -/* Play vibration */ -int lowmem_play_vibration() +static int lowmem_svi_play(void) { - int ret_val = 0; - int dev_handle = 0; - int mode = 0; - - /* Open the haptic device */ - dev_handle = device_haptic_open(DEV_IDX_0, mode); - if (dev_handle < 0) - return -1; - - /* Play a monotone pattern for 1s */ - ret_val = device_haptic_play_monotone(dev_handle, 1000); - device_haptic_close(dev_handle); - if (ret_val < 0) - return -1; + int r = 0; + int handle = 0; + r = svi_init(&handle); //Initialize SVI - return 0; + 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; } void lowmem_timeout_func(void *data) { - system_print("\n System-popup : In Lowmem timeout\n"); + _D(" System-popup : In Lowmem timeout"); /* Cleanup */ lowmem_cleanup(data); @@ -295,15 +178,33 @@ int lowmem_create_and_show_basic_popup(struct appdata *ad) /* Initialization */ char *note = (char *)malloc(MAX_PROCESS_NAME * (sizeof(char))); char note_buf[MAX_PROCESS_NAME] = {0, }; - int ret_val = 0; + char *text; + char *title; if (!note) { - system_print("\n System-popup : can not malloc \n"); + _E("System-popup : can not malloc "); return -1; } - system_print("\n System-popup : process name is %s \n", process_name); - snprintf(note_buf, MAX_PROCESS_NAME, _("IDS_IDLE_POP_PS_CLOSED"), process_name); - snprintf(note, MAX_PROCESS_NAME, "%s %s", _("IDS_COM_POP_NOT_ENOUGH_MEMORY"),note_buf); + + 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); + } /* Add notify */ /* No need to give main window, it will create internally */ @@ -313,7 +214,7 @@ int lowmem_create_and_show_basic_popup(struct appdata *ad) 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", _("IDS_COM_BODY_SYSTEM_INFO_ABB")); + 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")); @@ -341,16 +242,14 @@ int lowmem_start(void *data) if (ret_val != 0) return -1; + /* Play vibration */ + lowmem_svi_play(); + /* Change LCD brightness */ - ret_val = pm_change_state(LCD_NORMAL); +// ret_val = display_change_state(LCD_NORMAL); if (ret_val != 0) return -1; - /* Play vibration */ - ret_val = lowmem_play_vibration(); - if (ret_val == -1) - system_print("\n Lowmem : Play vibration failed \n"); - return 0; } @@ -371,6 +270,64 @@ int app_create(void *data) } +/* 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); + + 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; + + if (syspopup_has_popup(b)) { + syspopup_reset(b); + return 0; + } + ret = syspopup_create(b, &handler, ad->win_main, ad); + 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; + } + + process_name = bundle_get_val(b, "_APP_NAME_"); + if (process_name == NULL) + process_name = "unknown_app"; + lowmem_option = PROCESS_NOTI_ACT; + + +LOWMEM_START: + /* Start Main UI */ + lowmem_start((void *)ad); + return 0; +} int main(int argc, char *argv[]) { @@ -388,7 +345,7 @@ int main(int argc, char *argv[]) memset(&ad, 0x0, sizeof(struct appdata)); ops.data = &ad; - sysconf_set_mempolicy(OOM_IGNORE); + //deviced_conf_set_mempolicy(OOM_IGNORE); return appcore_efl_main(PACKAGE, &argc, &argv, &ops); } diff --git a/lowmem-popup/src/lowmem.h b/lowmem-popup/src/lowmem.h index 09596ee..b9b6c7a 100644 --- a/lowmem-popup/src/lowmem.h +++ b/lowmem-popup/src/lowmem.h @@ -1,5 +1,7 @@ /* - * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * system-popup + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,6 +14,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * */ @@ -30,8 +33,6 @@ #define TEMP_DIR "/tmp" #define PACKAGE "lowmem-popup" #define APPNAME "lowmem-popup" -#define ICON_DIR PREFIX"/apps/org.tizen.lowmem-syspopup/res/images" -#define BG_IMAGE TEMP_DIR"/01_popup_bg.jpg" #define MAIN_W (480) #define MAIN_H (800) #define EDJ_PATH PREFIX"/apps/org.tizen.lowmem-syspopup/res/edje/lowmem" @@ -43,21 +44,4 @@ #define PROCESS_NAME_FILE "/tmp/processname.txt" #define BEAT -struct appdata { - Evas *evas; - Evas_Object *win_main; - Evas_Object *popup; - - Evas_Object *layout_main; /* layout widget based on EDJ */ - - Evas_Object *root_w; - Evas_Object *root_h; - Evas_Object *bg; - Evas_Object *indicator; - - double w_ratio; - double h_ratio; - -}; - #endif /* __DEF_lowmem_H__ */ -- 2.7.4