tizen 2.4 release
[apps/home/settings.git] / setting-security / src / setting-security.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
22 #include <setting-security.h>
23 #include <setting-cfg.h>
24
25 #include <efl_extension.h>
26 #include <Ecore_X.h>
27 #include <utilX.h>
28 #include <app_manager.h>
29 #if SUPPORT_ENCRYPTION
30 #include <ode.h>
31 #endif
32 #include <sys/wait.h>
33 #include <bundle_internal.h>
34
35
36 #define Max_Passwd_View_Type_Len        64
37 #ifndef UG_MODULE_API
38 #define UG_MODULE_API __attribute__ ((visibility("default")))
39 #endif
40
41 enum {
42     RESULT_OK,
43     RESULT_FAILED,
44     RESULT_CANCELED,
45     RESULT_NETWORK_ERROR
46 };
47
48 void setting_security_ug_popup_resp_cb(void *data, Evas_Object *obj, void *event_info)
49 {
50         retm_if(data == NULL, "Data parameter is NULL");
51
52         SettingSecurityUG *ad = (SettingSecurityUG *)data;
53         if (ad->save_popup) {
54                 evas_object_del(ad->save_popup);
55                 ad->save_popup = NULL;
56         }
57         ug_destroy_me(ad->ug);
58 }
59
60 int pwd_handler_do_nothing(SettingSecurityUG *data, void *arg)
61 {
62         SETTING_TRACE_BEGIN;
63         /*SettingSecurityUG *ad = (SettingSecurityUG *)data; */
64         /* DO NOTHING */
65         return 0;
66 }
67
68 int pwd_handler_sec_pw_passwd(SettingSecurityUG *data, void *arg)
69 {
70         SETTING_TRACE_BEGIN;
71 #if SUPPORT_ENCRYPTION
72         SettingSecurityUG *ad = (SettingSecurityUG *)data;
73
74         if (setting_view_security_encryption.is_create == TRUE && ad->pw_type == SETTING_SEC_PW_ENCRYPTION) {
75                 if (setting_view_get_topview(&setting_view_security_confirm_encryption) != &setting_view_security_encryption) {
76                         SETTING_TRACE("view stack is missed. initialize again.");
77                         setting_view_node_table_intialize();
78                         /*SETTING_TRACE("viewtype 0x%x", ad->viewtype); */
79                         if (ad->viewtype == SETTING_SEC_VIEWTYPE_ENCRYPTION) {
80                                 setting_view_node_table_register(&setting_view_security_encryption, NULL);
81                                 setting_view_node_table_register(&setting_view_security_confirm_encryption, &setting_view_security_encryption);
82                         } else {
83                                 setting_view_node_table_register(&setting_view_security_main, NULL);
84                                 setting_view_node_table_register(&setting_view_security_sim_settings, &setting_view_security_main);
85                                 setting_view_node_table_register(&setting_view_security_update, &setting_view_security_main);
86                                 setting_view_node_table_register(&setting_view_security_encryption, &setting_view_security_main);
87                                 setting_view_node_table_register(&setting_view_security_confirm_encryption, &setting_view_security_encryption);
88                         }
89                 }
90                 setting_view_change(&setting_view_security_encryption, &setting_view_security_confirm_encryption, ad);
91                 return 0;
92         }
93 #endif
94
95         if (vconf_set_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, SETTING_SCREEN_LOCK_TYPE_PASSWORD) == 0) {
96                 /* Success to save */
97         } else {
98                 SETTING_TRACE_ERROR("setting vconf value failed : screen_lock_type");
99         }
100
101         return 0;
102 }
103
104 static void
105 __face_voice_done_cb(void *data, Evas_Object *obj, void *event_info)
106 {
107         /* error check */
108         retm_if(data == NULL, "[Setting > Security] Data parameter is NULL");
109         SettingSecurityUG *ad = (SettingSecurityUG *) data;
110
111         /*int i = 0; */
112         while (elm_naviframe_top_item_get(ad->navi_bar) != ad->screen_lock_main_item) {
113                 elm_naviframe_item_pop(ad->navi_bar);
114                 /*SETTING_TRACE("i:%d",i); */
115                 /*i++; */
116                 /*sleep(2); */
117                 if (elm_naviframe_top_item_get(ad->navi_bar) == elm_naviframe_bottom_item_get(ad->navi_bar)) {
118                         break;
119                 }
120         }
121 }
122
123 int pwd_handler_sec_pw_simple_passwd(SettingSecurityUG *data, void *arg)
124 {
125         SETTING_TRACE_BEGIN;
126         SettingSecurityUG *ad = (SettingSecurityUG *)data;
127
128         SETTING_TRACE("ad->selected_lock_type:%s", ad->selected_lock_type);
129         /*'face and voice ' and 'simple password' share the same PASSWD_TYPE and callback function */
130         int lock_type = SETTING_SCREEN_LOCK_TYPE_SIMPLE_PASSWORD;
131         if (!safeStrCmp(ad->selected_lock_type, Keystr_FaceAndVoice)) {
132                 lock_type = SETTING_SCREEN_LOCK_TYPE_FACE_AND_VOICE;
133                 setting_create_guild_layout(ad->navi_bar, Setup_Face_Unlock_Str,
134                                             _("IDS_SA_BUTTON_DONE_ABB"), NULL, NULL,
135                                             __face_voice_done_cb, NULL, NULL,
136                                             _(Finish_Setup_Face),
137                                             NULL, NULL, NULL, NULL, ad);
138         }
139
140         if (vconf_set_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, lock_type) == 0) {
141                 /* Success to save */
142         } else {
143                 SETTING_TRACE_ERROR("setting vconf value failed : screen_lock_type");
144         }
145         return 0;
146 }
147
148 int pwd_handler_sec_pw_sim_lock_on(SettingSecurityUG *data, void *arg)
149 {
150         SETTING_TRACE_BEGIN;
151         SettingSecurityUG *ad = (SettingSecurityUG *)data;
152         if (tel_get_sim_facility(ad->handle, TAPI_SIM_LOCK_PS, setting_security_sim_get_facility_cb, ad) != TAPI_API_SUCCESS) {
153                 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
154         }
155         return 0;
156 }
157
158
159 int pwd_handler_sec_pw_sim_lock_off(SettingSecurityUG *data, void *arg)
160 {
161         SETTING_TRACE_BEGIN;
162         SettingSecurityUG *ad = (SettingSecurityUG *)data;
163         if (tel_get_sim_facility(ad->handle, TAPI_SIM_LOCK_PS, setting_security_sim_get_facility_cb, ad) != TAPI_API_SUCCESS) {
164                 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
165         }
166         return 0;
167 }
168
169
170 int pwd_handler_sec_pw_pin_lock_on(SettingSecurityUG *data, void *arg)
171 {
172         SETTING_TRACE_BEGIN;
173         retv_if(!data, -1);
174         SettingSecurityUG *ad = (SettingSecurityUG *)data;
175
176         if (tel_get_sim_facility(ad->handle, TAPI_SIM_LOCK_SC, setting_security_pin_get_facility_cb, ad) != TAPI_API_SUCCESS) {
177                 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
178         }
179         return 0;
180 }
181
182
183 int pwd_handler_sec_pw_pin_lock_off(SettingSecurityUG *data, void *arg)
184 {
185         SETTING_TRACE_BEGIN;
186         SettingSecurityUG *ad = (SettingSecurityUG *)data;
187         if (tel_get_sim_facility(ad->handle, TAPI_SIM_LOCK_SC, setting_security_pin_get_facility_cb, ad) != TAPI_API_SUCCESS) {
188                 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
189         }
190         return 0;
191 }
192
193
194 int pwd_handler_sec_pw_sim_lock_disabled(SettingSecurityUG *data, void *arg)
195 {
196         SETTING_TRACE_BEGIN;
197         SettingSecurityUG *ad = (SettingSecurityUG *)data;
198         /* [in] Evas_Object *checkbtn */
199         if (ad->data_sim_lk)
200                 setting_disable_genlist_item(ad->data_sim_lk->item);
201
202         return 0;
203 }
204
205
206 int pwd_handler_sec_pw_change_pin1(SettingSecurityUG *data, void *arg)
207 {
208         SETTING_TRACE_BEGIN;
209         SettingSecurityUG *ad = (SettingSecurityUG *)data;
210
211         setting_create_popup(ad, ad->ly_main, NULL, "IDS_ST_POP_PIN_CHANGED",
212                                          NULL,
213                                          POPUP_INTERVAL, FALSE, FALSE, 0);
214         return 0;
215 }
216
217 #if SUPPORT_FDN
218 int pwd_handler_sec_pw_fdn_mode_on(SettingSecurityUG *data, void *arg)
219 {
220         SETTING_TRACE_BEGIN;
221         SettingSecurityUG *ad = (SettingSecurityUG *)data;
222         if (tel_get_sim_facility(ad->handle, TAPI_SIM_LOCK_FD, setting_security_sim_get_facility_cb, ad) != TAPI_API_SUCCESS) {
223                 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
224         }
225         return 0;
226 }
227
228
229 int pwd_handler_sec_pw_fdn_mode_off(SettingSecurityUG *data, void *arg)
230 {
231         SETTING_TRACE_BEGIN;
232         SettingSecurityUG *ad = (SettingSecurityUG *)data;
233         if (tel_get_sim_facility(ad->handle, TAPI_SIM_LOCK_FD, setting_security_sim_get_facility_cb, ad) != TAPI_API_SUCCESS) {
234                 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
235         }
236         return 0;
237 }
238 #endif
239
240 int pwd_handler_sec_pw_change_pin2(SettingSecurityUG *data, void *arg)
241 {
242         SETTING_TRACE_BEGIN;
243         return 0;
244 }
245
246 static void setting_security_pin1_blocked_resp_cb(void *data, Evas_Object *obj, void *event_info)
247 {
248         SETTING_TRACE_BEGIN;
249         ret_if(!data);
250         SettingSecurityUG *ad = data;
251
252         int ret = 0;
253         /* Call pwlock. */
254         bundle *b = bundle_create();
255         if (b) {
256                 bundle_add(b, "after_bootup", "1");
257                 ret = aul_launch_app("org.tizen.pwlock", b);
258                 SETTING_TRACE("aul_launch_app() returns %d", ret);
259                 bundle_free(b);
260         }
261
262         if (ad->sim_popup) {
263                 evas_object_del(ad->sim_popup);
264                 ad->sim_popup = NULL;
265         }
266 }
267
268 int pwd_handler_sec_pw_pin1_blocked(SettingSecurityUG *data, void *arg)
269 {
270         SETTING_TRACE_BEGIN;
271         SettingSecurityUG *ad = (SettingSecurityUG *)data;
272
273         if (ad->sim_popup) {
274                 evas_object_del(ad->sim_popup);
275                 ad->sim_popup = NULL;
276         }
277
278         /* To do : draw popup, */
279         /*         content - PIN Blocked\n The PIN is now blocked. Enter your PUK code to continue. */
280         /*                 button - OK */
281         char popup_text[2048] = {0,};
282         snprintf(popup_text, 2048, "%s", _(PIN_BLOCKED_ENTER_PUK_DESC));
283
284         Ecore_X_Window xwin = 0;
285         Ecore_X_Display *disp = NULL;
286
287         int ret = 0;
288         disp = ecore_x_display_get();
289         xwin = elm_win_xwindow_get(ad->win_get);
290
291         ecore_x_netwm_window_type_set(xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
292         utilx_set_system_notification_level(disp, xwin, UTILX_NOTIFICATION_LEVEL_LOW);
293
294         ret = eext_win_keygrab_set(xwin, "XF86Back");
295         if (ret)
296                 SETTING_TRACE("eext_win_keygrab_set() failed.");
297         ret = eext_win_keygrab_set(xwin, "XF86Home");
298         if (ret)
299                 SETTING_TRACE("eext_win_keygrab_set() failed.");
300         ret = eext_win_keygrab_set(xwin, "XF86AudioRaiseVolume");
301         if (ret)
302                 SETTING_TRACE("eext_win_keygrab_set() failed.");
303         ret = eext_win_keygrab_set(xwin, "XF86AudioLowerVolume");
304         if (ret)
305                 SETTING_TRACE("eext_win_keygrab_set() failed.");
306
307         unsigned int val[3];
308         val[0] = 0;     /* always enable F */
309         val[1] = 0;             /* quickpanel enable F */
310         val[2] = 0;     /* apptray enable F */
311         /* set quickpanel disable */
312         Ecore_X_Atom ATOM_PANEL_SCROLLABLE_STATE = 0;
313         ATOM_PANEL_SCROLLABLE_STATE = ecore_x_atom_get("_E_MOVE_PANEL_SCROLLABLE_STATE");
314         ecore_x_window_prop_card32_set(xwin, ATOM_PANEL_SCROLLABLE_STATE, val, 3);
315
316         ad->sim_popup = setting_create_popup(ad, ad->win_get, NULL,
317                                              popup_text,
318                                              setting_security_pin1_blocked_resp_cb,
319                                              0, FALSE, FALSE,
320                                                                                  1, "IDS_ST_BUTTON_OK");
321         eext_object_event_callback_del(ad->sim_popup, EEXT_CALLBACK_BACK, setting_popup_del_cb);
322
323         /* End. */
324         return 0;
325 }
326
327 int pwd_handler_sec_pw_pin2_blocked(SettingSecurityUG *data, void *arg)
328 {
329         SETTING_TRACE_BEGIN;
330
331         SettingSecurityUG *ad = (SettingSecurityUG *)data;
332 #if SUPPORT_FDN
333         if (tel_get_sim_facility(ad->handle, TAPI_SIM_LOCK_FD, setting_security_sim_get_facility_cb, ad) != TAPI_API_SUCCESS) {
334                 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
335         }
336 #endif
337
338         if (ad->sim_popup) {
339                 evas_object_del(ad->sim_popup);
340                 ad->sim_popup = NULL;
341         }
342         char popup_text[2048] = {0,};
343         snprintf(popup_text, 2048, "%s", _("IDS_ST_POP_PIN2_BLOCKED"));
344
345         setting_create_popup(ad, ad->win_get, NULL,
346                                          popup_text,
347                                          NULL,
348                                          2, FALSE, FALSE, 0);
349
350         ad->pin2_blocked_flag = TRUE;
351         setting_view_update(&setting_view_security_sim_settings, ad);
352
353         return 0;
354 }
355
356 int pwd_handler_sec_pw_pin2_unblocked(SettingSecurityUG *data, void *arg)
357 {
358         SETTING_TRACE_BEGIN;
359
360         SettingSecurityUG *ad = (SettingSecurityUG *)data;
361         ad->pin2_blocked_flag = FALSE;
362         setting_view_update(&setting_view_security_sim_settings, ad);
363
364         return 0;
365 }
366
367 int pwd_handler_sec_pw_puk1_blocked(SettingSecurityUG *data, void *arg)
368 {
369         SETTING_TRACE_BEGIN;
370         SettingSecurityUG *ad = (SettingSecurityUG *)data;
371         if (setting_view_security_sim_settings.is_create == TRUE) {
372                 setting_view_change(&setting_view_security_sim_settings, &setting_view_security_main, ad);
373         } else if (setting_view_security_main.is_create == TRUE) {
374                 setting_view_update(&setting_view_security_main, ad);
375         }
376
377         return 0;
378 }
379
380 static struct _security_item security_table[] = {
381         { SETTING_SEC_PW_PASSWORD,              "SETTING_PW_TYPE_PASSWORD",                     pwd_handler_sec_pw_passwd },
382         { SETTING_SEC_PW_SIMPLE_PASSWD,         "SETTING_PW_TYPE_SIMPLE_PASSWORD",              pwd_handler_sec_pw_simple_passwd },
383         { SETTING_SEC_PW_ENTER_LOCK_TYPE, "SETTING_PW_TYPE_ENTER_LOCK_TYPE",            pwd_handler_do_nothing},
384         { SETTING_SEC_PW_ENCRYPTION, "SETTING_PW_TYPE_ENCRYPTION",              pwd_handler_sec_pw_passwd},
385         { SETTING_SEC_PW_SIM_LOCK_ON,           "SETTING_PW_TYPE_SIM_LOCK_ON",                  pwd_handler_sec_pw_sim_lock_on },
386         { SETTING_SEC_PW_SIM_LOCK_OFF,          "SETTING_PW_TYPE_SIM_LOCK_OFF",                 pwd_handler_sec_pw_sim_lock_off },
387         { SETTING_SEC_PW_SIM_LOCK_DISABLED, "SETTING_PW_TYPE_SIM_LOCK_DISABLE",         pwd_handler_sec_pw_sim_lock_disabled},
388         { SETTING_SEC_PW_PIN_LOCK_ON,           "SETTING_PW_TYPE_PIN_LOCK_ON",                  pwd_handler_sec_pw_pin_lock_on },
389         { SETTING_SEC_PW_PIN_LOCK_OFF,          "SETTING_PW_TYPE_PIN_LOCK_OFF",                 pwd_handler_sec_pw_pin_lock_off },
390         { SETTING_SEC_PW_CHANGE_PIN1,           "SETTING_PW_TYPE_CHANGE_PIN",                   pwd_handler_sec_pw_change_pin1},
391 #if SUPPORT_FDN
392         { SETTING_SEC_PW_FDN_MODE_ON,           "SETTING_PW_TYPE_FDN_MODE_ON",                  pwd_handler_sec_pw_fdn_mode_on},
393         { SETTING_SEC_PW_FDN_MODE_OFF,          "SETTING_PW_TYPE_FDN_MODE_OFF",                 pwd_handler_sec_pw_fdn_mode_off},
394 #endif
395         { SETTING_SEC_PW_CHANGE_PIN2,           "SETTING_PW_TYPE_CHANGE_PIN2",                  pwd_handler_sec_pw_change_pin2},
396         { SETTING_SEC_PW_PIN1_BLOCKED,          "SETTING_PW_TYPE_PIN_BLOCKED",                  pwd_handler_sec_pw_pin1_blocked},
397         { SETTING_SEC_PW_PIN2_BLOCKED,          "SETTING_PW_TYPE_PIN2_BLOCKED",                 pwd_handler_sec_pw_pin2_blocked},
398         { SETTING_SEC_PW_PIN1_UNBLOCKED,                "SETTING_PW_TYPE_PIN1_UNBLOCKED",               pwd_handler_sec_pw_pin_lock_on},
399         { SETTING_SEC_PW_PIN2_UNBLOCKED,                "SETTING_PW_TYPE_PIN2_UNBLOCKED",               pwd_handler_sec_pw_pin2_unblocked},
400         { SETTING_SEC_PW_PUK1_BLOCKED,          "SETTING_PW_TYPE_PUK1_BLOCKED",         pwd_handler_sec_pw_puk1_blocked},
401         { SETTING_SEC_PW_PUK2_BLOCKED,          "SETTING_PW_TYPE_PUK2_BLOCKED",         pwd_handler_do_nothing},
402         /*------------------------------------------------------------------------------------------------------------*/
403         { SETTING_SEC_PW_MAX,                           NULL,                                                                   pwd_handler_do_nothing}
404 };
405
406 static void setting_security_ug_cb_resize(void *data, Evas *e,
407                                           Evas_Object *obj, void *event_info)
408 {
409         ret_if(data == NULL);
410
411         SettingSecurityUG *ad = (SettingSecurityUG *) data;     /* ad is point to data */
412         if (ad->viewtype == SETTING_SEC_VIEWTYPE_MAIN)
413                 setting_view_update(&setting_view_security_main, ad);
414 }
415
416 setting_view *__get_security_view_to_load(void *data, app_control_h service)
417 {
418         SETTING_TRACE_BEGIN;
419         SettingSecurityUG *ad = (SettingSecurityUG *)data;
420
421         char *viewtype = NULL;
422
423         app_control_get_extra_data(service, "viewtype", &viewtype);
424         /*if(!viewtype) */
425         /*      return NULL; */
426         if (viewtype) {
427                 if (!safeStrCmp(viewtype, "encryption"))
428                         ad->viewtype = SETTING_SEC_VIEWTYPE_ENCRYPTION;
429                 else if (!safeStrCmp(viewtype, "update"))
430                         ad->viewtype = SETTING_SEC_VIEWTYPE_UPDATE;
431                 else
432                         ad->viewtype = SETTING_SEC_VIEWTYPE_MAIN;
433         } else {
434                 ad->viewtype = SETTING_SEC_VIEWTYPE_MAIN;
435         }
436         FREE(viewtype);
437
438         if (ad->viewtype == SETTING_SEC_VIEWTYPE_MAIN) {
439                 setting_view_node_table_register(&setting_view_security_main, NULL);
440                 setting_view_node_table_register(&setting_view_security_sim_settings, &setting_view_security_main);
441                 setting_view_node_table_register(&setting_view_security_update, &setting_view_security_main);
442 #if SUPPORT_ENCRYPTION
443                 setting_view_node_table_register(&setting_view_security_encryption, &setting_view_security_main);
444                 setting_view_node_table_register(&setting_view_security_confirm_encryption, &setting_view_security_encryption);
445 #endif
446                 return &setting_view_security_main;
447         } else if (ad->viewtype == SETTING_SEC_VIEWTYPE_UPDATE) {
448                 setting_view_node_table_register(&setting_view_security_update, NULL);
449                 return &setting_view_security_update;
450         }
451 #if SUPPORT_ENCRYPTION
452         else if (ad->viewtype == SETTING_SEC_VIEWTYPE_ENCRYPTION) {
453                 setting_view_node_table_register(&setting_view_security_encryption, NULL);
454                 setting_view_node_table_register(&setting_view_security_confirm_encryption, &setting_view_security_encryption);
455                 /*setting_view_node_table_register(&setting_view_security_enc_processing, &setting_view_security_confirm_encryption); */
456                 return &setting_view_security_encryption;
457         }
458 #endif
459         else {
460                 /* unknown viewtype */
461                 return NULL;
462         }
463 }
464
465 static void *setting_security_ug_on_create(ui_gadget_h ug,
466                                            enum ug_mode mode, app_control_h service,
467                                            void *priv)
468 {
469         setting_retvm_if((!priv), NULL, "!priv");
470
471         SettingSecurityUG *securityUG = priv;
472         securityUG->ug = ug;
473
474         securityUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
475         securityUG->win_get = (Evas_Object *) ug_get_window();
476         evas_object_show(securityUG->win_main_layout);
477         securityUG->evas = evas_object_evas_get(securityUG->win_main_layout);
478
479         setting_retvm_if(securityUG->win_main_layout == NULL, NULL,
480                          "[Setting >> About] cannot get main window ");
481
482         /*setting_set_i18n(SETTING_PACKAGE, SETTING_LOCALEDIR); */
483         bindtextdomain(SETTING_PACKAGE, SETTING_LOCALEDIR);
484
485         /* register view node table */
486         setting_view_node_table_intialize();
487
488         setting_create_Gendial_itc(SETTING_GENLIST_ICON_1LINE_STYLE, &(securityUG->itc_1text));
489         setting_create_Gendial_itc(SETTING_GENLIST_ICON_1LINE_STYLE, &(securityUG->itc_1text_1icon));
490         setting_create_Gendial_itc(SETTING_GENLIST_GROUP_INDEX_STYLE, &(securityUG->itc_group_item));
491         setting_create_Gendial_itc("multiline_sub", &(securityUG->itc_bg_1icon));
492         setting_create_Gendial_itc(SETTING_GENLIST_2LINE_STYLE, &(securityUG->itc_2text_2));
493         setting_create_Gendial_itc(SETTING_GENLIST_2LINE_STYLE, &(securityUG->itc_2text_3_parent));
494
495         securityUG->update_view_timer = NULL;
496         securityUG->remove_sim_popup_timer = NULL;
497         securityUG->tapi_async_cb_check_timer = NULL;
498         securityUG->input_pwd = NULL;
499         /*securityUG->cur_enc_mode = 0; */
500         /*  creating a view. */
501         securityUG->handle =  tel_init(NULL);
502         if (!securityUG->handle) {
503                 SETTING_TRACE_ERROR("*** [ERR] tel_init. ***");
504                 /*return NULL; */
505         }
506         securityUG->view_to_load = __get_security_view_to_load(securityUG, service);
507         setting_retvm_if(NULL == securityUG->view_to_load, NULL,
508                          "NULL == securityUG->view_to_load");
509
510         app_control_get_extra_data(service, "current", &(securityUG->input_pwd));
511
512         setting_view_node_set_cur_view(securityUG->view_to_load);
513         setting_view_create(securityUG->view_to_load, (void *)securityUG);
514         evas_object_event_callback_add(securityUG->win_main_layout,
515                                        EVAS_CALLBACK_RESIZE,
516                                        setting_security_ug_cb_resize, securityUG);
517
518         return securityUG->ly_main;
519 }
520
521 static void setting_security_ug_on_start(ui_gadget_h ug, app_control_h service,
522                                          void *priv)
523 {
524 }
525
526 static void setting_security_ug_on_pause(ui_gadget_h ug, app_control_h service,
527                                          void *priv)
528 {
529         SETTING_TRACE_BEGIN;
530         setting_retm_if((!priv), "!priv");
531         SettingSecurityUG *securityUG = priv;
532
533         if (setting_view_security_sim_settings.is_create == TRUE) {
534                 bool is_running = FALSE;
535                 app_manager_is_running("org.tizen.pwlock", &is_running);
536                 if (is_running) {
537                         SETTING_TRACE_DEBUG("pwlock is running");
538                         Ecore_X_Window xwin = 0;
539                         Ecore_X_Display *disp = NULL;
540
541                         disp = ecore_x_display_get();
542                         xwin = elm_win_xwindow_get(securityUG->win_get);
543
544                         ecore_x_netwm_window_type_set(xwin, ECORE_X_WINDOW_TYPE_NORMAL);
545                         int ret;
546                         ret = eext_win_keygrab_unset(xwin, "XF86Back");
547                         if (ret)
548                                 SETTING_TRACE("eext_win_keygrab_unset() failed.");
549                         ret = eext_win_keygrab_unset(xwin, "XF86Home");
550                         if (ret)
551                                 SETTING_TRACE("eext_win_keygrab_unset() failed.");
552                         ret = eext_win_keygrab_unset(xwin, "XF86AudioRaiseVolume");
553                         if (ret)
554                                 SETTING_TRACE("eext_win_keygrab_unset() failed.");
555                         ret = eext_win_keygrab_unset(xwin, "XF86AudioLowerVolume");
556                         if (ret)
557                                 SETTING_TRACE("eext_win_keygrab_unset() failed.");
558
559                         unsigned int val[3];
560                         val[0] = 1;     /* always enable */
561                         val[1] = 1;             /* quickpanel enable */
562                         val[2] = 1;     /* apptray enable */
563                         /* set quickpanel enable */
564                         Ecore_X_Atom ATOM_PANEL_SCROLLABLE_STATE = 0;
565                         ATOM_PANEL_SCROLLABLE_STATE = ecore_x_atom_get("_E_MOVE_PANEL_SCROLLABLE_STATE");
566                         ecore_x_window_prop_card32_set(xwin, ATOM_PANEL_SCROLLABLE_STATE, val, 3);
567                 }
568         }
569 }
570
571 static void setting_security_ug_on_resume(ui_gadget_h ug, app_control_h service,
572                                           void *priv)
573 {
574         SETTING_TRACE_BEGIN;
575         setting_retm_if((!priv), "!priv");
576         SettingSecurityUG *securityUG = priv;
577
578         if (setting_view_security_sim_settings.is_create == TRUE) {
579                 if (tel_get_sim_facility(securityUG->handle, TAPI_SIM_LOCK_SC, setting_security_pin_get_facility_cb, securityUG) != TAPI_API_SUCCESS) {
580                         SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
581                 }
582         }
583 }
584
585 static void setting_security_ug_on_destroy(ui_gadget_h ug, app_control_h service,
586                                            void *priv)
587 {
588         SETTING_TRACE_BEGIN;
589         setting_retm_if((!priv), "!priv");
590         SettingSecurityUG *securityUG = priv;
591         securityUG->ug = ug;
592
593         evas_object_event_callback_del(securityUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_security_ug_cb_resize);       /* fix flash issue for gallery */
594
595         if (securityUG->handle && tel_deinit(securityUG->handle) != TAPI_API_SUCCESS) {
596                 SETTING_TRACE_DEBUG
597                 ("%s*** [ERR] setting_network_unsubscribe_tapi_events. ***%s",
598                  SETTING_FONT_RED, SETTING_FONT_BLACK);
599         }
600
601         FREE(securityUG->input_pwd);
602 #if SUPPORT_ENCRYPTION
603         if (securityUG->viewtype == SETTING_SEC_VIEWTYPE_ENCRYPTION) {
604                 setting_view_destroy(&setting_view_security_confirm_encryption, securityUG);
605                 setting_view_destroy(&setting_view_security_encryption, securityUG);
606         } else {
607 #endif
608                 setting_view_destroy(&setting_view_security_sim_settings, securityUG);
609                 setting_view_destroy(&setting_view_security_update, securityUG);
610                 setting_view_destroy(&setting_view_security_main, securityUG);
611 #if SUPPORT_ENCRYPTION
612                 setting_view_destroy(&setting_view_security_confirm_encryption, securityUG);
613                 setting_view_destroy(&setting_view_security_encryption, securityUG);
614         }
615 #endif
616
617         if (NULL != ug_get_layout(securityUG->ug)) {
618                 evas_object_hide((Evas_Object *) ug_get_layout(securityUG->ug));
619                 evas_object_del((Evas_Object *) ug_get_layout(securityUG->ug));
620         }
621 }
622
623 static void setting_security_ug_on_message(ui_gadget_h ug, app_control_h msg,
624                                            app_control_h service, void *priv)
625 {
626
627 }
628
629 static void setting_security_ug_on_event(ui_gadget_h ug,
630                                          enum ug_event event, app_control_h service,
631                                          void *priv)
632 {
633         if (!priv)
634                 return;
635         SettingSecurityUG *ad = (SettingSecurityUG *) priv;
636
637         switch (event) {
638                 case UG_EVENT_LOW_MEMORY:
639                         break;
640                 case UG_EVENT_LOW_BATTERY:
641                         break;
642                 case UG_EVENT_LANG_CHANGE:
643                         if (ad->navi_bar) {
644                                 setting_navi_items_update(ad->navi_bar);
645                         }
646                         break;
647                 case UG_EVENT_ROTATE_PORTRAIT:
648                         break;
649                 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
650                         break;
651                 case UG_EVENT_ROTATE_LANDSCAPE:
652                         break;
653                 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
654                         break;
655                 case UG_EVENT_REGION_CHANGE:
656                         break;
657                 default:
658                         break;
659         }
660 }
661
662 static void setting_security_ug_on_key_event(ui_gadget_h ug,
663                                              enum ug_key_event event,
664                                              app_control_h service, void *priv)
665 {
666         if (!priv)
667                 return;
668         SettingSecurityUG *ad = (SettingSecurityUG *) priv;     /* ad is point to priv */
669         switch (event) {
670                 case UG_KEY_EVENT_END: {
671                                 if (elm_naviframe_top_item_get(ad->navi_bar) ==
672                                     elm_naviframe_bottom_item_get(ad->navi_bar)) {
673                                         ug_destroy_me(ug);
674                                 } else {
675                                         /* elm_naviframe_item_pop(ad->navi_bar); */
676                                         setting_view_cb_at_endKey(ad);
677                                 }
678                         }
679                         break;
680
681                 default:
682                         break;
683         }
684 }
685
686 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
687 {
688         SettingSecurityUG *securityUG = calloc(1, sizeof(SettingSecurityUG));
689         setting_retvm_if(!securityUG, -1,
690                          "Create SettingSecurityUG obj failed");
691
692         memset(securityUG, 0x00, sizeof(SettingSecurityUG));
693
694         ops->create = setting_security_ug_on_create;
695         ops->start = setting_security_ug_on_start;
696         ops->pause = setting_security_ug_on_pause;
697         ops->resume = setting_security_ug_on_resume;
698         ops->destroy = setting_security_ug_on_destroy;
699         ops->message = setting_security_ug_on_message;
700         ops->event = setting_security_ug_on_event;
701         ops->key_event = setting_security_ug_on_key_event;
702         ops->priv = securityUG;
703         ops->opt = UG_OPT_INDICATOR_ENABLE;
704
705         return 0;
706 }
707
708 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
709 {
710         struct SettingSecurityUG *securityUG;
711         setting_retm_if(!ops, "ops == NULL");
712
713         securityUG = ops->priv;
714         if (securityUG)
715                 FREE(securityUG);
716 }
717
718 /* ***************************************************
719  *
720  *general func
721  *
722  ***************************************************/
723 void setting_security_sim_get_facility_cb(TapiHandle *handle, int result, void *data, void *user_data)
724 {
725         SETTING_TRACE_BEGIN;
726
727         ret_if(!user_data);
728         SETTING_TRACE_DEBUG("user_data is not NULL");
729
730         ret_if(!data);
731         SETTING_TRACE_DEBUG("data is not NULL");
732
733         TelSimPinOperationResult_t sec_rt = result;
734         TelSimFacilityInfo_t *fi = data;
735         SettingSecurityUG *ad = user_data;
736         ad->enter_tapi_async_cb_flag++;
737
738         SETTING_TRACE("sec_rt[%d]", sec_rt);
739         SETTING_TRACE("fi->type[%d]", fi->type);
740         SETTING_TRACE("fi->f_status[%d]", fi->f_status);
741         if (sec_rt == TAPI_SIM_PIN_OPERATION_SUCCESS) {
742                 SETTING_TRACE_DEBUG("PIN_OPERATION_SUCCESS");
743                 switch (fi->type) {
744                         case TAPI_SIM_LOCK_PS:/*sim status */
745                                 ad->sim_status = fi->f_status;
746                                 break;
747                         default:
748                                 break;
749                 }
750         } else {
751                 /*if failed, do nothing.. */
752         }
753
754         /* Update SIM Settings view if created. */
755         if (setting_view_security_sim_settings.is_create == 1) {
756                 SETTING_TRACE_DEBUG("SIM settings view is already created. [%d]", setting_view_security_sim_settings.is_create);
757                 setting_view_update(&setting_view_security_sim_settings, ad);
758         } else {
759                 SETTING_TRACE_DEBUG("Change view");
760                 setting_view_change(&setting_view_security_main, &setting_view_security_sim_settings, ad);
761         }
762
763         SETTING_TRACE_END;
764 }
765
766 void setting_security_pin2_get_lock_info_cb(TapiHandle *handle, int result, void *data, void *user_data)
767 {
768         SETTING_TRACE_BEGIN;
769         ret_if(!user_data);
770         SETTING_TRACE_DEBUG("user_data is not NULL");
771
772         ret_if(!data);
773         SETTING_TRACE_DEBUG("data is not NULL");
774
775         TelSimPinOperationResult_t sec_rt = result;
776         TelSimLockInfo_t *lock = data;
777
778         SettingSecurityUG *ad = (SettingSecurityUG *)user_data;
779
780         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);
781         if (lock->lock_type == TAPI_SIM_LOCK_FD
782             && lock->lock_status == TAPI_SIM_LOCK_KEY_PUK2) {
783                 ad->pin2_blocked_flag = TRUE;
784         }
785 }
786
787 void setting_security_pin_get_facility_cb(TapiHandle *handle, int result, void *data, void *user_data)
788 {
789         SETTING_TRACE_BEGIN;
790
791         ret_if(!user_data);
792         SETTING_TRACE_DEBUG("user_data is not NULL");
793
794         ret_if(!data);
795         SETTING_TRACE_DEBUG("data is not NULL");
796
797         TelSimPinOperationResult_t sec_rt = result;
798         TelSimFacilityInfo_t *fi = data;
799         SettingSecurityUG *ad = user_data;
800
801         SETTING_TRACE("sec_rt[%d]", sec_rt);
802         SETTING_TRACE("fi->type[%d]", fi->type);
803         SETTING_TRACE("fi->f_status[%d]", fi->f_status);
804         if (sec_rt == TAPI_SIM_PIN_OPERATION_SUCCESS) {
805                 SETTING_TRACE_DEBUG("PIN_OPERATION_SUCCESS");
806                 switch (fi->type) {
807                         case TAPI_SIM_LOCK_SC:/*pin1 status */
808                                 ad->pin1_status = fi->f_status;
809                                 break;
810                         case TAPI_SIM_LOCK_FD:/*pin2/fdn status */
811                                 ad->pin2_status = fi->f_status;
812                                 break;
813                         default:
814                                 break;
815                 }
816         } else {
817                 /*if failed, do nothing.. */
818         }
819
820         if (ad->tapi_async_cb_check_timer) {
821                 ecore_timer_del(ad->tapi_async_cb_check_timer);
822                 ad->tapi_async_cb_check_timer = NULL;
823         }
824         ad->enter_tapi_async_cb_flag = 1;
825
826         /* Update SIM Settings view if created. */
827         if (setting_view_security_sim_settings.is_create == 1) {
828                 SETTING_TRACE_DEBUG("SIM settings view is already created. [%d]", setting_view_security_sim_settings.is_create);
829                 setting_view_update(&setting_view_security_sim_settings, ad);
830         } else {
831                 SETTING_TRACE_DEBUG("Change view");
832                 setting_view_change(&setting_view_security_main, &setting_view_security_sim_settings, ad);
833         }
834
835         SETTING_TRACE_END;
836 }
837
838 void setting_security_layout_passwd_ug_cb(ui_gadget_h ug,
839                                           enum ug_mode mode, void *priv)
840 {
841         if (!priv)
842                 return;
843
844         Evas_Object *base = ug_get_layout(ug);
845         if (!base)
846                 return;
847
848         switch (mode) {
849                 case UG_MODE_FULLVIEW:
850                         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
851                         evas_object_show(base);
852                         break;
853                 default:
854                         break;
855         }
856
857         return;
858 }
859
860 void setting_security_destroy_password_ug_cb(ui_gadget_h ug,
861                                              void *priv)
862 {
863         SETTING_TRACE_BEGIN;
864         ret_if(priv == NULL);
865         SettingSecurityUG *ad = (SettingSecurityUG *) priv;
866
867         if (ad->ly_main)
868                 elm_object_tree_focus_allow_set(ad->ly_main, EINA_TRUE);
869
870         if (ug) {
871                 setting_ug_destroy(ug);
872         }
873
874         SETTING_TRACE_DEBUG("[TEST] current : %s", ad->input_pwd);
875 }
876
877 void setting_security_end_password_ug_cb(ui_gadget_h ug,
878                                          void *priv)
879 {
880         SETTING_TRACE_BEGIN;
881         ret_if(priv == NULL);
882         SettingSecurityUG *ad = (SettingSecurityUG *) priv;
883         ad->ug_passwd = NULL;
884
885         if (setting_view_security_sim_settings.is_create == TRUE && ad->pw_type == SETTING_SEC_PW_PIN1_UNBLOCKED) {
886                 SETTING_TRACE("ungrab keys");
887                 /* ungrab keys. */
888                 Ecore_X_Window xwin = 0;
889                 Ecore_X_Display *disp = NULL;
890
891                 int ret = 0;
892
893                 disp = ecore_x_display_get();
894                 xwin = elm_win_xwindow_get((Evas_Object *)ug_get_window());
895
896                 ret = eext_win_keygrab_unset(xwin, "XF86Back");
897                 if (ret)
898                         SETTING_TRACE("KEY_BACK ungrab failed.");
899                 ret = eext_win_keygrab_unset(xwin, "XF86Home");
900                 if (ret)
901                         SETTING_TRACE("XF86Home ungrab failed.");
902                 ret = eext_win_keygrab_unset(xwin, "XF86AudioRaiseVolume");
903                 if (ret)
904                         SETTING_TRACE("KEY_VOLUMEUP ungrab failed.");
905                 ret = eext_win_keygrab_unset(xwin, "XF86AudioLowerVolume");
906                 if (ret)
907                         SETTING_TRACE("KEY_VOLUMEDOWN ungrab failed.");
908         }
909 #if SUPPORT_ENCRYPTION
910         if (setting_view_security_confirm_encryption.is_create == TRUE) {
911                 SETTING_TRACE_DEBUG("[TEST] current : %s", ad->input_pwd);
912                 setting_view_update(&setting_view_security_confirm_encryption, ad);
913         } else if (setting_view_security_encryption.is_create == TRUE) {
914                 SETTING_TRACE_DEBUG("[TEST] current : %s", ad->input_pwd);
915                 setting_view_update(&setting_view_security_encryption, ad);
916         }
917 #endif
918 }
919
920 gboolean setting_security_create_password_sg(void *data)
921 {
922         SETTING_TRACE_BEGIN;
923         /* error check */
924         retv_if(data == NULL, FALSE);
925
926         SettingSecurityUG *ad = (SettingSecurityUG *) data;     /* ad is point to data */
927
928         /* prevent the ug from being loaded again due to window event queuing */
929         /* added by JTS: CQ H0100135346 */
930         if (ad->ug_passwd) {
931                 SETTING_TRACE("Password UG is already loaded.");
932                 return FALSE;
933         }
934
935         if ((ad->pw_type < 0) || (ad->pw_type > SETTING_SEC_PW_MAX))
936                 return FALSE;
937
938         char str[Max_Passwd_View_Type_Len + 1] = { 0, };
939         safeCopyStr(str, security_table[ad->pw_type].pw_type_string, Max_Passwd_View_Type_Len);
940
941         struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
942
943         if (!cbs)
944                 return FALSE;
945         cbs->layout_cb = setting_security_layout_passwd_ug_cb;
946         cbs->result_cb = setting_security_result_password_ug_cb;
947         cbs->destroy_cb = setting_security_destroy_password_ug_cb;
948         cbs->end_cb = setting_security_end_password_ug_cb;
949         cbs->priv = (void *)ad;
950
951         app_control_h svc;
952         if (app_control_create(&svc)) {
953                 FREE(cbs);
954                 return FALSE;
955         }
956
957         app_control_add_extra_data(svc, "viewtype", str);
958
959         SETTING_TRACE_DEBUG("send viewtype to password : %s", str);
960
961         if ((ad->pw_type != SETTING_SEC_PW_ENTER_LOCK_TYPE) && ad->input_pwd) {
962                 SETTING_TRACE_SECURE_DEBUG("Send current : %s", ad->input_pwd);
963                 app_control_add_extra_data(svc, "current", ad->input_pwd);
964         }
965
966         if (ad->ly_main)
967                 elm_object_tree_focus_allow_set(ad->ly_main, EINA_FALSE);
968         ad->ug_removed = FALSE;
969         ad->ug_passwd = setting_ug_create(ad->ug, "setting-password-efl", UG_MODE_FULLVIEW, svc, cbs);
970         if (NULL == ad->ug_passwd) {    /* error handling */
971                 evas_object_show(ad->ly_main);
972         }
973
974         app_control_destroy(svc);
975         FREE(cbs);
976
977         return TRUE;
978 }
979
980 void setting_security_layout_lockscreen_options_ug_cb(ui_gadget_h ug,
981                                                       enum ug_mode mode, void *priv)
982 {
983         if (!priv)
984                 return;
985
986         Evas_Object *base = ug_get_layout(ug);
987         if (!base)
988                 return;
989
990         switch (mode) {
991                 case UG_MODE_FULLVIEW:
992                         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
993                                                          EVAS_HINT_EXPAND);
994                         evas_object_show(base);
995                         break;
996                 default:
997                         break;
998         }
999
1000         return;
1001 }
1002
1003 void setting_security_destroy_lockscreen_options_ug_cb(ui_gadget_h ug,
1004                                                        void *priv)
1005 {
1006         ret_if(priv == NULL);
1007         SettingSecurityUG *ad = (SettingSecurityUG *) priv;
1008         if (ug) {
1009                 setting_ug_destroy(ug);
1010                 ad->ug_lockscreen = NULL;
1011         }
1012 }
1013
1014 gboolean setting_security_create_lockscreen_options_sg(void *data)
1015 {
1016         /* error check */
1017         retv_if(data == NULL, FALSE);
1018
1019         SettingSecurityUG *ad = (SettingSecurityUG *) data;     /* ad is point to data */
1020
1021         if (ad->ug_lockscreen) {
1022                 SETTING_TRACE("Password UG is already loaded.");
1023                 return FALSE;
1024         }
1025         struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
1026
1027         if (!cbs)
1028                 return FALSE;
1029         cbs->layout_cb = setting_security_layout_lockscreen_options_ug_cb;
1030         cbs->result_cb = NULL;
1031         cbs->destroy_cb = setting_security_destroy_lockscreen_options_ug_cb;
1032         cbs->priv = (void *)ad;
1033
1034         if (ad->ly_main)
1035                 elm_object_tree_focus_allow_set(ad->ly_main, EINA_FALSE);
1036         ad->ug_lockscreen = setting_ug_create(ad->ug, "lockscreen-options", UG_MODE_FULLVIEW, NULL, cbs);
1037         if (NULL == ad->ug_lockscreen) {        /* error handling */
1038                 SETTING_TRACE_ERROR("NULL == ad->ug_lockscreen");
1039                 evas_object_show(ad->ly_main);
1040         }
1041
1042         FREE(cbs);
1043
1044         return TRUE;
1045 }
1046 #if SUPPORT_ENCRYPTION
1047 void setting_security_layout_mmc_encryption_ug_cb(ui_gadget_h ug,
1048                                                   enum ug_mode mode, void *priv)
1049 {
1050         if (!priv)
1051                 return;
1052
1053         Evas_Object *base = ug_get_layout(ug);
1054         if (!base)
1055                 return;
1056
1057         switch (mode) {
1058                 case UG_MODE_FULLVIEW:
1059                         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
1060                                                          EVAS_HINT_EXPAND);
1061                         evas_object_show(base);
1062                         break;
1063                 default:
1064                         break;
1065         }
1066
1067         return;
1068 }
1069
1070 void setting_security_destroy_mmc_encryption_ug_cb(ui_gadget_h ug,
1071                                                    void *priv)
1072 {
1073         ret_if(priv == NULL);
1074         SettingSecurityUG *ad = (SettingSecurityUG *) priv;
1075         if (ug) {
1076                 setting_ug_destroy(ug);
1077                 ad->ug_mmc_encryption = NULL;
1078         }
1079
1080 }
1081
1082 gboolean setting_security_create_mmc_encryption_sg(void *data)
1083 {
1084         /* error check */
1085         retv_if(data == NULL, FALSE);
1086
1087         SettingSecurityUG *ad = (SettingSecurityUG *) data;     /* ad is point to data */
1088
1089         if (ad->ug_mmc_encryption) {
1090                 SETTING_TRACE("mmc encryption UG is already loaded.");
1091                 return FALSE;
1092         }
1093         struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
1094
1095         if (!cbs)
1096                 return FALSE;
1097         cbs->layout_cb = setting_security_layout_mmc_encryption_ug_cb;
1098         cbs->result_cb = NULL;
1099         cbs->destroy_cb = setting_security_destroy_mmc_encryption_ug_cb;
1100         cbs->priv = (void *)ad;
1101
1102         if (ad->ly_main)
1103                 elm_object_tree_focus_allow_set(ad->ly_main, EINA_FALSE);
1104         ad->ug_mmc_encryption = setting_ug_create(ad->ug, "setting-mmc-encryption-efl", UG_MODE_FULLVIEW, NULL, cbs);
1105         if (NULL == ad->ug_mmc_encryption) {    /* error handling */
1106                 SETTING_TRACE_ERROR("NULL == ad->ug_mmc_encryption");
1107                 evas_object_show(ad->ly_main);
1108         }
1109
1110         FREE(cbs);
1111
1112         return TRUE;
1113 }
1114 #endif
1115
1116 void setting_security_layout_firewall_ug_cb(ui_gadget_h ug,
1117                                             enum ug_mode mode, void *priv)
1118 {
1119         Evas_Object *base = ug_get_layout(ug);
1120         if (!base)
1121                 return;
1122
1123         switch (mode) {
1124                 case UG_MODE_FULLVIEW:
1125                         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
1126                                                          EVAS_HINT_EXPAND);
1127                         /*elm_win_resize_object_add(ad->win_get, base); */
1128                         evas_object_show(base);
1129                         break;
1130                 default:
1131                         break;
1132         }
1133
1134         return;
1135 }
1136
1137 void setting_security_destroy_firewall_ug_cb(ui_gadget_h ug,
1138                                              void *priv)
1139 {
1140         ret_if(priv == NULL);
1141         SettingSecurityUG *ad = (SettingSecurityUG *) priv;
1142
1143         elm_object_tree_focus_allow_set(ad->ly_main, EINA_TRUE);
1144         if (ug) {
1145                 setting_ug_destroy(ug);
1146                 ad->ug_firewall = NULL;
1147         }
1148 }
1149
1150 gboolean setting_security_create_firewall_sg(void *data)
1151 {
1152         retv_if(data == NULL, FALSE);
1153
1154         SettingSecurityUG *ad = (SettingSecurityUG *) data;
1155         if (ad->ug_firewall) {
1156                 SETTING_TRACE("firewall UG is already loaded.");
1157                 return FALSE;
1158         }
1159         struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
1160
1161         if (!cbs)
1162                 return FALSE;
1163         cbs->layout_cb = setting_security_layout_firewall_ug_cb;
1164         cbs->result_cb = NULL;
1165         cbs->destroy_cb = setting_security_destroy_firewall_ug_cb;
1166         cbs->priv = (void *)ad;
1167
1168         if (ad->ly_main)
1169                 elm_object_tree_focus_allow_set(ad->ly_main, EINA_FALSE);
1170         ad->ug_firewall = setting_ug_create(ad->ug, "setting-firewall-efl", UG_MODE_FULLVIEW, NULL, cbs);
1171         if (NULL == ad->ug_firewall) {
1172                 SETTING_TRACE_ERROR("NULL == ad->ug_firewall");
1173                 evas_object_show(ad->ly_main);
1174         }
1175
1176         FREE(cbs);
1177         return TRUE;
1178 }
1179
1180
1181 /* ***************************************************
1182  *
1183  *call back func
1184  *
1185  ***************************************************/
1186 /* -1   on fail */
1187 /* 0~n  on success */
1188 int _get_security_table_index(char *name)
1189 {
1190         int i = 0;
1191
1192         for (i = 0; i < SETTING_SEC_PW_MAX; i++) {
1193                 if (0 == safeStrCmp(name, security_table[i].pw_type_string))
1194                         return i;
1195         }
1196         return -1;
1197 }
1198
1199 void
1200 setting_security_result_password_ug_cb(ui_gadget_h ug, app_control_h service,
1201                                        void *priv)
1202 {
1203         SETTING_TRACE_BEGIN;
1204         /* error check */
1205         retm_if(priv == NULL, "Data paremeter is NULL");
1206
1207         SettingSecurityUG *ad = (SettingSecurityUG *) priv;     /* ad is point to priv */
1208
1209         if (ad->ly_main)
1210                 elm_object_tree_focus_allow_set(ad->ly_main, EINA_TRUE);
1211
1212         char *result = NULL;
1213         char *current = NULL;
1214
1215         app_control_get_extra_data(service, "result", &result);
1216         app_control_get_extra_data(service, "current", &current);
1217
1218         /* divided pw view type */
1219         SETTING_TRACE("ad->pw_type: %d result :%s", ad->pw_type, result);
1220         ret_if(NULL == result);
1221
1222         if (safeStrCmp(result, "Cancel") == 0) {
1223                 ad->pw_type = -1;
1224                 if (setting_view_security_sim_settings.is_create == 1) {
1225                         setting_view_update(&setting_view_security_sim_settings, ad);
1226                 }
1227                 FREE(result);
1228                 return;
1229                 /* To do : rollback previouse status. */
1230         } else if (safeStrCmp(result, "SETTING_PW_TYPE_ENTER_LOCK_TYPE") == 0) {
1231                 /*ug_destroy(ug); */
1232                 /*ad->ug_passwd = NULL; */
1233                 /*setting_view_update(&setting_view_security_locktype, ad); */
1234                 ad->pw_type = SETTING_SEC_PW_ENTER_LOCK_TYPE;
1235         } else if (safeStrCmp(result, "SETTING_PW_TYPE_ENTER_LOCK_TYPE:Fail") == 0) {
1236                 ad->pw_type = -1;
1237                 ug_destroy_me(ad->ug);
1238                 FREE(result);
1239                 if (current)
1240                         FREE(current);
1241                 return;
1242         } else {
1243                 int index =  _get_security_table_index(result);
1244
1245                 if (index != -1) {
1246                         security_table[index].passwd_handler(ad, NULL);
1247                         ad->pw_type = security_table[index].pw_type_num;
1248                 } else {
1249                         SETTING_TRACE_ERROR("no table entry");
1250                 }
1251                 if (ad->input_pwd)
1252                         FREE(ad->input_pwd);
1253         }
1254
1255         if (current) {
1256                 SETTING_TRACE_SECURE_DEBUG("current : %s", current);
1257                 ad->input_pwd = (char *)strdup(current);
1258                 FREE(current);
1259         }
1260
1261         evas_object_show(ad->ly_main);
1262         FREE(result);
1263         SETTING_TRACE_END;
1264 }
1265
1266 #ifdef Status
1267 #undef Status
1268 #endif
1269
1270 static Setting_Cfg_Node_T s_cfg_node_array[] = {
1271         {"IDS_JAVA_OPT_SIM_SETTINGS", NULL, "viewtype:frontpage;tab:first;keyword:IDS_JAVA_OPT_SIM_SETTINGS", 0, 0, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
1272         {"IDS_ST_BODY_DECRYPT_DEVICE", NULL, "viewtype:frontpage;tab:first;keyword:IDS_ST_BODY_DECRYPT_DEVICE", 0, 0, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
1273         {"IDS_ST_HEADER_ENCRYPT_DEVICE", NULL, "viewtype:frontpage;tab:first;keyword:IDS_ST_HEADER_ENCRYPT_DEVICE", 0, 0, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
1274         {"IDS_DN_BODY_ENCRYPT_SD_CARD", NULL, "viewtype:frontpage;tab:first;keyword:IDS_DN_BODY_ENCRYPT_SD_CARD", 0, 0, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
1275         {"IDS_ST_BODY_FIREWALL", NULL, "viewtype:frontpage;tab:first;keyword:IDS_ST_BODY_FIREWALL", 0, 0, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
1276         {"IDS_ST_BODY_ANTIVIRUS_SOFTWARE_ABB", NULL, "viewtype:frontpage;tab:first;keyword:IDS_ST_BODY_ANTIVIRUS_SOFTWARE_ABB", 0, 0, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
1277         {"IDS_EMAIL_POP_SECURITY_UPDATE_ABB", NULL, "viewtype:frontpage;tab:first;keyword:IDS_EMAIL_POP_SECURITY_UPDATE_ABB", 0, 0, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
1278 };
1279
1280 UG_MODULE_API int setting_plugin_search_init(app_control_h service, void *priv, char **applocale)
1281 {
1282         SETTING_TRACE_BEGIN;
1283         SETTING_TRACE(">> setting-security-efl DB search code");
1284
1285         *applocale = strdup("setting:/usr/apps/org.tizen.setting/res/locale");
1286
1287         Eina_List **pplist = (Eina_List **)priv;
1288         int i;
1289         int size = sizeof(s_cfg_node_array) / sizeof(s_cfg_node_array[0]);
1290         for (i = 0; i < size; i++) {
1291                 Setting_Cfg_Node_T *node = setting_plugin_search_item_subindex_add(s_cfg_node_array[i].key_name, s_cfg_node_array[i].ug_args, IMG_Security, s_cfg_node_array[i].item_type, s_cfg_node_array[i].data, "Security");
1292                 *pplist = eina_list_append(*pplist, node);
1293         }
1294         return 0;
1295 }
1296
1297 #if SUPPORT_SECURITY_FIREWALL
1298 int setting_security_system_command(const char *command, const char *commandex)
1299 {
1300         SETTING_TRACE_BEGIN;
1301         int pid = 0 , status = 0;
1302         char *argv[2] = {NULL,};
1303         /*int ret; */
1304
1305         if (command == 0 && commandex == 0) {
1306                 /*not exist input */
1307         }
1308
1309         pid = fork();
1310
1311         if (pid > 0) {
1312                 SETTING_TRACE("parent");
1313                 wait(&status);
1314                 return WEXITSTATUS(status);
1315         }
1316
1317         if (pid == 0) {
1318                 char *args[100] = {
1319                         argv[0] = (char *)command,
1320                         argv[1] = (char *)commandex,
1321                         NULL,
1322                 };
1323
1324                 SETTING_TRACE_DEBUG("[%s]:%s", argv[0], argv[1]);
1325                 execv("/usr/apps/org.tizen.setting/bin/firewall", args);
1326         }
1327         return 1;
1328 }
1329
1330 int setting_security_firewall_reset()
1331 {
1332         SETTING_TRACE_BEGIN;
1333
1334         struct dirent *next_file;
1335         DIR *theFolder;
1336
1337         char filepath[256];
1338
1339         theFolder = opendir(SEC_FIREWALL_DIR);
1340         next_file = readdir(theFolder);
1341         while (next_file) {
1342                 /* build the full path for each file in the folder */
1343                 sprintf(filepath, "%s/%s", SEC_FIREWALL_DIR, next_file->d_name);
1344                 SETTING_TRACE_DEBUG("[%s]", filepath);
1345                 /*(void) remove(filepath); */
1346                 if (remove(filepath) != 0) { /*delete the file */
1347                         perror("remove");
1348                 }
1349                 next_file = readdir(theFolder);
1350         }
1351
1352         closedir(theFolder);
1353         return 0;
1354 }
1355 #endif
1356