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_ST_BUTTON_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_ST_BODY_PIN_LOCK", NULL, setting_security_sim_settings_chk_btn_cb);
81 if (ad->data_pin_lk) {
82 ad->data_pin_lk->userdata = ad;
85 ad->data_change_pin1 = setting_create_Gendial_field_def(scroller, &(ad->itc_1text),
86 setting_security_sim_settings_mouse_up_Gendial_list_cb, ad,
89 0, "IDS_ST_HEADER_CHANGE_PIN_ABB", NULL, NULL);
91 if (ad->data_change_pin1) {
92 ad->data_change_pin1->userdata = ad;
95 if (!ad->pin1_status) {
96 if (ad->data_change_pin1) {
97 setting_disable_genlist_item(ad->data_change_pin1->item);
102 if (ad->pin2_blocked_flag) {
103 ad->data_change_pin2 = setting_create_Gendial_field_def(scroller, &(ad->itc_1text),
104 setting_security_sim_settings_mouse_up_Gendial_list_cb, ad,
105 SWALLOW_Type_INVALID,
107 0, "IDS_CST_BODY_UNBLOCK_PIN2", NULL, NULL);
109 ad->data_change_pin2 = setting_create_Gendial_field_def(scroller, &(ad->itc_1text),
110 setting_security_sim_settings_mouse_up_Gendial_list_cb, ad,
111 SWALLOW_Type_INVALID,
113 0, "IDS_ST_BODY_CHANGE_PIN2", NULL, NULL);
116 if (ad->data_change_pin2) {
117 ad->data_change_pin2->userdata = ad;
122 /*if TAPI is responsed in time, ad->sim_status will have invalid value, */
123 /*or else ad->data_fdn will be updated by setting_security_sim_get_facility_cb */
124 ad->data_fdn = setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
125 setting_security_sim_settings_mouse_up_Gendial_list_cb, ad,
126 SWALLOW_Type_1TOGGLE,
128 ad->pin2_status, Keystr_FDN, NULL, setting_security_sim_settings_chk_btn_cb);
130 ad->data_fdn->userdata = ad;
133 evas_object_smart_callback_add(scroller, "realized", __gl_realized_cb, ad);
135 setting_view_security_sim_settings.is_create = 1;
137 return SETTING_RETURN_SUCCESS;
141 static int setting_security_sim_settings_destroy(void *cb)
145 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
147 SettingSecurityUG *ad = (SettingSecurityUG *) cb;
148 if (ad->tapi_async_cb_check_timer) {
149 ecore_timer_del(ad->tapi_async_cb_check_timer);
150 ad->tapi_async_cb_check_timer = NULL;
152 /*elm_naviframe_item_pop(ad->navi_bar); */
154 setting_view_security_sim_settings.is_create = 0;
156 return SETTING_RETURN_SUCCESS;
159 static int setting_security_sim_settings_update(void *cb)
163 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
165 SettingSecurityUG *ad = (SettingSecurityUG *) cb;
166 SETTING_TRACE("Update PIN menu");
167 if (ad->data_pin_lk) { /*it indicates TAPI is not responsed in time */
168 /*setting_update_gl_item_chk_status(ad->data_pin_lk, ad->pin1_status); */
169 ad->data_pin_lk->chk_status = ad->pin1_status;
170 elm_genlist_item_fields_update(ad->data_pin_lk->item, "*", ELM_GENLIST_ITEM_FIELD_CONTENT);
172 if (ad->data_pin_lk->chk_status == 0)
173 setting_disable_genlist_item(ad->data_change_pin1->item);
175 setting_enable_genlist_item(ad->data_change_pin1->item);
178 if (ad->data_change_pin2 && ad->data_change_pin2->item) {
179 if (ad->pin2_blocked_flag) {
180 if (!safeStrCmp(ad->data_change_pin2->keyStr, "IDS_ST_BODY_CHANGE_PIN2")) {
181 ad->data_change_pin2->keyStr = (char *)g_strdup("IDS_CST_BODY_UNBLOCK_PIN2");
182 elm_object_item_data_set(ad->data_change_pin2->item, ad->data_change_pin2);
183 elm_genlist_item_update(ad->data_change_pin2->item);
186 if (!safeStrCmp(ad->data_change_pin2->keyStr, "IDS_CST_BODY_UNBLOCK_PIN2")) {
187 ad->data_change_pin2->keyStr = (char *)g_strdup("IDS_ST_BODY_CHANGE_PIN2");
188 elm_object_item_data_set(ad->data_change_pin2->item, ad->data_change_pin2);
189 elm_genlist_item_update(ad->data_change_pin2->item);
194 return SETTING_RETURN_SUCCESS;
197 static int setting_security_sim_settings_cleanup(void *cb)
201 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
203 SettingSecurityUG *ad = (SettingSecurityUG *) cb;
204 return setting_security_sim_settings_destroy(ad);
207 /* ***************************************************
211 ****************************************************/
213 static void get_pin_lock_info_cb(TapiHandle *handle, int result, void *data, void *user_data)
217 TelSimPinOperationResult_t sec_rt = result;
218 TelSimLockInfo_t *lock = data;
220 SettingSecurityUG *ad = (SettingSecurityUG *)user_data;
224 evas_object_del(ad->sim_popup);
225 ad->sim_popup = NULL;
227 ad->enter_tapi_async_cb_flag = 1;
229 int old_state = ad->data_pin_lk->chk_status;/*elm_check_state_get(ad->data_pin_lk->eo_check); */
231 SETTING_TRACE("Current status of PIN Lock is ON");
232 ad->pw_type = SETTING_SEC_PW_PIN_LOCK_OFF;
234 SETTING_TRACE("Current status of PIN Lock is OFF");
235 ad->pw_type = SETTING_SEC_PW_PIN_LOCK_ON;
238 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);
239 if (lock->lock_status == 2) { /* PUK */
240 SETTING_TRACE("Current status of PIN Lock is Blocked");
241 ad->pw_type = SETTING_SEC_PW_PIN1_BLOCKED;
242 } else if (lock->lock_status == 5) { /* Blocked */
243 setting_create_popup(NULL, ad->win_get,
244 NULL, _("PUK is blocked. Can't use PIN Lock"), NULL, 0, false, false, 0);
248 setting_security_create_password_sg(ad);
251 static Eina_Bool _check_tapi_async_cb_is_called(void *data)
254 retv_if(data == NULL, EINA_FALSE);
256 SettingSecurityUG *ad = (SettingSecurityUG *)data;
258 if (!ad->enter_tapi_async_cb_flag) {
259 ad->sim_popup = setting_create_popup(ad, ad->win_get,
260 NULL, KeyStr_Security_Waiting_Sim,
264 ad->tapi_async_cb_check_timer = NULL;
269 void _draw_pin_onoff_status(void *data, Evas_Object *check)
271 SETTING_TRACE("PIN Lock");
273 ret_if(data == NULL);
275 SettingSecurityUG *ad = (SettingSecurityUG *) data;
280 ad->sel_item = 0; /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
282 ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
284 ret = _handle_sim_exception(ad, value);
285 if (ret == SETTING_RETURN_FAIL)
288 /* check sim status */
289 int tapi_ret = TAPI_API_INVALID_INPUT;
290 TelSimCardType_t sim_card = TAPI_SIM_CARD_TYPE_UNKNOWN;
292 tapi_ret = tel_get_sim_type(ad->handle, &sim_card);
293 if (tapi_ret != TAPI_API_SUCCESS) {
294 SETTING_TRACE_ERROR("tel_get_sim_type call failed with error code %d", tapi_ret);
297 SETTING_TRACE("SIM Type is %d", (int)sim_card);
298 if (sim_card == (TelSimCardType_t) TAPI_SIM_CARD_TYPE_UNKNOWN) {
300 ("%s*** [ERR] tel_get_sim_type. sim_card=%d ***%s",
301 SETTING_FONT_RED, sim_card, SETTING_FONT_BLACK);
302 setting_create_popup(NULL, ad->win_get,
303 NULL, _("IDS_SIM_BODY_INVALID_SIM_CARD"), NULL, 0, false, false, 0);
307 ad->enter_tapi_async_cb_flag = 0;
308 ad->sim_popup = NULL;
309 ad->tapi_async_cb_check_timer = ecore_timer_add(0.5, _check_tapi_async_cb_is_called, ad);
311 if (tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_SC, get_pin_lock_info_cb, ad) != 0) {
312 SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
316 static void get_sim_lock_info_cb(TapiHandle *handle, int result, void *data, void *user_data)
319 ret_if(data == NULL || user_data == NULL);
321 TelSimPinOperationResult_t sec_rt = result;
322 TelSimLockInfo_t *lock = data;
324 SettingSecurityUG *ad = (SettingSecurityUG *)user_data;
328 evas_object_del(ad->sim_popup);
329 ad->sim_popup = NULL;
332 int old_state = ad->data_sim_lk->chk_status;/*elm_check_state_get(ad->data_sim_lk->eo_check); */
334 SETTING_TRACE("Current status of SIM Lock is ON");
335 ad->pw_type = SETTING_SEC_PW_SIM_LOCK_OFF;
337 SETTING_TRACE("Current status of SIM Lock is OFF");
338 ad->pw_type = SETTING_SEC_PW_SIM_LOCK_ON;
341 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);
343 if (lock->lock_status == 5) { /* Blocked */
344 setting_create_popup(NULL, ad->win_get,
345 NULL, _("SIM is blocked. Can't use SIM Lock"), NULL, 0, false, false, 0);
349 setting_security_create_password_sg(ad);
352 void _draw_sim_onoff_status(void *data, Evas_Object *check)
354 ret_if(data == NULL);
356 SettingSecurityUG *ad = (SettingSecurityUG *) data;
361 ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
362 ret = _handle_sim_exception(ad, value);
363 if (ret == SETTING_RETURN_FAIL)
368 evas_object_del(ad->sim_popup);
369 ad->sim_popup = NULL;
371 ad->sim_popup = setting_create_popup(ad, ad->win_get,
372 NULL, KeyStr_Security_Waiting_Sim,
376 if (tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_PS, get_sim_lock_info_cb, ad) != 0) {
377 SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
381 static void get_change_pin_info_cb(TapiHandle *handle, int result, void *data, void *user_data)
384 ret_if(data == NULL || user_data == NULL);
386 TelSimPinOperationResult_t sec_rt = result;
387 TelSimLockInfo_t *lock = data;
389 SettingSecurityUG *ad = (SettingSecurityUG *)user_data;
391 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);
392 if (lock->lock_type == TAPI_SIM_LOCK_SC && lock->lock_status == TAPI_SIM_LOCK_KEY_PUK) { /* PUK required : 0x02*/
393 SETTING_TRACE("Current status of PIN Lock is Blocked");
394 ad->pw_type = SETTING_SEC_PW_PIN1_BLOCKED;
395 } else if (lock->lock_type == TAPI_SIM_LOCK_SC &&
396 (lock->lock_status == TAPI_SIM_LOCK_KEY_NOT_NEED || lock->lock_status == TAPI_SIM_LOCK_KEY_PIN)) { /* PIN required : 0x00, 0x01 */
397 ad->pw_type = SETTING_SEC_PW_CHANGE_PIN1;
398 } else if (lock->lock_type == TAPI_SIM_LOCK_FD && lock->lock_status == TAPI_SIM_LOCK_KEY_PUK2) { /* PUK2 required : 0x04 */
399 SETTING_TRACE("Current status of Change PIN2 is Blocked");
400 ad->pw_type = SETTING_SEC_PW_PIN2_BLOCKED;
401 } else if (lock->lock_type == TAPI_SIM_LOCK_FD &&
402 (lock->lock_status == TAPI_SIM_LOCK_KEY_NOT_NEED || lock->lock_status == TAPI_SIM_LOCK_KEY_PIN2)) { /* PIN2 required : 0x00, 0x03 */
403 ad->pw_type = SETTING_SEC_PW_CHANGE_PIN2;
404 } else if (lock->lock_status == TAPI_SIM_LOCK_PERM_BLOCKED) { /* Blocked : 0x05 */
405 setting_create_popup(NULL, ad->win_get,
406 NULL, _("Permanent block SIM"), NULL, 0, false, false, 0);
410 setting_security_create_password_sg(ad);
413 void _mouse_up_change_pin(void *data, int sel_item)
415 ret_if(data == NULL);
417 SettingSecurityUG *ad = (SettingSecurityUG *) data;
419 ad->sel_item = sel_item; /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
424 ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
425 setting_retm_if(ret != 0, "failed to read vconf value");
427 case VCONFKEY_TELEPHONY_SIM_INSERTED:
429 case VCONFKEY_TELEPHONY_SIM_NOT_PRESENT:
430 setting_create_popup(NULL, ad->win_get,
431 NULL, _(SECURITY_SIM_NOT_PRESENT_MSG), NULL, 0, false, false, 0);
433 ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
434 SETTING_FONT_RED, value, SETTING_FONT_BLACK);
437 case VCONFKEY_TELEPHONY_SIM_CARD_ERROR:
438 case VCONFKEY_TELEPHONY_SIM_UNKNOWN:
439 setting_create_popup(NULL, ad->win_get,
440 NULL, _("IDS_SIM_BODY_INVALID_SIM_CARD"), NULL, 0, false, false, 0);
442 ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
443 SETTING_FONT_RED, value, SETTING_FONT_BLACK);
450 /* check sim status */
451 TapiResult_t tapi_ret = TAPI_API_INVALID_INPUT;
452 TelSimCardType_t sim_card = TAPI_SIM_CARD_TYPE_UNKNOWN;
454 tapi_ret = tel_get_sim_type(ad->handle, &sim_card);
455 if (tapi_ret != TAPI_API_SUCCESS) {
456 SETTING_TRACE_ERROR("tel_get_sim_type call failed with error code %d", tapi_ret);
459 if (sim_card == (TelSimCardType_t) SETTING_TAPI_UNKNOWN_SIM_TYPE) {
461 ("%s*** [ERR] tel_get_sim_type. sim_card=%d ***%s",
462 SETTING_FONT_RED, sim_card, SETTING_FONT_BLACK);
463 setting_create_popup(NULL, ad->win_get,
464 NULL, _("IDS_SIM_BODY_INVALID_SIM_CARD"), NULL, 0, false, false, 0);
467 if (sel_item == 1 && (ad->pin1_status == TAPI_SIM_FACILITY_ENABLED)) {
468 if (tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_SC, get_change_pin_info_cb, ad) != 0) {
469 SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
471 } else if (sel_item == 3) {
472 if (tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_FD, get_change_pin_info_cb, ad) != 0) {
473 SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
475 /*ad->pw_type = SETTING_SEC_PW_CHANGE_PIN2; */
476 /*setting_security_create_password_sg(ad); */
481 setting_security_sim_settings_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
486 setting_retm_if(data == NULL, "Data parameter is NULL");
488 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
489 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
490 elm_genlist_item_selected_set(item, 0);
491 Setting_GenGroupItem_Data *list_item =
492 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
493 setting_retm_if(NULL == list_item, "list_item is NULL");
495 SettingSecurityUG *ad = (SettingSecurityUG *) data;
497 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
498 if (!safeStrCmp("IDS_ST_BODY_PIN_LOCK", list_item->keyStr)) {
499 _draw_pin_onoff_status(ad, list_item->eo_check);
501 } else if (!safeStrCmp("IDS_ST_HEADER_CHANGE_PIN_ABB", list_item->keyStr)) {
502 _mouse_up_change_pin(ad, 1); /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
503 } else if (!safeStrCmp("IDS_ST_BODY_CHANGE_PIN2", list_item->keyStr)) {
504 _mouse_up_change_pin(ad, 3); /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
505 } else if (!safeStrCmp("IDS_CST_BODY_UNBLOCK_PIN2", list_item->keyStr)) {
506 ad->pw_type = SETTING_SEC_PW_PIN2_BLOCKED;
507 setting_security_create_password_sg(ad);
512 setting_security_sim_settings_chk_btn_cb(void *data, Evas_Object *obj,
517 retm_if(data == NULL, "[Setting > Reset] Data parameter is NULL");
518 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
519 SettingSecurityUG *ad = list_item->userdata;
521 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
522 if (!safeStrCmp("IDS_ST_BODY_PIN_LOCK", list_item->keyStr)) {
523 /*Rollback state of toggle. */
524 /*it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback */
525 /*setting_update_gl_item_chk_status(list_item, !(list_item->chk_status)); */
526 list_item->chk_status = !(list_item->chk_status);
527 _draw_pin_onoff_status(ad, obj);
531 else if (!safeStrCmp(Keystr_FDN, list_item->keyStr)) {
532 /*Rollback state of toggle. */
533 /*it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback */
534 setting_update_gl_item_chk_status(list_item, !(list_item->chk_status));
536 _draw_fdn_onoff_status(ad, obj);
543 /*setting_security_sim_settings_click_softkey_back_cb(void *data, Evas_Object *obj, */
544 /* void *event_info) */
545 Eina_Bool setting_security_sim_settings_click_softkey_back_cb(void *data, Elm_Object_Item *it)
549 retv_if(data == NULL, EINA_FALSE);
551 SettingSecurityUG *ad = (SettingSecurityUG *) data;
559 setting_view_change(&setting_view_security_sim_settings, &setting_view_security_main, ad);