delete opt desktop file during preload updated
[framework/appfw/pkgmgr-info.git] / parser / pkgmgr_parser.c
index 92097b9..eb73e69 100755 (executable)
@@ -33,7 +33,6 @@
 #include <libxml/xmlschemas.h>
 #include <vconf.h>
 
-
 #include "pkgmgr_parser.h"
 #include "pkgmgr_parser_internal.h"
 #include "pkgmgr_parser_db.h"
@@ -276,7 +275,7 @@ static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
        void *lib_handle = NULL;
        int (*plugin_install) (xmlDocPtr, const char *);
        int ret = -1;
-       char *ac;
+       char *ac = NULL;
 
        switch (action) {
        case ACTION_INSTALL:
@@ -301,16 +300,15 @@ static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
                DBGE("dlopen is failed lib_path[%s]\n", lib_path);
                goto END;
        }
-
        if ((plugin_install =
-            dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
+               dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
                DBGE("can not find symbol \n");
                goto END;
        }
 
        ret = plugin_install(docPtr, pkgid);
 
- END:
+END:
        if (lib_path)
                free(lib_path);
        if (lib_handle)
@@ -1227,6 +1225,10 @@ static void __ps_free_uiapplication(uiapplication_x *uiapplication)
                free((void *)uiapplication->package);
                uiapplication->package = NULL;
        }
+       if (uiapplication->launchcondition) {
+               free((void *)uiapplication->launchcondition);
+               uiapplication->launchcondition = NULL;
+       }
        /*Free Label*/
        if (uiapplication->label) {
                label_x *label = uiapplication->label;
@@ -1355,6 +1357,15 @@ static void __ps_free_uiapplication(uiapplication_x *uiapplication)
                free((void *)uiapplication->guestmode_visibility);
                uiapplication->guestmode_visibility = NULL;
        }
+       if (uiapplication->app_component) {
+               free((void *)uiapplication->app_component);
+               uiapplication->app_component = NULL;
+       }
+       if (uiapplication->permission_type) {
+               free((void *)uiapplication->permission_type);
+               uiapplication->permission_type = NULL;
+       }
+
        free((void*)uiapplication);
        uiapplication = NULL;
 }
@@ -1391,6 +1402,10 @@ static void __ps_free_serviceapplication(serviceapplication_x *serviceapplicatio
                free((void *)serviceapplication->package);
                serviceapplication->package = NULL;
        }
+       if (serviceapplication->permission_type) {
+               free((void *)serviceapplication->permission_type);
+               serviceapplication->permission_type = NULL;
+       }
        /*Free Label*/
        if (serviceapplication->label) {
                label_x *label = serviceapplication->label;
@@ -2129,6 +2144,8 @@ __get_icon_with_path(const char* icon)
                        if (access(icon_with_path, R_OK) == 0) break;
                        snprintf(icon_with_path, len, "/usr/apps/%s/res/icons/default/small/%s", package, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
+                       snprintf(icon_with_path, len, "/usr/ug/res/images/%s/%s", package, icon);
+                       if (access(icon_with_path, R_OK) == 0) break;
                } while (0);
 
                free(theme);
@@ -2146,6 +2163,54 @@ __get_icon_with_path(const char* icon)
        }
 }
 
+static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
+{
+       int i = 0;
+       char delims[] = "=";
+       char *ret_result = NULL;
+       char *tag = NULL;
+
+       if (tagv == NULL)
+               return;
+
+       for (tag = strdup(tagv[0]); tag != NULL; ) {
+               ret_result = strtok(tag, delims);
+
+               /*check tag :  preload */
+               if (strcmp(ret_result, "preload") == 0) {
+                       ret_result = strtok(NULL, delims);
+                       if (strcmp(ret_result, "true") == 0) {
+                               free((void *)mfx->preload);
+                               mfx->preload = strdup("true");
+                       } else if (strcmp(ret_result, "false") == 0) {
+                               free((void *)mfx->preload);
+                               mfx->preload = strdup("false");
+                       }
+               /*check tag :  removable*/
+               } else if (strcmp(ret_result, "removable") == 0) {
+                       ret_result = strtok(NULL, delims);
+                       if (strcmp(ret_result, "true") == 0){
+                               free((void *)mfx->removable);
+                               mfx->removable = strdup("true");
+                       } else if (strcmp(ret_result, "false") == 0) {
+                               free((void *)mfx->removable);
+                               mfx->removable = strdup("false");
+                       }
+               /*check tag :  not matched*/
+               } else
+                       DBG("tag process [%s]is not defined\n", ret_result);
+
+               free(tag);
+
+               /*check next value*/
+               if (tagv[++i] != NULL)
+                       tag = strdup(tagv[i]);
+               else {
+                       DBG("tag process success...\n");
+                       return;
+               }
+       }
+}
 
 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon)
 {
@@ -2393,6 +2458,7 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
                                free((void *)uiapplication->appid);
                        uiapplication->appid = newappid;
                }
+               uiapplication->package= strdup(package);
        }
        if (xmlTextReaderGetAttribute(reader, XMLCHAR("exec")))
                uiapplication->exec = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("exec")));
@@ -2446,6 +2512,14 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
        } else {
                uiapplication->mainapp = strdup("false");
        }
+       if (xmlTextReaderGetAttribute(reader, XMLCHAR("launchcondition"))) {
+               uiapplication->launchcondition = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("launchcondition")));
+               if (uiapplication->launchcondition == NULL)
+                       uiapplication->launchcondition = strdup("false");
+       } else {
+               uiapplication->launchcondition = strdup("false");
+       }
+
        if (xmlTextReaderGetAttribute(reader, XMLCHAR("indicatordisplay"))) {
                uiapplication->indicatordisplay = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("indicatordisplay")));
                if (uiapplication->indicatordisplay == NULL)
@@ -2468,6 +2542,13 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
        } else {
                uiapplication->guestmode_visibility = strdup("true");
        }
+       if (xmlTextReaderGetAttribute(reader, XMLCHAR("permission-type"))) {
+               uiapplication->permission_type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("permission-type")));
+               if (uiapplication->permission_type == NULL)
+                       uiapplication->permission_type = strdup("normal");
+       } else {
+               uiapplication->permission_type = strdup("normal");
+       }
 
        depth = xmlTextReaderDepth(reader);
        while ((ret = __next_child_element(reader, depth))) {
@@ -2689,6 +2770,13 @@ static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceappli
        } else {
                serviceapplication->autorestart = strdup("false");
        }
+       if (xmlTextReaderGetAttribute(reader, XMLCHAR("permission-type"))) {
+               serviceapplication->permission_type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("permission-type")));
+               if (serviceapplication->permission_type == NULL)
+                       serviceapplication->permission_type = strdup("normal");
+       } else {
+               serviceapplication->permission_type = strdup("normal");
+       }
 
        depth = xmlTextReaderDepth(reader);
        while ((ret = __next_child_element(reader, depth))) {
@@ -3159,6 +3247,17 @@ static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx)
                        } else {
                                mfx->appsetting = strdup("false");
                        }
+                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("storeclient-id")))
+                               mfx->storeclient_id= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("storeclient-id")));
+                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("nodisplay-setting"))) {
+                               mfx->nodisplay_setting = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("nodisplay-setting")));
+                               if (mfx->nodisplay_setting == NULL)
+                                       mfx->nodisplay_setting = strdup("false");
+                       } else {
+                               mfx->nodisplay_setting = strdup("false");
+                       }
+                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("url")))
+                               mfx->package_url= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("url")));
 
                        /*Assign default values. If required it will be overwritten in __add_preload_info()*/
                        mfx->preload = strdup("False");
@@ -3350,6 +3449,37 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, bool is_update)
                        fwrite(buf, 1, strlen(buf), file);
                }
 
+               // MIME types
+               if(mfx->uiapplication && mfx->uiapplication->appsvc) {
+                       appsvc_x *asvc = mfx->uiapplication->appsvc;
+                       mime_x *mi = NULL;
+                       const char *mime = NULL;
+                       const char *mime_delim = "; ";
+                       int mime_count = 0;
+
+                       strncpy(buf, "MimeType=", BUFMAX-1);
+                       while (asvc) {
+                               mi = asvc->mime;
+                               while (mi) {
+                                       mime_count++;
+                                       mime = mi->name;
+                                       DBG("MIME type: %s\n", mime);
+                                       strncat(buf, mime, BUFMAX-strlen(buf)-1);
+                                       if(mi->next) {
+                                               strncat(buf, mime_delim, BUFMAX-strlen(buf)-1);
+                                       }
+
+                                       mi = mi->next;
+                                       mime = NULL;
+                               }
+                               asvc = asvc->next;
+                       }
+                       DBG("MIME types: buf[%s]\n", buf);
+                       DBG("MIME count: %d\n", mime_count);
+                       if(mime_count)
+                               fwrite(buf, 1, strlen(buf), file);
+               }
+
                if(mfx->version) {
                        snprintf(buf, BUFMAX, "Version=%s\n", mfx->version);
                        fwrite(buf, 1, strlen(buf), file);
@@ -3582,11 +3712,12 @@ static int __ps_remove_nativeapp_desktop(manifest_x *mfx)
 {
        char filepath[PKG_STRING_LEN_MAX] = "";
        int ret = 0;
+       uiapplication_x *uiapplication = mfx->uiapplication;
 
-       for(; mfx->uiapplication; mfx->uiapplication=mfx->uiapplication->next) {
-               snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, mfx->uiapplication->appid);
+       for(; uiapplication; uiapplication=uiapplication->next) {
+               snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, uiapplication->appid);
 
-               __ail_change_info(AIL_REMOVE, mfx->uiapplication->appid);
+               __ail_change_info(AIL_REMOVE, uiapplication->appid);
 
                ret = remove(filepath);
                if (ret <0)
@@ -3596,6 +3727,39 @@ static int __ps_remove_nativeapp_desktop(manifest_x *mfx)
         return 0;
 }
 
+#define LIBAPPSVC_PATH "/usr/lib/libappsvc.so.0"
+
+static int __ps_remove_appsvc_db(manifest_x *mfx)
+{
+       void *lib_handle = NULL;
+       int (*appsvc_operation) (const char *);
+       int ret = 0;
+       uiapplication_x *uiapplication = mfx->uiapplication;
+
+       if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
+               DBGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAPPSVC_PATH);
+               goto END;
+       }
+
+       if ((appsvc_operation =
+                dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
+               DBGE("can not find symbol \n");
+               goto END;
+       }
+
+       for(; uiapplication; uiapplication=uiapplication->next) {
+               ret = appsvc_operation(uiapplication->appid);
+               if (ret <0)
+                       DBGE("can not operation  symbol \n");
+       }
+
+END:
+       if (lib_handle)
+               dlclose(lib_handle);
+
+       return ret;
+}
+
 #define MANIFEST_RO_PREFIX "/usr/share/packages/"
 #define PRELOAD_PACKAGE_LIST "/usr/etc/package-manager/preload/preload_list.txt"
 static int __add_preload_info(manifest_x * mfx, const char *manifest)
@@ -3660,6 +3824,24 @@ static int __add_preload_info(manifest_x * mfx, const char *manifest)
        return 0;
 }
 
+static int __check_preload_updated(manifest_x * mfx, const char *manifest)
+{
+       char filepath[PKG_STRING_LEN_MAX] = "";
+       int ret = 0;
+       uiapplication_x *uiapplication = mfx->uiapplication;
+
+       if(strstr(manifest, MANIFEST_RO_PREFIX)) {
+/* if preload app is updated, then remove previous desktop file on RW*/
+               for(; uiapplication; uiapplication=uiapplication->next) {
+                               snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, uiapplication->appid);
+                       ret = remove(filepath);
+                       if (ret <0)
+                               return -1;
+               }
+
+               return 0;
+       }
+}
 
 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
 {
@@ -3733,6 +3915,10 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
                free((void *)mfx->appsetting);
                mfx->appsetting = NULL;
        }
+       if (mfx->nodisplay_setting) {
+               free((void *)mfx->nodisplay_setting);
+               mfx->nodisplay_setting = NULL;
+       }
 
        /*Free Icon*/
        if (mfx->icon) {
@@ -3910,7 +4096,7 @@ API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
 
 API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
 {
-       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", NULL};
+       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
        if (manifest == NULL) {
                DBG("argument supplied is NULL\n");
                return PMINFO_R_EINVAL;
@@ -3936,6 +4122,8 @@ API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char
        else
                mfx->update = strdup("false");
 
+       __ps_process_tag(mfx, tagv);
+
        ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
        if (ret == -1)
                DBG("DB Insert failed\n");
@@ -3973,7 +4161,7 @@ API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
 
 API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
 {
-       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", NULL};
+       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
        if (manifest == NULL) {
                DBG("argument supplied is NULL\n");
                return PMINFO_R_EINVAL;
@@ -3981,6 +4169,9 @@ API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *con
        DBG("parsing manifest for upgradation: %s\n", manifest);
        manifest_x *mfx = NULL;
        int ret = -1;
+       bool preload;
+       pkgmgrinfo_pkginfo_h handle;
+
        xmlInitParser();
        mfx = pkgmgr_parser_process_manifest_xml(manifest);
        DBG("Parsing Finished\n");
@@ -3990,6 +4181,20 @@ API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *con
        __streamFile(manifest, ACTION_UPGRADE, temp, mfx->package);
        __add_preload_info(mfx, manifest);
        DBG("Added preload infomation\n");
+       __check_preload_updated(mfx, manifest);
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
+       if (ret != PMINFO_R_OK)
+               DBG("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
+
+       ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
+       if (ret != PMINFO_R_OK)
+               DBG("pkgmgrinfo_pkginfo_is_preload failed\n");
+
+       if (preload){
+               free((void *)mfx->preload);
+               mfx->preload = strdup("true");
+       }
 
        mfx->update = strdup("true");
        ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
@@ -4004,6 +4209,7 @@ API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *con
        else
                DBG("Creating desktop file Success\n");
 
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
        pkgmgr_parser_free_manifest_xml(mfx);
        DBG("Free Done\n");
        xmlCleanupParser();
@@ -4013,7 +4219,7 @@ API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *con
 
 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
 {
-       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", NULL};
+       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
        if (manifest == NULL) {
                DBG("argument supplied is NULL\n");
                return PMINFO_R_EINVAL;
@@ -4043,6 +4249,12 @@ API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, ch
        else
                DBG("Removing desktop file Success\n");
 
+       ret = __ps_remove_appsvc_db(mfx);
+       if (ret == -1)
+               DBG("Removing appsvc_db failed\n");
+       else
+               DBG("Removing appsvc_db Success\n");
+
        pkgmgr_parser_free_manifest_xml(mfx);
        DBG("Free Done\n");
        xmlCleanupParser();