/*
+ *
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
#include <app_control_internal.h>
#include <vconf.h>
-#include <notification.h>
#include <ode/secure-erase.h>
#include "secure-erase.h"
static const char *device_path = "/opt/usr"; /*To be removed */
-static Evas_Object *window = NULL;
static notification_h add_notification(notification_type_e type, const char *title, const char *content, const char *image, notification_ly_type_e layout)
{
return handle;
}
-static int create_finish_notification(void)
+
+static int create_finish_notification(struct ui_data *ud)
{
int ret = 0;
- notification_h handle = NULL;
-
- handle = add_notification(NOTIFICATION_TYPE_NOTI, __("IDS_ST_HEADER_SECURE_ERASE_ABB"),
+ ud->notification = add_notification(NOTIFICATION_TYPE_NOTI, __("IDS_ST_HEADER_SECURE_ERASE_ABB"),
__("IDS_ST_BUTTON_DONE"), APP_ICON_PATH, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
- if (handle == NULL) {
+ if (ud->notification == NULL) {
return -1;
}
- ret = notification_set_display_applist(handle, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_LOCK);
+ ret = notification_set_display_applist(ud->notification, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_LOCK);
if (ret != NOTIFICATION_ERROR_NONE) {
return -1;
}
- ret = notification_post(handle);
+ ret = notification_post(ud->notification);
if (ret != NOTIFICATION_ERROR_NONE) {
return -1;
}
- ret = notification_free(handle);
+ ret = notification_free(ud->notification);
if (ret != NOTIFICATION_ERROR_NONE) {
return -1;
}
-
return 0;
}
if (handle == NULL) {
return;
}
-
notification_delete(handle);
notification_free(handle);
handle = NULL;
static Eina_Bool progressbar_timer_cb(void *data)
{
- notification_h handle = NULL;
+ struct ui_data *ud = (struct ui_data *)data;
char *progress = NULL;
int percentage = 0;
double current_progress = 0.0, noti_progress = 0.0;
- handle = notification_load_by_tag("secure-erase-noti");
- if (handle == NULL) {
- return ECORE_CALLBACK_DONE;
- }
-
progress = vconf_get_str(VCONFKEY_ODE_ERASE_PROGRESS);
if (progress) {
percentage = atoi(progress);
} else {
- delete_notification(handle);
+ delete_notification(ud->notification);
ui_app_exit();
return ECORE_CALLBACK_DONE;
}
if (percentage == 100) {
- delete_notification(handle);
- create_finish_notification();
+ delete_notification(ud->notification);
+ int ret = 0;
+ ret = create_finish_notification(ud);
+ if (ret < 0 && ud->notification != NULL) {
+ delete_notification(ud->notification);
+ }
ui_app_exit();
return ECORE_CALLBACK_DONE;
- } else if (percentage < 100) {
- current_progress = (double)(percentage / 100.0);
- notification_get_progress(handle, ¬i_progress);
- if (current_progress != noti_progress) {
- notification_set_progress(handle, (double)(percentage / 100.0));
- notification_update(handle);
- }
}
+ current_progress = (double)(percentage / 100.0);
+ notification_get_progress(ud->notification, ¬i_progress);
+ if (current_progress != noti_progress) {
+ notification_set_progress(ud->notification, (double)(percentage / 100.0));
+ notification_update(ud->notification);
+ }
return ECORE_CALLBACK_PASS_ON;
}
-static int create_progress_notification(void)
+static int create_progress_notification(struct ui_data *ud)
{
int ret = 0;
- notification_h handle = NULL;
- handle = add_notification(NOTIFICATION_TYPE_ONGOING, __("IDS_ST_HEADER_SECURE_ERASE_ABB"), __("IDS_ST_SBODY_ERASING_ALL_DELETED_DATA_ING_ABB"),
+ ud->notification = add_notification(NOTIFICATION_TYPE_ONGOING, __("IDS_ST_HEADER_SECURE_ERASE_ABB"), __("IDS_ST_SBODY_ERASING_ALL_DELETED_DATA_ING_ABB"),
APP_ICON_PATH, NOTIFICATION_LY_ONGOING_PROGRESS);
- if (handle == NULL) {
+ if (ud->notification == NULL) {
return -1;
}
- ret = notification_set_progress(handle, 0);
+ ret = notification_set_progress(ud->notification, 0);
if (ret != NOTIFICATION_ERROR_NONE) {
return ret;
}
- ret = notification_set_tag(handle, "secure-erase-noti");
+ ret = notification_set_display_applist(ud->notification, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
if (ret != NOTIFICATION_ERROR_NONE) {
return ret;
}
- ret = notification_set_display_applist(handle, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
+ ret = notification_post(ud->notification);
if (ret != NOTIFICATION_ERROR_NONE) {
return ret;
}
- ret = notification_post(handle);
- if (ret != NOTIFICATION_ERROR_NONE) {
- return ret;
- }
-
- ecore_timer_add(1, progressbar_timer_cb, NULL);
+ ecore_timer_add(1, progressbar_timer_cb, ud);
return ret;
}
-static int on_secure_erase(void)
+static int on_secure_erase(struct ui_data *ud)
{
int ret = 0;
- evas_object_del(window);
+ evas_object_del(ud->window);
+ ud->window = NULL;
- ret = create_progress_notification();
+ ret = create_progress_notification(ud);
if (ret != 0) {
+ if (ud->notification) {
+ delete_notification(ud->notification);
+ }
dlog_print(DLOG_ERROR, LOG_TAG, "failed to create notification");
return -1;
}
static void reply_password_enter_event_cb(app_control_h ug, app_control_h reply, app_control_result_e result, void *data)
{
char *result_string = NULL;
+ struct ui_data *ud = (struct ui_data *)data;
if (result != APP_CONTROL_RESULT_SUCCEEDED) {
dlog_print(DLOG_ERROR, LOG_TAG, "failed to launch setting-pasword");
}
if (!strcmp(result_string, "Cancel")) {
+ free(result_string);
return;
}
if (!strcmp(result_string, "SETTING_PW_TYPE_ENTER_LOCK_TYPE") ||
!strcmp(result_string, "SETTING_PW_TYPE_VERIFY_FP_ALT_PASSWORD")) {
free(result_string);
- int ret = on_secure_erase();
+ int ret = 0;
+ ret = on_secure_erase(ud);
if (ret != 0) {
dlog_print(DLOG_ERROR, LOG_TAG, "failed to clean the device");
ui_app_exit();
}
}
-static int launch_setting_password(void)
+static int launch_setting_password(struct ui_data *ud)
{
int ret = 0;
- app_control_h app_handler = NULL;
- ret = app_control_create(&app_handler);
+ ret = app_control_create(&ud->appcontrol);
if (ret != APP_CONTROL_ERROR_NONE) {
return -1;
}
- ret = app_control_add_extra_data(app_handler, APP_CONTROL_DATA_SHIFT_WINDOW, "true");
+ ret = app_control_add_extra_data(ud->appcontrol, APP_CONTROL_DATA_SHIFT_WINDOW, "true");
if (ret != APP_CONTROL_ERROR_NONE) {
return -1;
}
- ret = app_control_add_extra_data(app_handler, "viewtype", "SETTING_PW_TYPE_ENTER_LOCK_TYPE");
+ ret = app_control_add_extra_data(ud->appcontrol, "viewtype", "SETTING_PW_TYPE_ENTER_LOCK_TYPE");
if (ret != APP_CONTROL_ERROR_NONE) {
return -1;
}
- ret = app_control_set_app_id(app_handler, "org.tizen.setting-password");
+ ret = app_control_set_app_id(ud->appcontrol, "org.tizen.setting-password");
if (ret != APP_CONTROL_ERROR_NONE) {
return -1;
}
- ret = app_control_send_launch_request(app_handler, reply_password_enter_event_cb, NULL);
+ ret = app_control_send_launch_request(ud->appcontrol, reply_password_enter_event_cb, ud);
if (ret != APP_CONTROL_ERROR_NONE) {
return -1;
}
- ret = app_control_destroy(app_handler);
+ ret = app_control_destroy(ud->appcontrol);
if (ret != APP_CONTROL_ERROR_NONE) {
return -1;
}
+ ud->appcontrol = NULL;
return 0;
}
{
int lock_type = 0;
int ret = 0;
- Ecore_Event_Handler *ecore_handler = (Ecore_Event_Handler *)data;
+ struct ui_data *ud = (struct ui_data *)data;
+
+ ecore_event_handler_del(ud->ecore_handler);
+ ud->ecore_handler = NULL;
- ecore_event_handler_del(ecore_handler);
/* Is password set? */
vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &lock_type);
if (lock_type == SETTING_SCREEN_LOCK_TYPE_PASSWORD
|| lock_type == SETTING_SCREEN_LOCK_TYPE_SIMPLE_PASSWORD) {
- ret = launch_setting_password();
+ ret = launch_setting_password(ud);
+ if (ret < 0 && ud->appcontrol != NULL) {
+ app_control_destroy(ud->appcontrol);
+ ud->appcontrol = NULL;
+ }
} else {
- ret = on_secure_erase();
+ ret = on_secure_erase(ud);
}
if (ret != 0) {
dlog_print(DLOG_ERROR, LOG_TAG, "fail to clean device");
ui_app_exit();
}
-
return;
}
return EINA_TRUE;
}
-void create_base_window(void)
+void create_base_window(struct ui_data *ud)
{
Evas_Object *popup = NULL, *cancel_button = NULL, *next_button = NULL;
- Ecore_Event_Handler *ecore_handler = NULL;
/* Create main UI widget */
- window = ui_create_window(PACKAGE);
- popup = ui_create_popup(window, __("IDS_ST_HEADER_SECURE_ERASE_ABB"),
+ ud->window = ui_create_window(PACKAGE);
+ popup = ui_create_popup(ud->window, __("IDS_ST_HEADER_SECURE_ERASE_ABB"),
__("IDS_ST_POP_ALL_DELETED_DATA_ON_THE_PHONE_WILL_BE_ERASED_THIS_DATA_WILL_NOT_BE_RECOVERABLE_BY_ANYONE_MSG"));
- ecore_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, key_event_cb, NULL);
+ ud->ecore_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, key_event_cb, NULL);
cancel_button = ui_create_popup_button(popup, _("IDS_ST_BUTTON_CANCEL_ABB"), secure_erase_cancel_cb, NULL);
- next_button = ui_create_popup_button(popup, _("IDS_ST_BUTTON_ERASE_ABB"), secure_erase_next_cb, ecore_handler);
+ next_button = ui_create_popup_button(popup, _("IDS_ST_BUTTON_ERASE_ABB"), secure_erase_next_cb, ud);
elm_object_part_content_set(popup, "button1", cancel_button);
elm_object_part_content_set(popup, "button2", next_button);