4 * Copyright 2012 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://www.tizenopensource.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.
20 #include <net_connection.h>
21 #include <dbus/dbus.h>
24 #include "mh_common_utility.h"
25 #include "mobile_hotspot.h"
27 void _handle_network_cellular_state_changed_cb(keynode_t *key, void *data)
29 if (key == NULL || data == NULL) {
30 ERR("Parameter is NULL\n");
33 mh_appdata_t *ad = (mh_appdata_t *)data;
36 if (vconf_keynode_get_type(key) != VCONF_TYPE_INT) {
37 ERR("Invalid vconf key type\n");
41 vconf_key = vconf_keynode_get_int(key);
42 SDBG("key = %s, value = %d(int)\n",
43 vconf_keynode_get_name(key), vconf_key);
45 if (vconf_key != VCONFKEY_NETWORK_CELLULAR_FLIGHT_MODE)
49 evas_object_del(ad->popup);
52 if (ad->is_wifi_teth_enabling) {
53 _update_wifi_item(ad, MH_STATE_NONE);
54 ad->is_wifi_teth_enabling = false;
56 if (ad->is_bt_teth_enabling) {
57 _update_bt_item(ad, MH_STATE_NONE);
58 ad->is_bt_teth_enabling = false;
60 if (ad->is_usb_teth_enabling) {
61 _update_usb_item(ad, MH_STATE_NONE);
62 ad->is_usb_teth_enabling = false;
67 void _device_name_changed_cb(keynode_t *key, void *data)
69 if (key == NULL || data == NULL) {
70 ERR("Parameter is NULL\n");
74 mh_appdata_t *ad = (mh_appdata_t *)data;
75 char *dev_name = NULL;
77 if (vconf_keynode_get_type(key) != VCONF_TYPE_STRING) {
78 ERR("Invalid vconf key type\n");
81 dev_name = vconf_keynode_get_str(key);
82 if (ad->setup.name_item != NULL)
83 elm_genlist_item_update(ad->setup.name_item);
85 if (ad->main.help_item != NULL)
86 elm_genlist_item_update(ad->main.help_item);
88 if (ad->rename_popup) {
89 elm_entry_entry_set(ad->rename_entry, dev_name);
90 elm_entry_cursor_end_set(ad->rename_entry);
92 if (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI)
93 _update_wifi_item(ad, MH_STATE_PROCESS);
98 Evas_Object *_create_progressbar(Evas_Object *parent, const char *style)
100 if (parent == NULL || style == NULL) {
101 ERR("Invalid param\n");
105 Evas_Object *progressbar;
107 progressbar = elm_progressbar_add(parent);
108 if (progressbar == NULL) {
109 ERR("progressbar is NULL\n");
113 elm_object_style_set(progressbar, style);
114 elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
115 elm_progressbar_pulse(progressbar, EINA_TRUE);
116 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
117 evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
118 evas_object_show(progressbar);
123 Evas_Object *_create_bg(Evas_Object *parent, const char *style)
125 __MOBILE_AP_FUNC_ENTER__;
127 if (parent == NULL || style == NULL) {
128 ERR("The param is NULL\n");
132 Evas_Object *bg = NULL;
134 bg = elm_bg_add(parent);
140 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
141 elm_object_style_set(bg, style);
142 evas_object_show(bg);
147 Evas_Object *_create_win_layout(mh_appdata_t *ad)
149 __MOBILE_AP_FUNC_ENTER__;
151 if (ad->win == NULL) {
152 ERR("There is no main window\n");
159 layout = elm_layout_add(ad->win);
160 if (layout == NULL) {
161 ERR("layout is NULL\n");
165 elm_layout_theme_set(layout, "layout", "application", "default");
166 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
169 bg = _create_bg(layout, "group_list");
172 evas_object_del(layout);
175 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
177 evas_object_show(layout);
182 __MOBILE_AP_FUNC_EXIT__;
187 Evas_Object *_create_naviframe(Evas_Object *parent)
189 __MOBILE_AP_FUNC_ENTER__;
191 if (parent == NULL) {
192 ERR("parent is NULL\n");
196 Evas_Object *naviframe;
198 naviframe = elm_naviframe_add(parent);
199 if (naviframe == NULL) {
200 ERR("naviframe is NULL\n");
203 evas_object_show(naviframe);
205 __MOBILE_AP_FUNC_EXIT__;
210 Evas_Object *_create_button(Evas_Object *parent, const char *text, const char *part,
211 Evas_Smart_Cb func, void *user_data)
213 if (parent == NULL || text == NULL || part == NULL || func == NULL) {
214 ERR("Invalid param\n");
220 btn = elm_button_add(parent);
221 elm_object_style_set(btn, "popup");
222 elm_object_domain_translatable_text_set(btn, PACKAGE, text);
223 elm_object_part_content_set(parent, part, btn);
224 evas_object_smart_callback_add(btn, "clicked", func, user_data);
225 evas_object_show(btn);
230 void _handle_mobileap_syspopup_popup_response(keynode_t *key, void *data)
233 ERR("The param is NULL\n");
237 if (vconf_keynode_get_type(key) != VCONF_TYPE_INT) {
238 ERR("Invalid vconf key\n");
242 mh_appdata_t *ad = (mh_appdata_t *)data;
245 vconf_key = vconf_keynode_get_int(key);
248 if (vconf_set_int(VCONF_KEY_MOBILEAP_SYSPOPUP_RESPONSE, 0) < 0)
249 ERR("vconf_set_int is failed\n");
251 if (ad->type != TETHERING_TYPE_WIFI) {
252 DBG("no need to handle user response\n");
256 evas_object_del(ad->popup);
259 if (ad->popup_checkbox) {
260 evas_object_del(ad->popup_checkbox);
261 ad->popup_checkbox = NULL;
264 _update_wifi_item(ad, MH_STATE_NONE);
268 void _handle_usb_status_change(keynode_t *key, void *data)
273 ERR("The param is NULL\n");
277 mh_appdata_t *ad = (mh_appdata_t *)data;
279 if (vconf_keynode_get_type(key) != VCONF_TYPE_INT) {
280 ERR("Invalid vconf key\n");
284 vconf_key = vconf_keynode_get_int(key);
285 if (vconf_key == SETTING_USB_NONE_MODE)
288 if (vconf_key == VCONFKEY_SYSMAN_USB_DISCONNECTED) {
289 if (ad->type == TETHERING_TYPE_USB && ad->popup) {
290 evas_object_del(ad->popup);
292 _update_tethering_item(ad, MH_STATE_NONE);
294 if (ad->main.usb_item)
295 elm_object_item_disabled_set(ad->main.usb_item, EINA_TRUE);
297 if (ad->main.usb_item)
298 elm_object_item_disabled_set(ad->main.usb_item, EINA_FALSE);
302 int _get_vconf_hotspot_mode(void)
304 int value = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
306 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &value) < 0) {
307 ERR("vconf_get_int is failed\n");
310 DBG("%s : %d\n", VCONFKEY_MOBILE_HOTSPOT_MODE, value);
315 Eina_Bool _get_no_of_connected_device(mh_appdata_t *ad, int *no, tethering_type_e type)
318 ERR("Invalid param\n");
322 if (ad->client_list == NULL) {
328 tethering_client_h handle;
329 tethering_type_e type2;
330 tethering_error_e ret;
333 for (l = ad->client_list; l != NULL; l = g_slist_next(l)) {
338 ret = tethering_client_get_tethering_type(handle, &type2);
339 if (ret != TETHERING_ERROR_NONE) {
340 ERR("tethering_client_get_tethering_type is failed [0x%X]\n", ret);
344 if (type != TETHERING_TYPE_ALL && type != type2)
354 void _append_list_client_handle(mh_appdata_t *ad, tethering_client_h client)
356 if (ad == NULL || client == NULL) {
357 ERR("Invalid param\n");
362 tethering_client_h handle;
364 ret = tethering_client_clone(&handle, client);
365 if (ret != TETHERING_ERROR_NONE) {
366 ERR("Unable to clone client handle");
370 ad->client_list = g_slist_append(ad->client_list, handle);
375 void _release_list_client_handle(mh_appdata_t *ad)
378 ERR("Invalid param\n");
382 if (ad->client_list == NULL)
386 tethering_client_h handle;
388 for (l = ad->client_list; l != NULL; l = g_slist_next(l)) {
393 tethering_client_destroy(handle);
396 g_slist_free(ad->client_list);
397 ad->client_list = NULL;
402 static int __find_mac_address(gconstpointer a, gconstpointer b)
404 tethering_client_h handle = (tethering_client_h)a;
405 const char *udn = (const char *)b;
409 ret = tethering_client_get_mac_address(handle, &mac_addr);
410 if (ret != TETHERING_ERROR_NONE)
413 ret = g_ascii_strcasecmp(mac_addr, udn);
421 void _delete_list_client_handle(mh_appdata_t *ad, const char *mac_addr)
423 if (ad == NULL || mac_addr == NULL) {
424 ERR("Invalid param\n");
429 tethering_client_h handle = NULL;
431 l = g_slist_find_custom(ad->client_list, mac_addr, __find_mac_address);
437 handle = (tethering_client_h)l->data;
438 ad->client_list = g_slist_delete_link(ad->client_list, l);
442 tethering_client_destroy(handle);
446 int _get_list_clients_count(mh_appdata_t *ad)
448 int client_list_counts;
451 ERR("Invalid param\n");
455 client_list_counts = g_slist_length(ad->client_list);
456 if (client_list_counts > TETHERING_WIFI_MAX_CONNECTED_STA) {
457 INFO("client_list_counts = [%d]\n", client_list_counts);
458 return TETHERING_WIFI_MAX_CONNECTED_STA;
460 return client_list_counts;
463 void _get_list_clients_informations(mh_appdata_t *ad)
466 ERR("Invalid param\n");
471 tethering_client_h handle;
474 tethering_type_e type = 0;
476 char *mac_addr = NULL;
478 for (l = ad->client_list; l != NULL; l = g_slist_next(l), i++) {
479 handle = (tethering_client_h)l->data;
481 ret = tethering_client_get_name(handle, &name);
482 if (ret != TETHERING_ERROR_NONE)
483 ERR("tethering_client_get_name is failed : %d\n", ret);
485 ret = tethering_client_get_mac_address(handle, &mac_addr);
486 if (ret != TETHERING_ERROR_NONE)
487 ERR("tethering_client_get_mac_address is failed : %d\n", ret);
489 ret = tethering_client_get_tethering_type(handle, &type);
490 if (ret != TETHERING_ERROR_NONE)
491 ERR("tethering_client_get_tethering_type is failed : %d\n", ret);
493 SDBG("Client[%d] : %s\n", i, name);
499 SDBG("MAC[%d] : %s\n", i, mac_addr);
504 SDBG("Type[%d] : %d\n", i, type);
510 void _free_genlist_item(Elm_Object_Item **item)
515 elm_object_item_del(*item);
519 void _free_genlist_itc(Elm_Genlist_Item_Class **itc)
524 elm_genlist_item_class_free(*itc);
528 int _get_sim_state(void)
532 if (vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &value) < 0)
533 ERR("vconf_get_int is failed\n");
535 DBG("%s : %d\n", VCONFKEY_TELEPHONY_SIM_SLOT, value);
536 if (value == VCONFKEY_TELEPHONY_SIM_INSERTED)
539 #if defined TIZEN_FEATURE_DUALSIM_ENABLE
540 if (vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT2, &value) < 0) {
541 ERR("vconf_get_int is failed\n");;
543 DBG("%s : %d\n", VCONFKEY_TELEPHONY_SIM_SLOT2, value);
549 connection_cellular_state_e _get_cellular_state(void)
552 connection_h handle = NULL;
553 connection_cellular_state_e cellular_state;
555 ret = connection_create(&handle);
556 if (ret != CONNECTION_ERROR_NONE) {
557 ERR("Connection create failed");
558 return CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
560 ret = connection_get_cellular_state(handle, &cellular_state);
561 if (ret != CONNECTION_ERROR_NONE) {
562 ERR("connection_get_cellular_state() is failed : %d\n", ret);
563 connection_destroy(handle);
564 return CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
567 connection_destroy(handle);
568 return cellular_state;
571 int _get_checkbox_status(tethering_type_e type)
574 char *vconf_key = NULL;
576 if (type == TETHERING_TYPE_WIFI)
577 vconf_key = VCONF_MOBILE_AP_WIFI_POPUP_CHECKBOX_STATUS;
578 else if (type == TETHERING_TYPE_BT)
579 vconf_key = VCONF_MOBILE_AP_BT_POPUP_CHECKBOX_STATUS;
580 else if (type == TETHERING_TYPE_USB)
581 vconf_key = VCONF_MOBILE_AP_USB_POPUP_CHECKBOX_STATUS;
584 if (vconf_get_int(vconf_key, &value) < 0) {
585 ERR("vconf_get_int() is failed\n");
588 DBG("%s : %d\n", vconf_key, value);
592 bool _set_checkbox_status(tethering_type_e type, int value)
594 char *vconf_key = NULL;
596 if (type == TETHERING_TYPE_WIFI)
597 vconf_key = VCONF_MOBILE_AP_WIFI_POPUP_CHECKBOX_STATUS;
598 else if (type == TETHERING_TYPE_BT)
599 vconf_key = VCONF_MOBILE_AP_BT_POPUP_CHECKBOX_STATUS;
600 else if (type == TETHERING_TYPE_USB)
601 vconf_key = VCONF_MOBILE_AP_USB_POPUP_CHECKBOX_STATUS;
605 if (vconf_set_int(vconf_key, value) < 0) {
606 ERR("vconf_set_int is failed\n");
612 bool _set_vconf_prev_wifi_state(bool value)
614 if (vconf_set_bool(VCONF_MOBILE_AP_PREV_WIFI_STATUS, value) < 0) {
615 ERR("vconf_set_bool failed\n");
621 bool _get_vconf_prev_wifi_state()
625 if (vconf_get_bool(VCONF_MOBILE_AP_PREV_WIFI_STATUS, &value) < 0) {
626 ERR("vconf_get_bool is failed\n");
629 DBG("%s : %d\n", VCONF_MOBILE_AP_PREV_WIFI_STATUS, value);
631 return value ? true : false;