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>
22 #include <bluetooth.h>
23 #include <bluetooth_internal.h>
24 #include <bluetooth_extension.h>
27 #include "_util_log.h"
33 static void _bt_display_bt_volume_view(sound_type_e sound_type, int sound, int vibration, bool bt_opened);
34 static void _bt_volume_changed_cb(int volume, void *user_data);
35 static void _bt_state_changed_cb(int result, bool opened, void *user_data);
36 static int _bt_register_changed_cb(void);
37 static int _bt_unregister_changed_cb(void);
39 int bt_get_bt_volume(void)
41 int ret = BT_ERROR_NONE;
44 ret = bt_ag_get_speaker_gain(&bt_vol);
46 if (ret != BT_ERROR_NONE) {
47 _E("bt_ag_get_speaker_gain Failed");
50 _D("bt vol: %d", bt_vol);
54 void bt_init_sco(void)
56 _D("SCO volume initialize");
57 if (BT_ERROR_NONE != bt_initialize())
58 _E("BT initialize failed");
60 if (_bt_register_changed_cb() != BT_ERROR_NONE)
61 _E("volume bt register changed cb failed");
64 void bt_fini_sco(void)
66 _D("SCO volume Deinitialize");
67 if (_bt_unregister_changed_cb() != BT_ERROR_NONE)
68 _E("volume bt Unregister changed cb failed");
70 if (BT_ERROR_NONE != bt_deinitialize())
71 _E("BT Deinitialize failed");
74 static void _bt_display_bt_volume_view(sound_type_e sound_type, int sound, int vibration, bool bt_opened)
76 if (VOLUME_ERROR_OK != volume_view_window_show(sound_type))
77 _E("Failed to show volume window");
79 volume_view_volume_icon_set(sound_type, sound, vibration, bt_opened);
82 static void _bt_volume_changed_cb(int volume, void *user_data)
84 bool bt_opened = false;
90 sound_type_e sound_type = 0;
91 _D("BT VOLUME is changed");
93 status = volume_control_check_status(&lock, &sound_type);
94 _D("status: %d, lock: %d, sound type : %d", status, lock, sound_type);
96 sound = volume_sound_vconf_status_get(TYPE_VCONF_SOUND_STATUS);
97 _D("sound status : %d", sound);
99 error = bt_ag_is_sco_opened(&bt_opened);
100 if (error != BT_ERROR_NONE)
101 _E("bt_ag_is_sco_opened return [%d]", error);
102 _D("BT state %d", bt_opened);
104 if (bt_opened == true && sound_type == SOUND_TYPE_CALL) {
105 _bt_display_bt_volume_view(sound_type, sound, vibration, bt_opened);
106 _D("BT SCO volume level is : %d", volume);
107 if (VOLUME_ERROR_OK != volume_view_slider_value_set(volume))
108 _E("Failed to set slider value");
110 volume_timer_add(3.0, TYPE_TIMER_BT);
114 static void _bt_state_changed_cb(int result, bool opened, void *user_data)
116 _D("SCO opened [%s]", opened ? "YES" : "NO");
119 static int _bt_register_changed_cb(void)
123 ret = bt_audio_initialize();
124 if (ret != BT_ERROR_NONE) {
125 _E("bt audio initialize failed");
129 ret = bt_ag_set_speaker_gain_changed_cb(_bt_volume_changed_cb, NULL);
130 if (ret != BT_ERROR_NONE) {
131 _E("register bt volume changed callback failed");
135 ret = bt_ag_set_sco_state_changed_cb(_bt_state_changed_cb, NULL);
136 if (ret != BT_ERROR_NONE)
137 _E("register bt state changed callback failed");
142 static int _bt_unregister_changed_cb(void)
146 ret = bt_audio_deinitialize();
147 if (ret != BT_ERROR_NONE) {
148 _E("bt audio initialize failed");
152 ret = bt_ag_unset_speaker_gain_changed_cb();
153 if (ret != BT_ERROR_NONE) {
154 _E("register bt volume changed callback failed");
158 ret = bt_ag_unset_sco_state_changed_cb();
159 if (ret != BT_ERROR_NONE)
160 _E("register bt state changed callback failed");