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 if (ret != TETHERING_ERROR_NONE) {
190 ERR("tethering_create is failed : %d\n", ret);
196 ad->win = ug_get_parent_layout(ug);
198 ERR("ad->win is NULL\n");
205 if (elm_win_wm_rotation_supported_get(ad->win)) {
206 int rots[4] = {0, 90, 180, 270};
207 elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
210 layout = _create_win_layout(ad);
211 if (layout == NULL) {
212 ERR("_create_win_layout is failed\n");
218 content = create_content(ad);
219 if (content == NULL) {
220 ERR("create_content is failed\n");
226 elm_object_part_content_set(layout, "elm.swallow.content", content);
227 evas_object_show(layout);
228 ret = connection_create(&ad->conn_handle);
229 if (ret != CONNECTION_ERROR_NONE)
230 ERR("connection_create() is failed : %d\n", ret);
232 ret = wifi_initialize();
233 if (ret != WIFI_ERROR_NONE)
234 ERR("wifi_initialize() is failed : %d\n", ret);
236 __set_callbacks(ad->handle, (void *)ad);
242 static void on_start(ui_gadget_h ug, app_control_h app_control, void *priv)
246 char * viewtype = NULL;
248 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
249 mh_appdata_t *ad = ugd->ad;
251 ad->is_foreground = true;
253 if (_get_list_clients_count(ad) > 0) {
254 #ifdef TETHERING_DATA_USAGE_SUPPORT
255 _start_update_data_packet_usage(ad);
258 _start_update_device_conn_time(ad);
261 app_control_get_extra_data(app_control, "viewtype", &viewtype);
263 if (viewtype != NULL) {
264 if (strcmp(viewtype, "wifisettings") == 0)
265 mh_draw_wifi_setup_view(ad);
273 static void on_pause(ui_gadget_h ug, app_control_h app_control, void *priv)
277 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
278 mh_appdata_t *ad = ugd->ad;
280 #ifdef TETHERING_DATA_USAGE_SUPPORT
281 _stop_update_data_packet_usage(ad);
283 _stop_update_device_conn_time(ad);
284 ad->is_foreground = false;
289 static void on_resume(ui_gadget_h ug, app_control_h app_control, void *priv)
293 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
294 mh_appdata_t *ad = ugd->ad;
295 Elm_Object_Item *item = ad->main.device_item;
298 ad->is_foreground = true;
300 if (item && elm_genlist_item_expanded_get(item)) {
301 for (l = ad->client_list; l != NULL; l = g_slist_next(l)) {
302 item = elm_genlist_item_next_get(item);
303 elm_genlist_item_fields_update(item, "elm.text", ELM_GENLIST_ITEM_FIELD_TEXT);
307 if (_get_list_clients_count(ad) > 0) {
308 #ifdef TETHERING_DATA_USAGE_SUPPORT
309 _start_update_data_packet_usage(ad);
312 _start_update_device_conn_time(ad);
317 static void on_destroy(ui_gadget_h ug, app_control_h app_control, void *priv)
322 ERR("The param is NULL\n");
326 mh_ugdata_t *ugd = priv;
327 mh_appdata_t *ad = ugd->ad;
331 ERR("The param is NULL\n");
335 __unset_callbacks(ad->handle);
337 #ifdef TETHERING_DATA_USAGE_SUPPORT
338 _stop_update_data_packet_usage(ad);
340 _stop_update_device_conn_time(ad);
342 if (vconf_set_int(VCONF_MOBILE_AP_CONNECT_USB_POPUP_STATUS, 0) < 0)
343 ERR("vconf_set_int is failed\n");
345 ret = wifi_deinitialize();
346 if (ret != WIFI_ERROR_NONE)
347 ERR("wifi_deinitialize() is failed : %d\n", ret);
349 ret = connection_destroy(ad->conn_handle);
350 if (ret != CONNECTION_ERROR_NONE)
351 ERR("connection_destroy() is failed : %d\n", ret);
353 ret = tethering_destroy(ad->handle);
354 if (ret != TETHERING_ERROR_NONE)
355 ERR("tethering_destroy() is failed : %d\n", ret);
357 if (ad->layout == NULL) {
358 ERR("ad->layout is NULL\n");
365 evas_object_del(ad->popup);
369 if (ad->ps_recheck_timer_id > 0) {
370 g_source_remove(ad->ps_recheck_timer_id);
371 ad->ps_recheck_timer_id = 0;
374 evas_object_del(ad->bg);
377 evas_object_del(ad->layout);
380 _main_free_genlist_itc(ad);
382 ecore_imf_shutdown();
391 static void on_message(ui_gadget_h ug, app_control_h msg,
392 app_control_h app_control, void *priv)
396 static void on_event(ui_gadget_h ug, enum ug_event event,
397 app_control_h app_control, void *priv)
399 __MOBILE_AP_FUNC_ENTER__;
402 ERR("The param is NULL\n");
407 case UG_EVENT_LOW_MEMORY:
409 case UG_EVENT_LOW_BATTERY:
411 case UG_EVENT_LANG_CHANGE:
413 case UG_EVENT_ROTATE_PORTRAIT:
414 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
415 DBG("UG_EVENT_ROTATE_PORTRAIT[_UPSIDEDOWN]\n");
417 case UG_EVENT_ROTATE_LANDSCAPE:
418 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
419 DBG("UG_EVENT_ROTATE_LANDSCAPE[_UPSIDEDOWN]\n");
425 __MOBILE_AP_FUNC_EXIT__;
428 static void on_key_event(ui_gadget_h ug, enum ug_key_event event,
429 app_control_h app_control, void *priv)
431 __MOBILE_AP_FUNC_ENTER__;
433 if (priv == NULL || ug == NULL) {
434 ERR("The param is NULL\n");
438 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
439 mh_appdata_t *ad = ugd->ad;
447 case UG_KEY_EVENT_END:
448 DBG("UG_KEY_EVENT_END is received : %p\n", ad->popup);
449 if (NULL == ad->popup)
459 __MOBILE_AP_FUNC_EXIT__;
462 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
467 ERR("The param is NULL\n");
472 ugd = calloc(1, sizeof(mh_ugdata_t));
474 ERR("Quit : calloc failed(ugd)\n");
478 ops->create = on_create;
479 ops->start = on_start;
480 ops->pause = on_pause;
481 ops->resume = on_resume;
482 ops->destroy = on_destroy;
483 ops->message = on_message;
484 ops->event = on_event;
485 ops->key_event = on_key_event;
487 ops->opt = UG_OPT_INDICATOR_ENABLE;
492 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
497 ERR("The param is NULL\n");
501 mh_ugdata_t *ugd = (mh_ugdata_t *)ops->priv;
507 static void __mh_reset_vconf(tethering_h handle)
511 ret = vconf_set_int(VCONF_MOBILE_AP_WIFI_POPUP_CHECKBOX_STATUS, 0);
513 ERR("vconf_set_int failed\n");
515 ret = vconf_set_int(VCONF_MOBILE_AP_BT_POPUP_CHECKBOX_STATUS, 0);
517 ERR("vconf_set_int failed\n");
519 ret = vconf_set_int(VCONF_MOBILE_AP_USB_POPUP_CHECKBOX_STATUS, 0);
521 ERR("vconf_set_int failed\n");
523 ret = vconf_set_int(VCONF_MOBILE_AP_PREV_WIFI_STATUS, 0);
525 ERR("vconf_set_int failed\n");
527 ret = vconf_set_int(VCONF_MOBILE_AP_CONNECT_USB_POPUP_STATUS, 0);
529 ERR("vconf_set_int is failed\n");
531 ret = tethering_wifi_set_ssid_visibility(handle, true);
532 if (ret != TETHERING_ERROR_NONE)
533 ERR("tethering_wifi_set_ssid_visibility failed\n");
535 ret = tethering_wifi_set_security_type(handle, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK);
536 if (ret != TETHERING_ERROR_NONE)
537 ERR("tethering_wifi_set_security_type failed\n");
542 UG_MODULE_API int setting_plugin_reset(app_control_h app_control, void *priv)
547 tethering_h handle = NULL;
549 if (tethering_create(&handle) != TETHERING_ERROR_NONE) {
550 ERR("tethering_create failed\n");
554 if (tethering_is_enabled(handle, TETHERING_TYPE_USB) ||
555 tethering_is_enabled(handle, TETHERING_TYPE_WIFI) ||
556 tethering_is_enabled(handle, TETHERING_TYPE_BT)) {
557 ret = tethering_disable(handle, TETHERING_TYPE_ALL);
558 if (ret != TETHERING_ERROR_NONE) {
559 ERR("tethering_disable failed : %d\n", ret);
560 tethering_destroy(handle);
566 __mh_reset_vconf(handle);
568 tethering_destroy(handle);