2 * Copyright (c) 2000 - 2017 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.
22 #include <sys/types.h>
24 #include <sys/smack.h>
25 #include <linux/limits.h>
32 #include <tzplatform_config.h>
33 #include <system_info.h>
35 #include "pkgmgr-info.h"
36 #include "pkgmgrinfo_basic.h"
37 #include "pkgmgr_parser.h"
38 #include "pkgmgr_parser_db_queries.h"
39 #include "pkgmgr_parser_debug.h"
40 #include "pkgmgr_parser_internal.h"
46 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
49 #define APPFW_USER "app_fw"
58 #define XXHDPI "xxhdpi"
68 #define XXHDPI_MIN 481
69 #define XXHDPI_MAX 600
71 /* app background category value */
72 #define APP_BG_CATEGORY_USER_DISABLE_FALSE_VAL 0x00000
73 #define APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL 0x00001
74 #define APP_BG_CATEGORY_MEDIA_VAL 0x00002
75 #define APP_BG_CATEGORY_DOWNLOAD_VAL 0x00004
76 #define APP_BG_CATEGORY_BGNETWORK_VAL 0x00008
77 #define APP_BG_CATEGORY_LOCATION_VAL 0x00010
78 #define APP_BG_CATEGORY_SENSOR_VAL 0x00020
79 #define APP_BG_CATEGORY_IOTCOMM_VAL 0x00040
80 #define APP_BG_CATEGORY_SYSTEM_VAL 0x00080
82 #define APP_BG_CATEGORY_USER_DISABLE_FALSE_STR "enable"
83 #define APP_BG_CATEGORY_USER_DISABLE_TRUE_STR "disable"
84 #define APP_BG_CATEGORY_MEDIA_STR "media"
85 #define APP_BG_CATEGORY_DOWNLOAD_STR "download"
86 #define APP_BG_CATEGORY_BGNETWORK_STR "background-network"
87 #define APP_BG_CATEGORY_LOCATION_STR "location"
88 #define APP_BG_CATEGORY_SENSOR_STR "sensor"
89 #define APP_BG_CATEGORY_IOTCOMM_STR "iot-communication"
90 #define APP_BG_CATEGORY_SYSTEM "system"
92 #define REGULAR_USER 5000
93 static inline uid_t __getuid(void)
97 if (uid < REGULAR_USER)
98 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
103 static const char *__get_bool(char *value, bool is_true)
106 if (!strcmp(value, ""))
107 return (is_true) ? "true" : "false";
111 return (is_true) ? "true" : "false";
114 #define __BEGIN_TRANSACTION(db) \
116 if (sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, NULL) != \
118 _LOGE("begin transaction failed: %s", sqlite3_errmsg(db)); \
119 sqlite3_close_v2(db); \
120 return PM_PARSER_R_ERROR; \
124 #define __DO_TRANSACTION(db, func) \
127 _LOGE("transaction failed: %s, rollback", sqlite3_errmsg(db)); \
128 if (sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL) != \
130 _LOGE("roll back transaction failed: %s", \
131 sqlite3_errmsg(db)); \
132 sqlite3_close_v2(db); \
133 return PM_PARSER_R_ERROR; \
137 #define __END_TRANSACTION(db) \
139 if (sqlite3_exec(db, "COMMIT", NULL, NULL, NULL) != \
141 _LOGE("commit failed: %s, rollback", sqlite3_errmsg(db)); \
142 if (sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL) != \
144 _LOGE("roll back transaction failed: %s", \
145 sqlite3_errmsg(db)); \
146 sqlite3_close_v2(db); \
147 return PM_PARSER_R_ERROR; \
151 #define __BIND_TEXT(db, stmt, i, text) \
153 if (sqlite3_bind_text(stmt, i, text, -1, SQLITE_STATIC) != SQLITE_OK) {\
154 _LOGE("bind error(index %d): %s", i, sqlite3_errmsg(db)); \
155 sqlite3_finalize(stmt); \
160 #define __BIND_INT(db, stmt, i, int) \
162 if (sqlite3_bind_int(stmt, i, int) != SQLITE_OK) { \
163 _LOGE("bind error(index %d): %s", i, sqlite3_errmsg(db)); \
164 sqlite3_finalize(stmt); \
169 static const char *__get_parser_db_path(uid_t uid)
174 if (uid == GLOBAL_USER || uid == OWNER_ROOT) {
175 path = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
177 snprintf(buf, sizeof(buf), "user/%d/.pkgmgr_parser.db", uid);
178 path = tzplatform_mkpath(TZ_SYS_DB, buf);
184 static const char *__get_cert_db_path(void)
186 return tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
189 static int __set_db_version(sqlite3 *db)
191 static const char query_raw[] = "PRAGMA user_version=";
196 version = atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 +
197 atoi(TIZEN_PATCH_VER);
198 snprintf(query, sizeof(query), "%s%d", query_raw, version);
200 ret = sqlite3_exec(db, query, NULL, NULL, NULL);
201 if (ret != SQLITE_OK) {
202 _LOGE("exec failed: %s", sqlite3_errmsg(db));
209 /* TODO: Do not labeling directly */
210 #define DB_LABEL "User::Home"
211 #define SET_SMACK_LABEL(x) \
213 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
214 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
216 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
219 static int __set_db_permission(const char *path, uid_t uid)
222 const char *files[2];
223 char journal_file[BUFSIZE];
227 struct passwd *result;
232 if (getuid() != OWNER_ROOT)
235 if (uid == OWNER_ROOT || uid == GLOBAL_USER) {
236 ret = getpwnam_r(APPFW_USER, &pwd, buf, sizeof(buf), &result);
237 if (result == NULL) {
239 _LOGE("no such user: %d", uid);
241 _LOGE("getpwuid_r failed: %d", errno);
247 snprintf(journal_file, sizeof(journal_file), "%s-journal", path);
249 files[1] = journal_file;
251 ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &result);
252 if (result == NULL) {
254 _LOGE("no such user: %d", uid);
256 _LOGE("getpwuid_r failed: %d", errno);
260 for (i = 0; i < 2; i++) {
261 fd = open(files[i], O_RDONLY);
263 _LOGE("open %s failed: %d", files[i], errno);
266 ret = fstat(fd, &sb);
268 _LOGE("stat %s failed: %d", files[i], errno);
272 if (S_ISLNK(sb.st_mode)) {
273 _LOGE("%s is symlink!", files[i]);
277 ret = fchown(fd, uid, pwd.pw_gid);
279 _LOGE("fchown %s failed: %d", files[i], errno);
284 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
285 if (!strcmp(path, __get_cert_db_path()))
287 ret = fchmod(fd, mode);
289 _LOGD("fchmod %s failed: %d", files[i], errno);
294 SET_SMACK_LABEL(files[i]);
300 static const char *parser_init_queries[] = {
301 QUERY_CREATE_TABLE_PACKAGE_INFO,
302 QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO,
303 QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO,
304 QUERY_CREATE_TABLE_PACKAGE_APP_INFO,
305 QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO,
306 QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO, /* ? */
307 QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO, /* ? */
308 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL,
309 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY,
310 QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA,
311 QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION, /* ? */
312 QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED, /* ? */
313 QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST, /* ? */
314 QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL,
315 QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID,
316 QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID,
317 QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN,
321 static const char *cert_init_queries[] = {
322 QUERY_CREATE_TABLE_PACKAGE_CERT_INFO,
323 QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO,
324 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO,
325 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2,
326 QUERY_CREATE_TRIGGER_DELETE_CERT_INFO,
327 QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO,
331 static int __initialize_db(sqlite3 *db, const char *dbpath, uid_t uid)
334 const char **queries;
337 if (__set_db_version(db))
340 if (strstr(dbpath, ".pkgmgr_parser.db")) {
341 queries = parser_init_queries;
342 } else if (strstr(dbpath, ".pkgmgr_cert.db")) {
343 queries = cert_init_queries;
345 _LOGE("unexpected dbpath: %s", dbpath);
349 for (i = 0; queries[i] != NULL; i++) {
350 ret = sqlite3_exec(db, queries[i], NULL, NULL, NULL);
351 if (ret != SQLITE_OK) {
352 _LOGE("exec failed: %s", sqlite3_errmsg(db));
357 if (__set_db_permission(dbpath, uid))
358 _LOGE("failed to set db permission");
363 API int pkgmgr_parser_initialize_parser_db(uid_t uid)
369 dbpath = __get_parser_db_path(uid);
370 if (access(dbpath, F_OK) != -1) {
371 _LOGE("Manifest db for user %d is already exists", uid);
372 return PM_PARSER_R_ERROR;
375 ret = sqlite3_open_v2(dbpath, &db,
376 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
377 if (ret != SQLITE_OK) {
378 _LOGE("open db failed: %d", ret);
379 return PM_PARSER_R_ERROR;
382 if (__initialize_db(db, dbpath, uid)) {
383 sqlite3_close_v2(db);
384 return PM_PARSER_R_ERROR;
386 sqlite3_close_v2(db);
388 return PM_PARSER_R_OK;
391 API int pkgmgr_parser_initialize_cert_db(void)
397 dbpath = __get_cert_db_path();
398 if (access(dbpath, F_OK) != -1) {
399 _LOGE("Cert db is already exists");
400 return PM_PARSER_R_ERROR;
403 ret = sqlite3_open_v2(dbpath, &db,
404 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
405 if (ret != SQLITE_OK) {
406 _LOGE("open db failed: %d", ret);
407 return PM_PARSER_R_ERROR;
410 if (__initialize_db(db, dbpath, GLOBAL_USER)) {
411 sqlite3_close_v2(db);
412 return PM_PARSER_R_ERROR;
414 sqlite3_close_v2(db);
416 return PM_PARSER_R_OK;
419 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
423 struct passwd *result;
426 ret = getpwnam_r(APPFW_USER, &pwd, buf, sizeof(buf), &result);
427 if (result == NULL) {
429 _LOGE("no such user: %s", APPFW_USER);
431 _LOGE("getpwnam_r failed: %d", errno);
432 return PM_PARSER_R_ERROR;
435 if (getuid() != OWNER_ROOT && getuid() != pwd.pw_uid) {
436 _LOGE("Only root or app_fw user is allowed");
437 return PM_PARSER_R_EINVAL;
440 if (pkgmgr_parser_initialize_parser_db(uid))
441 return PM_PARSER_R_ERROR;
443 if (pkgmgr_parser_initialize_cert_db())
444 return PM_PARSER_R_ERROR;
446 return PM_PARSER_R_OK;
449 #define BUSY_WAITING_USEC (1000000 / 10 / 2) /* 0.05 sec */
450 #define BUSY_WAITING_MAX 20 /* wait for max 1 sec */
451 static int __db_busy_handler(void *data, int count)
453 if (count < BUSY_WAITING_MAX) {
454 usleep(BUSY_WAITING_USEC);
457 /* sqlite3_prepare_v2 will return SQLITE_BUSY */
462 static int __open_db(uid_t uid, const char *path, sqlite3 **db, int flags)
466 /* FIXME: always open with OPEN_CREATE flag for keeping previous
469 if (flags & SQLITE_OPEN_READWRITE)
470 flags = flags | SQLITE_OPEN_CREATE;
472 ret = sqlite3_open_v2(path, db, flags, NULL);
473 if (ret != SQLITE_OK)
476 if (flags & SQLITE_OPEN_CREATE) {
477 ret = __initialize_db(*db, path, uid);
479 _LOGE("failed to initialize db: %s\n");
480 sqlite3_close_v2(*db);
485 ret = sqlite3_exec(*db, "PRAGMA foreign_keys=ON", NULL, NULL, NULL);
486 if (ret != SQLITE_OK) {
487 _LOGE("failed to enable foreign key support: %s",
488 sqlite3_errmsg(*db));
489 sqlite3_close_v2(*db);
493 ret = sqlite3_busy_handler(*db, __db_busy_handler, NULL);
494 if (ret != SQLITE_OK) {
495 _LOGE("failed to register busy handler: %s",
496 sqlite3_errmsg(*db));
497 sqlite3_close_v2(*db);
505 static int __convert_background_category(GList *category_list)
511 if (category_list == NULL)
514 for (tmp = category_list; tmp; tmp = tmp->next) {
515 category_data = (char *)tmp->data;
516 if (category_data == NULL)
518 if (!strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR))
519 ret |= APP_BG_CATEGORY_MEDIA_VAL;
520 else if (!strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR))
521 ret |= APP_BG_CATEGORY_DOWNLOAD_VAL;
522 else if (!strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR))
523 ret |= APP_BG_CATEGORY_BGNETWORK_VAL;
524 else if (!strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR))
525 ret |= APP_BG_CATEGORY_LOCATION_VAL;
526 else if (!strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR))
527 ret |= APP_BG_CATEGORY_SENSOR_VAL;
528 else if (!strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR))
529 ret |= APP_BG_CATEGORY_IOTCOMM_VAL;
530 else if (!strcmp(category_data, APP_BG_CATEGORY_SYSTEM))
531 ret |= APP_BG_CATEGORY_SYSTEM_VAL;
533 _LOGE("Unidentified category [%s]", category_data);
539 #define EFFECTIVE_APPID_KEY "http://tizen.org/metadata/effective-appid"
540 static const char *__find_effective_appid(GList *metadata_list)
545 for (tmp = metadata_list; tmp; tmp = tmp->next) {
546 md = (metadata_x *)tmp->data;
547 if (md == NULL || md->key == NULL)
550 if (strcmp(md->key, EFFECTIVE_APPID_KEY) == 0) {
559 static int __insert_appcontrol_info(sqlite3 *db, application_x *app)
561 static const char query[] =
562 "INSERT INTO package_app_app_control (app_id, app_control) "
567 char app_control[BUFSIZE];
571 if (app->appcontrol == NULL)
574 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
575 if (ret != SQLITE_OK) {
576 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
580 for (tmp = app->appcontrol; tmp; tmp = tmp->next) {
581 ac = (appcontrol_x *)tmp->data;
585 snprintf(app_control, sizeof(app_control), "%s|%s|%s",
586 ac->operation ? (strlen(ac->operation) > 0 ?
587 ac->operation : "NULL") : "NULL",
588 ac->uri ? (strlen(ac->uri) > 0 ?
589 ac->uri : "NULL") : "NULL",
590 ac->mime ? (strlen(ac->mime) > 0 ?
591 ac->mime : "NULL") : "NULL");
592 __BIND_TEXT(db, stmt, idx++, app->appid);
593 __BIND_TEXT(db, stmt, idx++, app_control);
595 ret = sqlite3_step(stmt);
596 if (ret != SQLITE_DONE) {
597 _LOGE("step failed: %s", sqlite3_errmsg(db));
598 sqlite3_finalize(stmt);
605 sqlite3_finalize(stmt);
610 static int __insert_category_info(sqlite3 *db, application_x *app)
612 static const char query[] =
613 "INSERT INTO package_app_app_category (app_id, category) "
619 const char *category;
621 if (app->category == NULL)
624 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
625 if (ret != SQLITE_OK) {
626 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
630 for (tmp = app->category; tmp; tmp = tmp->next) {
631 category = (const char *)tmp->data;
632 if (category == NULL)
635 __BIND_TEXT(db, stmt, idx++, app->appid);
636 __BIND_TEXT(db, stmt, idx++, category);
638 ret = sqlite3_step(stmt);
639 if (ret != SQLITE_DONE) {
640 _LOGE("step failed: %s", sqlite3_errmsg(db));
641 sqlite3_finalize(stmt);
648 sqlite3_finalize(stmt);
653 static int __insert_metadata_info(sqlite3 *db, application_x *app)
655 static const char query[] =
656 "INSERT INTO package_app_app_metadata (app_id,"
657 " md_key, md_value) VALUES (?, ?, ?)";
664 if (app->metadata == NULL)
667 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
668 if (ret != SQLITE_OK) {
669 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
673 for (tmp = app->metadata; tmp; tmp = tmp->next) {
674 md = (metadata_x *)tmp->data;
678 __BIND_TEXT(db, stmt, idx++, app->appid);
679 __BIND_TEXT(db, stmt, idx++, md->key);
680 __BIND_TEXT(db, stmt, idx++, md->value);
682 ret = sqlite3_step(stmt);
683 if (ret != SQLITE_DONE) {
684 _LOGE("step failed: %s", sqlite3_errmsg(db));
685 sqlite3_finalize(stmt);
692 sqlite3_finalize(stmt);
697 static int __insert_datacontrol_info(sqlite3 *db, application_x *app)
699 static const char query[] =
700 "INSERT INTO package_app_data_control (app_id, providerid,"
701 " access, type, trusted) VALUES (?, ?, ?, ?, ?)";
708 if (app->datacontrol == NULL)
711 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
712 if (ret != SQLITE_OK) {
713 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
717 for (tmp = app->datacontrol; tmp; tmp = tmp->next) {
718 dc = (datacontrol_x *)tmp->data;
722 __BIND_TEXT(db, stmt, idx++, app->appid);
723 __BIND_TEXT(db, stmt, idx++, dc->providerid);
724 __BIND_TEXT(db, stmt, idx++, dc->access);
725 __BIND_TEXT(db, stmt, idx++, dc->type);
726 __BIND_TEXT(db, stmt, idx++, dc->trusted);
728 ret = sqlite3_step(stmt);
729 if (ret != SQLITE_DONE) {
730 _LOGE("step failed: %s", sqlite3_errmsg(db));
731 sqlite3_finalize(stmt);
738 sqlite3_finalize(stmt);
743 /* TODO: move to installer */
744 static int __check_dpi(const char *dpi_char, int dpi_int)
746 if (dpi_char == NULL)
749 if (strcasecmp(dpi_char, LDPI) == 0) {
750 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
754 } else if (strcasecmp(dpi_char, MDPI) == 0) {
755 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
759 } else if (strcasecmp(dpi_char, HDPI) == 0) {
760 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
764 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
765 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
769 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
770 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
778 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a,
781 splashscreen_x *ss = (splashscreen_x *)a;
782 const char *orientation = (const char *)b;
786 if (ss->operation || ss->dpi == NULL)
789 ret = system_info_get_platform_int(
790 "http://tizen.org/feature/screen.dpi", &dpi);
791 if (ret != SYSTEM_INFO_ERROR_NONE)
794 if (strcasecmp(ss->orientation, orientation) == 0 &&
795 __check_dpi(ss->dpi, dpi) == 0)
801 static gint __compare_splashscreen_with_orientation(gconstpointer a,
804 splashscreen_x *ss = (splashscreen_x *)a;
805 const char *orientation = (const char *)b;
807 if (ss->operation || ss->dpi)
810 if (strcasecmp(ss->orientation, orientation) == 0)
816 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
817 const char *orientation)
821 tmp = g_list_find_custom(splashscreens, orientation,
823 __compare_splashscreen_with_orientation_dpi);
825 return (splashscreen_x *)tmp->data;
827 tmp = g_list_find_custom(splashscreens, orientation,
828 (GCompareFunc)__compare_splashscreen_with_orientation);
830 return (splashscreen_x *)tmp->data;
835 static void __find_appcontrol_splashscreen_with_dpi(gpointer data,
838 splashscreen_x *ss = (splashscreen_x *)data;
839 GList **list = (GList **)user_data;
843 if (ss->operation == NULL || ss->dpi == NULL)
846 ret = system_info_get_platform_int(
847 "http://tizen.org/feature/screen.dpi", &dpi);
848 if (ret != SYSTEM_INFO_ERROR_NONE)
851 if (__check_dpi(ss->dpi, dpi) != 0)
854 *list = g_list_append(*list, ss);
857 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
859 splashscreen_x *ss = (splashscreen_x *)data;
860 GList **list = (GList **)user_data;
861 splashscreen_x *ss_tmp;
864 if (ss->operation == NULL || ss->dpi)
867 for (tmp = *list; tmp; tmp = tmp->next) {
868 ss_tmp = (splashscreen_x *)tmp->data;
869 if (ss_tmp->operation
870 && strcmp(ss_tmp->operation, ss->operation) == 0
871 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
875 *list = g_list_append(*list, ss);
878 static GList *__find_splashscreens(GList *splashscreens)
883 g_list_foreach(splashscreens,
884 __find_appcontrol_splashscreen_with_dpi, &list);
885 g_list_foreach(splashscreens,
886 __find_appcontrol_splashscreen, &list);
888 ss = __find_default_splashscreen(splashscreens, "portrait");
890 list = g_list_append(list, ss);
891 ss = __find_default_splashscreen(splashscreens, "landscape");
893 list = g_list_append(list, ss);
898 static int __insert_splashscreen_info(sqlite3 *db, application_x *app)
900 static const char query[] =
901 "INSERT INTO package_app_splash_screen (app_id, src, type,"
902 " orientation, indicatordisplay, operation, color_depth) "
903 "VALUES (?, ?, ?, ?, ?, ?, ?)";
911 if (app->splashscreens == NULL)
914 ss_list = __find_splashscreens(app->splashscreens);
918 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
919 if (ret != SQLITE_OK) {
920 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
924 for (tmp = ss_list; tmp; tmp = tmp->next) {
925 ss = (splashscreen_x *)tmp->data;
929 __BIND_TEXT(db, stmt, idx++, app->appid);
930 __BIND_TEXT(db, stmt, idx++, ss->src);
931 __BIND_TEXT(db, stmt, idx++, ss->type);
932 __BIND_TEXT(db, stmt, idx++, ss->orientation);
933 __BIND_TEXT(db, stmt, idx++, ss->indicatordisplay);
934 __BIND_TEXT(db, stmt, idx++, ss->operation);
935 __BIND_TEXT(db, stmt, idx++, ss->color_depth);
937 ret = sqlite3_step(stmt);
938 if (ret != SQLITE_DONE) {
939 _LOGE("step failed: %s", sqlite3_errmsg(db));
940 sqlite3_finalize(stmt);
947 sqlite3_finalize(stmt);
952 static void __trimfunc(GList *trim_list)
956 GList *list = g_list_first(trim_list);
959 trim_data = (char *)list->data;
962 if (strcmp(trim_data, prev) == 0) {
963 trim_list = g_list_remove(trim_list,
965 list = g_list_first(trim_list);
974 list = g_list_next(list);
978 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
980 if (a == NULL || b == NULL)
982 if (strcmp((char *)a, (char *)b) == 0)
984 if (strcmp((char *)a, (char *)b) < 0)
986 if (strcmp((char *)a, (char *)b) > 0)
991 /* TODO: refactor inserting localized info */
992 static GList *__create_locale_list(GList *lbls, GList *lcns, GList *icns,
993 GList *dcns, GList *aths)
995 GList *locale = NULL;
1003 for (tmp = lbls; tmp; tmp = tmp->next) {
1004 lbl = (label_x *)tmp->data;
1008 locale = g_list_insert_sorted_with_data(
1009 locale, (gpointer)lbl->lang,
1010 __comparefunc, NULL);
1012 for (tmp = lcns; tmp; tmp = tmp->next) {
1013 lcn = (license_x *)tmp->data;
1017 locale = g_list_insert_sorted_with_data(
1018 locale, (gpointer)lcn->lang,
1019 __comparefunc, NULL);
1021 for (tmp = icns; tmp; tmp = tmp->next) {
1022 icn = (icon_x *)tmp->data;
1026 locale = g_list_insert_sorted_with_data(
1027 locale, (gpointer)icn->lang,
1028 __comparefunc, NULL);
1030 for (tmp = dcns; tmp; tmp = tmp->next) {
1031 dcn = (description_x *)tmp->data;
1035 locale = g_list_insert_sorted_with_data(
1036 locale, (gpointer)dcn->lang,
1037 __comparefunc, NULL);
1039 for (tmp = aths; tmp; tmp = tmp->next) {
1040 ath = (author_x *)tmp->data;
1044 locale = g_list_insert_sorted_with_data(
1045 locale, (gpointer)ath->lang,
1046 __comparefunc, NULL);
1052 static gint __check_icon_resolution(const char *orig_icon_path,
1053 char **new_icon_path)
1057 char *icon_filename;
1058 char modified_iconpath[BUFSIZE];
1059 char icon_path[BUFSIZE];
1063 if (orig_icon_path == NULL)
1066 ret = system_info_get_platform_int(
1067 "http://tizen.org/feature/screen.dpi", &dpi);
1068 if (ret != SYSTEM_INFO_ERROR_NONE)
1071 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
1072 dpi_path[0] = "LDPI";
1073 dpi_path[1] = "ldpi";
1074 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
1075 dpi_path[0] = "MDPI";
1076 dpi_path[1] = "mdpi";
1077 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
1078 dpi_path[0] = "HDPI";
1079 dpi_path[1] = "hdpi";
1080 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
1081 dpi_path[0] = "XHDPI";
1082 dpi_path[1] = "xhdpi";
1083 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
1084 dpi_path[0] = "XXHDPI";
1085 dpi_path[1] = "xxhdpi";
1087 _LOGE("Unidentified dpi[%d]", dpi);
1091 icon_filename = strrchr(orig_icon_path, '/');
1092 if (icon_filename == NULL)
1096 strlen(orig_icon_path) - (strlen(icon_filename) - 1),
1097 "%s", orig_icon_path);
1098 for (i = 0; i < 2; i++) {
1099 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s",
1100 icon_path, dpi_path[i], icon_filename);
1101 if (access(modified_iconpath, F_OK) != -1) {
1102 /* if exists, return modified icon path */
1103 *new_icon_path = strdup(modified_iconpath);
1111 static gint __compare_icon(gconstpointer a, gconstpointer b)
1113 icon_x *icon = (icon_x *)a;
1116 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
1119 if (icon->dpi != NULL)
1122 if (__check_icon_resolution(icon->text, &icon_path) == 0) {
1124 icon->text = icon_path;
1130 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
1132 icon_x *icon = (icon_x *)a;
1133 int dpi = GPOINTER_TO_INT(b);
1135 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
1138 if (icon->dpi == NULL)
1141 if (__check_dpi(icon->dpi, dpi) == 0)
1147 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
1149 icon_x *icon = (icon_x *)a;
1150 char *lang = (char *)b;
1153 if (icon->dpi != NULL)
1156 if (strcasecmp(icon->lang, lang) == 0) {
1157 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
1158 /* icon for no locale. check existance of
1159 * folder-hierachied default icons
1161 if (__check_icon_resolution(icon->text,
1164 icon->text = icon_path;
1173 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
1176 icon_x *icon = (icon_x *)a;
1177 char *lang = (char *)b;
1180 ret = system_info_get_platform_int(
1181 "http://tizen.org/feature/screen.dpi", &dpi);
1182 if (ret != SYSTEM_INFO_ERROR_NONE)
1185 if (strcasecmp(icon->lang, lang) == 0 &&
1186 __check_dpi(icon->dpi, dpi) == 0)
1192 static char *__find_icon(GList *icons, const char *lang)
1199 /* first, find icon whose locale and dpi with given lang and
1200 * system's dpi has matched
1202 tmp = g_list_find_custom(icons, lang,
1203 (GCompareFunc)__compare_icon_with_lang_dpi);
1205 icon = (icon_x *)tmp->data;
1206 return (char *)icon->text;
1209 /* if first has failed, find icon whose locale has matched */
1210 tmp = g_list_find_custom(icons, lang,
1211 (GCompareFunc)__compare_icon_with_lang);
1213 icon = (icon_x *)tmp->data;
1214 return (char *)icon->text;
1217 /* if second has failed, find icon whose dpi has matched with
1220 ret = system_info_get_platform_int(
1221 "http://tizen.org/feature/screen.dpi", &dpi);
1222 if (ret == SYSTEM_INFO_ERROR_NONE) {
1223 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi),
1224 (GCompareFunc)__compare_icon_with_dpi);
1226 icon = (icon_x *)tmp->data;
1227 return (char *)icon->text;
1231 /* last, find default icon marked as "No Locale" */
1232 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
1234 icon = (icon_x *)tmp->data;
1235 return (char *)icon->text;
1241 static void __extract_data(const char *locale, GList *lbls, GList *lcns,
1242 GList *icns, GList *dcns, GList *aths, char **label,
1243 char **license, char **icon, char **description, char **author)
1251 for (tmp = lbls; tmp; tmp = tmp->next) {
1252 lbl = (label_x *)tmp->data;
1256 if (strcmp(lbl->lang, locale) == 0) {
1257 *label = (char *)lbl->text;
1262 for (tmp = lcns; tmp; tmp = tmp->next) {
1263 lcn = (license_x *)tmp->data;
1267 if (strcmp(lcn->lang, locale) == 0) {
1268 *license = (char *)lcn->text;
1274 *icon = __find_icon(icns, locale);
1276 for (tmp = dcns; tmp; tmp = tmp->next) {
1277 dcn = (description_x *)tmp->data;
1281 if (strcmp(dcn->lang, locale) == 0) {
1282 *description = (char *)dcn->text;
1287 for (tmp = aths; tmp; tmp = tmp->next) {
1288 ath = (author_x *)tmp->data;
1292 if (strcmp(ath->lang, locale) == 0) {
1293 *author = (char *)ath->text;
1300 static int __insert_mainapp_localized_info(sqlite3 *db, application_x *app,
1301 const char *locale, const char *label, const char *icon)
1303 static const char query[] =
1304 "INSERT OR REPLACE INTO package_localized_info ("
1305 " package, package_locale, package_label, package_icon,"
1306 " package_description, package_license, package_author) "
1308 " COALESCE((SELECT package_label FROM package_localized_info"
1309 " WHERE package=? AND package_locale=?), ?),"
1310 " COALESCE((SELECT package_icon FROM package_localized_info"
1311 " WHERE package=? AND package_icon=?), ?),"
1312 " (SELECT package_description FROM package_localized_info"
1313 " WHERE package=? AND package_locale=?),"
1314 " (SELECT package_description FROM package_localized_info"
1315 " WHERE package=? AND package_locale=?),"
1316 " (SELECT package_description FROM package_localized_info"
1317 " WHERE package=? AND package_locale=?))";
1322 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1323 if (ret != SQLITE_OK) {
1324 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1328 __BIND_TEXT(db, stmt, idx++, app->package);
1329 __BIND_TEXT(db, stmt, idx++, locale);
1330 __BIND_TEXT(db, stmt, idx++, app->package);
1331 __BIND_TEXT(db, stmt, idx++, locale);
1332 __BIND_TEXT(db, stmt, idx++, label);
1333 __BIND_TEXT(db, stmt, idx++, app->package);
1334 __BIND_TEXT(db, stmt, idx++, locale);
1335 __BIND_TEXT(db, stmt, idx++, icon);
1336 __BIND_TEXT(db, stmt, idx++, app->package);
1337 __BIND_TEXT(db, stmt, idx++, locale);
1338 __BIND_TEXT(db, stmt, idx++, app->package);
1339 __BIND_TEXT(db, stmt, idx++, locale);
1340 __BIND_TEXT(db, stmt, idx++, app->package);
1341 __BIND_TEXT(db, stmt, idx++, locale);
1343 ret = sqlite3_step(stmt);
1344 if (ret != SQLITE_DONE) {
1345 _LOGE("step failed: %s", sqlite3_errmsg(db));
1346 sqlite3_finalize(stmt);
1350 sqlite3_finalize(stmt);
1355 static int __insert_app_localized_info(sqlite3 *db, application_x *app)
1357 static const char query[] =
1358 "INSERT INTO package_app_localized_info (app_id, app_locale,"
1359 " app_label, app_icon) "
1360 "VALUES (?, ?, ?, ?)";
1370 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1371 if (ret != SQLITE_OK) {
1372 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1376 locales = __create_locale_list(app->label, NULL, app->icon, NULL, NULL);
1377 for (tmp = locales; tmp; tmp = tmp->next) {
1378 locale = (const char *)tmp->data;
1381 __extract_data(locale, app->label, NULL, app->icon, NULL, NULL,
1382 &label, NULL, &icon, NULL, NULL);
1383 if (!label && !icon)
1387 __BIND_TEXT(db, stmt, idx++, app->appid);
1388 __BIND_TEXT(db, stmt, idx++, locale);
1389 __BIND_TEXT(db, stmt, idx++, label);
1390 __BIND_TEXT(db, stmt, idx++, icon);
1392 ret = sqlite3_step(stmt);
1393 if (ret != SQLITE_DONE) {
1394 _LOGE("step failed: %s", sqlite3_errmsg(db));
1395 g_list_free(locales);
1396 sqlite3_finalize(stmt);
1400 sqlite3_reset(stmt);
1402 if (strcasecmp(app->mainapp, "true")) {
1403 if (__insert_mainapp_localized_info(db, app, locale,
1405 _LOGE("insert mainapp localized info failed");
1409 g_list_free(locales);
1410 sqlite3_finalize(stmt);
1415 static int __insert_package_privilege_info(sqlite3 *db, manifest_x *mfx)
1417 static const char query[] =
1418 "INSERT INTO package_privilege_info (package, privilege, type) "
1426 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1427 if (ret != SQLITE_OK) {
1428 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1432 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1433 priv = (privilege_x *)tmp->data;
1438 __BIND_TEXT(db, stmt, idx++, mfx->package);
1439 __BIND_TEXT(db, stmt, idx++, priv->value);
1440 __BIND_TEXT(db, stmt, idx++, priv->type);
1442 ret = sqlite3_step(stmt);
1443 if (ret != SQLITE_DONE) {
1444 _LOGE("step failed: %s", sqlite3_errmsg(db));
1445 sqlite3_finalize(stmt);
1448 sqlite3_reset(stmt);
1451 sqlite3_finalize(stmt);
1456 /* _PRODUCT_LAUNCHING_ENHANCED_
1457 * app->indicatordisplay, app->portraitimg, app->landscapeimg,
1458 * app->guestmode_appstatus
1460 static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
1462 static const char query[] =
1463 "INSERT INTO package_app_info (app_id, app_component,"
1464 " app_exec, app_nodisplay, app_type, app_onboot, app_multiple,"
1465 " app_autorestart, app_taskmanage, app_hwacceleration,"
1466 " app_screenreader, app_mainapp, app_recentimage,"
1467 " app_launchcondition, app_indicatordisplay, app_portraitimg,"
1468 " app_landscapeimg, app_guestmodevisibility,"
1469 " app_permissiontype, app_preload, app_submode,"
1470 " app_submode_mainid, app_installed_storage, app_process_pool,"
1471 " app_launch_mode, app_ui_gadget, app_support_mode,"
1472 " app_support_disable, component_type, package, app_tep_name,"
1473 " app_zip_mount_file, app_background_category,"
1474 " app_package_type, app_root_path, app_api_version,"
1475 " app_effective_appid, app_splash_screen_display,"
1476 " app_package_system, app_removable,"
1477 " app_package_installed_time, app_support_ambient,"
1478 " app_setup_appid) "
1480 " ?, LOWER(?), ?, LOWER(?), LOWER(?),"
1481 " LOWER(?), LOWER(?), ?,"
1485 " ?, LOWER(?), LOWER(?),"
1487 " COALESCE(?, 'single'), LOWER(?), ?,"
1488 " LOWER(?), ?, ?, ?,"
1492 " LOWER(?), LOWER(?),"
1501 const char *effective_appid;
1503 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1504 if (ret != SQLITE_OK) {
1505 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1509 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1510 app = (application_x *)tmp->data;
1514 bg_category = __convert_background_category(
1515 app->background_category);
1516 effective_appid = __find_effective_appid(app->metadata);
1519 __BIND_TEXT(db, stmt, idx++, app->appid);
1520 __BIND_TEXT(db, stmt, idx++, app->component_type);
1521 __BIND_TEXT(db, stmt, idx++, app->exec);
1522 __BIND_TEXT(db, stmt, idx++, __get_bool(app->nodisplay, false));
1523 __BIND_TEXT(db, stmt, idx++, app->type);
1524 __BIND_TEXT(db, stmt, idx++, __get_bool(app->onboot, false));
1525 __BIND_TEXT(db, stmt, idx++, __get_bool(app->multiple, false));
1526 __BIND_TEXT(db, stmt, idx++,
1527 __get_bool(app->autorestart, false));
1528 __BIND_TEXT(db, stmt, idx++,
1529 __get_bool(app->taskmanage, false));
1530 __BIND_TEXT(db, stmt, idx++, app->hwacceleration);
1531 __BIND_TEXT(db, stmt, idx++, app->screenreader);
1532 __BIND_TEXT(db, stmt, idx++, __get_bool(app->mainapp, false));
1533 __BIND_TEXT(db, stmt, idx++, app->recentimage);
1534 __BIND_TEXT(db, stmt, idx++, app->launchcondition);
1535 __BIND_TEXT(db, stmt, idx++,
1536 __get_bool(app->indicatordisplay, true));
1537 __BIND_TEXT(db, stmt, idx++, app->portraitimg);
1538 __BIND_TEXT(db, stmt, idx++, app->landscapeimg);
1539 __BIND_TEXT(db, stmt, idx++,
1540 __get_bool(app->guestmode_visibility, true));
1541 __BIND_TEXT(db, stmt, idx++, app->permission_type);
1542 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->preload, false));
1543 __BIND_TEXT(db, stmt, idx++, __get_bool(app->submode, false));
1544 __BIND_TEXT(db, stmt, idx++, app->submode_mainid);
1545 __BIND_TEXT(db, stmt, idx++, mfx->installed_storage);
1546 __BIND_TEXT(db, stmt, idx++,
1547 __get_bool(app->process_pool, false));
1548 __BIND_TEXT(db, stmt, idx++, app->launch_mode);
1549 __BIND_TEXT(db, stmt, idx++, __get_bool(app->ui_gadget, false));
1550 __BIND_TEXT(db, stmt, idx++, app->support_mode);
1551 __BIND_TEXT(db, stmt, idx++,
1552 __get_bool(mfx->support_disable, false));
1553 __BIND_TEXT(db, stmt, idx++, app->component_type);
1554 __BIND_TEXT(db, stmt, idx++, mfx->package);
1555 __BIND_TEXT(db, stmt, idx++, mfx->tep_name);
1556 __BIND_TEXT(db, stmt, idx++, mfx->zip_mount_file);
1557 __BIND_INT(db, stmt, idx++, bg_category);
1558 __BIND_TEXT(db, stmt, idx++, mfx->type ? mfx->type : "tpk");
1559 __BIND_TEXT(db, stmt, idx++, mfx->root_path);
1560 __BIND_TEXT(db, stmt, idx++, mfx->api_version);
1561 __BIND_TEXT(db, stmt, idx++, effective_appid);
1562 __BIND_TEXT(db, stmt, idx++,
1563 __get_bool(app->splash_screen_display, false));
1564 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->system, false));
1565 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->removable, false));
1566 __BIND_TEXT(db, stmt, idx++, mfx->installed_time);
1567 __BIND_TEXT(db, stmt, idx++,
1568 __get_bool(app->support_ambient, false));
1569 __BIND_TEXT(db, stmt, idx++, app->setup_appid);
1571 ret = sqlite3_step(stmt);
1572 if (ret != SQLITE_DONE) {
1573 _LOGE("step failed: %s", sqlite3_errmsg(db));
1574 sqlite3_finalize(stmt);
1578 sqlite3_reset(stmt);
1580 if (__insert_appcontrol_info(db, app)) {
1581 sqlite3_finalize(stmt);
1584 if (__insert_category_info(db, app)) {
1585 sqlite3_finalize(stmt);
1588 if (__insert_metadata_info(db, app)) {
1589 sqlite3_finalize(stmt);
1592 if (__insert_datacontrol_info(db, app)) {
1593 sqlite3_finalize(stmt);
1596 if (__insert_splashscreen_info(db, app)) {
1597 sqlite3_finalize(stmt);
1600 if (__insert_app_localized_info(db, app)) {
1601 sqlite3_finalize(stmt);
1606 sqlite3_finalize(stmt);
1611 static int __insert_package_localized_info(sqlite3 *db, manifest_x *mfx)
1613 static const char query[] =
1614 "INSERT INTO package_localized_info (package, package_locale,"
1615 " package_label, package_icon, package_description,"
1616 " package_license, package_author) "
1617 "VALUES (?, ?, ?, ?, ?, ?, ?)";
1630 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1631 if (ret != SQLITE_OK) {
1632 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1636 locales = __create_locale_list(mfx->label, mfx->license, mfx->icon,
1637 mfx->description, mfx->author);
1638 for (tmp = locales; tmp; tmp = tmp->next) {
1639 locale = (const char *)tmp->data;
1645 __extract_data(locale, mfx->label, mfx->license, mfx->icon,
1646 mfx->description, mfx->author,
1647 &label, &license, &icon, &description, &author);
1648 if (!label && !license && !icon && !description && !author)
1652 __BIND_TEXT(db, stmt, idx++, mfx->package);
1653 __BIND_TEXT(db, stmt, idx++, locale);
1654 __BIND_TEXT(db, stmt, idx++, label);
1655 __BIND_TEXT(db, stmt, idx++, icon);
1656 __BIND_TEXT(db, stmt, idx++, description);
1657 __BIND_TEXT(db, stmt, idx++, license);
1658 __BIND_TEXT(db, stmt, idx++, author);
1660 ret = sqlite3_step(stmt);
1661 if (ret != SQLITE_DONE) {
1662 _LOGE("step failed: %s", sqlite3_errmsg(db));
1663 g_list_free(locales);
1664 sqlite3_finalize(stmt);
1668 sqlite3_reset(stmt);
1671 g_list_free(locales);
1672 sqlite3_finalize(stmt);
1677 static int __insert_package_info(sqlite3 *db, manifest_x *mfx)
1679 static const char query[] =
1680 "INSERT INTO package_info (package, package_type,"
1681 " package_version, package_api_version, package_tep_name,"
1682 " package_zip_mount_file, install_location, package_size,"
1683 " package_removable, package_preload, package_readonly,"
1684 " package_update, package_appsetting, package_nodisplay,"
1685 " package_system, author_name, author_email, author_href,"
1686 " installed_time, installed_storage, storeclient_id,"
1687 " mainapp_id, package_url, root_path, external_path,"
1688 " csc_path, package_support_mode, package_support_disable) "
1692 " LOWER(?), LOWER(?), LOWER(?),"
1693 " LOWER(?), LOWER(?), LOWER(?),"
1694 " LOWER(?), ?, ?, ?,"
1701 const char *author_name = NULL;
1702 const char *author_email = NULL;
1703 const char *author_href = NULL;
1705 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1706 if (ret != SQLITE_OK) {
1707 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1711 if (mfx->author && mfx->author->data) {
1712 author_name = ((author_x *)mfx->author->data)->text;
1713 author_email = ((author_x *)mfx->author->data)->email;
1714 author_href = ((author_x *)mfx->author->data)->href;
1717 __BIND_TEXT(db, stmt, idx++, mfx->package);
1718 __BIND_TEXT(db, stmt, idx++, mfx->type);
1719 __BIND_TEXT(db, stmt, idx++, mfx->version);
1720 __BIND_TEXT(db, stmt, idx++, mfx->api_version);
1721 __BIND_TEXT(db, stmt, idx++, mfx->tep_name);
1722 __BIND_TEXT(db, stmt, idx++, mfx->zip_mount_file);
1723 __BIND_TEXT(db, stmt, idx++, mfx->installlocation);
1724 __BIND_TEXT(db, stmt, idx++, mfx->package_size);
1725 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->removable, true));
1726 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->preload, false));
1727 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->readonly, false));
1728 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->update, false));
1729 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->appsetting, false));
1730 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->nodisplay_setting, false));
1731 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->system, false));
1732 __BIND_TEXT(db, stmt, idx++, author_name);
1733 __BIND_TEXT(db, stmt, idx++, author_email);
1734 __BIND_TEXT(db, stmt, idx++, author_href);
1735 __BIND_TEXT(db, stmt, idx++, mfx->installed_time);
1736 __BIND_TEXT(db, stmt, idx++, mfx->installed_storage);
1737 __BIND_TEXT(db, stmt, idx++, mfx->storeclient_id);
1738 __BIND_TEXT(db, stmt, idx++, mfx->mainapp_id);
1739 __BIND_TEXT(db, stmt, idx++, mfx->package_url);
1740 __BIND_TEXT(db, stmt, idx++, mfx->root_path);
1741 __BIND_TEXT(db, stmt, idx++, mfx->external_path);
1742 __BIND_TEXT(db, stmt, idx++, mfx->csc_path);
1743 __BIND_TEXT(db, stmt, idx++, mfx->support_mode);
1744 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->support_disable, false));
1746 ret = sqlite3_step(stmt);
1747 if (ret != SQLITE_DONE) {
1748 _LOGE("step failed: %s", sqlite3_errmsg(db));
1749 sqlite3_finalize(stmt);
1753 sqlite3_finalize(stmt);
1755 if (__insert_package_localized_info(db, mfx))
1757 if (__insert_application_info(db, mfx))
1759 if (__insert_package_privilege_info(db, mfx))
1765 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
1772 _LOGE("invalid parameter");
1773 return PM_PARSER_R_EINVAL;
1776 dbpath = __get_parser_db_path(uid);
1778 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
1779 if (ret != SQLITE_OK) {
1780 _LOGE("open db failed: %d", ret);
1781 return PM_PARSER_R_ERROR;
1784 __BEGIN_TRANSACTION(db);
1785 __DO_TRANSACTION(db, __insert_package_info(db, mfx));
1786 __END_TRANSACTION(db);
1788 sqlite3_close_v2(db);
1790 return PM_PARSER_R_OK;
1793 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
1795 return pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, __getuid());
1798 static int __delete_package_info(sqlite3 *db, const char *pkgid)
1800 static const char query[] =
1801 "DELETE FROM package_info WHERE package=?";
1805 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1806 if (ret != SQLITE_OK) {
1807 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1811 __BIND_TEXT(db, stmt, 1, pkgid);
1813 ret = sqlite3_step(stmt);
1814 if (ret != SQLITE_DONE) {
1815 _LOGE("step failed: %s", sqlite3_errmsg(db));
1816 sqlite3_finalize(stmt);
1820 sqlite3_finalize(stmt);
1825 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx,
1833 _LOGE("invalid parameter");
1834 return PM_PARSER_R_EINVAL;
1837 dbpath = __get_parser_db_path(uid);
1839 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
1840 if (ret != SQLITE_OK) {
1841 _LOGE("open db failed: %d", ret);
1842 return PM_PARSER_R_ERROR;
1845 __BEGIN_TRANSACTION(db);
1846 __DO_TRANSACTION(db, __delete_package_info(db, mfx->package));
1847 __END_TRANSACTION(db);
1849 sqlite3_close_v2(db);
1851 return PM_PARSER_R_OK;
1854 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
1856 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, __getuid());
1859 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
1866 _LOGE("invalid parameter");
1867 return PM_PARSER_R_EINVAL;
1870 dbpath = __get_parser_db_path(uid);
1872 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
1873 if (ret != SQLITE_OK) {
1874 _LOGE("open db failed: %d", ret);
1875 return PM_PARSER_R_ERROR;
1878 __BEGIN_TRANSACTION(db);
1879 __DO_TRANSACTION(db, __delete_package_info(db, mfx->package));
1880 __DO_TRANSACTION(db, __insert_package_info(db, mfx));
1881 __END_TRANSACTION(db);
1883 sqlite3_close_v2(db);
1885 return PM_PARSER_R_OK;
1888 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
1890 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, __getuid());
1893 static int __set_global_app_disable_for_uid(sqlite3 *db, const char *appid,
1894 uid_t uid, bool is_disable)
1896 static const char query[] =
1897 "INSERT OR REPLACE INTO package_app_info_for_uid ("
1898 " app_id, uid, is_disabled, is_splash_screen_enabled) "
1900 " (SELECT app_splash_screen_display FROM package_app_info"
1901 " WHERE app_id=?))";
1906 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1907 if (ret != SQLITE_OK) {
1908 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1912 __BIND_TEXT(db, stmt, idx++, appid);
1913 __BIND_INT(db, stmt, idx++, uid);
1914 __BIND_TEXT(db, stmt, idx++, is_disable ? "true" : "false");
1915 __BIND_TEXT(db, stmt, idx++, appid);
1917 ret = sqlite3_step(stmt);
1918 if (ret != SQLITE_DONE) {
1919 _LOGE("step failed: %s", sqlite3_errmsg(db));
1920 sqlite3_finalize(stmt);
1924 sqlite3_finalize(stmt);
1929 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(
1930 const char *appid, uid_t uid, int is_disable)
1936 if (appid == NULL) {
1937 _LOGE("invalid parameter");
1938 return PM_PARSER_R_EINVAL;
1941 dbpath = __get_parser_db_path(uid);
1943 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
1944 if (ret != SQLITE_OK) {
1945 _LOGE("open db failed: %d", ret);
1946 return PM_PARSER_R_ERROR;
1949 __BEGIN_TRANSACTION(db);
1950 __DO_TRANSACTION(db, __set_global_app_disable_for_uid(db, appid,
1951 uid, (bool)is_disable));
1952 __END_TRANSACTION(db);
1954 sqlite3_close_v2(db);
1956 return PM_PARSER_R_OK;
1959 static int __set_app_disable(sqlite3 *db, const char *appid, uid_t uid,
1962 static const char query[] =
1963 "UPDATE package_app_info SET app_disable=? "
1969 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1970 if (ret != SQLITE_OK) {
1971 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1975 __BIND_TEXT(db, stmt, idx++, is_disable ? "true" : "false");
1976 __BIND_TEXT(db, stmt, idx++, appid);
1978 ret = sqlite3_step(stmt);
1979 if (ret != SQLITE_DONE) {
1980 _LOGE("step failed: %s", sqlite3_errmsg(db));
1981 sqlite3_finalize(stmt);
1985 sqlite3_finalize(stmt);
1990 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid,
1991 uid_t uid, int is_disable)
1997 if (appid == NULL) {
1998 _LOGE("invalid parameter");
1999 return PM_PARSER_R_EINVAL;
2002 dbpath = __get_parser_db_path(uid);
2004 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2005 if (ret != SQLITE_OK) {
2006 _LOGE("open db failed: %d", ret);
2007 return PM_PARSER_R_ERROR;
2010 __BEGIN_TRANSACTION(db);
2011 __DO_TRANSACTION(db, __set_app_disable(db, appid, uid,
2013 __END_TRANSACTION(db);
2015 sqlite3_close_v2(db);
2017 return PM_PARSER_R_OK;
2020 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid,
2023 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid,
2024 __getuid(), is_disable);
2027 static int __set_pkg_disable(sqlite3 *db, const char *pkgid, uid_t uid,
2030 static const char query[] =
2031 "UPDATE package_info SET package_disable=? "
2037 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2038 if (ret != SQLITE_OK) {
2039 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2043 __BIND_TEXT(db, stmt, idx++, is_disable ? "true" : "false");
2044 __BIND_TEXT(db, stmt, idx++, pkgid);
2046 ret = sqlite3_step(stmt);
2047 if (ret != SQLITE_DONE) {
2048 _LOGE("step failed: %s", sqlite3_errmsg(db));
2049 sqlite3_finalize(stmt);
2053 sqlite3_finalize(stmt);
2058 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid,
2059 uid_t uid, int is_disable)
2065 if (pkgid == NULL) {
2066 _LOGE("invalid parameter");
2067 return PM_PARSER_R_EINVAL;
2070 dbpath = __get_parser_db_path(uid);
2072 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2073 if (ret != SQLITE_OK) {
2074 _LOGE("open db failed: %d", ret);
2075 return PM_PARSER_R_ERROR;
2078 __BEGIN_TRANSACTION(db);
2079 __DO_TRANSACTION(db, __set_pkg_disable(db, pkgid, uid,
2081 __END_TRANSACTION(db);
2083 sqlite3_close_v2(db);
2085 return PM_PARSER_R_OK;
2088 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid,
2091 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid,
2092 __getuid(), is_disable);
2095 static int __set_global_app_splash_screen_for_uid(sqlite3 *db,
2096 const char *appid, uid_t uid, bool is_enabled)
2098 static const char query[] =
2099 "INSERT OR REPLACE INTO package_app_info_for_uid("
2100 " appid, uid, is_splash_screen_enabled) "
2106 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2107 if (ret != SQLITE_OK) {
2108 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2112 __BIND_TEXT(db, stmt, idx++, appid);
2113 __BIND_INT(db, stmt, idx++, uid);
2114 __BIND_TEXT(db, stmt, idx++, is_enabled ? "true" : "false");
2116 ret = sqlite3_step(stmt);
2117 if (ret != SQLITE_DONE) {
2118 _LOGE("step failed: %s", sqlite3_errmsg(db));
2119 sqlite3_finalize(stmt);
2123 sqlite3_finalize(stmt);
2128 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(
2129 const char *appid, uid_t uid, int flag)
2135 if (appid == NULL) {
2136 _LOGE("invalid parameter");
2137 return PM_PARSER_R_EINVAL;
2140 dbpath = __get_parser_db_path(uid);
2142 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2143 if (ret != SQLITE_OK) {
2144 _LOGE("open db failed: %d", ret);
2145 return PM_PARSER_R_ERROR;
2148 __BEGIN_TRANSACTION(db);
2149 __DO_TRANSACTION(db, __set_global_app_splash_screen_for_uid(db,
2150 appid, uid, (bool)flag));
2151 __END_TRANSACTION(db);
2153 sqlite3_close_v2(db);
2155 return PM_PARSER_R_OK;
2158 static int __set_app_splash_screen(sqlite3 *db, const char *appid,
2161 static const char query[] =
2162 "UPDATE package_app_info SET app_splash_screen_display=? "
2168 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2169 if (ret != SQLITE_OK) {
2170 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2174 __BIND_TEXT(db, stmt, idx++, is_enabled ? "true" : "false");
2175 __BIND_TEXT(db, stmt, idx++, appid);
2177 ret = sqlite3_step(stmt);
2178 if (ret != SQLITE_DONE) {
2179 _LOGE("step failed: %s", sqlite3_errmsg(db));
2180 sqlite3_finalize(stmt);
2184 sqlite3_finalize(stmt);
2189 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(
2190 const char *appid, uid_t uid, int flag)
2196 if (appid == NULL) {
2197 _LOGE("invalid parameter");
2198 return PM_PARSER_R_EINVAL;
2201 dbpath = __get_parser_db_path(uid);
2203 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2204 if (ret != SQLITE_OK) {
2205 _LOGE("open db failed: %d", ret);
2206 return PM_PARSER_R_ERROR;
2209 __BEGIN_TRANSACTION(db);
2210 __DO_TRANSACTION(db, __set_app_splash_screen(db, appid, (bool)flag));
2211 __END_TRANSACTION(db);
2213 sqlite3_close_v2(db);
2215 return PM_PARSER_R_OK;
2218 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(
2219 const char *appid, int flag)
2221 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(
2222 appid, __getuid(), flag);
2225 static int __set_app_label(sqlite3 *db, const char *appid, const char *label)
2227 static const char query[] =
2228 "UPDATE package_app_localized_info SET app_label=? "
2229 "WHERE app_id=? AND app_label IS NOT NULL";
2234 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2235 if (ret != SQLITE_OK) {
2236 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2240 __BIND_TEXT(db, stmt, idx++, label);
2241 __BIND_TEXT(db, stmt, idx++, appid);
2243 ret = sqlite3_step(stmt);
2244 if (ret != SQLITE_DONE) {
2245 _LOGE("step failed: %s", sqlite3_errmsg(db));
2246 sqlite3_finalize(stmt);
2250 sqlite3_finalize(stmt);
2255 API int pkgmgr_parser_update_app_label_info_in_usr_db(const char *appid,
2256 uid_t uid, const char *label)
2262 if (appid == NULL) {
2263 _LOGE("invalid parameter");
2264 return PM_PARSER_R_EINVAL;
2267 dbpath = __get_parser_db_path(uid);
2269 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2270 if (ret != SQLITE_OK) {
2271 _LOGE("open db failed: %d", ret);
2272 return PM_PARSER_R_ERROR;
2275 __BEGIN_TRANSACTION(db);
2276 __DO_TRANSACTION(db, __set_app_label(db, appid, label));
2277 __END_TRANSACTION(db);
2279 sqlite3_close_v2(db);
2281 return PM_PARSER_R_OK;
2284 API int pkgmgr_parser_update_app_label_info_in_db(const char *appid,
2287 return pkgmgr_parser_update_app_label_info_in_usr_db(appid, __getuid(),
2291 static int __set_tep_path(sqlite3 *db, const char *pkgid, const char *tep_path)
2293 static const char query[] =
2294 "UPDATE package_info SET package_tep_name=? "
2300 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2301 if (ret != SQLITE_OK) {
2302 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2306 __BIND_TEXT(db, stmt, idx++, tep_path);
2307 __BIND_TEXT(db, stmt, idx++, pkgid);
2309 ret = sqlite3_step(stmt);
2310 if (ret != SQLITE_DONE) {
2311 _LOGE("step failed: %s", sqlite3_errmsg(db));
2312 sqlite3_finalize(stmt);
2316 sqlite3_finalize(stmt);
2321 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid,
2322 const char *tep_path, uid_t uid)
2328 if (pkgid == NULL) {
2329 _LOGE("invalid parameter");
2330 return PM_PARSER_R_EINVAL;
2333 dbpath = __get_parser_db_path(uid);
2335 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2336 if (ret != SQLITE_OK) {
2337 _LOGE("open db failed: %d", ret);
2338 return PM_PARSER_R_ERROR;
2341 __BEGIN_TRANSACTION(db);
2342 __DO_TRANSACTION(db, __set_tep_path(db, pkgid, tep_path));
2343 __END_TRANSACTION(db);
2345 sqlite3_close_v2(db);
2347 return PM_PARSER_R_OK;
2350 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid,
2351 const char *tep_path)
2353 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path,
2357 static int __convert_update_type(pkgmgrinfo_updateinfo_update_type type,
2358 const char **update_type)
2360 if (type == PMINFO_UPDATEINFO_NONE)
2361 *update_type = PMINFO_UPDATEINFO_TYPE_NONE;
2362 else if (type == PMINFO_UPDATEINFO_FORCE)
2363 *update_type = PMINFO_UPDATEINFO_TYPE_FORCE;
2364 else if (type == PMINFO_UPDATEINFO_OPTIONAL)
2365 *update_type = PMINFO_UPDATEINFO_TYPE_OPTIONAL;
2371 static int __register_pkg_update_info(sqlite3 *db, updateinfo_x *info,
2372 const char *update_type)
2374 static const char query[] =
2375 "UPDATE package_update_info "
2376 "SET update_version=?, update_type=? "
2382 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2383 if (ret != SQLITE_OK) {
2384 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2388 __BIND_TEXT(db, stmt, idx++, info->version);
2389 __BIND_TEXT(db, stmt, idx++, update_type);
2390 __BIND_TEXT(db, stmt, idx++, info->pkgid);
2392 ret = sqlite3_step(stmt);
2393 if (ret != SQLITE_DONE) {
2394 _LOGE("step failed: %s", sqlite3_errmsg(db));
2395 sqlite3_finalize(stmt);
2399 sqlite3_finalize(stmt);
2404 API int pkgmgr_parser_register_pkg_update_info_in_usr_db(
2405 pkgmgrinfo_updateinfo_h handle, uid_t uid)
2408 updateinfo_x *update_info;
2409 updateinfo_x *prev_update_info;
2410 pkgmgrinfo_updateinfo_h prev_update_handle;
2411 pkgmgrinfo_pkginfo_h pkginfo;
2412 pkgmgrinfo_version_compare_type compare_result;
2414 const char *update_type;
2418 if (handle == NULL) {
2419 _LOGE("invalid parameter");
2420 return PM_PARSER_R_EINVAL;
2423 update_info = (updateinfo_x *)handle;
2424 if (update_info->pkgid == NULL || update_info->version == NULL)
2425 return PM_PARSER_R_EINVAL;
2426 if (__convert_update_type(update_info->type, &update_type) != 0)
2427 return PM_PARSER_R_EINVAL;
2429 ret = pkgmgrinfo_updateinfo_get_usr_updateinfo(update_info->pkgid,
2430 &prev_update_handle, uid);
2431 if (ret != PMINFO_R_OK)
2432 return PM_PARSER_R_ERROR;
2434 prev_update_info = (updateinfo_x *)prev_update_handle;
2435 ret = pkgmgrinfo_compare_package_version(update_info->version,
2436 prev_update_info->version, &compare_result);
2437 if (ret != PMINFO_R_OK) {
2438 pkgmgrinfo_updateinfo_destroy(prev_update_handle);
2439 return PM_PARSER_R_ERROR;
2442 if (compare_result == PMINFO_VERSION_SAME &&
2443 prev_update_info->type == PMINFO_UPDATEINFO_NONE) {
2444 _LOGI("Given update info version[%s] of pkgid[%s] "
2446 update_info->version, update_info->pkgid);
2447 pkgmgrinfo_updateinfo_destroy(prev_update_handle);
2448 return PM_PARSER_R_OK;
2450 pkgmgrinfo_updateinfo_destroy(prev_update_handle);
2452 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(update_info->pkgid, uid,
2454 if (ret != PMINFO_R_OK)
2455 return PM_PARSER_R_ERROR;
2457 ret = pkgmgrinfo_pkginfo_is_global(pkginfo, &is_global_pkg);
2458 if (ret != PMINFO_R_OK) {
2459 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
2460 return PM_PARSER_R_ERROR;
2462 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
2464 dbpath = __get_parser_db_path(is_global_pkg ? GLOBAL_USER : uid);
2466 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2467 if (ret != SQLITE_OK) {
2468 _LOGE("open db failed: %d", ret);
2469 return PM_PARSER_R_ERROR;
2472 __BEGIN_TRANSACTION(db);
2473 __DO_TRANSACTION(db, __register_pkg_update_info(db, update_info,
2475 __END_TRANSACTION(db);
2477 sqlite3_close_v2(db);
2479 return PM_PARSER_R_OK;
2482 API int pkgmgr_parser_register_pkg_update_info_in_db(
2483 pkgmgrinfo_updateinfo_h handle)
2485 return pkgmgr_parser_register_pkg_update_info_in_usr_db(handle,
2489 static int __unregister_pkg_update_info(sqlite3 *db, const char *pkgid)
2491 static const char query[] =
2492 "UPDATE package_update_info SET update_type='none' "
2498 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2499 if (ret != SQLITE_OK) {
2500 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2504 __BIND_TEXT(db, stmt, idx++, pkgid);
2506 ret = sqlite3_step(stmt);
2507 if (ret != SQLITE_DONE) {
2508 _LOGE("step failed: %s", sqlite3_errmsg(db));
2509 sqlite3_finalize(stmt);
2513 sqlite3_finalize(stmt);
2518 API int pkgmgr_parser_unregister_pkg_update_info_in_usr_db(const char *pkgid,
2524 pkgmgrinfo_pkginfo_h pkginfo;
2527 if (pkgid == NULL) {
2528 _LOGE("invalid parameter");
2529 return PM_PARSER_R_EINVAL;
2532 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &pkginfo);
2533 if (ret != PMINFO_R_OK)
2534 return PM_PARSER_R_EINVAL;
2536 ret = pkgmgrinfo_pkginfo_is_global(pkginfo, &is_global_pkg);
2537 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
2538 if (ret != PMINFO_R_OK)
2539 return PM_PARSER_R_ERROR;
2541 dbpath = __get_parser_db_path(is_global_pkg ? GLOBAL_USER : uid);
2543 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2544 if (ret != SQLITE_OK) {
2545 _LOGE("open db failed: %d", ret);
2546 return PM_PARSER_R_ERROR;
2549 __BEGIN_TRANSACTION(db);
2550 __DO_TRANSACTION(db, __unregister_pkg_update_info(db, pkgid));
2551 __END_TRANSACTION(db);
2553 sqlite3_close_v2(db);
2555 return PM_PARSER_R_OK;
2558 API int pkgmgr_parser_unregister_pkg_update_info_in_db(const char *pkgid)
2560 return pkgmgr_parser_unregister_pkg_update_info_in_usr_db(pkgid,
2564 static int __unregister_all_pkg_update_info(sqlite3 *db)
2566 static const char query[] =
2567 "UPDATE package_update_info SET update_type='none'";
2571 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2572 if (ret != SQLITE_OK) {
2573 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2577 ret = sqlite3_step(stmt);
2578 if (ret != SQLITE_DONE) {
2579 _LOGE("step failed: %s", sqlite3_errmsg(db));
2580 sqlite3_finalize(stmt);
2584 sqlite3_finalize(stmt);
2589 API int pkgmgr_parser_unregister_all_pkg_update_info_in_usr_db(uid_t uid)
2595 dbpath = __get_parser_db_path(uid);
2597 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2598 if (ret != SQLITE_OK) {
2599 _LOGE("open db failed: %d", ret);
2600 return PM_PARSER_R_ERROR;
2603 __BEGIN_TRANSACTION(db);
2604 __DO_TRANSACTION(db, __unregister_all_pkg_update_info(db));
2605 __END_TRANSACTION(db);
2607 sqlite3_close_v2(db);
2609 return PM_PARSER_R_OK;
2612 API int pkgmgr_parser_unregister_all_pkg_update_info_in_db(void)
2614 return pkgmgr_parser_unregister_all_pkg_update_info_in_usr_db(