4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungbae Shin <seungbae.shin@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #include <sys/types.h>
32 #include <vconf-keys.h>
36 #include "../include/mm_sound_private.h"
37 #include "../include/mm_sound.h"
38 #include "../include/mm_sound_common.h"
39 #include "../include/mm_sound_utils.h"
41 static mm_sound_route g_valid_route[] = {
42 MM_SOUND_ROUTE_OUT_SPEAKER, MM_SOUND_ROUTE_OUT_RECEIVER, MM_SOUND_ROUTE_OUT_WIRED_ACCESSORY, MM_SOUND_ROUTE_OUT_BLUETOOTH_SCO, MM_SOUND_ROUTE_OUT_BLUETOOTH_A2DP,
43 MM_SOUND_ROUTE_OUT_DOCK, MM_SOUND_ROUTE_OUT_HDMI, MM_SOUND_ROUTE_OUT_MIRRORING, MM_SOUND_ROUTE_OUT_USB_AUDIO, MM_SOUND_ROUTE_OUT_MULTIMEDIA_DOCK,
44 MM_SOUND_ROUTE_IN_MIC, MM_SOUND_ROUTE_IN_WIRED_ACCESSORY, MM_SOUND_ROUTE_IN_MIC_OUT_RECEIVER,
45 MM_SOUND_ROUTE_IN_MIC_OUT_SPEAKER, MM_SOUND_ROUTE_IN_MIC_OUT_HEADPHONE,
46 MM_SOUND_ROUTE_INOUT_HEADSET, MM_SOUND_ROUTE_INOUT_BLUETOOTH
49 #define MM_SOUND_DEFAULT_VOLUME_SYSTEM 9
50 #define MM_SOUND_DEFAULT_VOLUME_NOTIFICATION 11
51 #define MM_SOUND_DEFAULT_VOLUME_ALARAM 7
52 #define MM_SOUND_DEFAULT_VOLUME_RINGTONE 11
53 #define MM_SOUND_DEFAULT_VOLUME_MEDIA 7
54 #define MM_SOUND_DEFAULT_VOLUME_CALL 4
55 #define MM_SOUND_DEFAULT_VOLUME_VOIP 4
56 #define MM_SOUND_DEFAULT_VOLUME_VOICE 7
57 #define MM_SOUND_DEFAULT_VOLUME_ANDROID 0
59 static char *g_volume_vconf[VOLUME_TYPE_MAX] = {
60 VCONF_KEY_VOLUME_TYPE_SYSTEM, /* VOLUME_TYPE_SYSTEM */
61 VCONF_KEY_VOLUME_TYPE_NOTIFICATION, /* VOLUME_TYPE_NOTIFICATION */
62 VCONF_KEY_VOLUME_TYPE_ALARM, /* VOLUME_TYPE_ALARM */
63 VCONF_KEY_VOLUME_TYPE_RINGTONE, /* VOLUME_TYPE_RINGTONE */
64 VCONF_KEY_VOLUME_TYPE_MEDIA, /* VOLUME_TYPE_MEDIA */
65 VCONF_KEY_VOLUME_TYPE_CALL, /* VOLUME_TYPE_CALL */
66 VCONF_KEY_VOLUME_TYPE_VOIP, /* VOLUME_TYPE_VOIP */
67 VCONF_KEY_VOLUME_TYPE_VOICE, /* VOLUME_TYPE_VOICE */
68 VCONF_KEY_VOLUME_TYPE_ANDROID /* VOLUME_TYPE_FIXED */
70 static char *g_volume_str[VOLUME_TYPE_MAX] = {
83 int mm_sound_util_get_valid_route_list(mm_sound_route **route_list)
85 *route_list = g_valid_route;
87 return (int)(sizeof(g_valid_route) / sizeof(mm_sound_route));
91 bool mm_sound_util_is_route_valid(mm_sound_route route)
93 mm_sound_route *route_list = 0;
95 int route_list_count = 0;
97 route_list_count = mm_sound_util_get_valid_route_list(&route_list);
98 for (route_index = 0; route_index < route_list_count; route_index++) {
99 if (route_list[route_index] == route)
107 void mm_sound_util_get_devices_from_route(mm_sound_route route, mm_sound_device_in *device_in, mm_sound_device_out *device_out)
109 if (device_in && device_out) {
110 *device_in = route & 0x00FF;
111 *device_out = route & 0xFFF00;
116 int mm_sound_util_volume_add_callback(volume_type_t type, void *func, void* user_data)
118 if (vconf_notify_key_changed(g_volume_vconf[type], func, user_data)) {
119 debug_error ("vconf_notify_key_changed failed..\n");
120 return MM_ERROR_SOUND_INTERNAL;
123 return MM_ERROR_NONE;
127 int mm_sound_util_volume_remove_callback(volume_type_t type, void *func)
129 if (vconf_ignore_key_changed(g_volume_vconf[type], func)) {
130 debug_error ("vconf_ignore_key_changed failed..\n");
131 return MM_ERROR_SOUND_INTERNAL;
134 return MM_ERROR_NONE;
138 int mm_sound_util_volume_get_value_by_type(volume_type_t type, unsigned int *value)
140 int ret = MM_ERROR_NONE;
143 /* Get volume value from VCONF */
144 if (vconf_get_int(g_volume_vconf[type], &vconf_value)) {
145 debug_error ("vconf_get_int(%s) failed..\n", g_volume_vconf[type]);
146 return MM_ERROR_SOUND_INTERNAL;
149 *value = vconf_value;
150 if (ret == MM_ERROR_NONE)
151 debug_log("volume_get_value %s %d", g_volume_str[type], *value);
157 int mm_sound_util_volume_set_value_by_type(volume_type_t type, unsigned int value)
159 int ret = MM_ERROR_NONE;
163 debug_log("volume_set_value %s %d", g_volume_str[type], value);
165 /* Set volume value to VCONF */
166 if ((ret = vconf_set_int(g_volume_vconf[type], vconf_value)) != 0) {
167 debug_error ("vconf_set_int(%s) failed..ret[%d]\n", g_volume_vconf[type], ret);
168 if (ret == -EPERM || ret == -EACCES)
169 return MM_ERROR_SOUND_PERMISSION_DENIED;
171 return MM_ERROR_SOUND_INTERNAL;
177 int mm_sound_util_get_earjack_type (int *type)
179 int earjack_status = 0;
182 debug_error ("invalid parameter!!!");
183 return MM_ERROR_INVALID_ARGUMENT;
186 /* Get actual vconf value */
187 vconf_get_int(VCONFKEY_SYSMAN_EARJACK, &earjack_status);
188 debug_msg ("[%s] get status=[%d]\n", VCONFKEY_SYSMAN_EARJACK, earjack_status);
190 *type = (earjack_status >= 0)? earjack_status : VCONFKEY_SYSMAN_EARJACK_REMOVED;
192 return MM_ERROR_NONE;
196 int mm_sound_util_get_dock_type (int *type)
201 debug_error ("invalid parameter!!!");
202 return MM_ERROR_INVALID_ARGUMENT;
205 /* Get actual vconf value */
206 vconf_get_int(VCONFKEY_SYSMAN_CRADLE_STATUS, &dock_status);
207 debug_msg ("[%s] get dock status=[%d]\n", VCONFKEY_SYSMAN_CRADLE_STATUS, dock_status);
211 return MM_ERROR_NONE;
215 bool mm_sound_util_is_recording (void)
217 int capture_status = 0;
225 bool mm_sound_util_is_mute_policy (void)
227 int setting_sound_status = true;
229 /* If sound is mute mode, force ringtone/notification path to headset */
230 vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &setting_sound_status);
231 debug_log ("[%s] setting_sound_status=%d\n", VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, setting_sound_status);
233 return !setting_sound_status;
237 bool mm_sound_util_is_process_alive(pid_t pid)
242 if (pid > 999999 || pid < 2)
245 if ((tmp = g_strdup_printf("/proc/%d", pid))) {
246 ret = access(tmp, F_OK);
251 if (errno == ENOENT) {
252 debug_warning ("/proc/%d not exist", pid);
255 debug_error ("/proc/%d access errno[%d]", pid, errno);
257 /* FIXME: error occured but file exists */