10 #include <sys/smack.h>
11 #include <linux/limits.h>
18 #include <system_info.h>
20 #include "pkgmgr_parser.h"
21 #include "pkgmgrinfo_basic.h"
22 #include "pkgmgrinfo_private.h"
23 #include "pkgmgrinfo_debug.h"
24 #include "pkgmgr-info.h"
26 #define __BEGIN_TRANSACTION(db) \
28 if (sqlite3_exec(db, "BEGIN DEFERRED", NULL, NULL, NULL) != \
30 _LOGE("begin transaction failed: %s", sqlite3_errmsg(db)); \
35 #define __DO_TRANSACTION(db, func) \
38 _LOGE("transaction failed: %s, rollback", sqlite3_errmsg(db)); \
39 if (sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL) != \
41 _LOGE("roll back transaction failed: %s", \
42 sqlite3_errmsg(db)); \
47 #define __END_TRANSACTION(db) \
49 if (sqlite3_exec(db, "COMMIT", NULL, NULL, NULL) != \
51 _LOGE("commit failed: %s, rollback", sqlite3_errmsg(db)); \
52 if (sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL) != \
54 _LOGE("roll back transaction failed: %s", \
55 sqlite3_errmsg(db)); \
60 #define __BIND_TEXT(db, stmt, i, text) \
62 if (sqlite3_bind_text(stmt, i, text, -1, SQLITE_STATIC) != SQLITE_OK) {\
63 _LOGE("bind error(index %d): %s", i, sqlite3_errmsg(db)); \
64 sqlite3_finalize(stmt); \
69 #define __BIND_INT(db, stmt, i, int) \
71 if (sqlite3_bind_int(stmt, i, int) != SQLITE_OK) { \
72 _LOGE("bind error(index %d): %s", i, sqlite3_errmsg(db)); \
73 sqlite3_finalize(stmt); \
82 #define XXHDPI "xxhdpi"
92 #define XXHDPI_MIN 481
93 #define XXHDPI_MAX 600
95 static const char join_localized_info[] =
96 " LEFT OUTER JOIN package_localized_info"
97 " ON pi.package=package_localized_info.package"
98 " AND package_localized_info.package_locale=?";
99 static const char join_privilege_info[] =
100 " LEFT OUTER JOIN package_privilege_info"
101 " ON pi.package=package_privilege_info.package";
103 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
104 const char *locale, uid_t uid,
105 char **query, GList **bind_params)
109 char buf[MAX_QUERY_LEN] = { '\0' };
110 char buf2[MAX_QUERY_LEN] = { '\0' };
111 char *condition = NULL;
117 snprintf(buf, sizeof(buf), "%s", " WHERE 1=1 ");
118 for (list = filter->list; list; list = list->next) {
119 joined |= __get_filter_condition(list->data, uid, &condition,
121 if (condition == NULL)
124 strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
126 strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
131 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
132 strncat(buf2, join_localized_info,
133 sizeof(buf2) - strlen(buf2) - 1);
134 *bind_params = g_list_append(*bind_params, strdup(locale));
136 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO)
137 strncat(buf2, join_privilege_info,
138 sizeof(buf2) - strlen(buf2) - 1);
140 size = strlen(buf2) + strlen(buf) + 1;
141 *query = (char *)calloc(1, size);
143 return PMINFO_R_ERROR;
144 snprintf(*query, size, "%s%s", buf2, buf);
149 static int __bind_params(sqlite3_stmt *stmt, GList *params)
151 GList *tmp_list = NULL;
155 if (stmt == NULL || params == NULL)
156 return PMINFO_R_EINVAL;
160 ret = sqlite3_bind_text(stmt, ++idx,
161 (char *)tmp_list->data, -1, SQLITE_STATIC);
162 if (ret != SQLITE_OK)
163 return PMINFO_R_ERROR;
164 tmp_list = tmp_list->next;
170 static bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter)
172 GSList *tmp_list = NULL;
173 pkgmgrinfo_node_x *tmp_node = NULL;
176 property = _pminfo_pkginfo_convert_to_prop_bool(
177 PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE);
178 for (tmp_list = tmp_filter->list; tmp_list != NULL;
179 tmp_list = g_slist_next(tmp_list)) {
180 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
181 if (property == tmp_node->prop) {
182 if (strcmp(tmp_node->value, "true") == 0)
191 static int _pkginfo_add_description_info_into_list(const char *locale,
192 char *record, GList **description)
196 info = calloc(1, sizeof(description_x));
198 LOGE("out of memory");
199 return PMINFO_R_ERROR;
201 info->lang = strdup(locale);
203 *description = g_list_prepend(*description, info);
208 static int _pkginfo_get_plugin_execution_info(sqlite3 *db, const char *pkgid,
211 static const char query_raw[] =
212 "SELECT appid, plugin_type, plugin_name FROM package_plugin_info "
219 query = sqlite3_mprintf(query_raw, pkgid);
221 LOGE("out of memory");
222 return PMINFO_R_ERROR;
225 ret = sqlite3_prepare_v2(db, query, strlen(query),
228 if (ret != SQLITE_OK) {
229 LOGE("prepare failed: %s", sqlite3_errmsg(db));
230 return PMINFO_R_ERROR;
233 while (sqlite3_step(stmt) == SQLITE_ROW) {
234 plugin = calloc(1, sizeof(plugin_x));
236 LOGE("out of memory");
237 sqlite3_finalize(stmt);
238 return PMINFO_R_ERROR;
240 plugin->pkgid = strdup(pkgid);
241 _save_column_str(stmt, 0, &plugin->appid);
242 _save_column_str(stmt, 1, &plugin->plugin_type);
243 _save_column_str(stmt, 2, &plugin->plugin_name);
244 *plugins = g_list_prepend(*plugins,
248 sqlite3_finalize(stmt);
253 static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
256 static const char query_raw[] =
257 "SELECT DISTINCT privilege, type FROM package_privilege_info "
262 privilege_x *privilege;
264 query = sqlite3_mprintf(query_raw, pkgid);
266 LOGE("out of memory");
267 return PMINFO_R_ERROR;
270 ret = sqlite3_prepare_v2(db, query, strlen(query),
273 if (ret != SQLITE_OK) {
274 LOGE("prepare failed: %s", sqlite3_errmsg(db));
275 return PMINFO_R_ERROR;
278 while (sqlite3_step(stmt) == SQLITE_ROW) {
279 privilege = calloc(1, sizeof(privilege_x));
281 LOGE("failed to alloc memory");
282 sqlite3_finalize(stmt);
283 return PMINFO_R_ERROR;
285 _save_column_str(stmt, 0, &privilege->value);
286 _save_column_str(stmt, 1, &privilege->type);
287 *privileges = g_list_prepend(*privileges,
288 (gpointer)privilege);
291 sqlite3_finalize(stmt);
296 static int _pkginfo_get_appdefined_privilege(sqlite3 *db, const char *pkgid,
299 static const char query_raw[] =
300 "SELECT DISTINCT privilege, license, type FROM "
301 "package_appdefined_privilege_info WHERE package=%Q";
305 appdefined_privilege_x *privilege;
307 query = sqlite3_mprintf(query_raw, pkgid);
309 LOGE("out of memory");
310 return PMINFO_R_ERROR;
313 ret = sqlite3_prepare_v2(db, query, strlen(query),
316 if (ret != SQLITE_OK) {
317 LOGE("prepare failed: %s", sqlite3_errmsg(db));
318 return PMINFO_R_ERROR;
321 while (sqlite3_step(stmt) == SQLITE_ROW) {
322 privilege = calloc(1, sizeof(appdefined_privilege_x));
324 LOGE("failed to alloc memory");
325 sqlite3_finalize(stmt);
326 return PMINFO_R_ERROR;
328 _save_column_str(stmt, 0, &privilege->value);
329 _save_column_str(stmt, 1, &privilege->license);
330 _save_column_str(stmt, 2, &privilege->type);
331 *privileges = g_list_prepend(*privileges,
332 (gpointer)privilege);
335 sqlite3_finalize(stmt);
340 static int _pkginfo_get_dependency(sqlite3 *db, const char *pkgid,
341 GList **dependencies)
343 static const char query_raw[] =
344 "SELECT DISTINCT depends_on, type, required_version "
345 "FROM package_dependency_info WHERE package=%Q";
349 dependency_x *dependency;
351 query = sqlite3_mprintf(query_raw, pkgid);
353 LOGE("out of memory");
354 return PMINFO_R_ERROR;
357 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
359 if (ret != SQLITE_OK) {
360 LOGE("prepare failed: %s", sqlite3_errmsg(db));
361 return PMINFO_R_ERROR;
364 while (sqlite3_step(stmt) == SQLITE_ROW) {
365 dependency = calloc(1, sizeof(dependency_x));
367 LOGE("failed to alloc memory");
368 sqlite3_finalize(stmt);
369 return PMINFO_R_ERROR;
371 _save_column_str(stmt, 0, &dependency->depends_on);
372 _save_column_str(stmt, 1, &dependency->type);
373 _save_column_str(stmt, 2, &dependency->required_version);
374 *dependencies = g_list_prepend(*dependencies,
375 (gpointer)dependency);
378 sqlite3_finalize(stmt);
383 static int _pkginfo_get_packages(sqlite3 *db, uid_t uid, const char *locale,
384 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
386 static const char query_raw[] =
387 "SELECT DISTINCT pi.package, pi.installed_storage, pi.external_path";
388 static const char query_basic[] =
389 ", pi.package_version, pi.install_location, "
390 "pi.package_removable, pi.package_preload, pi.package_readonly, "
391 "pi.package_update, pi.package_appsetting, pi.package_system, "
392 "pi.package_type, pi.package_size, pi.installed_time, "
393 "pi.storeclient_id, pi.mainapp_id, pi.package_url, pi.root_path, "
394 "pi.csc_path, pi.package_nodisplay, pi.package_api_version, "
395 "pi.package_support_disable, pi.package_tep_name, "
396 "pi.package_zip_mount_file, pi.package_support_mode";
397 static const char query_author[] =
398 ", pi.author_name, pi.author_email, pi.author_href";
399 static const char query_label[] =
401 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
402 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
403 static const char query_icon[] =
405 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
406 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
407 static const char query_description[] =
409 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
410 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
411 static const char query_from_clause[] = " FROM package_info as pi";
412 int ret = PMINFO_R_ERROR;
415 char *tmp_record = NULL;
416 char *constraints = NULL;
417 char query[MAX_QUERY_LEN] = { '\0' };
418 package_x *info = NULL;
419 author_x *author = NULL;
420 GList *bind_params = NULL;
422 sqlite3_stmt *stmt = NULL;
423 bool is_check_storage = true;
424 const uid_t global_user_uid = GLOBAL_USER;
426 dbpath = getUserPkgParserDBPathUID(uid);
428 return PMINFO_R_ERROR;
430 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
431 if (ret != SQLITE_OK) {
432 _LOGD("failed to open db(%s): %d", dbpath, ret);
434 return PMINFO_R_ERROR;
438 is_check_storage = __check_package_storage_status(filter);
440 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
441 if (flag & PMINFO_APPINFO_GET_BASICINFO)
442 strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
443 if (flag & PMINFO_PKGINFO_GET_AUTHOR)
444 strncat(query, query_author, sizeof(query) - strlen(query) - 1);
445 if (flag & PMINFO_PKGINFO_GET_LABEL) {
446 strncat(query, query_label, sizeof(query) - strlen(query) - 1);
447 bind_params = g_list_append(bind_params, strdup(locale));
449 if (flag & PMINFO_PKGINFO_GET_ICON) {
450 strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
451 bind_params = g_list_append(bind_params, strdup(locale));
453 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
454 strncat(query, query_description,
455 sizeof(query) - strlen(query) - 1);
456 bind_params = g_list_append(bind_params, strdup(locale));
459 strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
461 ret = _get_filtered_query(filter, locale, uid,
462 &constraints, &bind_params);
463 if (ret != PMINFO_R_OK) {
464 LOGE("Failed to get WHERE clause");
469 strncat(query, constraints, sizeof(query) - strlen(query) - 1);
471 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
472 if (ret != SQLITE_OK) {
473 LOGE("prepare failed: %s", sqlite3_errmsg(db));
474 ret = PMINFO_R_ERROR;
478 ret = __bind_params(stmt, bind_params);
479 if (ret != SQLITE_OK) {
480 LOGE("Failed to bind parameters");
484 while (sqlite3_step(stmt) == SQLITE_ROW) {
485 info = calloc(1, sizeof(package_x));
487 LOGE("out of memory");
488 ret = PMINFO_R_ERROR;
491 info->locale = strdup(locale);
492 if (info->locale == NULL) {
493 LOGE("Out of memory");
494 ret = PMINFO_R_ERROR;
499 _save_column_str(stmt, idx++, &info->package);
500 _save_column_str(stmt, idx++, &info->installed_storage);
501 _save_column_str(stmt, idx++, &info->external_path);
503 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
504 _save_column_str(stmt, idx++, &info->version);
505 _save_column_str(stmt, idx++, &info->installlocation);
506 _save_column_str(stmt, idx++, &info->removable);
507 _save_column_str(stmt, idx++, &info->preload);
508 _save_column_str(stmt, idx++, &info->readonly);
509 _save_column_str(stmt, idx++, &info->update);
510 _save_column_str(stmt, idx++, &info->appsetting);
511 _save_column_str(stmt, idx++, &info->system);
512 _save_column_str(stmt, idx++, &info->type);
513 _save_column_str(stmt, idx++, &info->package_size);
514 _save_column_str(stmt, idx++, &info->installed_time);
515 _save_column_str(stmt, idx++, &info->storeclient_id);
516 _save_column_str(stmt, idx++, &info->mainapp_id);
517 _save_column_str(stmt, idx++, &info->package_url);
518 _save_column_str(stmt, idx++, &info->root_path);
519 _save_column_str(stmt, idx++, &info->csc_path);
520 _save_column_str(stmt, idx++, &info->nodisplay_setting);
521 _save_column_str(stmt, idx++, &info->api_version);
522 _save_column_str(stmt, idx++, &info->support_disable);
523 _save_column_str(stmt, idx++, &info->tep_name);
524 _save_column_str(stmt, idx++, &info->zip_mount_file);
525 _save_column_str(stmt, idx++, &info->support_mode);
528 info->for_all_users =
529 strdup((uid != global_user_uid) ? "false" : "true");
531 if (_pkginfo_get_plugin_execution_info(db,
532 info->package, &info->plugin)) {
533 ret = PMINFO_R_ERROR;
537 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
538 /* TODO : author should be retrieved at package_localized_info */
539 author = calloc(1, sizeof(author_x));
540 if (author == NULL) {
541 ret = PMINFO_R_ERROR;
544 _save_column_str(stmt, idx++, &author->text);
545 _save_column_str(stmt, idx++, &author->email);
546 _save_column_str(stmt, idx++, &author->href);
547 info->author = g_list_prepend(info->author, author);
550 if (flag & PMINFO_PKGINFO_GET_LABEL) {
552 _save_column_str(stmt, idx++, &tmp_record);
554 if (_add_label_info_into_list(locale,
555 tmp_record, &info->label)) {
556 ret = PMINFO_R_ERROR;
561 if (flag & PMINFO_PKGINFO_GET_ICON) {
563 _save_column_str(stmt, idx++, &tmp_record);
564 if (_add_icon_info_into_list(locale,
565 tmp_record, &info->icon)) {
566 ret = PMINFO_R_ERROR;
571 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
573 _save_column_str(stmt, idx++, &tmp_record);
574 if (_pkginfo_add_description_info_into_list(locale,
575 tmp_record, &info->description)) {
576 ret = PMINFO_R_ERROR;
581 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
582 if (_pkginfo_get_privilege(db, info->package,
583 &info->privileges)) {
584 ret = PMINFO_R_ERROR;
589 if (flag & PMINFO_PKGINFO_GET_APPDEFINED_PRIVILEGE) {
590 if (_pkginfo_get_appdefined_privilege(db, info->package,
591 &info->appdefined_privileges)) {
592 ret = PMINFO_R_ERROR;
597 if (flag & PMINFO_PKGINFO_GET_DEPENDENCY) {
598 if (_pkginfo_get_dependency(db, info->package,
599 &info->dependencies)) {
600 ret = PMINFO_R_ERROR;
605 if (is_check_storage &&
606 __pkginfo_check_installed_storage(info) !=
608 ret = PMINFO_R_ERROR;
609 pkgmgrinfo_basic_free_package(info);
614 g_hash_table_insert(packages, (gpointer)info->package,
621 sqlite3_finalize(stmt);
626 if (ret != PMINFO_R_OK && info != NULL)
627 pkgmgrinfo_basic_free_package(info);
629 g_list_free_full(bind_params, free);
634 API int pkginfo_internal_filter_get_list(
635 sqlite3 *db, pkgmgrinfo_pkginfo_filter_h filter,
636 uid_t uid, const char *locale, GHashTable *pkginfo_list)
640 if (filter == NULL || pkginfo_list == NULL) {
641 LOGE("Invalid argument");
642 return PMINFO_R_EINVAL;
645 ret = _pkginfo_get_packages(db, uid, locale, filter,
646 PMINFO_PKGINFO_GET_ALL, pkginfo_list);
650 API int get_query_result(sqlite3 *db, const char *query,
651 GList **list, int *row, int *col)
657 sqlite3_stmt *stmt = NULL;
660 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
661 if (ret != SQLITE_OK) {
662 LOGE("prepare failed: %s", sqlite3_errmsg(db));
663 return PMINFO_R_ERROR;
666 col_cnt = sqlite3_column_count(stmt);
668 while (sqlite3_step(stmt) == SQLITE_ROW) {
670 for (idx = 0; idx < col_cnt; ++idx) {
671 _save_column_str(stmt, idx, &result);
672 *list = g_list_append(*list, result);
680 sqlite3_finalize(stmt);
685 static int _get_depends_on(sqlite3 *db, const char *pkgid, GQueue **queue,
686 GHashTable **table, GList **pkg_list)
688 static const char query[] =
689 "SELECT package, depends_on, type, required_version "
690 "FROM package_dependency_info WHERE depends_on=?";
695 /* already checked */
696 if (!g_hash_table_insert(*table, strdup(pkgid), GINT_TO_POINTER(1)))
699 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
700 if (ret != SQLITE_OK) {
701 LOGE("prepare failed: %s", sqlite3_errmsg(db));
702 return PMINFO_R_ERROR;
705 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_STATIC);
706 if (ret != SQLITE_OK) {
707 LOGE("bind failed: %s", sqlite3_errmsg(db));
708 sqlite3_finalize(stmt);
709 return PMINFO_R_ERROR;
712 while (sqlite3_step(stmt) == SQLITE_ROW) {
713 req = calloc(1, sizeof(dependency_x));
715 LOGE("out of memory");
716 sqlite3_finalize(stmt);
717 return PMINFO_R_ERROR;
719 _save_column_str(stmt, 0, &req->pkgid);
720 _save_column_str(stmt, 1, &req->depends_on);
721 _save_column_str(stmt, 2, &req->type);
722 _save_column_str(stmt, 3, &req->required_version);
724 *pkg_list = g_list_prepend(*pkg_list, req);
725 g_queue_push_tail(*queue, strdup(req->pkgid));
728 sqlite3_finalize(stmt);
733 static void __free_depends_on(gpointer data)
735 struct dependency_x *dep = (struct dependency_x *)data;
738 free(dep->depends_on);
740 free(dep->required_version);
744 API int pkginfo_internal_filter_get_depends_on(sqlite3 *db, const char *pkgid,
752 queue = g_queue_new();
754 LOGE("out of memory");
755 return PMINFO_R_ERROR;
757 table = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
759 g_queue_push_tail(queue, strdup(pkgid));
760 while (!g_queue_is_empty(queue)) {
761 item = g_queue_pop_head(queue);
762 ret = _get_depends_on(db, item, &queue, &table, list);
764 if (ret != PMINFO_R_OK) {
765 LOGE("failed to get pkgs depends on %s", pkgid);
766 g_hash_table_destroy(table);
767 g_list_free_full(*list, __free_depends_on);
768 g_queue_free_full(queue, free);
769 return PMINFO_R_ERROR;
773 g_hash_table_destroy(table);
774 g_queue_free_full(queue, free);
778 static int __execute_query(sqlite3 *db, const char *query)
781 sqlite3_stmt *stmt = NULL;
783 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
784 if (ret != SQLITE_OK) {
785 LOGE("prepare failed: %s", sqlite3_errmsg(db));
789 ret = sqlite3_step(stmt);
790 if (ret != SQLITE_DONE) {
791 LOGE("step failed: %s", sqlite3_errmsg(db));
792 sqlite3_finalize(stmt);
796 sqlite3_finalize(stmt);
801 API int execute_write_queries(sqlite3 *db, const char **queries, int len)
805 __BEGIN_TRANSACTION(db);
806 for (i = 0; i < len; ++i)
807 __DO_TRANSACTION(db, __execute_query(db, queries[i]));
808 __END_TRANSACTION(db);
810 // Is db handel freed by AbstractDBHandler?
811 // sqlite3_close_v2(db);
816 static int __check_dpi(const char *dpi_char, int dpi_int)
818 if (dpi_char == NULL)
821 if (strcasecmp(dpi_char, LDPI) == 0) {
822 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
826 } else if (strcasecmp(dpi_char, MDPI) == 0) {
827 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
831 } else if (strcasecmp(dpi_char, HDPI) == 0) {
832 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
836 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
837 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
841 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
842 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
850 static void __find_appcontrol_splashscreen_with_dpi(gpointer data,
853 splashscreen_x *ss = (splashscreen_x *)data;
854 GList **list = (GList **)user_data;
858 if (ss->operation == NULL || ss->dpi == NULL)
861 ret = system_info_get_platform_int(
862 "http://tizen.org/feature/screen.dpi", &dpi);
863 if (ret != SYSTEM_INFO_ERROR_NONE)
866 if (__check_dpi(ss->dpi, dpi) != 0)
869 *list = g_list_prepend(*list, ss);
872 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
874 splashscreen_x *ss = (splashscreen_x *)data;
875 GList **list = (GList **)user_data;
876 splashscreen_x *ss_tmp;
879 if (ss->operation == NULL || ss->dpi)
882 for (tmp = *list; tmp; tmp = tmp->next) {
883 ss_tmp = (splashscreen_x *)tmp->data;
884 if (ss_tmp->operation
885 && strcmp(ss_tmp->operation, ss->operation) == 0
886 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
890 *list = g_list_prepend(*list, ss);
893 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a,
896 splashscreen_x *ss = (splashscreen_x *)a;
897 const char *orientation = (const char *)b;
901 if (ss->operation || ss->dpi == NULL)
904 ret = system_info_get_platform_int(
905 "http://tizen.org/feature/screen.dpi", &dpi);
906 if (ret != SYSTEM_INFO_ERROR_NONE)
909 if (strcasecmp(ss->orientation, orientation) == 0 &&
910 __check_dpi(ss->dpi, dpi) == 0)
916 static gint __compare_splashscreen_with_orientation(gconstpointer a,
919 splashscreen_x *ss = (splashscreen_x *)a;
920 const char *orientation = (const char *)b;
922 if (ss->operation || ss->dpi)
925 if (strcasecmp(ss->orientation, orientation) == 0)
931 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
932 const char *orientation)
936 tmp = g_list_find_custom(splashscreens, orientation,
938 __compare_splashscreen_with_orientation_dpi);
940 return (splashscreen_x *)tmp->data;
942 tmp = g_list_find_custom(splashscreens, orientation,
943 (GCompareFunc)__compare_splashscreen_with_orientation);
945 return (splashscreen_x *)tmp->data;
950 static GList *__find_splashscreens(GList *splashscreens)
955 if (splashscreens == NULL)
958 g_list_foreach(splashscreens,
959 __find_appcontrol_splashscreen_with_dpi, &list);
960 g_list_foreach(splashscreens,
961 __find_appcontrol_splashscreen, &list);
963 ss = __find_default_splashscreen(splashscreens, "portrait");
965 list = g_list_prepend(list, ss);
966 ss = __find_default_splashscreen(splashscreens, "landscape");
968 list = g_list_prepend(list, ss);
973 static int __insert_splashscreen_info(sqlite3 *db, application_x *app,
976 static const char query[] =
977 "INSERT INTO package_app_splash_screen (app_id, src, type,"
978 " orientation, indicatordisplay, operation, color_depth) "
979 "VALUES (?, ?, ?, ?, ?, ?, ?)";
986 if (app->splashscreens == NULL)
992 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
993 if (ret != SQLITE_OK) {
994 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
998 for (tmp = ss_list; tmp; tmp = tmp->next) {
999 ss = (splashscreen_x *)tmp->data;
1003 __BIND_TEXT(db, stmt, idx++, app->appid);
1004 __BIND_TEXT(db, stmt, idx++, ss->src);
1005 __BIND_TEXT(db, stmt, idx++, ss->type);
1006 __BIND_TEXT(db, stmt, idx++, ss->orientation);
1007 __BIND_TEXT(db, stmt, idx++, ss->indicatordisplay);
1008 __BIND_TEXT(db, stmt, idx++, ss->operation);
1009 __BIND_TEXT(db, stmt, idx++, ss->color_depth);
1011 ret = sqlite3_step(stmt);
1012 if (ret != SQLITE_DONE) {
1013 _LOGE("step failed: %s", sqlite3_errmsg(db));
1014 sqlite3_finalize(stmt);
1018 sqlite3_reset(stmt);
1021 sqlite3_finalize(stmt);
1026 static void __trimfunc(GList *trim_list)
1030 GList *list = g_list_first(trim_list);
1033 trim_data = (char *)list->data;
1036 if (strcmp(trim_data, prev) == 0) {
1037 trim_list = g_list_remove(trim_list,
1039 list = g_list_first(trim_list);
1048 list = g_list_next(list);
1052 static int __insert_package_appdefined_privilege_info(sqlite3 *db,
1055 static const char query[] =
1056 "INSERT INTO package_appdefined_privilege_info "
1057 "(package, privilege, license, type) "
1058 "VALUES (?, ?, ?, ?)";
1063 appdefined_privilege_x *priv;
1065 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1066 if (ret != SQLITE_OK) {
1067 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1071 for (tmp = mfx->appdefined_privileges; tmp; tmp = tmp->next) {
1072 priv = (appdefined_privilege_x *)tmp->data;
1077 __BIND_TEXT(db, stmt, idx++, mfx->package);
1078 __BIND_TEXT(db, stmt, idx++, priv->value);
1079 __BIND_TEXT(db, stmt, idx++, priv->license);
1080 __BIND_TEXT(db, stmt, idx++, priv->type);
1082 ret = sqlite3_step(stmt);
1083 if (ret != SQLITE_DONE) {
1084 _LOGE("step failed: %s", sqlite3_errmsg(db));
1085 sqlite3_finalize(stmt);
1088 sqlite3_reset(stmt);
1091 sqlite3_finalize(stmt);
1096 static int __insert_package_dependency_info(sqlite3 *db, manifest_x *mfx)
1098 static const char query[] =
1099 "INSERT INTO package_dependency_info"
1100 " (package, depends_on, type, required_version) "
1101 "VALUES (?, ?, ?, ?)";
1108 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1109 if (ret != SQLITE_OK) {
1110 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1114 for (tmp = mfx->dependencies; tmp; tmp = tmp->next) {
1115 dep = (dependency_x *)tmp->data;
1120 __BIND_TEXT(db, stmt, idx++, mfx->package);
1121 __BIND_TEXT(db, stmt, idx++, dep->depends_on);
1122 __BIND_TEXT(db, stmt, idx++, dep->type);
1123 __BIND_TEXT(db, stmt, idx++, dep->required_version);
1125 ret = sqlite3_step(stmt);
1126 if (ret != SQLITE_DONE) {
1127 _LOGE("step failed: %s", sqlite3_errmsg(db));
1128 sqlite3_finalize(stmt);
1131 sqlite3_reset(stmt);
1134 sqlite3_finalize(stmt);
1139 static int __insert_mainapp_localized_info(sqlite3 *db, application_x *app,
1140 const char *locale, const char *label, const char *icon)
1142 static const char query[] =
1143 "INSERT OR REPLACE INTO package_localized_info ("
1144 " package, package_locale, package_label, package_icon,"
1145 " package_description, package_license, package_author) "
1147 " COALESCE((SELECT package_label FROM package_localized_info"
1148 " WHERE package=? AND package_locale=?), ?),"
1149 " COALESCE((SELECT package_icon FROM package_localized_info"
1150 " WHERE package=? AND package_icon=?), ?),"
1151 " (SELECT package_description FROM package_localized_info"
1152 " WHERE package=? AND package_locale=?),"
1153 " (SELECT package_description FROM package_localized_info"
1154 " WHERE package=? AND package_locale=?),"
1155 " (SELECT package_description FROM package_localized_info"
1156 " WHERE package=? AND package_locale=?))";
1161 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1162 if (ret != SQLITE_OK) {
1163 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1167 __BIND_TEXT(db, stmt, idx++, app->package);
1168 __BIND_TEXT(db, stmt, idx++, locale);
1169 __BIND_TEXT(db, stmt, idx++, app->package);
1170 __BIND_TEXT(db, stmt, idx++, locale);
1171 __BIND_TEXT(db, stmt, idx++, label);
1172 __BIND_TEXT(db, stmt, idx++, app->package);
1173 __BIND_TEXT(db, stmt, idx++, locale);
1174 __BIND_TEXT(db, stmt, idx++, icon);
1175 __BIND_TEXT(db, stmt, idx++, app->package);
1176 __BIND_TEXT(db, stmt, idx++, locale);
1177 __BIND_TEXT(db, stmt, idx++, app->package);
1178 __BIND_TEXT(db, stmt, idx++, locale);
1179 __BIND_TEXT(db, stmt, idx++, app->package);
1180 __BIND_TEXT(db, stmt, idx++, locale);
1182 ret = sqlite3_step(stmt);
1183 if (ret != SQLITE_DONE) {
1184 _LOGE("step failed: %s", sqlite3_errmsg(db));
1185 sqlite3_finalize(stmt);
1189 sqlite3_finalize(stmt);
1194 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
1196 if (a == NULL || b == NULL)
1198 if (strcmp((char *)a, (char *)b) == 0)
1200 if (strcmp((char *)a, (char *)b) < 0)
1202 if (strcmp((char *)a, (char *)b) > 0)
1207 static GList *__create_locale_list(GList *lbls, GList *lcns, GList *icns,
1208 GList *dcns, GList *aths)
1210 GList *locale = NULL;
1218 for (tmp = lbls; tmp; tmp = tmp->next) {
1219 lbl = (label_x *)tmp->data;
1223 locale = g_list_insert_sorted_with_data(
1224 locale, (gpointer)lbl->lang,
1225 __comparefunc, NULL);
1227 for (tmp = lcns; tmp; tmp = tmp->next) {
1228 lcn = (license_x *)tmp->data;
1232 locale = g_list_insert_sorted_with_data(
1233 locale, (gpointer)lcn->lang,
1234 __comparefunc, NULL);
1236 for (tmp = icns; tmp; tmp = tmp->next) {
1237 icn = (icon_x *)tmp->data;
1241 locale = g_list_insert_sorted_with_data(
1242 locale, (gpointer)icn->lang,
1243 __comparefunc, NULL);
1245 for (tmp = dcns; tmp; tmp = tmp->next) {
1246 dcn = (description_x *)tmp->data;
1250 locale = g_list_insert_sorted_with_data(
1251 locale, (gpointer)dcn->lang,
1252 __comparefunc, NULL);
1254 for (tmp = aths; tmp; tmp = tmp->next) {
1255 ath = (author_x *)tmp->data;
1259 locale = g_list_insert_sorted_with_data(
1260 locale, (gpointer)ath->lang,
1261 __comparefunc, NULL);
1267 static gint __check_icon_resolution(const char *orig_icon_path,
1268 char **new_icon_path)
1272 char *icon_filename;
1273 char modified_iconpath[BUFSIZE];
1274 char icon_path[BUFSIZE];
1278 if (orig_icon_path == NULL)
1281 ret = system_info_get_platform_int(
1282 "http://tizen.org/feature/screen.dpi", &dpi);
1283 if (ret != SYSTEM_INFO_ERROR_NONE)
1286 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
1287 dpi_path[0] = "LDPI";
1288 dpi_path[1] = "ldpi";
1289 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
1290 dpi_path[0] = "MDPI";
1291 dpi_path[1] = "mdpi";
1292 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
1293 dpi_path[0] = "HDPI";
1294 dpi_path[1] = "hdpi";
1295 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
1296 dpi_path[0] = "XHDPI";
1297 dpi_path[1] = "xhdpi";
1298 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
1299 dpi_path[0] = "XXHDPI";
1300 dpi_path[1] = "xxhdpi";
1302 _LOGE("Unidentified dpi[%d]", dpi);
1306 icon_filename = strrchr(orig_icon_path, '/');
1307 if (icon_filename == NULL)
1311 strlen(orig_icon_path) - (strlen(icon_filename) - 1),
1312 "%s", orig_icon_path);
1313 for (i = 0; i < 2; i++) {
1314 ret = snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s",
1315 icon_path, dpi_path[i], icon_filename);
1316 if (ret < 0 || ret > BUFSIZE - 1) {
1317 _LOGE("snprintf fail");
1320 if (access(modified_iconpath, F_OK) != -1) {
1321 /* if exists, return modified icon path */
1322 *new_icon_path = strdup(modified_iconpath);
1330 static gint __compare_icon(gconstpointer a, gconstpointer b)
1332 icon_x *icon = (icon_x *)a;
1335 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
1338 if (icon->dpi != NULL)
1341 if (__check_icon_resolution(icon->text, &icon_path) == 0) {
1343 icon->text = icon_path;
1349 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
1351 icon_x *icon = (icon_x *)a;
1352 char *lang = (char *)b;
1355 if (icon->dpi != NULL)
1358 if (strcasecmp(icon->lang, lang) == 0) {
1359 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
1360 /* icon for no locale. check existance of
1361 * folder-hierachied default icons
1363 if (__check_icon_resolution(icon->text,
1366 icon->text = icon_path;
1375 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
1377 icon_x *icon = (icon_x *)a;
1378 int dpi = GPOINTER_TO_INT(b);
1380 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
1383 if (icon->dpi == NULL)
1386 if (__check_dpi(icon->dpi, dpi) == 0)
1392 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
1395 icon_x *icon = (icon_x *)a;
1396 char *lang = (char *)b;
1399 ret = system_info_get_platform_int(
1400 "http://tizen.org/feature/screen.dpi", &dpi);
1401 if (ret != SYSTEM_INFO_ERROR_NONE)
1404 if (strcasecmp(icon->lang, lang) == 0 &&
1405 __check_dpi(icon->dpi, dpi) == 0)
1411 static char *__find_icon(GList *icons, const char *lang)
1418 /* first, find icon whose locale and dpi with given lang and
1419 * system's dpi has matched
1421 tmp = g_list_find_custom(icons, lang,
1422 (GCompareFunc)__compare_icon_with_lang_dpi);
1424 icon = (icon_x *)tmp->data;
1425 return (char *)icon->text;
1428 /* if first has failed, find icon whose locale has matched */
1429 tmp = g_list_find_custom(icons, lang,
1430 (GCompareFunc)__compare_icon_with_lang);
1432 icon = (icon_x *)tmp->data;
1433 return (char *)icon->text;
1436 /* if second has failed, find icon whose dpi has matched with
1439 ret = system_info_get_platform_int(
1440 "http://tizen.org/feature/screen.dpi", &dpi);
1441 if (ret == SYSTEM_INFO_ERROR_NONE) {
1442 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi),
1443 (GCompareFunc)__compare_icon_with_dpi);
1445 icon = (icon_x *)tmp->data;
1446 return (char *)icon->text;
1450 /* last, find default icon marked as "No Locale" */
1451 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
1453 icon = (icon_x *)tmp->data;
1454 return (char *)icon->text;
1460 static void __extract_data(const char *locale, GList *lbls, GList *lcns,
1461 GList *icns, GList *dcns, GList *aths, char **label,
1462 char **license, char **icon, char **description, char **author)
1470 for (tmp = lbls; tmp; tmp = tmp->next) {
1471 lbl = (label_x *)tmp->data;
1475 if (strcmp(lbl->lang, locale) == 0) {
1476 *label = (char *)lbl->text;
1481 for (tmp = lcns; tmp; tmp = tmp->next) {
1482 lcn = (license_x *)tmp->data;
1486 if (strcmp(lcn->lang, locale) == 0) {
1487 *license = (char *)lcn->text;
1493 *icon = __find_icon(icns, locale);
1495 for (tmp = dcns; tmp; tmp = tmp->next) {
1496 dcn = (description_x *)tmp->data;
1500 if (strcmp(dcn->lang, locale) == 0) {
1501 *description = (char *)dcn->text;
1506 for (tmp = aths; tmp; tmp = tmp->next) {
1507 ath = (author_x *)tmp->data;
1511 if (strcmp(ath->lang, locale) == 0) {
1512 *author = (char *)ath->text;
1519 static int __insert_app_localized_info(sqlite3 *db, application_x *app)
1521 static const char query[] =
1522 "INSERT INTO package_app_localized_info (app_id, app_locale,"
1523 " app_label, app_icon) "
1524 "VALUES (?, ?, ?, ?)";
1534 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1535 if (ret != SQLITE_OK) {
1536 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1540 locales = __create_locale_list(app->label, NULL, app->icon, NULL, NULL);
1541 for (tmp = locales; tmp; tmp = tmp->next) {
1542 locale = (const char *)tmp->data;
1545 __extract_data(locale, app->label, NULL, app->icon, NULL, NULL,
1546 &label, NULL, &icon, NULL, NULL);
1547 if (!label && !icon)
1551 __BIND_TEXT(db, stmt, idx++, app->appid);
1552 __BIND_TEXT(db, stmt, idx++, locale);
1553 __BIND_TEXT(db, stmt, idx++, label);
1554 __BIND_TEXT(db, stmt, idx++, icon);
1556 ret = sqlite3_step(stmt);
1557 if (ret != SQLITE_DONE) {
1558 _LOGE("step failed: %s", sqlite3_errmsg(db));
1559 g_list_free(locales);
1560 sqlite3_finalize(stmt);
1564 sqlite3_reset(stmt);
1566 if (strcasecmp(app->mainapp, "true") == 0) {
1567 if (__insert_mainapp_localized_info(db, app, locale,
1569 _LOGE("insert mainapp localized info failed");
1573 g_list_free(locales);
1574 sqlite3_finalize(stmt);
1579 static int __insert_package_privilege_info(sqlite3 *db, manifest_x *mfx)
1581 static const char query[] =
1582 "INSERT INTO package_privilege_info (package, privilege, type) "
1590 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1591 if (ret != SQLITE_OK) {
1592 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1596 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1597 priv = (privilege_x *)tmp->data;
1602 __BIND_TEXT(db, stmt, idx++, mfx->package);
1603 __BIND_TEXT(db, stmt, idx++, priv->value);
1604 __BIND_TEXT(db, stmt, idx++, priv->type);
1606 ret = sqlite3_step(stmt);
1607 if (ret != SQLITE_DONE) {
1608 _LOGE("step failed: %s", sqlite3_errmsg(db));
1609 sqlite3_finalize(stmt);
1612 sqlite3_reset(stmt);
1615 sqlite3_finalize(stmt);
1620 static int __insert_app_data_control_privilege_info(sqlite3 *db,
1621 datacontrol_x *datacontrol)
1623 static const char query[] =
1624 "INSERT INTO package_app_data_control_privilege (providerid,"
1625 " privilege, type) VALUES (?, ?, ?)";
1633 if (datacontrol == NULL)
1636 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1637 if (ret != SQLITE_OK) {
1638 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1642 for (privileges = datacontrol->privileges; privileges;
1643 privileges = privileges->next) {
1644 priv = (char *)privileges->data;
1649 __BIND_TEXT(db, stmt, idx++, datacontrol->providerid);
1650 __BIND_TEXT(db, stmt, idx++, priv);
1651 __BIND_TEXT(db, stmt, idx++, datacontrol->type);
1653 ret = sqlite3_step(stmt);
1654 if (ret != SQLITE_DONE) {
1655 _LOGE("step failed: %s", sqlite3_errmsg(db));
1656 sqlite3_finalize(stmt);
1660 sqlite3_reset(stmt);
1663 sqlite3_finalize(stmt);
1667 static int __insert_datacontrol_info(sqlite3 *db, application_x *app)
1669 static const char query[] =
1670 "INSERT INTO package_app_data_control (app_id, providerid,"
1671 " access, type, trusted) VALUES (?, ?, ?, ?, ?)";
1678 if (app->datacontrol == NULL)
1681 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1682 if (ret != SQLITE_OK) {
1683 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1687 for (tmp = app->datacontrol; tmp; tmp = tmp->next) {
1688 dc = (datacontrol_x *)tmp->data;
1692 __BIND_TEXT(db, stmt, idx++, app->appid);
1693 __BIND_TEXT(db, stmt, idx++, dc->providerid);
1694 __BIND_TEXT(db, stmt, idx++, dc->access);
1695 __BIND_TEXT(db, stmt, idx++, dc->type);
1696 __BIND_TEXT(db, stmt, idx++, dc->trusted);
1698 ret = sqlite3_step(stmt);
1699 if (ret != SQLITE_DONE) {
1700 _LOGE("step failed: %s", sqlite3_errmsg(db));
1701 sqlite3_finalize(stmt);
1705 if (dc->privileges &&
1706 __insert_app_data_control_privilege_info(
1708 sqlite3_finalize(stmt);
1712 sqlite3_reset(stmt);
1715 sqlite3_finalize(stmt);
1720 static int __insert_category_info(sqlite3 *db, application_x *app)
1722 static const char query[] =
1723 "INSERT INTO package_app_app_category (app_id, category) "
1729 const char *category;
1731 if (app->category == NULL)
1734 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1735 if (ret != SQLITE_OK) {
1736 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1740 for (tmp = app->category; tmp; tmp = tmp->next) {
1741 category = (const char *)tmp->data;
1742 if (category == NULL)
1745 __BIND_TEXT(db, stmt, idx++, app->appid);
1746 __BIND_TEXT(db, stmt, idx++, category);
1748 ret = sqlite3_step(stmt);
1749 if (ret != SQLITE_DONE) {
1750 _LOGE("step failed: %s", sqlite3_errmsg(db));
1751 sqlite3_finalize(stmt);
1755 sqlite3_reset(stmt);
1758 sqlite3_finalize(stmt);
1763 static int __insert_metadata_info(sqlite3 *db, application_x *app)
1765 static const char query[] =
1766 "INSERT INTO package_app_app_metadata (app_id,"
1767 " md_key, md_value) VALUES (?, ?, ?)";
1774 if (app->metadata == NULL)
1777 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1778 if (ret != SQLITE_OK) {
1779 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1783 for (tmp = app->metadata; tmp; tmp = tmp->next) {
1784 md = (metadata_x *)tmp->data;
1788 __BIND_TEXT(db, stmt, idx++, app->appid);
1789 __BIND_TEXT(db, stmt, idx++, md->key);
1790 __BIND_TEXT(db, stmt, idx++, md->value);
1792 ret = sqlite3_step(stmt);
1793 if (ret != SQLITE_DONE) {
1794 _LOGE("step failed: %s", sqlite3_errmsg(db));
1795 sqlite3_finalize(stmt);
1799 sqlite3_reset(stmt);
1802 sqlite3_finalize(stmt);
1807 static int __insert_appcontrol_privilege_info(sqlite3 *db, const char *appid,
1810 static const char query[] =
1811 "INSERT INTO package_app_app_control_privilege (app_id,"
1812 " app_control, privilege) VALUES (?, ?, ?)";
1816 char app_control[BUFSIZE];
1823 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1824 if (ret != SQLITE_OK) {
1825 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1829 for (tmp = ac->privileges; tmp; tmp = tmp->next) {
1830 privilege = (char *)tmp->data;
1831 if (privilege == NULL || !strlen(privilege))
1835 snprintf(app_control, sizeof(app_control), "%s|%s|%s",
1836 ac->operation ? (strlen(ac->operation) > 0 ?
1837 ac->operation : "NULL") : "NULL",
1838 ac->uri ? (strlen(ac->uri) > 0 ?
1839 ac->uri : "NULL") : "NULL",
1840 ac->mime ? (strlen(ac->mime) > 0 ?
1841 ac->mime : "NULL") : "NULL");
1842 __BIND_TEXT(db, stmt, idx++, appid);
1843 __BIND_TEXT(db, stmt, idx++, app_control);
1844 __BIND_TEXT(db, stmt, idx++, privilege);
1846 ret = sqlite3_step(stmt);
1847 if (ret != SQLITE_DONE) {
1848 _LOGE("step failed: %s", sqlite3_errmsg(db));
1849 sqlite3_finalize(stmt);
1853 sqlite3_reset(stmt);
1856 sqlite3_finalize(stmt);
1861 static int __insert_appcontrol_info(sqlite3 *db, application_x *app)
1863 static const char query[] =
1864 "INSERT INTO package_app_app_control (app_id, app_control,"
1865 " visibility, app_control_id) "
1866 "VALUES (?, ?, ?, ?)";
1870 char app_control[BUFSIZE];
1874 if (app->appcontrol == NULL)
1877 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
1878 if (ret != SQLITE_OK) {
1879 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
1883 for (tmp = app->appcontrol; tmp; tmp = tmp->next) {
1884 ac = (appcontrol_x *)tmp->data;
1888 snprintf(app_control, sizeof(app_control), "%s|%s|%s",
1889 ac->operation ? (strlen(ac->operation) > 0 ?
1890 ac->operation : "NULL") : "NULL",
1891 ac->uri ? (strlen(ac->uri) > 0 ?
1892 ac->uri : "NULL") : "NULL",
1893 ac->mime ? (strlen(ac->mime) > 0 ?
1894 ac->mime : "NULL") : "NULL");
1895 __BIND_TEXT(db, stmt, idx++, app->appid);
1896 __BIND_TEXT(db, stmt, idx++, app_control);
1897 __BIND_TEXT(db, stmt, idx++, ac->visibility);
1898 __BIND_TEXT(db, stmt, idx++, ac->id);
1900 ret = sqlite3_step(stmt);
1901 if (ret != SQLITE_DONE) {
1902 _LOGE("step failed: %s", sqlite3_errmsg(db));
1903 sqlite3_finalize(stmt);
1907 if (__insert_appcontrol_privilege_info(db, app->appid, ac)) {
1908 sqlite3_finalize(stmt);
1912 sqlite3_reset(stmt);
1915 sqlite3_finalize(stmt);
1920 static const char *__get_bool(char *value, bool is_true)
1922 if (value != NULL) {
1923 if (!strcmp(value, ""))
1924 return (is_true) ? "true" : "false";
1928 return (is_true) ? "true" : "false";
1931 #define EFFECTIVE_APPID_KEY "http://tizen.org/metadata/effective-appid"
1932 static const char *__find_effective_appid(GList *metadata_list)
1937 for (tmp = metadata_list; tmp; tmp = tmp->next) {
1938 md = (metadata_x *)tmp->data;
1939 if (md == NULL || md->key == NULL)
1942 if (strcmp(md->key, EFFECTIVE_APPID_KEY) == 0) {
1951 static int __convert_background_category(GList *category_list)
1955 char *category_data;
1957 if (category_list == NULL)
1960 for (tmp = category_list; tmp; tmp = tmp->next) {
1961 category_data = (char *)tmp->data;
1962 if (category_data == NULL)
1964 if (!strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR))
1965 ret |= APP_BG_CATEGORY_MEDIA_VAL;
1966 else if (!strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR))
1967 ret |= APP_BG_CATEGORY_DOWNLOAD_VAL;
1968 else if (!strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR))
1969 ret |= APP_BG_CATEGORY_BGNETWORK_VAL;
1970 else if (!strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR))
1971 ret |= APP_BG_CATEGORY_LOCATION_VAL;
1972 else if (!strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR))
1973 ret |= APP_BG_CATEGORY_SENSOR_VAL;
1974 else if (!strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR))
1975 ret |= APP_BG_CATEGORY_IOTCOMM_VAL;
1976 else if (!strcmp(category_data, APP_BG_CATEGORY_SYSTEM))
1977 ret |= APP_BG_CATEGORY_SYSTEM_VAL;
1979 _LOGE("Unidentified category [%s]", category_data);
1985 static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
1987 static const char query[] =
1988 "INSERT INTO package_app_info (app_id, app_component,"
1989 " app_exec, app_nodisplay, app_type, app_onboot, app_multiple,"
1990 " app_autorestart, app_taskmanage, app_hwacceleration,"
1991 " app_screenreader, app_mainapp, app_recentimage,"
1992 " app_launchcondition, app_indicatordisplay, app_portraitimg,"
1993 " app_landscapeimg, app_guestmodevisibility,"
1994 " app_permissiontype, app_preload, app_submode,"
1995 " app_submode_mainid, app_installed_storage, app_process_pool,"
1996 " app_launch_mode, app_ui_gadget, app_support_mode,"
1997 " app_support_disable, component_type, package, app_tep_name,"
1998 " app_zip_mount_file, app_background_category,"
1999 " app_package_type, app_root_path, app_api_version,"
2000 " app_effective_appid, app_splash_screen_display,"
2001 " app_package_system, app_removable,"
2002 " app_package_installed_time, app_support_ambient,"
2003 " app_external_path, app_setup_appid) "
2005 " ?, LOWER(?), ?, LOWER(?), LOWER(?),"
2006 " LOWER(?), LOWER(?), ?,"
2010 " ?, LOWER(?), LOWER(?),"
2012 " COALESCE(?, 'single'), LOWER(?), ?,"
2013 " LOWER(?), ?, ?, ?,"
2017 " LOWER(?), LOWER(?),"
2026 const char *effective_appid;
2029 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2030 if (ret != SQLITE_OK) {
2031 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2035 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2036 app = (application_x *)tmp->data;
2040 bg_category = __convert_background_category(
2041 app->background_category);
2042 effective_appid = __find_effective_appid(app->metadata);
2045 __BIND_TEXT(db, stmt, idx++, app->appid);
2046 __BIND_TEXT(db, stmt, idx++, app->component_type);
2047 __BIND_TEXT(db, stmt, idx++, app->exec);
2048 __BIND_TEXT(db, stmt, idx++, __get_bool(app->nodisplay, false));
2049 __BIND_TEXT(db, stmt, idx++, app->type);
2050 __BIND_TEXT(db, stmt, idx++, __get_bool(app->onboot, false));
2051 __BIND_TEXT(db, stmt, idx++, __get_bool(app->multiple, false));
2052 __BIND_TEXT(db, stmt, idx++,
2053 __get_bool(app->autorestart, false));
2054 __BIND_TEXT(db, stmt, idx++,
2055 __get_bool(app->taskmanage, false));
2056 __BIND_TEXT(db, stmt, idx++, app->hwacceleration);
2057 __BIND_TEXT(db, stmt, idx++, app->screenreader);
2058 __BIND_TEXT(db, stmt, idx++, __get_bool(app->mainapp, false));
2059 __BIND_TEXT(db, stmt, idx++, app->recentimage);
2060 __BIND_TEXT(db, stmt, idx++, app->launchcondition);
2061 __BIND_TEXT(db, stmt, idx++,
2062 __get_bool(app->indicatordisplay, true));
2063 __BIND_TEXT(db, stmt, idx++, app->portraitimg);
2064 __BIND_TEXT(db, stmt, idx++, app->landscapeimg);
2065 __BIND_TEXT(db, stmt, idx++,
2066 __get_bool(app->guestmode_visibility, true));
2067 __BIND_TEXT(db, stmt, idx++, app->permission_type);
2068 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->preload, false));
2069 __BIND_TEXT(db, stmt, idx++, __get_bool(app->submode, false));
2070 __BIND_TEXT(db, stmt, idx++, app->submode_mainid);
2071 __BIND_TEXT(db, stmt, idx++, mfx->installed_storage);
2072 __BIND_TEXT(db, stmt, idx++,
2073 __get_bool(app->process_pool, false));
2074 __BIND_TEXT(db, stmt, idx++, app->launch_mode);
2075 __BIND_TEXT(db, stmt, idx++, __get_bool(app->ui_gadget, false));
2076 __BIND_TEXT(db, stmt, idx++,
2077 app->support_mode ? app->support_mode : "0");
2078 __BIND_TEXT(db, stmt, idx++,
2079 __get_bool(mfx->support_disable, false));
2080 __BIND_TEXT(db, stmt, idx++, app->component_type);
2081 __BIND_TEXT(db, stmt, idx++, mfx->package);
2082 __BIND_TEXT(db, stmt, idx++, mfx->tep_name);
2083 __BIND_TEXT(db, stmt, idx++, mfx->zip_mount_file);
2084 __BIND_INT(db, stmt, idx++, bg_category);
2085 __BIND_TEXT(db, stmt, idx++, mfx->type ? mfx->type : "tpk");
2086 __BIND_TEXT(db, stmt, idx++, mfx->root_path);
2087 __BIND_TEXT(db, stmt, idx++, app->api_version);
2088 __BIND_TEXT(db, stmt, idx++, effective_appid);
2089 __BIND_TEXT(db, stmt, idx++,
2090 __get_bool(app->splash_screen_display, true));
2091 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->system, false));
2092 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->removable, false));
2093 __BIND_TEXT(db, stmt, idx++, mfx->installed_time);
2094 __BIND_TEXT(db, stmt, idx++,
2095 __get_bool(app->support_ambient, false));
2096 __BIND_TEXT(db, stmt, idx++, mfx->external_path);
2097 __BIND_TEXT(db, stmt, idx++, app->setup_appid);
2099 ret = sqlite3_step(stmt);
2100 if (ret != SQLITE_DONE) {
2101 _LOGE("step failed: %s", sqlite3_errmsg(db));
2102 sqlite3_finalize(stmt);
2106 sqlite3_reset(stmt);
2108 if (__insert_appcontrol_info(db, app)) {
2109 sqlite3_finalize(stmt);
2112 if (__insert_category_info(db, app)) {
2113 sqlite3_finalize(stmt);
2116 if (__insert_metadata_info(db, app)) {
2117 sqlite3_finalize(stmt);
2120 if (__insert_datacontrol_info(db, app)) {
2121 sqlite3_finalize(stmt);
2124 ss_list = __find_splashscreens(app->splashscreens);
2125 if (__insert_splashscreen_info(db, app, ss_list)) {
2126 g_list_free(ss_list);
2127 sqlite3_finalize(stmt);
2130 g_list_free(ss_list);
2131 if (__insert_app_localized_info(db, app)) {
2132 sqlite3_finalize(stmt);
2137 sqlite3_finalize(stmt);
2142 static int __insert_package_update_info(sqlite3 *db, manifest_x *mfx)
2144 static const char query[] =
2145 "INSERT INTO package_update_info (package, update_version) "
2151 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2152 if (ret != SQLITE_OK) {
2153 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2158 __BIND_TEXT(db, stmt, idx++, mfx->package);
2159 __BIND_TEXT(db, stmt, idx, mfx->version);
2160 ret = sqlite3_step(stmt);
2161 if (ret != SQLITE_DONE) {
2162 _LOGE("step failed: %s", sqlite3_errmsg(db));
2163 sqlite3_finalize(stmt);
2166 sqlite3_finalize(stmt);
2171 static int __insert_package_localized_info(sqlite3 *db, manifest_x *mfx)
2173 static const char query[] =
2174 "INSERT INTO package_localized_info (package, package_locale,"
2175 " package_label, package_icon, package_description,"
2176 " package_license, package_author) "
2177 "VALUES (?, ?, ?, ?, ?, ?, ?)";
2190 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2191 if (ret != SQLITE_OK) {
2192 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2196 locales = __create_locale_list(mfx->label, mfx->license, mfx->icon,
2197 mfx->description, mfx->author);
2198 for (tmp = locales; tmp; tmp = tmp->next) {
2199 locale = (const char *)tmp->data;
2205 __extract_data(locale, mfx->label, mfx->license, mfx->icon,
2206 mfx->description, mfx->author,
2207 &label, &license, &icon, &description, &author);
2208 if (!label && !license && !icon && !description && !author)
2212 __BIND_TEXT(db, stmt, idx++, mfx->package);
2213 __BIND_TEXT(db, stmt, idx++, locale);
2214 __BIND_TEXT(db, stmt, idx++, label);
2215 __BIND_TEXT(db, stmt, idx++, icon);
2216 __BIND_TEXT(db, stmt, idx++, description);
2217 __BIND_TEXT(db, stmt, idx++, license);
2218 __BIND_TEXT(db, stmt, idx++, author);
2220 ret = sqlite3_step(stmt);
2221 if (ret != SQLITE_DONE) {
2222 _LOGE("step failed: %s", sqlite3_errmsg(db));
2223 g_list_free(locales);
2224 sqlite3_finalize(stmt);
2228 sqlite3_reset(stmt);
2231 g_list_free(locales);
2232 sqlite3_finalize(stmt);
2237 static int __insert_package_info(sqlite3 *db, manifest_x *mfx)
2239 static const char query[] =
2240 "INSERT INTO package_info (package, package_type,"
2241 " package_version, package_api_version, package_tep_name,"
2242 " package_zip_mount_file, install_location, package_size,"
2243 " package_removable, package_preload, package_readonly,"
2244 " package_update, package_appsetting, package_nodisplay,"
2245 " package_system, author_name, author_email, author_href,"
2246 " installed_time, installed_storage, storeclient_id,"
2247 " mainapp_id, package_url, root_path, external_path,"
2248 " csc_path, package_support_mode, package_support_disable) "
2252 " LOWER(?), LOWER(?), LOWER(?),"
2253 " LOWER(?), LOWER(?), LOWER(?),"
2254 " LOWER(?), ?, ?, ?,"
2261 const char *author_name = NULL;
2262 const char *author_email = NULL;
2263 const char *author_href = NULL;
2265 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2266 if (ret != SQLITE_OK) {
2267 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2271 if (mfx->author && mfx->author->data) {
2272 author_name = ((author_x *)mfx->author->data)->text;
2273 author_email = ((author_x *)mfx->author->data)->email;
2274 author_href = ((author_x *)mfx->author->data)->href;
2277 __BIND_TEXT(db, stmt, idx++, mfx->package);
2278 __BIND_TEXT(db, stmt, idx++, mfx->type);
2279 __BIND_TEXT(db, stmt, idx++, mfx->version);
2280 __BIND_TEXT(db, stmt, idx++, mfx->api_version);
2281 __BIND_TEXT(db, stmt, idx++, mfx->tep_name);
2282 __BIND_TEXT(db, stmt, idx++, mfx->zip_mount_file);
2283 __BIND_TEXT(db, stmt, idx++, mfx->installlocation);
2284 __BIND_TEXT(db, stmt, idx++, mfx->package_size);
2285 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->removable, true));
2286 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->preload, false));
2287 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->readonly, false));
2288 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->update, false));
2289 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->appsetting, false));
2290 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->nodisplay_setting, false));
2291 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->system, false));
2292 __BIND_TEXT(db, stmt, idx++, author_name);
2293 __BIND_TEXT(db, stmt, idx++, author_email);
2294 __BIND_TEXT(db, stmt, idx++, author_href);
2295 __BIND_TEXT(db, stmt, idx++, mfx->installed_time);
2296 __BIND_TEXT(db, stmt, idx++, mfx->installed_storage);
2297 __BIND_TEXT(db, stmt, idx++, mfx->storeclient_id);
2298 __BIND_TEXT(db, stmt, idx++, mfx->mainapp_id);
2299 __BIND_TEXT(db, stmt, idx++, mfx->package_url);
2300 __BIND_TEXT(db, stmt, idx++, mfx->root_path);
2301 __BIND_TEXT(db, stmt, idx++, mfx->external_path);
2302 __BIND_TEXT(db, stmt, idx++, mfx->csc_path);
2303 __BIND_TEXT(db, stmt, idx++,
2304 mfx->support_mode ? mfx->support_mode : "0");
2305 __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->support_disable, false));
2307 ret = sqlite3_step(stmt);
2308 if (ret != SQLITE_DONE) {
2309 _LOGE("step failed: %s", sqlite3_errmsg(db));
2310 sqlite3_finalize(stmt);
2314 sqlite3_finalize(stmt);
2316 if (__insert_package_update_info(db, mfx))
2318 if (__insert_package_localized_info(db, mfx))
2320 if (__insert_application_info(db, mfx))
2322 if (__insert_package_privilege_info(db, mfx))
2324 if (__insert_package_appdefined_privilege_info(db, mfx))
2326 if (__insert_package_dependency_info(db, mfx))
2332 static int __delete_package_info(sqlite3 *db, const char *pkgid)
2334 static const char query[] =
2335 "DELETE FROM package_info WHERE package=?";
2339 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2340 if (ret != SQLITE_OK) {
2341 _LOGE("prepare failed: %s", sqlite3_errmsg(db));
2345 __BIND_TEXT(db, stmt, 1, pkgid);
2347 ret = sqlite3_step(stmt);
2348 if (ret != SQLITE_DONE) {
2349 _LOGE("step failed: %s", sqlite3_errmsg(db));
2350 sqlite3_finalize(stmt);
2354 sqlite3_finalize(stmt);
2359 API int pkgmgr_parser_delete_pkg_info(sqlite3 *db,
2360 const char *package, uid_t uid)
2362 if (db == NULL || package == NULL) {
2363 _LOGE("invalid parameter");
2364 return PM_PARSER_R_EINVAL;
2367 __BEGIN_TRANSACTION(db);
2368 __DO_TRANSACTION(db, __delete_package_info(db, package));
2369 __END_TRANSACTION(db);
2371 return PM_PARSER_R_OK;
2374 API int pkgmgr_parser_update_pkg_info(sqlite3 *db, manifest_x *mfx, uid_t uid)
2376 if (db == NULL || mfx == NULL) {
2377 _LOGE("invalid parameter");
2378 return PM_PARSER_R_EINVAL;
2381 __BEGIN_TRANSACTION(db);
2382 __DO_TRANSACTION(db, __delete_package_info(db, mfx->package));
2383 __DO_TRANSACTION(db, __insert_package_info(db, mfx));
2384 __END_TRANSACTION(db);
2386 sqlite3_close_v2(db);
2388 return PM_PARSER_R_OK;
2391 API int pkgmgr_parser_insert_pkg_info(sqlite3 *db, manifest_x *mfx, uid_t uid)
2393 if (db == NULL || mfx == NULL) {
2394 _LOGE("invalid parameter");
2395 return PM_PARSER_R_EINVAL;
2398 __BEGIN_TRANSACTION(db);
2399 __DO_TRANSACTION(db, __insert_package_info(db, mfx));
2400 __END_TRANSACTION(db);
2402 sqlite3_close_v2(db);
2404 return PM_PARSER_R_OK;