2 * Copyright (c) 2023 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.
23 #include <sys/smack.h>
24 #include <linux/limits.h>
29 #include <system_info.h>
34 #include <string_view>
36 #include "pkgmgr_parser.h"
37 #include "pkgmgrinfo_basic.h"
38 #include "pkgmgrinfo_internal.h"
39 #include "pkgmgrinfo_private.h"
40 #include "pkgmgrinfo_debug.h"
41 #include "pkgmgr-info.h"
45 constexpr const char LDPI[] = "ldpi";
46 constexpr const char MDPI[] = "mdpi";
47 constexpr const char HDPI[] = "hdpi";
48 constexpr const char XHDPI[] = "xhdpi";
49 constexpr const char XXHDPI[] = "xxhdpi";
51 constexpr const int LDPI_MIN = 0;
52 constexpr const int LDPI_MAX = 240;
53 constexpr const int MDPI_MIN = 241;
54 constexpr const int MDPI_MAX = 300;
55 constexpr const int HDPI_MIN = 301;
56 constexpr const int HDPI_MAX = 380;
57 constexpr const int XHDPI_MIN = 381;
58 constexpr const int XHDPI_MAX = 480;
59 constexpr const int XXHDPI_MIN = 481;
60 constexpr const int XXHDPI_MAX = 600;
62 constexpr const char join_localized_info[] =
63 " LEFT OUTER JOIN package_localized_info"
64 " ON pi.package=package_localized_info.package"
65 " AND package_localized_info.package_locale=?";
66 constexpr const char join_privilege_info[] =
67 " LEFT OUTER JOIN package_privilege_info"
68 " ON pi.package=package_privilege_info.package";
69 constexpr const char join_res_info[] =
70 " LEFT OUTER JOIN package_res_info"
71 " ON pi.package=package_res_info.package";
72 constexpr const char join_metadata[] =
73 " LEFT OUTER JOIN package_metadata"
74 " ON pi.package=package_metadata.package";
76 char* GetCString(int idx, const tizen_base::Database::Result::Record& rec) {
77 std::optional<std::string> str = rec.GetString(idx);
81 return strdup(str->c_str());
84 int _pkginfo_add_description_info_into_list(const char *locale,
85 char *record, GList **description) {
88 info = reinterpret_cast<description_x*>(calloc(1, sizeof(description_x)));
90 LOGE("out of memory");
91 return PMINFO_R_ERROR;
93 info->lang = strdup(locale);
95 *description = g_list_prepend(*description, info);
100 int GetPluginExecutionInfo(const tizen_base::Database& db,
101 const char* pkgid, GList** plugins) {
102 auto q = tizen_base::Database::Sql(
103 "SELECT appid, plugin_type, plugin_name FROM package_plugin_info "
109 LOGE("db.Exec failed : %s", static_cast<const char*>(r));
110 return PMINFO_R_ERROR;
113 for (const auto& rec : r) {
114 plugin_x* plugin = reinterpret_cast<plugin_x*>(
115 calloc(1, sizeof(plugin_x)));
117 LOGE("out of memory");
118 return PMINFO_R_ERROR;
121 plugin->pkgid = strdup(pkgid);
122 plugin->appid = GetCString(0, rec);
123 plugin->plugin_type = GetCString(1, rec);
124 plugin->plugin_name = GetCString(2, rec);
125 *plugins = g_list_prepend(*plugins, (gpointer)plugin);
131 int GetPrivilege(const tizen_base::Database& db, const char* pkgid,
132 GList** privileges) {
133 auto q = tizen_base::Database::Sql(
134 "SELECT DISTINCT privilege, type FROM package_privilege_info "
139 LOGE("db.Exec failed : %s", static_cast<const char*>(r));
140 return PMINFO_R_ERROR;
143 for (const auto& rec : r) {
144 privilege_x* privilege = reinterpret_cast<privilege_x*>(
145 calloc(1, sizeof(privilege_x)));
147 LOGE("failed to alloc memory");
148 return PMINFO_R_ERROR;
151 privilege->value = GetCString(0, rec);
152 privilege->type = GetCString(1, rec);
153 *privileges = g_list_prepend(*privileges, (gpointer)privilege);
159 int GetAppdefinedPrivilege(const tizen_base::Database& db,
160 const char* pkgid, GList** privileges) {
161 auto q = tizen_base::Database::Sql(
162 "SELECT DISTINCT privilege, license, type FROM "
163 "package_appdefined_privilege_info WHERE package=?")
167 LOGE("db.Exec failed : %s", static_cast<const char*>(r));
168 return PMINFO_R_ERROR;
171 for (const auto& rec : r) {
172 appdefined_privilege_x* privilege = reinterpret_cast<
173 appdefined_privilege_x*>(calloc(1, sizeof(appdefined_privilege_x)));
175 LOGE("failed to alloc memory");
176 return PMINFO_R_ERROR;
179 privilege->value = GetCString(0, rec);
180 privilege->license = GetCString(1, rec);
181 privilege->type = GetCString(2, rec);
182 *privileges = g_list_prepend(*privileges, (gpointer)privilege);
188 int GetDependency(const tizen_base::Database& db, const char* pkgid,
189 GList** dependencies) {
190 auto q = tizen_base::Database::Sql(
191 "SELECT DISTINCT depends_on, type, required_version "
192 "FROM package_dependency_info WHERE package=?")
196 LOGE("db.Exec failed : %s", static_cast<const char*>(r));
197 return PMINFO_R_ERROR;
200 for (const auto& rec : r) {
201 dependency_x* dependency = reinterpret_cast<
202 dependency_x*>(calloc(1, sizeof(dependency_x)));
204 LOGE("failed to alloc memory");
205 return PMINFO_R_ERROR;
208 dependency->depends_on = GetCString(0, rec);
209 dependency->type = GetCString(1, rec);
210 dependency->required_version = GetCString(2, rec);
211 *dependencies = g_list_prepend(*dependencies, (gpointer)dependency);
217 int GetResAllowedPackages(const tizen_base::Database& db, const char* pkgid,
218 GList** allowed_packages) {
219 auto q = tizen_base::Database::Sql(
220 "SELECT DISTINCT allowed_package, required_privilege "
221 "FROM package_res_allowed_package WHERE package=?")
225 LOGE("db.Exec failed : %s", static_cast<const char*>(r));
226 return PMINFO_R_ERROR;
229 for (const auto& rec : r) {
230 res_allowed_package_x* allowed_package_x = nullptr;
231 char* package = nullptr;
232 char* privilege = nullptr;
234 package = GetCString(0, rec);
238 for (GList* l = *allowed_packages; l; l = l->next) {
239 allowed_package_x = (res_allowed_package_x *)l->data;
240 if (!strcmp(package, allowed_package_x->allowed_package))
242 allowed_package_x = nullptr;
245 if (allowed_package_x) {
248 allowed_package_x = reinterpret_cast<res_allowed_package_x*>(calloc(1,
249 sizeof(res_allowed_package_x)));
250 if (allowed_package_x == nullptr) {
251 LOGE("failed to alloc memory");
253 return PMINFO_R_ERROR;
255 allowed_package_x->allowed_package = package;
256 *allowed_packages = g_list_prepend(*allowed_packages,
257 (gpointer)allowed_package_x);
260 privilege = GetCString(1, rec);
264 allowed_package_x->required_privileges = g_list_prepend(
265 allowed_package_x->required_privileges,
272 int GetResInfo(const tizen_base::Database& db, const char* pkgid,
273 char** res_type, char** res_version,
274 GList** res_allowed_packages) {
275 auto q = tizen_base::Database::Sql(
276 "SELECT DISTINCT res_type, res_version "
277 "FROM package_res_info WHERE package=?")
281 LOGE("db.Exec() failed : %s", static_cast<const char*>(r));
282 return PMINFO_R_ERROR;
285 auto rec = r.GetFirstRecord();
289 if (GetResAllowedPackages(db, pkgid, res_allowed_packages) != PMINFO_R_OK)
290 return PMINFO_R_ERROR;
292 *res_type = GetCString(0, *rec);
293 *res_version = GetCString(1, *rec);
298 int GetPackageMetadata(const tizen_base::Database& db,
299 const char* pkgid, GList** metadata) {
300 auto q = tizen_base::Database::Sql(
301 "SELECT md_key, md_value "
302 "FROM package_metadata WHERE package=?")
307 _LOGE("db.Exec() failed: %s", static_cast<const char*>(r));
308 return PMINFO_R_ERROR;
311 for (const auto& rec : r) {
312 metadata_x* info = static_cast<metadata_x*>(
313 calloc(1, sizeof(metadata_x)));
314 if (info == nullptr) {
315 LOGE("out of memory");
316 return PMINFO_R_ERROR;
320 info->key = GetCString(idx++, rec);
321 info->value = GetCString(idx++, rec);
322 *metadata = g_list_prepend(*metadata, info);
328 int _get_filtered_query(pkgmgrinfo_filter_x *filter,
329 const std::string& locale, uid_t uid,
330 std::string& query, std::vector<std::string>& bind_params) {
335 if (filter->cache_flag) {
336 joined = E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO |
337 E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO |
338 E_PMINFO_PKGINFO_JOIN_RES_INFO |
339 E_PMINFO_PKGINFO_JOIN_METADATA;
342 std::string buf = " WHERE 1=1 ";
343 GList *tmp_params = nullptr;
344 for (GSList* list = filter->list; list; list = list->next) {
345 char* condition = nullptr;
346 joined |= __get_filter_condition(list->data, uid, &condition,
348 if (condition == nullptr)
356 if (filter->list_pkg_metadata)
358 for (GSList* list = filter->list_pkg_metadata; list; list = list->next) {
359 char* condition = nullptr;
360 joined |= __get_pkg_metadata_filter_condition(list->data,
361 &condition, &tmp_params);
362 if (condition == nullptr)
368 if (filter->list_pkg_metadata)
372 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
373 buf2 += join_localized_info;
374 bind_params.push_back(locale);
377 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO)
378 buf2 += join_privilege_info;
379 if (joined & E_PMINFO_PKGINFO_JOIN_RES_INFO)
380 buf2 += join_res_info;
381 if (joined & E_PMINFO_PKGINFO_JOIN_METADATA)
382 buf2 += join_metadata;
384 for (GList* l = tmp_params; l != nullptr; l = l->next)
385 bind_params.push_back(reinterpret_cast<const char*>(l->data));
388 g_list_free_full(tmp_params, free);
393 bool CheckPackageStorageStatus(pkgmgrinfo_filter_x* tmp_filter) {
394 GSList* tmp_list = nullptr;
395 pkgmgrinfo_node_x* tmp_node = nullptr;
398 if (tmp_filter->cache_flag)
401 property = _pminfo_pkginfo_convert_to_prop_bool(
402 PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE);
403 for (tmp_list = tmp_filter->list; tmp_list != nullptr;
404 tmp_list = g_slist_next(tmp_list)) {
405 tmp_node = reinterpret_cast<pkgmgrinfo_node_x*>(tmp_list->data);
406 if (property == tmp_node->prop) {
407 if (strcmp(tmp_node->value, "true") == 0)
416 int DoGetPkgInfo(const tizen_base::Database& db, uid_t uid,
417 const std::string& locale, pkgmgrinfo_filter_x* filter, int flag,
418 std::map<std::string, std::shared_ptr<package_x>>& packages) {
419 static const char query_raw[] =
420 "SELECT DISTINCT pi.package, pi.installed_storage, pi.external_path";
421 static const char query_basic[] =
422 ", pi.package_version, pi.install_location, "
423 "pi.package_removable, pi.package_preload, pi.package_readonly, "
424 "pi.package_update, pi.package_appsetting, pi.package_system, "
425 "pi.package_type, pi.package_size, pi.installed_time, "
426 "pi.storeclient_id, pi.mainapp_id, pi.package_url, pi.root_path, "
427 "pi.csc_path, pi.package_nodisplay, pi.package_api_version, "
428 "pi.package_support_disable, pi.package_tep_name, "
429 "pi.package_zip_mount_file, pi.package_support_mode, pi.package_disable, "
430 "pi.light_user_switch_mode";
431 static const char query_author[] =
432 ", pi.author_name, pi.author_email, pi.author_href";
433 static const char query_label[] =
435 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
436 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
437 static const char query_icon[] =
439 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
440 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
441 static const char query_description[] =
443 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
444 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
445 static const char query_res_type[] =
446 ", (SELECT res_type FROM package_res_info WHERE pi.package=package)";
447 static const char query_res_version[] =
448 ", (SELECT res_version FROM package_res_info WHERE pi.package=package)";
449 static const char query_from_clause[] = " FROM package_info as pi";
450 int ret = PMINFO_R_ERROR;
451 char* tmp_record = nullptr;
452 std::vector<std::string> bind_params;
453 bool is_check_storage = true;
454 const uid_t global_user_uid = GLOBAL_USER;
456 if (!static_cast<bool>(db) || locale.empty() || filter == nullptr) {
457 LOGE("Invalid parameter");
458 return PMINFO_R_EINVAL;
461 is_check_storage = CheckPackageStorageStatus(filter);
462 std::string query = query_raw;
463 if (flag & PMINFO_APPINFO_GET_BASICINFO)
464 query += query_basic;
465 if (flag & PMINFO_PKGINFO_GET_AUTHOR)
466 query += query_author;
467 if (flag & PMINFO_PKGINFO_GET_LABEL) {
468 query += query_label;
469 bind_params.push_back(locale);
472 if (flag & PMINFO_PKGINFO_GET_ICON) {
474 bind_params.push_back(locale);
477 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
478 query += query_description;
479 bind_params.push_back(locale);
482 if (flag & PMINFO_PKGINFO_GET_RES_INFO) {
483 query += query_res_type;
484 query += query_res_version;
487 query += query_from_clause;
488 std::string constraints;
489 ret = _get_filtered_query(filter, locale, uid,
490 constraints, bind_params);
491 if (ret != PMINFO_R_OK) {
492 LOGE("Failed to get WHERE clause");
493 return PMINFO_R_EINVAL;
496 if (!constraints.empty())
497 query += constraints;
499 auto q = tizen_base::Database::Sql(query);
500 for (auto& i : bind_params)
505 LOGE("db.Exec failed : %s", static_cast<const char*>(r));
506 return PMINFO_R_ERROR;
509 for (const auto& rec : r) {
510 package_x* info = reinterpret_cast<package_x*>(calloc(1, sizeof(package_x)));
511 if (info == nullptr) {
512 LOGE("out of memory");
513 return PMINFO_R_ERROR;
516 std::shared_ptr<package_x> pkg(info, pkgmgrinfo_basic_free_package);
517 info->locale = strdup(locale.c_str());
518 if (info->locale == nullptr) {
519 LOGE("Out of memory");
520 return PMINFO_R_ERROR;
525 info->package = GetCString(idx++, rec);
526 info->installed_storage = GetCString(idx++, rec);
527 info->external_path = GetCString(idx++, rec);
528 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
529 info->version = GetCString(idx++, rec);
530 info->installlocation = GetCString(idx++, rec);
531 info->removable = GetCString(idx++, rec);
532 info->preload = GetCString(idx++, rec);
533 info->readonly = GetCString(idx++, rec);
534 info->update = GetCString(idx++, rec);
535 info->appsetting = GetCString(idx++, rec);
536 info->system = GetCString(idx++, rec);
537 info->type = GetCString(idx++, rec);
538 info->package_size = GetCString(idx++, rec);
539 info->installed_time = GetCString(idx++, rec);
540 info->storeclient_id = GetCString(idx++, rec);
541 info->mainapp_id = GetCString(idx++, rec);
542 info->package_url = GetCString(idx++, rec);
543 info->root_path = GetCString(idx++, rec);
544 info->csc_path = GetCString(idx++, rec);
545 info->nodisplay_setting = GetCString(idx++, rec);
546 info->api_version = GetCString(idx++, rec);
547 info->support_disable = GetCString(idx++, rec);
548 info->tep_name = GetCString(idx++, rec);
549 info->zip_mount_file = GetCString(idx++, rec);
550 info->support_mode = GetCString(idx++, rec);
551 info->is_disabled = GetCString(idx++, rec);
552 info->light_user_switch_mode = GetCString(idx++, rec);
555 info->for_all_users =
556 strdup((uid != global_user_uid) ? "false" : "true");
558 if (GetPluginExecutionInfo(db, info->package, &info->plugin))
559 return PMINFO_R_ERROR;
561 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
562 author_x* author = reinterpret_cast<author_x*>(calloc(1, sizeof(author_x)));
563 if (author == nullptr) {
564 return PMINFO_R_ERROR;
566 author->text = GetCString(idx++, rec);
567 author->email = GetCString(idx++, rec);
568 author->href = GetCString(idx++, rec);
569 info->author = g_list_prepend(info->author, author);
572 if (flag & PMINFO_PKGINFO_GET_LABEL) {
573 tmp_record = GetCString(idx++, rec);
574 if (_add_label_info_into_list(locale.c_str(),
575 tmp_record, &info->label)) {
576 return PMINFO_R_ERROR;
580 if (flag & PMINFO_PKGINFO_GET_ICON) {
581 tmp_record = GetCString(idx++, rec);
582 if (_add_icon_info_into_list(locale.c_str(),
583 tmp_record, &info->icon)) {
584 return PMINFO_R_ERROR;
588 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
589 tmp_record = GetCString(idx++, rec);
590 if (_pkginfo_add_description_info_into_list(locale.c_str(),
591 tmp_record, &info->description)) {
592 return PMINFO_R_ERROR;
596 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
597 if (GetPrivilege(db, info->package, &info->privileges))
598 return PMINFO_R_ERROR;
601 if (flag & PMINFO_PKGINFO_GET_APPDEFINED_PRIVILEGE) {
602 if (GetAppdefinedPrivilege(db, info->package,
603 &info->appdefined_privileges)) {
604 return PMINFO_R_ERROR;
608 if (flag & PMINFO_PKGINFO_GET_DEPENDENCY) {
609 if (GetDependency(db, info->package, &info->dependencies))
610 return PMINFO_R_ERROR;
613 if (flag & PMINFO_PKGINFO_GET_RES_INFO) {
614 if (GetResInfo(db, info->package, &info->res_type,
615 &info->res_version, &info->res_allowed_packages) < 0) {
616 return PMINFO_R_ERROR;
620 if (flag & PMINFO_PKGINFO_GET_METADATA) {
621 if (GetPackageMetadata(db, info->package, &info->metadata) < 0)
622 return PMINFO_R_ERROR;
625 if (is_check_storage && __pkginfo_check_installed_storage(info) !=
629 packages[info->package] = std::move(pkg);
635 int DoGetDependsOn(const tizen_base::Database& db, const std::string& pkgid,
636 std::queue<std::string>& queue, std::set<std::string>& dup_checker,
637 std::vector<dependency_x*>& dep_list) {
638 if (dup_checker.find(pkgid) != dup_checker.end())
640 dup_checker.insert(pkgid);
642 auto q = tizen_base::Database::Sql(
643 "SELECT package, depends_on, type, required_version "
644 "FROM package_dependency_info WHERE depends_on=?")
649 LOGE("db.Exec() failed : %s", static_cast<const char*>(r));
650 return PMINFO_R_ERROR;
653 for (const auto& rec : r) {
654 auto* req = reinterpret_cast<dependency_x*>(calloc(1, sizeof(dependency_x)));
655 if (req == nullptr) {
656 LOGE("out of memory");
657 return PMINFO_R_ERROR;
660 req->pkgid = GetCString(0, rec);
661 req->depends_on = GetCString(1, rec);
662 req->type = GetCString(2, rec);
663 req->required_version = GetCString(3, rec);
665 dep_list.push_back(req);
666 queue.push(req->pkgid);
672 void __free_depends_on(dependency_x* dep) {
674 free(dep->depends_on);
676 free(dep->required_version);
680 int DoExecuteQuery(const tizen_base::Database& db, const std::string& query,
681 const std::vector<std::optional<std::string>>& param) {
682 auto q = tizen_base::Database::Sql(query);
683 for (auto& p : param) {
687 q.Bind(std::nullopt);
692 LOGE("db.Exec() failed : %s", static_cast<const char*>(r));
693 return PMINFO_R_ERROR;
699 int __check_dpi(const char *dpi_char, int dpi_int) {
700 if (dpi_char == NULL)
703 if (strcasecmp(dpi_char, LDPI) == 0) {
704 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
708 } else if (strcasecmp(dpi_char, MDPI) == 0) {
709 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
713 } else if (strcasecmp(dpi_char, HDPI) == 0) {
714 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
718 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
719 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
723 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
724 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
732 void __find_appcontrol_splashscreen_with_dpi(gpointer data,
733 gpointer user_data) {
734 splashscreen_x *ss = (splashscreen_x *)data;
735 GList **list = (GList **)user_data;
739 if (ss->operation == NULL || ss->dpi == NULL)
742 ret = system_info_get_platform_int(
743 "http://tizen.org/feature/screen.dpi", &dpi);
744 if (ret != SYSTEM_INFO_ERROR_NONE)
747 if (__check_dpi(ss->dpi, dpi) != 0)
750 *list = g_list_prepend(*list, ss);
753 void __find_appcontrol_splashscreen(gpointer data, gpointer user_data) {
754 splashscreen_x *ss = (splashscreen_x *)data;
755 GList **list = (GList **)user_data;
756 splashscreen_x *ss_tmp;
759 if (ss->operation == NULL || ss->dpi)
762 for (tmp = *list; tmp; tmp = tmp->next) {
763 ss_tmp = (splashscreen_x *)tmp->data;
764 if (ss_tmp->operation
765 && strcmp(ss_tmp->operation, ss->operation) == 0
766 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
770 *list = g_list_prepend(*list, ss);
773 gint __compare_splashscreen_with_orientation_dpi(gconstpointer a,
775 splashscreen_x *ss = (splashscreen_x *)a;
776 const char *orientation = (const char *)b;
780 if (ss->operation || ss->dpi == NULL)
783 ret = system_info_get_platform_int(
784 "http://tizen.org/feature/screen.dpi", &dpi);
785 if (ret != SYSTEM_INFO_ERROR_NONE)
788 if (strcasecmp(ss->orientation, orientation) == 0 &&
789 __check_dpi(ss->dpi, dpi) == 0)
795 gint __compare_splashscreen_with_orientation(gconstpointer a,
797 splashscreen_x *ss = (splashscreen_x *)a;
798 const char *orientation = (const char *)b;
800 if (ss->operation || ss->dpi)
803 if (strcasecmp(ss->orientation, orientation) == 0)
809 splashscreen_x *__find_default_splashscreen(GList *splashscreens,
810 const char *orientation) {
813 tmp = g_list_find_custom(splashscreens, orientation,
815 __compare_splashscreen_with_orientation_dpi);
817 return (splashscreen_x *)tmp->data;
819 tmp = g_list_find_custom(splashscreens, orientation,
820 (GCompareFunc)__compare_splashscreen_with_orientation);
822 return (splashscreen_x *)tmp->data;
827 GList *__find_splashscreens(GList *splashscreens) {
831 if (splashscreens == NULL)
834 g_list_foreach(splashscreens,
835 __find_appcontrol_splashscreen_with_dpi, &list);
836 g_list_foreach(splashscreens,
837 __find_appcontrol_splashscreen, &list);
839 ss = __find_default_splashscreen(splashscreens, "portrait");
841 list = g_list_prepend(list, ss);
842 ss = __find_default_splashscreen(splashscreens, "landscape");
844 list = g_list_prepend(list, ss);
849 int InsertSplashscreenInfo(const tizen_base::Database& db,
850 application_x *app, GList *ss_list) {
851 if (app->splashscreens == nullptr)
854 if (ss_list == nullptr)
857 auto q = tizen_base::Database::Sql(
858 "INSERT INTO package_app_splash_screen (app_id, src, type,"
859 " orientation, indicatordisplay, operation, color_depth) "
860 "VALUES (?, ?, ?, ?, ?, ?, ?)");
861 auto r = db.Prepare(q);
863 _LOGE("db.Prepare() failed: %s", static_cast<const char*>(r));
867 for (GList* tmp = ss_list; tmp; tmp = tmp->next) {
868 splashscreen_x* ss = reinterpret_cast<splashscreen_x*>(tmp->data);
875 .Bind(ss->orientation)
876 .Bind(ss->indicatordisplay)
878 .Bind(ss->color_depth);
879 if (!db.Exec(q, r)) {
880 _LOGE("db.Exec() failed");
888 void __trimfunc(GList *trim_list) {
891 GList *list = g_list_first(trim_list);
894 trim_data = (char *)list->data;
897 if (strcmp(trim_data, prev) == 0) {
898 trim_list = g_list_remove(trim_list,
900 list = g_list_first(trim_list);
909 list = g_list_next(list);
913 int InsertPackageAppdefinedPrivilegeInfo(const tizen_base::Database& db,
915 auto q = tizen_base::Database::Sql(
916 "INSERT INTO package_appdefined_privilege_info "
917 "(package, privilege, license, type) "
918 "VALUES (?, ?, ?, ?)");
919 auto r = db.Prepare(q);
921 _LOGE("db.Prepare() failed: %s", static_cast<const char*>(r));
925 for (GList* tmp = mfx->appdefined_privileges; tmp; tmp = tmp->next) {
926 appdefined_privilege_x* priv =
927 reinterpret_cast<appdefined_privilege_x*>(tmp->data);
936 if (!db.Exec(q, r)) {
937 _LOGE("db.Exec() failed");
945 int InsertPackageDependencyInfo(const tizen_base::Database& db,
947 auto q = tizen_base::Database::Sql(
948 "INSERT INTO package_dependency_info"
949 " (package, depends_on, type, required_version) "
950 "VALUES (?, ?, ?, ?)");
951 auto r = db.Prepare(q);
953 _LOGE("db.Prepare() failed: %s", static_cast<const char*>(r));
957 for (GList* tmp = mfx->dependencies; tmp; tmp = tmp->next) {
958 dependency_x* dep = reinterpret_cast<dependency_x*>(tmp->data);
964 .Bind(dep->depends_on)
966 .Bind(dep->required_version);
968 if (!db.Exec(q, r)) {
969 _LOGE("db.Exec() failed");
977 int InsertMainappLocalizedInfo(const tizen_base::Database& db,
978 application_x* app, const char* locale, const char* label,
980 auto q = tizen_base::Database::Sql(
981 "INSERT OR REPLACE INTO package_localized_info ("
982 " package, package_locale, package_label, package_icon,"
983 " package_description, package_license, package_author) "
985 " COALESCE((SELECT package_label FROM package_localized_info"
986 " WHERE package=? AND package_locale=?), ?),"
987 " COALESCE((SELECT package_icon FROM package_localized_info"
988 " WHERE package=? AND package_icon=?), ?),"
989 " (SELECT package_description FROM package_localized_info"
990 " WHERE package=? AND package_locale=?),"
991 " (SELECT package_description FROM package_localized_info"
992 " WHERE package=? AND package_locale=?),"
993 " (SELECT package_description FROM package_localized_info"
994 " WHERE package=? AND package_locale=?))")
1009 auto r = db.Exec(q);
1011 _LOGE("db.Exec() failed: %s", static_cast<const char*>(r));
1018 gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata) {
1019 if (a == NULL || b == NULL)
1021 if (strcmp((char *)a, (char *)b) == 0)
1023 if (strcmp((char *)a, (char *)b) < 0)
1025 if (strcmp((char *)a, (char *)b) > 0)
1030 GList *__create_locale_list(GList *lbls, GList *lcns, GList *icns,
1031 GList *dcns, GList *aths) {
1032 GList *locale = NULL;
1040 for (tmp = lbls; tmp; tmp = tmp->next) {
1041 lbl = (label_x *)tmp->data;
1045 locale = g_list_insert_sorted_with_data(
1046 locale, (gpointer)lbl->lang,
1047 __comparefunc, NULL);
1049 for (tmp = lcns; tmp; tmp = tmp->next) {
1050 lcn = (license_x *)tmp->data;
1054 locale = g_list_insert_sorted_with_data(
1055 locale, (gpointer)lcn->lang,
1056 __comparefunc, NULL);
1058 for (tmp = icns; tmp; tmp = tmp->next) {
1059 icn = (icon_x *)tmp->data;
1063 locale = g_list_insert_sorted_with_data(
1064 locale, (gpointer)icn->lang,
1065 __comparefunc, NULL);
1067 for (tmp = dcns; tmp; tmp = tmp->next) {
1068 dcn = (description_x *)tmp->data;
1072 locale = g_list_insert_sorted_with_data(
1073 locale, (gpointer)dcn->lang,
1074 __comparefunc, NULL);
1076 for (tmp = aths; tmp; tmp = tmp->next) {
1077 ath = (author_x *)tmp->data;
1081 locale = g_list_insert_sorted_with_data(
1082 locale, (gpointer)ath->lang,
1083 __comparefunc, NULL);
1089 gint __check_icon_resolution(std::string_view orig_icon_path,
1090 char **new_icon_path) {
1091 const char* dpi_path[2];
1092 std::string modified_iconpath;
1093 if (orig_icon_path.empty())
1097 int ret = system_info_get_platform_int(
1098 "http://tizen.org/feature/screen.dpi", &dpi);
1099 if (ret != SYSTEM_INFO_ERROR_NONE)
1102 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
1103 dpi_path[0] = "LDPI";
1104 dpi_path[1] = "ldpi";
1105 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
1106 dpi_path[0] = "MDPI";
1107 dpi_path[1] = "mdpi";
1108 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
1109 dpi_path[0] = "HDPI";
1110 dpi_path[1] = "hdpi";
1111 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
1112 dpi_path[0] = "XHDPI";
1113 dpi_path[1] = "xhdpi";
1114 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
1115 dpi_path[0] = "XXHDPI";
1116 dpi_path[1] = "xxhdpi";
1118 _LOGE("Unidentified dpi[%d]", dpi);
1122 auto pos = orig_icon_path.rfind('/');
1123 if (pos == std::string::npos)
1125 std::string_view icon_filename = orig_icon_path.substr(pos);
1127 for (int i = 0; i < 2; i++) {
1128 modified_iconpath = std::string(orig_icon_path) +
1129 "/" + dpi_path[i] + std::string(icon_filename);
1130 if (access(modified_iconpath.c_str(), F_OK) != -1) {
1131 *new_icon_path = strdup(modified_iconpath.c_str());
1139 gint __compare_icon(gconstpointer a, gconstpointer b) {
1140 icon_x *icon = (icon_x *)a;
1143 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
1146 if (icon->dpi != NULL)
1149 if (__check_icon_resolution(icon->text, &icon_path) == 0) {
1151 icon->text = icon_path;
1157 gint __compare_icon_with_lang(gconstpointer a, gconstpointer b) {
1158 icon_x *icon = (icon_x *)a;
1159 char *lang = (char *)b;
1162 if (icon->dpi != NULL)
1165 if (strcasecmp(icon->lang, lang) == 0) {
1166 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
1167 /* icon for no locale. check existance of
1168 * folder-hierachied default icons
1170 if (__check_icon_resolution(icon->text,
1173 icon->text = icon_path;
1182 gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b) {
1183 icon_x *icon = (icon_x *)a;
1184 int dpi = GPOINTER_TO_INT(b);
1186 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
1189 if (icon->dpi == NULL)
1192 if (__check_dpi(icon->dpi, dpi) == 0)
1198 gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b) {
1200 icon_x *icon = (icon_x *)a;
1201 char *lang = (char *)b;
1204 ret = system_info_get_platform_int(
1205 "http://tizen.org/feature/screen.dpi", &dpi);
1206 if (ret != SYSTEM_INFO_ERROR_NONE)
1209 if (strcasecmp(icon->lang, lang) == 0 &&
1210 __check_dpi(icon->dpi, dpi) == 0)
1216 char *__find_icon(GList *icons, const char *lang) {
1222 /* first, find icon whose locale and dpi with given lang and
1223 * system's dpi has matched
1225 tmp = g_list_find_custom(icons, lang,
1226 (GCompareFunc)__compare_icon_with_lang_dpi);
1228 icon = (icon_x *)tmp->data;
1229 return (char *)icon->text;
1232 /* if first has failed, find icon whose locale has matched */
1233 tmp = g_list_find_custom(icons, lang,
1234 (GCompareFunc)__compare_icon_with_lang);
1236 icon = (icon_x *)tmp->data;
1237 return (char *)icon->text;
1240 /* if second has failed, find icon whose dpi has matched with
1243 ret = system_info_get_platform_int(
1244 "http://tizen.org/feature/screen.dpi", &dpi);
1245 if (ret == SYSTEM_INFO_ERROR_NONE) {
1246 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi),
1247 (GCompareFunc)__compare_icon_with_dpi);
1249 icon = (icon_x *)tmp->data;
1250 return (char *)icon->text;
1254 /* last, find default icon marked as "No Locale" */
1255 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
1257 icon = (icon_x *)tmp->data;
1258 return (char *)icon->text;
1264 void __extract_data(const char *locale, GList *lbls, GList *lcns,
1265 GList *icns, GList *dcns, GList *aths, char **label,
1266 char **license, char **icon, char **description, char **author) {
1273 for (tmp = lbls; tmp; tmp = tmp->next) {
1274 lbl = (label_x *)tmp->data;
1278 if (strcmp(lbl->lang, locale) == 0) {
1279 *label = (char *)lbl->text;
1284 for (tmp = lcns; tmp; tmp = tmp->next) {
1285 lcn = (license_x *)tmp->data;
1289 if (strcmp(lcn->lang, locale) == 0) {
1290 *license = (char *)lcn->text;
1296 *icon = __find_icon(icns, locale);
1298 for (tmp = dcns; tmp; tmp = tmp->next) {
1299 dcn = (description_x *)tmp->data;
1303 if (strcmp(dcn->lang, locale) == 0) {
1304 *description = (char *)dcn->text;
1309 for (tmp = aths; tmp; tmp = tmp->next) {
1310 ath = (author_x *)tmp->data;
1314 if (strcmp(ath->lang, locale) == 0) {
1315 *author = (char *)ath->text;
1322 int InsertAppLocalizedInfo(const tizen_base::Database& db,
1323 application_x* app) {
1324 auto q = tizen_base::Database::Sql(
1325 "INSERT INTO package_app_localized_info (app_id, app_locale,"
1326 " app_label, app_icon) "
1327 "VALUES (?, ?, ?, ?)");
1328 auto r = db.Prepare(q);
1330 _LOGE("db.Prepare() failed: %s", static_cast<const char*>(r));
1334 std::unique_ptr<GList, decltype(g_list_free)*> locales(
1335 __create_locale_list(app->label, nullptr, app->icon, nullptr, nullptr),
1337 for (GList* tmp = locales.get(); tmp; tmp = tmp->next) {
1338 const char* locale = reinterpret_cast<char*>(tmp->data);
1339 char* label = nullptr;
1340 char* icon = nullptr;
1341 __extract_data(locale, app->label, nullptr, app->icon, nullptr, nullptr,
1342 &label, nullptr, &icon, nullptr, nullptr);
1343 if (!label && !icon)
1351 if (!db.Exec(q, r)) {
1352 _LOGE("db.Exec() failed");
1356 if (strcasecmp(app->mainapp, "true") == 0) {
1357 if (InsertMainappLocalizedInfo(db, app, locale, label, icon))
1358 _LOGE("insert mainapp localized info failed");
1365 int InsertAppResControl(const tizen_base::Database& db,
1366 application_x *app) {
1367 if (app->res_control == nullptr)
1370 auto q = tizen_base::Database::Sql(
1371 "INSERT INTO package_app_res_control (app_id, res_type,"
1372 " min_res_version, max_res_version, auto_close) "
1373 "VALUES (?, ?, ?, ?, ?)");
1374 auto r = db.Prepare(q);
1376 _LOGE("db.Prepare() failed: %s", static_cast<const char*>(r));
1380 for (GList* tmp = app->res_control; tmp; tmp = tmp->next) {
1381 res_control_x* rc = reinterpret_cast<res_control_x*>(tmp->data);
1388 .Bind(rc->min_res_version)
1389 .Bind(rc->max_res_version)
1390 .Bind(rc->auto_close);
1391 if (!db.Exec(q, r)) {
1392 _LOGE("db.Exec() failed");
1400 int InsertPackagePrivilegeInfo(const tizen_base::Database& db, manifest_x* mfx) {
1401 auto q = tizen_base::Database::Sql(
1402 "INSERT INTO package_privilege_info (package, privilege, type) "
1403 "VALUES (?, ?, ?)");
1404 auto r = db.Prepare(q);
1406 _LOGE("db.Prepare() failed: %s", static_cast<const char*>(r));
1410 for (GList* tmp = mfx->privileges; tmp; tmp = tmp->next) {
1411 privilege_x* priv = reinterpret_cast<privilege_x*>(tmp->data);
1412 if (priv == nullptr)
1419 if (!db.Exec(q, r)) {
1420 _LOGE("db.Exec() failed");
1428 int InsertAppDataControlPrivilegeInfo(const tizen_base::Database& db,
1429 datacontrol_x* datacontrol) {
1430 if (datacontrol == nullptr)
1433 auto q = tizen_base::Database::Sql(
1434 "INSERT INTO package_app_data_control_privilege (providerid,"
1435 " privilege, type) VALUES (?, ?, ?)");
1437 auto r = db.Prepare(q);
1439 _LOGE("db.Prepare() failed: %s", static_cast<const char*>(r));
1443 for (GList* privileges = datacontrol->privileges; privileges;
1444 privileges = privileges->next) {
1445 char* priv = reinterpret_cast<char*>(privileges->data);
1446 if (priv == nullptr)
1450 .Bind(datacontrol->providerid)
1452 .Bind(datacontrol->type);
1453 if (!db.Exec(q, r)) {
1454 _LOGE("db.Exec() failed");
1462 int InsertDatacontrolInfo(const tizen_base::Database& db, application_x* app) {
1463 if (app->datacontrol == nullptr)
1466 auto q = tizen_base::Database::Sql(
1467 "INSERT INTO package_app_data_control (app_id, providerid,"
1468 " access, type, trusted) VALUES (?, ?, ?, ?, ?)");
1469 auto r = db.Prepare(q);
1471 _LOGE("db.Prepare() failed: %s", static_cast<const char*>(r));
1475 for (GList* tmp = app->datacontrol; tmp; tmp = tmp->next) {
1476 datacontrol_x* dc = reinterpret_cast<datacontrol_x*>(tmp->data);
1481 .Bind(dc->providerid)
1486 if (!db.Exec(q, r)) {
1487 _LOGE("db.Exec() failed: %s", static_cast<const char*>(r));
1491 if (dc->privileges && InsertAppDataControlPrivilegeInfo(db, dc))
1498 int InsertCategoryInfo(const tizen_base::Database& db, application_x* app) {
1499 if (app->category == nullptr)
1502 auto q = tizen_base::Database::Sql(
1503 "INSERT INTO package_app_app_category (app_id, category) "
1505 auto r = db.Prepare(q);
1507 _LOGE("db.Prepare() failed: %s", static_cast<const char*>(r));
1511 for (GList* tmp = app->category; tmp; tmp = tmp->next) {
1512 const char* category = reinterpret_cast<const char*>(tmp->data);
1513 if (category == nullptr)
1519 if (!db.Exec(q, r)) {
1520 _LOGE("db.Exec() failed");
1528 int InsertMetadataInfo(const tizen_base::Database& db, application_x* app) {
1529 if (app->metadata == nullptr)
1532 auto q = tizen_base::Database::Sql(
1533 "INSERT INTO package_app_app_metadata (app_id,"
1534 " md_key, md_value) VALUES (?, ?, ?)");
1535 auto r = db.Prepare(q);
1537 _LOGE("db.Prepare() failed: %s", static_cast<const char*>(r));
1541 for (GList* tmp = app->metadata; tmp; tmp = tmp->next) {
1542 metadata_x* md = reinterpret_cast<metadata_x*>(tmp->data);
1550 if (!db.Exec(q, r)) {
1551 _LOGE("db.Exec() failed: %s", static_cast<const char*>(r));
1559 int InsertAppcontrolPrivilegeInfo(const tizen_base::Database& db,
1560 const char *appid, appcontrol_x* ac) {
1564 auto q = tizen_base::Database::Sql(
1565 "INSERT INTO package_app_app_control_privilege (app_id,"
1566 " app_control, privilege) VALUES (?, ?, ?)");
1567 auto r = db.Prepare(q);
1569 _LOGE("db.Prepare() failed: %s", static_cast<const char*>(r));
1573 char app_control[BUFSIZE];
1574 for (GList* tmp = ac->privileges; tmp; tmp = tmp->next) {
1575 char* privilege = reinterpret_cast<char*>(tmp->data);
1576 if (privilege == nullptr || !strlen(privilege))
1579 snprintf(app_control, sizeof(app_control), "%s|%s|%s",
1580 ac->operation ? (strlen(ac->operation) > 0 ?
1581 ac->operation : "NULL") : "NULL",
1582 ac->uri ? (strlen(ac->uri) > 0 ?
1583 ac->uri : "NULL") : "NULL",
1584 ac->mime ? (strlen(ac->mime) > 0 ?
1585 ac->mime : "NULL") : "NULL");
1590 if (!db.Exec(q,r)) {
1591 _LOGE("db.Exec() failed: %s", static_cast<const char*>(r));
1599 int InsertAppcontrolInfo(const tizen_base::Database& db, application_x* app) {
1600 if (app->appcontrol == nullptr)
1603 auto q = tizen_base::Database::Sql(
1604 "INSERT INTO package_app_app_control (app_id, app_control,"
1605 " visibility, app_control_id) "
1606 "VALUES (?, ?, ?, ?)");
1607 auto r = db.Prepare(q);
1609 _LOGE("db.Prepare() failed: %s", static_cast<const char*>(r));
1613 for (GList* tmp = app->appcontrol; tmp; tmp = tmp->next) {
1614 appcontrol_x* ac = reinterpret_cast<appcontrol_x*>(tmp->data);
1617 std::string op = ac->operation ? (strlen(ac->operation) > 0 ?
1618 ac->operation : "NULL") : "NULL";
1619 std::string uri = ac->uri ? (strlen(ac->uri) > 0 ?
1620 ac->uri : "NULL") : "NULL";
1621 std::string mime = ac->mime ? (strlen(ac->mime) > 0 ?
1622 ac->mime : "NULL") : "NULL";
1623 std::string app_control = std::move(op) + "|" + std::move(uri)
1624 + "|" + std::move(mime);
1627 .Bind(std::move(app_control))
1628 .Bind(ac->visibility)
1630 if (!db.Exec(q, r)) {
1631 _LOGE("db.Exec() failed");
1635 if (InsertAppcontrolPrivilegeInfo(db, app->appid, ac))
1642 const char *__get_bool(char *value, bool is_true) {
1643 if (value != NULL) {
1644 if (!strcmp(value, ""))
1645 return (is_true) ? "true" : "false";
1649 return (is_true) ? "true" : "false";
1652 const char *__find_effective_appid(GList *metadata_list) {
1653 constexpr const char EFFECTIVE_APPID_KEY[] =
1654 "http://tizen.org/metadata/effective-appid";
1659 for (tmp = metadata_list; tmp; tmp = tmp->next) {
1660 md = (metadata_x *)tmp->data;
1661 if (md == NULL || md->key == NULL)
1664 if (strcmp(md->key, EFFECTIVE_APPID_KEY) == 0) {
1673 int __convert_background_category(GList *category_list) {
1676 char *category_data;
1678 if (category_list == NULL)
1681 for (tmp = category_list; tmp; tmp = tmp->next) {
1682 category_data = (char *)tmp->data;
1683 if (category_data == NULL)
1685 if (!strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR))
1686 ret |= APP_BG_CATEGORY_MEDIA_VAL;
1687 else if (!strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR))
1688 ret |= APP_BG_CATEGORY_DOWNLOAD_VAL;
1689 else if (!strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR))
1690 ret |= APP_BG_CATEGORY_BGNETWORK_VAL;
1691 else if (!strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR))
1692 ret |= APP_BG_CATEGORY_LOCATION_VAL;
1693 else if (!strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR))
1694 ret |= APP_BG_CATEGORY_SENSOR_VAL;
1695 else if (!strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR))
1696 ret |= APP_BG_CATEGORY_IOTCOMM_VAL;
1697 else if (!strcmp(category_data, APP_BG_CATEGORY_SYSTEM))
1698 ret |= APP_BG_CATEGORY_SYSTEM_VAL;
1700 _LOGE("Unidentified category [%s]", category_data);
1706 int InsertPackageResInfoAllowedPackage(const tizen_base::Database& db,
1707 const char* pkgid, GList* rap_list) {
1708 if (rap_list == nullptr)
1711 auto q = tizen_base::Database::Sql(
1712 "INSERT INTO package_res_allowed_package (package,"
1713 " allowed_package, required_privilege) VALUES (?, ?, ?)");
1714 auto r = db.Prepare(q);
1716 _LOGE("db.Prepare() failed: %s", static_cast<const char*>(r));
1720 for (GList* tmp = rap_list; tmp; tmp = tmp->next) {
1721 res_allowed_package_x* rap =
1722 reinterpret_cast<res_allowed_package_x*>(tmp->data);
1726 if (!rap->required_privileges) {
1729 .Bind(rap->allowed_package)
1732 if (!db.Exec(q, r)) {
1733 _LOGE("db.Exec() failed");
1740 for (GList* priv_list = rap->required_privileges; priv_list;
1741 priv_list = priv_list->next) {
1744 .Bind(rap->allowed_package)
1745 .Bind(reinterpret_cast<char*>(priv_list->data));
1747 if (!db.Exec(q, r)) {
1748 _LOGE("db.Exec() failed");
1757 int InsertPackageResInfo(const tizen_base::Database& db, manifest_x* mfx) {
1758 if (mfx->res_type == nullptr || mfx->res_version == nullptr)
1761 auto q = tizen_base::Database::Sql(
1762 "INSERT INTO package_res_info (package, res_type,"
1763 " res_version) VALUES (?, ?, ?)")
1765 .Bind(mfx->res_type)
1766 .Bind(mfx->res_version);
1768 auto r = db.Exec(q);
1770 _LOGE("db.Exec() failed: %s", static_cast<const char*>(r));
1774 if (InsertPackageResInfoAllowedPackage(db, mfx->package,
1775 mfx->res_allowed_packages) < 0) {
1782 int InsertPackageMetadataInfo(const tizen_base::Database& db, manifest_x* mfx) {
1783 if (mfx->metadata == nullptr)
1786 auto q = tizen_base::Database::Sql(
1787 "INSERT INTO package_metadata (package,"
1788 " md_key, md_value) VALUES (?, ?, ?)");
1789 auto r = db.Prepare(q);
1791 _LOGE("db.Prepare() failed: %s", static_cast<const char*>(r));
1795 for (GList* tmp = mfx->metadata; tmp; tmp = tmp->next) {
1796 metadata_x* md = reinterpret_cast<metadata_x*>(tmp->data);
1804 if (!db.Exec(q, r)) {
1805 _LOGE("db.Exec() failed: %s", static_cast<const char*>(r));
1813 int InsertApplicationInfo(const tizen_base::Database& db, manifest_x *mfx) {
1814 auto q = tizen_base::Database::Sql(
1815 "INSERT INTO package_app_info (app_id, app_component,"
1816 " app_exec, app_nodisplay, app_type, app_onboot, app_multiple,"
1817 " app_autorestart, app_taskmanage, app_hwacceleration,"
1818 " app_screenreader, app_mainapp, app_recentimage,"
1819 " app_launchcondition, app_indicatordisplay, app_portraitimg,"
1820 " app_landscapeimg, app_guestmodevisibility,"
1821 " app_permissiontype, app_preload, app_submode,"
1822 " app_submode_mainid, app_installed_storage, app_process_pool,"
1823 " app_launch_mode, app_ui_gadget, app_support_mode,"
1824 " app_support_disable, component_type, package, app_tep_name,"
1825 " app_zip_mount_file, app_background_category,"
1826 " app_package_type, app_root_path, app_api_version,"
1827 " app_effective_appid, app_splash_screen_display,"
1828 " app_package_system, app_removable,"
1829 " app_package_installed_time, app_support_ambient,"
1830 " app_external_path, app_setup_appid, light_user_switch_mode) "
1832 " ?, LOWER(?), ?, LOWER(?), LOWER(?),"
1833 " LOWER(?), LOWER(?), ?,"
1837 " ?, LOWER(?), LOWER(?),"
1839 " COALESCE(?, 'single'), LOWER(?), ?,"
1840 " LOWER(?), ?, ?, ?,"
1844 " LOWER(?), LOWER(?),"
1847 auto r = db.Prepare(q);
1849 _LOGE("db.Prepare() failed: %s", static_cast<const char*>(r));
1853 for (GList* tmp = mfx->application; tmp; tmp = tmp->next) {
1854 application_x* app = reinterpret_cast<application_x*>(tmp->data);
1858 int bg_category = __convert_background_category(
1859 app->background_category);
1860 const char* effective_appid = __find_effective_appid(app->metadata);
1864 .Bind(app->component_type)
1866 .Bind(__get_bool(app->nodisplay, false))
1868 .Bind(__get_bool(app->onboot, false))
1869 .Bind(__get_bool(app->multiple, false))
1870 .Bind(__get_bool(app->autorestart, false))
1871 .Bind(__get_bool(app->taskmanage, false))
1872 .Bind(app->hwacceleration)
1873 .Bind(app->screenreader)
1874 .Bind(__get_bool(app->mainapp, false))
1875 .Bind(app->recentimage)
1876 .Bind(app->launchcondition)
1877 .Bind(__get_bool(app->indicatordisplay, true))
1878 .Bind(app->portraitimg)
1879 .Bind(app->landscapeimg)
1880 .Bind(__get_bool(app->guestmode_visibility, true))
1881 .Bind(app->permission_type)
1882 .Bind(__get_bool(mfx->preload, false))
1883 .Bind(__get_bool(app->submode, false))
1884 .Bind(app->submode_mainid)
1885 .Bind(mfx->installed_storage)
1886 .Bind(__get_bool(app->process_pool, false))
1887 .Bind(app->launch_mode)
1888 .Bind(__get_bool(app->ui_gadget, false))
1889 .Bind(app->support_mode ? app->support_mode : "0")
1890 .Bind(__get_bool(mfx->support_disable, false))
1891 .Bind(app->component_type)
1893 .Bind(mfx->tep_name)
1894 .Bind(mfx->zip_mount_file)
1896 .Bind(mfx->type ? mfx->type : "tpk")
1897 .Bind(mfx->root_path)
1898 .Bind(app->api_version)
1899 .Bind(effective_appid)
1900 .Bind(__get_bool(app->splash_screen_display, true))
1901 .Bind(__get_bool(mfx->system, false))
1902 .Bind(__get_bool(mfx->removable, false))
1903 .Bind(mfx->installed_time)
1904 .Bind(__get_bool(app->support_ambient, false))
1905 .Bind(mfx->external_path)
1906 .Bind(app->setup_appid)
1907 .Bind(mfx->light_user_switch_mode);
1909 if (!db.Exec(q, r)) {
1910 _LOGE("db.Exec() failed");
1914 if (InsertAppcontrolInfo(db, app))
1916 if (InsertCategoryInfo(db, app))
1918 if (InsertMetadataInfo(db, app))
1920 if (InsertDatacontrolInfo(db, app))
1922 GList* ss_list = __find_splashscreens(app->splashscreens);
1923 if (InsertSplashscreenInfo(db, app, ss_list)) {
1924 g_list_free(ss_list);
1927 g_list_free(ss_list);
1928 if (InsertAppLocalizedInfo(db, app))
1930 if (InsertAppResControl(db, app))
1937 int InsertPackageUpdateInfo(const tizen_base::Database& db, manifest_x *mfx) {
1938 auto q = tizen_base::Database::Sql(
1939 "INSERT INTO package_update_info (package, update_version) "
1942 .Bind(mfx->version);
1944 auto r = db.Exec(q);
1946 _LOGE("db.Exec() failed : %s", static_cast<const char*>(r));
1953 int InsertPackageLocalizedInfo(const tizen_base::Database& db,
1955 auto q = tizen_base::Database::Sql(
1956 "INSERT INTO package_localized_info (package, package_locale,"
1957 " package_label, package_icon, package_description,"
1958 " package_license, package_author) "
1959 "VALUES (?, ?, ?, ?, ?, ?, ?)");
1960 auto r = db.Prepare(q);
1962 _LOGE("db.Prepare() failed: %s", static_cast<const char*>(r));
1966 GList* locales = __create_locale_list(mfx->label, mfx->license, mfx->icon,
1967 mfx->description, mfx->author);
1968 for (GList* tmp = locales; tmp; tmp = tmp->next) {
1969 const char* locale = (const char *)tmp->data;
1970 char* label = nullptr;
1971 char* icon = nullptr;
1972 char* description = nullptr;
1973 char* license = nullptr;
1974 char* author = nullptr;
1975 __extract_data(locale, mfx->label, mfx->license, mfx->icon,
1976 mfx->description, mfx->author,
1977 &label, &license, &icon, &description, &author);
1978 if (!label && !license && !icon && !description && !author)
1990 if (!db.Exec(q, r)) {
1991 _LOGE("db.Exec() failed : %s", static_cast<const char*>(r));
1992 g_list_free(locales);
1997 g_list_free(locales);
2002 int DoInsertPackageInfo(const tizen_base::Database& db, manifest_x* mfx) {
2003 const char* author_name = nullptr;
2004 const char* author_email = nullptr;
2005 const char* author_href = nullptr;
2007 if (mfx->author && mfx->author->data) {
2008 author_name = ((author_x *)mfx->author->data)->text;
2009 author_email = ((author_x *)mfx->author->data)->email;
2010 author_href = ((author_x *)mfx->author->data)->href;
2013 auto q = tizen_base::Database::Sql(
2014 "INSERT INTO package_info (package, package_type,"
2015 " package_version, package_api_version, package_tep_name,"
2016 " package_zip_mount_file, install_location, package_size,"
2017 " package_removable, package_preload, package_readonly,"
2018 " package_update, package_appsetting, package_nodisplay,"
2019 " package_system, author_name, author_email, author_href,"
2020 " installed_time, installed_storage, storeclient_id,"
2021 " mainapp_id, package_url, root_path, external_path,"
2022 " csc_path, package_support_mode, package_support_disable,"
2023 " light_user_switch_mode)"
2027 " LOWER(?), LOWER(?), LOWER(?),"
2028 " LOWER(?), LOWER(?), LOWER(?),"
2029 " LOWER(?), ?, ?, ?,"
2032 " ?, ?, LOWER(?), ?)")
2036 .Bind(mfx->api_version)
2037 .Bind(mfx->tep_name)
2038 .Bind(mfx->zip_mount_file)
2039 .Bind(mfx->installlocation)
2040 .Bind(mfx->package_size)
2041 .Bind(__get_bool(mfx->removable, true))
2042 .Bind(__get_bool(mfx->preload, false))
2043 .Bind(__get_bool(mfx->readonly, false))
2044 .Bind(__get_bool(mfx->update, false))
2045 .Bind(__get_bool(mfx->appsetting, false))
2046 .Bind(__get_bool(mfx->nodisplay_setting, false))
2047 .Bind(__get_bool(mfx->system, false))
2051 .Bind(mfx->installed_time)
2052 .Bind(mfx->installed_storage)
2053 .Bind(mfx->storeclient_id)
2054 .Bind(mfx->mainapp_id)
2055 .Bind(mfx->package_url)
2056 .Bind(mfx->root_path)
2057 .Bind(mfx->external_path)
2058 .Bind(mfx->csc_path)
2059 .Bind(mfx->support_mode ? mfx->support_mode : "0")
2060 .Bind(__get_bool(mfx->support_disable, false))
2061 .Bind(mfx->light_user_switch_mode);
2063 auto r = db.Exec(q);
2065 _LOGE("db.Exec() failed: %s", static_cast<const char*>(r));
2069 if (InsertPackageUpdateInfo(db, mfx))
2071 if (InsertPackageLocalizedInfo(db, mfx))
2073 if (InsertApplicationInfo(db, mfx))
2075 if (InsertPackagePrivilegeInfo(db, mfx))
2077 if (InsertPackageAppdefinedPrivilegeInfo(db, mfx))
2079 if (InsertPackageDependencyInfo(db, mfx))
2081 if (InsertPackageResInfo(db, mfx))
2083 if (InsertPackageMetadataInfo(db, mfx))
2089 int DoDeletePackageInfo(const tizen_base::Database& db, const char* pkgid) {
2090 auto q = tizen_base::Database::Sql(
2091 "DELETE FROM package_info WHERE package=?")
2093 auto r = db.Exec(q);
2095 _LOGE("db.Exec() failed: %s", static_cast<const char*>(r));
2105 namespace pkgmgr_server::internal {
2107 int DeletePkgInfo(const tizen_base::Database& db, const char* package,
2109 if (!static_cast<bool>(db) || package == nullptr) {
2110 _LOGE("invalid parameter");
2111 return PM_PARSER_R_EINVAL;
2114 auto guard = db.CreateTransactionGuard();
2115 if (DoDeletePackageInfo(db, package) != 0)
2119 return PM_PARSER_R_OK;
2122 int UpdatePkgInfo(const tizen_base::Database& db, manifest_x* mfx, uid_t uid) {
2123 if (!static_cast<bool>(db) || mfx == nullptr || mfx->package == nullptr) {
2124 _LOGE("invalid parameter");
2125 return PM_PARSER_R_EINVAL;
2128 auto guard = db.CreateTransactionGuard();
2129 if (DoDeletePackageInfo(db, mfx->package) != 0)
2131 if (DoInsertPackageInfo(db, mfx) != 0)
2135 return PM_PARSER_R_OK;
2138 int InsertPkgInfo(const tizen_base::Database& db, manifest_x* mfx, uid_t uid) {
2139 if (!static_cast<bool>(db) || mfx == nullptr) {
2140 _LOGE("invalid parameter");
2141 return PM_PARSER_R_EINVAL;
2144 auto guard = db.CreateTransactionGuard();
2145 if (DoInsertPackageInfo(db, mfx) != 0)
2149 return PM_PARSER_R_OK;
2152 bool CheckPackageStorageStatus(pkgmgrinfo_filter_x* tmp_filter) {
2153 return ::CheckPackageStorageStatus(tmp_filter);
2156 int ExecuteWriteQueries(const tizen_base::Database& db,
2157 const std::vector<std::string>& queries,
2158 const std::vector<std::vector<std::optional<std::string>>>& args_list) {
2159 if (!static_cast<bool>(db) || queries.empty()) {
2160 _LOGE("Invalid parameter");
2161 return PMINFO_R_EINVAL;
2164 auto guard = db.CreateTransactionGuard();
2167 for (const auto& i : queries) {
2168 if (DoExecuteQuery(db, i, args_list[idx++]) != 0)
2176 int GetQueryResult(const tizen_base::Database& db,
2177 const std::string& query,
2178 const std::vector<std::optional<std::string>>& param,
2179 std::vector<std::vector<std::optional<std::string>>>& result) {
2180 if (!static_cast<bool>(db) || query.empty()) {
2181 LOGE("Invalid parameter");
2182 return PMINFO_R_EINVAL;
2185 auto q = tizen_base::Database::Sql(query);
2186 for (auto& p : param) {
2190 q.Bind(std::nullopt);
2193 auto r = db.Exec(q);
2195 return PMINFO_R_ERROR;
2197 int col_cnt = r.GetColumnCount();
2198 for (const auto& row : r) {
2199 std::vector<std::optional<std::string>> rec;
2200 for (int i = 0; i < col_cnt; i++)
2201 rec.push_back(row.GetString(i));
2203 result.push_back(std::move(rec));
2209 int GetPkgInfo(const tizen_base::Database& db,
2210 pkgmgrinfo_pkginfo_filter_h filter, uid_t uid,
2211 const std::string& locale,
2212 std::map<std::string, std::shared_ptr<package_x>>& pkginfo_list) {
2213 if (!static_cast<bool>(db) || filter == nullptr) {
2214 LOGE("Invalid argument");
2215 return PMINFO_R_EINVAL;
2218 int ret = DoGetPkgInfo(db, uid, locale, (pkgmgrinfo_filter_x*)filter,
2219 PMINFO_PKGINFO_GET_ALL, pkginfo_list);
2223 int GetDependsOn(const tizen_base::Database& db, const std::string& pkgid,
2224 std::vector<dependency_x*>& dep_list) {
2225 if (!static_cast<bool>(db) || pkgid.empty()) {
2226 LOGE("Invalid parameter");
2227 return PMINFO_R_EINVAL;
2230 std::queue<std::string> queue;
2231 std::set<std::string> dup_checker;
2234 while (!queue.empty()) {
2235 auto item = queue.front();
2237 int ret = DoGetDependsOn(db, item, queue, dup_checker, dep_list);
2238 if (ret != PMINFO_R_OK) {
2239 LOGE("failed to get pkgs depends on %s", pkgid.c_str());
2240 for (auto i : dep_list)
2241 __free_depends_on(i);
2242 return PMINFO_R_ERROR;
2249 } // namespace pkgmgr_server::internal