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