d852080d15b5cefda63892feee04d63f44b43e9b
[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                                                    _("SIM 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         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 SUPPORT_FDN
120         /* j. FDN */
121         //if TAPI is responsed in time, ad->sim_status will have invalid value,
122         //or else ad->data_fdn will be updated by setting_security_sim_get_facility_cb
123         ad->data_fdn = setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
124                                                         setting_security_sim_settings_mouse_up_Gendial_list_cb, ad,
125                                                         SWALLOW_Type_1TOGGLE,
126                                                         NULL, NULL,
127                                                         ad->pin2_status, Keystr_FDN, NULL, setting_security_sim_settings_chk_btn_cb);
128         if(ad->data_fdn)
129                 ad->data_fdn->userdata = ad;
130 #endif
131
132         setting_view_security_sim_settings.is_create = 1;
133
134         vconf_notify_key_changed(VCONFKEY_SETAPPL_SIM_LOCK_ATTEMPTS_LEFT_INT,
135                                  setting_security_main_vconf_change_cb, ad);
136
137         return SETTING_RETURN_SUCCESS;
138
139 }
140
141 static int setting_security_sim_settings_destroy(void *cb)
142 {
143         SETTING_TRACE_BEGIN;
144         /* error check */
145         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
146
147         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
148
149         elm_naviframe_item_pop(ad->navi_bar);
150
151         vconf_ignore_key_changed(VCONFKEY_SETAPPL_SIM_LOCK_ATTEMPTS_LEFT_INT,
152                                  setting_security_main_vconf_change_cb);
153
154         setting_view_security_sim_settings.is_create = 0;
155
156         return SETTING_RETURN_SUCCESS;
157 }
158
159 static int setting_security_sim_settings_update(void *cb)
160 {
161         SETTING_TRACE_BEGIN;
162         /* error check */
163         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
164
165         return SETTING_RETURN_SUCCESS;
166 }
167
168 static int setting_security_sim_settings_cleanup(void *cb)
169 {
170         SETTING_TRACE_BEGIN;
171         /* error check */
172         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
173
174         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
175         return setting_security_sim_settings_destroy(ad);
176 }
177
178 /* ***************************************************
179  **
180  **call back func
181  **
182  ****************************************************/
183  void _draw_pin_onoff_status(void *data, Evas_Object *check)
184 {
185         SETTING_TRACE("PIN Lock");
186
187         ret_if(data == NULL);
188
189         SettingSecurityUG *ad = (SettingSecurityUG *) data;
190         int value = 0;
191         int err = 0;
192         int ret = 0;
193
194         ad->sel_item = 0;       /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
195
196         ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
197
198         ret = _handle_sim_exception(ad, value);
199         if(ret == SETTING_RETURN_FAIL)
200                 return;
201
202         /* check sim status */
203         int tapi_ret = TAPI_API_INVALID_INPUT;
204         TelSimCardType_t sim_card = TAPI_SIM_CARD_TYPE_UNKNOWN;
205
206         tapi_ret = tel_get_sim_type(ad->handle, &sim_card);
207         SETTING_TRACE("SIM Type is %d", (int)sim_card);
208         if (sim_card == (TelSimCardType_t) SETTING_TAPI_UNKNOWN_SIM_TYPE) {
209                 SETTING_TRACE_DEBUG
210                             ("%s*** [ERR] tel_get_sim_type. sim_card=%d ***%s",
211                              SETTING_FONT_RED, sim_card, SETTING_FONT_BLACK);
212                 setting_create_simple_popup(NULL, ad->win_get,
213                                 NULL, _("IDS_COM_BODY_INVALID_SIM_CARD"));
214                 return;
215         }
216
217         int old_state = elm_check_state_get(check);
218         if (old_state) {
219                 SETTING_TRACE("Current status of SIM Lock is ON");
220                 ad->pw_type = SETTING_SEC_PW_PIN_LOCK_OFF;
221                 setting_security_create_password_sg(ad);
222         } else {
223                 SETTING_TRACE("Current status of SIM Lock is OFF");
224                 ad->pw_type = SETTING_SEC_PW_PIN_LOCK_ON;
225                 setting_security_create_password_sg(ad);
226         }
227 }
228
229 void _draw_sim_onoff_status(void *data, Evas_Object *check)
230 {
231         ret_if(data == NULL);
232
233         SettingSecurityUG *ad = (SettingSecurityUG *) data;
234         int value = 0;
235         int err = 0;
236         int ret = 0;
237
238         ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
239         ret = _handle_sim_exception(ad, value);
240         if(ret == SETTING_RETURN_FAIL)
241                 return;
242
243         int old_state = elm_check_state_get(check);
244         if (old_state) {
245                 SETTING_TRACE("Current status of SIM Lock is ON");
246                 ad->pw_type = SETTING_SEC_PW_SIM_LOCK_OFF;
247                 setting_security_create_password_sg(ad);
248         } else {
249                 SETTING_TRACE("Current status of SIM Lock is OFF");
250                 ad->pw_type = SETTING_SEC_PW_SIM_LOCK_ON;
251                 setting_security_create_password_sg(ad);
252         }
253 }
254
255 void _mouse_up_change_pin(void *data, int sel_item)
256 {
257         ret_if(data == NULL);
258
259         SettingSecurityUG *ad = (SettingSecurityUG *) data;
260
261         ad->sel_item = sel_item;        /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
262         int ret;
263         int value = 0;
264         int err;
265
266         ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
267
268         switch (value) {
269                 case VCONFKEY_TELEPHONY_SIM_INSERTED:
270                         break;
271                 case VCONFKEY_TELEPHONY_SIM_NOT_PRESENT:
272                         setting_create_simple_popup(NULL, ad->win_get,
273                                                     NULL, _("IDS_ST_SECURITY_BODY_NOIMSI"));
274                         SETTING_TRACE_DEBUG
275                             ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
276                              SETTING_FONT_RED, value, SETTING_FONT_BLACK);
277                         return;
278                         break;
279                 case VCONFKEY_TELEPHONY_SIM_CARD_ERROR:
280                 case VCONFKEY_TELEPHONY_SIM_UNKNOWN:
281                         setting_create_simple_popup(NULL, ad->win_get,
282                                                     NULL, _("IDS_COM_BODY_INVALID_SIM_CARD"));
283                         SETTING_TRACE_DEBUG
284                             ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
285                              SETTING_FONT_RED, value, SETTING_FONT_BLACK);
286                         return;
287                         break;
288                 default:
289                         break;
290         }
291
292         /* check sim status */
293         TapiResult_t tapi_ret = TAPI_API_INVALID_INPUT;
294         TelSimCardType_t sim_card = TAPI_SIM_CARD_TYPE_UNKNOWN;
295
296         tapi_ret = tel_get_sim_type(ad->handle, &sim_card);
297
298         if (sim_card == (TelSimCardType_t) SETTING_TAPI_UNKNOWN_SIM_TYPE) {
299                 SETTING_TRACE_DEBUG
300                             ("%s*** [ERR] tel_get_sim_type. sim_card=%d ***%s",
301                              SETTING_FONT_RED, sim_card, SETTING_FONT_BLACK);
302                 setting_create_simple_popup(NULL, ad->win_get,
303                                             NULL, _("IDS_COM_BODY_INVALID_SIM_CARD"));
304                 return;
305         }
306         if(sel_item == 1)
307         {
308                 //pin_type = TAPI_SIM_PTYPE_PIN1;
309                 if (TAPI_SIM_FACILITY_ENABLED == ad->pin1_status)
310                 {
311                         ad->pw_type = SETTING_SEC_PW_CHANGE_PIN1;
312                         setting_security_create_password_sg(ad);
313                 }
314                 else
315                 {
316                         ad->pw_type = SETTING_SEC_PW_PIN1_BLOCKED;
317                         setting_security_create_password_sg(ad);
318                 }
319         }
320         else if(sel_item == 3)
321         {
322                 //pin_type = TAPI_SIM_PTYPE_PIN2;
323                 if (TAPI_SIM_FACILITY_ENABLED == ad->pin2_status)
324                 {
325                         ad->pw_type = SETTING_SEC_PW_CHANGE_PIN2;
326                         setting_security_create_password_sg(ad);
327                 }
328                 else
329                 {
330                         ad->pw_type = SETTING_SEC_PW_PIN2_BLOCKED;
331                         setting_security_create_password_sg(ad);
332                 }
333         }
334 }
335
336 static void
337 setting_security_sim_settings_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
338                                                void *event_info)
339 {
340         SETTING_TRACE_BEGIN;
341         /* error check */
342         setting_retm_if(data == NULL, "Data parameter is NULL");
343
344         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
345         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
346         elm_genlist_item_selected_set(item, 0);
347         Setting_GenGroupItem_Data *list_item =
348             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
349
350
351         SettingSecurityUG *ad = (SettingSecurityUG *) data;
352
353         SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
354
355         if (!safeStrCmp("IDS_ST_BODY_SIM_LOCK", list_item->keyStr)) {
356                 //it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback
357                 _draw_sim_onoff_status(ad, list_item->eo_check);
358
359         }else if (!safeStrCmp("IDS_COM_BODY_PIN_LOCK", list_item->keyStr)) {
360                 //it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback
361                 _draw_pin_onoff_status(ad, list_item->eo_check);
362
363         } else if (!safeStrCmp("IDS_ST_BODY_CHANGE_PIN1", list_item->keyStr)) {
364                 _mouse_up_change_pin(ad, 1); /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
365         } else if (!safeStrCmp("IDS_ST_BODY_CHANGE_PIN2", list_item->keyStr)) {
366                 _mouse_up_change_pin(ad, 3); /* 0:click pin lock, 1:change pin1 code, 2:fdn, 3: change pin2 code */
367         }
368 }
369
370 static void
371 setting_security_sim_settings_chk_btn_cb(void *data, Evas_Object *obj,
372                                  void *event_info)
373 {
374         SETTING_TRACE_BEGIN;
375         /* error check */
376         retm_if(data == NULL, "[Setting > Reset] Data parameter is NULL");
377         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
378         SettingSecurityUG *ad = list_item->userdata;
379
380         list_item->chk_status = elm_check_state_get(obj);       /*  for genlist update status */
381
382         if (!safeStrCmp("IDS_ST_BODY_SIM_LOCK", list_item->keyStr)) {
383                 //Rollback state of toggle.
384                 //it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback
385                 list_item->chk_status = !list_item->chk_status;
386                 elm_check_state_set(obj, list_item->chk_status);
387                 _draw_sim_onoff_status(ad, obj);
388
389         }else if (!safeStrCmp("IDS_COM_BODY_PIN_LOCK", list_item->keyStr)) {
390                 //Rollback state of toggle.
391                 //it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback
392                 list_item->chk_status = !list_item->chk_status;
393                 elm_check_state_set(obj, list_item->chk_status);
394                 _draw_pin_onoff_status(ad, obj);
395
396         }
397 #if SUPPORT_FDN
398         else if (!safeStrCmp(Keystr_FDN, list_item->keyStr)){
399                 //Rollback state of toggle.
400                 //it invokes async TAPIs to enable/disable, so don't change the status at first to avoid rollback
401                 list_item->chk_status = !list_item->chk_status;
402                 elm_check_state_set(obj, list_item->chk_status);
403                 ad->chk_fdn = obj;
404                 _draw_fdn_onoff_status(ad, obj);
405         }
406 #endif
407 }
408
409
410 static void
411 setting_security_sim_settings_click_softkey_back_cb(void *data, Evas_Object *obj,
412                                             void *event_info)
413 {
414         SETTING_TRACE_BEGIN;
415         /* error check */
416         retm_if(data == NULL, "[Setting > Security] Data parameter is NULL");
417
418         SettingSecurityUG *ad = (SettingSecurityUG *) data;
419
420         setting_view_change(&setting_view_security_sim_settings, &setting_view_security_main, ad);
421         SETTING_TRACE_END;
422 }