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 if (!TIZEN_FEATURE_BT_USB_DONGLE)
75 _bt_disable_adapter();
77 if (adapter_status_le == BT_LE_ACTIVATED) {
78 int bt_le_status_before_mode = 0;
80 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status_before_mode) == 0)
81 _bt_core_set_bt_le_status(BT_POWER_SAVING_MODE, bt_le_status_before_mode);
83 if (!TIZEN_FEATURE_BT_USB_DONGLE)
84 _bt_disable_adapter_le();
87 int ps_mode_value = 0;
89 if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &ps_mode_value))
90 BT_ERR("Fail get power saving mode value");
92 if (ps_mode_value == 0)
95 BT_DBG("Activate Bluetooth");
96 if (vconf_set_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, 0))
97 BT_ERR("Set vconf failed");
99 ret_if(__bt_off_cause_conflict_check());
101 BT_DBG("BT status before Emergency mode() :%d",
102 _bt_core_get_bt_status(BT_POWER_SAVING_MODE));
104 if (adapter_status == BT_DEACTIVATED && (_bt_core_get_bt_status(BT_POWER_SAVING_MODE) != 0)) {
105 _bt_core_set_bt_status(BT_POWER_SAVING_MODE, 0);
106 _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
107 if (!TIZEN_FEATURE_BT_USB_DONGLE)
108 _bt_enable_adapter();
110 BT_DBG("BT LE status before Emergency mode() :%d", _bt_core_get_bt_le_status(BT_POWER_SAVING_MODE));
111 if (adapter_status_le == BT_LE_DEACTIVATED && _bt_core_get_bt_le_status(BT_POWER_SAVING_MODE) != 0) {
112 _bt_core_set_bt_le_status(BT_POWER_SAVING_MODE, 0);
113 /* Enable the BT LE */
114 _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
115 if (!TIZEN_FEATURE_BT_USB_DONGLE)
116 _bt_enable_adapter_le();
121 void _bt_core_init_vconf_value(void)
123 gboolean flight_mode = FALSE;
124 int power_saving_mode = 0;
125 int bt_flight_mode = 0;
128 //_bt_core_handle_flight_mode_noti();
129 flight_mode = _bt_core_is_flight_mode_enabled();
131 if (!TIZEN_PROFILE_WEARABLE) {
132 if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_saving_mode) != 0)
133 BT_ERR("Fail to get the power_saving_mode status value");
134 BT_DBG("flight_mode = %d, power_saving_mode = %d", flight_mode, power_saving_mode);
137 BT_DBG("flight_mode = %d, power_saving_mode = %d", flight_mode, power_saving_mode);
139 if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &bt_flight_mode))
140 BT_ERR("Fail get flight mode value");
141 _bt_core_set_bt_status(BT_FLIGHT_MODE, bt_flight_mode);
143 if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &bt_ps_mode))
144 BT_ERR("Fail get power saving mode value");
145 _bt_core_set_bt_status(BT_POWER_SAVING_MODE, bt_ps_mode);
147 if (power_saving_mode > 0)
148 __bt_core_handle_adapter_with_power_saving_mode(power_saving_mode);
153 void _bt_core_unregister_vconf_handler(void)