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>
27 #include <sys/smack.h>
35 /* For multi-user support */
36 #include <tzplatform_config.h>
38 #include "pkgmgr-info.h"
39 #include "pkgmgrinfo_basic.h"
40 #include "pkgmgrinfo_debug.h"
41 #include "pkgmgr_parser_internal.h"
42 #include "pkgmgr_parser_db.h"
47 #define LOG_TAG "PKGMGR_PARSER"
49 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
50 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
51 #define MAX_QUERY_LEN 4096
55 #define DB_LABEL "User::Home"
56 #define SET_SMACK_LABEL(x) \
58 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
59 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
61 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
64 sqlite3 *pkgmgr_parser_db;
65 sqlite3 *pkgmgr_cert_db;
68 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
69 "(package text primary key not null, " \
70 "package_type text DEFAULT 'rpm', " \
71 "package_version text, " \
72 "package_api_version text, " \
73 "install_location text, " \
74 "package_size text, " \
75 "package_removable text DEFAULT 'true', " \
76 "package_preload text DEFAULT 'false', " \
77 "package_readonly text DEFAULT 'false', " \
78 "package_update text DEFAULT 'false', " \
79 "package_appsetting text DEFAULT 'false', " \
80 "package_nodisplay text DEFAULT 'false', " \
81 "package_system text DEFAULT 'false', " \
82 "author_name text, " \
83 "author_email text, " \
85 "installed_time text," \
86 "installed_storage text," \
87 "storeclient_id text," \
92 "package_support_disable text DEFAULT 'false')"
94 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
95 "(package text not null, " \
96 "package_locale text DEFAULT 'No Locale', " \
97 "package_label text, " \
98 "package_icon text, " \
99 "package_description text, " \
100 "package_license text, " \
102 "PRIMARY KEY(package, package_locale), " \
103 "FOREIGN KEY(package) " \
104 "REFERENCES package_info(package) " \
107 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
108 "(package text not null, " \
109 "privilege text not null, " \
110 "PRIMARY KEY(package, privilege) " \
111 "FOREIGN KEY(package) " \
112 "REFERENCES package_info(package) " \
115 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
116 "(app_id text primary key not null, " \
117 "app_component text, " \
119 "app_nodisplay text DEFAULT 'false', " \
121 "app_onboot text DEFAULT 'false', " \
122 "app_multiple text DEFAULT 'false', " \
123 "app_autorestart text DEFAULT 'false', " \
124 "app_taskmanage text DEFAULT 'false', " \
125 "app_enabled text DEFAULT 'true', " \
126 "app_hwacceleration text DEFAULT 'use-system-setting', " \
127 "app_screenreader text DEFAULT 'use-system-setting', " \
128 "app_mainapp text, " \
129 "app_recentimage text, " \
130 "app_launchcondition text, " \
131 "app_indicatordisplay text DEFAULT 'true', " \
132 "app_portraitimg text, " \
133 "app_landscapeimg text, " \
134 "app_guestmodevisibility text DEFAULT 'true', " \
135 "app_permissiontype text DEFAULT 'normal', " \
136 "app_preload text DEFAULT 'false', " \
137 "app_submode text DEFAULT 'false', " \
138 "app_submode_mainid text, " \
139 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
140 "app_ui_gadget text DEFAULT 'false', " \
141 "app_support_disable text DEFAULT 'false', " \
142 "component_type text, " \
143 "package text not null, " \
144 "FOREIGN KEY(package) " \
145 "REFERENCES package_info(package) " \
148 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
149 "(app_id text not null, " \
150 "app_locale text DEFAULT 'No Locale', " \
153 "PRIMARY KEY(app_id,app_locale) " \
154 "FOREIGN KEY(app_id) " \
155 "REFERENCES package_app_info(app_id) " \
158 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
159 "(app_id text not null, " \
161 "app_icon_section text, " \
162 "app_icon_resolution text, " \
163 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
164 "FOREIGN KEY(app_id) " \
165 "REFERENCES package_app_info(app_id) " \
168 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
169 "(app_id text not null, " \
170 "app_locale text DEFAULT 'No Locale', " \
171 "app_image_section text, " \
173 "PRIMARY KEY(app_id,app_image_section) " \
174 "FOREIGN KEY(app_id) " \
175 "REFERENCES package_app_info(app_id) " \
178 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
179 "(app_id text not null, " \
180 "app_control text not null, " \
181 "PRIMARY KEY(app_id,app_control) " \
182 "FOREIGN KEY(app_id) " \
183 "REFERENCES package_app_info(app_id) " \
186 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
187 "(app_id text not null, " \
188 "operation text not null, " \
189 "uri_scheme text, " \
191 "subapp_name text, " \
192 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
193 "FOREIGN KEY(app_id) " \
194 "REFERENCES package_app_info(app_id) " \
197 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
198 "(app_id text not null, " \
199 "category text not null, " \
200 "PRIMARY KEY(app_id,category) " \
201 "FOREIGN KEY(app_id) " \
202 "REFERENCES package_app_info(app_id) " \
205 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
206 "(app_id text not null, " \
207 "md_key text not null, " \
208 "md_value text not null, " \
209 "PRIMARY KEY(app_id, md_key, md_value) " \
210 "FOREIGN KEY(app_id) " \
211 "REFERENCES package_app_info(app_id) " \
214 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
215 "(app_id text not null, " \
216 "pm_type text not null, " \
217 "pm_value text not null, " \
218 "PRIMARY KEY(app_id, pm_type, pm_value) " \
219 "FOREIGN KEY(app_id) " \
220 "REFERENCES package_app_info(app_id) " \
223 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
224 "(app_id text not null, " \
225 "data_share_path text not null, " \
226 "data_share_allowed text not null, " \
227 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
228 "FOREIGN KEY(app_id) " \
229 "REFERENCES package_app_info(app_id) " \
232 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
233 "(app_id text not null, " \
234 "data_share_request text not null, " \
235 "PRIMARY KEY(app_id,data_share_request) " \
236 "FOREIGN KEY(app_id) " \
237 "REFERENCES package_app_info(app_id) " \
240 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
241 "(cert_info text not null, " \
242 "cert_id integer, " \
243 "cert_ref_count integer, " \
244 "PRIMARY KEY(cert_id)) "
246 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
247 "(package text not null, " \
248 "author_root_cert integer, " \
249 "author_im_cert integer, " \
250 "author_signer_cert integer, " \
251 "dist_root_cert integer, " \
252 "dist_im_cert integer, " \
253 "dist_signer_cert integer, " \
254 "dist2_root_cert integer, " \
255 "dist2_im_cert integer, " \
256 "dist2_signer_cert integer, " \
257 "PRIMARY KEY(package)) "
259 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
260 "(app_id text not null, " \
261 "providerid text not null, " \
262 "access text not null, " \
263 "type text not null, " \
264 "PRIMARY KEY(app_id, providerid, access, type) " \
265 "FOREIGN KEY(app_id) " \
266 "REFERENCES package_app_info(app_id) " \
269 static int __insert_application_info(manifest_x *mfx);
270 static int __insert_application_appsvc_info(manifest_x *mfx);
271 static int __insert_application_appcategory_info(manifest_x *mfx);
272 static int __insert_application_appcontrol_info(manifest_x *mfx);
273 static int __insert_application_appmetadata_info(manifest_x *mfx);
274 static int __insert_application_share_allowed_info(manifest_x *mfx);
275 static int __insert_application_share_request_info(manifest_x *mfx);
276 static int __insert_application_datacontrol_info(manifest_x *mfx);
277 static void __insert_application_locale_info(gpointer data, gpointer userdata);
278 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
279 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
280 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
281 static int __delete_subpkg_info_from_db(char *appid);
282 static int __delete_appinfo_from_db(char *db_table, const char *appid);
283 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
284 static int __exec_query(char *query);
285 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
286 char **label, char **license, char **icon, char **description, char **author);
287 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
288 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
289 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
290 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
291 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
292 static int __parserdb_change_perm(const char *db_file, uid_t uid);
294 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
297 __delete_subpkg_info_from_db(coltxt[0]);
302 static const char *__get_str(const char *str)
306 return PKGMGR_PARSER_EMPTY_STR;
312 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
317 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
318 if (ret != SQLITE_OK) {
319 _LOGD("connect db [%s] failed!\n", db_path);
327 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
329 manifest_x *mfx = (manifest_x *)data;
333 application_x *app = NULL;
334 for(i = 0; i < ncols; i++)
336 app = mfx->application;
337 if (strcmp(colname[i], "app_id") == 0) {
339 appid = strdup(coltxt[i]);
340 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
342 status = strdup(coltxt[i]);
346 _LOGD("app id is NULL\n");
349 /*update guest mode visibility*/
350 for (; app != NULL; app = app->next) {
351 if (strcmp(app->appid, appid) == 0) {
352 free((void *)app->guestmode_visibility);
353 app->guestmode_visibility = strdup(status);
369 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
371 char *error_message = NULL;
372 char query[MAX_QUERY_LEN] = {'\0'};
373 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
375 sqlite3_exec(pkgmgr_parser_db, query,
376 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
377 _LOGD("Don't execute query = %s error message = %s\n",
378 query, error_message);
379 sqlite3_free(error_message);
384 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
386 char *error_message = NULL;
388 sqlite3_exec(db_handle, db_query,
389 NULL, NULL, &error_message)) {
390 _LOGD("Don't execute query = %s error message = %s\n",
391 db_query, error_message);
392 sqlite3_free(error_message);
395 sqlite3_free(error_message);
399 static int __exec_query(char *query)
401 char *error_message = NULL;
403 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
404 _LOGD("Don't execute query = %s error message = %s\n", query,
406 sqlite3_free(error_message);
409 sqlite3_free(error_message);
413 static int __exec_query_no_msg(char *query)
415 char *error_message = NULL;
417 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
418 sqlite3_free(error_message);
421 sqlite3_free(error_message);
425 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
431 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
437 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
443 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
449 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
455 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
462 static GList *__create_icon_list(GList *locale, icon_x *icn)
467 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
473 static GList *__create_image_list(GList *locale, image_x *image)
478 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
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_application_locale_info(gpointer data, gpointer userdata)
652 char query[MAX_QUERY_LEN] = {'\0'};
654 application_x *app = (application_x*)userdata;
655 label_x *lbl = app->label;
656 icon_x *icn = app->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')", app->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(app->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, app->package, (char*)data);
687 ret = __exec_query_no_msg(query);
692 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
696 char *resolution = NULL;
697 char query[MAX_QUERY_LEN] = {'\0'};
699 application_x *app = (application_x*)userdata;
700 icon_x *icn = app->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')", app->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_application_image_info(gpointer data, gpointer userdata)
721 char query[MAX_QUERY_LEN] = {'\0'};
723 application_x *app = (application_x*)userdata;
724 image_x *image = app->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')", app->appid, lang, (char*)data, img);
733 ret = __exec_query(query);
735 _LOGD("Package UiApp image Info DB Insert failed\n");
740 static int __insert_mainapp_info(manifest_x *mfx)
742 application_x *app = mfx->application;
744 char query[MAX_QUERY_LEN] = {'\0'};
745 while (app != NULL) {
746 snprintf(query, MAX_QUERY_LEN,
747 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
749 ret = __exec_query(query);
751 _LOGD("Package App Info DB Insert Failed\n");
754 if (strcasecmp(app->mainapp, "True")==0)
755 mfx->mainapp_id = strdup(app->appid);
758 memset(query, '\0', MAX_QUERY_LEN);
761 if (mfx->mainapp_id == NULL) {
762 if (mfx->application && mfx->application->appid) {
763 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->application->appid);
765 _LOGD("Not valid appid\n");
769 ret = __exec_query(query);
771 _LOGD("Package UiApp Info DB Insert Failed\n");
775 free((void *)mfx->application->mainapp);
776 mfx->application->mainapp= strdup("true");
777 mfx->mainapp_id = strdup(mfx->application->appid);
780 memset(query, '\0', MAX_QUERY_LEN);
781 snprintf(query, MAX_QUERY_LEN,
782 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
783 ret = __exec_query(query);
785 _LOGD("Package Info DB update Failed\n");
791 /* _PRODUCT_LAUNCHING_ENHANCED_
792 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
794 static int __insert_application_info(manifest_x *mfx)
796 application_x *app = mfx->application;
798 char query[MAX_QUERY_LEN] = {'\0'};
799 while (app != NULL) {
800 snprintf(query, MAX_QUERY_LEN,
801 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
802 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
803 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
804 "app_preload, app_submode, app_submode_mainid, app_launch_mode, app_ui_gadget, app_support_disable, component_type, package) " \
805 "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')",\
819 __get_str(app->recentimage),
820 app->launchcondition,
821 app->indicatordisplay,
822 __get_str(app->portraitimg),
823 __get_str(app->landscapeimg),
824 app->guestmode_visibility,
825 app->permission_type,
828 __get_str(app->submode_mainid),
831 mfx->support_disable,
835 ret = __exec_query(query);
837 _LOGD("Package UiApp Info DB Insert Failed\n");
841 memset(query, '\0', MAX_QUERY_LEN);
846 static int __insert_application_appcategory_info(manifest_x *mfx)
848 application_x *app = mfx->application;
849 category_x *ct = NULL;
851 char query[MAX_QUERY_LEN] = {'\0'};
852 while (app != NULL) {
855 snprintf(query, MAX_QUERY_LEN,
856 "insert into package_app_app_category(app_id, category) " \
857 "values('%s','%s')",\
858 app->appid, ct->name);
859 ret = __exec_query(query);
861 _LOGD("Package UiApp Category Info DB Insert Failed\n");
865 memset(query, '\0', MAX_QUERY_LEN);
872 static int __insert_application_appmetadata_info(manifest_x *mfx)
874 application_x *app = mfx->application;
875 metadata_x *md = NULL;
877 char query[MAX_QUERY_LEN] = {'\0'};
878 while (app != NULL) {
882 snprintf(query, MAX_QUERY_LEN,
883 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
884 "values('%s','%s', '%s')",\
885 app->appid, md->key, md->value ? md->value : "");
886 ret = __exec_query(query);
888 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
893 memset(query, '\0', MAX_QUERY_LEN);
900 static int __insert_application_apppermission_info(manifest_x *mfx)
902 application_x *app = mfx->application;
903 permission_x *pm = NULL;
905 char query[MAX_QUERY_LEN] = {'\0'};
906 while (app != NULL) {
907 pm = app->permission;
909 snprintf(query, MAX_QUERY_LEN,
910 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
911 "values('%s','%s', '%s')",\
912 app->appid, pm->type, pm->value);
913 ret = __exec_query(query);
915 _LOGD("Package UiApp permission Info DB Insert Failed\n");
919 memset(query, '\0', MAX_QUERY_LEN);
926 static int __insert_application_appcontrol_info(manifest_x *mfx)
928 application_x *app = mfx->application;
929 appcontrol_x *acontrol = NULL;
931 char query[MAX_QUERY_LEN] = {'\0'};
932 char buf[BUFSIZE] = {'\0'};
933 while (app != NULL) {
934 acontrol = app->appcontrol;
935 while (acontrol != NULL) {
936 snprintf(buf, BUFSIZE, "%s|%s|%s",\
937 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
938 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
939 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
940 snprintf(query, MAX_QUERY_LEN,
941 "insert into package_app_app_control(app_id, app_control) " \
942 "values('%s', '%s')",\
944 ret = __exec_query(query);
946 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
949 memset(query, '\0', MAX_QUERY_LEN);
950 acontrol = acontrol->next;
957 /* FIXME: should be changed to app_control */
958 static int __insert_application_appsvc_info(manifest_x *mfx)
960 application_x *app = mfx->application;
961 appsvc_x *asvc = NULL;
962 operation_x *op = NULL;
965 subapp_x *sub = NULL;
967 char query[MAX_QUERY_LEN] = {'\0'};
968 const char *operation = NULL;
969 const char *mime = NULL;
970 const char *uri = NULL;
971 const char *subapp = NULL;
977 op = asvc->operation;
981 operation = op->name;
998 snprintf(query, MAX_QUERY_LEN,
999 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1000 "values('%s', '%s', '%s', '%s', '%s')",\
1007 ret = __exec_query(query);
1009 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1012 memset(query, '\0', MAX_QUERY_LEN);
1016 } while(ui != NULL);
1020 }while(sub != NULL);
1036 static int __insert_application_datacontrol_info(manifest_x *mfx)
1038 application_x *app = mfx->application;
1039 datacontrol_x *dc = NULL;
1041 char query[MAX_QUERY_LEN] = {'\0'};
1043 while (app != NULL) {
1044 dc = app->datacontrol;
1045 while (dc != NULL) {
1046 snprintf(query, MAX_QUERY_LEN,
1047 "insert into package_app_data_control(app_id, providerid, access, type) " \
1048 "values('%s', '%s', '%s', '%s')",\
1049 mfx->application->appid,
1054 ret = __exec_query(query);
1056 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1059 memset(query, '\0', MAX_QUERY_LEN);
1067 static int __insert_application_share_request_info(manifest_x *mfx)
1069 application_x *app = mfx->application;
1070 datashare_x *ds = NULL;
1071 request_x *rq = NULL;
1073 char query[MAX_QUERY_LEN] = {'\0'};
1074 while (app != NULL) {
1075 ds = app->datashare;
1076 while (ds != NULL) {
1078 while (rq != NULL) {
1079 snprintf(query, MAX_QUERY_LEN,
1080 "insert into package_app_share_request(app_id, data_share_request) " \
1081 "values('%s', '%s')",\
1082 app->appid, rq->text);
1083 ret = __exec_query(query);
1085 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1088 memset(query, '\0', MAX_QUERY_LEN);
1098 static int __insert_application_share_allowed_info(manifest_x *mfx)
1100 application_x *app = mfx->application;
1101 datashare_x *ds = NULL;
1102 define_x *df = NULL;
1103 allowed_x *al = NULL;
1105 char query[MAX_QUERY_LEN] = {'\0'};
1106 while (app != NULL) {
1107 ds = app->datashare;
1108 while (ds != NULL) {
1110 while (df != NULL) {
1112 while (al != NULL) {
1113 snprintf(query, MAX_QUERY_LEN,
1114 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1115 "values('%s', '%s', '%s')",\
1116 app->appid, df->path, al->text);
1117 ret = __exec_query(query);
1119 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1122 memset(query, '\0', MAX_QUERY_LEN);
1134 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1136 label_x *lbl = mfx->label;
1137 license_x *lcn = mfx->license;
1138 icon_x *icn = mfx->icon;
1139 description_x *dcn = mfx->description;
1140 author_x *ath = mfx->author;
1141 application_x *app = mfx->application;
1142 application_x *app_icn = mfx->application;
1143 application_x *app_image = mfx->application;
1144 privileges_x *pvs = NULL;
1145 privilege_x *pv = NULL;
1146 char query[MAX_QUERY_LEN] = { '\0' };
1148 const char *auth_name = NULL;
1149 const char *auth_email = NULL;
1150 const char *auth_href = NULL;
1152 GList *pkglocale = NULL;
1153 GList *applocale = NULL;
1154 GList *appicon = NULL;
1155 GList *appimage = NULL;
1159 auth_name = ath->text;
1161 auth_email = ath->email;
1163 auth_href = ath->href;
1165 /*Insert in the package_cert_info CERT_DB*/
1166 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1167 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1168 if (ret != PMINFO_R_OK) {
1169 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1170 _LOGE("Cert Info DB create handle failed\n");
1173 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1174 if (ret != PMINFO_R_OK) {
1175 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1176 _LOGE("Cert Info DB Insert Failed\n");
1180 /*Insert in the package_info DB*/
1181 snprintf(query, MAX_QUERY_LEN,
1182 "insert into package_info(package, package_type, package_version, package_api_version, install_location, package_size, " \
1183 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1184 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1185 "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')",\
1189 __get_str(mfx->api_version),
1190 __get_str(mfx->installlocation),
1191 __get_str(mfx->package_size),
1197 mfx->nodisplay_setting,
1199 __get_str(auth_name),
1200 __get_str(auth_email),
1201 __get_str(auth_href),
1202 mfx->installed_time,
1203 mfx->installed_storage,
1204 __get_str(mfx->storeclient_id),
1206 __get_str(mfx->package_url),
1208 __get_str(mfx->csc_path),
1209 mfx->support_disable);
1211 ret = __exec_query(query);
1213 _LOGD("Package Info DB Insert Failed\n");
1217 /*Insert in the package_privilege_info DB*/
1218 pvs = mfx->privileges;
1219 while (pvs != NULL) {
1220 pv = pvs->privilege;
1221 while (pv != NULL) {
1222 memset(query, '\0', MAX_QUERY_LEN);
1223 snprintf(query, MAX_QUERY_LEN,
1224 "insert into package_privilege_info(package, privilege) " \
1225 "values('%s','%s')",\
1226 mfx->package, pv->text);
1227 ret = __exec_query(query);
1229 _LOGD("Package Privilege Info DB Insert Failed\n");
1238 ret = __insert_mainapp_info(mfx);
1243 /*Insert the package locale*/
1244 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1245 /*remove duplicated data in pkglocale*/
1246 __trimfunc(pkglocale);
1248 /*Insert the app locale info */
1249 while (app != NULL) {
1250 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1253 /*remove duplicated data in applocale*/
1254 __trimfunc(applocale);
1256 /*Insert the app icon info */
1257 while (app_icn != NULL) {
1258 appicon = __create_icon_list(appicon, app_icn->icon);
1259 app_icn = app_icn->next;
1261 /*remove duplicated data in appicon*/
1262 __trimfunc(appicon);
1264 /*Insert the image info */
1265 while (app_image != NULL) {
1266 appimage = __create_image_list(appimage, app_image->image);
1267 app_image = app_image->next;
1269 /*remove duplicated data in appimage*/
1270 __trimfunc(appimage);
1272 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1274 /*native app locale info*/
1275 app = mfx->application;
1276 while (app != NULL) {
1277 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1281 /*app icon locale info*/
1282 app_icn = mfx->application;
1283 while (app_icn != NULL) {
1284 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app_icn);
1285 app_icn = app_icn->next;
1289 app_image = mfx->application;
1290 while (app_image != NULL) {
1291 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app_image);
1292 app_image = app_image->next;
1295 g_list_free(pkglocale);
1297 g_list_free(applocale);
1299 g_list_free(appicon);
1301 g_list_free(appimage);
1304 /*Insert in the package_app_info DB*/
1305 ret = __insert_application_info(mfx);
1308 /*Insert in the package_app_app_control DB*/
1309 ret = __insert_application_appcontrol_info(mfx);
1313 /*Insert in the package_app_app_category DB*/
1314 ret = __insert_application_appcategory_info(mfx);
1318 /*Insert in the package_app_app_metadata DB*/
1319 ret = __insert_application_appmetadata_info(mfx);
1323 /*Insert in the package_app_app_permission DB*/
1324 ret = __insert_application_apppermission_info(mfx);
1328 /*Insert in the package_app_app_svc DB*/
1329 ret = __insert_application_appsvc_info(mfx);
1333 /*Insert in the package_app_share_allowed DB*/
1334 ret = __insert_application_share_allowed_info(mfx);
1338 /*Insert in the package_app_share_request DB*/
1339 ret = __insert_application_share_request_info(mfx);
1343 /*Insert in the package_app_data_control DB*/
1344 ret = __insert_application_datacontrol_info(mfx);
1352 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1354 char query[MAX_QUERY_LEN] = { '\0' };
1356 memset(query, '\0', MAX_QUERY_LEN);
1357 snprintf(query, MAX_QUERY_LEN,
1358 "delete from %s where app_id='%s'", db_table, appid);
1359 ret = __exec_query(query);
1361 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1367 static int __delete_subpkg_info_from_db(char *appid)
1371 ret = __delete_appinfo_from_db("package_app_info", appid);
1374 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1377 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1380 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1383 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1386 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1389 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1392 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1395 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1398 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1401 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1404 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1411 static int __delete_subpkg_from_db(manifest_x *mfx)
1413 char query[MAX_QUERY_LEN] = { '\0' };
1414 char *error_message = NULL;
1416 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1418 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1419 _LOGE("Don't execute query = %s error message = %s\n", query,
1421 sqlite3_free(error_message);
1424 sqlite3_free(error_message);
1429 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1431 char query[MAX_QUERY_LEN] = { '\0' };
1433 application_x *app = mfx->application;
1434 /*Delete from cert table*/
1435 if (uid != GLOBAL_USER)
1436 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1438 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1440 _LOGD("Cert Info DB Delete Failed\n");
1444 /*Delete from Package Info DB*/
1445 snprintf(query, MAX_QUERY_LEN,
1446 "delete from package_info where package='%s'", mfx->package);
1447 ret = __exec_query(query);
1449 _LOGD("Package Info DB Delete Failed\n");
1452 memset(query, '\0', MAX_QUERY_LEN);
1454 /*Delete from Package Localized Info*/
1455 snprintf(query, MAX_QUERY_LEN,
1456 "delete from package_localized_info where package='%s'", mfx->package);
1457 ret = __exec_query(query);
1459 _LOGD("Package Localized Info DB Delete Failed\n");
1463 /*Delete from Package Privilege Info*/
1464 snprintf(query, MAX_QUERY_LEN,
1465 "delete from package_privilege_info where package='%s'", mfx->package);
1466 ret = __exec_query(query);
1468 _LOGD("Package Privilege Info DB Delete Failed\n");
1472 while (app != NULL) {
1473 ret = __delete_appinfo_from_db("package_app_info", app->appid);
1476 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
1479 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
1482 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
1485 ret = __delete_appinfo_from_db("package_app_app_svc", app->appid);
1488 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
1491 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
1494 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
1497 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
1500 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
1503 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
1506 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
1512 /* if main package has sub pkg, delete sub pkg data*/
1513 __delete_subpkg_from_db(mfx);
1518 static int __update_preload_condition_in_db()
1521 char query[MAX_QUERY_LEN] = {'\0'};
1523 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
1525 ret = __exec_query(query);
1527 _LOGD("Package preload_condition update failed\n");
1532 API int pkgmgr_parser_initialize_db(uid_t uid)
1536 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
1538 _LOGD("package info DB initialization failed\n");
1541 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
1543 _LOGD("package localized info DB initialization failed\n");
1546 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
1548 _LOGD("package app app privilege DB initialization failed\n");
1551 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
1553 _LOGD("package app info DB initialization failed\n");
1556 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
1558 _LOGD("package app localized info DB initialization failed\n");
1561 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
1563 _LOGD("package app icon localized info DB initialization failed\n");
1566 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
1568 _LOGD("package app image info DB initialization failed\n");
1571 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
1573 _LOGD("package app app control DB initialization failed\n");
1576 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
1578 _LOGD("package app app category DB initialization failed\n");
1581 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
1583 _LOGD("package app app category DB initialization failed\n");
1586 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
1588 _LOGD("package app app permission DB initialization failed\n");
1591 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
1593 _LOGD("package app app svc DB initialization failed\n");
1596 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
1598 _LOGD("package app share allowed DB initialization failed\n");
1601 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
1603 _LOGD("package app share request DB initialization failed\n");
1606 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
1608 _LOGD("package app data control DB initialization failed\n");
1612 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
1614 _LOGD("package cert info DB initialization failed\n");
1617 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
1619 _LOGD("package cert index info DB initialization failed\n");
1623 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
1624 _LOGD("Failed to change cert db permission\n");
1626 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
1627 _LOGD("Failed to change parser db permission\n");
1633 static int __parserdb_change_perm(const char *db_file, uid_t uid)
1636 char journal_file[BUFSIZE];
1639 struct passwd *userinfo = NULL;
1640 files[0] = (char *)db_file;
1641 files[1] = journal_file;
1644 if (db_file == NULL)
1647 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
1649 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
1650 if (uid == OWNER_ROOT)
1652 userinfo = getpwuid(uid);
1654 _LOGE("FAIL: user %d doesn't exist", uid);
1657 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
1659 for (i = 0; files[i]; i++) {
1660 ret = chown(files[i], uid, userinfo->pw_gid);
1662 if (strerror_r(errno, buf, sizeof(buf)))
1664 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
1665 userinfo->pw_gid, buf);
1669 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
1671 if (strerror_r(errno, buf, sizeof(buf)))
1673 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
1676 SET_SMACK_LABEL(files[i]);
1681 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
1685 if (getuid() != OWNER_ROOT) {
1686 _LOGE("Only root user is allowed");
1690 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
1691 _LOGE("Manifest db for user %d is already exists", uid);
1695 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
1696 _LOGE("Cert db for user %d is already exists", uid);
1700 ret = pkgmgr_parser_check_and_create_db(uid);
1703 ret = pkgmgr_parser_initialize_db(uid);
1705 pkgmgr_parser_close_db();
1708 pkgmgr_parser_close_db();
1713 API int pkgmgr_parser_check_and_create_db(uid_t uid)
1717 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
1719 _LOGD("Manifest DB creation Failed\n");
1724 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid));
1726 _LOGD("Cert DB creation Failed\n");
1732 void pkgmgr_parser_close_db(void)
1734 sqlite3_close(pkgmgr_parser_db);
1735 sqlite3_close(pkgmgr_cert_db);
1739 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
1741 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
1743 _LOGD("manifest pointer is NULL\n");
1747 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
1749 _LOGD("Failed to open DB\n");
1752 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
1755 /*Begin transaction*/
1756 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1757 if (ret != SQLITE_OK) {
1758 _LOGD("Failed to begin transaction\n");
1762 _LOGD("Transaction Begin\n");
1763 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
1765 _LOGD("Insert into DB failed. Rollback now\n");
1766 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1769 /*Commit transaction*/
1770 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1771 if (ret != SQLITE_OK) {
1772 _LOGD("Failed to commit transaction. Rollback now\n");
1773 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1777 _LOGD("Transaction Commit and End\n");
1779 pkgmgr_parser_close_db();
1783 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
1785 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
1787 _LOGD("manifest pointer is NULL\n");
1791 ret = pkgmgr_parser_check_and_create_db(uid);
1793 _LOGD("Failed to open DB\n");
1796 ret = pkgmgr_parser_initialize_db(uid);
1799 /*Begin transaction*/
1800 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1801 if (ret != SQLITE_OK) {
1802 _LOGD("Failed to begin transaction\n");
1806 _LOGD("Transaction Begin\n");
1807 ret = __insert_manifest_info_in_db(mfx, uid);
1809 _LOGD("Insert into DB failed. Rollback now\n");
1810 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1813 /*Commit transaction*/
1814 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1815 if (ret != SQLITE_OK) {
1816 _LOGD("Failed to commit transaction. Rollback now\n");
1817 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1821 _LOGD("Transaction Commit and End\n");
1823 pkgmgr_parser_close_db();
1827 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
1830 _LOGD("manifest pointer is NULL\n");
1834 ret = pkgmgr_parser_check_and_create_db(uid);
1836 _LOGD("Failed to open DB\n");
1839 ret = pkgmgr_parser_initialize_db(uid);
1842 /*Preserve guest mode visibility*/
1843 __preserve_guestmode_visibility_value( mfx);
1844 /*Begin transaction*/
1845 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1846 if (ret != SQLITE_OK) {
1847 _LOGD("Failed to begin transaction\n");
1851 _LOGD("Transaction Begin\n");
1852 ret = __delete_manifest_info_from_db(mfx, uid);
1854 _LOGD("Delete from DB failed. Rollback now\n");
1855 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1858 ret = __insert_manifest_info_in_db(mfx, uid);
1860 _LOGD("Insert into DB failed. Rollback now\n");
1861 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1865 /*Commit transaction*/
1866 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1867 if (ret != SQLITE_OK) {
1868 _LOGD("Failed to commit transaction. Rollback now\n");
1869 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1873 _LOGD("Transaction Commit and End\n");
1875 pkgmgr_parser_close_db();
1879 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
1881 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
1884 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
1887 _LOGD("manifest pointer is NULL\n");
1891 ret = pkgmgr_parser_check_and_create_db(uid);
1893 _LOGD("Failed to open DB\n");
1896 /*Begin transaction*/
1897 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1898 if (ret != SQLITE_OK) {
1899 _LOGD("Failed to begin transaction\n");
1903 _LOGD("Transaction Begin\n");
1904 ret = __delete_manifest_info_from_db(mfx, uid);
1906 _LOGD("Delete from DB failed. Rollback now\n");
1907 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1910 /*Commit transaction*/
1911 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1912 if (ret != SQLITE_OK) {
1913 _LOGD("Failed to commit transaction, Rollback now\n");
1914 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1918 _LOGD("Transaction Commit and End\n");
1920 pkgmgr_parser_close_db();
1924 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
1926 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
1929 API int pkgmgr_parser_update_preload_info_in_db()
1932 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
1934 _LOGD("Failed to open DB\n");
1937 /*Begin transaction*/
1938 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1939 if (ret != SQLITE_OK) {
1940 _LOGD("Failed to begin transaction\n");
1944 _LOGD("Transaction Begin\n");
1945 ret = __update_preload_condition_in_db();
1947 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
1948 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1951 /*Commit transaction*/
1952 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1953 if (ret != SQLITE_OK) {
1954 _LOGD("Failed to commit transaction, Rollback now\n");
1955 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1959 _LOGD("Transaction Commit and End\n");
1961 pkgmgr_parser_close_db();
1965 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
1968 ret = pkgmgr_parser_check_and_create_db(uid);
1970 _LOGD("Failed to open DB\n");
1973 /*Begin transaction*/
1974 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1975 if (ret != SQLITE_OK) {
1976 _LOGD("Failed to begin transaction\n");
1980 _LOGD("Transaction Begin\n");
1981 ret = __update_preload_condition_in_db();
1983 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
1984 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1987 /*Commit transaction*/
1988 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1989 if (ret != SQLITE_OK) {
1990 _LOGD("Failed to commit transaction, Rollback now\n");
1991 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1995 _LOGD("Transaction Commit and End\n");
1997 pkgmgr_parser_close_db();