[Backup and reset] Reset device popups 16/150416/8
authorPawel Aksiutowicz <p.aksiutowic@partner.samsung.com>
Fri, 15 Sep 2017 11:16:17 +0000 (13:16 +0200)
committerPawel Aksiutowicz <p.aksiutowic@partner.samsung.com>
Wed, 20 Sep 2017 16:12:41 +0000 (18:12 +0200)
Change-Id: I866373e769db700d3d1ce946ec252ce352ed8308
Signed-off-by: Pawel Aksiutowicz <p.aksiutowic@partner.samsung.com>
setting-backup-and-reset/include/setting-backup-and-reset.h
setting-backup-and-reset/src/setting-backup-and-reset-main-view.c

index c82933f2e09e57491747fee025dca2104c95b668..90fad77dbb5553addf0e043ea4f18ebb2dc9571f 100755 (executable)
@@ -29,7 +29,8 @@
 
 typedef struct {
        MainData md;
-
+       bool sd_card_encrypted;
+       bool sd_inserted;
        /* Main view: */
        setting_view *main_view;
        Elm_Object_Item *item_samsung_cloud;
index 0c9cfb15347c8badfa43872d3f5db37ce71cc20d..fae1bbf7d63c02ae9d537bde15cf3fa9615cc94b 100755 (executable)
 
 setting_view setting_backup_reset_main_view;
 
+static const char *reset_device_without_sim_msg = \
+                               "All settings will be reset and your data. \
+                               will be erased. To make sure your data cannot \
+                               be recovered after being erased, select Secure \
+                               erase. This may mean the data takes longer to erase.";
+
+static const char *reset_device_with_sim_msg = \
+                               "All settings and data will be erased from your \
+                               device storage including system and app data and\
+                               downloaded apps.<br><br>\
+                               Note: You cannot access encrypted files on the SD \
+                               card after a factory data reset.";
+
 static int _create(void *data);
 static int _destroy(void *data);
 static int _update(void *data);
 
+static void _create_reset_first_warning_popup(SettingBackupReset *sbr,
+                                                                               const char *text, bool check_active);
+
 /* UI callbacks:*/
 static Eina_Bool _navi_pop_cb(void *data, Elm_Object_Item *it);
 
@@ -109,6 +125,9 @@ static int _create(void *data)
        setting_view_node_table_register(&setting_backup_reset_usb_view,
                                                                        ad->main_view);
 
+       ad->sd_card_encrypted = true;
+       ad->sd_inserted = false;
+
        return SETTING_RETURN_SUCCESS;
 }
 
@@ -154,6 +173,18 @@ static void _item_click(void *data, Evas_Object *genlist, void *event_info)
        if (event_info == ad->item_usb_mass_storage)
                setting_view_change(ad->main_view,
                                                        &setting_backup_reset_usb_view, ad);
+
+       if (event_info == ad->item_factory_reset) {
+               if (ad->sd_inserted) {
+                       if (ad->sd_card_encrypted) {
+                               _create_reset_first_warning_popup(ad, reset_device_with_sim_msg, false);
+                       } else {
+                               _create_reset_first_warning_popup(ad, "All settings and data will be erased", false);
+                       }
+               } else {
+                       _create_reset_first_warning_popup(ad, reset_device_without_sim_msg, true);
+               }
+       }
 }
 
 static char *_gl_itc_item_text_get(void *data, Evas_Object *obj,
@@ -166,3 +197,143 @@ static char *_gl_itc_item_text_get(void *data, Evas_Object *obj,
 
        return NULL;
 }
+
+static Evas_Object *_create_popup(Evas_Object *parent, const char *title)
+{
+       Evas_Object *popup = elm_popup_add(parent);
+       if (!popup) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] popup == NULL", __FILE__, __LINE__);
+               return NULL;
+       }
+
+       elm_object_part_text_set(popup, "title,text", "Reset device");
+       elm_popup_align_set(popup, 0.5, 0.5);
+       return popup;
+}
+
+static Evas_Object *_create_box(Evas_Object *parent)
+{
+       Evas_Object *box = elm_box_add(parent);
+
+       if (!box) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] box == NULL", __FILE__, __LINE__);
+               return NULL;
+       }
+
+       elm_object_content_set(parent, box);
+       return box;
+}
+
+static Evas_Object *_create_label(Evas_Object *parent, const char *text)
+{
+       Evas_Object *label = elm_label_add(parent);
+       if (!label) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] label == NULL", __FILE__, __LINE__);
+               return NULL;
+       }
+
+       elm_label_line_wrap_set(label, ELM_WRAP_WORD);
+       elm_object_text_set(label, text);
+       evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
+       evas_object_show(label);
+
+       return label;
+}
+
+static Evas_Object *_create_popup_button(Evas_Object *parent, const char *part, const char *title, Evas_Smart_Cb cb, void *callback_data)
+{
+       Evas_Object *btn = elm_button_add(parent);
+       if (!btn) {
+               SETTING_TRACE_ERROR("btn == NULL");
+               return NULL;
+       }
+
+       elm_object_text_set(btn, title);
+       evas_object_smart_callback_add(btn, "clicked", cb, callback_data);
+
+       elm_object_part_content_set(parent, part, btn);
+
+       return btn;
+}
+
+static void check_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+
+}
+
+static Evas_Object *_create_check(Evas_Object *parent, const char *label_text, bool checked)
+{
+       Evas_Object *check = elm_check_add(parent);
+       elm_check_state_set(check, checked);
+       elm_object_text_set(check, label_text);
+       evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
+       evas_object_smart_callback_add(check, "changed", check_clicked_cb, NULL);
+       evas_object_show(check);
+       return check;
+}
+
+static Evas_Object *get_widget_specified_type_ancestor(Evas_Object *widget, const char *specified_ancestor_type)
+{
+       const int MAX_NESTING = 10;
+       int i = 0;
+       Evas_Object *potential_ancestor = widget;
+
+       for (i = 0; i < MAX_NESTING; i++) {
+               if (!strcmp(evas_object_type_get(potential_ancestor), specified_ancestor_type)) {
+                       return potential_ancestor;
+               }
+
+               potential_ancestor = elm_object_parent_widget_get(potential_ancestor);
+       }
+
+       return NULL;
+}
+
+static void warning_cancel_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+       evas_object_del(get_widget_specified_type_ancestor(obj, "elm_popup"));
+}
+
+static void second_warning_ok_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+       evas_object_del(get_widget_specified_type_ancestor(obj, "elm_popup"));
+}
+
+static void first_warning_reset_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+       SettingBackupReset *sbr = (SettingBackupReset *)data;
+
+       evas_object_del(get_widget_specified_type_ancestor(obj, "elm_popup"));
+       const char *popup_text = "The factory reset can't be stopped after it has started.";
+       Evas_Object *popup = _create_popup(sbr->md.window, "Reset Device");
+       Evas_Object *box = _create_box(popup);
+       Evas_Object *label = _create_label(popup, popup_text);
+       elm_box_pack_end(box, label);
+
+       _create_popup_button(popup, "button1", "Cancel", warning_cancel_btn_clicked_cb, NULL);
+       _create_popup_button(popup, "button2", "Ok", second_warning_ok_btn_clicked_cb, NULL);
+
+       evas_object_show(popup);
+}
+
+static void _create_reset_first_warning_popup(SettingBackupReset *sbr,
+                                                                               const char *text, bool check_active)
+{
+       SETTING_TRACE_BEGIN;
+       Evas_Object *popup = _create_popup(sbr->md.window, "Reset_Device");
+       Evas_Object *box = _create_box(popup);
+       Evas_Object *label = _create_label(box, text);
+       Evas_Object *check = NULL;
+
+       elm_box_pack_end(box, label);
+       if (check_active) {
+               check = _create_check(box, "Secure erase", false);
+               elm_box_pack_end(box, check);
+       }
+
+       _create_popup_button(popup, "button1", "Cancel", warning_cancel_btn_clicked_cb, sbr);
+       _create_popup_button(popup, "button2", "Reset", first_warning_reset_btn_clicked_cb, sbr);
+
+       evas_object_show(popup);
+       SETTING_TRACE_END;
+}