Implement OOBE view #6
[apps/native/ug-wifi-efl.git] / sources / libraries / Common / common_utils.c
1 /*
2  * Wi-Fi
3  *
4  * Copyright 2012 Samsung Electronics Co., Ltd
5  *
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
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 <vconf.h>
21 #include <aul.h>
22 #include <ui-gadget-module.h>
23 #include <bundle_internal.h>
24 #include <efl_extension.h>
25 #include <libxml/xmlmemory.h>
26 #include <libxml/parser.h>
27 #include <libxml/tree.h>
28
29 #include "common.h"
30 #include "ug_wifi.h"
31 #include "common_utils.h"
32 #include "i18nmanager.h"
33
34 #define SUPPLICANT_SERVICE                              "fi.w1.wpa_supplicant1"
35 #define SUPPLICANT_SERVICE_INTERFACE    SUPPLICANT_SERVICE ".Interface"
36 #define COLOR_TABLE "/usr/apps/wifi-efl-ug/shared/res/tables/ug-wifi-efl_ChangeableColorTable.xml"
37 #define FONT_TABLE "/usr/apps/wifi-efl-ug/shared/res/tables/ug-wifi-efl_FontInfoTable.xml"
38
39 #define MODEL_CONFIG_FILE "/etc/config/model-config.xml"
40 #define TYPE_FIELD "string"
41 #define FEATURE_TAG "platform"
42 #define MODEL_CONFIG_TAG "model-config"
43
44 typedef enum {
45         TIZEN_MODEL_UNKNOWN = 0,
46         TIZEN_MODEL_EMULATOR = 0x1,
47         TIZEN_MODEL_NOT_EMULATOR = 0x2,
48 } tizen_model_t;
49
50 static tizen_model_t emulator = TIZEN_MODEL_UNKNOWN;
51 static UG_TYPE g_ug_type = UG_VIEW_DEFAULT;
52
53 typedef struct {
54         char *title_str;
55         char *info_str;
56 } two_line_disp_data_t;
57
58 struct managed_idle_data {
59         GSourceFunc func;
60         gpointer user_data;
61         guint id;
62 };
63
64 struct gdbus_connection_data {
65         GDBusConnection *connection;
66         guint subscribe_id_supplicant;
67 };
68
69 #if 0
70 // not used at this moment 06/15/2018 
71 static struct gdbus_connection_data gdbus_conn = { NULL, 0 };
72 #endif
73 static GSList *managed_idler_list = NULL;
74 static int (*rotate_cb)(enum appcore_rm, void*, Eina_Bool, Eina_Bool) = NULL;
75 static void *rotate_cb_data = NULL;
76 static Eina_Bool is_wps = EINA_FALSE;
77 static Eina_Bool is_setting = EINA_FALSE;
78 static Eina_Bool is_portrait_mode = EINA_TRUE;
79 static Ecore_Timer *scan_update_timer = NULL;
80
81 static char *__common_utils_2line_text_get(void *data, Evas_Object *obj, const char *part)
82 {
83         two_line_disp_data_t *item_data = (two_line_disp_data_t *)data;
84         if (!strcmp("elm.text", part))
85                 return g_strdup(item_data->title_str);
86         else if (!strcmp("elm.text.sub", part))
87                 return g_strdup(item_data->info_str);
88
89         return NULL;
90 }
91
92 static void __common_utils_2line_text_del(void *data, Evas_Object *obj)
93 {
94         two_line_disp_data_t *item_data = (two_line_disp_data_t *)data;
95         if (item_data) {
96                 g_free(item_data->info_str);
97                 g_free(item_data->title_str);
98                 g_free(item_data);
99         }
100 }
101
102 static void __common_utils_separator_del(void *data, Evas_Object *obj)
103 {
104         elm_genlist_item_class_free(data);
105         return;
106 }
107
108 Eina_Bool common_utils_is_portrait_mode(void)
109 {
110         return is_portrait_mode;
111 }
112
113 static void __common_utils_set_portrait_mode(Eina_Bool on)
114 {
115         is_portrait_mode = on;
116 }
117
118 void common_utils_set_rotate_cb(int (*func)(enum appcore_rm, void*, Eina_Bool, Eina_Bool),
119                 void *data, Eina_Bool wps_value, Eina_Bool setting_value)
120 {
121         rotate_cb = func;
122         rotate_cb_data = data;
123         is_wps = wps_value;
124         is_setting = setting_value;
125 }
126
127 static void __common_utils_rotate_popup(enum appcore_rm rotmode)
128 {
129         if (rotate_cb)
130                 rotate_cb(rotmode, rotate_cb_data, is_wps, is_setting);
131 }
132
133 void common_utils_contents_rotation_adjust(int event)
134 {
135         if (event == UG_EVENT_ROTATE_PORTRAIT ||
136                         event == UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN) {
137                 __common_utils_rotate_popup(APPCORE_RM_PORTRAIT_NORMAL);
138                 __common_utils_set_portrait_mode(EINA_TRUE);
139         } else {
140                 __common_utils_rotate_popup(APPCORE_RM_LANDSCAPE_NORMAL);
141                 __common_utils_set_portrait_mode(EINA_FALSE);
142         }
143 }
144
145 Elm_Object_Item* common_utils_add_dialogue_separator(Evas_Object* genlist, const char *separator_style)
146 {
147         assertm_if(NULL == genlist, "NULL!!");
148
149         static Elm_Genlist_Item_Class *separator_itc;
150         separator_itc = elm_genlist_item_class_new();
151         separator_itc->item_style = separator_style;
152         separator_itc->func.text_get = NULL;
153         separator_itc->func.content_get = NULL;
154         separator_itc->func.state_get = NULL;
155         separator_itc->func.del = __common_utils_separator_del;
156
157         Elm_Object_Item* sep = elm_genlist_item_append(
158                                         genlist,
159                                         separator_itc,
160                                         NULL,
161                                         NULL,
162                                         ELM_GENLIST_ITEM_GROUP,
163                                         NULL,
164                                         NULL);
165
166         assertm_if(NULL == sep, "NULL!!");
167
168         elm_genlist_item_select_mode_set(sep, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
169
170         return sep;
171 }
172
173 char *common_utils_get_ap_security_type_info_txt(const char *pkg_name,
174                 wifi_device_info_t *device_info, bool check_fav)
175 {
176         bool favorite = false;
177         char *temp = NULL;
178         char *status_txt = NULL;
179
180         switch (device_info->security_mode) {
181         case WIFI_MANAGER_SECURITY_TYPE_NONE:           /** Security disabled */
182                 status_txt = g_strdup(sc(pkg_name, I18N_TYPE_Open));
183                 break;
184         case WIFI_MANAGER_SECURITY_TYPE_WEP:                    /** WEP */
185         case WIFI_MANAGER_SECURITY_TYPE_WPA_PSK:                /** WPA-PSK */
186         case WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK:       /** WPA2-PSK */
187                 if (TRUE == device_info->wps_mode) {
188                         status_txt = g_strdup_printf("%s (%s)", sc(pkg_name,
189                                         I18N_TYPE_Secured), sc(pkg_name, I18N_TYPE_WPS_Available));
190                 } else {
191                         status_txt = g_strdup(sc(pkg_name, I18N_TYPE_Secured));
192                 }
193                 break;
194         case WIFI_MANAGER_SECURITY_TYPE_EAP:    /** EAP */
195                 status_txt = g_strdup_printf("%s (%s)", sc(pkg_name, I18N_TYPE_Secured),
196                                 sc(pkg_name, I18N_TYPE_EAP));
197                 break;
198         default:                                                /** Unknown */
199                 status_txt = g_strdup(sc(pkg_name, I18N_TYPE_Unknown));
200                 break;
201         }
202
203         if (true == check_fav) {
204                 wifi_manager_ap_is_favorite(device_info->ap, &favorite);
205                 if (true == favorite) {
206                         temp = status_txt;
207                         status_txt = g_strdup_printf("%s, %s",
208                                         sc(pkg_name, I18N_TYPE_Saved), temp);
209                         g_free(temp);
210                 }
211         }
212
213         return status_txt;
214 }
215
216 void common_utils_get_device_icon(wifi_device_info_t *device_info, char **icon_path)
217 {
218         char buf[MAX_DEVICE_ICON_PATH_STR_LEN] = {'\0', };
219
220         g_strlcat(buf, "A01-3_icon", sizeof(buf));
221
222         if (device_info->security_mode != WIFI_MANAGER_SECURITY_TYPE_NONE)
223                 g_strlcat(buf, "_lock", sizeof(buf));
224
225         switch (wlan_manager_get_signal_strength(device_info->rssi)) {
226         case SIGNAL_STRENGTH_TYPE_EXCELLENT:
227                 g_strlcat(buf, "_03", sizeof(buf));
228                 break;
229         case SIGNAL_STRENGTH_TYPE_GOOD:
230                 g_strlcat(buf, "_02", sizeof(buf));
231                 break;
232         case SIGNAL_STRENGTH_TYPE_WEAK:
233                 g_strlcat(buf, "_01", sizeof(buf));
234                 break;
235         case SIGNAL_STRENGTH_TYPE_VERY_WEAK:
236         default:
237                 g_strlcat(buf, "_00", sizeof(buf));
238                 break;
239         }
240
241         if (icon_path)
242                 *icon_path = g_strdup_printf("%s", buf);
243 }
244
245 char *common_utils_get_rssi_text(const char *str_pkg_name, int rssi)
246 {
247         switch (wlan_manager_get_signal_strength(rssi)) {
248         case SIGNAL_STRENGTH_TYPE_EXCELLENT:
249                 return g_strdup(sc(str_pkg_name, I18N_TYPE_Excellent));
250         case SIGNAL_STRENGTH_TYPE_GOOD:
251                 return g_strdup(sc(str_pkg_name, I18N_TYPE_Good));
252         default:
253                 return g_strdup(sc(str_pkg_name, I18N_TYPE_Weak));
254         }
255 }
256
257 void common_utils_set_edit_box_imf_panel_evnt_cb(Elm_Object_Item *item,
258                                                 imf_ctxt_panel_cb_t input_panel_cb, void *user_data)
259 {
260         __COMMON_FUNC_ENTER__;
261         common_utils_entry_info_t *entry_info;
262         entry_info = elm_object_item_data_get(item);
263         if (!entry_info)
264                 return;
265
266         entry_info->input_panel_cb = input_panel_cb;
267         entry_info->input_panel_cb_data = user_data;
268
269         Evas_Object *entry = elm_object_item_part_content_get(item, "elm.icon.entry");
270         Ecore_IMF_Context *imf_ctxt = elm_entry_imf_context_get(entry);
271         if (imf_ctxt && entry_info->input_panel_cb) {
272                 /* Deleting the previously attached callback */
273                 ecore_imf_context_input_panel_event_callback_del(imf_ctxt,
274                                 ECORE_IMF_INPUT_PANEL_STATE_EVENT,
275                                 entry_info->input_panel_cb);
276                 ecore_imf_context_input_panel_event_callback_add(imf_ctxt,
277                                 ECORE_IMF_INPUT_PANEL_STATE_EVENT,
278                                 entry_info->input_panel_cb,
279                                 entry_info->input_panel_cb_data);
280                 DEBUG_LOG(UG_NAME_NORMAL, "set the imf ctxt cbs");
281         }
282
283         __COMMON_FUNC_EXIT__;
284         return;
285 }
286
287 void common_utils_edit_box_focus_set(Elm_Object_Item *item, Eina_Bool focus_set)
288 {
289         __COMMON_FUNC_ENTER__;
290         if (!item)
291                 return;
292
293         Evas_Object *entry = elm_object_item_part_content_get(item, "elm.icon.entry");
294
295         if (entry) {
296                 elm_object_focus_set(entry, focus_set);
297                 elm_object_focus_allow_set(entry, focus_set);
298         }
299
300         __COMMON_FUNC_EXIT__;
301         return;
302 }
303
304 void common_utils_edit_box_allow_focus_set(Elm_Object_Item *item,
305                 Eina_Bool focus_set)
306 {
307         __COMMON_FUNC_ENTER__;
308         if (!item)
309                 return;
310
311         Evas_Object *entry = elm_object_item_part_content_get(item, "elm.icon.entry");
312         elm_object_focus_allow_set(entry, focus_set);
313
314         __COMMON_FUNC_EXIT__;
315         return;
316 }
317
318 Elm_Object_Item *common_utils_add_2_line_txt_disabled_item(
319                 Evas_Object* view_list, const char *style_name,
320                 const char *line1_txt, const char *line2_txt)
321 {
322         static Elm_Genlist_Item_Class two_line_display_itc;
323         two_line_disp_data_t *two_line_data = NULL;
324         Elm_Object_Item *item = NULL;
325
326         two_line_display_itc.item_style = style_name;
327         two_line_display_itc.func.text_get = __common_utils_2line_text_get;
328         two_line_display_itc.func.content_get = NULL;
329         two_line_display_itc.func.state_get = NULL;
330         two_line_display_itc.func.del = __common_utils_2line_text_del;
331
332         two_line_data = g_new0(two_line_disp_data_t, 1);
333         two_line_data->title_str = g_strdup(line1_txt);
334         two_line_data->info_str = g_strdup(line2_txt);
335         SECURE_INFO_LOG(UG_NAME_NORMAL, "title_str = %s info_str = %s",
336                         two_line_data->title_str, two_line_data->info_str);
337
338         item = elm_genlist_item_append(view_list, &two_line_display_itc,
339                         two_line_data, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
340         elm_object_item_disabled_set(item, TRUE);
341
342         return item;
343 }
344
345 char *common_utils_get_list_item_entry_txt(Elm_Object_Item *entry_item)
346 {
347         common_utils_entry_info_t *entry_info =
348                         (common_utils_entry_info_t *)elm_object_item_data_get(entry_item);
349         if (entry_info == NULL)
350                 return NULL;
351
352         DEBUG_LOG(UG_NAME_NORMAL, "entry_info: %p", entry_info);
353
354         return g_strdup(entry_info->entry_txt);
355 }
356
357 Evas_Object *common_utils_create_layout(Evas_Object *navi_frame)
358 {
359         Evas_Object *layout;
360         layout = elm_layout_add(navi_frame);
361         elm_layout_theme_set(layout, "layout", "application", "noindicator");
362         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
363         evas_object_show(layout);
364
365         return layout;
366 }
367
368 static void __common_utils_del_popup(void *data, Evas_Object *obj, void *event_info)
369 {
370         Evas_Object *popup = (Evas_Object *)data;
371         evas_object_del(popup);
372 }
373
374 Evas_Object *common_utils_show_info_popup(Evas_Object *parent,
375                 popup_btn_info_t *popup_data)
376 {
377         __COMMON_FUNC_ENTER__;
378
379         Evas_Object *popup = elm_popup_add(parent);
380         char *txt = NULL;
381         double vertical = g_ug_type == UG_VIEW_OOBE ? 0.5 : 1.0;
382
383         if (!popup) {
384                 ERROR_LOG(UG_NAME_ERR, "Could not add popup");
385                 return NULL;
386         }
387
388         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, vertical);
389         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
390
391         if (popup_data->title_txt) {
392                 char *full_txt = NULL;
393                 txt = evas_textblock_text_utf8_to_markup(NULL, popup_data->title_txt);
394                 if (g_ug_type == UG_VIEW_OOBE)
395                         full_txt = g_strdup_printf("<align=left>%s: <b>%s</b></align>",
396                                         sc(PACKAGE, I18N_TYPE_Ssid), txt);
397                 elm_object_domain_translatable_part_text_set(popup,
398                                 "title,text", PACKAGE, g_ug_type == UG_VIEW_OOBE ? full_txt : txt);
399                 g_free(txt);
400                 g_free(full_txt);
401                 txt = NULL;
402         }
403
404         if (g_ug_type == UG_VIEW_OOBE && popup_data->sub_title_txt) {
405                 txt = g_strdup_printf("<align=left>%s: <b>%s</b></align>",
406                                 sc(PACKAGE, I18N_TYPE_Security),
407                                 popup_data->sub_title_txt);
408                 elm_object_part_text_set(popup, "subtitle,text", txt);
409                 g_free(txt);
410                 txt = NULL;
411         }
412
413         if (popup_data->info_txt) {
414                 elm_object_domain_translatable_text_set(popup, PACKAGE,
415                                 popup_data->info_txt);
416         }
417
418         if (popup_data->btn1_txt) {
419                 Evas_Object *btn_1 = elm_button_add(popup);
420
421                 if (g_ug_type== UG_VIEW_OOBE)
422                         elm_object_style_set(btn_1, "cancel");
423                 else
424                         elm_object_style_set(btn_1, "popup");
425
426                 elm_object_domain_translatable_text_set(btn_1, PACKAGE,
427                                 popup_data->btn1_txt);
428                 elm_object_part_content_set(popup, "button1", btn_1);
429                 if (popup_data->btn1_cb) {
430                         evas_object_smart_callback_add(btn_1, "clicked",
431                                         popup_data->btn1_cb, popup_data->btn1_data);
432                         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
433                                         popup_data->btn1_cb, popup_data->btn1_data);
434                 } else {
435                         evas_object_smart_callback_add(btn_1, "clicked",
436                                         __common_utils_del_popup, popup);
437                         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
438                                         __common_utils_del_popup, popup);
439                 }
440         }
441
442         if (popup_data->btn2_txt) {
443                 Evas_Object *btn_2 = elm_button_add(popup);
444
445                 if (g_ug_type == UG_VIEW_OOBE)
446                         elm_object_style_set(btn_2, "connect");
447                 else
448                         elm_object_style_set(btn_2, "popup");
449
450                 /* This button reference used in case of hidden AP case */
451                 popup_data->btn = btn_2;
452                 elm_object_domain_translatable_text_set(btn_2, PACKAGE,
453                                 popup_data->btn2_txt);
454                 elm_object_part_content_set(popup, "button2", btn_2);
455                 //evas_object_smart_callback_add(btn_2, "clicked", popup_data->btn2_cb, NULL);
456                 evas_object_show(popup);
457                 if (popup_data->btn2_cb) {
458                         evas_object_smart_callback_add(btn_2, "clicked",
459                                         popup_data->btn2_cb, popup_data->btn2_data);
460                 } else {
461                         evas_object_smart_callback_add(btn_2, "clicked",
462                                         __common_utils_del_popup, popup);
463                 }
464         }
465
466         evas_object_show(popup);
467         elm_object_focus_set(popup, EINA_TRUE);
468
469         return popup;
470 }
471
472 Evas_Object *common_utils_show_info_ok_popup(Evas_Object *win,
473                 const char *str_pkg_name, const char *info_txt,
474                 Evas_Smart_Cb ok_cb, void *cb_data)
475 {
476         popup_btn_info_t popup_data;
477
478         memset(&popup_data, 0, sizeof(popup_data));
479         popup_data.info_txt = (char *)info_txt;
480         popup_data.btn1_txt = sc(str_pkg_name, I18N_TYPE_Ok);
481         popup_data.btn1_cb = ok_cb;
482         popup_data.btn1_data = cb_data;
483
484         return common_utils_show_info_popup(win, &popup_data);
485 }
486
487 Evas_Object *common_utils_show_info_timeout_popup(Evas_Object *win,
488                 const char* info_text, const double timeout)
489 {
490         Evas_Object *popup = elm_popup_add(win);
491
492         elm_object_text_set(popup, info_text);
493         elm_popup_timeout_set(popup, timeout);
494         evas_object_smart_callback_add(popup, "timeout",
495                         __common_utils_del_popup, popup);
496         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
497         elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
498         evas_object_show(popup);
499
500         return popup;
501 }
502
503 int common_utils_get_rotate_angle(enum appcore_rm rotate_mode)
504 {
505         int rotate_angle;
506         if (APPCORE_RM_UNKNOWN == rotate_mode)
507                 appcore_get_rotation_state(&rotate_mode);
508
509         DEBUG_LOG(SP_NAME_NORMAL, "rotate_mode = %d", rotate_mode);
510
511         switch (rotate_mode) {
512         case APPCORE_RM_PORTRAIT_NORMAL:         /**< Portrait mode */
513                 DEBUG_LOG(SP_NAME_NORMAL, "rotate mode is APPCORE_RM_PORTRAIT_NORMAL");
514                 rotate_angle = 0;
515                 break;
516
517         case APPCORE_RM_PORTRAIT_REVERSE:         /**< Portrait upside down mode */
518                 DEBUG_LOG(SP_NAME_NORMAL, "rotate mode is APPCORE_RM_PORTRAIT_REVERSE");
519                 rotate_angle = 180;
520                 break;
521
522         case APPCORE_RM_LANDSCAPE_NORMAL:         /**< Left handed landscape mode */
523                 DEBUG_LOG(SP_NAME_NORMAL, "rotate mode is APPCORE_RM_LANDSCAPE_NORMAL");
524                 rotate_angle = 270;
525                 break;
526
527         case APPCORE_RM_LANDSCAPE_REVERSE:          /**< Right handed landscape mode */
528                 DEBUG_LOG(SP_NAME_NORMAL, "rotate mode is APPCORE_RM_LANDSCAPE_REVERSE");
529                 rotate_angle = 90;
530                 break;
531
532         default:
533                 ERROR_LOG(SP_NAME_ERR, "Invalid rotate mode. The default value (0) is set to 'rotate_angle'.");
534                 rotate_angle = 0;
535                 break;
536         }
537
538         return rotate_angle;
539 }
540
541 int common_utils_send_message_to_net_popup(const char *title,
542                 const char *content, const char *type, const char *ssid)
543 {
544         int ret = 0;
545         bundle *b = bundle_create();
546
547         bundle_add_str(b, "_SYSPOPUP_TITLE_", title);
548         bundle_add_str(b, "_SYSPOPUP_CONTENT_", content);
549         bundle_add_str(b, "_SYSPOPUP_TYPE_", type);
550         bundle_add_str(b, "_AP_NAME_", ssid);
551
552         ret = aul_launch_app("net.netpopup", b);
553
554         bundle_free(b);
555
556         return ret;
557 }
558
559 int common_utils_send_restriction_to_net_popup(const char *title,
560                 const char *type, const char *restriction)
561 {
562         int ret = 0;
563         bundle *b = bundle_create();
564
565         bundle_add_str(b, "_SYSPOPUP_TITLE_", title);
566         bundle_add_str(b, "_SYSPOPUP_CONTENT_", "security restriction");
567         bundle_add_str(b, "_SYSPOPUP_TYPE_", type);
568         bundle_add_str(b, "_RESTRICTED_TYPE_", restriction);
569
570         ret = aul_launch_app("net.netpopup", b);
571
572         bundle_free(b);
573
574         return ret;
575 }
576
577 int common_util_set_system_registry(const char *key, int value)
578 {
579         __COMMON_FUNC_ENTER__;
580
581         if (vconf_set_int(key, value) < 0) {
582                 ERROR_LOG(UG_NAME_NORMAL, "Failed to set vconf");
583
584                 __COMMON_FUNC_EXIT__;
585                 return -1;
586         }
587
588         __COMMON_FUNC_EXIT__;
589         return 0;
590 }
591
592 int common_util_get_system_registry(const char *key)
593 {
594         __COMMON_FUNC_ENTER__;
595
596         int value = 0;
597
598         if (vconf_get_int(key, &value) < 0) {
599                 ERROR_LOG(UG_NAME_NORMAL, "Failed to get vconf");
600
601                 __COMMON_FUNC_EXIT__;
602                 return -1;
603         }
604
605         __COMMON_FUNC_EXIT__;
606         return value;
607 }
608
609 static void __common_util_managed_idle_destroy_cb(gpointer data)
610 {
611         if (!data)
612                 return;
613
614         managed_idler_list = g_slist_remove(managed_idler_list, data);
615         g_free(data);
616 }
617
618 static gboolean __common_util_managed_idle_cb(gpointer user_data)
619 {
620         struct managed_idle_data *data = (struct managed_idle_data *)user_data;
621
622         if (!data)
623                 return FALSE;
624
625         return data->func(data->user_data);
626 }
627
628 guint common_util_managed_idle_add(GSourceFunc func, gpointer user_data)
629 {
630         guint id;
631         struct managed_idle_data *data;
632
633         if (!func)
634                 return 0;
635
636         data = g_try_new0(struct managed_idle_data, 1);
637         if (!data)
638                 return 0;
639
640         data->func = func;
641         data->user_data = user_data;
642
643         id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __common_util_managed_idle_cb,
644                         data, __common_util_managed_idle_destroy_cb);
645         if (!id) {
646                 g_free(data);
647                 return id;
648         }
649
650         data->id = id;
651
652         managed_idler_list = g_slist_append(managed_idler_list, data);
653
654         return id;
655 }
656
657 void common_util_managed_idle_cleanup(void)
658 {
659         if (managed_idler_list == NULL)
660                 return;
661
662         GSList *cur = managed_idler_list;
663         GSource *src;
664         struct managed_idle_data *data;
665
666         while (cur) {
667                 GSList *next = cur->next;
668                 data = (struct managed_idle_data *)cur->data;
669
670                 src = g_main_context_find_source_by_id(g_main_context_default(), data->id);
671                 if (src) {
672                         g_source_destroy(src);
673                         cur = managed_idler_list;
674                 } else {
675                         cur = next;
676                 }
677         }
678
679         g_slist_free(managed_idler_list);
680         managed_idler_list = NULL;
681 }
682
683 void common_util_managed_ecore_scan_update_timer_add(double interval,
684                 common_util_scan_update_cb callback, void *data)
685 {
686         if (callback == NULL)
687                 return;
688
689         common_util_managed_ecore_scan_update_timer_del();
690
691         scan_update_timer = ecore_timer_add(interval, callback, data);
692 }
693
694 void common_util_managed_ecore_scan_update_timer_del(void)
695 {
696         if (scan_update_timer != NULL) {
697                 ecore_timer_del(scan_update_timer);
698                 scan_update_timer = NULL;
699         }
700 }
701
702 void common_util_manager_ecore_scan_update_timer_reset(void)
703 {
704         scan_update_timer = NULL;
705 }
706
707 #if 0
708 // not used at this moment 06/15/2018 
709 static GDBusConnection *common_util_get_gdbus_conn(void)
710 {
711         GError *error = NULL;
712
713         if (gdbus_conn.connection != NULL)
714                 return gdbus_conn.connection;
715
716 #if !GLIB_CHECK_VERSION(2, 36, 0)
717         g_type_init();
718 #endif
719
720         gdbus_conn.connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
721         if (gdbus_conn.connection == NULL) {
722                 ERROR_LOG(UG_NAME_NORMAL,
723                                 "Failed to connect to the D-BUS daemon: [%s]\n", error->message);
724                 g_error_free(error);
725                 return NULL;
726         }
727
728         return gdbus_conn.connection;
729 }
730 #endif // #if 0
731
732 int common_utils_get_sim_state(void)
733 {
734         int value = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
735         int sim_count = 0;
736
737         value = common_util_get_system_registry(VCONFKEY_TELEPHONY_SIM_SLOT);
738         INFO_LOG(UG_NAME_NORMAL, "SIM slot 1 state : %d", value);
739         if (value == VCONFKEY_TELEPHONY_SIM_INSERTED)
740                 return value;
741
742         sim_count = common_util_get_system_registry(
743                         VCONFKEY_TELEPHONY_SIM_SLOT_COUNT);
744         if (sim_count == 1)
745                 return value;
746
747         value = common_util_get_system_registry(VCONFKEY_TELEPHONY_SIM_SLOT2);
748         INFO_LOG(UG_NAME_NORMAL, "SIM slot 2 state : %d", value);
749
750         return value;
751 }
752
753 static inline int __get_model_from_model_config_xml(const char *field, char **value)
754 {
755         char *node_name = NULL;
756         char *node_value = NULL;
757         xmlNode *cur_node = NULL;
758         xmlNodePtr cur_ptr = NULL;
759         xmlNodePtr model_ptr = NULL;
760         xmlDocPtr xml_doc = NULL;
761
762         xml_doc = xmlParseFile(MODEL_CONFIG_FILE);
763         if (xml_doc == NULL)
764                 return -1;
765
766         cur_ptr = xmlDocGetRootElement(xml_doc);
767         if (cur_ptr == NULL) {
768                 xmlFreeDoc(xml_doc);
769                 return -1;
770         }
771
772         for (cur_node = cur_ptr; cur_node; cur_node = cur_node->next) {
773                 if (!xmlStrcmp(cur_ptr->name, (const xmlChar*)MODEL_CONFIG_TAG))
774                         break;
775         }
776
777         cur_ptr = cur_ptr->xmlChildrenNode;
778         for (cur_node = cur_ptr; cur_node; cur_node = cur_node->next) {
779                 if (!xmlStrcmp(cur_node->name, (const xmlChar*)FEATURE_TAG)) {
780                         model_ptr = cur_node;
781                         break;
782                 }
783         }
784
785         if (model_ptr == NULL) {
786                 xmlFreeDoc(xml_doc);
787                 return -1;
788         }
789
790         if (model_ptr) {
791                 cur_ptr = model_ptr->xmlChildrenNode;
792
793                 for (cur_node = cur_ptr; cur_node; cur_node = cur_node->next) {
794                         if (cur_node->type == XML_ELEMENT_NODE) {
795                                 node_name = (char *)xmlGetProp(cur_node, (const xmlChar*)"name");
796                                 if (node_name == NULL) {
797                                         xmlFreeDoc(xml_doc);
798                                         return -1;
799                                 }
800
801                                 if (!strncmp(node_name, field, strlen(node_name))) {
802                                         node_value = (char *)xmlNodeListGetString(xml_doc, cur_node->xmlChildrenNode, 1);
803                                         if (node_value) {
804                                                 *value = strdup(node_value);
805                                                 free(node_name);
806                                                 free(node_value);
807                                                 break;
808                                         }
809                                 }
810                                 free(node_name);
811                         }
812                 }
813         }
814
815         xmlFreeDoc(xml_doc);
816         return 0;
817 }
818
819 Eina_Bool _is_emulator(void)
820 {
821         char *model_name = NULL;
822
823         if (emulator == TIZEN_MODEL_EMULATOR)
824                 return EINA_TRUE;
825         else if (emulator == TIZEN_MODEL_NOT_EMULATOR)
826                 return EINA_FALSE;
827
828         if (__get_model_from_model_config_xml("tizen.org/system/model_name", &model_name) < 0)
829                 return EINA_FALSE;
830
831         if (model_name == NULL)
832                 return EINA_FALSE;
833
834         if (strncmp(model_name, "Emulator", strlen("Emulator")) == 0) {
835                 free(model_name);
836                 emulator = TIZEN_MODEL_EMULATOR;
837                 return EINA_TRUE;
838         } else {
839                 free(model_name);
840                 emulator = TIZEN_MODEL_NOT_EMULATOR;
841                 return EINA_FALSE;
842         }
843 }
844
845 void common_util_set_ug_type(UG_TYPE type)
846 {
847         g_ug_type = type;
848 }
849
850 UG_TYPE common_util_get_ug_type(void)
851 {
852         return g_ug_type;
853 }