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>
29 #include <tzplatform_config.h>
30 #include <systemd/sd-login.h>
32 #include <gum/gum-user.h>
33 #include <gum/gum-user-service.h>
34 #include <gum/common/gum-user-types.h>
36 /* Define EXPORT_API */
38 #define EXPORT_API __attribute__((visibility("default")))
44 #define LOG_TAG "tts-engine-parser"
46 #define TTS_TAG_ENGINE_BASE "tts-engine"
47 #define TTS_TAG_ENGINE_NAME "name"
48 #define TTS_TAG_ENGINE_ID "id"
49 #define TTS_TAG_ENGINE_SETTING "setting"
50 #define TTS_TAG_ENGINE_VOICE_SET "voices"
51 #define TTS_TAG_ENGINE_VOICE "voice"
52 #define TTS_TAG_ENGINE_VOICE_TYPE "type"
53 #define TTS_TAG_ENGINE_PITCH_SUPPORT "pitch-support"
54 #define TTS_TAG_ENGINE_CREDENTIAL "credential"
55 #define TTS_TAG_ENGINE_TEXT_SIZE "text-size"
57 #define TTS_CONFIG_BASE tzplatform_mkpath(TZ_USER_HOME, "share/.voice")
58 #define TTS_HOME tzplatform_mkpath(TZ_USER_HOME, "share/.voice/tts")
59 #define TTS_ENGINE_BASE tzplatform_mkpath(TZ_USER_HOME, "share/.voice/tts/1.0")
60 #define TTS_ENGINE_INFO tzplatform_mkpath(TZ_USER_SHARE, ".voice/tts/1.0/engine-info")
62 #define TTS_GLOBAL_CONFIG_BASE "/etc/skel/share/.voice"
63 #define TTS_GLOBAL_HOME "/etc/skel/share/.voice/tts"
64 #define TTS_GLOBAL_ENGINE_BASE "/etc/skel/share/.voice/tts/1.0"
65 #define TTS_GLOBAL_ENGINE_INFO "/etc/skel/share/.voice/tts/1.0/engine-info"
67 #define TTS_METADATA_NAME "http://tizen.org/metadata/tts-engine/name"
68 #define TTS_METADATA_LANGUAGE "http://tizen.org/metadata/tts-engine/language"
69 #define TTS_METADATA_CREDENTIAL_REQUIRED "http://tizen.org/metadata/tts-engine/credential-required"
70 #define TTS_METADATA_SETTING "http://tizen.org/metadata/tts-engine/setting"
71 #define TTS_METADATA_TEXT_SIZE "http://tizen.org/metadata/tts-engine/text-size"
74 #define FREE(x) { if (NULL != x) { free(x); x = NULL; } }
75 #define G_FREE(x) { if (NULL != x) { g_free(x); x = NULL; } }
77 typedef struct metadata {
82 static xmlDocPtr g_doc;
83 GumUser *g_guser = NULL;
84 uid_t g_uid = 301; // app_fw
85 gid_t g_gid = 301; // app_fw
86 GumUserType g_ut = GUM_USERTYPE_NONE;
87 gchar *g_user_type = NULL;
89 char *g_dir_config_base = NULL;
90 char *g_dir_home = NULL;
91 char *g_dir_engine_base = NULL;
92 char *g_dir_engine_info = NULL;
94 static int __create_engine_info_xml(const char *pkgid)
96 LOGD("=== Create engine info doc");
97 g_doc = xmlNewDoc((xmlChar*)"1.0");
99 LOGE("[ERROR] Fail to new doc");
106 static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t gid)
108 LOGD("=== Save engine info doc");
109 char *dir_config_base = NULL;
110 char *dir_home = NULL;
111 char *dir_engine_base = NULL;
112 char *dir_engine_info = NULL;
114 if (NULL == ut || (NULL != ut && 0 == strcmp(ut, "none"))) {
115 LOGE("[ERROR] Usertype is NONE");
119 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
123 LOGD("uid(%d)", uid);
125 if (globalapp_uid == uid) {
127 dir_config_base = strdup(TTS_GLOBAL_CONFIG_BASE);
128 dir_home = strdup(TTS_GLOBAL_HOME);
129 dir_engine_base = strdup(TTS_GLOBAL_ENGINE_BASE);
130 dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
131 tmp_uid = 301; // app_fw
132 tmp_gid = 301; // app_fw
134 /* User app, Guest app, Security app */
135 if (NULL != g_dir_config_base)
136 dir_config_base = strdup(g_dir_config_base);
137 if (NULL != g_dir_home)
138 dir_home = strdup(g_dir_home);
139 if (NULL != g_dir_engine_base)
140 dir_engine_base = strdup(g_dir_engine_base);
141 if (NULL != g_dir_engine_info)
142 dir_engine_info = strdup(g_dir_engine_info);
147 if (NULL == dir_config_base || NULL == dir_home || NULL == dir_engine_base || NULL == dir_engine_info) {
148 LOGE("[ERROR] Fail to allocate memory");
149 FREE(dir_config_base)
151 FREE(dir_engine_base)
152 FREE(dir_engine_info)
157 LOGD("[DEBUG] dir_engine_info(%s)", dir_engine_info);
160 /* Make directories */
162 // if (0 != access(dir_config_base, F_OK)) {
163 fd = open(dir_config_base, O_DIRECTORY);
165 LOGE("[INFO] No directory : %s, errno : %d", dir_config_base, errno);
166 if (0 != mkdir(dir_config_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
167 LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_config_base, errno);
168 FREE(dir_config_base)
170 FREE(dir_engine_base)
171 FREE(dir_engine_info)
174 LOGD("Success to make directory : %s", dir_config_base);
175 if (0 != chown(dir_config_base, tmp_uid, tmp_gid)) {
176 LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
178 LOGD("[DEBUG] Success to change user and group");
185 // if (0 != access(dir_home, F_OK)) {
186 fd = open(dir_home, O_DIRECTORY);
188 LOGE("[INFO] No directory : %s, errno : %d", dir_home, errno);
189 if (0 != mkdir(dir_home, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
190 LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_home, errno);
191 FREE(dir_config_base)
193 FREE(dir_engine_base)
194 FREE(dir_engine_info)
197 LOGD("Success to make directory : %s", dir_home);
198 if (0 != chown(dir_home, tmp_uid, tmp_gid)) {
199 LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
201 LOGD("[DEBUG] Success to change user and group");
208 // if (0 != access(dir_engine_base, F_OK)) {
209 fd = open(dir_engine_base, O_DIRECTORY);
211 LOGE("[INFO] No directory : %s, errno : %d", dir_engine_base, errno);
212 if (0 != mkdir(dir_engine_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
213 LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_engine_base, errno);
214 FREE(dir_config_base)
216 FREE(dir_engine_base)
217 FREE(dir_engine_info)
220 LOGD("Success to make directory : %s", dir_engine_base);
221 if (0 != chown(dir_engine_base, tmp_uid, tmp_gid)) {
222 LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
224 LOGD("[DEBUG] Success to change user and group");
231 // if (0 != access(dir_engine_info, F_OK)) {
232 fd = open(dir_engine_info, O_DIRECTORY);
234 LOGE("[INFO] No directory : %s, errno : %d", dir_engine_info, errno);
235 if (0 != mkdir(dir_engine_info, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
236 LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_engine_info, errno);
237 FREE(dir_config_base)
239 FREE(dir_engine_base)
240 FREE(dir_engine_info)
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, errno : %d", errno);
247 LOGD("[DEBUG] Success to change user and group");
255 char path[256] = {'\0',};
256 snprintf(path, 256, "%s/%s.xml", dir_engine_info, pkgid);
257 int ret = xmlSaveFormatFile(path, g_doc, 1);
258 LOGD("xmlSaveFile (%d)", ret);
260 if (0 != chown(path, tmp_uid, tmp_gid)) {
261 LOGD("[ERROR] Fail to change user and group");
263 LOGD("[DEBUG] Success to change user and group");
267 FREE(dir_config_base)
269 FREE(dir_engine_base)
270 FREE(dir_engine_info)
276 static int __remove_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
278 LOGD("=== Remove engine info doc");
280 char *dir_engine_info = NULL;
282 if (NULL == ut || (NULL != ut && 0 == strcmp(ut, "none"))) {
283 LOGE("[ERROR] Usertype is NONE");
287 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
289 LOGD("uid(%d)", uid);
291 if (globalapp_uid == uid) {
293 dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
295 /* User app, Guest app, Security app */
296 if (NULL != g_dir_engine_info)
297 dir_engine_info = strdup(g_dir_engine_info);
300 if (NULL == dir_engine_info) {
301 LOGE("[ERROR] Fail to allocate memory");
305 LOGD("[DEBUG] dir_engine_info(%s)", dir_engine_info);
308 char path[256] = {'\0',};
309 snprintf(path, 256, "%s/%s.xml", dir_engine_info, pkgid);
310 if (0 == access(path, F_OK)) {
311 LOGD("Remove engine info xml(%s)", path);
312 if (0 != remove(path)) {
313 LOGE("[ERROR] Fail to Remove engine info xml(%s)", path);
317 FREE(dir_engine_info)
323 static void __insert_language_from_metadata(xmlNodePtr root, const char *language)
325 LOGD("==== Insert language");
329 if (NULL == root || NULL == language) {
330 LOGE("Invalid parameter, root(%p), language(%s)", root, language);
334 char *tmp_lang = NULL;
335 char *tmp_free = NULL;
336 tmp_free = tmp_lang = strdup(language);
337 if (NULL == tmp_lang) {
338 LOGE("Fail to memory allocation");
341 xmlNodePtr voices_node = NULL;
342 xmlNodePtr voice_node = NULL;
344 voices_node = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_VOICE_SET);
346 voice = strsep(&tmp_lang, ",");
347 while (NULL != voice) {
348 LOGD("voice (%s)", voice);
349 voice_node = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_VOICE);
350 lang = strsep(&voice, ":");
351 LOGD("lang (%s)", lang);
352 type = strsep(&voice, " ");
353 LOGD("type (%s)", type);
354 xmlSetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE, (const xmlChar*)type);
355 xmlNodeSetContent(voice_node, (const xmlChar*)lang);
356 xmlAddChild(voices_node, voice_node);
357 voice = strsep(&tmp_lang, ",");
359 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);
399 } else if (!strcmp(md->key, TTS_METADATA_SETTING)) {
400 cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_SETTING);
401 xmlNodeSetContent(cur, (const xmlChar*)md->value);
402 xmlAddChild(root, cur);
403 } else if (!strcmp(md->key, TTS_METADATA_NAME)) {
404 cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_NAME);
405 xmlNodeSetContent(cur, (const xmlChar*)md->value);
406 xmlAddChild(root, cur);
407 } else if (!strcmp(md->key, TTS_METADATA_TEXT_SIZE)) {
408 cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_TEXT_SIZE);
409 xmlNodeSetContent(cur, (const xmlChar*)md->value);
410 xmlAddChild(root, cur);
412 LOGW("[WARNING] Unknown metadata type");
415 iter = g_list_next(iter);
418 cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_ID);
419 xmlNodeSetContent(cur, (const xmlChar*)pkgid);
420 xmlAddChild(root, cur);
429 int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
431 LOGD("METADATA INSTALL");
432 LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
435 ret = pkgmgr_installer_info_get_target_uid(&g_uid);
437 LOGE("[ERROR] Fail to get target uid");
440 LOGD("uid(%d)", g_uid);
441 printf("[Parser Debug][DEBUG] uid(%d)", g_uid);
444 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
445 if (globalapp_uid == g_uid) {
446 g_user_type = g_strdup("admin");
448 g_guser = gum_user_get_sync(g_uid, FALSE);
449 if (NULL == g_guser) {
450 LOGE("[ERROR] g_guser is NULL");
454 g_object_get(G_OBJECT(g_guser), "gid", &g_gid, NULL);
455 g_object_get(G_OBJECT(g_guser), "usertype", &g_ut, NULL);
456 g_user_type = g_strdup(gum_user_type_to_string(g_ut));
459 if (NULL == g_user_type) {
460 LOGE("[ERROR] Fail to allocate memory");
461 if (NULL != g_guser) {
462 g_object_unref(g_guser);
468 if (0 == strcmp(g_user_type, "none")) {
469 /* GUM_USERTYPE_NONE */
470 LOGE("[ERROR] Fail to get target uid");
471 g_object_unref(g_guser);
477 if (globalapp_uid == g_uid) {
478 /* global directory */
479 LOGD("[DEBUG] usertype: %s", g_user_type);
480 if (0 >= g_list_length(list)) {
481 LOGE("[ERROR] No Engine Metadata");
486 if (0 != __write_metadata_inxml(pkgid, appid, list)) {
487 LOGE("[ERROR] Fail to write metadata in the xml");
493 /* Save in /etc/skel/share/ */
494 g_dir_config_base = strdup(TTS_GLOBAL_CONFIG_BASE);
495 g_dir_home = strdup(TTS_GLOBAL_HOME);
496 g_dir_engine_base = strdup(TTS_GLOBAL_ENGINE_BASE);
497 g_dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
499 if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
500 LOGE("[ERROR] Fail to allocate memory");
501 FREE(g_dir_config_base)
503 FREE(g_dir_engine_base)
504 FREE(g_dir_engine_info)
511 if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid, g_gid)) {
512 LOGE("[ERROR] Fail to make engine info file");
518 /* Get user data by using libgum */
520 GumUserService *gus = NULL;
521 GumUserList *users = NULL;
522 GumUserList *iter = NULL;
523 GumUser *user = NULL;
525 GumUserType gumut = GUM_USERTYPE_NONE;
526 gchar *user_type = NULL;
530 gchar *home_dir = NULL;
532 gus = gum_user_service_create_sync(TRUE);
534 LOGE("Failed to create gum user service");
539 query = g_strsplit("admin,normal", ",", -1);
541 users = gum_user_service_get_user_list_sync(gus, (const gchar *const *)query);
552 /* Make new user list */
555 while (iter != NULL) {
556 user = (GumUser*) iter->data;
557 g_object_get(G_OBJECT(user), "uid", &uid, NULL);
560 g_object_get(G_OBJECT(user), "gid", &gid, NULL);
561 g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
562 g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
563 user_type = g_strdup(gum_user_type_to_string(gumut));
564 if (NULL == user_type) {
565 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 FREE(g_dir_config_base)
585 FREE(g_dir_engine_base)
586 FREE(g_dir_engine_info)
587 gum_user_service_list_free(users);
594 snprintf(g_dir_config_base, strlen(home_dir) + 14, "%s/share/.voice", home_dir);
595 snprintf(g_dir_home, strlen(home_dir) + 18, "%s/share/.voice/tts", home_dir);
596 snprintf(g_dir_engine_base, strlen(home_dir) + 22, "%s/share/.voice/tts/1.0", home_dir);
597 snprintf(g_dir_engine_info, strlen(home_dir) + 34, "%s/share/.voice/tts/1.0/engine-info", home_dir);
599 LOGD("[DEBUG] g_dir_engine_info(%s)", g_dir_engine_info);
601 if (0 != __save_engine_info_xml(pkgid, user_type, uid, gid)) {
602 LOGE("[ERROR] Fail to make engine info file");
605 FREE(g_dir_config_base)
607 FREE(g_dir_engine_base)
608 FREE(g_dir_engine_info)
614 iter = g_list_next(iter);
617 gum_user_service_list_free(users);
622 LOGD("[DEBUG] usertype: %s", g_user_type);
624 ret = tzplatform_set_user(g_uid);
626 LOGE("[ERROR] Invalid uid");
627 g_object_unref(g_guser);
632 LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
633 printf("[Parser Debug][DEBUG] TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
636 if (0 >= g_list_length(list)) {
637 LOGE("[ERROR] No Engine Metadata");
638 g_object_unref(g_guser);
644 if (0 != __write_metadata_inxml(pkgid, appid, list)) {
645 LOGE("[ERROR] Fail to write metadata in the xml");
647 g_object_unref(g_guser);
653 g_dir_config_base = strdup(TTS_CONFIG_BASE);
654 g_dir_home = strdup(TTS_HOME);
655 g_dir_engine_base = strdup(TTS_ENGINE_BASE);
656 g_dir_engine_info = strdup(TTS_ENGINE_INFO);
658 if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
659 LOGE("[ERROR] Fail to allocate memory");
660 FREE(g_dir_config_base)
662 FREE(g_dir_engine_base)
663 FREE(g_dir_engine_info)
665 g_object_unref(g_guser);
671 if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid, g_gid)) {
672 LOGE("[ERROR] Fail to make engine info file");
674 if (NULL != g_guser) {
675 g_object_unref(g_guser);
684 if (NULL != g_guser) {
685 g_object_unref(g_guser);
690 FREE(g_dir_config_base)
692 FREE(g_dir_engine_base)
693 FREE(g_dir_engine_info)
699 int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list)
701 LOGD("METADATA UNINSTALL");
702 LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
705 ret = pkgmgr_installer_info_get_target_uid(&g_uid);
707 LOGE("[ERROR] Fail to get target uid");
710 LOGD("uid(%d)", g_uid);
711 printf("[Parser Debug][DEBUG] uid(%d)", g_uid);
714 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
715 if (globalapp_uid == g_uid) {
716 g_user_type = g_strdup("admin");
718 g_guser = gum_user_get_sync(g_uid, FALSE);
719 if (NULL == g_guser) {
720 LOGE("[ERROR] g_guser is NULL");
724 g_object_get(G_OBJECT(g_guser), "usertype", &g_ut, NULL);
725 g_user_type = g_strdup(gum_user_type_to_string(g_ut));
728 if (NULL == g_user_type) {
729 LOGE("[ERROR] Fail to allocate memory");
730 if (NULL != g_guser) {
731 g_object_unref(g_guser);
737 if (0 == strcmp(g_user_type, "none")) {
738 /* GUM_USERTYPE_NONE */
739 LOGE("[ERROR] Fail to get target uid");
740 g_object_unref(g_guser);
746 if (globalapp_uid == g_uid) {
747 /* global directory */
748 LOGD("[DEBUG] usertype: %s", g_user_type);
750 /* Remove files in /etc/skel/share/ */
751 g_dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
752 if (NULL == g_dir_engine_info) {
753 LOGE("[ERROR] Fail to allocate memory");
758 if (0 != __remove_engine_info_xml(pkgid, g_user_type, g_uid)) {
759 LOGE("[ERROR] Fail to remove engine info file");
762 /* Get user data by using libgum */
764 GumUserService *gus = NULL;
765 GumUserList *users = NULL;
766 GumUserList *iter = NULL;
767 GumUser *user = NULL;
769 GumUserType gumut = GUM_USERTYPE_NONE;
770 gchar *user_type = NULL;
773 gchar *home_dir = NULL;
775 GList *md_iter = NULL;
778 gus = gum_user_service_create_sync(TRUE);
780 LOGE("Failed to create gum user service");
785 query = g_strsplit("admin,normal", ",", -1);
787 users = gum_user_service_get_user_list_sync(gus, (const gchar *const *)query);
798 /* Make new user list */
801 while (iter != NULL) {
802 user = (GumUser*) iter->data;
803 g_object_get(G_OBJECT(user), "uid", &uid, NULL);
805 g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
806 g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
807 user_type = g_strdup(gum_user_type_to_string(gumut));
808 if (NULL == user_type) {
809 gum_user_service_list_free(users);
816 if (NULL != home_dir) {
817 g_dir_engine_info = (char*)calloc(strlen(home_dir) + 34, sizeof(char));
818 if (NULL == g_dir_engine_info) {
819 gum_user_service_list_free(users);
827 snprintf(g_dir_engine_info, strlen(home_dir) + 34, "%s/share/.voice/tts/1.0/engine-info", home_dir);
829 md_iter = g_list_first(list);
830 while (NULL != md_iter) {
831 md = (metadata *)md_iter->data;
832 LOGD(" - key(%s) value(%s)", md->key, md->value);
833 md_iter = g_list_next(md_iter);
836 if (0 != __remove_engine_info_xml(pkgid, user_type, uid)) {
837 LOGE("[ERROR] Fail to remove engine info file");
841 FREE(g_dir_engine_info)
845 LOGD("Finish release memory");
846 iter = g_list_next(iter);
847 LOGD("Finish next iter");
850 gum_user_service_list_free(users);
855 LOGD("[DEBUG] usertype: %s", g_user_type);
857 ret = tzplatform_set_user(g_uid);
859 LOGE("[ERROR] Invalid uid");
860 g_object_unref(g_guser);
865 LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
866 printf("[Parser Debug][DEBUG] TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
869 g_dir_engine_info = strdup(TTS_ENGINE_INFO);
870 if (NULL == g_dir_engine_info) {
871 LOGE("[ERROR] Fail to allocate memory");
872 g_object_unref(g_guser);
878 if (0 != __remove_engine_info_xml(pkgid, g_user_type, g_uid)) {
879 LOGE("[ERROR] Fail to remove engine info file");
884 if (NULL != g_guser) {
885 g_object_unref(g_guser);
890 FREE(g_dir_engine_info)
897 int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list)
899 LOGD("METADATA UPGRADE");
900 LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
902 PKGMGR_MDPARSER_PLUGIN_UNINSTALL(pkgid, appid, list);
903 PKGMGR_MDPARSER_PLUGIN_INSTALL(pkgid, appid, list);