4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
26 #include <sys/types.h>
32 /* For multi-user support */
33 #include <tzplatform_config.h>
35 #include "pkgmgr-info.h"
36 #include "pkgmgr_parser_internal.h"
37 #include "pkgmgr_parser_db.h"
39 #include "pkgmgr-info-debug.h"
44 #define LOG_TAG "PKGMGR_PARSER"
46 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
47 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
48 #define MAX_QUERY_LEN 4096
50 sqlite3 *pkgmgr_parser_db;
51 sqlite3 *pkgmgr_cert_db;
54 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
55 "(package text primary key not null, " \
56 "package_type text DEFAULT 'rpm', " \
57 "package_version text, " \
58 "install_location text, " \
59 "package_size text, " \
60 "package_removable text DEFAULT 'true', " \
61 "package_preload text DEFAULT 'false', " \
62 "package_readonly text DEFAULT 'false', " \
63 "package_update text DEFAULT 'false', " \
64 "package_appsetting text DEFAULT 'false', " \
65 "package_nodisplay text DEFAULT 'false', " \
66 "package_system text DEFAULT 'false', " \
67 "author_name text, " \
68 "author_email text, " \
70 "installed_time text," \
71 "installed_storage text," \
72 "storeclient_id text," \
78 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
79 "(package text not null, " \
80 "package_locale text DEFAULT 'No Locale', " \
81 "package_label text, " \
82 "package_icon text, " \
83 "package_description text, " \
84 "package_license text, " \
86 "PRIMARY KEY(package, package_locale), " \
87 "FOREIGN KEY(package) " \
88 "REFERENCES package_info(package) " \
91 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
92 "(package text not null, " \
93 "privilege text not null, " \
94 "PRIMARY KEY(package, privilege) " \
95 "FOREIGN KEY(package) " \
96 "REFERENCES package_info(package) " \
99 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
100 "(app_id text primary key not null, " \
101 "app_component text, " \
103 "app_nodisplay text DEFAULT 'false', " \
105 "app_onboot text DEFAULT 'false', " \
106 "app_multiple text DEFAULT 'false', " \
107 "app_autorestart text DEFAULT 'false', " \
108 "app_taskmanage text DEFAULT 'false', " \
109 "app_enabled text DEFAULT 'true', " \
110 "app_hwacceleration text DEFAULT 'use-system-setting', " \
111 "app_screenreader text DEFAULT 'use-system-setting', " \
112 "app_mainapp text, " \
113 "app_recentimage text, " \
114 "app_launchcondition text, " \
115 "app_indicatordisplay text DEFAULT 'true', " \
116 "app_portraitimg text, " \
117 "app_landscapeimg text, " \
118 "app_guestmodevisibility text DEFAULT 'true', " \
119 "app_permissiontype text DEFAULT 'normal', " \
120 "app_preload text DEFAULT 'false', " \
121 "app_submode text DEFAULT 'false', " \
122 "app_submode_mainid text, " \
123 "component_type text, " \
124 "package text not null, " \
125 "FOREIGN KEY(package) " \
126 "REFERENCES package_info(package) " \
129 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
130 "(app_id text not null, " \
131 "app_locale text DEFAULT 'No Locale', " \
134 "PRIMARY KEY(app_id,app_locale) " \
135 "FOREIGN KEY(app_id) " \
136 "REFERENCES package_app_info(app_id) " \
139 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
140 "(app_id text not null, " \
142 "app_icon_section text, " \
143 "app_icon_resolution text, " \
144 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
145 "FOREIGN KEY(app_id) " \
146 "REFERENCES package_app_info(app_id) " \
149 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
150 "(app_id text not null, " \
151 "app_locale text DEFAULT 'No Locale', " \
152 "app_image_section text, " \
154 "PRIMARY KEY(app_id,app_image_section) " \
155 "FOREIGN KEY(app_id) " \
156 "REFERENCES package_app_info(app_id) " \
159 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
160 "(app_id text not null, " \
161 "operation text not null, " \
162 "uri_scheme text, " \
164 "subapp_name text, " \
165 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
166 "FOREIGN KEY(app_id) " \
167 "REFERENCES package_app_info(app_id) " \
170 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
171 "(app_id text not null, " \
172 "operation text not null, " \
173 "uri_scheme text, " \
175 "subapp_name text, " \
176 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
177 "FOREIGN KEY(app_id) " \
178 "REFERENCES package_app_info(app_id) " \
181 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
182 "(app_id text not null, " \
183 "category text not null, " \
184 "PRIMARY KEY(app_id,category) " \
185 "FOREIGN KEY(app_id) " \
186 "REFERENCES package_app_info(app_id) " \
189 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
190 "(app_id text not null, " \
191 "md_key text not null, " \
192 "md_value text not null, " \
193 "PRIMARY KEY(app_id, md_key, md_value) " \
194 "FOREIGN KEY(app_id) " \
195 "REFERENCES package_app_info(app_id) " \
198 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
199 "(app_id text not null, " \
200 "pm_type text not null, " \
201 "pm_value text not null, " \
202 "PRIMARY KEY(app_id, pm_type, pm_value) " \
203 "FOREIGN KEY(app_id) " \
204 "REFERENCES package_app_info(app_id) " \
207 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
208 "(app_id text not null, " \
209 "data_share_path text not null, " \
210 "data_share_allowed text not null, " \
211 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
212 "FOREIGN KEY(app_id) " \
213 "REFERENCES package_app_info(app_id) " \
216 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
217 "(app_id text not null, " \
218 "data_share_request text not null, " \
219 "PRIMARY KEY(app_id,data_share_request) " \
220 "FOREIGN KEY(app_id) " \
221 "REFERENCES package_app_info(app_id) " \
224 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
225 "(cert_info text not null, " \
226 "cert_id integer, " \
227 "cert_ref_count integer, " \
228 "PRIMARY KEY(cert_id)) "
230 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
231 "(package text not null, " \
232 "author_root_cert integer, " \
233 "author_im_cert integer, " \
234 "author_signer_cert integer, " \
235 "dist_root_cert integer, " \
236 "dist_im_cert integer, " \
237 "dist_signer_cert integer, " \
238 "dist2_root_cert integer, " \
239 "dist2_im_cert integer, " \
240 "dist2_signer_cert integer, " \
241 "PRIMARY KEY(package)) "
243 static int __insert_uiapplication_info(manifest_x *mfx);
244 static int __insert_serviceapplication_info(manifest_x *mfx);
245 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
246 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
247 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
248 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
249 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
250 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
251 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
252 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
253 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
254 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
255 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
256 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
257 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
258 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
259 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
260 static int __insert_manifest_info_in_db(manifest_x *mfx);
261 static int __delete_manifest_info_from_db(manifest_x *mfx);
262 static int __delete_subpkg_info_from_db(char *appid);
263 static int __delete_appinfo_from_db(char *db_table, const char *appid);
264 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
265 static int __exec_query(char *query);
266 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
267 char **label, char **license, char **icon, char **description, char **author);
268 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
269 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
270 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
271 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
272 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
274 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
277 __delete_subpkg_info_from_db(coltxt[0]);
282 static char *__get_str(const char *str)
286 return PKGMGR_PARSER_EMPTY_STR;
292 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
296 if (access(db_path, F_OK) == 0) {
298 db_util_open(db_path, &handle,
299 DB_UTIL_REGISTER_HOOK_METHOD);
300 if (ret != SQLITE_OK) {
301 _LOGD("connect db [%s] failed!\n",
308 _LOGD("%s DB does not exists. Create one!!\n", db_path);
311 db_util_open(db_path, &handle,
312 DB_UTIL_REGISTER_HOOK_METHOD);
314 if (ret != SQLITE_OK) {
315 _LOGD("connect db [%s] failed!\n", db_path);
322 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
324 manifest_x *mfx = (manifest_x *)data;
328 uiapplication_x *uiapp = NULL;
329 for(i = 0; i < ncols; i++)
331 uiapp = mfx->uiapplication;
332 if (strcmp(colname[i], "app_id") == 0) {
334 appid = strdup(coltxt[i]);
335 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
337 status = strdup(coltxt[i]);
341 _LOGD("app id is NULL\n");
344 /*update guest mode visibility*/
345 for (; uiapp != NULL; uiapp = uiapp->next) {
346 if (strcmp(uiapp->appid, appid) == 0) {
347 free((void *)uiapp->guestmode_visibility);
348 uiapp->guestmode_visibility = strdup(status);
364 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
366 char *error_message = NULL;
367 char query[MAX_QUERY_LEN] = {'\0'};
368 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
370 sqlite3_exec(pkgmgr_parser_db, query,
371 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
372 _LOGD("Don't execute query = %s error message = %s\n",
373 query, error_message);
374 sqlite3_free(error_message);
379 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
381 char *error_message = NULL;
383 sqlite3_exec(db_handle, db_query,
384 NULL, NULL, &error_message)) {
385 _LOGD("Don't execute query = %s error message = %s\n",
386 db_query, error_message);
387 sqlite3_free(error_message);
390 sqlite3_free(error_message);
394 static int __exec_query(char *query)
396 char *error_message = NULL;
398 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
399 _LOGD("Don't execute query = %s error message = %s\n", query,
401 sqlite3_free(error_message);
404 sqlite3_free(error_message);
408 static int __exec_query_no_msg(char *query)
410 char *error_message = NULL;
412 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
413 sqlite3_free(error_message);
416 sqlite3_free(error_message);
420 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
426 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
432 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
438 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
444 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
450 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
457 static GList *__create_icon_list(GList *locale, icon_x *icn)
462 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
468 static GList *__create_image_list(GList *locale, image_x *image)
473 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
479 static void __printfunc(gpointer data, gpointer userdata)
481 _LOGD("%s ", (char*)data);
484 static void __trimfunc(GList* trim_list)
486 char *trim_data = NULL;
490 list = g_list_first(trim_list);
493 trim_data = (char *)list->data;
496 if (strcmp(trim_data, prev) == 0) {
497 trim_list = g_list_remove(trim_list, trim_data);
498 list = g_list_first(trim_list);
507 list = g_list_next(list);
511 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
513 if (a == NULL || b == NULL)
515 if (strcmp((char*)a, (char*)b) == 0)
517 if (strcmp((char*)a, (char*)b) < 0)
519 if (strcmp((char*)a, (char*)b) > 0)
524 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
525 char **label, char **license, char **icon, char **description, char **author)
530 if (strcmp(lbl->lang, (char *)data) == 0) {
531 *label = (char*)lbl->text;
540 if (strcmp(lcn->lang, (char *)data) == 0) {
541 *license = (char*)lcn->text;
550 if (strcmp(icn->lang, (char *)data) == 0) {
551 *icon = (char*)icn->text;
560 if (strcmp(dcn->lang, (char *)data) == 0) {
561 *description = (char*)dcn->text;
570 if (strcmp(ath->lang, (char *)data) == 0) {
571 *author = (char*)ath->text;
580 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
585 if (strcmp(icn->section, (char *)data) == 0) {
586 *icon = (char*)icn->text;
587 *resolution = (char*)icn->resolution;
595 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
599 if (image->section) {
600 if (strcmp(image->section, (char *)data) == 0) {
601 *lang = (char*)image->lang;
602 *img = (char*)image->text;
610 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
615 char *description = NULL;
616 char *license = NULL;
618 char query[MAX_QUERY_LEN] = {'\0'};
620 manifest_x *mfx = (manifest_x *)userdata;
621 label_x *lbl = mfx->label;
622 license_x *lcn = mfx->license;
623 icon_x *icn = mfx->icon;
624 description_x *dcn = mfx->description;
625 author_x *ath = mfx->author;
627 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
628 if (!label && !description && !icon && !license && !author)
631 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
632 "package_label, package_icon, package_description, package_license, package_author) values " \
633 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
638 __get_str(description),
642 ret = __exec_query(query);
644 _LOGD("Package Localized Info DB Insert failed\n");
647 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
652 char query[MAX_QUERY_LEN] = {'\0'};
654 uiapplication_x *up = (uiapplication_x*)userdata;
655 label_x *lbl = up->label;
656 icon_x *icn = up->icon;
658 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
661 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
662 "app_label, app_icon) values " \
663 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
665 ret = __exec_query(query);
667 _LOGD("Package UiApp Localized Info DB Insert failed\n");
669 /*insert ui app locale info to pkg locale to get mainapp data */
670 if (strcasecmp(up->mainapp, "true")==0) {
671 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
672 "package_label, package_icon, package_description, package_license, package_author) values " \
673 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
678 PKGMGR_PARSER_EMPTY_STR,
679 PKGMGR_PARSER_EMPTY_STR,
680 PKGMGR_PARSER_EMPTY_STR);
682 ret = __exec_query_no_msg(query);
685 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
686 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
687 ret = __exec_query_no_msg(query);
692 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
696 char *resolution = NULL;
697 char query[MAX_QUERY_LEN] = {'\0'};
699 uiapplication_x *up = (uiapplication_x*)userdata;
700 icon_x *icn = up->icon;
702 __extract_icon_data(data, icn, &icon, &resolution);
703 if (!icon && !resolution)
705 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
706 "app_icon, app_icon_section, app_icon_resolution) values " \
707 "('%q', '%q', '%q', '%q')", up->appid,
708 icon, (char*)data, resolution);
710 ret = __exec_query(query);
712 _LOGD("Package UiApp Localized Info DB Insert failed\n");
716 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
721 char query[MAX_QUERY_LEN] = {'\0'};
723 uiapplication_x *up = (uiapplication_x*)userdata;
724 image_x *image = up->image;
726 __extract_image_data(data, image, &lang, &img);
729 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
730 "app_image_section, app_image) values " \
731 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
733 ret = __exec_query(query);
735 _LOGD("Package UiApp image Info DB Insert failed\n");
740 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
745 char query[MAX_QUERY_LEN] = {'\0'};
747 serviceapplication_x *sp = (serviceapplication_x*)userdata;
748 label_x *lbl = sp->label;
749 icon_x *icn = sp->icon;
751 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
754 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
755 "app_label, app_icon) values " \
756 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
758 ret = __exec_query(query);
760 _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
763 static int __insert_ui_mainapp_info(manifest_x *mfx)
765 uiapplication_x *up = mfx->uiapplication;
767 char query[MAX_QUERY_LEN] = {'\0'};
770 snprintf(query, MAX_QUERY_LEN,
771 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
773 ret = __exec_query(query);
775 _LOGD("Package UiApp Info DB Insert Failed\n");
778 if (strcasecmp(up->mainapp, "True")==0)
779 mfx->mainapp_id = strdup(up->appid);
782 memset(query, '\0', MAX_QUERY_LEN);
785 if (mfx->mainapp_id == NULL){
786 if (mfx->uiapplication && mfx->uiapplication->appid) {
787 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
789 _LOGD("Not valid appid\n");
793 ret = __exec_query(query);
795 _LOGD("Package UiApp Info DB Insert Failed\n");
799 free((void *)mfx->uiapplication->mainapp);
800 mfx->uiapplication->mainapp= strdup("true");
801 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
804 memset(query, '\0', MAX_QUERY_LEN);
805 snprintf(query, MAX_QUERY_LEN,
806 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
807 ret = __exec_query(query);
809 _LOGD("Package Info DB update Failed\n");
815 /* _PRODUCT_LAUNCHING_ENHANCED_
816 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
818 static int __insert_uiapplication_info(manifest_x *mfx)
820 uiapplication_x *up = mfx->uiapplication;
822 char query[MAX_QUERY_LEN] = {'\0'};
825 snprintf(query, MAX_QUERY_LEN,
826 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
827 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
828 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
829 "app_preload, app_submode, app_submode_mainid, component_type, package) " \
830 "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')",\
836 PKGMGR_PARSER_EMPTY_STR,
838 PKGMGR_PARSER_EMPTY_STR,
844 __get_str(up->recentimage),
846 up->indicatordisplay,
847 __get_str(up->portraitimg),
848 __get_str(up->landscapeimg),
849 up->guestmode_visibility,
853 __get_str(up->submode_mainid),
857 ret = __exec_query(query);
859 _LOGD("Package UiApp Info DB Insert Failed\n");
863 memset(query, '\0', MAX_QUERY_LEN);
868 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
870 uiapplication_x *up = mfx->uiapplication;
871 category_x *ct = NULL;
873 char query[MAX_QUERY_LEN] = {'\0'};
879 snprintf(query, MAX_QUERY_LEN,
880 "insert into package_app_app_category(app_id, category) " \
881 "values('%s','%s')",\
882 up->appid, ct->name);
883 ret = __exec_query(query);
885 _LOGD("Package UiApp Category Info DB Insert Failed\n");
889 memset(query, '\0', MAX_QUERY_LEN);
896 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
898 uiapplication_x *up = mfx->uiapplication;
899 metadata_x *md = NULL;
901 char query[MAX_QUERY_LEN] = {'\0'};
908 snprintf(query, MAX_QUERY_LEN,
909 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
910 "values('%s','%s', '%s')",\
911 up->appid, md->key, md->value);
912 ret = __exec_query(query);
914 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
919 memset(query, '\0', MAX_QUERY_LEN);
926 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
928 uiapplication_x *up = mfx->uiapplication;
929 permission_x *pm = NULL;
931 char query[MAX_QUERY_LEN] = {'\0'};
937 snprintf(query, MAX_QUERY_LEN,
938 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
939 "values('%s','%s', '%s')",\
940 up->appid, pm->type, pm->value);
941 ret = __exec_query(query);
943 _LOGD("Package UiApp permission Info DB Insert Failed\n");
947 memset(query, '\0', MAX_QUERY_LEN);
954 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
956 uiapplication_x *up = mfx->uiapplication;
957 appcontrol_x *acontrol = NULL;
958 operation_x *op = NULL;
961 subapp_x *sub = NULL;
963 char query[MAX_QUERY_LEN] = {'\0'};
964 const char *operation = NULL;
965 const char *mime = NULL;
966 const char *uri = NULL;
967 const char *subapp = NULL;
970 acontrol = up->appcontrol;
971 while(acontrol != NULL)
973 op = acontrol->operation;
977 operation = op->name;
984 sub = acontrol->subapp;
994 snprintf(query, MAX_QUERY_LEN,
995 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type, subapp_name) " \
996 "values('%s', '%s', '%s', '%s', '%s')",\
997 up->appid, operation, uri, mime, subapp);
999 ret = __exec_query(query);
1001 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1004 memset(query, '\0', MAX_QUERY_LEN);
1008 } while(ui != NULL);
1012 }while(sub != NULL);
1021 acontrol = acontrol->next;
1028 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1030 uiapplication_x *up = mfx->uiapplication;
1031 appsvc_x *asvc = NULL;
1032 operation_x *op = NULL;
1035 subapp_x *sub = NULL;
1037 char query[MAX_QUERY_LEN] = {'\0'};
1038 const char *operation = NULL;
1039 const char *mime = NULL;
1040 const char *uri = NULL;
1041 const char *subapp = NULL;
1047 op = asvc->operation;
1051 operation = op->name;
1068 snprintf(query, MAX_QUERY_LEN,
1069 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1070 "values('%s', '%s', '%s', '%s', '%s')",\
1077 ret = __exec_query(query);
1079 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1082 memset(query, '\0', MAX_QUERY_LEN);
1086 } while(ui != NULL);
1090 }while(sub != NULL);
1106 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1108 uiapplication_x *up = mfx->uiapplication;
1109 datashare_x *ds = NULL;
1110 request_x *rq = NULL;
1112 char query[MAX_QUERY_LEN] = {'\0'};
1121 snprintf(query, MAX_QUERY_LEN,
1122 "insert into package_app_share_request(app_id, data_share_request) " \
1123 "values('%s', '%s')",\
1124 up->appid, rq->text);
1125 ret = __exec_query(query);
1127 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1130 memset(query, '\0', MAX_QUERY_LEN);
1140 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1142 uiapplication_x *up = mfx->uiapplication;
1143 datashare_x *ds = NULL;
1144 define_x *df = NULL;
1145 allowed_x *al = NULL;
1147 char query[MAX_QUERY_LEN] = {'\0'};
1159 snprintf(query, MAX_QUERY_LEN,
1160 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1161 "values('%s', '%s', '%s')",\
1162 up->appid, df->path, al->text);
1163 ret = __exec_query(query);
1165 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1168 memset(query, '\0', MAX_QUERY_LEN);
1180 static int __insert_serviceapplication_info(manifest_x *mfx)
1182 serviceapplication_x *sp = mfx->serviceapplication;
1184 char query[MAX_QUERY_LEN] = {'\0'};
1187 snprintf(query, MAX_QUERY_LEN,
1188 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1189 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1190 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1191 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1192 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1193 ret = __exec_query(query);
1195 _LOGD("Package ServiceApp Info DB Insert Failed\n");
1199 memset(query, '\0', MAX_QUERY_LEN);
1204 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1206 serviceapplication_x *sp = mfx->serviceapplication;
1207 category_x *ct = NULL;
1209 char query[MAX_QUERY_LEN] = {'\0'};
1215 snprintf(query, MAX_QUERY_LEN,
1216 "insert into package_app_app_category(app_id, category) " \
1217 "values('%s','%s')",\
1218 sp->appid, ct->name);
1219 ret = __exec_query(query);
1221 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1225 memset(query, '\0', MAX_QUERY_LEN);
1232 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1234 serviceapplication_x *sp = mfx->serviceapplication;
1235 metadata_x *md = NULL;
1237 char query[MAX_QUERY_LEN] = {'\0'};
1244 snprintf(query, MAX_QUERY_LEN,
1245 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1246 "values('%s','%s', '%s')",\
1247 sp->appid, md->key, md->value);
1248 ret = __exec_query(query);
1250 _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1255 memset(query, '\0', MAX_QUERY_LEN);
1262 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1264 serviceapplication_x *sp = mfx->serviceapplication;
1265 permission_x *pm = NULL;
1267 char query[MAX_QUERY_LEN] = {'\0'};
1270 pm = sp->permission;
1273 snprintf(query, MAX_QUERY_LEN,
1274 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1275 "values('%s','%s', '%s')",\
1276 sp->appid, pm->type, pm->value);
1277 ret = __exec_query(query);
1279 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1283 memset(query, '\0', MAX_QUERY_LEN);
1290 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1292 serviceapplication_x *sp = mfx->serviceapplication;
1293 appcontrol_x *acontrol = NULL;
1295 char query[MAX_QUERY_LEN] = {'\0'};
1296 operation_x *op = NULL;
1299 subapp_x *sub = NULL;
1300 const char *operation = NULL;
1301 const char *mime = NULL;
1302 const char *uri = NULL;
1303 const char *subapp = NULL;
1306 acontrol = sp->appcontrol;
1307 while(acontrol != NULL)
1309 op = acontrol->operation;
1313 operation = op->name;
1314 mi = acontrol->mime;
1319 sub = acontrol->subapp;
1329 snprintf(query, MAX_QUERY_LEN,
1330 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type,subapp_name) " \
1331 "values('%s', '%s', '%s', '%s', '%s')",\
1332 sp->appid, operation, uri, mime, subapp);
1333 ret = __exec_query(query);
1335 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1338 memset(query, '\0', MAX_QUERY_LEN);
1342 } while(ui != NULL);
1346 }while(sub != NULL);
1355 acontrol = acontrol->next;
1362 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1364 serviceapplication_x *sp = mfx->serviceapplication;
1365 appsvc_x *asvc = NULL;
1367 char query[MAX_QUERY_LEN] = {'\0'};
1368 operation_x *op = NULL;
1371 subapp_x *sub = NULL;
1372 const char *operation = NULL;
1373 const char *mime = NULL;
1374 const char *uri = NULL;
1375 const char *subapp = NULL;
1381 op = asvc->operation;
1385 operation = op->name;
1401 snprintf(query, MAX_QUERY_LEN,
1402 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1403 "values('%s', '%s', '%s', '%s', '%s')",\
1409 ret = __exec_query(query);
1411 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1414 memset(query, '\0', MAX_QUERY_LEN);
1418 } while(ui != NULL);
1422 }while(sub != NULL);
1440 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1442 serviceapplication_x *sp = mfx->serviceapplication;
1443 datashare_x *ds = NULL;
1444 request_x *rq = NULL;
1446 char query[MAX_QUERY_LEN] = {'\0'};
1455 snprintf(query, MAX_QUERY_LEN,
1456 "insert into package_app_share_request(app_id, data_share_request) " \
1457 "values('%s', '%s')",\
1458 sp->appid, rq->text);
1459 ret = __exec_query(query);
1461 _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1464 memset(query, '\0', MAX_QUERY_LEN);
1476 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1478 serviceapplication_x *sp = mfx->serviceapplication;
1479 datashare_x *ds = NULL;
1480 define_x *df = NULL;
1481 allowed_x *al = NULL;
1483 char query[MAX_QUERY_LEN] = {'\0'};
1495 snprintf(query, MAX_QUERY_LEN,
1496 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1497 "values('%s', '%s', '%s')",\
1498 sp->appid, df->path, al->text);
1499 ret = __exec_query(query);
1501 _LOGD("Package App Share Allowed DB Insert Failed\n");
1504 memset(query, '\0', MAX_QUERY_LEN);
1516 static int __insert_manifest_info_in_db(manifest_x *mfx)
1518 label_x *lbl = mfx->label;
1519 license_x *lcn = mfx->license;
1520 icon_x *icn = mfx->icon;
1521 description_x *dcn = mfx->description;
1522 author_x *ath = mfx->author;
1523 uiapplication_x *up = mfx->uiapplication;
1524 uiapplication_x *up_icn = mfx->uiapplication;
1525 uiapplication_x *up_image = mfx->uiapplication;
1526 serviceapplication_x *sp = mfx->serviceapplication;
1527 privileges_x *pvs = NULL;
1528 privilege_x *pv = NULL;
1529 char query[MAX_QUERY_LEN] = { '\0' };
1530 char root[MAX_QUERY_LEN] = { '\0' };
1534 const char *auth_name = NULL;
1535 const char *auth_email = NULL;
1536 const char *auth_href = NULL;
1537 const char *apps_path = NULL;
1539 GList *pkglocale = NULL;
1540 GList *applocale = NULL;
1541 GList *appicon = NULL;
1542 GList *appimage = NULL;
1546 auth_name = ath->text;
1548 auth_email = ath->email;
1550 auth_href = ath->href;
1553 /*Insert in the package_info DB*/
1555 type = strdup(mfx->type);
1557 type = strdup("rpm");
1558 /*Insert in the package_info DB*/
1560 path = strdup(mfx->root_path);
1562 if (strcmp(type,"rpm")==0) {
1563 apps_path = tzplatform_getenv(TZ_SYS_RO_APP);
1564 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1566 apps_path = tzplatform_getenv(TZ_USER_APP);
1567 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1570 path = strdup(root);
1572 snprintf(query, MAX_QUERY_LEN,
1573 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1574 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1575 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
1576 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1580 __get_str(mfx->installlocation),
1581 __get_str(mfx->package_size),
1587 mfx->nodisplay_setting,
1589 __get_str(auth_name),
1590 __get_str(auth_email),
1591 __get_str(auth_href),
1592 mfx->installed_time,
1593 mfx->installed_storage,
1594 __get_str(mfx->storeclient_id),
1596 __get_str(mfx->package_url),
1598 __get_str(mfx->csc_path));
1600 /*If package dont have main_package tag, this package is main package.*/
1601 if (mfx->main_package == NULL) {
1602 ret = __exec_query(query);
1604 _LOGD("Package Info DB Insert Failed\n");
1616 /*If package has main_package tag, this package is sub package(ug, efl).
1617 skip __exec_query for package_info and change pkgid with main_package*/
1618 memset(root, '\0', MAX_QUERY_LEN);
1619 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->main_package);
1620 if (access(root, F_OK) == 0) {
1621 free((void *)mfx->package);
1622 mfx->package = strdup(mfx->main_package);
1624 _LOGE("main package[%s] is not installed\n", root);
1637 /*Insert in the package_privilege_info DB*/
1638 pvs = mfx->privileges;
1639 while (pvs != NULL) {
1640 pv = pvs->privilege;
1641 while (pv != NULL) {
1642 memset(query, '\0', MAX_QUERY_LEN);
1643 snprintf(query, MAX_QUERY_LEN,
1644 "insert into package_privilege_info(package, privilege) " \
1645 "values('%s','%s')",\
1646 mfx->package, pv->text);
1647 ret = __exec_query(query);
1649 _LOGD("Package Privilege Info DB Insert Failed\n");
1657 ret = __insert_ui_mainapp_info(mfx);
1661 /*Insert the package locale*/
1662 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1663 /*remove duplicated data in pkglocale*/
1664 __trimfunc(pkglocale);
1666 /*Insert the app locale info */
1669 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1674 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1677 /*remove duplicated data in applocale*/
1678 __trimfunc(applocale);
1680 /*Insert the app icon info */
1681 while(up_icn != NULL)
1683 appicon = __create_icon_list(appicon, up_icn->icon);
1684 up_icn = up_icn->next;
1686 /*remove duplicated data in appicon*/
1687 __trimfunc(appicon);
1689 /*Insert the image info */
1690 while(up_image != NULL)
1692 appimage = __create_image_list(appimage, up_image->image);
1693 up_image = up_image->next;
1695 /*remove duplicated data in appimage*/
1696 __trimfunc(appimage);
1698 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1700 /*g_list_foreach(applocale, __printfunc, NULL);*/
1702 /*package locale info, it is only for main package.*/
1703 if (mfx->main_package == NULL)
1704 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1706 /*native app locale info*/
1707 up = mfx->uiapplication;
1710 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1713 /*agent app locale info*/
1714 sp = mfx->serviceapplication;
1717 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1721 /*app icon locale info*/
1722 up_icn = mfx->uiapplication;
1723 while(up_icn != NULL)
1725 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1726 up_icn = up_icn->next;
1730 up_image = mfx->uiapplication;
1731 while(up_image != NULL)
1733 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1734 up_image = up_image->next;
1737 g_list_free(pkglocale);
1739 g_list_free(applocale);
1741 g_list_free(appicon);
1743 g_list_free(appimage);
1747 /*Insert in the package_app_info DB*/
1748 ret = __insert_uiapplication_info(mfx);
1751 ret = __insert_serviceapplication_info(mfx);
1755 /*Insert in the package_app_app_control DB*/
1756 ret = __insert_uiapplication_appcontrol_info(mfx);
1759 ret = __insert_serviceapplication_appcontrol_info(mfx);
1763 /*Insert in the package_app_app_category DB*/
1764 ret = __insert_uiapplication_appcategory_info(mfx);
1767 ret = __insert_serviceapplication_appcategory_info(mfx);
1771 /*Insert in the package_app_app_metadata DB*/
1772 ret = __insert_uiapplication_appmetadata_info(mfx);
1775 ret = __insert_serviceapplication_appmetadata_info(mfx);
1779 /*Insert in the package_app_app_permission DB*/
1780 ret = __insert_uiapplication_apppermission_info(mfx);
1783 ret = __insert_serviceapplication_apppermission_info(mfx);
1787 /*Insert in the package_app_app_svc DB*/
1788 ret = __insert_uiapplication_appsvc_info(mfx);
1791 ret = __insert_serviceapplication_appsvc_info(mfx);
1795 /*Insert in the package_app_share_allowed DB*/
1796 ret = __insert_uiapplication_share_allowed_info(mfx);
1799 ret = __insert_serviceapplication_share_allowed_info(mfx);
1803 /*Insert in the package_app_share_request DB*/
1804 ret = __insert_uiapplication_share_request_info(mfx);
1807 ret = __insert_serviceapplication_share_request_info(mfx);
1815 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1817 char query[MAX_QUERY_LEN] = { '\0' };
1819 memset(query, '\0', MAX_QUERY_LEN);
1820 snprintf(query, MAX_QUERY_LEN,
1821 "delete from %s where app_id='%s'", db_table, appid);
1822 ret = __exec_query(query);
1824 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1830 static int __delete_subpkg_info_from_db(char *appid)
1834 ret = __delete_appinfo_from_db("package_app_info", appid);
1837 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1840 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1843 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1846 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1849 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1852 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1855 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1858 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1861 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1864 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1871 static int __delete_subpkg_from_db(manifest_x *mfx)
1873 char query[MAX_QUERY_LEN] = { '\0' };
1875 char *error_message = NULL;
1877 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1879 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1880 _LOGE("Don't execute query = %s error message = %s\n", query,
1882 sqlite3_free(error_message);
1885 sqlite3_free(error_message);
1890 static int __delete_manifest_info_from_db(manifest_x *mfx)
1892 char query[MAX_QUERY_LEN] = { '\0' };
1894 uiapplication_x *up = mfx->uiapplication;
1895 serviceapplication_x *sp = mfx->serviceapplication;
1896 /*Delete from cert table*/
1897 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1899 _LOGD("Cert Info DB Delete Failed\n");
1903 /*Delete from Package Info DB*/
1904 snprintf(query, MAX_QUERY_LEN,
1905 "delete from package_info where package='%s'", mfx->package);
1906 ret = __exec_query(query);
1908 _LOGD("Package Info DB Delete Failed\n");
1911 memset(query, '\0', MAX_QUERY_LEN);
1913 /*Delete from Package Localized Info*/
1914 snprintf(query, MAX_QUERY_LEN,
1915 "delete from package_localized_info where package='%s'", mfx->package);
1916 ret = __exec_query(query);
1918 _LOGD("Package Localized Info DB Delete Failed\n");
1922 /*Delete from Package Privilege Info*/
1923 snprintf(query, MAX_QUERY_LEN,
1924 "delete from package_privilege_info where package='%s'", mfx->package);
1925 ret = __exec_query(query);
1927 _LOGD("Package Privilege Info DB Delete Failed\n");
1931 while (up != NULL) {
1932 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1935 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1938 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
1941 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
1944 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
1947 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
1950 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
1953 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
1956 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
1959 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
1962 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
1968 while (sp != NULL) {
1969 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
1972 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
1975 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
1978 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
1981 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
1984 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
1987 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
1990 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
1993 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
1996 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
1999 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
2005 /* if main package has sub pkg, delete sub pkg data*/
2006 __delete_subpkg_from_db(mfx);
2011 static int __update_preload_condition_in_db()
2014 char query[MAX_QUERY_LEN] = {'\0'};
2016 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2018 ret = __exec_query(query);
2020 _LOGD("Package preload_condition update failed\n");
2025 int pkgmgr_parser_initialize_db()
2029 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2031 _LOGD("package info DB initialization failed\n");
2034 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2036 _LOGD("package localized info DB initialization failed\n");
2039 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2041 _LOGD("package app app privilege DB initialization failed\n");
2044 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2046 _LOGD("package app info DB initialization failed\n");
2049 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2051 _LOGD("package app localized info DB initialization failed\n");
2054 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2056 _LOGD("package app icon localized info DB initialization failed\n");
2059 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2061 _LOGD("package app image info DB initialization failed\n");
2064 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2066 _LOGD("package app app control DB initialization failed\n");
2069 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2071 _LOGD("package app app category DB initialization failed\n");
2074 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2076 _LOGD("package app app category DB initialization failed\n");
2079 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2081 _LOGD("package app app permission DB initialization failed\n");
2084 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2086 _LOGD("package app app svc DB initialization failed\n");
2089 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2091 _LOGD("package app share allowed DB initialization failed\n");
2094 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2096 _LOGD("package app share request DB initialization failed\n");
2100 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2102 _LOGD("package cert info DB initialization failed\n");
2105 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2107 _LOGD("package cert index info DB initialization failed\n");
2113 int pkgmgr_parser_check_and_create_db()
2117 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, PKGMGR_PARSER_DB_FILE);
2119 _LOGD("Manifest DB creation Failed\n");
2123 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, PKGMGR_CERT_DB_FILE);
2125 _LOGD("Cert DB creation Failed\n");
2131 void pkgmgr_parser_close_db()
2133 sqlite3_close(pkgmgr_parser_db);
2134 sqlite3_close(pkgmgr_cert_db);
2137 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2140 _LOGD("manifest pointer is NULL\n");
2144 ret = pkgmgr_parser_check_and_create_db();
2146 _LOGD("Failed to open DB\n");
2149 ret = pkgmgr_parser_initialize_db();
2152 /*Begin transaction*/
2153 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2154 if (ret != SQLITE_OK) {
2155 _LOGD("Failed to begin transaction\n");
2159 _LOGD("Transaction Begin\n");
2160 ret = __insert_manifest_info_in_db(mfx);
2162 _LOGD("Insert into DB failed. Rollback now\n");
2163 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2166 /*Commit transaction*/
2167 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2168 if (ret != SQLITE_OK) {
2169 _LOGD("Failed to commit transaction. Rollback now\n");
2170 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2174 _LOGD("Transaction Commit and End\n");
2176 pkgmgr_parser_close_db();
2180 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2183 _LOGD("manifest pointer is NULL\n");
2187 ret = pkgmgr_parser_check_and_create_db();
2189 _LOGD("Failed to open DB\n");
2192 ret = pkgmgr_parser_initialize_db();
2195 /*Preserve guest mode visibility*/
2196 __preserve_guestmode_visibility_value( mfx);
2197 /*Begin transaction*/
2198 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2199 if (ret != SQLITE_OK) {
2200 _LOGD("Failed to begin transaction\n");
2204 _LOGD("Transaction Begin\n");
2205 ret = __delete_manifest_info_from_db(mfx);
2207 _LOGD("Delete from DB failed. Rollback now\n");
2208 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2211 ret = __insert_manifest_info_in_db(mfx);
2213 _LOGD("Insert into DB failed. Rollback now\n");
2214 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2218 /*Commit transaction*/
2219 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2220 if (ret != SQLITE_OK) {
2221 _LOGD("Failed to commit transaction. Rollback now\n");
2222 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2226 _LOGD("Transaction Commit and End\n");
2228 pkgmgr_parser_close_db();
2232 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2235 _LOGD("manifest pointer is NULL\n");
2239 ret = pkgmgr_parser_check_and_create_db();
2241 _LOGD("Failed to open DB\n");
2244 /*Begin transaction*/
2245 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2246 if (ret != SQLITE_OK) {
2247 _LOGD("Failed to begin transaction\n");
2251 _LOGD("Transaction Begin\n");
2252 ret = __delete_manifest_info_from_db(mfx);
2254 _LOGD("Delete from DB failed. Rollback now\n");
2255 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2258 /*Commit transaction*/
2259 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2260 if (ret != SQLITE_OK) {
2261 _LOGD("Failed to commit transaction, Rollback now\n");
2262 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2266 _LOGD("Transaction Commit and End\n");
2268 pkgmgr_parser_close_db();
2272 API int pkgmgr_parser_update_preload_info_in_db()
2275 ret = pkgmgr_parser_check_and_create_db();
2277 _LOGD("Failed to open DB\n");
2280 /*Begin transaction*/
2281 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2282 if (ret != SQLITE_OK) {
2283 _LOGD("Failed to begin transaction\n");
2287 _LOGD("Transaction Begin\n");
2288 ret = __update_preload_condition_in_db();
2290 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2291 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2294 /*Commit transaction*/
2295 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2296 if (ret != SQLITE_OK) {
2297 _LOGD("Failed to commit transaction, Rollback now\n");
2298 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2302 _LOGD("Transaction Commit and End\n");
2304 pkgmgr_parser_close_db();