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 _("IDS_ST_BODY_SIM_CARD_SETTINGS"),
62 dgettext("sys_string", "IDS_COM_BODY_BACK"), NULL,
63 setting_security_sim_settings_click_softkey_back_cb,
64 NULL, ad, &scroller, ad->navi_bar);
67 item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
68 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
70 /* to do : sim settings menu */
73 //if TAPI is responsed in time, ad->sim_status will have invalid value,
74 //or else ad->data_sim_lk will be updated by setting_security_sim_get_facility_cb
75 ad->data_sim_lk = setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
76 setting_security_sim_settings_mouse_up_Gendial_list_cb, ad,
79 ad->sim_status,"IDS_ST_BODY_SIM_LOCK", NULL, setting_security_sim_settings_chk_btn_cb);
81 ad->data_sim_lk->userdata = ad;
83 SETTING_TRACE_ERROR("ad->data_sim_lk is null");
84 return SETTING_RETURN_FAIL;
87 //setting_security_main_update_view(ad, "IDS_ST_BODY_SIM_LOCK");
89 item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
90 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
93 //if TAPI is responsed in time, ad->sim_status will have invalid value,
94 //or else ad->data_pin_lk will be updated by setting_security_sim_get_facility_cb
95 ad->data_pin_lk = setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
96 setting_security_sim_settings_mouse_up_Gendial_list_cb, ad,
99 ad->pin1_status,"IDS_COM_BODY_PIN_LOCK", NULL, setting_security_sim_settings_chk_btn_cb);
101 ad->data_pin_lk->userdata = ad;
104 ad->data_change_pin1 = 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_ST_BODY_CHANGE_PIN1", NULL, NULL);
111 setting_disable_genlist_item(ad->data_change_pin1->item);
114 ad->data_change_pin2 = setting_create_Gendial_field_def(scroller, &(ad->itc_1text),
115 setting_security_sim_settings_mouse_up_Gendial_list_cb,ad,
116 SWALLOW_Type_INVALID,
118 0,"IDS_ST_BODY_CHANGE_PIN2", NULL, NULL);
120 setting_disable_genlist_item(ad->data_change_pin2->item);
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 setting_view_security_sim_settings.is_create = 1;
136 return SETTING_RETURN_SUCCESS;
140 static int setting_security_sim_settings_destroy(void *cb)
144 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
146 SettingSecurityUG *ad = (SettingSecurityUG *) cb;
148 elm_naviframe_item_pop(ad->navi_bar);
150 setting_view_security_sim_settings.is_create = 0;
152 return SETTING_RETURN_SUCCESS;
155 static int setting_security_sim_settings_update(void *cb)
159 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
161 SettingSecurityUG *ad = (SettingSecurityUG *) cb;
163 SETTING_TRACE("Update SIM menu");
164 if (ad->data_sim_lk)//it indicates TAPI is not responsed in time
166 ad->data_sim_lk->chk_status = ad->sim_status;
167 elm_check_state_set(ad->data_sim_lk->eo_check, ad->sim_status);
170 SETTING_TRACE("Update PIN menu");
171 if (ad->data_pin_lk)//it indicates TAPI is not responsed in time
173 ad->data_pin_lk->chk_status = ad->pin1_status;
174 elm_check_state_set(ad->data_pin_lk->eo_check, ad->pin1_status);
175 if(ad->data_pin_lk->chk_status == 0)
176 setting_disable_genlist_item(ad->data_change_pin1->item);
178 setting_enable_genlist_item(ad->data_change_pin1->item);
181 if(ad->data_change_pin2)
183 if(ad->pin2_status == 0)
184 setting_disable_genlist_item(ad->data_change_pin2->item);
186 setting_enable_genlist_item(ad->data_change_pin2->item);
188 return SETTING_RETURN_SUCCESS;
191 static int setting_security_sim_settings_cleanup(void *cb)
195 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
197 SettingSecurityUG *ad = (SettingSecurityUG *) cb;
198 return setting_security_sim_settings_destroy(ad);
201 /* ***************************************************
205 ****************************************************/
207 static void get_pin_lock_info_cb(TapiHandle *handle, int result, void *data, void *user_data)
211 TelSimPinOperationResult_t sec_rt = result;
212 TelSimLockInfo_t *lock = data;
214 SettingSecurityUG *ad = (SettingSecurityUG *)user_data;
219 evas_object_del(ad->sim_popup);
220 ad->sim_popup = NULL;
223 int old_state = elm_check_state_get(ad->data_pin_lk->eo_check);
225 SETTING_TRACE("Current status of PIN Lock is ON");
226 ad->pw_type = SETTING_SEC_PW_PIN_LOCK_OFF;
228 SETTING_TRACE("Current status of PIN Lock is OFF");
229 ad->pw_type = SETTING_SEC_PW_PIN_LOCK_ON;
232 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);
233 if(lock->lock_status == 2) /* PUK */
235 SETTING_TRACE("Current status of PIN Lock is Blocked");
236 ad->pw_type = SETTING_SEC_PW_PIN1_BLOCKED;
238 else if(lock->lock_status == 5) /* Blocked */
240 setting_create_simple_popup(NULL, ad->win_get,
241 NULL, _("PUK is blocked. Can't use PIN Lock"));
245 setting_security_create_password_sg(ad);
248 void _draw_pin_onoff_status(void *data, Evas_Object *check)
250 SETTING_TRACE("PIN Lock");
252 ret_if(data == NULL);
254 SettingSecurityUG *ad = (SettingSecurityUG *) data;
259 ad->sel_item = 0; /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
261 ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
263 ret = _handle_sim_exception(ad, value);
264 if(ret == SETTING_RETURN_FAIL)
267 /* check sim status */
268 int tapi_ret = TAPI_API_INVALID_INPUT;
269 TelSimCardType_t sim_card = TAPI_SIM_CARD_TYPE_UNKNOWN;
271 tapi_ret = tel_get_sim_type(ad->handle, &sim_card);
272 SETTING_TRACE("SIM Type is %d", (int)sim_card);
273 if (sim_card == (TelSimCardType_t) TAPI_SIM_CARD_TYPE_UNKNOWN) {
275 ("%s*** [ERR] tel_get_sim_type. sim_card=%d ***%s",
276 SETTING_FONT_RED, sim_card, SETTING_FONT_BLACK);
277 setting_create_simple_popup(NULL, ad->win_get,
278 NULL, _("IDS_COM_BODY_INVALID_SIM_CARD"));
285 evas_object_del(ad->sim_popup);
286 ad->sim_popup = NULL;
288 ad->sim_popup = setting_create_popup_without_btn(ad, ad->win_get,
289 NULL, _("Waiting response of SIM ..."),
293 if(tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_SC, get_pin_lock_info_cb, ad) != 0)
295 SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
299 static void get_sim_lock_info_cb(TapiHandle *handle, int result, void *data, void *user_data)
302 ret_if(data == NULL || user_data == NULL);
304 TelSimPinOperationResult_t sec_rt = result;
305 TelSimLockInfo_t *lock = data;
307 SettingSecurityUG *ad = (SettingSecurityUG *)user_data;
312 evas_object_del(ad->sim_popup);
313 ad->sim_popup = NULL;
316 int old_state = elm_check_state_get(ad->data_sim_lk->eo_check);
318 SETTING_TRACE("Current status of SIM Lock is ON");
319 ad->pw_type = SETTING_SEC_PW_SIM_LOCK_OFF;
321 SETTING_TRACE("Current status of SIM Lock is OFF");
322 ad->pw_type = SETTING_SEC_PW_SIM_LOCK_ON;
325 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);
327 if(lock->lock_status == 5) /* Blocked */
329 setting_create_simple_popup(NULL, ad->win_get,
330 NULL, _("SIM is blocked. Can't use SIM Lock"));
334 setting_security_create_password_sg(ad);
337 void _draw_sim_onoff_status(void *data, Evas_Object *check)
339 ret_if(data == NULL);
341 SettingSecurityUG *ad = (SettingSecurityUG *) data;
346 ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
347 ret = _handle_sim_exception(ad, value);
348 if(ret == SETTING_RETURN_FAIL)
354 evas_object_del(ad->sim_popup);
355 ad->sim_popup = NULL;
357 ad->sim_popup = setting_create_popup_without_btn(ad, ad->win_get,
358 NULL, _("Waiting response of SIM ..."),
362 if(tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_PS, get_sim_lock_info_cb, ad) != 0)
364 SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
368 static void get_change_pin_info_cb(TapiHandle *handle, int result, void *data, void *user_data)
371 ret_if(data == NULL || user_data == NULL);
373 TelSimPinOperationResult_t sec_rt = result;
374 TelSimLockInfo_t *lock = data;
376 SettingSecurityUG *ad = (SettingSecurityUG *)user_data;
378 ad->pw_type = SETTING_SEC_PW_CHANGE_PIN1;
380 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);
381 if(lock->lock_status == 2) /* PUK */
383 SETTING_TRACE("Current status of PIN Lock is Blocked");
384 ad->pw_type = SETTING_SEC_PW_PIN1_BLOCKED;
386 else if(lock->lock_status == 5) /* Blocked */
388 setting_create_simple_popup(NULL, ad->win_get,
389 NULL, _("PUK is blocked. Can't use PIN Lock"));
393 setting_security_create_password_sg(ad);
396 void _mouse_up_change_pin(void *data, int sel_item)
398 ret_if(data == NULL);
400 SettingSecurityUG *ad = (SettingSecurityUG *) data;
402 ad->sel_item = sel_item; /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
407 ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
410 case VCONFKEY_TELEPHONY_SIM_INSERTED:
412 case VCONFKEY_TELEPHONY_SIM_NOT_PRESENT:
413 setting_create_simple_popup(NULL, ad->win_get,
414 NULL, _("IDS_ST_SECURITY_BODY_NOIMSI"));
416 ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
417 SETTING_FONT_RED, value, SETTING_FONT_BLACK);
420 case VCONFKEY_TELEPHONY_SIM_CARD_ERROR:
421 case VCONFKEY_TELEPHONY_SIM_UNKNOWN:
422 setting_create_simple_popup(NULL, ad->win_get,
423 NULL, _("IDS_COM_BODY_INVALID_SIM_CARD"));
425 ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
426 SETTING_FONT_RED, value, SETTING_FONT_BLACK);
433 /* check sim status */
434 TapiResult_t tapi_ret = TAPI_API_INVALID_INPUT;
435 TelSimCardType_t sim_card = TAPI_SIM_CARD_TYPE_UNKNOWN;
437 tapi_ret = tel_get_sim_type(ad->handle, &sim_card);
439 if (sim_card == (TelSimCardType_t) SETTING_TAPI_UNKNOWN_SIM_TYPE) {
441 ("%s*** [ERR] tel_get_sim_type. sim_card=%d ***%s",
442 SETTING_FONT_RED, sim_card, SETTING_FONT_BLACK);
443 setting_create_simple_popup(NULL, ad->win_get,
444 NULL, _("IDS_COM_BODY_INVALID_SIM_CARD"));
447 if(sel_item == 1 && (ad->pin1_status == TAPI_SIM_FACILITY_ENABLED))
449 if(tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_SC, get_change_pin_info_cb, ad) != 0)
451 SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
454 else if(sel_item == 3 && (ad->pin2_status == TAPI_SIM_FACILITY_ENABLED))
456 ad->pw_type = SETTING_SEC_PW_CHANGE_PIN2;
457 setting_security_create_password_sg(ad);
462 setting_security_sim_settings_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
467 setting_retm_if(data == NULL, "Data parameter is NULL");
469 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
470 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
471 elm_genlist_item_selected_set(item, 0);
472 Setting_GenGroupItem_Data *list_item =
473 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
476 SettingSecurityUG *ad = (SettingSecurityUG *) data;
478 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
480 if (!safeStrCmp("IDS_ST_BODY_SIM_LOCK", list_item->keyStr)) {
481 //it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback
482 _draw_sim_onoff_status(ad, list_item->eo_check);
484 }else if (!safeStrCmp("IDS_COM_BODY_PIN_LOCK", list_item->keyStr)) {
485 //it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback
486 _draw_pin_onoff_status(ad, list_item->eo_check);
488 } else if (!safeStrCmp("IDS_ST_BODY_CHANGE_PIN1", list_item->keyStr)) {
489 _mouse_up_change_pin(ad, 1); /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
490 } else if (!safeStrCmp("IDS_ST_BODY_CHANGE_PIN2", list_item->keyStr)) {
491 _mouse_up_change_pin(ad, 3); /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
496 setting_security_sim_settings_chk_btn_cb(void *data, Evas_Object *obj,
501 retm_if(data == NULL, "[Setting > Reset] Data parameter is NULL");
502 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
503 SettingSecurityUG *ad = list_item->userdata;
505 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
507 if (!safeStrCmp("IDS_ST_BODY_SIM_LOCK", list_item->keyStr)) {
508 //Rollback state of toggle.
509 //it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback
510 list_item->chk_status = !list_item->chk_status;
511 elm_check_state_set(obj, list_item->chk_status);
512 _draw_sim_onoff_status(ad, obj);
514 }else if (!safeStrCmp("IDS_COM_BODY_PIN_LOCK", list_item->keyStr)) {
515 //Rollback state of toggle.
516 //it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback
517 list_item->chk_status = !list_item->chk_status;
518 elm_check_state_set(obj, list_item->chk_status);
519 _draw_pin_onoff_status(ad, obj);
526 setting_security_sim_settings_click_softkey_back_cb(void *data, Evas_Object *obj,
531 retm_if(data == NULL, "[Setting > Security] Data parameter is NULL");
533 SettingSecurityUG *ad = (SettingSecurityUG *) data;
535 setting_view_change(&setting_view_security_sim_settings, &setting_view_security_main, ad);