Fix directories to install TTS engine info file in tts-engine-parser.c and Fix pthread 81/109681/1
authorsooyeon.kim <sooyeon.kim@samsung.com>
Mon, 26 Dec 2016 12:28:56 +0000 (21:28 +0900)
committerWonnam Jang <wn.jang@samsung.com>
Wed, 11 Jan 2017 07:16:11 +0000 (23:16 -0800)
Change-Id: I9df608213f3446bc60e34090856445d838538880
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
(cherry picked from commit f02f850520bb152b65750ff81585e29a1cedde7f)

CMakeLists.txt
engine-parser/src/tts-engine-parser.c
packaging/tts.spec
server/ttsd_data.cpp

index 1b3a2d4..c9f5eec 100644 (file)
@@ -39,7 +39,7 @@ INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/common")
 INCLUDE(FindPkgConfig)
 pkg_check_modules(pkgs REQUIRED  
        aul capi-media-audio-io capi-appfw-app-manager capi-system-info dbus-1 dlog ecore
-       glib-2.0 libtzplatform-config libxml-2.0 vconf bundle buxton2
+       glib-2.0 libgum libtzplatform-config libxml-2.0 libsystemd-login vconf bundle buxton2
 )
 
 pkg_check_modules(pkgs_test REQUIRED
index 35ab1b7..1a3e8dc 100644 (file)
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <tzplatform_config.h>
+#include <systemd/sd-login.h>
+
+#include <gum/gum-user.h>
+#include <gum/gum-user-service.h>
+#include <gum/common/gum-user-types.h>
 
 /* Define EXPORT_API */
 #ifndef EXPORT_API
 #define TTS_ENGINE_BASE                tzplatform_mkpath(TZ_USER_HOME, "share/.voice/tts/1.0")
 #define TTS_ENGINE_INFO                tzplatform_mkpath(TZ_USER_SHARE, ".voice/tts/1.0/engine-info")
 
+#define TTS_GLOBAL_CONFIG_BASE         "/etc/skel/share/.voice"
+#define TTS_GLOBAL_HOME                "/etc/skel/share/.voice/tts"
+#define TTS_GLOBAL_ENGINE_BASE         "/etc/skel/share/.voice/tts/1.0"
+#define TTS_GLOBAL_ENGINE_INFO         "/etc/skel/share/.voice/tts/1.0/engine-info"
+
 #define TTS_METADATA_LANGUAGE                  "http://tizen.org/metadata/tts-engine/language"
 #define TTS_METADATA_CREDENTIAL_REQUIRED       "http://tizen.org/metadata/tts-engine/credential-required"
 
@@ -62,6 +72,15 @@ typedef struct metadata {
 } metadata;
 
 static xmlDocPtr g_doc;
+GumUser *g_guser = NULL;
+uid_t g_uid = 5001;
+GumUserType g_ut = GUM_USERTYPE_NONE;
+gchar *g_user_type = NULL;
+
+char *g_dir_config_base = NULL;
+char *g_dir_home = NULL;
+char *g_dir_engine_base = NULL;
+char *g_dir_engine_info = NULL;
 
 static int __create_engine_info_xml(const char *pkgid)
 {
@@ -75,66 +94,197 @@ static int __create_engine_info_xml(const char *pkgid)
        return 0;
 }
 
-static int __save_engine_info_xml(const char *pkgid)
+static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
 {
        LOGD("=== Save engine info doc");
+       char *dir_config_base = NULL;
+       char *dir_home = NULL;
+       char *dir_engine_base = NULL;
+       char *dir_engine_info = NULL;
+
+       if (NULL == ut || (NULL != ut && 0 == strcmp(ut, "none"))) {
+               LOGE("[ERROR] Usertype is NONE");
+               return -1;
+       }
+
+       uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+
+       LOGD("uid(%d)", uid);
+
+       if (globalapp_uid == uid) {
+               /* Global app */
+               dir_config_base = strdup(TTS_GLOBAL_CONFIG_BASE);
+               dir_home = strdup(TTS_GLOBAL_HOME);
+               dir_engine_base = strdup(TTS_GLOBAL_ENGINE_BASE);
+               dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
+       } else {
+               /* User app, Guest app, Security app */
+               if (NULL != g_dir_config_base)
+                       dir_config_base = strdup(g_dir_config_base);
+               if (NULL != g_dir_home)
+                       dir_home = strdup(g_dir_home);
+               if (NULL != g_dir_engine_base)
+                       dir_engine_base = strdup(g_dir_engine_base);
+               if (NULL != g_dir_engine_info)
+                       dir_engine_info = strdup(g_dir_engine_info);
+       }
+
+       if (NULL == dir_config_base || NULL == dir_home || NULL == dir_engine_base || NULL == dir_engine_info) {
+               LOGE("[ERROR] Fail to allocate memory");
+               if (NULL != dir_config_base) {
+                       free(dir_config_base);
+                       dir_config_base = NULL;
+               }
+               if (NULL != dir_home) {
+                       free(dir_home);
+                       dir_home = NULL;
+               }
+               if (NULL != dir_engine_base) {
+                       free(dir_engine_base);
+                       dir_engine_base = NULL;
+               }
+               if (NULL != dir_engine_info) {
+                       free(dir_engine_info);
+                       dir_engine_info = NULL;
+               }
+               return -1;
+       }
+
+       LOGD("[DEBUG] dir_engine_info(%s)", dir_engine_info);
+
 
        /* Make directories */
-       if (0 != access(TTS_CONFIG_BASE, F_OK)) {
-               if (0 != mkdir(TTS_CONFIG_BASE, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
-                       LOGE("[ERROR] Fail to make directory : %s", TTS_CONFIG_BASE);
+       if (0 != access(dir_config_base, F_OK)) {
+               if (0 != mkdir(dir_config_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
+                       LOGE("[ERROR] Fail to make directory : %s", dir_config_base);
+                       free(dir_config_base);
+                       dir_config_base = NULL;
+                       free(dir_home);
+                       dir_home = NULL;
+                       free(dir_engine_base);
+                       dir_engine_base = NULL;
+                       free(dir_engine_info);
+                       dir_engine_info = NULL;
                        return -1;
                } else {
-                       LOGD("Success to make directory : %s", TTS_CONFIG_BASE);
+                       LOGD("Success to make directory : %s", dir_config_base);
                }
        }
 
-       if (0 != access(TTS_HOME, F_OK)) {
-               if (0 != mkdir(TTS_HOME, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
-                       LOGE("[ERROR] Fail to make directory : %s", TTS_HOME);
+       if (0 != access(dir_home, F_OK)) {
+               if (0 != mkdir(dir_home, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
+                       LOGE("[ERROR] Fail to make directory : %s", dir_home);
+                       free(dir_config_base);
+                       dir_config_base = NULL;
+                       free(dir_home);
+                       dir_home = NULL;
+                       free(dir_engine_base);
+                       dir_engine_base = NULL;
+                       free(dir_engine_info);
+                       dir_engine_info = NULL;
                        return -1;
                } else {
-                       LOGD("Success to make directory : %s", TTS_HOME);
+                       LOGD("Success to make directory : %s", dir_home);
                }
        }
 
-       if (0 != access(TTS_ENGINE_BASE, F_OK)) {
-               if (0 != mkdir(TTS_ENGINE_BASE, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
-                       LOGE("[ERROR] Fail to make directory : %s", TTS_ENGINE_BASE);
+       if (0 != access(dir_engine_base, F_OK)) {
+               if (0 != mkdir(dir_engine_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
+                       LOGE("[ERROR] Fail to make directory : %s", dir_engine_base);
+                       free(dir_config_base);
+                       dir_config_base = NULL;
+                       free(dir_home);
+                       dir_home = NULL;
+                       free(dir_engine_base);
+                       dir_engine_base = NULL;
+                       free(dir_engine_info);
+                       dir_engine_info = NULL;
                        return -1;
                } else {
-                       LOGD("Success to make directory : %s", TTS_ENGINE_BASE);
+                       LOGD("Success to make directory : %s", dir_engine_base);
                }
        }
 
-       if (0 != access(TTS_ENGINE_INFO, F_OK)) {
-               if (0 != mkdir(TTS_ENGINE_INFO, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
-                       LOGE("[ERROR] Fail to make directory : %s", TTS_ENGINE_INFO);
+       if (0 != access(dir_engine_info, F_OK)) {
+               if (0 != mkdir(dir_engine_info, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
+                       LOGE("[ERROR] Fail to make directory : %s", dir_engine_info);
+                       free(dir_config_base);
+                       dir_config_base = NULL;
+                       free(dir_home);
+                       dir_home = NULL;
+                       free(dir_engine_base);
+                       dir_engine_base = NULL;
+                       free(dir_engine_info);
+                       dir_engine_info = NULL;
                        return -1;
                } else {
-                       LOGD("Success to make directory : %s", TTS_ENGINE_INFO);
+                       LOGD("Success to make directory : %s", dir_engine_info);
                }
        }
 
+
        char path[256] = {'\0',};
-       snprintf(path, 256, "%s/%s.xml", TTS_ENGINE_INFO, pkgid);
+       snprintf(path, 256, "%s/%s.xml", dir_engine_info, pkgid);
        int ret = xmlSaveFormatFile(path, g_doc, 1);
        LOGD("xmlSaveFile (%d)", ret);
+
+       free(dir_config_base);
+       dir_config_base = NULL;
+       free(dir_home);
+       dir_home = NULL;
+       free(dir_engine_base);
+       dir_engine_base = NULL;
+       free(dir_engine_info);
+       dir_engine_info = NULL;
+
        LOGD("===");
        return 0;
 }
 
-static int __remove_engine_info_xml(const char *pkgid)
+static int __remove_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
 {
        LOGD("=== Remove engine info doc");
+
+       char *dir_engine_info = NULL;
+
+       if (NULL == ut || (NULL != ut && 0 == strcmp(ut, "none"))) {
+               LOGE("[ERROR] Usertype is NONE");
+               return -1;
+       }
+
+       uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+
+       LOGD("uid(%d)", uid);
+
+       if (globalapp_uid == uid) {
+               /* Global app */
+               dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
+       } else {
+               /* User app, Guest app, Security app */
+               if (NULL != g_dir_engine_info)
+                       dir_engine_info = strdup(g_dir_engine_info);
+       }
+
+       if (NULL == dir_engine_info) {
+               LOGE("[ERROR] Fail to allocate memory");
+               return -1;
+       }
+
+       LOGD("[DEBUG] dir_engine_info(%s)", dir_engine_info);
+
+
        char path[256] = {'\0',};
-       snprintf(path, 256, "%s/%s.xml", TTS_ENGINE_INFO, pkgid);
+       snprintf(path, 256, "%s/%s.xml", dir_engine_info, pkgid);
        if (0 == access(path, F_OK)) {
                LOGD("Remove engine info xml(%s)", path);
                if (0 != remove(path)) {
                        LOGE("[ERROR] Fail to Remove engine info xml(%s)", path);
                }
        }
+
+       free(dir_engine_info);
+       dir_engine_info = NULL;
+
        LOGD("===");
        return 0;
 }
@@ -177,35 +327,8 @@ static void __insert_language_from_metadata(xmlNodePtr root, const char *languag
        tmp_free = NULL;
 }
 
-EXPORT_API
-int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
+static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *list)
 {
-       LOGD("METADATA INSTALL");
-       LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
-
-       uid_t uid = 0;
-       int ret = -1;
-       ret = pkgmgr_installer_info_get_target_uid(&uid);
-       if (ret < 0) {
-               LOGE("[ERROR] Fail to get target uid");
-               return 0;
-       } else {
-               LOGD("uid(%d)", uid);
-       }
-
-       ret = tzplatform_set_user(uid);
-       if (ret < 0) {
-               LOGE("[ERROR] Invalid uid");
-               return 0;
-       } else {
-               LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
-       }
-
-       if (0 >= g_list_length(list)) {
-               LOGE("[ERROR] No Engine Metadata");
-               return 0;
-       }
-
        GList *iter = NULL;
        metadata *md = NULL;
 
@@ -217,7 +340,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
        root = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_BASE);
        if (NULL == root) {
                LOGE("[ERROR] Fail to get new node");
-               xmlFreeDoc(g_doc);
+//             xmlFreeDoc(g_doc);
                return -1;
        }
        xmlDocSetRootElement(g_doc, root);
@@ -227,6 +350,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
        xmlNodeSetContent(cur, (const xmlChar*)pkgid);
        xmlAddChild(root, cur);
 
+
        iter = g_list_first(list);
        while (NULL != iter) {
                md = (metadata *)iter->data;
@@ -251,8 +375,296 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
 
        LOGD("");
 
-       __save_engine_info_xml(pkgid);
+       return 0;
+
+}
+
+EXPORT_API
+int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
+{
+       LOGD("METADATA INSTALL");
+       LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
+
+       int ret = -1;
+       ret = pkgmgr_installer_info_get_target_uid(&g_uid);
+       if (ret < 0) {
+               LOGE("[ERROR] Fail to get target uid");
+               return 0;
+       } else {
+               LOGD("uid(%d)", g_uid);
+               printf("[Parser Debug][DEBUG] uid(%d)", g_uid);
+       }
+
+       uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+       if (globalapp_uid == g_uid) {
+               g_user_type = g_strdup("admin");
+       } else {
+               g_guser = gum_user_get_sync(g_uid, FALSE);
+               if (NULL == g_guser) {
+                       LOGE("[ERROR] g_guser is NULL");
+                       return -1;
+               }
+
+               g_object_get(G_OBJECT(g_guser), "usertype", &g_ut, NULL);
+               g_user_type = g_strdup(gum_user_type_to_string(g_ut));
+       }
+
+       if (NULL == g_user_type) {
+               LOGE("[ERROR] Fail to allocate memory");
+               if (NULL != g_guser) {
+                       g_object_unref(g_guser);
+                       g_guser = NULL;
+               }
+               return -1;
+       }
+
+       if (0 == strcmp(g_user_type, "none")) {
+               /* GUM_USERTYPE_NONE */
+               LOGE("[ERROR] Fail to get target uid");
+               g_object_unref(g_guser);
+               g_guser = NULL;
+               g_free(g_user_type);
+               return -1;
+       }
+
+       if (globalapp_uid == g_uid) {
+               /* global directory */
+               LOGD("[DEBUG] usertype: %s", g_user_type);
+               if (0 >= g_list_length(list)) {
+                       LOGE("[ERROR] No Engine Metadata");
+                       g_free(g_user_type);
+                       return 0;
+               }
+
+               if (0 != __write_metadata_inxml(pkgid, appid, list)) {
+                       LOGE("[ERROR] Fail to write metadata in the xml");
+                       xmlFreeDoc(g_doc);
+                       g_free(g_user_type);
+                       return -1;
+               }
+
+               /* Get user data by using libgum */
+
+               GumUserService *gus = NULL;
+               GumUserList *users = NULL;
+               GumUserList *iter = NULL;
+               GumUser *user = NULL;
+               gchar **query;
+               GumUserType gumut = GUM_USERTYPE_NONE;
+               gchar *user_type = NULL;
+
+               uid_t uid;
+               gchar *home_dir = NULL;
+
+               gus = gum_user_service_create_sync(TRUE);
+               if (!gus) {
+                       LOGE("Failed to create gum user service");
+                       g_free(g_user_type);
+                       return -1;
+               }
+
+               query = g_strsplit("admin,normal", ",", -1);
+
+               users = gum_user_service_get_user_list_sync(gus, (const gchar *const *)query);
+               g_strfreev(query);
+
+               if (!users) {
+                       LOGE("Failed to get gum user list");
+                       g_object_unref(gus);
+                       gus = NULL;
+                       g_free(g_user_type);
+                       return -1;
+               }
+
+               /* Make new user list */
+
+               iter = users;
+               while (iter != NULL) {
+                       user = (GumUser*) iter->data;
+                       g_object_get(G_OBJECT(user), "uid", &uid, NULL);
+                       if (NULL != home_dir) {
+                               free(home_dir);
+                               home_dir = NULL;
+                       }
+                       g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
+                       g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
+                       user_type = g_strdup(gum_user_type_to_string(gumut));
+                       if (NULL == user_type) {
+                               gum_user_service_list_free(users);
+                               g_object_unref(gus);
+                               gus = NULL;
+                               return -1;
+                       }
+
+                       LOGD("[DEBUG] user info");
+                       if (NULL != home_dir) {
+                               LOGD("[DEBUG] uid(%d), user_type(%s), home_dir(%s)", uid, user_type, home_dir);
+
+                               g_dir_config_base = (char*)calloc(strlen(home_dir) + 14, sizeof(char));
+                               g_dir_home = (char*)calloc(strlen(home_dir) + 18, sizeof(char));
+                               g_dir_engine_base = (char*)calloc(strlen(home_dir) + 22, sizeof(char));
+                               g_dir_engine_info = (char*)calloc(strlen(home_dir) + 34, sizeof(char));
+
+                               if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
+                                       LOGE("[ERROR] Fail to allocate memory");
+                                       if (NULL != g_dir_config_base) {
+                                               free(g_dir_config_base);
+                                               g_dir_config_base = NULL;
+                                       }
+                                       if (NULL != g_dir_home) {
+                                               free(g_dir_home);
+                                               g_dir_home = NULL;
+                                       }
+                                       if (NULL != g_dir_engine_base) {
+                                               free(g_dir_engine_base);
+                                               g_dir_engine_base = NULL;
+                                       }
+                                       if (NULL != g_dir_engine_info) {
+                                               free(g_dir_engine_info);
+                                               g_dir_engine_info = NULL;
+                                       }
+                                       gum_user_service_list_free(users);
+                                       g_object_unref(gus);
+                                       gus = NULL;
+                                       return -1;
+                               }
+                               snprintf(g_dir_config_base, strlen(home_dir) + 14, "%s/share/.voice", home_dir);
+                               snprintf(g_dir_home, strlen(home_dir) + 18, "%s/share/.voice/tts", home_dir);
+                               snprintf(g_dir_engine_base, strlen(home_dir) + 22, "%s/share/.voice/tts/1.0", home_dir);
+                               snprintf(g_dir_engine_info, strlen(home_dir) + 34, "%s/share/.voice/tts/1.0/engine-info", home_dir);
+
+                               LOGD("[DEBUG] g_dir_engine_info(%s)", g_dir_engine_info);
+
+                               if (0 != __save_engine_info_xml(pkgid, user_type, uid)) {
+                                       LOGE("[ERROR] Fail to make engine info file");
+                               }
+
+                               free(g_dir_config_base);
+                               g_dir_config_base = NULL;
+                               free(g_dir_home);
+                               g_dir_home = NULL;
+                               free(g_dir_engine_base);
+                               g_dir_engine_base = NULL;
+                               free(g_dir_engine_info);
+                               g_dir_engine_info = NULL;
+
+                               g_free(user_type);
+                               user_type = NULL;
+                               free(home_dir);
+                               home_dir = NULL;
+
+                               iter = g_list_next(iter);
+                       } else {
+                               iter = g_list_next(iter);
+                       }
+
+                       if (NULL != user_type) {
+                               g_free(user_type);
+                               user_type = NULL;
+                       }
+               }
+
+               gum_user_service_list_free(users);
+               g_object_unref(gus);
+               gus = NULL;
+       } else {
+               /* user directory */
+               LOGD("[DEBUG] usertype: %s", g_user_type);
+
+               ret = tzplatform_set_user(g_uid);
+               if (ret < 0) {
+                       LOGE("[ERROR] Invalid uid");
+                       g_object_unref(g_guser);
+                       g_guser = NULL;
+                       g_free(g_user_type);
+                       return 0;
+               } else {
+                       LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
+                       printf("[Parser Debug][DEBUG] TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
+               }
+
+               if (0 >= g_list_length(list)) {
+                       LOGE("[ERROR] No Engine Metadata");
+                       g_object_unref(g_guser);
+                       g_guser = NULL;
+                       g_free(g_user_type);
+                       return 0;
+               }
+
+               if (0 != __write_metadata_inxml(pkgid, appid, list)) {
+                       LOGE("[ERROR] Fail to write metadata in the xml");
+                       xmlFreeDoc(g_doc);
+                       g_object_unref(g_guser);
+                       g_guser = NULL;
+                       g_free(g_user_type);
+                       return -1;
+               }
+
+               g_dir_config_base = strdup(TTS_CONFIG_BASE);
+               g_dir_home = strdup(TTS_HOME);
+               g_dir_engine_base = strdup(TTS_ENGINE_BASE);
+               g_dir_engine_info = strdup(TTS_ENGINE_INFO);
+
+               if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
+                       LOGE("[ERROR] Fail to allocate memory");
+                       if (NULL != g_dir_config_base) {
+                               free(g_dir_config_base);
+                               g_dir_config_base = NULL;
+                       }
+                       if (NULL != g_dir_home) {
+                               free(g_dir_home);
+                               g_dir_home = NULL;
+                       }
+                       if (NULL != g_dir_engine_base) {
+                               free(g_dir_engine_base);
+                               g_dir_engine_base = NULL;
+                       }
+                       if (NULL != g_dir_engine_info) {
+                               free(g_dir_engine_info);
+                               g_dir_engine_info = NULL;
+                       }
+                       xmlFreeDoc(g_doc);
+                       g_object_unref(g_guser);
+                       g_guser = NULL;
+                       g_free(g_user_type);
+                       return -1;
+               }
+
+               if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid)) {
+                       LOGE("[ERROR] Fail to make engine info file");
+                       xmlFreeDoc(g_doc);
+                       if (NULL != g_guser) {
+                               g_object_unref(g_guser);
+                               g_guser = NULL;
+                       }
+                       g_free(g_user_type);
+                       return -1;
+               }
+       }
+
        xmlFreeDoc(g_doc);
+       if (NULL != g_guser) {
+               g_object_unref(g_guser);
+               g_guser = NULL;
+       }
+       g_free(g_user_type);
+
+       if (NULL != g_dir_config_base) {
+               free(g_dir_config_base);
+               g_dir_config_base = NULL;
+       }
+       if (NULL != g_dir_home) {
+               free(g_dir_home);
+               g_dir_home = NULL;
+       }
+       if (NULL != g_dir_engine_base) {
+               free(g_dir_engine_base);
+               g_dir_engine_base = NULL;
+       }
+       if (NULL != g_dir_engine_info) {
+               free(g_dir_engine_info);
+               g_dir_engine_info = NULL;
+       }
 
        return 0;
 }
@@ -263,19 +675,190 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
        LOGD("METADATA UNINSTALL");
        LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
 
-       GList *iter = NULL;
-       metadata *md = NULL;
+       int ret = -1;
+       ret = pkgmgr_installer_info_get_target_uid(&g_uid);
+       if (ret < 0) {
+               LOGE("[ERROR] Fail to get target uid");
+               return 0;
+       } else {
+               LOGD("uid(%d)", g_uid);
+               printf("[Parser Debug][DEBUG] uid(%d)", g_uid);
+       }
 
-       iter = g_list_first(list);
-       while (NULL != iter) {
-               md = (metadata *)iter->data;
-               if (NULL != md && NULL != md->key) {
-                       LOGD(" - key(%s) value(%s)", md->key, md->value);
+       uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+       if (globalapp_uid == g_uid) {
+               g_user_type = g_strdup("admin");
+       } else {
+               g_guser = gum_user_get_sync(g_uid, FALSE);
+               if (NULL == g_guser) {
+                       LOGE("[ERROR] g_guser is NULL");
+                       return -1;
                }
-               iter = g_list_next(iter);
+
+               g_object_get(G_OBJECT(g_guser), "usertype", &g_ut, NULL);
+               g_user_type = g_strdup(gum_user_type_to_string(g_ut));
+       }
+
+       if (NULL == g_user_type) {
+               LOGE("[ERROR] Fail to allocate memory");
+               if (NULL != g_guser) {
+                       g_object_unref(g_guser);
+                       g_guser = NULL;
+               }
+               return -1;
+       }
+
+       if (0 == strcmp(g_user_type, "none")) {
+               /* GUM_USERTYPE_NONE */
+               LOGE("[ERROR] Fail to get target uid");
+               g_object_unref(g_guser);
+               g_guser = NULL;
+               g_free(g_user_type);
+               return -1;
        }
 
-       __remove_engine_info_xml(pkgid);
+       if (globalapp_uid == g_uid) {
+               /* global directory */
+               LOGD("[DEBUG] usertype: %s", g_user_type);
+
+               /* Get user data by using libgum */
+
+               GumUserService *gus = NULL;
+               GumUserList *users = NULL;
+               GumUserList *iter = NULL;
+               GumUser *user = NULL;
+               gchar **query;
+               GumUserType gumut = GUM_USERTYPE_NONE;
+               gchar *user_type = NULL;
+
+               uid_t uid;
+               gchar *home_dir = NULL;
+
+               GList *md_iter = NULL;
+               metadata *md = NULL;
+
+               gus = gum_user_service_create_sync(TRUE);
+               if (!gus) {
+                       LOGE("Failed to create gum user service");
+                       g_free(g_user_type);
+                       return -1;
+               }
+
+               query = g_strsplit("admin,normal", ",", -1);
+
+               users = gum_user_service_get_user_list_sync(gus, (const gchar *const *)query);
+               g_strfreev(query);
+
+               if (!users) {
+                       LOGE("Failed to get gum user list");
+                       g_object_unref(gus);
+                       gus = NULL;
+                       g_free(g_user_type);
+                       return -1;
+               }
+
+               /* Make new user list */
+
+               iter = users;
+               while (iter != NULL) {
+                       user = (GumUser*) iter->data;
+                       g_object_get(G_OBJECT(user), "uid", &uid, NULL);
+                       if (NULL != home_dir) {
+                               free(home_dir);
+                               home_dir = NULL;
+                       }
+                       g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
+                       g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
+                       user_type = g_strdup(gum_user_type_to_string(gumut));
+                       if (NULL == user_type) {
+                               gum_user_service_list_free(users);
+                               g_object_unref(gus);
+                               gus = NULL;
+                               return -1;
+                       }
+
+                       if (NULL != home_dir) {
+                               g_dir_engine_info = (char*)calloc(strlen(home_dir) + 34, sizeof(char));
+                               if (NULL == g_dir_engine_info) {
+                                       gum_user_service_list_free(users);
+                                       g_object_unref(gus);
+                                       gus = NULL;
+                                       return -1;
+                               }
+
+                               snprintf(g_dir_engine_info, strlen(home_dir) + 34, "%s/share/.voice/tts/1.0/engine-info", home_dir);
+
+                               md_iter = g_list_first(list);
+                               while (NULL != md_iter) {
+                                       md = (metadata *)md_iter->data;
+                                       LOGD(" - key(%s) value(%s)", md->key, md->value);
+                                       md_iter = g_list_next(md_iter);
+                               }
+
+                               if (0 != __remove_engine_info_xml(pkgid, user_type, uid)) {
+                                       LOGE("[ERROR] Fail to remove engine info file");
+                               }
+
+                               free(home_dir);
+                               home_dir = NULL;
+
+                               free(g_dir_engine_info);
+                               g_dir_engine_info = NULL;
+
+                               g_free(user_type);
+
+                               LOGD("Finish release memory");
+                               iter = g_list_next(iter);
+                               LOGD("Finish next iter");
+                       } else {
+                               iter = g_list_next(iter);
+                       }
+               }
+
+               gum_user_service_list_free(users);
+               g_object_unref(gus);
+               gus = NULL;
+       } else {
+               /* user directory */
+               LOGD("[DEBUG] usertype: %s", g_user_type);
+
+               ret = tzplatform_set_user(g_uid);
+               if (ret < 0) {
+                       LOGE("[ERROR] Invalid uid");
+                       g_object_unref(g_guser);
+                       g_guser = NULL;
+                       g_free(g_user_type);
+                       return -1;
+               } else {
+                       LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
+                       printf("[Parser Debug][DEBUG] TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
+               }
+
+               g_dir_engine_info = strdup(TTS_ENGINE_INFO);
+               if (NULL == g_dir_engine_info) {
+                       LOGE("[ERROR] Fail to allocate memory");
+                       g_object_unref(g_guser);
+                       g_guser = NULL;
+                       g_free(g_user_type);
+                       return -1;
+               }
+
+               if (0 != __remove_engine_info_xml(pkgid, g_user_type, g_uid)) {
+                       LOGE("[ERROR] Fail to remove engine info file");
+               }
+
+       }
+
+       if (NULL != g_guser) {
+               g_object_unref(g_guser);
+               g_guser = NULL;
+       }
+       g_free(g_user_type);
+
+       if (NULL != g_dir_engine_info) {
+               free(g_dir_engine_info);
+               g_dir_engine_info = NULL;
+       }
 
        LOGD("");
        return 0;
index 406eae4..677da0d 100644 (file)
@@ -20,8 +20,10 @@ BuildRequires:  pkgconfig(dbus-1)
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(ecore)
 BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(libgum)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(libxml-2.0)
+BuildRequires:  pkgconfig(libsystemd)
 BuildRequires:  pkgconfig(pkgmgr-info)
 BuildRequires:  pkgconfig(pkgmgr-installer)
 BuildRequires:  pkgconfig(vconf)
index 385b84d..186565a 100644 (file)
@@ -451,9 +451,6 @@ int ttsd_data_clear_data(int uid)
                return TTSD_ERROR_INVALID_PARAMETER;
        }
 
-       /* mutex is locked */
-       pthread_mutex_lock(&g_sound_data_mutex);
-
        int removed_last_uttid = -1;
        speak_data_s* temp_speak = NULL;
        sound_data_s* temp_sound = NULL;
@@ -506,6 +503,9 @@ int ttsd_data_clear_data(int uid)
                }
        }
 
+       /* mutex is locked */
+       pthread_mutex_lock(&g_sound_data_mutex);
+
        g_app_list[index].m_speak_data.clear();
        g_app_list[index].m_wav_data.clear();