2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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.
22 #include <Elementary.h>
25 #include <sys/types.h>
30 #include "desktop_to_db.h"
33 #include "pkg_event.h"
40 #define QUERY_UPDATE_NAME "UPDATE app_info SET name='%s' where package='%s';"
41 #define SAT_DESKTOP_FILE "/opt/share/applications/org.tizen.sat-ui.desktop"
45 // Define prototype of the "hidden API of AUL"
46 extern int aul_listen_app_dead_signal(int (*func)(int signal, void *data), void *data);
58 static inline char *_get_pkgname(keynode_t *node)
63 pkgname = vconf_keynode_get_str(node);
65 pkgname = vconf_get_str(MENU_PKG_VCONF_KEY);
68 _E("Cannot get pkgname from vconf.");
69 pkgname = strdup(HOME_SCREEN_PKG_NAME);
71 _E("strdup error for pkgname, %s", strerror(errno));
79 static inline void _open_homescreen(const char *pkgname)
82 char *homescreen = (char *) pkgname;
84 ret = aul_open_app(homescreen);
85 _D("can%s launch %s now. (%d)", ret < 0 ? "not" : "", homescreen, ret);
86 if (ret < 0 && strcmp(homescreen, HOME_SCREEN_PKG_NAME)) {
87 ret = aul_open_app(HOME_SCREEN_PKG_NAME);
89 _E("Failed to open a default home, %s", HOME_SCREEN_PKG_NAME);
91 homescreen = HOME_SCREEN_PKG_NAME;
100 static void _show_cb(keynode_t* node, void *data)
105 _D("[MENU_DAEMON] _show_cb is invoked");
107 pkgname = _get_pkgname(NULL);
112 seq = vconf_keynode_get_int(node);
114 if (vconf_get_int("memory/startapps/sequence", &seq) < 0) {
115 _E("Failed to get sequence info");
123 if (s_info.pid > 0) {
125 _D("pid[%d] is terminated.", s_info.pid);
128 s_info.pid = -1; /* to freeze the dead_cb */
130 if (aul_terminate_pid(pid) != AUL_R_OK)
131 _E("Failed to terminate %d", s_info.pid);
135 _open_homescreen(pkgname);
138 _E("False sequence [%d]", seq);
149 static void _pkg_changed(keynode_t* node, void *data)
154 if (vconf_get_int("memory/startapps/sequence", &seq) < 0) {
155 _E("Do nothing, there is no sequence info yet");
160 _E("Sequence is not ready yet, do nothing");
164 _D("_pkg_changed is invoked");
166 pkgname = _get_pkgname(node);
170 _D("pkg_name : %s", pkgname);
172 if (s_info.pid > 0) {
173 char old_pkgname[256];
175 if (aul_app_get_pkgname_bypid(s_info.pid, old_pkgname, sizeof(old_pkgname)) == AUL_R_OK) {
176 if (!strcmp(pkgname, old_pkgname)) {
177 _D("Package is changed but same package is selected");
183 if (aul_terminate_pid(s_info.pid) != AUL_R_OK)
184 _D("Failed to terminate pid %d", s_info.pid);
186 /* If there is no running home */
187 _open_homescreen(pkgname);
190 /* NOTE: Dead callback will catch the termination of a current menuscreen
191 * _open_homescreen(pkgname);
199 static int _dead_cb(int pid, void *data)
203 _D("Process %d is termianted", pid);
204 if (pid != s_info.pid || s_info.pid <= 0) {
205 _D("Unknown process, ignore it (pid %d, menu pid %d)", pid, s_info.pid);
209 pkgname = _get_pkgname(NULL);
213 _D("pkg_name : %s", pkgname);
216 _open_homescreen(pkgname);
223 static void _hibernation_preleave_cb(void *data)
225 _D( "[MENU_DAEMON]_hibernation_preleave_cb is invoked");
227 aul_launch_init(NULL,NULL);
228 aul_listen_app_dead_signal(_dead_cb, NULL);
233 if (unlink(SAT_DESKTOP_FILE) != 0)
234 _E("cannot remove sat-ui desktop.");
236 if (vconf_notify_key_changed(MENU_PKG_VCONF_KEY, _pkg_changed, NULL) < 0)
237 _E("Failed to add callback for package change event");
239 if (vconf_notify_key_changed("memory/startapps/sequence", _show_cb, NULL) < 0)
240 _E("Failed to add callback for show event");
242 _pkg_changed(NULL, NULL);
243 // THIS ROUTINE IS FOR SAT.
244 vconf_set_int("memory/menu-screen/is_menu_screen_done", 1);
249 int elm_main(int argc, char *argv[])
254 elm_init(argc, argv);
257 system("/usr/bin/ail_initdb");
259 fp = fopen("/opt/etc/.hib_capturing", "r");
261 fprintf(stderr, "[MENU_DAEMON]hib_capturing file is not found\n");
262 _hibernation_preleave_cb(NULL);
264 fprintf(stderr,"\n\n\n Menu Daemon enter %s hey noti init\n", __func__);
266 fprintf(stderr, "[MENU_DAEMON]\n\n\n Hey Noti Init Failed\n");
268 if (heynoti_subscribe(fd, "HIBERNATION_PRELEAVE", _hibernation_preleave_cb, NULL)) {
269 fprintf(stderr,"Heynoti subscribe is failed\n");
271 fprintf(stderr,"Heynoti subscribe is done\n");
274 if (heynoti_attach_handler(fd)) {
275 fprintf(stderr,"Heynoti attach handler is failed\n");
277 fprintf(stderr,"Heynoti attach handler is done\n");
278 if (vconf_set_int("memory/hibernation/menuscreen_ready", 1)) {
279 fprintf(stderr, "[MENU_DAEMON]vconf_set_int FAIL\n");
281 fprintf(stderr, "[MENU_DAEMON]vconf_set_int OK\n");
289 destroy_key_window();