- if (lbl->lang) {
- if (strcmp(lbl->lang, (char *)data) == 0) {
- *label = (char *)lbl->text;
- break;
- }
- }
- }
- for (tmp = lcns; tmp; tmp = tmp->next) {
- lcn = (license_x *)tmp->data;
- if (lcn == NULL)
- continue;
- if (lcn->lang) {
- if (strcmp(lcn->lang, (char *)data) == 0) {
- *license = (char *)lcn->text;
- break;
- }
- }
- }
-
- *icon = __find_icon(icns, (char *)data);
-
- for (tmp = dcns; tmp; tmp = tmp->next) {
- dcn = (description_x *)tmp->data;
- if (dcn == NULL)
- continue;
- if (dcn->lang) {
- if (strcmp(dcn->lang, (char *)data) == 0) {
- *description = (char *)dcn->text;
- break;
- }
- }
- }
- for (tmp = aths; tmp; tmp = tmp->next) {
- ath = (author_x *)tmp->data;
- if (ath == NULL)
- continue;
- if (ath->lang) {
- if (strcmp(ath->lang, (char *)data) == 0) {
- *author = (char *)ath->text;
- break;
- }
- }
- }
-
-}
-
-static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
-{
- GList *tmp;
- icon_x *icn;
- for (tmp = icns; tmp; tmp = tmp->next) {
- icn = (icon_x *)tmp->data;
- if (icn == NULL)
- continue;
- if (icn->section) {
- if (strcmp(icn->section, (char *)data) == 0) {
- *icon = (char *)icn->text;
- *resolution = (char *)icn->resolution;
- break;
- }
- }
- }
-}
-
-static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
-{
- GList *tmp;
- image_x *img;
- for (tmp = imgs; tmp; tmp = tmp->next) {
- img = (image_x *)tmp->data;
- if (img == NULL)
- continue;
- if (img->section) {
- if (strcmp(img->section, (char *)data) == 0) {
- *lang = (char *)img->lang;
- *image = (char *)img->text;
- break;
- }
- }
- }
-}
-
-static void __insert_pkglocale_info(gpointer data, gpointer userdata)
-{
- int ret = -1;
- char *label = NULL;
- char *icon = NULL;
- char *description = NULL;
- char *license = NULL;
- char *author = NULL;
- char *query = NULL;
-
- manifest_x *mfx = (manifest_x *)userdata;
- GList *lbl = mfx->label;
- GList *lcn = mfx->license;
- GList *icn = mfx->icon;
- GList *dcn = mfx->description;
- GList *ath = mfx->author;
-
- __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
- if (!label && !description && !icon && !license && !author)
- return;
-
- query = sqlite3_mprintf("INSERT INTO package_localized_info(package, package_locale, " \
- "package_label, package_icon, package_description, package_license, package_author) VALUES" \
- "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
- mfx->package,
- (char *)data,
- label,
- icon,
- description,
- license,
- author);
-
- ret = __exec_query(query);
- if (ret == -1)
- _LOGD("Package Localized Info DB Insert failed\n");
-
- sqlite3_free(query);
-}
-
-static void __insert_application_locale_info(gpointer data, gpointer userdata)
-{
- int ret = -1;
- char *label = NULL;
- char *icon = NULL;
- char *query = NULL;
- char *locale = (char *)data;
-
- application_x *app = (application_x *)userdata;
- GList *lbl = app->label;
- GList *icn = app->icon;
-
- __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
- if (!label && !icon)
- return;
-
- query = sqlite3_mprintf("INSERT INTO package_app_localized_info(app_id, app_locale, " \
- "app_label, app_icon) VALUES" \
- "(%Q, %Q, %Q, %Q)", app->appid, (char *)data,
- label, icon);
- ret = __exec_query(query);
- if (ret == -1)
- _LOGD("Package UiApp Localized Info DB Insert failed\n");
-
- sqlite3_free(query);
-
- /*insert ui app locale info to pkg locale to get mainapp data */
- if (strcasecmp(app->mainapp, "true") == 0) {
- query = sqlite3_mprintf("INSERT OR REPLACE INTO package_localized_info(package, package_locale, "
- "package_label, package_icon, package_description, package_license, package_author) VALUES"
- "(%Q, %Q, "
- "COALESCE((SELECT package_label FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
- "COALESCE((SELECT package_icon FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
- "(SELECT package_description FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
- "(SELECT package_license FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
- "(SELECT package_author FROM package_localized_info WHERE package=%Q AND package_locale=%Q))",
- app->package, locale,
- app->package, locale, label,
- app->package, locale, icon,
- app->package, locale,
- app->package, locale,
- app->package, locale);
-
- ret = __exec_query(query);
- if (ret == -1)
- _LOGE("Package Localized Info DB Insert failed");
- sqlite3_free(query);
- }
-}
-
-static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
-{
- int ret = -1;
- char *icon = NULL;
- char *resolution = NULL;
- char query[MAX_QUERY_LEN] = {'\0'};
-
- application_x *app = (application_x *)userdata;
- GList *icn = app->icon;
-
- __extract_icon_data(data, icn, &icon, &resolution);
- if (!icon && !resolution)
- return;
- sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO package_app_icon_section_info(app_id, " \
- "app_icon, app_icon_section, app_icon_resolution) VALUES " \
- "(%Q, %Q, %Q, %Q)", app->appid,
- icon, (char *)data, resolution);
-
- ret = __exec_query(query);
- if (ret == -1)
- _LOGD("Package UiApp Localized Info DB Insert failed\n");
-
-}
-
-static void __insert_application_image_info(gpointer data, gpointer userdata)
-{
- int ret = -1;
- char *lang = NULL;
- char *img = NULL;
- char query[MAX_QUERY_LEN] = {'\0'};
-
- application_x *app = (application_x *)userdata;
- GList *image = app->image;
-
- __extract_image_data(data, image, &lang, &img);
- if (!lang && !img)
- return;
- sqlite3_snprintf(MAX_QUERY_LEN, query,
- "INSERT INTO package_app_image_info(app_id, app_locale, " \
- "app_image_section, app_image) VALUES" \
- "(%Q, %Q, %Q, %Q)", app->appid, lang, (char *)data, img);
-
- ret = __exec_query(query);
- if (ret == -1)
- _LOGD("Package UiApp image Info DB Insert failed\n");
-
-}
-
-
-static int __insert_mainapp_info(manifest_x *mfx)
-{
- GList *tmp;
- application_x *app;
- int ret = -1;
- char query[MAX_QUERY_LEN] = {'\0'};
- for (tmp = mfx->application; tmp; tmp = tmp->next) {
- app = (application_x *)tmp->data;
- if (app == NULL)
- continue;
- if (strcasecmp(app->mainapp, "True") == 0)
- mfx->mainapp_id = strdup(app->appid);
- }
-
- if (mfx->mainapp_id == NULL) {
- if (mfx->application == NULL)
- return -1;
- app = (application_x *)mfx->application->data;
- if (app == NULL)
- return -1;
- free((void *)app->mainapp);
- app->mainapp = strdup("true");
- mfx->mainapp_id = strdup(app->appid);
- }
-
- memset(query, '\0', MAX_QUERY_LEN);
- sqlite3_snprintf(MAX_QUERY_LEN, query,
- "UPDATE package_info SET mainapp_id=%Q WHERE package=%Q", mfx->mainapp_id, mfx->package);
- ret = __exec_query(query);
- if (ret == -1) {
- _LOGD("Package Info DB update Failed\n");
- return -1;
- }
-
- return 0;
-}
-
-static int __convert_background_category(GList *category_list)
-{
- int ret = 0;
- GList *tmp_list = category_list;
- char *category_data = NULL;
-
- if (category_list == NULL)
- return 0;
-
- while (tmp_list != NULL) {
- category_data = (char *)tmp_list->data;
- if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0)
- ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
- else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0)
- ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
- else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0)
- ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
- else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0)
- ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
- else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0)
- ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
- else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0)
- ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
- else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0)
- ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
- else
- _LOGE("Unidentified category [%s]", category_data);
- tmp_list = g_list_next(tmp_list);
- }
-
- return ret;
-}
-
-static const char *__find_effective_appid(GList *metadata_list)
-{
- GList *tmp_list;
- metadata_x *md;
-
- for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
- md = (metadata_x *)tmp_list->data;
- if (md == NULL || md->key == NULL)
- continue;
-
- if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
- if (md->value)
- return md->value;
- }
- }
-
- return NULL;
-}
-
-static char *__get_bool(char *value, bool is_true)
-{
- if (value != NULL) {
- if (!strcmp(value, ""))
- return (is_true) ? "true" : "false";
- return value;
- }
-
- return (is_true) ? "true" : "false";
-}
-
-static int __insert_pkg_updateinfo_in_db(manifest_x *mfx, uid_t uid)
-{
- char query[MAX_QUERY_LEN] = {'\0'};
- int ret;
-
- if (mfx == NULL)
- return -1;
-
- sqlite3_snprintf(MAX_QUERY_LEN, query,
- "INSERT INTO package_update_info(" \
- "package, update_version) VALUES(%Q, %Q)",
- mfx->package, mfx->version);
- ret = __exec_query(query);
-
- return ret;
-}
-
-/* _PRODUCT_LAUNCHING_ENHANCED_
-* app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
-*/
-static int __insert_application_info(manifest_x *mfx)
-{
- GList *tmp;
- application_x *app;
- int ret = -1;
- int background_value = 0;
- char query[MAX_QUERY_LEN] = {'\0'};
- char *type = NULL;
- const char *effective_appid;
-
- if (mfx->type)
- type = strdup(mfx->type);
- else
- type = strdup("tpk");
-
- for (tmp = mfx->application; tmp; tmp = tmp->next) {
- app = (application_x *)tmp->data;
- if (app == NULL)
- continue;
-
- background_value = __convert_background_category(app->background_category);
- if (background_value < 0) {
- _LOGE("Failed to retrieve background value[%d]", background_value);
- background_value = 0;
- }
-
- effective_appid = __find_effective_appid(app->metadata);
-
- sqlite3_snprintf(MAX_QUERY_LEN, query,
- "INSERT INTO package_app_info(" \
- "app_id, app_component, app_exec, app_nodisplay, app_type, " \
- "app_onboot, app_multiple, app_autorestart, app_taskmanage, " \
- "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_installed_storage, app_process_pool, " \
- "app_launch_mode, app_ui_gadget, app_support_mode, app_support_disable, component_type, package, " \
- "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, " \
- "app_api_version, app_effective_appid, app_splash_screen_display, app_package_system, app_removable, " \
- "app_package_installed_time, app_support_ambient, app_setup_appid) " \
- "VALUES(" \
- "%Q, %Q, %Q, LOWER(%Q), %Q, " \
- "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
- "%Q, %Q, %Q, %Q, %Q, " \
- "LOWER(%Q), %Q, %Q, LOWER(%Q), %Q, " \
- "LOWER(%Q), LOWER(%Q), %Q, %Q, LOWER(%Q), " \
- "COALESCE(%Q, 'caller'), LOWER(%Q), %Q, LOWER(%Q), %Q, %Q, " \
- "%Q, %Q, %d, %Q, %Q, " \
- "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
- "%Q, LOWER(%Q), %Q)", \
- app->appid, app->component_type, app->exec, __get_bool(app->nodisplay, false), app->type,
- __get_bool(app->onboot, false), __get_bool(app->multiple, false), __get_bool(app->autorestart, false), __get_bool(app->taskmanage, false),
- app->hwacceleration, app->screenreader, app->mainapp, app->recentimage, app->launchcondition,
- __get_bool(app->indicatordisplay, true), app->portraitimg, app->landscapeimg,
- __get_bool(app->guestmode_visibility, true), app->permission_type,
- __get_bool(mfx->preload, false), __get_bool(app->submode, false), app->submode_mainid, mfx->installed_storage, __get_bool(app->process_pool, false),
- app->launch_mode, __get_bool(app->ui_gadget, false), mfx->support_mode, __get_bool(mfx->support_disable, false), app->component_type, mfx->package,
- mfx->tep_name, mfx->zip_mount_file, background_value, type, mfx->root_path, mfx->api_version,
- effective_appid, __get_bool(app->splash_screen_display, false), __get_bool(mfx->system, false), __get_bool(mfx->removable, true),
- mfx->installed_time, __get_bool(app->support_ambient, false), app->setup_appid);
-
- ret = __exec_query(query);
- if (ret == -1) {
- _LOGD("Package UiApp Info DB Insert Failed\n");
- if (type)
- free(type);
- return -1;
- }
- memset(query, '\0', MAX_QUERY_LEN);
- }
-
- if (type)
- free(type);
-
- return 0;
-}
-
-static int __insert_application_appcategory_info(manifest_x *mfx)
-{
- GList *app_tmp;
- application_x *app;
- GList *ct_tmp;
- const char *ct;
- int ret = -1;
- char query[MAX_QUERY_LEN] = {'\0'};
- for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
- app = (application_x *)app_tmp->data;
- if (app == NULL)
- continue;
- for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
- ct = (const char *)ct_tmp->data;
- if (ct == NULL)
- continue;
- sqlite3_snprintf(MAX_QUERY_LEN, query,
- "INSERT INTO package_app_app_category(app_id, category) " \
- "VALUES(%Q, %Q)",\
- app->appid, ct);
- ret = __exec_query(query);
- if (ret == -1) {
- _LOGD("Package UiApp Category Info DB Insert Failed\n");
- return -1;
- }
- memset(query, '\0', MAX_QUERY_LEN);
- }
- }
- return 0;
-}
-
-static int __insert_application_appmetadata_info(manifest_x *mfx)
-{
- GList *app_tmp;
- application_x *app;
- GList *md_tmp;
- metadata_x *md;
- int ret = -1;
- char query[MAX_QUERY_LEN] = {'\0'};
- for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
- app = (application_x *)app_tmp->data;
- if (app == NULL)
- continue;
- for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
- md = (metadata_x *)md_tmp->data;
- if (md == NULL)
- continue;
- if (md->key) {
- sqlite3_snprintf(MAX_QUERY_LEN, query,
- "INSERT INTO package_app_app_metadata(app_id, md_key, md_value) " \
- "VALUES(%Q, %Q, %Q)",\
- app->appid, md->key, md->value ? md->value : NULL);
- ret = __exec_query(query);
- if (ret == -1) {
- _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
- return -1;
- }
- }
- memset(query, '\0', MAX_QUERY_LEN);
- }
- }
- return 0;
-}
-
-static int __insert_application_apppermission_info(manifest_x *mfx)
-{
- GList *app_tmp;
- application_x *app;
- GList *pm_tmp;
- permission_x *pm;
- int ret = -1;
- char query[MAX_QUERY_LEN] = {'\0'};
- for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
- app = (application_x *)app_tmp->data;
- if (app == NULL)
- continue;
- for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
- pm = (permission_x *)pm_tmp->data;
- if (pm == NULL)
- continue;
- sqlite3_snprintf(MAX_QUERY_LEN, query,
- "INSERT INTO package_app_app_permission(app_id, pm_type, pm_value) " \
- "VALUES(%Q, %Q, %Q)",\
- app->appid, pm->type, pm->value);
- ret = __exec_query(query);
- if (ret == -1) {
- _LOGD("Package UiApp permission Info DB Insert Failed\n");
- return -1;