X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fpkgmgr-info.c;h=3a7c2649d2e8aeefe4724ce512a78b48c2e23d99;hb=83f990165548fb458fbb677dbefa446f1fdb026d;hp=8b7335bb2b66fe77aebbfd5322e8151c2923a189;hpb=b78e0867a8cfaaf42bd32f86090eb1d041c2630e;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git diff --git a/src/pkgmgr-info.c b/src/pkgmgr-info.c old mode 100755 new mode 100644 index 8b7335b..3a7c264 --- a/src/pkgmgr-info.c +++ b/src/pkgmgr-info.c @@ -32,10 +32,10 @@ #include #include #include -#include -#include #include #include +#include +#include #include #include @@ -52,6 +52,7 @@ #include "pkgmgr-info-debug.h" #include "pkgmgr-info.h" #include "pkgmgr_parser_db.h" +#include "pkgmgr_parser_internal.h" #include #include @@ -76,7 +77,7 @@ #define PKG_RO_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "") #define BLOCK_SIZE 4096 /*in bytes*/ #define BUFSIZE 4096 -#define OWNER_ROOT 0 +#define ROOT_UID 0 #define MMC_PATH tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard") #define PKG_SD_PATH tzplatform_mkpath3(TZ_SYS_STORAGE, "sdcard", "app2sd/") @@ -117,7 +118,6 @@ #define METADATA_FILTER_QUERY_UNION_CLAUSE " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE #define LANGUAGE_LENGTH 2 -#define LIBAIL_PATH "/usr/lib/libail.so.0" #define SERVICE_NAME "org.tizen.system.deviced" #define PATH_NAME "/Org/Tizen/System/DeviceD/Mmc" @@ -182,6 +182,7 @@ typedef struct _pkgmgr_appinfo_x { } pkgmgr_appinfo_x; typedef struct _pkgmgr_certinfo_x { + int for_all_users; char *pkgid; char *cert_value; char *cert_info[MAX_CERT_TYPE]; /*certificate info*/ @@ -275,37 +276,6 @@ typedef enum { "dist2_signer_cert integer, " \ "PRIMARY KEY(package)) " - -#define QUERY_ATTACH "attach database '%s' as Global" -#define QUERY_CREATE_VIEW_1 "CREATE temp VIEW package_app_app_category as select * " \ - "from (select *,0 as for_all_users from main.package_app_app_category union select *,1 as for_all_users from Global.package_app_app_category)" -#define QUERY_CREATE_VIEW_2 "CREATE temp VIEW package_app_info as select * "\ - "from (select *,0 as for_all_users from main.package_app_info union select *,1 as for_all_users from Global.package_app_info)" -#define QUERY_CREATE_VIEW_3 "CREATE temp VIEW package_app_app_control as select * "\ - "from (select *,0 as for_all_users from main.package_app_app_control union select *,1 as for_all_users from Global.package_app_app_control)" -#define QUERY_CREATE_VIEW_4 "CREATE temp VIEW package_app_localized_info as select * "\ - "from (select *,0 as for_all_users from main.package_app_localized_info union select *,1 as for_all_users from Global.package_app_localized_info)" -#define QUERY_CREATE_VIEW_5 "CREATE temp VIEW package_app_app_metadata as select * "\ - "from (select *,0 as for_all_users from main.package_app_app_metadata union select *,1 as for_all_users from Global.package_app_app_metadata)" -#define QUERY_CREATE_VIEW_6 "CREATE temp VIEW package_app_share_allowed as select * "\ - "from (select *,0 as for_all_users from main.package_app_share_allowed union select *,1 as for_all_users from Global.package_app_share_allowed)" -#define QUERY_CREATE_VIEW_7 "CREATE temp VIEW package_app_app_permission as select * "\ - "from (select *,0 as for_all_users from main.package_app_app_permission union select *,1 as for_all_users from Global.package_app_app_permission)" -#define QUERY_CREATE_VIEW_8 "CREATE temp VIEW package_app_share_request as select * "\ - "from (select *,0 as for_all_users from main.package_app_share_request union select *,1 as for_all_users from Global.package_app_share_request)" -#define QUERY_CREATE_VIEW_9 "CREATE temp VIEW package_app_app_svc as select * "\ - "from (select *,0 as for_all_users from main.package_app_app_svc union select *,1 as for_all_users from Global.package_app_app_svc)" -#define QUERY_CREATE_VIEW_10 "CREATE temp VIEW package_info as select * "\ - "from (select *,0 as for_all_users from main.package_info union select *,1 as for_all_users from Global.package_info)" -#define QUERY_CREATE_VIEW_11 "CREATE temp VIEW package_app_icon_section_info as select * "\ - "from (select *,0 as for_all_users from main.package_app_icon_section_info union select *,1 as for_all_users from Global.package_app_icon_section_info)" -#define QUERY_CREATE_VIEW_12 "CREATE temp VIEW package_localized_info as select * "\ - "from (select *,0 as for_all_users from main.package_localized_info union select *,1 as for_all_users from Global.package_localized_info)" -#define QUERY_CREATE_VIEW_13 "CREATE temp VIEW package_app_image_info as select * "\ - "from (select *,0 as for_all_users from main.package_app_image_info union select *,1 as for_all_users from Global.package_app_image_info )" -#define QUERY_CREATE_VIEW_14 "CREATE temp VIEW package_privilege_info as select * "\ - "from (select *,0 as for_all_users from main.package_privilege_info union select *,1 as for_all_users from Global.package_privilege_info)" - #define GET_DB(X) (X).dbHandle char *pkgtype = "rpm"; __thread db_handle manifest_db; @@ -314,7 +284,7 @@ __thread db_handle cert_db; static int __open_manifest_db(uid_t uid); static int __close_manifest_db(void); -static int __open_cert_db(uid_t uid); +static int __open_cert_db(uid_t uid, char* mode); static int __close_cert_db(void); static int __exec_pkginfo_query(char *query, void *data); static int __exec_certinfo_query(char *query, void *data); @@ -337,191 +307,89 @@ static void __destroy_each_node(gpointer data, gpointer user_data); static void __get_filter_condition(gpointer data, char **condition); static void __get_metadata_filter_condition(gpointer data, char **condition); static gint __compare_func(gconstpointer data1, gconstpointer data2); -static int __delete_certinfo(const char *pkgid); +static int __delete_certinfo(const char *pkgid, uid_t uid); static int _check_create_Cert_db( sqlite3 *certdb); static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data); -static int _mkdir(const char *dir, mode_t mode) +static int _mkdir_for_user(const char* dir, uid_t uid, gid_t gid) { - char tmp[PATH_MAX]; - char *p = NULL; - size_t len; int ret; + char *fullpath; + char *subpath; - snprintf(tmp, sizeof(tmp), "%s", dir); - len = strlen(tmp); - if(tmp[len - 1] == '/') - tmp[len - 1] = 0; - for(p = tmp + 1; *p; p++) { - if(*p == '/') { - *p = 0; - ret = mkdir(tmp, mode); - if (ret && errno != EEXIST) - return ret; - *p = '/'; + fullpath = strdup(dir); + subpath = dirname(fullpath); + if (strlen(subpath) > 1 && strcmp(subpath, fullpath) != 0) { + ret = _mkdir_for_user(fullpath, uid, gid); + if (ret == -1) { + free(fullpath); + return ret; } } - return mkdir(tmp, mode); -} - -static int _pkgmgr_parser_attach_create_view_certdb(sqlite3 *handle, uid_t uid) -{ - char *error_message = NULL; - char query_attach[MAX_QUERY_LEN] = {'\0'}; - char query_view[MAX_QUERY_LEN] = {'\0'}; - if(uid != GLOBAL_USER){ - snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, CERT_DB); - if (SQLITE_OK != - sqlite3_exec(handle, query_attach, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - query_attach, error_message); - sqlite3_free(error_message); - } - struct dbtable { - char *name_table; - char *primary_key; - }; + ret = mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH); + if (ret && errno != EEXIST) { + free(fullpath); + return ret; + } else if (ret && errno == EEXIST) { + free(fullpath); + return 0; + } - snprintf(query_view, MAX_QUERY_LEN - 1, "CREATE temp VIEW %s as select * from (select *,0 as for_all_users from main.%s union select *,1 as for_all_users from Global.%s )", "package_cert_index_info", "package_cert_index_info", "package_cert_index_info"); - if (SQLITE_OK != - sqlite3_exec(handle, query_view, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - query_view, error_message); - sqlite3_free(error_message); - } - snprintf(query_view, MAX_QUERY_LEN - 1, "CREATE temp VIEW %s as select * from (select *,0 as for_all_users from main.%s union select *,1 as for_all_users from Global.%s)", "package_cert_info", "package_cert_info", "package_cert_info"); - if (SQLITE_OK != - sqlite3_exec(handle, query_view, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - query_view, error_message); - sqlite3_free(error_message); - } + if (getuid() == ROOT_UID) { + ret = chown(dir, uid, gid); + if (ret == -1) + _LOGE("FAIL : chown %s %d.%d, because %s", dir, uid, + gid, strerror(errno)); } - return SQLITE_OK; + + free(fullpath); + + return 0; } +static const char *_get_db_path(uid_t uid) { + const char *db_path = NULL; + if (uid != GLOBAL_USER && uid != ROOT_UID) { + tzplatform_set_user(uid); + db_path = tzplatform_getenv(TZ_USER_DB); + tzplatform_reset_user(); + } else { + db_path = tzplatform_getenv(TZ_SYS_DB); + } + return db_path; +} -static int _pkgmgr_parser_attach_create_view_parserdb(sqlite3 *handle, uid_t uid) +static int __attach_and_create_view(sqlite3 *handle, const char *db, const char *tables[], uid_t uid) { - char *error_message = NULL; - char query_attach[MAX_QUERY_LEN] = {'\0'}; - if(uid != GLOBAL_USER){ - snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, MANIFEST_DB); - if (SQLITE_OK != - sqlite3_exec(handle, query_attach, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - query_attach, error_message); - sqlite3_free(error_message); - } - if (SQLITE_OK != - sqlite3_exec(handle, QUERY_CREATE_VIEW_1, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - QUERY_CREATE_VIEW_1, error_message); - sqlite3_free(error_message); - } - if (SQLITE_OK != - sqlite3_exec(handle, QUERY_CREATE_VIEW_2, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - QUERY_CREATE_VIEW_2, error_message); - sqlite3_free(error_message); - } - if (SQLITE_OK != - sqlite3_exec(handle, QUERY_CREATE_VIEW_3, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - QUERY_CREATE_VIEW_3, error_message); - sqlite3_free(error_message); - } - if (SQLITE_OK != - sqlite3_exec(handle, QUERY_CREATE_VIEW_4, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - QUERY_CREATE_VIEW_4, error_message); - sqlite3_free(error_message); - } - if (SQLITE_OK != - sqlite3_exec(handle, QUERY_CREATE_VIEW_5, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - QUERY_CREATE_VIEW_5, error_message); - sqlite3_free(error_message); - } - if (SQLITE_OK != - sqlite3_exec(handle, QUERY_CREATE_VIEW_6, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - QUERY_CREATE_VIEW_6, error_message); - sqlite3_free(error_message); - } - if (SQLITE_OK != - sqlite3_exec(handle, QUERY_CREATE_VIEW_7, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - QUERY_CREATE_VIEW_7, error_message); - sqlite3_free(error_message); - } - if (SQLITE_OK != - sqlite3_exec(handle, QUERY_CREATE_VIEW_8, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - QUERY_CREATE_VIEW_8, error_message); - sqlite3_free(error_message); - } - if (SQLITE_OK != - sqlite3_exec(handle, QUERY_CREATE_VIEW_9, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - QUERY_CREATE_VIEW_9, error_message); - sqlite3_free(error_message); - } - if (SQLITE_OK != - sqlite3_exec(handle, QUERY_CREATE_VIEW_10, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - QUERY_CREATE_VIEW_10, error_message); - sqlite3_free(error_message); - } - if (SQLITE_OK != - sqlite3_exec(handle, QUERY_CREATE_VIEW_11, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - QUERY_CREATE_VIEW_11, error_message); - sqlite3_free(error_message); - } - if (SQLITE_OK != - sqlite3_exec(handle, QUERY_CREATE_VIEW_12, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - QUERY_CREATE_VIEW_12, error_message); - sqlite3_free(error_message); - } - if (SQLITE_OK != - sqlite3_exec(handle, QUERY_CREATE_VIEW_13, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - QUERY_CREATE_VIEW_13, error_message); - sqlite3_free(error_message); - } - if (SQLITE_OK != - sqlite3_exec(handle, QUERY_CREATE_VIEW_14, - NULL, NULL, &error_message)) { - _LOGD("Don't execute query = %s error message = %s\n", - QUERY_CREATE_VIEW_14, error_message); - sqlite3_free(error_message); + int i; + char *err; + char query[MAX_QUERY_LEN]; + + if (uid == GLOBAL_USER || uid == ROOT_UID) + return SQLITE_OK; + + snprintf(query, sizeof(query), "ATTACH DATABASE '%s' AS Global", db); + if (SQLITE_OK != sqlite3_exec(handle, query, NULL, NULL, &err)) { + _LOGD("Don't execute query = %s error message = %s\n", query, err); + sqlite3_free(err); + return SQLITE_ERROR; + } + + for (i = 0; tables[i]; i++) { + snprintf(query, sizeof(query), "CREATE TEMP VIEW '%s' AS SELECT * \ + FROM (SELECT *,0 AS for_all_users FROM main.'%s' UNION \ + SELECT *,1 AS for_all_users FROM Global.'%s')", + tables[i], tables[i], tables[i]); + if (SQLITE_OK != sqlite3_exec(handle, query, NULL, NULL, &err)) { + _LOGD("Don't execute query = %s error message = %s\n", query, err); + sqlite3_free(err); } } + return SQLITE_OK; } - - static int _check_create_Cert_db( sqlite3 *certdb) { int ret = 0; @@ -532,125 +400,71 @@ static int _check_create_Cert_db( sqlite3 *certdb) return ret; } +static gid_t _get_gid(const char *name) +{ + char buf[BUFSIZE]; + struct group entry; + struct group *ge; + int ret; + + ret = getgrnam_r(name, &entry, buf, sizeof(buf), &ge); + if (ret || ge == NULL) { + _LOGE("fail to get gid of %s", name); + return -1; + } + return entry.gr_gid; +} API char *getIconPath(uid_t uid) { - char *result = NULL; - struct group *grpinfo = NULL; - struct passwd *userinfo = getpwuid(uid); - int ret = 0; - if (uid == 0) { - _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER"); - return NULL; - } - if (uid != GLOBAL_USER) { - if (userinfo == NULL) { - _LOGE("getpwuid(%d) returns NULL !", uid); - return NULL; - } - grpinfo = getgrnam("users"); - if (grpinfo == NULL) { - _LOGE("getgrnam(users) returns NULL !"); - return 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); - return NULL; - } - ret = asprintf(&result, "%s/.applications/icons/", userinfo->pw_dir); - if (ret == -1) { - _LOGE("asprintf fails"); - return NULL; - } - + const char *path = NULL; + uid_t uid_caller = getuid(); + gid_t gid = ROOT_UID; + + if (uid != GLOBAL_USER && uid != ROOT_UID) { + tzplatform_set_user(uid); + path = tzplatform_mkpath(TZ_USER_ICONS, "/"); + gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP)); + tzplatform_reset_user(); } else { - result = tzplatform_mkpath(TZ_SYS_RW_ICONS, "/"); + path = tzplatform_mkpath(TZ_SYS_RW_ICONS, "/"); } - ret = _mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH); - if (ret == -1 && errno != EEXIST) { - _LOGE("FAIL : to create directory %s %d", result, errno); - } else if (getuid() == OWNER_ROOT) { - ret = chown(result, uid, ((grpinfo)?grpinfo->gr_gid:0)); - if (ret == -1) { - char buf[BUFSIZE]; - strerror_r(errno, buf, sizeof(buf)); - _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf); - } - } - return result; + // just allow certain users to create the icon directory if needed. + if (uid_caller == ROOT_UID || uid_caller == uid) + _mkdir_for_user(path, uid, gid); + + return path; } API char *getUserPkgParserDBPath(void) { - return getUserPkgParserDBPathUID(GLOBAL_USER); + return getUserPkgParserDBPathUID(GLOBAL_USER); } API char *getUserPkgParserDBPathUID(uid_t uid) { - const char *result = NULL; - const char *journal = NULL; - struct group *grpinfo = NULL; - char * dir = NULL; - struct passwd *userinfo = getpwuid(uid); - int ret = 0; - if (uid == 0) { - _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER"); - return NULL; - } - if (uid != GLOBAL_USER) { - if (userinfo == NULL) { - _LOGE("getpwuid(%d) returns NULL !", uid); - return NULL; - } - grpinfo = getgrnam("users"); - if (grpinfo == NULL) { - _LOGE("getgrnam(users) returns NULL !"); - return 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); - return NULL; - } - ret = asprintf(&result, "%s/.applications/dbspace/.pkgmgr_parser.db", userinfo->pw_dir); - if (ret == -1) { - _LOGE("asprintf fails"); - return NULL; - } - ret = asprintf(&journal, "%s/.applications/dbspace/.pkgmgr_parser.db-journal", userinfo->pw_dir); - if (ret == -1) { - _LOGE("asprintf fails"); - return NULL; - } + const char *pkgmgr_parser_db = NULL; + uid_t uid_caller = getuid(); + gid_t gid = ROOT_UID; + + if (uid != GLOBAL_USER && uid != ROOT_UID) { + tzplatform_set_user(uid); + pkgmgr_parser_db = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_parser.db"); + gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP)); + tzplatform_reset_user(); } else { - result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db"); - journal = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db-journal"); - } - char *temp = strdup(result); - dir = strrchr(temp, '/'); - if(!dir) - { - free(temp); - return result; + pkgmgr_parser_db = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db"); } - *dir = 0; - ret = _mkdir(temp, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH); - if (ret == -1 && errno != EEXIST) { - _LOGE("FAIL : to create directory %s %d", temp, errno); - } else if (getuid() == OWNER_ROOT) { - ret = chown(temp, uid, ((grpinfo)?grpinfo->gr_gid:0)); - if (ret == -1) { - char buf[BUFSIZE]; - strerror_r(errno, buf, sizeof(buf)); - _LOGE("FAIL : chown %s %d.%d, because %s", temp, uid, ((grpinfo)?grpinfo->gr_gid:0), buf); - } + // just allow certain users to create the dbspace directory if needed. + if (uid_caller == ROOT_UID || uid_caller == uid) { + const char *db_path = _get_db_path(uid); + _mkdir_for_user(db_path, uid, gid); } - free(temp); - return result; + + return pkgmgr_parser_db; } API char *getUserPkgCertDBPath(void) @@ -660,150 +474,70 @@ API char *getUserPkgCertDBPath(void) API char *getUserPkgCertDBPathUID(uid_t uid) { - char *result = NULL; - char *journal = NULL; - struct group *grpinfo = NULL; - char * dir = NULL; - struct passwd *userinfo = getpwuid(uid); + const char *pkgmgr_cert_db = NULL; + uid_t uid_caller = getuid(); + gid_t gid = ROOT_UID; - if (uid == 0) { - _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER"); - return NULL; - } - if (uid != GLOBAL_USER) { - if (userinfo == NULL) { - _LOGE("getpwuid(%d) returns NULL !", uid); - return NULL; - } - grpinfo = getgrnam("users"); - if (grpinfo == NULL) { - _LOGE("getgrnam(users) returns NULL !"); - return 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); - return NULL; - } - asprintf(&result, "%s/.applications/dbspace/.pkgmgr_cert.db", userinfo->pw_dir); - asprintf(&journal, "%s/.applications/dbspace/.pkgmgr_cert.db-journal", userinfo->pw_dir); + if (uid != GLOBAL_USER && uid != ROOT_UID) { + tzplatform_set_user(uid); + pkgmgr_cert_db = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_cert.db"); + gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP)); + tzplatform_reset_user(); } else { - result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db"); - journal = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db-journal"); + pkgmgr_cert_db = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db"); } - char *temp = strdup(result); - dir = strrchr(temp, '/'); - if(!dir) - { - free(temp); - return result; + + // just allow certain users to create the dbspace directory if needed. + if (uid_caller == ROOT_UID || uid_caller == uid) { + const char *db_path = _get_db_path(uid); + _mkdir_for_user(db_path, uid, gid); } - *dir = 0; - int ret = _mkdir(temp, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH); - if (ret == -1 && errno != EEXIST) { - _LOGE("FAIL : to create directory %s %d", temp, errno); - } else if (getuid() == OWNER_ROOT) { - ret = chown(temp, uid, ((grpinfo)?grpinfo->gr_gid:0)); - if (ret == -1) { - char buf[BUFSIZE]; - strerror_r(errno, buf, sizeof(buf)); - _LOGE("FAIL : chown %s %d.%d, because %s", temp, uid, ((grpinfo)?grpinfo->gr_gid:0), buf); - } - } - free(temp); - return result; + return pkgmgr_cert_db; } API const char* getUserDesktopPath(uid_t uid) { - char *result = NULL; - struct group *grpinfo = NULL; - char * dir = NULL; - struct passwd *userinfo = getpwuid(uid); + const char *path = NULL; + uid_t uid_caller = getuid(); + gid_t gid = ROOT_UID; - if (uid == 0) { - _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER"); - return NULL; - } - if (uid != GLOBAL_USER) { - if (userinfo == NULL) { - _LOGE("getpwuid(%d) returns NULL !", uid); - return NULL; - } - grpinfo = getgrnam("users"); - if (grpinfo == NULL) { - _LOGE("getgrnam(users) returns NULL !"); - return 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); - return NULL; - } - asprintf(&result, "%s/.applications/desktop/", userinfo->pw_dir); + if (uid != GLOBAL_USER && uid != ROOT_UID) { + tzplatform_set_user(uid); + path = tzplatform_mkpath(TZ_USER_DESKTOP, "/"); + gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP)); + tzplatform_reset_user(); } else { - result = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/"); + path = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/"); } - int ret = _mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH); - if (ret == -1 && errno != EEXIST) { - _LOGE("FAIL : to create directory %s %d", result, errno); - } else if (getuid() == OWNER_ROOT) { - ret = chown(result, uid,((grpinfo)?grpinfo->gr_gid:0)); - if (ret == -1) { - char buf[BUFSIZE]; - strerror_r(errno, buf, sizeof(buf)); - _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf); - } - } - return result; + // just allow certain users to create the icon directory if needed. + if (uid_caller == ROOT_UID || uid_caller == uid) + _mkdir_for_user(path, uid, gid); + + return path; } API const char* getUserManifestPath(uid_t uid) { - char *result = NULL; - struct group *grpinfo = NULL; - char * dir = NULL; - struct passwd *userinfo = getpwuid(uid); + const char *path = NULL; + uid_t uid_caller = getuid(); + gid_t gid = ROOT_UID; - if (uid == 0) { - _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER"); - return NULL; - } - if (uid != GLOBAL_USER) { - if (userinfo == NULL) { - _LOGE("getpwuid(%d) returns NULL !", uid); - return NULL; - } - grpinfo = getgrnam("users"); - if (grpinfo == NULL) { - _LOGE("getgrnam(users) returns NULL !"); - return 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); - return NULL; - } - asprintf(&result, "%s/.applications/manifest/", userinfo->pw_dir); + if (uid != GLOBAL_USER && uid != ROOT_UID) { + tzplatform_set_user(uid); + path = tzplatform_mkpath(TZ_USER_PACKAGES, "/"); + gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP)); + tzplatform_reset_user(); } else { - result = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/"); + path = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/"); } - int ret = _mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH); - if (ret == -1 && errno != EEXIST) { - _LOGE("FAIL : to create directory %s %d", result, errno); - } else if (getuid() == OWNER_ROOT) { - ret = chown(result, uid, ((grpinfo)?grpinfo->gr_gid:0)); - if (ret == -1) { - char buf[BUFSIZE]; - strerror_r(errno, buf, sizeof(buf)); - _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf); - } - } + // just allow certain users to create the icon directory if needed. + if (uid_caller == ROOT_UID || uid_caller == uid) + _mkdir_for_user(path, uid, gid); - return result; + return path; } static gint __compare_func(gconstpointer data1, gconstpointer data2) @@ -1030,7 +764,6 @@ static void __cleanup_appinfo(pkgmgr_appinfo_x *data) static int __close_manifest_db(void) { - int ret = -1; if(manifest_db.ref) { if(--manifest_db.ref == 0) sqlite3_close(GET_DB(manifest_db)); @@ -1039,6 +772,24 @@ static int __close_manifest_db(void) return -1; } +static const char *parserdb_tables[] = { + "package_app_app_category", + "package_app_info", + "package_app_app_control", + "package_app_localized_info", + "package_app_app_metadata", + "package_app_share_allowed", + "package_app_app_permission", + "package_app_share_request", + "package_app_app_svc", + "package_info", + "package_app_data_control", + "package_localized_info", + "package_app_icon_section_info", + "package_privilege_info", + "package_app_image_info", + NULL +}; static int __open_manifest_db(uid_t uid) { @@ -1048,46 +799,65 @@ static int __open_manifest_db(uid_t uid) return 0; } const char* user_pkg_parser = getUserPkgParserDBPathUID(uid); - if (access(user_pkg_parser, F_OK) == 0) { - ret = - db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db), - SQLITE_OPEN_READONLY, NULL); - retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_pkg_parser); - manifest_db.ref ++; - ret = _pkgmgr_parser_attach_create_view_parserdb(GET_DB(manifest_db),uid); - retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_pkg_parser); + if (access(user_pkg_parser, F_OK) != 0) { + _LOGE("Manifest DB does not exists !! try to create\n"); - return 0; + if (pkgmgr_parser_check_and_create_db(uid)) { + _LOGE("create db failed"); + return -1; + } + + if (pkgmgr_parser_initialize_db()) { + _LOGE("initialize db failed"); + return -1; + } } - _LOGE("Manifest DB does not exists !!\n"); - return -1; + + ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db), + SQLITE_OPEN_READONLY, NULL); + retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_pkg_parser); + manifest_db.ref ++; + ret = __attach_and_create_view(GET_DB(manifest_db), MANIFEST_DB, parserdb_tables, uid); + retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_pkg_parser); + + return 0; } static int __close_cert_db(void) { - int ret = -1; if(cert_db.ref) { if(--cert_db.ref == 0) sqlite3_close(GET_DB(cert_db)); + return 0; } _LOGE("Certificate DB is already closed !!\n"); return -1; } +static const char *certdb_tables[] = { + "package_cert_index_info", + "package_cert_info", + NULL +}; -static int __open_cert_db(uid_t uid) +static int __open_cert_db(uid_t uid, char* mode) { int ret = -1; + if(cert_db.ref) { + cert_db.ref ++; + return 0; + } + const char* user_cert_parser = getUserPkgCertDBPathUID(uid); if (access(user_cert_parser, F_OK) == 0) { - ret = - db_util_open_with_options(user_cert_parser, &GET_DB(cert_db), - SQLITE_OPEN_READWRITE, NULL); + ret = db_util_open_with_options(user_cert_parser, &GET_DB(cert_db), + SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_cert_parser); - - ret = _pkgmgr_parser_attach_create_view_certdb(GET_DB(cert_db),uid); - retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_cert_parser); - + cert_db.ref ++; + if ((strcmp(mode, "w") != 0)) { + ret = __attach_and_create_view(GET_DB(cert_db), CERT_DB, certdb_tables, uid); + retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_cert_parser); + } return 0; } _LOGE("Cert DB does not exists !!\n"); @@ -1096,10 +866,10 @@ static int __open_cert_db(uid_t uid) static int __close_datacontrol_db(void) { - int ret = -1; if(datacontrol_db.ref) { if(--datacontrol_db.ref == 0) sqlite3_close(GET_DB(datacontrol_db)); + return 0; } _LOGE("Certificate DB is already closed !!\n"); return -1; @@ -1108,11 +878,15 @@ static int __close_datacontrol_db(void) static int __open_datacontrol_db() { int ret = -1; + if(datacontrol_db.ref) { + datacontrol_db.ref ++; + return 0; + } if (access(DATACONTROL_DB, F_OK) == 0) { - ret = - db_util_open_with_options(DATACONTROL_DB, &GET_DB(datacontrol_db), + ret = db_util_open_with_options(DATACONTROL_DB, &GET_DB(datacontrol_db), SQLITE_OPEN_READONLY, NULL); retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB); + datacontrol_db.ref ++; return 0; } _LOGE("Datacontrol DB does not exists !!\n"); @@ -1354,6 +1128,11 @@ static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname) info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[i]); else info->manifest_info->uiapplication->submode_mainid = NULL; + } else if (strcmp(colname, "app_launch_mode") == 0 ) { + if (coltxt[i]) + info->manifest_info->uiapplication->launch_mode = strdup(coltxt[i]); + else + info->manifest_info->uiapplication->launch_mode = NULL; } else continue; } @@ -1903,6 +1682,11 @@ static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname) info->cert_value = strdup(coltxt[i]); else info->cert_value = NULL; + } else if (strcmp(colname[i], "for_all_users") == 0 ){ + if (coltxt[i]) + info->for_all_users = atoi(coltxt[i]); + else + info->for_all_users = 0; } else continue; } @@ -2037,6 +1821,11 @@ static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colnam info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[j]); else info->manifest_info->uiapplication->submode_mainid = NULL; + } else if (strcmp(colname[j], "app_launch_mode") == 0 ) { + if (coltxt[j]) + info->manifest_info->uiapplication->launch_mode = strdup(coltxt[j]); + else + info->manifest_info->uiapplication->launch_mode = NULL; } else continue; } @@ -2094,6 +1883,34 @@ static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colnam return 0; } +static void __parse_appcontrol(appcontrol_x **appcontrol, char *appcontrol_str) +{ + char *dup; + char *token; + char *ptr; + appcontrol_x *ac; + + if (appcontrol_str == NULL) + return; + + dup = strdup(appcontrol_str); + do { + ac = calloc(1, sizeof(appcontrol_x)); + token = strtok_r(dup, "|", &ptr); + if (strcmp(token, "NULL")) + ac->operation = strdup(token); + token = strtok_r(NULL, "|", &ptr); + if (strcmp(token, "NULL")) + ac->uri = strdup(token); + token = strtok_r(NULL, "|", &ptr); + if (strcmp(token, "NULL")) + ac->mime = strdup(token); + LISTADD(*appcontrol, ac); + } while (token = strtok_r(NULL, ";", &ptr)); + + free(dup); +} + static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname) { pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data; @@ -2104,6 +1921,7 @@ static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname) metadata_x *metadata = NULL; permission_x *permission = NULL; image_x *image = NULL; + appcontrol_x *appcontrol = NULL; switch (info->app_component) { case PMINFO_UI_APP: @@ -2286,6 +2104,13 @@ static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname) info->uiapp_info->submode_mainid = strdup(coltxt[i]); else info->uiapp_info->submode_mainid = NULL; + } else if (strcmp(colname[i], "app_launch_mode") == 0 ) { + if (coltxt[i]) + info->uiapp_info->launch_mode = strdup(coltxt[i]); + else + info->uiapp_info->launch_mode = NULL; + } else if (strcmp(colname[i], "app_control") == 0 ) { + __parse_appcontrol(&info->uiapp_info->appcontrol, coltxt[i]); } else continue; } @@ -2387,6 +2212,8 @@ static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname) info->svcapp_info->permission_type = strdup(coltxt[i]); else info->svcapp_info->permission_type = NULL; + } else if (strcmp(colname[i], "app_control") == 0 ) { + __parse_appcontrol(&info->svcapp_info->appcontrol, coltxt[i]); } else continue; } @@ -2728,7 +2555,7 @@ long long _pkgmgr_calculate_dir_size(char *dirname) } -static int __delete_certinfo(const char *pkgid) +static int __delete_certinfo(const char *pkgid, uid_t uid) { int ret = -1; int i = 0; @@ -2747,6 +2574,8 @@ static int __delete_certinfo(const char *pkgid) ret = PMINFO_R_ERROR; goto err; } + + __open_cert_db(uid, "w"); /*populate certinfo from DB*/ snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid); ret = __exec_certinfo_query(query, (void *)certinfo); @@ -2821,6 +2650,7 @@ err: (certinfo->cert_info)[i] = NULL; } } + __close_cert_db(); free(certinfo); certinfo = NULL; return ret; @@ -3192,9 +3022,7 @@ API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *si retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); char *val = NULL; - char *location = NULL; pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; - location = (char *)info->manifest_info->installlocation; val = (char *)info->manifest_info->package_size; if (val) { *size = atoi(val); @@ -3713,15 +3541,17 @@ API int pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(const char *lhs_package_id, int ret = PMINFO_R_OK; char query[MAX_QUERY_LEN] = {'\0'}; char *error_message = NULL; - pkgmgr_cert_x *info= NULL; + sqlite3_stmt *stmt = NULL; + char *lhs_certinfo = NULL; + char *rhs_certinfo = NULL; int lcert = 0; int rcert = 0; int exist = -1; + int i; + int is_global = 0; *compare_result = PMINFO_CERT_COMPARE_ERROR; - info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x)); - retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!"); - ret = __open_cert_db(uid); + ret = __open_cert_db(uid, "r"); if (ret != 0) { ret = PMINFO_R_ERROR; goto err; @@ -3735,20 +3565,7 @@ API int pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(const char *lhs_package_id, ret = PMINFO_R_ERROR; goto err; } - - if (exist == 0) { - lcert = 0; - } else { - snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id); - if (SQLITE_OK != - sqlite3_exec(GET_DB(cert_db), query, __cert_cb, (void *)info, &error_message)) { - _LOGE("Don't execute query = %s error message = %s\n", query, - error_message); - ret = PMINFO_R_ERROR; - goto err; - } - lcert = info->cert_id; - } + lcert = exist; snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id); if (SQLITE_OK != @@ -3758,21 +3575,51 @@ API int pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(const char *lhs_package_id, ret = PMINFO_R_ERROR; goto err; } + rcert = exist; - if (exist == 0) { - rcert = 0; - } else { - snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id); - if (SQLITE_OK != - sqlite3_exec(GET_DB(cert_db), query, __cert_cb, (void *)info, &error_message)) { - _LOGE("Don't execute query = %s error message = %s\n", query, - error_message); + if (uid == GLOBAL_USER || uid == ROOT_UID) { + snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=(select author_signer_cert from package_cert_info where package=?)"); + is_global = 1; + } else + snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=(select author_signer_cert from package_cert_info where package=?) and for_all_users=(select for_all_users from package_cert_info where package=?)"); + if (SQLITE_OK != sqlite3_prepare_v2(GET_DB(cert_db), query, strlen(query), &stmt, NULL)) { + _LOGE("sqlite3_prepare_v2 error: %s", sqlite3_errmsg(GET_DB(cert_db))); + ret = PMINFO_R_ERROR; + goto err; + } + + for (i = 1; i <= 2 - is_global; i++) { + if (SQLITE_OK != sqlite3_bind_text(stmt, i, lhs_package_id, -1, SQLITE_STATIC)) { + _LOGE("sqlite3_bind_text error: %s", sqlite3_errmsg(GET_DB(cert_db))); ret = PMINFO_R_ERROR; goto err; } - rcert = info->cert_id; + } + if (SQLITE_ROW != sqlite3_step(stmt) || sqlite3_column_text(stmt, 0) == NULL) { + _LOGE("sqlite3_step error: %s", sqlite3_errmsg(GET_DB(cert_db))); + ret = PMINFO_R_ERROR; + goto err; + } + + lhs_certinfo = strdup((const char *)sqlite3_column_text(stmt, 0)); + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + + for (i = 1; i <= 2 - is_global; i++) { + if (SQLITE_OK != sqlite3_bind_text(stmt, i, rhs_package_id, -1, SQLITE_STATIC)) { + _LOGE("sqlite3_bind_text error: %s", sqlite3_errmsg(GET_DB(cert_db))); + ret = PMINFO_R_ERROR; + goto err; + } + } + if (SQLITE_ROW != sqlite3_step(stmt) || sqlite3_column_text(stmt, 0) == NULL) { + _LOGE("sqlite3_step error: %s", sqlite3_errmsg(GET_DB(cert_db))); + ret = PMINFO_R_ERROR; + goto err; } + rhs_certinfo = strdup((const char *)sqlite3_column_text(stmt, 0)); + if ((lcert == 0) || (rcert == 0)) { if ((lcert == 0) && (rcert == 0)) @@ -3782,23 +3629,22 @@ API int pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(const char *lhs_package_id, else if (rcert == 0) *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT; } else { - if (lcert == rcert) + if (!strcmp(lhs_certinfo, rhs_certinfo)) *compare_result = PMINFO_CERT_COMPARE_MATCH; else *compare_result = PMINFO_CERT_COMPARE_MISMATCH; } err: + if (stmt) + sqlite3_finalize(stmt); + if (lhs_certinfo) + free(lhs_certinfo); + if (rhs_certinfo) + free(rhs_certinfo); sqlite3_free(error_message); __close_cert_db(); - if (info) { - if (info->pkgid) { - free(info->pkgid); - info->pkgid = NULL; - } - free(info); - info = NULL; - } + return ret; } @@ -4440,12 +4286,10 @@ API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, where[sizeof(where) - 1] = '\0'; } } - _LOGE("where = %s\n", where); if (strlen(where) > 0) { strncat(query, where, sizeof(query) - strlen(query) - 1); query[sizeof(query) - 1] = '\0'; } - _LOGE("query = %s\n", query); /*Execute Query*/ if (SQLITE_OK != @@ -4536,12 +4380,10 @@ API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_ where[sizeof(where) - 1] = '\0'; } } - _LOGE("where = %s\n", where); if (strlen(where) > 0) { strncat(query, where, sizeof(query) - strlen(query) - 1); query[sizeof(query) - 1] = '\0'; } - _LOGE("query = %s\n", query); tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x)); if (tmphead == NULL) { _LOGE("Out of Memory!!!\n"); @@ -4689,6 +4531,7 @@ API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_ metadata_x *ptr4 = NULL; permission_x *ptr5 = NULL; image_x *ptr6 = NULL; + appcontrol_x *ptr7 = NULL; const char* user_pkg_parser = NULL; /*get system locale*/ @@ -4777,6 +4620,12 @@ API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_ ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo); tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed"); + /*store app control info*/ + snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid); + ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo); + tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed"); + + memset(query, '\0', MAX_QUERY_LEN); if (appinfo->uiapp_info->label) { LISTHEAD(appinfo->uiapp_info->label, ptr2); appinfo->uiapp_info->label = ptr2; @@ -4801,6 +4650,10 @@ API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_ LISTHEAD(appinfo->uiapp_info->image, ptr6); appinfo->uiapp_info->image = ptr6; } + if (appinfo->uiapp_info->appcontrol) { + LISTHEAD(appinfo->uiapp_info->appcontrol, ptr7); + appinfo->uiapp_info->appcontrol = ptr7; + } ret = app_func((void *)appinfo, user_data); if (ret < 0) break; @@ -4833,6 +4686,10 @@ API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_ ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo); tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed"); + snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->svcapp_info->appid); + ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo); + tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed"); + if (appinfo->svcapp_info->label) { LISTHEAD(appinfo->svcapp_info->label, ptr2); appinfo->svcapp_info->label = ptr2; @@ -4853,6 +4710,10 @@ API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_ LISTHEAD(appinfo->svcapp_info->permission, ptr5); appinfo->svcapp_info->permission = ptr5; } + if (appinfo->svcapp_info->appcontrol) { + LISTHEAD(appinfo->svcapp_info->appcontrol, ptr7); + appinfo->svcapp_info->appcontrol = ptr7; + } ret = app_func((void *)appinfo, user_data); if (ret < 0) break; @@ -4902,6 +4763,11 @@ API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_ ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo); tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed"); + /*store app control info*/ + snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid); + ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo); + tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed"); + if (appinfo->uiapp_info->label) { LISTHEAD(appinfo->uiapp_info->label, ptr2); appinfo->uiapp_info->label = ptr2; @@ -4926,6 +4792,10 @@ API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_ LISTHEAD(appinfo->uiapp_info->image, ptr6); appinfo->uiapp_info->image = ptr6; } + if (appinfo->uiapp_info->appcontrol) { + LISTHEAD(appinfo->uiapp_info->appcontrol, ptr7); + appinfo->uiapp_info->appcontrol = ptr7; + } ret = app_func((void *)appinfo, user_data); if (ret < 0) break; @@ -4955,6 +4825,10 @@ API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_ ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo); tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed"); + snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->svcapp_info->appid); + ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo); + tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed"); + if (appinfo->svcapp_info->label) { LISTHEAD(appinfo->svcapp_info->label, ptr2); appinfo->svcapp_info->label = ptr2; @@ -4975,6 +4849,10 @@ API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_ LISTHEAD(appinfo->svcapp_info->permission, ptr5); appinfo->svcapp_info->permission = ptr5; } + if (appinfo->svcapp_info->appcontrol) { + LISTHEAD(appinfo->svcapp_info->appcontrol, ptr7); + appinfo->svcapp_info->appcontrol = ptr7; + } ret = app_func((void *)appinfo, user_data); if (ret < 0) break; @@ -5117,6 +4995,7 @@ API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_fun metadata_x *tmp4 = NULL; permission_x *tmp5 = NULL; image_x *tmp6 = NULL; + appcontrol_x *tmp7 = NULL; const char *user_pkg_parser = NULL; /*get system locale*/ @@ -5200,13 +5079,18 @@ API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_fun snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid); ret = __exec_db_query(GET_DB(manifest_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'", ptr1->appid); ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo); tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed"); + /*store app control info*/ + snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", ptr1->appid); + ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo); + tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed"); + if (appinfo->uiapp_info->label) { LISTHEAD(appinfo->uiapp_info->label, tmp1); appinfo->uiapp_info->label = tmp1; @@ -5231,6 +5115,10 @@ API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_fun LISTHEAD(appinfo->uiapp_info->image, tmp6); appinfo->uiapp_info->image = tmp6; } + if (appinfo->uiapp_info->appcontrol) { + LISTHEAD(appinfo->uiapp_info->appcontrol, tmp7); + appinfo->uiapp_info->appcontrol = tmp7; + } ret = app_func((void *)appinfo, user_data); if (ret < 0) break; @@ -5267,6 +5155,10 @@ API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_fun ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo); tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed"); + snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", ptr2->appid); + ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo); + tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed"); + if (appinfo->svcapp_info->label) { LISTHEAD(appinfo->svcapp_info->label, tmp1); appinfo->svcapp_info->label = tmp1; @@ -5287,6 +5179,10 @@ API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_fun LISTHEAD(appinfo->svcapp_info->permission, tmp5); appinfo->svcapp_info->permission = tmp5; } + if (appinfo->svcapp_info->appcontrol) { + LISTHEAD(appinfo->svcapp_info->appcontrol, tmp7); + appinfo->svcapp_info->appcontrol = tmp7; + } ret = app_func((void *)appinfo, user_data); if (ret < 0) break; @@ -5334,6 +5230,7 @@ API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgri metadata_x *tmp4 = NULL; permission_x *tmp5 = NULL; image_x *tmp6 = NULL; + appcontrol_x *tmp7 = NULL; char query[MAX_QUERY_LEN] = {'\0'}; const char* user_pkg_parser = NULL; @@ -5425,6 +5322,11 @@ API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgri ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo); tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed"); + /*store app control info*/ + snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid); + ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo); + tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed"); + switch (appinfo->app_component) { case PMINFO_UI_APP: if (appinfo->uiapp_info->label) { @@ -5451,6 +5353,10 @@ API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgri LISTHEAD(appinfo->uiapp_info->image, tmp6); appinfo->uiapp_info->image = tmp6; } + if (appinfo->uiapp_info->appcontrol) { + LISTHEAD(appinfo->uiapp_info->appcontrol, tmp7); + appinfo->uiapp_info->appcontrol = tmp7; + } break; case PMINFO_SVC_APP: if (appinfo->svcapp_info->label) { @@ -5473,6 +5379,10 @@ API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgri LISTHEAD(appinfo->svcapp_info->permission, tmp5); appinfo->svcapp_info->permission = tmp5; } + if (appinfo->svcapp_info->appcontrol) { + LISTHEAD(appinfo->svcapp_info->appcontrol, tmp7); + appinfo->svcapp_info->appcontrol = tmp7; + } break; default: break; @@ -5636,6 +5546,76 @@ API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label) return PMINFO_R_OK; } +static char *_get_localed_label(const char *appid, const char *locale, uid_t uid) +{ + char *result = NULL; + char *query = NULL; + sqlite3_stmt *stmt = NULL; + sqlite3 *db = NULL; + char *val; + char *manifest_db; + + manifest_db = getUserPkgParserDBPathUID(uid); + if (manifest_db == NULL) { + _LOGE("Failed to get manifest db path"); + goto err; + } + + if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) { + _LOGE("DB open fail\n"); + goto err; + } + + query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale); + if (query == NULL) { + _LOGE("Out of memory"); + goto err; + } + + if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) { + _LOGE("prepare_v2 fail\n"); + goto err; + } + + if (sqlite3_step(stmt) == SQLITE_ROW) { + val = (char *)sqlite3_column_text(stmt, 0); + if (val != NULL) + result = strdup(val); + } + +err: + sqlite3_finalize(stmt); + sqlite3_free(query); + sqlite3_close(db); + + return result; +} + +API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label) +{ + char *val; + int ret; + + retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL"); + + val = _get_localed_label(appid, locale, uid); + if (val == NULL) + val = _get_localed_label(appid, DEFAULT_LOCALE, uid); + + if (val == NULL) { + ret = PMINFO_R_ERROR; + } else { + *label = val; + ret = PMINFO_R_OK; + } + + return ret; +} + +API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label) +{ + return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label); +} API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component) { @@ -5911,6 +5891,106 @@ API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char return PMINFO_R_OK; } +API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n"); + retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + if (info->app_component != PMINFO_UI_APP) + return PMINFO_R_EINVAL; + + if (info->uiapp_info->launch_mode == NULL) + return PMINFO_R_ERROR; + + *mode = (char *)(info->uiapp_info->launch_mode); + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access) +{ + retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n"); + retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n"); + retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); + retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); + + int ret = PMINFO_R_OK; + char *query = NULL; + sqlite3_stmt *stmt = NULL; + + /*open db*/ + ret = __open_manifest_db(uid); + retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB); + + /*Start constructing query*/ + query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type); + + /*prepare query*/ + ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL); + tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query); + + /*step query*/ + ret = sqlite3_step(stmt); + tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found"); + + *appid = strdup((char *)sqlite3_column_text(stmt, 0)); + *access = strdup((char *)sqlite3_column_text(stmt, 2)); + + ret = PMINFO_R_OK; + +catch: + sqlite3_free(query); + sqlite3_finalize(stmt); + __close_manifest_db(); + return ret; +} + +API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access) +{ + return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access); +} + +API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid) +{ + retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n"); + retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); + + int ret = PMINFO_R_OK; + char *query = NULL; + sqlite3_stmt *stmt = NULL; + + /*open db*/ + ret = __open_manifest_db(uid); + retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB); + + /*Start constructing query*/ + query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid); + + /*prepare query*/ + ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL); + tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query); + + /*step query*/ + ret = sqlite3_step(stmt); + tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found"); + + *appid = strdup((char *)sqlite3_column_text(stmt, 0)); + + ret = PMINFO_R_OK; + +catch: + sqlite3_free(query); + sqlite3_finalize(stmt); + __close_manifest_db(); + return ret; +} + +API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid) +{ + return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid); +} + API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_permission_list_cb permission_func, void *user_data) { @@ -5983,371 +6063,40 @@ API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle, return PMINFO_R_OK; } -API int pkgmgrinfo_usr_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle, - pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data, uid_t uid) -{ - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL"); - int i = 0; - int ret = -1; - int oc = 0; - int mc = 0; - int uc = 0; - int sc = 0; - char *pkgid = NULL; - char *manifest = NULL; - char **operation = NULL; - char **uri = NULL; - char **mime = NULL; - char **subapp = NULL; - appcontrol_x *appcontrol = NULL; - manifest_x *mfx = NULL; - operation_x *op = NULL; - uri_x *ui = NULL; - mime_x *mi = NULL; - subapp_x *sa = NULL; - pkgmgrinfo_app_component component; - pkgmgrinfo_appcontrol_x *ptr = NULL; - ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); - if (ret < 0) { - _LOGE("Failed to get package name\n"); - return PMINFO_R_ERROR; - } - ret = pkgmgrinfo_appinfo_get_component(handle, &component); - if (ret < 0) { - _LOGE("Failed to get app component name\n"); - return PMINFO_R_ERROR; - } - manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid); - if (manifest == NULL) { - _LOGE("Failed to fetch package manifest file\n"); - return PMINFO_R_ERROR; - } - mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid); - if (mfx == NULL) { - _LOGE("Failed to parse package manifest file\n"); - free(manifest); - manifest = NULL; - return PMINFO_R_ERROR; - } - free(manifest); - ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x)); - if (ptr == NULL) { - _LOGE("Out of Memory!!!\n"); - pkgmgr_parser_free_manifest_xml(mfx); - return PMINFO_R_ERROR; - } - /*Get Operation, Uri, Mime*/ - switch (component) { - case PMINFO_UI_APP: - if (mfx->uiapplication) { - if (mfx->uiapplication->appsvc) { - appcontrol = mfx->uiapplication->appsvc; - } - } - break; - case PMINFO_SVC_APP: - if (mfx->serviceapplication) { - if (mfx->serviceapplication->appsvc) { - appcontrol = mfx->serviceapplication->appsvc; - } - } - break; - default: - break; - } - for (; appcontrol; appcontrol = appcontrol->next) { - op = appcontrol->operation; - for (; op; op = op->next) - oc = oc + 1; - op = appcontrol->operation; - - ui = appcontrol->uri; - for (; ui; ui = ui->next) - uc = uc + 1; - ui = appcontrol->uri; - - mi = appcontrol->mime; - for (; mi; mi = mi->next) - mc = mc + 1; - mi = appcontrol->mime; - - sa = appcontrol->subapp; - for (; sa; sa = sa->next) - sc = sc + 1; - sa = appcontrol->subapp; - - operation = (char **)calloc(oc, sizeof(char *)); - for (i = 0; i < oc; i++) { - operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1); - op = op->next; - } - - uri = (char **)calloc(uc, sizeof(char *)); - for (i = 0; i < uc; i++) { - uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1); - ui = ui->next; - } - - mime = (char **)calloc(mc, sizeof(char *)); - for (i = 0; i < mc; i++) { - mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1); - mi = mi->next; - } - - subapp = (char **)calloc(sc, sizeof(char *)); - for (i = 0; i < sc; i++) { - subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1); - sa = sa->next; - } - - /*populate appcontrol handle*/ - ptr->operation_count = oc; - ptr->uri_count = uc; - ptr->mime_count = mc; - ptr->subapp_count = sc; - ptr->operation = operation; - ptr->uri = uri; - ptr->mime = mime; - ptr->subapp = subapp; - - ret = appcontrol_func((void *)ptr, user_data); - for (i = 0; i < oc; i++) { - if (operation[i]) { - free(operation[i]); - operation[i] = NULL; - } - } - if (operation) { - free(operation); - operation = NULL; - } - for (i = 0; i < uc; i++) { - if (uri[i]) { - free(uri[i]); - uri[i] = NULL; - } - } - if (uri) { - free(uri); - uri = NULL; - } - for (i = 0; i < mc; i++) { - if (mime[i]) { - free(mime[i]); - mime[i] = NULL; - } - } - if (mime) { - free(mime); - mime = NULL; - } - for (i = 0; i < sc; i++) { - if (subapp[i]) { - free(subapp[i]); - subapp[i] = NULL; - } - } - if (subapp) { - free(subapp); - subapp = NULL; - } - if (ret < 0) - break; - uc = 0; - mc = 0; - oc = 0; - sc = 0; - } - pkgmgr_parser_free_manifest_xml(mfx); - if (ptr) { - free(ptr); - ptr = NULL; - } - return PMINFO_R_OK; -} - API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data) { retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL"); - int i = 0; - int ret = -1; - int oc = 0; - int mc = 0; - int uc = 0; - int sc = 0; - char *pkgid = NULL; - char *manifest = NULL; - char **operation = NULL; - char **uri = NULL; - char **mime = NULL; - char **subapp = NULL; - appcontrol_x *appcontrol = NULL; - manifest_x *mfx = NULL; - operation_x *op = NULL; - uri_x *ui = NULL; - mime_x *mi = NULL; - subapp_x *sa = NULL; + int ret; + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + appcontrol_x *appcontrol; pkgmgrinfo_app_component component; - pkgmgrinfo_appcontrol_x *ptr = NULL; - ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); - if (ret < 0) { - _LOGE("Failed to get package name\n"); - return PMINFO_R_ERROR; - } ret = pkgmgrinfo_appinfo_get_component(handle, &component); if (ret < 0) { _LOGE("Failed to get app component name\n"); return PMINFO_R_ERROR; } - manifest = pkgmgr_parser_get_manifest_file(pkgid); - if (manifest == NULL) { - _LOGE("Failed to fetch package manifest file\n"); - return PMINFO_R_ERROR; - } - mfx = pkgmgr_parser_process_manifest_xml(manifest); - if (mfx == NULL) { - _LOGE("Failed to parse package manifest file\n"); - free(manifest); - manifest = NULL; - return PMINFO_R_ERROR; - } - free(manifest); - ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x)); - if (ptr == NULL) { - _LOGE("Out of Memory!!!\n"); - pkgmgr_parser_free_manifest_xml(mfx); - return PMINFO_R_ERROR; - } - /*Get Operation, Uri, Mime*/ switch (component) { case PMINFO_UI_APP: - if (mfx->uiapplication) { - if (mfx->uiapplication->appsvc) { - appcontrol = mfx->uiapplication->appsvc; - } - } + if (info->uiapp_info == NULL) + return PMINFO_R_EINVAL; + appcontrol = info->uiapp_info->appcontrol; break; case PMINFO_SVC_APP: - if (mfx->serviceapplication) { - if (mfx->serviceapplication->appsvc) { - appcontrol = mfx->serviceapplication->appsvc; - } - } + if (info->svcapp_info == NULL) + return PMINFO_R_EINVAL; + appcontrol = info->svcapp_info->appcontrol; break; default: break; } for (; appcontrol; appcontrol = appcontrol->next) { - op = appcontrol->operation; - for (; op; op = op->next) - oc = oc + 1; - op = appcontrol->operation; - - ui = appcontrol->uri; - for (; ui; ui = ui->next) - uc = uc + 1; - ui = appcontrol->uri; - - mi = appcontrol->mime; - for (; mi; mi = mi->next) - mc = mc + 1; - mi = appcontrol->mime; - - sa = appcontrol->subapp; - for (; sa; sa = sa->next) - sc = sc + 1; - sa = appcontrol->subapp; - - operation = (char **)calloc(oc, sizeof(char *)); - for (i = 0; i < oc; i++) { - operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1); - op = op->next; - } - - uri = (char **)calloc(uc, sizeof(char *)); - for (i = 0; i < uc; i++) { - uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1); - ui = ui->next; - } - - mime = (char **)calloc(mc, sizeof(char *)); - for (i = 0; i < mc; i++) { - mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1); - mi = mi->next; - } - - subapp = (char **)calloc(sc, sizeof(char *)); - for (i = 0; i < sc; i++) { - subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1); - sa = sa->next; - } - - /*populate appcontrol handle*/ - ptr->operation_count = oc; - ptr->uri_count = uc; - ptr->mime_count = mc; - ptr->subapp_count = sc; - ptr->operation = operation; - ptr->uri = uri; - ptr->mime = mime; - ptr->subapp = subapp; - - ret = appcontrol_func((void *)ptr, user_data); - for (i = 0; i < oc; i++) { - if (operation[i]) { - free(operation[i]); - operation[i] = NULL; - } - } - if (operation) { - free(operation); - operation = NULL; - } - for (i = 0; i < uc; i++) { - if (uri[i]) { - free(uri[i]); - uri[i] = NULL; - } - } - if (uri) { - free(uri); - uri = NULL; - } - for (i = 0; i < mc; i++) { - if (mime[i]) { - free(mime[i]); - mime[i] = NULL; - } - } - if (mime) { - free(mime); - mime = NULL; - } - for (i = 0; i < sc; i++) { - if (subapp[i]) { - free(subapp[i]); - subapp[i] = NULL; - } - } - if (subapp) { - free(subapp); - subapp = NULL; - } + ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data); if (ret < 0) break; - uc = 0; - mc = 0; - oc = 0; - sc = 0; - } - pkgmgr_parser_free_manifest_xml(mfx); - if (ptr) { - free(ptr); - ptr = NULL; } + return PMINFO_R_OK; } @@ -6541,6 +6290,32 @@ API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode return PMINFO_R_OK; } +API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL"); + retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL"); + + category_x *ptr = NULL; + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + *exist = 0; + + ptr = info->uiapp_info->category; + + for (; ptr; ptr = ptr->next) { + if (ptr->name) { + if (strcasecmp(ptr->name, category) == 0) + { + *exist = 1; + break; + } + } + } + + return PMINFO_R_OK; +} + API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle) { retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); @@ -6774,12 +6549,10 @@ API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, where[sizeof(where) - 1] = '\0'; } } - _LOGE("where = %s\n", where); if (strlen(where) > 0) { strncat(query, where, sizeof(query) - strlen(query) - 1); query[sizeof(query) - 1] = '\0'; } - _LOGE("query = %s\n", query); /*Execute Query*/ if (SQLITE_OK != @@ -6862,12 +6635,10 @@ API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_ where[sizeof(where) - 1] = '\0'; } } - _LOGE("where = %s\n", where); if (strlen(where) > 0) { strncat(query, where, sizeof(query) - strlen(query) - 1); query[sizeof(query) - 1] = '\0'; } - _LOGE("query = %s\n", query); /*To get filtered list*/ pkgmgr_pkginfo_x *info = NULL; pkgmgr_pkginfo_x *filtinfo = NULL; @@ -6953,6 +6724,7 @@ API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_ /*If the callback func return < 0 we break and no more call back is called*/ while(ptr1 != NULL) { + appinfo->package = strdup(ptr1->package); appinfo->locale = strdup(locale); appinfo->uiapp_info = ptr1; appinfo->app_component = PMINFO_UI_APP; @@ -6969,6 +6741,7 @@ API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_ /*If the callback func return < 0 we break and no more call back is called*/ while(ptr2 != NULL) { + appinfo->package = strdup(ptr2->package); appinfo->locale = strdup(locale); appinfo->svcapp_info = ptr2; appinfo->app_component = PMINFO_SVC_APP; @@ -7102,11 +6875,9 @@ API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metada strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1); } } - _LOGE("where = %s (%d)\n", where, strlen(where)); if (strlen(where) > 0) { strncat(query, where, sizeof(query) - strlen(query) - 1); } - _LOGE("query = %s (%d)\n", query, strlen(query)); /*To get filtered list*/ info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x)); tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n"); @@ -7225,7 +6996,7 @@ API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle) return PMINFO_R_OK; } -API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle) +API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle, uid_t uid) { retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n"); retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n"); @@ -7235,15 +7006,13 @@ API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_ char query[MAX_QUERY_LEN] = {'\0'}; int exist = 0; int i = 0; - const char* user_pkg_cert = NULL; /*Open db.*/ - user_pkg_cert = getUserPkgCertDBPath(); - ret = db_util_open_with_options(user_pkg_cert, &GET_DB(cert_db), - SQLITE_OPEN_READWRITE, NULL); + ret = __open_cert_db(uid,"r"); if (ret != SQLITE_OK) { - _LOGE("connect db [%s] failed!\n", user_pkg_cert); - return PMINFO_R_ERROR; + _LOGE("connect db [%s] failed!\n"); + ret = PMINFO_R_ERROR; + goto err; } _check_create_Cert_db(GET_DB(cert_db)); /*validate pkgid*/ @@ -7272,7 +7041,10 @@ API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_ } for (i = 0; i < MAX_CERT_TYPE; i++) { memset(query, '\0', MAX_QUERY_LEN); - snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]); + if (uid == GLOBAL_USER || uid == ROOT_UID) + snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d", (certinfo->cert_id)[i]); + else + snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d and for_all_users=%d", (certinfo->cert_id)[i], certinfo->for_all_users); ret = __exec_certinfo_query(query, (void *)certinfo); if (ret == -1) { _LOGE("Cert Info DB Information retrieval failed\n"); @@ -7349,7 +7121,7 @@ API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_i return PMINFO_R_OK; } -API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle) +API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle, uid_t uid) { retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n"); retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n"); @@ -7377,22 +7149,21 @@ API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h ha info->pkgid = strdup(pkgid); /*Open db.*/ - ret = db_util_open_with_options(getUserPkgCertDBPath(), &GET_DB(cert_db), - SQLITE_OPEN_READWRITE, NULL); - if (ret != SQLITE_OK) { - _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath()); + ret =__open_cert_db(uid, "w"); + if (ret != 0) { ret = PMINFO_R_ERROR; + _LOGE("Failed to open cert db \n"); goto err; } _check_create_Cert_db(GET_DB(cert_db)); /*Begin Transaction*/ ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL); - if (ret != SQLITE_OK) { - _LOGE("Failed to begin transaction\n"); + if (ret == -1) { + _LOGE("Failed to begin transaction %s\n"); ret = PMINFO_R_ERROR; goto err; } - _LOGE("Transaction Begin\n"); + /*Check if request is to insert/update*/ snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid); if (SQLITE_OK != @@ -7407,7 +7178,7 @@ API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h ha /*Update request. We cant just issue update query directly. We need to manage index table also. Hence it is better to delete and insert again in case of update*/ - ret = __delete_certinfo(pkgid); + ret = __delete_certinfo(pkgid, uid); if (ret < 0) _LOGE("Certificate Deletion Failed\n"); } @@ -7459,7 +7230,6 @@ API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h ha (info->cert_id)[i] = indexinfo->cert_id; (info->is_new)[i] = is_new; (info->ref_count)[i] = indexinfo->cert_ref_count; - _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count); indexinfo->cert_id = 0; indexinfo->cert_ref_count = 0; is_new = 0; @@ -7531,7 +7301,7 @@ API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h ha ret = PMINFO_R_ERROR; goto err; } - _LOGE("Transaction Commit and End\n"); + ret = PMINFO_R_OK; err: __close_cert_db(); @@ -7572,7 +7342,7 @@ API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid) retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n"); int ret = -1; /*Open db.*/ - ret = __open_cert_db(uid); + ret = __open_cert_db(uid, "w"); if (ret != 0) { _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid)); ret = PMINFO_R_ERROR; @@ -7587,7 +7357,7 @@ API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid) goto err; } _LOGE("Transaction Begin\n"); - ret = __delete_certinfo(pkgid); + ret = __delete_certinfo(pkgid, uid); if (ret < 0) { _LOGE("Certificate Deletion Failed\n"); } else { @@ -7982,7 +7752,7 @@ API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * typ } snprintf(query, MAX_QUERY_LEN, - "select appinfo.package_name, datacontrol.access from appinfo, datacontrol where datacontrol.id=appinfo.unique_id and datacontrol.provider_id = '%s' and datacontrol.type='%s' COLLATE NOCASE", + "select appinfo.package_name, datacontrol.access from appinfo, datacontrol where datacontrol.id=appinfo.unique_id and datacontrol.providerid = '%s' and datacontrol.type='%s' COLLATE NOCASE", providerid, type); if (SQLITE_OK != @@ -8074,7 +7844,6 @@ API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h han retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n"); char *val = NULL; int ret = 0; - char *noti_string = NULL; int len = 0; char query[MAX_QUERY_LEN] = {'\0'}; char *errmsg = NULL; @@ -8098,22 +7867,12 @@ API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h han else snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid); - if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) { + ret = sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg); + sqlite3_close(pkgmgr_parser_db); + if (ret != SQLITE_OK) { _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg); free(errmsg); - sqlite3_close(pkgmgr_parser_db); - return PMINFO_R_ERROR; - }else{ - sqlite3_close(pkgmgr_parser_db); - len = strlen((char *)info->uiapp_info->appid) + 8; - noti_string = calloc(1, len); - if (noti_string == NULL){ - return PMINFO_R_ERROR; - } - snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid); - vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string); - vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed - free(noti_string); + return PMINFO_R_ERROR; } } return PMINFO_R_OK;