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://floralicense.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.
19 #include <Elementary.h>
22 #include <sys/types.h>
33 #include <system_info.h>
36 #include "starter-util.h"
38 #include "lock-daemon.h"
39 #include "lockd-debug.h"
40 #include "menu_daemon.h"
43 #define PACKAGE_NAME "org.tizen.starter"
46 #define DEFAULT_THEME "tizen"
47 #define PWLOCK_PATH "/usr/apps/org.tizen.pwlock/bin/pwlock"
48 #define PWLOCK_PKG_NAME "org.tizen.pwlock"
49 #define QP_EMUL_STR "Emulator"
51 static void lock_menu_screen(void)
53 vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 0);
56 static void unlock_menu_screen(void)
62 r = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &show_menu);
63 if (r || !show_menu) {
64 vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 1);
68 static void _set_elm_theme(void)
73 vstr = vconf_get_str(VCONFKEY_SETAPPL_WIDGET_THEME_STR);
75 theme = DEFAULT_THEME;
80 _DBG("theme vconf[%s]\n set[%s]\n", vstr, theme);
81 elm_theme_set(th, theme);
87 static int _check_emul()
92 if (system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &info) == 0) {
93 if (info == NULL) return 0;
94 if (!strncmp(QP_EMUL_STR, info, strlen(info))) {
99 if (info != NULL) free(info);
104 static int _launch_pwlock(void)
108 _DBG("%s", __func__);
111 _DBG("Emulator => skip pwlock");
112 vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 1);
116 r = aul_launch_app(PWLOCK_PKG_NAME, NULL);
118 _ERR("PWLock launch error: error(%d)", r);
119 if (r == AUL_R_ETIMEOUT) {
120 _DBG("Launch pwlock is failed for AUL_R_ETIMEOUT, again launch pwlock");
121 r = aul_launch_app(PWLOCK_PKG_NAME, NULL);
123 _ERR("2'nd PWLock launch error: error(%d)", r);
126 _DBG("Launch pwlock");
133 _DBG("Launch pwlock");
138 static void _signal_handler(int signum, siginfo_t *info, void *unused)
140 _DBG("_signal_handler : Terminated...");
144 static void _heynoti_event_power_off(void *data)
146 _DBG("_heynoti_event_power_off : Terminated...");
150 static Eina_Bool _init_idle(void *data)
152 _DBG("%s %d\n", __func__, __LINE__);
153 if (_launch_pwlock() < 0) {
154 _ERR("launch pwlock error");
156 menu_daemon_init(NULL);
158 return ECORE_CALLBACK_CANCEL;
161 static void _lock_state_cb(keynode_t * node, void *data)
163 _DBG("%s %d\n", __func__, __LINE__);
164 WRITE_FILE_LOG("%s", "Lock state is changed!");
166 if (_launch_pwlock() < 0) {
167 _ERR("launch pwlock error");
169 menu_daemon_init(NULL);
170 if (vconf_ignore_key_changed(VCONFKEY_IDLE_LOCK_STATE,
171 _lock_state_cb) != 0) {
172 LOCKD_DBG("Fail to unregister");
176 static void _init(struct appdata *ad)
179 struct sigaction act;
181 memset(&act,0x00,sizeof(struct sigaction));
182 act.sa_sigaction = _signal_handler;
183 act.sa_flags = SA_SIGINFO;
185 int ret = sigemptyset(&act.sa_mask);
187 _ERR("Failed to sigemptyset[%s]", strerror(errno));
189 ret = sigaddset(&act.sa_mask, SIGTERM);
191 _ERR("Failed to sigaddset[%s]", strerror(errno));
193 ret = sigaction(SIGTERM, &act, NULL);
195 _ERR("Failed to sigaction[%s]", strerror(errno));
198 memset(ad, 0, sizeof(struct appdata));
200 gettimeofday(&ad->tv_start, NULL);
205 _DBG("%s %d\n", __func__, __LINE__);
207 r = start_lock_daemon(TRUE);
209 if (vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE,
210 _lock_state_cb, NULL) != 0) {
211 _ERR("[Error] vconf notify : lock state");
212 ecore_timer_add(1.5, _init_idle, NULL);
215 if (_launch_pwlock() < 0) {
216 _ERR("launch pwlock error");
218 menu_daemon_init(NULL);
222 static void _fini(struct appdata *ad)
224 struct timeval tv, res;
227 fprintf(stderr, "Invalid argument: appdata is NULL\n");
231 unlock_menu_screen();
234 gettimeofday(&tv, NULL);
235 timersub(&tv, &ad->tv_start, &res);
236 _DBG("Total time: %d.%06d sec\n", (int)res.tv_sec, (int)res.tv_usec);
239 int main(int argc, char *argv[])
243 WRITE_FILE_LOG("%s", "Main function is started in starter");
245 int heyfd = heynoti_init();
247 _ERR("Failed to heynoti_init[%d]", heyfd);
251 int ret = heynoti_subscribe(heyfd, "power_off_start", _heynoti_event_power_off, NULL);
253 _ERR("Failed to heynoti_subscribe[%d]", ret);
255 ret = heynoti_attach_handler(heyfd);
257 _ERR("Failed to heynoti_attach_handler[%d]", ret);
260 elm_init(argc, argv);