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_NAME "http://tizen.org/metadata/tts-engine/name"
66 #define TTS_METADATA_LANGUAGE "http://tizen.org/metadata/tts-engine/language"
67 #define TTS_METADATA_CREDENTIAL_REQUIRED "http://tizen.org/metadata/tts-engine/credential-required"
68 #define TTS_METADATA_SETTING "http://tizen.org/metadata/tts-engine/setting"
70 typedef struct metadata {
75 static xmlDocPtr g_doc;
76 GumUser *g_guser = NULL;
77 uid_t g_uid = 301; // app_fw
78 gid_t g_gid = 301; // app_fw
79 GumUserType g_ut = GUM_USERTYPE_NONE;
80 gchar *g_user_type = NULL;
82 char *g_dir_config_base = NULL;
83 char *g_dir_home = NULL;
84 char *g_dir_engine_base = NULL;
85 char *g_dir_engine_info = NULL;
87 static int __create_engine_info_xml(const char *pkgid)
89 LOGD("=== Create engine info doc");
90 g_doc = xmlNewDoc((xmlChar*)"1.0");
92 LOGE("[ERROR] Fail to new doc");
99 static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t gid)
101 LOGD("=== Save engine info doc");
102 char *dir_config_base = NULL;
103 char *dir_home = NULL;
104 char *dir_engine_base = NULL;
105 char *dir_engine_info = NULL;
107 if (NULL == ut || (NULL != ut && 0 == strcmp(ut, "none"))) {
108 LOGE("[ERROR] Usertype is NONE");
112 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
116 LOGD("uid(%d)", uid);
118 if (globalapp_uid == uid) {
120 dir_config_base = strdup(TTS_GLOBAL_CONFIG_BASE);
121 dir_home = strdup(TTS_GLOBAL_HOME);
122 dir_engine_base = strdup(TTS_GLOBAL_ENGINE_BASE);
123 dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
124 tmp_uid = 301; // app_fw
125 tmp_gid = 301; // app_fw
127 /* User app, Guest app, Security app */
128 if (NULL != g_dir_config_base)
129 dir_config_base = strdup(g_dir_config_base);
130 if (NULL != g_dir_home)
131 dir_home = strdup(g_dir_home);
132 if (NULL != g_dir_engine_base)
133 dir_engine_base = strdup(g_dir_engine_base);
134 if (NULL != g_dir_engine_info)
135 dir_engine_info = strdup(g_dir_engine_info);
140 if (NULL == dir_config_base || NULL == dir_home || NULL == dir_engine_base || NULL == dir_engine_info) {
141 LOGE("[ERROR] Fail to allocate memory");
142 if (NULL != dir_config_base) {
143 free(dir_config_base);
144 dir_config_base = NULL;
146 if (NULL != dir_home) {
150 if (NULL != dir_engine_base) {
151 free(dir_engine_base);
152 dir_engine_base = NULL;
154 if (NULL != dir_engine_info) {
155 free(dir_engine_info);
156 dir_engine_info = NULL;
161 LOGD("[DEBUG] dir_engine_info(%s)", dir_engine_info);
164 /* Make directories */
165 if (0 != access(dir_config_base, F_OK)) {
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", dir_config_base);
168 free(dir_config_base);
169 dir_config_base = NULL;
172 free(dir_engine_base);
173 dir_engine_base = NULL;
174 free(dir_engine_info);
175 dir_engine_info = NULL;
178 LOGD("Success to make directory : %s", dir_config_base);
179 if (0 != chown(dir_config_base, tmp_uid, tmp_gid)) {
180 LOGD("[ERROR] Fail to change user and group");
182 LOGD("[DEBUG] Success to change user and group");
187 if (0 != access(dir_home, F_OK)) {
188 if (0 != mkdir(dir_home, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
189 LOGE("[ERROR] Fail to make directory : %s", dir_home);
190 free(dir_config_base);
191 dir_config_base = NULL;
194 free(dir_engine_base);
195 dir_engine_base = NULL;
196 free(dir_engine_info);
197 dir_engine_info = NULL;
200 LOGD("Success to make directory : %s", dir_home);
201 if (0 != chown(dir_home, tmp_uid, tmp_gid)) {
202 LOGD("[ERROR] Fail to change user and group");
204 LOGD("[DEBUG] Success to change user and group");
209 if (0 != access(dir_engine_base, F_OK)) {
210 if (0 != mkdir(dir_engine_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
211 LOGE("[ERROR] Fail to make directory : %s", dir_engine_base);
212 free(dir_config_base);
213 dir_config_base = NULL;
216 free(dir_engine_base);
217 dir_engine_base = NULL;
218 free(dir_engine_info);
219 dir_engine_info = NULL;
222 LOGD("Success to make directory : %s", dir_engine_base);
223 if (0 != chown(dir_engine_base, tmp_uid, tmp_gid)) {
224 LOGD("[ERROR] Fail to change user and group");
226 LOGD("[DEBUG] Success to change user and group");
231 if (0 != access(dir_engine_info, F_OK)) {
232 if (0 != mkdir(dir_engine_info, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
233 LOGE("[ERROR] Fail to make directory : %s", dir_engine_info);
234 free(dir_config_base);
235 dir_config_base = NULL;
238 free(dir_engine_base);
239 dir_engine_base = NULL;
240 free(dir_engine_info);
241 dir_engine_info = NULL;
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");
248 LOGD("[DEBUG] Success to change user and group");
254 char path[256] = {'\0',};
255 snprintf(path, 256, "%s/%s.xml", dir_engine_info, pkgid);
256 int ret = xmlSaveFormatFile(path, g_doc, 1);
257 LOGD("xmlSaveFile (%d)", ret);
259 if (0 != chown(path, tmp_uid, tmp_gid)) {
260 LOGD("[ERROR] Fail to change user and group");
262 LOGD("[DEBUG] Success to change user and group");
266 free(dir_config_base);
267 dir_config_base = NULL;
270 free(dir_engine_base);
271 dir_engine_base = NULL;
272 free(dir_engine_info);
273 dir_engine_info = NULL;
279 static int __remove_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
281 LOGD("=== Remove engine info doc");
283 char *dir_engine_info = NULL;
285 if (NULL == ut || (NULL != ut && 0 == strcmp(ut, "none"))) {
286 LOGE("[ERROR] Usertype is NONE");
290 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
292 LOGD("uid(%d)", uid);
294 if (globalapp_uid == uid) {
296 dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
298 /* User app, Guest app, Security app */
299 if (NULL != g_dir_engine_info)
300 dir_engine_info = strdup(g_dir_engine_info);
303 if (NULL == dir_engine_info) {
304 LOGE("[ERROR] Fail to allocate memory");
308 LOGD("[DEBUG] dir_engine_info(%s)", dir_engine_info);
311 char path[256] = {'\0',};
312 snprintf(path, 256, "%s/%s.xml", dir_engine_info, pkgid);
313 if (0 == access(path, F_OK)) {
314 LOGD("Remove engine info xml(%s)", path);
315 if (0 != remove(path)) {
316 LOGE("[ERROR] Fail to Remove engine info xml(%s)", path);
320 free(dir_engine_info);
321 dir_engine_info = NULL;
327 static void __insert_language_from_metadata(xmlNodePtr root, const char *language)
329 LOGD("==== Insert 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);
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);
409 LOGW("[WARNING] Unknown metadata type");
412 iter = g_list_next(iter);
415 cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_ID);
416 xmlNodeSetContent(cur, (const xmlChar*)pkgid);
417 xmlAddChild(root, cur);
426 int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
428 LOGD("METADATA INSTALL");
429 LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
432 ret = pkgmgr_installer_info_get_target_uid(&g_uid);
434 LOGE("[ERROR] Fail to get target uid");
437 LOGD("uid(%d)", g_uid);
438 printf("[Parser Debug][DEBUG] uid(%d)", g_uid);
441 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
442 if (globalapp_uid == g_uid) {
443 g_user_type = g_strdup("admin");
445 g_guser = gum_user_get_sync(g_uid, FALSE);
446 if (NULL == g_guser) {
447 LOGE("[ERROR] g_guser is NULL");
451 g_object_get(G_OBJECT(g_guser), "gid", &g_gid, NULL);
452 g_object_get(G_OBJECT(g_guser), "usertype", &g_ut, NULL);
453 g_user_type = g_strdup(gum_user_type_to_string(g_ut));
456 if (NULL == g_user_type) {
457 LOGE("[ERROR] Fail to allocate memory");
458 if (NULL != g_guser) {
459 g_object_unref(g_guser);
465 if (0 == strcmp(g_user_type, "none")) {
466 /* GUM_USERTYPE_NONE */
467 LOGE("[ERROR] Fail to get target uid");
468 g_object_unref(g_guser);
474 if (globalapp_uid == g_uid) {
475 /* global directory */
476 LOGD("[DEBUG] usertype: %s", g_user_type);
477 if (0 >= g_list_length(list)) {
478 LOGE("[ERROR] No Engine Metadata");
483 if (0 != __write_metadata_inxml(pkgid, appid, list)) {
484 LOGE("[ERROR] Fail to write metadata in the xml");
490 /* Save in /etc/skel/share/ */
491 g_dir_config_base = strdup(TTS_GLOBAL_CONFIG_BASE);
492 g_dir_home = strdup(TTS_GLOBAL_HOME);
493 g_dir_engine_base = strdup(TTS_GLOBAL_ENGINE_BASE);
494 g_dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
496 if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
497 LOGE("[ERROR] Fail to allocate memory");
498 if (NULL != g_dir_config_base) {
499 free(g_dir_config_base);
500 g_dir_config_base = NULL;
502 if (NULL != g_dir_home) {
506 if (NULL != g_dir_engine_base) {
507 free(g_dir_engine_base);
508 g_dir_engine_base = NULL;
510 if (NULL != g_dir_engine_info) {
511 free(g_dir_engine_info);
512 g_dir_engine_info = NULL;
519 if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid, g_gid)) {
520 LOGE("[ERROR] Fail to make engine info file");
526 /* Get user data by using libgum */
528 GumUserService *gus = NULL;
529 GumUserList *users = NULL;
530 GumUserList *iter = NULL;
531 GumUser *user = NULL;
533 GumUserType gumut = GUM_USERTYPE_NONE;
534 gchar *user_type = NULL;
538 gchar *home_dir = NULL;
540 gus = gum_user_service_create_sync(TRUE);
542 LOGE("Failed to create gum user service");
547 query = g_strsplit("admin,normal", ",", -1);
549 users = gum_user_service_get_user_list_sync(gus, (const gchar *const *)query);
553 LOGE("Failed to get gum user list");
560 /* Make new user list */
563 while (iter != NULL) {
564 user = (GumUser*) iter->data;
565 g_object_get(G_OBJECT(user), "uid", &uid, NULL);
566 if (NULL != home_dir) {
570 g_object_get(G_OBJECT(user), "gid", &gid, NULL);
571 g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
572 g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
573 user_type = g_strdup(gum_user_type_to_string(gumut));
574 if (NULL == user_type) {
575 gum_user_service_list_free(users);
581 LOGD("[DEBUG] user info");
582 if (NULL != home_dir) {
583 LOGD("[DEBUG] uid(%d), gid(%d), user_type(%s), home_dir(%s)", uid, gid, user_type, home_dir);
585 g_dir_config_base = (char*)calloc(strlen(home_dir) + 14, sizeof(char));
586 g_dir_home = (char*)calloc(strlen(home_dir) + 18, sizeof(char));
587 g_dir_engine_base = (char*)calloc(strlen(home_dir) + 22, sizeof(char));
588 g_dir_engine_info = (char*)calloc(strlen(home_dir) + 34, sizeof(char));
590 if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
591 LOGE("[ERROR] Fail to allocate memory");
592 if (NULL != g_dir_config_base) {
593 free(g_dir_config_base);
594 g_dir_config_base = NULL;
596 if (NULL != g_dir_home) {
600 if (NULL != g_dir_engine_base) {
601 free(g_dir_engine_base);
602 g_dir_engine_base = NULL;
604 if (NULL != g_dir_engine_info) {
605 free(g_dir_engine_info);
606 g_dir_engine_info = NULL;
608 gum_user_service_list_free(users);
613 snprintf(g_dir_config_base, strlen(home_dir) + 14, "%s/share/.voice", home_dir);
614 snprintf(g_dir_home, strlen(home_dir) + 18, "%s/share/.voice/tts", home_dir);
615 snprintf(g_dir_engine_base, strlen(home_dir) + 22, "%s/share/.voice/tts/1.0", home_dir);
616 snprintf(g_dir_engine_info, strlen(home_dir) + 34, "%s/share/.voice/tts/1.0/engine-info", home_dir);
618 LOGD("[DEBUG] g_dir_engine_info(%s)", g_dir_engine_info);
620 if (0 != __save_engine_info_xml(pkgid, user_type, uid, gid)) {
621 LOGE("[ERROR] Fail to make engine info file");
624 free(g_dir_config_base);
625 g_dir_config_base = NULL;
628 free(g_dir_engine_base);
629 g_dir_engine_base = NULL;
630 free(g_dir_engine_info);
631 g_dir_engine_info = NULL;
638 iter = g_list_next(iter);
640 iter = g_list_next(iter);
643 if (NULL != user_type) {
649 gum_user_service_list_free(users);
654 LOGD("[DEBUG] usertype: %s", g_user_type);
656 ret = tzplatform_set_user(g_uid);
658 LOGE("[ERROR] Invalid uid");
659 g_object_unref(g_guser);
664 LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
665 printf("[Parser Debug][DEBUG] TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
668 if (0 >= g_list_length(list)) {
669 LOGE("[ERROR] No Engine Metadata");
670 g_object_unref(g_guser);
676 if (0 != __write_metadata_inxml(pkgid, appid, list)) {
677 LOGE("[ERROR] Fail to write metadata in the xml");
679 g_object_unref(g_guser);
685 g_dir_config_base = strdup(TTS_CONFIG_BASE);
686 g_dir_home = strdup(TTS_HOME);
687 g_dir_engine_base = strdup(TTS_ENGINE_BASE);
688 g_dir_engine_info = strdup(TTS_ENGINE_INFO);
690 if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
691 LOGE("[ERROR] Fail to allocate memory");
692 if (NULL != g_dir_config_base) {
693 free(g_dir_config_base);
694 g_dir_config_base = NULL;
696 if (NULL != g_dir_home) {
700 if (NULL != g_dir_engine_base) {
701 free(g_dir_engine_base);
702 g_dir_engine_base = NULL;
704 if (NULL != g_dir_engine_info) {
705 free(g_dir_engine_info);
706 g_dir_engine_info = NULL;
709 g_object_unref(g_guser);
715 if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid, g_gid)) {
716 LOGE("[ERROR] Fail to make engine info file");
718 if (NULL != g_guser) {
719 g_object_unref(g_guser);
728 if (NULL != g_guser) {
729 g_object_unref(g_guser);
734 if (NULL != g_dir_config_base) {
735 free(g_dir_config_base);
736 g_dir_config_base = NULL;
738 if (NULL != g_dir_home) {
742 if (NULL != g_dir_engine_base) {
743 free(g_dir_engine_base);
744 g_dir_engine_base = NULL;
746 if (NULL != g_dir_engine_info) {
747 free(g_dir_engine_info);
748 g_dir_engine_info = NULL;
755 int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list)
757 LOGD("METADATA UNINSTALL");
758 LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
761 ret = pkgmgr_installer_info_get_target_uid(&g_uid);
763 LOGE("[ERROR] Fail to get target uid");
766 LOGD("uid(%d)", g_uid);
767 printf("[Parser Debug][DEBUG] uid(%d)", g_uid);
770 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
771 if (globalapp_uid == g_uid) {
772 g_user_type = g_strdup("admin");
774 g_guser = gum_user_get_sync(g_uid, FALSE);
775 if (NULL == g_guser) {
776 LOGE("[ERROR] g_guser is NULL");
780 g_object_get(G_OBJECT(g_guser), "usertype", &g_ut, NULL);
781 g_user_type = g_strdup(gum_user_type_to_string(g_ut));
784 if (NULL == g_user_type) {
785 LOGE("[ERROR] Fail to allocate memory");
786 if (NULL != g_guser) {
787 g_object_unref(g_guser);
793 if (0 == strcmp(g_user_type, "none")) {
794 /* GUM_USERTYPE_NONE */
795 LOGE("[ERROR] Fail to get target uid");
796 g_object_unref(g_guser);
802 if (globalapp_uid == g_uid) {
803 /* global directory */
804 LOGD("[DEBUG] usertype: %s", g_user_type);
806 /* Remove files in /etc/skel/share/ */
807 g_dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
808 if (NULL == g_dir_engine_info) {
809 LOGE("[ERROR] Fail to allocate memory");
814 if (0 != __remove_engine_info_xml(pkgid, g_user_type, g_uid)) {
815 LOGE("[ERROR] Fail to remove engine info file");
818 /* Get user data by using libgum */
820 GumUserService *gus = NULL;
821 GumUserList *users = NULL;
822 GumUserList *iter = NULL;
823 GumUser *user = NULL;
825 GumUserType gumut = GUM_USERTYPE_NONE;
826 gchar *user_type = NULL;
829 gchar *home_dir = NULL;
831 GList *md_iter = NULL;
834 gus = gum_user_service_create_sync(TRUE);
836 LOGE("Failed to create gum user service");
841 query = g_strsplit("admin,normal", ",", -1);
843 users = gum_user_service_get_user_list_sync(gus, (const gchar *const *)query);
847 LOGE("Failed to get gum user list");
854 /* Make new user list */
857 while (iter != NULL) {
858 user = (GumUser*) iter->data;
859 g_object_get(G_OBJECT(user), "uid", &uid, NULL);
860 if (NULL != home_dir) {
864 g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
865 g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
866 user_type = g_strdup(gum_user_type_to_string(gumut));
867 if (NULL == user_type) {
868 gum_user_service_list_free(users);
874 if (NULL != home_dir) {
875 g_dir_engine_info = (char*)calloc(strlen(home_dir) + 34, sizeof(char));
876 if (NULL == g_dir_engine_info) {
877 gum_user_service_list_free(users);
883 snprintf(g_dir_engine_info, strlen(home_dir) + 34, "%s/share/.voice/tts/1.0/engine-info", home_dir);
885 md_iter = g_list_first(list);
886 while (NULL != md_iter) {
887 md = (metadata *)md_iter->data;
888 LOGD(" - key(%s) value(%s)", md->key, md->value);
889 md_iter = g_list_next(md_iter);
892 if (0 != __remove_engine_info_xml(pkgid, user_type, uid)) {
893 LOGE("[ERROR] Fail to remove engine info file");
899 free(g_dir_engine_info);
900 g_dir_engine_info = NULL;
904 LOGD("Finish release memory");
905 iter = g_list_next(iter);
906 LOGD("Finish next iter");
908 iter = g_list_next(iter);
912 gum_user_service_list_free(users);
917 LOGD("[DEBUG] usertype: %s", g_user_type);
919 ret = tzplatform_set_user(g_uid);
921 LOGE("[ERROR] Invalid uid");
922 g_object_unref(g_guser);
927 LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
928 printf("[Parser Debug][DEBUG] TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
931 g_dir_engine_info = strdup(TTS_ENGINE_INFO);
932 if (NULL == g_dir_engine_info) {
933 LOGE("[ERROR] Fail to allocate memory");
934 g_object_unref(g_guser);
940 if (0 != __remove_engine_info_xml(pkgid, g_user_type, g_uid)) {
941 LOGE("[ERROR] Fail to remove engine info file");
946 if (NULL != g_guser) {
947 g_object_unref(g_guser);
952 if (NULL != g_dir_engine_info) {
953 free(g_dir_engine_info);
954 g_dir_engine_info = NULL;
962 int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list)
964 LOGD("METADATA UPGRADE");
965 LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
967 PKGMGR_MDPARSER_PLUGIN_UNINSTALL(pkgid, appid, list);
968 PKGMGR_MDPARSER_PLUGIN_INSTALL(pkgid, appid, list);