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.
22 #include <setting-reset-main.h>
23 #include <dd-deviced.h>
24 #if SUPPORT_ENCRYPTION
26 #include <act_lock_api.h>
29 #include <dbus/dbus-glib-lowlevel.h>
31 #define FACTORY_RESET_DBUS_OBJPATH "/org.tizen/factoryreset"
32 #define FACTORY_RESET_DBUS_DEST "org.tizen.factoryreset"
33 #define FACTORY_RESET_DBUS_INTERFACE FACTORY_RESET_DBUS_DEST".start"
35 #define RESULT_FONT_SIZE 28//18
36 #define ITEM_NAME_FONT_SIZE 35//22
37 #define PREDEF_FACTORY_RESET "launchfr"
39 static int setting_reset_main_create(void *cb);
40 static int setting_reset_main_destroy(void *cb);
41 static int setting_reset_main_update(void *cb);
42 static int setting_reset_main_cleanup(void *cb);
44 setting_view setting_view_reset_main = {
45 .create = setting_reset_main_create,
46 .destroy = setting_reset_main_destroy,
47 .update = setting_reset_main_update,
48 .cleanup = setting_reset_main_cleanup,
51 static Eina_Bool setting_reset_main_click_softkey_cancel_cb(void *data, Elm_Object_Item *it);
53 #if SUPPORT_RESET_DETAILS
54 static void setting_reset_main_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj, void *event_info);
59 #if SUPPORT_FACTORY_RESET
61 *@brief check the file "/usr/bin/factory-reset " exist.
63 static bool is_factory_reset_installed()
65 char *file_name = "/usr/bin/factory-reset";
68 if(stat(file_name, &st) == 0) {
72 SETTING_TRACE_ERROR(" %s is *NOT* present\n", file_name);
81 *@brief create the reset main view.
83 static int setting_reset_main_create(void *cb)
87 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
89 SettingResetUG *ad = (SettingResetUG *) cb;
90 Evas_Object *scroller = NULL;
92 #if SUPPORT_RESET_DETAILS
94 setting_create_layout_navi_bar_genlist(ad->win_main_layout,
101 ad->genlist = scroller;
102 evas_object_smart_callback_add(ad->genlist, "realized", __gl_realized_cb, ad);
103 Elm_Object_Item * navi_it = elm_naviframe_top_item_get(ad->navi_bar);
104 elm_naviframe_item_pop_cb_set(navi_it, setting_reset_main_click_softkey_cancel_cb, ad);
105 //Elm_Object_Item *item = NULL;;
106 Setting_GenGroupItem_Data *item_data = NULL;
109 ADD_GL_SEPARATOR(scroller);
111 bool isFoundOther = FALSE;
112 #if SUPPORT_FACTORY_RESET
113 /* 3. Factory reset */
114 item_data = setting_create_Gendial_field_def(scroller, &itc_1text,
115 setting_reset_main_mouse_up_Gendial_list_cb,ad,
116 SWALLOW_Type_INVALID,
118 0,FACTORY_RESET_STR, NULL, NULL);
119 item_data->group_style = isFoundOther ? SETTING_GROUP_STYLE_BOTTOM : SETTING_GROUP_STYLE_NONE;
121 setting_view_reset_main.is_create = 1;
122 ad->main_scroller = scroller;
123 return SETTING_RETURN_SUCCESS;
128 static int setting_reset_main_destroy(void *cb)
132 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
134 SettingResetUG *ad = (SettingResetUG *) cb;
135 evas_object_smart_callback_del(ad->genlist, "realized", __gl_realized_cb);
138 evas_object_del(ad->notify);
141 if (ad->old_notify) {
142 evas_object_del(ad->old_notify);
143 ad->old_notify = NULL;
145 if (ad->pop_progress) {
146 evas_object_del(ad->pop_progress);
147 ad->pop_progress = NULL;
151 evas_object_del(ad->ask_popup);
152 ad->ask_popup = NULL;
155 ecore_animator_del(ad->animator);
159 evas_object_del(ad->pop);
162 if (ad->pop_factory_reset) {
163 evas_object_del(ad->pop_factory_reset);
164 ad->pop_factory_reset = NULL;
166 if (ad->ly_main != NULL) {
167 evas_object_del(ad->ly_main);
168 setting_view_reset_main.is_create = 0;
171 return SETTING_RETURN_SUCCESS;
174 static int setting_reset_main_update(void *cb)
178 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
180 SettingResetUG *ad = (SettingResetUG *) cb;
182 if (ad->ly_main != NULL) {
183 evas_object_show(ad->ly_main);
186 return SETTING_RETURN_SUCCESS;
189 static int setting_reset_main_cleanup(void *cb)
193 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
195 SettingResetUG *ad = (SettingResetUG *) cb;
197 if (ad->ly_main != NULL) {
198 evas_object_hide(ad->ly_main);
201 return SETTING_RETURN_SUCCESS;
204 static void __setting_reset_main_factory_reset()
206 DBusMessage *message = NULL;
207 DBusConnection *conn = NULL;
209 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
211 SETTING_TRACE_ERROR("dbus_bus_get() error");
214 message = dbus_message_new_signal(FACTORY_RESET_DBUS_OBJPATH,
215 FACTORY_RESET_DBUS_INTERFACE,
218 SETTING_TRACE_ERROR("dbus_message_new_signal() error");
219 dbus_connection_unref(conn);
222 dbus_message_set_destination(message, FACTORY_RESET_DBUS_DEST);
223 dbus_connection_send(conn, message, NULL);
224 dbus_message_unref(message);
225 dbus_connection_unref(conn);
229 * @brief do some init before the factory reset.
231 static void __setting_reset_main_elm_profile_initialise()
234 const char *profile = NULL;
235 const char *pdir = NULL;
237 Eina_List *profs = NULL;
239 profs = elm_config_profile_list_get();
240 EINA_LIST_FOREACH(profs, l, profile)
242 pdir = elm_config_profile_dir_get(profile, EINA_TRUE);
244 ecore_file_recursive_rm(pdir);
245 elm_config_profile_dir_free(pdir);
248 elm_config_profile_list_free(profs);
251 * @brief do some init before the factory reset.
253 static void __setting_reset_main_initialise_for_factory_reset()
256 __setting_reset_main_elm_profile_initialise();
261 * execute /usr/bin/factory-reset after creating a process with fork()
264 setting_reset_main_result_password_ug_cb(ui_gadget_h ug, app_control_h result,
269 retm_if(priv == NULL, "Data parameter is NULL");
271 SettingResetUG *ad = (SettingResetUG *) priv;
273 char *ret_str = NULL;
274 app_control_get_extra_data(result, "result", &ret_str);
275 SETTING_TRACE("result:%s", ret_str);
277 retm_if(ret_str == NULL, "result paremeter is NULL");
280 if (0 == safeStrCmp("Cancel", ret_str)) {
283 else if (!strncmp(ret_str, "SETTING_PW_TYPE_", strlen("SETTING_PW_TYPE_")))
285 setting_ug_destroy(ad->ug_loading);
286 ad->ug_loading = NULL;
288 /* before factory reset, do some initialization */
289 __setting_reset_main_initialise_for_factory_reset();
291 #if SUPPORT_ENCRYPTION
292 // If ode status is "encrypted" or "mounted', call ode_restore() instead of below.
293 char *encryption_state = NULL;
294 encryption_state = vconf_get_str(VCONFKEY_ODE_CRYPTO_STATE);
295 if(encryption_state && (safeStrCmp(encryption_state, "mounted") == 0 || safeStrCmp(encryption_state, "encrypted") == 0)) {
301 //deviced_call_predef_action(PREDEF_FACTORY_RESET, 0, NULL);
302 __setting_reset_main_factory_reset();
304 FREE(encryption_state);
306 //deviced_call_predef_action(PREDEF_FACTORY_RESET, 0, NULL);
307 __setting_reset_main_factory_reset();
315 * @brief the callback function for calling ug layout,it use for call checking screen lock ug.
318 setting_reset_main_layout_ug_cb(ui_gadget_h ug, enum ug_mode mode,
321 //SettingResetUG *ad = (SettingResetUG *) priv;
329 base = (Evas_Object *) ug_get_layout(ug);
334 case UG_MODE_FULLVIEW:
335 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
337 //elm_win_resize_object_add(ad->win_get, base);
338 evas_object_show(base);
346 static void setting_reset_main_destroy_ug_cb(ui_gadget_h ug,
350 /* if(ug) ug_destroy(ug); */
352 SettingResetUG *ad = (SettingResetUG *) priv;
354 setting_ug_destroy(ug);
355 ad->ug_loading = NULL;
359 *@brief the function check the lockscreen.If the screen lock was set by password,It need to check the password before reset operation.
361 static bool setting_reset_main_create_password_sg(void *data, int cur_locktype)
365 retv_if(data == NULL, FALSE);
367 SettingResetUG *ad = (SettingResetUG *) data;
369 struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
372 cbs->layout_cb = setting_reset_main_layout_ug_cb;
373 cbs->result_cb = setting_reset_main_result_password_ug_cb;
374 cbs->destroy_cb = setting_reset_main_destroy_ug_cb;
375 cbs->priv = (void *)ad;
377 if (app_control_create(&svc))
383 if(cur_locktype == SETTING_SCREEN_LOCK_TYPE_SIMPLE_PASSWORD)
385 app_control_add_extra_data(svc, "viewtype", "SETTING_PW_TYPE_SIMPLE_PASSWORD");
387 else if(cur_locktype == SETTING_SCREEN_LOCK_TYPE_PASSWORD)
389 app_control_add_extra_data(svc, "viewtype", "SETTING_PW_TYPE_PASSWORD");
393 SETTING_TRACE_DEBUG("unsupported locktype : %d", cur_locktype);
394 app_control_destroy(svc);
399 elm_object_tree_focus_allow_set(ad->ly_main, EINA_FALSE);
401 setting_ug_create(ad->ug, "setting-password-efl", UG_MODE_FULLVIEW, svc, cbs);
402 if (NULL == ad->ug_loading) { /* error handling */
405 app_control_destroy(svc);
412 *@brief callback function for factory reset popup,when you excute the factory reset,it will popup the message to check.
414 static void __ask_create_factory_reset_resp_cb(void *data, Evas_Object *obj,
419 SettingResetUG *ad = (SettingResetUG *) data;
420 ret_if(NULL == data);
422 int response_type = POPUP_RESPONSE_CANCEL;
423 char *utf8 = elm_entry_markup_to_utf8(elm_object_text_get(obj));
424 if (0 == safeStrCmp(utf8, _("IDS_ST_HEADER_RESET")))
426 response_type = POPUP_RESPONSE_OK;
429 int screen_lock_type = 0;
431 if (POPUP_RESPONSE_OK == response_type) {
433 vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &screen_lock_type);
434 if(screen_lock_type == SETTING_SCREEN_LOCK_TYPE_PASSWORD
435 || screen_lock_type == SETTING_SCREEN_LOCK_TYPE_SIMPLE_PASSWORD)
437 setting_reset_main_create_password_sg(ad, screen_lock_type);
440 /* before factory reset, do some initialization */
441 __setting_reset_main_initialise_for_factory_reset();
442 __setting_reset_main_factory_reset();
443 //deviced_call_predef_action(PREDEF_FACTORY_RESET, 0, NULL);
446 else if (POPUP_RESPONSE_CANCEL == response_type) {
451 evas_object_del(ad->pop_factory_reset);
452 ad->pop_factory_reset = NULL;
456 *@brief the callback for reboot,when you reset the factory mode,it will be called to reboot the target.
459 static void setting_reset_reboot_resp_cb(void *data, Evas_Object *obj,
463 int response_type = POPUP_RESPONSE_CANCEL;
464 char *utf8 = elm_entry_markup_to_utf8(elm_object_text_get(obj));
465 if (0 == safeStrCmp(utf8, _("IDS_ST_HEADER_RESET")))
467 response_type = POPUP_RESPONSE_OK;
471 if (POPUP_RESPONSE_OK == response_type) { // OK cliked
473 deviced_request_reboot();
476 else if (POPUP_RESPONSE_CANCEL == response_type) { // cancel clicked
480 SettingResetUG *ad = data;
482 evas_object_del(ad->pop);
488 #if SUPPORT_RESET_DETAILS
490 setting_reset_main_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj, void *event_info)
493 setting_retm_if(data == NULL, "Data parameter is NULL");
495 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
496 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
497 elm_genlist_item_selected_set(item, 0);
499 Setting_GenGroupItem_Data *list_item =
500 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
502 SettingResetUG *ad = (SettingResetUG *) data;
504 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
506 if (!safeStrCmp(RESET_SETTINGS_STR, list_item->keyStr)) {
507 setting_view_change(&setting_view_reset_main, &setting_view_reset_settings, ad);
509 #if SUPPORT_FACTORY_RESET
510 else if (!safeStrCmp(FACTORY_RESET_STR, list_item->keyStr))
513 SETTING_TRACE("FACTORY RESET");
514 if(is_factory_reset_installed()) {
515 char guide_str[2048 + 1] = {0,};
516 int ret = snprintf(guide_str, 2048, "%s %s", _(FACTORY_RESET00), _(FACTORY_RESET02));
518 SETTING_TRACE("snprintf failed");
520 //setting_create_simple_popup(NULL, ad->win_get, NULL, "NOT IMPLMENTED YET");
521 ad->pop_factory_reset = setting_create_popup_with_btn(ad,
524 __ask_create_factory_reset_resp_cb,
525 0, 2, _("IDS_ST_HEADER_RESET"),_("IDS_COM_SK_CANCEL"));
528 setting_create_simple_popup(NULL, ad->win_get, NULL, _("IDS_MSGF_POP_UNSUPPORTED"));
532 else if (!safeStrCmp(KeyStr_Accounts, list_item->keyStr))
534 struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
539 cbs->layout_cb = setting_reset_main_layout_ug_cb;
540 cbs->result_cb = NULL;
541 cbs->destroy_cb = setting_reset_main_destroy_ug_cb;
542 cbs->priv = (void *)ad;
545 if (app_control_create(&svc)) {
549 app_control_add_extra_data(svc, "mode", "account_list");
550 elm_object_tree_focus_allow_set(ad->ly_main, EINA_FALSE);
552 setting_ug_create(ad->ug, "setting-myaccount-efl", UG_MODE_FULLVIEW, svc, cbs);
554 if (NULL == ad->ug_loading) { /* error handling */
555 SETTING_TRACE_ERROR("NULL == ad->ug_loading");
557 app_control_destroy(svc);
565 *@brief the callback function for cancel button,when press the back key or cancel button,it will be called.
567 static Eina_Bool setting_reset_main_click_softkey_cancel_cb(void *data, Elm_Object_Item *it)
571 retvm_if(data == NULL, EINA_FALSE, "Data parameter is NULL");
573 SettingResetUG *ad = (SettingResetUG *) data;
574 if (ad->list_data.selInfoPop) {
575 evas_object_del(ad->list_data.selInfoPop);
576 ad->list_data.selInfoPop = NULL;
578 /* Send destroy request */
579 ug_destroy_me(ad->ug);