[security,password] remove unused code
[apps/core/preloaded/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 /**
23  *@defgroup setting-security
24  *UG creation code for setting-security
25  */
26
27 #include <setting-security.h>
28 #define Max_Passwd_View_Type_Len        64
29 #ifndef UG_MODULE_API
30 #define UG_MODULE_API __attribute__ ((visibility("default")))
31 #endif
32
33
34 int pwd_handler_do_nothing(SettingSecurityUG *data, void* arg)
35 {
36         SETTING_TRACE_BEGIN;
37         //SettingSecurityUG *ad = (SettingSecurityUG *)data;
38         // DO NOTHING
39         return 0;
40 }
41
42 int pwd_handler_sec_pw_sim_lock_on(SettingSecurityUG *data, void* arg)
43 {
44         SETTING_TRACE_BEGIN;
45         SettingSecurityUG *ad = (SettingSecurityUG *)data;
46         if (tel_get_sim_facility(ad->handle, TAPI_SIM_LOCK_PS, setting_security_sim_get_facility_cb, ad) != TAPI_API_SUCCESS)
47         {
48                 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
49         }
50         return 0;
51 }
52
53
54 int pwd_handler_sec_pw_sim_lock_off(SettingSecurityUG *data, void* arg)
55 {
56         SETTING_TRACE_BEGIN;
57         SettingSecurityUG *ad = (SettingSecurityUG *)data;
58         if (tel_get_sim_facility(ad->handle, TAPI_SIM_LOCK_PS, setting_security_sim_get_facility_cb, ad) != TAPI_API_SUCCESS)
59         {
60                 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
61         }
62         return 0;
63 }
64
65
66 int pwd_handler_sec_pw_pin_lock_on(SettingSecurityUG *data, void* arg)
67 {
68         SETTING_TRACE_BEGIN;
69         SettingSecurityUG *ad = (SettingSecurityUG *)data;
70         if (tel_get_sim_facility(ad->handle, TAPI_SIM_LOCK_SC, setting_security_sim_get_facility_cb, ad) != TAPI_API_SUCCESS)
71         {
72                 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
73         }
74         return 0;
75 }
76
77
78 int pwd_handler_sec_pw_pin_lock_off(SettingSecurityUG *data, void* arg)
79 {
80         SETTING_TRACE_BEGIN;
81         SettingSecurityUG *ad = (SettingSecurityUG *)data;
82         if (tel_get_sim_facility(ad->handle, TAPI_SIM_LOCK_SC, setting_security_sim_get_facility_cb, ad) != TAPI_API_SUCCESS)
83         {
84                 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
85         }
86         return 0;
87 }
88
89
90 int pwd_handler_sec_pw_sim_lock_disabled(SettingSecurityUG *data, void* arg)
91 {
92         SETTING_TRACE_BEGIN;
93         SettingSecurityUG *ad = (SettingSecurityUG *)data;
94         // [in] Evas_Object *checkbtn
95         if (ad->data_sim_lk)
96                 setting_disable_genlist_item(ad->data_sim_lk->item);
97
98         return 0;
99 }
100
101
102 int pwd_handler_sec_pw_change_pin1(SettingSecurityUG *data, void* arg)
103 {
104         SETTING_TRACE_BEGIN;
105         SettingSecurityUG *ad = (SettingSecurityUG *)data;
106         if (tel_get_sim_facility(ad->handle, TAPI_SIM_LOCK_SC, setting_security_sim_get_facility_cb, ad) != TAPI_API_SUCCESS)
107         {
108                 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
109         }
110         return 0;
111 }
112
113 int pwd_handler_sec_pw_change_pin2(SettingSecurityUG *data, void* arg)
114 {
115         SETTING_TRACE_BEGIN;
116         SettingSecurityUG *ad = (SettingSecurityUG *)data;
117
118         if (tel_get_sim_facility(ad->handle, TAPI_SIM_LOCK_FD, setting_security_sim_get_facility_cb, ad) != TAPI_API_SUCCESS)
119         {
120                 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
121         }
122         return 0;
123 }
124
125
126 int pwd_handler_sec_pw_pin1_blocked(SettingSecurityUG *data, void* arg)
127 {
128         SETTING_TRACE_BEGIN;
129         SettingSecurityUG *ad = (SettingSecurityUG *)data;
130         return 0;
131 }
132
133
134 int pwd_handler_sec_pw_pin2_blocked(SettingSecurityUG *data, void* arg)
135 {
136         SETTING_TRACE_BEGIN;
137         SettingSecurityUG *ad = (SettingSecurityUG *)data;
138         return 0;
139 }
140
141 static struct _security_item security_table[] = {
142         { SETTING_SEC_PW_SIM_LOCK_ON,           "SETTING_PW_TYPE_SIM_LOCK_ON",                  pwd_handler_sec_pw_sim_lock_on },
143         { SETTING_SEC_PW_SIM_LOCK_OFF,          "SETTING_PW_TYPE_SIM_LOCK_OFF",                 pwd_handler_sec_pw_sim_lock_off },
144         { SETTING_SEC_PW_SIM_LOCK_DISABLED, "SETTING_PW_TYPE_SIM_LOCK_DISABLE",         pwd_handler_sec_pw_sim_lock_disabled},
145         { SETTING_SEC_PW_PIN_LOCK_ON,           "SETTING_PW_TYPE_PIN_LOCK_ON",                  pwd_handler_sec_pw_pin_lock_on },
146         { SETTING_SEC_PW_PIN_LOCK_OFF,          "SETTING_PW_TYPE_PIN_LOCK_OFF",                 pwd_handler_sec_pw_pin_lock_off },
147         { SETTING_SEC_PW_CHANGE_PIN1,           "SETTING_PW_TYPE_CHANGE_PIN1",                  pwd_handler_sec_pw_change_pin1},
148         { SETTING_SEC_PW_CHANGE_PIN2,           "SETTING_PW_TYPE_CHANGE_PIN2",                  pwd_handler_sec_pw_change_pin2},
149         { SETTING_SEC_PW_PIN1_BLOCKED,          "SETTING_PW_TYPE_PIN1_BLOCKED",                 pwd_handler_sec_pw_pin1_blocked},
150         { SETTING_SEC_PW_PIN2_BLOCKED,          "SETTING_PW_TYPE_PIN2_BLOCKED",                 pwd_handler_do_nothing},
151         { SETTING_SEC_PW_PIN1_UNBLOCKED,                "SETTING_PW_TYPE_PIN1_UNBLOCKED",               pwd_handler_sec_pw_pin_lock_on},
152         { SETTING_SEC_PW_PIN2_UNBLOCKED,                "SETTING_PW_TYPE_PIN2_UNBLOCKED",               pwd_handler_do_nothing},
153         /*------------------------------------------------------------------------------------------------------------*/
154         { SETTING_SEC_PW_MAX,                           NULL,                                                                   pwd_handler_do_nothing}
155 };
156
157 static void setting_security_ug_cb_resize(void *data, Evas *e,
158                                           Evas_Object *obj, void *event_info)
159 {
160         ret_if(data == NULL);
161
162         SettingSecurityUG *ad = (SettingSecurityUG *) data;     /* ad is point to data */
163         setting_view_update(&setting_view_security_main, ad);
164 }
165
166 static void *setting_security_ug_on_create(ui_gadget_h ug,
167                                            enum ug_mode mode, service_h service,
168                                            void *priv)
169 {
170         setting_retvm_if((!priv), NULL, "!priv");
171
172         SettingSecurityUG *securityUG = priv;
173         securityUG->ug = ug;
174
175         securityUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
176         securityUG->win_get = (Evas_Object *) ug_get_window();
177         evas_object_show(securityUG->win_main_layout);
178         securityUG->evas = evas_object_evas_get(securityUG->win_main_layout);
179
180         setting_retvm_if(securityUG->win_main_layout == NULL, NULL,
181                          "[Setting >> About] cannot get main window ");
182
183         /* register view node table */
184         setting_view_node_table_intialize();
185         setting_view_node_table_register(&setting_view_security_main, NULL);
186         setting_view_node_table_register(&setting_view_security_sim_settings, &setting_view_security_main);
187
188         setting_create_Gendial_itc("dialogue/1text", &(securityUG->itc_1text));
189         setting_create_Gendial_itc("dialogue/2text.3", &(securityUG->itc_2text_2));
190         setting_create_Gendial_itc("dialogue/1text.1icon", &(securityUG->itc_1text_1icon));
191
192         securityUG->itc_seperator.item_style = "dialogue/separator/21/with_line";
193         securityUG->itc_seperator.func.text_get = NULL;
194         securityUG->itc_seperator.func.content_get = NULL;
195         securityUG->itc_seperator.func.state_get = NULL;
196         securityUG->itc_seperator.func.del = NULL;
197
198         securityUG->update_view_timer = NULL;
199         /*  creating a view. */
200         securityUG->handle =  tel_init(NULL);
201         if (!securityUG->handle) {
202                 SETTING_TRACE_ERROR("*** [ERR] tel_init. ***");
203                 //return NULL;
204         }
205         else {
206                 if (TAPI_API_SUCCESS != tel_get_sim_facility(securityUG->handle, TAPI_SIM_LOCK_PS, setting_security_sim_get_facility_cb, securityUG)) {
207                         SETTING_TRACE_ERROR("*** [ERR] tel_get_sim_facility(sim_status). ***");
208                 }
209
210                 if (TAPI_API_SUCCESS != tel_get_sim_facility(securityUG->handle, TAPI_SIM_LOCK_SC, setting_security_sim_get_facility_cb, securityUG)) {
211                         SETTING_TRACE_ERROR("*** [ERR] tel_get_sim_facility(pin1). ***");
212                 }
213                 if (TAPI_API_SUCCESS != tel_get_sim_facility(securityUG->handle, TAPI_SIM_LOCK_FD, setting_security_sim_get_facility_cb, securityUG)) {
214                         SETTING_TRACE_ERROR("*** [ERR] tel_get_sim_facility(pin2). ***");
215                 }
216         }
217
218         setting_view_node_set_cur_view(&setting_view_security_main);
219         setting_view_create(&setting_view_security_main, (void *)securityUG);
220         evas_object_event_callback_add(securityUG->win_main_layout,
221                                        EVAS_CALLBACK_RESIZE,
222                                        setting_security_ug_cb_resize,
223                                        securityUG);
224
225         return securityUG->ly_main;
226 }
227
228 static void setting_security_ug_on_start(ui_gadget_h ug, service_h service,
229                                          void *priv)
230 {
231 }
232
233 static void setting_security_ug_on_pause(ui_gadget_h ug, service_h service,
234                                          void *priv)
235 {
236 }
237
238 static void setting_security_ug_on_resume(ui_gadget_h ug, service_h service,
239                                           void *priv)
240 {
241 }
242
243 static void setting_security_ug_on_destroy(ui_gadget_h ug, service_h service,
244                                            void *priv)
245 {
246         setting_retm_if((!priv), "!priv");
247         SettingSecurityUG *securityUG = priv;
248
249         evas_object_event_callback_del(securityUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_security_ug_cb_resize);       /* fix flash issue for gallery */
250         securityUG->ug = ug;
251         if (securityUG->handle && tel_deinit(securityUG->handle) != TAPI_API_SUCCESS) {
252                 SETTING_TRACE_DEBUG
253                     ("%s*** [ERR] setting_network_unsubscribe_tapi_events. ***%s",
254                      SETTING_FONT_RED, SETTING_FONT_BLACK);
255         }
256
257         /*  delete the allocated objects. */
258         if (TRUE == setting_view_security_sim_settings.is_create) {
259                 setting_view_destroy(&setting_view_security_sim_settings, securityUG);
260         }
261         if (TRUE == setting_view_security_main.is_create) {
262                 setting_view_destroy(&setting_view_security_main, securityUG);
263         }
264
265         if (NULL != ug_get_layout(securityUG->ug)) {
266                 evas_object_hide((Evas_Object *) ug_get_layout(securityUG->ug));
267                 evas_object_del((Evas_Object *) ug_get_layout(securityUG->ug));
268         }
269 }
270
271 static void setting_security_ug_on_message(ui_gadget_h ug, service_h msg,
272                                            service_h service, void *priv)
273 {
274
275 }
276
277 static void setting_security_ug_on_event(ui_gadget_h ug,
278                                          enum ug_event event, service_h service,
279                                          void *priv)
280 {
281         switch (event) {
282         case UG_EVENT_LOW_MEMORY:
283                 break;
284         case UG_EVENT_LOW_BATTERY:
285                 break;
286         case UG_EVENT_LANG_CHANGE:
287                 break;
288         case UG_EVENT_ROTATE_PORTRAIT:
289                 break;
290         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
291                 break;
292         case UG_EVENT_ROTATE_LANDSCAPE:
293                 break;
294         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
295                 break;
296         case UG_EVENT_REGION_CHANGE:
297                 break;
298         default:
299                 break;
300         }
301 }
302
303 static void setting_security_ug_on_key_event(ui_gadget_h ug,
304                                              enum ug_key_event event,
305                                              service_h service, void *priv)
306 {
307         if (!priv)
308                 return;
309         SettingSecurityUG *ad = (SettingSecurityUG *) priv;     /* ad is point to priv */
310         switch (event) {
311         case UG_KEY_EVENT_END:
312                 {
313                         if (elm_naviframe_top_item_get(ad->navi_bar) ==
314                            elm_naviframe_bottom_item_get(ad->navi_bar)) {
315                                 ug_destroy_me(ug);
316                         } else {
317                                 /* elm_naviframe_item_pop(ad->navi_bar); */
318                                 setting_view_cb_at_endKey(ad);
319                         }
320                 }
321                 break;
322
323         default:
324                 break;
325         }
326 }
327
328 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
329 {
330         SettingSecurityUG *securityUG = calloc(1, sizeof(SettingSecurityUG));
331         setting_retvm_if(!securityUG, -1,
332                          "Create SettingSecurityUG obj failed");
333
334         ops->create = setting_security_ug_on_create;
335         ops->start = setting_security_ug_on_start;
336         ops->pause = setting_security_ug_on_pause;
337         ops->resume = setting_security_ug_on_resume;
338         ops->destroy = setting_security_ug_on_destroy;
339         ops->message = setting_security_ug_on_message;
340         ops->event = setting_security_ug_on_event;
341         ops->key_event = setting_security_ug_on_key_event;
342         ops->priv = securityUG;
343         ops->opt = UG_OPT_INDICATOR_ENABLE;
344
345         return 0;
346 }
347
348 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
349 {
350         struct SettingSecurityUG *securityUG;
351         setting_retm_if(!ops, "ops == NULL");
352
353         securityUG = ops->priv;
354         if (securityUG)
355                 FREE(securityUG);
356 }
357
358 /* ***************************************************
359  *
360  *general func
361  *
362  ***************************************************/
363 void setting_security_sim_get_facility_cb(TapiHandle *handle, int result, void *data, void *user_data)
364 {
365         SETTING_TRACE_BEGIN;
366         ret_if(!data || !user_data);
367         TelSimPinOperationResult_t sec_rt = result;
368         TelSimFacilityInfo_t *fi = data;
369         SettingSecurityUG *ad = user_data;
370
371         SETTING_TRACE("sec_rt[%d]", sec_rt);
372         SETTING_TRACE("fi->type[%d]", fi->type);
373         SETTING_TRACE("fi->f_status[%d]", fi->f_status);
374         if (sec_rt == TAPI_SIM_PIN_OPERATION_SUCCESS)
375         {
376                 SETTING_TRACE_DEBUG("PIN_OPERATION_SUCCESS");
377                 switch (fi->type)
378                 {
379                     case TAPI_SIM_LOCK_PS://sim status
380                         ad->sim_status = fi->f_status;
381                         break;
382                     case TAPI_SIM_LOCK_SC://pin1 status
383                         ad->pin1_status = fi->f_status;
384                         break;
385                     case TAPI_SIM_LOCK_FD://pin2/fdn status
386                         ad->pin2_status = fi->f_status;
387                         break;
388                     default:
389                         break;
390                 }
391         }
392         else
393         {
394                 //if failed, do nothing..
395         }
396
397         /* Update SIM Settings view if created. */
398         if(setting_view_security_sim_settings.is_create == 1)
399         {
400                 SETTING_TRACE_DEBUG("SIM settings view is already created. [%d]", setting_view_security_sim_settings.is_create);
401                 setting_view_update(&setting_view_security_sim_settings, ad);
402         }
403         SETTING_TRACE_END;
404 }
405
406 void setting_security_layout_passwd_ug_cb(ui_gadget_h ug,
407                                                  enum ug_mode mode, void *priv)
408 {
409         if (!priv)
410                 return;
411
412         SettingSecurityUG *ad = (SettingSecurityUG *) priv;
413         Evas_Object *base = ug_get_layout(ug);
414         if (!base)
415                 return;
416
417         switch (mode) {
418         case UG_MODE_FULLVIEW:
419                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
420                                                  EVAS_HINT_EXPAND);
421                 elm_win_resize_object_add(ad->win_get, base);
422                 evas_object_show(base);
423                 break;
424         default:
425                 break;
426         }
427
428         return;
429 }
430
431 void setting_security_destroy_password_ug_cb(ui_gadget_h ug,
432                                                     void *priv)
433 {
434         SETTING_TRACE_BEGIN;
435         ret_if(priv == NULL);
436         SettingSecurityUG *ad = (SettingSecurityUG *) priv;
437         if (ug) {
438                 ug_destroy(ug);
439                 ad->ug_passwd = NULL;
440         }
441 }
442
443 gboolean setting_security_create_password_sg(void *data)
444 {
445         SETTING_TRACE_BEGIN;
446         /* error check */
447         retv_if(data == NULL, FALSE);
448
449         SettingSecurityUG *ad = (SettingSecurityUG *) data;     /* ad is point to data */
450
451         /* prevent the ug from being loaded again due to window event queuing */
452         /* added by JTS: CQ H0100135346 */
453         if (ad->ug_passwd) {
454                 SETTING_TRACE("Password UG is already loaded.");
455                 return FALSE;
456         }
457
458         if((ad->pw_type < 0) || (ad->pw_type > SETTING_SEC_PW_MAX))
459                 return FALSE;
460
461         char str[Max_Passwd_View_Type_Len + 1] = { 0, };
462         safeCopyStr(str, security_table[ad->pw_type].pw_type_string, Max_Passwd_View_Type_Len);
463
464         struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
465
466         if (!cbs)
467                 return FALSE;
468         cbs->layout_cb = setting_security_layout_passwd_ug_cb;
469         cbs->result_cb = setting_security_result_password_ug_cb;
470         cbs->destroy_cb = setting_security_destroy_password_ug_cb;
471         cbs->priv = (void *)ad;
472
473         service_h svc;
474         if (service_create(&svc)) {
475                 FREE(cbs);
476                 return FALSE;
477         }
478
479         service_add_extra_data(svc, "viewtype", str);
480         if(ad->input_pwd)
481         {
482                 SETTING_TRACE_DEBUG("Send current : %s", ad->input_pwd);
483                 service_add_extra_data(svc, "current", ad->input_pwd);
484         }
485         ad->ug_passwd = ug_create(ad->ug, "setting-password-efl", UG_MODE_FULLVIEW, svc, cbs);
486         if (NULL == ad->ug_passwd) {    /* error handling */
487                 evas_object_show(ad->ly_main);
488         }
489
490         service_destroy(svc);
491         FREE(cbs);
492
493         return TRUE;
494 }
495
496 /* ***************************************************
497  *
498  *call back func
499  *
500  ***************************************************/
501 // -1   on fail
502 // 0~n  on success
503 int _get_security_table_index(char* name)
504 {
505         int i=0;
506
507         for(i=0;i<SETTING_SEC_PW_MAX;i++)
508         {
509                 if (0 == safeStrCmp(name, security_table[i].pw_type_string))
510                         return i;
511         }
512         return -1;
513 }
514
515 void
516 setting_security_result_password_ug_cb(ui_gadget_h ug, service_h service,
517                                        void *priv)
518 {
519         SETTING_TRACE_BEGIN;
520         /* error check */
521         retm_if(priv == NULL, "Data paremeter is NULL");
522
523         SettingSecurityUG *ad = (SettingSecurityUG *) priv;     /* ad is point to priv */
524
525         char *result = NULL;
526         char *current = NULL;
527
528         service_get_extra_data(service, "result", &result);
529         service_get_extra_data(service, "current", &current);
530
531         /* divided pw view type */
532         SETTING_TRACE("ad->pw_type: %d result :%s", ad->pw_type, result);
533         ret_if(NULL == result);
534
535         if(safeStrCmp(result, "Cancel") == 0)
536         {
537                 /* To do : rollback previouse status. */
538         }
539         else
540         {
541                 int index =  _get_security_table_index(result);
542                 int ret;
543                 if (index != -1)
544                 {
545                         ret = security_table[index].passwd_handler(ad, NULL);
546                 } else {
547                         SETTING_TRACE_ERROR("no table entry");
548                 }
549                 if(ad->input_pwd)
550                         FREE(ad->input_pwd);
551         }
552
553         evas_object_show(ad->ly_main);
554         SETTING_TRACE_END;
555 }
556
557 #ifdef Status
558 #undef Status
559 #endif
560
561
562 /*****/
563 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
564 {
565         SETTING_TRACE_BEGIN;
566         int ret = 0;
567 #if SUPPORT_RUN_SYSTEM_COMMAND
568         ret += excuteCmd(SETTING_POSTINST_FILE, 1, "security");
569 #else
570
571         /* it may write some stragne thing into /opt/data/setting/set_info */
572         /* setting_store_init_password(""); */
573         struct stat st;
574         if (stat(PWD_FILE, &st) == 0)//file exist
575         {
576                 if (remove(PWD_FILE) != 0) //delete the file
577                 {
578                         perror("remove");
579                         SETTING_TRACE("Failed to remove %s", PWD_FILE);
580                         ret += -1;
581                 }
582         }
583
584         #if SUPPORT_RCS_FOR_DEMO
585         ret += vconf_set_bool("db/setting/rcs", FALSE);
586         #endif
587 #endif
588         return ret;
589 }
590