/* * pwlock * * Copyright 2012 Samsung Electronics Co., Ltd * * Licensed under the Flora License, Version 1.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://floralicense.org/license/ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * 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 //#include #include #include #include #include #include #include #include "pwlock.h" #include "util.h" #include "ui.h" #include "langs.h" #define _ST_START _ST_FIRST #define HOME_KEY KEY_SELECT #define BACK_KEY KEY_END #define MENUSCREEN_PKG_NAME "db/menuscreen/pkgname" /* menu screen pkg name string */ #define TIMEZONE_CITY_NAME "db/setting/cityname_id" /* get the city name */ #define TIMEZONE_TIMEZONE_ID "db/setting/timezone_id" /* get the timezone id */ #define TIMEZONE_INFO_PATH "/usr/share/zoneinfo/" /* the path of the timezone infomation */ #define TIMEZONE_INFO_FILE TIMEZONE_INFO_PATH"zone.tab" /* the file of the timezone infomation */ struct state { int (*_do) (struct appdata * ad); }; //struct sigaction g_oldact; static int do_ST_FIRST(struct appdata *ad); static int do_ST_TAPI_INIT(struct appdata *ad); static int do_ST_SIM(struct appdata *ad); static int do_ST_SIM_PINCNF(struct appdata *ad); static int do_ST_SIM_PUKCNF(struct appdata *ad); static int do_ST_SIM_LOCKCNF(struct appdata *ad); static int do_ST_NETWORK_LOCKCNF(struct appdata *ad); static int do_ST_EXIT(struct appdata *ad); static int do_ST_GREETING(struct appdata *ad); static int do_ST_LANG(struct appdata *ad); static int do_ST_NOSIM(struct appdata *ad); static int do_ST_TIME(struct appdata *ad); static int do_ST_CONNECTION(struct appdata *ad); static int do_ST_TUTORIAL(struct appdata *ad); static int do_ST_FINISH(struct appdata *ad); static void set_pwlock_unlock_state(struct appdata *ad); static void set_pwlock_lock_state(struct appdata *ad); static Eina_Bool timer_do(void *data); static void set_default_timezone(void *data); //static void pwlock_signal_handler(int sig); //static void register_sig_handler(void); static struct state states[_ST_MAX] = { {do_ST_FIRST,}, /* { do_ST_INIT, }, */ {do_ST_TAPI_INIT,}, {do_ST_SIM,}, {do_ST_SIM_PINCNF,}, {do_ST_SIM_PUKCNF,}, {do_ST_SIM_LOCKCNF,}, {do_ST_NETWORK_LOCKCNF,}, {do_ST_EXIT,}, {do_ST_LANG,}, {do_ST_NOSIM,}, {do_ST_TIME,}, {do_ST_GREETING,}, {do_ST_CONNECTION,}, {do_ST_TUTORIAL,}, {do_ST_FINISH,}, }; static inline void _trans(struct appdata *ad, int state) { _DBG("trans state %d --> state %d", ad->state, state); ad->state = state; } static void set_default_timezone(void *data) { struct appdata *ad = (struct appdata *)data; char *timezone_id = NULL; FILE *fp = NULL; char tmp[256] = { 0 }; char buf1[256] = { 0 }; char buf2[256] = { 0 }; char buf3[256] = { 0 }; char timezone_path[256] = { 0 }; _DBG("%s", __func__); if (ad == NULL) { return; } timezone_id = vconf_get_str(TIMEZONE_TIMEZONE_ID); _DBG("timezone_id = %s", timezone_id); if (timezone_id == NULL) { _ERR("Timezone id is null!!!"); return; } fp = fopen(TIMEZONE_INFO_FILE, "r"); while (fp != NULL && fgets(tmp, sizeof(tmp), fp) != NULL) { if (strstr(tmp, timezone_id)) { sscanf(tmp, "%s\t%s\t%s", buf1, buf2, buf3); snprintf(timezone_path, 256, TIMEZONE_INFO_PATH "%s", buf3); } } if (fp != NULL) { fclose(fp); } if (timezone_id != NULL) { free(timezone_id); timezone_id = NULL; } _DBG("timezone_path = %s", timezone_path); sysman_set_timezone(timezone_path); } static void _sim_retry(struct appdata *ad, int retry) { char buf[256]; int len = -1; _DBG("%s", __func__); if (retry == 0) { _trans(ad, _ST_SIM); do_state(ad); return; } if (retry == 1) { len = g_strlcpy(buf, pwlock_get_string(IDS_IDLE_BODY_1_ATTEMPT_LEFT), sizeof(buf)); if (len >= sizeof(buf)) { return; /* overrun */ } } else { len = snprintf(buf, sizeof(buf), pwlock_get_string(IDS_IDLE_BODY_PD_ATTEMPTS_LEFT), retry); if (len == -1) { return; /* over run */ } else if (len > 0) { buf[len] = '\0'; } } show_popup(ad, buf, EINA_TRUE); clear_entry(ad); pwlock_tapi_get_sim_lock_info(ad->t); //if (ad->state == _ST_SIM_PUKCNF) { // ecore_timer_add(3, show_puk_do, ad); //} } static void _sim_retry_no_cnt(struct appdata *ad) { _DBG("%s", __func__); show_msg(ad, IDS_IDLE_BODY_WRONG_PASSWORD); clear_entry(ad); } static void _pwlock_tapi_cb(struct pwlock_tapi_info *i, struct appdata *ad) { _DBG("%s, i->st:%d", __func__, i->st); switch (i->st) { case SIM_REQUIRED_EVENT: if ((ad->sim_status != 0) && (ad->sim_status == SIM_WAITING)) { _trans(ad, _ST_SIM); do_state(ad); } break; case SIM_OK: _trans(ad, _ST_SIM); do_state(ad); break; case SIM_RETRY: _sim_retry(ad, i->retry_cnt); break; case SIM_ERROR: _ERR("SIM check error"); _trans(ad, _ST_EXIT); show_msg(ad, IDS_IDLE_POP_SIM_CARD_ERROR); ecore_timer_add(3, timer_do, ad); break; case SIM_REQ_PIN: if (ad->state == _ST_SIM_PINCNF) { _sim_retry(ad, i->retry_cnt); } else { _trans(ad, _ST_SIM); do_state(ad); } break; case SIM_REQ_PUK: if (ad->state == _ST_SIM_PUKCNF) { _sim_retry(ad, i->retry_cnt); } else { show_msg(ad, IDS_IDLE_BODY_INCORRECT_PIN); //ecore_timer_add(3, show_puk_do, ad); pwlock_tapi_get_sim_lock_info(ad->t); ad->sim_status = i->st; } break; case SIM_REQ_LOCK: _sim_retry_no_cnt(ad); break; case SIM_REQ_NCK: clear_entry(ad); ad->sub_state = TAPI_SIM_LOCK_PN; _trans(ad, _ST_NETWORK_LOCKCNF); do_state(ad); break; case SIM_REQ_NSCK: clear_entry(ad); ad->sub_state = TAPI_SIM_LOCK_PU; _trans(ad, _ST_NETWORK_LOCKCNF); do_state(ad); break; case SIM_REQ_SPCK: clear_entry(ad); ad->sub_state = TAPI_SIM_LOCK_PP; _trans(ad, _ST_NETWORK_LOCKCNF); do_state(ad); break; case SIM_REQ_CCK: clear_entry(ad); ad->sub_state = TAPI_SIM_LOCK_PC; _trans(ad, _ST_NETWORK_LOCKCNF); do_state(ad); break; case SIM_LOCK_INFO: { _DBG("ad->sim_status = %d", ad->sim_status); ad->retry_cnt = i->retry_cnt; switch (ad->sim_status) { case SIM_REQ_PIN: show_pin(ad); _trans(ad, _ST_SIM_PINCNF); break; case SIM_REQ_PUK: show_puk(ad); _trans(ad, _ST_SIM_PUKCNF); break; case SIM_REQ_LOCK: if (ad->pin_changed == 1) { show_msg(ad, IDS_IDLE_POP_PIN_CHANGED); } else { show_sim_lock(ad); } _trans(ad, _ST_SIM_LOCKCNF); break; case SIM_REQ_NCK: if (ad->pin_changed == 1) { show_msg(ad, IDS_IDLE_POP_PIN_CHANGED); } else { show_sim_lock(ad); } ad->sub_state = TAPI_SIM_LOCK_PN; _trans(ad, _ST_NETWORK_LOCKCNF); break; case SIM_REQ_NSCK: if (ad->pin_changed == 1) { show_msg(ad, IDS_IDLE_POP_PIN_CHANGED); } else { show_sim_lock(ad); } ad->sub_state = TAPI_SIM_LOCK_PU; _trans(ad, _ST_NETWORK_LOCKCNF); break; case SIM_REQ_SPCK: if (ad->pin_changed == 1) { show_msg(ad, IDS_IDLE_POP_PIN_CHANGED); } else { show_sim_lock(ad); } ad->sub_state = TAPI_SIM_LOCK_PP; _trans(ad, _ST_NETWORK_LOCKCNF); break; case SIM_REQ_CCK: if (ad->pin_changed == 1) { show_msg(ad, IDS_IDLE_POP_PIN_CHANGED); } else { show_sim_lock(ad); } ad->sub_state = TAPI_SIM_LOCK_PC; _trans(ad, _ST_NETWORK_LOCKCNF); break; default: break; } } break; default: /* do nothing */ break; } } static void pwlock_tapi_cb(struct pwlock_tapi_info *i, void *data) { struct appdata *ad = data; _DBG("%s, ad->state:%d", __func__, ad->state); if (ad->state == _ST_EXIT) return; _pwlock_tapi_cb(i, ad); return; } static int do_ST_FIRST(struct appdata *ad) { int r = 0; int first = 0; int is_emul; char *model = NULL; _DBG("%s", __func__); r = system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &model); if (r != SYSTEM_INFO_ERROR_NONE) { _ERR("system_info_get_value_string return error : %d", r); } else { _DBG("SYSTEM_INFO_KEY_MODEL = %s\n", model); } /* * if model is NULL, pwlock crash */ if (model && !strncmp("Emulator", model, strlen(model))) is_emul = 1; else is_emul = 0; PWLOCK_MEMFREE(model); r = vconf_get_bool(VCONFKEY_PWLOCK_FIRST_BOOT, &first); _DBG("vconf get %s, result:%d, get_value:%d", VCONFKEY_PWLOCK_FIRST_BOOT, r, first); if ((r == 0 && first == 0) || (ad->is_exec_after_bootup > 0)) { _DBG("Not first booting time"); ad->is_first_boot = 0; // change booting seq. - syhwang@20120627 vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 1); } else { _DBG("First booting time"); ad->is_first_boot = 1; set_default_timezone(ad); if (is_emul) vconf_set_bool(VCONFKEY_PWLOCK_FIRST_BOOT, 0); } if (is_emul) _trans(ad, _ST_EXIT); else _trans(ad, _ST_TAPI_INIT); do_state(ad); return EINA_TRUE; } static int do_ST_GREETING(struct appdata *ad) { _DBG("%s", __func__); if (show_greeting(ad)) { if (ad->is_first_boot) vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 1); return EINA_TRUE; } else return EINA_FALSE; } static int do_ST_CONNECTION(struct appdata *ad) { _DBG("%s", __func__); if (show_connection(ad)) return EINA_TRUE; else return EINA_FALSE; } static int do_ST_TUTORIAL(struct appdata *ad) { _DBG("%s", __func__); if (show_tutorial(ad)) return EINA_TRUE; else return EINA_FALSE; } static Eina_Bool timer_do(void *data) { do_state(data); return ECORE_CALLBACK_CANCEL; } static void set_pwlock_unlock_state(struct appdata *ad) { if (ad->is_exec_after_bootup > 0) vconf_set_int(VCONFKEY_PWLOCK_STATE, VCONFKEY_PWLOCK_RUNNING_UNLOCK); else vconf_set_int(VCONFKEY_PWLOCK_STATE, VCONFKEY_PWLOCK_BOOTING_UNLOCK); } static void set_pwlock_lock_state(struct appdata *ad) { if (ad->is_exec_after_bootup > 0) vconf_set_int(VCONFKEY_PWLOCK_STATE, VCONFKEY_PWLOCK_RUNNING_LOCK); else vconf_set_int(VCONFKEY_PWLOCK_STATE, VCONFKEY_PWLOCK_BOOTING_LOCK); } static void vconf_call_state_changed_cb(keynode_t * node, void *data) { int api_ret = 0; int vconf_val = 0; struct appdata *ad = data; _DBG("%s", __func__); api_ret = vconf_get_int(VCONFKEY_CALL_STATE, &vconf_val); if (api_ret != 0) { _DBG("fail to get vconf key %s value", VCONFKEY_CALL_STATE); } else { if (vconf_val == VCONFKEY_CALL_OFF) { _DBG("call off state.."); set_win_prop(ad, ECORE_X_WINDOW_TYPE_NOTIFICATION); } else { _DBG("call on state.."); set_win_prop(ad, ECORE_X_WINDOW_TYPE_NORMAL); } } return; } static void register_vconf_call_state_changed(struct appdata *ad) { _DBG("%s", __func__); if (vconf_notify_key_changed (VCONFKEY_CALL_STATE, vconf_call_state_changed_cb, ad) != 0) { _DBG("Fail to register"); } } void vconf_tapi_ready_changed_cb(keynode_t * node, void *data) { int api_ret = 0; int vconf_val = 0; struct appdata *ad = data; _DBG("vconf_tapi_ready_changed_cb..!!"); api_ret = vconf_get_int(VCONFKEY_TELEPHONY_TAPI_STATE, &vconf_val); if (api_ret != 0) { _DBG("fail to get vconf key value"); } else { if (vconf_val == VCONFKEY_TELEPHONY_TAPI_STATE_NONE) { _DBG("TAPI is not ready"); } else { _DBG("TAPI is ready"); if (ad->pTimerId != NULL) { if (ecore_timer_del(ad->pTimerId) == NULL) { _DBG("FAIL to stop timer with pTimerId[%x]", (int)ad->pTimerId); } else { _DBG("SUCCESS to stop timer with pTimerId[%x]", (int)ad->pTimerId); } } _trans(ad, _ST_SIM); do_state(ad); } } return; } void register_vconf_tapi_ready_changed(struct appdata *ad) { _DBG("%s", __func__); if (vconf_notify_key_changed (VCONFKEY_TELEPHONY_TAPI_STATE, vconf_tapi_ready_changed_cb, ad) != 0) { _DBG("Fail to register"); } } Eina_Bool vconf_tapi_ready_expire_cb(void *pData) { int api_ret = 0; int vconf_val = 0; struct appdata *ad = pData; _DBG("vconf_tapi_ready_expire_cb..!!"); api_ret = vconf_get_int(VCONFKEY_TELEPHONY_TAPI_STATE, &vconf_val); if (api_ret != 0) { _DBG("fail to get vconf key value"); } else { if (vconf_val == VCONFKEY_TELEPHONY_TAPI_STATE_NONE) { _DBG("TAPI is not ready, pwlock exit"); if (ad->is_exec_after_bootup == 0 && ad->is_first_boot && ad->cancel_setup == 0) _trans(ad, _ST_GREETING); else _trans(ad, _ST_EXIT); do_state(ad); } else { _DBG("TAPI is ready"); _trans(ad, _ST_SIM); do_state(ad); } } return ECORE_CALLBACK_CANCEL; } void vconf_tapi_init_ready_changed_cb(keynode_t * node, void *data) { int api_ret = 0; int isReady = 0; struct appdata *ad = data; _DBG("vconf_tapi_init_ready_changed_cb..!!"); api_ret = vconf_get_bool(VCONFKEY_TELEPHONY_READY, &isReady); if (api_ret != 0) { _DBG("fail to get vconf key value"); } else { if (!isReady) { _DBG("telephony init is not ready"); } else { _DBG("telephony init is ready"); vconf_ignore_key_changed (VCONFKEY_TELEPHONY_READY, vconf_tapi_init_ready_changed_cb); _trans(ad, _ST_TAPI_INIT); do_state(ad); } } return; } void register_vconf_tapi_init_ready_changed(struct appdata *ad) { _DBG("%s", __func__); if (vconf_notify_key_changed (VCONFKEY_TELEPHONY_READY, vconf_tapi_init_ready_changed_cb, ad) != 0) { _DBG("Fail to register"); } } static int do_ST_TAPI_INIT(struct appdata *ad) { int r; int is_emul; char *model = NULL; int bReady = 0; _DBG("%s", __func__); vconf_get_bool(VCONFKEY_TELEPHONY_READY, &bReady); if (!bReady) { _DBG("telephony is not ready"); register_vconf_tapi_init_ready_changed(ad); return EINA_FALSE; } _DBG("telephony is ready for init"); r = system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &model); if (r != SYSTEM_INFO_ERROR_NONE) { _ERR("system_info_get_value_string return error : %d", r); } else { _DBG("SYSTEM_INFO_KEY_MODEL = %s\n", model); } if (model && !strncmp("Emulator", model, strlen(model))) is_emul = 1; else is_emul = 0; PWLOCK_MEMFREE(model); ad->t = pwlock_tapi_init(pwlock_tapi_cb, ad); if (ad->t == NULL) { _ERR("TAPI init error"); if (ad->is_exec_after_bootup == 0 && ad->is_first_boot && ad->cancel_setup == 0) _trans(ad, _ST_GREETING); else _trans(ad, _ST_EXIT); do_state(ad); return EINA_FALSE; } r = pwlock_tapi_ready_check(); _DBG("tapi_ready_check : %d", r); if (r == 0 && is_emul == 0) { /* SHOULD MANAGE TIMER FROM NOW - START PART */ ad->pTimerId = ecore_timer_add(20, vconf_tapi_ready_expire_cb, ad); register_vconf_tapi_ready_changed(ad); r = EINA_FALSE; } else { _trans(ad, _ST_SIM); do_state(ad); r = EINA_TRUE; } return r; } static int do_ST_SIM(struct appdata *ad) { int r; int is_sim_changed = 0; _DBG("%s", __func__); set_pwlock_unlock_state(ad); set_pwlock_lock_state(ad); ad->sim_status = pwlock_tapi_check_sim(ad->t, &is_sim_changed); _DBG("ad->sim_status=%d, sim_changed=%d, ad->is_first_boot=%d", ad->sim_status, is_sim_changed, ad->is_first_boot); switch (ad->sim_status) { case SIM_REQ_PIN: case SIM_REQ_PUK: case SIM_REQ_LOCK: case SIM_REQ_NCK: case SIM_REQ_NSCK: case SIM_REQ_SPCK: case SIM_REQ_CCK: _DBG("ad->sim_status = %d", ad->sim_status); pwlock_tapi_get_sim_lock_info(ad->t); r = EINA_TRUE; break; case SIM_OK: if (ad->is_exec_after_bootup == 0 && ad->is_first_boot && ad->cancel_setup == 0) { /* First boot & don't cancel setup wizard */ if (ad->is_no_sim == 1) { _trans(ad, _ST_TIME); } else { _trans(ad, _ST_GREETING); } } else { _trans(ad, _ST_EXIT); } ad->is_no_sim = 0; if (ad->pin_changed == 1) { r = EINA_TRUE; show_msg(ad, IDS_IDLE_POP_PIN_CHANGED); ecore_timer_add(3, timer_do, ad); ad->pin_changed = 0; } else { do_state(ad); r = EINA_TRUE; } break; case SIM_WAITING: /* wait till tapi send evt.. */ r = EINA_TRUE; break; case SIM_BLOCKED: show_block(ad); r = EINA_TRUE; break; case SIM_RETRY: /* do nothing, wait for TAPI callback */ ecore_timer_add(0.2, timer_do, ad); r = EINA_TRUE; break; case SIM_EMPTY: if (ad->is_exec_after_bootup == 0 && ad->is_first_boot && ad->cancel_setup == 0) { if (ad->is_no_sim != 1) { _trans(ad, _ST_GREETING); } else { _trans(ad, _ST_NOSIM); } } else { _trans(ad, _ST_EXIT); } ad->is_no_sim = 1; if (ad->state != _ST_NOSIM) { _DBG("not _ST_NOSIM"); do_state(ad); } r = EINA_TRUE; break; default: _ERR("Unexpected sim state: %d", ad->sim_status); _trans(ad, _ST_EXIT); do_state(ad); r = EINA_FALSE; break; } return r; } static int do_ST_NOSIM(struct appdata *ad) { _DBG("%s", __func__); if (show_nosim(ad)) return EINA_TRUE; else return EINA_FALSE; } static int do_ST_SIM_PINCNF(struct appdata *ad) { int r; _DBG("%s", __func__); if (!ad->entry_str) { _ERR("entry string is empty"); return EINA_FALSE; } r = pwlock_tapi_verify_pins(ad->t, ad->entry_str); if (r == -1) { _ERR("verify pin error"); _trans(ad, _ST_EXIT); do_state(ad); return EINA_FALSE; } return EINA_TRUE; } static int do_ST_SIM_PUKCNF(struct appdata *ad) { int r; _DBG("%s", __func__); ad->pin_changed = 1; if (!ad->entry_str || !ad->pin_str) { _ERR("entry string is empty"); return EINA_FALSE; } r = pwlock_tapi_verify_puks(ad->t, ad->entry_str, ad->pin_str); if (r == -1) { _ERR("verify puk error"); _trans(ad, _ST_EXIT); do_state(ad); return EINA_FALSE; } return EINA_TRUE; } static int do_ST_SIM_LOCKCNF(struct appdata *ad) { int r; _DBG("%s", __func__); if (!ad->entry_str) { _ERR("entry string is empty"); return EINA_FALSE; } r = pwlock_tapi_verify_lock(ad->t, ad->entry_str); if (r == -1) { _ERR("verify pin error"); _trans(ad, _ST_EXIT); do_state(ad); return EINA_FALSE; } return EINA_TRUE; } static int do_ST_NETWORK_LOCKCNF(struct appdata *ad) { int r; _DBG("%s", __func__); if (!ad->entry_str) { _ERR("entry string is empty"); return EINA_FALSE; } r = pwlock_tapi_disable_net_pers(ad->t, ad->entry_str, ad->sub_state); if (r == -1) { _ERR("Disable network personalization failed"); _trans(ad, _ST_EXIT); do_state(ad); return EINA_FALSE; } return EINA_TRUE; } static int do_ST_EXIT(struct appdata *ad) { int r; int locked; _DBG("%s", __func__); locked = 0; r = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &locked); _DBG("r = %d locked = %d", r, locked); if ((r != 0) || (locked == 0)) { /* prevent */ _DBG("set %s to true", VCONFKEY_STARTER_SEQUENCE); vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 1); } elm_exit(); return EINA_TRUE; } static int do_ST_LANG(struct appdata *ad) { _DBG("%s", __func__); if (show_lang(ad)) return EINA_TRUE; else return EINA_FALSE; } static int do_ST_TIME(struct appdata *ad) { _DBG("%s", __func__); if (show_time(ad)) return EINA_TRUE; else return EINA_FALSE; } static int do_ST_FINISH(struct appdata *ad) { _DBG("%s", __func__); if (show_finish(ad)) return EINA_TRUE; else return EINA_FALSE; } void do_state(struct appdata *ad) { if ( ad == NULL ) { _ERR("%s, ad is null", __func__); return ; } _DBG("%s, ad->state:%d", __func__, ad->state); if (ad->state < _ST_START || ad->state >= _ST_MAX) { _ERR("Unknown state: %d", ad->state); do_state_directly(_ST_EXIT, ad); } else states[ad->state]._do(ad); } void do_state_directly(int state, void *data) { struct appdata *ad = data; if ( ad == NULL ) { _ERR("ad is null"); return ; } _trans(ad, state); if (ad->state < _ST_START || ad->state >= _ST_MAX) { _ERR("Unknown state: %d", ad->state); do_state_directly(_ST_EXIT, ad); } else states[ad->state]._do(ad); } void set_win_prop(struct appdata *ad, int type) { Ecore_X_Window w; w = elm_win_xwindow_get(ad->win); if (type == ECORE_X_WINDOW_TYPE_NORMAL) { ecore_x_netwm_window_type_set(w, ECORE_X_WINDOW_TYPE_NORMAL); ad->win_type = ECORE_X_WINDOW_TYPE_NORMAL; } else if (type == ECORE_X_WINDOW_TYPE_NOTIFICATION) { ecore_x_netwm_window_type_set(w, ECORE_X_WINDOW_TYPE_NOTIFICATION); utilx_set_system_notification_level(ecore_x_display_get(), w, UTILX_NOTIFICATION_LEVEL_LOW); ad->win_type = ECORE_X_WINDOW_TYPE_NOTIFICATION; } } static void set_key_grab(Evas_Object * win) { Ecore_X_Window w; w = elm_win_xwindow_get(win); utilx_grab_key(ecore_x_display_get(), w, KEY_SELECT, EXCLUSIVE_GRAB); /* FIXME for blocking camera launching */ utilx_grab_key(ecore_x_display_get(), w, KEY_CAMERA, TOP_POSITION_GRAB); } static void pwlock_focus_out_cb(void *data, Evas_Object * obj, void *event_info) { int pid = 0; char buf[128]; Ecore_X_Window x_win_focused; struct appdata *ad = data; _DBG("%s", __func__); x_win_focused = ecore_x_window_focus_get(); if (!ecore_x_netwm_pid_get(x_win_focused, &pid)) { pid = 0; } if (aul_app_get_pkgname_bypid(pid, buf, sizeof(buf)) < 0) { _DBG("no such pkg by pid %d\n", pid); } else { char *pkg_str; _DBG("created pkgname = %s, pid = %d\n", buf, pid); pkg_str = vconf_get_str(MENUSCREEN_PKG_NAME); if ((pkg_str != NULL) && !strncmp(pkg_str, buf, strlen(pkg_str))) { _DBG("%s is on the pwlock.!!\n", pkg_str); elm_win_raise(ad->win); free(pkg_str); pkg_str = NULL; } else if (!strncmp("org.tizen.live-magazine", buf, strlen(buf))) { _DBG("%s is on the pwlock.!!\n", buf); elm_win_raise(ad->win); } } } static int _batt_cb(void *data) { _ERR("System battry goes low"); return 0; } static int app_create(void *data) { struct appdata *ad = data; _DBG("%s", __func__); ad->win = create_win(PACKAGE); if (ad->win == NULL) { _ERR("Create win error"); return -1; } ecore_imf_init(); set_key_grab(ad->win); register_vconf_call_state_changed(ad); /* for exception */ evas_object_smart_callback_add(ad->win, "focus,out", pwlock_focus_out_cb, ad); appcore_set_i18n(PACKAGE, LOCALEDIR); appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY, _batt_cb, ad); if (ad->elm_navigation_frame) { evas_object_del(ad->elm_navigation_frame); ad->elm_navigation_frame = NULL; if (ad->layout_contents) { evas_object_del(ad->layout_contents); ad->layout_contents = NULL; } if (ad->layout_entry) { evas_object_del(ad->layout_entry); ad->layout_entry = NULL; } if (ad->layout_second_entry) { evas_object_del(ad->layout_second_entry); ad->layout_second_entry = NULL; } if (ad->elm_conform) { evas_object_del(ad->elm_conform); ad->elm_conform = NULL; } } ad->is_no_sim = 0; ad->retry_cnt = 0; pwlock_langlist_load(); ad->state = _ST_FIRST; do_state(ad); return 0; } static int app_terminate(void *data) { struct appdata *ad = data; _DBG("===============> %s", __func__); set_pwlock_unlock_state(ad); pwlock_langlist_destroy(); if (ad->t) pwlock_tapi_exit(&ad->t); if (ad->win) { utilx_ungrab_key(ecore_x_display_get(), elm_win_xwindow_get(ad->win), KEY_SELECT); /* FIXME for blocking camera launching */ utilx_ungrab_key(ecore_x_display_get(), elm_win_xwindow_get(ad->win), KEY_CAMERA); evas_object_del(ad->win); } if (ad->elm_navigation_frame) { evas_object_del(ad->elm_navigation_frame); ad->elm_navigation_frame = NULL; } if (ad->layout_contents) { evas_object_del(ad->layout_contents); ad->layout_contents = NULL; } if (ad->layout_entry) { evas_object_del(ad->layout_entry); ad->layout_entry = NULL; } if (ad->layout_second_entry) { evas_object_del(ad->layout_second_entry); ad->layout_second_entry = NULL; } if (ad->elm_bg) { evas_object_del(ad->elm_bg); ad->elm_bg = NULL; } if (ad->elm_conform) { evas_object_del(ad->elm_conform); ad->elm_conform = NULL; } if (ad->idler) { ecore_idler_del(ad->idler); ad->idler = NULL; } if (ad->date_ug) { ug_destroy(ad->date_ug); ad->date_ug = NULL; } if (ad->connection_ug) { ug_destroy(ad->connection_ug); ad->connection_ug = NULL; } remove_waiting_popup(ad); ecore_imf_shutdown(); return 0; } static int app_pause(void *data) { struct appdata *ad = data; _DBG("%s", __func__); if (ad->current_ug) { _DBG("ug_pause!!"); ug_pause(); } return 0; } static int app_reset(service_h service, void *data) { struct appdata *ad = data; _DBG("%s", __func__); if (ad->win) elm_win_activate(ad->win); return 0; } static int app_resume(void *data) { struct appdata *ad = data; _DBG("%s", __func__); if (ad->current_ug) { _DBG("ug_resume!!"); ug_resume(); } return 0; } /* static void pwlock_signal_handler(int sig) { _DBG("pwlock recieve signal[%d]", sig); switch(sig) { case SIGSEGV: _DBG("SIGSEGV signal is raised"); vconf_set_int(VCONFKEY_PWLOCK_STATE, VCONFKEY_PWLOCK_BOOTING_UNLOCK); break; default: break; } sigaction(sig, &g_oldact, NULL); raise(sig); } static void register_sig_handler(void) { _DBG("register pwlock signal handler"); struct sigaction act; act.sa_handler = pwlock_signal_handler; sigemptyset(&act.sa_mask); act.sa_flags = SA_RESETHAND; if (sigaction(SIGSEGV, &act, &g_oldact) < 0) { _ERR("%s - could not set signal handler", __func__); } } */ int main(int argc, char *argv[]) { struct appdata ad; struct appcore_ops ops = { .create = app_create, .terminate = app_terminate, .pause = app_pause, .reset = app_reset, .resume = app_resume, }; memset(&ad, 0x0, sizeof(struct appdata)); // disable temporary (libisf-imf-module.so SIGSEGV) //register_sig_handler(); _DBG("\n\n========= pwlock is started..!! ===========\n"); if (argc > 1) { _DBG("argv[1]:%s ", argv[1]); ad.is_exec_after_bootup = atoi(argv[1]); _DBG("ad.is_exec_after_bootup : %d", ad.is_exec_after_bootup); } else { ad.is_exec_after_bootup = 0; system("chmod 666 " LOGFILE); } ops.data = &ad; return appcore_efl_main(PACKAGE, &argc, &argv, &ops); }