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"
29 static struct _s_info {
33 Eina_Bool is_vibration;
37 .vibration_status = 0,
38 .is_vibration = EINA_FALSE,
41 int volume_sound_step_get(void)
43 return s_info.sound_step;
46 int volume_sound_sound_status_get(void)
48 return s_info.sound_status;
51 int volume_sound_vibration_status_get(void)
53 return s_info.vibration_status;
56 Eina_Bool volume_sound_is_vibration_get(void)
58 return s_info.is_vibration;
61 void volume_sound_is_vibration_set(Eina_Bool val)
63 s_info.is_vibration = val;
66 void volume_sound_feedback_play(int feedback_type, int pattern)
68 _D("Feedback type : %d / pattern : %d", feedback_type, pattern);
70 if (FEEDBACK_ERROR_NONE != feedback_play_type(feedback_type, pattern))
72 _E("Failed to play feedback");
76 void volume_sound_vib_play(void)
78 ret_if(s_info.is_vibration);
80 _D("Play Feedback : vibration");
82 if (FEEDBACK_ERROR_NONE != feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_VIBRATION_ON))
84 _E("Failed to play feedback");
87 s_info.is_vibration = EINA_TRUE;
90 void volume_sound_play(void)
92 sound_type_e sound_type = volume_control_sound_type_at_show_get();
93 _D("sound type at show : %d", sound_type);
95 ret_if(sound_type == SOUND_TYPE_ALARM);
96 ret_if(sound_type == SOUND_TYPE_MEDIA);
97 ret_if(sound_type == SOUND_TYPE_VOICE);
98 ret_if(sound_type == SOUND_TYPE_NOTIFICATION);
100 _D("Play Feedback : sound");
101 if(FEEDBACK_ERROR_NONE != feedback_play(FEEDBACK_PATTERN_VOLUME_KEY)) {
102 _E("Failed to play feedback");
108 static int _setting_sound_enabled(void)
112 if(vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &snd_status) < 0)
114 _E("Failed to get vconfkey : VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
125 //void _play_setting_sound(void)
126 void volume_sound_setting_sound_play(void)
128 int snd_enabled = _setting_sound_enabled();
129 _D("snd_enabled(%d)", snd_enabled);
133 //feedback_play_type(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_TOUCH_TAP);
134 volume_sound_feedback_play(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_TOUCH_TAP);
138 int volume_sound_sound_manager_step_get(sound_type_e type)
140 int ret = -1, step = 0;
142 ret = sound_manager_get_max_volume(type, &step);
143 retvm_if(ret < 0, -1, "Failed to get step");
145 s_info.sound_step = step;
150 int volume_sound_sound_manager_volume_get(sound_type_e type)
152 int ret = -1, val = 0;
153 ret = sound_manager_get_volume(type, &val);
154 retvm_if(ret < 0, -1, "Failed to get volume");
158 //sound_type_e _get_volume_type
159 sound_type_e volume_sound_sound_manager_type_get(void)
161 _D(" Volume sound manager type get");
163 sound_type_e sound_type = -1;
165 ret = sound_manager_get_current_sound_type(&sound_type);
167 case SOUND_MANAGER_ERROR_NONE:
169 case SOUND_MANAGER_ERROR_NO_PLAYING_SOUND:
170 sound_type = SOUND_TYPE_RINGTONE;
173 _E("Failed to get sound type : %d", ret);
174 sound_type = SOUND_TYPE_RINGTONE;
178 if(sound_type == SOUND_TYPE_SYSTEM) {
179 sound_type = SOUND_TYPE_RINGTONE;
185 void _mm_func(sound_type_e type, unsigned int volume, void *data)
187 _D("type : %d, volume : %d", type, volume);
188 if(type == volume_control_sound_type_at_show_get()){
189 _D("current show type : %d, volume : %d", type, volume);
190 /* Need to check sound type & device in media type volume. */
191 if(type == SOUND_TYPE_MEDIA){
192 int sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
193 _D("sound status : %d", sound);
195 int vibration = volume_sound_vconf_status_get(TYPE_VCONF_VIBRATION_STATUS);
196 _D("vibration : %d", vibration);
197 volume_view_volume_icon_set(type, sound, vibration);
199 if(VOLUME_ERROR_OK != volume_view_slider_value_set(volume))
201 _E("Failed to set slider value");
206 //int _init_mm_sound(void *data);
207 void volume_sound_mm_sound_init(void)
209 int ret = sound_manager_set_volume_changed_cb(_mm_func, NULL);
210 if (ret != SOUND_MANAGER_ERROR_NONE)
212 _E("Failed to set volume changed event[%d]", ret);
216 //int _get_sound_level(sound_type_e type, int *val)
217 int volume_sound_level_get(sound_type_e type)
220 if(sound_manager_get_volume(type, &val) < 0)
222 _E("Failed to get Volume step");
229 //int _set_sound_level(sound_type_e type, int val)
230 int volume_sound_level_set(sound_type_e type, int val)
233 ret = sound_manager_set_volume(type, val);
238 void volume_sound_change_set(int val)
240 sound_type_e sound_type = volume_control_sound_type_at_show_get();
241 _D("sound type at show : %d", sound_type);
243 int sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
244 _D("sound status : %d", sound);
248 if(sound_type != SOUND_TYPE_MEDIA)
250 if(!volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS))
252 volume_sound_vconf_status_set(TYPE_VCONF_SOUND_STATUS, 1);
253 volume_sound_vconf_status_set(TYPE_VCONF_VIBRATION_STATUS, 0);
256 if(volume_sound_level_set(sound_type, val) != 0)
258 volume_sound_level_set(sound_type, 9);
265 if(sound_type != SOUND_TYPE_MEDIA)
267 volume_sound_vconf_status_set(TYPE_VCONF_SOUND_STATUS, 0);
269 volume_view_slider_value_set(0);
270 volume_sound_level_set(sound_type, 0);
272 if(sound_type == SOUND_TYPE_RINGTONE)
274 volume_sound_vconf_status_set(TYPE_VCONF_VIBRATION_STATUS, 1);
275 volume_sound_vib_play();
280 static void _sound_status_changed_cb(keynode_t *key, void *data)
282 const char *keyname = vconf_keynode_get_name(key);
284 _D("keyname : %s", keyname);
286 sound_type_e sound_type = volume_control_sound_type_at_show_get();
287 _D("sound type at show : %d", sound_type);
289 int sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
290 _D("sound status : %d", sound);
291 s_info.sound_status = sound;
293 int vibration = volume_sound_vconf_status_get(TYPE_VCONF_VIBRATION_STATUS);
294 _D("vibration : %d", vibration);
295 s_info.vibration_status = vibration;
297 if(sound == 0 && vibration == 1)
299 _D("vibration mode");
300 } else if(sound == 1 && vibration == 0)
303 s_info.is_vibration = EINA_FALSE;
304 } else if(sound == 0 && vibration == 0)
307 s_info.is_vibration = EINA_FALSE;
310 volume_view_volume_icon_set(sound_type, sound, vibration);
313 void volume_sound_vconf_status_set(volume_vconf_type_e type, int val)
315 char *vconfkey = NULL;
318 case TYPE_VCONF_SOUND_STATUS:
319 vconfkey = VCONFKEY_SETAPPL_SOUND_STATUS_BOOL;
321 case TYPE_VCONF_VIBRATION_STATUS:
322 vconfkey = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL;
325 _E("Failed to set vconfkey : Type error");
329 if(vconf_set_bool(vconfkey, val) < 0)
331 _E("Failed to set vconfkey : %s", vconfkey);
335 int volume_sound_vconf_status_get(volume_vconf_type_e type)
338 char *vconfkey = NULL;
342 case TYPE_VCONF_SOUND_STATUS:
343 vconfkey = VCONFKEY_SETAPPL_SOUND_STATUS_BOOL;
345 case TYPE_VCONF_VIBRATION_STATUS:
346 vconfkey = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL;
349 _E("Failed to get vconfkey : Type error");
353 if(vconf_get_bool(vconfkey, &ret) < 0)
355 _E("Failed to get vconfkey : %s", vconfkey);
362 void volume_sound_vconfkey_register(void)
364 if(vconf_notify_key_changed(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, _sound_status_changed_cb, NULL) < 0)
366 _E("Failed to notify vconfkey : VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
369 if(vconf_notify_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, _sound_status_changed_cb, NULL) < 0)
371 _E("Failed to notify vconfkey : VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");
373 _sound_status_changed_cb(NULL, NULL);
376 void volume_sound_vconfkey_unregister(void)
378 if(vconf_ignore_key_changed(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, _sound_status_changed_cb) < 0)
380 _E("Failed to ignore vconfkey : VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
383 if(vconf_ignore_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, _sound_status_changed_cb) < 0)
385 _E("Failed to ignore vconfkey : VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");