4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
21 #include <setting-common-data-type.h>
22 #include <setting-common-data-slp-setting.h>
23 #include <setting-common-draw-widget.h>
24 #include <setting-common-view.h>
26 #include <setting-security-sim-settings.h>
27 #include <setting-security-main.h>
28 #include <setting-debug.h>
30 static int setting_security_sim_settings_create(void *cb);
31 static int setting_security_sim_settings_destroy(void *cb);
32 static int setting_security_sim_settings_update(void *cb);
33 static int setting_security_sim_settings_cleanup(void *cb);
35 setting_view setting_view_security_sim_settings = {
36 .create = setting_security_sim_settings_create,
37 .destroy = setting_security_sim_settings_destroy,
38 .update = setting_security_sim_settings_update,
39 .cleanup = setting_security_sim_settings_cleanup,
42 /* ***************************************************
46 ****************************************************/
48 static int setting_security_sim_settings_create(void *cb)
51 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
53 SettingSecurityUG *ad = (SettingSecurityUG *) cb;
55 Evas_Object *scroller;
56 Elm_Object_Item *item = NULL;
58 /* add basic layout */
59 setting_push_layout_navi_bar_genlist(ad->win_main_layout,
61 SECURITY_SIM_SETTINGS,
62 _("IDS_COM_BODY_BACK"), NULL,
63 (setting_call_back_func)setting_security_sim_settings_click_softkey_back_cb,
64 NULL, ad, &scroller, ad->navi_bar);
66 evas_object_smart_callback_add(scroller, "realized", __gl_realized_cb, NULL);
69 item = elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
70 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
72 /* to do : sim settings menu */
74 /*if TAPI is responsed in time, ad->sim_status will have invalid value, */
75 /*or else ad->data_pin_lk will be updated by setting_security_sim_get_facility_cb */
76 ad->data_pin_lk = setting_create_Gendial_field_def(scroller, &itc_1text_1icon,
77 setting_security_sim_settings_mouse_up_Gendial_list_cb, ad,
78 SWALLOW_Type_1ICON_1RADIO,
80 ad->pin1_status, "IDS_COM_BODY_PIN_LOCK", NULL, setting_security_sim_settings_chk_btn_cb);
81 if (ad->data_pin_lk) {
82 ad->data_pin_lk->userdata = ad;
83 ad->data_pin_lk->group_style = SETTING_GROUP_STYLE_TOP;
86 ad->data_change_pin1 = setting_create_Gendial_field_def(scroller, &(ad->itc_1text),
87 setting_security_sim_settings_mouse_up_Gendial_list_cb, ad,
90 0, "IDS_ST_HEADER_CHANGE_PIN_ABB", NULL, NULL);
92 if (ad->data_change_pin1) {
93 ad->data_change_pin1->group_style = SETTING_GROUP_STYLE_CENTER;
96 if (!ad->pin1_status) {
97 if (ad->data_change_pin1) {
98 setting_disable_genlist_item(ad->data_change_pin1->item);
103 if (ad->pin2_blocked_flag) {
104 ad->data_change_pin2 = setting_create_Gendial_field_def(scroller, &(ad->itc_1text),
105 setting_security_sim_settings_mouse_up_Gendial_list_cb, ad,
106 SWALLOW_Type_INVALID,
108 0, "IDS_CST_BODY_UNBLOCK_PIN2", NULL, NULL);
110 ad->data_change_pin2 = setting_create_Gendial_field_def(scroller, &(ad->itc_1text),
111 setting_security_sim_settings_mouse_up_Gendial_list_cb, ad,
112 SWALLOW_Type_INVALID,
114 0, "IDS_ST_BODY_CHANGE_PIN2", NULL, NULL);
117 if (ad->data_change_pin2) {
118 ad->data_change_pin2->group_style = SETTING_GROUP_STYLE_BOTTOM;
123 /*if TAPI is responsed in time, ad->sim_status will have invalid value, */
124 /*or else ad->data_fdn will be updated by setting_security_sim_get_facility_cb */
125 ad->data_fdn = setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
126 setting_security_sim_settings_mouse_up_Gendial_list_cb, ad,
127 SWALLOW_Type_1TOGGLE,
129 ad->pin2_status, Keystr_FDN, NULL, setting_security_sim_settings_chk_btn_cb);
131 ad->data_fdn->userdata = ad;
134 evas_object_smart_callback_add(scroller, "realized", __gl_realized_cb, ad);
136 setting_view_security_sim_settings.is_create = 1;
138 return SETTING_RETURN_SUCCESS;
142 static int setting_security_sim_settings_destroy(void *cb)
146 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
148 SettingSecurityUG *ad = (SettingSecurityUG *) cb;
149 if (ad->tapi_async_cb_check_timer) {
150 ecore_timer_del(ad->tapi_async_cb_check_timer);
151 ad->tapi_async_cb_check_timer = NULL;
153 /*elm_naviframe_item_pop(ad->navi_bar); */
155 setting_view_security_sim_settings.is_create = 0;
157 return SETTING_RETURN_SUCCESS;
160 static int setting_security_sim_settings_update(void *cb)
164 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
166 SettingSecurityUG *ad = (SettingSecurityUG *) cb;
167 SETTING_TRACE("Update PIN menu");
168 if (ad->data_pin_lk) { /*it indicates TAPI is not responsed in time */
169 /*setting_update_gl_item_chk_status(ad->data_pin_lk, ad->pin1_status); */
170 ad->data_pin_lk->chk_status = ad->pin1_status;
171 elm_genlist_item_fields_update(ad->data_pin_lk->item, "*", ELM_GENLIST_ITEM_FIELD_CONTENT);
173 if (ad->data_pin_lk->chk_status == 0)
174 setting_disable_genlist_item(ad->data_change_pin1->item);
176 setting_enable_genlist_item(ad->data_change_pin1->item);
179 if (ad->data_change_pin2 && ad->data_change_pin2->item) {
180 if (ad->pin2_blocked_flag) {
181 if (!safeStrCmp(ad->data_change_pin2->keyStr, "IDS_ST_BODY_CHANGE_PIN2")) {
182 ad->data_change_pin2->keyStr = (char *)g_strdup("IDS_CST_BODY_UNBLOCK_PIN2");
183 elm_object_item_data_set(ad->data_change_pin2->item, ad->data_change_pin2);
184 elm_genlist_item_update(ad->data_change_pin2->item);
187 if (!safeStrCmp(ad->data_change_pin2->keyStr, "IDS_CST_BODY_UNBLOCK_PIN2")) {
188 ad->data_change_pin2->keyStr = (char *)g_strdup("IDS_ST_BODY_CHANGE_PIN2");
189 elm_object_item_data_set(ad->data_change_pin2->item, ad->data_change_pin2);
190 elm_genlist_item_update(ad->data_change_pin2->item);
195 return SETTING_RETURN_SUCCESS;
198 static int setting_security_sim_settings_cleanup(void *cb)
202 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
204 SettingSecurityUG *ad = (SettingSecurityUG *) cb;
205 return setting_security_sim_settings_destroy(ad);
208 /* ***************************************************
212 ****************************************************/
214 static void get_pin_lock_info_cb(TapiHandle *handle, int result, void *data, void *user_data)
218 TelSimPinOperationResult_t sec_rt = result;
219 TelSimLockInfo_t *lock = data;
221 SettingSecurityUG *ad = (SettingSecurityUG *)user_data;
225 evas_object_del(ad->sim_popup);
226 ad->sim_popup = NULL;
228 ad->enter_tapi_async_cb_flag = 1;
230 int old_state = ad->data_pin_lk->chk_status;/*elm_check_state_get(ad->data_pin_lk->eo_check); */
232 SETTING_TRACE("Current status of PIN Lock is ON");
233 ad->pw_type = SETTING_SEC_PW_PIN_LOCK_OFF;
235 SETTING_TRACE("Current status of PIN Lock is OFF");
236 ad->pw_type = SETTING_SEC_PW_PIN_LOCK_ON;
239 SETTING_TRACE_DEBUG("sec_ret[%d], lock_type[%d], lock_status[%d], retry_count[%d]", sec_rt, lock->lock_type, lock->lock_status, lock->retry_count);
240 if (lock->lock_status == 2) { /* PUK */
241 SETTING_TRACE("Current status of PIN Lock is Blocked");
242 ad->pw_type = SETTING_SEC_PW_PIN1_BLOCKED;
243 } else if (lock->lock_status == 5) { /* Blocked */
244 setting_create_simple_popup(NULL, ad->win_get,
245 NULL, _("PUK is blocked. Can't use PIN Lock"));
249 setting_security_create_password_sg(ad);
252 static Eina_Bool _check_tapi_async_cb_is_called(void *data)
255 retv_if(data == NULL, EINA_FALSE);
257 SettingSecurityUG *ad = (SettingSecurityUG *)data;
259 if (!ad->enter_tapi_async_cb_flag) {
260 ad->sim_popup = setting_create_popup_without_btn(ad, ad->win_get,
261 NULL, _(KeyStr_Security_Waiting_Sim),
265 ad->tapi_async_cb_check_timer = NULL;
270 void _draw_pin_onoff_status(void *data, Evas_Object *check)
272 SETTING_TRACE("PIN Lock");
274 ret_if(data == NULL);
276 SettingSecurityUG *ad = (SettingSecurityUG *) data;
281 ad->sel_item = 0; /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
283 ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
285 ret = _handle_sim_exception(ad, value);
286 if (ret == SETTING_RETURN_FAIL)
289 /* check sim status */
290 int tapi_ret = TAPI_API_INVALID_INPUT;
291 TelSimCardType_t sim_card = TAPI_SIM_CARD_TYPE_UNKNOWN;
293 tapi_ret = tel_get_sim_type(ad->handle, &sim_card);
294 if (tapi_ret != TAPI_API_SUCCESS) {
295 SETTING_TRACE_ERROR("tel_get_sim_type call failed with error code %d", tapi_ret);
298 SETTING_TRACE("SIM Type is %d", (int)sim_card);
299 if (sim_card == (TelSimCardType_t) TAPI_SIM_CARD_TYPE_UNKNOWN) {
301 ("%s*** [ERR] tel_get_sim_type. sim_card=%d ***%s",
302 SETTING_FONT_RED, sim_card, SETTING_FONT_BLACK);
303 setting_create_simple_popup(NULL, ad->win_get,
304 NULL, _("IDS_COM_BODY_INVALID_SIM_CARD"));
308 ad->enter_tapi_async_cb_flag = 0;
309 ad->sim_popup = NULL;
310 ad->tapi_async_cb_check_timer = ecore_timer_add(0.5, _check_tapi_async_cb_is_called, ad);
312 if (tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_SC, get_pin_lock_info_cb, ad) != 0) {
313 SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
317 static void get_sim_lock_info_cb(TapiHandle *handle, int result, void *data, void *user_data)
320 ret_if(data == NULL || user_data == NULL);
322 TelSimPinOperationResult_t sec_rt = result;
323 TelSimLockInfo_t *lock = data;
325 SettingSecurityUG *ad = (SettingSecurityUG *)user_data;
329 evas_object_del(ad->sim_popup);
330 ad->sim_popup = NULL;
333 int old_state = ad->data_sim_lk->chk_status;/*elm_check_state_get(ad->data_sim_lk->eo_check); */
335 SETTING_TRACE("Current status of SIM Lock is ON");
336 ad->pw_type = SETTING_SEC_PW_SIM_LOCK_OFF;
338 SETTING_TRACE("Current status of SIM Lock is OFF");
339 ad->pw_type = SETTING_SEC_PW_SIM_LOCK_ON;
342 SETTING_TRACE_DEBUG("sec_ret[%d], lock_type[%d], lock_status[%d], retry_count[%d]", sec_rt, lock->lock_type, lock->lock_status, lock->retry_count);
344 if (lock->lock_status == 5) { /* Blocked */
345 setting_create_simple_popup(NULL, ad->win_get,
346 NULL, _("SIM is blocked. Can't use SIM Lock"));
350 setting_security_create_password_sg(ad);
353 void _draw_sim_onoff_status(void *data, Evas_Object *check)
355 ret_if(data == NULL);
357 SettingSecurityUG *ad = (SettingSecurityUG *) data;
362 ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
363 ret = _handle_sim_exception(ad, value);
364 if (ret == SETTING_RETURN_FAIL)
369 evas_object_del(ad->sim_popup);
370 ad->sim_popup = NULL;
372 ad->sim_popup = setting_create_popup_without_btn(ad, ad->win_get,
373 NULL, _(KeyStr_Security_Waiting_Sim),
377 if (tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_PS, get_sim_lock_info_cb, ad) != 0) {
378 SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
382 static void get_change_pin_info_cb(TapiHandle *handle, int result, void *data, void *user_data)
385 ret_if(data == NULL || user_data == NULL);
387 TelSimPinOperationResult_t sec_rt = result;
388 TelSimLockInfo_t *lock = data;
390 SettingSecurityUG *ad = (SettingSecurityUG *)user_data;
392 SETTING_TRACE_DEBUG("sec_ret[%d], lock_type[%d], lock_status[%d], retry_count[%d]", sec_rt, lock->lock_type, lock->lock_status, lock->retry_count);
393 if (lock->lock_type == TAPI_SIM_LOCK_SC && lock->lock_status == TAPI_SIM_LOCK_KEY_PUK) { /* PUK required : 0x02*/
394 SETTING_TRACE("Current status of PIN Lock is Blocked");
395 ad->pw_type = SETTING_SEC_PW_PIN1_BLOCKED;
396 } else if (lock->lock_type == TAPI_SIM_LOCK_SC &&
397 (lock->lock_status == TAPI_SIM_LOCK_KEY_NOT_NEED || lock->lock_status == TAPI_SIM_LOCK_KEY_PIN)) { /* PIN required : 0x00, 0x01 */
398 ad->pw_type = SETTING_SEC_PW_CHANGE_PIN1;
399 } else if (lock->lock_type == TAPI_SIM_LOCK_FD && lock->lock_status == TAPI_SIM_LOCK_KEY_PUK2) { /* PUK2 required : 0x04 */
400 SETTING_TRACE("Current status of Change PIN2 is Blocked");
401 ad->pw_type = SETTING_SEC_PW_PIN2_BLOCKED;
402 } else if (lock->lock_type == TAPI_SIM_LOCK_FD &&
403 (lock->lock_status == TAPI_SIM_LOCK_KEY_NOT_NEED || lock->lock_status == TAPI_SIM_LOCK_KEY_PIN2)) { /* PIN2 required : 0x00, 0x03 */
404 ad->pw_type = SETTING_SEC_PW_CHANGE_PIN2;
405 } else if (lock->lock_status == TAPI_SIM_LOCK_PERM_BLOCKED) { /* Blocked : 0x05 */
406 setting_create_simple_popup(NULL, ad->win_get,
407 NULL, _("Permanent block SIM"));
411 setting_security_create_password_sg(ad);
414 void _mouse_up_change_pin(void *data, int sel_item)
416 ret_if(data == NULL);
418 SettingSecurityUG *ad = (SettingSecurityUG *) data;
420 ad->sel_item = sel_item; /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
425 ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
426 setting_retm_if(ret != 0, "failed to read vconf value");
428 case VCONFKEY_TELEPHONY_SIM_INSERTED:
430 case VCONFKEY_TELEPHONY_SIM_NOT_PRESENT:
431 setting_create_simple_popup(NULL, ad->win_get,
432 NULL, _(SECURITY_SIM_NOT_PRESENT_MSG));
434 ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
435 SETTING_FONT_RED, value, SETTING_FONT_BLACK);
438 case VCONFKEY_TELEPHONY_SIM_CARD_ERROR:
439 case VCONFKEY_TELEPHONY_SIM_UNKNOWN:
440 setting_create_simple_popup(NULL, ad->win_get,
441 NULL, _("IDS_COM_BODY_INVALID_SIM_CARD"));
443 ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
444 SETTING_FONT_RED, value, SETTING_FONT_BLACK);
451 /* check sim status */
452 TapiResult_t tapi_ret = TAPI_API_INVALID_INPUT;
453 TelSimCardType_t sim_card = TAPI_SIM_CARD_TYPE_UNKNOWN;
455 tapi_ret = tel_get_sim_type(ad->handle, &sim_card);
456 if (tapi_ret != TAPI_API_SUCCESS) {
457 SETTING_TRACE_ERROR("tel_get_sim_type call failed with error code %d", tapi_ret);
460 if (sim_card == (TelSimCardType_t) SETTING_TAPI_UNKNOWN_SIM_TYPE) {
462 ("%s*** [ERR] tel_get_sim_type. sim_card=%d ***%s",
463 SETTING_FONT_RED, sim_card, SETTING_FONT_BLACK);
464 setting_create_simple_popup(NULL, ad->win_get,
465 NULL, _("IDS_COM_BODY_INVALID_SIM_CARD"));
468 if (sel_item == 1 && (ad->pin1_status == TAPI_SIM_FACILITY_ENABLED)) {
469 if (tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_SC, get_change_pin_info_cb, ad) != 0) {
470 SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
472 } else if (sel_item == 3) {
473 if (tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_FD, get_change_pin_info_cb, ad) != 0) {
474 SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
476 /*ad->pw_type = SETTING_SEC_PW_CHANGE_PIN2; */
477 /*setting_security_create_password_sg(ad); */
482 setting_security_sim_settings_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
487 setting_retm_if(data == NULL, "Data parameter is NULL");
489 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
490 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
491 elm_genlist_item_selected_set(item, 0);
492 Setting_GenGroupItem_Data *list_item =
493 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
496 SettingSecurityUG *ad = (SettingSecurityUG *) data;
498 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
499 if (!safeStrCmp("IDS_COM_BODY_PIN_LOCK", list_item->keyStr)) {
500 /*it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback */
501 _draw_pin_onoff_status(ad, list_item->eo_check);
503 } else if (!safeStrCmp("IDS_ST_HEADER_CHANGE_PIN_ABB", list_item->keyStr)) {
504 _mouse_up_change_pin(ad, 1); /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
505 } else if (!safeStrCmp("IDS_ST_BODY_CHANGE_PIN2", list_item->keyStr)) {
506 _mouse_up_change_pin(ad, 3); /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
507 } else if (!safeStrCmp("IDS_CST_BODY_UNBLOCK_PIN2", list_item->keyStr)) {
508 ad->pw_type = SETTING_SEC_PW_PIN2_BLOCKED;
509 setting_security_create_password_sg(ad);
514 setting_security_sim_settings_chk_btn_cb(void *data, Evas_Object *obj,
519 retm_if(data == NULL, "[Setting > Reset] Data parameter is NULL");
520 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
521 SettingSecurityUG *ad = list_item->userdata;
523 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
524 if (!safeStrCmp("IDS_COM_BODY_PIN_LOCK", list_item->keyStr)) {
525 /*Rollback state of toggle. */
526 /*it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback */
527 /*setting_update_gl_item_chk_status(list_item, !(list_item->chk_status)); */
528 list_item->chk_status = !(list_item->chk_status);
529 _draw_pin_onoff_status(ad, obj);
533 else if (!safeStrCmp(Keystr_FDN, list_item->keyStr)) {
534 /*Rollback state of toggle. */
535 /*it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback */
536 setting_update_gl_item_chk_status(list_item, !(list_item->chk_status));
538 _draw_fdn_onoff_status(ad, obj);
545 /*setting_security_sim_settings_click_softkey_back_cb(void *data, Evas_Object *obj, */
546 /* void *event_info) */
547 Eina_Bool setting_security_sim_settings_click_softkey_back_cb(void *data, Elm_Object_Item *it)
551 retv_if(data == NULL, EINA_FALSE);
553 SettingSecurityUG *ad = (SettingSecurityUG *) data;
561 setting_view_change(&setting_view_security_sim_settings, &setting_view_security_main, ad);