2 * Copyright (c) 2009-2015 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 int sound_changed_callback_id;
35 Eina_Bool is_vibration;
38 static struct _sound_s_info sound_info = {
41 .vibration_status = 0,
42 .sound_changed_callback_id = 1,
43 .is_vibration = EINA_FALSE,
46 static void _sound_status_changed_cb(keynode_t *key, void *data);
47 static int _setting_sound_enabled(void);
49 int volume_sound_step_get(void)
51 return sound_info.sound_step;
54 int volume_sound_sound_status_get(void)
56 return sound_info.sound_status;
59 int volume_sound_vibration_status_get(void)
61 return sound_info.vibration_status;
64 Eina_Bool volume_sound_is_vibration_get(void)
66 return sound_info.is_vibration;
69 void volume_sound_is_vibration_set(Eina_Bool val)
71 sound_info.is_vibration = val;
74 void volume_sound_feedback_play(int feedback_type, int pattern)
76 _D("Feedback type : %d / pattern : %d", feedback_type, pattern);
78 if (FEEDBACK_ERROR_NONE != feedback_play_type(feedback_type, pattern))
79 _E("Failed to play feedback");
82 void volume_sound_vib_play(void)
84 ret_if(sound_info.is_vibration);
86 _D("Play Feedback : vibration");
88 if (FEEDBACK_ERROR_NONE != feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_VIBRATION_ON))
89 _E("Failed to play feedback");
91 sound_info.is_vibration = EINA_TRUE;
94 void volume_sound_play(void)
96 sound_type_e sound_type = volume_control_get_sound_type_at_show();
97 _D("sound type at show : %d", sound_type);
99 ret_if(sound_type == SOUND_TYPE_ALARM);
100 ret_if(sound_type == SOUND_TYPE_MEDIA);
101 ret_if(sound_type == SOUND_TYPE_VOICE);
102 ret_if(sound_type == SOUND_TYPE_NOTIFICATION);
104 _D("Play Feedback : sound");
105 if (FEEDBACK_ERROR_NONE != feedback_play(FEEDBACK_PATTERN_VOLUME_KEY))
106 _E("Failed to play feedback");
111 void volume_sound_setting_sound_play(void)
113 int snd_enabled = _setting_sound_enabled();
114 _D("snd_enabled(%d)", snd_enabled);
116 if (snd_enabled == 1)
117 volume_sound_feedback_play(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_TAP);
120 int volume_sound_sound_manager_step_get(sound_type_e type)
122 _D("volume sound manager step get");
123 int ret = -1, step = 0;
125 ret = sound_manager_get_max_volume(type, &step);
126 retvm_if(ret < 0, -1, "Failed to get step");
128 sound_info.sound_step = step;
133 int volume_sound_sound_manager_volume_get(sound_type_e type)
135 int ret = -1, val = 0;
136 ret = sound_manager_get_volume(type, &val);
137 retvm_if(ret < 0, -1, "Failed to get volume");
141 sound_type_e volume_sound_sound_manager_type_get(void)
143 _D(" Volume sound manager type get");
145 sound_type_e sound_type = -1;
147 ret = sound_manager_get_current_sound_type(&sound_type);
148 _D("ret: %d, sound type: %d", ret, sound_type);
150 case SOUND_MANAGER_ERROR_NONE:
153 case SOUND_MANAGER_ERROR_NO_PLAYING_SOUND:
154 _D("NO playing sound");
155 sound_type = SOUND_TYPE_RINGTONE;
158 _E("Failed to get sound type : %d", ret);
159 sound_type = SOUND_TYPE_RINGTONE;
166 void _mm_func(sound_type_e type, unsigned int volume, void *data)
168 bool bt_opened = false;
170 _D("mm func is called type : %d, volume : %d", type, volume);
171 if (type == volume_control_get_sound_type_at_show()) {
172 _D("current show type : %d, volume : %d", type, volume);
173 /* Need to check sound type & device in media type volume. */
174 if (type == SOUND_TYPE_MEDIA) {
175 int sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
176 _D("sound status : %d", sound);
178 int vibration = volume_sound_vconf_status_get(TYPE_VCONF_VIBRATION_STATUS);
179 _D("vibration : %d", vibration);
180 volume_view_volume_icon_set(type, sound, vibration, bt_opened);
182 if (VOLUME_ERROR_OK != volume_view_slider_value_set(volume))
183 _E("Failed to set slider value");
187 void volume_sound_mm_sound_init(void)
190 int ret = sound_manager_add_volume_changed_cb(_mm_func, NULL, &sound_info.sound_changed_callback_id);
191 if (ret != SOUND_MANAGER_ERROR_NONE)
192 _E("Failed to set volume changed event[%d]", ret);
195 int volume_sound_level_get(sound_type_e type)
198 if (sound_manager_get_volume(type, &val) < 0) {
199 _E("Failed to get Volume step");
206 int volume_sound_level_set(sound_type_e type, int val)
209 ret = sound_manager_set_volume(type, val);
214 void volume_sound_change_set(int val)
216 sound_type_e sound_type = volume_control_get_sound_type_at_show();
217 _D("sound type at show : %d", sound_type);
219 int sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
220 _D("sound status : %d", sound);
223 if (sound_type != SOUND_TYPE_MEDIA) {
224 if (!volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS)) {
225 volume_sound_vconf_status_set(TYPE_VCONF_SOUND_STATUS, 1);
226 volume_sound_vconf_status_set(TYPE_VCONF_VIBRATION_STATUS, 0);
229 if (volume_sound_level_set(sound_type, val) != 0)
230 volume_sound_level_set(sound_type, 9);
234 if (sound_type != SOUND_TYPE_MEDIA)
235 volume_sound_vconf_status_set(TYPE_VCONF_SOUND_STATUS, 0);
237 if (VOLUME_ERROR_OK != volume_view_slider_value_set(0))
238 _E("Failed to set slider value");
240 volume_sound_level_set(sound_type, 0);
242 if (sound_type == SOUND_TYPE_RINGTONE) {
243 volume_sound_vconf_status_set(TYPE_VCONF_VIBRATION_STATUS, 1);
244 volume_sound_vib_play();
249 void volume_sound_vconf_status_set(volume_vconf_type_e type, int val)
251 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;
274 case TYPE_VCONF_SOUND_STATUS:
275 vconfkey = VCONFKEY_SETAPPL_SOUND_STATUS_BOOL;
277 case TYPE_VCONF_VIBRATION_STATUS:
278 vconfkey = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL;
281 _E("Failed to get vconfkey : Type error");
285 if (vconf_get_bool(vconfkey, &ret) < 0) {
286 _E("Failed to get vconfkey : %s", vconfkey);
293 void volume_sound_vconfkey_register(void)
295 if (vconf_notify_key_changed(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, _sound_status_changed_cb, NULL) < 0)
296 _E("Failed to notify vconfkey : VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
298 if (vconf_notify_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, _sound_status_changed_cb, NULL) < 0)
299 _E("Failed to notify vconfkey : VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");
300 _sound_status_changed_cb(NULL, NULL);
303 void volume_sound_vconfkey_unregister(void)
305 if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, _sound_status_changed_cb) < 0)
306 _E("Failed to ignore vconfkey : VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
308 if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, _sound_status_changed_cb) < 0)
309 _E("Failed to ignore vconfkey : VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");
312 static int _setting_sound_enabled(void)
316 if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &snd_status) < 0)
317 _E("Failed to get vconfkey : VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
325 static void _sound_status_changed_cb(keynode_t *key, void *data)
327 bool bt_opened = false;
328 const char *keyname = vconf_keynode_get_name(key);
330 _D("keyname : %s", keyname);
332 sound_type_e sound_type = volume_control_get_sound_type_at_show();
333 _D("sound type at show : %d", sound_type);
335 int sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
336 _D("sound status : %d", sound);
337 sound_info.sound_status = sound;
339 int vibration = volume_sound_vconf_status_get(TYPE_VCONF_VIBRATION_STATUS);
340 _D("vibration : %d", vibration);
341 sound_info.vibration_status = vibration;
343 if (sound == 0 && vibration == 1)
344 _D("vibration mode");
345 else if (sound == 1 && vibration == 0) {
347 sound_info.is_vibration = EINA_FALSE;
348 } else if (sound == 0 && vibration == 0) {
350 sound_info.is_vibration = EINA_FALSE;
353 volume_view_volume_icon_set(sound_type, sound, vibration, bt_opened);