4 * Copyright 2012-2013 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.1 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://floralicense.org/license
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <dbus/dbus.h>
22 #include <dbus/dbus-glib.h>
23 #include <dbus/dbus-glib-lowlevel.h>
25 #include "mobileap_agent.h"
26 #include "mobileap_common.h"
27 #include "mobileap_bluetooth.h"
28 #include "mobileap_wifi.h"
29 #include "mobileap_usb.h"
30 #include "mobileap_notification.h"
32 /* Need translation */
33 #define MH_NOTI_TIMEOUT_STR "Tap for setting"
34 #define MH_NOTI_TIMEOUT_TITLE "Disable tethering by timeout"
40 } sp_timeout_handler_t;
42 static gboolean __wifi_timeout_cb(gpointer user_data);
43 static gboolean __bt_timeout_cb(gpointer user_data);
45 static sp_timeout_handler_t sp_timeout_handler[MOBILE_AP_TYPE_MAX] = {
46 {0, __wifi_timeout_cb, NULL},
48 {0, __bt_timeout_cb, NULL}};
52 static void __handle_flight_mode_changed_cb(keynode_t *key, void *data)
55 ERR("Parameter is NULL\n");
59 TetheringObject *obj = (TetheringObject *)data;
62 if (!_mobileap_is_enabled(MOBILE_AP_STATE_WIFI)) {
63 DBG("Wi-Fi tethering is not enabled\n");
67 if (vconf_keynode_get_type(key) != VCONF_TYPE_BOOL) {
68 ERR("Invalid vconf key type\n");
72 vconf_key = vconf_keynode_get_bool(key);
73 DBG("key = %s, value = %d(bool)\n",
74 vconf_keynode_get_name(key), vconf_key);
76 if (vconf_key == FALSE)
80 _disable_wifi_tethering(obj);
81 _emit_mobileap_dbus_signal(obj, E_SIGNAL_FLIGHT_MODE, NULL);
86 static void __handle_device_name_changed_cb(keynode_t *key, void *data)
88 if (key == NULL || data == NULL) {
89 ERR("Parameter is NULL\n");
93 TetheringObject *obj = (TetheringObject *)data;
94 char *vconf_key = NULL;
96 if (!_mobileap_is_enabled(MOBILE_AP_STATE_WIFI)) {
97 DBG("Wi-Fi hotspot is not enabled\n");
101 if (vconf_keynode_get_type(key) != VCONF_TYPE_STRING) {
102 ERR("Invalid vconf key type\n");
106 vconf_key = vconf_keynode_get_str(key);
107 DBG("key = %s, value = %s(str)\n",
108 vconf_keynode_get_name(key), vconf_key);
110 if (g_strcmp0(vconf_key, obj->ssid) == 0) {
111 DBG("ssid is not changed\n");
113 DBG("ssid is changed\n");
114 _disable_wifi_tethering(obj);
120 void _register_vconf_cb(void *user_data)
122 if (user_data == NULL) {
123 ERR("Invalid param\n");
127 vconf_reg_t vconf_reg[] = {
128 {VCONFKEY_TELEPHONY_FLIGHT_MODE,
129 __handle_flight_mode_changed_cb, NULL},
130 {VCONFKEY_SETAPPL_DEVICE_NAME_STR,
131 __handle_device_name_changed_cb, NULL},
138 while (vconf_reg[i].key != NULL && vconf_reg[i].cb != NULL) {
139 DBG("Register [%d] : %s\n", i, vconf_reg[i].key);
140 ret = vconf_notify_key_changed(vconf_reg[i].key,
141 vconf_reg[i].cb, user_data);
143 ERR("vconf_notify_key_changed is failed : %d\n", ret);
146 if (vconf_reg[i].value) {
147 ret = vconf_get_int(vconf_reg[i].key,
150 ERR("vconf_get_int is failed : %d\n", ret);
160 void _unregister_vconf_cb(void *user_data)
162 if (user_data == NULL) {
163 ERR("Invalid param\n");
167 vconf_reg_t vconf_reg[] = {
168 {VCONFKEY_TELEPHONY_FLIGHT_MODE,
169 __handle_flight_mode_changed_cb, NULL},
170 {VCONFKEY_SETAPPL_DEVICE_NAME_STR,
171 __handle_device_name_changed_cb, NULL},
178 while (vconf_reg[i].key != NULL && vconf_reg[i].cb != NULL) {
179 DBG("Register [%d] : %s\n", i, vconf_reg[i].key);
180 ret = vconf_ignore_key_changed(vconf_reg[i].key,
183 ERR("vconf_notify_key_changed is failed : %d\n", ret);
192 static gboolean __wifi_timeout_cb(gpointer data)
196 ERR("data is NULL\n");
200 TetheringObject *obj = (TetheringObject *)data;
202 if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI) == FALSE) {
203 ERR("There is no conn. via Wi-Fi tethernig. But nothing to do\n");
207 _disable_wifi_tethering(obj);
208 _emit_mobileap_dbus_signal(obj,
209 E_SIGNAL_WIFI_TETHER_OFF, SIGNAL_MSG_TIMEOUT);
211 _create_timeout_noti(MH_NOTI_TIMEOUT_STR, MH_NOTI_TIMEOUT_TITLE,
218 static gboolean __bt_timeout_cb(gpointer data)
222 ERR("data is NULL\n");
226 TetheringObject *obj = (TetheringObject *)data;
228 if (_mobileap_is_enabled(MOBILE_AP_STATE_BT) == FALSE) {
229 ERR("There is no conn. via BT tethering. But nothing to do\n");
233 _disable_bt_tethering(obj);
234 _emit_mobileap_dbus_signal(obj,
235 E_SIGNAL_BT_TETHER_OFF, SIGNAL_MSG_TIMEOUT);
237 _create_timeout_noti(MH_NOTI_TIMEOUT_STR, MH_NOTI_TIMEOUT_TITLE,
243 void _init_timeout_cb(mobile_ap_type_e type, void *user_data)
246 if (sp_timeout_handler[type].func == NULL) {
247 DBG("Not supported timeout : type[%d]\n", type);
251 if (user_data == NULL) {
252 ERR("Invalid param\n");
256 if (sp_timeout_handler[type].src_id > 0) {
257 DBG("There is already registered timeout source\n");
258 g_source_remove(sp_timeout_handler[type].src_id);
259 sp_timeout_handler[type].src_id = 0;
262 sp_timeout_handler[type].user_data = user_data;
268 void _start_timeout_cb(mobile_ap_type_e type)
271 if (sp_timeout_handler[type].func == NULL) {
272 DBG("Not supported timeout : type[%d]\n", type);
276 if (sp_timeout_handler[type].src_id > 0) {
277 ERR("It is not registered or stopped\n");
281 sp_timeout_handler[type].src_id = g_timeout_add(TETHERING_CONN_TIMEOUT,
282 sp_timeout_handler[type].func,
283 sp_timeout_handler[type].user_data);
289 void _stop_timeout_cb(mobile_ap_type_e type)
292 if (sp_timeout_handler[type].func == NULL) {
293 DBG("Not supported timeout : type[%d]\n", type);
297 if (sp_timeout_handler[type].src_id == 0) {
298 ERR("It is not started yet\n");
302 g_source_remove(sp_timeout_handler[type].src_id);
303 sp_timeout_handler[type].src_id = 0;
309 void _deinit_timeout_cb(mobile_ap_type_e type) {
311 if (sp_timeout_handler[type].func == NULL) {
312 DBG("Not supported timeout : type[%d]\n", type);
316 if (sp_timeout_handler[type].src_id > 0) {
317 g_source_remove(sp_timeout_handler[type].src_id);
318 sp_timeout_handler[type].src_id = 0;
321 sp_timeout_handler[type].user_data = NULL;