3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
29 #include <mm_sound_private.h>
31 #include <feedback-ids.h>
37 #define SOUND_CONF_FILE FEEDBACK_SYS_RO_SHARE"/feedback/sound.conf"
40 #ifndef VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL
41 #define VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL "db/setting/sound/button_sounds"
45 static int touch_sndstatus;
46 static int keytone_sndstatus;
47 static struct feedback_config_info sound_info = {
51 static char *get_data(feedback_pattern_e pattern)
57 if (pattern <= FEEDBACK_PATTERN_NONE ||
58 pattern >= profile->max_pattern)
61 for (i = 0; i < profile->get_num_of_pattern(); i++) {
62 if (pattern == sound_info.data[i].pattern) {
68 _E("Not supported pattern : %d", pattern);
72 if (sound_info.data[index].changed)
73 data = sound_info.data[index].changed;
75 data = sound_info.data[index].origin;
80 inline int is_sound_mode(void)
85 inline int is_touch_sndstatus(void)
87 return touch_sndstatus;
90 inline int is_keytone_sndstatus(void)
92 return keytone_sndstatus;
95 //LCOV_EXCL_START Not called Callback
96 static void feedback_touch_sndstatus_cb(keynode_t *key, void* data)
98 touch_sndstatus = vconf_keynode_get_bool(key);
101 static void feedback_keytone_sndstatus_cb(keynode_t *key, void* data)
103 keytone_sndstatus = vconf_keynode_get_bool(key);
107 static void sound_init(void)
112 feedback_load_config(SOUND_CONF_FILE, &sound_info);
114 /* check sound status */
115 if (vconf_get_bool(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, &touch_sndstatus) < 0)
116 _W("VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL ==> FAIL!!"); //LCOV_EXCL_LINE
118 if (vconf_get_bool(VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL, &keytone_sndstatus) < 0)
119 _W("VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL ==> FAIL!!"); //LCOV_EXCL_LINE
121 if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sndstatus) < 0) {
122 _D("fail to get sound status, will work as turning off"); //LCOV_EXCL_LINE
126 /* add watch for status value */
127 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, feedback_touch_sndstatus_cb, NULL);
129 _W("Add watch for VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL failed");
130 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL, feedback_keytone_sndstatus_cb, NULL);
132 _W("Add watch for VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL failed");
135 static void sound_exit(void)
140 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, feedback_touch_sndstatus_cb);
142 _W("Remove watch for VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL failed");
143 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL, feedback_keytone_sndstatus_cb);
145 _W("Remove watch for VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL failed");
147 /* free sound data */
148 feedback_free_config(&sound_info);
151 static int sound_play(feedback_pattern_e pattern)
154 int retry = FEEDBACK_RETRY_CNT, ret;
158 if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sndstatus) < 0) {
159 _D("fail to get sound status, will work as turning off"); //LCOV_EXCL_LINE
163 if (sndstatus == 0 && profile->get_always_alert_case &&
164 !profile->get_always_alert_case(FEEDBACK_TYPE_SOUND, pattern)) {
165 _D("Sound condition is OFF (sndstatus : %d)", sndstatus); //LCOV_EXCL_LINE
169 if (sndstatus && profile->get_always_off_case &&
170 profile->get_always_off_case(FEEDBACK_TYPE_SOUND, pattern)) {
171 _D("Sound always off condition(pattern %s)", profile->str_pattern(pattern)); //LCOV_EXCL_LINE
175 /* get sound file path */
176 path = get_data(pattern);
177 if (!path || stat(path, &buf)) {
178 _E("Not supported sound pattern(pattern %d)", pattern); //LCOV_EXCL_LINE
182 /* play sound file */
184 if (profile->get_strength_type)
185 level = profile->get_strength_type(FEEDBACK_TYPE_SOUND, pattern);
187 level = VOLUME_TYPE_SYSTEM;
189 ret = mm_sound_play_keysound(path, level);
190 if (ret == MM_ERROR_NONE) {
191 _D("Play success! SND filename is %s", path);
194 _E("mm_sound_play_keysound() returned error(%d)", ret); //LCOV_EXCL_LINE
200 static int sound_is_supported(feedback_pattern_e pattern, bool *supported)
207 _E("Invalid parameter : supported(NULL)"); //LCOV_EXCL_LINE
211 /* get sound file path */
212 path = get_data(pattern);
213 if (!path || stat(path, &buf)) {
214 _D("%d is not presents", pattern);
222 //LCOV_EXCL_START Not used function
223 static int sound_get_path(feedback_pattern_e pattern, char *buf, unsigned int buflen)
228 if (!buf || buflen <= 0)
231 /* get sound file path */
232 cur_path = get_data(pattern);
234 _E("This pattern(%s) in sound type is not supported to play",
235 profile->str_pattern(pattern));
240 snprintf(buf, buflen, "%s", cur_path);
245 //LCOV_EXCL_START Not used function
246 static int sound_set_path(feedback_pattern_e pattern, char *path)
253 * check the path is valid
254 * if path is null, below operation is ignored
256 if (path && stat(path, &buf)) {
257 _E("%s is not presents", path);
261 if (!profile->str_pattern(pattern)) {
262 _E("%d is not supported", pattern);
266 for (i = 0; i < profile->get_num_of_pattern(); i++) {
267 if (pattern == sound_info.data[i].pattern) {
274 for (i = 0; i < profile->get_num_of_pattern(); i++) {
275 if (sound_info.data[i].pattern != -1)
278 sound_info.data[i].pattern = pattern;
279 sound_info.data[i].changed = strdup(path);
280 _D("The file of pattern(%s) is changed to [%s]",
281 profile->str_pattern(pattern), path);
285 _E("%d is not supported", pattern);
289 if (sound_info.data[index].changed) {
290 free(sound_info.data[index].changed);
291 sound_info.data[index].changed = NULL;
294 /* if path is NULL, this pattern set to default file */
296 sound_info.data[index].changed = strdup(path);
298 _D("The file of pattern(%s) is changed to [%s]",
299 profile->str_pattern(pattern), path);
304 static const struct device_ops sound_device_ops = {
305 .type = FEEDBACK_TYPE_SOUND,
310 .is_supported = sound_is_supported,
311 .get_path = sound_get_path,
312 .set_path = sound_set_path,
315 DEVICE_OPS_REGISTER(&sound_device_ops);