remove old code
[apps/native/volume-app.git] / src / control.c
1 /*
2  * Copyright (c) 2009-2014 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 <vconf.h>
18 #include <vconf-keys.h>
19 #include <app_manager.h>
20 #include <bluetooth.h>
21 #include <bluetooth_internal.h>
22 #include <app.h>
23 //#include <bluetooth_extention.h>
24
25 #include "main.h"
26 #include "_util_efl.h"
27 #include "_util_log.h"
28 #include "view.h"
29 #include "control.h"
30 #include "sound.h"
31 #include "timer.h"
32 #include "x_event.h"
33 #include "key_event.h"
34 #include "bt.h"
35
36 #define VCONF_KEY_FMRADIO_RECORDING "memory/private/Sound/FMRadioRecording"
37
38 struct _control_s_info{
39         bundle *volume_bundle;
40         Ecore_Event_Handler *handler_qp_state;
41         Ecore_Timer *shape_timer;
42
43         Eina_Bool is_deleting;
44         Eina_Bool is_launching;
45         Eina_Bool is_new;
46         Eina_Bool is_warning_visible;
47         Eina_Bool reset_once;
48         Eina_Bool show_once;
49
50         int current_angle;
51         int viewport_width;
52         int viewport_height;
53
54         sound_type_e sound_type_at_show;
55 };
56 static struct _control_s_info control_info = {
57         .volume_bundle = NULL,
58         .handler_qp_state = NULL,
59         .shape_timer = NULL,
60
61         .is_deleting = EINA_FALSE,
62         .is_launching = EINA_FALSE,
63         .is_new = EINA_FALSE,
64         .is_warning_visible = EINA_FALSE,
65         .reset_once = EINA_FALSE,
66         .show_once = EINA_FALSE,
67
68         .current_angle = 0,
69         .viewport_width = 0,
70         .viewport_height= 0,
71
72         .sound_type_at_show = SOUND_TYPE_RINGTONE,
73 };
74
75 static int _myterm(bundle *b, void *data);
76 static int _mytimeout(bundle *b, void *data);
77 static void _notify_pm_lcdoff_cb(keynode_t * node, void *data);
78 static void _idle_lock_state_vconf_changed_cb(keynode_t *key, void *data);
79 static void _starter_user_volume_key_vconf_changed_cb(keynode_t *key, void *data);
80 static Eina_Bool _shape_cb(void *data);
81 static Eina_Bool _idler_top_position_grab(void *data);
82 static void _control_set_window_rotation(Evas_Object *win);
83 static void _rotate_changed_cb(void *data, Evas_Object *obj, void *event_info);
84
85 bundle* volume_control_reset_get_bundle(void)
86 {
87         return control_info.volume_bundle;
88 }
89
90 Eina_Bool volume_control_get_is_deleting(void)
91 {
92         return control_info.is_deleting;
93 }
94
95 Eina_Bool volume_control_get_is_launching(void)
96 {
97         return control_info.is_launching;
98 }
99
100 int volume_control_get_current_angle(void)
101 {
102         return control_info.current_angle;
103 }
104
105 sound_type_e volume_control_get_sound_type_at_show(void)
106 {
107         return control_info.sound_type_at_show;
108 }
109
110 int volume_control_get_viewport_height()
111 {
112         return control_info.viewport_height;
113 }
114
115 int volume_control_get_viewport_width()
116 {
117         return control_info.viewport_width;
118 }
119
120 Eina_Bool volume_control_viewport_is_warning_visible()
121 {
122     return control_info.is_warning_visible;
123 }
124
125 volume_error_e volume_control_cache_flush(void)
126 {
127         Evas_Object *win = volume_view_win_get();
128         retv_if(win == NULL, VOLUME_ERROR_FAIL);
129
130         Evas *evas = NULL;
131         int file_cache = -1;
132         int collection_cache = -1;
133         int image_cache = -1;
134         int font_cache = -1;
135
136         evas = evas_object_evas_get(win);
137         retv_if(!evas, VOLUME_ERROR_FAIL);
138
139         file_cache = edje_file_cache_get();
140         collection_cache = edje_collection_cache_get();
141         image_cache = evas_image_cache_get(evas);
142         font_cache = evas_font_cache_get(evas);
143
144         edje_file_cache_set(file_cache);
145         edje_collection_cache_set(collection_cache);
146         evas_image_cache_set(evas, 0);
147         evas_font_cache_set(evas, 0);
148
149         evas_image_cache_flush(evas);
150         evas_render_idle_flush(evas);
151         evas_font_cache_flush(evas);
152
153         edje_file_cache_flush();
154         edje_collection_cache_flush();
155
156         edje_file_cache_set(file_cache);
157         edje_collection_cache_set(collection_cache);
158         evas_image_cache_set(evas, image_cache);
159         evas_font_cache_set(evas, font_cache);
160
161         return VOLUME_ERROR_OK;
162 }
163
164 /* rotation event callback func. */
165 volume_error_e volume_control_app_launch_with_bundle(const char *op_type, const char *operation, const char *pkgname)
166 {
167         app_control_h app_control;
168         int ret = 0;
169
170         ret = app_control_create(&app_control);
171         if (ret != 0) {
172                 _E("Failed to create app control");
173                 return VOLUME_ERROR_FAIL;
174         }
175
176         ret = app_control_set_app_id(app_control, pkgname);
177         if (ret != 0)
178         {
179                 _E("Failed to set appid");
180                 app_control_destroy(app_control);
181                 return VOLUME_ERROR_FAIL;
182         }
183
184         ret = app_control_add_extra_data(app_control, op_type, operation);
185         if (ret != 0)
186         {
187                 _E("Failed to add extra data");
188                 app_control_destroy(app_control);
189                 return VOLUME_ERROR_FAIL;
190         }
191
192         ret = app_control_send_launch_request(app_control, NULL, NULL);
193         _D("launch app with service : [%s][%d]", pkgname, ret);
194
195         app_control_destroy(app_control);
196
197         return VOLUME_ERROR_OK;
198 }
199
200 int volume_control_get_vconf_idlelock(void)
201 {
202         int lock = IDLELOCK_OFF;
203         int pm_state = VCONFKEY_PM_STATE_NORMAL;
204
205         /* Check Idle-Lock */
206         if(vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock) < 0)
207         {
208                 _E("Failed to get vconfkey : VCONFKEY_IDLE_LOCK_STATE");
209                 return IDLELOCK_ERROR;
210         }
211         _D("idlelock vconf : %d", lock);
212
213         /* Check PM state */
214         if(vconf_get_int(VCONFKEY_PM_STATE, &pm_state) < 0)
215         {
216                 _E("Failed to get vconfkey : VCONFKEY_PM_STATE");
217                 return IDLELOCK_ERROR;
218         }
219         _D("PM STATE vconf : %d", pm_state);
220
221         return (lock == VCONFKEY_IDLE_LOCK ||
222                 pm_state == VCONFKEY_PM_STATE_LCDOFF ||
223                 pm_state  == VCONFKEY_PM_STATE_SLEEP
224                 ) ? IDLELOCK_ON : IDLELOCK_OFF;
225 }
226
227
228 int volume_control_check_status(int *lock, sound_type_e *sound_type)
229 {
230         *lock = volume_control_get_vconf_idlelock();
231         *sound_type = volume_sound_sound_manager_type_get();
232         _D("lock : %d / sound_type : %d", *lock, *sound_type);
233
234         if(*lock == IDLELOCK_ON)
235         {
236                 if(*sound_type == SOUND_TYPE_RINGTONE)
237                 {
238                         _D("IDLELOCK is ON / sound type is Ringtone");
239                         return LOCK_AND_NOT_MEDIA;
240                 }
241
242                 if(*sound_type != SOUND_TYPE_RINGTONE)
243                 {
244                         _D("IDLELOCK is ON / sound type is not Ringtone(media or alaram)");
245                         return LOCK_AND_MEDIA;
246                 }
247         }
248
249         _D("IDLELOCK is OFF / normal case");
250
251         return UNLOCK_STATUS;
252 }
253
254 void volume_control_shape_event_area(Eina_Bool is_warning_visible)
255 {
256         _D("shape event area");
257         Evas_Object *win = volume_view_win_get();
258         //volume_x_input_event_shape(win, is_warning_visible);
259 }
260
261 void volume_control_show_hide_worning()
262 {
263         Evas_Object *ly_outer = volume_view_outer_layout_get();
264         sound_type_e sound_type = volume_sound_sound_manager_type_get();
265         int volume = volume_sound_sound_manager_volume_get(sound_type);
266
267         if(sound_type == SOUND_TYPE_MEDIA
268         && volume>VOLUME_MAX_SAFETY_VOLUME_LEVEL)
269         {
270                 if(!control_info.is_warning_visible)
271                 {
272                         control_info.is_warning_visible = EINA_TRUE;
273
274                         if(control_info.current_angle == 90 || control_info.current_angle == 270)
275                         {
276                                 elm_object_signal_emit(ly_outer, "show_warning_l", "clipper"); //landscape
277                         }
278                         else
279                         {
280                                 elm_object_signal_emit(ly_outer, "show_warning", "clipper"); //landscape
281                         }
282
283             volume_control_shape_event_area(EINA_TRUE);
284                 }
285         }
286         else if(control_info.is_warning_visible)
287         {
288                 control_info.is_warning_visible = EINA_FALSE;
289
290                 if(control_info.current_angle == 90 || control_info.current_angle == 270)
291                 {
292                         elm_object_signal_emit(ly_outer, "hide_warning_l", "clipper"); //landscape
293                 }
294                 else
295                 {
296                         elm_object_signal_emit(ly_outer, "hide_warning", "clipper"); //landscape
297                 }
298
299                 volume_control_shape_event_area(EINA_FALSE);
300         }
301 }
302
303 int volume_register_shape_timer()
304 {
305         if (control_info.shape_timer) {
306                 ecore_timer_del(control_info.shape_timer);
307                 control_info.shape_timer = NULL;
308         }
309
310         control_info.shape_timer = ecore_timer_add(0.1, _shape_cb, NULL);
311
312         if (control_info.shape_timer)
313                 return VOLUME_ERROR_OK;
314         else
315                 return VOLUME_ERROR_FAIL;
316 }
317
318 void volume_control_check_syspopup()
319 {
320         if(syspopup_has_popup(control_info.volume_bundle)) {
321                 syspopup_reset(control_info.volume_bundle);
322         }
323 }
324
325 void volume_control_check_once(void)
326 {
327         if(control_info.show_once) {
328                 ecore_idler_add(_idler_top_position_grab, NULL);
329                 control_info.show_once = EINA_FALSE;
330         }
331 }
332
333 Eina_Bool volume_control_show_view(int status, sound_type_e sound_type, int sound, bool bt_opened)
334 {
335         _D("Volume control show");
336         Evas_Object *win = NULL;
337         int volume = 0;
338         int vibration = 0;
339
340         retv_if(control_info.is_deleting, EINA_FALSE);
341
342         control_info.is_new = EINA_TRUE;
343
344         win = volume_view_win_get();
345         retv_if(!win, EINA_FALSE);
346
347         if(status == LOCK_AND_NOT_MEDIA)
348         {
349                 _D("Lock and Not Media");
350                 if(evas_object_visible_get(win))
351                 {
352                         if(VOLUME_ERROR_OK != volume_control_hide_view())
353                         {
354                                 _E("Failed to close volume");
355                         }
356
357                         if(VOLUME_ERROR_OK != volume_control_cache_flush())
358                         {
359                                 _E("Failed to flush cache");
360                         }
361                 }
362                 return EINA_FALSE;
363         } else {
364                 _D("UNLOCK or LOCK_AND_MEDIA");
365                 control_info.sound_type_at_show = sound_type;
366
367                 if(status == UNLOCK_STATUS)     {
368                         if(VOLUME_ERROR_OK != volume_view_window_show()) {
369                                 _E("Failed to show volume window");
370                         }
371
372                         /*if(VOLUME_ERROR_OK != volume_x_input_event_register()) {
373                                 _E("Failed to add x input event handler");
374                         }*/
375
376                         volume_control_check_syspopup();
377
378                         volume_control_check_once();
379                 }
380
381                 control_info.is_launching = EINA_TRUE;
382
383                 if(bt_opened == 1 && sound_type == SOUND_TYPE_CALL)
384                 {
385                         _D("bt is opened and is calling");
386                         volume = bt_get_bt_volume();
387                         _D("bt volume is : %d", volume);
388
389                         if(VOLUME_ERROR_OK != volume_view_slider_value_set(volume))
390                         {
391                                 _E("Failed to set volume value to slider");
392                         }
393                 }
394                 else
395                 {
396                         volume = volume_sound_sound_manager_volume_get(sound_type);
397                         _D("volume : %d", volume);
398
399                         vibration = volume_sound_vconf_status_get(TYPE_VCONF_VIBRATION_STATUS);
400                         _D("vibration : %d", vibration);
401
402                         if(((vibration == 1 && sound == 0) || sound == 0) && sound_type == SOUND_TYPE_RINGTONE)
403                         {
404                                 volume = 0;
405                         }
406
407                         if(VOLUME_ERROR_OK != volume_view_slider_value_set(volume))
408                         {
409                                 _E("Failed to set volume value to slider");
410                         }
411                 }
412
413                 //@TODO: need to check
414                 volume_view_volume_icon_set(sound_type, sound, vibration, bt_opened);
415
416                 if(VOLUME_ERROR_OK != volume_register_shape_timer())
417                 {
418                         _E("Failed to register shape_timer");
419                 }
420
421                 return EINA_TRUE;
422         }
423 }
424
425 volume_error_e volume_control_close_bt_display(void)
426 {
427         retv_if(volume_control_get_is_deleting(), VOLUME_ERROR_FAIL);
428
429         _D("Start closing bt display");
430
431         Ecore_X_Window input_win = volume_key_event_input_window_get();
432         retv_if(!input_win, VOLUME_ERROR_FAIL);
433
434         control_info.is_deleting = EINA_TRUE;
435
436         /* unregister outer event handler */
437         /*if(VOLUME_ERROR_OK != volume_x_input_event_unregister())
438         {
439                 _E("Failed to unregister x input event handler");
440         }*/
441
442         /* hide window */
443         if(VOLUME_ERROR_OK != volume_view_window_hide())
444         {
445                 _E("Failed to hide window");
446         }
447
448         control_info.is_deleting = EINA_FALSE;
449
450         _D("End closing bt display");
451         volume_timer_del(TYPE_TIMER_BT);
452
453         return 0;
454 }
455
456 volume_error_e volume_control_hide_view(void)
457 {
458         retv_if(volume_control_get_is_deleting(), VOLUME_ERROR_FAIL);
459
460         _D("Start closing volume view");
461
462         int ret = 0;
463         int ret1 = 0;
464         int i = 0;
465         int count_grabed = volume_key_event_count_grabed_get();
466
467         control_info.is_deleting = EINA_TRUE;
468
469         elm_win_keygrab_unset(volume_view_win_get(), KEY_VOLUMEUP, 0, 0);
470         elm_win_keygrab_unset(volume_view_win_get(), KEY_VOLUMEDOWN, 0, 0);
471         volume_key_event_count_grabed_set(0);
472         ret = elm_win_keygrab_set(volume_view_win_get(), KEY_VOLUMEUP, 0, 0, 0, ELM_WIN_KEYGRAB_SHARED);
473         ret1 = elm_win_keygrab_set(volume_view_win_get(), KEY_VOLUMEDOWN, 0, 0, 0, ELM_WIN_KEYGRAB_SHARED);
474
475         volume_timer_del(TYPE_TIMER_SU);
476         volume_timer_del(TYPE_TIMER_SD);
477         volume_timer_del(TYPE_TIMER_SLIDER);
478         volume_timer_del(TYPE_TIMER_POPUP);
479
480         /* hide window */
481         if (VOLUME_ERROR_OK != volume_view_window_hide()) {
482                 _E("Failed to hide window");
483         }
484
485         control_info.is_deleting = EINA_FALSE;
486         control_info.is_launching = EINA_FALSE;
487
488         _D("End closing volume view");
489
490         return 0;
491 }
492
493 void volume_control_register_vconfkey(void)
494 {
495         /* other app grab volume key => close volume */
496         if(vconf_notify_key_changed(VCONFKEY_STARTER_USE_VOLUME_KEY, _starter_user_volume_key_vconf_changed_cb, NULL) != 0)
497         {
498                 _E("Failed to register callback function : VCONFKEY_STARTER_USE_VOLUME_KEY");
499         }
500
501         /* Lock screen status vconf changed callback */
502         if(vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE, _idle_lock_state_vconf_changed_cb, NULL) != 0)
503         {
504                 _E("Failed to notify vconfkey : VCONFKEY_IDLE_LOCK_STATE");
505         }
506
507         if (vconf_notify_key_changed(VCONFKEY_PM_LCDOFF_SOURCE, _notify_pm_lcdoff_cb, NULL) != 0) {
508                 _E("Failed to notify vconfkey : VCONFKEY_PM_LCDOFF_SOURCE");
509         }
510 }
511
512 void volume_control_unregister_vconfkey(void)
513 {
514         /* other app grab volume key => close volume */
515         if(vconf_ignore_key_changed(VCONFKEY_STARTER_USE_VOLUME_KEY, _starter_user_volume_key_vconf_changed_cb) < 0)
516         {
517                 _E("Failed to ignore vconfkey : VCONFKEY_STARTER_USE_VOLUME_KEY");
518         }
519
520         /* Lock screen status vconf changed callback */
521         if(vconf_ignore_key_changed(VCONFKEY_IDLE_LOCK_STATE, _idle_lock_state_vconf_changed_cb) < 0)
522         {
523                 _E("Failed to ignore vconfkey : VCONFKEY_IDLE_LOCK_STATE");
524         }
525
526         if (vconf_ignore_key_changed
527                 (VCONFKEY_PM_LCDOFF_SOURCE, _notify_pm_lcdoff_cb) != 0) {
528                 _E("Fail vconf_ignore_key_changed : VCONFKEY_PM_LCDOFF_SOURCE");
529         }
530 }
531
532 volume_error_e volume_control_pause(void)
533 {
534         Evas_Object *win = volume_view_win_get();
535         retv_if(!win, VOLUME_ERROR_FAIL);
536
537         if(evas_object_visible_get(win)) {
538                 if(VOLUME_ERROR_OK != volume_control_hide_view())
539                 {
540                         _E("Failed to close volume");
541                 }
542
543                 if(VOLUME_ERROR_OK != volume_control_cache_flush())
544                 {
545                         _E("Failed to flush cache");
546                 }
547         }
548
549         return VOLUME_ERROR_OK;
550 }
551
552 volume_error_e volume_control_reset(bundle *b)
553 {
554         _D("Volume control reset");
555         Evas_Object *win = volume_view_win_get();
556         retv_if(!win, VOLUME_ERROR_FAIL);
557
558         int ret = -1;
559         int lock = IDLELOCK_ON;
560         int status = 0;
561         int volume = 0;
562         int sound = 0;
563         int error = 0;
564         bool bt_opened = false;
565         sound_type_e sound_type = 0;
566         const char *show_volume = NULL;
567 /*
568         if(control_info.reset_once) {
569                 static syspopup_handler handler = {
570                         .def_term_fn = _myterm,
571                         .def_timeout_fn = _mytimeout
572                 };
573
574                 ret = syspopup_create(b, &handler, win, NULL);
575                 retvm_if(ret < 0, VOLUME_ERROR_FAIL, "Failed to create syspopup");
576                 control_info.volume_bundle = bundle_dup(b);
577                 control_info.reset_once = EINA_FALSE;
578         }*/
579
580         status = volume_control_check_status(&lock, &sound_type);
581         _D("status: %d, lock: %d, sound type : %d", status, lock, sound_type);
582
583         volume = volume_sound_sound_manager_volume_get(sound_type);
584         _D("volume : %d", volume);
585
586         sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
587         _D("sound status : %d", sound);
588
589         error = bt_ag_is_sco_opened(&bt_opened);
590         if(error != BT_ERROR_NONE)
591         {
592                 _E("bt_ag_is_sco_opened return [%d]", error);
593         }
594         _D("BT state %d", bt_opened);
595
596         show_volume = bundle_get_val(b, SHOWVOLUME);
597         retv_if(!show_volume, VOLUME_ERROR_FAIL);
598
599         if(!strncasecmp(show_volume, ISTRUE, strlen(ISTRUE)))
600         {
601                 _D("Bundle : %s", show_volume);
602                 if(lock == IDLELOCK_OFF)
603                 {
604                         _D("Show Volume");
605                         volume_timer_add(3.0, TYPE_TIMER_POPUP);
606                         volume_control_show_view(status, sound_type, sound, bt_opened);
607                 }
608         }
609
610         return VOLUME_ERROR_OK;
611 }
612
613 volume_error_e volume_control_initialize(void)
614 {
615         _D("Volume control initialize");
616
617         /* Create main window */
618         Evas_Object *win = volume_view_window_create();
619         retv_if(!win, VOLUME_ERROR_FAIL);
620
621         /* Create volume layout */
622         if(VOLUME_ERROR_OK != volume_view_layout_create(win)) {
623                 _E("Failed to create volume layout");
624                 return VOLUME_ERROR_FAIL;
625         }
626
627         elm_win_screen_size_get(win, NULL, NULL, &(control_info.viewport_width), &(control_info.viewport_height));
628
629
630         /* Set available rotations */
631         _control_set_window_rotation(win);
632
633         /* Register vconfkey changed callback
634          * : VCONFKEY_STARTER_USE_VOLUME_KEY
635          * : VCONFKEY_IDLE_LOCK_STATE
636          * : VCONFKEY_LOCKSCREEN_SVIEW_STATE
637          * */
638         volume_control_register_vconfkey();
639
640         /* Register vconfkey changed callback
641          * : VCONFKEY_SETAPPL_SOUND_STATUS_BOOL
642          * : VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL
643          * */
644         volume_sound_vconfkey_register();
645
646         /* Add key event handler */
647         volume_key_event_handler_add();
648
649         /* Register volume changed callback */
650         volume_sound_mm_sound_init();
651
652         /* BT initialize and register changed callback */
653         bt_init_sco();
654
655         return VOLUME_ERROR_OK;
656 }
657
658 void volume_control_deinitialize(void)
659 {
660         /* Unregister vconfkey changed callback */
661         volume_control_unregister_vconfkey();
662
663         /* Unregister sound vconfkey changed callback */
664         volume_sound_vconfkey_unregister();
665
666         /* Unregister bt changed callback */
667         bt_deinit_sco();
668 }
669
670 static void _rotate_changed_cb(void *data, Evas_Object *obj, void *event_info)
671 {
672         static int current_angle = -1;
673         int changed_angle = elm_win_rotation_get(obj);
674         LOGD("MIK");
675
676         Evas_Object *ly_outer = volume_view_outer_layout_get();
677         ret_if(!ly_outer);
678
679         _D("window rotated [%d] => [%d]", current_angle, changed_angle);
680         if(current_angle != changed_angle) {
681                 current_angle = changed_angle;
682                 control_info.current_angle = current_angle;
683                 switch(current_angle){
684                 case 90 :
685                 case 270 :
686                         _D("show,landscape");
687                         elm_object_signal_emit(ly_outer, "show,landscape", "bg");
688                         if(control_info.is_warning_visible)
689                         {
690                                 elm_object_signal_emit(ly_outer, "show_warning_l", "clipper");
691                         }
692                         break;
693                 default :
694                         _D("show,portrait");
695                         elm_object_signal_emit(ly_outer, "show,portrait", "bg");
696                         if(control_info.is_warning_visible)
697                         {
698                                 elm_object_signal_emit(ly_outer, "show_warning", "clipper");
699                         }
700                         break;
701                 }
702
703                 //volume_x_input_eddddent_shape(obj, control_info.is_warning_visible);
704         }
705 }
706
707 static void _control_set_window_rotation(Evas_Object *win)
708 {
709         ret_if(!win);
710
711         if (elm_win_wm_rotation_supported_get(win)) {
712                 const int rots[4] = { 0, 90, 180, 270 };
713                 elm_win_wm_rotation_available_rotations_set(win, (const int *)&rots, 4);
714                 _D("set available rotations");
715         }
716
717         /* rotation event callback */
718         evas_object_smart_callback_add(win, "wm,rotation,changed", _rotate_changed_cb, NULL);
719
720         /* initialize degree */
721         _rotate_changed_cb(NULL, win, NULL);
722 }
723
724 static Eina_Bool _idler_top_position_grab(void *data)
725 {
726         Evas_Object *win = NULL;
727         _D("Unset shared keygrab");
728
729         win = volume_view_win_get();
730         elm_win_keygrab_unset(win, KEY_VOLUMEUP, 0, 0);
731         elm_win_keygrab_unset(win, KEY_VOLUMEDOWN, 0, 0);
732         elm_win_keygrab_set(win, KEY_VOLUMEUP, 0, 0, 0, ELM_WIN_KEYGRAB_TOPMOST);
733         elm_win_keygrab_set(win, KEY_VOLUMEDOWN, 0, 0, 0, ELM_WIN_KEYGRAB_TOPMOST);
734
735         return ECORE_CALLBACK_CANCEL;
736 }
737
738 static Eina_Bool _shape_cb(void *data)
739 {
740         LOGD("shape callback");
741         volume_control_shape_event_area(control_info.is_warning_visible);
742         control_info.shape_timer = NULL;
743         return ECORE_CALLBACK_CANCEL;
744 }
745
746 static void _starter_user_volume_key_vconf_changed_cb(keynode_t *key, void *data)
747 {
748         int ret = EINA_FALSE;
749
750         if(vconf_get_int(VCONFKEY_STARTER_USE_VOLUME_KEY, &ret) < 0)
751         {
752                 _E("Failed to get vconfkey : VCONFKEY_STARTER_USE_VOLUME_KEY");
753                 return;
754         }
755         _D("ret : %d", ret);
756
757         if(ret == 1)
758         {
759                 _D("any other App grab volume hard key");
760                 if(VOLUME_ERROR_OK != volume_control_hide_view()) {
761                         _E("Failed to close volume");
762                         return;
763                 }
764                 if(VOLUME_ERROR_OK != volume_control_cache_flush()) {
765                         _E("Failed to flush cache");
766                         return;
767                 }
768                 if(vconf_set_int(VCONFKEY_STARTER_USE_VOLUME_KEY, 0) < 0) {
769                         _E("Failed to get vconfkey : VCONFKEY_STATER_USE_VOLUME_KEY");
770                         return;
771                 }
772         }
773         else if(ret == 2)
774         {
775                 _D("setting App grab volume hard key");
776         }
777 }
778
779 static void _idle_lock_state_vconf_changed_cb(keynode_t *key, void *data)
780 {
781         int lock = VCONFKEY_IDLE_UNLOCK;
782
783         if(vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock) < 0)
784         {
785                 _E("Failed to get vconfkey : VCONFKEY_IDLE_LOCK_STATE");
786                 return;
787         }
788         _D("idle lock state : %d", lock);
789
790         if(lock == VCONFKEY_IDLE_LAUNCHING_LOCK)
791         {
792                 if(VOLUME_ERROR_OK != volume_view_window_hide())
793                 {
794                         _E("Failed to hide window");
795                 }
796         }
797 }
798
799 static void _notify_pm_lcdoff_cb(keynode_t * node, void *data)
800 {
801         if(VOLUME_ERROR_OK != volume_control_hide_view())
802         {
803                 _E("Failed to close volume");
804         }
805
806         if(VOLUME_ERROR_OK != volume_control_cache_flush())
807         {
808                 _E("Failed to flush cache");
809         }
810 }
811
812 static int _mytimeout(bundle *b, void *data)
813 {
814         return 0;
815 }
816
817 static int _myterm(bundle *b, void *data)
818 {
819         if (VOLUME_ERROR_OK != volume_control_hide_view())
820         {
821                 _E("Failed to close volume");
822         }
823         if (VOLUME_ERROR_OK != volume_control_cache_flush())
824         {
825                 _E("Failed to flush cache");
826         }
827
828         return 0;
829 }
830