#include <string.h>
#include <stdio.h>
#include <ctype.h>
+#include <dlfcn.h>
#include <vconf.h>
#include <sqlite3.h>
#include <glib.h>
+#include <unzip.h>
#include "pkgmgr-info.h"
#include "pkgmgrinfo_debug.h"
#include "pkgmgrinfo_private.h"
#include "pkgmgr_parser.h"
+static GHashTable *plugin_set_list;
+
struct _pkginfo_str_map_t {
pkgmgrinfo_pkginfo_filter_prop_str prop;
const char *property;
{E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING, PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING},
{E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING, PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING},
{E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE},
- {E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE}
+ {E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE},
+ {E_PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE},
+ {E_PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM, PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM}
};
struct _appinfo_str_map_t {
{E_PMINFO_APPINFO_PROP_APP_CATEGORY, PMINFO_APPINFO_PROP_APP_CATEGORY},
{E_PMINFO_APPINFO_PROP_APP_HWACCELERATION, PMINFO_APPINFO_PROP_APP_HWACCELERATION},
{E_PMINFO_APPINFO_PROP_APP_SCREENREADER, PMINFO_APPINFO_PROP_APP_SCREENREADER},
- {E_PMINFO_APPINFO_PROP_APP_METADATA_KEY, PMINFO_APPINFO_PROP_APP_METADATA_KEY},
- {E_PMINFO_APPINFO_PROP_APP_METADATA_VALUE, PMINFO_APPINFO_PROP_APP_METADATA_VALUE},
{E_PMINFO_APPINFO_PROP_APP_PACKAGE, PMINFO_APPINFO_PROP_APP_PACKAGE},
- {E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE, PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE}
+ {E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE, PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE},
+ {E_PMINFO_APPINFO_PROP_PRIVILEGE, PMINFO_APPINFO_PROP_PRIVILEGE}
};
struct _appinfo_int_map_t {
};
static struct _appinfo_int_map_t appinfo_int_prop_map[] = {
- {E_PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER, PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER}
+ {E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE, PMINFO_APPINFO_PROP_APP_SUPPORT_MODE}
};
struct _appinfo_bool_map_t {
{E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION, PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION},
{E_PMINFO_APPINFO_PROP_APP_UI_GADGET, PMINFO_APPINFO_PROP_APP_UI_GADGET},
{E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE, PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE},
- {E_PMINFO_APPINFO_PROP_APP_DISABLE, PMINFO_APPINFO_PROP_APP_DISABLE}
+ {E_PMINFO_APPINFO_PROP_APP_DISABLE, PMINFO_APPINFO_PROP_APP_DISABLE},
+ {E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, PMINFO_APPINFO_PROP_APP_CHECK_STORAGE},
+ {E_PMINFO_APPINFO_PROP_PKG_DISABLE, PMINFO_APPINFO_PROP_PKG_DISABLE}
};
inline pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(const char *property)
return prop;
}
-int __get_filter_condition(gpointer data, char **condition, GList **params)
+int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **params)
{
- pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
+ pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data;
char buf[MAX_QUERY_LEN] = {'\0'};
int flag = 0;
+ char *value;
char *ptr = NULL;
char *saveptr = NULL;
case E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE:
snprintf(buf, sizeof(buf), "pi.package_disable=? COLLATE NOCASE");
break;
+ case E_PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM:
+ snprintf(buf, sizeof(buf), "pi.package_system=? COLLATE NOCASE");
+ break;
case E_PMINFO_APPINFO_PROP_APP_ID:
snprintf(buf, sizeof(buf), "ai.app_id=?");
break;
case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
snprintf(buf, sizeof(buf), "package_app_app_category.category IN (");
- ptr = strtok_r(node->value, ",", &saveptr);
- if (ptr == NULL)
+ value = strdup(node->value);
+ if (value == NULL) {
+ _LOGE("out of memeory");
+ return 0;
+ }
+ ptr = strtok_r(value, ",", &saveptr);
+ if (ptr == NULL) {
+ free(value);
return 0;
- strncat(buf, "?", MAX_QUERY_LEN - 2);
+ }
+ strncat(buf, "?", sizeof(buf) - strlen(buf) - 1);
*params = g_list_append(*params, strdup(ptr));
while ((ptr = strtok_r(NULL, ",", &saveptr))) {
- strncat(buf, ", ?", MAX_QUERY_LEN - strlen(", ?") - 1);
+ strncat(buf, ", ?", sizeof(buf) - strlen(buf) - 1);
*params = g_list_append(*params, strdup(ptr));
}
- strncat(buf, ")", MAX_QUERY_LEN - 2);
+ strncat(buf, ")", sizeof(buf) - strlen(buf) - 1);
*condition = strdup(buf);
flag = E_PMINFO_APPINFO_JOIN_CATEGORY;
+ free(value);
return flag;
case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
snprintf(buf, sizeof(buf), "ai.package=?");
break;
case E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE:
- snprintf(buf, sizeof(buf), "ai.installed_storage=?");
+ snprintf(buf, sizeof(buf), "ai.app_installed_storage=?");
break;
case E_PMINFO_APPINFO_PROP_APP_UI_GADGET:
snprintf(buf, sizeof(buf), "ai.app_ui_gadget=? COLLATE NOCASE");
break;
- case E_PMINFO_APPINFO_PROP_APP_METADATA_KEY:
- snprintf(buf, sizeof(buf), "package_app_app_metadata.md_key=?");
- flag = E_PMINFO_APPINFO_JOIN_METADATA;
- break;
- case E_PMINFO_APPINFO_PROP_APP_METADATA_VALUE:
- snprintf(buf, sizeof(buf), "package_app_app_metadata.md_value=?");
- flag = E_PMINFO_APPINFO_JOIN_METADATA;
- break;
case E_PMINFO_APPINFO_PROP_APP_DISABLE:
- snprintf(buf, MAX_QUERY_LEN, "ai.app_disable=? COLLATE NOCASE");
+ 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))");
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_APP_DISABLE_FOR_USER:
- snprintf(buf, MAX_QUERY_LEN, "ai.app_id NOT IN "
- "(SELECT app_id from package_app_info_for_uid WHERE uid=? " \
- "AND is_disabled='true' COLLATE NOCASE)");
+ case E_PMINFO_APPINFO_PROP_PKG_DISABLE:
+ snprintf(buf, MAX_QUERY_LEN,
+ "ai.package IN (SELECT package FROM " \
+ "package_info WHERE package_disable=?)");
+ break;
+ case E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE:
+ snprintf(buf, sizeof(buf), "ai.app_support_mode=?");
+ break;
+ case E_PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE:
+ case E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE:
+ *condition = NULL;
+ return 0;
+ case E_PMINFO_APPINFO_PROP_PRIVILEGE:
+ snprintf(buf, sizeof(buf), "package_privilege_info.privilege=?");
+ flag = E_PMINFO_APPINFO_JOIN_PRIVILEGE;
break;
default:
_LOGE("Invalid Property Type\n");
return flag;
}
+int __get_metadata_filter_condition(gpointer data, char **condition,
+ GList **params)
+{
+ pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data;
+ char buf[MAX_QUERY_LEN];
+
+ snprintf(buf, sizeof(buf), "(package_app_app_metadata.md_key=?");
+ if (node->value)
+ strncat(buf, " AND package_app_app_metadata.md_value=?",
+ sizeof(buf) - strlen(buf) - 1);
+ strncat(buf, ")", sizeof(buf) - strlen(buf) - 1);
+
+ *condition = strdup(buf);
+ *params = g_list_append(*params, strdup(node->key));
+ if (node->value)
+ *params = g_list_append(*params, strdup(node->value));
+
+ return E_PMINFO_APPINFO_JOIN_METADATA;
+}
+
int _add_icon_info_into_list(const char *locale, char *value, GList **icon)
{
icon_x *info;
}
info->text = value;
info->lang = strdup(locale);
- *icon = g_list_append(*icon, info);
+ *icon = g_list_prepend(*icon, info);
return PMINFO_R_OK;
}
}
info->text = value;
info->lang = strdup(locale);
- *label = g_list_append(*label, info);
+ *label = g_list_prepend(*label, info);
return PMINFO_R_OK;
}
return locale;
}
+int __pkginfo_check_installed_storage(package_x *pkginfo)
+{
+ char buf[MAX_QUERY_LEN] = {'\0'};
+ int ret;
+
+ retvm_if(pkginfo->package == NULL, PMINFO_R_OK, "pkgid is NULL\n");
+ retvm_if(pkginfo->installed_storage == NULL, PMINFO_R_ERROR,
+ "installed_storage is NULL\n");
+
+ if (strcmp(pkginfo->installed_storage, "installed_external") == 0) {
+ snprintf(buf, MAX_QUERY_LEN - 1, "%s", pkginfo->external_path);
+ ret = access(buf, R_OK);
+ if (ret != 0) {
+ _LOGE("can not access [%s] - %d", buf, ret);
+ return PMINFO_R_ERROR;
+ }
+ }
+
+ return PMINFO_R_OK;
+}
+
+int __appinfo_check_installed_storage(application_x *appinfo)
+{
+ retvm_if(appinfo->installed_storage == NULL, PMINFO_R_ERROR,
+ "installed_storage is NULL\n");
+
+ if (strcmp(appinfo->installed_storage, "installed_external") == 0) {
+ retvm_if(appinfo->external_path == NULL, PMINFO_R_ERROR,
+ "external path is NULL\n");
+ if (access(appinfo->external_path, R_OK) != 0) {
+ _LOGE("can not access [%s]", appinfo->external_path);
+ return PMINFO_R_ERROR;
+ }
+ }
+
+ return PMINFO_R_OK;
+}
+
+#define BUSY_WAITING_USEC (1000000 / 10 / 2) /* 0.05 sec */
+#define BUSY_WAITING_MAX 100 /* wait for max 5 sec */
+static int __db_busy_handler(void *data, int count)
+{
+ if (count < BUSY_WAITING_MAX) {
+ usleep(BUSY_WAITING_USEC);
+ return 1;
+ } else {
+ /* sqlite3_prepare_v2 will return SQLITE_BUSY */
+ return 0;
+ }
+}
+
+int __open_db(const char *path, sqlite3 **db, int flags)
+{
+ int ret;
+
+ ret = sqlite3_open_v2(path, db, flags, NULL);
+ if (ret != SQLITE_OK) {
+ sqlite3_close_v2(*db);
+ return ret;
+ }
+
+ ret = sqlite3_busy_handler(*db, __db_busy_handler, NULL);
+ if (ret != SQLITE_OK) {
+ _LOGE("failed to register busy handler: %s",
+ sqlite3_errmsg(*db));
+ sqlite3_close_v2(*db);
+ return ret;
+ }
+
+ return ret;
+}
+
+struct type_map {
+ const char *manifest;
+ const char *type;
+};
+
+struct type_map type_map[] = {
+ { "res/wgt/config.xml", "wgt" },
+ { "config.xml", "wgt" },
+ { "tizen-manifest.xml", "tpk" },
+ { NULL, NULL}
+};
+
+char *__get_type_from_path(const char *pkg_path)
+{
+ const char *type = NULL;
+ unzFile uf;
+ int i;
+
+ uf = unzOpen(pkg_path);
+ if (uf == NULL) {
+ _LOGE("failed to open zip file %s", pkg_path);
+ return NULL;
+ }
+
+ for (i = 0; type_map[i].manifest != NULL; i++) {
+ if (unzLocateFile(uf, type_map[i].manifest, 0) == UNZ_OK) {
+ _LOGD("pkgtype of %s: [%s]", pkg_path,
+ type_map[i].type);
+ type = type_map[i].type;
+ break;
+ }
+ }
+ unzClose(uf);
+
+ if (type == NULL) {
+ _LOGE("cannot get pkg type of file %s", pkg_path);
+ return NULL;
+ }
+
+ return strdup(type);
+}
+
+static const char *__get_library_path(const char *pkg_type)
+{
+ char buf[64];
+ const char *path;
+
+ snprintf(buf, sizeof(buf), "package-manager/backendlib/lib%s.so",
+ pkg_type);
+ path = tzplatform_mkpath(TZ_SYS_RO_ETC, buf);
+
+ return path;
+}
+
+pkg_plugin_set *__load_library(const char *pkg_type)
+{
+ void *library_handle;
+ pkg_plugin_set *plugin_set;
+ bool (*on_load)(pkg_plugin_set *plugin);
+ const char *library_path;
+
+ library_path = __get_library_path(pkg_type);
+ if (library_path == NULL) {
+ _LOGE("cannot get library path for %s", pkg_type);
+ return NULL;
+ }
+
+ if (plugin_set_list == NULL) {
+ plugin_set_list = g_hash_table_new_full(g_str_hash,
+ g_str_equal, free, free);
+ if (plugin_set_list == NULL) {
+ _LOGE("out of memory");
+ return NULL;
+ }
+ }
+
+ plugin_set = (pkg_plugin_set *)g_hash_table_lookup(plugin_set_list,
+ (gconstpointer)pkg_type);
+ if (plugin_set) {
+ _LOGD("already loaded [%s]", library_path);
+ return plugin_set;
+ }
+
+ if ((library_handle = dlopen(library_path, RTLD_LAZY)) == NULL) {
+ _LOGE("dlopen is failed library_path[%s]", library_path);
+ return NULL;
+ }
+
+ if ((on_load = dlsym(library_handle, "pkg_plugin_on_load")) == NULL ||
+ dlerror() != NULL) {
+ _LOGE("cannot find symbol");
+ dlclose(library_handle);
+ return NULL;
+ }
+
+ plugin_set = (pkg_plugin_set *)calloc(1, sizeof(pkg_plugin_set));
+ if (plugin_set == NULL) {
+ _LOGE("out of memory");
+ dlclose(library_handle);
+ return NULL;
+ }
+
+ if (on_load(plugin_set) != 0) {
+ _LOGE("pkg_plugin_on_load failed");
+ free(plugin_set);
+ dlclose(library_handle);
+ plugin_set = NULL;
+ return NULL;
+ }
+
+ plugin_set->plugin_handle = library_handle;
+ snprintf(plugin_set->pkg_type,
+ sizeof(plugin_set->pkg_type), "%s", pkg_type);
+
+ g_hash_table_insert(plugin_set_list, (gpointer)strdup(pkg_type),
+ (gpointer)plugin_set);
+
+ _LOGD("library [%s] is loaded", library_path);
+
+ return plugin_set;
+}
+
+void __unload_library(const char *pkg_type)
+{
+ pkg_plugin_set *plugin_set;
+
+ if (plugin_set_list == NULL)
+ return;
+
+ plugin_set = (pkg_plugin_set *)g_hash_table_lookup(plugin_set_list,
+ (gconstpointer)pkg_type);
+
+ if (plugin_set == NULL) {
+ _LOGE("pkg plugin for %s is not loaded", pkg_type);
+ return;
+ }
+
+ plugin_set->plugin_on_unload();
+ dlclose(plugin_set->plugin_handle);
+ g_hash_table_remove(plugin_set_list, (gconstpointer)pkg_type);
+}