2 * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <Elementary.h>
23 #include <pkgmgr-info.h>
25 #include <dd-deviced.h>
26 #include <sys/types.h>
32 #include "dbus_util.h"
34 #include "process_mgr.h"
37 #define HOME_TERMINATED "home_terminated"
39 #define SYSPOPUPID_VOLUME "volume"
40 #define APPID_INDICATOR "org.tizen.indicator"
41 #define APPID_QUICKPANEL "org.tizen.quickpanel"
43 #define DEAD_TIMER_SEC 10.0
44 #define DEAD_TIMER_COUNT_MAX 2
56 Ecore_Timer *dead_timer;
61 .home_pid = (pid_t)-1,
62 .volume_pid = (pid_t)-1,
63 .indicator_pid = (pid_t)-1,
64 .quickpanel_pid = (pid_t)-1,
74 int home_mgr_get_home_pid(void)
76 return s_home_mgr.home_pid;
81 int home_mgr_get_volume_pid(void)
83 return s_home_mgr.volume_pid;
88 int home_mgr_get_indicator_pid(void)
90 return s_home_mgr.indicator_pid;
95 int home_mgr_get_quickpanel_pid(void)
97 return s_home_mgr.quickpanel_pid;
102 static void _after_launch_home(int pid)
104 if (dbus_util_send_oomadj(pid, OOM_ADJ_VALUE_HOMESCREEN) < 0){
105 _E("failed to send oom dbus signal");
107 s_home_mgr.home_pid = pid;
112 static int _change_home_cb(const char *appid, const char *key, const char *value, void *cfn, void *afn)
114 if (!strcmp(appid, MENU_SCREEN_PKG_NAME)) {
115 _E("We cannot do anything anymore.");
116 } else if (!strcmp(appid, status_active_get()->setappl_selected_package_name)) {
117 if (vconf_set_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, MENU_SCREEN_PKG_NAME) != 0) {
118 _E("cannot set the vconf key as %s", MENU_SCREEN_PKG_NAME);
120 /* change_home func will be called by changing the home */
123 _E("cannot change home");
129 #define SERVICE_OPERATION_MAIN_KEY "__APP_SVC_OP_TYPE__"
130 #define SERVICE_OPERATION_MAIN_VALUE "http://tizen.org/appcontrol/operation/main"
131 void home_mgr_open_home(const char *appid)
133 char *home_appid = NULL;
135 #ifndef TIZEN_BUILD_TARGET_64
137 home_appid = status_active_get()->setappl_selected_package_name;
139 home_appid = (char *) appid;
144 * If the architecture is 64bit,
145 * starter will launch menu-screen only.
147 _D("[64bit] menu-screen will be launched.");
148 home_appid = MENU_SCREEN_PKG_NAME;
151 process_mgr_must_launch(home_appid, SERVICE_OPERATION_MAIN_KEY, SERVICE_OPERATION_MAIN_VALUE, _change_home_cb, _after_launch_home);
156 static int _show_home_cb(status_active_key_e key, void *data)
158 int seq = status_active_get()->starter_sequence;
161 _D("[MENU_DAEMON] _show_home_cb is invoked(%d)", seq);
165 if (s_home_mgr.home_pid > 0) {
166 _D("Home[%d] has to be terminated.", s_home_mgr.home_pid);
167 if (aul_terminate_pid(s_home_mgr.home_pid) != AUL_R_OK) {
168 _E("Failed to terminate %d", s_home_mgr.home_pid);
170 s_home_mgr.home_pid = -1; /* to freeze the dead_cb */
174 if (vconf_get_int(VCONFKEY_STARTER_IS_FALLBACK, &is_fallback) < 0) {
175 _E("Failed to get vconfkey : %s", VCONFKEY_STARTER_IS_FALLBACK);
179 if (vconf_set_int(VCONFKEY_STARTER_IS_FALLBACK, 0)) {
180 _E("Failed to set vconfkey : %s", VCONFKEY_STARTER_IS_FALLBACK);
183 if (!strcmp(status_active_get()->setappl_selected_package_name, MENU_SCREEN_PKG_NAME)) {
186 fallback_pkg = vconf_get_str(VCONFKEY_STARTER_FALLBACK_PKG);
187 _D("fallback pkg : %s", fallback_pkg);
191 status = vconf_set_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, fallback_pkg);
196 _E("Failed to set vconfkey : %s (%d)", VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, status);
198 _E("Failed to get vconfkey : %s", VCONFKEY_STARTER_FALLBACK_PKG);
203 home_mgr_open_home(NULL);
206 _E("False sequence [%d]", seq);
215 static int _change_selected_package_name(status_active_key_e key, void *data)
218 int seq = status_active_get()->starter_sequence;
221 _E("Sequence is not ready yet, do nothing");
225 _D("_change_selected_package_name is invoked");
227 appid = status_active_get()->setappl_selected_package_name;
231 _SECURE_D("pkg_name : %s", appid);
233 if (s_home_mgr.home_pid > 0) {
234 char old_appid[BUF_SIZE_512] = { 0 , };
236 if (aul_app_get_pkgname_bypid(s_home_mgr.home_pid, old_appid, sizeof(old_appid)) == AUL_R_OK) {
237 if (!strcmp(appid, old_appid)) {
238 _D("Package is changed but same package is selected");
243 if (AUL_R_OK != aul_terminate_pid(s_home_mgr.home_pid)) {
244 _D("Failed to terminate pid %d", s_home_mgr.home_pid);
246 s_home_mgr.home_pid = -1;
247 s_home_mgr.dead_count = 0;
248 if (s_home_mgr.dead_timer) {
249 ecore_timer_del(s_home_mgr.dead_timer);
250 s_home_mgr.dead_timer = NULL;
254 home_mgr_open_home(appid);
261 static void _after_launch_volume(int pid)
263 if (dbus_util_send_oomadj(pid, OOM_ADJ_VALUE_DEFAULT) < 0){
264 _E("failed to send oom dbus signal");
266 s_home_mgr.volume_pid = pid;
271 static void _after_launch_indicator(int pid)
273 s_home_mgr.indicator_pid = pid;
278 static void _after_launch_quickpanel(int pid)
280 s_home_mgr.quickpanel_pid = pid;
285 static void _launch_after_home(int pid)
288 if(dbus_util_send_oomadj(pid, OOM_ADJ_VALUE_HOMESCREEN) < 0){
289 _E("failed to send oom dbus signal");
292 s_home_mgr.home_pid = pid;
297 static void _launch_home(const char *appid)
299 const char *home_appid = NULL;
302 home_appid = status_active_get()->setappl_selected_package_name;
304 home_appid = (char *) appid;
308 process_mgr_must_launch(home_appid, HOME_TERMINATED, ISTRUE, _change_home_cb, _launch_after_home);
313 static void _popup_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
315 _D("popup is deleted");
317 s_home_mgr.popup = NULL;
322 static Eina_Bool _dead_timer_cb(void *data)
324 Evas_Object *popup = NULL;
325 char title[BUF_SIZE_128] = { 0, };
326 char text[BUF_SIZE_1024] = { 0, };
329 appid = status_active_get()->setappl_selected_package_name;
332 return ECORE_CALLBACK_CANCEL;
335 _D("dead count : %s(%d)", appid, s_home_mgr.dead_count);
337 if (s_home_mgr.dead_count >= DEAD_TIMER_COUNT_MAX) {
338 _D("Change homescreen package to default");
340 /* set fallback status */
341 if (vconf_set_int(VCONFKEY_STARTER_IS_FALLBACK, 1) < 0) {
342 _E("Failed to set vconfkey : %s", VCONFKEY_STARTER_IS_FALLBACK);
345 if (vconf_set_str(VCONFKEY_STARTER_FALLBACK_PKG, appid) < 0) {
346 _E("Failed to set vconfkey : %s", VCONFKEY_STARTER_FALLBACK_PKG);
349 strncpy(title, _("IDS_COM_POP_WARNING"), sizeof(title));
350 title[sizeof(title) - 1] = '\0';
352 snprintf(text, sizeof(text), _("IDS_IDLE_POP_UNABLE_TO_LAUNCH_PS"), appid);
353 _D("title : %s / text : %s", title, text);
355 if (!s_home_mgr.popup) {
356 popup = popup_create(title, text);
358 _E("Failed to create popup");
360 s_home_mgr.popup = popup;
361 evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, _popup_del_cb, NULL);
365 if (vconf_set_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, MENU_SCREEN_PKG_NAME) != 0) {
366 _E("cannot set the vconf key as %s", MENU_SCREEN_PKG_NAME);
367 return ECORE_CALLBACK_RENEW;
371 s_home_mgr.dead_timer = NULL;
372 s_home_mgr.dead_count = 0;
374 return ECORE_CALLBACK_CANCEL;
379 void home_mgr_relaunch_homescreen(void)
383 if (s_home_mgr.power_off) {
388 appid = status_active_get()->setappl_selected_package_name;
394 s_home_mgr.dead_count++;
395 _D("home dead count : %d", s_home_mgr.dead_count);
397 if (!s_home_mgr.dead_timer) {
398 _D("Add dead timer");
399 s_home_mgr.dead_timer = ecore_timer_add(DEAD_TIMER_SEC, _dead_timer_cb, NULL);
400 if (!s_home_mgr.dead_timer) {
401 _E("Failed to add a dead timer");
410 void home_mgr_relaunch_volume(void)
412 process_mgr_must_syspopup_launch(SYSPOPUPID_VOLUME, NULL, NULL, NULL, _after_launch_volume);
417 void home_mgr_relaunch_indicator(void)
419 process_mgr_must_launch(APPID_INDICATOR, NULL, NULL, NULL, _after_launch_indicator);
424 void home_mgr_relaunch_quickpanel(void)
426 process_mgr_must_launch(APPID_QUICKPANEL, NULL, NULL, NULL, _after_launch_quickpanel);
431 static int _power_off_cb(status_active_key_e key, void *data)
433 int val = status_active_get()->sysman_power_off_status;
435 if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART) {
436 s_home_mgr.power_off = 1;
438 s_home_mgr.power_off = 0;
441 _D("power off status : %d", s_home_mgr.power_off);
448 static Eina_Bool _launch_apps_idler_cb(void *data)
450 #ifndef TIZEN_BUILD_TARGET_64
451 process_mgr_must_syspopup_launch(SYSPOPUPID_VOLUME, NULL, NULL, NULL, _after_launch_volume);
452 process_mgr_must_launch(APPID_INDICATOR, NULL, NULL, NULL, _after_launch_indicator);
453 process_mgr_must_launch(APPID_QUICKPANEL, NULL, NULL, NULL, _after_launch_quickpanel);
456 return ECORE_CALLBACK_CANCEL;
461 void home_mgr_init(void *data)
463 _D( "[MENU_DAEMON]home_mgr_init is invoked");
465 status_active_register_cb(STATUS_ACTIVE_KEY_STARTER_SEQUENCE, _show_home_cb, NULL);
466 status_active_register_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb, NULL);
467 status_active_register_cb(STATUS_ACTIVE_KEY_SETAPPL_SELECTED_PACKAGE_NAME, _change_selected_package_name, NULL);
468 _change_selected_package_name(STATUS_ACTIVE_KEY_SETAPPL_SELECTED_PACKAGE_NAME, NULL);
470 ecore_idler_add(_launch_apps_idler_cb, NULL);
475 void home_mgr_fini(void)
477 if (s_home_mgr.volume_pid > 0) {
478 process_mgr_terminate_app(s_home_mgr.volume_pid, 1);
479 s_home_mgr.volume_pid = -1;
482 status_active_unregister_cb(STATUS_ACTIVE_KEY_STARTER_SEQUENCE, _show_home_cb);
483 status_active_unregister_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb);
484 status_active_unregister_cb(STATUS_ACTIVE_KEY_SETAPPL_SELECTED_PACKAGE_NAME, _change_selected_package_name);