2 // Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 #include <app_manager.h>
21 #include <libxml/parser.h>
22 #include <libxml/tree.h>
23 #include <pkgmgr-info.h>
24 #include <pkgmgr_installer_info.h>
27 #include <sys/types.h>
28 #include <tzplatform_config.h>
29 #include <systemd/sd-login.h>
31 #include <gum/gum-user.h>
32 #include <gum/gum-user-service.h>
33 #include <gum/common/gum-user-types.h>
35 /* Define EXPORT_API */
37 #define EXPORT_API __attribute__((visibility("default")))
43 #define LOG_TAG "tts-engine-parser"
45 #define TTS_TAG_ENGINE_BASE "tts-engine"
46 #define TTS_TAG_ENGINE_NAME "name"
47 #define TTS_TAG_ENGINE_ID "id"
48 #define TTS_TAG_ENGINE_SETTING "setting"
49 #define TTS_TAG_ENGINE_VOICE_SET "voices"
50 #define TTS_TAG_ENGINE_VOICE "voice"
51 #define TTS_TAG_ENGINE_VOICE_TYPE "type"
52 #define TTS_TAG_ENGINE_PITCH_SUPPORT "pitch-support"
53 #define TTS_TAG_ENGINE_CREDENTIAL "credential"
55 #define TTS_CONFIG_BASE tzplatform_mkpath(TZ_USER_HOME, "share/.voice")
56 #define TTS_HOME tzplatform_mkpath(TZ_USER_HOME, "share/.voice/tts")
57 #define TTS_ENGINE_BASE tzplatform_mkpath(TZ_USER_HOME, "share/.voice/tts/1.0")
58 #define TTS_ENGINE_INFO tzplatform_mkpath(TZ_USER_SHARE, ".voice/tts/1.0/engine-info")
60 #define TTS_GLOBAL_CONFIG_BASE "/etc/skel/share/.voice"
61 #define TTS_GLOBAL_HOME "/etc/skel/share/.voice/tts"
62 #define TTS_GLOBAL_ENGINE_BASE "/etc/skel/share/.voice/tts/1.0"
63 #define TTS_GLOBAL_ENGINE_INFO "/etc/skel/share/.voice/tts/1.0/engine-info"
65 #define TTS_METADATA_LANGUAGE "http://tizen.org/metadata/tts-engine/language"
66 #define TTS_METADATA_CREDENTIAL_REQUIRED "http://tizen.org/metadata/tts-engine/credential-required"
69 typedef struct metadata {
74 static xmlDocPtr g_doc;
75 GumUser *g_guser = NULL;
76 uid_t g_uid = 301; // app_fw
77 gid_t g_gid = 301; // app_fw
78 GumUserType g_ut = GUM_USERTYPE_NONE;
79 gchar *g_user_type = NULL;
81 char *g_dir_config_base = NULL;
82 char *g_dir_home = NULL;
83 char *g_dir_engine_base = NULL;
84 char *g_dir_engine_info = NULL;
86 static int __create_engine_info_xml(const char *pkgid)
88 LOGD("=== Create engine info doc");
89 g_doc = xmlNewDoc((xmlChar*)"1.0");
91 LOGE("[ERROR] Fail to new doc");
98 static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t gid)
100 LOGD("=== Save engine info doc");
101 char *dir_config_base = NULL;
102 char *dir_home = NULL;
103 char *dir_engine_base = NULL;
104 char *dir_engine_info = NULL;
106 if (NULL == ut || (NULL != ut && 0 == strcmp(ut, "none"))) {
107 LOGE("[ERROR] Usertype is NONE");
111 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
115 LOGD("uid(%d)", uid);
117 if (globalapp_uid == uid) {
119 dir_config_base = strdup(TTS_GLOBAL_CONFIG_BASE);
120 dir_home = strdup(TTS_GLOBAL_HOME);
121 dir_engine_base = strdup(TTS_GLOBAL_ENGINE_BASE);
122 dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
123 tmp_uid = 301; // app_fw
124 tmp_gid = 301; // app_fw
126 /* User app, Guest app, Security app */
127 if (NULL != g_dir_config_base)
128 dir_config_base = strdup(g_dir_config_base);
129 if (NULL != g_dir_home)
130 dir_home = strdup(g_dir_home);
131 if (NULL != g_dir_engine_base)
132 dir_engine_base = strdup(g_dir_engine_base);
133 if (NULL != g_dir_engine_info)
134 dir_engine_info = strdup(g_dir_engine_info);
139 if (NULL == dir_config_base || NULL == dir_home || NULL == dir_engine_base || NULL == dir_engine_info) {
140 LOGE("[ERROR] Fail to allocate memory");
141 if (NULL != dir_config_base) {
142 free(dir_config_base);
143 dir_config_base = NULL;
145 if (NULL != dir_home) {
149 if (NULL != dir_engine_base) {
150 free(dir_engine_base);
151 dir_engine_base = NULL;
153 if (NULL != dir_engine_info) {
154 free(dir_engine_info);
155 dir_engine_info = NULL;
160 LOGD("[DEBUG] dir_engine_info(%s)", dir_engine_info);
163 /* Make directories */
164 if (0 != access(dir_config_base, F_OK)) {
165 if (0 != mkdir(dir_config_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
166 LOGE("[ERROR] Fail to make directory : %s", dir_config_base);
167 free(dir_config_base);
168 dir_config_base = NULL;
171 free(dir_engine_base);
172 dir_engine_base = NULL;
173 free(dir_engine_info);
174 dir_engine_info = NULL;
177 LOGD("Success to make directory : %s", dir_config_base);
178 if (0 != chown(dir_config_base, tmp_uid, tmp_gid)) {
179 LOGD("[ERROR] Fail to change user and group");
181 LOGD("[DEBUG] Success to change user and group");
186 if (0 != access(dir_home, F_OK)) {
187 if (0 != mkdir(dir_home, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
188 LOGE("[ERROR] Fail to make directory : %s", dir_home);
189 free(dir_config_base);
190 dir_config_base = NULL;
193 free(dir_engine_base);
194 dir_engine_base = NULL;
195 free(dir_engine_info);
196 dir_engine_info = NULL;
199 LOGD("Success to make directory : %s", dir_home);
200 if (0 != chown(dir_home, tmp_uid, tmp_gid)) {
201 LOGD("[ERROR] Fail to change user and group");
203 LOGD("[DEBUG] Success to change user and group");
208 if (0 != access(dir_engine_base, F_OK)) {
209 if (0 != mkdir(dir_engine_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
210 LOGE("[ERROR] Fail to make directory : %s", dir_engine_base);
211 free(dir_config_base);
212 dir_config_base = NULL;
215 free(dir_engine_base);
216 dir_engine_base = NULL;
217 free(dir_engine_info);
218 dir_engine_info = NULL;
221 LOGD("Success to make directory : %s", dir_engine_base);
222 if (0 != chown(dir_engine_base, tmp_uid, tmp_gid)) {
223 LOGD("[ERROR] Fail to change user and group");
225 LOGD("[DEBUG] Success to change user and group");
230 if (0 != access(dir_engine_info, F_OK)) {
231 if (0 != mkdir(dir_engine_info, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
232 LOGE("[ERROR] Fail to make directory : %s", dir_engine_info);
233 free(dir_config_base);
234 dir_config_base = NULL;
237 free(dir_engine_base);
238 dir_engine_base = NULL;
239 free(dir_engine_info);
240 dir_engine_info = NULL;
243 LOGD("Success to make directory : %s", dir_engine_info);
244 if (0 != chown(dir_engine_info, tmp_uid, tmp_gid)) {
245 LOGD("[ERROR] Fail to change user and group");
247 LOGD("[DEBUG] Success to change user and group");
253 char path[256] = {'\0',};
254 snprintf(path, 256, "%s/%s.xml", dir_engine_info, pkgid);
255 int ret = xmlSaveFormatFile(path, g_doc, 1);
256 LOGD("xmlSaveFile (%d)", ret);
258 if (0 != chown(path, tmp_uid, tmp_gid)) {
259 LOGD("[ERROR] Fail to change user and group");
261 LOGD("[DEBUG] Success to change user and group");
265 free(dir_config_base);
266 dir_config_base = NULL;
269 free(dir_engine_base);
270 dir_engine_base = NULL;
271 free(dir_engine_info);
272 dir_engine_info = NULL;
278 static int __remove_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
280 LOGD("=== Remove engine info doc");
282 char *dir_engine_info = NULL;
284 if (NULL == ut || (NULL != ut && 0 == strcmp(ut, "none"))) {
285 LOGE("[ERROR] Usertype is NONE");
289 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
291 LOGD("uid(%d)", uid);
293 if (globalapp_uid == uid) {
295 dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
297 /* User app, Guest app, Security app */
298 if (NULL != g_dir_engine_info)
299 dir_engine_info = strdup(g_dir_engine_info);
302 if (NULL == dir_engine_info) {
303 LOGE("[ERROR] Fail to allocate memory");
307 LOGD("[DEBUG] dir_engine_info(%s)", dir_engine_info);
310 char path[256] = {'\0',};
311 snprintf(path, 256, "%s/%s.xml", dir_engine_info, pkgid);
312 if (0 == access(path, F_OK)) {
313 LOGD("Remove engine info xml(%s)", path);
314 if (0 != remove(path)) {
315 LOGE("[ERROR] Fail to Remove engine info xml(%s)", path);
319 free(dir_engine_info);
320 dir_engine_info = NULL;
326 static void __insert_language_from_metadata(xmlNodePtr root, const char *language)
328 LOGD("==== Insert language");
333 char *tmp_lang = NULL;
334 char *tmp_free = NULL;
335 tmp_free = tmp_lang = strdup(language);
336 if (NULL == tmp_lang) {
337 LOGE("Fail to memory allocation");
340 xmlNodePtr voices_node = NULL;
341 xmlNodePtr voice_node = NULL;
343 voices_node = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_VOICE_SET);
345 voice = strsep(&tmp_lang, ",");
346 while (NULL != voice) {
347 LOGD("voice (%s)", voice);
348 voice_node = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_VOICE);
349 lang = strsep(&voice, ":");
350 LOGD("lang (%s)", lang);
351 type = strsep(&voice, " ");
352 LOGD("type (%s)", type);
353 xmlSetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE, (const xmlChar*)type);
354 xmlNodeSetContent(voice_node, (const xmlChar*)lang);
355 xmlAddChild(voices_node, voice_node);
356 voice = strsep(&tmp_lang, ",");
358 xmlAddChild(root, voices_node);
364 static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *list)
369 __create_engine_info_xml(pkgid);
371 xmlNodePtr root = NULL;
372 xmlNodePtr cur = NULL;
374 root = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_BASE);
376 LOGE("[ERROR] Fail to get new node");
377 // xmlFreeDoc(g_doc);
380 xmlDocSetRootElement(g_doc, root);
383 cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_NAME);
384 xmlNodeSetContent(cur, (const xmlChar*)pkgid);
385 xmlAddChild(root, cur);
388 iter = g_list_first(list);
389 while (NULL != iter) {
390 md = (metadata *)iter->data;
391 if (NULL != md && NULL != md->key) {
392 LOGD(" - key(%s) value(%s)", md->key, md->value);
393 if (!strcmp(md->key, TTS_METADATA_LANGUAGE)) {
394 __insert_language_from_metadata(root, md->value);
395 } else if (!strcmp(md->key, TTS_METADATA_CREDENTIAL_REQUIRED)) {
396 cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_CREDENTIAL);
397 xmlNodeSetContent(cur, (const xmlChar*)md->value);
398 xmlAddChild(root, cur);
400 LOGW("[WARNING] Unknown metadata type");
403 iter = g_list_next(iter);
406 cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_ID);
407 xmlNodeSetContent(cur, (const xmlChar*)pkgid);
408 xmlAddChild(root, cur);
417 int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
419 LOGD("METADATA INSTALL");
420 LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
423 ret = pkgmgr_installer_info_get_target_uid(&g_uid);
425 LOGE("[ERROR] Fail to get target uid");
428 LOGD("uid(%d)", g_uid);
429 printf("[Parser Debug][DEBUG] uid(%d)", g_uid);
432 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
433 if (globalapp_uid == g_uid) {
434 g_user_type = g_strdup("admin");
436 g_guser = gum_user_get_sync(g_uid, FALSE);
437 if (NULL == g_guser) {
438 LOGE("[ERROR] g_guser is NULL");
442 g_object_get(G_OBJECT(g_guser), "gid", &g_gid, NULL);
443 g_object_get(G_OBJECT(g_guser), "usertype", &g_ut, NULL);
444 g_user_type = g_strdup(gum_user_type_to_string(g_ut));
447 if (NULL == g_user_type) {
448 LOGE("[ERROR] Fail to allocate memory");
449 if (NULL != g_guser) {
450 g_object_unref(g_guser);
456 if (0 == strcmp(g_user_type, "none")) {
457 /* GUM_USERTYPE_NONE */
458 LOGE("[ERROR] Fail to get target uid");
459 g_object_unref(g_guser);
465 if (globalapp_uid == g_uid) {
466 /* global directory */
467 LOGD("[DEBUG] usertype: %s", g_user_type);
468 if (0 >= g_list_length(list)) {
469 LOGE("[ERROR] No Engine Metadata");
474 if (0 != __write_metadata_inxml(pkgid, appid, list)) {
475 LOGE("[ERROR] Fail to write metadata in the xml");
481 /* Save in /etc/skel/share/ */
482 g_dir_config_base = strdup(TTS_GLOBAL_CONFIG_BASE);
483 g_dir_home = strdup(TTS_GLOBAL_HOME);
484 g_dir_engine_base = strdup(TTS_GLOBAL_ENGINE_BASE);
485 g_dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
487 if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
488 LOGE("[ERROR] Fail to allocate memory");
489 if (NULL != g_dir_config_base) {
490 free(g_dir_config_base);
491 g_dir_config_base = NULL;
493 if (NULL != g_dir_home) {
497 if (NULL != g_dir_engine_base) {
498 free(g_dir_engine_base);
499 g_dir_engine_base = NULL;
501 if (NULL != g_dir_engine_info) {
502 free(g_dir_engine_info);
503 g_dir_engine_info = NULL;
510 if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid, g_gid)) {
511 LOGE("[ERROR] Fail to make engine info file");
517 /* Get user data by using libgum */
519 GumUserService *gus = NULL;
520 GumUserList *users = NULL;
521 GumUserList *iter = NULL;
522 GumUser *user = NULL;
524 GumUserType gumut = GUM_USERTYPE_NONE;
525 gchar *user_type = NULL;
529 gchar *home_dir = NULL;
531 gus = gum_user_service_create_sync(TRUE);
533 LOGE("Failed to create gum user service");
538 query = g_strsplit("admin,normal", ",", -1);
540 users = gum_user_service_get_user_list_sync(gus, (const gchar *const *)query);
544 LOGE("Failed to get gum user list");
551 /* Make new user list */
554 while (iter != NULL) {
555 user = (GumUser*) iter->data;
556 g_object_get(G_OBJECT(user), "uid", &uid, NULL);
557 if (NULL != home_dir) {
561 g_object_get(G_OBJECT(user), "gid", &gid, NULL);
562 g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
563 g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
564 user_type = g_strdup(gum_user_type_to_string(gumut));
565 if (NULL == user_type) {
566 gum_user_service_list_free(users);
572 LOGD("[DEBUG] user info");
573 if (NULL != home_dir) {
574 LOGD("[DEBUG] uid(%d), gid(%d), user_type(%s), home_dir(%s)", uid, gid, user_type, home_dir);
576 g_dir_config_base = (char*)calloc(strlen(home_dir) + 14, sizeof(char));
577 g_dir_home = (char*)calloc(strlen(home_dir) + 18, sizeof(char));
578 g_dir_engine_base = (char*)calloc(strlen(home_dir) + 22, sizeof(char));
579 g_dir_engine_info = (char*)calloc(strlen(home_dir) + 34, sizeof(char));
581 if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
582 LOGE("[ERROR] Fail to allocate memory");
583 if (NULL != g_dir_config_base) {
584 free(g_dir_config_base);
585 g_dir_config_base = NULL;
587 if (NULL != g_dir_home) {
591 if (NULL != g_dir_engine_base) {
592 free(g_dir_engine_base);
593 g_dir_engine_base = NULL;
595 if (NULL != g_dir_engine_info) {
596 free(g_dir_engine_info);
597 g_dir_engine_info = NULL;
599 gum_user_service_list_free(users);
604 snprintf(g_dir_config_base, strlen(home_dir) + 14, "%s/share/.voice", home_dir);
605 snprintf(g_dir_home, strlen(home_dir) + 18, "%s/share/.voice/tts", home_dir);
606 snprintf(g_dir_engine_base, strlen(home_dir) + 22, "%s/share/.voice/tts/1.0", home_dir);
607 snprintf(g_dir_engine_info, strlen(home_dir) + 34, "%s/share/.voice/tts/1.0/engine-info", home_dir);
609 LOGD("[DEBUG] g_dir_engine_info(%s)", g_dir_engine_info);
611 if (0 != __save_engine_info_xml(pkgid, user_type, uid, gid)) {
612 LOGE("[ERROR] Fail to make engine info file");
615 free(g_dir_config_base);
616 g_dir_config_base = NULL;
619 free(g_dir_engine_base);
620 g_dir_engine_base = NULL;
621 free(g_dir_engine_info);
622 g_dir_engine_info = NULL;
629 iter = g_list_next(iter);
631 iter = g_list_next(iter);
634 if (NULL != user_type) {
640 gum_user_service_list_free(users);
645 LOGD("[DEBUG] usertype: %s", g_user_type);
647 ret = tzplatform_set_user(g_uid);
649 LOGE("[ERROR] Invalid uid");
650 g_object_unref(g_guser);
655 LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
656 printf("[Parser Debug][DEBUG] TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
659 if (0 >= g_list_length(list)) {
660 LOGE("[ERROR] No Engine Metadata");
661 g_object_unref(g_guser);
667 if (0 != __write_metadata_inxml(pkgid, appid, list)) {
668 LOGE("[ERROR] Fail to write metadata in the xml");
670 g_object_unref(g_guser);
676 g_dir_config_base = strdup(TTS_CONFIG_BASE);
677 g_dir_home = strdup(TTS_HOME);
678 g_dir_engine_base = strdup(TTS_ENGINE_BASE);
679 g_dir_engine_info = strdup(TTS_ENGINE_INFO);
681 if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
682 LOGE("[ERROR] Fail to allocate memory");
683 if (NULL != g_dir_config_base) {
684 free(g_dir_config_base);
685 g_dir_config_base = NULL;
687 if (NULL != g_dir_home) {
691 if (NULL != g_dir_engine_base) {
692 free(g_dir_engine_base);
693 g_dir_engine_base = NULL;
695 if (NULL != g_dir_engine_info) {
696 free(g_dir_engine_info);
697 g_dir_engine_info = NULL;
700 g_object_unref(g_guser);
706 if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid, g_gid)) {
707 LOGE("[ERROR] Fail to make engine info file");
709 if (NULL != g_guser) {
710 g_object_unref(g_guser);
719 if (NULL != g_guser) {
720 g_object_unref(g_guser);
725 if (NULL != g_dir_config_base) {
726 free(g_dir_config_base);
727 g_dir_config_base = NULL;
729 if (NULL != g_dir_home) {
733 if (NULL != g_dir_engine_base) {
734 free(g_dir_engine_base);
735 g_dir_engine_base = NULL;
737 if (NULL != g_dir_engine_info) {
738 free(g_dir_engine_info);
739 g_dir_engine_info = NULL;
746 int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list)
748 LOGD("METADATA UNINSTALL");
749 LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
752 ret = pkgmgr_installer_info_get_target_uid(&g_uid);
754 LOGE("[ERROR] Fail to get target uid");
757 LOGD("uid(%d)", g_uid);
758 printf("[Parser Debug][DEBUG] uid(%d)", g_uid);
761 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
762 if (globalapp_uid == g_uid) {
763 g_user_type = g_strdup("admin");
765 g_guser = gum_user_get_sync(g_uid, FALSE);
766 if (NULL == g_guser) {
767 LOGE("[ERROR] g_guser is NULL");
771 g_object_get(G_OBJECT(g_guser), "usertype", &g_ut, NULL);
772 g_user_type = g_strdup(gum_user_type_to_string(g_ut));
775 if (NULL == g_user_type) {
776 LOGE("[ERROR] Fail to allocate memory");
777 if (NULL != g_guser) {
778 g_object_unref(g_guser);
784 if (0 == strcmp(g_user_type, "none")) {
785 /* GUM_USERTYPE_NONE */
786 LOGE("[ERROR] Fail to get target uid");
787 g_object_unref(g_guser);
793 if (globalapp_uid == g_uid) {
794 /* global directory */
795 LOGD("[DEBUG] usertype: %s", g_user_type);
797 /* Remove files in /etc/skel/share/ */
798 g_dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
799 if (NULL == g_dir_engine_info) {
800 LOGE("[ERROR] Fail to allocate memory");
805 if (0 != __remove_engine_info_xml(pkgid, g_user_type, g_uid)) {
806 LOGE("[ERROR] Fail to remove engine info file");
809 /* Get user data by using libgum */
811 GumUserService *gus = NULL;
812 GumUserList *users = NULL;
813 GumUserList *iter = NULL;
814 GumUser *user = NULL;
816 GumUserType gumut = GUM_USERTYPE_NONE;
817 gchar *user_type = NULL;
820 gchar *home_dir = NULL;
822 GList *md_iter = NULL;
825 gus = gum_user_service_create_sync(TRUE);
827 LOGE("Failed to create gum user service");
832 query = g_strsplit("admin,normal", ",", -1);
834 users = gum_user_service_get_user_list_sync(gus, (const gchar *const *)query);
838 LOGE("Failed to get gum user list");
845 /* Make new user list */
848 while (iter != NULL) {
849 user = (GumUser*) iter->data;
850 g_object_get(G_OBJECT(user), "uid", &uid, NULL);
851 if (NULL != home_dir) {
855 g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
856 g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
857 user_type = g_strdup(gum_user_type_to_string(gumut));
858 if (NULL == user_type) {
859 gum_user_service_list_free(users);
865 if (NULL != home_dir) {
866 g_dir_engine_info = (char*)calloc(strlen(home_dir) + 34, sizeof(char));
867 if (NULL == g_dir_engine_info) {
868 gum_user_service_list_free(users);
874 snprintf(g_dir_engine_info, strlen(home_dir) + 34, "%s/share/.voice/tts/1.0/engine-info", home_dir);
876 md_iter = g_list_first(list);
877 while (NULL != md_iter) {
878 md = (metadata *)md_iter->data;
879 LOGD(" - key(%s) value(%s)", md->key, md->value);
880 md_iter = g_list_next(md_iter);
883 if (0 != __remove_engine_info_xml(pkgid, user_type, uid)) {
884 LOGE("[ERROR] Fail to remove engine info file");
890 free(g_dir_engine_info);
891 g_dir_engine_info = NULL;
895 LOGD("Finish release memory");
896 iter = g_list_next(iter);
897 LOGD("Finish next iter");
899 iter = g_list_next(iter);
903 gum_user_service_list_free(users);
908 LOGD("[DEBUG] usertype: %s", g_user_type);
910 ret = tzplatform_set_user(g_uid);
912 LOGE("[ERROR] Invalid uid");
913 g_object_unref(g_guser);
918 LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
919 printf("[Parser Debug][DEBUG] TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
922 g_dir_engine_info = strdup(TTS_ENGINE_INFO);
923 if (NULL == g_dir_engine_info) {
924 LOGE("[ERROR] Fail to allocate memory");
925 g_object_unref(g_guser);
931 if (0 != __remove_engine_info_xml(pkgid, g_user_type, g_uid)) {
932 LOGE("[ERROR] Fail to remove engine info file");
937 if (NULL != g_guser) {
938 g_object_unref(g_guser);
943 if (NULL != g_dir_engine_info) {
944 free(g_dir_engine_info);
945 g_dir_engine_info = NULL;
953 int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list)
955 LOGD("METADATA UPGRADE");
956 LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
958 PKGMGR_MDPARSER_PLUGIN_UNINSTALL(pkgid, appid, list);
959 PKGMGR_MDPARSER_PLUGIN_INSTALL(pkgid, appid, list);