/*
- * Copyright (c) 2009-2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
#include <Ecore.h>
-//#include <Ecore_X.h>
#include <vconf.h>
#include <vconf-keys.h>
#include <feedback.h>
#include <bluetooth.h>
#include <bluetooth_internal.h>
-//#include <bluetooth_extention.h>
-#include <app.h>
+#include <bluetooth_extension.h>
+#include <device/display.h>
#include "main.h"
#include "_util_log.h"
#include "timer.h"
#include "key_event.h"
#include "bt.h"
+#include "earphone.h"
#define VCONFKEY_ALARM_VOLUME_POPUP_ENABLE "memory/alarm/volume_popup_enable"
#define VOLUME_INPUT_WIN_NAME "volumekey-input-window"
+#define SAFETY_LIMIT 9
struct _key_event_s_info {
Ecore_X_Window input_win;
static Eina_Bool _key_release_cb(void *data, int type, void *event);
static Eina_Bool _key_press_cb(void *data, int type, void *event);
static volume_error_e _volume_popup_check_in_alarm_type(sound_type_e sound_type);
-static volume_error_e _volume_down_key_press(sound_type_e sound_type, int sound, bool bt_opened);
-static volume_error_e _volume_up_key_press(sound_type_e sound_type, int sound, bool bt_opened);
+static volume_error_e _volume_down_key_press(int status, sound_type_e sound_type, int sound, bool bt_opened, int earphone_connected);
+static volume_error_e _volume_up_key_press(int status, sound_type_e sound_type, int sound, bool bt_opened, int earphone_connected);
static volume_error_e _mute_key_press();
-/*
-Ecore_X_Window _add_input_window(void)
-{
- Ecore_X_Window win = 0;
- win = ecore_x_window_input_new(0, -10000, -10000, 1, 1);
- retv_if(!win, 0);
-
- ecore_x_icccm_title_set(win, VOLUME_INPUT_WIN_NAME);
- ecore_x_netwm_name_set(win, VOLUME_INPUT_WIN_NAME);
- ecore_x_netwm_pid_set(win, getpid());
- ecore_x_flush();
-
- return win;
-}*/
-
-Ecore_X_Window volume_key_event_input_window_get(void)
-{
- return key_event_info.input_win;
-}
-
Ecore_Event_Handler* volume_key_event_handler_volume_up_get(void)
{
return key_event_info.handler_volume_up;
return key_event_info.handler_volume_down;
}
-Ecore_Event_Handler* volume_key_event_handler_qp_state_check(void)
-{
- return key_event_info.handler_qp_state_check;
-}
-
Eina_Bool volume_key_event_is_pressing_get(void)
{
return key_event_info.is_pressing;
}
-int volume_key_event_count_grabed_get(void)
-{
- return key_event_info.count_grabed;
-}
-
-void volume_key_event_count_grabed_set(int val)
-{
- key_event_info.count_grabed = val;
-}
-
-/*
-volume_error_e volume_key_event_key_grab(Ecore_X_Window _xwin, int grab_mode)
-{
- Evas_Object *win = volume_view_win_get();
- retv_if(win == NULL, VOLUME_ERROR_FAIL);
-
- Ecore_X_Display *disp = NULL;
- Ecore_X_Window xwin = 0;
- int ret = -1;
-
- key_event_info.count_grabed++;
- _D("count_grabed : %d", key_event_info.count_grabed);
-
- disp = ecore_x_display_get();
- retvm_if(disp == NULL, VOLUME_ERROR_FAIL, "Failed to get display");
-
- if (_xwin == -1) {
- _D("Top position grab");
- xwin = elm_win_xwindow_get(win);
- retvm_if(xwin == 0, VOLUME_ERROR_FAIL, "Failed to get xwindow");
- } else
- xwin = _xwin;
-
- ret = utilx_grab_key(disp, xwin, KEY_VOLUMEDOWN, grab_mode);
- retvm_if(ret < 0, VOLUME_ERROR_FAIL, "Failed to grab key down");
- retvm_if(ret == 1, VOLUME_ERROR_FAIL, "Already grab");
-
- ret = utilx_grab_key(disp, xwin, KEY_VOLUMEUP, grab_mode);
- retvm_if(ret < 0, VOLUME_ERROR_FAIL, "Failed to grab key up");
- retvm_if(ret == 1, VOLUME_ERROR_FAIL, "Already grab");
-
- ret = utilx_grab_key(disp, xwin, KEY_MUTE, grab_mode);
- retvm_if(ret < 0, VOLUME_ERROR_FAIL, "Failed to grab key mute");
- retvm_if(ret == 1, VOLUME_ERROR_FAIL, "Already grab");
-
- return VOLUME_ERROR_OK;
-}
-
-volume_error_e volume_key_event_key_ungrab(void)
-{
- Ecore_X_Window xwin = 0;
- Ecore_X_Display *disp = NULL;
-
- Evas_Object *win = volume_view_win_get();
- retv_if(win == NULL, VOLUME_ERROR_FAIL);
-
- Ecore_X_Window input_win = volume_key_event_input_window_get();
- retv_if(input_win == 0, VOLUME_ERROR_FAIL);
-
- xwin = elm_win_xwindow_get(win);
- retv_if(xwin == 0, VOLUME_ERROR_FAIL);
-
- disp = ecore_x_display_get();
- retv_if(disp == NULL, VOLUME_ERROR_FAIL);
-
- //@TODO : need to check
- utilx_ungrab_key(disp, input_win, KEY_VOLUMEUP);
- utilx_ungrab_key(disp, input_win, KEY_VOLUMEDOWN);
- utilx_ungrab_key(disp, input_win, KEY_MUTE);
-
- _D("key ungrabed");
-
- return VOLUME_ERROR_OK;
-}*/
-
void volume_key_event_handler_add(void)
{
- if(!key_event_info.handler_volume_up)
+ if (!key_event_info.handler_volume_up)
key_event_info.handler_volume_up = ecore_event_handler_add(ECORE_EVENT_KEY_UP, _key_release_cb, NULL);
- if(!key_event_info.handler_volume_down)
+ if (!key_event_info.handler_volume_down)
key_event_info.handler_volume_down = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, _key_press_cb, NULL);
}
{
ret_if(key_event_info.handler_volume_up == NULL);
ecore_event_handler_del(key_event_info.handler_volume_up);
- key_event_info.handler_volume_up= NULL;
+ key_event_info.handler_volume_up = NULL;
ret_if(key_event_info.handler_volume_down == NULL);
ecore_event_handler_del(key_event_info.handler_volume_down);
key_event_info.handler_volume_down = NULL;
}
-/*
-volume_error_e volume_key_event_input_window_create(void)
-{
- Ecore_X_Window input_win = _add_input_window();
- retv_if(!input_win, VOLUME_ERROR_FAIL);
-
- key_event_info.input_win = input_win;
-
- return volume_key_event_key_grab(input_win, SHARED_GRAB);
-}*/
static volume_error_e _mute_key_press()
{
int status = 0;
int sound = 0;
int error = 0;
+ int earphone_connected = 0;
bool bt_opened = false;
sound_type_e sound_type = 0;
_D("sound status : %d", sound);
error = bt_ag_is_sco_opened(&bt_opened);
- if(error != BT_ERROR_NONE)
+ if (error != BT_ERROR_NONE)
_E("bt_ag_is_sco_opened return [%d]", error);
- _D("BT state %d", bt_opened);
+ earphone_connected = earphone_get_earphone_is_connected();
+
+ _D("BT state %d, Earphone state: %d", bt_opened, earphone_connected);
- volume_control_show_view(status, sound_type, sound, bt_opened);
+ volume_control_show_view(status, sound_type, sound, bt_opened, earphone_connected);
if (sound_type == SOUND_TYPE_MEDIA) {
if (key_event_info.is_mute == EINA_FALSE) {
}
}
-static volume_error_e _volume_up_key_press(sound_type_e sound_type, int sound, bool bt_opened)
+static volume_error_e _volume_up_key_press(int status, sound_type_e sound_type, int sound, bool bt_opened, int earphone_connected)
{
int sound_step = 0;
int sound_level = 0;
_D("mute -> vib.");
volume_sound_vconf_status_set(TYPE_VCONF_VIBRATION_STATUS, 1);
volume_sound_vib_play();
- }
- else {
+ } else {
_D("vib -> sound");
volume_sound_vconf_status_set(TYPE_VCONF_SOUND_STATUS, 1);
volume_sound_vconf_status_set(TYPE_VCONF_VIBRATION_STATUS, 0);
volume_view_slider_value_set(sound_level+1);
_D("new sound value: %d", sound_level+1);
}
- }
- else {
+ } else {
/*adjust the sound level normally */
if (sound_level != sound_step) {
volume_sound_level_set(sound_type, sound_level+1);
_D("new sound value: %d", sound_level+1);
}
}
- }
- else if (sound_type == SOUND_TYPE_NOTIFICATION) {
+ } else if (sound_type == SOUND_TYPE_NOTIFICATION) {
if (!sound) {
/* No sound in notification type. */
volume_view_slider_value_set(0);
elm_object_disabled_set(volume_view_slider_get(), EINA_TRUE);
- }
- else {
+ } else {
/*adjust the sound level normally */
if (sound_level != sound_step) {
volume_sound_level_set(sound_type, sound_level+1);
_D("new sound value: %d", sound_level+1);
}
}
- }
+ } else if (sound_type == SOUND_TYPE_CALL && bt_opened) {
/* Sound type is not ringtone. Need to adjust sound level */
- else if (sound_type == SOUND_TYPE_CALL && bt_opened) {
int bt_vol = 0;
if (bt_ag_get_speaker_gain(&bt_vol) != BT_ERROR_NONE)
_E("Getting bt volume is failed");
_D("BT VOLUME : %d", bt_vol);
if (bt_vol != sound_step) {
- if(bt_ag_notify_speaker_gain(bt_vol+1) != BT_ERROR_NONE)
+ if (bt_ag_notify_speaker_gain(bt_vol+1) != BT_ERROR_NONE)
_E("Setting bt volume is failed");
volume_view_slider_value_set(bt_vol+1);
_D("New BT VOLUME : %d", bt_vol+1);
}
- }
- else {
+ } else {
+ if (sound_type == SOUND_TYPE_MEDIA && (bt_opened || earphone_connected) && sound_level + 1 > SAFETY_LIMIT) {
+ if (volume_control_get_safety_limit()) {
+ display_state_e state;
+ volume_sound_level_set(sound_type, SAFETY_LIMIT);
+ volume_view_slider_value_set(SAFETY_LIMIT);
+ if (VOLUME_ERROR_OK != volume_view_send_warning_signal(EINA_TRUE))
+ _E("Failed to set warning status");
+
+ if (VOLUME_ERROR_OK != volume_view_open_warning_popup()) {
+ _E("Failed to open waring popup!!");
+ return VOLUME_ERROR_FAIL;
+ }
+ if (device_display_get_state(&state) != DEVICE_ERROR_NONE)
+ _E("Failed to get display state");
+
+ if (state == DISPLAY_STATE_SCREEN_OFF || state == DISPLAY_STATE_SCREEN_DIM) {
+ device_display_change_state(DISPLAY_STATE_NORMAL);
+ if (FEEDBACK_ERROR_NONE != feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_WAKEUP))
+ _E("Failed to play vibration");
+ }
+ if (status == LOCK_AND_MEDIA) {
+ /* Check LCD */
+ volume_view_window_show(sound_type);
+ }
+ volume_timer_del(TYPE_TIMER_SU);
+ volume_timer_del(TYPE_TIMER_SD);
+ volume_timer_add(10.0, TYPE_TIMER_WARNING_POPUP);
+ return VOLUME_ERROR_OK;
+ }
+ }
if (sound_level != sound_step) {
volume_sound_level_set(sound_type, sound_level+1);
volume_view_slider_value_set(sound_level+1);
return VOLUME_ERROR_OK;
}
-static volume_error_e _volume_down_key_press(sound_type_e sound_type, int sound, bool bt_opened)
+static volume_error_e _volume_down_key_press(int status, sound_type_e sound_type, int sound, bool bt_opened, int earphone_connected)
{
key_event_info.is_mute = EINA_FALSE;
if (elm_object_disabled_get(volume_view_slider_get()))
elm_object_disabled_set(volume_view_slider_get(), EINA_FALSE);
- if(sound_type == SOUND_TYPE_RINGTONE){
+ if (sound_type == SOUND_TYPE_RINGTONE) {
if (!sound)
/* Check sound status change case. */
_D("Do nothing.");
}
}
}
- }
- else if (sound_type == SOUND_TYPE_NOTIFICATION) {
- if(!sound) {
+ } else if (sound_type == SOUND_TYPE_NOTIFICATION) {
+ if (!sound) {
/* No sound in notification type. */
volume_view_slider_value_set(0);
elm_object_disabled_set(volume_view_slider_get(), EINA_TRUE);
- }
- else {
+ } else {
/*adjust the sound level normally */
if (val != 0) {
volume_sound_level_set(sound_type, val-1);
_D("new sound value: %d", val-1);
}
}
- }
- else if(sound_type == SOUND_TYPE_CALL && bt_opened) {
+ } else if (sound_type == SOUND_TYPE_CALL && bt_opened) {
int bt_vol = 0;
- if(bt_ag_get_speaker_gain(&bt_vol) != BT_ERROR_NONE)
+ if (bt_ag_get_speaker_gain(&bt_vol) != BT_ERROR_NONE)
_E("Getting bt volume is failed");
_D("BT VOLUME : %d", bt_vol);
- if(bt_ag_notify_speaker_gain(bt_vol-1) != BT_ERROR_NONE)
+ if (bt_ag_notify_speaker_gain(bt_vol-1) != BT_ERROR_NONE)
_E("Setting bt volume is failed");
volume_view_slider_value_set(bt_vol-1);
_D("New BT VOLUME : %d", bt_vol-1);
- }
+ } else {
/* Sound type is not ringtone. Need to adjust sound level */
- else {
- if (val != 0) {
+ if (volume_control_get_safety_limit() && sound_type == SOUND_TYPE_MEDIA
+ && (bt_opened || earphone_connected) && val > SAFETY_LIMIT) {
+ display_state_e state;
+ volume_sound_level_set(sound_type, SAFETY_LIMIT);
+ volume_view_slider_value_set(SAFETY_LIMIT);
+ if (VOLUME_ERROR_OK != volume_view_send_warning_signal(EINA_TRUE))
+ _E("Failed to set warning status");
+
+ if (VOLUME_ERROR_OK != volume_view_open_warning_popup()) {
+ _E("Failed to open waring popup!!");
+ return VOLUME_ERROR_FAIL;
+ }
+ if (device_display_get_state(&state) != DEVICE_ERROR_NONE)
+ _E("Failed to get display state");
+
+ if (state == DISPLAY_STATE_SCREEN_OFF || state == DISPLAY_STATE_SCREEN_DIM) {
+ device_display_change_state(DISPLAY_STATE_NORMAL);
+ if (FEEDBACK_ERROR_NONE != feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_WAKEUP))
+ _E("Failed to play vibration");
+ }
+ if (status == LOCK_AND_MEDIA)
+ /* Check LCD */
+ volume_view_window_show(sound_type);
+
+ volume_timer_del(TYPE_TIMER_SU);
+ volume_timer_del(TYPE_TIMER_SD);
+ volume_timer_add(10.0, TYPE_TIMER_WARNING_POPUP);
+ } else if (val != 0) {
volume_sound_level_set(sound_type, val - 1);
volume_view_slider_value_set(val - 1);
_D("new sound value: %d", val-1);
}
}
- if(sound_type != SOUND_TYPE_ALARM)
+ if (sound_type != SOUND_TYPE_ALARM)
volume_sound_play();
volume_timer_del(TYPE_TIMER_SD);
{
int is_enabled = 0;
- if(sound_type == SOUND_TYPE_ALARM) {
+ if (sound_type == SOUND_TYPE_ALARM) {
_D("Sound type is Alarm Type");
- if(vconf_get_bool(VCONFKEY_ALARM_VOLUME_POPUP_ENABLE, &is_enabled) < 0) {
+ if (vconf_get_bool(VCONFKEY_ALARM_VOLUME_POPUP_ENABLE, &is_enabled) < 0) {
_E("Failed to get vconfkey : VCONFKEY_ALARM_VOLUME_POPUP_ENABLE");
return VOLUME_ERROR_FAIL;
}
_D("volume popup enabled in alarm type : %d", is_enabled);
- if(!is_enabled) {
+ if (!is_enabled) {
_D("alarm type but vconf for the volume popup is disabled");
return VOLUME_ERROR_FAIL;
}
int key_status = 0;
int status = 0;
int error = 0;
+ int earphone_connected = 0;
bool bt_opened = false;
sound_type_e sound_type = 0;
Evas_Object *win = NULL;
win = volume_view_win_get();
retv_if(!win, ECORE_CALLBACK_CANCEL);
- if(!strncmp(ev->keyname, KEY_CANCEL, strlen(KEY_CANCEL)) || !strncmp(ev->keyname, KEY_BACK, strlen(KEY_BACK))) {
+ if (volume_view_warning_popup_get()) {
+ _D("Safety warning popup is exist");
+ return ECORE_CALLBACK_CANCEL;
+ }
+
+ if (!volume_control_get_safety_limit() && volume_control_get_time_for_safety_limit()) {
+ _D("Already passed 20 hour after checking warning popup, open warning again");
+ volume_control_set_safety_limit(EINA_TRUE);
+ }
+
+ if (!strncmp(ev->keyname, KEY_CANCEL, strlen(KEY_CANCEL)) || !strncmp(ev->keyname, KEY_BACK, strlen(KEY_BACK))) {
_D("%s is pressed", ev->keyname);
return ECORE_CALLBACK_CANCEL;
}
- if(volume_view_is_slider_touching_get()) {
+ if (volume_view_is_slider_touching_get()) {
_E("Failed to show volume : is_slider_touching is EINA_TRUE");
return ECORE_CALLBACK_CANCEL;
}
- if(vconf_get_int(VCONFKEY_STARTER_USE_VOLUME_KEY, &key_status) < 0) {
+ if (vconf_get_int(VCONFKEY_STARTER_USE_VOLUME_KEY, &key_status) < 0) {
_E("Failed to get vconf : VCONFKEY_STATER_USE_VOLUME_KEY");
return ECORE_CALLBACK_CANCEL;
}
#ifndef FEATURE_SDK
int is_call = -1;
- if(!strncmp(ev->keyname, KEY_MUTE, strlen(KEY_MUTE))) {
+ if (!strncmp(ev->keyname, KEY_MUTE, strlen(KEY_MUTE))) {
_D("MUTE key is pressed");
- if(VOLUME_ERROR_OK != _mute_key_press())
+ if (VOLUME_ERROR_OK != _mute_key_press())
_E("Failed to press MUTE key");
return ECORE_CALLBACK_CANCEL;
}
- if(vconf_get_int(VCONFKEY_TELEPHONY_CALL_STATE, &is_call) < 0 || is_call < 0) {
+ if (vconf_get_int(VCONFKEY_TELEPHONY_CALL_STATE, &is_call) < 0 || is_call < 0) {
_E("Failed to get call state vconf");
return ECORE_CALLBACK_CANCEL;
}
- if(is_call>0) {
+ if (is_call > 0) {
_D("Call is active");
return ECORE_CALLBACK_CANCEL;
}
_D("sound status : %d", sound);
error = bt_ag_is_sco_opened(&bt_opened);
- if(error != BT_ERROR_NONE)
+ if (error != BT_ERROR_NONE)
_E("bt_ag_is_sco_opened return [%d]", error);
- _D("BT state %d", bt_opened);
+ earphone_connected = earphone_get_earphone_is_connected();
+ _D("module state - bt: %d, earphone: %d", bt_opened, earphone_connected);
- if(VOLUME_ERROR_OK != _volume_popup_check_in_alarm_type(sound_type)) {
+ if (VOLUME_ERROR_OK != _volume_popup_check_in_alarm_type(sound_type)) {
_E("Failed to set volume popup");
return ECORE_CALLBACK_CANCEL;
}
- volume_control_show_view(status, sound_type, sound, bt_opened);
+ volume_control_show_view(status, sound_type, sound, bt_opened, earphone_connected);
key_event_info.is_pressing = EINA_TRUE;
volume_timer_del(TYPE_TIMER_POPUP);
if (!strncmp(ev->keyname, KEY_VOLUMEUP, strlen(KEY_VOLUMEUP))) {
- if(VOLUME_ERROR_OK != _volume_up_key_press(sound_type, sound, bt_opened))
+ if (VOLUME_ERROR_OK != _volume_up_key_press(status, sound_type, sound, bt_opened, earphone_connected))
_E("Failed to press volume up key");
- }
- else if (!strncmp(ev->keyname, KEY_VOLUMEDOWN, strlen(KEY_VOLUMEDOWN))) {
- if(VOLUME_ERROR_OK != _volume_down_key_press(sound_type, sound, bt_opened))
+ } else if (!strncmp(ev->keyname, KEY_VOLUMEDOWN, strlen(KEY_VOLUMEDOWN))) {
+ if (VOLUME_ERROR_OK != _volume_down_key_press(status, sound_type, sound, bt_opened, earphone_connected))
_E("Failed to press volume down key");
}
key_event_info.is_pressing = EINA_FALSE;
- if(!strncmp(ev->keyname, KEY_CANCEL, strlen(KEY_CANCEL))) {
+ if (!strncmp(ev->keyname, KEY_CANCEL, strlen(KEY_CANCEL))) {
_D("%s is released", ev->keyname);
- if(VOLUME_ERROR_OK != volume_control_hide_view())
+ if (VOLUME_ERROR_OK != volume_control_hide_view())
_E("Failed to close volume");
- if(VOLUME_ERROR_OK != volume_control_cache_flush())
+ if (VOLUME_ERROR_OK != volume_control_cache_flush())
_E("Failed to flush cache");
return ECORE_CALLBACK_CANCEL;
}
- if(!strncmp(ev->keyname, KEY_BACK, strlen(KEY_BACK))) {
+ if (!strncmp(ev->keyname, KEY_BACK, strlen(KEY_BACK))) {
_D("BACK Key is released");
return ECORE_CALLBACK_CANCEL;
}
if (!strncmp(ev->keyname, KEY_VOLUMEUP, strlen(KEY_VOLUMEUP))) {
_D("up key released and del timer");
volume_timer_del(TYPE_TIMER_SU);
- }
- else if (!strncmp(ev->keyname, KEY_VOLUMEDOWN, strlen(KEY_VOLUMEDOWN))) {
+ } else if (!strncmp(ev->keyname, KEY_VOLUMEDOWN, strlen(KEY_VOLUMEDOWN))) {
_D("down key released and del timer");
volume_timer_del(TYPE_TIMER_SD);
}
volume_timer_del(TYPE_TIMER_POPUP);
- if(volume_view_is_slider_touching_get() == EINA_FALSE)
- volume_timer_add(3.0, TYPE_TIMER_POPUP);
+ if (volume_view_is_slider_touching_get() == EINA_FALSE) {
+ if (!volume_view_warning_popup_get())
+ volume_timer_add(3.0, TYPE_TIMER_POPUP);
+ }
_D("key release fini");
return ECORE_CALLBACK_CANCEL;