Add recovery APIs to use when there is something wrong with encryption
[platform/core/security/ode.git] / tools / apps / ode / src / reset-sdcard.c
1 /*
2  *
3  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18
19 #include <vconf.h>
20 #include <ode/external-encryption.h>
21 #include "ode-password.h"
22
23 static void key_event_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
24 {
25         Evas_Event_Key_Down *ev = (Evas_Event_Key_Down *)event_info;
26
27         if (!strcmp(ev->keyname, "XF86Back")) {
28                 evas_object_del(obj);
29                 ui_app_exit();
30         }
31         return;
32 }
33
34 static void popup_cancel_cb(void *data, Evas_Object *obj, void *event_info)
35 {
36         Evas_Object *popup = (Evas_Object *)data;
37         evas_object_del(popup);
38         ui_app_exit();
39         return;
40 }
41
42 static void popup_confirm_cb(void *data, Evas_Object *obj, void *event_info)
43 {
44         popup_data_s *popup_data = (popup_data_s *)data;
45
46         evas_object_del(popup_data->popup);
47         popup_data->popup = NULL;
48
49         ode_external_encryption_recovery();
50
51         return;
52 }
53
54 void create_reset_sdcard_popup(popup_data_s *data)
55 {
56         Evas_Object *cancel_button = NULL, *next_button = NULL;
57         int sdcard_status = 0;
58
59         vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcard_status);
60         if (sdcard_status != VCONFKEY_SYSMAN_MMC_MOUNTED) {
61                 data->popup = ode_create_popup(data->parent, __("IDS_ST_HEADER_COULDNT_USE_SD_CARD"), __("IDS_ST_POP_TAP_RESET_TO_DELETE_THE_PASSWORD_YOU_CAN_USE_SD_CARDS_THAT_WERE_ENCRYPTED_BY_THIS_PHONE_MSG"));
62         } else {
63                 data->popup = ode_create_popup(data->parent, __("IDS_ST_HEADER_COULDNT_USE_SD_CARD"), __("IDS_ST_POP_AN_INCORRECT_PASSWORD_HAS_BEEN_ENTERED_15_TIMES_YOU_CAN_NO_LONGER_ACCESS_DATA_ON_ANY_MSG"));
64         }
65
66         cancel_button = ode_create_popup_button(data->popup, __("IDS_ST_BUTTON_CANCEL"), popup_cancel_cb, data->popup);
67         next_button = ode_create_popup_button(data->popup, __("IDS_ST_BUTTON_OK"), popup_confirm_cb, data);
68
69         elm_object_part_content_set(data->popup, "button1", cancel_button);
70         elm_object_part_content_set(data->popup, "button2", next_button);
71         evas_object_event_callback_add(data->popup, EVAS_CALLBACK_KEY_DOWN, key_event_cb, NULL);
72         evas_object_show(data->popup);
73         return;
74 }