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>
28 #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 "stt-engine-parser"
46 #define STT_TAG_ENGINE_BASE "stt-engine"
47 #define STT_TAG_ENGINE_NAME "name"
48 #define STT_TAG_ENGINE_ID "id"
49 #define STT_TAG_ENGINE_SETTING "setting"
50 #define STT_TAG_ENGINE_LANGUAGE_SET "languages"
51 #define STT_TAG_ENGINE_LANGUAGE "lang"
52 #define STT_TAG_ENGINE_SILENCE_DETECTION_SUPPORT "silence-detection-support"
53 #define STT_TAG_ENGINE_CREDENTIAL "credential"
55 #define STT_CONFIG_BASE tzplatform_mkpath(TZ_USER_HOME, "share/.voice")
56 #define STT_HOME tzplatform_mkpath(TZ_USER_HOME, "share/.voice/stt")
57 #define STT_ENGINE_BASE tzplatform_mkpath(TZ_USER_HOME, "share/.voice/stt/1.0")
58 #define STT_ENGINE_INFO tzplatform_mkpath(TZ_USER_SHARE, ".voice/stt/1.0/engine-info")
60 #define STT_GLOBAL_CONFIG_BASE "/etc/skel/share/.voice"
61 #define STT_GLOBAL_HOME "/etc/skel/share/.voice/stt"
62 #define STT_GLOBAL_ENGINE_BASE "/etc/skel/share/.voice/stt/1.0"
63 #define STT_GLOBAL_ENGINE_INFO "/etc/skel/share/.voice/stt/1.0/engine-info"
65 #define STT_METADATA_LANGUAGE "http://tizen.org/metadata/stt-engine/language"
66 #define STT_METADATA_SILENCE_DETECTION "http://tizen.org/metadata/stt-engine/silence-detection"
67 #define STT_METADATA_CREDENTIAL_REQUIRED "http://tizen.org/metadata/stt-engine/credential-required"
68 #define STT_METADATA_ENGINE_SETTING "http://tizen.org/metadata/stt-engine/setting"
69 #define STT_METADATA_ENGINE_NAME "http://tizen.org/metadata/stt-engine/name"
71 typedef struct metadata {
76 static xmlDocPtr g_doc;
77 GumUser *g_guser = NULL;
78 uid_t g_uid = 301; // app_fw
79 gid_t g_gid = 301; // app_fw
80 GumUserType g_ut = GUM_USERTYPE_NONE;
81 gchar *g_user_type = NULL;
83 char *g_dir_config_base = NULL;
84 char *g_dir_home = NULL;
85 char *g_dir_engine_base = NULL;
86 char *g_dir_engine_info = NULL;
89 static int __create_engine_info_xml(const char *pkgid)
91 LOGD("=== Create engine info doc");
92 g_doc = xmlNewDoc((xmlChar*)"1.0");
94 LOGE("[ERROR] Fail to new doc");
101 static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t gid)
103 LOGD("=== Save engine info doc");
104 char *dir_config_base = NULL;
105 char *dir_home = NULL;
106 char *dir_engine_base = NULL;
107 char *dir_engine_info = NULL;
109 if (NULL == ut || (NULL != ut && 0 == strcmp(ut, "none"))) {
110 LOGE("[ERROR] Usertype is NONE");
114 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
117 LOGD("uid(%d)", uid);
119 if (globalapp_uid == uid) {
121 dir_config_base = strdup(STT_GLOBAL_CONFIG_BASE);
122 dir_home = strdup(STT_GLOBAL_HOME);
123 dir_engine_base = strdup(STT_GLOBAL_ENGINE_BASE);
124 dir_engine_info = strdup(STT_GLOBAL_ENGINE_INFO);
125 tmp_uid = 301; // app_fw
126 tmp_gid = 301; // app_fw
128 /* User app, Guest app, Security app */
129 if (NULL != g_dir_config_base)
130 dir_config_base = strdup(g_dir_config_base);
131 if (NULL != g_dir_home)
132 dir_home = strdup(g_dir_home);
133 if (NULL != g_dir_engine_base)
134 dir_engine_base = strdup(g_dir_engine_base);
135 if (NULL != g_dir_engine_info)
136 dir_engine_info = strdup(g_dir_engine_info);
141 if (NULL == dir_config_base || NULL == dir_home || NULL == dir_engine_base || NULL == dir_engine_info) {
142 LOGE("[ERROR] Fail to allocate memory");
143 if (NULL != dir_config_base) {
144 free(dir_config_base);
145 dir_config_base = NULL;
147 if (NULL != dir_home) {
151 if (NULL != dir_engine_base) {
152 free(dir_engine_base);
153 dir_engine_base = NULL;
155 if (NULL != dir_engine_info) {
156 free(dir_engine_info);
157 dir_engine_info = NULL;
162 LOGD("[DEBUG] dir_engine_info(%s)", dir_engine_info);
164 /* Make directories */
165 // if (0 != access(dir_config_base, F_OK)) {
166 if (-1 == open(dir_config_base, O_DIRECTORY)) {
167 LOGE("[INFO] No directory : %s, errno : %d", dir_config_base, errno);
168 if (0 != mkdir(dir_config_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
169 LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_config_base, errno);
170 free(dir_config_base);
171 dir_config_base = NULL;
174 free(dir_engine_base);
175 dir_engine_base = NULL;
176 free(dir_engine_info);
177 dir_engine_info = NULL;
180 LOGD("Success to make directory : %s", dir_config_base);
181 if (0 != chown(dir_config_base, tmp_uid, tmp_gid)) {
182 LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
184 LOGD("[DEBUG] Success to change user and group");
189 // if (0 != access(dir_home, F_OK)) {
190 if (-1 == open(dir_home, O_DIRECTORY)) {
191 LOGE("[INFO] No directory : %s, errno : %d", dir_home, errno);
192 if (0 != mkdir(dir_home, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
193 LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_home, errno);
194 free(dir_config_base);
195 dir_config_base = NULL;
198 free(dir_engine_base);
199 dir_engine_base = NULL;
200 free(dir_engine_info);
201 dir_engine_info = NULL;
204 LOGD("Success to make directory : %s", dir_home);
205 if (0 != chown(dir_home, tmp_uid, tmp_gid)) {
206 LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
208 LOGD("[DEBUG] Success to change user and group");
213 // if (0 != access(dir_engine_base, F_OK)) {
214 if (-1 == open(dir_engine_base, O_DIRECTORY)) {
215 LOGE("[INFO] No directory : %s, errno : %d", dir_engine_base, errno);
216 if (0 != mkdir(dir_engine_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
217 LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_engine_base, errno);
218 free(dir_config_base);
219 dir_config_base = NULL;
222 free(dir_engine_base);
223 dir_engine_base = NULL;
224 free(dir_engine_info);
225 dir_engine_info = NULL;
228 LOGD("Success to make directory : %s", dir_engine_base);
229 if (0 != chown(dir_engine_base, tmp_uid, tmp_gid)) {
230 LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
232 LOGD("[DEBUG] Success to change user and group");
237 // if (0 != access(dir_engine_info, F_OK)) {
238 if (-1 == open(dir_engine_info, O_DIRECTORY)) {
239 LOGE("[INFO] No directory : %s, errno : %d", dir_engine_info, errno);
240 if (0 != mkdir(dir_engine_info, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
241 LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_engine_info, errno);
242 free(dir_config_base);
243 dir_config_base = NULL;
246 free(dir_engine_base);
247 dir_engine_base = NULL;
248 free(dir_engine_info);
249 dir_engine_info = NULL;
252 LOGD("Success to make directory : %s", dir_engine_info);
253 if (0 != chown(dir_engine_info, tmp_uid, tmp_gid)) {
254 LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
256 LOGD("[DEBUG] Success to change user and group");
261 char path[256] = {'\0',};
262 snprintf(path, 256, "%s/%s.xml", dir_engine_info, pkgid);
263 int ret = xmlSaveFormatFile(path, g_doc, 1);
264 LOGD("xmlSaveFile (%d)", ret);
266 if (0 != chown(path, tmp_uid, tmp_gid)) {
267 LOGD("[ERROR] Fail to change user and group");
269 LOGD("[DEBUG] Success to change user and group");
273 free(dir_config_base);
274 dir_config_base = NULL;
277 free(dir_engine_base);
278 dir_engine_base = NULL;
279 free(dir_engine_info);
280 dir_engine_info = NULL;
287 static int __remove_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
289 LOGD("=== Remove engine info doc");
290 char *dir_engine_info = NULL;
292 if (NULL == ut || (NULL != ut && 0 == strcmp(ut, "none"))) {
293 LOGE("[ERROR] Usertype is NONE");
297 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
299 LOGD("uid(%d)", uid);
301 if (globalapp_uid == uid) {
303 dir_engine_info = strdup(STT_GLOBAL_ENGINE_INFO);
305 /* User app, Guest app, Security app */
306 if (NULL != g_dir_engine_info)
307 dir_engine_info = strdup(g_dir_engine_info);
310 if (NULL == dir_engine_info) {
311 LOGE("[ERROR] Fail to allocate memory");
315 LOGD("[DEBUG] dir_engine_info(%s)", dir_engine_info);
317 char path[256] = {'\0',};
318 snprintf(path, 256, "%s/%s.xml", dir_engine_info, pkgid);
319 if (0 == access(path, F_OK)) {
320 LOGD("Remove engine info xml(%s)", path);
321 if (0 != remove(path)) {
322 LOGE("[ERROR] Fail to emove engine info xml(%s)", path);
326 if (NULL != dir_engine_info) {
327 free(dir_engine_info);
328 dir_engine_info = NULL;
336 static void __insert_language_from_metadata(xmlNodePtr root, const char *language)
338 LOGD("==== Insert language");
341 char *tmp_lang, *tmp_free;
342 tmp_free = tmp_lang = strdup(language);
343 xmlNodePtr languages_node = NULL;
344 xmlNodePtr lang_node = NULL;
346 languages_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_ENGINE_LANGUAGE_SET);
348 lang = strsep(&tmp_lang, ",");
349 while (NULL != lang) {
350 LOGD("lang (%s)", lang);
351 lang_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_ENGINE_LANGUAGE);
352 xmlNodeSetContent(lang_node, (const xmlChar*)lang);
353 xmlAddChild(languages_node, lang_node);
354 lang = strsep(&tmp_lang, ",");
356 xmlAddChild(root, languages_node);
361 static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *list)
366 __create_engine_info_xml(pkgid);
368 xmlNodePtr root = NULL;
369 xmlNodePtr cur = NULL;
371 root = xmlNewNode(NULL, (const xmlChar*)STT_TAG_ENGINE_BASE);
374 LOGE("[ERROR] Fail to get new node");
375 // xmlFreeDoc(g_doc);
378 xmlDocSetRootElement(g_doc, root);
380 iter = g_list_first(list);
381 while (NULL != iter) {
382 md = (metadata *)iter->data;
383 if (NULL != md && NULL != md->key && NULL != md->value) {
384 LOGD(" - key(%s) value(%s)", md->key, md->value);
385 if (!strcmp(md->key, STT_METADATA_LANGUAGE)) {
386 __insert_language_from_metadata(root, md->value);
387 } else if (!strcmp(md->key, STT_METADATA_SILENCE_DETECTION)) {
388 cur = xmlNewNode(NULL, (const xmlChar*)STT_TAG_ENGINE_SILENCE_DETECTION_SUPPORT);
389 xmlNodeSetContent(cur, (const xmlChar*)md->value);
390 xmlAddChild(root, cur);
391 } else if (!strcmp(md->key, STT_METADATA_CREDENTIAL_REQUIRED)) {
392 cur = xmlNewNode(NULL, (const xmlChar*)STT_TAG_ENGINE_CREDENTIAL);
393 xmlNodeSetContent(cur, (const xmlChar*)md->value);
394 xmlAddChild(root, cur);
395 } else if (!strcmp(md->key, STT_METADATA_ENGINE_SETTING)) {
396 cur = xmlNewNode(NULL, (const xmlChar*)STT_TAG_ENGINE_SETTING);
397 xmlNodeSetContent(cur, (const xmlChar*)md->value);
398 xmlAddChild(root, cur);
399 } else if (!strcmp(md->key, STT_METADATA_ENGINE_NAME)) {
400 cur = xmlNewNode(NULL, (const xmlChar*)STT_TAG_ENGINE_NAME);
401 xmlNodeSetContent(cur, (const xmlChar*)md->value);
402 xmlAddChild(root, cur);
404 LOGW("[WARNING] Unknown metadata type");
407 iter = g_list_next(iter);
410 cur = xmlNewNode(NULL, (const xmlChar*)STT_TAG_ENGINE_ID);
411 xmlNodeSetContent(cur, (const xmlChar*)appid);
412 xmlAddChild(root, cur);
419 int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
421 LOGD("METADATA INSTALL");
422 LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
425 ret = pkgmgr_installer_info_get_target_uid(&g_uid);
427 LOGE("[ERROR] Fail to get target uid");
430 LOGD("uid(%d)", g_uid);
431 printf("[Parser Debug][DEBUG] uid(%d)", g_uid);
434 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
435 if (globalapp_uid == g_uid) {
436 g_user_type = g_strdup("admin");
438 g_guser = gum_user_get_sync(g_uid, FALSE);
439 if (NULL == g_guser) {
440 LOGE("[ERROR] g_guser is NULL");
444 g_object_get(G_OBJECT(g_guser), "gid", &g_gid, NULL);
445 g_object_get(G_OBJECT(g_guser), "usertype", &g_ut, NULL);
446 g_user_type = g_strdup(gum_user_type_to_string(g_ut));
449 if (NULL == g_user_type) {
450 LOGE("[ERROR] Fail to allocate memory");
451 if (NULL != g_guser) {
452 g_object_unref(g_guser);
458 if (0 == strcmp(g_user_type, "none")) {
459 /* GUM_USERTYPE_NONE */
460 LOGE("[ERROR] Fail to get target uid");
461 g_object_unref(g_guser);
467 if (globalapp_uid == g_uid) {
468 /* global directory */
469 LOGD("[DEBUG] usertype: %s", g_user_type);
470 if (0 >= g_list_length(list)) {
471 LOGE("[ERROR] No Engine Metadata");
476 if (0 != __write_metadata_inxml(pkgid, appid, list)) {
477 LOGE("[ERROR] Fail to write metadata in the xml");
483 /* Save in /etc/skel/share/ */
484 g_dir_config_base = strdup(STT_GLOBAL_CONFIG_BASE);
485 g_dir_home = strdup(STT_GLOBAL_HOME);
486 g_dir_engine_base = strdup(STT_GLOBAL_ENGINE_BASE);
487 g_dir_engine_info = strdup(STT_GLOBAL_ENGINE_INFO);
489 if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
490 LOGE("[ERROR] Fail to allocate memory");
491 if (NULL != g_dir_config_base) {
492 free(g_dir_config_base);
493 g_dir_config_base = NULL;
495 if (NULL != g_dir_home) {
499 if (NULL != g_dir_engine_base) {
500 free(g_dir_engine_base);
501 g_dir_engine_base = NULL;
503 if (NULL != g_dir_engine_info) {
504 free(g_dir_engine_info);
505 g_dir_engine_info = NULL;
512 if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid, g_gid)) {
513 LOGE("[ERROR] Fail to make engine info file");
519 /* Get user data by using libgum */
521 GumUserService *gus = NULL;
522 GumUserList *users = NULL;
523 GumUserList *iter = NULL;
524 GumUser *user = NULL;
526 GumUserType gumut = GUM_USERTYPE_NONE;
527 gchar *user_type = NULL;
531 gchar *home_dir = NULL;
533 gus = gum_user_service_create_sync(TRUE);
535 LOGE("Failed to create gum user service");
540 query = g_strsplit("admin,normal", ",", -1);
542 users = gum_user_service_get_user_list_sync(gus, (const gchar *const *)query);
546 LOGE("Failed to get gum user list");
553 /* Make new user list */
556 while (iter != NULL) {
557 user = (GumUser*) iter->data;
558 g_object_get(G_OBJECT(user), "uid", &uid, NULL);
559 if (NULL != home_dir) {
563 g_object_get(G_OBJECT(user), "gid", &gid, NULL);
564 g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
565 g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
566 user_type = g_strdup(gum_user_type_to_string(gumut));
567 if (NULL == user_type) {
568 gum_user_service_list_free(users);
574 LOGD("[DEBUG] user info");
575 if (NULL != home_dir) {
576 LOGD("[DEBUG] uid(%d), gid(%d), user_type(%s), home_dir(%s)", uid, gid, user_type, home_dir);
578 g_dir_config_base = (char*)calloc(strlen(home_dir) + 14, sizeof(char));
579 g_dir_home = (char*)calloc(strlen(home_dir) + 18, sizeof(char));
580 g_dir_engine_base = (char*)calloc(strlen(home_dir) + 22, sizeof(char));
581 g_dir_engine_info = (char*)calloc(strlen(home_dir) + 34, sizeof(char));
583 if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
584 LOGE("[ERROR] Fail to allocate memory");
585 if (NULL != g_dir_config_base) {
586 free(g_dir_config_base);
587 g_dir_config_base = NULL;
589 if (NULL != g_dir_home) {
593 if (NULL != g_dir_engine_base) {
594 free(g_dir_engine_base);
595 g_dir_engine_base = NULL;
597 if (NULL != g_dir_engine_info) {
598 free(g_dir_engine_info);
599 g_dir_engine_info = NULL;
601 gum_user_service_list_free(users);
606 snprintf(g_dir_config_base, strlen(home_dir) + 14, "%s/share/.voice", home_dir);
607 snprintf(g_dir_home, strlen(home_dir) + 18, "%s/share/.voice/stt", home_dir);
608 snprintf(g_dir_engine_base, strlen(home_dir) + 22, "%s/share/.voice/stt/1.0", home_dir);
609 snprintf(g_dir_engine_info, strlen(home_dir) + 34, "%s/share/.voice/stt/1.0/engine-info", home_dir);
611 LOGD("[DEBUG] g_dir_engine_info(%s)", g_dir_engine_info);
613 if (0 != __save_engine_info_xml(pkgid, user_type, uid, gid)) {
614 LOGE("[ERROR] Fail to make engine info file");
617 free(g_dir_config_base);
618 g_dir_config_base = NULL;
621 free(g_dir_engine_base);
622 g_dir_engine_base = NULL;
623 free(g_dir_engine_info);
624 g_dir_engine_info = NULL;
631 iter = g_list_next(iter);
633 iter = g_list_next(iter);
636 if (NULL != user_type) {
642 gum_user_service_list_free(users);
647 LOGD("[DEBUG] usertype: %s", g_user_type);
649 ret = tzplatform_set_user(g_uid);
651 LOGE("[ERROR] Invalid uid");
652 g_object_unref(g_guser);
657 LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
658 printf("[Parser Debug][DEBUG] TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
661 if (0 >= g_list_length(list)) {
662 LOGE("[ERROR] No Engine Metadata");
663 g_object_unref(g_guser);
669 if (0 != __write_metadata_inxml(pkgid, appid, list)) {
670 LOGE("[ERROR] Fail to write metadata in the xml");
672 g_object_unref(g_guser);
678 g_dir_config_base = strdup(STT_CONFIG_BASE);
679 g_dir_home = strdup(STT_HOME);
680 g_dir_engine_base = strdup(STT_ENGINE_BASE);
681 g_dir_engine_info = strdup(STT_ENGINE_INFO);
683 if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
684 LOGE("[ERROR] Fail to allocate memory");
685 if (NULL != g_dir_config_base) {
686 free(g_dir_config_base);
687 g_dir_config_base = NULL;
689 if (NULL != g_dir_home) {
693 if (NULL != g_dir_engine_base) {
694 free(g_dir_engine_base);
695 g_dir_engine_base = NULL;
697 if (NULL != g_dir_engine_info) {
698 free(g_dir_engine_info);
699 g_dir_engine_info = NULL;
702 g_object_unref(g_guser);
708 if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid, g_gid)) {
709 LOGE("[ERROR] Fail to make engine info file");
711 if (NULL != g_guser) {
712 g_object_unref(g_guser);
721 if (NULL != g_guser) {
722 g_object_unref(g_guser);
727 if (NULL != g_dir_config_base) {
728 free(g_dir_config_base);
729 g_dir_config_base = NULL;
731 if (NULL != g_dir_home) {
735 if (NULL != g_dir_engine_base) {
736 free(g_dir_engine_base);
737 g_dir_engine_base = NULL;
739 if (NULL != g_dir_engine_info) {
740 free(g_dir_engine_info);
741 g_dir_engine_info = NULL;
748 int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list)
750 LOGD("METADATA UNINSTALL");
751 LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
754 ret = pkgmgr_installer_info_get_target_uid(&g_uid);
756 LOGE("[ERROR] Fail to get target uid");
759 LOGD("uid(%d)", g_uid);
760 printf("[Parser Debug][DEBUG] uid(%d)", g_uid);
763 uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
764 if (globalapp_uid == g_uid) {
765 g_user_type = g_strdup("admin");
767 g_guser = gum_user_get_sync(g_uid, FALSE);
768 if (NULL == g_guser) {
769 LOGE("[ERROR] g_guser is NULL");
773 g_object_get(G_OBJECT(g_guser), "usertype", &g_ut, NULL);
774 g_user_type = g_strdup(gum_user_type_to_string(g_ut));
777 if (NULL == g_user_type) {
778 LOGE("[ERROR] Fail to allocate memory");
779 if (NULL != g_guser) {
780 g_object_unref(g_guser);
786 if (0 == strcmp(g_user_type, "none")) {
787 /* GUM_USERTYPE_NONE */
788 LOGE("[ERROR] Fail to get target uid");
789 g_object_unref(g_guser);
795 if (globalapp_uid == g_uid) {
796 /* global directory */
797 LOGD("[DEBUG] usertype: %s", g_user_type);
799 /* Remove files in /etc/skel/share/ */
800 g_dir_engine_info = strdup(STT_GLOBAL_ENGINE_INFO);
801 if (NULL == g_dir_engine_info) {
802 LOGE("[ERROR] Fail to allocate memory");
807 if (0 != __remove_engine_info_xml(pkgid, g_user_type, g_uid)) {
808 LOGE("[ERROR] Fail to remove engine info file");
811 /* Get user data by using libgum */
813 GumUserService *gus = NULL;
814 GumUserList *users = NULL;
815 GumUserList *iter = NULL;
816 GumUser *user = NULL;
818 GumUserType gumut = GUM_USERTYPE_NONE;
819 gchar *user_type = NULL;
822 gchar *home_dir = NULL;
824 GList *md_iter = NULL;
827 gus = gum_user_service_create_sync(TRUE);
829 LOGE("Failed to create gum user service");
834 query = g_strsplit("admin,normal", ",", -1);
836 users = gum_user_service_get_user_list_sync(gus, (const gchar *const *)query);
840 LOGE("Failed to get gum user list");
847 /* Make new user list */
850 while (iter != NULL) {
851 user = (GumUser*) iter->data;
852 g_object_get(G_OBJECT(user), "uid", &uid, NULL);
853 if (NULL != home_dir) {
857 g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
858 g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
859 user_type = g_strdup(gum_user_type_to_string(gumut));
860 if (NULL == user_type) {
861 gum_user_service_list_free(users);
867 if (NULL != home_dir) {
868 g_dir_engine_info = (char*)calloc(strlen(home_dir) + 34, sizeof(char));
869 if (NULL == g_dir_engine_info) {
870 gum_user_service_list_free(users);
876 snprintf(g_dir_engine_info, strlen(home_dir) + 34, "%s/share/.voice/stt/1.0/engine-info", home_dir);
878 md_iter = g_list_first(list);
879 while (NULL != md_iter) {
880 md = (metadata *)md_iter->data;
881 LOGD(" - key(%s) value(%s)", md->key, md->value);
882 md_iter = g_list_next(md_iter);
885 if (0 != __remove_engine_info_xml(pkgid, user_type, uid)) {
886 LOGE("[ERROR] Fail to remove engine info file");
892 free(g_dir_engine_info);
893 g_dir_engine_info = NULL;
897 LOGD("Finish release memory");
898 iter = g_list_next(iter);
899 LOGD("Finish next iter");
901 iter = g_list_next(iter);
905 gum_user_service_list_free(users);
910 LOGD("[DEBUG] usertype: %s", g_user_type);
912 ret = tzplatform_set_user(g_uid);
914 LOGE("[ERROR] Invalid uid");
915 g_object_unref(g_guser);
920 LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
921 printf("[Parser Debug][DEBUG] TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
924 g_dir_engine_info = strdup(STT_ENGINE_INFO);
925 if (NULL == g_dir_engine_info) {
926 LOGE("[ERROR] Fail to allocate memory");
927 g_object_unref(g_guser);
933 if (0 != __remove_engine_info_xml(pkgid, g_user_type, g_uid)) {
934 LOGE("[ERROR] Fail to remove engine info file");
939 if (NULL != g_guser) {
940 g_object_unref(g_guser);
945 if (NULL != g_dir_engine_info) {
946 free(g_dir_engine_info);
947 g_dir_engine_info = NULL;
955 int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list)
957 LOGD("METADATA UPGRADE");
958 LOGD("pkgid(%s) appid(%s) list(%d)", pkgid, appid, g_list_length(list));
960 PKGMGR_MDPARSER_PLUGIN_UNINSTALL(pkgid, appid, list);
961 PKGMGR_MDPARSER_PLUGIN_INSTALL(pkgid, appid, list);