#include <libxml/xmlschemas.h>
#include <vconf.h>
#include <glib.h>
-
-/* For multi-user support */
-#include <tzplatform_config.h>
+#include <pwd.h>
+#include <grp.h>
#include "pkgmgr_parser.h"
#include "pkgmgr_parser_internal.h"
#define PKG_TAG_LEN_MAX 128
+
+
/* operation_type */
typedef enum {
ACTION_INSTALL = 0,
static void __processNode(xmlTextReaderPtr reader, ACTION_TYPE action, char *const tagv[], const char *pkgid);
static void __streamFile(const char *filename, ACTION_TYPE action, char *const tagv[], const char *pkgid);
static int __validate_appid(const char *pkgid, const char *appid, char **newappid);
+static int __is_admin();
+
+API char *getUserDBLabel(void)
+{
+ char *result;
+ if(__is_admin())
+ result = strdup("System");
+ else
+ result = strdup("User");
+ return result;
+}
+
+API char *getUserPkgParserDBPath(void)
+{
+ return getUserPkgParserDBPathUID(getuid());
+}
+
+API char *getUserPkgParserDBPathUID(uid_t uid)
+{
+ char *result = NULL;
+ if(!uid)
+ {
+ result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
+ }
+ else
+ {
+ const char *name = "users";
+ struct passwd *userinfo = NULL;
+ struct group *grpinfo = NULL;
+
+ userinfo = getpwuid(uid);
+ if(userinfo == NULL)
+ _LOGE("getpwuid(%d) returns NULL !", uid);
+
+ grpinfo = getgrnam(name);
+ if(grpinfo == NULL)
+ _LOGE("getgrnam(users) returns NULL !");
+
+ // Compare git_t type and not group name
+ if (grpinfo->gr_gid != userinfo->pw_gid)
+ _LOGE("UID [%d] does not belong to 'users' group!", uid);
+
+ result = userinfo->pw_dir;
+ strcat(result,"/.applications/dbspace/.pkgmgr_parser.db");
+ }
+ return result;
+}
+
+API char *getUserPkgParserJournalDBPath(void)
+{
+ char *result;
+ if(getuid())
+ result = tzplatform_mkpath(TZ_USER_HOME, ".applications/dbspace/.pkgmgr_parser-journal.db");
+ else
+ result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db-journal");
+ return result;
+}
+
+API char *getUserPkgCertDBPath(void)
+{
+ char *result;
+ if(getuid())
+ result = tzplatform_mkpath(TZ_USER_HOME, ".applications/dbspace/.pkgmgr_cert.db");
+ else
+ result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
+ return result;
+}
+
+API char *getUserPkgCertJournalDBPath(void)
+{
+ char *result;
+ if(getuid())
+ result = tzplatform_mkpath(TZ_USER_HOME, ".applications/dbspace/.pkgmgr_cert-journal.db");
+ else
+ result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert-journal.db");
+ return result;
+}
void *__open_lib_handle(char *tag)
{
return;
}
+static int __is_admin()
+{
+ uid_t uid = getuid();
+ if ((uid_t) 0 == uid )
+ return 1;
+ else
+ return 0;
+}
+
+
+
static int __validate_appid(const char *pkgid, const char *appid, char **newappid)
{
if (!pkgid || !appid || !newappid) {
return ret;
}
-#define DESKTOP_RW_PATH tzplatform_mkpath(TZ_SYS_SHARE, "applications/")
-#define DESKTOP_RO_PATH "/usr/share/applications/"
-#define MANIFEST_RO_PREFIX "/usr/share/packages/"
+static const char* getUserDesktopPath(void)
+{
+ const char* desktop_path;
+ if(getuid() > 0)
+ {
+ desktop_path = tzplatform_mkpath(TZ_USER_HOME, ".applications/desktop/");
+ }
+ else
+ {
+ desktop_path = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/");
+ }
+
+ _LOGD("uid: [%d] / desktop_path: [%s]\n", getuid(), desktop_path);
+ return desktop_path;
+}
+
+static const char* getUserManifestPath(void)
+{
+ const char* manifest_path;
+ if(getuid() > 0)
+ {
+ manifest_path = tzplatform_mkpath(TZ_USER_HOME, ".config/xwalk-service/applications/");
+ }
+ else
+ {
+ manifest_path = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/");
+ }
+
+ _LOGD("uid: [%d] / manifest_path: [%s]\n", getuid(), manifest_path);
+ return manifest_path;
+}
static char* __convert_to_system_locale(const char *mlocale)
{
if (manifest != NULL) {
/* skip making a deskfile and update ail, if preload app is updated */
- if(strstr(manifest, MANIFEST_RO_PREFIX)) {
+ if(strstr(manifest, getUserManifestPath())) {
__ail_change_info(AIL_INSTALL, mfx->uiapplication->appid);
_LOGE("preload app is update : skip and update ail : %s", manifest);
continue;
}
}
- if(mfx->readonly && !strcasecmp(mfx->readonly, "True"))
- snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RO_PATH, mfx->uiapplication->appid);
- else
- snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, mfx->uiapplication->appid);
+ snprintf(filepath, sizeof(filepath),"%s%s.desktop", getUserDesktopPath(), mfx->uiapplication->appid);
/* skip if desktop exists
if (access(filepath, R_OK) == 0)
uiapplication_x *uiapplication = mfx->uiapplication;
for(; uiapplication; uiapplication=uiapplication->next) {
- snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, uiapplication->appid);
+ snprintf(filepath, sizeof(filepath),"%s%s.desktop", getUserDesktopPath(), uiapplication->appid);
__ail_change_info(AIL_REMOVE, uiapplication->appid);
char buffer[1024] = { 0 };
int state = 0;
- if(strstr(manifest, MANIFEST_RO_PREFIX)) {
+ if(strstr(manifest, getUserManifestPath())) {
free((void *)mfx->readonly);
mfx->readonly = strdup("True");
int ret = 0;
uiapplication_x *uiapplication = mfx->uiapplication;
- if(strstr(manifest, MANIFEST_RO_PREFIX)) {
+ if(strstr(manifest, getUserManifestPath())) {
/* if preload app is updated, then remove previous desktop file on RW*/
for(; uiapplication; uiapplication=uiapplication->next) {
- snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, uiapplication->appid);
+ snprintf(filepath, sizeof(filepath),"%s%s.desktop", getUserDesktopPath(), uiapplication->appid);
ret = remove(filepath);
if (ret <0)
return -1;
static int __open_manifest_db()
{
int ret = -1;
- if (access(MANIFEST_DB, F_OK) == 0) {
+ if (access(getUserPkgParserDBPath(), F_OK) == 0) {
ret =
- db_util_open_with_options(MANIFEST_DB, &manifest_db,
+ db_util_open_with_options(getUserPkgParserDBPath(), &manifest_db,
SQLITE_OPEN_READONLY, NULL);
- retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", MANIFEST_DB);
+ retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", getUserPkgParserDBPath());
return 0;
}
_LOGE("Manifest DB does not exists !!\n");
sqlite3 *pkginfo_db = NULL;
/*validate pkgid*/
- ret = db_util_open_with_options(MANIFEST_DB, &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
- retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
+ ret = db_util_open_with_options(getUserPkgParserDBPath(), &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
+ retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
/*check pkgid exist on db*/
snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
- ret = db_util_open_with_options(MANIFEST_DB, &manifest_db,
+ ret = db_util_open_with_options(getUserPkgParserDBPath(), &manifest_db,
SQLITE_OPEN_READONLY, NULL);
if (ret != SQLITE_OK) {
- _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
+ _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPath());
ret = PMINFO_R_ERROR;
goto err;
}
appinfo->app_component = PMINFO_ALL_APP;
/*open db */
- ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
- tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
+ ret = db_util_open_with_options(getUserPkgParserDBPath(), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
+ tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
appinfo->package = strdup(info->manifest_info->package);
snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
sqlite3 *appinfo_db = NULL;
/*open db*/
- ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
- retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
+ ret = db_util_open_with_options(getUserPkgParserDBPath(), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
+ retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
/*calloc pkginfo*/
pkgmgr_pkginfo_x *info = NULL;
tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
/*open db*/
- ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
- retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
+ ret = db_util_open_with_options(getUserPkgParserDBPath(), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
+ retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
/*calloc pkginfo*/
pkgmgr_pkginfo_x *info = NULL;
return ret;
}
+API int pkgmgrinfo_appinfo_get_appinfo_user(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
+{
+ retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
+ retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+
+ pkgmgr_appinfo_x *appinfo = NULL;
+ char *syslocale = NULL;
+ char *locale = NULL;
+ int ret = -1;
+ int exist = 0;
+ label_x *tmp1 = NULL;
+ icon_x *tmp2 = NULL;
+ category_x *tmp3 = NULL;
+ metadata_x *tmp4 = NULL;
+ permission_x *tmp5 = NULL;
+ image_x *tmp6 = NULL;
+ char query[MAX_QUERY_LEN] = {'\0'};
+ sqlite3 *appinfo_db = NULL;
+
+ if (uid != 0) {
+ /*open db*/
+ _LOGD("getUserPkgParserDBPathUID(%d) returns: [%s]", uid, getUserPkgParserDBPathUID(uid));
+ ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
+ retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
+ }else
+ {
+ /*open db*/
+ _LOGD("getUserPkgParserDBPath() returns: [%s]", getUserPkgParserDBPath);
+ ret = db_util_open_with_options(getUserPkgParserDBPath(), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
+ retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
+ }
+
+ /*check appid exist on db*/
+ snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
+ ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
+ tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
+ tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
+
+ /*get system locale*/
+ syslocale = vconf_get_str(VCONFKEY_LANGSET);
+ tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
+
+ /*get locale on db*/
+ locale = __convert_system_locale_to_manifest_locale(syslocale);
+ tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
+
+ /*calloc appinfo*/
+ appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
+ tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
+
+ /*check app_component from DB*/
+ memset(query, '\0', MAX_QUERY_LEN);
+ snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
+ ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
+ tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
+
+ /*calloc app_component*/
+ if (appinfo->app_component == PMINFO_UI_APP) {
+ appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
+ tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
+ } else {
+ appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
+ tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
+ }
+ appinfo->locale = strdup(locale);
+
+ /*populate app_info from DB*/
+ memset(query, '\0', MAX_QUERY_LEN);
+ snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
+ ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+ tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
+
+ memset(query, '\0', MAX_QUERY_LEN);
+ snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
+ ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+ tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
+
+ /*Also store the values corresponding to default locales*/
+ memset(query, '\0', MAX_QUERY_LEN);
+ snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
+ ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+ tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
+
+ /*Populate app category*/
+ memset(query, '\0', MAX_QUERY_LEN);
+ snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
+ ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+ tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
+
+ /*Populate app metadata*/
+ memset(query, '\0', MAX_QUERY_LEN);
+ snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
+ ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+ tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
+
+ /*Populate app permission*/
+ memset(query, '\0', MAX_QUERY_LEN);
+ snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
+ ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+ tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
+
+ /*store setting notification icon section*/
+ memset(query, '\0', MAX_QUERY_LEN);
+ snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
+ ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+ tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
+
+ /*store app preview image info*/
+ memset(query, '\0', MAX_QUERY_LEN);
+ snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
+ ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+ tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
+
+ switch (appinfo->app_component) {
+ case PMINFO_UI_APP:
+ if (appinfo->uiapp_info->label) {
+ LISTHEAD(appinfo->uiapp_info->label, tmp1);
+ appinfo->uiapp_info->label = tmp1;
+ }
+ if (appinfo->uiapp_info->icon) {
+ LISTHEAD(appinfo->uiapp_info->icon, tmp2);
+ appinfo->uiapp_info->icon = tmp2;
+ }
+ if (appinfo->uiapp_info->category) {
+ LISTHEAD(appinfo->uiapp_info->category, tmp3);
+ appinfo->uiapp_info->category = tmp3;
+ }
+ if (appinfo->uiapp_info->metadata) {
+ LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
+ appinfo->uiapp_info->metadata = tmp4;
+ }
+ if (appinfo->uiapp_info->permission) {
+ LISTHEAD(appinfo->uiapp_info->permission, tmp5);
+ appinfo->uiapp_info->permission = tmp5;
+ }
+ if (appinfo->uiapp_info->image) {
+ LISTHEAD(appinfo->uiapp_info->image, tmp6);
+ appinfo->uiapp_info->image = tmp6;
+ }
+ break;
+ case PMINFO_SVC_APP:
+ if (appinfo->svcapp_info->label) {
+ LISTHEAD(appinfo->svcapp_info->label, tmp1);
+ appinfo->svcapp_info->label = tmp1;
+ }
+ if (appinfo->svcapp_info->icon) {
+ LISTHEAD(appinfo->svcapp_info->icon, tmp2);
+ appinfo->svcapp_info->icon = tmp2;
+ }
+ if (appinfo->svcapp_info->category) {
+ LISTHEAD(appinfo->svcapp_info->category, tmp3);
+ appinfo->svcapp_info->category = tmp3;
+ }
+ if (appinfo->svcapp_info->metadata) {
+ LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
+ appinfo->svcapp_info->metadata = tmp4;
+ }
+ if (appinfo->svcapp_info->permission) {
+ LISTHEAD(appinfo->svcapp_info->permission, tmp5);
+ appinfo->svcapp_info->permission = tmp5;
+ }
+ break;
+ default:
+ break;
+ }
+
+ ret = PMINFO_R_OK;
+
+catch:
+ if (ret == PMINFO_R_OK)
+ *handle = (void*)appinfo;
+ else {
+ *handle = NULL;
+ __cleanup_appinfo(appinfo);
+ }
+
+ sqlite3_close(appinfo_db);
+ if (syslocale) {
+ free(syslocale);
+ syslocale = NULL;
+ }
+ if (locale) {
+ free(locale);
+ locale = NULL;
+ }
+ return ret;
+}
+
API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
{
retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
sqlite3 *appinfo_db = NULL;
/*open db*/
- ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
- retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
+ ret = db_util_open_with_options(getUserPkgParserDBPath(), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
+ retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
/*check appid exist on db*/
snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
char query[MAX_QUERY_LEN] = {'\0'};
ret = __open_manifest_db();
- if (access(MANIFEST_DB, F_OK) == 0) {
+ if (access(getUserPkgParserDBPath(), F_OK) == 0) {
ret = db_util_open(MANIFEST_DB, &manifest_db,
DB_UTIL_REGISTER_HOOK_METHOD);
if (ret != SQLITE_OK) {
- _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
+ _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", getUserPkgParserDBPath());
return PMINFO_R_ERROR;
}
}
char *error_message = NULL;
ret = __open_manifest_db();
- if (access(MANIFEST_DB, F_OK) == 0) {
- ret = db_util_open(MANIFEST_DB, &manifest_db,
+ if (access(getUserPkgParserDBPath(), F_OK) == 0) {
+ ret = db_util_open(getUserPkgParserDBPath(), &manifest_db,
DB_UTIL_REGISTER_HOOK_METHOD);
if (ret != SQLITE_OK) {
- _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
+ _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", getUserPkgParserDBPath());
return PMINFO_R_ERROR;
}
}
val = (char *)info->uiapp_info->guestmode_visibility;
if (val ) {
ret =
- db_util_open_with_options(MANIFEST_DB, &pkgmgr_parser_db,
+ db_util_open_with_options(getUserPkgParserDBPath(), &pkgmgr_parser_db,
SQLITE_OPEN_READWRITE, NULL);
if (ret != SQLITE_OK) {