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