4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 *@defgroup setting-security
24 *UG creation code for setting-security
27 #include <setting-security.h>
28 #define Max_Passwd_View_Type_Len 64
30 #define UG_MODULE_API __attribute__ ((visibility("default")))
34 int pwd_handler_do_nothing(SettingSecurityUG *data, void* arg)
37 //SettingSecurityUG *ad = (SettingSecurityUG *)data;
42 int pwd_handler_sec_pw_sim_lock_on(SettingSecurityUG *data, void* arg)
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)
48 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
54 int pwd_handler_sec_pw_sim_lock_off(SettingSecurityUG *data, void* arg)
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)
60 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
66 int pwd_handler_sec_pw_pin_lock_on(SettingSecurityUG *data, void* arg)
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)
72 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
78 int pwd_handler_sec_pw_pin_lock_off(SettingSecurityUG *data, void* arg)
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)
84 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
90 int pwd_handler_sec_pw_sim_lock_disabled(SettingSecurityUG *data, void* arg)
93 SettingSecurityUG *ad = (SettingSecurityUG *)data;
94 // [in] Evas_Object *checkbtn
96 setting_disable_genlist_item(ad->data_sim_lk->item);
102 int pwd_handler_sec_pw_change_pin1(SettingSecurityUG *data, void* arg)
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)
108 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
113 int pwd_handler_sec_pw_change_pin2(SettingSecurityUG *data, void* arg)
116 SettingSecurityUG *ad = (SettingSecurityUG *)data;
118 if (tel_get_sim_facility(ad->handle, TAPI_SIM_LOCK_FD, setting_security_sim_get_facility_cb, ad) != TAPI_API_SUCCESS)
120 SETTING_TRACE_ERROR("tel_get_sim_facility(TAPI_SIM_LOCK_PS) failed");
126 int pwd_handler_sec_pw_pin1_blocked(SettingSecurityUG *data, void* arg)
129 SettingSecurityUG *ad = (SettingSecurityUG *)data;
134 int pwd_handler_sec_pw_pin2_blocked(SettingSecurityUG *data, void* arg)
137 SettingSecurityUG *ad = (SettingSecurityUG *)data;
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_sec_pw_pin2_blocked},
151 { SETTING_SEC_PW_PIN1_BLOCKED, "SETTING_PW_TYPE_PIN1_UNBLOCKED", pwd_handler_sec_pw_pin_lock_on},
152 { SETTING_SEC_PW_PIN2_BLOCKED, "SETTING_PW_TYPE_PIN2_UNBLOCKED", pwd_handler_do_nothing},
153 /*------------------------------------------------------------------------------------------------------------*/
154 { SETTING_SEC_PW_MAX, NULL, pwd_handler_do_nothing}
157 static void setting_security_ug_cb_resize(void *data, Evas *e,
158 Evas_Object *obj, void *event_info)
160 ret_if(data == NULL);
162 SettingSecurityUG *ad = (SettingSecurityUG *) data; /* ad is point to data */
163 setting_view_update(&setting_view_security_main, ad);
166 static void *setting_security_ug_on_create(ui_gadget_h ug,
167 enum ug_mode mode, service_h service,
170 setting_retvm_if((!priv), NULL, "!priv");
172 SettingSecurityUG *securityUG = priv;
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);
180 setting_retvm_if(securityUG->win_main_layout == NULL, NULL,
181 "[Setting >> About] cannot get main window ");
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);
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));
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;
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. ***");
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). ***");
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). ***");
215 setting_view_node_set_cur_view(&setting_view_security_main);
216 setting_view_create(&setting_view_security_main, (void *)securityUG);
217 evas_object_event_callback_add(securityUG->win_main_layout,
218 EVAS_CALLBACK_RESIZE,
219 setting_security_ug_cb_resize,
222 return securityUG->ly_main;
225 static void setting_security_ug_on_start(ui_gadget_h ug, service_h service,
230 static void setting_security_ug_on_pause(ui_gadget_h ug, service_h service,
235 static void setting_security_ug_on_resume(ui_gadget_h ug, service_h service,
240 static void setting_security_ug_on_destroy(ui_gadget_h ug, service_h service,
243 setting_retm_if((!priv), "!priv");
244 SettingSecurityUG *securityUG = priv;
246 evas_object_event_callback_del(securityUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_security_ug_cb_resize); /* fix flash issue for gallery */
248 if (securityUG->handle && tel_deinit(securityUG->handle) != TAPI_API_SUCCESS) {
250 ("%s*** [ERR] setting_network_unsubscribe_tapi_events. ***%s",
251 SETTING_FONT_RED, SETTING_FONT_BLACK);
254 /* delete the allocated objects. */
255 if (TRUE == setting_view_security_sim_settings.is_create) {
256 setting_view_destroy(&setting_view_security_sim_settings, securityUG);
258 if (TRUE == setting_view_security_main.is_create) {
259 setting_view_destroy(&setting_view_security_main, securityUG);
262 if (NULL != ug_get_layout(securityUG->ug)) {
263 evas_object_hide((Evas_Object *) ug_get_layout(securityUG->ug));
264 evas_object_del((Evas_Object *) ug_get_layout(securityUG->ug));
268 static void setting_security_ug_on_message(ui_gadget_h ug, service_h msg,
269 service_h service, void *priv)
274 static void setting_security_ug_on_event(ui_gadget_h ug,
275 enum ug_event event, service_h service,
279 case UG_EVENT_LOW_MEMORY:
281 case UG_EVENT_LOW_BATTERY:
283 case UG_EVENT_LANG_CHANGE:
285 case UG_EVENT_ROTATE_PORTRAIT:
287 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
289 case UG_EVENT_ROTATE_LANDSCAPE:
291 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
293 case UG_EVENT_REGION_CHANGE:
300 static void setting_security_ug_on_key_event(ui_gadget_h ug,
301 enum ug_key_event event,
302 service_h service, void *priv)
306 SettingSecurityUG *ad = (SettingSecurityUG *) priv; /* ad is point to priv */
308 case UG_KEY_EVENT_END:
310 if (elm_naviframe_top_item_get(ad->navi_bar) ==
311 elm_naviframe_bottom_item_get(ad->navi_bar)) {
314 /* elm_naviframe_item_pop(ad->navi_bar); */
315 setting_view_cb_at_endKey(ad);
325 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
327 SettingSecurityUG *securityUG = calloc(1, sizeof(SettingSecurityUG));
328 setting_retvm_if(!securityUG, -1,
329 "Create SettingSecurityUG obj failed");
331 ops->create = setting_security_ug_on_create;
332 ops->start = setting_security_ug_on_start;
333 ops->pause = setting_security_ug_on_pause;
334 ops->resume = setting_security_ug_on_resume;
335 ops->destroy = setting_security_ug_on_destroy;
336 ops->message = setting_security_ug_on_message;
337 ops->event = setting_security_ug_on_event;
338 ops->key_event = setting_security_ug_on_key_event;
339 ops->priv = securityUG;
340 ops->opt = UG_OPT_INDICATOR_ENABLE;
345 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
347 struct SettingSecurityUG *securityUG;
348 setting_retm_if(!ops, "ops == NULL");
350 securityUG = ops->priv;
355 /* ***************************************************
359 ***************************************************/
360 void setting_security_sim_get_facility_cb(TapiHandle *handle, int result, void *data, void *user_data)
363 ret_if(!data || !user_data);
364 TelSimPinOperationResult_t sec_rt = result;
365 TelSimFacilityInfo_t *fi = data;
366 SettingSecurityUG *ad = user_data;
368 SETTING_TRACE("sec_rt[%d]", sec_rt);
369 SETTING_TRACE("fi->type[%d]", fi->type);
370 SETTING_TRACE("fi->f_status[%d]", fi->f_status);
371 if (sec_rt == TAPI_SIM_PIN_OPERATION_SUCCESS)
373 SETTING_TRACE_DEBUG("PIN_OPERATION_SUCCESS");
376 case TAPI_SIM_LOCK_PS://sim status
377 ad->sim_status = fi->f_status;
379 case TAPI_SIM_LOCK_SC://pin1 status
380 ad->pin1_status = fi->f_status;
382 case TAPI_SIM_LOCK_FD://pin2/fdn status
383 ad->pin2_status = fi->f_status;
391 //if failed, do nothing..
394 /* Update SIM Settings view if created. */
395 if(setting_view_security_sim_settings.is_create == 1)
397 SETTING_TRACE_DEBUG("SIM settings view is already created. [%d]", setting_view_security_sim_settings.is_create);
398 setting_view_update(&setting_view_security_sim_settings, ad);
403 void setting_security_layout_passwd_ug_cb(ui_gadget_h ug,
404 enum ug_mode mode, void *priv)
409 SettingSecurityUG *ad = (SettingSecurityUG *) priv;
410 Evas_Object *base = ug_get_layout(ug);
415 case UG_MODE_FULLVIEW:
416 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
418 elm_win_resize_object_add(ad->win_get, base);
419 evas_object_show(base);
428 void setting_security_destroy_password_ug_cb(ui_gadget_h ug,
432 ret_if(priv == NULL);
433 SettingSecurityUG *ad = (SettingSecurityUG *) priv;
436 ad->ug_passwd = NULL;
440 gboolean setting_security_create_password_sg(void *data)
444 retv_if(data == NULL, FALSE);
446 SettingSecurityUG *ad = (SettingSecurityUG *) data; /* ad is point to data */
448 /* prevent the ug from being loaded again due to window event queuing */
449 /* added by JTS: CQ H0100135346 */
451 SETTING_TRACE("Password UG is already loaded.");
455 if((ad->pw_type < 0) || (ad->pw_type > SETTING_SEC_PW_MAX))
458 char str[Max_Passwd_View_Type_Len + 1] = { 0, };
459 safeCopyStr(str, security_table[ad->pw_type].pw_type_string, Max_Passwd_View_Type_Len);
461 struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
465 cbs->layout_cb = setting_security_layout_passwd_ug_cb;
466 cbs->result_cb = setting_security_result_password_ug_cb;
467 cbs->destroy_cb = setting_security_destroy_password_ug_cb;
468 cbs->priv = (void *)ad;
471 if (service_create(&svc)) {
476 service_add_extra_data(svc, "viewtype", str);
479 SETTING_TRACE_DEBUG("Send current : %s", ad->input_pwd);
480 service_add_extra_data(svc, "current", ad->input_pwd);
482 ad->ug_passwd = ug_create(ad->ug, "setting-password-efl", UG_MODE_FULLVIEW, svc, cbs);
483 if (NULL == ad->ug_passwd) { /* error handling */
484 evas_object_show(ad->ly_main);
487 service_destroy(svc);
493 /* ***************************************************
497 ***************************************************/
500 int _get_security_table_index(char* name)
504 for(i=0;i<SETTING_SEC_PW_MAX;i++)
506 if (0 == safeStrCmp(name, security_table[i].pw_type_string))
513 setting_security_result_password_ug_cb(ui_gadget_h ug, service_h service,
518 retm_if(priv == NULL, "Data paremeter is NULL");
520 SettingSecurityUG *ad = (SettingSecurityUG *) priv; /* ad is point to priv */
523 char *current = NULL;
525 service_get_extra_data(service, "result", &result);
526 service_get_extra_data(service, "current", ¤t);
528 /* divided pw view type */
529 SETTING_TRACE("ad->pw_type: %d result :%s", ad->pw_type, result);
530 ret_if(NULL == result);
532 if(safeStrCmp(result, "Cancel") == 0)
534 /* To do : rollback previouse status. */
538 int index = _get_security_table_index(result);
542 ret = security_table[index].passwd_handler(ad, NULL);
544 SETTING_TRACE_ERROR("no table entry");
550 evas_object_show(ad->ly_main);
560 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
564 #if SUPPORT_RUN_SYSTEM_COMMAND
565 ret += excuteCmd(SETTING_POSTINST_FILE, 1, "security");
568 /* it may write some stragne thing into /opt/data/setting/set_info */
569 /* setting_store_init_password(""); */
571 if (stat(PWD_FILE, &st) == 0)//file exist
573 if (remove(PWD_FILE) != 0) //delete the file
576 SETTING_TRACE("Failed to remove %s", PWD_FILE);
581 #if SUPPORT_RCS_FOR_DEMO
582 ret += vconf_set_bool("db/setting/rcs", FALSE);