From f62035d2f7b86ca6ac9916e4ca58c52e5c9318ba Mon Sep 17 00:00:00 2001 From: ilho kim Date: Thu, 9 Mar 2023 12:42:07 +0900 Subject: [PATCH] Add debugging log for disabled pkg/app for db When using a filter for package_disable or app_disable do not filter using a query, get a values from db and then apply filter and print log when package or application is disabled Change-Id: I3842c346e6bdebee2a7703897ab91cd323d33a45 Signed-off-by: ilho kim --- src/pkgmgrinfo_private.c | 15 ++---- src/server/appinfo_internal.cc | 103 ++++++++++++++++++++++++++++++++++++++++- src/server/pkginfo_internal.cc | 40 ++++++++++++++-- 3 files changed, 141 insertions(+), 17 deletions(-) diff --git a/src/pkgmgrinfo_private.c b/src/pkgmgrinfo_private.c index e81cf51..e6d023d 100644 --- a/src/pkgmgrinfo_private.c +++ b/src/pkgmgrinfo_private.c @@ -313,8 +313,7 @@ API int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList snprintf(buf, sizeof(buf), "pi.package_support_disable=? COLLATE NOCASE"); break; case E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE: - snprintf(buf, sizeof(buf), "pi.package_disable=? COLLATE NOCASE"); - break; + return 0; case E_PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM: snprintf(buf, sizeof(buf), "pi.package_system=? COLLATE NOCASE"); break; @@ -417,21 +416,13 @@ API int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList snprintf(buf, sizeof(buf), "ai.app_ui_gadget=? COLLATE NOCASE"); break; case E_PMINFO_APPINFO_PROP_APP_DISABLE: - if (strcasecmp(node->value, "true") == 0) - snprintf(buf, MAX_QUERY_LEN, "(ai.app_disable=? COLLATE NOCASE " \ - "OR ui.is_disabled='true' COLLATE NOCASE)"); - else - snprintf(buf, MAX_QUERY_LEN, "(ai.app_disable=? COLLATE NOCASE " \ - "AND (ui.is_disabled='false' COLLATE NOCASE " \ - "OR ui.is_disabled IS NULL))"); + return 0; break; case E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE: snprintf(buf, MAX_QUERY_LEN, "ai.app_support_disable=? COLLATE NOCASE"); break; case E_PMINFO_APPINFO_PROP_PKG_DISABLE: - snprintf(buf, MAX_QUERY_LEN, - "ai.package IN (SELECT package FROM " \ - "package_info WHERE package_disable=?)"); + return 0; break; case E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE: snprintf(buf, sizeof(buf), "ai.app_support_mode=?"); diff --git a/src/server/appinfo_internal.cc b/src/server/appinfo_internal.cc index 7469b75..e6babbc 100644 --- a/src/server/appinfo_internal.cc +++ b/src/server/appinfo_internal.cc @@ -385,12 +385,89 @@ bool __check_app_storage_status(pkgmgrinfo_filter_x* tmp_filter) { return true; } +enum class PackageDisableFilterStatus { + None, + True, + False +}; + +PackageDisableFilterStatus GetPackageDisableFilterStatus( + const pkgmgrinfo_filter_x* filter) { + GSList* tmp_list = nullptr; + pkgmgrinfo_node_x* tmp_node = nullptr; + int property = -1; + + property = _pminfo_appinfo_convert_to_prop_bool( + PMINFO_APPINFO_PROP_APP_DISABLE); + for (tmp_list = filter->list; tmp_list != nullptr; + tmp_list = g_slist_next(tmp_list)) { + tmp_node = reinterpret_cast(tmp_list->data); + if (property != tmp_node->prop) + continue; + + return strcasecmp(tmp_node->value, "true") == 0 ? + PackageDisableFilterStatus::True : PackageDisableFilterStatus::False; + } + + return PackageDisableFilterStatus::None; +} + +bool CheckPkgDisableFilter(PackageDisableFilterStatus expected, + const char* package_disable, application_x* app_info) { + if (!package_disable) + return true; + + PackageDisableFilterStatus result = strcasecmp(package_disable, "true") == 0 ? + PackageDisableFilterStatus::True : PackageDisableFilterStatus::False; + + if (expected == result) + return true; + + if (result == PackageDisableFilterStatus::True) + LOGW("The package [%s] to which the application [%s] belongs is disabled", + app_info->package, app_info->appid); + + return false; +} + +bool CheckAppDisableFilter(const pkgmgrinfo_filter_x* filter, + const application_x* app_info) { + GSList* tmp_list = nullptr; + pkgmgrinfo_node_x* tmp_node = nullptr; + int property = -1; + + property = _pminfo_appinfo_convert_to_prop_bool( + PMINFO_APPINFO_PROP_APP_DISABLE); + for (tmp_list = filter->list; tmp_list != nullptr; + tmp_list = g_slist_next(tmp_list)) { + tmp_node = reinterpret_cast(tmp_list->data); + if (property != tmp_node->prop) + continue; + + if (strcasecmp(tmp_node->value, app_info->is_disabled) == 0) + return true; + + if (strcasecmp(app_info->is_disabled, "true") == 0) + LOGW("The application [%s] is disabled", app_info->appid); + + return false; + } + return true; +} + int DoGetAppInfo(const tizen_base::Database& db, uid_t db_uid, uid_t uid, const char* locale, pkgmgrinfo_filter_x* filter, int flag, std::vector>& applications) { static const char query_raw[] = "SELECT DISTINCT ai.app_id, ai.app_installed_storage, " "ai.app_external_path"; + static const char query_app_disable[] = ", " + "CASE " + "WHEN ai.app_disable='true' COLLATE NOCASE OR " + "ui.is_disabled='true' COLLATE NOCASE " + "THEN 'true' " + "ELSE 'false' " + "END AS app_disable"; static const char query_basic[] = ", ai.app_component, ai.app_exec, " "ai.app_nodisplay, ai.app_type, ai.app_onboot, " @@ -404,7 +481,7 @@ int DoGetAppInfo(const tizen_base::Database& db, uid_t db_uid, uid_t uid, "ai.app_support_disable, ai.app_process_pool, " "ai.app_background_category, ai.app_package_type, " "ai.app_root_path, ai.app_api_version, ai.app_effective_appid, " - "ai.app_disable, ai.app_splash_screen_display, ai.app_tep_name, " + "ai.app_splash_screen_display, ai.app_tep_name, " "ai.app_zip_mount_file, ai.component_type, ai.package, " "ai.app_package_system, ai.app_removable, " "ai.app_package_installed_time, ai.app_support_mode, " @@ -423,6 +500,8 @@ int DoGetAppInfo(const tizen_base::Database& db, uid_t db_uid, uid_t uid, "AND app_locale=?), " "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id " "AND app_locale='No Locale'))"; + static const char query_package_disable[] = + ", (SELECT package_disable FROM package_info WHERE ai.package=package)"; static const char query_from_clause[] = " FROM package_app_info as ai"; static const char query_uid_info_clause[] = " LEFT OUTER JOIN package_app_info_for_uid AS ui " @@ -433,6 +512,9 @@ int DoGetAppInfo(const tizen_base::Database& db, uid_t db_uid, uid_t uid, bool is_check_storage = true; const uid_t global_user_uid = GLOBAL_USER; std::string query = query_raw; + auto pkg_disable_filter_statue = GetPackageDisableFilterStatus(filter); + + query += query_app_disable; if (flag & PMINFO_APPINFO_GET_BASICINFO) { query += query_basic; @@ -449,6 +531,9 @@ int DoGetAppInfo(const tizen_base::Database& db, uid_t db_uid, uid_t uid, bind_params.push_back(locale); } + if (pkg_disable_filter_statue != PackageDisableFilterStatus::None) + query += query_package_disable; + bind_params.push_back(std::to_string(uid)); is_check_storage = __check_app_storage_status(filter); @@ -495,6 +580,7 @@ int DoGetAppInfo(const tizen_base::Database& db, uid_t db_uid, uid_t uid, info->appid = GetCString(idx++, rec); info->installed_storage = GetCString(idx++, rec); info->external_path = GetCString(idx++, rec); + info->is_disabled = GetCString(idx++, rec); if (flag & PMINFO_APPINFO_GET_BASICINFO) { info->component = GetCString(idx++, rec); info->exec = GetCString(idx++, rec); @@ -526,7 +612,6 @@ int DoGetAppInfo(const tizen_base::Database& db, uid_t db_uid, uid_t uid, info->root_path = GetCString(idx++, rec); info->api_version = GetCString(idx++, rec); info->effective_appid = GetCString(idx++, rec); - info->is_disabled = GetCString(idx++, rec); info->splash_screen_display = GetCString(idx++, rec); info->tep_name = GetCString(idx++, rec); info->zip_mount_file = GetCString(idx++, rec); @@ -589,6 +674,12 @@ int DoGetAppInfo(const tizen_base::Database& db, uid_t db_uid, uid_t uid, } } + if (pkg_disable_filter_statue != PackageDisableFilterStatus::None) { + tmp_record = GetCString(idx++, rec); + if (!CheckPkgDisableFilter(pkg_disable_filter_statue, tmp_record, info)) + continue; + } + if (flag & PMINFO_APPINFO_GET_CATEGORY) { if (GetCategory(db, info->appid, &info->category)) return PMINFO_R_ERROR; @@ -620,6 +711,14 @@ int DoGetAppInfo(const tizen_base::Database& db, uid_t db_uid, uid_t uid, continue; } + if (!CheckAppDisableFilter(filter, info)) + continue; + + if (!(flag & PMINFO_APPINFO_GET_BASICINFO) && info->is_disabled) { + free(info->is_disabled); + info->is_disabled = nullptr; + } + applications.push_back(std::move(info_auto)); } diff --git a/src/server/pkginfo_internal.cc b/src/server/pkginfo_internal.cc index f2e7c39..3b79f5c 100644 --- a/src/server/pkginfo_internal.cc +++ b/src/server/pkginfo_internal.cc @@ -413,11 +413,37 @@ bool CheckPackageStorageStatus(pkgmgrinfo_filter_x* tmp_filter) { return true; } +bool CheckPackageDisableFilter(const pkgmgrinfo_filter_x* filter, + const package_x* pkg_info) { + GSList* tmp_list = nullptr; + pkgmgrinfo_node_x* tmp_node = nullptr; + int property = -1; + + property = _pminfo_pkginfo_convert_to_prop_bool( + PMINFO_PKGINFO_PROP_PACKAGE_DISABLE); + for (tmp_list = filter->list; tmp_list != nullptr; + tmp_list = g_slist_next(tmp_list)) { + tmp_node = reinterpret_cast(tmp_list->data); + if (property != tmp_node->prop) + continue; + + if (strcasecmp(tmp_node->value, pkg_info->is_disabled) == 0) + return true; + + if (strcasecmp(pkg_info->is_disabled, "true") == 0) + LOGW("The package [%s] is disabled", pkg_info->package); + + return false; + } + return true; +} + int DoGetPkgInfo(const tizen_base::Database& db, uid_t uid, const std::string& locale, pkgmgrinfo_filter_x* filter, int flag, std::map>& packages) { static const char query_raw[] = - "SELECT DISTINCT pi.package, pi.installed_storage, pi.external_path"; + "SELECT DISTINCT pi.package, pi.installed_storage, pi.external_path, " + "pi.package_disable"; static const char query_basic[] = ", pi.package_version, pi.install_location, " "pi.package_removable, pi.package_preload, pi.package_readonly, " @@ -426,7 +452,7 @@ int DoGetPkgInfo(const tizen_base::Database& db, uid_t uid, "pi.storeclient_id, pi.mainapp_id, pi.package_url, pi.root_path, " "pi.csc_path, pi.package_nodisplay, pi.package_api_version, " "pi.package_support_disable, pi.package_tep_name, " - "pi.package_zip_mount_file, pi.package_support_mode, pi.package_disable, " + "pi.package_zip_mount_file, pi.package_support_mode, " "pi.light_user_switch_mode"; static const char query_author[] = ", pi.author_name, pi.author_email, pi.author_href"; @@ -525,6 +551,7 @@ int DoGetPkgInfo(const tizen_base::Database& db, uid_t uid, info->package = GetCString(idx++, rec); info->installed_storage = GetCString(idx++, rec); info->external_path = GetCString(idx++, rec); + info->is_disabled = GetCString(idx++, rec); if (flag & PMINFO_APPINFO_GET_BASICINFO) { info->version = GetCString(idx++, rec); info->installlocation = GetCString(idx++, rec); @@ -548,7 +575,6 @@ int DoGetPkgInfo(const tizen_base::Database& db, uid_t uid, info->tep_name = GetCString(idx++, rec); info->zip_mount_file = GetCString(idx++, rec); info->support_mode = GetCString(idx++, rec); - info->is_disabled = GetCString(idx++, rec); info->light_user_switch_mode = GetCString(idx++, rec); } @@ -626,6 +652,14 @@ int DoGetPkgInfo(const tizen_base::Database& db, uid_t uid, PMINFO_R_OK) continue; + if (!CheckPackageDisableFilter(filter, info)) + continue; + + if (!(flag & PMINFO_APPINFO_GET_BASICINFO) && info->is_disabled) { + free(info->is_disabled); + info->is_disabled = nullptr; + } + packages[info->package] = std::move(pkg); } -- 2.7.4