44656b5e43e9f7c0e613912734dd035d042cbcfd
[apps/core/preloaded/settings.git] / setting-security / src / setting-security-sim-settings.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
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>
25
26 #include <setting-security-sim-settings.h>
27 #include <setting-security-main.h>
28 #include <setting-debug.h>
29
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);
34
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,
40 };
41
42 /* ***************************************************
43  **
44  **basic func
45  **
46  ****************************************************/
47
48 static int setting_security_sim_settings_create(void *cb)
49 {
50         SETTING_TRACE_BEGIN;
51         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
52
53         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
54
55         Evas_Object *scroller;
56         Elm_Object_Item *item = NULL;
57
58         /* add basic layout */
59         setting_push_layout_navi_bar_genlist(ad->win_main_layout,
60                                                    ad->win_get,
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);
65
66         /* separator */
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);
69
70         /* to do : sim settings menu */
71
72         /* f. sim lock */
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,
77                                                         SWALLOW_Type_1TOGGLE,
78                                                         NULL, NULL,
79                                                         ad->sim_status,"IDS_ST_BODY_SIM_LOCK", NULL, setting_security_sim_settings_chk_btn_cb);
80         if(ad->data_sim_lk)
81                 ad->data_sim_lk->userdata = ad;
82         else {
83                 SETTING_TRACE_ERROR("ad->data_sim_lk is null");
84                 return SETTING_RETURN_FAIL;
85         }
86
87         //setting_security_main_update_view(ad, "IDS_ST_BODY_SIM_LOCK");
88
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);
91
92         /* g. pin lock */
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,
97                                                         SWALLOW_Type_1TOGGLE,
98                                                         NULL, NULL,
99                                                         ad->pin1_status,"IDS_COM_BODY_PIN_LOCK", NULL, setting_security_sim_settings_chk_btn_cb);
100         if(ad->data_pin_lk)
101                 ad->data_pin_lk->userdata = ad;
102
103         /* h. change pin1 */
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,
107                                                                 NULL, NULL,
108                                                                 0,"IDS_ST_BODY_CHANGE_PIN1", NULL, NULL);
109
110         if(!ad->pin1_status)
111                 setting_disable_genlist_item(ad->data_change_pin1->item);
112
113         /* i. change pin2 */
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,
117                                                                 NULL, NULL,
118                                                                 0,"IDS_ST_BODY_CHANGE_PIN2", NULL, NULL);
119         if(!ad->pin2_status)
120                 setting_disable_genlist_item(ad->data_change_pin2->item);
121 #if SUPPORT_FDN
122         /* j. FDN */
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,
128                                                         NULL, NULL,
129                                                         ad->pin2_status, Keystr_FDN, NULL, setting_security_sim_settings_chk_btn_cb);
130         if(ad->data_fdn)
131                 ad->data_fdn->userdata = ad;
132 #endif
133
134         setting_view_security_sim_settings.is_create = 1;
135
136         return SETTING_RETURN_SUCCESS;
137
138 }
139
140 static int setting_security_sim_settings_destroy(void *cb)
141 {
142         SETTING_TRACE_BEGIN;
143         /* error check */
144         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
145
146         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
147
148         elm_naviframe_item_pop(ad->navi_bar);
149
150         setting_view_security_sim_settings.is_create = 0;
151
152         return SETTING_RETURN_SUCCESS;
153 }
154
155 static int setting_security_sim_settings_update(void *cb)
156 {
157         SETTING_TRACE_BEGIN;
158         /* error check */
159         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
160
161         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
162
163         SETTING_TRACE("Update SIM menu");
164         if (ad->data_sim_lk)//it indicates TAPI is not responsed in time
165         {
166                 ad->data_sim_lk->chk_status = ad->sim_status;
167                 elm_check_state_set(ad->data_sim_lk->eo_check, ad->sim_status);
168         }
169
170         SETTING_TRACE("Update PIN menu");
171         if (ad->data_pin_lk)//it indicates TAPI is not responsed in time
172         {
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);
177                 else
178                         setting_enable_genlist_item(ad->data_change_pin1->item);
179         }
180
181         if(ad->data_change_pin2)
182         {
183                 if(ad->pin2_status == 0)
184                         setting_disable_genlist_item(ad->data_change_pin2->item);
185                 else
186                         setting_enable_genlist_item(ad->data_change_pin2->item);
187         }
188         return SETTING_RETURN_SUCCESS;
189 }
190
191 static int setting_security_sim_settings_cleanup(void *cb)
192 {
193         SETTING_TRACE_BEGIN;
194         /* error check */
195         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
196
197         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
198         return setting_security_sim_settings_destroy(ad);
199 }
200
201 /* ***************************************************
202  **
203  **call back func
204  **
205  ****************************************************/
206
207 static void get_pin_lock_info_cb(TapiHandle *handle, int result, void *data, void *user_data)
208 {
209         SETTING_TRACE_BEGIN;
210
211         TelSimPinOperationResult_t sec_rt = result;
212         TelSimLockInfo_t *lock = data;
213
214         SettingSecurityUG *ad = (SettingSecurityUG *)user_data;
215
216         /* delete popup */
217         if(ad->sim_popup)
218         {
219                 evas_object_del(ad->sim_popup);
220                 ad->sim_popup = NULL;
221         }
222
223         int old_state = elm_check_state_get(ad->data_pin_lk->eo_check);
224         if (old_state) {
225                 SETTING_TRACE("Current status of PIN Lock is ON");
226                 ad->pw_type = SETTING_SEC_PW_PIN_LOCK_OFF;
227         } else {
228                 SETTING_TRACE("Current status of PIN Lock is OFF");
229                 ad->pw_type = SETTING_SEC_PW_PIN_LOCK_ON;
230         }
231
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 */
234         {
235                 SETTING_TRACE("Current status of PIN Lock is Blocked");
236                 ad->pw_type = SETTING_SEC_PW_PIN1_BLOCKED;
237         }
238         else if(lock->lock_status == 5) /* Blocked */
239         {
240                 setting_create_simple_popup(NULL, ad->win_get,
241                                 NULL, _("PUK is blocked. Can't use PIN Lock"));
242                 return;
243         }
244
245         setting_security_create_password_sg(ad);
246 }
247
248  void _draw_pin_onoff_status(void *data, Evas_Object *check)
249 {
250         SETTING_TRACE("PIN Lock");
251
252         ret_if(data == NULL);
253
254         SettingSecurityUG *ad = (SettingSecurityUG *) data;
255         int value = 0;
256         int err = 0;
257         int ret = 0;
258
259         ad->sel_item = 0;       /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
260
261         ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
262
263         ret = _handle_sim_exception(ad, value);
264         if(ret == SETTING_RETURN_FAIL)
265                 return;
266
267         /* check sim status */
268         int tapi_ret = TAPI_API_INVALID_INPUT;
269         TelSimCardType_t sim_card = TAPI_SIM_CARD_TYPE_UNKNOWN;
270
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) {
274                 SETTING_TRACE_DEBUG
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"));
279                 return;
280         }
281
282         /* create popup */
283         if(ad->sim_popup)
284         {
285                 evas_object_del(ad->sim_popup);
286                 ad->sim_popup = NULL;
287         }
288         ad->sim_popup = setting_create_popup_without_btn(ad, ad->win_get,
289                                                                                 NULL, _("Waiting response of SIM ..."), 
290                                                                                 NULL,
291                                                                                 0, FALSE, FALSE);
292
293         if(tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_SC, get_pin_lock_info_cb, ad) != 0)
294         {
295                 SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
296         }
297 }
298
299 static void get_sim_lock_info_cb(TapiHandle *handle, int result, void *data, void *user_data)
300 {
301         SETTING_TRACE_BEGIN;
302         ret_if(data == NULL || user_data == NULL);
303
304         TelSimPinOperationResult_t sec_rt = result;
305         TelSimLockInfo_t *lock = data;
306
307         SettingSecurityUG *ad = (SettingSecurityUG *)user_data;
308
309         /* delete popup */
310         if(ad->sim_popup)
311         {
312                 evas_object_del(ad->sim_popup);
313                 ad->sim_popup = NULL;
314         }
315
316         int old_state = elm_check_state_get(ad->data_sim_lk->eo_check);
317         if (old_state) {
318                 SETTING_TRACE("Current status of SIM Lock is ON");
319                 ad->pw_type = SETTING_SEC_PW_SIM_LOCK_OFF;
320         } else {
321                 SETTING_TRACE("Current status of SIM Lock is OFF");
322                 ad->pw_type = SETTING_SEC_PW_SIM_LOCK_ON;
323         }
324
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);
326
327         if(lock->lock_status == 5) /* Blocked */
328         {
329                 setting_create_simple_popup(NULL, ad->win_get,
330                                 NULL, _("SIM is blocked. Can't use SIM Lock"));
331                 return;
332         }
333
334         setting_security_create_password_sg(ad);
335 }
336
337 void _draw_sim_onoff_status(void *data, Evas_Object *check)
338 {
339         ret_if(data == NULL);
340
341         SettingSecurityUG *ad = (SettingSecurityUG *) data;
342         int value = 0;
343         int err = 0;
344         int ret = 0;
345
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)
349                 return;
350
351         /* create popup */
352         if(ad->sim_popup)
353         {
354                 evas_object_del(ad->sim_popup);
355                 ad->sim_popup = NULL;
356         }
357         ad->sim_popup = setting_create_popup_without_btn(ad, ad->win_get,
358                                                                                 NULL, _("Waiting response of SIM ..."), 
359                                                                                 NULL,
360                                                                                 0, FALSE, FALSE);
361
362         if(tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_PS, get_sim_lock_info_cb, ad) != 0)
363         {
364                 SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
365         }
366 }
367
368 static void get_change_pin_info_cb(TapiHandle *handle, int result, void *data, void *user_data)
369 {
370         SETTING_TRACE_BEGIN;
371         ret_if(data == NULL || user_data == NULL);
372
373         TelSimPinOperationResult_t sec_rt = result;
374         TelSimLockInfo_t *lock = data;
375
376         SettingSecurityUG *ad = (SettingSecurityUG *)user_data;
377
378         ad->pw_type = SETTING_SEC_PW_CHANGE_PIN1;
379
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 */
382         {
383                 SETTING_TRACE("Current status of PIN Lock is Blocked");
384                 ad->pw_type = SETTING_SEC_PW_PIN1_BLOCKED;
385         }
386         else if(lock->lock_status == 5) /* Blocked */
387         {
388                 setting_create_simple_popup(NULL, ad->win_get,
389                                 NULL, _("PUK is blocked. Can't use PIN Lock"));
390                 return;
391         }
392
393         setting_security_create_password_sg(ad);
394 }
395
396 void _mouse_up_change_pin(void *data, int sel_item)
397 {
398         ret_if(data == NULL);
399
400         SettingSecurityUG *ad = (SettingSecurityUG *) data;
401
402         ad->sel_item = sel_item;        /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
403         int ret;
404         int value = 0;
405         int err;
406
407         ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
408
409         switch (value) {
410                 case VCONFKEY_TELEPHONY_SIM_INSERTED:
411                         break;
412                 case VCONFKEY_TELEPHONY_SIM_NOT_PRESENT:
413                         setting_create_simple_popup(NULL, ad->win_get,
414                                                     NULL, _("IDS_ST_SECURITY_BODY_NOIMSI"));
415                         SETTING_TRACE_DEBUG
416                             ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
417                              SETTING_FONT_RED, value, SETTING_FONT_BLACK);
418                         return;
419                         break;
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"));
424                         SETTING_TRACE_DEBUG
425                             ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
426                              SETTING_FONT_RED, value, SETTING_FONT_BLACK);
427                         return;
428                         break;
429                 default:
430                         break;
431         }
432
433         /* check sim status */
434         TapiResult_t tapi_ret = TAPI_API_INVALID_INPUT;
435         TelSimCardType_t sim_card = TAPI_SIM_CARD_TYPE_UNKNOWN;
436
437         tapi_ret = tel_get_sim_type(ad->handle, &sim_card);
438
439         if (sim_card == (TelSimCardType_t) SETTING_TAPI_UNKNOWN_SIM_TYPE) {
440                 SETTING_TRACE_DEBUG
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"));
445                 return;
446         }
447         if(sel_item == 1 && (ad->pin1_status == TAPI_SIM_FACILITY_ENABLED))
448         {
449                 if(tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_SC, get_change_pin_info_cb, ad) != 0)
450                 {
451                         SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
452                 }
453         }
454         else if(sel_item == 3 && (ad->pin2_status == TAPI_SIM_FACILITY_ENABLED))
455         {
456                 ad->pw_type = SETTING_SEC_PW_CHANGE_PIN2;
457                 setting_security_create_password_sg(ad);
458         }
459 }
460
461 static void
462 setting_security_sim_settings_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
463                                                void *event_info)
464 {
465         SETTING_TRACE_BEGIN;
466         /* error check */
467         setting_retm_if(data == NULL, "Data parameter is NULL");
468
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);
474
475
476         SettingSecurityUG *ad = (SettingSecurityUG *) data;
477
478         SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
479
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);
483
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);
487
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 */
492         }
493 }
494
495 static void
496 setting_security_sim_settings_chk_btn_cb(void *data, Evas_Object *obj,
497                                  void *event_info)
498 {
499         SETTING_TRACE_BEGIN;
500         /* error check */
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;
504
505         list_item->chk_status = elm_check_state_get(obj);       /*  for genlist update status */
506
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);
513
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);
520
521         }
522 }
523
524
525 static void
526 setting_security_sim_settings_click_softkey_back_cb(void *data, Evas_Object *obj,
527                                             void *event_info)
528 {
529         SETTING_TRACE_BEGIN;
530         /* error check */
531         retm_if(data == NULL, "[Setting > Security] Data parameter is NULL");
532
533         SettingSecurityUG *ad = (SettingSecurityUG *) data;
534
535         setting_view_change(&setting_view_security_sim_settings, &setting_view_security_main, ad);
536         SETTING_TRACE_END;
537 }