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>
33 #include <tzplatform_config.h>
34 #include <system_info.h>
36 #include "pkgmgr-info.h"
37 #include "pkgmgrinfo_basic.h"
38 #include "pkgmgr_parser.h"
39 #include "pkgmgr_parser_db_queries.h"
40 #include "pkgmgr_parser_debug.h"
41 #include "pkgmgr_parser_internal.h"
47 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
50 #define APPFW_USER "app_fw"
59 #define XXHDPI "xxhdpi"
69 #define XXHDPI_MIN 481
70 #define XXHDPI_MAX 600
72 /* app background category value */
73 #define APP_BG_CATEGORY_USER_DISABLE_FALSE_VAL 0x00000
74 #define APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL 0x00001
75 #define APP_BG_CATEGORY_MEDIA_VAL 0x00002
76 #define APP_BG_CATEGORY_DOWNLOAD_VAL 0x00004
77 #define APP_BG_CATEGORY_BGNETWORK_VAL 0x00008
78 #define APP_BG_CATEGORY_LOCATION_VAL 0x00010
79 #define APP_BG_CATEGORY_SENSOR_VAL 0x00020
80 #define APP_BG_CATEGORY_IOTCOMM_VAL 0x00040
81 #define APP_BG_CATEGORY_SYSTEM_VAL 0x00080
83 #define APP_BG_CATEGORY_USER_DISABLE_FALSE_STR "enable"
84 #define APP_BG_CATEGORY_USER_DISABLE_TRUE_STR "disable"
85 #define APP_BG_CATEGORY_MEDIA_STR "media"
86 #define APP_BG_CATEGORY_DOWNLOAD_STR "download"
87 #define APP_BG_CATEGORY_BGNETWORK_STR "background-network"
88 #define APP_BG_CATEGORY_LOCATION_STR "location"
89 #define APP_BG_CATEGORY_SENSOR_STR "sensor"
90 #define APP_BG_CATEGORY_IOTCOMM_STR "iot-communication"
91 #define APP_BG_CATEGORY_SYSTEM "system"
93 #define REGULAR_USER 5000
94 static inline uid_t __getuid(void)
98 if (uid < REGULAR_USER)
99 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
104 static const char *__get_bool(char *value, bool is_true)
107 if (!strcmp(value, ""))
108 return (is_true) ? "true" : "false";
112 return (is_true) ? "true" : "false";
115 #define __BEGIN_TRANSACTION(db) \
117 if (sqlite3_exec(db, "BEGIN DEFERRED", NULL, NULL, NULL) != \
119 _LOGE("begin transaction failed: %s", sqlite3_errmsg(db)); \
120 sqlite3_close_v2(db); \
121 return PM_PARSER_R_ERROR; \
125 #define __DO_TRANSACTION(db, func) \
128 _LOGE("transaction failed: %s, rollback", sqlite3_errmsg(db)); \
129 if (sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL) != \
131 _LOGE("roll back transaction failed: %s", \
132 sqlite3_errmsg(db)); \
133 sqlite3_close_v2(db); \
134 return PM_PARSER_R_ERROR; \
138 #define __END_TRANSACTION(db) \
140 if (sqlite3_exec(db, "COMMIT", NULL, NULL, NULL) != \
142 _LOGE("commit failed: %s, rollback", sqlite3_errmsg(db)); \
143 if (sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL) != \
145 _LOGE("roll back transaction failed: %s", \
146 sqlite3_errmsg(db)); \
147 sqlite3_close_v2(db); \
148 return PM_PARSER_R_ERROR; \
152 #define __BIND_TEXT(db, stmt, i, text) \
154 if (sqlite3_bind_text(stmt, i, text, -1, SQLITE_STATIC) != SQLITE_OK) {\
155 _LOGE("bind error(index %d): %s", i, sqlite3_errmsg(db)); \
156 sqlite3_finalize(stmt); \
161 #define __BIND_INT(db, stmt, i, int) \
163 if (sqlite3_bind_int(stmt, i, int) != SQLITE_OK) { \
164 _LOGE("bind error(index %d): %s", i, sqlite3_errmsg(db)); \
165 sqlite3_finalize(stmt); \
170 static const char *__get_parser_db_path(uid_t uid)
175 if (uid == GLOBAL_USER || uid == OWNER_ROOT) {
176 path = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
178 snprintf(buf, sizeof(buf), "user/%d/.pkgmgr_parser.db", uid);
179 path = tzplatform_mkpath(TZ_SYS_DB, buf);
185 static const char *__get_cert_db_path(void)
187 return tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
190 #define DB_VERSION_PATH SYSCONFDIR "/package-manager/pkg_db_version.txt"
191 static int __set_db_version(sqlite3 *db)
195 char version[PKG_STRING_LEN_MAX] = { 0 };
198 fp = fopen(DB_VERSION_PATH, "r");
199 retvm_if(fp == NULL, -1, "Failed to open db version file");
200 if (fgets(version, sizeof(version), fp) == NULL) {
201 _LOGE("Failed to get version information");
207 query = sqlite3_mprintf("PRAGMA user_version=%Q", version);
209 _LOGE("Out of memory");
213 ret = sqlite3_exec(db, query, NULL, NULL, NULL);
214 if (ret != SQLITE_OK) {
215 _LOGE("exec failed: %s", sqlite3_errmsg(db));
224 /* TODO: Do not labeling directly */
225 #define DB_LABEL "User::Home"
226 #define SET_SMACK_LABEL(x) \
228 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
229 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
231 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
234 static int __set_db_permission(const char *path, uid_t uid)
237 const char *files[2];
238 char journal_file[BUFSIZE];
242 struct passwd *result;
247 if (getuid() != OWNER_ROOT)
250 if (uid == OWNER_ROOT || uid == GLOBAL_USER) {
251 ret = getpwnam_r(APPFW_USER, &pwd, buf, sizeof(buf), &result);
252 if (result == NULL) {
254 _LOGE("no such user: %d", uid);
256 _LOGE("getpwuid_r failed: %d", errno);
262 snprintf(journal_file, sizeof(journal_file), "%s-journal", path);
264 files[1] = journal_file;
266 ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &result);
267 if (result == NULL) {
269 _LOGE("no such user: %d", uid);
271 _LOGE("getpwuid_r failed: %d", errno);
275 for (i = 0; i < 2; i++) {
276 fd = open(files[i], O_RDONLY);
278 _LOGE("open %s failed: %d", files[i], errno);
281 ret = fstat(fd, &sb);
283 _LOGE("stat %s failed: %d", files[i], errno);
287 if (S_ISLNK(sb.st_mode)) {
288 _LOGE("%s is symlink!", files[i]);
292 ret = fchown(fd, uid, pwd.pw_gid);
294 _LOGE("fchown %s failed: %d", files[i], errno);
299 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
300 if (!strcmp(path, __get_cert_db_path()))
302 ret = fchmod(fd, mode);
304 _LOGD("fchmod %s failed: %d", files[i], errno);
309 SET_SMACK_LABEL(files[i]);
315 static const char *parser_init_queries[] = {
316 QUERY_CREATE_TABLE_PACKAGE_INFO,
317 QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO,
318 QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO,
319 QUERY_CREATE_TABLE_PACKAGE_APPDEFINED_PRIVILEGE_INFO,
320 QUERY_CREATE_TABLE_PACKAGE_UPDATE_INFO,
321 QUERY_CREATE_TABLE_PACKAGE_APP_INFO,
322 QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO,
323 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL,
324 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL_PRIVILEGE,
325 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY,
326 QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA,
327 QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL,
328 QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL_PRIVILEGE,
329 QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID,
330 QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID,
331 QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN,
332 QUERY_CREATE_TABLE_PACKAGE_DEPENDENCY_INFO,
333 QUERY_CREATE_TABLE_PACKAGE_PLUGIN_INFO,
334 QUERY_CREATE_TABLE_PACKAGE_APP_COMPONENT_INFO,
338 static const char *cert_init_queries[] = {
339 QUERY_CREATE_TABLE_PACKAGE_CERT_INFO,
340 QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO,
341 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO,
342 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2,
343 QUERY_CREATE_TRIGGER_DELETE_CERT_INFO,
344 QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO,
348 static int __create_tables(sqlite3 *db, const char **queries)
352 for (i = 0; queries[i] != NULL; i++) {
353 ret = sqlite3_exec(db, queries[i], NULL, NULL, NULL);
354 if (ret != SQLITE_OK) {
355 _LOGE("exec failed: %s", sqlite3_errmsg(db));
362 static int __initialize_db(sqlite3 *db, const char *dbpath, uid_t uid)
364 const char **queries;
366 if (__set_db_version(db))
369 if (strstr(dbpath, ".pkgmgr_parser.db")) {
370 queries = parser_init_queries;
371 } else if (strstr(dbpath, ".pkgmgr_cert.db")) {
372 queries = cert_init_queries;
374 _LOGE("unexpected dbpath: %s", dbpath);
378 __BEGIN_TRANSACTION(db);
379 __DO_TRANSACTION(db, __create_tables(db, queries));
380 __END_TRANSACTION(db);
382 if (__set_db_permission(dbpath, uid))
383 _LOGE("failed to set db permission");
388 #define RESOURCED_BUS_NAME "org.tizen.resourced"
389 #define RESOURCED_PROC_PATH "/Org/Tizen/ResourceD/Process"
390 #define RESOURCED_PROC_INTERFACE "org.tizen.resourced.process"
391 #define RESOURCED_PROC_METHOD "ProcExclude"
392 static void __send_wakeup_signal_to_resourced(pid_t pid)
394 GError *error = NULL;
395 GDBusConnection *conn;
399 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
401 _LOGE("Failed to connect to dbus: %s", error->message);
406 proxy = g_dbus_proxy_new_sync(conn,
407 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
408 NULL, RESOURCED_BUS_NAME,
409 RESOURCED_PROC_PATH, RESOURCED_PROC_INTERFACE,
412 _LOGE("failed to get proxy object: %s", error->message);
414 g_object_unref(conn);
418 reply = g_dbus_proxy_call_sync(proxy, RESOURCED_PROC_METHOD,
419 g_variant_new("(si)", "wakeup", pid),
420 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
422 _LOGE("failed to get reply from resourced");
424 _LOGE("failed to send request: %s", error->message);
428 g_object_unref(proxy);
429 g_object_unref(conn);
432 static void __check_db_lock(const char *dbpath)
441 char cmdline[BUFSIZE];
445 if (stat(dbpath, &sb) == -1) {
446 _LOGE("get db file(%s) status failed: %d", dbpath, errno);
450 fp = fopen("/proc/locks", "r");
452 _LOGE("Failed to open lock info: %d", errno);
456 while (fscanf(fp, "%*s %*s %*s %*s %d %x:%x:%lu %*s %*s",
457 &pid, &maj, &min, &ino) != EOF) {
458 if (maj != major(sb.st_dev) || min != minor(sb.st_dev) ||
459 ino != sb.st_ino || pid == getpid())
462 snprintf(cmdline, sizeof(cmdline), "/proc/%d/cmdline", pid);
463 fp_cmdline = fopen(cmdline, "r");
465 if (fp_cmdline != NULL) {
466 len = fread(name, sizeof(char), sizeof(name) - 1,
469 if (name[len - 1] == '\n')
470 name[len - 1] = '\0';
477 _LOGE("%s (%d) has lock on pkgmgr db(%s)!", name, pid, dbpath);
478 __send_wakeup_signal_to_resourced(pid);
484 #define BUSY_WAITING_USEC (1000000 / 10 / 2) /* 0.05 sec */
485 #define BUSY_WAITING_MAX 40 /* wait for max 2 sec */
486 static int __db_busy_handler(void *data, int count)
488 if (count < (BUSY_WAITING_MAX / 2)) {
489 usleep(BUSY_WAITING_USEC);
491 } else if (count == (BUSY_WAITING_MAX / 2)) {
492 __check_db_lock((const char *)data);
493 usleep(BUSY_WAITING_USEC);
495 } else if (count < BUSY_WAITING_MAX) {
496 usleep(BUSY_WAITING_USEC);
499 /* sqlite3_prepare_v2 will return SQLITE_BUSY */
504 API int pkgmgr_parser_initialize_parser_db(uid_t uid)
510 dbpath = __get_parser_db_path(uid);
511 if (access(dbpath, F_OK) != -1) {
512 _LOGE("Manifest db for user %d is already exists", uid);
513 return PM_PARSER_R_ERROR;
516 ret = sqlite3_open_v2(dbpath, &db,
517 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
518 if (ret != SQLITE_OK) {
519 _LOGE("open db failed: %d", ret);
520 return PM_PARSER_R_ERROR;
523 ret = sqlite3_busy_handler(db, __db_busy_handler, NULL);
524 if (ret != SQLITE_OK) {
525 _LOGE("failed to register busy handler: %s",
527 sqlite3_close_v2(db);
531 if (__initialize_db(db, dbpath, uid)) {
532 sqlite3_close_v2(db);
533 return PM_PARSER_R_ERROR;
535 sqlite3_close_v2(db);
537 return PM_PARSER_R_OK;
540 API int pkgmgr_parser_initialize_cert_db(void)
546 dbpath = __get_cert_db_path();
547 if (access(dbpath, F_OK) != -1) {
548 _LOGE("Cert db is already exists");
549 return PM_PARSER_R_ERROR;
552 ret = sqlite3_open_v2(dbpath, &db,
553 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
554 if (ret != SQLITE_OK) {
555 _LOGE("open db failed: %d", ret);
556 return PM_PARSER_R_ERROR;
559 ret = sqlite3_busy_handler(db, __db_busy_handler, NULL);
560 if (ret != SQLITE_OK) {
561 _LOGE("failed to register busy handler: %s",
563 sqlite3_close_v2(db);
567 if (__initialize_db(db, dbpath, GLOBAL_USER)) {
568 sqlite3_close_v2(db);
569 return PM_PARSER_R_ERROR;
571 sqlite3_close_v2(db);
573 return PM_PARSER_R_OK;
576 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
580 struct passwd *result;
583 ret = getpwnam_r(APPFW_USER, &pwd, buf, sizeof(buf), &result);
584 if (result == NULL) {
586 _LOGE("no such user: %s", APPFW_USER);
588 _LOGE("getpwnam_r failed: %d", errno);
589 return PM_PARSER_R_ERROR;
592 if (getuid() != OWNER_ROOT && getuid() != pwd.pw_uid) {
593 _LOGE("Only root or app_fw user is allowed");
594 return PM_PARSER_R_EINVAL;
597 if (pkgmgr_parser_initialize_parser_db(uid))
598 return PM_PARSER_R_ERROR;
600 if (uid == OWNER_ROOT || uid == GLOBAL_USER)
601 if (pkgmgr_parser_initialize_cert_db())
602 return PM_PARSER_R_ERROR;
604 return PM_PARSER_R_OK;
607 static int __open_db(uid_t uid, const char *path, sqlite3 **db, int flags)
611 /* FIXME: always open with OPEN_CREATE flag for keeping previous
614 if (flags & SQLITE_OPEN_READWRITE)
615 flags = flags | SQLITE_OPEN_CREATE;
617 ret = sqlite3_open_v2(path, db, flags, NULL);
618 if (ret != SQLITE_OK)
621 ret = sqlite3_busy_handler(*db, __db_busy_handler, (void *)path);
622 if (ret != SQLITE_OK) {
623 _LOGE("failed to register busy handler: %s",
624 sqlite3_errmsg(*db));
625 sqlite3_close_v2(*db);
629 if (flags & SQLITE_OPEN_CREATE) {
630 ret = __initialize_db(*db, path, uid);
632 _LOGE("failed to initialize db: %s", path);
633 sqlite3_close_v2(*db);
638 ret = sqlite3_exec(*db, "PRAGMA foreign_keys=ON", NULL, NULL, NULL);
639 if (ret != SQLITE_OK) {
640 _LOGE("failed to enable foreign key support: %s",
641 sqlite3_errmsg(*db));
642 sqlite3_close_v2(*db);
650 static int __convert_background_category(GList *category_list)
656 if (category_list == NULL)
659 for (tmp = category_list; tmp; tmp = tmp->next) {
660 category_data = (char *)tmp->data;
661 if (category_data == NULL)
663 if (!strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR))
664 ret |= APP_BG_CATEGORY_MEDIA_VAL;
665 else if (!strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR))
666 ret |= APP_BG_CATEGORY_DOWNLOAD_VAL;
667 else if (!strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR))
668 ret |= APP_BG_CATEGORY_BGNETWORK_VAL;
669 else if (!strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR))
670 ret |= APP_BG_CATEGORY_LOCATION_VAL;
671 else if (!strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR))
672 ret |= APP_BG_CATEGORY_SENSOR_VAL;
673 else if (!strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR))
674 ret |= APP_BG_CATEGORY_IOTCOMM_VAL;
675 else if (!strcmp(category_data, APP_BG_CATEGORY_SYSTEM))
676 ret |= APP_BG_CATEGORY_SYSTEM_VAL;
678 _LOGE("Unidentified category [%s]", category_data);
684 #define EFFECTIVE_APPID_KEY "http://tizen.org/metadata/effective-appid"
685 static const char *__find_effective_appid(GList *metadata_list)
690 for (tmp = metadata_list; tmp; tmp = tmp->next) {
691 md = (metadata_x *)tmp->data;
692 if (md == NULL || md->key == NULL)
695 if (strcmp(md->key, EFFECTIVE_APPID_KEY) == 0) {
704 static int __insert_appcontrol_privilege_info(sqlite3 *db, const char *appid,
707 static const char query[] =
708 "INSERT INTO package_app_app_control_privilege (app_id,"
709 " app_control, privilege) VALUES (?, ?, ?)";
713 char app_control[BUFSIZE];
720 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
721 if (ret != SQLITE_OK) {
722 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
726 for (tmp = ac->privileges; tmp; tmp = tmp->next) {
727 privilege = (char *)tmp->data;
728 if (privilege == NULL || !strlen(privilege))
732 snprintf(app_control, sizeof(app_control), "%s|%s|%s",
733 ac->operation ? (strlen(ac->operation) > 0 ?
734 ac->operation : "NULL") : "NULL",
735 ac->uri ? (strlen(ac->uri) > 0 ?
736 ac->uri : "NULL") : "NULL",
737 ac->mime ? (strlen(ac->mime) > 0 ?
738 ac->mime : "NULL") : "NULL");
739 __BIND_TEXT(db, stmt, idx++, appid);
740 __BIND_TEXT(db, stmt, idx++, app_control);
741 __BIND_TEXT(db, stmt, idx++, privilege);
743 ret = sqlite3_step(stmt);
744 if (ret != SQLITE_DONE) {
745 _LOGE("step failed: %s", sqlite3_errmsg(db));
746 sqlite3_finalize(stmt);
753 sqlite3_finalize(stmt);
758 static int __insert_appcontrol_info(sqlite3 *db, application_x *app)
760 static const char query[] =
761 "INSERT INTO package_app_app_control (app_id, app_control,"
762 " visibility, app_control_id) "
763 "VALUES (?, ?, ?, ?)";
767 char app_control[BUFSIZE];
771 if (app->appcontrol == NULL)
774 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
775 if (ret != SQLITE_OK) {
776 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
780 for (tmp = app->appcontrol; tmp; tmp = tmp->next) {
781 ac = (appcontrol_x *)tmp->data;
785 snprintf(app_control, sizeof(app_control), "%s|%s|%s",
786 ac->operation ? (strlen(ac->operation) > 0 ?
787 ac->operation : "NULL") : "NULL",
788 ac->uri ? (strlen(ac->uri) > 0 ?
789 ac->uri : "NULL") : "NULL",
790 ac->mime ? (strlen(ac->mime) > 0 ?
791 ac->mime : "NULL") : "NULL");
792 __BIND_TEXT(db, stmt, idx++, app->appid);
793 __BIND_TEXT(db, stmt, idx++, app_control);
794 __BIND_TEXT(db, stmt, idx++, ac->visibility);
795 __BIND_TEXT(db, stmt, idx++, ac->id);
797 ret = sqlite3_step(stmt);
798 if (ret != SQLITE_DONE) {
799 _LOGE("step failed: %s", sqlite3_errmsg(db));
800 sqlite3_finalize(stmt);
804 if (__insert_appcontrol_privilege_info(db, app->appid, ac)) {
805 sqlite3_finalize(stmt);
812 sqlite3_finalize(stmt);
817 static int __insert_category_info(sqlite3 *db, application_x *app)
819 static const char query[] =
820 "INSERT INTO package_app_app_category (app_id, category) "
826 const char *category;
828 if (app->category == NULL)
831 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
832 if (ret != SQLITE_OK) {
833 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
837 for (tmp = app->category; tmp; tmp = tmp->next) {
838 category = (const char *)tmp->data;
839 if (category == NULL)
842 __BIND_TEXT(db, stmt, idx++, app->appid);
843 __BIND_TEXT(db, stmt, idx++, category);
845 ret = sqlite3_step(stmt);
846 if (ret != SQLITE_DONE) {
847 _LOGE("step failed: %s", sqlite3_errmsg(db));
848 sqlite3_finalize(stmt);
855 sqlite3_finalize(stmt);
860 static int __insert_metadata_info(sqlite3 *db, application_x *app)
862 static const char query[] =
863 "INSERT INTO package_app_app_metadata (app_id,"
864 " md_key, md_value) VALUES (?, ?, ?)";
871 if (app->metadata == NULL)
874 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
875 if (ret != SQLITE_OK) {
876 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
880 for (tmp = app->metadata; tmp; tmp = tmp->next) {
881 md = (metadata_x *)tmp->data;
885 __BIND_TEXT(db, stmt, idx++, app->appid);
886 __BIND_TEXT(db, stmt, idx++, md->key);
887 __BIND_TEXT(db, stmt, idx++, md->value);
889 ret = sqlite3_step(stmt);
890 if (ret != SQLITE_DONE) {
891 _LOGE("step failed: %s", sqlite3_errmsg(db));
892 sqlite3_finalize(stmt);
899 sqlite3_finalize(stmt);
904 static int __insert_app_data_control_privilege_info(sqlite3 *db,
905 datacontrol_x *datacontrol)
907 static const char query[] =
908 "INSERT INTO package_app_data_control_privilege (providerid,"
909 " privilege, type) VALUES (?, ?, ?)";
917 if (datacontrol == NULL)
920 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
921 if (ret != SQLITE_OK) {
922 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
926 for (privileges = datacontrol->privileges; privileges;
927 privileges = privileges->next) {
928 priv = (char *)privileges->data;
933 __BIND_TEXT(db, stmt, idx++, datacontrol->providerid);
934 __BIND_TEXT(db, stmt, idx++, priv);
935 __BIND_TEXT(db, stmt, idx++, datacontrol->type);
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);
951 static int __insert_datacontrol_info(sqlite3 *db, application_x *app)
953 static const char query[] =
954 "INSERT INTO package_app_data_control (app_id, providerid,"
955 " access, type, trusted) VALUES (?, ?, ?, ?, ?)";
962 if (app->datacontrol == NULL)
965 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
966 if (ret != SQLITE_OK) {
967 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
971 for (tmp = app->datacontrol; tmp; tmp = tmp->next) {
972 dc = (datacontrol_x *)tmp->data;
976 __BIND_TEXT(db, stmt, idx++, app->appid);
977 __BIND_TEXT(db, stmt, idx++, dc->providerid);
978 __BIND_TEXT(db, stmt, idx++, dc->access);
979 __BIND_TEXT(db, stmt, idx++, dc->type);
980 __BIND_TEXT(db, stmt, idx++, dc->trusted);
982 ret = sqlite3_step(stmt);
983 if (ret != SQLITE_DONE) {
984 _LOGE("step failed: %s", sqlite3_errmsg(db));
985 sqlite3_finalize(stmt);
989 if (dc->privileges &&
990 __insert_app_data_control_privilege_info(db, dc)) {
991 sqlite3_finalize(stmt);
998 sqlite3_finalize(stmt);
1003 /* TODO: move to installer */
1004 static int __check_dpi(const char *dpi_char, int dpi_int)
1006 if (dpi_char == NULL)
1009 if (strcasecmp(dpi_char, LDPI) == 0) {
1010 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
1014 } else if (strcasecmp(dpi_char, MDPI) == 0) {
1015 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
1019 } else if (strcasecmp(dpi_char, HDPI) == 0) {
1020 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
1024 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
1025 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
1029 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
1030 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
1038 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a,
1041 splashscreen_x *ss = (splashscreen_x *)a;
1042 const char *orientation = (const char *)b;
1046 if (ss->operation || ss->dpi == NULL)
1049 ret = system_info_get_platform_int(
1050 "http://tizen.org/feature/screen.dpi", &dpi);
1051 if (ret != SYSTEM_INFO_ERROR_NONE)
1054 if (strcasecmp(ss->orientation, orientation) == 0 &&
1055 __check_dpi(ss->dpi, dpi) == 0)
1061 static gint __compare_splashscreen_with_orientation(gconstpointer a,
1064 splashscreen_x *ss = (splashscreen_x *)a;
1065 const char *orientation = (const char *)b;
1067 if (ss->operation || ss->dpi)
1070 if (strcasecmp(ss->orientation, orientation) == 0)
1076 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1077 const char *orientation)
1081 tmp = g_list_find_custom(splashscreens, orientation,
1083 __compare_splashscreen_with_orientation_dpi);
1085 return (splashscreen_x *)tmp->data;
1087 tmp = g_list_find_custom(splashscreens, orientation,
1088 (GCompareFunc)__compare_splashscreen_with_orientation);
1090 return (splashscreen_x *)tmp->data;
1095 static void __find_appcontrol_splashscreen_with_dpi(gpointer data,
1098 splashscreen_x *ss = (splashscreen_x *)data;
1099 GList **list = (GList **)user_data;
1103 if (ss->operation == NULL || ss->dpi == NULL)
1106 ret = system_info_get_platform_int(
1107 "http://tizen.org/feature/screen.dpi", &dpi);
1108 if (ret != SYSTEM_INFO_ERROR_NONE)
1111 if (__check_dpi(ss->dpi, dpi) != 0)
1114 *list = g_list_append(*list, ss);
1117 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1119 splashscreen_x *ss = (splashscreen_x *)data;
1120 GList **list = (GList **)user_data;
1121 splashscreen_x *ss_tmp;
1124 if (ss->operation == NULL || ss->dpi)
1127 for (tmp = *list; tmp; tmp = tmp->next) {
1128 ss_tmp = (splashscreen_x *)tmp->data;
1129 if (ss_tmp->operation
1130 && strcmp(ss_tmp->operation, ss->operation) == 0
1131 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1135 *list = g_list_append(*list, ss);
1138 static GList *__find_splashscreens(GList *splashscreens)
1143 if (splashscreens == NULL)
1146 g_list_foreach(splashscreens,
1147 __find_appcontrol_splashscreen_with_dpi, &list);
1148 g_list_foreach(splashscreens,
1149 __find_appcontrol_splashscreen, &list);
1151 ss = __find_default_splashscreen(splashscreens, "portrait");
1153 list = g_list_append(list, ss);
1154 ss = __find_default_splashscreen(splashscreens, "landscape");
1156 list = g_list_append(list, ss);
1161 static int __insert_splashscreen_info(sqlite3 *db, application_x *app,
1164 static const char query[] =
1165 "INSERT INTO package_app_splash_screen (app_id, src, type,"
1166 " orientation, indicatordisplay, operation, color_depth) "
1167 "VALUES (?, ?, ?, ?, ?, ?, ?)";
1174 if (app->splashscreens == NULL)
1177 if (ss_list == NULL)
1180 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1181 if (ret != SQLITE_OK) {
1182 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1186 for (tmp = ss_list; tmp; tmp = tmp->next) {
1187 ss = (splashscreen_x *)tmp->data;
1191 __BIND_TEXT(db, stmt, idx++, app->appid);
1192 __BIND_TEXT(db, stmt, idx++, ss->src);
1193 __BIND_TEXT(db, stmt, idx++, ss->type);
1194 __BIND_TEXT(db, stmt, idx++, ss->orientation);
1195 __BIND_TEXT(db, stmt, idx++, ss->indicatordisplay);
1196 __BIND_TEXT(db, stmt, idx++, ss->operation);
1197 __BIND_TEXT(db, stmt, idx++, ss->color_depth);
1199 ret = sqlite3_step(stmt);
1200 if (ret != SQLITE_DONE) {
1201 _LOGE("step failed: %s", sqlite3_errmsg(db));
1202 sqlite3_finalize(stmt);
1206 sqlite3_reset(stmt);
1209 sqlite3_finalize(stmt);
1214 static int __insert_component_info(sqlite3 *db, application_x *app)
1216 static const char query[] =
1217 "INSERT INTO package_app_component_info (app_id, component_id, "
1218 "type, launch_mode) VALUES(?, ?, ?, ?)";
1225 if (app->components == NULL)
1228 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1229 if (ret != SQLITE_OK) {
1230 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1234 for (tmp = app->components; tmp; tmp = tmp->next) {
1235 c = (component_x *)tmp->data;
1240 __BIND_TEXT(db, stmt, idx++, app->appid);
1241 __BIND_TEXT(db, stmt, idx++, c->id);
1242 __BIND_TEXT(db, stmt, idx++, c->type);
1243 __BIND_TEXT(db, stmt, idx++, c->launch_mode);
1245 ret = sqlite3_step(stmt);
1246 if (ret != SQLITE_DONE) {
1247 _LOGE("step failed: %s", sqlite3_errmsg(db));
1248 sqlite3_finalize(stmt);
1251 sqlite3_reset(stmt);
1254 sqlite3_finalize(stmt);
1259 static void __trimfunc(GList *trim_list)
1263 GList *list = g_list_first(trim_list);
1266 trim_data = (char *)list->data;
1269 if (strcmp(trim_data, prev) == 0) {
1270 trim_list = g_list_remove(trim_list,
1272 list = g_list_first(trim_list);
1281 list = g_list_next(list);
1285 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
1287 if (a == NULL || b == NULL)
1289 if (strcmp((char *)a, (char *)b) == 0)
1291 if (strcmp((char *)a, (char *)b) < 0)
1293 if (strcmp((char *)a, (char *)b) > 0)
1298 /* TODO: refactor inserting localized info */
1299 static GList *__create_locale_list(GList *lbls, GList *lcns, GList *icns,
1300 GList *dcns, GList *aths)
1302 GList *locale = NULL;
1310 for (tmp = lbls; tmp; tmp = tmp->next) {
1311 lbl = (label_x *)tmp->data;
1315 locale = g_list_insert_sorted_with_data(
1316 locale, (gpointer)lbl->lang,
1317 __comparefunc, NULL);
1319 for (tmp = lcns; tmp; tmp = tmp->next) {
1320 lcn = (license_x *)tmp->data;
1324 locale = g_list_insert_sorted_with_data(
1325 locale, (gpointer)lcn->lang,
1326 __comparefunc, NULL);
1328 for (tmp = icns; tmp; tmp = tmp->next) {
1329 icn = (icon_x *)tmp->data;
1333 locale = g_list_insert_sorted_with_data(
1334 locale, (gpointer)icn->lang,
1335 __comparefunc, NULL);
1337 for (tmp = dcns; tmp; tmp = tmp->next) {
1338 dcn = (description_x *)tmp->data;
1342 locale = g_list_insert_sorted_with_data(
1343 locale, (gpointer)dcn->lang,
1344 __comparefunc, NULL);
1346 for (tmp = aths; tmp; tmp = tmp->next) {
1347 ath = (author_x *)tmp->data;
1351 locale = g_list_insert_sorted_with_data(
1352 locale, (gpointer)ath->lang,
1353 __comparefunc, NULL);
1359 static gint __check_icon_resolution(const char *orig_icon_path,
1360 char **new_icon_path)
1364 char *icon_filename;
1365 char modified_iconpath[BUFSIZE];
1366 char icon_path[BUFSIZE];
1370 if (orig_icon_path == NULL)
1373 ret = system_info_get_platform_int(
1374 "http://tizen.org/feature/screen.dpi", &dpi);
1375 if (ret != SYSTEM_INFO_ERROR_NONE)
1378 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
1379 dpi_path[0] = "LDPI";
1380 dpi_path[1] = "ldpi";
1381 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
1382 dpi_path[0] = "MDPI";
1383 dpi_path[1] = "mdpi";
1384 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
1385 dpi_path[0] = "HDPI";
1386 dpi_path[1] = "hdpi";
1387 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
1388 dpi_path[0] = "XHDPI";
1389 dpi_path[1] = "xhdpi";
1390 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
1391 dpi_path[0] = "XXHDPI";
1392 dpi_path[1] = "xxhdpi";
1394 _LOGE("Unidentified dpi[%d]", dpi);
1398 icon_filename = strrchr(orig_icon_path, '/');
1399 if (icon_filename == NULL)
1403 strlen(orig_icon_path) - (strlen(icon_filename) - 1),
1404 "%s", orig_icon_path);
1405 for (i = 0; i < 2; i++) {
1406 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s",
1407 icon_path, dpi_path[i], icon_filename);
1408 if (access(modified_iconpath, F_OK) != -1) {
1409 /* if exists, return modified icon path */
1410 *new_icon_path = strdup(modified_iconpath);
1418 static gint __compare_icon(gconstpointer a, gconstpointer b)
1420 icon_x *icon = (icon_x *)a;
1423 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
1426 if (icon->dpi != NULL)
1429 if (__check_icon_resolution(icon->text, &icon_path) == 0) {
1431 icon->text = icon_path;
1437 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
1439 icon_x *icon = (icon_x *)a;
1440 int dpi = GPOINTER_TO_INT(b);
1442 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
1445 if (icon->dpi == NULL)
1448 if (__check_dpi(icon->dpi, dpi) == 0)
1454 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
1456 icon_x *icon = (icon_x *)a;
1457 char *lang = (char *)b;
1460 if (icon->dpi != NULL)
1463 if (strcasecmp(icon->lang, lang) == 0) {
1464 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
1465 /* icon for no locale. check existance of
1466 * folder-hierachied default icons
1468 if (__check_icon_resolution(icon->text,
1471 icon->text = icon_path;
1480 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
1483 icon_x *icon = (icon_x *)a;
1484 char *lang = (char *)b;
1487 ret = system_info_get_platform_int(
1488 "http://tizen.org/feature/screen.dpi", &dpi);
1489 if (ret != SYSTEM_INFO_ERROR_NONE)
1492 if (strcasecmp(icon->lang, lang) == 0 &&
1493 __check_dpi(icon->dpi, dpi) == 0)
1499 static char *__find_icon(GList *icons, const char *lang)
1506 /* first, find icon whose locale and dpi with given lang and
1507 * system's dpi has matched
1509 tmp = g_list_find_custom(icons, lang,
1510 (GCompareFunc)__compare_icon_with_lang_dpi);
1512 icon = (icon_x *)tmp->data;
1513 return (char *)icon->text;
1516 /* if first has failed, find icon whose locale has matched */
1517 tmp = g_list_find_custom(icons, lang,
1518 (GCompareFunc)__compare_icon_with_lang);
1520 icon = (icon_x *)tmp->data;
1521 return (char *)icon->text;
1524 /* if second has failed, find icon whose dpi has matched with
1527 ret = system_info_get_platform_int(
1528 "http://tizen.org/feature/screen.dpi", &dpi);
1529 if (ret == SYSTEM_INFO_ERROR_NONE) {
1530 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi),
1531 (GCompareFunc)__compare_icon_with_dpi);
1533 icon = (icon_x *)tmp->data;
1534 return (char *)icon->text;
1538 /* last, find default icon marked as "No Locale" */
1539 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
1541 icon = (icon_x *)tmp->data;
1542 return (char *)icon->text;
1548 static void __extract_data(const char *locale, GList *lbls, GList *lcns,
1549 GList *icns, GList *dcns, GList *aths, char **label,
1550 char **license, char **icon, char **description, char **author)
1558 for (tmp = lbls; tmp; tmp = tmp->next) {
1559 lbl = (label_x *)tmp->data;
1563 if (strcmp(lbl->lang, locale) == 0) {
1564 *label = (char *)lbl->text;
1569 for (tmp = lcns; tmp; tmp = tmp->next) {
1570 lcn = (license_x *)tmp->data;
1574 if (strcmp(lcn->lang, locale) == 0) {
1575 *license = (char *)lcn->text;
1581 *icon = __find_icon(icns, locale);
1583 for (tmp = dcns; tmp; tmp = tmp->next) {
1584 dcn = (description_x *)tmp->data;
1588 if (strcmp(dcn->lang, locale) == 0) {
1589 *description = (char *)dcn->text;
1594 for (tmp = aths; tmp; tmp = tmp->next) {
1595 ath = (author_x *)tmp->data;
1599 if (strcmp(ath->lang, locale) == 0) {
1600 *author = (char *)ath->text;
1607 static int __insert_mainapp_localized_info(sqlite3 *db, application_x *app,
1608 const char *locale, const char *label, const char *icon)
1610 static const char query[] =
1611 "INSERT OR REPLACE INTO package_localized_info ("
1612 " package, package_locale, package_label, package_icon,"
1613 " package_description, package_license, package_author) "
1615 " COALESCE((SELECT package_label FROM package_localized_info"
1616 " WHERE package=? AND package_locale=?), ?),"
1617 " COALESCE((SELECT package_icon FROM package_localized_info"
1618 " WHERE package=? AND package_icon=?), ?),"
1619 " (SELECT package_description FROM package_localized_info"
1620 " WHERE package=? AND package_locale=?),"
1621 " (SELECT package_description FROM package_localized_info"
1622 " WHERE package=? AND package_locale=?),"
1623 " (SELECT package_description FROM package_localized_info"
1624 " WHERE package=? AND package_locale=?))";
1629 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1630 if (ret != SQLITE_OK) {
1631 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1635 __BIND_TEXT(db, stmt, idx++, app->package);
1636 __BIND_TEXT(db, stmt, idx++, locale);
1637 __BIND_TEXT(db, stmt, idx++, app->package);
1638 __BIND_TEXT(db, stmt, idx++, locale);
1639 __BIND_TEXT(db, stmt, idx++, label);
1640 __BIND_TEXT(db, stmt, idx++, app->package);
1641 __BIND_TEXT(db, stmt, idx++, locale);
1642 __BIND_TEXT(db, stmt, idx++, icon);
1643 __BIND_TEXT(db, stmt, idx++, app->package);
1644 __BIND_TEXT(db, stmt, idx++, locale);
1645 __BIND_TEXT(db, stmt, idx++, app->package);
1646 __BIND_TEXT(db, stmt, idx++, locale);
1647 __BIND_TEXT(db, stmt, idx++, app->package);
1648 __BIND_TEXT(db, stmt, idx++, locale);
1650 ret = sqlite3_step(stmt);
1651 if (ret != SQLITE_DONE) {
1652 _LOGE("step failed: %s", sqlite3_errmsg(db));
1653 sqlite3_finalize(stmt);
1657 sqlite3_finalize(stmt);
1662 static int __insert_app_localized_info(sqlite3 *db, application_x *app)
1664 static const char query[] =
1665 "INSERT INTO package_app_localized_info (app_id, app_locale,"
1666 " app_label, app_icon) "
1667 "VALUES (?, ?, ?, ?)";
1677 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1678 if (ret != SQLITE_OK) {
1679 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1683 locales = __create_locale_list(app->label, NULL, app->icon, NULL, NULL);
1684 for (tmp = locales; tmp; tmp = tmp->next) {
1685 locale = (const char *)tmp->data;
1688 __extract_data(locale, app->label, NULL, app->icon, NULL, NULL,
1689 &label, NULL, &icon, NULL, NULL);
1690 if (!label && !icon)
1694 __BIND_TEXT(db, stmt, idx++, app->appid);
1695 __BIND_TEXT(db, stmt, idx++, locale);
1696 __BIND_TEXT(db, stmt, idx++, label);
1697 __BIND_TEXT(db, stmt, idx++, icon);
1699 ret = sqlite3_step(stmt);
1700 if (ret != SQLITE_DONE) {
1701 _LOGE("step failed: %s", sqlite3_errmsg(db));
1702 g_list_free(locales);
1703 sqlite3_finalize(stmt);
1707 sqlite3_reset(stmt);
1709 if (strcasecmp(app->mainapp, "true") == 0) {
1710 if (__insert_mainapp_localized_info(db, app, locale,
1712 _LOGE("insert mainapp localized info failed");
1716 g_list_free(locales);
1717 sqlite3_finalize(stmt);
1722 static int __insert_package_privilege_info(sqlite3 *db, manifest_x *mfx)
1724 static const char query[] =
1725 "INSERT INTO package_privilege_info (package, privilege, type) "
1733 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1734 if (ret != SQLITE_OK) {
1735 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1739 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1740 priv = (privilege_x *)tmp->data;
1745 __BIND_TEXT(db, stmt, idx++, mfx->package);
1746 __BIND_TEXT(db, stmt, idx++, priv->value);
1747 __BIND_TEXT(db, stmt, idx++, priv->type);
1749 ret = sqlite3_step(stmt);
1750 if (ret != SQLITE_DONE) {
1751 _LOGE("step failed: %s", sqlite3_errmsg(db));
1752 sqlite3_finalize(stmt);
1755 sqlite3_reset(stmt);
1758 sqlite3_finalize(stmt);
1763 static int __insert_package_plugin_execution_info(sqlite3 *db,
1766 static const char query[] =
1767 "INSERT INTO package_plugin_info "
1768 "(pkgid, appid, plugin_type, plugin_name) "
1769 "VALUES (?, ?, ?, ?)";
1779 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1780 if (ret != SQLITE_OK) {
1781 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1785 for (tmp = mfx->plugin; tmp; tmp = tmp->next) {
1786 plugin = (plugin_x *)tmp->data;
1791 __BIND_TEXT(db, stmt, idx++, plugin->pkgid);
1792 __BIND_TEXT(db, stmt, idx++, plugin->appid);
1793 __BIND_TEXT(db, stmt, idx++, plugin->plugin_type);
1794 __BIND_TEXT(db, stmt, idx++, plugin->plugin_name);
1796 ret = sqlite3_step(stmt);
1797 if (ret != SQLITE_DONE) {
1798 _LOGE("step failed: %s", sqlite3_errmsg(db));
1799 sqlite3_finalize(stmt);
1802 sqlite3_reset(stmt);
1805 sqlite3_finalize(stmt);
1810 static int __delete_package_plugin_execution_info(sqlite3 *db,
1813 static const char query[] =
1814 "DELETE FROM package_plugin_info WHERE pkgid=?";
1818 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1819 if (ret != SQLITE_OK) {
1820 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1824 __BIND_TEXT(db, stmt, 1, pkgid);
1826 ret = sqlite3_step(stmt);
1827 if (ret != SQLITE_DONE) {
1828 _LOGE("step failed: %s", sqlite3_errmsg(db));
1829 sqlite3_finalize(stmt);
1833 sqlite3_finalize(stmt);
1838 static int __insert_package_appdefined_privilege_info(sqlite3 *db,
1841 static const char query[] =
1842 "INSERT INTO package_appdefined_privilege_info "
1843 "(package, privilege, license, type) "
1844 "VALUES (?, ?, ?, ?)";
1849 appdefined_privilege_x *priv;
1851 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1852 if (ret != SQLITE_OK) {
1853 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1857 for (tmp = mfx->appdefined_privileges; tmp; tmp = tmp->next) {
1858 priv = (appdefined_privilege_x *)tmp->data;
1863 __BIND_TEXT(db, stmt, idx++, mfx->package);
1864 __BIND_TEXT(db, stmt, idx++, priv->value);
1865 __BIND_TEXT(db, stmt, idx++, priv->license);
1866 __BIND_TEXT(db, stmt, idx++, priv->type);
1868 ret = sqlite3_step(stmt);
1869 if (ret != SQLITE_DONE) {
1870 _LOGE("step failed: %s", sqlite3_errmsg(db));
1871 sqlite3_finalize(stmt);
1874 sqlite3_reset(stmt);
1877 sqlite3_finalize(stmt);
1882 static int __insert_package_dependency_info(sqlite3 *db, manifest_x *mfx)
1884 static const char query[] =
1885 "INSERT INTO package_dependency_info"
1886 " (package, depends_on, type, required_version) "
1887 "VALUES (?, ?, ?, ?)";
1894 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1895 if (ret != SQLITE_OK) {
1896 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1900 for (tmp = mfx->dependencies; tmp; tmp = tmp->next) {
1901 dep = (dependency_x *)tmp->data;
1906 __BIND_TEXT(db, stmt, idx++, mfx->package);
1907 __BIND_TEXT(db, stmt, idx++, dep->depends_on);
1908 __BIND_TEXT(db, stmt, idx++, dep->type);
1909 __BIND_TEXT(db, stmt, idx++, dep->required_version);
1911 ret = sqlite3_step(stmt);
1912 if (ret != SQLITE_DONE) {
1913 _LOGE("step failed: %s", sqlite3_errmsg(db));
1914 sqlite3_finalize(stmt);
1917 sqlite3_reset(stmt);
1920 sqlite3_finalize(stmt);
1925 /* _PRODUCT_LAUNCHING_ENHANCED_
1926 * app->indicatordisplay, app->portraitimg, app->landscapeimg,
1927 * app->guestmode_appstatus
1929 static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
1931 static const char query[] =
1932 "INSERT INTO package_app_info (app_id, app_component,"
1933 " app_exec, app_nodisplay, app_type, app_onboot, app_multiple,"
1934 " app_autorestart, app_taskmanage, app_hwacceleration,"
1935 " app_screenreader, app_mainapp, app_recentimage,"
1936 " app_launchcondition, app_indicatordisplay, app_portraitimg,"
1937 " app_landscapeimg, app_guestmodevisibility,"
1938 " app_permissiontype, app_preload, app_submode,"
1939 " app_submode_mainid, app_installed_storage, app_process_pool,"
1940 " app_launch_mode, app_ui_gadget, app_support_mode,"
1941 " app_support_disable, component_type, package, app_tep_name,"
1942 " app_zip_mount_file, app_background_category,"
1943 " app_package_type, app_root_path, app_api_version,"
1944 " app_effective_appid, app_splash_screen_display,"
1945 " app_package_system, app_removable,"
1946 " app_package_installed_time, app_support_ambient,"
1947 " app_external_path, app_setup_appid) "
1949 " ?, LOWER(?), ?, LOWER(?), LOWER(?),"
1950 " LOWER(?), LOWER(?), ?,"
1954 " ?, LOWER(?), LOWER(?),"
1956 " COALESCE(?, 'single'), LOWER(?), ?,"
1957 " LOWER(?), ?, ?, ?,"
1961 " LOWER(?), LOWER(?),"
1970 const char *effective_appid;
1973 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1974 if (ret != SQLITE_OK) {
1975 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1979 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1980 app = (application_x *)tmp->data;
1984 bg_category = __convert_background_category(
1985 app->background_category);
1986 effective_appid = __find_effective_appid(app->metadata);
1989 __BIND_TEXT(db, stmt, idx++, app->appid);
1990 __BIND_TEXT(db, stmt, idx++, app->component_type);
1991 __BIND_TEXT(db, stmt, idx++, app->exec);
1992 __BIND_TEXT(db, stmt, idx++, __get_bool(app->nodisplay, false));
1993 __BIND_TEXT(db, stmt, idx++, app->type);
1994 __BIND_TEXT(db, stmt, idx++, __get_bool(app->onboot, false));
1995 __BIND_TEXT(db, stmt, idx++, __get_bool(app->multiple, false));
1996 __BIND_TEXT(db, stmt, idx++,
1997 __get_bool(app->autorestart, false));
1998 __BIND_TEXT(db, stmt, idx++,
1999 __get_bool(app->taskmanage, false));
2000 __BIND_TEXT(db, stmt, idx++, app->hwacceleration);
2001 __BIND_TEXT(db, stmt, idx++, app->screenreader);
2002 __BIND_TEXT(db, stmt, idx++, __get_bool(app->mainapp, false));
2003 __BIND_TEXT(db, stmt, idx++, app->recentimage);
2004 __BIND_TEXT(db, stmt, idx++, app->launchcondition);
2005 __BIND_TEXT(db, stmt, idx++,
2006 __get_bool(app->indicatordisplay, true));
2007 __BIND_TEXT(db, stmt, idx++, app->portraitimg);
2008 __BIND_TEXT(db, stmt, idx++, app->landscapeimg);
2009 __BIND_TEXT(db, stmt, idx++,
2010 __get_bool(app->guestmode_visibility, true));
2011 __BIND_TEXT(db, stmt, idx++, app->permission_type);
2012 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->preload, false));
2013 __BIND_TEXT(db, stmt, idx++, __get_bool(app->submode, false));
2014 __BIND_TEXT(db, stmt, idx++, app->submode_mainid);
2015 __BIND_TEXT(db, stmt, idx++, mfx->installed_storage);
2016 __BIND_TEXT(db, stmt, idx++,
2017 __get_bool(app->process_pool, false));
2018 __BIND_TEXT(db, stmt, idx++, app->launch_mode);
2019 __BIND_TEXT(db, stmt, idx++, __get_bool(app->ui_gadget, false));
2020 __BIND_TEXT(db, stmt, idx++,
2021 app->support_mode ? app->support_mode : "0");
2022 __BIND_TEXT(db, stmt, idx++,
2023 __get_bool(mfx->support_disable, false));
2024 __BIND_TEXT(db, stmt, idx++, app->component_type);
2025 __BIND_TEXT(db, stmt, idx++, mfx->package);
2026 __BIND_TEXT(db, stmt, idx++, mfx->tep_name);
2027 __BIND_TEXT(db, stmt, idx++, mfx->zip_mount_file);
2028 __BIND_INT(db, stmt, idx++, bg_category);
2029 __BIND_TEXT(db, stmt, idx++, mfx->type ? mfx->type : "tpk");
2030 __BIND_TEXT(db, stmt, idx++, mfx->root_path);
2031 __BIND_TEXT(db, stmt, idx++, app->api_version);
2032 __BIND_TEXT(db, stmt, idx++, effective_appid);
2033 __BIND_TEXT(db, stmt, idx++,
2034 __get_bool(app->splash_screen_display, true));
2035 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->system, false));
2036 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->removable, false));
2037 __BIND_TEXT(db, stmt, idx++, mfx->installed_time);
2038 __BIND_TEXT(db, stmt, idx++,
2039 __get_bool(app->support_ambient, false));
2040 __BIND_TEXT(db, stmt, idx++, mfx->external_path);
2041 __BIND_TEXT(db, stmt, idx++, app->setup_appid);
2043 ret = sqlite3_step(stmt);
2044 if (ret != SQLITE_DONE) {
2045 _LOGE("step failed: %s", sqlite3_errmsg(db));
2046 sqlite3_finalize(stmt);
2050 sqlite3_reset(stmt);
2052 if (__insert_appcontrol_info(db, app)) {
2053 sqlite3_finalize(stmt);
2056 if (__insert_category_info(db, app)) {
2057 sqlite3_finalize(stmt);
2060 if (__insert_metadata_info(db, app)) {
2061 sqlite3_finalize(stmt);
2064 if (__insert_datacontrol_info(db, app)) {
2065 sqlite3_finalize(stmt);
2068 ss_list = __find_splashscreens(app->splashscreens);
2069 if (__insert_splashscreen_info(db, app, ss_list)) {
2070 g_list_free(ss_list);
2071 sqlite3_finalize(stmt);
2074 g_list_free(ss_list);
2075 if (__insert_app_localized_info(db, app)) {
2076 sqlite3_finalize(stmt);
2080 if (!strcmp(app->component_type, "componentbasedapp")) {
2081 if (__insert_component_info(db, app)) {
2082 sqlite3_finalize(stmt);
2088 sqlite3_finalize(stmt);
2093 static int __insert_package_update_info(sqlite3 *db, manifest_x *mfx)
2095 static const char query[] =
2096 "INSERT INTO package_update_info (package, update_version) "
2102 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2103 if (ret != SQLITE_OK) {
2104 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2109 __BIND_TEXT(db, stmt, idx++, mfx->package);
2110 __BIND_TEXT(db, stmt, idx, mfx->version);
2111 ret = sqlite3_step(stmt);
2112 if (ret != SQLITE_DONE) {
2113 _LOGE("step failed: %s", sqlite3_errmsg(db));
2114 sqlite3_finalize(stmt);
2117 sqlite3_finalize(stmt);
2122 static int __insert_package_localized_info(sqlite3 *db, manifest_x *mfx)
2124 static const char query[] =
2125 "INSERT INTO package_localized_info (package, package_locale,"
2126 " package_label, package_icon, package_description,"
2127 " package_license, package_author) "
2128 "VALUES (?, ?, ?, ?, ?, ?, ?)";
2141 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2142 if (ret != SQLITE_OK) {
2143 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2147 locales = __create_locale_list(mfx->label, mfx->license, mfx->icon,
2148 mfx->description, mfx->author);
2149 for (tmp = locales; tmp; tmp = tmp->next) {
2150 locale = (const char *)tmp->data;
2156 __extract_data(locale, mfx->label, mfx->license, mfx->icon,
2157 mfx->description, mfx->author,
2158 &label, &license, &icon, &description, &author);
2159 if (!label && !license && !icon && !description && !author)
2163 __BIND_TEXT(db, stmt, idx++, mfx->package);
2164 __BIND_TEXT(db, stmt, idx++, locale);
2165 __BIND_TEXT(db, stmt, idx++, label);
2166 __BIND_TEXT(db, stmt, idx++, icon);
2167 __BIND_TEXT(db, stmt, idx++, description);
2168 __BIND_TEXT(db, stmt, idx++, license);
2169 __BIND_TEXT(db, stmt, idx++, author);
2171 ret = sqlite3_step(stmt);
2172 if (ret != SQLITE_DONE) {
2173 _LOGE("step failed: %s", sqlite3_errmsg(db));
2174 g_list_free(locales);
2175 sqlite3_finalize(stmt);
2179 sqlite3_reset(stmt);
2182 g_list_free(locales);
2183 sqlite3_finalize(stmt);
2188 static int __insert_package_info(sqlite3 *db, manifest_x *mfx)
2190 static const char query[] =
2191 "INSERT INTO package_info (package, package_type,"
2192 " package_version, package_api_version, package_tep_name,"
2193 " package_zip_mount_file, install_location, package_size,"
2194 " package_removable, package_preload, package_readonly,"
2195 " package_update, package_appsetting, package_nodisplay,"
2196 " package_system, author_name, author_email, author_href,"
2197 " installed_time, installed_storage, storeclient_id,"
2198 " mainapp_id, package_url, root_path, external_path,"
2199 " csc_path, package_support_mode, package_support_disable) "
2203 " LOWER(?), LOWER(?), LOWER(?),"
2204 " LOWER(?), LOWER(?), LOWER(?),"
2205 " LOWER(?), ?, ?, ?,"
2212 const char *author_name = NULL;
2213 const char *author_email = NULL;
2214 const char *author_href = NULL;
2216 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2217 if (ret != SQLITE_OK) {
2218 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2222 if (mfx->author && mfx->author->data) {
2223 author_name = ((author_x *)mfx->author->data)->text;
2224 author_email = ((author_x *)mfx->author->data)->email;
2225 author_href = ((author_x *)mfx->author->data)->href;
2228 __BIND_TEXT(db, stmt, idx++, mfx->package);
2229 __BIND_TEXT(db, stmt, idx++, mfx->type);
2230 __BIND_TEXT(db, stmt, idx++, mfx->version);
2231 __BIND_TEXT(db, stmt, idx++, mfx->api_version);
2232 __BIND_TEXT(db, stmt, idx++, mfx->tep_name);
2233 __BIND_TEXT(db, stmt, idx++, mfx->zip_mount_file);
2234 __BIND_TEXT(db, stmt, idx++, mfx->installlocation);
2235 __BIND_TEXT(db, stmt, idx++, mfx->package_size);
2236 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->removable, true));
2237 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->preload, false));
2238 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->readonly, false));
2239 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->update, false));
2240 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->appsetting, false));
2241 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->nodisplay_setting, false));
2242 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->system, false));
2243 __BIND_TEXT(db, stmt, idx++, author_name);
2244 __BIND_TEXT(db, stmt, idx++, author_email);
2245 __BIND_TEXT(db, stmt, idx++, author_href);
2246 __BIND_TEXT(db, stmt, idx++, mfx->installed_time);
2247 __BIND_TEXT(db, stmt, idx++, mfx->installed_storage);
2248 __BIND_TEXT(db, stmt, idx++, mfx->storeclient_id);
2249 __BIND_TEXT(db, stmt, idx++, mfx->mainapp_id);
2250 __BIND_TEXT(db, stmt, idx++, mfx->package_url);
2251 __BIND_TEXT(db, stmt, idx++, mfx->root_path);
2252 __BIND_TEXT(db, stmt, idx++, mfx->external_path);
2253 __BIND_TEXT(db, stmt, idx++, mfx->csc_path);
2254 __BIND_TEXT(db, stmt, idx++,
2255 mfx->support_mode ? mfx->support_mode : "0");
2256 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->support_disable, false));
2258 ret = sqlite3_step(stmt);
2259 if (ret != SQLITE_DONE) {
2260 _LOGE("step failed: %s", sqlite3_errmsg(db));
2261 sqlite3_finalize(stmt);
2265 sqlite3_finalize(stmt);
2267 if (__insert_package_update_info(db, mfx))
2269 if (__insert_package_localized_info(db, mfx))
2271 if (__insert_application_info(db, mfx))
2273 if (__insert_package_privilege_info(db, mfx))
2275 if (__insert_package_appdefined_privilege_info(db, mfx))
2277 if (__insert_package_dependency_info(db, mfx))
2283 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2290 _LOGE("invalid parameter");
2291 return PM_PARSER_R_EINVAL;
2294 dbpath = __get_parser_db_path(uid);
2296 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2297 if (ret != SQLITE_OK) {
2298 _LOGE("open db failed: %d", ret);
2299 return PM_PARSER_R_ERROR;
2302 __BEGIN_TRANSACTION(db);
2303 __DO_TRANSACTION(db, __insert_package_info(db, mfx));
2304 __END_TRANSACTION(db);
2306 sqlite3_close_v2(db);
2308 return PM_PARSER_R_OK;
2311 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2313 return pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, __getuid());
2316 static int __delete_package_info(sqlite3 *db, const char *pkgid)
2318 static const char query[] =
2319 "DELETE FROM package_info WHERE package=?";
2323 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2324 if (ret != SQLITE_OK) {
2325 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2329 __BIND_TEXT(db, stmt, 1, pkgid);
2331 ret = sqlite3_step(stmt);
2332 if (ret != SQLITE_DONE) {
2333 _LOGE("step failed: %s", sqlite3_errmsg(db));
2334 sqlite3_finalize(stmt);
2338 sqlite3_finalize(stmt);
2343 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx,
2351 _LOGE("invalid parameter");
2352 return PM_PARSER_R_EINVAL;
2355 dbpath = __get_parser_db_path(uid);
2357 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2358 if (ret != SQLITE_OK) {
2359 _LOGE("open db failed: %d", ret);
2360 return PM_PARSER_R_ERROR;
2363 __BEGIN_TRANSACTION(db);
2364 __DO_TRANSACTION(db, __delete_package_info(db, mfx->package));
2365 __END_TRANSACTION(db);
2367 sqlite3_close_v2(db);
2369 return PM_PARSER_R_OK;
2372 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2374 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, __getuid());
2377 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2384 _LOGE("invalid parameter");
2385 return PM_PARSER_R_EINVAL;
2388 dbpath = __get_parser_db_path(uid);
2390 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2391 if (ret != SQLITE_OK) {
2392 _LOGE("open db failed: %d", ret);
2393 return PM_PARSER_R_ERROR;
2396 __BEGIN_TRANSACTION(db);
2397 __DO_TRANSACTION(db, __delete_package_info(db, mfx->package));
2398 __DO_TRANSACTION(db, __insert_package_info(db, mfx));
2399 __END_TRANSACTION(db);
2401 sqlite3_close_v2(db);
2403 return PM_PARSER_R_OK;
2406 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2408 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, __getuid());
2411 static int __set_global_app_disable_for_uid(sqlite3 *db, const char *appid,
2412 uid_t uid, bool is_disable)
2414 static const char query[] =
2415 "INSERT OR REPLACE INTO package_app_info_for_uid ("
2416 " app_id, uid, is_disabled, is_splash_screen_enabled) "
2418 " (SELECT app_splash_screen_display FROM package_app_info"
2419 " WHERE app_id=?))";
2424 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2425 if (ret != SQLITE_OK) {
2426 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2430 __BIND_TEXT(db, stmt, idx++, appid);
2431 __BIND_INT(db, stmt, idx++, uid);
2432 __BIND_TEXT(db, stmt, idx++, is_disable ? "true" : "false");
2433 __BIND_TEXT(db, stmt, idx++, appid);
2435 ret = sqlite3_step(stmt);
2436 if (ret != SQLITE_DONE) {
2437 _LOGE("step failed: %s", sqlite3_errmsg(db));
2438 sqlite3_finalize(stmt);
2442 sqlite3_finalize(stmt);
2447 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(
2448 const char *appid, uid_t uid, int is_disable)
2454 if (appid == NULL) {
2455 _LOGE("invalid parameter");
2456 return PM_PARSER_R_EINVAL;
2459 dbpath = __get_parser_db_path(GLOBAL_USER);
2461 ret = __open_db(GLOBAL_USER, dbpath, &db, SQLITE_OPEN_READWRITE);
2462 if (ret != SQLITE_OK) {
2463 _LOGE("open db failed: %d", ret);
2464 return PM_PARSER_R_ERROR;
2467 __BEGIN_TRANSACTION(db);
2468 __DO_TRANSACTION(db, __set_global_app_disable_for_uid(db, appid,
2469 uid, (bool)is_disable));
2470 __END_TRANSACTION(db);
2472 sqlite3_close_v2(db);
2474 return PM_PARSER_R_OK;
2477 static int __set_app_disable(sqlite3 *db, const char *appid, uid_t uid,
2480 static const char query[] =
2481 "UPDATE package_app_info SET app_disable=? "
2487 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2488 if (ret != SQLITE_OK) {
2489 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2493 __BIND_TEXT(db, stmt, idx++, is_disable ? "true" : "false");
2494 __BIND_TEXT(db, stmt, idx++, appid);
2496 ret = sqlite3_step(stmt);
2497 if (ret != SQLITE_DONE) {
2498 _LOGE("step failed: %s", sqlite3_errmsg(db));
2499 sqlite3_finalize(stmt);
2503 sqlite3_finalize(stmt);
2508 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid,
2509 uid_t uid, int is_disable)
2515 if (appid == NULL) {
2516 _LOGE("invalid parameter");
2517 return PM_PARSER_R_EINVAL;
2520 dbpath = __get_parser_db_path(uid);
2522 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2523 if (ret != SQLITE_OK) {
2524 _LOGE("open db failed: %d", ret);
2525 return PM_PARSER_R_ERROR;
2528 __BEGIN_TRANSACTION(db);
2529 __DO_TRANSACTION(db, __set_app_disable(db, appid, uid,
2531 __END_TRANSACTION(db);
2533 sqlite3_close_v2(db);
2535 return PM_PARSER_R_OK;
2538 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid,
2541 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid,
2542 __getuid(), is_disable);
2545 static int __set_pkg_disable(sqlite3 *db, const char *pkgid, uid_t uid,
2548 static const char query[] =
2549 "UPDATE package_info SET package_disable=? "
2555 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2556 if (ret != SQLITE_OK) {
2557 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2561 __BIND_TEXT(db, stmt, idx++, is_disable ? "true" : "false");
2562 __BIND_TEXT(db, stmt, idx++, pkgid);
2564 ret = sqlite3_step(stmt);
2565 if (ret != SQLITE_DONE) {
2566 _LOGE("step failed: %s", sqlite3_errmsg(db));
2567 sqlite3_finalize(stmt);
2571 sqlite3_finalize(stmt);
2576 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid,
2577 uid_t uid, int is_disable)
2583 if (pkgid == NULL) {
2584 _LOGE("invalid parameter");
2585 return PM_PARSER_R_EINVAL;
2588 dbpath = __get_parser_db_path(uid);
2590 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2591 if (ret != SQLITE_OK) {
2592 _LOGE("open db failed: %d", ret);
2593 return PM_PARSER_R_ERROR;
2596 __BEGIN_TRANSACTION(db);
2597 __DO_TRANSACTION(db, __set_pkg_disable(db, pkgid, uid,
2599 __END_TRANSACTION(db);
2601 sqlite3_close_v2(db);
2603 return PM_PARSER_R_OK;
2606 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid,
2609 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid,
2610 __getuid(), is_disable);
2613 static int __set_global_app_splash_screen_for_uid(sqlite3 *db,
2614 const char *appid, uid_t uid, bool is_enabled)
2616 static const char query[] =
2617 "INSERT OR REPLACE INTO package_app_info_for_uid("
2618 " appid, uid, is_splash_screen_enabled) "
2624 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2625 if (ret != SQLITE_OK) {
2626 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2630 __BIND_TEXT(db, stmt, idx++, appid);
2631 __BIND_INT(db, stmt, idx++, uid);
2632 __BIND_TEXT(db, stmt, idx++, is_enabled ? "true" : "false");
2634 ret = sqlite3_step(stmt);
2635 if (ret != SQLITE_DONE) {
2636 _LOGE("step failed: %s", sqlite3_errmsg(db));
2637 sqlite3_finalize(stmt);
2641 sqlite3_finalize(stmt);
2646 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(
2647 const char *appid, uid_t uid, int flag)
2653 if (appid == NULL) {
2654 _LOGE("invalid parameter");
2655 return PM_PARSER_R_EINVAL;
2658 dbpath = __get_parser_db_path(GLOBAL_USER);
2660 ret = __open_db(GLOBAL_USER, dbpath, &db, SQLITE_OPEN_READWRITE);
2661 if (ret != SQLITE_OK) {
2662 _LOGE("open db failed: %d", ret);
2663 return PM_PARSER_R_ERROR;
2666 __BEGIN_TRANSACTION(db);
2667 __DO_TRANSACTION(db, __set_global_app_splash_screen_for_uid(db,
2668 appid, uid, (bool)flag));
2669 __END_TRANSACTION(db);
2671 sqlite3_close_v2(db);
2673 return PM_PARSER_R_OK;
2676 static int __set_app_splash_screen(sqlite3 *db, const char *appid,
2679 static const char query[] =
2680 "UPDATE package_app_info SET app_splash_screen_display=? "
2686 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2687 if (ret != SQLITE_OK) {
2688 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2692 __BIND_TEXT(db, stmt, idx++, is_enabled ? "true" : "false");
2693 __BIND_TEXT(db, stmt, idx++, appid);
2695 ret = sqlite3_step(stmt);
2696 if (ret != SQLITE_DONE) {
2697 _LOGE("step failed: %s", sqlite3_errmsg(db));
2698 sqlite3_finalize(stmt);
2702 sqlite3_finalize(stmt);
2707 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(
2708 const char *appid, uid_t uid, int flag)
2714 if (appid == NULL) {
2715 _LOGE("invalid parameter");
2716 return PM_PARSER_R_EINVAL;
2719 dbpath = __get_parser_db_path(uid);
2721 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2722 if (ret != SQLITE_OK) {
2723 _LOGE("open db failed: %d", ret);
2724 return PM_PARSER_R_ERROR;
2727 __BEGIN_TRANSACTION(db);
2728 __DO_TRANSACTION(db, __set_app_splash_screen(db, appid, (bool)flag));
2729 __END_TRANSACTION(db);
2731 sqlite3_close_v2(db);
2733 return PM_PARSER_R_OK;
2736 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(
2737 const char *appid, int flag)
2739 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(
2740 appid, __getuid(), flag);
2743 static int __set_app_label(sqlite3 *db, const char *appid, const char *label)
2745 static const char query[] =
2746 "UPDATE package_app_localized_info SET app_label=? "
2747 "WHERE app_id=? AND app_label IS NOT NULL";
2752 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2753 if (ret != SQLITE_OK) {
2754 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2758 __BIND_TEXT(db, stmt, idx++, label);
2759 __BIND_TEXT(db, stmt, idx++, appid);
2761 ret = sqlite3_step(stmt);
2762 if (ret != SQLITE_DONE) {
2763 _LOGE("step failed: %s", sqlite3_errmsg(db));
2764 sqlite3_finalize(stmt);
2768 sqlite3_finalize(stmt);
2773 API int pkgmgr_parser_update_app_label_info_in_usr_db(const char *appid,
2774 uid_t uid, const char *label)
2780 if (appid == NULL) {
2781 _LOGE("invalid parameter");
2782 return PM_PARSER_R_EINVAL;
2785 dbpath = __get_parser_db_path(uid);
2787 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2788 if (ret != SQLITE_OK) {
2789 _LOGE("open db failed: %d", ret);
2790 return PM_PARSER_R_ERROR;
2793 __BEGIN_TRANSACTION(db);
2794 __DO_TRANSACTION(db, __set_app_label(db, appid, label));
2795 __END_TRANSACTION(db);
2797 sqlite3_close_v2(db);
2799 return PM_PARSER_R_OK;
2802 API int pkgmgr_parser_update_app_label_info_in_db(const char *appid,
2805 return pkgmgr_parser_update_app_label_info_in_usr_db(appid, __getuid(),
2809 static int __set_app_icon(sqlite3 *db, const char *appid, const char *icon_path)
2811 static const char query[] =
2812 "UPDATE package_app_localized_info SET app_icon=? "
2813 "WHERE app_id=? AND app_icon IS NOT NULL";
2818 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2819 if (ret != SQLITE_OK) {
2820 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2824 __BIND_TEXT(db, stmt, idx++, icon_path);
2825 __BIND_TEXT(db, stmt, idx++, appid);
2827 ret = sqlite3_step(stmt);
2828 if (ret != SQLITE_DONE) {
2829 _LOGE("step failed: %s", sqlite3_errmsg(db));
2830 sqlite3_finalize(stmt);
2834 sqlite3_finalize(stmt);
2839 API int pkgmgr_parser_update_app_icon_info_in_usr_db(const char *appid,
2840 uid_t uid, const char *icon_path)
2846 if (appid == NULL) {
2847 _LOGE("invalid parameter");
2848 return PM_PARSER_R_EINVAL;
2851 dbpath = __get_parser_db_path(uid);
2853 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2854 if (ret != SQLITE_OK) {
2855 _LOGE("open db failed: %d", ret);
2856 return PM_PARSER_R_ERROR;
2859 __BEGIN_TRANSACTION(db);
2860 __DO_TRANSACTION(db, __set_app_icon(db, appid, icon_path));
2861 __END_TRANSACTION(db);
2863 sqlite3_close_v2(db);
2865 return PM_PARSER_R_OK;
2868 API int pkgmgr_parser_update_app_icon_info_in_db(const char *appid,
2869 const char *icon_path)
2871 return pkgmgr_parser_update_app_icon_info_in_usr_db(appid, __getuid(),
2875 static int __set_tep_path(sqlite3 *db, const char *pkgid, const char *tep_path)
2877 static const char query[] =
2878 "UPDATE package_info SET package_tep_name=? "
2884 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2885 if (ret != SQLITE_OK) {
2886 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2890 __BIND_TEXT(db, stmt, idx++, tep_path);
2891 __BIND_TEXT(db, stmt, idx++, pkgid);
2893 ret = sqlite3_step(stmt);
2894 if (ret != SQLITE_DONE) {
2895 _LOGE("step failed: %s", sqlite3_errmsg(db));
2896 sqlite3_finalize(stmt);
2900 sqlite3_finalize(stmt);
2905 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid,
2906 const char *tep_path, uid_t uid)
2912 if (pkgid == NULL) {
2913 _LOGE("invalid parameter");
2914 return PM_PARSER_R_EINVAL;
2917 dbpath = __get_parser_db_path(uid);
2919 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2920 if (ret != SQLITE_OK) {
2921 _LOGE("open db failed: %d", ret);
2922 return PM_PARSER_R_ERROR;
2925 __BEGIN_TRANSACTION(db);
2926 __DO_TRANSACTION(db, __set_tep_path(db, pkgid, tep_path));
2927 __END_TRANSACTION(db);
2929 sqlite3_close_v2(db);
2931 return PM_PARSER_R_OK;
2934 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid,
2935 const char *tep_path)
2937 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path,
2941 static int __convert_update_type(pkgmgrinfo_updateinfo_update_type type,
2942 const char **update_type)
2944 if (type == PMINFO_UPDATEINFO_NONE)
2945 *update_type = PMINFO_UPDATEINFO_TYPE_NONE;
2946 else if (type == PMINFO_UPDATEINFO_FORCE)
2947 *update_type = PMINFO_UPDATEINFO_TYPE_FORCE;
2948 else if (type == PMINFO_UPDATEINFO_OPTIONAL)
2949 *update_type = PMINFO_UPDATEINFO_TYPE_OPTIONAL;
2955 static int __register_pkg_update_info(sqlite3 *db, updateinfo_x *info,
2956 const char *update_type)
2958 static const char query[] =
2959 "UPDATE package_update_info "
2960 "SET update_version=?, update_type=? "
2966 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2967 if (ret != SQLITE_OK) {
2968 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2972 __BIND_TEXT(db, stmt, idx++, info->version);
2973 __BIND_TEXT(db, stmt, idx++, update_type);
2974 __BIND_TEXT(db, stmt, idx++, info->pkgid);
2976 ret = sqlite3_step(stmt);
2977 if (ret != SQLITE_DONE) {
2978 _LOGE("step failed: %s", sqlite3_errmsg(db));
2979 sqlite3_finalize(stmt);
2983 sqlite3_finalize(stmt);
2988 API int pkgmgr_parser_register_pkg_update_info_in_usr_db(
2989 pkgmgrinfo_updateinfo_h handle, uid_t uid)
2992 updateinfo_x *update_info;
2993 updateinfo_x *prev_update_info;
2994 pkgmgrinfo_updateinfo_h prev_update_handle;
2995 pkgmgrinfo_pkginfo_h pkginfo;
2996 pkgmgrinfo_version_compare_type compare_result;
2998 const char *update_type;
3002 if (handle == NULL) {
3003 _LOGE("invalid parameter");
3004 return PM_PARSER_R_EINVAL;
3007 update_info = (updateinfo_x *)handle;
3008 if (update_info->pkgid == NULL || update_info->version == NULL)
3009 return PM_PARSER_R_EINVAL;
3010 if (__convert_update_type(update_info->type, &update_type) != 0)
3011 return PM_PARSER_R_EINVAL;
3013 ret = pkgmgrinfo_updateinfo_get_usr_updateinfo(update_info->pkgid,
3014 &prev_update_handle, uid);
3015 if (ret != PMINFO_R_OK)
3016 return PM_PARSER_R_ERROR;
3018 prev_update_info = (updateinfo_x *)prev_update_handle;
3019 ret = pkgmgrinfo_compare_package_version(update_info->version,
3020 prev_update_info->version, &compare_result);
3021 if (ret != PMINFO_R_OK) {
3022 pkgmgrinfo_updateinfo_destroy(prev_update_handle);
3023 return PM_PARSER_R_ERROR;
3026 if (compare_result == PMINFO_VERSION_SAME &&
3027 prev_update_info->type == PMINFO_UPDATEINFO_NONE) {
3028 _LOGI("Given update info version[%s] of pkgid[%s] "
3030 update_info->version, update_info->pkgid);
3031 pkgmgrinfo_updateinfo_destroy(prev_update_handle);
3032 return PM_PARSER_R_OK;
3034 pkgmgrinfo_updateinfo_destroy(prev_update_handle);
3036 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(update_info->pkgid, uid,
3038 if (ret != PMINFO_R_OK)
3039 return PM_PARSER_R_ERROR;
3041 ret = pkgmgrinfo_pkginfo_is_global(pkginfo, &is_global_pkg);
3042 if (ret != PMINFO_R_OK) {
3043 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
3044 return PM_PARSER_R_ERROR;
3046 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
3048 dbpath = __get_parser_db_path(is_global_pkg ? GLOBAL_USER : uid);
3050 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
3051 if (ret != SQLITE_OK) {
3052 _LOGE("open db failed: %d", ret);
3053 return PM_PARSER_R_ERROR;
3056 __BEGIN_TRANSACTION(db);
3057 __DO_TRANSACTION(db, __register_pkg_update_info(db, update_info,
3059 __END_TRANSACTION(db);
3061 sqlite3_close_v2(db);
3063 return PM_PARSER_R_OK;
3066 API int pkgmgr_parser_register_pkg_update_info_in_db(
3067 pkgmgrinfo_updateinfo_h handle)
3069 return pkgmgr_parser_register_pkg_update_info_in_usr_db(handle,
3073 static int __unregister_pkg_update_info(sqlite3 *db, const char *pkgid)
3075 static const char query[] =
3076 "UPDATE package_update_info SET update_type='none' "
3082 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
3083 if (ret != SQLITE_OK) {
3084 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
3088 __BIND_TEXT(db, stmt, idx++, pkgid);
3090 ret = sqlite3_step(stmt);
3091 if (ret != SQLITE_DONE) {
3092 _LOGE("step failed: %s", sqlite3_errmsg(db));
3093 sqlite3_finalize(stmt);
3097 sqlite3_finalize(stmt);
3102 API int pkgmgr_parser_unregister_pkg_update_info_in_usr_db(const char *pkgid,
3108 pkgmgrinfo_pkginfo_h pkginfo;
3111 if (pkgid == NULL) {
3112 _LOGE("invalid parameter");
3113 return PM_PARSER_R_EINVAL;
3116 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &pkginfo);
3117 if (ret != PMINFO_R_OK)
3118 return PM_PARSER_R_EINVAL;
3120 ret = pkgmgrinfo_pkginfo_is_global(pkginfo, &is_global_pkg);
3121 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
3122 if (ret != PMINFO_R_OK)
3123 return PM_PARSER_R_ERROR;
3125 dbpath = __get_parser_db_path(is_global_pkg ? GLOBAL_USER : uid);
3127 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
3128 if (ret != SQLITE_OK) {
3129 _LOGE("open db failed: %d", ret);
3130 return PM_PARSER_R_ERROR;
3133 __BEGIN_TRANSACTION(db);
3134 __DO_TRANSACTION(db, __unregister_pkg_update_info(db, pkgid));
3135 __END_TRANSACTION(db);
3137 sqlite3_close_v2(db);
3139 return PM_PARSER_R_OK;
3142 API int pkgmgr_parser_unregister_pkg_update_info_in_db(const char *pkgid)
3144 return pkgmgr_parser_unregister_pkg_update_info_in_usr_db(pkgid,
3148 static int __unregister_all_pkg_update_info(sqlite3 *db)
3150 static const char query[] =
3151 "UPDATE package_update_info SET update_type='none'";
3155 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
3156 if (ret != SQLITE_OK) {
3157 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
3161 ret = sqlite3_step(stmt);
3162 if (ret != SQLITE_DONE) {
3163 _LOGE("step failed: %s", sqlite3_errmsg(db));
3164 sqlite3_finalize(stmt);
3168 sqlite3_finalize(stmt);
3173 API int pkgmgr_parser_unregister_all_pkg_update_info_in_usr_db(uid_t uid)
3179 dbpath = __get_parser_db_path(uid);
3181 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
3182 if (ret != SQLITE_OK) {
3183 _LOGE("open db failed: %d", ret);
3184 return PM_PARSER_R_ERROR;
3187 __BEGIN_TRANSACTION(db);
3188 __DO_TRANSACTION(db, __unregister_all_pkg_update_info(db));
3189 __END_TRANSACTION(db);
3191 sqlite3_close_v2(db);
3193 return PM_PARSER_R_OK;
3196 API int pkgmgr_parser_unregister_all_pkg_update_info_in_db(void)
3198 return pkgmgr_parser_unregister_all_pkg_update_info_in_usr_db(
3202 API int pkgmgr_parser_register_pkg_plugin_info_in_usr_db(
3203 manifest_x *mfx, uid_t uid)
3210 return PM_PARSER_R_EINVAL;
3211 dbpath = __get_parser_db_path(uid);
3212 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
3213 if (ret != SQLITE_OK) {
3214 _LOGE("open db failed: %d", ret);
3215 return PM_PARSER_R_ERROR;
3218 __BEGIN_TRANSACTION(db);
3219 __DO_TRANSACTION(db, __insert_package_plugin_execution_info(db, mfx));
3220 __END_TRANSACTION(db);
3222 sqlite3_close_v2(db);
3224 return PM_PARSER_R_OK;
3227 API int pkgmgr_parser_register_pkg_plugin_info_in_db(manifest_x *mfx)
3229 return pkgmgr_parser_register_pkg_plugin_info_in_usr_db(mfx, __getuid());
3232 API int pkgmgr_parser_update_pkg_plugin_info_in_usr_db(
3233 manifest_x *mfx, uid_t uid)
3240 return PM_PARSER_R_EINVAL;
3241 dbpath = __get_parser_db_path(uid);
3242 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
3243 if (ret != SQLITE_OK) {
3244 _LOGE("open db failed: %d", ret);
3245 return PM_PARSER_R_ERROR;
3248 __BEGIN_TRANSACTION(db);
3249 __DO_TRANSACTION(db, __delete_package_plugin_execution_info(db, mfx->package));
3250 __DO_TRANSACTION(db, __insert_package_plugin_execution_info(db, mfx));
3251 __END_TRANSACTION(db);
3253 sqlite3_close_v2(db);
3255 return PM_PARSER_R_OK;
3258 API int pkgmgr_parser_update_pkg_plugin_info_in_db(manifest_x *mfx)
3260 return pkgmgr_parser_update_pkg_plugin_info_in_usr_db(mfx, __getuid());
3263 API int pkgmgr_parser_unregister_pkg_plugin_info_in_usr_db(
3264 const char *pkgid, uid_t uid)
3270 dbpath = __get_parser_db_path(uid);
3271 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
3272 if (ret != SQLITE_OK) {
3273 _LOGE("open db failed: %d", ret);
3274 return PM_PARSER_R_ERROR;
3277 __BEGIN_TRANSACTION(db);
3278 __DO_TRANSACTION(db, __delete_package_plugin_execution_info(db, pkgid));
3279 __END_TRANSACTION(db);
3281 sqlite3_close_v2(db);
3283 return PM_PARSER_R_OK;
3286 API int pkgmgr_parser_unregister_pkg_plugin_info_in_db(const char *pkgid)
3288 return pkgmgr_parser_unregister_pkg_plugin_info_in_usr_db(pkgid, __getuid());