diff options
Diffstat (limited to 'src/menu_daemon.c')
-rwxr-xr-x[-rw-r--r--] | src/menu_daemon.c | 360 |
1 files changed, 264 insertions, 96 deletions
diff --git a/src/menu_daemon.c b/src/menu_daemon.c index a33e193..be0cc94 100644..100755 --- a/src/menu_daemon.c +++ b/src/menu_daemon.c @@ -1,9 +1,5 @@ /* - * starter - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * Copyright (c) 2000 - 2015 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. @@ -16,11 +12,11 @@ * 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 <ail.h> #include <aul.h> +#include <app.h> #include <db-util.h> #include <Elementary.h> #include <errno.h> @@ -33,11 +29,12 @@ #include <sys/wait.h> #include <unistd.h> #include <vconf.h> +//#include <bincfg.h> #include "hw_key.h" #include "util.h" -#include "xmonitor.h" - +//#include "xmonitor.h" +#include "dbus-util.h" int errno; @@ -48,8 +45,10 @@ int errno; #if !defined(VCONFKEY_SVOICE_PACKAGE_NAME) #define VCONFKEY_SVOICE_PACKAGE_NAME "db/svoice/package_name" #endif +#define HOME_TERMINATED "home_terminated" +#define ISTRUE "TRUE" - +#define RELAUNCH_TASKMGR 0 // Define prototype of the "hidden API of AUL" //extern int aul_listen_app_dead_signal(int (*func)(int signal, void *data), void *data); @@ -59,25 +58,45 @@ int errno; static struct info { pid_t home_pid; pid_t tray_pid; + pid_t taskmgr_pid; pid_t volume_pid; int safe_mode; int cradle_status; int pm_key_ignore; int power_off; char *svoice_pkg_name; + char *taskmgr_pkg_name; } s_info = { .home_pid = (pid_t)-1, .tray_pid = (pid_t)-1, + .taskmgr_pid = (pid_t)-1, .volume_pid = (pid_t)-1, .safe_mode = -1, .cradle_status = -1, .pm_key_ignore = -1, .power_off = 0, .svoice_pkg_name = NULL, + .taskmgr_pkg_name = NULL, }; +inline char *menu_daemon_get_selected_pkgname(void) +{ + char *pkgname = NULL; + + pkgname = vconf_get_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME); + retv_if(NULL == pkgname, NULL); + + return pkgname; +} + +char *menu_daemon_get_taskmgr_pkgname(void) +{ + return s_info.taskmgr_pkg_name; +} + + #define VCONFKEY_IDLE_SCREEN_SAFEMODE "memory/idle-screen/safemode" int menu_daemon_is_safe_mode(void) { @@ -114,6 +133,7 @@ int menu_daemon_open_app(const char *pkgname) register int i; int r = AUL_R_OK; for (i = 0; i < RETRY_COUNT; i ++) { + _D("pkgname: %s", pkgname); r = aul_open_app(pkgname); if (0 <= r) return r; else { @@ -132,16 +152,39 @@ int menu_daemon_launch_app(const char *pkgname, bundle *b) { register int i; int r = AUL_R_OK; - for (i = 0; i < RETRY_COUNT; i ++) { - r = aul_launch_app(pkgname, b); - if (0 <= r) return r; - else { - _D("aul_launch_app error(%d)", r); - _F("cannot launch an app(%s) by %d", pkgname, r); + pkgmgrinfo_appinfo_filter_h handle = NULL; + bool enabled = false; + + if (PMINFO_R_OK != pkgmgrinfo_appinfo_get_appinfo(pkgname, &handle)) { + _E("Cannot get the pkginfo"); + return -77; + } + if (PMINFO_R_OK != pkgmgrinfo_appinfo_is_enabled(handle, &enabled)) { + _E("Cannot get if app is enabled or not"); + pkgmgrinfo_appinfo_destroy_appinfo(handle); + return -77; + } + + if (enabled) { + for (i = 0; i < RETRY_COUNT; i ++) { + r = aul_launch_app(pkgname, b); + if (0 <= r){ + pkgmgrinfo_appinfo_destroy_appinfo(handle); + return r; + } + else { + _D("aul_launch_app error(%d)", r); + _F("cannot launch an app(%s) by %d", pkgname, r); + } + usleep(500000); } - usleep(500000); + } + else { + _SECURE_E("%s is disabled, so can't launch this", pkgname); + r = -77; } + pkgmgrinfo_appinfo_destroy_appinfo(handle); return r; } @@ -150,19 +193,34 @@ int menu_daemon_launch_app(const char *pkgname, bundle *b) void menu_daemon_launch_app_tray(void) { bundle *kb = NULL; + char *pkgname = NULL; _D("launch App-tray"); + + pkgname = menu_daemon_get_selected_pkgname(); + if (!pkgname) + return; + _SECURE_D("home pkg_name : %s", pkgname); + + //Check preloaded Homescreen + if (!strncmp(pkgname, EASY_HOME_PKG_NAME, strlen(pkgname))) { + pkgname = EASY_APPS_PKG_NAME; + } else if (!strncmp(pkgname, HOMESCREEN_PKG_NAME, strlen(pkgname))) { + pkgname = HOMESCREEN_PKG_NAME; + } + _SECURE_D("apps pkg_name : %s", pkgname); + + kb = bundle_create(); bundle_add(kb, "HIDE_LAUNCH", "0"); + bundle_add(kb, "SHOW_APPS", "TRUE"); - s_info.tray_pid = menu_daemon_launch_app(APP_TRAY_PKG_NAME, kb); + s_info.tray_pid = menu_daemon_launch_app(pkgname, kb); if (s_info.tray_pid < 0) { - _SECURE_E("Failed to reset %s", APP_TRAY_PKG_NAME); + _SECURE_E("Failed to reset %s", pkgname); } else if (s_info.tray_pid > 0) { - if (-1 == deviced_conf_set_mempolicy_bypid(s_info.tray_pid, OOM_IGNORE)) { - _E("Cannot set the memory policy for App tray(%d)", s_info.tray_pid); - } else { - _D("Set the memory policy for App tray(%d)", s_info.tray_pid); + if(starter_dbus_set_oomadj(s_info.tray_pid, OOM_ADJ_VALUE_HOMESCREEN) < 0){ + _E("failed to send oom dbus signal"); } } @@ -179,35 +237,21 @@ bool menu_daemon_is_homescreen(pid_t pid) -inline char *menu_daemon_get_selected_pkgname(void) -{ - char *pkgname = NULL; - - pkgname = vconf_get_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME); - retv_if(NULL == pkgname, NULL); - - return pkgname; -} - - -/* NOTE: THIS FUNCTION Is ONLY USED FOR CONFIDENTIAL FEATURE. REMOVE ME */ -static inline void _hide_launch_app_tray(void) +static inline void _hide_launch_task_mgr(void) { bundle *kb = NULL; - _D("Hide-launch App-tray"); + _D("Hide to launch Taskmgr"); kb = bundle_create(); bundle_add(kb, "HIDE_LAUNCH", "1"); - s_info.tray_pid = menu_daemon_launch_app(APP_TRAY_PKG_NAME, kb); - if (s_info.tray_pid < 0) { + s_info.taskmgr_pid = menu_daemon_launch_app(menu_daemon_get_taskmgr_pkgname(), kb); + if (s_info.taskmgr_pid < 0) { _SECURE_E("Failed to reset %s", APP_TRAY_PKG_NAME); - } else if (s_info.tray_pid > 0) { - if (-1 == deviced_conf_set_mempolicy_bypid(s_info.tray_pid, OOM_IGNORE)) { - _E("Cannot set the memory policy for App tray(%d)", s_info.tray_pid); - } else { - _E("Set the memory policy for App tray(%d)", s_info.tray_pid); + } else if (s_info.taskmgr_pid > 0) { + if(starter_dbus_set_oomadj(s_info.taskmgr_pid, OOM_ADJ_VALUE_DEFAULT) < 0){ + _E("failed to send oom dbus signal"); } } @@ -247,74 +291,107 @@ static void _check_home_screen_package(void) } } +#if 0 /* Homescreen pkg is changed */ if (_exist_package(CLUSTER_HOME_PKG_NAME)) { if (0 != vconf_set_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, CLUSTER_HOME_PKG_NAME)) { _SECURE_E("Cannot set value(%s) into key(%s)", VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, CLUSTER_HOME_PKG_NAME); } else return; } +#else + if (_exist_package(HOMESCREEN_PKG_NAME)) { + if (0 != vconf_set_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, HOMESCREEN_PKG_NAME)) { + _SECURE_E("Cannot set value(%s) into key(%s)", VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, HOMESCREEN_PKG_NAME); + } else return; + } +#endif if (_exist_package(MENU_SCREEN_PKG_NAME)) { if (0 != vconf_set_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, MENU_SCREEN_PKG_NAME)) { _SECURE_E("Cannot set value(%s) into key(%s)", VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, MENU_SCREEN_PKG_NAME); } else return; } + _E("Invalid Homescreen..!!"); } -inline void menu_daemon_open_homescreen(const char *pkgname) +#define SERVICE_OPERATION_MAIN_KEY "__APP_SVC_OP_TYPE__" +#define SERVICE_OPERATION_MAIN_VALUE "http://tizen.org/appcontrol/operation/main" +inline int menu_daemon_open_homescreen(const char *pkgname) { char *homescreen = NULL; char *tmp = NULL; - if (menu_daemon_is_safe_mode()) { - homescreen = CLUSTER_HOME_PKG_NAME; - } else { +// if (bincfg_is_factory_binary() != 1) { + if (menu_daemon_is_safe_mode()) { + homescreen = HOMESCREEN_PKG_NAME; + } else { + homescreen = (char *) pkgname; + } +/* } else { homescreen = (char *) pkgname; } - +*/ if (!pkgname) { tmp = menu_daemon_get_selected_pkgname(); - ret_if(NULL == tmp); + retv_if(NULL == tmp, -1); homescreen = tmp; } int ret = -1; - ret = menu_daemon_open_app(homescreen); - while (0 > ret) { - _E("Failed to open a default home, %s", homescreen); - ret = menu_daemon_open_app(homescreen); - } - /* NOTE: [BEGIN] REMOVE THIS, THIS CODE Is ONLY USED FOR CONFIDENTIAL FEATURE */ - if (!strcmp(homescreen, CLUSTER_HOME_PKG_NAME) || !strcmp(homescreen, EASY_HOME_PKG_NAME)) { - if (s_info.tray_pid < 0) { - _hide_launch_app_tray(); + //Check preloaded Homescreen + if (!strncmp(homescreen, HOMESCREEN_PKG_NAME, strlen(homescreen))) { + _SECURE_D("Launch %s", homescreen); + bundle *b = NULL; + b = bundle_create(); + if (!b) { + _E("Failed to create bundle"); + ret = menu_daemon_open_app(homescreen); + while (0 > ret) { + _E("Failed to open a default home, %s", homescreen); + ret = menu_daemon_open_app(homescreen); + } + } else { + bundle_add(b, SERVICE_OPERATION_MAIN_KEY, SERVICE_OPERATION_MAIN_VALUE); + ret = menu_daemon_launch_app(homescreen, b); + while (0 > ret) { + _E("Failed to launch a default home, %s", homescreen); + ret = menu_daemon_launch_app(homescreen, b); + } + bundle_free(b); + } + } else { + ret = menu_daemon_open_app(homescreen); + while (0 > ret) { + _E("Failed to open a default home, %s", homescreen); + ret = menu_daemon_open_app(homescreen); } } - /* NOTE: [END] REMOVE THIS, THIS CODE Is ONLY USED FOR CONFIDENTIAL FEATURE */ - +#if RELAUNCH_TASKMGR + if (s_info.taskmgr_pid < 0) { + _hide_launch_task_mgr(); + } +#endif s_info.home_pid = ret; if (ret > 0) { - if (-1 == deviced_conf_set_mempolicy_bypid(ret, OOM_IGNORE)) { - _E("Cannot set the memory policy for Home-screen(%d)", ret); - } else { - _D("Set the memory policy for Home-screen(%d)", ret); + if(starter_dbus_set_oomadj(ret, OOM_ADJ_VALUE_HOMESCREEN) < 0){ + _E("failed to send oom dbus signal"); } } if (tmp) free(tmp); + return ret; } - +#if 0 inline int menu_daemon_get_pm_key_ignore(int ignore_key) { return s_info.pm_key_ignore & ignore_key; } - inline void menu_daemon_set_pm_key_ignore(int ignore_key, int value) { if (value) { @@ -327,7 +404,7 @@ inline void menu_daemon_set_pm_key_ignore(int ignore_key, int value) _E("Can't set %s", VCONFKEY_PM_KEY_IGNORE); } } - +#endif static void _show_cb(keynode_t* node, void *data) @@ -355,11 +432,11 @@ static void _show_cb(keynode_t* node, void *data) if (aul_terminate_pid(pid) != AUL_R_OK) _E("Failed to terminate %d", s_info.home_pid); - _D("pid[%d] is terminated.", s_info.tray_pid); - pid = s_info.tray_pid; - s_info.tray_pid = -1; /* to freeze the dead_cb */ + _D("pid[%d] is terminated.", s_info.taskmgr_pid); + pid = s_info.taskmgr_pid; + s_info.taskmgr_pid = -1; /* to freeze the dead_cb */ if (pid > 0 && aul_terminate_pid(pid) != AUL_R_OK) - _E("Failed to terminate %d", s_info.tray_pid); + _E("Failed to terminate %d", s_info.taskmgr_pid); } break; case 1: @@ -379,8 +456,8 @@ static void _font_cb(keynode_t* node, void *data) { _D("Font is changed"); - if (AUL_R_OK != aul_terminate_pid(s_info.tray_pid)) - _E("Cannot terminate App-tray"); + if (AUL_R_OK != aul_terminate_pid(s_info.taskmgr_pid)) + _E("Cannot terminate Taskmgr"); } @@ -396,7 +473,7 @@ static void _cradle_status_cb(keynode_t* node, void *data) } - +#if 0 static void _pm_key_ignore_cb(keynode_t* node, void *data) { if (vconf_get_int(VCONFKEY_PM_KEY_IGNORE, &s_info.pm_key_ignore) < 0) { @@ -406,7 +483,7 @@ static void _pm_key_ignore_cb(keynode_t* node, void *data) _D("pm key ignore is changed to [%d]", s_info.pm_key_ignore); } - +#endif static void _pkg_changed(keynode_t* node, void *data) @@ -445,11 +522,6 @@ static void _pkg_changed(keynode_t* node, void *data) } } - if (!strcmp(old_pkgname, CLUSTER_HOME_PKG_NAME)) { - if (AUL_R_OK != aul_terminate_pid(s_info.tray_pid)) - _D("Failed to terminate pid %d", s_info.tray_pid); - } - if (AUL_R_OK != aul_terminate_pid(s_info.home_pid)) _D("Failed to terminate pid %d", s_info.home_pid); } else { @@ -483,12 +555,64 @@ static void _launch_volume(void) usleep(RELAUNCH_INTERVAL); } else { s_info.volume_pid = pid; + if(starter_dbus_set_oomadj(s_info.volume_pid, OOM_ADJ_VALUE_DEFAULT) < 0){ + _E("failed to send oom dbus signal"); + } return; } } } +static void _menu_daemon_launch_homescreen(const char *pkgname) +{ + char *homescreen = NULL; + char *tmp = NULL; + bundle *b; + +// if (bincfg_is_factory_binary() != 1) { + if (menu_daemon_is_safe_mode()) { + homescreen = HOMESCREEN_PKG_NAME; + } else { + homescreen = (char *) pkgname; + } +/* } else { + homescreen = (char *) pkgname; + } +*/ + if (!pkgname) { + tmp = menu_daemon_get_selected_pkgname(); + ret_if(NULL == tmp); + homescreen = tmp; + } + + int ret = -1; + b = bundle_create(); + bundle_add(b, HOME_TERMINATED, ISTRUE); + ret = aul_launch_app(homescreen, b); + while (0 > ret) { + _E("Failed to open a default home, %s", homescreen); + ret = aul_launch_app(homescreen, b); + } + + if(b) { + bundle_free(b); + } +#if RELAUNCH_TASKMGR + if (s_info.taskmgr_pid < 0) { + _hide_launch_task_mgr(); + } +#endif + s_info.home_pid = ret; + if (ret > 0) { + if(starter_dbus_set_oomadj(ret, OOM_ADJ_VALUE_HOMESCREEN) < 0){ + _E("failed to send oom dbus signal"); + } + } + + if (tmp) free(tmp); +} + int menu_daemon_check_dead_signal(int pid) { @@ -506,22 +630,20 @@ int menu_daemon_check_dead_signal(int pid) if (pid == s_info.home_pid) { /* Relaunch */ _SECURE_D("pkg_name : %s", pkgname); - menu_daemon_open_homescreen(pkgname); - } else if (pid == s_info.tray_pid) { - /* NOTE: [BEGIN] REMOVE THIS, THIS CODE Is ONLY USED FOR CONFIDENTIAL FEATURE */ - if (!strcmp(pkgname, CLUSTER_HOME_PKG_NAME) || !strcmp(pkgname, EASY_HOME_PKG_NAME)) { - _hide_launch_app_tray(); - } else { - _D("Do not launch App-tray"); - s_info.tray_pid = -1; - } - /* NOTE: [END] REMOVE THIS, THIS CODE Is ONLY USED FOR CONFIDENTIAL FEATURE */ - } else if (pid == s_info.volume_pid) { + //menu_daemon_open_homescreen(pkgname); + _menu_daemon_launch_homescreen(pkgname); + } +#if RELAUNCH_TASKMGR + else if (pid == s_info.taskmgr_pid) { + _hide_launch_task_mgr(); + } +#endif + else if (pid == s_info.volume_pid) { /* Relaunch */ _launch_volume(); } else { - _D("Unknown process, ignore it (dead pid %d, home pid %d, tray pid %d)", - pid, s_info.home_pid, s_info.tray_pid); + _D("Unknown process, ignore it (dead pid %d, home pid %d, taskmgr pid %d)", + pid, s_info.home_pid, s_info.taskmgr_pid); } free(pkgname); @@ -547,6 +669,27 @@ static void _svoice_pkg_cb(keynode_t* node, void *data) } +#define SERVICE_OPERATION_POPUP_SEARCH "http://samsung.com/appcontrol/operation/search" +#define SEARCH_PKG_NAME "com.samsung.sfinder" +int menu_daemon_launch_search(void) +{ + app_control_h app_control; + int ret = APP_CONTROL_ERROR_NONE; + + app_control_create(&app_control); + app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT); + app_control_set_app_id(app_control, SEARCH_PKG_NAME); + + ret = app_control_send_launch_request(app_control, NULL, NULL); + + if(ret != APP_CONTROL_ERROR_NONE) { + _E("Cannot launch search!! err[%d]", ret); + } + + app_control_destroy(app_control); + return ret; +} + const char *menu_daemon_get_svoice_pkg_name(void) { @@ -567,10 +710,17 @@ static void _power_off_cb(keynode_t* node, void *data) _D("power off status : %d", s_info.power_off); } +static Eina_Bool _launch_volume_idler_cb(void *data) +{ + _D("%s, %d", __func__, __LINE__); + _launch_volume(); + return ECORE_CALLBACK_CANCEL; +} void menu_daemon_init(void *data) { + bool is_exist = false; _D( "[MENU_DAEMON]menu_daemon_init is invoked"); aul_launch_init(NULL,NULL); @@ -578,9 +728,17 @@ void menu_daemon_init(void *data) _check_home_screen_package(); create_key_window(); - if (xmonitor_init() < 0) _E("cannot init xmonitor"); + //if (xmonitor_init() < 0) _E("cannot init xmonitor"); - _launch_volume(); +// _launch_volume(); + + is_exist = _exist_package(TASKMGR_PKG_NAME); + if(is_exist){ + s_info.taskmgr_pkg_name = TASKMGR_PKG_NAME; + } + else{ + s_info.taskmgr_pkg_name = DEFAULT_TASKMGR_PKG_NAME; /* rsa task manager */ + } if (vconf_notify_key_changed(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, _pkg_changed, NULL) < 0) _E("Failed to add the callback for package change event"); @@ -593,14 +751,22 @@ void menu_daemon_init(void *data) if (vconf_notify_key_changed(VCONFKEY_SYSMAN_CRADLE_STATUS, _cradle_status_cb, NULL) < 0) _E("Failed to add the callback for cradle status"); + _D("Cradle status : %d", menu_daemon_get_cradle_status()); +#if 0 if (vconf_notify_key_changed(VCONFKEY_PM_KEY_IGNORE, _pm_key_ignore_cb, NULL) < 0) _E("Failed to add the callback for pm key ignore"); + _pm_key_ignore_cb(NULL, NULL); +#endif + _pkg_changed(NULL, NULL); + ecore_idler_add(_launch_volume_idler_cb, NULL); + if (vconf_notify_key_changed(VCONFKEY_SVOICE_PACKAGE_NAME, _svoice_pkg_cb, NULL) < 0) _E("Failed to add the callback for svoice pkg"); + _svoice_pkg_cb(NULL, NULL); if (vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb, NULL) < 0) @@ -626,8 +792,10 @@ void menu_daemon_fini(void) if (vconf_ignore_key_changed(VCONFKEY_SYSMAN_CRADLE_STATUS, _cradle_status_cb) < 0) _E("Failed to ignore the callback for cradle status"); +#if 0 if (vconf_ignore_key_changed(VCONFKEY_PM_KEY_IGNORE, _pm_key_ignore_cb) < 0) _E("Failed to ignore the callback for pm key ignore"); +#endif if (vconf_ignore_key_changed(VCONFKEY_SVOICE_PACKAGE_NAME, _svoice_pkg_cb) < 0) _E("Failed to ignore the callback for svoice pkg"); @@ -636,7 +804,7 @@ void menu_daemon_fini(void) if (vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb) < 0) _E("Failed to ignore the callback for power-off"); - xmonitor_fini(); + //xmonitor_fini(); destroy_key_window(); } |