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.
17 #include <Elementary.h>
20 #include <sys/types.h>
33 #include <dd-deviced.h>
35 #include "starter_w.h"
36 #include "starter-util.h"
38 #include "lockd-debug.h"
45 #define PACKAGE_NAME "com.samsung.starter"
48 #define DEFAULT_THEME "tizen"
50 #define W_LOCKSCREEN_PKGNAME "com.samsung.w-lockscreen"
51 #define REMOTE_LOCK_PKGNAME "com.samsung.wfmw-remote-lock"
53 #ifdef FEATURE_TIZENW2
54 #define SETUP_WIZARD_PKGNAME "com.samsung.b2-setup-wizard"
56 #define SETUP_WIZARD_PKGNAME "com.samsung.b2-setup-wizard"
58 #define PWLOCK_PKGNAME "com.samsung.b2-pwlock"
60 #define NOTIFICATION_APP_PKGNAME "com.samsung.idle-noti-drawer"
62 #define FACTORY_TDF_NOTIFIER_PATH "/csa/factory/cblkftdf"
64 #define VCONFKEY_BT_CONNECTED "memory/private/sap/conn_type"
66 #define VCONFKEY_REMOTE_LOCK_ISLOCKED "db/private/com.samsung.wfmw/is_locked"
68 static struct appdata *g_app_data = NULL;
70 void *starter_get_app_data(void){
75 static void _signal_handler(int signum, siginfo_t *info, void *unused)
77 _DBG("_signal_handler : Terminated...");
81 int w_open_app(char *pkgname)
85 _SECURE_D("w_open_app:[%s]", pkgname);
87 r = aul_open_app(pkgname);
90 _ERR("open app failed [%s] ret=[%d]", pkgname, r);
96 int w_launch_app(char *pkgname, bundle *b)
100 _SECURE_D("w_launch_app:[%s]", pkgname);
102 r = aul_launch_app(pkgname, b);
105 _ERR("launch failed [%s] ret=[%d]", pkgname, r);
112 static Eina_Bool _w_retry_idler_cb(void *data)
114 struct appdata *ad = (struct appdata *)data;
116 _DBG("%s, %d", __func__, __LINE__);
119 ad->launcher_pid = w_launch_app(ad->home_pkgname, NULL);
121 if (ad->launcher_pid > 0) {
122 if (-1 == deviced_conf_set_mempolicy_bypid(ad->launcher_pid, OOM_IGNORE)) {
123 _ERR("Cannot set the memory policy for Homescreen(%d)", ad->launcher_pid);
125 _ERR("Set the memory policy for Homescreen(%d)", ad->launcher_pid);
129 if(ad->retry_cnt >= RETRY_CNT){
131 return ECORE_CALLBACK_CANCEL;
134 return ECORE_CALLBACK_RENEW;
138 return ECORE_CALLBACK_CANCEL;
141 static Eina_Bool _w_retry_idler_first_launch_cb(void *data)
143 struct appdata *ad = (struct appdata *)data;
147 _E("Cannot create bundle");
148 return ECORE_CALLBACK_CANCEL;
151 _DBG("%s, %d", __func__, __LINE__);
153 bundle_add(b, "home_op", "first_boot");
156 ad->launcher_pid = w_launch_app(ad->home_pkgname, b);
158 if (ad->launcher_pid > 0) {
159 if (-1 == deviced_conf_set_mempolicy_bypid(ad->launcher_pid, OOM_IGNORE)) {
160 _ERR("Cannot set the memory policy for Homescreen(%d)", ad->launcher_pid);
162 _ERR("Set the memory policy for Homescreen(%d)", ad->launcher_pid);
166 if(ad->retry_cnt >= RETRY_CNT){
169 return ECORE_CALLBACK_CANCEL;
173 return ECORE_CALLBACK_RENEW;
178 return ECORE_CALLBACK_CANCEL;
181 static int _w_app_dead_cb(int pid, void *data)
183 _DBG("app dead cb call! (pid : %d)", pid);
185 struct appdata *ad = (struct appdata *)data;
187 if (pid == ad->launcher_pid) {
188 _ERR("w-launcher-app (pid:%d) is destroyed.", pid);
189 ad->launcher_pid = w_launch_app(ad->home_pkgname, NULL);
190 if (ad->launcher_pid > 0) {
191 if (-1 == deviced_conf_set_mempolicy_bypid(ad->launcher_pid, OOM_IGNORE)) {
192 _ERR("Cannot set the memory policy for Homescreen(%d)", ad->launcher_pid);
194 _ERR("Set the memory policy for Homescreen(%d)", ad->launcher_pid);
198 _ERR("Launch Home failed.");
199 ecore_idler_add(_w_retry_idler_cb, ad);
201 } else if (pid == ad->pid_clock_viewer) {
202 _ERR("w-clock-viewer (pid:%d) is destroyed.", pid);
203 int ambient_mode = 0;
204 if (vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, &ambient_mode) < 0) {
205 _E("Failed to get vconfkey : %s", VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL);
210 ad->pid_clock_viewer = w_launch_app(W_CLOCK_VIEWER_PKGNAME, NULL);
217 static int _w_check_first_boot(void)
222 #if 1 // NOT YET define vconfkey from setting "VCONFKEY_SETUP_WIZARD_FIRST_BOOT"
223 ret = vconf_get_bool(VCONFKEY_SETUP_WIZARD_FIRST_BOOT, &is_first);
225 _ERR("can't get vconfkey value of [%s], ret=[%d]", VCONFKEY_SETUP_WIZARD_FIRST_BOOT, ret);
227 } else if (is_first == 1) {
228 _ERR("[%s] value is [%d], first booting..!!", VCONFKEY_SETUP_WIZARD_FIRST_BOOT, is_first);
235 static Eina_Bool _w_starter_idler_cb(void *data)
237 struct appdata *ad = (struct appdata *)data;
239 _DBG("%s, %d", __func__, __LINE__);
241 ad->launcher_pid = w_launch_app(ad->home_pkgname, NULL);
243 if (ad->launcher_pid > 0) {
244 if (-1 == deviced_conf_set_mempolicy_bypid(ad->launcher_pid, OOM_IGNORE)) {
245 _ERR("Cannot set the memory policy for Homescreen(%d)", ad->launcher_pid);
247 _ERR("Set the memory policy for Homescreen(%d)", ad->launcher_pid);
251 _ERR("Launch Home failed.");
252 ecore_idler_add(_w_retry_idler_cb, ad);
255 return ECORE_CALLBACK_CANCEL;
259 static Eina_Bool _w_starter_lockscreen_idler_cb(void *data)
261 struct appdata *ad = (struct appdata *)data;
263 _DBG("%s, %d", __func__, __LINE__);
265 w_launch_app(W_LOCKSCREEN_PKGNAME, NULL);
267 if (ad->first_boot == FALSE)
268 ecore_idler_add(_w_starter_idler_cb, ad);
270 return ECORE_CALLBACK_CANCEL;
274 #define TEMP_VCONFKEY_LOCK_TYPE "db/setting/lock_type"
275 static void _w_BT_changed_cb(keynode_t* node, void *data)
280 struct appdata *ad = (struct appdata *)data;
282 _DBG("%s, %d", __func__, __LINE__);
285 bt_state = vconf_keynode_get_int(node);
287 if (vconf_get_int(VCONFKEY_BT_CONNECTED, &bt_state) < 0) {
288 _ERR("Failed to get %s", VCONFKEY_BT_CONNECTED);
292 _DBG("WMS key value:[%d], previous state:[%d]", bt_state, ad->bt_connected);
294 vconf_get_int(TEMP_VCONFKEY_LOCK_TYPE, &lock_type);
295 vconf_get_int(VCONFKEY_TESTMODE_SCREEN_LOCK, &test_mode);
297 if ((lock_type != 1) || (test_mode == VCONFKEY_TESTMODE_SCREEN_LOCK_DISABLE)) {
298 ad->bt_connected = bt_state;
302 if (bt_state == FALSE) {
303 if (ad->bt_connected == TRUE) {
304 _ERR("BT connect state is changed from [%d] to [%d]", ad->bt_connected, bt_state);
305 w_launch_app(W_LOCKSCREEN_PKGNAME, NULL);
308 ad->bt_connected = bt_state;
313 static void _w_power_off_cb(keynode_t* node, void *data)
315 int val = VCONFKEY_SYSMAN_POWER_OFF_NONE;
317 vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val);
319 if (val > VCONFKEY_SYSMAN_POWER_OFF_POPUP) {
320 _ERR("power off status : %d", val);
321 if (vconf_ignore_key_changed(VCONFKEY_BT_CONNECTED, _w_BT_changed_cb) < 0)
322 _ERR("Failed to ignore the callback for [%s]", VCONFKEY_BT_CONNECTED);
327 static void _w_lang_changed_cb(keynode_t* node, void *data)
330 _DBG("%s, %d", __func__, __LINE__);
332 locale = vconf_get_str(VCONFKEY_LANGSET);
334 if (locale != NULL) {
335 elm_language_set(locale);
340 static void _launch_home_cb(keynode_t* node, void *data)
343 struct appdata *ad = (struct appdata *)data;
347 seq = vconf_keynode_get_int(node);
349 if (vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &seq) < 0) {
350 _E("Failed to get sequence info");
357 _E("Cannot create bundle");
360 bundle_add(b, "home_op", "first_boot");
362 _DBG("_launch_home_cb, seq=%d", seq);
364 ad->launcher_pid = w_launch_app(ad->home_pkgname, b);
365 if (ad->launcher_pid > 0) {
366 if (-1 == deviced_conf_set_mempolicy_bypid(ad->launcher_pid, OOM_IGNORE)) {
367 _ERR("Cannot set the memory policy for Homescreen(%d)", ad->launcher_pid);
369 _ERR("Set the memory policy for Homescreen(%d)", ad->launcher_pid);
372 _ERR("Launch Home failed.");
373 ecore_idler_add(_w_retry_idler_first_launch_cb, ad);
377 create_key_window(ad->home_pkgname, ad);
381 static void _ambient_mode_event_add(void *data)
383 _DBG("%s", __func__);
385 int ambient_mode = 0;
386 struct appdata *ad = (struct appdata *)data;
389 if (vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, &ambient_mode) < 0) {
390 _E("Failed to get vconfkey : %s", VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL);
395 ad->pid_clock_viewer = w_launch_app(W_CLOCK_VIEWER_PKGNAME, NULL);
399 static void _init(struct appdata *ad)
402 struct sigaction act;
410 memset(&act,0x00,sizeof(struct sigaction));
411 act.sa_sigaction = _signal_handler;
412 act.sa_flags = SA_SIGINFO;
414 int ret = sigemptyset(&act.sa_mask);
416 _ERR("Failed to sigemptyset[%s]", strerror(errno));
418 ret = sigaddset(&act.sa_mask, SIGTERM);
420 _ERR("Failed to sigaddset[%s]", strerror(errno));
422 ret = sigaction(SIGTERM, &act, NULL);
424 _ERR("Failed to sigaction[%s]", strerror(errno));
427 memset(ad, 0, sizeof(struct appdata));
431 ad->nike_running_status = 0;
434 gettimeofday(&ad->tv_start, NULL);
435 aul_launch_init(NULL,NULL);
437 aul_listen_app_dead_signal(_w_app_dead_cb, ad);
439 if (vconf_notify_key_changed(VCONFKEY_LANGSET, _w_lang_changed_cb, NULL) < 0)
440 _ERR("Failed to add the callback for [%s]", VCONFKEY_LANGSET);
442 ad->home_pkgname = vconf_get_str("file/private/homescreen/pkgname");
443 if (!ad->home_pkgname) {
444 ad->home_pkgname = W_HOME_PKGNAME;
446 _ERR("Home pkg name is [%s]", ad->home_pkgname);
449 if (bincfg_is_factory_binary() == BIN_TYPE_FACTORY) {
452 GError *error = NULL;
453 gboolean result = FALSE;
455 _ERR("Factory binary..!!");
457 if (g_file_get_contents(FACTORY_TDF_NOTIFIER_PATH, &contents, &length, &error)) {
459 _ERR("Read %d bytes from filesystem", length);
460 if ((found = g_strstr_len(contents, strlen(contents), "ON"))) {
461 // Launch TDF Notifier
463 argv[0] = "/usr/bin/testmode";
467 execv("/usr/bin/testmode", argv);
474 _ERR("read failed [%d]: [%s]", error->code, error->message);
478 ad->launcher_pid = w_launch_app(ad->home_pkgname, NULL);
479 if(ad->launcher_pid < 0){
480 _ERR("Launch Home failed.");
481 ecore_idler_add(_w_retry_idler_cb, ad);
483 create_key_window_factory_mode(ad->home_pkgname, ad);
486 if (vconf_notify_key_changed(VCONFKEY_BT_CONNECTED, _w_BT_changed_cb, ad) < 0) {
487 _ERR("Failed to add the callback for %s changed", VCONFKEY_BT_CONNECTED);
489 if (vconf_get_int(VCONFKEY_BT_CONNECTED, &bt_state) < 0) {
490 _ERR("Failed to get [%s]", VCONFKEY_BT_CONNECTED);
492 ad->bt_connected = bt_state;
493 _DBG("ad->bt_connected : [%d]", ad->bt_connected);
496 #ifdef TELEPHONY_DISABLE //B2
497 if (_w_check_first_boot() == TRUE) {
498 w_launch_app(SETUP_WIZARD_PKGNAME, NULL);
499 ecore_idler_add(_w_starter_idler_cb, ad);
501 _DBG("Not first booting, launch [%s]..!!", ad->home_pkgname);
503 vconf_get_int(VCONFKEY_TESTMODE_SCREEN_LOCK, &test_mode);
504 vconf_get_int(TEMP_VCONFKEY_LOCK_TYPE, &lock_type);
506 if ((bt_state == FALSE) && (lock_type == 1) && (test_mode != VCONFKEY_TESTMODE_SCREEN_LOCK_DISABLE)) {
507 _ERR("BT disconneted and privacy lock is set");
508 w_launch_app(W_LOCKSCREEN_PKGNAME, NULL);
509 ecore_idler_add(_w_starter_idler_cb, ad);
511 ad->launcher_pid = w_launch_app(ad->home_pkgname, NULL);
512 if (ad->launcher_pid > 0) {
513 if (-1 == deviced_conf_set_mempolicy_bypid(ad->launcher_pid, OOM_IGNORE)) {
514 _ERR("Cannot set the memory policy for Homescreen(%d)", ad->launcher_pid);
516 _ERR("Set the memory policy for Homescreen(%d)", ad->launcher_pid);
521 #else //B2-3G //TELEPHONY_DISABLE
523 #if 0 // To do not display home before setupwizard
525 w_launch_app(PWLOCK_PKGNAME, NULL);
526 vconf_get_int(VCONFKEY_TESTMODE_SCREEN_LOCK, &test_mode);
527 vconf_get_int(TEMP_VCONFKEY_LOCK_TYPE, &lock_type);
529 if ((wms_state == FALSE) && (lock_type == 1) && (test_mode != VCONFKEY_TESTMODE_SCREEN_LOCK_DISABLE)) {
530 _ERR("BT disconneted and privacy lock is set");
531 ecore_idler_add(_w_starter_lockscreen_idler_cb, ad);
533 ad->launcher_pid = w_launch_app(ad->home_pkgname, NULL);
534 if (ad->launcher_pid > 0) {
535 if (-1 == deviced_conf_set_mempolicy_bypid(ad->launcher_pid, OOM_IGNORE)) {
536 _ERR("Cannot set the memory policy for Homescreen(%d)", ad->launcher_pid);
538 _ERR("Set the memory policy for Homescreen(%d)", ad->launcher_pid);
545 vconf_get_int(VCONFKEY_TESTMODE_SCREEN_LOCK, &test_mode);
546 vconf_get_int(TEMP_VCONFKEY_LOCK_TYPE, &lock_type);
548 if (_w_check_first_boot() == TRUE) {
550 //First boot : launch pwlock > set seq > home
551 ad->first_boot = TRUE;
553 vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 0);
555 if (vconf_notify_key_changed(VCONFKEY_STARTER_SEQUENCE, _launch_home_cb, ad) < 0)
556 _ERR("Failed to add the callback for show event");
557 #ifdef MODEM_ALWAYS_OFF
558 w_launch_app(SETUP_WIZARD_PKGNAME, NULL);
560 w_launch_app(PWLOCK_PKGNAME, NULL);
562 if ((bt_state == FALSE) && (lock_type == 1) && (test_mode != VCONFKEY_TESTMODE_SCREEN_LOCK_DISABLE)) {
563 _ERR("BT disconneted and privacy lock is set");
564 ecore_idler_add(_w_starter_lockscreen_idler_cb, ad);
568 // Not first boot : launch home > pwlock
569 ad->first_boot = FALSE;
571 if ((bt_state == FALSE) && (lock_type == 1) && (test_mode != VCONFKEY_TESTMODE_SCREEN_LOCK_DISABLE)) {
572 _ERR("BT disconneted and privacy lock is set");
573 ecore_idler_add(_w_starter_lockscreen_idler_cb, ad);
575 ad->launcher_pid = w_launch_app(ad->home_pkgname, NULL);
576 if (ad->launcher_pid > 0) {
577 if (-1 == deviced_conf_set_mempolicy_bypid(ad->launcher_pid, OOM_IGNORE)) {
578 _ERR("Cannot set the memory policy for Homescreen(%d)", ad->launcher_pid);
580 _ERR("Set the memory policy for Homescreen(%d)", ad->launcher_pid);
584 _ERR("Launch Home failed.");
585 ecore_idler_add(_w_retry_idler_cb, ad);
588 create_key_window(ad->home_pkgname, ad);
589 #ifndef MODEM_ALWAYS_OFF
590 w_launch_app(PWLOCK_PKGNAME, NULL);
595 #endif //TELEPHONY_DISABLE
600 /* add ambient mode event */
601 _ambient_mode_event_add(ad);
603 /* Check remote-lock state */
604 if(vconf_get_bool(VCONFKEY_REMOTE_LOCK_ISLOCKED, &remote_lock) < 0){
605 _E("failed to get %s", VCONFKEY_REMOTE_LOCK_ISLOCKED);
608 if(remote_lock == true){
609 w_launch_app(REMOTE_LOCK_PKGNAME, NULL);
612 // create_key_window(ad->home_pkgname, ad);
613 init_hourly_alert(ad);
614 get_dbus_cool_down_mode(ad);
615 init_dbus_COOL_DOWN_MODE_signal(ad);
616 starter_dbus_connection_get();
617 init_dbus_lcd_on_off_signal(ad);
620 // THIS ROUTINE IS FOR SAT.
621 vconf_set_int(VCONFKEY_IDLE_SCREEN_LAUNCHED, VCONFKEY_IDLE_SCREEN_LAUNCHED_TRUE);
623 if (vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, _w_power_off_cb, NULL) < 0)
624 _ERR("Failed to add the callback for [%s]", VCONFKEY_SYSMAN_POWER_OFF_STATUS);
629 static void _fini(struct appdata *ad)
631 struct timeval tv, res;
634 fprintf(stderr, "Invalid argument: appdata is NULL\n");
638 destroy_key_window();
639 fini_hourly_alert(ad);
642 gettimeofday(&tv, NULL);
643 timersub(&tv, &ad->tv_start, &res);
644 _DBG("Total time: %d.%06d sec\n", (int)res.tv_sec, (int)res.tv_usec);
647 int main(int argc, char *argv[])
651 // WRITE_FILE_LOG("%s", "Main function is started in starter");
652 _DBG("starter is launched..!!");
654 set_window_scale(); /* not in loop */
657 elm_init(argc, argv);