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");
92 sound_info.is_vibration = EINA_TRUE;
95 void volume_sound_play(void)
97 sound_type_e sound_type = volume_control_get_sound_type_at_show();
98 _D("sound type at show : %d", sound_type);
100 ret_if(sound_type == SOUND_TYPE_ALARM);
101 ret_if(sound_type == SOUND_TYPE_MEDIA);
102 ret_if(sound_type == SOUND_TYPE_VOICE);
103 ret_if(sound_type == SOUND_TYPE_NOTIFICATION);
105 _D("Play Feedback : sound");
106 if(FEEDBACK_ERROR_NONE != feedback_play(FEEDBACK_PATTERN_VOLUME_KEY)) {
107 _E("Failed to play feedback");
113 void volume_sound_setting_sound_play(void)
115 int snd_enabled = _setting_sound_enabled();
116 _D("snd_enabled(%d)", snd_enabled);
119 volume_sound_feedback_play(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_TAP);
122 int volume_sound_sound_manager_step_get(sound_type_e type)
124 _D("volume sound manager step get");
125 int ret = -1, step = 0;
127 ret = sound_manager_get_max_volume(type, &step);
128 retvm_if(ret < 0, -1, "Failed to get step");
130 sound_info.sound_step = step;
135 int volume_sound_sound_manager_volume_get(sound_type_e type)
137 int ret = -1, val = 0;
138 ret = sound_manager_get_volume(type, &val);
139 retvm_if(ret < 0, -1, "Failed to get volume");
143 sound_type_e volume_sound_sound_manager_type_get(void)
145 _D(" Volume sound manager type get");
147 sound_type_e sound_type = -1;
149 ret = sound_manager_get_current_sound_type(&sound_type);
150 _D("ret: %d, sound type: %d", ret, sound_type);
152 case SOUND_MANAGER_ERROR_NONE:
155 case SOUND_MANAGER_ERROR_NO_PLAYING_SOUND:
156 _D("NO playing sound");
157 sound_type = SOUND_TYPE_RINGTONE;
160 _E("Failed to get sound type : %d", ret);
161 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_add_volume_changed_cb(_mm_func, NULL, &sound_info.sound_changed_callback_id);
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);
239 volume_view_slider_value_set(0);
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;
254 case TYPE_VCONF_SOUND_STATUS:
255 vconfkey = VCONFKEY_SETAPPL_SOUND_STATUS_BOOL;
257 case TYPE_VCONF_VIBRATION_STATUS:
258 vconfkey = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL;
261 _E("Failed to set vconfkey : Type error");
265 if (vconf_set_bool(vconfkey, val) < 0)
266 _E("Failed to set vconfkey : %s", vconfkey);
269 int volume_sound_vconf_status_get(volume_vconf_type_e type)
272 char *vconfkey = NULL;
276 case TYPE_VCONF_SOUND_STATUS:
277 vconfkey = VCONFKEY_SETAPPL_SOUND_STATUS_BOOL;
279 case TYPE_VCONF_VIBRATION_STATUS:
280 vconfkey = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL;
283 _E("Failed to get vconfkey : Type error");
287 if (vconf_get_bool(vconfkey, &ret) < 0) {
288 _E("Failed to get vconfkey : %s", vconfkey);
295 void volume_sound_vconfkey_register(void)
297 if (vconf_notify_key_changed(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, _sound_status_changed_cb, NULL) < 0)
298 _E("Failed to notify vconfkey : VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
300 if (vconf_notify_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, _sound_status_changed_cb, NULL) < 0)
301 _E("Failed to notify vconfkey : VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");
302 _sound_status_changed_cb(NULL, NULL);
305 void volume_sound_vconfkey_unregister(void)
307 if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, _sound_status_changed_cb) < 0)
308 _E("Failed to ignore vconfkey : VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
310 if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, _sound_status_changed_cb) < 0)
311 _E("Failed to ignore vconfkey : VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL");
314 static int _setting_sound_enabled(void)
318 if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &snd_status) < 0)
319 _E("Failed to get vconfkey : VCONFKEY_SETAPPL_SOUND_STATUS_BOOL");
327 static void _sound_status_changed_cb(keynode_t *key, void *data)
329 bool bt_opened = false;
330 const char *keyname = vconf_keynode_get_name(key);
332 _D("keyname : %s", keyname);
334 sound_type_e sound_type = volume_control_get_sound_type_at_show();
335 _D("sound type at show : %d", sound_type);
337 int sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
338 _D("sound status : %d", sound);
339 sound_info.sound_status = sound;
341 int vibration = volume_sound_vconf_status_get(TYPE_VCONF_VIBRATION_STATUS);
342 _D("vibration : %d", vibration);
343 sound_info.vibration_status = vibration;
345 if (sound == 0 && vibration == 1)
346 _D("vibration mode");
347 else if (sound == 1 && vibration == 0) {
349 sound_info.is_vibration = EINA_FALSE;
350 } else if (sound == 0 && vibration == 0) {
352 sound_info.is_vibration = EINA_FALSE;
355 volume_view_volume_icon_set(sound_type, sound, vibration, bt_opened);