2 * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
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.
23 #include <json-glib/json-glib.h>
24 #include <pkgmgr-info.h>
26 #include <tzplatform_config.h>
27 #include <package_manager.h>
29 #include <sys/types.h>
33 #include <linux/limits.h>
36 #define EXPORT_API __attribute__((visibility("default")))
42 #define LOG_TAG "STICKER_PARSER"
44 #define STICKER_DIRECTORY "/opt/usr/share/sticker-data"
45 #define STICKER_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_info(sticker_info_id INTEGER PRIMARY KEY AUTOINCREMENT, app_id TEXT NOT NULL, type INTEGER NOT NULL, uri TEXT NOT NULL, thumbnail TEXT, description TEXT, group_name TEXT NOT NULL, date TEXT NOT NULL, display_type INTEGER)"
46 #define STICKER_KEYWORD_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_keyword_info(keyword_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, keyword TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)"
47 #define STICKER_WHITELIST_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_whitelist_info(whitelist_id INTEGER PRIMARY KEY AUTOINCREMENT, provider_id TEXT NOT NULL, consumer_id TEXT NOT NULL)"
48 #define STICKER_RECENT_HISTORY_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_recent_history_info(history_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, count INTEGER NOT NULL, timestamp TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)"
51 #define MAX_ERROR_BUFFER 256
53 static char error_buffer[MAX_ERROR_BUFFER];
54 static gboolean is_corrupted = FALSE;
56 typedef struct metadata {
61 static char* __get_string_from_object(JsonObject *object, const char *key)
63 if (json_object_has_member(object, key) == false)
66 const char *str = json_object_get_string_member(object, key);
73 static int __get_int_from_object(JsonObject *object, const char *key)
75 if (json_object_has_member(object, key) == false)
78 int type = json_object_get_int_member(object, key);
83 static int __change_ownership(const char *path, int user, int group)
86 uid_t uid = (uid_t)user;
87 gid_t gid = (gid_t)group;
89 ret = chown(path, uid, gid);
91 strerror_r(errno, error_buffer, MAX_ERROR_BUFFER);
92 LOGE("chown() failed : %s", error_buffer);
98 static void __recover_db()
103 const char *db_path = tzplatform_mkpath(TZ_SYS_DB, ".sticker_info.db");
105 LOGD("Start to recover sticker db");
106 if (unlink(db_path) == -1)
107 LOGE("Failed to remove db file");
109 ret = sqlite3_open_v2(db_path, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
110 if (ret != SQLITE_OK) {
111 LOGE("Failed to open db : %s", sqlite3_errmsg(db));
112 if (unlink(db_path) == -1)
113 LOGE("Failed to remove db file");
117 ret = sqlite3_exec(db, STICKER_INFO_CREATE_TABLE, NULL, NULL, &err);
118 if (ret != SQLITE_OK) {
119 LOGE("Failed to create sticker_info table : %s" , err);
123 ret = sqlite3_exec(db, STICKER_KEYWORD_INFO_CREATE_TABLE, NULL, NULL, &err);
124 if (ret != SQLITE_OK) {
125 LOGE("Failed to create sticker_keyword_info table : %s", err);
129 ret = sqlite3_exec(db, STICKER_WHITELIST_INFO_CREATE_TABLE, NULL, NULL, &err);
130 if (ret != SQLITE_OK) {
131 LOGE("Failed to create sticker_whitelist_info table : %s", err);
135 ret = sqlite3_exec(db, STICKER_RECENT_HISTORY_INFO_CREATE_TABLE, NULL, NULL, &err);
136 if (ret != SQLITE_OK) {
137 LOGE("Failed to create sticker_recent_history_info table : %s", err);
141 is_corrupted = FALSE;
151 static int __integrity_check_cb(void *pid, int argc, char **argv, char **notUsed)
153 if (strcmp(argv[0], "ok") != 0) {
154 LOGE("DB integrity check failed : %s", argv[0]);
159 LOGD("Result integrity : %s", argv[0]);
163 static void __db_init()
168 const char *db_path = tzplatform_mkpath(TZ_SYS_DB, ".sticker_info.db");
170 ret = sqlite3_open_v2(db_path, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
171 if (ret != SQLITE_OK) {
172 LOGE("Failed to open db : %s", sqlite3_errmsg(db));
176 if (__change_ownership(db_path, UIFW_ID, UIFW_ID) != 0)
177 LOGE("failed to change ownership");
179 ret = sqlite3_exec(db, STICKER_INFO_CREATE_TABLE, NULL, NULL, &err);
180 if (ret != SQLITE_OK) {
181 LOGE("Failed to create sticker_info table : %s" , err);
185 ret = sqlite3_exec(db, STICKER_KEYWORD_INFO_CREATE_TABLE, NULL, NULL, &err);
186 if (ret != SQLITE_OK) {
187 LOGE("Failed to create sticker_keyword_info table : %s", err);
191 ret = sqlite3_exec(db, STICKER_WHITELIST_INFO_CREATE_TABLE, NULL, NULL, &err);
192 if (ret != SQLITE_OK) {
193 LOGE("Failed to create sticker_whitelist_info table : %s", err);
197 ret = sqlite3_exec(db, STICKER_RECENT_HISTORY_INFO_CREATE_TABLE, NULL, NULL, &err);
198 if (ret != SQLITE_OK) {
199 LOGE("Failed to create sticker_recent_history_info table : %s", err);
203 ret = sqlite3_exec(db, "PRAGMA journal_mode = WAL", NULL, NULL, &err);
204 if (ret != SQLITE_OK) {
205 LOGE("Failed to set journal_mode : %s", err);
209 ret = sqlite3_exec(db, "PRAGMA integrity_check", __integrity_check_cb, NULL, &err);
210 if (ret != SQLITE_OK)
211 LOGE("Failed to check integrity : %s", err);
220 if (ret == SQLITE_CORRUPT || ret == SQLITE_NOTADB || is_corrupted)
224 static sqlite3 *__db_open(const char *path)
230 ret = sqlite3_open(path, &db);
231 if (ret != SQLITE_OK) {
232 LOGE("Failed to open db : %s", sqlite3_errmsg(db));
236 ret = sqlite3_exec(db, "PRAGMA foreign_keys = ON", NULL, NULL, &err);
237 if (ret != SQLITE_OK) {
238 LOGE("Failed to turn on foreign keys : %s", err);
247 static int __remove_app_path(char *uri, const char *app_path)
251 for (int i = 0; uri[i] != '\0'; i++) {
252 if (uri[i] == app_path[n]) {
254 while (uri[i] == app_path[n]) {
255 if (app_path[++n] == '\0') {
256 for(; uri[k + n] != '\0'; k++) {
271 static int __mkdirs(const char *path, mode_t mode)
274 char prev_path[2048];
275 const char *tmp = path;
277 if (!path || strlen(path) > 2048)
280 memset(prev_path, '\0', 2048);
281 while ((tmp = strchr(tmp, '/')) != NULL) {
288 strncpy(prev_path, path, len);
289 prev_path[len] = 0x00;
291 if (mkdir(prev_path, mode) == -1) {
292 if (errno != EEXIST) {
293 strerror_r(errno, error_buffer, MAX_ERROR_BUFFER);
294 LOGE("directory create error : %s", error_buffer);
298 if (__change_ownership(prev_path, UIFW_ID, UIFW_ID) != 0)
299 LOGE("failed to change ownership");
303 if (mkdir(prev_path, mode) == -1) {
304 if (errno != EEXIST) {
305 strerror_r(errno, error_buffer, MAX_ERROR_BUFFER);
306 LOGE("directory create error : %s", error_buffer);
310 if (__change_ownership(prev_path, UIFW_ID, UIFW_ID) != 0)
311 LOGE("failed to change ownership");
316 static int __file_copy(const char *src, const char *dest)
319 int fd = -1, n_fd = -1;
324 memset(buf, '\0', 4096);
325 fd = open(src, O_RDONLY);
326 n_fd = open(dest, O_WRONLY | O_CREAT | O_TRUNC, 0755);
328 if (fd == -1 || n_fd == -1) {
334 while((size = read(fd, buf, 4096))) {
344 while(write(n_fd, buf, size) == -1) {
365 static char* __convert_sticker_uri(char *uri, const char *appid, const char *app_path)
368 char *copy_uri = (char *)calloc(PATH_MAX, sizeof(char));
369 if (copy_uri == NULL) {
370 LOGE("failed to allocate memory");
374 strncpy(copy_uri, uri, PATH_MAX - 1);
375 __remove_app_path(uri, app_path);
376 int len = strlen(STICKER_DIRECTORY) + strlen(appid) + strlen(uri) + 2;
377 char *new_path = (char *)calloc(len, sizeof(char));
378 if (new_path == NULL) {
379 LOGE("failed to allocate memory");
384 snprintf(new_path, len, "%s/%s%s",STICKER_DIRECTORY, appid, uri);
386 if (access(new_path, F_OK) == 0) {
387 LOGE("sticker file already exists");
392 ret = __mkdirs(new_path, 0755);
394 LOGE("directory create error");
398 if (__file_copy(copy_uri, new_path) == -1) {
399 strerror_r(errno, error_buffer, MAX_ERROR_BUFFER);
400 LOGE("failed to copy sticker file : %s", error_buffer);
405 ret = unlink(copy_uri);
407 strerror_r(errno, error_buffer, MAX_ERROR_BUFFER);
408 LOGE("failed to remove sticker file : %s", error_buffer);
411 if (__change_ownership(new_path, UIFW_ID, UIFW_ID) != 0)
412 LOGE("failed to change ownership");
429 static void __insert_sticker_info(const char *app_id, int type, const char *uri, const char *group, const char *thumbnail, const char *description, int disp_type)
433 sqlite3_stmt *stmt = NULL;
436 db_path = tzplatform_mkpath(TZ_SYS_DB, ".sticker_info.db");
437 db = __db_open(db_path);
441 ret = sqlite3_prepare_v2(db, "INSERT INTO sticker_info (app_id, type, uri, thumbnail, description, group_name, date, display_type) VALUES (?, ?, ?, ?, ?, ?, DateTime('now','localtime'), ?)",-1, &stmt, NULL);
442 if (ret == SQLITE_OK) {
443 sqlite3_bind_text(stmt, 1, app_id, -1, SQLITE_TRANSIENT);
444 sqlite3_bind_int(stmt, 2, type);
445 sqlite3_bind_text(stmt, 3, uri, -1, SQLITE_TRANSIENT);
446 sqlite3_bind_text(stmt, 4, thumbnail, -1, SQLITE_TRANSIENT);
447 sqlite3_bind_text(stmt, 5, description, -1, SQLITE_TRANSIENT);
448 sqlite3_bind_text(stmt, 6, group, -1, SQLITE_TRANSIENT);
449 sqlite3_bind_int(stmt, 7, disp_type);
451 ret = sqlite3_step(stmt);
452 if (ret != SQLITE_OK && ret != SQLITE_DONE)
453 LOGE("sqlite3_step() failed : ret(%d)", ret);
455 if (sqlite3_changes(db) == 0)
456 LOGE("No changes to DB");
458 sqlite3_finalize(stmt);
461 LOGE("failed to insert sticker information : %s", sqlite3_errmsg(db));
462 sqlite3_finalize(stmt);
469 static void __insert_sticker_keyword_info(const char *keyword)
474 sqlite3_stmt *stmt = NULL;
477 db_path = tzplatform_mkpath(TZ_SYS_DB, ".sticker_info.db");
478 db = __db_open(db_path);
482 ret = sqlite3_prepare_v2(db, "SELECT sticker_info_id FROM sticker_info ORDER BY sticker_info_id DESC LIMIT 1", -1, &stmt, NULL);
483 if (ret == SQLITE_OK) {
484 ret = sqlite3_step(stmt);
485 if (ret == SQLITE_ERROR) {
486 LOGE("sqlite3_step() failed : ret(%d)", ret);
487 sqlite3_finalize(stmt);
490 record_id = sqlite3_column_int(stmt, 0);
492 sqlite3_finalize(stmt);
495 ret = sqlite3_prepare_v2(db, "INSERT INTO sticker_keyword_info (sticker_info_id, keyword) VALUES (?, ?)", -1, &stmt, NULL);
496 if (ret == SQLITE_OK) {
497 sqlite3_bind_int(stmt, 1, record_id);
498 sqlite3_bind_text(stmt, 2, keyword, -1, SQLITE_TRANSIENT);
500 ret = sqlite3_step(stmt);
501 if (ret != SQLITE_OK && ret != SQLITE_DONE)
502 LOGE("sqlite3_step() failed : ret(%d)", ret);
504 if (sqlite3_changes(db) == 0)
505 LOGE("No changes to DB");
507 sqlite3_finalize(stmt);
510 LOGE("fail to insert sticker keyword : %s", sqlite3_errmsg(db));
511 sqlite3_finalize(stmt);
516 LOGE("fail to insert sticker information : %s", sqlite3_errmsg(db));
517 sqlite3_finalize(stmt);
524 static void __insert_sticker_allowlist_info(const char *provider, const char *consumer) {
527 sqlite3_stmt *stmt = NULL;
530 db_path = tzplatform_mkpath(TZ_SYS_DB, ".sticker_info.db");
531 db = __db_open(db_path);
535 ret = sqlite3_prepare_v2(db, "INSERT INTO sticker_whitelist_info (provider_id, consumer_id) VALUES (?, ?)", -1, &stmt, NULL);
536 if (ret == SQLITE_OK) {
537 sqlite3_bind_text(stmt, 1, provider, -1, SQLITE_TRANSIENT);
538 sqlite3_bind_text(stmt, 2, consumer, -1, SQLITE_TRANSIENT);
540 ret = sqlite3_step(stmt);
541 if (ret != SQLITE_OK && ret != SQLITE_DONE)
542 LOGE("sqlite3_step() failed : ret(%d)", ret);
544 if (sqlite3_changes(db) == 0)
545 LOGE("No changes to DB");
547 sqlite3_finalize(stmt);
550 LOGE("fail to insert sticker allowlist : %s", sqlite3_errmsg(db));
551 sqlite3_finalize(stmt);
558 static int __get_sticker_info_from_json(const char *appid, const char *file_path, const char *app_path)
562 JsonParser* parser = NULL;
563 GError* err_msg = NULL;
566 char *description = NULL;
567 char *thumbnail_path = NULL;
568 char *uri_path = NULL;
570 parser = json_parser_new();
571 json_parser_load_from_file(parser, file_path, &err_msg);
573 LOGE("failed to load json file. error message: %s", err_msg->message);
578 JsonNode *root = json_parser_get_root(parser);
580 LOGE("failed to get root");
585 JsonObject *root_obj = json_node_get_object(root);
586 if (root_obj == NULL) {
587 LOGE("failed to get object");
592 JsonArray *allowlist_arr = json_object_get_array_member(root_obj, "whitelist");
593 if (allowlist_arr != NULL) {
594 for (int i = 0; i < json_array_get_length(allowlist_arr); i++) {
595 __insert_sticker_allowlist_info(appid, json_array_get_string_element(allowlist_arr, i));
599 JsonArray *sticker_arr = json_object_get_array_member(root_obj, "sticker");
600 if (sticker_arr == NULL) {
601 LOGE("failed to get array member");
606 arr_len = json_array_get_length(sticker_arr);
607 for (int i = 0; i < arr_len; i++) {
608 JsonObject *info_object = json_array_get_object_element(sticker_arr, i);
609 if (info_object != NULL) {
610 int type = __get_int_from_object(info_object, "type");
614 uri = __get_string_from_object(info_object, "uri");
618 group = __get_string_from_object(info_object, "group");
622 char *rel_thumbnail = __get_string_from_object(info_object, "thumbnail");
623 if (rel_thumbnail && rel_thumbnail[0] != '\0') {
624 if (access(rel_thumbnail, F_OK) == 0) {
625 thumbnail_path = __convert_sticker_uri(rel_thumbnail, appid, app_path);
627 int len = strlen(app_path) + strlen(rel_thumbnail) + 2;
628 char *new_thumbnail_path = (char *)calloc(len, sizeof(char));
629 if (new_thumbnail_path) {
630 if (rel_thumbnail[0] == '/')
631 snprintf(new_thumbnail_path, len, "%s%s",app_path, rel_thumbnail);
633 snprintf(new_thumbnail_path, len, "%s%s%s",app_path, "/", rel_thumbnail);
635 if (access(new_thumbnail_path, F_OK) == 0)
636 thumbnail_path = __convert_sticker_uri(new_thumbnail_path, appid, app_path);
638 free(new_thumbnail_path);
639 new_thumbnail_path = NULL;
645 description = __get_string_from_object(info_object, "description");
646 int disp_type = __get_int_from_object(info_object, "display_type");
648 JsonArray *keyword_arr = json_object_get_array_member(info_object, "keyword");
649 int keyword_arr_len = json_array_get_length(keyword_arr);
650 if (keyword_arr_len < 1)
654 if (access(uri, F_OK) == 0) {
655 char *new_uri = __convert_sticker_uri(uri, appid, app_path);
658 __insert_sticker_info(appid, type, new_uri, group, thumbnail_path, description, disp_type);
665 int path_len = strlen(app_path) + strlen(uri) + 2;
666 uri_path = (char *)calloc(path_len, sizeof(char));
668 LOGE("failed to alloc memory");
673 snprintf(uri_path, path_len, "%s%s",app_path, uri);
675 snprintf(uri_path, path_len, "%s%s%s",app_path, "/", uri);
677 if (access(uri_path, F_OK) == 0) {
678 char *new_uri = __convert_sticker_uri(uri_path, appid, app_path);
684 __insert_sticker_info(appid, type, new_uri, group, thumbnail_path, description, disp_type);
692 LOGE("%s does not exist", uri_path);
699 __insert_sticker_info(appid, type, uri, group, thumbnail_path, description, disp_type);
702 for (int j = 0; j < keyword_arr_len; j++) {
703 __insert_sticker_keyword_info(json_array_get_string_element(keyword_arr, j));
717 if (thumbnail_path) {
718 free(thumbnail_path);
719 thumbnail_path = NULL;
731 g_error_free(err_msg);
734 g_object_unref(parser);
739 static void __delete_sticker_allowlist(const char *db_path, const char *app_id)
743 sqlite3_stmt *stmt = NULL;
745 db = __db_open(db_path);
749 ret = sqlite3_prepare_v2(db, "DELETE FROM sticker_whitelist_info WHERE provider_id = ?", -1, &stmt, NULL);
750 if (ret != SQLITE_OK) {
751 LOGE("failed to delete sticker allowlist : %s", sqlite3_errmsg(db));
752 sqlite3_finalize(stmt);
757 sqlite3_bind_text(stmt, 1, app_id, -1, SQLITE_TRANSIENT);
759 ret = sqlite3_step(stmt);
760 if (ret != SQLITE_OK && ret != SQLITE_DONE) {
761 LOGE("sqlite3_step() failed : ret(%d)", ret);
765 if (sqlite3_changes(db) == 0) {
766 LOGE("No changes to DB");
770 sqlite3_finalize(stmt);
775 sqlite3_finalize(stmt);
780 static void __delete_sticker_info(const char *db_path, int record_id)
784 sqlite3_stmt *stmt = NULL;
786 db = __db_open(db_path);
790 ret = sqlite3_prepare_v2(db, "DELETE FROM sticker_info WHERE sticker_info_id = ?", -1, &stmt, NULL);
791 if (ret != SQLITE_OK) {
792 LOGE("failed to delete sticker information : %s", sqlite3_errmsg(db));
793 sqlite3_finalize(stmt);
798 sqlite3_bind_int(stmt, 1, record_id);
800 ret = sqlite3_step(stmt);
801 if (ret != SQLITE_OK && ret != SQLITE_DONE) {
802 LOGE("sqlite3_step() failed : ret(%d)", ret);
806 if (sqlite3_changes(db) == 0) {
807 LOGE("No changes to DB");
811 sqlite3_finalize(stmt);
816 sqlite3_finalize(stmt);
821 static int __remove_directory(const char *path, int is_error_stop)
824 struct dirent *file = NULL;
828 memset(filename, '\0', 1024);
830 if (__change_ownership(path, APPFW_ID, APPFW_ID) != 0)
831 LOGE("failed to change ownership");
833 dir_ptr = opendir(path);
837 while ((file = readdir(dir_ptr)) != NULL) {
838 if (strcmp(file->d_name, ".") == 0 || strcmp(file->d_name, "..") == 0)
841 snprintf(filename, strlen(path) + strlen(file->d_name) + 2, "%s/%s", path, file->d_name);
843 if (lstat(filename, &buf) == -1)
846 if (S_ISDIR(buf.st_mode)) {
847 if (__remove_directory(filename, is_error_stop) == -1 && is_error_stop) {
851 } else if (S_ISREG(buf.st_mode) || S_ISLNK(buf.st_mode)) {
852 if (unlink(filename) == -1 && is_error_stop) {
864 int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
866 LOGD("METADATA INSTALL");
867 LOGD("pkgid: %s, appid: %s", pkgid, appid);
869 metadata *md = (metadata *)list->data;
870 package_info_h package_info = NULL;
871 char *app_path = NULL;
872 char *file_path = NULL;
877 ret = package_info_create(pkgid, &package_info);
878 if (ret != PACKAGE_MANAGER_ERROR_NONE || package_info == NULL) {
879 LOGE("failed to create package_info. ret: %d", ret);
883 ret = package_info_get_root_path(package_info, &app_path);
884 if (ret != PACKAGE_MANAGER_ERROR_NONE || app_path == NULL) {
885 LOGE("failed to create package_info. ret: %d", ret);
889 int path_len = strlen(app_path) + strlen((char *)md->value) + 2;
890 file_path = (char *)calloc(path_len, sizeof(char));
892 LOGE("failed to alloc memory");
896 if ((char)md->value[0] == '/')
897 snprintf(file_path, path_len, "%s%s",app_path, (char *)md->value);
899 snprintf(file_path, path_len, "%s%s%s",app_path, "/", (char *)md->value);
901 if (__get_sticker_info_from_json(appid, file_path, app_path) == 0)
902 LOGE("failed to get sticker information [path : %s]", file_path);
906 package_info_destroy(package_info);
922 int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list)
924 LOGD("METADATA UNINSTALL");
925 LOGD("pkgid: %s, appid: %s", pkgid, appid);
930 sqlite3_stmt *stmt = NULL;
932 GList *id_list = NULL;
934 db_path = tzplatform_mkpath(TZ_SYS_DB, ".sticker_info.db");
935 db = __db_open(db_path);
939 ret = sqlite3_prepare_v2(db, "SELECT sticker_info_id from sticker_info WHERE app_id = ?", -1, &stmt, NULL);
940 if (ret == SQLITE_OK) {
941 sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT);
942 while (sqlite3_step(stmt) == SQLITE_ROW) {
943 const unsigned char *record_id = sqlite3_column_text(stmt, 0);
945 id_list = g_list_append(id_list, strdup((const char *)record_id));
948 sqlite3_finalize(stmt);
951 for(GList *tmp = g_list_first(id_list); tmp != NULL; tmp = tmp->next) {
952 del_id = atoi((const char*)tmp->data);
953 __delete_sticker_info(db_path, del_id);
957 g_list_free_full(id_list, free);
959 LOGE("failed to get sticker id");
960 sqlite3_finalize(stmt);
964 __delete_sticker_allowlist(db_path, appid);
970 int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list)
972 LOGD("METADATA UPGRADE");
973 LOGD("pkgid: %s, appid: %s", pkgid, appid);
975 PKGMGR_MDPARSER_PLUGIN_UNINSTALL(pkgid, appid, list);
976 PKGMGR_MDPARSER_PLUGIN_INSTALL(pkgid, appid, list);
981 int PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
983 LOGD("STICKER CATEGORY INSTALL");
984 LOGD("pkgid: %s, appid: %s", pkgid, appid);
986 int len = strlen(STICKER_DIRECTORY) + strlen(appid) + 2;
987 char *dir_path = (char *)calloc(len, sizeof(char));
989 if (dir_path != NULL) {
990 snprintf(dir_path, len, "%s%s%s", STICKER_DIRECTORY, "/", appid);
991 LOGD("directory path : %s", dir_path);
993 if (mkdir(dir_path, 0755) == -1 && errno != EEXIST) {
994 strerror_r(errno, error_buffer, MAX_ERROR_BUFFER);
995 LOGE("directory create error : %s", error_buffer);
997 if (__change_ownership(dir_path, UIFW_ID, UIFW_ID) != 0)
998 LOGE("failed to change ownership");
1009 int PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list)
1011 LOGD("STICKER CATEGORY UNINSTALL");
1012 LOGD("pkgid: %s, appid: %s", pkgid, appid);
1014 int len = strlen(STICKER_DIRECTORY) + strlen(appid) + 2;
1015 char * dir_path = (char *)calloc(len, sizeof(char));
1017 if (dir_path != NULL) {
1018 snprintf(dir_path, len, "%s%s%s", STICKER_DIRECTORY, "/", appid);
1019 LOGD("directory path : %s", dir_path);
1021 if (__remove_directory(dir_path, 0) < 0) {
1022 strerror_r(errno, error_buffer, MAX_ERROR_BUFFER);
1023 LOGE("directory remove error : %s", error_buffer);
1034 int PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list)
1036 LOGD("STICKER CATEGORY UPGRADE");
1037 LOGD("pkgid: %s, appid: %s", pkgid, appid);
1039 PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL(pkgid, appid, list);
1040 PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL(pkgid, appid, list);