4 * Copyright 2012 Samsung Electronics Co., Ltd
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
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.
21 #define UG_MODULE_API __attribute__ ((visibility("default")))
24 //#include <setting-cfg.h>
26 #include "mobile_hotspot.h"
27 #include "mh_view_main.h"
28 #include "mh_func_onoff.h"
29 #include "mh_common_utility.h"
31 #include "mh_string.h"
32 #include "mh_view_wifi_setup.h"
34 //UG_MODULE_API int setting_plugin_search_init(app_control_h app_control, void * priv, char ** domainname);
36 static Evas_Object *create_content(mh_appdata_t *ad)
38 __MOBILE_AP_FUNC_ENTER__;
40 ad->naviframe = _create_naviframe(ad->layout);
41 _main_draw_contents(ad);
43 __MOBILE_AP_FUNC_EXIT__;
48 static void __set_callbacks(tethering_h handle, void *user_data)
54 ret = tethering_set_enabled_cb(handle, TETHERING_TYPE_ALL,
55 _enabled_cb, user_data);
56 if (ret != TETHERING_ERROR_NONE)
57 ERR("tethering_set_enabled_cb [0x%X]\n", ret);
59 ret = tethering_set_enabled_cb(handle, TETHERING_TYPE_RESERVED,
60 _enabled_cb, user_data);
61 if (ret != TETHERING_ERROR_NONE)
62 ERR("tethering_set_enabled_cb [0x%X]\n", ret);
64 ret = tethering_wifi_set_passphrase_changed_cb(handle,
65 _passphrase_changed_cb, user_data);
66 if (ret != TETHERING_ERROR_NONE)
67 ERR("tethering_wifi_set_passphrase_changed_cb [0x%X]\n", ret);
69 ret = tethering_wifi_set_ssid_visibility_changed_cb(handle,
70 _visibility_changed_cb, user_data);
71 if (ret != TETHERING_ERROR_NONE)
72 ERR("tethering_wifi_set_ssid_visibility_changed_cb [0x%X]\n", ret);
74 ret = tethering_wifi_set_security_type_changed_cb(handle,
75 _security_type_changed_cb, user_data);
76 if (ret != TETHERING_ERROR_NONE)
77 ERR("tethering_wifi_set_security_type_changed_cb [0x%X]\n", ret);
79 ret = tethering_set_disabled_cb(handle, TETHERING_TYPE_ALL,
80 _disabled_cb, user_data);
81 if (ret != TETHERING_ERROR_NONE)
82 ERR("tethering_set_disabled_cb [0x%X]\n", ret);
84 ret = tethering_set_disabled_cb(handle, TETHERING_TYPE_RESERVED,
85 _disabled_cb, user_data);
86 if (ret != TETHERING_ERROR_NONE)
87 ERR("tethering_set_disabled_cb [0x%X]\n", ret);
89 ret = tethering_set_connection_state_changed_cb(handle,
91 _connection_changed_cb, user_data);
92 if (ret != TETHERING_ERROR_NONE)
93 ERR("tethering_set_connection_state_changed_cb [0x%X]\n", ret);
95 ret = wifi_set_device_state_changed_cb(_wifi_state_changed_cb, user_data);
96 if (ret != WIFI_ERROR_NONE)
97 ERR("wifi_set_device_state_changed_cb [0x%X]\n", ret);
98 vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
99 _device_name_changed_cb, user_data);
101 vconf_notify_key_changed(VCONFKEY_NETWORK_CELLULAR_STATE,
102 _handle_network_cellular_state_changed_cb, user_data);
104 vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_STATUS,
105 _handle_usb_status_change, (void *)user_data);
107 vconf_notify_key_changed(VCONF_KEY_MOBILEAP_SYSPOPUP_RESPONSE,
108 _handle_mobileap_syspopup_popup_response, (void *)user_data);
113 static void __unset_callbacks(tethering_h handle)
119 ret = wifi_unset_device_state_changed_cb();
120 if (ret != WIFI_ERROR_NONE)
121 ERR("wifi_unset_device_state_changed_cb [0x%X]\n", ret);
123 ret = tethering_unset_connection_state_changed_cb(handle,
125 if (ret != TETHERING_ERROR_NONE)
126 ERR("tethering_unset_connection_state_changed_cb[0x%X]\n", ret);
128 ret = tethering_unset_disabled_cb(handle, TETHERING_TYPE_RESERVED);
129 if (ret != TETHERING_ERROR_NONE)
130 ERR("tethering_unset_disabled_cb [0x%X]\n", ret);
132 ret = tethering_unset_disabled_cb(handle, TETHERING_TYPE_ALL);
133 if (ret != TETHERING_ERROR_NONE)
134 ERR("tethering_unset_disabled_cb [0x%X]\n", ret);
136 ret = tethering_wifi_unset_security_type_changed_cb(handle);
137 if (ret != TETHERING_ERROR_NONE)
138 ERR("tethering_wifi_unset_security_type_changed_cb [0x%X]\n", ret);
140 ret = tethering_wifi_unset_ssid_visibility_changed_cb(handle);
141 if (ret != TETHERING_ERROR_NONE)
142 ERR("tethering_wifi_unset_ssid_visibility_changed_cb [0x%X]\n", ret);
144 ret = tethering_wifi_unset_passphrase_changed_cb(handle);
145 if (ret != TETHERING_ERROR_NONE)
146 ERR("tethering_wifi_unset_passphrase_changed_cb [0x%X]\n", ret);
148 ret = tethering_unset_enabled_cb(handle, TETHERING_TYPE_RESERVED);
149 if (ret != TETHERING_ERROR_NONE)
150 ERR("tethering_unset_enabled [0x%X]\n", ret);
152 ret = tethering_unset_enabled_cb(handle, TETHERING_TYPE_ALL);
153 if (ret != TETHERING_ERROR_NONE)
154 ERR("tethering_unset_enabled [0x%X]\n", ret);
156 vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
157 _device_name_changed_cb);
159 vconf_ignore_key_changed(VCONFKEY_NETWORK_CELLULAR_STATE,
160 _handle_network_cellular_state_changed_cb);
162 vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_STATUS, _handle_usb_status_change);
164 vconf_ignore_key_changed(VCONF_KEY_MOBILEAP_SYSPOPUP_RESPONSE,
165 _handle_mobileap_syspopup_popup_response);
170 static void *on_create(ui_gadget_h ug, enum ug_mode mode,
171 app_control_h app_control, void *priv)
176 ERR("The param is NULL\n");
180 if (mode != UG_MODE_FULLVIEW) {
181 ERR("Only Fullview is supported\n");
186 Evas_Object *content;
191 bindtextdomain(MH_TEXT_DOMAIN, MH_LOCALEDIR);
192 dgettext(PACKAGE, LOCALEDIR);
194 ad = (mh_appdata_t *)malloc(sizeof(mh_appdata_t));
196 ERR("Error!!! failed to allocate memory()\n");
199 memset(ad, 0x0, sizeof(mh_appdata_t));
201 ugd = (mh_ugdata_t *)priv;
206 _send_signal_qp(QP_SIGNAL_PROGRESS_RESET);
210 ret = tethering_create(&ad->handle);
211 if (ret != TETHERING_ERROR_NONE) {
212 ERR("tethering_create is failed : %d\n", ret);
218 ad->win = ug_get_parent_layout(ug);
220 ERR("ad->win is NULL\n");
227 if (elm_win_wm_rotation_supported_get(ad->win)) {
228 int rots[4] = {0, 90, 180, 270};
229 elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
232 layout = _create_win_layout(ad);
233 if (layout == NULL) {
234 ERR("_create_win_layout is failed\n");
240 content = create_content(ad);
241 if (content == NULL) {
242 ERR("create_content is failed\n");
248 elm_object_part_content_set(layout, "elm.swallow.content", content);
249 evas_object_show(layout);
250 ret = connection_create(&ad->conn_handle);
251 if (ret != CONNECTION_ERROR_NONE) {
252 ERR("connection_create() is failed : %d\n", ret);
255 ret = wifi_initialize();
256 if (ret != WIFI_ERROR_NONE) {
257 ERR("wifi_initialize() is failed : %d\n", ret);
260 __set_callbacks(ad->handle, (void *)ad);
266 static void on_start(ui_gadget_h ug, app_control_h app_control, void *priv)
270 char * viewtype = NULL;
272 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
273 mh_appdata_t *ad = ugd->ad;
275 ad->is_foreground = true;
277 if (_get_list_clients_count(ad) > 0) {
278 #ifdef TETHERING_DATA_USAGE_SUPPORT
279 _start_update_data_packet_usage(ad);
281 if (ad->connected_device.navi_it) {
282 _start_update_device_conn_time(ad);
286 if (tethering_is_enabled(NULL, TETHERING_TYPE_RESERVED) == true) {
287 DBG("MobileAP is turned on\n");
288 _prepare_popup(MH_POPUP_WIFI_AP_OFF, STR_WIFI_AP_CONTROLLED_ANOTHER_APP);
292 app_control_get_extra_data(app_control, "viewtype", &viewtype);
294 if (viewtype != NULL) {
295 if(strcmp(viewtype, "wifisettings") == 0)
296 mh_draw_wifi_setup_view(ad);
304 static void on_pause(ui_gadget_h ug, app_control_h app_control, void *priv)
308 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
309 mh_appdata_t *ad = ugd->ad;
311 #ifdef TETHERING_DATA_USAGE_SUPPORT
312 _stop_update_data_packet_usage(ad);
314 _stop_update_device_conn_time(ad);
315 ad->is_foreground = false;
320 static void on_resume(ui_gadget_h ug, app_control_h app_control, void *priv)
324 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
325 mh_appdata_t *ad = ugd->ad;
326 Elm_Object_Item *item = ad->main.device_item;
329 ad->is_foreground = true;
331 if (item && elm_genlist_item_expanded_get(item)) {
332 for (l = ad->client_list; l != NULL; l = g_slist_next(l) ) {
333 item = elm_genlist_item_next_get(item);
334 elm_genlist_item_fields_update(item, "elm.text", ELM_GENLIST_ITEM_FIELD_TEXT);
338 if (_get_list_clients_count(ad) > 0) {
339 #ifdef TETHERING_DATA_USAGE_SUPPORT
340 _start_update_data_packet_usage(ad);
342 if (ad->connected_device.navi_it) {
343 _start_update_device_conn_time(ad);
349 static void on_destroy(ui_gadget_h ug, app_control_h app_control, void *priv)
354 ERR("The param is NULL\n");
358 mh_ugdata_t *ugd = priv;
359 mh_appdata_t *ad = ugd->ad;
363 ERR("The param is NULL\n");
367 __unset_callbacks(ad->handle);
369 #ifdef TETHERING_DATA_USAGE_SUPPORT
370 _stop_update_data_packet_usage(ad);
372 _stop_update_device_conn_time(ad);
374 if (vconf_set_int(VCONF_MOBILE_AP_CONNECT_USB_POPUP_STATUS, 0) < 0) {
375 ERR("vconf_set_int is failed\n");
378 ret = wifi_deinitialize();
379 if (ret != WIFI_ERROR_NONE) {
380 ERR("wifi_deinitialize() is failed : %d\n", ret);
383 ret = connection_destroy(ad->conn_handle);
384 if (ret != CONNECTION_ERROR_NONE) {
385 ERR("connection_destroy() is failed : %d\n", ret);
388 ret = tethering_destroy(ad->handle);
389 if (ret != TETHERING_ERROR_NONE) {
390 ERR("tethering_destroy() is failed : %d\n", ret);
393 if (ad->layout == NULL) {
394 ERR("ad->layout is NULL\n");
401 evas_object_del(ad->popup);
405 if(ad->ps_recheck_timer_id > 0) {
406 g_source_remove(ad->ps_recheck_timer_id);
407 ad->ps_recheck_timer_id = 0;
410 evas_object_del(ad->bg);
413 evas_object_del(ad->layout);
416 _main_free_genlist_itc(ad);
418 ecore_imf_shutdown();
427 static void on_message(ui_gadget_h ug, app_control_h msg,
428 app_control_h app_control, void *priv)
432 static void on_event(ui_gadget_h ug, enum ug_event event,
433 app_control_h app_control, void *priv)
435 __MOBILE_AP_FUNC_ENTER__;
438 ERR("The param is NULL\n");
443 case UG_EVENT_LOW_MEMORY:
445 case UG_EVENT_LOW_BATTERY:
447 case UG_EVENT_LANG_CHANGE:
449 case UG_EVENT_ROTATE_PORTRAIT:
450 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
451 DBG("UG_EVENT_ROTATE_PORTRAIT[_UPSIDEDOWN]\n");
452 #if 0 /* device rename not supported */
453 _rotate_adjust_rename_popup();
456 case UG_EVENT_ROTATE_LANDSCAPE:
457 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
458 DBG("UG_EVENT_ROTATE_LANDSCAPE[_UPSIDEDOWN]\n");
459 #if 0 /* device rename not supported */
460 _rotate_adjust_rename_popup();
467 __MOBILE_AP_FUNC_EXIT__;
470 static void on_key_event(ui_gadget_h ug, enum ug_key_event event,
471 app_control_h app_control, void *priv)
473 __MOBILE_AP_FUNC_ENTER__;
475 if (priv == NULL || ug == NULL) {
476 ERR("The param is NULL\n");
480 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
481 mh_appdata_t *ad = ugd->ad;
489 case UG_KEY_EVENT_END:
490 DBG("UG_KEY_EVENT_END is received : %p\n", ad->popup);
491 if (NULL == ad->popup)
501 __MOBILE_AP_FUNC_EXIT__;
504 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
509 ERR("The param is NULL\n");
514 ugd = calloc(1, sizeof(mh_ugdata_t));
516 ERR("Quit : calloc failed(ugd)\n");
520 ops->create = on_create;
521 ops->start = on_start;
522 ops->pause = on_pause;
523 ops->resume = on_resume;
524 ops->destroy = on_destroy;
525 ops->message = on_message;
526 ops->event = on_event;
527 ops->key_event = on_key_event;
529 ops->opt = UG_OPT_INDICATOR_ENABLE;
534 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
539 ERR("The param is NULL\n");
543 mh_ugdata_t *ugd = (mh_ugdata_t *)ops->priv;
549 static void __mh_reset_vconf(tethering_h handle)
553 ret = vconf_set_int(VCONF_MOBILE_AP_WIFI_POPUP_CHECKBOX_STATUS, 0);
555 ERR("vconf_set_int failed\n");
557 ret = vconf_set_int(VCONF_MOBILE_AP_BT_POPUP_CHECKBOX_STATUS, 0);
559 ERR("vconf_set_int failed\n");
561 ret = vconf_set_int(VCONF_MOBILE_AP_USB_POPUP_CHECKBOX_STATUS, 0);
563 ERR("vconf_set_int failed\n");
565 ret = vconf_set_int(VCONF_MOBILE_AP_PREV_WIFI_STATUS, 0);
567 ERR("vconf_set_int failed\n");
569 ret = vconf_set_int(VCONF_MOBILE_AP_CONNECT_USB_POPUP_STATUS, 0);
571 ERR("vconf_set_int is failed\n");
573 ret = tethering_wifi_set_ssid_visibility(handle, true);
574 if (ret != TETHERING_ERROR_NONE)
575 ERR("tethering_wifi_set_ssid_visibility failed\n");
577 ret = tethering_wifi_set_security_type(handle, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK);
578 if (ret != TETHERING_ERROR_NONE)
579 ERR("tethering_wifi_set_security_type failed\n");
584 UG_MODULE_API int setting_plugin_reset(app_control_h app_control, void *priv)
589 tethering_h handle = NULL;
591 if (tethering_create(&handle) != TETHERING_ERROR_NONE) {
592 ERR("tethering_create failed\n");
596 if (tethering_is_enabled(handle, TETHERING_TYPE_USB) ||
597 tethering_is_enabled(handle, TETHERING_TYPE_WIFI) ||
598 tethering_is_enabled(handle, TETHERING_TYPE_BT)) {
599 ret = tethering_disable(handle, TETHERING_TYPE_ALL);
600 if (ret != TETHERING_ERROR_NONE) {
601 ERR("tethering_disable failed : %d\n", ret);
602 tethering_destroy(handle);
608 __mh_reset_vconf(handle);
610 tethering_destroy(handle);
615 /* Below code is commented as search in setting is no more supported in kiran */
618 UG_MODULE_API int setting_plugin_search_init(app_control_h app_control, void * priv, char ** domainname)
620 *domainname = strdup(PACKAGE":/usr/apps/ug-setting-mobileap-efl/res/locale");
622 Eina_List ** pplist = (Eina_List**)priv;
625 node = setting_plugin_search_item_add("IDS_MOBILEAP_MBODY_USB_TETHERING", "viewtype:frontpage", NULL, 5, NULL);
626 *pplist = eina_list_append(*pplist, node);
628 node = setting_plugin_search_item_add("IDS_MOBILEAP_MBODY_WI_FI_TETHERING", "viewtype:frontpage", NULL, 5, NULL);
629 *pplist = eina_list_append(*pplist, node);
631 node = setting_plugin_search_item_add("IDS_MOBILEAP_BODY_BLUETOOTH_TETHERING", "viewtype:frontpage", NULL, 5, NULL);
632 *pplist = eina_list_append(*pplist, node);
634 node = setting_plugin_search_item_add("IDS_MOBILEAP_MBODY_WI_FI_TETHERING_SETTINGS", "viewtype:wifisettings", NULL, 5, NULL);
635 *pplist = eina_list_append(*pplist, node);
637 node = setting_plugin_search_item_add("IDS_MOBILEAP_BODY_HIDE_MY_DEVICE", "viewtype:wifisettings", NULL, 5, NULL);
638 *pplist = eina_list_append(*pplist, node);
640 node = setting_plugin_search_item_add("IDS_MOBILEAP_BODY_SECURITY", "viewtype:wifisettings", NULL, 5, NULL);
641 *pplist = eina_list_append(*pplist, node);