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,
336 static const char *cert_init_queries[] = {
337 QUERY_CREATE_TABLE_PACKAGE_CERT_INFO,
338 QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO,
339 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO,
340 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2,
341 QUERY_CREATE_TRIGGER_DELETE_CERT_INFO,
342 QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO,
346 static int __create_tables(sqlite3 *db, const char **queries)
350 for (i = 0; queries[i] != NULL; i++) {
351 ret = sqlite3_exec(db, queries[i], NULL, NULL, NULL);
352 if (ret != SQLITE_OK) {
353 _LOGE("exec failed: %s", sqlite3_errmsg(db));
360 static int __initialize_db(sqlite3 *db, const char *dbpath, uid_t uid)
362 const char **queries;
364 if (__set_db_version(db))
367 if (strstr(dbpath, ".pkgmgr_parser.db")) {
368 queries = parser_init_queries;
369 } else if (strstr(dbpath, ".pkgmgr_cert.db")) {
370 queries = cert_init_queries;
372 _LOGE("unexpected dbpath: %s", dbpath);
376 __BEGIN_TRANSACTION(db);
377 __DO_TRANSACTION(db, __create_tables(db, queries));
378 __END_TRANSACTION(db);
380 if (__set_db_permission(dbpath, uid))
381 _LOGE("failed to set db permission");
386 #define RESOURCED_BUS_NAME "org.tizen.resourced"
387 #define RESOURCED_PROC_PATH "/Org/Tizen/ResourceD/Process"
388 #define RESOURCED_PROC_INTERFACE "org.tizen.resourced.process"
389 #define RESOURCED_PROC_METHOD "ProcExclude"
390 static void __send_wakeup_signal_to_resourced(pid_t pid)
392 GError *error = NULL;
393 GDBusConnection *conn;
397 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
399 _LOGE("Failed to connect to dbus: %s", error->message);
404 proxy = g_dbus_proxy_new_sync(conn,
405 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
406 NULL, RESOURCED_BUS_NAME,
407 RESOURCED_PROC_PATH, RESOURCED_PROC_INTERFACE,
410 _LOGE("failed to get proxy object: %s", error->message);
412 g_object_unref(conn);
416 reply = g_dbus_proxy_call_sync(proxy, RESOURCED_PROC_METHOD,
417 g_variant_new("(si)", "wakeup", pid),
418 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
420 _LOGE("failed to get reply from resourced");
422 _LOGE("failed to send request: %s", error->message);
426 g_object_unref(proxy);
427 g_object_unref(conn);
430 static void __check_db_lock(const char *dbpath)
439 char cmdline[BUFSIZE];
443 if (stat(dbpath, &sb) == -1) {
444 _LOGE("get db file(%s) status failed: %d", dbpath, errno);
448 fp = fopen("/proc/locks", "r");
450 _LOGE("Failed to open lock info: %d", errno);
454 while (fscanf(fp, "%*s %*s %*s %*s %d %x:%x:%lu %*s %*s",
455 &pid, &maj, &min, &ino) != EOF) {
456 if (maj != major(sb.st_dev) || min != minor(sb.st_dev) ||
457 ino != sb.st_ino || pid == getpid())
460 snprintf(cmdline, sizeof(cmdline), "/proc/%d/cmdline", pid);
461 fp_cmdline = fopen(cmdline, "r");
463 if (fp_cmdline != NULL) {
464 len = fread(name, sizeof(char), sizeof(name) - 1,
467 if (name[len - 1] == '\n')
468 name[len - 1] = '\0';
475 _LOGE("%s (%d) has lock on pkgmgr db(%s)!", name, pid, dbpath);
476 __send_wakeup_signal_to_resourced(pid);
482 #define BUSY_WAITING_USEC (1000000 / 10 / 2) /* 0.05 sec */
483 #define BUSY_WAITING_MAX 40 /* wait for max 2 sec */
484 static int __db_busy_handler(void *data, int count)
486 if (count < (BUSY_WAITING_MAX / 2)) {
487 usleep(BUSY_WAITING_USEC);
489 } else if (count == (BUSY_WAITING_MAX / 2)) {
490 __check_db_lock((const char *)data);
491 usleep(BUSY_WAITING_USEC);
493 } else if (count < BUSY_WAITING_MAX) {
494 usleep(BUSY_WAITING_USEC);
497 /* sqlite3_prepare_v2 will return SQLITE_BUSY */
502 API int pkgmgr_parser_initialize_parser_db(uid_t uid)
508 dbpath = __get_parser_db_path(uid);
509 if (access(dbpath, F_OK) != -1) {
510 _LOGE("Manifest db for user %d is already exists", uid);
511 return PM_PARSER_R_ERROR;
514 ret = sqlite3_open_v2(dbpath, &db,
515 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
516 if (ret != SQLITE_OK) {
517 _LOGE("open db failed: %d", ret);
518 return PM_PARSER_R_ERROR;
521 ret = sqlite3_busy_handler(db, __db_busy_handler, NULL);
522 if (ret != SQLITE_OK) {
523 _LOGE("failed to register busy handler: %s",
525 sqlite3_close_v2(db);
529 if (__initialize_db(db, dbpath, uid)) {
530 sqlite3_close_v2(db);
531 return PM_PARSER_R_ERROR;
533 sqlite3_close_v2(db);
535 return PM_PARSER_R_OK;
538 API int pkgmgr_parser_initialize_cert_db(void)
544 dbpath = __get_cert_db_path();
545 if (access(dbpath, F_OK) != -1) {
546 _LOGE("Cert db is already exists");
547 return PM_PARSER_R_ERROR;
550 ret = sqlite3_open_v2(dbpath, &db,
551 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
552 if (ret != SQLITE_OK) {
553 _LOGE("open db failed: %d", ret);
554 return PM_PARSER_R_ERROR;
557 ret = sqlite3_busy_handler(db, __db_busy_handler, NULL);
558 if (ret != SQLITE_OK) {
559 _LOGE("failed to register busy handler: %s",
561 sqlite3_close_v2(db);
565 if (__initialize_db(db, dbpath, GLOBAL_USER)) {
566 sqlite3_close_v2(db);
567 return PM_PARSER_R_ERROR;
569 sqlite3_close_v2(db);
571 return PM_PARSER_R_OK;
574 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
578 struct passwd *result;
581 ret = getpwnam_r(APPFW_USER, &pwd, buf, sizeof(buf), &result);
582 if (result == NULL) {
584 _LOGE("no such user: %s", APPFW_USER);
586 _LOGE("getpwnam_r failed: %d", errno);
587 return PM_PARSER_R_ERROR;
590 if (getuid() != OWNER_ROOT && getuid() != pwd.pw_uid) {
591 _LOGE("Only root or app_fw user is allowed");
592 return PM_PARSER_R_EINVAL;
595 if (pkgmgr_parser_initialize_parser_db(uid))
596 return PM_PARSER_R_ERROR;
598 if (uid == OWNER_ROOT || uid == GLOBAL_USER)
599 if (pkgmgr_parser_initialize_cert_db())
600 return PM_PARSER_R_ERROR;
602 return PM_PARSER_R_OK;
605 static int __open_db(uid_t uid, const char *path, sqlite3 **db, int flags)
609 /* FIXME: always open with OPEN_CREATE flag for keeping previous
612 if (flags & SQLITE_OPEN_READWRITE)
613 flags = flags | SQLITE_OPEN_CREATE;
615 ret = sqlite3_open_v2(path, db, flags, NULL);
616 if (ret != SQLITE_OK)
619 ret = sqlite3_busy_handler(*db, __db_busy_handler, (void *)path);
620 if (ret != SQLITE_OK) {
621 _LOGE("failed to register busy handler: %s",
622 sqlite3_errmsg(*db));
623 sqlite3_close_v2(*db);
627 if (flags & SQLITE_OPEN_CREATE) {
628 ret = __initialize_db(*db, path, uid);
630 _LOGE("failed to initialize db: %s", path);
631 sqlite3_close_v2(*db);
636 ret = sqlite3_exec(*db, "PRAGMA foreign_keys=ON", NULL, NULL, NULL);
637 if (ret != SQLITE_OK) {
638 _LOGE("failed to enable foreign key support: %s",
639 sqlite3_errmsg(*db));
640 sqlite3_close_v2(*db);
648 static int __convert_background_category(GList *category_list)
654 if (category_list == NULL)
657 for (tmp = category_list; tmp; tmp = tmp->next) {
658 category_data = (char *)tmp->data;
659 if (category_data == NULL)
661 if (!strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR))
662 ret |= APP_BG_CATEGORY_MEDIA_VAL;
663 else if (!strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR))
664 ret |= APP_BG_CATEGORY_DOWNLOAD_VAL;
665 else if (!strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR))
666 ret |= APP_BG_CATEGORY_BGNETWORK_VAL;
667 else if (!strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR))
668 ret |= APP_BG_CATEGORY_LOCATION_VAL;
669 else if (!strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR))
670 ret |= APP_BG_CATEGORY_SENSOR_VAL;
671 else if (!strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR))
672 ret |= APP_BG_CATEGORY_IOTCOMM_VAL;
673 else if (!strcmp(category_data, APP_BG_CATEGORY_SYSTEM))
674 ret |= APP_BG_CATEGORY_SYSTEM_VAL;
676 _LOGE("Unidentified category [%s]", category_data);
682 #define EFFECTIVE_APPID_KEY "http://tizen.org/metadata/effective-appid"
683 static const char *__find_effective_appid(GList *metadata_list)
688 for (tmp = metadata_list; tmp; tmp = tmp->next) {
689 md = (metadata_x *)tmp->data;
690 if (md == NULL || md->key == NULL)
693 if (strcmp(md->key, EFFECTIVE_APPID_KEY) == 0) {
702 static int __insert_appcontrol_privilege_info(sqlite3 *db, const char *appid,
705 static const char query[] =
706 "INSERT INTO package_app_app_control_privilege (app_id,"
707 " app_control, privilege) VALUES (?, ?, ?)";
711 char app_control[BUFSIZE];
718 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
719 if (ret != SQLITE_OK) {
720 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
724 for (tmp = ac->privileges; tmp; tmp = tmp->next) {
725 privilege = (char *)tmp->data;
726 if (privilege == NULL || !strlen(privilege))
730 snprintf(app_control, sizeof(app_control), "%s|%s|%s",
731 ac->operation ? (strlen(ac->operation) > 0 ?
732 ac->operation : "NULL") : "NULL",
733 ac->uri ? (strlen(ac->uri) > 0 ?
734 ac->uri : "NULL") : "NULL",
735 ac->mime ? (strlen(ac->mime) > 0 ?
736 ac->mime : "NULL") : "NULL");
737 __BIND_TEXT(db, stmt, idx++, appid);
738 __BIND_TEXT(db, stmt, idx++, app_control);
739 __BIND_TEXT(db, stmt, idx++, privilege);
741 ret = sqlite3_step(stmt);
742 if (ret != SQLITE_DONE) {
743 _LOGE("step failed: %s", sqlite3_errmsg(db));
744 sqlite3_finalize(stmt);
751 sqlite3_finalize(stmt);
756 static int __insert_appcontrol_info(sqlite3 *db, application_x *app)
758 static const char query[] =
759 "INSERT INTO package_app_app_control (app_id, app_control,"
760 " visibility, app_control_id) "
761 "VALUES (?, ?, ?, ?)";
765 char app_control[BUFSIZE];
769 if (app->appcontrol == NULL)
772 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
773 if (ret != SQLITE_OK) {
774 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
778 for (tmp = app->appcontrol; tmp; tmp = tmp->next) {
779 ac = (appcontrol_x *)tmp->data;
783 snprintf(app_control, sizeof(app_control), "%s|%s|%s",
784 ac->operation ? (strlen(ac->operation) > 0 ?
785 ac->operation : "NULL") : "NULL",
786 ac->uri ? (strlen(ac->uri) > 0 ?
787 ac->uri : "NULL") : "NULL",
788 ac->mime ? (strlen(ac->mime) > 0 ?
789 ac->mime : "NULL") : "NULL");
790 __BIND_TEXT(db, stmt, idx++, app->appid);
791 __BIND_TEXT(db, stmt, idx++, app_control);
792 __BIND_TEXT(db, stmt, idx++, ac->visibility);
793 __BIND_TEXT(db, stmt, idx++, ac->id);
795 ret = sqlite3_step(stmt);
796 if (ret != SQLITE_DONE) {
797 _LOGE("step failed: %s", sqlite3_errmsg(db));
798 sqlite3_finalize(stmt);
802 if (__insert_appcontrol_privilege_info(db, app->appid, ac)) {
803 sqlite3_finalize(stmt);
810 sqlite3_finalize(stmt);
815 static int __insert_category_info(sqlite3 *db, application_x *app)
817 static const char query[] =
818 "INSERT INTO package_app_app_category (app_id, category) "
824 const char *category;
826 if (app->category == NULL)
829 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
830 if (ret != SQLITE_OK) {
831 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
835 for (tmp = app->category; tmp; tmp = tmp->next) {
836 category = (const char *)tmp->data;
837 if (category == NULL)
840 __BIND_TEXT(db, stmt, idx++, app->appid);
841 __BIND_TEXT(db, stmt, idx++, category);
843 ret = sqlite3_step(stmt);
844 if (ret != SQLITE_DONE) {
845 _LOGE("step failed: %s", sqlite3_errmsg(db));
846 sqlite3_finalize(stmt);
853 sqlite3_finalize(stmt);
858 static int __insert_metadata_info(sqlite3 *db, application_x *app)
860 static const char query[] =
861 "INSERT INTO package_app_app_metadata (app_id,"
862 " md_key, md_value) VALUES (?, ?, ?)";
869 if (app->metadata == NULL)
872 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
873 if (ret != SQLITE_OK) {
874 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
878 for (tmp = app->metadata; tmp; tmp = tmp->next) {
879 md = (metadata_x *)tmp->data;
883 __BIND_TEXT(db, stmt, idx++, app->appid);
884 __BIND_TEXT(db, stmt, idx++, md->key);
885 __BIND_TEXT(db, stmt, idx++, md->value);
887 ret = sqlite3_step(stmt);
888 if (ret != SQLITE_DONE) {
889 _LOGE("step failed: %s", sqlite3_errmsg(db));
890 sqlite3_finalize(stmt);
897 sqlite3_finalize(stmt);
902 static int __insert_app_data_control_privilege_info(sqlite3 *db,
903 datacontrol_x *datacontrol)
905 static const char query[] =
906 "INSERT INTO package_app_data_control_privilege (providerid,"
907 " privilege, type) VALUES (?, ?, ?)";
915 if (datacontrol == NULL)
918 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
919 if (ret != SQLITE_OK) {
920 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
924 for (privileges = datacontrol->privileges; privileges;
925 privileges = privileges->next) {
926 priv = (char *)privileges->data;
931 __BIND_TEXT(db, stmt, idx++, datacontrol->providerid);
932 __BIND_TEXT(db, stmt, idx++, priv);
933 __BIND_TEXT(db, stmt, idx++, datacontrol->type);
935 ret = sqlite3_step(stmt);
936 if (ret != SQLITE_DONE) {
937 _LOGE("step failed: %s", sqlite3_errmsg(db));
938 sqlite3_finalize(stmt);
945 sqlite3_finalize(stmt);
949 static int __insert_datacontrol_info(sqlite3 *db, application_x *app)
951 static const char query[] =
952 "INSERT INTO package_app_data_control (app_id, providerid,"
953 " access, type, trusted) VALUES (?, ?, ?, ?, ?)";
960 if (app->datacontrol == NULL)
963 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
964 if (ret != SQLITE_OK) {
965 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
969 for (tmp = app->datacontrol; tmp; tmp = tmp->next) {
970 dc = (datacontrol_x *)tmp->data;
974 __BIND_TEXT(db, stmt, idx++, app->appid);
975 __BIND_TEXT(db, stmt, idx++, dc->providerid);
976 __BIND_TEXT(db, stmt, idx++, dc->access);
977 __BIND_TEXT(db, stmt, idx++, dc->type);
978 __BIND_TEXT(db, stmt, idx++, dc->trusted);
980 ret = sqlite3_step(stmt);
981 if (ret != SQLITE_DONE) {
982 _LOGE("step failed: %s", sqlite3_errmsg(db));
983 sqlite3_finalize(stmt);
987 if (dc->privileges &&
988 __insert_app_data_control_privilege_info(db, dc)) {
989 sqlite3_finalize(stmt);
996 sqlite3_finalize(stmt);
1001 /* TODO: move to installer */
1002 static int __check_dpi(const char *dpi_char, int dpi_int)
1004 if (dpi_char == NULL)
1007 if (strcasecmp(dpi_char, LDPI) == 0) {
1008 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
1012 } else if (strcasecmp(dpi_char, MDPI) == 0) {
1013 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
1017 } else if (strcasecmp(dpi_char, HDPI) == 0) {
1018 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
1022 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
1023 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
1027 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
1028 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
1036 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a,
1039 splashscreen_x *ss = (splashscreen_x *)a;
1040 const char *orientation = (const char *)b;
1044 if (ss->operation || ss->dpi == NULL)
1047 ret = system_info_get_platform_int(
1048 "http://tizen.org/feature/screen.dpi", &dpi);
1049 if (ret != SYSTEM_INFO_ERROR_NONE)
1052 if (strcasecmp(ss->orientation, orientation) == 0 &&
1053 __check_dpi(ss->dpi, dpi) == 0)
1059 static gint __compare_splashscreen_with_orientation(gconstpointer a,
1062 splashscreen_x *ss = (splashscreen_x *)a;
1063 const char *orientation = (const char *)b;
1065 if (ss->operation || ss->dpi)
1068 if (strcasecmp(ss->orientation, orientation) == 0)
1074 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1075 const char *orientation)
1079 tmp = g_list_find_custom(splashscreens, orientation,
1081 __compare_splashscreen_with_orientation_dpi);
1083 return (splashscreen_x *)tmp->data;
1085 tmp = g_list_find_custom(splashscreens, orientation,
1086 (GCompareFunc)__compare_splashscreen_with_orientation);
1088 return (splashscreen_x *)tmp->data;
1093 static void __find_appcontrol_splashscreen_with_dpi(gpointer data,
1096 splashscreen_x *ss = (splashscreen_x *)data;
1097 GList **list = (GList **)user_data;
1101 if (ss->operation == NULL || ss->dpi == NULL)
1104 ret = system_info_get_platform_int(
1105 "http://tizen.org/feature/screen.dpi", &dpi);
1106 if (ret != SYSTEM_INFO_ERROR_NONE)
1109 if (__check_dpi(ss->dpi, dpi) != 0)
1112 *list = g_list_append(*list, ss);
1115 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1117 splashscreen_x *ss = (splashscreen_x *)data;
1118 GList **list = (GList **)user_data;
1119 splashscreen_x *ss_tmp;
1122 if (ss->operation == NULL || ss->dpi)
1125 for (tmp = *list; tmp; tmp = tmp->next) {
1126 ss_tmp = (splashscreen_x *)tmp->data;
1127 if (ss_tmp->operation
1128 && strcmp(ss_tmp->operation, ss->operation) == 0
1129 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1133 *list = g_list_append(*list, ss);
1136 static GList *__find_splashscreens(GList *splashscreens)
1141 if (splashscreens == NULL)
1144 g_list_foreach(splashscreens,
1145 __find_appcontrol_splashscreen_with_dpi, &list);
1146 g_list_foreach(splashscreens,
1147 __find_appcontrol_splashscreen, &list);
1149 ss = __find_default_splashscreen(splashscreens, "portrait");
1151 list = g_list_append(list, ss);
1152 ss = __find_default_splashscreen(splashscreens, "landscape");
1154 list = g_list_append(list, ss);
1159 static int __insert_splashscreen_info(sqlite3 *db, application_x *app,
1162 static const char query[] =
1163 "INSERT INTO package_app_splash_screen (app_id, src, type,"
1164 " orientation, indicatordisplay, operation, color_depth) "
1165 "VALUES (?, ?, ?, ?, ?, ?, ?)";
1172 if (app->splashscreens == NULL)
1175 if (ss_list == NULL)
1178 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1179 if (ret != SQLITE_OK) {
1180 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1184 for (tmp = ss_list; tmp; tmp = tmp->next) {
1185 ss = (splashscreen_x *)tmp->data;
1189 __BIND_TEXT(db, stmt, idx++, app->appid);
1190 __BIND_TEXT(db, stmt, idx++, ss->src);
1191 __BIND_TEXT(db, stmt, idx++, ss->type);
1192 __BIND_TEXT(db, stmt, idx++, ss->orientation);
1193 __BIND_TEXT(db, stmt, idx++, ss->indicatordisplay);
1194 __BIND_TEXT(db, stmt, idx++, ss->operation);
1195 __BIND_TEXT(db, stmt, idx++, ss->color_depth);
1197 ret = sqlite3_step(stmt);
1198 if (ret != SQLITE_DONE) {
1199 _LOGE("step failed: %s", sqlite3_errmsg(db));
1200 sqlite3_finalize(stmt);
1204 sqlite3_reset(stmt);
1207 sqlite3_finalize(stmt);
1212 static void __trimfunc(GList *trim_list)
1216 GList *list = g_list_first(trim_list);
1219 trim_data = (char *)list->data;
1222 if (strcmp(trim_data, prev) == 0) {
1223 trim_list = g_list_remove(trim_list,
1225 list = g_list_first(trim_list);
1234 list = g_list_next(list);
1238 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
1240 if (a == NULL || b == NULL)
1242 if (strcmp((char *)a, (char *)b) == 0)
1244 if (strcmp((char *)a, (char *)b) < 0)
1246 if (strcmp((char *)a, (char *)b) > 0)
1251 /* TODO: refactor inserting localized info */
1252 static GList *__create_locale_list(GList *lbls, GList *lcns, GList *icns,
1253 GList *dcns, GList *aths)
1255 GList *locale = NULL;
1263 for (tmp = lbls; tmp; tmp = tmp->next) {
1264 lbl = (label_x *)tmp->data;
1268 locale = g_list_insert_sorted_with_data(
1269 locale, (gpointer)lbl->lang,
1270 __comparefunc, NULL);
1272 for (tmp = lcns; tmp; tmp = tmp->next) {
1273 lcn = (license_x *)tmp->data;
1277 locale = g_list_insert_sorted_with_data(
1278 locale, (gpointer)lcn->lang,
1279 __comparefunc, NULL);
1281 for (tmp = icns; tmp; tmp = tmp->next) {
1282 icn = (icon_x *)tmp->data;
1286 locale = g_list_insert_sorted_with_data(
1287 locale, (gpointer)icn->lang,
1288 __comparefunc, NULL);
1290 for (tmp = dcns; tmp; tmp = tmp->next) {
1291 dcn = (description_x *)tmp->data;
1295 locale = g_list_insert_sorted_with_data(
1296 locale, (gpointer)dcn->lang,
1297 __comparefunc, NULL);
1299 for (tmp = aths; tmp; tmp = tmp->next) {
1300 ath = (author_x *)tmp->data;
1304 locale = g_list_insert_sorted_with_data(
1305 locale, (gpointer)ath->lang,
1306 __comparefunc, NULL);
1312 static gint __check_icon_resolution(const char *orig_icon_path,
1313 char **new_icon_path)
1317 char *icon_filename;
1318 char modified_iconpath[BUFSIZE];
1319 char icon_path[BUFSIZE];
1323 if (orig_icon_path == NULL)
1326 ret = system_info_get_platform_int(
1327 "http://tizen.org/feature/screen.dpi", &dpi);
1328 if (ret != SYSTEM_INFO_ERROR_NONE)
1331 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
1332 dpi_path[0] = "LDPI";
1333 dpi_path[1] = "ldpi";
1334 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
1335 dpi_path[0] = "MDPI";
1336 dpi_path[1] = "mdpi";
1337 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
1338 dpi_path[0] = "HDPI";
1339 dpi_path[1] = "hdpi";
1340 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
1341 dpi_path[0] = "XHDPI";
1342 dpi_path[1] = "xhdpi";
1343 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
1344 dpi_path[0] = "XXHDPI";
1345 dpi_path[1] = "xxhdpi";
1347 _LOGE("Unidentified dpi[%d]", dpi);
1351 icon_filename = strrchr(orig_icon_path, '/');
1352 if (icon_filename == NULL)
1356 strlen(orig_icon_path) - (strlen(icon_filename) - 1),
1357 "%s", orig_icon_path);
1358 for (i = 0; i < 2; i++) {
1359 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s",
1360 icon_path, dpi_path[i], icon_filename);
1361 if (access(modified_iconpath, F_OK) != -1) {
1362 /* if exists, return modified icon path */
1363 *new_icon_path = strdup(modified_iconpath);
1371 static gint __compare_icon(gconstpointer a, gconstpointer b)
1373 icon_x *icon = (icon_x *)a;
1376 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
1379 if (icon->dpi != NULL)
1382 if (__check_icon_resolution(icon->text, &icon_path) == 0) {
1384 icon->text = icon_path;
1390 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
1392 icon_x *icon = (icon_x *)a;
1393 int dpi = GPOINTER_TO_INT(b);
1395 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
1398 if (icon->dpi == NULL)
1401 if (__check_dpi(icon->dpi, dpi) == 0)
1407 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
1409 icon_x *icon = (icon_x *)a;
1410 char *lang = (char *)b;
1413 if (icon->dpi != NULL)
1416 if (strcasecmp(icon->lang, lang) == 0) {
1417 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
1418 /* icon for no locale. check existance of
1419 * folder-hierachied default icons
1421 if (__check_icon_resolution(icon->text,
1424 icon->text = icon_path;
1433 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
1436 icon_x *icon = (icon_x *)a;
1437 char *lang = (char *)b;
1440 ret = system_info_get_platform_int(
1441 "http://tizen.org/feature/screen.dpi", &dpi);
1442 if (ret != SYSTEM_INFO_ERROR_NONE)
1445 if (strcasecmp(icon->lang, lang) == 0 &&
1446 __check_dpi(icon->dpi, dpi) == 0)
1452 static char *__find_icon(GList *icons, const char *lang)
1459 /* first, find icon whose locale and dpi with given lang and
1460 * system's dpi has matched
1462 tmp = g_list_find_custom(icons, lang,
1463 (GCompareFunc)__compare_icon_with_lang_dpi);
1465 icon = (icon_x *)tmp->data;
1466 return (char *)icon->text;
1469 /* if first has failed, find icon whose locale has matched */
1470 tmp = g_list_find_custom(icons, lang,
1471 (GCompareFunc)__compare_icon_with_lang);
1473 icon = (icon_x *)tmp->data;
1474 return (char *)icon->text;
1477 /* if second has failed, find icon whose dpi has matched with
1480 ret = system_info_get_platform_int(
1481 "http://tizen.org/feature/screen.dpi", &dpi);
1482 if (ret == SYSTEM_INFO_ERROR_NONE) {
1483 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi),
1484 (GCompareFunc)__compare_icon_with_dpi);
1486 icon = (icon_x *)tmp->data;
1487 return (char *)icon->text;
1491 /* last, find default icon marked as "No Locale" */
1492 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
1494 icon = (icon_x *)tmp->data;
1495 return (char *)icon->text;
1501 static void __extract_data(const char *locale, GList *lbls, GList *lcns,
1502 GList *icns, GList *dcns, GList *aths, char **label,
1503 char **license, char **icon, char **description, char **author)
1511 for (tmp = lbls; tmp; tmp = tmp->next) {
1512 lbl = (label_x *)tmp->data;
1516 if (strcmp(lbl->lang, locale) == 0) {
1517 *label = (char *)lbl->text;
1522 for (tmp = lcns; tmp; tmp = tmp->next) {
1523 lcn = (license_x *)tmp->data;
1527 if (strcmp(lcn->lang, locale) == 0) {
1528 *license = (char *)lcn->text;
1534 *icon = __find_icon(icns, locale);
1536 for (tmp = dcns; tmp; tmp = tmp->next) {
1537 dcn = (description_x *)tmp->data;
1541 if (strcmp(dcn->lang, locale) == 0) {
1542 *description = (char *)dcn->text;
1547 for (tmp = aths; tmp; tmp = tmp->next) {
1548 ath = (author_x *)tmp->data;
1552 if (strcmp(ath->lang, locale) == 0) {
1553 *author = (char *)ath->text;
1560 static int __insert_mainapp_localized_info(sqlite3 *db, application_x *app,
1561 const char *locale, const char *label, const char *icon)
1563 static const char query[] =
1564 "INSERT OR REPLACE INTO package_localized_info ("
1565 " package, package_locale, package_label, package_icon,"
1566 " package_description, package_license, package_author) "
1568 " COALESCE((SELECT package_label FROM package_localized_info"
1569 " WHERE package=? AND package_locale=?), ?),"
1570 " COALESCE((SELECT package_icon FROM package_localized_info"
1571 " WHERE package=? AND package_icon=?), ?),"
1572 " (SELECT package_description FROM package_localized_info"
1573 " WHERE package=? AND package_locale=?),"
1574 " (SELECT package_description FROM package_localized_info"
1575 " WHERE package=? AND package_locale=?),"
1576 " (SELECT package_description FROM package_localized_info"
1577 " WHERE package=? AND package_locale=?))";
1582 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1583 if (ret != SQLITE_OK) {
1584 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1588 __BIND_TEXT(db, stmt, idx++, app->package);
1589 __BIND_TEXT(db, stmt, idx++, locale);
1590 __BIND_TEXT(db, stmt, idx++, app->package);
1591 __BIND_TEXT(db, stmt, idx++, locale);
1592 __BIND_TEXT(db, stmt, idx++, label);
1593 __BIND_TEXT(db, stmt, idx++, app->package);
1594 __BIND_TEXT(db, stmt, idx++, locale);
1595 __BIND_TEXT(db, stmt, idx++, icon);
1596 __BIND_TEXT(db, stmt, idx++, app->package);
1597 __BIND_TEXT(db, stmt, idx++, locale);
1598 __BIND_TEXT(db, stmt, idx++, app->package);
1599 __BIND_TEXT(db, stmt, idx++, locale);
1600 __BIND_TEXT(db, stmt, idx++, app->package);
1601 __BIND_TEXT(db, stmt, idx++, locale);
1603 ret = sqlite3_step(stmt);
1604 if (ret != SQLITE_DONE) {
1605 _LOGE("step failed: %s", sqlite3_errmsg(db));
1606 sqlite3_finalize(stmt);
1610 sqlite3_finalize(stmt);
1615 static int __insert_app_localized_info(sqlite3 *db, application_x *app)
1617 static const char query[] =
1618 "INSERT INTO package_app_localized_info (app_id, app_locale,"
1619 " app_label, app_icon) "
1620 "VALUES (?, ?, ?, ?)";
1630 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1631 if (ret != SQLITE_OK) {
1632 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1636 locales = __create_locale_list(app->label, NULL, app->icon, NULL, NULL);
1637 for (tmp = locales; tmp; tmp = tmp->next) {
1638 locale = (const char *)tmp->data;
1641 __extract_data(locale, app->label, NULL, app->icon, NULL, NULL,
1642 &label, NULL, &icon, NULL, NULL);
1643 if (!label && !icon)
1647 __BIND_TEXT(db, stmt, idx++, app->appid);
1648 __BIND_TEXT(db, stmt, idx++, locale);
1649 __BIND_TEXT(db, stmt, idx++, label);
1650 __BIND_TEXT(db, stmt, idx++, icon);
1652 ret = sqlite3_step(stmt);
1653 if (ret != SQLITE_DONE) {
1654 _LOGE("step failed: %s", sqlite3_errmsg(db));
1655 g_list_free(locales);
1656 sqlite3_finalize(stmt);
1660 sqlite3_reset(stmt);
1662 if (strcasecmp(app->mainapp, "true") == 0) {
1663 if (__insert_mainapp_localized_info(db, app, locale,
1665 _LOGE("insert mainapp localized info failed");
1669 g_list_free(locales);
1670 sqlite3_finalize(stmt);
1675 static int __insert_package_privilege_info(sqlite3 *db, manifest_x *mfx)
1677 static const char query[] =
1678 "INSERT INTO package_privilege_info (package, privilege, type) "
1686 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1687 if (ret != SQLITE_OK) {
1688 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1692 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1693 priv = (privilege_x *)tmp->data;
1698 __BIND_TEXT(db, stmt, idx++, mfx->package);
1699 __BIND_TEXT(db, stmt, idx++, priv->value);
1700 __BIND_TEXT(db, stmt, idx++, priv->type);
1702 ret = sqlite3_step(stmt);
1703 if (ret != SQLITE_DONE) {
1704 _LOGE("step failed: %s", sqlite3_errmsg(db));
1705 sqlite3_finalize(stmt);
1708 sqlite3_reset(stmt);
1711 sqlite3_finalize(stmt);
1716 static int __insert_package_appdefined_privilege_info(sqlite3 *db,
1719 static const char query[] =
1720 "INSERT INTO package_appdefined_privilege_info "
1721 "(package, privilege, license, type) "
1722 "VALUES (?, ?, ?, ?)";
1727 appdefined_privilege_x *priv;
1729 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1730 if (ret != SQLITE_OK) {
1731 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1735 for (tmp = mfx->appdefined_privileges; tmp; tmp = tmp->next) {
1736 priv = (appdefined_privilege_x *)tmp->data;
1741 __BIND_TEXT(db, stmt, idx++, mfx->package);
1742 __BIND_TEXT(db, stmt, idx++, priv->value);
1743 __BIND_TEXT(db, stmt, idx++, priv->license);
1744 __BIND_TEXT(db, stmt, idx++, priv->type);
1746 ret = sqlite3_step(stmt);
1747 if (ret != SQLITE_DONE) {
1748 _LOGE("step failed: %s", sqlite3_errmsg(db));
1749 sqlite3_finalize(stmt);
1752 sqlite3_reset(stmt);
1755 sqlite3_finalize(stmt);
1760 static int __insert_package_dependency_info(sqlite3 *db, manifest_x *mfx)
1762 static const char query[] =
1763 "INSERT INTO package_dependency_info"
1764 " (package, depends_on, type, required_version) "
1765 "VALUES (?, ?, ?, ?)";
1772 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1773 if (ret != SQLITE_OK) {
1774 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1778 for (tmp = mfx->dependencies; tmp; tmp = tmp->next) {
1779 dep = (dependency_x *)tmp->data;
1784 __BIND_TEXT(db, stmt, idx++, mfx->package);
1785 __BIND_TEXT(db, stmt, idx++, dep->depends_on);
1786 __BIND_TEXT(db, stmt, idx++, dep->type);
1787 __BIND_TEXT(db, stmt, idx++, dep->required_version);
1789 ret = sqlite3_step(stmt);
1790 if (ret != SQLITE_DONE) {
1791 _LOGE("step failed: %s", sqlite3_errmsg(db));
1792 sqlite3_finalize(stmt);
1795 sqlite3_reset(stmt);
1798 sqlite3_finalize(stmt);
1803 /* _PRODUCT_LAUNCHING_ENHANCED_
1804 * app->indicatordisplay, app->portraitimg, app->landscapeimg,
1805 * app->guestmode_appstatus
1807 static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
1809 static const char query[] =
1810 "INSERT INTO package_app_info (app_id, app_component,"
1811 " app_exec, app_nodisplay, app_type, app_onboot, app_multiple,"
1812 " app_autorestart, app_taskmanage, app_hwacceleration,"
1813 " app_screenreader, app_mainapp, app_recentimage,"
1814 " app_launchcondition, app_indicatordisplay, app_portraitimg,"
1815 " app_landscapeimg, app_guestmodevisibility,"
1816 " app_permissiontype, app_preload, app_submode,"
1817 " app_submode_mainid, app_installed_storage, app_process_pool,"
1818 " app_launch_mode, app_ui_gadget, app_support_mode,"
1819 " app_support_disable, component_type, package, app_tep_name,"
1820 " app_zip_mount_file, app_background_category,"
1821 " app_package_type, app_root_path, app_api_version,"
1822 " app_effective_appid, app_splash_screen_display,"
1823 " app_package_system, app_removable,"
1824 " app_package_installed_time, app_support_ambient,"
1825 " app_external_path, app_setup_appid) "
1827 " ?, LOWER(?), ?, LOWER(?), LOWER(?),"
1828 " LOWER(?), LOWER(?), ?,"
1832 " ?, LOWER(?), LOWER(?),"
1834 " COALESCE(?, 'single'), LOWER(?), ?,"
1835 " LOWER(?), ?, ?, ?,"
1839 " LOWER(?), LOWER(?),"
1848 const char *effective_appid;
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->application; tmp; tmp = tmp->next) {
1858 app = (application_x *)tmp->data;
1862 bg_category = __convert_background_category(
1863 app->background_category);
1864 effective_appid = __find_effective_appid(app->metadata);
1867 __BIND_TEXT(db, stmt, idx++, app->appid);
1868 __BIND_TEXT(db, stmt, idx++, app->component_type);
1869 __BIND_TEXT(db, stmt, idx++, app->exec);
1870 __BIND_TEXT(db, stmt, idx++, __get_bool(app->nodisplay, false));
1871 __BIND_TEXT(db, stmt, idx++, app->type);
1872 __BIND_TEXT(db, stmt, idx++, __get_bool(app->onboot, false));
1873 __BIND_TEXT(db, stmt, idx++, __get_bool(app->multiple, false));
1874 __BIND_TEXT(db, stmt, idx++,
1875 __get_bool(app->autorestart, false));
1876 __BIND_TEXT(db, stmt, idx++,
1877 __get_bool(app->taskmanage, false));
1878 __BIND_TEXT(db, stmt, idx++, app->hwacceleration);
1879 __BIND_TEXT(db, stmt, idx++, app->screenreader);
1880 __BIND_TEXT(db, stmt, idx++, __get_bool(app->mainapp, false));
1881 __BIND_TEXT(db, stmt, idx++, app->recentimage);
1882 __BIND_TEXT(db, stmt, idx++, app->launchcondition);
1883 __BIND_TEXT(db, stmt, idx++,
1884 __get_bool(app->indicatordisplay, true));
1885 __BIND_TEXT(db, stmt, idx++, app->portraitimg);
1886 __BIND_TEXT(db, stmt, idx++, app->landscapeimg);
1887 __BIND_TEXT(db, stmt, idx++,
1888 __get_bool(app->guestmode_visibility, true));
1889 __BIND_TEXT(db, stmt, idx++, app->permission_type);
1890 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->preload, false));
1891 __BIND_TEXT(db, stmt, idx++, __get_bool(app->submode, false));
1892 __BIND_TEXT(db, stmt, idx++, app->submode_mainid);
1893 __BIND_TEXT(db, stmt, idx++, mfx->installed_storage);
1894 __BIND_TEXT(db, stmt, idx++,
1895 __get_bool(app->process_pool, false));
1896 __BIND_TEXT(db, stmt, idx++, app->launch_mode);
1897 __BIND_TEXT(db, stmt, idx++, __get_bool(app->ui_gadget, false));
1898 __BIND_TEXT(db, stmt, idx++, app->support_mode);
1899 __BIND_TEXT(db, stmt, idx++,
1900 __get_bool(mfx->support_disable, false));
1901 __BIND_TEXT(db, stmt, idx++, app->component_type);
1902 __BIND_TEXT(db, stmt, idx++, mfx->package);
1903 __BIND_TEXT(db, stmt, idx++, mfx->tep_name);
1904 __BIND_TEXT(db, stmt, idx++, mfx->zip_mount_file);
1905 __BIND_INT(db, stmt, idx++, bg_category);
1906 __BIND_TEXT(db, stmt, idx++, mfx->type ? mfx->type : "tpk");
1907 __BIND_TEXT(db, stmt, idx++, mfx->root_path);
1908 __BIND_TEXT(db, stmt, idx++, mfx->api_version);
1909 __BIND_TEXT(db, stmt, idx++, effective_appid);
1910 __BIND_TEXT(db, stmt, idx++,
1911 __get_bool(app->splash_screen_display, true));
1912 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->system, false));
1913 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->removable, false));
1914 __BIND_TEXT(db, stmt, idx++, mfx->installed_time);
1915 __BIND_TEXT(db, stmt, idx++,
1916 __get_bool(app->support_ambient, false));
1917 __BIND_TEXT(db, stmt, idx++, mfx->external_path);
1918 __BIND_TEXT(db, stmt, idx++, app->setup_appid);
1920 ret = sqlite3_step(stmt);
1921 if (ret != SQLITE_DONE) {
1922 _LOGE("step failed: %s", sqlite3_errmsg(db));
1923 sqlite3_finalize(stmt);
1927 sqlite3_reset(stmt);
1929 if (__insert_appcontrol_info(db, app)) {
1930 sqlite3_finalize(stmt);
1933 if (__insert_category_info(db, app)) {
1934 sqlite3_finalize(stmt);
1937 if (__insert_metadata_info(db, app)) {
1938 sqlite3_finalize(stmt);
1941 if (__insert_datacontrol_info(db, app)) {
1942 sqlite3_finalize(stmt);
1945 ss_list = __find_splashscreens(app->splashscreens);
1946 if (__insert_splashscreen_info(db, app, ss_list)) {
1947 g_list_free(ss_list);
1948 sqlite3_finalize(stmt);
1951 g_list_free(ss_list);
1952 if (__insert_app_localized_info(db, app)) {
1953 sqlite3_finalize(stmt);
1958 sqlite3_finalize(stmt);
1963 static int __insert_package_update_info(sqlite3 *db, manifest_x *mfx)
1965 static const char query[] =
1966 "INSERT INTO package_update_info (package, update_version) "
1972 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1973 if (ret != SQLITE_OK) {
1974 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1979 __BIND_TEXT(db, stmt, idx++, mfx->package);
1980 __BIND_TEXT(db, stmt, idx, mfx->version);
1981 ret = sqlite3_step(stmt);
1982 if (ret != SQLITE_DONE) {
1983 _LOGE("step failed: %s", sqlite3_errmsg(db));
1984 sqlite3_finalize(stmt);
1987 sqlite3_finalize(stmt);
1992 static int __insert_package_localized_info(sqlite3 *db, manifest_x *mfx)
1994 static const char query[] =
1995 "INSERT INTO package_localized_info (package, package_locale,"
1996 " package_label, package_icon, package_description,"
1997 " package_license, package_author) "
1998 "VALUES (?, ?, ?, ?, ?, ?, ?)";
2011 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2012 if (ret != SQLITE_OK) {
2013 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2017 locales = __create_locale_list(mfx->label, mfx->license, mfx->icon,
2018 mfx->description, mfx->author);
2019 for (tmp = locales; tmp; tmp = tmp->next) {
2020 locale = (const char *)tmp->data;
2026 __extract_data(locale, mfx->label, mfx->license, mfx->icon,
2027 mfx->description, mfx->author,
2028 &label, &license, &icon, &description, &author);
2029 if (!label && !license && !icon && !description && !author)
2033 __BIND_TEXT(db, stmt, idx++, mfx->package);
2034 __BIND_TEXT(db, stmt, idx++, locale);
2035 __BIND_TEXT(db, stmt, idx++, label);
2036 __BIND_TEXT(db, stmt, idx++, icon);
2037 __BIND_TEXT(db, stmt, idx++, description);
2038 __BIND_TEXT(db, stmt, idx++, license);
2039 __BIND_TEXT(db, stmt, idx++, author);
2041 ret = sqlite3_step(stmt);
2042 if (ret != SQLITE_DONE) {
2043 _LOGE("step failed: %s", sqlite3_errmsg(db));
2044 g_list_free(locales);
2045 sqlite3_finalize(stmt);
2049 sqlite3_reset(stmt);
2052 g_list_free(locales);
2053 sqlite3_finalize(stmt);
2058 static int __insert_package_info(sqlite3 *db, manifest_x *mfx)
2060 static const char query[] =
2061 "INSERT INTO package_info (package, package_type,"
2062 " package_version, package_api_version, package_tep_name,"
2063 " package_zip_mount_file, install_location, package_size,"
2064 " package_removable, package_preload, package_readonly,"
2065 " package_update, package_appsetting, package_nodisplay,"
2066 " package_system, author_name, author_email, author_href,"
2067 " installed_time, installed_storage, storeclient_id,"
2068 " mainapp_id, package_url, root_path, external_path,"
2069 " csc_path, package_support_mode, package_support_disable) "
2073 " LOWER(?), LOWER(?), LOWER(?),"
2074 " LOWER(?), LOWER(?), LOWER(?),"
2075 " LOWER(?), ?, ?, ?,"
2082 const char *author_name = NULL;
2083 const char *author_email = NULL;
2084 const char *author_href = NULL;
2086 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2087 if (ret != SQLITE_OK) {
2088 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2092 if (mfx->author && mfx->author->data) {
2093 author_name = ((author_x *)mfx->author->data)->text;
2094 author_email = ((author_x *)mfx->author->data)->email;
2095 author_href = ((author_x *)mfx->author->data)->href;
2098 __BIND_TEXT(db, stmt, idx++, mfx->package);
2099 __BIND_TEXT(db, stmt, idx++, mfx->type);
2100 __BIND_TEXT(db, stmt, idx++, mfx->version);
2101 __BIND_TEXT(db, stmt, idx++, mfx->api_version);
2102 __BIND_TEXT(db, stmt, idx++, mfx->tep_name);
2103 __BIND_TEXT(db, stmt, idx++, mfx->zip_mount_file);
2104 __BIND_TEXT(db, stmt, idx++, mfx->installlocation);
2105 __BIND_TEXT(db, stmt, idx++, mfx->package_size);
2106 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->removable, true));
2107 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->preload, false));
2108 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->readonly, false));
2109 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->update, false));
2110 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->appsetting, false));
2111 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->nodisplay_setting, false));
2112 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->system, false));
2113 __BIND_TEXT(db, stmt, idx++, author_name);
2114 __BIND_TEXT(db, stmt, idx++, author_email);
2115 __BIND_TEXT(db, stmt, idx++, author_href);
2116 __BIND_TEXT(db, stmt, idx++, mfx->installed_time);
2117 __BIND_TEXT(db, stmt, idx++, mfx->installed_storage);
2118 __BIND_TEXT(db, stmt, idx++, mfx->storeclient_id);
2119 __BIND_TEXT(db, stmt, idx++, mfx->mainapp_id);
2120 __BIND_TEXT(db, stmt, idx++, mfx->package_url);
2121 __BIND_TEXT(db, stmt, idx++, mfx->root_path);
2122 __BIND_TEXT(db, stmt, idx++, mfx->external_path);
2123 __BIND_TEXT(db, stmt, idx++, mfx->csc_path);
2124 __BIND_TEXT(db, stmt, idx++, mfx->support_mode);
2125 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->support_disable, false));
2127 ret = sqlite3_step(stmt);
2128 if (ret != SQLITE_DONE) {
2129 _LOGE("step failed: %s", sqlite3_errmsg(db));
2130 sqlite3_finalize(stmt);
2134 sqlite3_finalize(stmt);
2136 if (__insert_package_update_info(db, mfx))
2138 if (__insert_package_localized_info(db, mfx))
2140 if (__insert_application_info(db, mfx))
2142 if (__insert_package_privilege_info(db, mfx))
2144 if (__insert_package_appdefined_privilege_info(db, mfx))
2146 if (__insert_package_dependency_info(db, mfx))
2152 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2159 _LOGE("invalid parameter");
2160 return PM_PARSER_R_EINVAL;
2163 dbpath = __get_parser_db_path(uid);
2165 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2166 if (ret != SQLITE_OK) {
2167 _LOGE("open db failed: %d", ret);
2168 return PM_PARSER_R_ERROR;
2171 __BEGIN_TRANSACTION(db);
2172 __DO_TRANSACTION(db, __insert_package_info(db, mfx));
2173 __END_TRANSACTION(db);
2175 sqlite3_close_v2(db);
2177 return PM_PARSER_R_OK;
2180 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2182 return pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, __getuid());
2185 static int __delete_package_info(sqlite3 *db, const char *pkgid)
2187 static const char query[] =
2188 "DELETE FROM package_info WHERE package=?";
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, 1, pkgid);
2200 ret = sqlite3_step(stmt);
2201 if (ret != SQLITE_DONE) {
2202 _LOGE("step failed: %s", sqlite3_errmsg(db));
2203 sqlite3_finalize(stmt);
2207 sqlite3_finalize(stmt);
2212 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx,
2220 _LOGE("invalid parameter");
2221 return PM_PARSER_R_EINVAL;
2224 dbpath = __get_parser_db_path(uid);
2226 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2227 if (ret != SQLITE_OK) {
2228 _LOGE("open db failed: %d", ret);
2229 return PM_PARSER_R_ERROR;
2232 __BEGIN_TRANSACTION(db);
2233 __DO_TRANSACTION(db, __delete_package_info(db, mfx->package));
2234 __END_TRANSACTION(db);
2236 sqlite3_close_v2(db);
2238 return PM_PARSER_R_OK;
2241 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2243 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, __getuid());
2246 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2253 _LOGE("invalid parameter");
2254 return PM_PARSER_R_EINVAL;
2257 dbpath = __get_parser_db_path(uid);
2259 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2260 if (ret != SQLITE_OK) {
2261 _LOGE("open db failed: %d", ret);
2262 return PM_PARSER_R_ERROR;
2265 __BEGIN_TRANSACTION(db);
2266 __DO_TRANSACTION(db, __delete_package_info(db, mfx->package));
2267 __DO_TRANSACTION(db, __insert_package_info(db, mfx));
2268 __END_TRANSACTION(db);
2270 sqlite3_close_v2(db);
2272 return PM_PARSER_R_OK;
2275 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2277 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, __getuid());
2280 static int __set_global_app_disable_for_uid(sqlite3 *db, const char *appid,
2281 uid_t uid, bool is_disable)
2283 static const char query[] =
2284 "INSERT OR REPLACE INTO package_app_info_for_uid ("
2285 " app_id, uid, is_disabled, is_splash_screen_enabled) "
2287 " (SELECT app_splash_screen_display FROM package_app_info"
2288 " WHERE app_id=?))";
2293 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2294 if (ret != SQLITE_OK) {
2295 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2299 __BIND_TEXT(db, stmt, idx++, appid);
2300 __BIND_INT(db, stmt, idx++, uid);
2301 __BIND_TEXT(db, stmt, idx++, is_disable ? "true" : "false");
2302 __BIND_TEXT(db, stmt, idx++, appid);
2304 ret = sqlite3_step(stmt);
2305 if (ret != SQLITE_DONE) {
2306 _LOGE("step failed: %s", sqlite3_errmsg(db));
2307 sqlite3_finalize(stmt);
2311 sqlite3_finalize(stmt);
2316 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(
2317 const char *appid, uid_t uid, int is_disable)
2323 if (appid == NULL) {
2324 _LOGE("invalid parameter");
2325 return PM_PARSER_R_EINVAL;
2328 dbpath = __get_parser_db_path(GLOBAL_USER);
2330 ret = __open_db(GLOBAL_USER, dbpath, &db, SQLITE_OPEN_READWRITE);
2331 if (ret != SQLITE_OK) {
2332 _LOGE("open db failed: %d", ret);
2333 return PM_PARSER_R_ERROR;
2336 __BEGIN_TRANSACTION(db);
2337 __DO_TRANSACTION(db, __set_global_app_disable_for_uid(db, appid,
2338 uid, (bool)is_disable));
2339 __END_TRANSACTION(db);
2341 sqlite3_close_v2(db);
2343 return PM_PARSER_R_OK;
2346 static int __set_app_disable(sqlite3 *db, const char *appid, uid_t uid,
2349 static const char query[] =
2350 "UPDATE package_app_info SET app_disable=? "
2356 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2357 if (ret != SQLITE_OK) {
2358 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2362 __BIND_TEXT(db, stmt, idx++, is_disable ? "true" : "false");
2363 __BIND_TEXT(db, stmt, idx++, appid);
2365 ret = sqlite3_step(stmt);
2366 if (ret != SQLITE_DONE) {
2367 _LOGE("step failed: %s", sqlite3_errmsg(db));
2368 sqlite3_finalize(stmt);
2372 sqlite3_finalize(stmt);
2377 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid,
2378 uid_t uid, int is_disable)
2384 if (appid == NULL) {
2385 _LOGE("invalid parameter");
2386 return PM_PARSER_R_EINVAL;
2389 dbpath = __get_parser_db_path(uid);
2391 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2392 if (ret != SQLITE_OK) {
2393 _LOGE("open db failed: %d", ret);
2394 return PM_PARSER_R_ERROR;
2397 __BEGIN_TRANSACTION(db);
2398 __DO_TRANSACTION(db, __set_app_disable(db, appid, uid,
2400 __END_TRANSACTION(db);
2402 sqlite3_close_v2(db);
2404 return PM_PARSER_R_OK;
2407 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid,
2410 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid,
2411 __getuid(), is_disable);
2414 static int __set_pkg_disable(sqlite3 *db, const char *pkgid, uid_t uid,
2417 static const char query[] =
2418 "UPDATE package_info SET package_disable=? "
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++, is_disable ? "true" : "false");
2431 __BIND_TEXT(db, stmt, idx++, pkgid);
2433 ret = sqlite3_step(stmt);
2434 if (ret != SQLITE_DONE) {
2435 _LOGE("step failed: %s", sqlite3_errmsg(db));
2436 sqlite3_finalize(stmt);
2440 sqlite3_finalize(stmt);
2445 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid,
2446 uid_t uid, int is_disable)
2452 if (pkgid == NULL) {
2453 _LOGE("invalid parameter");
2454 return PM_PARSER_R_EINVAL;
2457 dbpath = __get_parser_db_path(uid);
2459 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2460 if (ret != SQLITE_OK) {
2461 _LOGE("open db failed: %d", ret);
2462 return PM_PARSER_R_ERROR;
2465 __BEGIN_TRANSACTION(db);
2466 __DO_TRANSACTION(db, __set_pkg_disable(db, pkgid, uid,
2468 __END_TRANSACTION(db);
2470 sqlite3_close_v2(db);
2472 return PM_PARSER_R_OK;
2475 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid,
2478 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid,
2479 __getuid(), is_disable);
2482 static int __set_global_app_splash_screen_for_uid(sqlite3 *db,
2483 const char *appid, uid_t uid, bool is_enabled)
2485 static const char query[] =
2486 "INSERT OR REPLACE INTO package_app_info_for_uid("
2487 " appid, uid, is_splash_screen_enabled) "
2493 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2494 if (ret != SQLITE_OK) {
2495 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2499 __BIND_TEXT(db, stmt, idx++, appid);
2500 __BIND_INT(db, stmt, idx++, uid);
2501 __BIND_TEXT(db, stmt, idx++, is_enabled ? "true" : "false");
2503 ret = sqlite3_step(stmt);
2504 if (ret != SQLITE_DONE) {
2505 _LOGE("step failed: %s", sqlite3_errmsg(db));
2506 sqlite3_finalize(stmt);
2510 sqlite3_finalize(stmt);
2515 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(
2516 const char *appid, uid_t uid, int flag)
2522 if (appid == NULL) {
2523 _LOGE("invalid parameter");
2524 return PM_PARSER_R_EINVAL;
2527 dbpath = __get_parser_db_path(GLOBAL_USER);
2529 ret = __open_db(GLOBAL_USER, dbpath, &db, SQLITE_OPEN_READWRITE);
2530 if (ret != SQLITE_OK) {
2531 _LOGE("open db failed: %d", ret);
2532 return PM_PARSER_R_ERROR;
2535 __BEGIN_TRANSACTION(db);
2536 __DO_TRANSACTION(db, __set_global_app_splash_screen_for_uid(db,
2537 appid, uid, (bool)flag));
2538 __END_TRANSACTION(db);
2540 sqlite3_close_v2(db);
2542 return PM_PARSER_R_OK;
2545 static int __set_app_splash_screen(sqlite3 *db, const char *appid,
2548 static const char query[] =
2549 "UPDATE package_app_info SET app_splash_screen_display=? "
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_enabled ? "true" : "false");
2562 __BIND_TEXT(db, stmt, idx++, appid);
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_app_splash_screen_display_info_in_usr_db(
2577 const char *appid, uid_t uid, int flag)
2583 if (appid == 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_app_splash_screen(db, appid, (bool)flag));
2598 __END_TRANSACTION(db);
2600 sqlite3_close_v2(db);
2602 return PM_PARSER_R_OK;
2605 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(
2606 const char *appid, int flag)
2608 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(
2609 appid, __getuid(), flag);
2612 static int __set_app_label(sqlite3 *db, const char *appid, const char *label)
2614 static const char query[] =
2615 "UPDATE package_app_localized_info SET app_label=? "
2616 "WHERE app_id=? AND app_label IS NOT NULL";
2621 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2622 if (ret != SQLITE_OK) {
2623 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2627 __BIND_TEXT(db, stmt, idx++, label);
2628 __BIND_TEXT(db, stmt, idx++, appid);
2630 ret = sqlite3_step(stmt);
2631 if (ret != SQLITE_DONE) {
2632 _LOGE("step failed: %s", sqlite3_errmsg(db));
2633 sqlite3_finalize(stmt);
2637 sqlite3_finalize(stmt);
2642 API int pkgmgr_parser_update_app_label_info_in_usr_db(const char *appid,
2643 uid_t uid, const char *label)
2649 if (appid == NULL) {
2650 _LOGE("invalid parameter");
2651 return PM_PARSER_R_EINVAL;
2654 dbpath = __get_parser_db_path(uid);
2656 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2657 if (ret != SQLITE_OK) {
2658 _LOGE("open db failed: %d", ret);
2659 return PM_PARSER_R_ERROR;
2662 __BEGIN_TRANSACTION(db);
2663 __DO_TRANSACTION(db, __set_app_label(db, appid, label));
2664 __END_TRANSACTION(db);
2666 sqlite3_close_v2(db);
2668 return PM_PARSER_R_OK;
2671 API int pkgmgr_parser_update_app_label_info_in_db(const char *appid,
2674 return pkgmgr_parser_update_app_label_info_in_usr_db(appid, __getuid(),
2678 static int __set_app_icon(sqlite3 *db, const char *appid, const char *icon_path)
2680 static const char query[] =
2681 "UPDATE package_app_localized_info SET app_icon=? "
2682 "WHERE app_id=? AND app_icon IS NOT NULL";
2687 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2688 if (ret != SQLITE_OK) {
2689 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2693 __BIND_TEXT(db, stmt, idx++, icon_path);
2694 __BIND_TEXT(db, stmt, idx++, appid);
2696 ret = sqlite3_step(stmt);
2697 if (ret != SQLITE_DONE) {
2698 _LOGE("step failed: %s", sqlite3_errmsg(db));
2699 sqlite3_finalize(stmt);
2703 sqlite3_finalize(stmt);
2708 API int pkgmgr_parser_update_app_icon_info_in_usr_db(const char *appid,
2709 uid_t uid, const char *icon_path)
2715 if (appid == NULL) {
2716 _LOGE("invalid parameter");
2717 return PM_PARSER_R_EINVAL;
2720 dbpath = __get_parser_db_path(uid);
2722 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2723 if (ret != SQLITE_OK) {
2724 _LOGE("open db failed: %d", ret);
2725 return PM_PARSER_R_ERROR;
2728 __BEGIN_TRANSACTION(db);
2729 __DO_TRANSACTION(db, __set_app_icon(db, appid, icon_path));
2730 __END_TRANSACTION(db);
2732 sqlite3_close_v2(db);
2734 return PM_PARSER_R_OK;
2737 API int pkgmgr_parser_update_app_icon_info_in_db(const char *appid,
2738 const char *icon_path)
2740 return pkgmgr_parser_update_app_icon_info_in_usr_db(appid, __getuid(),
2744 static int __set_tep_path(sqlite3 *db, const char *pkgid, const char *tep_path)
2746 static const char query[] =
2747 "UPDATE package_info SET package_tep_name=? "
2753 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2754 if (ret != SQLITE_OK) {
2755 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2759 __BIND_TEXT(db, stmt, idx++, tep_path);
2760 __BIND_TEXT(db, stmt, idx++, pkgid);
2762 ret = sqlite3_step(stmt);
2763 if (ret != SQLITE_DONE) {
2764 _LOGE("step failed: %s", sqlite3_errmsg(db));
2765 sqlite3_finalize(stmt);
2769 sqlite3_finalize(stmt);
2774 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid,
2775 const char *tep_path, uid_t uid)
2781 if (pkgid == NULL) {
2782 _LOGE("invalid parameter");
2783 return PM_PARSER_R_EINVAL;
2786 dbpath = __get_parser_db_path(uid);
2788 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2789 if (ret != SQLITE_OK) {
2790 _LOGE("open db failed: %d", ret);
2791 return PM_PARSER_R_ERROR;
2794 __BEGIN_TRANSACTION(db);
2795 __DO_TRANSACTION(db, __set_tep_path(db, pkgid, tep_path));
2796 __END_TRANSACTION(db);
2798 sqlite3_close_v2(db);
2800 return PM_PARSER_R_OK;
2803 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid,
2804 const char *tep_path)
2806 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path,
2810 static int __convert_update_type(pkgmgrinfo_updateinfo_update_type type,
2811 const char **update_type)
2813 if (type == PMINFO_UPDATEINFO_NONE)
2814 *update_type = PMINFO_UPDATEINFO_TYPE_NONE;
2815 else if (type == PMINFO_UPDATEINFO_FORCE)
2816 *update_type = PMINFO_UPDATEINFO_TYPE_FORCE;
2817 else if (type == PMINFO_UPDATEINFO_OPTIONAL)
2818 *update_type = PMINFO_UPDATEINFO_TYPE_OPTIONAL;
2824 static int __register_pkg_update_info(sqlite3 *db, updateinfo_x *info,
2825 const char *update_type)
2827 static const char query[] =
2828 "UPDATE package_update_info "
2829 "SET update_version=?, update_type=? "
2835 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2836 if (ret != SQLITE_OK) {
2837 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2841 __BIND_TEXT(db, stmt, idx++, info->version);
2842 __BIND_TEXT(db, stmt, idx++, update_type);
2843 __BIND_TEXT(db, stmt, idx++, info->pkgid);
2845 ret = sqlite3_step(stmt);
2846 if (ret != SQLITE_DONE) {
2847 _LOGE("step failed: %s", sqlite3_errmsg(db));
2848 sqlite3_finalize(stmt);
2852 sqlite3_finalize(stmt);
2857 API int pkgmgr_parser_register_pkg_update_info_in_usr_db(
2858 pkgmgrinfo_updateinfo_h handle, uid_t uid)
2861 updateinfo_x *update_info;
2862 updateinfo_x *prev_update_info;
2863 pkgmgrinfo_updateinfo_h prev_update_handle;
2864 pkgmgrinfo_pkginfo_h pkginfo;
2865 pkgmgrinfo_version_compare_type compare_result;
2867 const char *update_type;
2871 if (handle == NULL) {
2872 _LOGE("invalid parameter");
2873 return PM_PARSER_R_EINVAL;
2876 update_info = (updateinfo_x *)handle;
2877 if (update_info->pkgid == NULL || update_info->version == NULL)
2878 return PM_PARSER_R_EINVAL;
2879 if (__convert_update_type(update_info->type, &update_type) != 0)
2880 return PM_PARSER_R_EINVAL;
2882 ret = pkgmgrinfo_updateinfo_get_usr_updateinfo(update_info->pkgid,
2883 &prev_update_handle, uid);
2884 if (ret != PMINFO_R_OK)
2885 return PM_PARSER_R_ERROR;
2887 prev_update_info = (updateinfo_x *)prev_update_handle;
2888 ret = pkgmgrinfo_compare_package_version(update_info->version,
2889 prev_update_info->version, &compare_result);
2890 if (ret != PMINFO_R_OK) {
2891 pkgmgrinfo_updateinfo_destroy(prev_update_handle);
2892 return PM_PARSER_R_ERROR;
2895 if (compare_result == PMINFO_VERSION_SAME &&
2896 prev_update_info->type == PMINFO_UPDATEINFO_NONE) {
2897 _LOGI("Given update info version[%s] of pkgid[%s] "
2899 update_info->version, update_info->pkgid);
2900 pkgmgrinfo_updateinfo_destroy(prev_update_handle);
2901 return PM_PARSER_R_OK;
2903 pkgmgrinfo_updateinfo_destroy(prev_update_handle);
2905 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(update_info->pkgid, uid,
2907 if (ret != PMINFO_R_OK)
2908 return PM_PARSER_R_ERROR;
2910 ret = pkgmgrinfo_pkginfo_is_global(pkginfo, &is_global_pkg);
2911 if (ret != PMINFO_R_OK) {
2912 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
2913 return PM_PARSER_R_ERROR;
2915 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
2917 dbpath = __get_parser_db_path(is_global_pkg ? GLOBAL_USER : 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, __register_pkg_update_info(db, update_info,
2928 __END_TRANSACTION(db);
2930 sqlite3_close_v2(db);
2932 return PM_PARSER_R_OK;
2935 API int pkgmgr_parser_register_pkg_update_info_in_db(
2936 pkgmgrinfo_updateinfo_h handle)
2938 return pkgmgr_parser_register_pkg_update_info_in_usr_db(handle,
2942 static int __unregister_pkg_update_info(sqlite3 *db, const char *pkgid)
2944 static const char query[] =
2945 "UPDATE package_update_info SET update_type='none' "
2951 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2952 if (ret != SQLITE_OK) {
2953 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2957 __BIND_TEXT(db, stmt, idx++, pkgid);
2959 ret = sqlite3_step(stmt);
2960 if (ret != SQLITE_DONE) {
2961 _LOGE("step failed: %s", sqlite3_errmsg(db));
2962 sqlite3_finalize(stmt);
2966 sqlite3_finalize(stmt);
2971 API int pkgmgr_parser_unregister_pkg_update_info_in_usr_db(const char *pkgid,
2977 pkgmgrinfo_pkginfo_h pkginfo;
2980 if (pkgid == NULL) {
2981 _LOGE("invalid parameter");
2982 return PM_PARSER_R_EINVAL;
2985 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &pkginfo);
2986 if (ret != PMINFO_R_OK)
2987 return PM_PARSER_R_EINVAL;
2989 ret = pkgmgrinfo_pkginfo_is_global(pkginfo, &is_global_pkg);
2990 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
2991 if (ret != PMINFO_R_OK)
2992 return PM_PARSER_R_ERROR;
2994 dbpath = __get_parser_db_path(is_global_pkg ? GLOBAL_USER : uid);
2996 ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
2997 if (ret != SQLITE_OK) {
2998 _LOGE("open db failed: %d", ret);
2999 return PM_PARSER_R_ERROR;
3002 __BEGIN_TRANSACTION(db);
3003 __DO_TRANSACTION(db, __unregister_pkg_update_info(db, pkgid));
3004 __END_TRANSACTION(db);
3006 sqlite3_close_v2(db);
3008 return PM_PARSER_R_OK;
3011 API int pkgmgr_parser_unregister_pkg_update_info_in_db(const char *pkgid)
3013 return pkgmgr_parser_unregister_pkg_update_info_in_usr_db(pkgid,
3017 static int __unregister_all_pkg_update_info(sqlite3 *db)
3019 static const char query[] =
3020 "UPDATE package_update_info SET update_type='none'";
3024 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
3025 if (ret != SQLITE_OK) {
3026 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
3030 ret = sqlite3_step(stmt);
3031 if (ret != SQLITE_DONE) {
3032 _LOGE("step failed: %s", sqlite3_errmsg(db));
3033 sqlite3_finalize(stmt);
3037 sqlite3_finalize(stmt);
3042 API int pkgmgr_parser_unregister_all_pkg_update_info_in_usr_db(uid_t uid)
3048 dbpath = __get_parser_db_path(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, __unregister_all_pkg_update_info(db));
3058 __END_TRANSACTION(db);
3060 sqlite3_close_v2(db);
3062 return PM_PARSER_R_OK;
3065 API int pkgmgr_parser_unregister_all_pkg_update_info_in_db(void)
3067 return pkgmgr_parser_unregister_all_pkg_update_info_in_usr_db(