tizen 2.3 release
[apps/home/settings.git] / setting-password / src / setting-password.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-password.h>
22 #include <setting-password-main.h>
23 #include <security-server.h>
24
25 extern void setting_get_pin_lock_info_cb(TapiHandle *handle, int result, void *data, void *user_data);
26
27 #ifndef UG_MODULE_API
28 #define UG_MODULE_API __attribute__ ((visibility("default")))
29 #endif
30
31 struct _pw_item pw_its[] = {
32         { 0, NULL, 0, 0},
33         { SETTING_PW_TYPE_PASSWORD, "SETTING_PW_TYPE_PASSWORD", SETTING_PW_CATEGORY_LOCK, 1 },
34         { SETTING_PW_TYPE_SET_PASSWORD, "SETTING_PW_TYPE_SET_PASSWORD", SETTING_PW_CATEGORY_LOCK, 2 },
35         { SETTING_PW_TYPE_SIMPLE_PASSWORD, "SETTING_PW_TYPE_SIMPLE_PASSWORD", SETTING_PW_CATEGORY_LOCK+SETTING_PW_SUB_CATEGORY_SIMPLE, 1 },
36         { SETTING_PW_TYPE_SET_SIMPLE_PASSWORD, "SETTING_PW_TYPE_SET_SIMPLE_PASSWORD", SETTING_PW_CATEGORY_LOCK+SETTING_PW_SUB_CATEGORY_SIMPLE, 2 },
37         { SETTING_PW_TYPE_ENTER_LOCK_TYPE, "SETTING_PW_TYPE_ENTER_LOCK_TYPE", SETTING_PW_CATEGORY_LOCK, 1 },
38         { SETTING_PW_TYPE_SIM_LOCK_ON, "SETTING_PW_TYPE_SIM_LOCK_ON", SETTING_PW_CATEGORY_SIM, 2 },
39         { SETTING_PW_TYPE_SIM_LOCK_OFF, "SETTING_PW_TYPE_SIM_LOCK_OFF", SETTING_PW_CATEGORY_SIM, 1 },
40         { SETTING_PW_TYPE_PIN_LOCK_ON, "SETTING_PW_TYPE_PIN_LOCK_ON", SETTING_PW_CATEGORY_SIM, 1 },
41         { SETTING_PW_TYPE_PIN_LOCK_OFF, "SETTING_PW_TYPE_PIN_LOCK_OFF", SETTING_PW_CATEGORY_SIM, 1 },
42         { SETTING_PW_TYPE_CHANGE_PIN, "SETTING_PW_TYPE_CHANGE_PIN", SETTING_PW_CATEGORY_SIM, 3 },
43         { SETTING_PW_TYPE_CHANGE_PIN2, "SETTING_PW_TYPE_CHANGE_PIN2", SETTING_PW_CATEGORY_SIM, 3 },
44         { SETTING_PW_TYPE_PIN_BLOCKED, "SETTING_PW_TYPE_PIN_BLOCKED", SETTING_PW_CATEGORY_SIM, 3 },
45         { SETTING_PW_TYPE_PIN2_BLOCKED, "SETTING_PW_TYPE_PIN2_BLOCKED", SETTING_PW_CATEGORY_SIM, 3 },
46         { SETTING_PW_TYPE_MAX, NULL }
47 };
48
49 static void setting_password_ug_cb_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
50 {
51         //SettingPasswordUG *ad = (SettingPasswordUG *) data;
52         //setting_view_update(&setting_view_password_main, ad);
53 }
54
55 void __chk_cur_pw_status(SettingPasswordUG *ad, app_control_h service)
56 {
57         int ret = 0;
58         unsigned int attempt = 0;
59         unsigned int max_attempt = 0;
60         unsigned int expire_sec = 0;
61
62         ad->pw_status = SETTING_PW_STATUS_DEFAULT;
63
64         ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec);
65         SETTING_TRACE_DEBUG("status of password : %d (cur attempt %d, max %d, expire %d", ret, attempt, max_attempt, expire_sec);
66
67         if(ret == SECURITY_SERVER_API_ERROR_NO_PASSWORD)
68         {
69                 SETTING_TRACE("security-server has no password!");
70                 ad->pw_status = SETTING_PW_STATUS_EMPTY;
71         }
72 }
73
74 void __get_extra_data(SettingPasswordUG *ad, app_control_h service)
75 {
76         SETTING_TRACE_BEGIN;
77
78         char *encryption = NULL;
79
80         // #1. viewtype
81         app_control_get_extra_data(service, "viewtype", &(ad->view_type_string));
82         SETTING_TRACE("viewtype:%s", ad->view_type_string);
83         // #2. current pw
84         app_control_get_extra_data(service, "current", &(ad->cur_pwd));
85         if(ad->cur_pwd)
86                 SETTING_TRACE_SECURE_DEBUG("Receive current : %s", ad->cur_pwd);
87 }
88
89 void __get_password_view_type(SettingPasswordUG *ad, app_control_h service)
90 {
91         SETTING_TRACE_BEGIN;
92
93         setting_pw_type ret_pw_type = 0;
94         int i;
95
96         for(i = 1; i < SETTING_PW_TYPE_MAX; i++)
97         {
98                 if (0 == safeStrCmp(ad->view_type_string, pw_its[i].pw_type_string))
99                 {
100                         SETTING_TRACE_DEBUG("%s %d", ad->view_type_string, pw_its[i].pw_type_num);
101                         ret_pw_type = pw_its[i].pw_type_num;
102                         break;
103                 }
104         }
105
106         if(pw_its[ret_pw_type].category == SETTING_PW_CATEGORY_SIM)
107         {
108                 SETTING_TRACE_DEBUG("SIM or Fingerprint do not need to check pw status. %d", pw_its[ret_pw_type].category);
109                 ad->view_type = ret_pw_type;
110                 return;
111         }
112
113         __chk_cur_pw_status(ad, service);
114
115         /* Some pw types should be changed, according to pw status and current lock type */
116         if( ret_pw_type == SETTING_PW_TYPE_ENTER_LOCK_TYPE)
117         {
118                 if(ad->pw_status == SETTING_PW_STATUS_EMPTY)
119                 {
120                         if(ad->screen_lock_type == SETTING_SCREEN_LOCK_TYPE_PASSWORD)
121                                 ret_pw_type = SETTING_PW_TYPE_SET_PASSWORD;
122                         else if(ad->screen_lock_type == SETTING_SCREEN_LOCK_TYPE_SIMPLE_PASSWORD)
123                                 ret_pw_type = SETTING_PW_TYPE_SET_SIMPLE_PASSWORD;
124                 }
125                 else
126                 {
127                         if(ad->screen_lock_type == SETTING_SCREEN_LOCK_TYPE_PASSWORD)
128                                 ret_pw_type = SETTING_PW_TYPE_PASSWORD;
129                         else if(ad->screen_lock_type == SETTING_SCREEN_LOCK_TYPE_SIMPLE_PASSWORD)
130                                 ret_pw_type = SETTING_PW_TYPE_SIMPLE_PASSWORD;
131                 }
132         }
133         /* end */
134
135         ad->view_type = ret_pw_type;
136 }
137
138 static setting_view * __initialize_view_node_table(int category)
139 {
140         setting_view_node_table_intialize();
141
142         if(category == SETTING_PW_CATEGORY_SIM)
143         {
144                 setting_view_node_table_register(&setting_view_password_sim, NULL);
145                 return &setting_view_password_sim;
146         }
147         else if(category & SETTING_PW_SUB_CATEGORY_SIMPLE)
148         {
149                 setting_view_node_table_register(&setting_view_password_simple, NULL);
150                 return &setting_view_password_simple;
151         }
152         else
153         {
154                 setting_view_node_table_register(&setting_view_password_main, NULL);
155                 return &setting_view_password_main;
156         }
157 }
158
159 static void __destroy_view(SettingPasswordUG *ad)
160 {
161         ret_if(!ad);
162
163         if(pw_its[ad->view_type].category == SETTING_PW_CATEGORY_SIM)
164         {
165                 setting_view_destroy(&setting_view_password_sim, ad);
166         }
167         if(pw_its[ad->view_type].category & SETTING_PW_SUB_CATEGORY_SIMPLE)
168         {
169                 setting_view_destroy(&setting_view_password_simple, ad);
170         }
171         else
172         {
173                 /*  delete the allocated objects. */
174                 setting_view_destroy(&setting_view_password_main, ad);
175         }
176 }
177
178 static char *__gl_err_desc_text_get(void *data, Evas_Object *obj, const char *part)
179 {
180         SETTING_TRACE_BEGIN;
181         retv_if(data == NULL, NULL);
182         char buf[256] = {0,};
183
184         snprintf(buf, 256, "<font color=#ff0000>%s</font>", (char*)data);
185
186         SETTING_TRACE_DEBUG("buf is %s", buf);
187
188         return (char*)g_strdup(buf);
189 }
190
191 static void __gl_err_desc_del(void *data, Evas_Object *obj)
192 {
193         SETTING_TRACE_BEGIN;
194         char *desc = data;
195         if (desc) {
196                 G_FREE(desc);
197                 SETTING_TRACE_DEBUG("free err_desc");
198         }
199 }
200
201 static void setting_password_rotated_cb(void *data, Evas_Object *obj, void *event)
202 {
203         SETTING_TRACE_BEGIN;
204         SettingPasswordUG *ad = (SettingPasswordUG *)data;
205
206         if(ad == NULL || ad->win_get == NULL || obj == NULL)
207                 return;
208
209         /*int changed_ang = 0;
210         changed_ang = elm_win_rotation_get(obj);*/
211
212         if(ad->view_type == SETTING_PW_TYPE_PIN_LOCK_OFF
213                 || ad->view_type == SETTING_PW_TYPE_PIN_LOCK_ON
214                 || ad->view_type == SETTING_PW_TYPE_CHANGE_PIN
215                 || ad->view_type == SETTING_PW_TYPE_PIN_BLOCKED)
216         {
217                 if(ad->handle)
218                 {
219                         if(tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_SC, setting_get_pin_lock_info_cb, ad) != 0)
220                                 SETTING_TRACE_DEBUG("failed to call tel_get_sim_lock_info()");
221                 }
222         }
223         else if(ad->view_type == SETTING_PW_TYPE_CHANGE_PIN2
224                 || ad->view_type == SETTING_PW_TYPE_PIN2_BLOCKED)
225         {
226                 if(ad->handle)
227                 {
228                         if(tel_get_sim_lock_info(ad->handle, TAPI_SIM_LOCK_FD, setting_get_pin_lock_info_cb, ad) != 0)
229                                 SETTING_TRACE_DEBUG("failed to call tel_get_sim_lock_info()");
230                 }
231         }
232         // it can manage the cursor self
233         if(ad->ed_pw1 && (ad->ed_pw1->isFocusFlag == TRUE))
234         {
235                 if (ad->ed_pw1->eo_check)
236                 {
237                         SETTING_TRACE_DEBUG("set focus on first entry");
238                         // no matter how many edifileds, it only need focus on 1st editfiled
239                         elm_object_focus_set(ad->ed_pw1->eo_check, EINA_TRUE);
240                         elm_entry_cursor_end_set(ad->ed_pw1->eo_check);
241                 }
242         }
243         else if(ad->ed_pw2 && (ad->ed_pw2->isFocusFlag == TRUE))
244         {
245                 if (ad->ed_pw2->eo_check)
246                 {
247                         SETTING_TRACE_DEBUG("set focus on second entry");
248                         //no matter how many edifileds, it only need focus on 1st editfiled
249                         elm_object_focus_set(ad->ed_pw2->eo_check, EINA_TRUE);
250                         elm_entry_cursor_end_set(ad->ed_pw2->eo_check);
251                 }
252         }
253         else if(ad->ed_pw3 && (ad->ed_pw3->isFocusFlag == TRUE))
254         {
255                 if (ad->ed_pw3->eo_check)
256                 {
257                         SETTING_TRACE_DEBUG("set focus on third entry");
258                         //no matter how many edifileds, it only need focus on 1st editfiled
259                         elm_object_focus_set(ad->ed_pw3->eo_check, EINA_TRUE);
260                         elm_entry_cursor_end_set(ad->ed_pw3->eo_check);
261                 }
262         }
263         else
264         {
265                 SETTING_TRACE_DEBUG("no entry to set focus");
266         }
267 }
268
269 static void *setting_password_ug_on_create(ui_gadget_h ug,
270                                            enum ug_mode mode, app_control_h service,
271                                            void *priv)
272 {
273         SETTING_TRACE_BEGIN;
274         setting_retvm_if((!priv), NULL, "!priv");
275
276         SettingPasswordUG *passwordUG = (SettingPasswordUG *)priv;
277         passwordUG->ug = ug;
278         passwordUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
279         passwordUG->win_get = (Evas_Object *) ug_get_window();
280         evas_object_show(passwordUG->win_main_layout);
281         passwordUG->evas = evas_object_evas_get(passwordUG->win_main_layout);
282
283         setting_retvm_if(passwordUG->win_main_layout == NULL, NULL,
284                          "cannot get main window ");
285
286         /* set launguage */
287         //setting_set_i18n(SETTING_PACKAGE, SETTING_LOCALEDIR);
288         bindtextdomain(SETTING_PACKAGE, SETTING_LOCALEDIR);
289         evas_object_smart_callback_add(passwordUG->win_get, "wm,rotation,changed", setting_password_rotated_cb, passwordUG);
290
291         setting_create_Gendial_itc("groupindex", &(passwordUG->itc_title));
292         setting_create_Gendial_itc("1icon",&(passwordUG->itc_variable_height));
293
294         passwordUG->itc_err_desc.item_style = "multiline_sub";
295         passwordUG->itc_err_desc.func.text_get = __gl_err_desc_text_get;
296         passwordUG->itc_err_desc.func.content_get = NULL;
297         passwordUG->itc_err_desc.func.state_get = NULL;
298         passwordUG->itc_err_desc.func.del = __gl_err_desc_del;
299
300         /* get screen lock type */
301         vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &(passwordUG->screen_lock_type));
302         SETTING_TRACE_DEBUG("screen lock type : %d", passwordUG->screen_lock_type);
303
304         /* init */
305         __get_extra_data(passwordUG, service);
306         __get_password_view_type(passwordUG, service);
307         passwordUG->step1_str = NULL;
308
309         setting_view *main_view = __initialize_view_node_table(pw_its[passwordUG->view_type].category);
310
311         /*  creating a view. */
312         setting_view_create(main_view,(void *)passwordUG);
313         evas_object_event_callback_add(passwordUG->win_main_layout,
314                                                EVAS_CALLBACK_RESIZE,
315                                                setting_password_ug_cb_resize,
316                                                passwordUG);
317
318         return passwordUG->ly_main;
319 }
320
321 static void setting_password_ug_on_start(ui_gadget_h ug, app_control_h service, void *priv)
322 {
323 }
324
325 static void setting_password_ug_on_pause(ui_gadget_h ug, app_control_h service, void *priv)
326 {
327         SETTING_TRACE_BEGIN;
328         SettingPasswordUG *passwordUG = (SettingPasswordUG *)priv;
329
330         if(pw_its[passwordUG->view_type].category & SETTING_PW_SUB_CATEGORY_SIMPLE)
331         {
332                 /* If pause, simple password's SIP should be focused out.
333                         If not, Our SIP will not be shown after using Other apps with independent SIP. */
334                 if(passwordUG->imf_context)
335                 {
336                         ecore_imf_context_reset(passwordUG->imf_context);
337                         ecore_imf_context_focus_out(passwordUG->imf_context);
338                 }
339         }
340 }
341
342 static void setting_password_ug_on_resume(ui_gadget_h ug, app_control_h service, void *priv)
343 {
344         SETTING_TRACE_BEGIN;
345         SettingPasswordUG *passwordUG = (SettingPasswordUG *)priv;
346
347         if(pw_its[passwordUG->view_type].category & SETTING_PW_SUB_CATEGORY_SIMPLE)
348         {
349                 /* If resume, simple password's SIP should be focused in.
350                 If not, Our SIP will not be shown after using Other apps with independent SIP. */
351                 if(passwordUG->imf_context)
352                 {
353                         //ecore_imf_context_input_panel_show(passwordUG->imf_context);
354                         ecore_imf_context_focus_in(passwordUG->imf_context);
355                 }
356         }
357 }
358
359 static void setting_password_ug_on_destroy(ui_gadget_h ug, app_control_h service, void *priv)
360 {
361         SETTING_TRACE_BEGIN;
362         SettingPasswordUG *passwordUG = (SettingPasswordUG *)priv;
363
364         evas_object_event_callback_del(passwordUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_password_ug_cb_resize);       /* fix flash issue for gallery */
365         evas_object_smart_callback_del(passwordUG->win_get, "wm,rotation,changed", setting_password_rotated_cb);
366         passwordUG->ug = ug;
367
368         if(passwordUG->view_type_string)
369                 FREE(passwordUG->view_type_string);
370
371         if(passwordUG->cur_pwd)
372                 FREE(passwordUG->cur_pwd);
373
374         if (passwordUG->t_info) {
375                 FREE(passwordUG->t_info);
376                 passwordUG->t_info = NULL;
377         }
378
379         if(pw_its[passwordUG->view_type].category & SETTING_PW_SUB_CATEGORY_SIMPLE)
380         {
381                 if(passwordUG->imf_context)
382                 {
383                         ecore_imf_context_del(passwordUG->imf_context);
384                         passwordUG->imf_context = NULL;
385                 }
386         }
387
388         __destroy_view(passwordUG);
389
390         if (NULL != ug_get_layout(passwordUG->ug)) {
391                 evas_object_hide((Evas_Object *) ug_get_layout(passwordUG->ug));
392                 evas_object_del((Evas_Object *) ug_get_layout(passwordUG->ug));
393         }
394         SETTING_TRACE_END;
395 }
396
397 static void setting_password_ug_on_message(ui_gadget_h ug, app_control_h msg,
398                                            app_control_h service, void *priv)
399 {
400
401 }
402
403 static void setting_password_ug_on_event(ui_gadget_h ug,
404                                          enum ug_event event, app_control_h service,
405                                          void *priv)
406 {
407         SETTING_TRACE_BEGIN;
408         if (!priv)
409                 return;
410
411         SettingPasswordUG *ad = (SettingPasswordUG*)priv;
412         //static int old_event = -1;
413         switch (event) {
414         case UG_EVENT_LOW_MEMORY:
415                 break;
416         case UG_EVENT_LOW_BATTERY:
417                 break;
418         case UG_EVENT_LANG_CHANGE:
419                 {
420 #if 0
421                         // update toolbar items
422                         Evas_Object *toolbar = elm_object_item_part_content_get(ad->navi_it, "toolbar");
423                         if(toolbar != NULL)
424                         {
425                                 Elm_Object_Item *last_item = elm_toolbar_last_item_get(toolbar);
426                                 Elm_Object_Item *first_item = elm_toolbar_last_item_get(toolbar);
427
428                                 if(last_item)
429                                         elm_object_item_text_set(last_item, _("IDS_COM_SK_DONE"));
430                                 if(first_item && (first_item != last_item))
431                                         elm_object_item_text_set(last_item, _("IDS_COM_SK_CANCEL"));
432                         }
433 #endif
434                 }
435                 break;
436         case UG_EVENT_ROTATE_PORTRAIT:
437         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
438         case UG_EVENT_ROTATE_LANDSCAPE:
439         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
440                 break;
441         case UG_EVENT_REGION_CHANGE:
442                 break;
443         default:
444                 break;
445         }
446 }
447
448 static void setting_password_ug_on_key_event(ui_gadget_h ug,
449                                              enum ug_key_event event,
450                                              app_control_h service, void *priv)
451 {
452         if (!priv)
453                 return;
454
455         SettingPasswordUG *ad = (SettingPasswordUG*)priv;
456
457         switch (event) {
458         case UG_KEY_EVENT_END:
459                 ug_destroy_me(ug);
460                 break;
461         default:
462                 break;
463         }
464 }
465
466 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
467 {
468         SettingPasswordUG *passwordUG = calloc(1, sizeof(SettingPasswordUG));
469         setting_retvm_if(!passwordUG, -1, "Create SettingPasswordUG obj failed");
470
471         ops->create = setting_password_ug_on_create;
472         ops->start = setting_password_ug_on_start;
473         ops->pause = setting_password_ug_on_pause;
474         ops->resume = setting_password_ug_on_resume;
475         ops->destroy = setting_password_ug_on_destroy;
476         ops->message = setting_password_ug_on_message;
477         ops->event = setting_password_ug_on_event;
478         ops->key_event = setting_password_ug_on_key_event;
479         ops->priv = passwordUG;
480         ops->opt = UG_OPT_INDICATOR_ENABLE;
481
482         memset(passwordUG, 0x00, sizeof(SettingPasswordUG));
483
484         return 0;
485 }
486
487 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
488 {
489         SETTING_TRACE_BEGIN;
490         struct SettingPasswordUG *passwordUG;
491         setting_retm_if(!ops, "ops == NULL");
492
493         passwordUG = ops->priv;
494         if (passwordUG)
495                 FREE(passwordUG);
496 }
497
498 void setting_password_ug_popup_resp_cb(void *data, Evas_Object *obj,
499                                        void *event_info)
500 {
501         retm_if(data == NULL, "Data parameter is NULL");
502
503         app_control_h svc;
504         SettingPasswordUG *ad = (SettingPasswordUG *) data;
505         if (ad->destroy) {
506                 /*  Success to Operate */
507
508                 if (app_control_create(&svc))
509                         return;
510
511                 app_control_add_extra_data(svc, "result", ad->view_type_string);
512                 ug_send_result(ad->ug, svc);
513                 SETTING_TRACE("Send Result : %s\n", ad->view_type_string);
514
515                 app_control_destroy(svc);
516                 /* Send destroy request */
517                 ug_destroy_me(ad->ug);
518         } else {
519                 if (ad->view_type == SETTING_PW_TYPE_PIN_BLOCKED)
520                 {
521                         ug_destroy_me(ad->ug);
522                         return;
523                 }
524                 else if (ad->view_type == SETTING_PW_TYPE_PIN2_BLOCKED)
525                 {
526                         ug_destroy_me(ad->ug);
527                         return;
528                 }
529 #if SUPPORT_SIMLOCK
530                 char *diable_view_type = NULL;
531                 if (ad->disable_item_type == SETTING_PW_TYPE_SIM_LOCK_OFF) {
532                         diable_view_type = "SETTING_PW_TYPE_SIM_LOCK_DISABLE";
533                 }
534
535                 if (diable_view_type) {
536                         /*  Success to Operate */
537
538                         if (app_control_create(&svc))
539                                 return;
540
541                         app_control_add_extra_data(svc, "result", diable_view_type);
542                         ug_send_result(ad->ug, svc);
543
544                         app_control_destroy(svc);
545                         /* Send destroy request */
546                         ug_destroy_me(ad->ug);
547                 }
548 #endif
549                 if (ad->focus_data) {
550                         ad->focus_data->isFocusFlag = TRUE;
551                         elm_object_item_data_set(ad->focus_data->item, ad->focus_data);
552                         elm_genlist_item_update(ad->focus_data->item);
553                 }
554         }
555 }
556
557 void setting_password_ug_display_desc(void *data, char *desc, int destroy)
558 {
559         SETTING_TRACE_BEGIN;
560         ret_if(data == NULL || desc == NULL);
561
562         SettingPasswordUG *ad = (SettingPasswordUG *)data;
563
564         ad->destroy = destroy;
565
566         if(ad->scroller == NULL)
567                 return;
568
569         if(ad->err_desc && ad->err_desc->item)
570         {
571                 elm_object_item_del(ad->err_desc->item);
572                 ad->err_desc = NULL;
573         }
574
575         ad->err_desc = setting_create_Gendial_field_helpitem_without_bottom_separator(
576                                                                                                         ad->scroller,
577                                                                                                         &(itc_multiline_text),
578                                                                                                         SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
579                                                                                                         desc);
580
581         /* if pw incorrect, show keyboard again. */
582         //if(ad->ed_pw1 && ad->ed_pw1->eo_check)
583         //{
584         //      elm_object_focus_set(ad->ed_pw1->eo_check, EINA_TRUE);
585         //}
586 }
587
588 void
589 setting_password_ug_create_popup_notitle_nobtn(void *data, char *str,
590                                                int destroy)
591 {
592         /* error check */
593         retm_if(data == NULL, "Data parameter is NULL");
594
595         SettingPasswordUG *ad = (SettingPasswordUG *) data;
596
597         ad->destroy = destroy;
598         if(ad->notify)
599         {
600                 evas_object_del(ad->notify);
601                 ad->notify = NULL;
602         }
603         ad->notify = setting_create_popup_without_btn(ad, ad->ly_main, NULL, str,
604                                           setting_password_ug_popup_resp_cb,
605                                           POPUP_INTERVAL, FALSE, FALSE);
606 }
607
608 void setting_password_ug_check_attemps_left(void *data)
609 {
610         ret_if(!data);
611         SettingPasswordUG *ad = (SettingPasswordUG *) data;
612
613         setting_int_slp_list item_attempts_left;
614         setting_str_slp_list item_lock_timestamp;
615         int attemps_left_max = 5;
616
617         if (ad->view_type == SETTING_PW_TYPE_PASSWORD) {
618                 item_attempts_left = INT_SLP_SETTING_PHONE_LOCK_ATTEMPTS_LEFT;
619                 item_lock_timestamp = STR_SLP_SETTING_PHONE_LOCK_TIMESTAMP;
620                 attemps_left_max = PHONE_LOCK_ATTEMPS_MAX;
621         } else if (ad->view_type == SETTING_PW_TYPE_SIM_LOCK_OFF) {
622                 item_attempts_left = INT_SLP_SETTING_SIM_LOCK_ATTEMPTS_LEFT;
623                 item_lock_timestamp = STR_SLP_SETTING_SIM_LOCK_TIMESTAMP;
624                 attemps_left_max = SIM_LOCK_ATTEMPS_MAX;
625         } else {
626                 return;
627         }
628
629         int value = -1;
630         int err = SETTING_RETURN_SUCCESS;
631         setting_get_int_slp_key(item_attempts_left, &value, &err);
632         setting_retm_if(err == SETTING_RETURN_FAIL,
633                         "[Error] get value of vconf fail.");
634
635         value--;
636
637         if (value > 0 && value <= attemps_left_max) {
638                 setting_set_int_slp_key(item_attempts_left, value, &err);
639                 setting_retm_if(err == SETTING_RETURN_FAIL, "[Error] set value of vconf fail.");
640                 char temp_str[MAX_SPECIALIZITION_LEN] = {0,};
641                 char temp[MAX_SPECIALIZITION_LEN] ={0,};
642
643                 if(value > 1)
644                         snprintf(temp, sizeof(temp), "%s. %s.", PW_ERR_DESC, ATTEMPTS_DESC);
645                 else
646                         snprintf(temp, sizeof(temp), "%s. %s.", PW_ERR_DESC, ATTEMPT_DESC);
647
648                 int ret = snprintf(temp_str, MAX_SPECIALIZITION_LEN, temp, value);
649
650                 ret_if(ret < 0);
651
652                 setting_password_ug_display_desc(ad, temp_str, FALSE);
653         } else if (value == 0) {
654                 /*  store the lock timestamp */
655                 time_t cur_time = time(NULL);
656                 char cur_timestamp[LOCK_TIMESTAMP_LEN] = { 0, };
657                 int ret = snprintf(cur_timestamp, sizeof(cur_timestamp), "%ld", cur_time);
658                 ret_if(ret < 0);
659
660                 setting_set_string_slp_key(item_lock_timestamp, cur_timestamp, &err);
661                 setting_retm_if(err == SETTING_RETURN_FAIL,
662                                 "[Error] set value of vconf fail.");
663
664                 setting_set_int_slp_key(item_attempts_left, value, &err);
665                 setting_retm_if(err == SETTING_RETURN_FAIL,
666                                 "[Error] set value of vconf fail.");
667
668                 ad->disable_item_type = ad->view_type;
669
670                 char temp[MAX_SPECIALIZITION_LEN] = {0,};
671                 snprintf(temp, sizeof(temp), PW_ERR_DELAY_DESC, PW_ERR_DELAY_TIME);
672
673                 setting_password_ug_create_popup_notitle_nobtn(ad, temp, FALSE);
674         } else {
675                 setting_password_ug_create_popup_notitle_nobtn(ad,
676                                                                _("IDS_COM_POP_ERROR"), FALSE);
677         }
678
679 }
680
681 int setting_password_check_password(const char *challenge, unsigned int *remain_attempt, unsigned int *valid_sec)
682 {
683         SETTING_TRACE_BEGIN;
684         retv_if(challenge == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
685
686         int inner_ret = 0;
687         int ret = 0;
688         unsigned int current_attempt = 0;
689         unsigned int max_attempt = 0;
690         unsigned int valid_secs = 0;
691
692         inner_ret = security_server_chk_pwd(challenge, &current_attempt, &max_attempt, &valid_secs);
693
694         SETTING_TRACE_DEBUG("chk password : %d", inner_ret);
695         SETTING_TRACE_SECURE_DEBUG("current_attempt : %d, max_attempt : %d, valid_secs : %d secs", current_attempt, max_attempt, valid_secs);
696
697         if(valid_sec != NULL)
698                 *valid_sec = valid_secs;
699
700         if(inner_ret == SECURITY_SERVER_API_SUCCESS)
701         {
702                 ret = SETTING_RETURN_SUCCESS;
703         }
704         else
705         {
706                 if(remain_attempt != NULL)
707                 {
708                         if((max_attempt > 0) && (max_attempt >= current_attempt))
709                                 *remain_attempt = max_attempt - current_attempt;
710                         else
711                                 *remain_attempt = ATTEMPT_INFINITE;     // infinite
712                 }
713                 ret = SETTING_RETURN_FAIL;
714         }
715
716         return ret;
717 }
718
719 int setting_password_set_password(const char *cur_pwd, const char *new_pwd, void *data)
720 {
721         SETTING_TRACE_BEGIN;
722         retv_if(new_pwd == NULL || data == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
723
724         SettingPasswordUG *ad = (SettingPasswordUG*)data;
725         int ret = 0;
726         int err;
727
728         /* To support key manager */
729         uid_t user = 5000;
730         //int ckmc_ret = CKMC_ERROR_NONE;
731
732         /* max attempt count will be handled in passwordug for a while. */
733         if(ad->pw_status == SETTING_PW_STATUS_EMPTY)
734         {
735                 ret = security_server_set_pwd(NULL, new_pwd, 0, 0);
736                 SETTING_TRACE_DEBUG("[security_server_set_pwd() + empty current] returns %d, INFINITE", ret);
737                 if(ret == SECURITY_SERVER_API_SUCCESS)
738                 {
739                         #if 0
740                         ckmc_ret = ckmc_reset_user_password(user, new_pwd);
741                         SETTING_TRACE("ckmc_reset_user_password() returns %d", ckmc_ret);
742                         setting_set_int_slp_key(INT_SLP_SETTING_PHONE_LOCK_ATTEMPTS_LEFT, PHONE_LOCK_ATTEMPS_MAX, &err);
743                         #endif
744                         return SETTING_RETURN_SUCCESS;
745                 }
746                 else
747                 {
748                         return SETTING_PW_ERROR_UNKNOWN;
749                 }
750         }
751         else
752         {
753                 ret = security_server_set_pwd(cur_pwd, new_pwd, 0, 0);
754                 SETTING_TRACE_DEBUG("[security_server_set_pwd()] returns %d, INFINITE", ret);
755                 if(ret == SECURITY_SERVER_API_SUCCESS)
756                 {
757                         #if 0
758                         ckmc_ret = ckmc_change_user_password(user, cur_pwd, new_pwd);
759                         SETTING_TRACE("ckmc_change_user_password() returns %d", ckmc_ret);
760                         setting_set_int_slp_key(INT_SLP_SETTING_PHONE_LOCK_ATTEMPTS_LEFT, PHONE_LOCK_ATTEMPS_MAX, &err);
761                         #endif
762                         return SETTING_RETURN_SUCCESS;
763                 }
764                 else
765                 {
766                         return SETTING_PW_ERROR_UNKNOWN;
767                 }
768         }
769 }
770
771