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 "mobile_hotspot.h"
25 #include "mh_view_main.h"
26 #include "mh_func_onoff.h"
27 #include "mh_common_utility.h"
29 #include "mh_string.h"
30 #include "mh_view_wifi_setup.h"
32 static Evas_Object *create_content(mh_appdata_t *ad)
34 __MOBILE_AP_FUNC_ENTER__;
36 ad->naviframe = _create_naviframe(ad->layout);
37 _main_draw_contents(ad);
39 __MOBILE_AP_FUNC_EXIT__;
44 static void __set_callbacks(tethering_h handle, void *user_data)
50 ret = tethering_set_enabled_cb(handle, TETHERING_TYPE_ALL,
51 _enabled_cb, user_data);
52 if (ret != TETHERING_ERROR_NONE)
53 ERR("tethering_set_enabled_cb [0x%X]\n", ret);
55 ret = tethering_wifi_set_passphrase_changed_cb(handle,
56 _passphrase_changed_cb, user_data);
57 if (ret != TETHERING_ERROR_NONE)
58 ERR("tethering_wifi_set_passphrase_changed_cb [0x%X]\n", ret);
60 ret = tethering_wifi_set_ssid_visibility_changed_cb(handle,
61 _visibility_changed_cb, user_data);
62 if (ret != TETHERING_ERROR_NONE)
63 ERR("tethering_wifi_set_ssid_visibility_changed_cb [0x%X]\n", ret);
65 ret = tethering_wifi_set_security_type_changed_cb(handle,
66 _security_type_changed_cb, user_data);
67 if (ret != TETHERING_ERROR_NONE)
68 ERR("tethering_wifi_set_security_type_changed_cb [0x%X]\n", ret);
70 ret = tethering_set_disabled_cb(handle, TETHERING_TYPE_ALL,
71 _disabled_cb, user_data);
72 if (ret != TETHERING_ERROR_NONE)
73 ERR("tethering_set_disabled_cb [0x%X]\n", ret);
75 ret = tethering_set_connection_state_changed_cb(handle,
77 _connection_changed_cb, user_data);
78 if (ret != TETHERING_ERROR_NONE)
79 ERR("tethering_set_connection_state_changed_cb [0x%X]\n", ret);
81 ret = wifi_set_device_state_changed_cb(_wifi_state_changed_cb, user_data);
82 if (ret != WIFI_ERROR_NONE)
83 ERR("wifi_set_device_state_changed_cb [0x%X]\n", ret);
84 vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
85 _device_name_changed_cb, user_data);
87 vconf_notify_key_changed(VCONFKEY_NETWORK_CELLULAR_STATE,
88 _handle_network_cellular_state_changed_cb, user_data);
90 vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_STATUS,
91 _handle_usb_status_change, (void *)user_data);
93 vconf_notify_key_changed(VCONF_KEY_MOBILEAP_SYSPOPUP_RESPONSE,
94 _handle_mobileap_syspopup_popup_response, (void *)user_data);
99 static void __unset_callbacks(tethering_h handle)
105 ret = wifi_unset_device_state_changed_cb();
106 if (ret != WIFI_ERROR_NONE)
107 ERR("wifi_unset_device_state_changed_cb [0x%X]\n", ret);
109 ret = tethering_unset_connection_state_changed_cb(handle,
111 if (ret != TETHERING_ERROR_NONE)
112 ERR("tethering_unset_connection_state_changed_cb[0x%X]\n", ret);
114 ret = tethering_unset_disabled_cb(handle, TETHERING_TYPE_ALL);
115 if (ret != TETHERING_ERROR_NONE)
116 ERR("tethering_unset_disabled_cb [0x%X]\n", ret);
118 ret = tethering_wifi_unset_security_type_changed_cb(handle);
119 if (ret != TETHERING_ERROR_NONE)
120 ERR("tethering_wifi_unset_security_type_changed_cb [0x%X]\n", ret);
122 ret = tethering_wifi_unset_ssid_visibility_changed_cb(handle);
123 if (ret != TETHERING_ERROR_NONE)
124 ERR("tethering_wifi_unset_ssid_visibility_changed_cb [0x%X]\n", ret);
126 ret = tethering_wifi_unset_passphrase_changed_cb(handle);
127 if (ret != TETHERING_ERROR_NONE)
128 ERR("tethering_wifi_unset_passphrase_changed_cb [0x%X]\n", ret);
130 ret = tethering_unset_enabled_cb(handle, TETHERING_TYPE_ALL);
131 if (ret != TETHERING_ERROR_NONE)
132 ERR("tethering_unset_enabled [0x%X]\n", ret);
134 vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
135 _device_name_changed_cb);
137 vconf_ignore_key_changed(VCONFKEY_NETWORK_CELLULAR_STATE,
138 _handle_network_cellular_state_changed_cb);
140 vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_STATUS, _handle_usb_status_change);
142 vconf_ignore_key_changed(VCONF_KEY_MOBILEAP_SYSPOPUP_RESPONSE,
143 _handle_mobileap_syspopup_popup_response);
148 static void *on_create(ui_gadget_h ug, enum ug_mode mode,
149 app_control_h app_control, void *priv)
154 ERR("The param is NULL\n");
158 if (mode != UG_MODE_FULLVIEW) {
159 ERR("Only Fullview is supported\n");
164 Evas_Object *content;
169 bindtextdomain(MH_TEXT_DOMAIN, MH_LOCALEDIR);
170 dgettext(PACKAGE, LOCALEDIR);
172 ad = (mh_appdata_t *)malloc(sizeof(mh_appdata_t));
174 ERR("Error!!! failed to allocate memory()\n");
177 memset(ad, 0x0, sizeof(mh_appdata_t));
179 ugd = (mh_ugdata_t *)priv;
184 _send_signal_qp(QP_SIGNAL_PROGRESS_RESET);
188 ret = tethering_create(&ad->handle);
189 #ifndef TIZEN_FEATURE_EMULATOR
190 if (ret != TETHERING_ERROR_NONE) {
191 ERR("tethering_create is failed : %d\n", ret);
198 ad->win = ug_get_parent_layout(ug);
200 ERR("ad->win is NULL\n");
207 if (elm_win_wm_rotation_supported_get(ad->win)) {
208 int rots[4] = {0, 90, 180, 270};
209 elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
212 layout = _create_win_layout(ad);
213 if (layout == NULL) {
214 ERR("_create_win_layout is failed\n");
220 content = create_content(ad);
221 if (content == NULL) {
222 ERR("create_content is failed\n");
228 elm_object_part_content_set(layout, "elm.swallow.content", content);
229 evas_object_show(layout);
230 ret = connection_create(&ad->conn_handle);
231 if (ret != CONNECTION_ERROR_NONE)
232 ERR("connection_create() is failed : %d\n", ret);
234 ret = wifi_initialize();
235 if (ret != WIFI_ERROR_NONE)
236 ERR("wifi_initialize() is failed : %d\n", ret);
238 __set_callbacks(ad->handle, (void *)ad);
244 static void on_start(ui_gadget_h ug, app_control_h app_control, void *priv)
248 char * viewtype = NULL;
250 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
251 mh_appdata_t *ad = ugd->ad;
253 ad->is_foreground = true;
255 if (_get_list_clients_count(ad) > 0) {
256 #ifdef TETHERING_DATA_USAGE_SUPPORT
257 _start_update_data_packet_usage(ad);
260 _start_update_device_conn_time(ad);
263 app_control_get_extra_data(app_control, "viewtype", &viewtype);
265 if (viewtype != NULL) {
266 if (strcmp(viewtype, "wifisettings") == 0)
267 mh_draw_wifi_setup_view(ad);
275 static void on_pause(ui_gadget_h ug, app_control_h app_control, void *priv)
279 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
280 mh_appdata_t *ad = ugd->ad;
282 #ifdef TETHERING_DATA_USAGE_SUPPORT
283 _stop_update_data_packet_usage(ad);
285 _stop_update_device_conn_time(ad);
286 ad->is_foreground = false;
291 static void on_resume(ui_gadget_h ug, app_control_h app_control, void *priv)
295 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
296 mh_appdata_t *ad = ugd->ad;
297 Elm_Object_Item *item = ad->main.device_item;
300 ad->is_foreground = true;
302 if (item && elm_genlist_item_expanded_get(item)) {
303 for (l = ad->client_list; l != NULL; l = g_slist_next(l)) {
304 item = elm_genlist_item_next_get(item);
305 elm_genlist_item_fields_update(item, "elm.text", ELM_GENLIST_ITEM_FIELD_TEXT);
309 if (_get_list_clients_count(ad) > 0) {
310 #ifdef TETHERING_DATA_USAGE_SUPPORT
311 _start_update_data_packet_usage(ad);
314 _start_update_device_conn_time(ad);
319 static void on_destroy(ui_gadget_h ug, app_control_h app_control, void *priv)
324 ERR("The param is NULL\n");
328 mh_ugdata_t *ugd = priv;
329 mh_appdata_t *ad = ugd->ad;
333 ERR("The param is NULL\n");
337 __unset_callbacks(ad->handle);
339 #ifdef TETHERING_DATA_USAGE_SUPPORT
340 _stop_update_data_packet_usage(ad);
342 _stop_update_device_conn_time(ad);
344 if (vconf_set_int(VCONF_MOBILE_AP_CONNECT_USB_POPUP_STATUS, 0) < 0)
345 ERR("vconf_set_int is failed\n");
347 ret = wifi_deinitialize();
348 if (ret != WIFI_ERROR_NONE)
349 ERR("wifi_deinitialize() is failed : %d\n", ret);
351 ret = connection_destroy(ad->conn_handle);
352 if (ret != CONNECTION_ERROR_NONE)
353 ERR("connection_destroy() is failed : %d\n", ret);
355 ret = tethering_destroy(ad->handle);
356 if (ret != TETHERING_ERROR_NONE)
357 ERR("tethering_destroy() is failed : %d\n", ret);
359 if (ad->layout == NULL) {
360 ERR("ad->layout is NULL\n");
367 evas_object_del(ad->popup);
371 if (ad->ps_recheck_timer_id > 0) {
372 g_source_remove(ad->ps_recheck_timer_id);
373 ad->ps_recheck_timer_id = 0;
376 evas_object_del(ad->bg);
379 evas_object_del(ad->layout);
382 _main_free_genlist_itc(ad);
384 ecore_imf_shutdown();
393 static void on_message(ui_gadget_h ug, app_control_h msg,
394 app_control_h app_control, void *priv)
398 static void on_event(ui_gadget_h ug, enum ug_event event,
399 app_control_h app_control, void *priv)
401 __MOBILE_AP_FUNC_ENTER__;
404 ERR("The param is NULL\n");
409 case UG_EVENT_LOW_MEMORY:
411 case UG_EVENT_LOW_BATTERY:
413 case UG_EVENT_LANG_CHANGE:
415 case UG_EVENT_ROTATE_PORTRAIT:
416 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
417 DBG("UG_EVENT_ROTATE_PORTRAIT[_UPSIDEDOWN]\n");
419 case UG_EVENT_ROTATE_LANDSCAPE:
420 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
421 DBG("UG_EVENT_ROTATE_LANDSCAPE[_UPSIDEDOWN]\n");
427 __MOBILE_AP_FUNC_EXIT__;
430 static void on_key_event(ui_gadget_h ug, enum ug_key_event event,
431 app_control_h app_control, void *priv)
433 __MOBILE_AP_FUNC_ENTER__;
435 if (priv == NULL || ug == NULL) {
436 ERR("The param is NULL\n");
440 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
441 mh_appdata_t *ad = ugd->ad;
449 case UG_KEY_EVENT_END:
450 DBG("UG_KEY_EVENT_END is received : %p\n", ad->popup);
451 if (NULL == ad->popup)
461 __MOBILE_AP_FUNC_EXIT__;
464 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
469 ERR("The param is NULL\n");
474 ugd = calloc(1, sizeof(mh_ugdata_t));
476 ERR("Quit : calloc failed(ugd)\n");
480 ops->create = on_create;
481 ops->start = on_start;
482 ops->pause = on_pause;
483 ops->resume = on_resume;
484 ops->destroy = on_destroy;
485 ops->message = on_message;
486 ops->event = on_event;
487 ops->key_event = on_key_event;
489 ops->opt = UG_OPT_INDICATOR_ENABLE;
494 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
499 ERR("The param is NULL\n");
503 mh_ugdata_t *ugd = (mh_ugdata_t *)ops->priv;
509 static void __mh_reset_vconf(tethering_h handle)
513 ret = vconf_set_int(VCONF_MOBILE_AP_WIFI_POPUP_CHECKBOX_STATUS, 0);
515 ERR("vconf_set_int failed\n");
517 ret = vconf_set_int(VCONF_MOBILE_AP_BT_POPUP_CHECKBOX_STATUS, 0);
519 ERR("vconf_set_int failed\n");
521 ret = vconf_set_int(VCONF_MOBILE_AP_USB_POPUP_CHECKBOX_STATUS, 0);
523 ERR("vconf_set_int failed\n");
525 ret = vconf_set_int(VCONF_MOBILE_AP_PREV_WIFI_STATUS, 0);
527 ERR("vconf_set_int failed\n");
529 ret = vconf_set_int(VCONF_MOBILE_AP_CONNECT_USB_POPUP_STATUS, 0);
531 ERR("vconf_set_int is failed\n");
533 ret = tethering_wifi_set_ssid_visibility(handle, true);
534 if (ret != TETHERING_ERROR_NONE)
535 ERR("tethering_wifi_set_ssid_visibility failed\n");
537 ret = tethering_wifi_set_security_type(handle, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK);
538 if (ret != TETHERING_ERROR_NONE)
539 ERR("tethering_wifi_set_security_type failed\n");
544 UG_MODULE_API int setting_plugin_reset(app_control_h app_control, void *priv)
549 tethering_h handle = NULL;
551 if (tethering_create(&handle) != TETHERING_ERROR_NONE) {
552 ERR("tethering_create failed\n");
556 if (tethering_is_enabled(handle, TETHERING_TYPE_USB) ||
557 tethering_is_enabled(handle, TETHERING_TYPE_WIFI) ||
558 tethering_is_enabled(handle, TETHERING_TYPE_BT)) {
559 ret = tethering_disable(handle, TETHERING_TYPE_ALL);
560 if (ret != TETHERING_ERROR_NONE) {
561 ERR("tethering_disable failed : %d\n", ret);
562 tethering_destroy(handle);
568 __mh_reset_vconf(handle);
570 tethering_destroy(handle);