2 * Copyright (c) 2011 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.
19 #include <vconf-keys.h>
21 #include "bt-core-adapter.h"
22 #include "bt-core-common.h"
23 #include "bt-core-noti-handler.h"
25 static gboolean flightmode_request = FALSE;
27 void _bt_set_flightmode_request(gboolean value)
29 flightmode_request = value;
32 gboolean _bt_is_flightmode_request(void)
34 return flightmode_request;
37 static gboolean __bt_off_cause_conflict_check(void)
39 int flight_mode_value = 0;
40 int ps_mode_value = 0;
43 retv_if(vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE,
44 &flight_mode_value) != 0, FALSE);
45 retv_if(vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE,
46 &ps_mode_value) != 0, FALSE);
48 if (flight_mode_value == 1 || ps_mode_value > 0) {
49 BT_DBG("Bt should not turn on");
56 static void __bt_core_handle_adapter_with_power_saving_mode(int power_saving_mode)
58 bt_status_t adapter_status;
59 bt_le_status_t adapter_status_le;
61 adapter_status = _bt_core_get_status();
62 adapter_status_le = _bt_core_get_le_status();
64 if (power_saving_mode == 2) {
65 BT_DBG("Deactivate Bluetooth Service");
66 if (vconf_set_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, 1) != 0)
67 BT_ERR("Set vconf failed");
69 if (adapter_status == BT_ACTIVATED) {
70 int bt_status_before_mode = 0;
71 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status_before_mode) == 0)
72 _bt_core_set_bt_status(BT_POWER_SAVING_MODE, bt_status_before_mode);
74 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER);
76 if (!TIZEN_FEATURE_BT_USB_DONGLE)
77 _bt_disable_adapter();
79 if (adapter_status_le == BT_LE_ACTIVATED) {
80 int bt_le_status_before_mode = 0;
82 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status_before_mode) == 0)
83 _bt_core_set_bt_le_status(BT_POWER_SAVING_MODE, bt_le_status_before_mode);
85 /* Disable the BT LE */
86 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
88 if (!TIZEN_FEATURE_BT_USB_DONGLE)
89 _bt_disable_adapter_le();
92 int ps_mode_value = 0;
94 if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &ps_mode_value))
95 BT_ERR("Fail get power saving mode value");
97 if (ps_mode_value == 0)
100 BT_DBG("Activate Bluetooth");
101 if (vconf_set_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, 0))
102 BT_ERR("Set vconf failed");
104 ret_if(__bt_off_cause_conflict_check());
106 BT_DBG("BT status before Emergency mode() :%d",
107 _bt_core_get_bt_status(BT_POWER_SAVING_MODE));
109 if (adapter_status == BT_DEACTIVATED && (_bt_core_get_bt_status(BT_POWER_SAVING_MODE) != 0)) {
110 _bt_core_set_bt_status(BT_POWER_SAVING_MODE, 0);
111 _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
112 if (!TIZEN_FEATURE_BT_USB_DONGLE)
113 _bt_enable_adapter();
115 BT_DBG("BT LE status before Emergency mode() :%d", _bt_core_get_bt_le_status(BT_POWER_SAVING_MODE));
116 if (adapter_status_le == BT_LE_DEACTIVATED && _bt_core_get_bt_le_status(BT_POWER_SAVING_MODE) != 0) {
117 _bt_core_set_bt_le_status(BT_POWER_SAVING_MODE, 0);
118 /* Enable the BT LE */
119 _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
120 if (!TIZEN_FEATURE_BT_USB_DONGLE)
121 _bt_enable_adapter_le();
126 void _bt_core_init_vconf_value(void)
128 gboolean flight_mode = FALSE;
129 int power_saving_mode = 0;
130 int bt_flight_mode = 0;
133 //_bt_core_handle_flight_mode_noti();
134 flight_mode = _bt_core_is_flight_mode_enabled();
136 if (!TIZEN_PROFILE_WEARABLE) {
137 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_saving_mode) != 0)
138 BT_ERR("Fail to get the power_saving_mode status value");
139 BT_DBG("flight_mode = %d, power_saving_mode = %d", flight_mode, power_saving_mode);
142 BT_DBG("flight_mode = %d, power_saving_mode = %d", flight_mode, power_saving_mode);
144 if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &bt_flight_mode))
145 BT_ERR("Fail get flight mode value");
146 _bt_core_set_bt_status(BT_FLIGHT_MODE, bt_flight_mode);
148 if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &bt_ps_mode))
149 BT_ERR("Fail get power saving mode value");
150 _bt_core_set_bt_status(BT_POWER_SAVING_MODE, bt_ps_mode);
152 if (power_saving_mode > 0)
153 __bt_core_handle_adapter_with_power_saving_mode(power_saving_mode);
158 void _bt_core_unregister_vconf_handler(void)