added dir check for the installed UG
[apps/core/preloaded/settings.git] / setting-common / src / setting-cfg.c
index bf3fc39..fa2cf55 100755 (executable)
@@ -1,28 +1,30 @@
 /*
-  * Copyright 2012  Samsung Electronics Co., Ltd
-  *
-  * Licensed under the Flora License, Version 1.0 (the "License");
-  * you may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at
-  *
-  *     http://www.tizenopensource.org/license
-  *
-  * Unless required by applicable law or agreed to in writing, software
-  * distributed under the License is distributed on an "AS IS" BASIS,
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  */
-
-
+ * setting
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
+ *
+ * Contact: MyoungJune Park <mj2004.park@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 #include <setting-cfg.h>
 #include <setting-debug.h>
 #include <stdio.h>
 #include <Elementary.h>
 #include <setting-common-general-func.h>
-
-#include <vconf-keys.h>
+#include <unistd.h>
 
 #define CFG_FILE_DIR_PATH      "/opt/data/setting/"
 #define CFG_FILE_PATH          CFG_FILE_DIR_PATH"setting.cfg"
 JsonParser* parser;
 JsonNode*   root; /* category_list */
 
+char* setting_cfg_get_path()
+{
+       return CFG_FILE_PATH;
+}
+
 int setting_cfg_file_write( JsonNode * node );
 
-#define __create_an_item(item_name, icon_path, ug_args, defaultPos, is_resetable)\
+#define __create_an_item(item_name, icon_path, ug_args, defaultPos, is_resetable) do\
 {\
+       if (!is_ug_installed_by_ug_args(ug_args)) break;\
        menu_item = json_node_new(JSON_NODE_OBJECT); \
        object = json_object_new(); \
        json_node_take_object(menu_item, object); \
@@ -44,10 +52,11 @@ int setting_cfg_file_write( JsonNode * node );
        json_object_set_int_member(object, "click_times", 0); \
        json_object_set_int_member(object, "is_resetable", is_resetable); \
        json_array_add_element(menu, menu_item); \
-}
+} while(0);\
 
-#define __create_an_item_by_pkg(item_name, pkg_name, ug_args, defaultPos, is_resetable)\
+#define __create_an_item_by_pkg(item_name, pkg_name, ug_args, defaultPos, is_resetable) do\
 {\
+       if (!is_ug_installed_by_ug_args(ug_args)) break;\
        menu_item = json_node_new(JSON_NODE_OBJECT); \
        object = json_object_new(); \
        char* __temp_##item_name = get_icon_path(pkg_name); \
@@ -60,7 +69,7 @@ int setting_cfg_file_write( JsonNode * node );
        json_object_set_int_member(object, "is_resetable", is_resetable); \
        json_array_add_element(menu, menu_item); \
        free(__temp_##item_name); __temp_##item_name = NULL; \
-}
+} while(0);\
 
 
 #define __create_a_menu(menu_name)\
@@ -95,72 +104,124 @@ int setting_cfg_create(void)
        JsonArray *menu;
        JsonObject *object;
 
-       int ret = 0;
-       int support_nfc = 0;
-
        /* Category list */
        category_list = json_node_new (JSON_NODE_ARRAY);
        json_node_take_array ( category_list, json_array_new () );
 
        /* Connectivity */
        __create_a_menu(KeyStr_Connectivity);
+
+       __create_an_item(KeyStr_FlightMode, IMG_FlightMode, NULL, Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
        __create_an_item(KeyStr_WiFi, IMG_WiFi, "wifi-efl-UG", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
+       __create_an_item(KeyStr_MobileAP, IMG_MobileAP, "setting-mobile-ap-ug", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
+       __create_an_item(KeyStr_Location, IMG_Location, "setting-location-efl", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
+       __create_an_item(KeyStr_Network, IMG_Network, "setting-network-efl", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
+       __create_an_item(KeyStr_Bluetooth, IMG_Bluetooth, "setting-bluetooth-efl", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
+       __create_an_item(KeyStr_NFC, IMG_NFC, "setting-nfc-efl", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
 
-       ret = vconf_get_bool(VCONFKEY_NFC_FEATURE, &support_nfc);
-       if((ret != -1) && (support_nfc == 1))
-               __create_an_item(KeyStr_NFC, IMG_NFC, "setting-nfc-efl", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
+#if SUPPORT_DATA_USAGE
+       __create_an_item(KeyStr_DataUsage, IMG_DataUsage, "setting-datausage-efl", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
+#endif
 
-       __create_an_item(KeyStr_Location, IMG_Location, "setting-location-efl", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
-       __create_an_item(KeyStr_DataRoaming, IMG_DataRoaming, NULL, Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
-       if(!isEmulBin()) {
-               __create_an_item(KeyStr_WiFiDirect, IMG_WiFiDirect, "setting-wifidirect-efl", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
-       }
-       __create_an_item(KeyStr_USBconnection, IMG_USBconnection, "setting-connectivity-efl|viewtype:usb", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
+#if SUPPORT_WIFI_DIRECT
+       __create_an_item(KeyStr_WiFiDirect, IMG_WiFiDirect, "setting-wifidirect-efl", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
+#endif
 
        /* System */
        __create_a_menu(KeyStr_System);
        /* a new group..        */
 
-       __create_an_item(KeyStr_Sounds, IMG_Sounds, "setting-profile-efl", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
+       // Wallpaper -- here
+#if SUPPORT_WALLPAPER
        /* kinds of wallpaper version.. */
        __create_an_item(KeyStr_Wallpaper, IMG_Wallpaper, "setting-display-efl|viewtype:wallpaper", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
+#endif
+
+       __create_an_item(KeyStr_Sounds, IMG_Sounds, "setting-profile-efl", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
 
+#if SUPPOR_SEPARATE_BRIGHTNESS
+       __create_an_item(KeyStr_Brightness, IMG_Brightness, "setting-display-efl|viewtype:brightness", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
+#endif
 
-       __create_an_item(KeyStr_Display, IMG_Dispaly, "setting-display-efl|viewtype:main", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
+#if SUPPORT_SECURITY
+       __create_an_item(KeyStr_Security, IMG_Security, "setting-security-efl", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
+#endif
 
-       /* a new group.. */
-       __create_an_item(KeyStr_DateTime, IMG_DateTime, "setting-time-efl", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
+#if SUPPORT_POWERSAVING
+       __create_an_item(KeyStr_Powersaving, IMG_Powersaving, "setting-powersaving-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
+#endif
 
-       /* a new group.. */
+#if SUPPORT_MOTIONS
+       __create_an_item(KeyStr_Motions, IMG_Motion, "setting-motion-efl|viewtype:motions", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
+#endif
+
+#if SUPPORT_ACCESSIBILITY
+       __create_an_item(KeyStr_Accessibility, IMG_Accessibility, "setting-accessibility-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
+#endif
+
+#if SUPPORT_FONT
+       __create_an_item(KeyStr_Font, IMG_Font, "setting-font-efl", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
+#endif
+
+       __create_an_item(KeyStr_Display, IMG_Dispaly, "setting-display-efl|viewtype:main", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
+#if SUPPORT_MENUSCREEN
+       __create_an_item(KeyStr_Menuscreen, IMG_Menuscreen, "setting-homescreen-efl", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
+#endif
+       __create_an_item(KeyStr_Landscape, IMG_Landscape, NULL, Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
+       __create_an_item(KeyStr_DateTime, IMG_DateTime, "setting-time-efl", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
        __create_an_item(KeyStr_LanguageRegion, IMG_DisplayLanguage, "setting-phone-efl|viewtype:language", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
        __create_an_item(KeyStr_KeyboradLanguage, IMG_KeyboradLanguage, "isfsetting-efl", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
 
-       __create_an_item(KeyStr_EventsNotifications, IMG_EventsNotifications, "setting-phone-efl|viewtype:notification", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
+#if SUPPORT_STORAGE
+       __create_an_item(KeyStr_Storage, IMG_DefaultIcon, "setting-storage-efl", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
+#endif
+       __create_an_item(KeyStr_ManageApps, IMG_MANAGE_APPS, "setting-manage-applications-efl|viewtype:manage-applications", Cfg_Item_Pos_Level1,
+                           Cfg_Item_Resetable);
+
+       __create_an_item(KeyStr_WebApps, IMG_Web_Apps, "webapp-common-efl", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
+
+#if SUPPORT_CERTIFICATES
+       __create_an_item(KeyStr_CertUI, IMG_MANAGE_APPS, "setting-manage-certificates-efl", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
+#endif
+
        __create_an_item(KeyStr_Memory, IMG_Memory, "setting-memory-efl", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
        __create_an_item(KeyStr_Reset, IMG_Reset, "setting-reset-efl", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
+       __create_an_item(KeyStr_DeveloperOption, IMG_USBconnection, "setting-developeroption-efl|viewtype:usb", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
        __create_an_item(KeyStr_AboutPhone, IMG_AboutPhone, "setting-about-efl", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
 
        /* Applications */
        __create_a_menu(KeyStr_Applications);
 
-       __create_an_item_by_pkg(KeyStr_Call, "org.tizen.phone", "setting-call-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
-       __create_an_item_by_pkg(KeyStr_Messages, "org.tizen.message", "msg-setting-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
-       __create_an_item_by_pkg(KeyStr_Contacts, "org.tizen.contacts", "contacts-settings-efl|request_type:71", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
+       __create_an_item(KeyStr_Call, IMG_Call, "setting-call-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
+       __create_an_item(KeyStr_Messages, IMG_Messages, "msg-setting-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
+       __create_an_item(KeyStr_Email, IMG_Email, "email-setting-efl|VIEW_TYPE:main-view", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
+       __create_an_item(KeyStr_Contacts, IMG_Contacts, "contacts-settings-efl|request_type:71", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
+
+       __create_an_item(KeyStr_Calendar, IMG_Calendar, "calendar-settings-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
+
+       __create_an_item(KeyStr_Gallery, IMG_Gallery, "setting-gallery-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
+       __create_an_item(KeyStr_VoiceRecorder, IMG_VoiceRecorder, "setting-voicerecorder-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
+
+#if SUPPORT_FMradio
+       // FMradio setting
+       __create_an_item_by_pkg(KeyStr_FMRadio, "org.tizen.fm-radio", "setting-fmradio-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
+       SETTING_TRACE_DEBUG("Added FMRadio");
+#endif
 
-       __create_an_item_by_pkg(KeyStr_Calendar, "org.tizen.efl-calendar", "calendar-settings-efl", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
 
-       __create_an_item_by_pkg(KeyStr_Gallery, "org.tizen.gallery", "setting-gallery-efl", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
 
 
-       /* Downloaded App */
-       __create_a_menu(KeyStr_DownloadedAPPs);
 
-       __create_an_item(KeyStr_ManageApps, IMG_MANAGE_APPS, "setting-manage-applications-efl|viewtype:manage-applications", Cfg_Item_Pos_Level1,
-                           Cfg_Item_Resetable);
 
+#if DISABLED_CODE
+       __create_an_item_by_pkg(KeyStr_NFC, "com.samsung.nfc-app", "setting-nfc-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
+#endif
+
+       /* Downloaded App */
+       __create_a_menu(KeyStr_DownloadedAPPs);
 
        /* write to file */
-       ret = setting_cfg_file_write( category_list );
+       int ret = setting_cfg_file_write( category_list );
 
        json_node_free( category_list );
 
@@ -171,6 +232,14 @@ int setting_cfg_create(void)
 /* load file */
 int setting_cfg_file_read( void )
 {
+#if DISABLED_CODE
+       if (access( CFG_FILE_PATH, R_OK|F_OK ) !=0 )
+       {
+               SETTING_TRACE("file [%s] not legal, need to check your file-system.[%s:%d]\n", CFG_FILE_PATH, __FILE__, __LINE__);
+               //return Cfg_Error_Type_FilePermissionDenied;
+               return FALSE;
+       }
+#endif
        parser = json_parser_new (); /* to be freed on exit */
 
        /* file -> parser */
@@ -179,6 +248,8 @@ int setting_cfg_file_read( void )
 
        if( FALSE == ret )
        {
+               return FALSE;
+#if DISABLED_CODE
                SETTING_TRACE_ERROR("error->message:%s", (char*)(error->message));
 
         /* The file is existing and can be accessed normally, but it was
@@ -206,7 +277,7 @@ int setting_cfg_file_read( void )
         }
         /*if the failed is  caused by reading the file recursively invoking */
         return setting_cfg_file_read();
-
+#endif
        }
 
        /* parser -> root */
@@ -239,6 +310,7 @@ int setting_cfg_file_write( JsonNode * node )
 }
 
 /*   public functions  */
+#if DISABLED_CODE
 int setting_cfg_init( void )
 {
        g_type_init ();
@@ -307,6 +379,47 @@ int setting_cfg_init( void )
 
        return Cfg_Error_Type_Sucess;
 }
+#endif
+
+int setting_cfg_init( void )
+{
+       g_type_init ();
+
+       if (!access(CFG_FILE_PATH, R_OK|W_OK|F_OK )) { // succeed to access
+               if(!setting_cfg_file_read()) { // return FALSE
+                       if (remove(CFG_FILE_PATH)) {
+                               return Cfg_Error_Type_RemoveCfg_Failed;
+                       }
+                       return Cfg_Error_Type_ReadCfg_Failed;
+               }
+
+               return Cfg_Error_Type_Sucess;
+       } else { // fail to access
+               switch (errno) {
+                       // file non-existing case
+                       case ENOENT:
+                               SETTING_TRACE_ERROR("non-existing file/dir");
+                               ecore_file_mkdir(CFG_FILE_DIR_PATH);
+                               if (!setting_cfg_create()) { // return FALSE
+                                       SETTING_TRACE_ERROR("Error to create a new config file");
+                                       return Cfg_Error_Type_CreateCfg_Failed;
+                               }
+                               if(!setting_cfg_file_read() ) { // return FALSE
+                                       if (remove(CFG_FILE_PATH)) {
+                                               return Cfg_Error_Type_RemoveCfg_Failed;
+                                       }
+                                       return Cfg_Error_Type_ReadCfg_Failed;
+                               }
+
+                               return Cfg_Error_Type_Sucess;
+                       // other cases
+                       case EACCES:
+                       case EROFS:
+                       default:
+                               return Cfg_Error_Type_DirPermissionDenied;
+               }
+       }
+}
 
 void setting_cfg_exit( void )
 {
@@ -546,6 +659,55 @@ void setting_cfg_remove_downloaded_app( char * keyname )
        }
 }
 
+bool is_ug_installed_by_ug_args(void *data)
+{
+   retv_if(!data, TRUE);//if passing NULL,drawing it
+    char* ug_args = data;
+    char *ug_name = get_ug_path_from_ug_args(ug_args);
+
+    bool is_installed_in_usr = false;
+    bool is_installed_in_opt = false;
+
+    //1.first do exist-checking in /usr/ug/lib
+    char ug_file[PATH_MAX + 1];
+    snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH, ug_name);
+    struct stat st;
+    if(stat(ug_file, &st) != 0) {
+
+        //2.if it does not exit in /usr/ug/lib, then do exist-checking in /usr/ug/lib
+        memset(ug_file, 0x00, PATH_MAX + 1);
+        snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH_USR, ug_name);
+        if(stat(ug_file, &st) != 0) {
+            //both not exist,skip it
+            SETTING_TRACE_ERROR(" libug-%s.so is *NOT* present, so skip it..\n", ug_name);
+            //return FALSE;
+            is_installed_in_usr = false;
+        }
+    }
+    is_installed_in_usr = true;
+
+    //2.first do exist-checking in /opt/ug/lib
+    //char ug_file[PATH_MAX + 1];
+    memset(ug_file, 0x00, PATH_MAX + 1);
+    snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH_OPT, ug_name);
+    //struct stat st;
+    if(stat(ug_file, &st) != 0) {
+
+        //2.if it does not exit in /usr/ug/lib, then do exist-checking in /usr/ug/lib
+        memset(ug_file, 0x00, PATH_MAX + 1);
+        snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH_USR_OPT, ug_name);
+        if(stat(ug_file, &st) != 0) {
+            //both not exist,skip it
+            SETTING_TRACE_ERROR(" libug-%s.so is *NOT* present, so skip it..\n", ug_name);
+            //return FALSE;
+            is_installed_in_opt = false;
+        }
+    }
+    is_installed_in_opt = true;
+
+    return (is_installed_in_opt || is_installed_in_opt);
+}
+
 /*other relative function*/
 char *get_ug_path_from_ug_args(void *data)
 {
@@ -574,7 +736,7 @@ char *get_ug_path_from_ug_args(void *data)
        return path;
 }
 
-bundle *get_bundle_from_ug_args(void *data)
+service_h get_bundle_from_ug_args(void *data)
 {
        /*SETTING_TRACE_BEGIN;*/
        char *p = (char *)data;
@@ -585,19 +747,19 @@ bundle *get_bundle_from_ug_args(void *data)
        char *q = strchr(p, '|');
        if (q) {                /* (key, value) pairs exit. eg: ug_args = "sevenemail-setting-efl|caller:setting; cmd:main option" */
                /* alloc data */
-               bundle *b = bundle_create();
-               if (!b)
+               service_h svc;
+               if (service_create(&svc))
                        return NULL;
                int str_len = safeStrLen(p) + 1;
                char *v_key = (char *)calloc(1, str_len);
                if (!v_key) {
-                       bundle_free(b);
+                       service_destroy(svc);
                        return NULL;
                }
 
                char *v_value = (char *)calloc(1, str_len);
                if (!v_value) {
-                       bundle_free(b);
+                       service_destroy(svc);
                        FREE(v_key);
                        return NULL;
                }
@@ -615,7 +777,7 @@ bundle *get_bundle_from_ug_args(void *data)
                                        SETTING_TRACE
                                            ("To add ('%s', '%s') to bundle data",
                                             v_key, v_value);
-                                       bundle_add(b, v_key, v_value);
+                                       service_add_extra_data(svc, v_key, v_value);
                                } else {
                                        SETTING_TRACE_ERROR
                                            ("invalid key-value format!!\n");
@@ -628,11 +790,8 @@ bundle *get_bundle_from_ug_args(void *data)
                                        safeCopyStr(v_key, p, m - p);
                                        ++m;
                                        safeCopyStr(v_value, m, safeStrLen(m));
-                                       /*SETTING_TRACE
-                                           ("To add ('%s', '%s') to bundle data",
-                                            v_key, v_value);
-                                       */
-                                       bundle_add(b, v_key, v_value);
+
+                                       service_add_extra_data(svc, v_key, v_value);
                                } else {
                                        SETTING_TRACE_ERROR
                                            ("invalid key-value format!!\n");
@@ -647,7 +806,7 @@ bundle *get_bundle_from_ug_args(void *data)
 
                FREE(v_key);
                FREE(v_value);
-               return b;
+               return svc;
        } else {                /* eg: ug_args = "setting-browser-efl" */
 
                /*SETTING_TRACE("(key, value) pairs not exit");*/