[security,password] remove unused code
[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         vconf_notify_key_changed(VCONFKEY_SETAPPL_SIM_LOCK_ATTEMPTS_LEFT_INT,
137                                  setting_security_main_vconf_change_cb, ad);
138
139         return SETTING_RETURN_SUCCESS;
140
141 }
142
143 static int setting_security_sim_settings_destroy(void *cb)
144 {
145         SETTING_TRACE_BEGIN;
146         /* error check */
147         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
148
149         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
150
151         elm_naviframe_item_pop(ad->navi_bar);
152
153         vconf_ignore_key_changed(VCONFKEY_SETAPPL_SIM_LOCK_ATTEMPTS_LEFT_INT,
154                                  setting_security_main_vconf_change_cb);
155
156         setting_view_security_sim_settings.is_create = 0;
157
158         return SETTING_RETURN_SUCCESS;
159 }
160
161 static int setting_security_sim_settings_update(void *cb)
162 {
163         SETTING_TRACE_BEGIN;
164         /* error check */
165         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
166
167         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
168
169         SETTING_TRACE("Update SIM menu");
170         if (ad->data_sim_lk)//it indicates TAPI is not responsed in time
171         {
172                 ad->data_sim_lk->chk_status = ad->sim_status;
173                 elm_check_state_set(ad->data_sim_lk->eo_check, ad->sim_status);
174         }
175
176         SETTING_TRACE("Update PIN menu");
177         if (ad->data_pin_lk)//it indicates TAPI is not responsed in time
178         {
179                 ad->data_pin_lk->chk_status = ad->pin1_status;
180                 elm_check_state_set(ad->data_pin_lk->eo_check, ad->pin1_status);
181                 if(ad->data_pin_lk->chk_status == 0)
182                         setting_disable_genlist_item(ad->data_change_pin1->item);
183                 else
184                         setting_enable_genlist_item(ad->data_change_pin1->item);
185         }
186
187         if(ad->data_change_pin2)
188         {
189                 if(ad->pin2_status == 0)
190                         setting_disable_genlist_item(ad->data_change_pin2->item);
191                 else
192                         setting_enable_genlist_item(ad->data_change_pin2->item);
193         }
194         return SETTING_RETURN_SUCCESS;
195 }
196
197 static int setting_security_sim_settings_cleanup(void *cb)
198 {
199         SETTING_TRACE_BEGIN;
200         /* error check */
201         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
202
203         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
204         return setting_security_sim_settings_destroy(ad);
205 }
206
207 /* ***************************************************
208  **
209  **call back func
210  **
211  ****************************************************/
212
213 static void get_pin_lock_info_cb(TapiHandle *handle, int result, void *data, void *user_data)
214 {
215         SETTING_TRACE_BEGIN;
216
217         TelSimPinOperationResult_t sec_rt = result;
218         TelSimLockInfo_t *lock = data;
219
220         SettingSecurityUG *ad = (SettingSecurityUG *)user_data;
221
222         int old_state = elm_check_state_get(ad->data_pin_lk->eo_check);
223         if (old_state) {
224                 SETTING_TRACE("Current status of PIN Lock is ON");
225                 ad->pw_type = SETTING_SEC_PW_PIN_LOCK_OFF;
226         } else {
227                 SETTING_TRACE("Current status of PIN Lock is OFF");
228                 ad->pw_type = SETTING_SEC_PW_PIN_LOCK_ON;
229         }
230
231         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);
232         if(lock->lock_status == 2) /* PUK */
233         {
234                 SETTING_TRACE("Current status of PIN Lock is Blocked");
235                 ad->pw_type = SETTING_SEC_PW_PIN1_BLOCKED;
236         }
237         else if(lock->lock_status == 5) /* Blocked */
238         {
239                 setting_create_simple_popup(NULL, ad->win_get,
240                                 NULL, _("PUK is blocked. Can't use PIN Lock"));
241                 return;
242         }
243
244         setting_security_create_password_sg(ad);
245 }
246
247  void _draw_pin_onoff_status(void *data, Evas_Object *check)
248 {
249         SETTING_TRACE("PIN Lock");
250
251         ret_if(data == NULL);
252
253         SettingSecurityUG *ad = (SettingSecurityUG *) data;
254         int value = 0;
255         int err = 0;
256         int ret = 0;
257
258         ad->sel_item = 0;       /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
259
260         ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
261
262         ret = _handle_sim_exception(ad, value);
263         if(ret == SETTING_RETURN_FAIL)
264                 return;
265
266         /* check sim status */
267         int tapi_ret = TAPI_API_INVALID_INPUT;
268         TelSimCardType_t sim_card = TAPI_SIM_CARD_TYPE_UNKNOWN;
269
270         tapi_ret = tel_get_sim_type(ad->handle, &sim_card);
271         SETTING_TRACE("SIM Type is %d", (int)sim_card);
272         if (sim_card == (TelSimCardType_t) TAPI_SIM_CARD_TYPE_UNKNOWN) {
273                 SETTING_TRACE_DEBUG
274                             ("%s*** [ERR] tel_get_sim_type. sim_card=%d ***%s",
275                              SETTING_FONT_RED, sim_card, SETTING_FONT_BLACK);
276                 setting_create_simple_popup(NULL, ad->win_get,
277                                 NULL, _("IDS_COM_BODY_INVALID_SIM_CARD"));
278                 return;
279         }
280
281         if(tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_SC, get_pin_lock_info_cb, ad) != 0)
282         {
283                 SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
284         }
285 }
286
287 static void get_sim_lock_info_cb(TapiHandle *handle, int result, void *data, void *user_data)
288 {
289         SETTING_TRACE_BEGIN;
290
291         TelSimPinOperationResult_t sec_rt = result;
292         TelSimLockInfo_t *lock = data;
293
294         SettingSecurityUG *ad = (SettingSecurityUG *)user_data;
295
296         int old_state = elm_check_state_get(ad->data_sim_lk->eo_check);
297         if (old_state) {
298                 SETTING_TRACE("Current status of SIM Lock is ON");
299                 ad->pw_type = SETTING_SEC_PW_SIM_LOCK_OFF;
300         } else {
301                 SETTING_TRACE("Current status of SIM Lock is OFF");
302                 ad->pw_type = SETTING_SEC_PW_SIM_LOCK_ON;
303         }
304
305         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);
306
307         if(lock->lock_status == 5) /* Blocked */
308         {
309                 setting_create_simple_popup(NULL, ad->win_get,
310                                 NULL, _("SIM is blocked. Can't use SIM Lock"));
311                 return;
312         }
313
314         setting_security_create_password_sg(ad);
315 }
316
317 void _draw_sim_onoff_status(void *data, Evas_Object *check)
318 {
319         ret_if(data == NULL);
320
321         SettingSecurityUG *ad = (SettingSecurityUG *) data;
322         int value = 0;
323         int err = 0;
324         int ret = 0;
325
326         ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
327         ret = _handle_sim_exception(ad, value);
328         if(ret == SETTING_RETURN_FAIL)
329                 return;
330
331         if(tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_PS, get_sim_lock_info_cb, ad) != 0)
332         {
333                 SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
334         }
335 }
336
337 static void get_change_pin_info_cb(TapiHandle *handle, int result, void *data, void *user_data)
338 {
339         SETTING_TRACE_BEGIN;
340
341         TelSimPinOperationResult_t sec_rt = result;
342         TelSimLockInfo_t *lock = data;
343
344         SettingSecurityUG *ad = (SettingSecurityUG *)user_data;
345
346         ad->pw_type = SETTING_SEC_PW_CHANGE_PIN1;
347
348         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);
349         if(lock->lock_status == 2) /* PUK */
350         {
351                 SETTING_TRACE("Current status of PIN Lock is Blocked");
352                 ad->pw_type = SETTING_SEC_PW_PIN1_BLOCKED;
353         }
354         else if(lock->lock_status == 5) /* Blocked */
355         {
356                 setting_create_simple_popup(NULL, ad->win_get,
357                                 NULL, _("PUK is blocked. Can't use PIN Lock"));
358                 return;
359         }
360
361         setting_security_create_password_sg(ad);
362 }
363
364 void _mouse_up_change_pin(void *data, int sel_item)
365 {
366         ret_if(data == NULL);
367
368         SettingSecurityUG *ad = (SettingSecurityUG *) data;
369
370         ad->sel_item = sel_item;        /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
371         int ret;
372         int value = 0;
373         int err;
374
375         ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
376
377         switch (value) {
378                 case VCONFKEY_TELEPHONY_SIM_INSERTED:
379                         break;
380                 case VCONFKEY_TELEPHONY_SIM_NOT_PRESENT:
381                         setting_create_simple_popup(NULL, ad->win_get,
382                                                     NULL, _("IDS_ST_SECURITY_BODY_NOIMSI"));
383                         SETTING_TRACE_DEBUG
384                             ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
385                              SETTING_FONT_RED, value, SETTING_FONT_BLACK);
386                         return;
387                         break;
388                 case VCONFKEY_TELEPHONY_SIM_CARD_ERROR:
389                 case VCONFKEY_TELEPHONY_SIM_UNKNOWN:
390                         setting_create_simple_popup(NULL, ad->win_get,
391                                                     NULL, _("IDS_COM_BODY_INVALID_SIM_CARD"));
392                         SETTING_TRACE_DEBUG
393                             ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
394                              SETTING_FONT_RED, value, SETTING_FONT_BLACK);
395                         return;
396                         break;
397                 default:
398                         break;
399         }
400
401         /* check sim status */
402         TapiResult_t tapi_ret = TAPI_API_INVALID_INPUT;
403         TelSimCardType_t sim_card = TAPI_SIM_CARD_TYPE_UNKNOWN;
404
405         tapi_ret = tel_get_sim_type(ad->handle, &sim_card);
406
407         if (sim_card == (TelSimCardType_t) SETTING_TAPI_UNKNOWN_SIM_TYPE) {
408                 SETTING_TRACE_DEBUG
409                             ("%s*** [ERR] tel_get_sim_type. sim_card=%d ***%s",
410                              SETTING_FONT_RED, sim_card, SETTING_FONT_BLACK);
411                 setting_create_simple_popup(NULL, ad->win_get,
412                                             NULL, _("IDS_COM_BODY_INVALID_SIM_CARD"));
413                 return;
414         }
415         if(sel_item == 1 && (ad->pin1_status == TAPI_SIM_FACILITY_ENABLED))
416         {
417                 if(tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_SC, get_change_pin_info_cb, ad) != 0)
418                 {
419                         SETTING_TRACE_ERROR("failed to call tel_get_sim_lock_info()");
420                 }
421         }
422         else if(sel_item == 3 && (ad->pin2_status == TAPI_SIM_FACILITY_ENABLED))
423         {
424                 ad->pw_type = SETTING_SEC_PW_CHANGE_PIN2;
425                 setting_security_create_password_sg(ad);
426         }
427 }
428
429 static void
430 setting_security_sim_settings_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
431                                                void *event_info)
432 {
433         SETTING_TRACE_BEGIN;
434         /* error check */
435         setting_retm_if(data == NULL, "Data parameter is NULL");
436
437         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
438         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
439         elm_genlist_item_selected_set(item, 0);
440         Setting_GenGroupItem_Data *list_item =
441             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
442
443
444         SettingSecurityUG *ad = (SettingSecurityUG *) data;
445
446         SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
447
448         if (!safeStrCmp("IDS_ST_BODY_SIM_LOCK", list_item->keyStr)) {
449                 //it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback
450                 _draw_sim_onoff_status(ad, list_item->eo_check);
451
452         }else if (!safeStrCmp("IDS_COM_BODY_PIN_LOCK", list_item->keyStr)) {
453                 //it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback
454                 _draw_pin_onoff_status(ad, list_item->eo_check);
455
456         } else if (!safeStrCmp("IDS_ST_BODY_CHANGE_PIN1", list_item->keyStr)) {
457                 _mouse_up_change_pin(ad, 1); /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
458         } else if (!safeStrCmp("IDS_ST_BODY_CHANGE_PIN2", list_item->keyStr)) {
459                 _mouse_up_change_pin(ad, 3); /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
460         }
461 }
462
463 static void
464 setting_security_sim_settings_chk_btn_cb(void *data, Evas_Object *obj,
465                                  void *event_info)
466 {
467         SETTING_TRACE_BEGIN;
468         /* error check */
469         retm_if(data == NULL, "[Setting > Reset] Data parameter is NULL");
470         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
471         SettingSecurityUG *ad = list_item->userdata;
472
473         list_item->chk_status = elm_check_state_get(obj);       /*  for genlist update status */
474
475         if (!safeStrCmp("IDS_ST_BODY_SIM_LOCK", list_item->keyStr)) {
476                 //Rollback state of toggle.
477                 //it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback
478                 list_item->chk_status = !list_item->chk_status;
479                 elm_check_state_set(obj, list_item->chk_status);
480                 _draw_sim_onoff_status(ad, obj);
481
482         }else if (!safeStrCmp("IDS_COM_BODY_PIN_LOCK", list_item->keyStr)) {
483                 //Rollback state of toggle.
484                 //it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback
485                 list_item->chk_status = !list_item->chk_status;
486                 elm_check_state_set(obj, list_item->chk_status);
487                 _draw_pin_onoff_status(ad, obj);
488
489         }
490 #if SUPPORT_FDN
491         else if (!safeStrCmp(Keystr_FDN, list_item->keyStr)){
492                 //Rollback state of toggle.
493                 //it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback
494                 list_item->chk_status = !list_item->chk_status;
495                 elm_check_state_set(obj, list_item->chk_status);
496                 ad->chk_fdn = obj;
497                 _draw_fdn_onoff_status(ad, obj);
498         }
499 #endif
500 }
501
502
503 static void
504 setting_security_sim_settings_click_softkey_back_cb(void *data, Evas_Object *obj,
505                                             void *event_info)
506 {
507         SETTING_TRACE_BEGIN;
508         /* error check */
509         retm_if(data == NULL, "[Setting > Security] Data parameter is NULL");
510
511         SettingSecurityUG *ad = (SettingSecurityUG *) data;
512
513         setting_view_change(&setting_view_security_sim_settings, &setting_view_security_main, ad);
514         SETTING_TRACE_END;
515 }