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.
21 #include <setting-common-data-type.h>
22 #include <setting-common-data-slp-setting.h>
23 #include <setting-common-draw-widget.h>
25 #include <setting-security-enc-processing.h>
26 #include <setting-debug.h>
31 #include <dd-deviced.h>
33 static int setting_security_enc_processing_create(void *cb);
34 static int setting_security_enc_processing_destroy(void *cb);
35 static int setting_security_enc_processing_update(void *cb);
36 static int setting_security_enc_processing_cleanup(void *cb);
38 setting_view setting_view_security_enc_processing = {
39 .create = setting_security_enc_processing_create,
40 .destroy = setting_security_enc_processing_destroy,
41 .update = setting_security_enc_processing_update,
42 .cleanup = setting_security_enc_processing_cleanup,
45 /* ***************************************************
49 ****************************************************/
51 static void __encrypting_key_grab(SettingSecurityUG *ad)
54 Ecore_X_Window xwin = 0;
55 Ecore_X_Display *disp = NULL;
62 disp = ecore_x_display_get();
63 xwin = elm_win_xwindow_get((Evas_Object *)ug_get_window());
65 ret = eext_win_keygrab_set(xwin, "XF86PowerOff");
68 ret = eext_win_keygrab_set(xwin, "XF86Home");
71 ret = eext_win_keygrab_set(xwin, "XF86AudioRaiseVolume");
74 ret = eext_win_keygrab_set(xwin, "XF86AudioLowerVolume");
78 ad->event_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, NULL, NULL);
81 static void __encrypting_key_ungrab(SettingSecurityUG *ad)
84 Ecore_X_Window xwin = 0;
85 Ecore_X_Display *disp = NULL;
92 disp = ecore_x_display_get();
93 xwin = elm_win_xwindow_get((Evas_Object *)ug_get_window());
95 ret = eext_win_keygrab_unset(xwin, "XF86PowerOff");
98 ret = eext_win_keygrab_unset(xwin, "XF86Home");
101 ret = eext_win_keygrab_unset(xwin, "XF86AudioRaiseVolume");
104 ret = eext_win_keygrab_unset(xwin, "XF86AudioLowerVolume");
108 ecore_event_handler_del(ad->event_handler);
111 static void __vconf_change_cb(keynode_t *key, void *data)
114 ret_if(data == NULL);
115 SettingSecurityUG *ad = (SettingSecurityUG *) data;
117 /* To do : update progressbar */
118 char *vconf_name = vconf_keynode_get_name(key);
119 char *vconf_value = NULL;
120 char temp[MAX_COMMON_BUFFER_LEN] = {0,};
122 /*if (!safeStrCmp(vconf_name, VCONFKEY_ODE_ENCRYPT_PROGRESS)) {*/
123 if (!safeStrCmp(vconf_name, "db/ode/encrypt_progress")) {
124 vconf_value = (char *)g_strdup(vconf_keynode_get_str(key));
125 if (vconf_value == NULL)
128 SETTING_TRACE_DEBUG("progress : %s", vconf_value);
129 float i_value = atof(vconf_value);
133 if (ad->cur_enc_mode == 0) {
134 snprintf(temp, MAX_COMMON_BUFFER_LEN, _(ENCRYPTING_GUIDE_02), (int)i_value);
135 } else if (ad->cur_enc_mode == 1) {
136 snprintf(temp, MAX_COMMON_BUFFER_LEN, _(DECRYPTING_GUIDE_02), (int)i_value);
138 elm_object_part_text_set(ad->enc_layout, "description", temp);
139 SETTING_TRACE_DEBUG("current status : %s", temp);
141 elm_progressbar_value_set(ad->enc_progressbar, i_value / 100.0);
142 SETTING_TRACE_DEBUG("progressbar is updated. %f", i_value / 100.0);
145 if (i_value == 100) {
146 SETTING_TRACE_DEBUG("100%");
147 /* To do : Encryption completed. Restart target. */
148 if (ode_crypto_complete() == 0) {
149 SETTING_TRACE_DEBUG("ode_crypto_complete() success.");
151 /*system("reboot"); */
157 int __listen_vconf_change(void *data)
160 retv_if(data == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
164 ret = vconf_notify_key_changed(VCONFKEY_ODE_ENCRYPT_PROGRESS,
165 __vconf_change_cb, data);
166 setting_retvm_if(ret < 0, ret, "%s notifications Failed(%d)",
167 (char *)VCONFKEY_ODE_ENCRYPT_PROGRESS, ret);
172 static int setting_security_enc_processing_create(void *cb)
175 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
177 SettingSecurityUG *ad = (SettingSecurityUG *) cb;
179 if (ad->input_pwd == NULL)
180 return SETTING_RETURN_FAIL;
182 Evas_Object *window = NULL;
183 Evas_Object *layout = NULL;
184 Evas_Object *progressbar = NULL;
185 char enc_type[16] = {0,};
187 layout = elm_layout_add(ad->win_main_layout);
188 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
190 elm_layout_file_set(layout, SETTING_THEME_EDJ_NAME, "encryption_layout");
191 /*elm_win_center(layout, EINA_TRUE, EINA_TRUE); */
192 /*elm_win_fullscreen_set(layout, EINA_TRUE); */
193 /*setting_resize_object(layout, 720, 1280); */
195 /*elm_win_resize_object_add(ad->win_get, layout); */
197 progressbar = elm_progressbar_add(layout);
198 elm_progressbar_value_set(progressbar, 0);
199 elm_object_part_content_set(layout, "progressbar", progressbar);
201 evas_object_show(layout);
203 ad->enc_progressbar = progressbar;
204 ad->enc_layout = layout;
206 /* grab home key and volume key */
207 __encrypting_key_grab(ad);
208 __listen_vconf_change(ad);
210 if (ode_init() < 0) {
211 SETTING_TRACE_DEBUG("ode_init() failed");
212 setting_security_enc_processing_destroy(ad);
213 return SETTING_RETURN_FAIL;
216 if (ad->cur_enc_mode == 0) {
217 elm_object_part_text_set(layout, "title", _(Keystr_Encrypting));
218 elm_object_part_text_set(layout, "description", _(ENCRYPTING_GUIDE_01));
219 safeCopyStr(enc_type, "inplace", 16);
221 if (ode_enable(enc_type, ad->input_pwd) == 0) {
222 SETTING_TRACE_DEBUG("ode_enable(%s, %s) success", ad->input_pwd, enc_type);
224 SETTING_TRACE_DEBUG("ode_enable(%s, %s) failed", ad->input_pwd, enc_type);
227 } else if (ad->cur_enc_mode == 1) {
228 elm_object_part_text_set(layout, "title", _(Keystr_Decrypting));
229 elm_object_part_text_set(layout, "description", _(DECRYPTING_GUIDE_02));
230 safeCopyStr(enc_type, "disable", 16);
232 if (ode_disable(ad->input_pwd) == 0) {
233 SETTING_TRACE_DEBUG("ode_disable(%s, %s) success", ad->input_pwd, enc_type);
235 SETTING_TRACE_DEBUG("ode_disable(%s, %s) failed", ad->input_pwd, enc_type);
240 setting_view_security_enc_processing.is_create = 1;
242 return SETTING_RETURN_SUCCESS;
246 static int setting_security_enc_processing_destroy(void *cb)
249 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
251 SettingSecurityUG *ad = (SettingSecurityUG *) cb;
253 vconf_ignore_key_changed(VCONFKEY_ODE_ENCRYPT_PROGRESS, __vconf_change_cb);
255 if (ad->enc_layout) {
256 evas_object_del(ad->enc_layout);
257 ad->enc_layout = NULL;
260 setting_view_security_enc_processing.is_create = 0;
262 return SETTING_RETURN_SUCCESS;
265 static int setting_security_enc_processing_update(void *cb)
268 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
270 return SETTING_RETURN_SUCCESS;
273 static int setting_security_enc_processing_cleanup(void *cb)
276 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
278 setting_security_enc_processing_destroy(cb);
280 return SETTING_RETURN_SUCCESS;