return PMINFO_R_OK;
}
+
+static int __convert_update_type(const char *type, pkgmgrinfo_updateinfo_update_type *convert_type)
+{
+ if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_NONE,
+ strlen(PMINFO_UPDATEINFO_TYPE_NONE)) == 0)
+ *convert_type = PMINFO_UPDATEINFO_NONE;
+ else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_FORCE,
+ strlen(PMINFO_UPDATEINFO_TYPE_FORCE)) == 0)
+ *convert_type = PMINFO_UPDATEINFO_FORCE;
+ else if (strncasecmp(type, PMINFO_UPDATEINFO_TYPE_OPTIONAL,
+ strlen(PMINFO_UPDATEINFO_TYPE_OPTIONAL)) == 0)
+ *convert_type = PMINFO_UPDATEINFO_OPTIONAL;
+ else
+ return -1;
+ return 0;
+}
+
+static void __free_update_info(gpointer data)
+{
+ updateinfo_x *update_info = (updateinfo_x *)data;
+ if (update_info == NULL)
+ return;
+
+ if (update_info->pkgid)
+ free((void *)update_info->pkgid);
+ if (update_info->version)
+ free((void *)update_info->version);
+ free((void *)update_info);
+
+}
+
+extern "C" EXPORT_API int _get_pkg_updateinfo(const char *pkgid,
+ GSList **update_info_list, uid_t uid)
+{
+ char *query = nullptr;
+ int ret;
+
+ if (pkgid == NULL)
+ query = sqlite3_mprintf(
+ "SELECT package, update_version, update_type "
+ "FROM package_update_info");
+ else
+ query = sqlite3_mprintf(
+ "SELECT package, update_version, update_type "
+ "FROM package_update_info WHERE package=%Q",
+ pkgid);
+ if (query == NULL) {
+ LOG(ERROR) << "Out of memory";
+ return PMINFO_R_ERROR;
+ }
+
+ std::shared_ptr<pkgmgr_common::parcel::AbstractParcelable> parcelable(
+ new pkgmgr_common::parcel::QueryParcelable(uid, std::string(query)));
+ sqlite3_free(query);
+
+ pkgmgr_client::PkgInfoClient client(parcelable, uid,
+ pkgmgr_common::ReqType::QUERY);
+ if (!client.SendRequest()) {
+ return PMINFO_R_ERROR;
+ }
+
+ std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> return_parcel(
+ std::static_pointer_cast<pkgmgr_common::parcel::ResultParcelable>(
+ client.GetResultParcel()));
+ if (return_parcel->GetCol() != 3) {
+ LOG(ERROR) << "Invalid result";
+ return PMINFO_R_ERROR;
+ }
+
+ auto result_list = return_parcel->GetResult();
+ if (result_list.size() == 0)
+ return PMINFO_R_ENOENT;
+
+ for (auto result : result_list) {
+ if (result.size() != 3) {
+ LOG(ERROR) << "Invalid result";
+ g_slist_free_full(*update_info_list, __free_update_info);
+ return PMINFO_R_ERROR;
+ }
+ updateinfo_x *update_info = reinterpret_cast<updateinfo_x *>(calloc(1, sizeof(updateinfo_x)));
+ if (update_info == NULL) {
+ LOG(ERROR) << "Out of memory";
+ return PMINFO_R_ERROR;
+ }
+ update_info->pkgid = strdup(result[0].c_str());
+ update_info->version = strdup(result[1].c_str());
+ pkgmgrinfo_updateinfo_update_type convert_type;
+ ret = __convert_update_type(result[2].c_str(), &convert_type);
+ if (ret != 0) {
+ __free_update_info(update_info);
+ g_slist_free_full(*update_info_list, __free_update_info);
+ return PMINFO_R_ERROR;
+ }
+ update_info->type = static_cast<int>(convert_type);
+ *update_info_list = g_slist_prepend(*update_info_list,
+ update_info);
+ }
+
+ return PMINFO_R_OK;
+}
const char *pkgid, const char *plugin_type,
const char *plugin_name, GList **list);
+int _get_pkg_updateinfo(const char *pkgid,
+ GSList **update_info_list, uid_t uid);
+
#ifdef __cplusplus
}
#endif
#include "pkgmgrinfo_private.h"
#include "pkgmgrinfo_debug.h"
#include "pkgmgr-info.h"
+#include "manager/pkginfo_manager.h"
static void __free_update_info(gpointer data)
{
return PMINFO_R_OK;
}
-static int _get_pkg_updateinfo_from_db(const char *pkgid,
- GSList **update_info_list, uid_t uid)
-{
- char *dbpath;
- char *type;
- char query[MAX_QUERY_LEN] = { '\0' };
- int ret;
- int idx;
- sqlite3 *db;
- sqlite3_stmt *stmt;
- updateinfo_x *update_info = NULL;
- pkgmgrinfo_updateinfo_update_type convert_type;
-
- dbpath = getUserPkgParserDBPathUID(uid);
- if (dbpath == NULL)
- return PMINFO_R_ERROR;
-
- ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
- if (ret != SQLITE_OK) {
- _LOGD("failed to open db: %d", ret);
- free(dbpath);
- return -1;
- }
-
- if (pkgid == NULL)
- sqlite3_snprintf(MAX_QUERY_LEN, query,
- "SELECT package, update_version, update_type " \
- "FROM package_update_info");
- else
- sqlite3_snprintf(MAX_QUERY_LEN, query,
- "SELECT package, update_version, update_type " \
- "FROM package_update_info WHERE package=%Q",
- pkgid);
-
- ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
- if (ret != SQLITE_OK) {
- _LOGE("Don't execute query = %s error message = %s\n", query,
- sqlite3_errmsg(db));
- sqlite3_close_v2(db);
- free(dbpath);
- return -1;
- }
-
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- type = NULL;
- update_info = calloc(1, sizeof(updateinfo_x));
- if (update_info == NULL) {
- _LOGE("Out of memory");
- free(dbpath);
- sqlite3_finalize(stmt);
- sqlite3_close_v2(db);
- return -1;
- }
- idx = 0;
- _save_column_str(stmt, idx++, &update_info->pkgid);
- _save_column_str(stmt, idx++, &update_info->version);
- _save_column_str(stmt, idx, &type);
- ret = __convert_update_type(type, &convert_type);
- free(type);
- if (ret != 0) {
- __free_update_info(update_info);
- free(dbpath);
- sqlite3_finalize(stmt);
- sqlite3_close_v2(db);
- return -1;
- }
- update_info->type = convert_type;
- *update_info_list = g_slist_prepend(*update_info_list,
- update_info);
- }
-
- free(dbpath);
- sqlite3_finalize(stmt);
- sqlite3_close_v2(db);
-
- return 0;
-}
-
API int pkgmgrinfo_updateinfo_get_usr_updateinfo(const char *pkgid,
pkgmgrinfo_updateinfo_h *update_handle, uid_t uid)
{
}
pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
- ret = _get_pkg_updateinfo_from_db(pkgid, &info_list,
+ ret = _get_pkg_updateinfo(pkgid, &info_list,
(is_global_pkg) ? GLOBAL_USER : uid);
if (ret != PMINFO_R_OK) {
if (callback == NULL)
return PMINFO_R_EINVAL;
- ret = _get_pkg_updateinfo_from_db(NULL, &info_list, uid);
+ ret = _get_pkg_updateinfo(NULL, &info_list, uid);
if (ret != 0) {
_LOGE("Failed to get pkg update info for user[%d]", (int)uid);
g_slist_free_full(info_list, __free_update_info);
return PMINFO_R_ERROR;
}
- ret = _get_pkg_updateinfo_from_db(NULL, &info_list, GLOBAL_USER);
+ ret = _get_pkg_updateinfo(NULL, &info_list, GLOBAL_USER);
if (ret != 0) {
_LOGE("Failed to get pkg update info for user[%d]",
(int)GLOBAL_USER);