f53ce2622efdc132a48b27c7e7b4ec4d5d31c6f9
[platform/core/security/ode.git] / tools / apps / ode / src / ode-app-confirm.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 "ode-app.h"
20 #include "ode-password.h"
21 #include <ode/external-encryption.h>
22 #include <ode/internal-encryption.h>
23
24 char *confirm_button_text[] = {
25         "IDS_ST_BUTTON_BACK",
26         "IDS_ST_BUTTON_ENCRYPT_ABB2",
27         "IDS_ST_BUTTON_DECRYPT_DEVICE"
28 };
29 extern char *encrypt_header_text[];
30 static int sdcard_option_selected = 0;
31 static int device_full_encryption_state = 0;
32 popup_data_s popup_data; /* for temporary */
33
34 #define sdcard_option_num 2
35
36 static void _confirm_next_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
37 {
38         int ret = 0;
39         appdata_s *ad = (appdata_s *) data;
40         dlog_print(DLOG_DEBUG, LOG_TAG, "_confirm_btn_clicked_cb start");
41
42         switch (ad->view_type) {
43         case ENCRYPT_DEVICE:
44                 dlog_print(DLOG_DEBUG, LOG_TAG, "encrypt device confirm");
45                 if (device_full_encryption_state == 0)
46                         ad->device_info.device_option = 0;
47                 else
48                         ad->device_info.device_option = 1;
49                 popup_data.parent = ad->base;
50                 popup_data.popup = NULL;
51                 popup_data.mode = INTERNAL_ENCRYPT_PASSWORD;
52                 popup_data.callback_data = ad;
53                 create_confirm_password_popup(&popup_data);
54                 break;
55         case DECRYPT_DEVICE:
56                 dlog_print(DLOG_DEBUG, LOG_TAG, "decrypt device confirm");
57                 popup_data.parent = ad->base;
58                 popup_data.popup = NULL;
59                 popup_data.mode = INTERNAL_DECRYPT_PASSWORD;
60                 create_confirm_password_popup(&popup_data);
61                 break;
62         case ENCRYPT_SD_CARD:
63                 dlog_print(DLOG_DEBUG, LOG_TAG, "encrypt sd card confrim");
64                 create_base_window();
65                 create_progress_view("Encrypting", "External");
66                 ret = ode_external_encryption_encrypt(ad->entry_data, 0);
67                 if (ret != 0) {
68                         dlog_print(DLOG_DEBUG, LOG_TAG, "external encryption failed");
69                 }
70                 break;
71         case DECRYPT_SD_CARD:
72                 dlog_print(DLOG_DEBUG, LOG_TAG, "decrypt sd card confrim");
73                 create_base_window();
74                 create_progress_view("Decrypting", "External");
75                 ret = ode_external_encryption_decrypt(ad->entry_data);
76                 if (ret != 0) {
77                         dlog_print(DLOG_DEBUG, LOG_TAG, "external decryption failed");
78                 }
79                 break;
80         }
81 }
82
83 static char *confirm_multiline_text_get(void *data, Evas_Object *obj, const char *part)
84 {
85         char *genlist_text[] = {
86                 "IDS_ST_MBODY_FULL_ENCRYPTION",
87                 "IDS_ST_SBODY_ENCRYPT_NOT_ONLY_THE_USED_PHONE_STORAGE_BUT_ALSO_ANY_EMPTY_SPACE_THIS_WILL_TAKE_MORE_TIME"
88         };
89
90         if (!strcmp(part, "elm.text"))
91                 return strdup(__(genlist_text[0]));
92         else if (!strcmp(part, "elm.text.multiline"))
93                 return strdup(__(genlist_text[1]));
94
95         return NULL;
96 }
97
98 void device_encrypt_option_changed_cb(void *data, Evas_Object *obj, void *event_info)
99 {
100         dlog_print(DLOG_INFO, LOG_TAG, "The value has changed \n");
101         if (elm_check_state_get(obj) == EINA_TRUE)
102                 device_full_encryption_state = 1;
103         else
104                 device_full_encryption_state = 0;
105 }
106
107 static Evas_Object *device_encrypt_content_get(void *data, Evas_Object *obj, const char *part)
108 {
109         if (!strcmp(part, "elm.swallow.end")) {
110                 Evas_Object *check = elm_check_add(obj);
111                 elm_object_style_set(check, "default");
112                 elm_check_state_set(check, EINA_FALSE);
113                 evas_object_smart_callback_add(check, "changed", device_encrypt_option_changed_cb, data);
114                 return check;
115         }
116
117         return NULL;
118 }
119
120 static void _prev_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
121 {
122         appdata_s *ad = (appdata_s *)data;
123         elm_naviframe_item_pop(ad->navi_bar);
124 }
125
126 static void set_confirm_two_btn_layout(Evas_Object *layout, appdata_s *ad, int text_idx)
127 {
128         Evas_Object *btn_layout;
129         Evas_Object *prev_btn, *next_btn;
130
131         btn_layout = ode_create_layout(layout, ad->edj_path, "two_button_layout");
132
133         prev_btn = ode_create_button(layout, __(confirm_button_text[0]), "bottom");
134         elm_object_part_content_set(btn_layout, "prev_button", prev_btn);
135         evas_object_smart_callback_add(prev_btn, "clicked", _prev_btn_clicked_cb, ad);
136
137         next_btn = ode_create_button(layout, __(confirm_button_text[text_idx]), "bottom");
138         elm_object_part_content_set(btn_layout, "next_button", next_btn);
139
140         evas_object_smart_callback_add(next_btn, "clicked", _confirm_next_btn_clicked_cb, ad);
141         elm_object_part_content_set(layout, "bottom_layout", btn_layout);
142         return;
143 }
144
145 static char *sd_confirm_multiline_text_get(void *data, Evas_Object *obj, const char *part)
146 {
147         char *genlist_text[2][2] = {
148                 {
149                         "IDS_ST_MBODY_ENCRYPT_ALL_FILES",
150                         "IDS_ST_SBODY_ENCRYPT_ALL_FILES_SAVED_ON_THE_SD_CARD_NEW_FILES_WILL_ALSO_BE_ENCRYPTED"
151                 },
152                 {
153                         "IDS_ST_MBODY_ENCRYPT_NEW_FILES",
154                         "IDS_ST_BODY_ENCRYPT_ALL_NEW_FILES_SAVED_ON_THIS_SD_CARD_EXISTING_FILES_WILL_NOT_BE_ENCRYPTED"
155                 }
156         };
157
158         char **text = genlist_text[(intptr_t)data];
159
160         if (!strcmp(part, "elm.text"))
161                 return strdup(__(text[0]));
162         else if (!strcmp(part, "elm.text.multiline"))
163                 return strdup(__(text[1]));
164         return NULL;
165 }
166
167 void radio_changed_cb(void *data, Evas_Object *obj, void *event_info)
168 {
169         dlog_print(DLOG_INFO, LOG_TAG, "The value has changed %d\n", (intptr_t)data);
170         sdcard_option_selected = (intptr_t)data;
171
172         dlog_print(DLOG_INFO, LOG_TAG, "sdcard_option_selected is  %d\n", sdcard_option_selected);
173 }
174
175 static Evas_Object *sd_confirm_content_get(void *data, Evas_Object *obj, const char *part)
176 {
177         static Evas_Object *group = NULL;
178         int idx = (intptr_t)data;
179
180         if (!strcmp(part, "elm.swallow.end")) {
181                 if (idx == 0) {
182                         dlog_print(DLOG_DEBUG, LOG_TAG, "radio group null");
183                         group = elm_radio_add(obj);
184                         elm_radio_state_value_set(group, 0);
185                         elm_radio_value_set(group, 0);
186                 }
187
188                 dlog_print(DLOG_DEBUG, LOG_TAG, "radio group not null");
189                 Evas_Object *radio = elm_radio_add(obj);
190                 elm_radio_state_value_set(radio, idx);
191
192                 if (idx == sdcard_option_selected) {
193                         elm_radio_state_value_set(radio, idx);
194                 }
195
196                 elm_radio_group_add(radio, group);
197                 evas_object_propagate_events_set(radio, EINA_FALSE);
198                 evas_object_repeat_events_set(radio, EINA_FALSE);
199
200                 evas_object_smart_callback_add(radio, "changed", radio_changed_cb, data);
201                 return radio;
202         }
203         return NULL;
204 }
205
206 static Eina_Bool sdcard_encrypt_view_pop_cb(void *data, Elm_Object_Item *it)
207 {
208         sdcard_option_selected = 0;
209         return EINA_TRUE;
210 }
211
212 static Eina_Bool device_encrypt_view_pop_cb(void *data, Elm_Object_Item *it)
213 {
214         appdata_s *ad = (appdata_s *)data;
215
216         if (ad->view_type == ENCRYPT_DEVICE)
217                 device_full_encryption_state = 0;
218         return EINA_TRUE;
219 }
220
221
222 void ode_confirm_encrypt_device_create_view(appdata_s *ad)
223 {
224         Evas_Object *naviframe = ad->navi_bar;
225         Evas_Object *base_layout = NULL;
226         Evas_Object *confirm_msg = NULL;
227         Evas_Object *confirm_layout = NULL;
228
229         Evas_Object *genlist = NULL;
230         Elm_Genlist_Item_Class *itc;
231         Elm_Object_Item *item;
232
233         dlog_print(DLOG_DEBUG, LOG_TAG, "start ode_confirm_encrypt_device_create_view");
234
235         char string[PATH_MAX] = "";
236         char *confirm_text[2][3] = {
237                 {
238                         "IDS_ST_BODY_TAP_ENCRYPT_TO_START_THE_ENCRYPTION_PROCESS",
239                         "IDS_ST_BODY_THE_ENCRYPTION_CANT_BE_CANCELLED_AND_DATA_WILL_BE_LOST_IF_THE_PROCESS_IS_INTERRUPTED_DURING_MSG",
240                         "IDS_ST_HEADER_ENCRYPTION_OPTIONS_ABB"
241                 },
242                 {
243                         "IDS_ST_BODY_TAP_DECRYPT_TO_START_THE_DECRYPTION_PROCESS",
244                         "IDS_ST_BODY_THE_DECRYPTION_CANT_BE_CANCELLED_AND_DATA_WILL_BE_LOST_IF_THE_PROCESS_IS_INTERRUPTED_DURING_THE_DECRYPTION_MSG",
245                         ""
246                 }
247         };
248
249         char **text = confirm_text[ad->view_type];
250
251         if (naviframe == NULL) {
252                 dlog_print(DLOG_ERROR, LOG_TAG, "naviframe is null");
253                 return;
254         }
255
256         base_layout = ode_create_layout(naviframe, ad->edj_path, "base_layout");
257         confirm_layout = ode_create_layout(base_layout, ad->edj_path, "encrypt_device_confirm_layout");
258         text = confirm_text[ad->view_type];
259         snprintf(string, sizeof(string), "%s<br><br>%s", __(text[0]), __(text[1]));
260         confirm_msg = ode_create_textblock(confirm_layout, string, MSG_TEXT_STYLE);
261         elm_object_part_content_set(confirm_layout, "msg_content", confirm_msg);
262
263         if (ad->view_type == ENCRYPT_DEVICE) {
264                 /* add group index */
265                 genlist = elm_genlist_add(confirm_layout);
266                 elm_object_style_set(genlist, "solid/default");
267                 elm_layout_content_set(confirm_layout, "genlist_base", genlist);
268                 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
269
270                 itc =  ode_create_genlist_item_class("group_index", ode_group_text_get, NULL);
271                 ode_append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, text[2]);
272
273                 itc = ode_create_genlist_item_class("multiline", confirm_multiline_text_get, device_encrypt_content_get);
274                 ode_append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, NULL);
275         }
276
277         elm_object_part_content_set(base_layout, "content_layout", confirm_layout);
278         /* set button */
279         set_confirm_two_btn_layout(base_layout, ad, (ad->view_type + 1));
280         item = elm_naviframe_item_push(naviframe, __(encrypt_header_text[ad->view_type]), NULL, NULL, base_layout, NULL);
281         elm_naviframe_item_pop_cb_set(item, device_encrypt_view_pop_cb, ad);
282 }
283
284 void ode_confirm_encrypt_sd_card_create_view(appdata_s *ad)
285 {
286         Evas_Object *naviframe = ad->navi_bar;
287         Evas_Object *base_layout = NULL;
288         Evas_Object *confirm_msg = NULL;
289         Evas_Object *confirm_layout = NULL;
290
291         Evas_Object *genlist = NULL;
292         Elm_Genlist_Item_Class *itc;
293         Elm_Object_Item *item;
294
295         dlog_print(DLOG_DEBUG, LOG_TAG, "start ode_confirm_encrypt_sd_card_create_view");
296
297         char string[PATH_MAX] = "";
298         char *confirm_text[] = {
299                 "IDS_ST_BODY_TAP_ENCRYPT_SD_CARD_TO_START_THE_ENCRYPTION_PROCESS",
300                 "IDS_ST_BODY_ALL_OPEN_FILES_ON_SD_CARD_WILL_BE_CLOSED",
301                 "IDS_ST_BODY_THE_ENCRYPTION_CANT_BE_CANCELLED_AND_DATA_WILL_BE_LOST_IF_THE_PROCESS_IS_INTERRUPTED_DURING_THE_MSG",
302                 "IDS_ST_HEADER_ENCRYPTION_OPTIONS_ABB"
303         };
304
305         if (naviframe == NULL) {
306                 dlog_print(DLOG_ERROR, LOG_TAG, "naviframe is null");
307                 return;
308         }
309
310         base_layout = ode_create_layout(naviframe, ad->edj_path, "base_layout");
311         confirm_layout = ode_create_layout(base_layout, ad->edj_path, "encrypt_device_confirm_layout");
312
313         snprintf(string, sizeof(string), "%s<br><br>%s%s", __(confirm_text[0]), __(confirm_text[1]), __(confirm_text[2]));
314         confirm_msg = ode_create_textblock(confirm_layout, string, MSG_TEXT_STYLE);
315         elm_object_part_content_set(confirm_layout, "msg_content", confirm_msg);
316
317         genlist = elm_genlist_add(confirm_layout);
318         elm_object_style_set(genlist, "solid/default");
319         elm_layout_content_set(confirm_layout, "genlist_base", genlist);
320         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
321
322         itc =  ode_create_genlist_item_class("group_index", ode_group_text_get, NULL);
323         ode_append_genlist_item(genlist, itc, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY, confirm_text[3]);
324
325         int index;
326         itc = ode_create_genlist_item_class("multiline", sd_confirm_multiline_text_get, sd_confirm_content_get);
327
328         for (index = 0; index < sdcard_option_num; index++) {
329                 item = elm_genlist_item_append(genlist, itc, (void*)(intptr_t)index, NULL, ELM_GENLIST_ITEM_NONE , NULL, NULL);
330                 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_NONE);
331         }
332
333         elm_object_part_content_set(base_layout, "content_layout", confirm_layout);
334         set_confirm_two_btn_layout(base_layout, ad, 1);
335         item = elm_naviframe_item_push(naviframe, __(encrypt_header_text[2]), NULL, NULL, base_layout, NULL);
336         elm_naviframe_item_pop_cb_set(item, sdcard_encrypt_view_pop_cb, NULL);
337 }
338
339 void ode_confirm_decrypt_sd_card_create_view(appdata_s *ad)
340 {
341         Evas_Object *naviframe = ad->navi_bar;
342         Evas_Object *base_layout = NULL;
343         Evas_Object *confirm_msg = NULL;
344         Evas_Object *confirm_layout = NULL;
345
346         dlog_print(DLOG_DEBUG, LOG_TAG, "start ode_confirm_decrypt_sd_card_create_view");
347
348         char string[PATH_MAX] = "";
349         char *confirm_text[] = {
350                 "IDS_ST_BODY_TAP_ENCRYPT_SD_CARD_TO_START_THE_ENCRYPTION_PROCESS",
351                 "IDS_ST_BODY_ALL_OPEN_FILES_ON_SD_CARD_WILL_BE_CLOSED",
352                 "IDS_ST_BODY_THE_DECRYPTION_CANT_BE_CANCELLED_AND_DATA_WILL_BE_LOST_IF_THE_PROCESS_IS_INTERRUPTED_MSG"
353         };
354
355         if (naviframe == NULL) {
356                 dlog_print(DLOG_ERROR, LOG_TAG, "naviframe is null");
357                 return;
358         }
359
360         base_layout = ode_create_layout(naviframe, ad->edj_path, "base_layout");
361         confirm_layout = ode_create_layout(base_layout, ad->edj_path, "encrypt_device_confirm_layout");
362
363         snprintf(string, sizeof(string), "%s<br><br>%s%s", __(confirm_text[0]), __(confirm_text[1]), __(confirm_text[2]));
364         confirm_msg = ode_create_textblock(confirm_layout, string, MSG_TEXT_STYLE);
365         elm_object_part_content_set(confirm_layout, "msg_content", confirm_msg);
366
367         elm_object_part_content_set(base_layout, "content_layout", confirm_layout);
368         set_confirm_two_btn_layout(base_layout, ad, 2);
369         elm_naviframe_item_push(naviframe, __(encrypt_header_text[3]), NULL, NULL, base_layout, NULL);
370 }