[mobile] Fix logic to launch menu-screen at 64bit binary
[apps/native/starter.git] / src / mobile / lock_pwd_util.c
1 /*
2  * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <system_settings.h>
18 #include <efl_extension.h>
19
20 #include "lock_mgr.h"
21 #include "util.h"
22 #include "status.h"
23 #include "status.h"
24 #include "lock_pwd_util.h"
25 #include "lock_pwd_simple.h"
26 #include "lock_pwd_complex.h"
27
28 static struct _s_lock_pwd_util {
29         Evas_Object *lock_pwd_win;
30         Evas_Object *conformant;
31         Evas_Object *layout;
32         Evas_Object *bg;
33
34         int win_w;
35         int win_h;
36 } s_lock_pwd_util = {
37         .lock_pwd_win = NULL,
38         .conformant = NULL,
39         .layout = NULL,
40         .bg = NULL,
41
42         .win_w = 0,
43         .win_h = 0,
44 };
45
46
47
48 int lock_pwd_util_win_width_get(void)
49 {
50         return s_lock_pwd_util.win_w;
51 }
52
53
54
55 int lock_pwd_util_win_height_get(void)
56 {
57         return s_lock_pwd_util.win_h;
58 }
59
60
61
62 static Evas_Object *_pwd_conformant_add(void *data)
63 {
64         Evas_Object *win = NULL;
65         Evas_Object *conformant = NULL;
66
67         win = (Evas_Object *)data;
68         retv_if(!win, NULL);
69
70         conformant = elm_conformant_add(win);
71         retv_if(!conformant, NULL);
72
73         evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
74         elm_win_resize_object_add(win, conformant);
75
76         elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_SHOW);
77         elm_win_indicator_opacity_set(win, ELM_WIN_INDICATOR_TRANSLUCENT);
78         elm_win_conformant_set(win, EINA_TRUE);
79
80         evas_object_show(conformant);
81
82         return conformant;
83 }
84
85
86 void lock_pwd_util_bg_image_set(Evas_Object *bg, char *file)
87 {
88         char *bg_path = NULL;
89         int ret = 0;
90
91         ret_if(!bg);
92
93         if (file) {
94                 _D("lock bg : %s", file);
95                 if (!elm_bg_file_set(bg, file, NULL)) {
96                         _E("Failed to set BG : %s", file);
97                         goto ERROR;
98                 }
99         } else {
100                 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, &bg_path);
101                 if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
102                         _E("Failed to get system setting value : %d", SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN);
103                         goto ERROR;
104                 }
105                 _D("lock bg : %s", bg_path);
106
107                 if (!elm_bg_file_set(bg, bg_path, NULL)) {
108                         _E("Failed to set bg : %s", bg_path);
109                         goto ERROR;
110                 }
111
112                 if (bg_path) {
113                         free(bg_path);
114                         bg_path = NULL;
115                 }
116         }
117
118         return;
119
120 ERROR:
121         if (bg_path) {
122                 free(bg_path);
123                 bg_path = NULL;
124         }
125
126         if (!elm_bg_file_set(bg, LOCK_MGR_DEFAULT_BG_PATH, NULL)) {
127                 _E("Failed to set default BG : %s. Retry to set default BG.", LOCK_MGR_DEFAULT_BG_PATH);
128                 if (!elm_bg_file_set(bg, LOCK_MGR_DEFAULT_BG_PATH, NULL)) {
129                         _E("Failed to set default BG : %s", LOCK_MGR_DEFAULT_BG_PATH);
130                 }
131         }
132
133         return;
134 }
135
136
137
138 static void _wallpaper_lock_screen_changed_cb(system_settings_key_e key, void *data)
139 {
140         _D("%s", __func__);
141         Evas_Object *bg = (Evas_Object *)data;
142         ret_if(!bg);
143
144         lock_pwd_util_bg_image_set(bg, NULL);
145 }
146
147
148
149 static Evas_Object *_pwd_bg_add(void *data)
150 {
151         Evas_Object *bg = NULL;
152         Evas_Object *parent = NULL;
153         int ret = 0;
154
155         parent = (Evas_Object *)data;
156         retv_if(!parent, NULL);
157
158         bg = elm_bg_add(parent);
159         retv_if(!bg, NULL);
160
161         elm_bg_option_set(bg, ELM_BG_OPTION_SCALE);
162         elm_win_resize_object_add(parent, bg);
163         lock_pwd_util_bg_image_set(bg, NULL);
164         evas_object_show(bg);
165
166         ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, _wallpaper_lock_screen_changed_cb, bg);
167         if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
168                 _E("Failed to register settings changed cb : %d", SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN);
169         }
170
171         return bg;
172 }
173
174
175
176 static Evas_Object *_pwd_layout_create(void *data)
177 {
178         Evas_Object *layout = NULL;
179         Evas_Object *parent = NULL;
180
181         parent = (Evas_Object *)data;
182         retv_if(!parent, NULL);
183
184         layout = elm_layout_add(parent);
185         retv_if(!layout, NULL);
186
187         if (!elm_layout_file_set(layout, LOCK_PWD_EDJE_FILE, "lock_pwd")) {
188                 _E("Failed to set edje file : %s", LOCK_PWD_EDJE_FILE);
189                 goto ERROR;
190         }
191
192         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
193         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
194
195         evas_object_show(layout);
196
197         return layout;
198
199 ERROR:
200         _E("Failed to create password layout");
201
202         if (layout) {
203                 evas_object_del(layout);
204                 layout = NULL;
205         }
206
207         return NULL;
208 }
209
210
211
212 void lock_pwd_util_back_key_relased(void)
213 {
214         _D("%s", __func__);
215
216         ret_if(lock_pwd_simple_is_blocked_get());
217
218         lock_mgr_sound_play(LOCK_SOUND_TAP);
219
220         if (!lock_mgr_lockscreen_launch()) {
221                 _E("Failed to launch lockscreen");
222         }
223
224         lock_pwd_util_view_init();
225 }
226
227
228
229 void lock_pwd_util_create(Eina_Bool is_show)
230 {
231         Evas_Object *win = NULL;
232         Evas_Object *conformant = NULL;
233         Evas_Object *bg = NULL;
234         Evas_Object *layout = NULL;
235         Evas_Object *pwd_layout = NULL;
236         int lock_type = 0;
237         int x = 0, y = 0, w = 0, h = 0;
238
239         if (!s_lock_pwd_util.lock_pwd_win) {
240                 win = window_mgr_pwd_lock_win_create();
241                 ret_if(!win);
242                 s_lock_pwd_util.lock_pwd_win = win;
243
244                 elm_win_screen_size_get(win, &x, &y, &w, &h);
245                 _D("win size : %dx%d(%d, %d)", w, h, x, y);
246                 s_lock_pwd_util.win_w = w;
247                 s_lock_pwd_util.win_h = h;
248         }
249
250         conformant = _pwd_conformant_add(win);
251         goto_if(!conformant, ERROR);
252         s_lock_pwd_util.conformant = conformant;
253
254         layout = _pwd_layout_create(conformant);
255         goto_if(!layout, ERROR);
256         s_lock_pwd_util.layout = layout;
257
258         elm_object_content_set(conformant, layout);
259
260         bg = _pwd_bg_add(win);
261         goto_if(!bg, ERROR);
262         s_lock_pwd_util.bg = bg;
263
264         elm_object_part_content_set(layout, "sw.bg", bg);
265
266         lock_type = status_active_get()->setappl_screen_lock_type_int;
267         _D("lock type : %d", lock_type);
268
269         switch(lock_type) {
270         case SETTING_SCREEN_LOCK_TYPE_SIMPLE_PASSWORD:
271                 pwd_layout = lock_pwd_simple_layout_create(layout);
272                 break;
273         case SETTING_SCREEN_LOCK_TYPE_PASSWORD:
274                 pwd_layout = lock_pwd_complex_layout_create(layout);
275                 break;
276         default:
277                 _E("lock type is not password : %d", lock_type);
278                 goto ERROR;
279         }
280         goto_if(!pwd_layout, ERROR);
281
282         elm_object_part_content_set(layout, "sw.lock_pwd", pwd_layout);
283
284         if (is_show) {
285                 evas_object_show(win);
286         }
287
288         return;
289
290 ERROR:
291         _E("Failed to launch password lockscreen");
292
293         lock_pwd_util_del();
294
295         return;
296 }
297
298
299
300 void lock_pwd_util_del(void)
301 {
302         int lock_type = status_active_get()->setappl_screen_lock_type_int;
303         _D("lock type : %d", lock_type);
304
305         if (lock_type == SETTING_SCREEN_LOCK_TYPE_SIMPLE_PASSWORD) {
306                 lock_pwd_simple_layout_del();
307         } else if (lock_type == SETTING_SCREEN_LOCK_TYPE_PASSWORD) {
308                 lock_pwd_complex_layout_del();
309         }
310
311         if (s_lock_pwd_util.layout) {
312                 evas_object_del(s_lock_pwd_util.layout);
313                 s_lock_pwd_util.layout = NULL;
314         }
315
316         if (s_lock_pwd_util.conformant) {
317                 evas_object_del(s_lock_pwd_util.conformant);
318                 s_lock_pwd_util.conformant = NULL;
319         }
320
321         if (s_lock_pwd_util.bg) {
322                 system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN);
323                 evas_object_del(s_lock_pwd_util.bg);
324                 s_lock_pwd_util.bg = NULL;
325         }
326
327         if (s_lock_pwd_util.lock_pwd_win) {
328                 evas_object_del(s_lock_pwd_util.lock_pwd_win);
329                 s_lock_pwd_util.lock_pwd_win = NULL;
330         }
331 }
332
333
334
335
336 static void _pwd_popup_cb(void *data, Evas_Object *obj, void *event_info)
337 {
338         ret_if(!data);
339
340         evas_object_del((Evas_Object *)data);
341 }
342
343
344
345 void lock_pwd_util_popup_create(char *title, char *text, Evas_Smart_Cb func, double timeout)
346 {
347         Evas_Object *popup = NULL;
348         Evas_Object *btn = NULL;
349
350         ret_if(!s_lock_pwd_util.lock_pwd_win);
351
352         popup = elm_popup_add(s_lock_pwd_util.lock_pwd_win);
353         ret_if(!popup);
354
355         elm_popup_orient_set(popup, ELM_POPUP_ORIENT_BOTTOM);
356         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
357
358         if (title) {
359                 elm_object_part_text_set(popup, "title,text", title);
360         }
361
362         if (text) {
363                 elm_object_text_set(popup, text);
364         }
365
366         btn = elm_button_add(popup);
367         if (!btn) {
368                 _E("Failed to create lock popup button");
369                 evas_object_del(popup);
370                 return;
371         }
372
373         elm_object_style_set(btn, "popup");
374         elm_object_text_set(btn, _("IDS_COM_BUTTON_OK_ABB"));
375         elm_object_part_content_set(popup, "button1", btn);
376
377         if (timeout > 0.0) {
378                 elm_popup_timeout_set(popup, timeout);
379         }
380
381         if (func) {
382                 evas_object_smart_callback_add(btn, "clicked", func, popup);
383                 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, func, popup);
384         } else {
385                 evas_object_smart_callback_add(btn, "clicked", _pwd_popup_cb, popup);
386                 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _pwd_popup_cb, popup);
387         }
388
389         evas_object_show(popup);
390
391         return;
392 }
393
394
395
396 void lock_pwd_util_view_init(void)
397 {
398         _D("initialize password lock values");
399         int lock_type = 0;
400
401         /* clear pwd lockscreen */
402         lock_type = status_active_get()->setappl_screen_lock_type_int;
403         if (lock_type == SETTING_SCREEN_LOCK_TYPE_SIMPLE_PASSWORD) {
404                 lock_pwd_simple_view_init();
405         } else if (lock_type == SETTING_SCREEN_LOCK_TYPE_PASSWORD) {
406                 lock_pwd_complex_view_init();
407         }
408 }
409
410
411
412 Evas_Object *lock_pwd_util_win_get(void)
413 {
414         return s_lock_pwd_util.lock_pwd_win;
415 }
416
417
418
419 Eina_Bool lock_pwd_util_win_visible_get(void)
420 {
421         retv_if(!s_lock_pwd_util.lock_pwd_win, EINA_FALSE);
422         return evas_object_visible_get(s_lock_pwd_util.lock_pwd_win);
423 }
424
425
426
427 void lock_pwd_util_win_show(void)
428 {
429         ret_if(!s_lock_pwd_util.lock_pwd_win);
430         evas_object_show(s_lock_pwd_util.lock_pwd_win);
431 }
432
433
434
435 void lock_pwd_util_win_hide(void)
436 {
437         ret_if(!s_lock_pwd_util.lock_pwd_win);
438         evas_object_hide(s_lock_pwd_util.lock_pwd_win);
439 }