Add TIZEN_FEATURE_EMULATOR feature for emulator
[apps/native/ug-mobile-ap.git] / src / mh_func_onoff.c
1 /*
2 * ug-mobile-ap
3 *
4 * Copyright 2012  Samsung Electronics Co., Ltd
5
6 * Licensed under the Flora License, Version 1.0 (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
9
10 * http://www.tizenopensource.org/license
11
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.
17 *
18 */
19
20 #include <stdlib.h>
21 #include <glib.h>
22
23 #include "mh_func_onoff.h"
24 #include "mh_popup.h"
25 #include "mh_string.h"
26
27 static bool is_wifi_tethering_checkbox_popup_active = false;
28
29 void _update_tethering_enabling_item(mh_appdata_t *ad, tethering_type_e type, mh_state_e state)
30 {
31         switch (type) {
32         case TETHERING_TYPE_WIFI:
33                 _update_wifi_item(ad, MH_STATE_NONE);
34                 ad->is_wifi_teth_enabling = false;
35                 break;
36         case TETHERING_TYPE_BT:
37                 _update_bt_item(ad, MH_STATE_NONE);
38                 ad->is_bt_teth_enabling = false;
39                 break;
40         case TETHERING_TYPE_USB:
41                 _update_usb_item(ad, MH_STATE_NONE);
42                 ad->is_usb_teth_enabling = false;
43                 break;
44         default:
45                 ERR("invalid type \n");
46                 break;
47         }
48 }
49 void _wifi_tethering_checkbox_popup_status_set(bool value)
50 {
51         is_wifi_tethering_checkbox_popup_active = value;
52 }
53
54 bool _wifi_tethering_checkbox_popup_status_get(void)
55 {
56         return is_wifi_tethering_checkbox_popup_active;
57 }
58
59 int _get_vconf_usb_state()
60 {
61         int value = VCONFKEY_SYSMAN_USB_DISCONNECTED;
62
63         if (vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, &value) < 0) {
64                 ERR("vconf_get_int is failed\n");
65                 return 0;
66         }
67         DBG("%s : %d\n", VCONFKEY_SYSMAN_USB_STATUS, value);
68
69         return value;
70 }
71
72 void _update_tethering_item(mh_appdata_t * ad, mh_state_e state)
73 {
74         ERR("type : %d state : %d\n", ad->type, state);
75         switch (ad->type) {
76         case TETHERING_TYPE_WIFI:
77                 _update_wifi_item(ad, state);
78                 break;
79         case TETHERING_TYPE_BT:
80                 _update_bt_item(ad, state);
81                 break;
82         case TETHERING_TYPE_USB:
83                 _update_usb_item(ad, state);
84                 break;
85         default:
86                 break;
87         }
88 }
89
90 gboolean _ps_recheck_timeout_cb(gpointer data)
91 {
92         connection_cellular_state_e cellular_state = _get_cellular_state();
93         mh_appdata_t *ad = (mh_appdata_t *)data;
94         static int recheck_count = 0;
95
96         DBG("Re-Check cellular state (%d)\n", recheck_count);
97
98         if (cellular_state == CONNECTION_CELLULAR_STATE_FLIGHT_MODE) {
99                 _update_tethering_item(ad, MH_STATE_NONE);
100                 recheck_count = 0;
101                 return FALSE;
102         }
103
104         if (cellular_state == CONNECTION_CELLULAR_STATE_CONNECTED ||
105                 cellular_state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
106                 if (ad->type == TETHERING_TYPE_WIFI) {
107                         if (_create_wifi_hotspot_on_popup(ad) < 0) {
108                                 ERR("__create_wifi_hotspot_on_popup fail\n");
109                                 _update_tethering_item(ad, MH_STATE_NONE);
110                                 recheck_count = 0;
111                                 return FALSE;
112                         }
113                 _send_signal_qp(QP_SIGNAL_PROGRESS_ON);
114                 } else if (ad->type == TETHERING_TYPE_BT && _create_bt_tethering_on_popup(ad) < 0) {
115                                 ERR("_create_bt_tethering_on_popup fail\n");
116                                 _update_tethering_item(ad, MH_STATE_NONE);
117                                 recheck_count = 0;
118                                 return FALSE;
119                 } else if (ad->type == TETHERING_TYPE_USB && _create_usb_tethering_on_popup(ad) < 0) {
120                                 ERR("__create_usb_hotspot_on_popup fail\n");
121                                 _update_tethering_item(ad, MH_STATE_NONE);
122                                 recheck_count = 0;
123                                 return FALSE;
124                 } else {
125                         ERR("Unknown tethering type \n");
126                         recheck_count = 0;
127                         return FALSE;
128                 }
129         } else {
130                 if (++recheck_count >= PS_RECHECK_COUNT_MAX) {
131                         DBG("Cellular network is not connected : %d\n", cellular_state);
132                         _update_tethering_item(ad, MH_STATE_NONE);
133                         _prepare_popup(MH_POPUP_NETWORK_OUT_OF_RANGE, STR_NO_DATA_SERVICE);
134                         _create_popup(ad);
135                         recheck_count = 0;
136                         return FALSE;
137                 }
138                 return TRUE;
139         }
140         recheck_count = 0;
141         return FALSE;
142 }
143
144 static bool __is_connected_wifi_net(mh_appdata_t *ad)
145 {
146         connection_wifi_state_e wifi_state = CONNECTION_WIFI_STATE_DEACTIVATED;
147         int ret;
148
149         ret = connection_get_wifi_state(ad->conn_handle, &wifi_state);
150         if (ret != CONNECTION_ERROR_NONE) {
151                 ERR("connection_get_wifi_state() is failed : %d\n");
152                 return false;
153         }
154
155         if (wifi_state != CONNECTION_WIFI_STATE_CONNECTED) {
156                 ERR("Wi-Fi network is not connected : %d\n", wifi_state);
157                 return false;
158         }
159
160         DBG("Wi-Fi network is connected\n");
161         return true;
162 }
163
164 static bool __is_connected_ethernet_net(mh_appdata_t *ad)
165 {
166         connection_ethernet_state_e ethernet_state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
167         int ret;
168
169         ret = connection_get_ethernet_state(ad->conn_handle, &ethernet_state);
170         if (ret != CONNECTION_ERROR_NONE) {
171                 ERR("connection_get_ethernet_state() is failed : %d\n");
172                 return false;
173         }
174
175         if (ethernet_state != CONNECTION_ETHERNET_STATE_CONNECTED) {
176                 ERR("Ethernet network is not connected : %d\n", ethernet_state);
177                 return false;
178         }
179
180         DBG("Ethernet network is connected\n");
181         return true;
182 }
183
184 static int __is_preconditions_handled(mh_appdata_t *ad)
185 {
186         DBG("+\n");
187
188         connection_cellular_state_e cellular_state = CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
189         int dnet_state = 0;
190
191         /* check ethernet connection */
192         if (__is_connected_ethernet_net(ad)) {
193                 DBG("ethernet network is connected\n");
194                 return 1;
195         }
196
197         /*  check wifi connection */
198         if (ad->type != TETHERING_TYPE_WIFI) {
199                 if (__is_connected_wifi_net(ad)) {
200                         DBG("wifi network is connected\n");
201                         return 1;
202                 }
203         }
204
205         /* Check SIM state */
206         if (_get_sim_state() != VCONFKEY_TELEPHONY_SIM_INSERTED) {
207                 if (ad->type == TETHERING_TYPE_WIFI)
208                         _prepare_popup(MH_POPUP_NO_SIM, STR_INSERT_SIM_TO_USE_TETH);
209                 else
210                         _prepare_popup(MH_POPUP_NO_SIM, STR_CONN_MOBILE_DATA_TO_USE_TETH);
211
212                 _create_popup(ad);
213                 return -1;
214         }
215
216         /* Check cellular state */
217         cellular_state = _get_cellular_state();
218         DBG("cellular state is :  %d \n", cellular_state);
219         if (cellular_state == CONNECTION_CELLULAR_STATE_FLIGHT_MODE) {
220                 _prepare_popup(MH_POPUP_FLIGHT_MODE, STR_DISABLE_FLIGHT_MODE_MSG);
221                 _create_popup(ad);
222                 ERR("Flight mode is ON\n");
223                 return -1;
224         } else {
225                 if (vconf_get_bool(VCONFKEY_3G_ENABLE , &dnet_state) < 0) {
226                         ERR("vconf_get_bool is failed\n");
227                 } else if (dnet_state == 0) {
228                         DBG("Data Network is not connected");
229                         _prepare_popup(MH_POPUP_MOBILE_DATA_OFF, STR_NO_NET_CONN_MSG);
230                         _create_popup(ad);
231                         return 0;
232                 }
233                 if (cellular_state != CONNECTION_CELLULAR_STATE_CONNECTED &&
234                         cellular_state != CONNECTION_CELLULAR_STATE_AVAILABLE) {
235                         if (ad->ps_recheck_timer_id > 0) {
236                                 g_source_remove(ad->ps_recheck_timer_id);
237                                 ad->ps_recheck_timer_id = 0;
238                                 if (ad->is_wifi_teth_enabling == true
239                                                 && ad->type != TETHERING_TYPE_WIFI)
240                                         _update_tethering_enabling_item(ad, TETHERING_TYPE_WIFI,
241                                                                                                         MH_STATE_NONE);
242                                 if (ad->is_bt_teth_enabling == true
243                                                 && ad->type != TETHERING_TYPE_BT)
244                                         _update_tethering_enabling_item(ad, TETHERING_TYPE_BT,
245                                                                                                         MH_STATE_NONE);
246                                 if (ad->is_usb_teth_enabling == true
247                                                 && ad->type != TETHERING_TYPE_USB)
248                                         _update_tethering_enabling_item(ad, TETHERING_TYPE_USB,
249                                                                                                         MH_STATE_NONE);
250                         }
251                         ad->ps_recheck_timer_id = g_timeout_add(PS_RECHECK_INTERVAL,
252                                                                                 _ps_recheck_timeout_cb, (void*)ad);
253                         return 0;
254                 }
255         }
256
257         DBG("-\n");
258         return 1;
259 }
260
261 int _create_wifi_hotspot_on_popup(mh_appdata_t *ad)
262 {
263         char *fmt = NULL;
264         char *str = NULL;
265         bool wifi_state = false;
266         int value = 0;
267
268         wifi_is_activated(&wifi_state);
269         _set_vconf_prev_wifi_state(wifi_state);
270         value = _get_checkbox_status(TETHERING_TYPE_WIFI);
271         if (0 == value) {
272                 if (wifi_state == true || _is_wifi_direct_on() == true)
273                         fmt = STR_TETH_ON_DESC_1;
274                 else
275                         fmt = STR_TETH_ON_DESC_2;
276
277                 str = g_malloc0(MH_LABEL_LENGTH_MAX);
278                 if (str == NULL) {
279                         ERR("memory allocation is failed\n");
280                         return -1;
281                 }
282                 snprintf(str, MH_LABEL_LENGTH_MAX, fmt, TETHERING_WIFI_MAX_CONNECTED_STA);
283                 _wifi_tethering_checkbox_popup_status_set(true);
284                 _prepare_popup(MH_POPUP_WIFI_ON_CHECKBOX, str);
285                 g_free(str);
286                 _create_popup(ad);
287         } else {
288                 _prepare_popup_type(MH_POPUP_WIFI_ON_CHECKBOX);
289                 _teth_on(ad);
290         }
291         return 0;
292 }
293
294 int _create_bt_tethering_on_popup(mh_appdata_t *ad)
295 {
296         char *fmt = STR_TETH_ON_DESC_2;
297         char *str = NULL;
298         int value = 0;
299         value = _get_checkbox_status(TETHERING_TYPE_BT);
300         if (0 == value) {
301                 str = g_malloc0(MH_LABEL_LENGTH_MAX);
302                 if (str == NULL) {
303                         ERR("memory allocation is failed\n");
304                         return -1;
305                 }
306                 snprintf(str, MH_LABEL_LENGTH_MAX, fmt,
307                                 TETHERING_BT_MAX_CONNECTED_STA);
308                 _prepare_popup(MH_POPUP_BT_ON_CHECKBOX, str);
309                 g_free(str);
310                 _create_popup(ad);
311         } else {
312                 _prepare_popup_type(MH_POPUP_BT_ON_CHECKBOX);
313                 _teth_on(ad);
314         }
315         return 0;
316 }
317
318 int _create_usb_tethering_on_popup(mh_appdata_t *ad)
319 {
320         int value = 0;
321         char *str = NULL;
322         value = _get_checkbox_status(TETHERING_TYPE_USB);
323         DBG("%s : %d\n", VCONF_MOBILE_AP_USB_POPUP_CHECKBOX_STATUS, value);
324         if (0 == value) {
325                 str = g_malloc0(MH_LABEL_LENGTH_MAX);
326                 if (str == NULL) {
327                         ERR("memory allocation is failed\n");
328                         return -1;
329                 }
330                 snprintf(str, MH_LABEL_LENGTH_MAX, "%s",
331                                 STR_TETH_ON_DESC_3);
332                 _prepare_popup(MH_POPUP_USB_ON_CHECKBOX, str);
333                 g_free(str);
334                 _create_popup(ad);
335         } else {
336                 _prepare_popup_type(MH_POPUP_USB_ON_CHECKBOX);
337                 _teth_on(ad);
338         }
339         return 0;
340 }
341
342 static void __disable_tethering_by_ind(mh_appdata_t *ad, tethering_disabled_cause_e cause)
343 {
344         if (ad == NULL) {
345                 ERR("Param is NULL\n");
346                 return;
347         }
348
349         DBG("cause : %d\n", cause);
350         switch (cause) {
351         case TETHERING_DISABLED_BY_WIFI_ON:
352                 break;
353
354         case TETHERING_DISABLED_BY_BT_OFF:
355                 break;
356
357         case TETHERING_DISABLED_BY_USB_DISCONNECTION:
358                 if (ad->is_bt_teth_enabling && ad->main.bt_item) {
359                         _update_bt_item(ad, MH_STATE_NONE);
360                         ad->is_bt_teth_enabling = false;
361                 }
362                 if (ad->is_wifi_teth_enabling && ad->main.wifi_item) {
363                         _update_wifi_item(ad, MH_STATE_NONE);
364                         ad->is_wifi_teth_enabling = false;
365                 }
366                 break;
367
368         case TETHERING_DISABLED_BY_FLIGHT_MODE:
369                 break;
370
371         case TETHERING_DISABLED_BY_TIMEOUT:
372                 break;
373
374         case TETHERING_DISABLED_BY_OTHERS:
375                 if (ad->main.wifi_item && _get_vconf_prev_wifi_state() == true)
376                         elm_object_item_disabled_set(ad->main.wifi_item, EINA_TRUE);
377                 break;
378
379         case TETHERING_DISABLED_BY_LOW_BATTERY:
380                 break;
381
382         default:
383                 break;
384         }
385
386         return;
387 }
388
389 /* Wi-Fi callbacks */
390 static void __wifi_activated_cb(wifi_error_e result, void *user_data)
391 {
392         DBG("+\n");
393
394         return;
395 }
396
397 /* Tethering callbacks */
398 void _enabled_cb(tethering_error_e result, tethering_type_e type, bool is_requested, void *user_data)
399 {
400         DBG("+\n");
401         DBG("result : %d, type : %d, is_requested : %d\n", result, type, is_requested);
402
403         if (user_data == NULL) {
404                 ERR("user_data is NULL\n");
405                 return;
406         }
407
408         mh_appdata_t *ad = (mh_appdata_t *)user_data;
409
410         if (!is_requested) {
411                 if (ad->type == type && ad->popup) {
412                         DBG("This tethering type is already enabled\n");
413                         evas_object_del(ad->popup);
414                         ad->popup = NULL;
415                 }
416                 _update_main_view(ad, type);
417                 return;
418         }
419
420         _update_main_view(ad, type);
421
422         return;
423 }
424
425 void _disabled_cb(tethering_error_e result, tethering_type_e type, tethering_disabled_cause_e cause, void *user_data)
426 {
427         DBG("+\n");
428         DBG("result : %d, type : %d, cause : %d\n", result, type, cause);
429
430         if (user_data == NULL) {
431                 ERR("user_data is NULL\n");
432                 return;
433         }
434
435         mh_appdata_t *ad = (mh_appdata_t *)user_data;
436
437         if (cause != TETHERING_DISABLED_BY_REQUEST) {
438                 if (ad->type == type && ad->popup) {
439                         DBG("This tethering type is already disabled\n");
440                         evas_object_del(ad->popup);
441                         ad->popup = NULL;
442                 }
443                 __disable_tethering_by_ind(ad, cause);
444                 _update_main_view(ad, type);
445                 return;
446         }
447
448         if (result != TETHERING_ERROR_NONE) {
449                 _prepare_popup(MH_POPUP_TETH_ENABLING_FAILED, STR_UNABLE_TO_USE_TETH);
450                 _create_popup(ad);
451                 _update_main_view(ad, type);
452                 return;
453         }
454
455         if (ad->main.wifi_item && type == TETHERING_TYPE_WIFI && _get_vconf_prev_wifi_state() == true)
456                 elm_object_item_disabled_set(ad->main.wifi_item, EINA_TRUE);
457
458         _update_main_view(ad, type);
459
460         return;
461 }
462
463 void _connection_changed_cb(tethering_client_h client, bool is_opened, void *user_data)
464 {
465         DBG("+\n");
466
467         if (user_data == NULL) {
468                 ERR("user_data is NULL\n");
469                 return;
470         }
471
472         mh_appdata_t *ad = (mh_appdata_t *)user_data;
473         char *mac_addr = NULL;
474
475         if (is_opened) {
476                 _append_list_client_handle(ad, client);
477
478 #ifdef TETHERING_DATA_USAGE_SUPPORT
479                 if (ad->is_foreground && _get_list_clients_count(ad) == 1)
480                         _start_update_data_packet_usage(ad);
481 #endif
482         } else {
483                 tethering_client_get_mac_address(client, &mac_addr);
484                 if (mac_addr) {
485                         _delete_list_client_handle(ad, mac_addr);
486                         free(mac_addr);
487                 }
488 #ifdef TETHERING_DATA_USAGE_SUPPORT
489                 if (ad->is_foreground && _get_list_clients_count(ad) == 0)
490                         _stop_update_data_packet_usage(ad);
491 #endif
492         }
493
494         ap_update_data_device(ad);
495
496         return;
497 }
498
499 void _wifi_state_changed_cb(wifi_device_state_e state, void *user_data)
500 {
501         if (user_data == NULL) {
502                 ERR("user_data is NULL\n");
503                 return;
504         }
505
506         DBG("+\n");
507
508         mh_appdata_t *ad = (mh_appdata_t *)user_data;
509         char *str = NULL;
510         char *fmt = NULL;
511         if (state == WIFI_DEVICE_STATE_ACTIVATED) {
512                 if (ad->main.wifi_item && elm_object_item_disabled_get(ad->main.wifi_item))
513                         elm_object_item_disabled_set(ad->main.wifi_item, EINA_FALSE);
514                 _set_vconf_prev_wifi_state(false);
515         } else if (state == WIFI_DEVICE_STATE_DEACTIVATED) {
516                 _set_vconf_prev_wifi_state(true);
517         }
518
519         if (ad->type == TETHERING_TYPE_WIFI && ad->popup && ad->popup_checkbox &&
520                         _wifi_tethering_checkbox_popup_status_get()) {
521                 evas_object_del(ad->popup_checkbox);
522                 ad->popup_checkbox = NULL;
523                 evas_object_del(ad->popup);
524                 ad->popup = NULL;
525                 if (state == WIFI_DEVICE_STATE_ACTIVATED)
526                         fmt = STR_TETH_ON_DESC_1;
527                 else
528                         fmt = STR_TETH_ON_DESC_2;
529
530                 str = g_malloc0(MH_LABEL_LENGTH_MAX);
531                 if (str == NULL) {
532                         ERR("memory allocation is failed\n");
533                         return;
534                 }
535                 snprintf(str, MH_LABEL_LENGTH_MAX, fmt, TETHERING_WIFI_MAX_CONNECTED_STA);
536                 _prepare_popup(MH_POPUP_WIFI_ON_CHECKBOX, str);
537                 g_free(str);
538                 _create_popup(ad);
539         }
540         DBG("-\n");
541 }
542
543 void _visibility_changed_cb(bool is_visible, void *user_data)
544 {
545         DBG("+\n");
546
547         if (user_data == NULL) {
548                 ERR("user_data is NULL\n");
549                 return;
550         }
551
552         mh_appdata_t *ad = (mh_appdata_t *)user_data;
553
554         if (ad->setup.visibility == is_visible)
555                 return;
556
557         ad->setup.visibility = is_visible;
558         ad->setup.visibility_new = is_visible;
559         if (ad->setup.hide_item)
560                 elm_genlist_item_update(ad->setup.hide_item);
561
562         DBG("-\n");
563
564         return;
565 }
566
567 void _security_type_changed_cb(tethering_wifi_security_type_e changed_type, void *user_data)
568 {
569         DBG("+\n");
570
571         if (user_data == NULL) {
572                 ERR("user_data is NULL\n");
573                 return;
574         }
575
576         mh_appdata_t *ad = (mh_appdata_t *)user_data;
577
578         if (ad->setup.security_type == changed_type)
579                 return;
580
581         ad->setup.security_type = changed_type;
582         ad->setup.security_type_new = changed_type;
583
584         if (ad->setup.security_item)
585                 elm_genlist_item_update(ad->setup.security_item);
586
587         DBG("-\n");
588
589         return;
590 }
591
592 void _passphrase_changed_cb(void *user_data)
593 {
594         DBG("+\n");
595
596         if (user_data == NULL) {
597                 ERR("user_data is NULL\n");
598                 return;
599         }
600
601         mh_appdata_t *ad = (mh_appdata_t *)user_data;
602         char *passphrase = NULL;
603         int ret;
604
605         ret = tethering_wifi_get_passphrase(ad->handle, &passphrase);
606         if (ret != TETHERING_ERROR_NONE) {
607                 ERR("tethering_wifi_get_passphrase failed ret = [0x%x]\n", ret);
608                 return;
609         }
610
611         if (!g_strcmp0(passphrase, ad->setup.wifi_passphrase))
612                 goto DONE;
613
614         g_strlcpy(ad->setup.wifi_passphrase, passphrase,
615                 sizeof(ad->setup.wifi_passphrase));
616
617         g_strlcpy(ad->setup.wifi_passphrase_new, passphrase,
618                 sizeof(ad->setup.wifi_passphrase_new));
619
620         if (ad->setup.pw_item)
621                 elm_genlist_item_update(ad->setup.pw_item);
622
623 DONE:
624         g_free(passphrase);
625         DBG("-\n");
626         return;
627 }
628
629 #ifdef TETHERING_DATA_USAGE_SUPPORT
630 void _data_usage_cb(tethering_error_e result, unsigned long long received_data, unsigned long long sent_data, void *user_data)
631 {
632         if (user_data == NULL) {
633                 ERR("user_data is NULL\n");
634                 return;
635         }
636
637         mh_appdata_t *ad = (mh_appdata_t *)user_data;
638
639         if (ad->data_statistics.pdp_total_sent != sent_data ||
640                         ad->data_statistics.pdp_total_receive != received_data) {
641                 ad->data_statistics.pdp_total_sent = sent_data;
642                 ad->data_statistics.pdp_total_receive = received_data;
643                 ap_update_data_packet_usage(ad);
644         }
645
646         ad->data_statistics.is_updated = true;
647
648         return;
649 }
650 #endif
651 /* End of Tethering callbacks */
652
653 int _handle_wifi_onoff_change(mh_appdata_t *ad)
654 {
655         __MOBILE_AP_FUNC_ENTER__;
656
657         int ret;
658         int connected_wifi_clients = 0;
659
660         /* Turn off WiFi hotspot */
661         if (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) {
662                 if (_get_no_of_connected_device(ad, &connected_wifi_clients,
663                                         TETHERING_TYPE_WIFI) == EINA_FALSE) {
664                         ERR("Getting the number of connected device is failed\n");
665                 }
666                 if (connected_wifi_clients > 0) {
667                         _prepare_popup(MH_POPUP_WIFI_OFF, STR_CLOSE_INTERNET_Q);
668                         _create_popup(ad);
669                 } else {
670 #ifndef TIZEN_FEATURE_EMULATOR
671                         ret = tethering_disable(ad->handle, TETHERING_TYPE_WIFI);
672                         if (ret != TETHERING_ERROR_NONE) {
673                                 ERR("wifi tethering off is failed : %d\n", ret);
674                                 return -1;
675                         }
676 #endif
677                         _send_signal_qp(QP_SIGNAL_PROGRESS_OFF);
678                 }
679                 return 0;
680         }
681
682         /* Turn on WiFi hotspot */
683         ret = __is_preconditions_handled(ad);
684         if (ret < 0)
685                 return -1;
686         else if (ret == 0)
687                 return 0;
688
689         if (_create_wifi_hotspot_on_popup(ad) < 0) {
690                 ERR("__create_wifi_hotspot_on_popup fail\n");
691                 return -1;
692         }
693
694         __MOBILE_AP_FUNC_EXIT__;
695
696         return 0;
697 }
698
699 int _handle_bt_onoff_change(mh_appdata_t *ad)
700 {
701         __MOBILE_AP_FUNC_ENTER__;
702
703         int ret;
704
705         /* Turn off Bluetooth tethering */
706         if (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_BT) {
707 #ifndef TIZEN_FEATURE_EMULATOR
708                 ret = tethering_disable(ad->handle, TETHERING_TYPE_BT);
709                 if (ret) {
710                         ERR("Error disable bt tethering [%d]\n", ret);
711                         return -1;
712                 }
713 #endif
714                 return 0;
715         }
716
717         /* Turn on Bluetooth tethering */
718         ret = __is_preconditions_handled(ad);
719         if (ret < 0)
720                 return -1;
721         else if (ret == 0)
722                 return 0;
723
724         if (_create_bt_tethering_on_popup(ad) < 0) {
725                 ERR("_create_bt_tethering_on_popup fail\n");
726                 return -1;
727         }
728
729         __MOBILE_AP_FUNC_EXIT__;
730
731         return 0;
732 }
733
734 int _handle_usb_onoff_change(mh_appdata_t *ad)
735 {
736         __MOBILE_AP_FUNC_ENTER__;
737
738         int ret;
739
740         /* Turn off USB tethering */
741         if (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_USB) {
742 #ifndef TIZEN_FEATURE_EMULATOR
743                 ret = tethering_disable(ad->handle, TETHERING_TYPE_USB);
744                 if (ret) {
745                         ERR("Error disable usb tethering : %d\n", ret);
746                         return -1;
747                 }
748 #endif
749                 return 0;
750         }
751
752         /* Turn on USB tethering */
753         ret = __is_preconditions_handled(ad);
754         if (ret < 0)
755                 return -1;
756         else if (ret == 0)
757                 return 0;
758
759         if (_create_usb_tethering_on_popup(ad) < 0) {
760                 ERR("_create_usb_tethering_on_popup fail\n");
761                 return -1;
762         }
763
764         __MOBILE_AP_FUNC_EXIT__;
765
766         return 0;
767 }
768
769 int _turn_on_wifi(void)
770 {
771         int ret;
772
773         ret = wifi_activate(__wifi_activated_cb, NULL);
774         if (ret != WIFI_ERROR_NONE) {
775                 ERR("wifi_activate() is failed : %d\n", ret);
776                 return -1;
777         }
778
779         return 0;
780 }
781
782 bool _is_wifi_direct_on(void)
783 {
784         int wifi_direct_state = 0;
785         int ret;
786
787         ret = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state);
788         if (ret < 0) {
789                 ERR("vconf_get_int() is failed : %d\n", ret);
790                 return false;
791         }
792
793         return wifi_direct_state != 0 ? true : false;
794 }