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"
72 #define TTS_METADATA_PITCH_SUPPORT "http://tizen.org/metadata/tts-engine/pitch-support"
75 #define FREE(x) { if (NULL != x) { free(x); x = NULL; } }
76 #define G_FREE(x) { if (NULL != x) { g_free(x); x = NULL; } }
78 typedef struct metadata {
83 static xmlDocPtr g_doc;
84 GumUser *g_guser = NULL;
85 uid_t g_uid = 301; // app_fw
86 gid_t g_gid = 301; // app_fw
87 GumUserType g_ut = GUM_USERTYPE_NONE;
88 gchar *g_user_type = NULL;
90 char *g_dir_config_base = NULL;
91 char *g_dir_home = NULL;
92 char *g_dir_engine_base = NULL;
93 char *g_dir_engine_info = NULL;
95 static int __create_engine_info_xml(const char *pkgid)
97 LOGD("@@@ Create engine info doc");
98 g_doc = xmlNewDoc((xmlChar*)"1.0");
100 LOGE("[ERROR] Fail to new doc");
107 static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t gid)
109 LOGD("@@@ Save engine info doc");
110 char *dir_config_base = NULL;
111 char *dir_home = NULL;
112 char *dir_engine_base = NULL;
113 char *dir_engine_info = NULL;
115 if (NULL == ut || (NULL != ut && 0 == strcmp(ut, "none"))) {
116 LOGE("[ERROR] Usertype is NONE");
120 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
124 LOGD("uid(%d)", uid);
126 if (globalapp_uid == uid) {
128 dir_config_base = strdup(TTS_GLOBAL_CONFIG_BASE);
129 dir_home = strdup(TTS_GLOBAL_HOME);
130 dir_engine_base = strdup(TTS_GLOBAL_ENGINE_BASE);
131 dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
132 tmp_uid = 301; // app_fw
133 tmp_gid = 301; // app_fw
135 /* User app, Guest app, Security app */
136 if (NULL != g_dir_config_base)
137 dir_config_base = strdup(g_dir_config_base);
138 if (NULL != g_dir_home)
139 dir_home = strdup(g_dir_home);
140 if (NULL != g_dir_engine_base)
141 dir_engine_base = strdup(g_dir_engine_base);
142 if (NULL != g_dir_engine_info)
143 dir_engine_info = strdup(g_dir_engine_info);
148 if (NULL == dir_config_base || NULL == dir_home || NULL == dir_engine_base || NULL == dir_engine_info) {
149 LOGE("[ERROR] Fail to allocate memory");
150 FREE(dir_config_base)
152 FREE(dir_engine_base)
153 FREE(dir_engine_info)
158 LOGD("[DEBUG] dir_engine_info(%s)", dir_engine_info);
161 /* Make directories */
163 // if (0 != access(dir_config_base, F_OK)) {
164 fd = open(dir_config_base, O_DIRECTORY);
166 LOGE("[INFO] No directory : %s, errno : %d", dir_config_base, errno);
167 if (0 != mkdir(dir_config_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
168 LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_config_base, errno);
169 FREE(dir_config_base)
171 FREE(dir_engine_base)
172 FREE(dir_engine_info)
175 LOGD("Success to make directory : %s", dir_config_base);
176 if (0 != chown(dir_config_base, tmp_uid, tmp_gid)) {
177 LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
179 LOGD("[DEBUG] Success to change user and group");
186 // if (0 != access(dir_home, F_OK)) {
187 fd = open(dir_home, O_DIRECTORY);
189 LOGE("[INFO] No directory : %s, errno : %d", dir_home, errno);
190 if (0 != mkdir(dir_home, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
191 LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_home, errno);
192 FREE(dir_config_base)
194 FREE(dir_engine_base)
195 FREE(dir_engine_info)
198 LOGD("Success to make directory : %s", dir_home);
199 if (0 != chown(dir_home, tmp_uid, tmp_gid)) {
200 LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
202 LOGD("[DEBUG] Success to change user and group");
209 // if (0 != access(dir_engine_base, F_OK)) {
210 fd = open(dir_engine_base, O_DIRECTORY);
212 LOGE("[INFO] No directory : %s, errno : %d", dir_engine_base, errno);
213 if (0 != mkdir(dir_engine_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
214 LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_engine_base, errno);
215 FREE(dir_config_base)
217 FREE(dir_engine_base)
218 FREE(dir_engine_info)
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, errno : %d", errno);
225 LOGD("[DEBUG] Success to change user and group");
232 // if (0 != access(dir_engine_info, F_OK)) {
233 fd = open(dir_engine_info, O_DIRECTORY);
235 LOGE("[INFO] No directory : %s, errno : %d", dir_engine_info, errno);
236 if (0 != mkdir(dir_engine_info, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
237 LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_engine_info, errno);
238 FREE(dir_config_base)
240 FREE(dir_engine_base)
241 FREE(dir_engine_info)
244 LOGD("Success to make directory : %s", dir_engine_info);
245 if (0 != chown(dir_engine_info, tmp_uid, tmp_gid)) {
246 LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
248 LOGD("[DEBUG] Success to change user and group");
256 char path[256] = {'\0',};
257 snprintf(path, 256, "%s/%s.xml", dir_engine_info, pkgid);
258 int ret = xmlSaveFormatFile(path, g_doc, 1);
259 LOGD("xmlSaveFile (%d)", ret);
261 if (0 != chown(path, tmp_uid, tmp_gid)) {
262 LOGD("[ERROR] Fail to change user and group");
264 LOGD("[DEBUG] Success to change user and group");
268 FREE(dir_config_base)
270 FREE(dir_engine_base)
271 FREE(dir_engine_info)
277 static int __remove_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
279 LOGD("@@@ Remove engine info doc");
281 char *dir_engine_info = NULL;
283 if (NULL == ut || (NULL != ut && 0 == strcmp(ut, "none"))) {
284 LOGE("[ERROR] Usertype is NONE");
288 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
290 LOGD("uid(%d)", uid);
292 if (globalapp_uid == uid) {
294 dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
296 /* User app, Guest app, Security app */
297 if (NULL != g_dir_engine_info)
298 dir_engine_info = strdup(g_dir_engine_info);
301 if (NULL == dir_engine_info) {
302 LOGE("[ERROR] Fail to allocate memory");
306 LOGD("[DEBUG] dir_engine_info(%s)", dir_engine_info);
309 char path[256] = {'\0',};
310 snprintf(path, 256, "%s/%s.xml", dir_engine_info, pkgid);
311 if (0 == access(path, F_OK)) {
312 LOGD("Remove engine info xml(%s)", path);
313 if (0 != remove(path)) {
314 LOGE("[ERROR] Fail to Remove engine info xml(%s)", path);
318 FREE(dir_engine_info)
324 static void __insert_language_from_metadata(xmlNodePtr root, const char *language)
326 LOGD("@@@ Insert language");
330 if (NULL == root || NULL == language) {
331 LOGE("Invalid parameter, root(%p), language(%s)", root, language);
335 char *tmp_lang = NULL;
336 char *tmp_free = NULL;
337 tmp_free = tmp_lang = strdup(language);
338 if (NULL == tmp_lang) {
339 LOGE("Fail to memory allocation");
342 xmlNodePtr voices_node = NULL;
343 xmlNodePtr voice_node = NULL;
345 voices_node = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_VOICE_SET);
347 voice = strsep(&tmp_lang, ",");
348 while (NULL != voice) {
349 LOGD("voice (%s)", voice);
350 voice_node = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_VOICE);
351 lang = strsep(&voice, ":");
352 LOGD("lang (%s)", lang);
353 type = strsep(&voice, " ");
354 LOGD("type (%s)", type);
355 xmlSetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE, (const xmlChar*)type);
356 xmlNodeSetContent(voice_node, (const xmlChar*)lang);
357 xmlAddChild(voices_node, voice_node);
358 voice = strsep(&tmp_lang, ",");
360 xmlAddChild(root, voices_node);
365 static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *list)
370 __create_engine_info_xml(pkgid);
372 xmlNodePtr root = NULL;
373 xmlNodePtr cur = NULL;
375 root = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_BASE);
377 LOGE("[ERROR] Fail to get new node");
378 // xmlFreeDoc(g_doc);
381 xmlDocSetRootElement(g_doc, root);
384 // cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_NAME);
385 // xmlNodeSetContent(cur, (const xmlChar*)pkgid);
386 // xmlAddChild(root, cur);
389 iter = g_list_first(list);
390 while (NULL != iter) {
391 md = (metadata *)iter->data;
392 if (NULL != md && NULL != md->key) {
393 LOGD(" - key(%s) value(%s)", md->key, md->value);
394 if (!strcmp(md->key, TTS_METADATA_LANGUAGE)) {
395 __insert_language_from_metadata(root, md->value);
396 } else if (!strcmp(md->key, TTS_METADATA_CREDENTIAL_REQUIRED)) {
397 cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_CREDENTIAL);
398 xmlNodeSetContent(cur, (const xmlChar*)md->value);
399 xmlAddChild(root, cur);
400 } else if (!strcmp(md->key, TTS_METADATA_SETTING)) {
401 cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_SETTING);
402 xmlNodeSetContent(cur, (const xmlChar*)md->value);
403 xmlAddChild(root, cur);
404 } else if (!strcmp(md->key, TTS_METADATA_NAME)) {
405 cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_NAME);
406 xmlNodeSetContent(cur, (const xmlChar*)md->value);
407 xmlAddChild(root, cur);
408 } else if (!strcmp(md->key, TTS_METADATA_TEXT_SIZE)) {
409 cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_TEXT_SIZE);
410 xmlNodeSetContent(cur, (const xmlChar*)md->value);
411 xmlAddChild(root, cur);
412 } else if (!strcmp(md->key, TTS_METADATA_PITCH_SUPPORT)) {
413 cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_PITCH_SUPPORT);
414 xmlNodeSetContent(cur, (const xmlChar*)md->value);
415 xmlAddChild(root, cur);
417 LOGW("[WARNING] Unknown metadata type");
420 iter = g_list_next(iter);
423 cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_ID);
424 xmlNodeSetContent(cur, (const xmlChar*)pkgid);
425 xmlAddChild(root, cur);
434 int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
436 LOGD("METADATA INSTALL");
437 LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
440 ret = pkgmgr_installer_info_get_target_uid(&g_uid);
442 LOGE("[ERROR] Fail to get target uid");
445 LOGD("uid(%d)", g_uid);
446 printf("[Parser Debug][DEBUG] uid(%d)", g_uid);
449 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
450 if (globalapp_uid == g_uid) {
451 g_user_type = g_strdup("admin");
453 g_guser = gum_user_get_sync(g_uid, FALSE);
454 if (NULL == g_guser) {
455 LOGE("[ERROR] g_guser is NULL");
459 g_object_get(G_OBJECT(g_guser), "gid", &g_gid, NULL);
460 g_object_get(G_OBJECT(g_guser), "usertype", &g_ut, NULL);
461 g_user_type = g_strdup(gum_user_type_to_string(g_ut));
464 if (NULL == g_user_type) {
465 LOGE("[ERROR] Fail to allocate memory");
466 if (NULL != g_guser) {
467 g_object_unref(g_guser);
473 if (0 == strcmp(g_user_type, "none")) {
474 /* GUM_USERTYPE_NONE */
475 LOGE("[ERROR] Fail to get target uid");
476 g_object_unref(g_guser);
482 if (globalapp_uid == g_uid) {
483 /* global directory */
484 LOGD("[DEBUG] usertype: %s", g_user_type);
485 if (0 >= g_list_length(list)) {
486 LOGE("[ERROR] No Engine Metadata");
491 if (0 != __write_metadata_inxml(pkgid, appid, list)) {
492 LOGE("[ERROR] Fail to write metadata in the xml");
498 /* Save in /etc/skel/share/ */
499 g_dir_config_base = strdup(TTS_GLOBAL_CONFIG_BASE);
500 g_dir_home = strdup(TTS_GLOBAL_HOME);
501 g_dir_engine_base = strdup(TTS_GLOBAL_ENGINE_BASE);
502 g_dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
504 if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
505 LOGE("[ERROR] Fail to allocate memory");
506 FREE(g_dir_config_base)
508 FREE(g_dir_engine_base)
509 FREE(g_dir_engine_info)
516 if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid, g_gid)) {
517 LOGE("[ERROR] Fail to make engine info file");
523 /* Get user data by using libgum */
525 GumUserService *gus = NULL;
526 GumUserList *users = NULL;
527 GumUserList *iter = NULL;
528 GumUser *user = NULL;
530 GumUserType gumut = GUM_USERTYPE_NONE;
531 gchar *user_type = NULL;
535 gchar *home_dir = NULL;
537 gus = gum_user_service_create_sync(TRUE);
539 LOGE("Failed to create gum user service");
544 query = g_strsplit("admin,normal", ",", -1);
546 users = gum_user_service_get_user_list_sync(gus, (const gchar *const *)query);
557 /* Make new user list */
560 while (iter != NULL) {
561 user = (GumUser*) iter->data;
562 g_object_get(G_OBJECT(user), "uid", &uid, NULL);
565 g_object_get(G_OBJECT(user), "gid", &gid, NULL);
566 g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
567 g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
568 user_type = g_strdup(gum_user_type_to_string(gumut));
569 if (NULL == user_type) {
570 gum_user_service_list_free(users);
577 LOGD("[DEBUG] user info");
578 if (NULL != home_dir) {
579 LOGD("[DEBUG] uid(%d), gid(%d), user_type(%s), home_dir(%s)", uid, gid, user_type, home_dir);
581 g_dir_config_base = (char*)calloc(strlen(home_dir) + 14, sizeof(char));
582 g_dir_home = (char*)calloc(strlen(home_dir) + 18, sizeof(char));
583 g_dir_engine_base = (char*)calloc(strlen(home_dir) + 22, sizeof(char));
584 g_dir_engine_info = (char*)calloc(strlen(home_dir) + 34, sizeof(char));
586 if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
587 LOGE("[ERROR] Fail to allocate memory");
588 FREE(g_dir_config_base)
590 FREE(g_dir_engine_base)
591 FREE(g_dir_engine_info)
592 gum_user_service_list_free(users);
599 snprintf(g_dir_config_base, strlen(home_dir) + 14, "%s/share/.voice", home_dir);
600 snprintf(g_dir_home, strlen(home_dir) + 18, "%s/share/.voice/tts", home_dir);
601 snprintf(g_dir_engine_base, strlen(home_dir) + 22, "%s/share/.voice/tts/1.0", home_dir);
602 snprintf(g_dir_engine_info, strlen(home_dir) + 34, "%s/share/.voice/tts/1.0/engine-info", home_dir);
604 LOGD("[DEBUG] g_dir_engine_info(%s)", g_dir_engine_info);
606 if (0 != __save_engine_info_xml(pkgid, user_type, uid, gid)) {
607 LOGE("[ERROR] Fail to make engine info file");
610 FREE(g_dir_config_base)
612 FREE(g_dir_engine_base)
613 FREE(g_dir_engine_info)
619 iter = g_list_next(iter);
622 gum_user_service_list_free(users);
627 LOGD("[DEBUG] usertype: %s", g_user_type);
629 ret = tzplatform_set_user(g_uid);
631 LOGE("[ERROR] Invalid uid");
632 g_object_unref(g_guser);
637 LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
638 printf("[Parser Debug][DEBUG] TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
641 if (0 >= g_list_length(list)) {
642 LOGE("[ERROR] No Engine Metadata");
643 g_object_unref(g_guser);
649 if (0 != __write_metadata_inxml(pkgid, appid, list)) {
650 LOGE("[ERROR] Fail to write metadata in the xml");
652 g_object_unref(g_guser);
658 g_dir_config_base = strdup(TTS_CONFIG_BASE);
659 g_dir_home = strdup(TTS_HOME);
660 g_dir_engine_base = strdup(TTS_ENGINE_BASE);
661 g_dir_engine_info = strdup(TTS_ENGINE_INFO);
663 if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
664 LOGE("[ERROR] Fail to allocate memory");
665 FREE(g_dir_config_base)
667 FREE(g_dir_engine_base)
668 FREE(g_dir_engine_info)
670 g_object_unref(g_guser);
676 if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid, g_gid)) {
677 LOGE("[ERROR] Fail to make engine info file");
679 if (NULL != g_guser) {
680 g_object_unref(g_guser);
689 if (NULL != g_guser) {
690 g_object_unref(g_guser);
695 FREE(g_dir_config_base)
697 FREE(g_dir_engine_base)
698 FREE(g_dir_engine_info)
704 int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list)
706 LOGD("METADATA UNINSTALL");
707 LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
710 ret = pkgmgr_installer_info_get_target_uid(&g_uid);
712 LOGE("[ERROR] Fail to get target uid");
715 LOGD("uid(%d)", g_uid);
716 printf("[Parser Debug][DEBUG] uid(%d)", g_uid);
719 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
720 if (globalapp_uid == g_uid) {
721 g_user_type = g_strdup("admin");
723 g_guser = gum_user_get_sync(g_uid, FALSE);
724 if (NULL == g_guser) {
725 LOGE("[ERROR] g_guser is NULL");
729 g_object_get(G_OBJECT(g_guser), "usertype", &g_ut, NULL);
730 g_user_type = g_strdup(gum_user_type_to_string(g_ut));
733 if (NULL == g_user_type) {
734 LOGE("[ERROR] Fail to allocate memory");
735 if (NULL != g_guser) {
736 g_object_unref(g_guser);
742 if (0 == strcmp(g_user_type, "none")) {
743 /* GUM_USERTYPE_NONE */
744 LOGE("[ERROR] Fail to get target uid");
745 g_object_unref(g_guser);
751 if (globalapp_uid == g_uid) {
752 /* global directory */
753 LOGD("[DEBUG] usertype: %s", g_user_type);
755 /* Remove files in /etc/skel/share/ */
756 g_dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
757 if (NULL == g_dir_engine_info) {
758 LOGE("[ERROR] Fail to allocate memory");
763 if (0 != __remove_engine_info_xml(pkgid, g_user_type, g_uid)) {
764 LOGE("[ERROR] Fail to remove engine info file");
767 /* Get user data by using libgum */
769 GumUserService *gus = NULL;
770 GumUserList *users = NULL;
771 GumUserList *iter = NULL;
772 GumUser *user = NULL;
774 GumUserType gumut = GUM_USERTYPE_NONE;
775 gchar *user_type = NULL;
778 gchar *home_dir = NULL;
780 GList *md_iter = NULL;
783 gus = gum_user_service_create_sync(TRUE);
785 LOGE("Failed to create gum user service");
790 query = g_strsplit("admin,normal", ",", -1);
792 users = gum_user_service_get_user_list_sync(gus, (const gchar *const *)query);
803 /* Make new user list */
806 while (iter != NULL) {
807 user = (GumUser*) iter->data;
808 g_object_get(G_OBJECT(user), "uid", &uid, NULL);
810 g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
811 g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
812 user_type = g_strdup(gum_user_type_to_string(gumut));
813 if (NULL == user_type) {
814 gum_user_service_list_free(users);
821 if (NULL != home_dir) {
822 g_dir_engine_info = (char*)calloc(strlen(home_dir) + 34, sizeof(char));
823 if (NULL == g_dir_engine_info) {
824 gum_user_service_list_free(users);
832 snprintf(g_dir_engine_info, strlen(home_dir) + 34, "%s/share/.voice/tts/1.0/engine-info", home_dir);
834 md_iter = g_list_first(list);
835 while (NULL != md_iter) {
836 md = (metadata *)md_iter->data;
837 LOGD(" - key(%s) value(%s)", md->key, md->value);
838 md_iter = g_list_next(md_iter);
841 if (0 != __remove_engine_info_xml(pkgid, user_type, uid)) {
842 LOGE("[ERROR] Fail to remove engine info file");
846 FREE(g_dir_engine_info)
850 LOGD("Finish release memory");
851 iter = g_list_next(iter);
852 LOGD("Finish next iter");
855 gum_user_service_list_free(users);
860 LOGD("[DEBUG] usertype: %s", g_user_type);
862 ret = tzplatform_set_user(g_uid);
864 LOGE("[ERROR] Invalid uid");
865 g_object_unref(g_guser);
870 LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
871 printf("[Parser Debug][DEBUG] TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
874 g_dir_engine_info = strdup(TTS_ENGINE_INFO);
875 if (NULL == g_dir_engine_info) {
876 LOGE("[ERROR] Fail to allocate memory");
877 g_object_unref(g_guser);
883 if (0 != __remove_engine_info_xml(pkgid, g_user_type, g_uid)) {
884 LOGE("[ERROR] Fail to remove engine info file");
889 if (NULL != g_guser) {
890 g_object_unref(g_guser);
895 FREE(g_dir_engine_info)
902 int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list)
904 LOGD("METADATA UPGRADE");
905 LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
907 PKGMGR_MDPARSER_PLUGIN_UNINSTALL(pkgid, appid, list);
908 PKGMGR_MDPARSER_PLUGIN_INSTALL(pkgid, appid, list);