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