From 9bae27e991220ce00787f86bc010ba3d26fac24c Mon Sep 17 00:00:00 2001 From: VBS Date: Thu, 12 Nov 2015 09:47:19 +0900 Subject: [PATCH] implement TEP install, update [app-installer][pkgmgr-info][pkgmgr-server][pkgmgr-tool][slp-pkgmgr] Change-Id: I7960878b14694d1011cf75fa16d8aa522272e66e Signed-off-by: Junghyun Yeon --- parser/pkgmgr_parser.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++ parser/pkgmgr_parser.h | 62 ++++++++++++++++++++++++++++++ parser/pkgmgr_parser_db.c | 97 ++++++++++++++++++++++++++++++++++++++++++++--- parser/pkgmgr_parser_db.h | 27 +++++++++++++ src/pkgmgrinfo_basic.c | 2 + 5 files changed, 277 insertions(+), 6 deletions(-) diff --git a/parser/pkgmgr_parser.c b/parser/pkgmgr_parser.c index 7e7eb4c..3683c22 100644 --- a/parser/pkgmgr_parser.c +++ b/parser/pkgmgr_parser.c @@ -2088,6 +2088,101 @@ API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid } /* These APIs are intended to call parser directly */ +API int pkgmgr_parser_parse_manifest_for_installation_withtep(const char *manifest, const char *tep_path, char *const tagv[]) +{ + retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL"); + _LOGD("parsing manifest for installation: %s\n", manifest); + + manifest_x *mfx = NULL; + int ret = -1; + + xmlInitParser(); + mfx = pkgmgr_parser_process_manifest_xml(manifest); + retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL"); + + _LOGD("Parsing Finished\n"); + + __add_preload_info(mfx, manifest, GLOBAL_USER); + + _LOGD("Added preload infomation\n"); + + __ps_process_tag(mfx, tagv); + + if (tep_path != NULL && strlen(tep_path) != 0) + mfx->tep_name = strdup(tep_path); + else + mfx->tep_name = NULL; + + ret = pkgmgr_parser_insert_manifest_info_in_db(mfx); + retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed"); + + _LOGD("DB Insert Success\n"); + + __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL); + ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL); + if (ret == -1) + _LOGD("Creating metadata parser failed\n"); + + ret = __ps_process_category_parser(mfx, ACTION_INSTALL); + if (ret == -1) + _LOGD("Creating category parser failed\n"); + + pkgmgr_parser_free_manifest_xml(mfx); + _LOGD("Free Done\n"); + xmlCleanupParser(); + + return PMINFO_R_OK; +} + +API int pkgmgr_parser_parse_usr_manifest_for_installation_withtep(const char *manifest, const char *tep_path, uid_t uid, char *const tagv[]) +{ + retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL"); + _LOGD("parsing manifest for installation: %s\n", manifest); + manifest_x *mfx = NULL; + int ret = -1; + + xmlInitParser(); + mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid); + retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL"); + + _LOGD("Parsing Finished\n"); + + __ps_process_tag(mfx, tagv); + + if (tep_path != NULL && strlen(tep_path) != 0) + mfx->tep_name = strdup(tep_path); + else + mfx->tep_name = NULL; + + ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid); + retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed"); + + _LOGD("DB Insert Success\n"); + + __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL); + ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL); + if (ret == -1) + _LOGD("Creating metadata parser failed\n"); + ret = __ps_process_category_parser(mfx, ACTION_INSTALL); + if (ret == -1) + _LOGD("Creating category parser failed\n"); + + pkgmgr_parser_free_manifest_xml(mfx); + _LOGD("Free Done\n"); + xmlCleanupParser(); + + return PMINFO_R_OK; +} + +API int pkgmgr_parser_usr_update_tep(const char *pkgid, const char *tep_path, uid_t uid) +{ + return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, uid); +} + +API int pkgmgr_parser_update_tep(const char *pkgid, const char *tep_path) +{ + return pkgmgr_parser_update_tep_info_in_db(pkgid, tep_path); +} API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]) { diff --git a/parser/pkgmgr_parser.h b/parser/pkgmgr_parser.h index 3df85a7..f9402e1 100644 --- a/parser/pkgmgr_parser.h +++ b/parser/pkgmgr_parser.h @@ -128,6 +128,68 @@ int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *co int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[]); /** + * @fn int pkgmgr_parser_parse_manifest_for_installation_withtep(const char *manifest, const char *tep_path, char *const tagv[]) + * @fn int pkgmgr_parser_parse_usr_manifest_for_installation_withtep(const char *manifest, const char *tep_path, uid_t uid, char *const tagv[]) + * @brief This API parses the manifest file of the package after installation and stores the parsed data and tep information in DB if exists. + * + * @par This API is for package-manager installer backends. + * @par Sync (or) Async : Synchronous API + * + * @param[in] manifest pointer to package manifest file + * @param[in] uid the addressee user id of the instruction + * @param[in] tagv array of xml tags or NULL + * @return 0 if success, error code(<0) if fail + * @retval PMINFO_R_OK success + * @retval PMINFO_R_EINVAL invalid argument + * @retval PMINFO_R_ERROR internal error + * @pre None + * @post None + * @code +static int parse_manifest_file_for_installation(const char *manifest, const char *tep_path) +{ + int ret = 0; + ret = pkgmgr_parser_parse_manifest_for_installation_withtep(manifest, tep_path, NULL); + if (ret) + return -1; + return 0; +} + * @endcode + */ +int pkgmgr_parser_parse_manifest_for_installation_withtep(const char *manifest, const char *tep_path, char *const tagv[]); +int pkgmgr_parser_parse_usr_manifest_for_installation_withtep(const char *manifest, const char *tep_path, uid_t uid, char *const tagv[]); + +/** + * @fn int pkgmgr_parser_update_tep(const char* pkgid, const char * tep_path) + * @fn int pkgmgr_parser_usr_update_tep(const char* pkgid, const char* tep_path, uid_t uid) + * @brief This API updates tep path information stored in DB. + * + * @par This API is for package-manager installer backends. + * @par Sync (or) Async : Synchronous API + * + * @param[in] pkgid pointer to package ID + * @param[in]tep_path pointer to path of TEP file + * @param[in] uid the addressee user id of the instruction + * @return 0 if success, error code(<0) if fail + * @retval PMINFO_R_OK success + * @retval PMINFO_R_EINVAL invalid argument + * @retval PMINFO_R_ERROR internal error + * @pre None + * @post None + * @code +static int update_tep_info_for_upgrade(const char *pkgid, const char *tep_path) +{ + int ret = 0; + ret = pkgmgr_parser_update_tep(pkgid, tep_path); + if (ret) + return -1; + return 0; +} + * @endcode + */ +int pkgmgr_parser_update_tep(const char* pkgid, const char* tep_path); +int pkgmgr_parser_usr_update_tep(const char* pkgid, const char* tep_path, uid_t uid); + +/** * @fn int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[]) * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]) * @brief This API parses the manifest file of the package after upgrade and stores the data in DB. diff --git a/parser/pkgmgr_parser_db.c b/parser/pkgmgr_parser_db.c index b025fce..60e705b 100644 --- a/parser/pkgmgr_parser_db.c +++ b/parser/pkgmgr_parser_db.c @@ -70,6 +70,7 @@ sqlite3 *pkgmgr_cert_db; "package_type text DEFAULT 'rpm', " \ "package_version text, " \ "package_api_version text, " \ + "package_tep_name text, " \ "install_location text, " \ "package_size text, " \ "package_removable text DEFAULT 'true', " \ @@ -141,6 +142,7 @@ sqlite3 *pkgmgr_cert_db; "app_support_disable text DEFAULT 'false', " \ "component_type text, " \ "package text not null, " \ + "app_tep_name text, " \ "FOREIGN KEY(package) " \ "REFERENCES package_info(package) " \ "ON DELETE CASCADE)" @@ -836,12 +838,13 @@ static int __insert_application_info(manifest_x *mfx) app = (application_x *)tmp->data; if (app == NULL) continue; + snprintf(query, MAX_QUERY_LEN, "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \ "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \ "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\ - "app_preload, app_submode, app_submode_mainid, app_launch_mode, app_ui_gadget, app_support_disable, component_type, package) " \ - "values('%s', '%s', '%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\ + "app_preload, app_submode, app_submode_mainid, app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, app_tep_name) " \ + "values('%s', '%s', '%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\ app->appid, app->component_type, app->exec, @@ -869,7 +872,8 @@ static int __insert_application_info(manifest_x *mfx) app->ui_gadget, mfx->support_disable, app->component_type, - mfx->package); + mfx->package, + __get_str(mfx->tep_name)); ret = __exec_query(query); if (ret == -1) { @@ -1174,14 +1178,15 @@ static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid) /*Insert in the package_info DB*/ snprintf(query, MAX_QUERY_LEN, - "insert into package_info(package, package_type, package_version, package_api_version, install_location, package_size, " \ + "insert into package_info(package, package_type, package_version, package_api_version, package_tep_name, install_location, package_size, " \ "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \ "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path, package_support_disable) " \ - "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\ + "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\ mfx->package, mfx->type, mfx->version, __get_str(mfx->api_version), + __get_str(mfx->tep_name), __get_str(mfx->installlocation), __get_str(mfx->package_size), mfx->removable, @@ -1577,7 +1582,7 @@ API int pkgmgr_parser_initialize_db(uid_t uid) _LOGD("package cert index info DB initialization failed\n"); return ret; } - + if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) { _LOGD("Failed to change cert db permission\n"); } @@ -1782,6 +1787,86 @@ err: return ret; } +API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path) +{ + return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, GLOBAL_USER); +} + +API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid) +{ + if (pkgid == NULL || tep_path == NULL) { + _LOGE("invalid parameter"); + return -1; + } + + int ret = -1; + char *query = NULL; + + ret = pkgmgr_parser_check_and_create_db(uid); + if (ret == -1) { + _LOGD("Failed to open DB\n"); + return ret; + } + ret = pkgmgr_parser_initialize_db(uid); + if (ret == -1) + goto err; + + /*Begin transaction*/ + ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL); + if (ret != SQLITE_OK) { + _LOGD("Failed to begin transaction\n"); + ret = -1; + goto err; + } + _LOGD("Transaction Begin\n"); + + + /* Updating TEP info in "package_info" table */ + query = sqlite3_mprintf("UPDATE package_info "\ + "SET package_tep_name = %Q "\ + "WHERE package = %Q", tep_path, pkgid); + + ret = __exec_query(query); + sqlite3_free(query); + if (ret != SQLITE_OK) { + ret = PM_PARSER_R_ERROR; + _LOGE("sqlite exec failed to insert entries into package_info!!"); + goto err; + } + + /* Updating TEP info in "package_app_info" table */ + query = sqlite3_mprintf("UPDATE package_app_info "\ + "SET app_tep_name = %Q "\ + "WHERE package = %Q", tep_path, pkgid); + + ret = __exec_query(query); + sqlite3_free(query); + if (ret != SQLITE_OK) { + ret = PM_PARSER_R_ERROR; + _LOGE("sqlite exec failed to insert entries into package_app_info!!"); + goto err; + } + + /*Commit transaction*/ + ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL); + if (ret != SQLITE_OK) { + _LOGE("Failed to commit transaction, Rollback now\n"); + ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL); + if (ret != SQLITE_OK) + _LOGE("Failed to Rollback\n"); + + ret = PM_PARSER_R_ERROR; + goto err; + } + _LOGD("Transaction Commit and End\n"); + ret = PM_PARSER_R_OK; + +err: + pkgmgr_parser_close_db(); + return ret; +} + + API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid) { if (mfx == NULL) { diff --git a/parser/pkgmgr_parser_db.h b/parser/pkgmgr_parser_db.h index 6a9496f..2c145bb 100644 --- a/parser/pkgmgr_parser_db.h +++ b/parser/pkgmgr_parser_db.h @@ -105,6 +105,33 @@ int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx); int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid); /** + * @fn int pkgmgr_parser_update_tep_info_in_db(const char * pkgid, const char * tep_path) + * @fn int pkgmgr_parser_update_tep_info_in_usr_db(const char * pkgid, const char * tep_path,uid_t uid) + * @brief This API updates the tep info in db + * + * @par This API is for package-manager installer backends + * @par Sync (or) Async : Synchronous API + * + * @param[in] pkgid pointer to pkgid + * @param[in] tep_path path of tep file + * @return 0 if success, error code(<0) if fail + * @pre None + * @post None + * @code +static int update_tep_data(const char *pkgid, *tep_path) +{ + int ret = 0; + ret = pkgmgr_parser_update_tep_info_in_db(pkgid, tep_path); + if (ret < 0) + return -1; + return 0; +} + * @endcode + */ +int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path); +int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid); + +/** * @fn int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid) * @fn int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx) * @brief This API deletes the parsed manifest info from db diff --git a/src/pkgmgrinfo_basic.c b/src/pkgmgrinfo_basic.c index 51d8052..2b6fb5b 100644 --- a/src/pkgmgrinfo_basic.c +++ b/src/pkgmgrinfo_basic.c @@ -348,6 +348,8 @@ API void pkgmgrinfo_basic_free_package(package_x *package) free((void *)package->api_version); if (package->support_disable) free((void *)package->support_disable); + if (package->tep_name) + free((void *)package->tep_name); /*Free Icon*/ g_list_free_full(package->icon, __ps_free_icon); -- 2.7.4