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_UPDATE_INFO,
305 QUERY_CREATE_TABLE_PACKAGE_APP_INFO,
306 QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO,
307 QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO, /* ? */
308 QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO, /* ? */
309 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL,
310 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY,
311 QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA,
312 QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION, /* ? */
313 QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED, /* ? */
314 QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST, /* ? */
315 QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL,
316 QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL_PRIVILEGE,
317 QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID,
318 QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID,
319 QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN,
323 static const char *cert_init_queries[] = {
324 QUERY_CREATE_TABLE_PACKAGE_CERT_INFO,
325 QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO,
326 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO,
327 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2,
328 QUERY_CREATE_TRIGGER_DELETE_CERT_INFO,
329 QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO,
333 static int __initialize_db(sqlite3 *db, const char *dbpath, uid_t uid)
336 const char **queries;
339 if (__set_db_version(db))
342 if (strstr(dbpath, ".pkgmgr_parser.db")) {
343 queries = parser_init_queries;
344 } else if (strstr(dbpath, ".pkgmgr_cert.db")) {
345 queries = cert_init_queries;
347 _LOGE("unexpected dbpath: %s", dbpath);
351 for (i = 0; queries[i] != NULL; i++) {
352 ret = sqlite3_exec(db, queries[i], NULL, NULL, NULL);
353 if (ret != SQLITE_OK) {
354 _LOGE("exec failed: %s", sqlite3_errmsg(db));
359 if (__set_db_permission(dbpath, uid))
360 _LOGE("failed to set db permission");
365 API int pkgmgr_parser_initialize_parser_db(uid_t uid)
371 dbpath = __get_parser_db_path(uid);
372 if (access(dbpath, F_OK) != -1) {
373 _LOGE("Manifest db for user %d is already exists", uid);
374 return PM_PARSER_R_ERROR;
377 ret = sqlite3_open_v2(dbpath, &db,
378 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
379 if (ret != SQLITE_OK) {
380 _LOGE("open db failed: %d", ret);
381 return PM_PARSER_R_ERROR;
384 if (__initialize_db(db, dbpath, uid)) {
385 sqlite3_close_v2(db);
386 return PM_PARSER_R_ERROR;
388 sqlite3_close_v2(db);
390 return PM_PARSER_R_OK;
393 API int pkgmgr_parser_initialize_cert_db(void)
399 dbpath = __get_cert_db_path();
400 if (access(dbpath, F_OK) != -1) {
401 _LOGE("Cert db is already exists");
402 return PM_PARSER_R_ERROR;
405 ret = sqlite3_open_v2(dbpath, &db,
406 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
407 if (ret != SQLITE_OK) {
408 _LOGE("open db failed: %d", ret);
409 return PM_PARSER_R_ERROR;
412 if (__initialize_db(db, dbpath, GLOBAL_USER)) {
413 sqlite3_close_v2(db);
414 return PM_PARSER_R_ERROR;
416 sqlite3_close_v2(db);
418 return PM_PARSER_R_OK;
421 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
425 struct passwd *result;
428 ret = getpwnam_r(APPFW_USER, &pwd, buf, sizeof(buf), &result);
429 if (result == NULL) {
431 _LOGE("no such user: %s", APPFW_USER);
433 _LOGE("getpwnam_r failed: %d", errno);
434 return PM_PARSER_R_ERROR;
437 if (getuid() != OWNER_ROOT && getuid() != pwd.pw_uid) {
438 _LOGE("Only root or app_fw user is allowed");
439 return PM_PARSER_R_EINVAL;
442 if (pkgmgr_parser_initialize_parser_db(uid))
443 return PM_PARSER_R_ERROR;
445 if (pkgmgr_parser_initialize_cert_db())
446 return PM_PARSER_R_ERROR;
448 return PM_PARSER_R_OK;
451 #define BUSY_WAITING_USEC (1000000 / 10 / 2) /* 0.05 sec */
452 #define BUSY_WAITING_MAX 20 /* wait for max 1 sec */
453 static int __db_busy_handler(void *data, int count)
455 if (count < BUSY_WAITING_MAX) {
456 usleep(BUSY_WAITING_USEC);
459 /* sqlite3_prepare_v2 will return SQLITE_BUSY */
464 static int __open_db(uid_t uid, const char *path, sqlite3 **db, int flags)
468 /* FIXME: always open with OPEN_CREATE flag for keeping previous
471 if (flags & SQLITE_OPEN_READWRITE)
472 flags = flags | SQLITE_OPEN_CREATE;
474 ret = sqlite3_open_v2(path, db, flags, NULL);
475 if (ret != SQLITE_OK)
478 ret = sqlite3_busy_handler(*db, __db_busy_handler, NULL);
479 if (ret != SQLITE_OK) {
480 _LOGE("failed to register busy handler: %s",
481 sqlite3_errmsg(*db));
482 sqlite3_close_v2(*db);
486 if (flags & SQLITE_OPEN_CREATE) {
487 ret = __initialize_db(*db, path, uid);
489 _LOGE("failed to initialize db: %s\n");
490 sqlite3_close_v2(*db);
495 ret = sqlite3_exec(*db, "PRAGMA foreign_keys=ON", NULL, NULL, NULL);
496 if (ret != SQLITE_OK) {
497 _LOGE("failed to enable foreign key support: %s",
498 sqlite3_errmsg(*db));
499 sqlite3_close_v2(*db);
507 static int __convert_background_category(GList *category_list)
513 if (category_list == NULL)
516 for (tmp = category_list; tmp; tmp = tmp->next) {
517 category_data = (char *)tmp->data;
518 if (category_data == NULL)
520 if (!strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR))
521 ret |= APP_BG_CATEGORY_MEDIA_VAL;
522 else if (!strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR))
523 ret |= APP_BG_CATEGORY_DOWNLOAD_VAL;
524 else if (!strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR))
525 ret |= APP_BG_CATEGORY_BGNETWORK_VAL;
526 else if (!strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR))
527 ret |= APP_BG_CATEGORY_LOCATION_VAL;
528 else if (!strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR))
529 ret |= APP_BG_CATEGORY_SENSOR_VAL;
530 else if (!strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR))
531 ret |= APP_BG_CATEGORY_IOTCOMM_VAL;
532 else if (!strcmp(category_data, APP_BG_CATEGORY_SYSTEM))
533 ret |= APP_BG_CATEGORY_SYSTEM_VAL;
535 _LOGE("Unidentified category [%s]", category_data);
541 #define EFFECTIVE_APPID_KEY "http://tizen.org/metadata/effective-appid"
542 static const char *__find_effective_appid(GList *metadata_list)
547 for (tmp = metadata_list; tmp; tmp = tmp->next) {
548 md = (metadata_x *)tmp->data;
549 if (md == NULL || md->key == NULL)
552 if (strcmp(md->key, EFFECTIVE_APPID_KEY) == 0) {
561 static int __insert_appcontrol_info(sqlite3 *db, application_x *app)
563 static const char query[] =
564 "INSERT INTO package_app_app_control (app_id, app_control) "
569 char app_control[BUFSIZE];
573 if (app->appcontrol == NULL)
576 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
577 if (ret != SQLITE_OK) {
578 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
582 for (tmp = app->appcontrol; tmp; tmp = tmp->next) {
583 ac = (appcontrol_x *)tmp->data;
587 snprintf(app_control, sizeof(app_control), "%s|%s|%s",
588 ac->operation ? (strlen(ac->operation) > 0 ?
589 ac->operation : "NULL") : "NULL",
590 ac->uri ? (strlen(ac->uri) > 0 ?
591 ac->uri : "NULL") : "NULL",
592 ac->mime ? (strlen(ac->mime) > 0 ?
593 ac->mime : "NULL") : "NULL");
594 __BIND_TEXT(db, stmt, idx++, app->appid);
595 __BIND_TEXT(db, stmt, idx++, app_control);
597 ret = sqlite3_step(stmt);
598 if (ret != SQLITE_DONE) {
599 _LOGE("step failed: %s", sqlite3_errmsg(db));
600 sqlite3_finalize(stmt);
607 sqlite3_finalize(stmt);
612 static int __insert_category_info(sqlite3 *db, application_x *app)
614 static const char query[] =
615 "INSERT INTO package_app_app_category (app_id, category) "
621 const char *category;
623 if (app->category == NULL)
626 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
627 if (ret != SQLITE_OK) {
628 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
632 for (tmp = app->category; tmp; tmp = tmp->next) {
633 category = (const char *)tmp->data;
634 if (category == NULL)
637 __BIND_TEXT(db, stmt, idx++, app->appid);
638 __BIND_TEXT(db, stmt, idx++, category);
640 ret = sqlite3_step(stmt);
641 if (ret != SQLITE_DONE) {
642 _LOGE("step failed: %s", sqlite3_errmsg(db));
643 sqlite3_finalize(stmt);
650 sqlite3_finalize(stmt);
655 static int __insert_metadata_info(sqlite3 *db, application_x *app)
657 static const char query[] =
658 "INSERT INTO package_app_app_metadata (app_id,"
659 " md_key, md_value) VALUES (?, ?, ?)";
666 if (app->metadata == NULL)
669 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
670 if (ret != SQLITE_OK) {
671 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
675 for (tmp = app->metadata; tmp; tmp = tmp->next) {
676 md = (metadata_x *)tmp->data;
680 __BIND_TEXT(db, stmt, idx++, app->appid);
681 __BIND_TEXT(db, stmt, idx++, md->key);
682 __BIND_TEXT(db, stmt, idx++, md->value);
684 ret = sqlite3_step(stmt);
685 if (ret != SQLITE_DONE) {
686 _LOGE("step failed: %s", sqlite3_errmsg(db));
687 sqlite3_finalize(stmt);
694 sqlite3_finalize(stmt);
699 static int __insert_app_data_control_privilege_info(sqlite3 *db,
700 datacontrol_x *datacontrol)
702 static const char query[] =
703 "INSERT INTO package_app_data_control_privilege (providerid,"
704 " privilege, type) VALUES (?, ?, ?)";
712 if (datacontrol == NULL)
715 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
716 if (ret != SQLITE_OK) {
717 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
721 for (privileges = datacontrol->privileges; privileges;
722 privileges = privileges->next) {
723 priv = (char *)privileges->data;
728 __BIND_TEXT(db, stmt, idx++, datacontrol->providerid);
729 __BIND_TEXT(db, stmt, idx++, priv);
730 __BIND_TEXT(db, stmt, idx++, datacontrol->type);
732 ret = sqlite3_step(stmt);
733 if (ret != SQLITE_DONE) {
734 _LOGE("step failed: %s", sqlite3_errmsg(db));
735 sqlite3_finalize(stmt);
742 sqlite3_finalize(stmt);
746 static int __insert_datacontrol_info(sqlite3 *db, application_x *app)
748 static const char query[] =
749 "INSERT INTO package_app_data_control (app_id, providerid,"
750 " access, type, trusted) VALUES (?, ?, ?, ?, ?)";
757 if (app->datacontrol == NULL)
760 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
761 if (ret != SQLITE_OK) {
762 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
766 for (tmp = app->datacontrol; tmp; tmp = tmp->next) {
767 dc = (datacontrol_x *)tmp->data;
771 __BIND_TEXT(db, stmt, idx++, app->appid);
772 __BIND_TEXT(db, stmt, idx++, dc->providerid);
773 __BIND_TEXT(db, stmt, idx++, dc->access);
774 __BIND_TEXT(db, stmt, idx++, dc->type);
775 __BIND_TEXT(db, stmt, idx++, dc->trusted);
777 ret = sqlite3_step(stmt);
778 if (ret != SQLITE_DONE) {
779 _LOGE("step failed: %s", sqlite3_errmsg(db));
780 sqlite3_finalize(stmt);
784 if (dc->privileges &&
785 __insert_app_data_control_privilege_info(db, dc)) {
786 sqlite3_finalize(stmt);
793 sqlite3_finalize(stmt);
798 /* TODO: move to installer */
799 static int __check_dpi(const char *dpi_char, int dpi_int)
801 if (dpi_char == NULL)
804 if (strcasecmp(dpi_char, LDPI) == 0) {
805 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
809 } else if (strcasecmp(dpi_char, MDPI) == 0) {
810 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
814 } else if (strcasecmp(dpi_char, HDPI) == 0) {
815 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
819 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
820 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
824 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
825 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
833 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a,
836 splashscreen_x *ss = (splashscreen_x *)a;
837 const char *orientation = (const char *)b;
841 if (ss->operation || ss->dpi == NULL)
844 ret = system_info_get_platform_int(
845 "http://tizen.org/feature/screen.dpi", &dpi);
846 if (ret != SYSTEM_INFO_ERROR_NONE)
849 if (strcasecmp(ss->orientation, orientation) == 0 &&
850 __check_dpi(ss->dpi, dpi) == 0)
856 static gint __compare_splashscreen_with_orientation(gconstpointer a,
859 splashscreen_x *ss = (splashscreen_x *)a;
860 const char *orientation = (const char *)b;
862 if (ss->operation || ss->dpi)
865 if (strcasecmp(ss->orientation, orientation) == 0)
871 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
872 const char *orientation)
876 tmp = g_list_find_custom(splashscreens, orientation,
878 __compare_splashscreen_with_orientation_dpi);
880 return (splashscreen_x *)tmp->data;
882 tmp = g_list_find_custom(splashscreens, orientation,
883 (GCompareFunc)__compare_splashscreen_with_orientation);
885 return (splashscreen_x *)tmp->data;
890 static void __find_appcontrol_splashscreen_with_dpi(gpointer data,
893 splashscreen_x *ss = (splashscreen_x *)data;
894 GList **list = (GList **)user_data;
898 if (ss->operation == NULL || ss->dpi == NULL)
901 ret = system_info_get_platform_int(
902 "http://tizen.org/feature/screen.dpi", &dpi);
903 if (ret != SYSTEM_INFO_ERROR_NONE)
906 if (__check_dpi(ss->dpi, dpi) != 0)
909 *list = g_list_append(*list, ss);
912 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
914 splashscreen_x *ss = (splashscreen_x *)data;
915 GList **list = (GList **)user_data;
916 splashscreen_x *ss_tmp;
919 if (ss->operation == NULL || ss->dpi)
922 for (tmp = *list; tmp; tmp = tmp->next) {
923 ss_tmp = (splashscreen_x *)tmp->data;
924 if (ss_tmp->operation
925 && strcmp(ss_tmp->operation, ss->operation) == 0
926 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
930 *list = g_list_append(*list, ss);
933 static GList *__find_splashscreens(GList *splashscreens)
938 g_list_foreach(splashscreens,
939 __find_appcontrol_splashscreen_with_dpi, &list);
940 g_list_foreach(splashscreens,
941 __find_appcontrol_splashscreen, &list);
943 ss = __find_default_splashscreen(splashscreens, "portrait");
945 list = g_list_append(list, ss);
946 ss = __find_default_splashscreen(splashscreens, "landscape");
948 list = g_list_append(list, ss);
953 static int __insert_splashscreen_info(sqlite3 *db, application_x *app)
955 static const char query[] =
956 "INSERT INTO package_app_splash_screen (app_id, src, type,"
957 " orientation, indicatordisplay, operation, color_depth) "
958 "VALUES (?, ?, ?, ?, ?, ?, ?)";
966 if (app->splashscreens == NULL)
969 ss_list = __find_splashscreens(app->splashscreens);
973 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
974 if (ret != SQLITE_OK) {
975 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
979 for (tmp = ss_list; tmp; tmp = tmp->next) {
980 ss = (splashscreen_x *)tmp->data;
984 __BIND_TEXT(db, stmt, idx++, app->appid);
985 __BIND_TEXT(db, stmt, idx++, ss->src);
986 __BIND_TEXT(db, stmt, idx++, ss->type);
987 __BIND_TEXT(db, stmt, idx++, ss->orientation);
988 __BIND_TEXT(db, stmt, idx++, ss->indicatordisplay);
989 __BIND_TEXT(db, stmt, idx++, ss->operation);
990 __BIND_TEXT(db, stmt, idx++, ss->color_depth);
992 ret = sqlite3_step(stmt);
993 if (ret != SQLITE_DONE) {
994 _LOGE("step failed: %s", sqlite3_errmsg(db));
995 sqlite3_finalize(stmt);
1002 sqlite3_finalize(stmt);
1007 static void __trimfunc(GList *trim_list)
1011 GList *list = g_list_first(trim_list);
1014 trim_data = (char *)list->data;
1017 if (strcmp(trim_data, prev) == 0) {
1018 trim_list = g_list_remove(trim_list,
1020 list = g_list_first(trim_list);
1029 list = g_list_next(list);
1033 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
1035 if (a == NULL || b == NULL)
1037 if (strcmp((char *)a, (char *)b) == 0)
1039 if (strcmp((char *)a, (char *)b) < 0)
1041 if (strcmp((char *)a, (char *)b) > 0)
1046 /* TODO: refactor inserting localized info */
1047 static GList *__create_locale_list(GList *lbls, GList *lcns, GList *icns,
1048 GList *dcns, GList *aths)
1050 GList *locale = NULL;
1058 for (tmp = lbls; tmp; tmp = tmp->next) {
1059 lbl = (label_x *)tmp->data;
1063 locale = g_list_insert_sorted_with_data(
1064 locale, (gpointer)lbl->lang,
1065 __comparefunc, NULL);
1067 for (tmp = lcns; tmp; tmp = tmp->next) {
1068 lcn = (license_x *)tmp->data;
1072 locale = g_list_insert_sorted_with_data(
1073 locale, (gpointer)lcn->lang,
1074 __comparefunc, NULL);
1076 for (tmp = icns; tmp; tmp = tmp->next) {
1077 icn = (icon_x *)tmp->data;
1081 locale = g_list_insert_sorted_with_data(
1082 locale, (gpointer)icn->lang,
1083 __comparefunc, NULL);
1085 for (tmp = dcns; tmp; tmp = tmp->next) {
1086 dcn = (description_x *)tmp->data;
1090 locale = g_list_insert_sorted_with_data(
1091 locale, (gpointer)dcn->lang,
1092 __comparefunc, NULL);
1094 for (tmp = aths; tmp; tmp = tmp->next) {
1095 ath = (author_x *)tmp->data;
1099 locale = g_list_insert_sorted_with_data(
1100 locale, (gpointer)ath->lang,
1101 __comparefunc, NULL);
1107 static gint __check_icon_resolution(const char *orig_icon_path,
1108 char **new_icon_path)
1112 char *icon_filename;
1113 char modified_iconpath[BUFSIZE];
1114 char icon_path[BUFSIZE];
1118 if (orig_icon_path == NULL)
1121 ret = system_info_get_platform_int(
1122 "http://tizen.org/feature/screen.dpi", &dpi);
1123 if (ret != SYSTEM_INFO_ERROR_NONE)
1126 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
1127 dpi_path[0] = "LDPI";
1128 dpi_path[1] = "ldpi";
1129 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
1130 dpi_path[0] = "MDPI";
1131 dpi_path[1] = "mdpi";
1132 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
1133 dpi_path[0] = "HDPI";
1134 dpi_path[1] = "hdpi";
1135 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
1136 dpi_path[0] = "XHDPI";
1137 dpi_path[1] = "xhdpi";
1138 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
1139 dpi_path[0] = "XXHDPI";
1140 dpi_path[1] = "xxhdpi";
1142 _LOGE("Unidentified dpi[%d]", dpi);
1146 icon_filename = strrchr(orig_icon_path, '/');
1147 if (icon_filename == NULL)
1151 strlen(orig_icon_path) - (strlen(icon_filename) - 1),
1152 "%s", orig_icon_path);
1153 for (i = 0; i < 2; i++) {
1154 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s",
1155 icon_path, dpi_path[i], icon_filename);
1156 if (access(modified_iconpath, F_OK) != -1) {
1157 /* if exists, return modified icon path */
1158 *new_icon_path = strdup(modified_iconpath);
1166 static gint __compare_icon(gconstpointer a, gconstpointer b)
1168 icon_x *icon = (icon_x *)a;
1171 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
1174 if (icon->dpi != NULL)
1177 if (__check_icon_resolution(icon->text, &icon_path) == 0) {
1179 icon->text = icon_path;
1185 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
1187 icon_x *icon = (icon_x *)a;
1188 int dpi = GPOINTER_TO_INT(b);
1190 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
1193 if (icon->dpi == NULL)
1196 if (__check_dpi(icon->dpi, dpi) == 0)
1202 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
1204 icon_x *icon = (icon_x *)a;
1205 char *lang = (char *)b;
1208 if (icon->dpi != NULL)
1211 if (strcasecmp(icon->lang, lang) == 0) {
1212 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
1213 /* icon for no locale. check existance of
1214 * folder-hierachied default icons
1216 if (__check_icon_resolution(icon->text,
1219 icon->text = icon_path;
1228 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
1231 icon_x *icon = (icon_x *)a;
1232 char *lang = (char *)b;
1235 ret = system_info_get_platform_int(
1236 "http://tizen.org/feature/screen.dpi", &dpi);
1237 if (ret != SYSTEM_INFO_ERROR_NONE)
1240 if (strcasecmp(icon->lang, lang) == 0 &&
1241 __check_dpi(icon->dpi, dpi) == 0)
1247 static char *__find_icon(GList *icons, const char *lang)
1254 /* first, find icon whose locale and dpi with given lang and
1255 * system's dpi has matched
1257 tmp = g_list_find_custom(icons, lang,
1258 (GCompareFunc)__compare_icon_with_lang_dpi);
1260 icon = (icon_x *)tmp->data;
1261 return (char *)icon->text;
1264 /* if first has failed, find icon whose locale has matched */
1265 tmp = g_list_find_custom(icons, lang,
1266 (GCompareFunc)__compare_icon_with_lang);
1268 icon = (icon_x *)tmp->data;
1269 return (char *)icon->text;
1272 /* if second has failed, find icon whose dpi has matched with
1275 ret = system_info_get_platform_int(
1276 "http://tizen.org/feature/screen.dpi", &dpi);
1277 if (ret == SYSTEM_INFO_ERROR_NONE) {
1278 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi),
1279 (GCompareFunc)__compare_icon_with_dpi);
1281 icon = (icon_x *)tmp->data;
1282 return (char *)icon->text;
1286 /* last, find default icon marked as "No Locale" */
1287 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
1289 icon = (icon_x *)tmp->data;
1290 return (char *)icon->text;
1296 static void __extract_data(const char *locale, GList *lbls, GList *lcns,
1297 GList *icns, GList *dcns, GList *aths, char **label,
1298 char **license, char **icon, char **description, char **author)
1306 for (tmp = lbls; tmp; tmp = tmp->next) {
1307 lbl = (label_x *)tmp->data;
1311 if (strcmp(lbl->lang, locale) == 0) {
1312 *label = (char *)lbl->text;
1317 for (tmp = lcns; tmp; tmp = tmp->next) {
1318 lcn = (license_x *)tmp->data;
1322 if (strcmp(lcn->lang, locale) == 0) {
1323 *license = (char *)lcn->text;
1329 *icon = __find_icon(icns, locale);
1331 for (tmp = dcns; tmp; tmp = tmp->next) {
1332 dcn = (description_x *)tmp->data;
1336 if (strcmp(dcn->lang, locale) == 0) {
1337 *description = (char *)dcn->text;
1342 for (tmp = aths; tmp; tmp = tmp->next) {
1343 ath = (author_x *)tmp->data;
1347 if (strcmp(ath->lang, locale) == 0) {
1348 *author = (char *)ath->text;
1355 static int __insert_mainapp_localized_info(sqlite3 *db, application_x *app,
1356 const char *locale, const char *label, const char *icon)
1358 static const char query[] =
1359 "INSERT OR REPLACE INTO package_localized_info ("
1360 " package, package_locale, package_label, package_icon,"
1361 " package_description, package_license, package_author) "
1363 " COALESCE((SELECT package_label FROM package_localized_info"
1364 " WHERE package=? AND package_locale=?), ?),"
1365 " COALESCE((SELECT package_icon FROM package_localized_info"
1366 " WHERE package=? AND package_icon=?), ?),"
1367 " (SELECT package_description FROM package_localized_info"
1368 " WHERE package=? AND package_locale=?),"
1369 " (SELECT package_description FROM package_localized_info"
1370 " WHERE package=? AND package_locale=?),"
1371 " (SELECT package_description FROM package_localized_info"
1372 " WHERE package=? AND package_locale=?))";
1377 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1378 if (ret != SQLITE_OK) {
1379 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1383 __BIND_TEXT(db, stmt, idx++, app->package);
1384 __BIND_TEXT(db, stmt, idx++, locale);
1385 __BIND_TEXT(db, stmt, idx++, app->package);
1386 __BIND_TEXT(db, stmt, idx++, locale);
1387 __BIND_TEXT(db, stmt, idx++, label);
1388 __BIND_TEXT(db, stmt, idx++, app->package);
1389 __BIND_TEXT(db, stmt, idx++, locale);
1390 __BIND_TEXT(db, stmt, idx++, icon);
1391 __BIND_TEXT(db, stmt, idx++, app->package);
1392 __BIND_TEXT(db, stmt, idx++, locale);
1393 __BIND_TEXT(db, stmt, idx++, app->package);
1394 __BIND_TEXT(db, stmt, idx++, locale);
1395 __BIND_TEXT(db, stmt, idx++, app->package);
1396 __BIND_TEXT(db, stmt, idx++, locale);
1398 ret = sqlite3_step(stmt);
1399 if (ret != SQLITE_DONE) {
1400 _LOGE("step failed: %s", sqlite3_errmsg(db));
1401 sqlite3_finalize(stmt);
1405 sqlite3_finalize(stmt);
1410 static int __insert_app_localized_info(sqlite3 *db, application_x *app)
1412 static const char query[] =
1413 "INSERT INTO package_app_localized_info (app_id, app_locale,"
1414 " app_label, app_icon) "
1415 "VALUES (?, ?, ?, ?)";
1425 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1426 if (ret != SQLITE_OK) {
1427 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1431 locales = __create_locale_list(app->label, NULL, app->icon, NULL, NULL);
1432 for (tmp = locales; tmp; tmp = tmp->next) {
1433 locale = (const char *)tmp->data;
1436 __extract_data(locale, app->label, NULL, app->icon, NULL, NULL,
1437 &label, NULL, &icon, NULL, NULL);
1438 if (!label && !icon)
1442 __BIND_TEXT(db, stmt, idx++, app->appid);
1443 __BIND_TEXT(db, stmt, idx++, locale);
1444 __BIND_TEXT(db, stmt, idx++, label);
1445 __BIND_TEXT(db, stmt, idx++, icon);
1447 ret = sqlite3_step(stmt);
1448 if (ret != SQLITE_DONE) {
1449 _LOGE("step failed: %s", sqlite3_errmsg(db));
1450 g_list_free(locales);
1451 sqlite3_finalize(stmt);
1455 sqlite3_reset(stmt);
1457 if (strcasecmp(app->mainapp, "true") == 0) {
1458 if (__insert_mainapp_localized_info(db, app, locale,
1460 _LOGE("insert mainapp localized info failed");
1464 g_list_free(locales);
1465 sqlite3_finalize(stmt);
1470 static int __insert_package_privilege_info(sqlite3 *db, manifest_x *mfx)
1472 static const char query[] =
1473 "INSERT INTO package_privilege_info (package, privilege, type) "
1481 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1482 if (ret != SQLITE_OK) {
1483 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1487 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1488 priv = (privilege_x *)tmp->data;
1493 __BIND_TEXT(db, stmt, idx++, mfx->package);
1494 __BIND_TEXT(db, stmt, idx++, priv->value);
1495 __BIND_TEXT(db, stmt, idx++, priv->type);
1497 ret = sqlite3_step(stmt);
1498 if (ret != SQLITE_DONE) {
1499 _LOGE("step failed: %s", sqlite3_errmsg(db));
1500 sqlite3_finalize(stmt);
1503 sqlite3_reset(stmt);
1506 sqlite3_finalize(stmt);
1511 /* _PRODUCT_LAUNCHING_ENHANCED_
1512 * app->indicatordisplay, app->portraitimg, app->landscapeimg,
1513 * app->guestmode_appstatus
1515 static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
1517 static const char query[] =
1518 "INSERT INTO package_app_info (app_id, app_component,"
1519 " app_exec, app_nodisplay, app_type, app_onboot, app_multiple,"
1520 " app_autorestart, app_taskmanage, app_hwacceleration,"
1521 " app_screenreader, app_mainapp, app_recentimage,"
1522 " app_launchcondition, app_indicatordisplay, app_portraitimg,"
1523 " app_landscapeimg, app_guestmodevisibility,"
1524 " app_permissiontype, app_preload, app_submode,"
1525 " app_submode_mainid, app_installed_storage, app_process_pool,"
1526 " app_launch_mode, app_ui_gadget, app_support_mode,"
1527 " app_support_disable, component_type, package, app_tep_name,"
1528 " app_zip_mount_file, app_background_category,"
1529 " app_package_type, app_root_path, app_api_version,"
1530 " app_effective_appid, app_splash_screen_display,"
1531 " app_package_system, app_removable,"
1532 " app_package_installed_time, app_support_ambient,"
1533 " app_setup_appid) "
1535 " ?, LOWER(?), ?, LOWER(?), LOWER(?),"
1536 " LOWER(?), LOWER(?), ?,"
1540 " ?, LOWER(?), LOWER(?),"
1542 " COALESCE(?, 'single'), LOWER(?), ?,"
1543 " LOWER(?), ?, ?, ?,"
1547 " LOWER(?), LOWER(?),"
1556 const char *effective_appid;
1558 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1559 if (ret != SQLITE_OK) {
1560 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1564 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1565 app = (application_x *)tmp->data;
1569 bg_category = __convert_background_category(
1570 app->background_category);
1571 effective_appid = __find_effective_appid(app->metadata);
1574 __BIND_TEXT(db, stmt, idx++, app->appid);
1575 __BIND_TEXT(db, stmt, idx++, app->component_type);
1576 __BIND_TEXT(db, stmt, idx++, app->exec);
1577 __BIND_TEXT(db, stmt, idx++, __get_bool(app->nodisplay, false));
1578 __BIND_TEXT(db, stmt, idx++, app->type);
1579 __BIND_TEXT(db, stmt, idx++, __get_bool(app->onboot, false));
1580 __BIND_TEXT(db, stmt, idx++, __get_bool(app->multiple, false));
1581 __BIND_TEXT(db, stmt, idx++,
1582 __get_bool(app->autorestart, false));
1583 __BIND_TEXT(db, stmt, idx++,
1584 __get_bool(app->taskmanage, false));
1585 __BIND_TEXT(db, stmt, idx++, app->hwacceleration);
1586 __BIND_TEXT(db, stmt, idx++, app->screenreader);
1587 __BIND_TEXT(db, stmt, idx++, __get_bool(app->mainapp, false));
1588 __BIND_TEXT(db, stmt, idx++, app->recentimage);
1589 __BIND_TEXT(db, stmt, idx++, app->launchcondition);
1590 __BIND_TEXT(db, stmt, idx++,
1591 __get_bool(app->indicatordisplay, true));
1592 __BIND_TEXT(db, stmt, idx++, app->portraitimg);
1593 __BIND_TEXT(db, stmt, idx++, app->landscapeimg);
1594 __BIND_TEXT(db, stmt, idx++,
1595 __get_bool(app->guestmode_visibility, true));
1596 __BIND_TEXT(db, stmt, idx++, app->permission_type);
1597 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->preload, false));
1598 __BIND_TEXT(db, stmt, idx++, __get_bool(app->submode, false));
1599 __BIND_TEXT(db, stmt, idx++, app->submode_mainid);
1600 __BIND_TEXT(db, stmt, idx++, mfx->installed_storage);
1601 __BIND_TEXT(db, stmt, idx++,
1602 __get_bool(app->process_pool, false));
1603 __BIND_TEXT(db, stmt, idx++, app->launch_mode);
1604 __BIND_TEXT(db, stmt, idx++, __get_bool(app->ui_gadget, false));
1605 __BIND_TEXT(db, stmt, idx++, app->support_mode);
1606 __BIND_TEXT(db, stmt, idx++,
1607 __get_bool(mfx->support_disable, false));
1608 __BIND_TEXT(db, stmt, idx++, app->component_type);
1609 __BIND_TEXT(db, stmt, idx++, mfx->package);
1610 __BIND_TEXT(db, stmt, idx++, mfx->tep_name);
1611 __BIND_TEXT(db, stmt, idx++, mfx->zip_mount_file);
1612 __BIND_INT(db, stmt, idx++, bg_category);
1613 __BIND_TEXT(db, stmt, idx++, mfx->type ? mfx->type : "tpk");
1614 __BIND_TEXT(db, stmt, idx++, mfx->root_path);
1615 __BIND_TEXT(db, stmt, idx++, mfx->api_version);
1616 __BIND_TEXT(db, stmt, idx++, effective_appid);
1617 __BIND_TEXT(db, stmt, idx++,
1618 __get_bool(app->splash_screen_display, true));
1619 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->system, false));
1620 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->removable, false));
1621 __BIND_TEXT(db, stmt, idx++, mfx->installed_time);
1622 __BIND_TEXT(db, stmt, idx++,
1623 __get_bool(app->support_ambient, false));
1624 __BIND_TEXT(db, stmt, idx++, app->setup_appid);
1626 ret = sqlite3_step(stmt);
1627 if (ret != SQLITE_DONE) {
1628 _LOGE("step failed: %s", sqlite3_errmsg(db));
1629 sqlite3_finalize(stmt);
1633 sqlite3_reset(stmt);
1635 if (__insert_appcontrol_info(db, app)) {
1636 sqlite3_finalize(stmt);
1639 if (__insert_category_info(db, app)) {
1640 sqlite3_finalize(stmt);
1643 if (__insert_metadata_info(db, app)) {
1644 sqlite3_finalize(stmt);
1647 if (__insert_datacontrol_info(db, app)) {
1648 sqlite3_finalize(stmt);
1651 if (__insert_splashscreen_info(db, app)) {
1652 sqlite3_finalize(stmt);
1655 if (__insert_app_localized_info(db, app)) {
1656 sqlite3_finalize(stmt);
1661 sqlite3_finalize(stmt);
1666 static int __insert_package_update_info(sqlite3 *db, manifest_x *mfx)
1668 static const char query[] =
1669 "INSERT INTO package_update_info (package, update_version) "
1675 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1676 if (ret != SQLITE_OK) {
1677 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1682 __BIND_TEXT(db, stmt, idx++, mfx->package);
1683 __BIND_TEXT(db, stmt, idx, mfx->version);
1684 ret = sqlite3_step(stmt);
1685 if (ret != SQLITE_DONE) {
1686 _LOGE("step failed: %s", sqlite3_errmsg(db));
1687 sqlite3_finalize(stmt);
1690 sqlite3_finalize(stmt);
1695 static int __insert_package_localized_info(sqlite3 *db, manifest_x *mfx)
1697 static const char query[] =
1698 "INSERT INTO package_localized_info (package, package_locale,"
1699 " package_label, package_icon, package_description,"
1700 " package_license, package_author) "
1701 "VALUES (?, ?, ?, ?, ?, ?, ?)";
1714 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1715 if (ret != SQLITE_OK) {
1716 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1720 locales = __create_locale_list(mfx->label, mfx->license, mfx->icon,
1721 mfx->description, mfx->author);
1722 for (tmp = locales; tmp; tmp = tmp->next) {
1723 locale = (const char *)tmp->data;
1729 __extract_data(locale, mfx->label, mfx->license, mfx->icon,
1730 mfx->description, mfx->author,
1731 &label, &license, &icon, &description, &author);
1732 if (!label && !license && !icon && !description && !author)
1736 __BIND_TEXT(db, stmt, idx++, mfx->package);
1737 __BIND_TEXT(db, stmt, idx++, locale);
1738 __BIND_TEXT(db, stmt, idx++, label);
1739 __BIND_TEXT(db, stmt, idx++, icon);
1740 __BIND_TEXT(db, stmt, idx++, description);
1741 __BIND_TEXT(db, stmt, idx++, license);
1742 __BIND_TEXT(db, stmt, idx++, author);
1744 ret = sqlite3_step(stmt);
1745 if (ret != SQLITE_DONE) {
1746 _LOGE("step failed: %s", sqlite3_errmsg(db));
1747 g_list_free(locales);
1748 sqlite3_finalize(stmt);
1752 sqlite3_reset(stmt);
1755 g_list_free(locales);
1756 sqlite3_finalize(stmt);
1761 static int __insert_package_info(sqlite3 *db, manifest_x *mfx)
1763 static const char query[] =
1764 "INSERT INTO package_info (package, package_type,"
1765 " package_version, package_api_version, package_tep_name,"
1766 " package_zip_mount_file, install_location, package_size,"
1767 " package_removable, package_preload, package_readonly,"
1768 " package_update, package_appsetting, package_nodisplay,"
1769 " package_system, author_name, author_email, author_href,"
1770 " installed_time, installed_storage, storeclient_id,"
1771 " mainapp_id, package_url, root_path, external_path,"
1772 " csc_path, package_support_mode, package_support_disable) "
1776 " LOWER(?), LOWER(?), LOWER(?),"
1777 " LOWER(?), LOWER(?), LOWER(?),"
1778 " LOWER(?), ?, ?, ?,"
1785 const char *author_name = NULL;
1786 const char *author_email = NULL;
1787 const char *author_href = NULL;
1789 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1790 if (ret != SQLITE_OK) {
1791 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1795 if (mfx->author && mfx->author->data) {
1796 author_name = ((author_x *)mfx->author->data)->text;
1797 author_email = ((author_x *)mfx->author->data)->email;
1798 author_href = ((author_x *)mfx->author->data)->href;
1801 __BIND_TEXT(db, stmt, idx++, mfx->package);
1802 __BIND_TEXT(db, stmt, idx++, mfx->type);
1803 __BIND_TEXT(db, stmt, idx++, mfx->version);
1804 __BIND_TEXT(db, stmt, idx++, mfx->api_version);
1805 __BIND_TEXT(db, stmt, idx++, mfx->tep_name);
1806 __BIND_TEXT(db, stmt, idx++, mfx->zip_mount_file);
1807 __BIND_TEXT(db, stmt, idx++, mfx->installlocation);
1808 __BIND_TEXT(db, stmt, idx++, mfx->package_size);
1809 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->removable, true));
1810 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->preload, false));
1811 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->readonly, false));
1812 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->update, false));
1813 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->appsetting, false));
1814 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->nodisplay_setting, false));
1815 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->system, false));
1816 __BIND_TEXT(db, stmt, idx++, author_name);
1817 __BIND_TEXT(db, stmt, idx++, author_email);
1818 __BIND_TEXT(db, stmt, idx++, author_href);
1819 __BIND_TEXT(db, stmt, idx++, mfx->installed_time);
1820 __BIND_TEXT(db, stmt, idx++, mfx->installed_storage);
1821 __BIND_TEXT(db, stmt, idx++, mfx->storeclient_id);
1822 __BIND_TEXT(db, stmt, idx++, mfx->mainapp_id);
1823 __BIND_TEXT(db, stmt, idx++, mfx->package_url);
1824 __BIND_TEXT(db, stmt, idx++, mfx->root_path);
1825 __BIND_TEXT(db, stmt, idx++, mfx->external_path);
1826 __BIND_TEXT(db, stmt, idx++, mfx->csc_path);
1827 __BIND_TEXT(db, stmt, idx++, mfx->support_mode);
1828 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->support_disable, false));
1830 ret = sqlite3_step(stmt);
1831 if (ret != SQLITE_DONE) {
1832 _LOGE("step failed: %s", sqlite3_errmsg(db));
1833 sqlite3_finalize(stmt);
1837 sqlite3_finalize(stmt);
1839 if (__insert_package_update_info(db, mfx))
1841 if (__insert_package_localized_info(db, mfx))
1843 if (__insert_application_info(db, mfx))
1845 if (__insert_package_privilege_info(db, mfx))
1851 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
1858 _LOGE("invalid parameter");
1859 return PM_PARSER_R_EINVAL;
1862 dbpath = __get_parser_db_path(uid);
1864 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
1865 if (ret != SQLITE_OK) {
1866 _LOGE("open db failed: %d", ret);
1867 return PM_PARSER_R_ERROR;
1870 __BEGIN_TRANSACTION(db);
1871 __DO_TRANSACTION(db, __insert_package_info(db, mfx));
1872 __END_TRANSACTION(db);
1874 sqlite3_close_v2(db);
1876 return PM_PARSER_R_OK;
1879 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
1881 return pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, __getuid());
1884 static int __delete_package_info(sqlite3 *db, const char *pkgid)
1886 static const char query[] =
1887 "DELETE FROM package_info WHERE package=?";
1891 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1892 if (ret != SQLITE_OK) {
1893 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1897 __BIND_TEXT(db, stmt, 1, pkgid);
1899 ret = sqlite3_step(stmt);
1900 if (ret != SQLITE_DONE) {
1901 _LOGE("step failed: %s", sqlite3_errmsg(db));
1902 sqlite3_finalize(stmt);
1906 sqlite3_finalize(stmt);
1911 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx,
1919 _LOGE("invalid parameter");
1920 return PM_PARSER_R_EINVAL;
1923 dbpath = __get_parser_db_path(uid);
1925 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
1926 if (ret != SQLITE_OK) {
1927 _LOGE("open db failed: %d", ret);
1928 return PM_PARSER_R_ERROR;
1931 __BEGIN_TRANSACTION(db);
1932 __DO_TRANSACTION(db, __delete_package_info(db, mfx->package));
1933 __END_TRANSACTION(db);
1935 sqlite3_close_v2(db);
1937 return PM_PARSER_R_OK;
1940 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
1942 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, __getuid());
1945 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
1952 _LOGE("invalid parameter");
1953 return PM_PARSER_R_EINVAL;
1956 dbpath = __get_parser_db_path(uid);
1958 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
1959 if (ret != SQLITE_OK) {
1960 _LOGE("open db failed: %d", ret);
1961 return PM_PARSER_R_ERROR;
1964 __BEGIN_TRANSACTION(db);
1965 __DO_TRANSACTION(db, __delete_package_info(db, mfx->package));
1966 __DO_TRANSACTION(db, __insert_package_info(db, mfx));
1967 __END_TRANSACTION(db);
1969 sqlite3_close_v2(db);
1971 return PM_PARSER_R_OK;
1974 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
1976 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, __getuid());
1979 static int __set_global_app_disable_for_uid(sqlite3 *db, const char *appid,
1980 uid_t uid, bool is_disable)
1982 static const char query[] =
1983 "INSERT OR REPLACE INTO package_app_info_for_uid ("
1984 " app_id, uid, is_disabled, is_splash_screen_enabled) "
1986 " (SELECT app_splash_screen_display FROM package_app_info"
1987 " WHERE app_id=?))";
1992 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1993 if (ret != SQLITE_OK) {
1994 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1998 __BIND_TEXT(db, stmt, idx++, appid);
1999 __BIND_INT(db, stmt, idx++, uid);
2000 __BIND_TEXT(db, stmt, idx++, is_disable ? "true" : "false");
2001 __BIND_TEXT(db, stmt, idx++, appid);
2003 ret = sqlite3_step(stmt);
2004 if (ret != SQLITE_DONE) {
2005 _LOGE("step failed: %s", sqlite3_errmsg(db));
2006 sqlite3_finalize(stmt);
2010 sqlite3_finalize(stmt);
2015 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(
2016 const char *appid, uid_t uid, int is_disable)
2022 if (appid == NULL) {
2023 _LOGE("invalid parameter");
2024 return PM_PARSER_R_EINVAL;
2027 dbpath = __get_parser_db_path(GLOBAL_USER);
2029 ret = __open_db(GLOBAL_USER, dbpath, &db, SQLITE_OPEN_READWRITE);
2030 if (ret != SQLITE_OK) {
2031 _LOGE("open db failed: %d", ret);
2032 return PM_PARSER_R_ERROR;
2035 __BEGIN_TRANSACTION(db);
2036 __DO_TRANSACTION(db, __set_global_app_disable_for_uid(db, appid,
2037 uid, (bool)is_disable));
2038 __END_TRANSACTION(db);
2040 sqlite3_close_v2(db);
2042 return PM_PARSER_R_OK;
2045 static int __set_app_disable(sqlite3 *db, const char *appid, uid_t uid,
2048 static const char query[] =
2049 "UPDATE package_app_info SET app_disable=? "
2055 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2056 if (ret != SQLITE_OK) {
2057 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2061 __BIND_TEXT(db, stmt, idx++, is_disable ? "true" : "false");
2062 __BIND_TEXT(db, stmt, idx++, appid);
2064 ret = sqlite3_step(stmt);
2065 if (ret != SQLITE_DONE) {
2066 _LOGE("step failed: %s", sqlite3_errmsg(db));
2067 sqlite3_finalize(stmt);
2071 sqlite3_finalize(stmt);
2076 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid,
2077 uid_t uid, int is_disable)
2083 if (appid == NULL) {
2084 _LOGE("invalid parameter");
2085 return PM_PARSER_R_EINVAL;
2088 dbpath = __get_parser_db_path(uid);
2090 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2091 if (ret != SQLITE_OK) {
2092 _LOGE("open db failed: %d", ret);
2093 return PM_PARSER_R_ERROR;
2096 __BEGIN_TRANSACTION(db);
2097 __DO_TRANSACTION(db, __set_app_disable(db, appid, uid,
2099 __END_TRANSACTION(db);
2101 sqlite3_close_v2(db);
2103 return PM_PARSER_R_OK;
2106 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid,
2109 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid,
2110 __getuid(), is_disable);
2113 static int __set_pkg_disable(sqlite3 *db, const char *pkgid, uid_t uid,
2116 static const char query[] =
2117 "UPDATE package_info SET package_disable=? "
2123 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2124 if (ret != SQLITE_OK) {
2125 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2129 __BIND_TEXT(db, stmt, idx++, is_disable ? "true" : "false");
2130 __BIND_TEXT(db, stmt, idx++, pkgid);
2132 ret = sqlite3_step(stmt);
2133 if (ret != SQLITE_DONE) {
2134 _LOGE("step failed: %s", sqlite3_errmsg(db));
2135 sqlite3_finalize(stmt);
2139 sqlite3_finalize(stmt);
2144 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid,
2145 uid_t uid, int is_disable)
2151 if (pkgid == NULL) {
2152 _LOGE("invalid parameter");
2153 return PM_PARSER_R_EINVAL;
2156 dbpath = __get_parser_db_path(uid);
2158 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2159 if (ret != SQLITE_OK) {
2160 _LOGE("open db failed: %d", ret);
2161 return PM_PARSER_R_ERROR;
2164 __BEGIN_TRANSACTION(db);
2165 __DO_TRANSACTION(db, __set_pkg_disable(db, pkgid, uid,
2167 __END_TRANSACTION(db);
2169 sqlite3_close_v2(db);
2171 return PM_PARSER_R_OK;
2174 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid,
2177 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid,
2178 __getuid(), is_disable);
2181 static int __set_global_app_splash_screen_for_uid(sqlite3 *db,
2182 const char *appid, uid_t uid, bool is_enabled)
2184 static const char query[] =
2185 "INSERT OR REPLACE INTO package_app_info_for_uid("
2186 " appid, uid, is_splash_screen_enabled) "
2192 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2193 if (ret != SQLITE_OK) {
2194 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2198 __BIND_TEXT(db, stmt, idx++, appid);
2199 __BIND_INT(db, stmt, idx++, uid);
2200 __BIND_TEXT(db, stmt, idx++, is_enabled ? "true" : "false");
2202 ret = sqlite3_step(stmt);
2203 if (ret != SQLITE_DONE) {
2204 _LOGE("step failed: %s", sqlite3_errmsg(db));
2205 sqlite3_finalize(stmt);
2209 sqlite3_finalize(stmt);
2214 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(
2215 const char *appid, uid_t uid, int flag)
2221 if (appid == NULL) {
2222 _LOGE("invalid parameter");
2223 return PM_PARSER_R_EINVAL;
2226 dbpath = __get_parser_db_path(GLOBAL_USER);
2228 ret = __open_db(GLOBAL_USER, dbpath, &db, SQLITE_OPEN_READWRITE);
2229 if (ret != SQLITE_OK) {
2230 _LOGE("open db failed: %d", ret);
2231 return PM_PARSER_R_ERROR;
2234 __BEGIN_TRANSACTION(db);
2235 __DO_TRANSACTION(db, __set_global_app_splash_screen_for_uid(db,
2236 appid, uid, (bool)flag));
2237 __END_TRANSACTION(db);
2239 sqlite3_close_v2(db);
2241 return PM_PARSER_R_OK;
2244 static int __set_app_splash_screen(sqlite3 *db, const char *appid,
2247 static const char query[] =
2248 "UPDATE package_app_info SET app_splash_screen_display=? "
2254 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2255 if (ret != SQLITE_OK) {
2256 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2260 __BIND_TEXT(db, stmt, idx++, is_enabled ? "true" : "false");
2261 __BIND_TEXT(db, stmt, idx++, appid);
2263 ret = sqlite3_step(stmt);
2264 if (ret != SQLITE_DONE) {
2265 _LOGE("step failed: %s", sqlite3_errmsg(db));
2266 sqlite3_finalize(stmt);
2270 sqlite3_finalize(stmt);
2275 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(
2276 const char *appid, uid_t uid, int flag)
2282 if (appid == NULL) {
2283 _LOGE("invalid parameter");
2284 return PM_PARSER_R_EINVAL;
2287 dbpath = __get_parser_db_path(uid);
2289 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2290 if (ret != SQLITE_OK) {
2291 _LOGE("open db failed: %d", ret);
2292 return PM_PARSER_R_ERROR;
2295 __BEGIN_TRANSACTION(db);
2296 __DO_TRANSACTION(db, __set_app_splash_screen(db, appid, (bool)flag));
2297 __END_TRANSACTION(db);
2299 sqlite3_close_v2(db);
2301 return PM_PARSER_R_OK;
2304 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(
2305 const char *appid, int flag)
2307 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(
2308 appid, __getuid(), flag);
2311 static int __set_app_label(sqlite3 *db, const char *appid, const char *label)
2313 static const char query[] =
2314 "UPDATE package_app_localized_info SET app_label=? "
2315 "WHERE app_id=? AND app_label IS NOT NULL";
2320 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2321 if (ret != SQLITE_OK) {
2322 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2326 __BIND_TEXT(db, stmt, idx++, label);
2327 __BIND_TEXT(db, stmt, idx++, appid);
2329 ret = sqlite3_step(stmt);
2330 if (ret != SQLITE_DONE) {
2331 _LOGE("step failed: %s", sqlite3_errmsg(db));
2332 sqlite3_finalize(stmt);
2336 sqlite3_finalize(stmt);
2341 API int pkgmgr_parser_update_app_label_info_in_usr_db(const char *appid,
2342 uid_t uid, const char *label)
2348 if (appid == NULL) {
2349 _LOGE("invalid parameter");
2350 return PM_PARSER_R_EINVAL;
2353 dbpath = __get_parser_db_path(uid);
2355 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2356 if (ret != SQLITE_OK) {
2357 _LOGE("open db failed: %d", ret);
2358 return PM_PARSER_R_ERROR;
2361 __BEGIN_TRANSACTION(db);
2362 __DO_TRANSACTION(db, __set_app_label(db, appid, label));
2363 __END_TRANSACTION(db);
2365 sqlite3_close_v2(db);
2367 return PM_PARSER_R_OK;
2370 API int pkgmgr_parser_update_app_label_info_in_db(const char *appid,
2373 return pkgmgr_parser_update_app_label_info_in_usr_db(appid, __getuid(),
2377 static int __set_tep_path(sqlite3 *db, const char *pkgid, const char *tep_path)
2379 static const char query[] =
2380 "UPDATE package_info SET package_tep_name=? "
2386 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2387 if (ret != SQLITE_OK) {
2388 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2392 __BIND_TEXT(db, stmt, idx++, tep_path);
2393 __BIND_TEXT(db, stmt, idx++, pkgid);
2395 ret = sqlite3_step(stmt);
2396 if (ret != SQLITE_DONE) {
2397 _LOGE("step failed: %s", sqlite3_errmsg(db));
2398 sqlite3_finalize(stmt);
2402 sqlite3_finalize(stmt);
2407 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid,
2408 const char *tep_path, uid_t uid)
2414 if (pkgid == NULL) {
2415 _LOGE("invalid parameter");
2416 return PM_PARSER_R_EINVAL;
2419 dbpath = __get_parser_db_path(uid);
2421 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2422 if (ret != SQLITE_OK) {
2423 _LOGE("open db failed: %d", ret);
2424 return PM_PARSER_R_ERROR;
2427 __BEGIN_TRANSACTION(db);
2428 __DO_TRANSACTION(db, __set_tep_path(db, pkgid, tep_path));
2429 __END_TRANSACTION(db);
2431 sqlite3_close_v2(db);
2433 return PM_PARSER_R_OK;
2436 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid,
2437 const char *tep_path)
2439 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path,
2443 static int __convert_update_type(pkgmgrinfo_updateinfo_update_type type,
2444 const char **update_type)
2446 if (type == PMINFO_UPDATEINFO_NONE)
2447 *update_type = PMINFO_UPDATEINFO_TYPE_NONE;
2448 else if (type == PMINFO_UPDATEINFO_FORCE)
2449 *update_type = PMINFO_UPDATEINFO_TYPE_FORCE;
2450 else if (type == PMINFO_UPDATEINFO_OPTIONAL)
2451 *update_type = PMINFO_UPDATEINFO_TYPE_OPTIONAL;
2457 static int __register_pkg_update_info(sqlite3 *db, updateinfo_x *info,
2458 const char *update_type)
2460 static const char query[] =
2461 "UPDATE package_update_info "
2462 "SET update_version=?, update_type=? "
2468 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2469 if (ret != SQLITE_OK) {
2470 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2474 __BIND_TEXT(db, stmt, idx++, info->version);
2475 __BIND_TEXT(db, stmt, idx++, update_type);
2476 __BIND_TEXT(db, stmt, idx++, info->pkgid);
2478 ret = sqlite3_step(stmt);
2479 if (ret != SQLITE_DONE) {
2480 _LOGE("step failed: %s", sqlite3_errmsg(db));
2481 sqlite3_finalize(stmt);
2485 sqlite3_finalize(stmt);
2490 API int pkgmgr_parser_register_pkg_update_info_in_usr_db(
2491 pkgmgrinfo_updateinfo_h handle, uid_t uid)
2494 updateinfo_x *update_info;
2495 updateinfo_x *prev_update_info;
2496 pkgmgrinfo_updateinfo_h prev_update_handle;
2497 pkgmgrinfo_pkginfo_h pkginfo;
2498 pkgmgrinfo_version_compare_type compare_result;
2500 const char *update_type;
2504 if (handle == NULL) {
2505 _LOGE("invalid parameter");
2506 return PM_PARSER_R_EINVAL;
2509 update_info = (updateinfo_x *)handle;
2510 if (update_info->pkgid == NULL || update_info->version == NULL)
2511 return PM_PARSER_R_EINVAL;
2512 if (__convert_update_type(update_info->type, &update_type) != 0)
2513 return PM_PARSER_R_EINVAL;
2515 ret = pkgmgrinfo_updateinfo_get_usr_updateinfo(update_info->pkgid,
2516 &prev_update_handle, uid);
2517 if (ret != PMINFO_R_OK)
2518 return PM_PARSER_R_ERROR;
2520 prev_update_info = (updateinfo_x *)prev_update_handle;
2521 ret = pkgmgrinfo_compare_package_version(update_info->version,
2522 prev_update_info->version, &compare_result);
2523 if (ret != PMINFO_R_OK) {
2524 pkgmgrinfo_updateinfo_destroy(prev_update_handle);
2525 return PM_PARSER_R_ERROR;
2528 if (compare_result == PMINFO_VERSION_SAME &&
2529 prev_update_info->type == PMINFO_UPDATEINFO_NONE) {
2530 _LOGI("Given update info version[%s] of pkgid[%s] "
2532 update_info->version, update_info->pkgid);
2533 pkgmgrinfo_updateinfo_destroy(prev_update_handle);
2534 return PM_PARSER_R_OK;
2536 pkgmgrinfo_updateinfo_destroy(prev_update_handle);
2538 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(update_info->pkgid, uid,
2540 if (ret != PMINFO_R_OK)
2541 return PM_PARSER_R_ERROR;
2543 ret = pkgmgrinfo_pkginfo_is_global(pkginfo, &is_global_pkg);
2544 if (ret != PMINFO_R_OK) {
2545 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
2546 return PM_PARSER_R_ERROR;
2548 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
2550 dbpath = __get_parser_db_path(is_global_pkg ? GLOBAL_USER : uid);
2552 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2553 if (ret != SQLITE_OK) {
2554 _LOGE("open db failed: %d", ret);
2555 return PM_PARSER_R_ERROR;
2558 __BEGIN_TRANSACTION(db);
2559 __DO_TRANSACTION(db, __register_pkg_update_info(db, update_info,
2561 __END_TRANSACTION(db);
2563 sqlite3_close_v2(db);
2565 return PM_PARSER_R_OK;
2568 API int pkgmgr_parser_register_pkg_update_info_in_db(
2569 pkgmgrinfo_updateinfo_h handle)
2571 return pkgmgr_parser_register_pkg_update_info_in_usr_db(handle,
2575 static int __unregister_pkg_update_info(sqlite3 *db, const char *pkgid)
2577 static const char query[] =
2578 "UPDATE package_update_info SET update_type='none' "
2584 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2585 if (ret != SQLITE_OK) {
2586 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2590 __BIND_TEXT(db, stmt, idx++, pkgid);
2592 ret = sqlite3_step(stmt);
2593 if (ret != SQLITE_DONE) {
2594 _LOGE("step failed: %s", sqlite3_errmsg(db));
2595 sqlite3_finalize(stmt);
2599 sqlite3_finalize(stmt);
2604 API int pkgmgr_parser_unregister_pkg_update_info_in_usr_db(const char *pkgid,
2610 pkgmgrinfo_pkginfo_h pkginfo;
2613 if (pkgid == NULL) {
2614 _LOGE("invalid parameter");
2615 return PM_PARSER_R_EINVAL;
2618 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &pkginfo);
2619 if (ret != PMINFO_R_OK)
2620 return PM_PARSER_R_EINVAL;
2622 ret = pkgmgrinfo_pkginfo_is_global(pkginfo, &is_global_pkg);
2623 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
2624 if (ret != PMINFO_R_OK)
2625 return PM_PARSER_R_ERROR;
2627 dbpath = __get_parser_db_path(is_global_pkg ? GLOBAL_USER : uid);
2629 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2630 if (ret != SQLITE_OK) {
2631 _LOGE("open db failed: %d", ret);
2632 return PM_PARSER_R_ERROR;
2635 __BEGIN_TRANSACTION(db);
2636 __DO_TRANSACTION(db, __unregister_pkg_update_info(db, pkgid));
2637 __END_TRANSACTION(db);
2639 sqlite3_close_v2(db);
2641 return PM_PARSER_R_OK;
2644 API int pkgmgr_parser_unregister_pkg_update_info_in_db(const char *pkgid)
2646 return pkgmgr_parser_unregister_pkg_update_info_in_usr_db(pkgid,
2650 static int __unregister_all_pkg_update_info(sqlite3 *db)
2652 static const char query[] =
2653 "UPDATE package_update_info SET update_type='none'";
2657 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2658 if (ret != SQLITE_OK) {
2659 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2663 ret = sqlite3_step(stmt);
2664 if (ret != SQLITE_DONE) {
2665 _LOGE("step failed: %s", sqlite3_errmsg(db));
2666 sqlite3_finalize(stmt);
2670 sqlite3_finalize(stmt);
2675 API int pkgmgr_parser_unregister_all_pkg_update_info_in_usr_db(uid_t uid)
2681 dbpath = __get_parser_db_path(uid);
2683 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2684 if (ret != SQLITE_OK) {
2685 _LOGE("open db failed: %d", ret);
2686 return PM_PARSER_R_ERROR;
2689 __BEGIN_TRANSACTION(db);
2690 __DO_TRANSACTION(db, __unregister_all_pkg_update_info(db));
2691 __END_TRANSACTION(db);
2693 sqlite3_close_v2(db);
2695 return PM_PARSER_R_OK;
2698 API int pkgmgr_parser_unregister_all_pkg_update_info_in_db(void)
2700 return pkgmgr_parser_unregister_all_pkg_update_info_in_usr_db(