2 * Copyright (c) 2009-2014 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <appcore-common.h>
20 #include <vconf-keys.h>
24 #include "_util_log.h"
30 struct _sound_s_info {
34 Eina_Bool is_vibration;
37 static struct _sound_s_info sound_info = {
40 .vibration_status = 0,
41 .is_vibration = EINA_FALSE,
44 static void _sound_status_changed_cb(keynode_t *key, void *data);
45 static int _setting_sound_enabled(void);
47 int volume_sound_step_get(void)
49 return sound_info.sound_step;
52 int volume_sound_sound_status_get(void)
54 return sound_info.sound_status;
57 int volume_sound_vibration_status_get(void)
59 return sound_info.vibration_status;
62 Eina_Bool volume_sound_is_vibration_get(void)
64 return sound_info.is_vibration;
67 void volume_sound_is_vibration_set(Eina_Bool val)
69 sound_info.is_vibration = val;
72 void volume_sound_feedback_play(int feedback_type, int pattern)
74 _D("Feedback type : %d / pattern : %d", feedback_type, pattern);
76 if (FEEDBACK_ERROR_NONE != feedback_play_type(feedback_type, pattern))
77 _E("Failed to play feedback");
80 void volume_sound_vib_play(void)
82 ret_if(sound_info.is_vibration);
84 _D("Play Feedback : vibration");
86 //if (FEEDBACK_ERROR_NONE != feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_VIBRATION_ON))
87 // _E("Failed to play feedback");
89 sound_info.is_vibration = EINA_TRUE;
92 void volume_sound_play(void)
94 sound_type_e sound_type = volume_control_get_sound_type_at_show();
95 _D("sound type at show : %d", sound_type);
97 ret_if(sound_type == SOUND_TYPE_ALARM);
98 ret_if(sound_type == SOUND_TYPE_MEDIA);
99 ret_if(sound_type == SOUND_TYPE_VOICE);
100 ret_if(sound_type == SOUND_TYPE_NOTIFICATION);
102 _D("Play Feedback : sound");
103 if(FEEDBACK_ERROR_NONE != feedback_play(FEEDBACK_PATTERN_VOLUME_KEY)) {
104 _E("Failed to play feedback");
110 void volume_sound_setting_sound_play(void)
112 int snd_enabled = _setting_sound_enabled();
113 _D("snd_enabled(%d)", snd_enabled);
116 volume_sound_feedback_play(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_TOUCH_TAP);
119 int volume_sound_sound_manager_step_get(sound_type_e type)
121 _D("volume sound manager step get");
122 int ret = -1, step = 0;
124 ret = sound_manager_get_max_volume(type, &step);
125 retvm_if(ret < 0, -1, "Failed to get step");
127 sound_info.sound_step = step;
132 int volume_sound_sound_manager_volume_get(sound_type_e type)
134 int ret = -1, val = 0;
135 ret = sound_manager_get_volume(type, &val);
136 retvm_if(ret < 0, -1, "Failed to get volume");
140 sound_type_e volume_sound_sound_manager_type_get(void)
142 _D(" Volume sound manager type get");
144 sound_type_e sound_type = -1;
146 ret = sound_manager_get_current_sound_type(&sound_type);
147 _D("ret: %d, sound type: %d", ret, sound_type);
149 case SOUND_MANAGER_ERROR_NONE:
152 case SOUND_MANAGER_ERROR_NO_PLAYING_SOUND:
153 _D("NO playing sound");
154 sound_type = SOUND_TYPE_RINGTONE;
157 _E("Failed to get sound type : %d", ret);
158 sound_type = SOUND_TYPE_RINGTONE;
162 if(sound_type == SOUND_TYPE_SYSTEM)
163 sound_type = SOUND_TYPE_RINGTONE;
168 void _mm_func(sound_type_e type, unsigned int volume, void *data)
170 bool bt_opened = false;
172 _D("mm func is called type : %d, volume : %d", type, volume);
173 if (type == volume_control_get_sound_type_at_show()) {
174 _D("current show type : %d, volume : %d", type, volume);
175 /* Need to check sound type & device in media type volume. */
176 if (type == SOUND_TYPE_MEDIA) {
177 int sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
178 _D("sound status : %d", sound);
180 int vibration = volume_sound_vconf_status_get(TYPE_VCONF_VIBRATION_STATUS);
181 _D("vibration : %d", vibration);
182 volume_view_volume_icon_set(type, sound, vibration, bt_opened);
184 if (VOLUME_ERROR_OK != volume_view_slider_value_set(volume))
185 _E("Failed to set slider value");
189 void volume_sound_mm_sound_init(void)
192 int ret = sound_manager_set_volume_changed_cb(_mm_func, NULL);
193 if (ret != SOUND_MANAGER_ERROR_NONE)
194 _E("Failed to set volume changed event[%d]", ret);
197 int volume_sound_level_get(sound_type_e type)
200 if (sound_manager_get_volume(type, &val) < 0) {
201 _E("Failed to get Volume step");
208 int volume_sound_level_set(sound_type_e type, int val)
211 ret = sound_manager_set_volume(type, val);
216 void volume_sound_change_set(int val)
218 sound_type_e sound_type = volume_control_get_sound_type_at_show();
219 _D("sound type at show : %d", sound_type);
221 int sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
222 _D("sound status : %d", sound);
225 if (sound_type != SOUND_TYPE_MEDIA) {
226 if (!volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS)) {
227 volume_sound_vconf_status_set(TYPE_VCONF_SOUND_STATUS, 1);
228 volume_sound_vconf_status_set(TYPE_VCONF_VIBRATION_STATUS, 0);
231 if (volume_sound_level_set(sound_type, val) != 0)
232 volume_sound_level_set(sound_type, 9);
236 if (sound_type != SOUND_TYPE_MEDIA)
237 volume_sound_vconf_status_set(TYPE_VCONF_SOUND_STATUS, 0);
238 volume_view_slider_value_set(0);
239 volume_sound_level_set(sound_type, 0);
241 if (sound_type == SOUND_TYPE_RINGTONE) {
242 volume_sound_vconf_status_set(TYPE_VCONF_VIBRATION_STATUS, 1);
243 volume_sound_vib_play();
248 void volume_sound_vconf_status_set(volume_vconf_type_e type, int val)
250 char *vconfkey = NULL;
253 case TYPE_VCONF_SOUND_STATUS:
254 vconfkey = VCONFKEY_SETAPPL_SOUND_STATUS_BOOL;
256 case TYPE_VCONF_VIBRATION_STATUS:
257 vconfkey = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL;
260 _E("Failed to set vconfkey : Type error");
264 if (vconf_set_bool(vconfkey, val) < 0)
265 _E("Failed to set vconfkey : %s", vconfkey);
268 int volume_sound_vconf_status_get(volume_vconf_type_e type)
271 char *vconfkey = NULL;
275 case TYPE_VCONF_SOUND_STATUS:
276 vconfkey = VCONFKEY_SETAPPL_SOUND_STATUS_BOOL;
278 case TYPE_VCONF_VIBRATION_STATUS:
279 vconfkey = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL;
282 _E("Failed to get vconfkey : Type error");
286 if (vconf_get_bool(vconfkey, &ret) < 0) {
287 _E("Failed to get vconfkey : %s", vconfkey);
294 void volume_sound_vconfkey_register(void)
296 if (vconf_notify_key_changed(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, _sound_status_changed_cb, NULL) < 0)
297 _E("Failed to notify vconfkey : VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
299 if (vconf_notify_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, _sound_status_changed_cb, NULL) < 0)
300 _E("Failed to notify vconfkey : VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");
301 _sound_status_changed_cb(NULL, NULL);
304 void volume_sound_vconfkey_unregister(void)
306 if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, _sound_status_changed_cb) < 0)
307 _E("Failed to ignore vconfkey : VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
309 if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, _sound_status_changed_cb) < 0)
310 _E("Failed to ignore vconfkey : VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");
313 static int _setting_sound_enabled(void)
317 if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &snd_status) < 0)
318 _E("Failed to get vconfkey : VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
326 static void _sound_status_changed_cb(keynode_t *key, void *data)
328 bool bt_opened = false;
329 const char *keyname = vconf_keynode_get_name(key);
331 _D("keyname : %s", keyname);
333 sound_type_e sound_type = volume_control_get_sound_type_at_show();
334 _D("sound type at show : %d", sound_type);
336 int sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
337 _D("sound status : %d", sound);
338 sound_info.sound_status = sound;
340 int vibration = volume_sound_vconf_status_get(TYPE_VCONF_VIBRATION_STATUS);
341 _D("vibration : %d", vibration);
342 sound_info.vibration_status = vibration;
344 if (sound == 0 && vibration == 1)
345 _D("vibration mode");
346 else if (sound == 1 && vibration == 0) {
348 sound_info.is_vibration = EINA_FALSE;
349 } else if (sound == 0 && vibration == 0) {
351 sound_info.is_vibration = EINA_FALSE;
354 volume_view_volume_icon_set(sound_type, sound, vibration, bt_opened);