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_CATEGORY "create table if not exists package_app_app_category " \
187 "(app_id text not null, " \
188 "category text not null, " \
189 "PRIMARY KEY(app_id,category) " \
190 "FOREIGN KEY(app_id) " \
191 "REFERENCES package_app_info(app_id) " \
194 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
195 "(app_id text not null, " \
196 "md_key text not null, " \
197 "md_value text not null, " \
198 "PRIMARY KEY(app_id, md_key, md_value) " \
199 "FOREIGN KEY(app_id) " \
200 "REFERENCES package_app_info(app_id) " \
203 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
204 "(app_id text not null, " \
205 "pm_type text not null, " \
206 "pm_value text not null, " \
207 "PRIMARY KEY(app_id, pm_type, pm_value) " \
208 "FOREIGN KEY(app_id) " \
209 "REFERENCES package_app_info(app_id) " \
212 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
213 "(app_id text not null, " \
214 "data_share_path text not null, " \
215 "data_share_allowed text not null, " \
216 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
217 "FOREIGN KEY(app_id) " \
218 "REFERENCES package_app_info(app_id) " \
221 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
222 "(app_id text not null, " \
223 "data_share_request text not null, " \
224 "PRIMARY KEY(app_id,data_share_request) " \
225 "FOREIGN KEY(app_id) " \
226 "REFERENCES package_app_info(app_id) " \
229 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
230 "(cert_info text not null, " \
231 "cert_id integer, " \
232 "cert_ref_count integer, " \
233 "PRIMARY KEY(cert_id)) "
235 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
236 "(package text not null, " \
237 "author_root_cert integer, " \
238 "author_im_cert integer, " \
239 "author_signer_cert integer, " \
240 "dist_root_cert integer, " \
241 "dist_im_cert integer, " \
242 "dist_signer_cert integer, " \
243 "dist2_root_cert integer, " \
244 "dist2_im_cert integer, " \
245 "dist2_signer_cert integer, " \
246 "PRIMARY KEY(package)) "
248 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
249 "(app_id text not null, " \
250 "providerid text not null, " \
251 "access text not null, " \
252 "type text not null, " \
253 "PRIMARY KEY(app_id, providerid, access, type) " \
254 "FOREIGN KEY(app_id) " \
255 "REFERENCES package_app_info(app_id) " \
258 static int __insert_application_info(manifest_x *mfx);
259 static int __insert_application_appcategory_info(manifest_x *mfx);
260 static int __insert_application_appcontrol_info(manifest_x *mfx);
261 static int __insert_application_appmetadata_info(manifest_x *mfx);
262 static int __insert_application_share_allowed_info(manifest_x *mfx);
263 static int __insert_application_share_request_info(manifest_x *mfx);
264 static int __insert_application_datacontrol_info(manifest_x *mfx);
265 static void __insert_application_locale_info(gpointer data, gpointer userdata);
266 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
267 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
268 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
269 static int __delete_subpkg_info_from_db(char *appid);
270 static int __delete_appinfo_from_db(char *db_table, const char *appid);
271 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
272 static int __exec_query(char *query);
273 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
274 char **label, char **license, char **icon, char **description, char **author);
275 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
276 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
277 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
278 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
279 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
280 static int __parserdb_change_perm(const char *db_file, uid_t uid);
282 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
285 __delete_subpkg_info_from_db(coltxt[0]);
290 static const char *__get_str(const char *str)
294 return PKGMGR_PARSER_EMPTY_STR;
300 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
305 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
306 if (ret != SQLITE_OK) {
307 _LOGD("connect db [%s] failed!\n", db_path);
315 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
317 manifest_x *mfx = (manifest_x *)data;
323 if (mfx->application == NULL)
325 app = (application_x *)mfx->application->data;
326 for(i = 0; i < ncols; i++)
328 if (strcmp(colname[i], "app_id") == 0) {
330 appid = strdup(coltxt[i]);
331 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
333 status = strdup(coltxt[i]);
337 _LOGD("app id is NULL\n");
340 /*update guest mode visibility*/
341 for (tmp = mfx->application; tmp; tmp = tmp->next) {
342 app = (application_x *)tmp->data;
345 if (strcmp(app->appid, appid) == 0) {
346 free((void *)app->guestmode_visibility);
347 app->guestmode_visibility = strdup(status);
363 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
365 char *error_message = NULL;
366 char query[MAX_QUERY_LEN] = {'\0'};
367 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
369 sqlite3_exec(pkgmgr_parser_db, query,
370 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
371 _LOGD("Don't execute query = %s error message = %s\n",
372 query, error_message);
373 sqlite3_free(error_message);
378 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
380 char *error_message = NULL;
382 sqlite3_exec(db_handle, db_query,
383 NULL, NULL, &error_message)) {
384 _LOGD("Don't execute query = %s error message = %s\n",
385 db_query, error_message);
386 sqlite3_free(error_message);
389 sqlite3_free(error_message);
393 static int __exec_query(char *query)
395 char *error_message = NULL;
397 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
398 _LOGD("Don't execute query = %s error message = %s\n", query,
400 sqlite3_free(error_message);
403 sqlite3_free(error_message);
407 static int __exec_query_no_msg(char *query)
409 char *error_message = NULL;
411 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
412 sqlite3_free(error_message);
415 sqlite3_free(error_message);
419 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
427 for (tmp = lbls; tmp; tmp = tmp->next) {
428 lbl = (label_x *)tmp->data;
432 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
434 for (tmp = lcns; tmp; tmp = tmp->next) {
435 lcn = (license_x *)tmp->data;
439 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
441 for (tmp = icns; tmp; tmp = tmp->next) {
442 icn = (icon_x *)tmp->data;
446 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
448 for (tmp = dcns; tmp; tmp = tmp->next) {
449 dcn = (description_x *)tmp->data;
453 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
455 for (tmp = aths; tmp; tmp = tmp->next) {
456 ath = (author_x *)tmp->data;
460 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
466 static GList *__create_icon_list(GList *locale, GList *icns)
471 for (tmp = icns; tmp; tmp = tmp->next) {
472 icn = (icon_x *)tmp->data;
476 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
481 static GList *__create_image_list(GList *locale, GList *imgs)
486 for (tmp = imgs; tmp; tmp = tmp->next) {
487 img = (image_x *)tmp->data;
491 locale = g_list_insert_sorted_with_data(locale, (gpointer)img->section, __comparefunc, NULL);
496 static void __trimfunc(GList* trim_list)
498 char *trim_data = NULL;
502 list = g_list_first(trim_list);
505 trim_data = (char *)list->data;
508 if (strcmp(trim_data, prev) == 0) {
509 trim_list = g_list_remove(trim_list, trim_data);
510 list = g_list_first(trim_list);
519 list = g_list_next(list);
523 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
525 if (a == NULL || b == NULL)
527 if (strcmp((char*)a, (char*)b) == 0)
529 if (strcmp((char*)a, (char*)b) < 0)
531 if (strcmp((char*)a, (char*)b) > 0)
536 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
537 char **label, char **license, char **icon, char **description, char **author)
545 for (tmp = lbls; tmp; tmp = tmp->next) {
546 lbl = (label_x *)tmp->data;
550 if (strcmp(lbl->lang, (char *)data) == 0) {
551 *label = (char*)lbl->text;
556 for (tmp = lcns; tmp; tmp = tmp->next) {
557 lcn = (license_x *)tmp->data;
561 if (strcmp(lcn->lang, (char *)data) == 0) {
562 *license = (char*)lcn->text;
567 for (tmp = icns; tmp; tmp = tmp->next) {
568 icn = (icon_x *)tmp->data;
572 if (strcmp(icn->lang, (char *)data) == 0) {
573 *icon = (char*)icn->text;
578 for (tmp = dcns; tmp; tmp = tmp->next) {
579 dcn = (description_x *)tmp->data;
583 if (strcmp(dcn->lang, (char *)data) == 0) {
584 *description = (char*)dcn->text;
589 for (tmp = aths; tmp; tmp = tmp->next) {
590 ath = (author_x *)tmp->data;
594 if (strcmp(ath->lang, (char *)data) == 0) {
595 *author = (char*)ath->text;
603 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
607 for (tmp = icns; tmp; tmp = tmp->next) {
608 icn = (icon_x *)tmp->data;
612 if (strcmp(icn->section, (char *)data) == 0) {
613 *icon = (char*)icn->text;
614 *resolution = (char*)icn->resolution;
621 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
625 for (tmp = imgs; tmp; tmp = tmp->next) {
626 img = (image_x *)tmp->data;
630 if (strcmp(img->section, (char *)data) == 0) {
631 *lang = (char*)img->lang;
632 *image = (char*)img->text;
639 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
644 char *description = NULL;
645 char *license = NULL;
647 char query[MAX_QUERY_LEN] = {'\0'};
649 manifest_x *mfx = (manifest_x *)userdata;
650 GList *lbl = mfx->label;
651 GList *lcn = mfx->license;
652 GList *icn = mfx->icon;
653 GList *dcn = mfx->description;
654 GList *ath = mfx->author;
656 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
657 if (!label && !description && !icon && !license && !author)
660 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
661 "package_label, package_icon, package_description, package_license, package_author) values " \
662 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
667 __get_str(description),
671 ret = __exec_query(query);
673 _LOGD("Package Localized Info DB Insert failed\n");
676 static void __insert_application_locale_info(gpointer data, gpointer userdata)
681 char query[MAX_QUERY_LEN] = {'\0'};
683 application_x *app = (application_x*)userdata;
684 GList *lbl = app->label;
685 GList *icn = app->icon;
687 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
690 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
691 "app_label, app_icon) values " \
692 "('%q', '%q', '%q', '%q')", app->appid, (char*)data,
694 ret = __exec_query(query);
696 _LOGD("Package UiApp Localized Info DB Insert failed\n");
698 /*insert ui app locale info to pkg locale to get mainapp data */
699 if (strcasecmp(app->mainapp, "true")==0) {
700 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
701 "package_label, package_icon, package_description, package_license, package_author) values " \
702 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
707 PKGMGR_PARSER_EMPTY_STR,
708 PKGMGR_PARSER_EMPTY_STR,
709 PKGMGR_PARSER_EMPTY_STR);
711 ret = __exec_query_no_msg(query);
714 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
715 "where package='%s' and package_locale='%s'", icon, app->package, (char*)data);
716 ret = __exec_query_no_msg(query);
721 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
725 char *resolution = NULL;
726 char query[MAX_QUERY_LEN] = {'\0'};
728 application_x *app = (application_x*)userdata;
729 GList *icn = app->icon;
731 __extract_icon_data(data, icn, &icon, &resolution);
732 if (!icon && !resolution)
734 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
735 "app_icon, app_icon_section, app_icon_resolution) values " \
736 "('%q', '%q', '%q', '%q')", app->appid,
737 icon, (char*)data, resolution);
739 ret = __exec_query(query);
741 _LOGD("Package UiApp Localized Info DB Insert failed\n");
745 static void __insert_application_image_info(gpointer data, gpointer userdata)
750 char query[MAX_QUERY_LEN] = {'\0'};
752 application_x *app = (application_x*)userdata;
753 GList *image = app->image;
755 __extract_image_data(data, image, &lang, &img);
758 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
759 "app_image_section, app_image) values " \
760 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
762 ret = __exec_query(query);
764 _LOGD("Package UiApp image Info DB Insert failed\n");
769 static int __insert_mainapp_info(manifest_x *mfx)
774 char query[MAX_QUERY_LEN] = {'\0'};
775 for (tmp = mfx->application; tmp; tmp = tmp->next) {
776 app = (application_x *)tmp->data;
779 snprintf(query, MAX_QUERY_LEN,
780 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
782 ret = __exec_query(query);
784 _LOGD("Package App Info DB Insert Failed\n");
787 if (strcasecmp(app->mainapp, "True")==0)
788 mfx->mainapp_id = strdup(app->appid);
791 if (mfx->mainapp_id == NULL) {
792 if (mfx->application == NULL)
794 app = (application_x *)mfx->application->data;
798 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
800 _LOGD("Not valid appid\n");
804 ret = __exec_query(query);
806 _LOGD("Package UiApp Info DB Insert Failed\n");
810 free((void *)app->mainapp);
811 app->mainapp= strdup("true");
812 mfx->mainapp_id = strdup(app->appid);
815 memset(query, '\0', MAX_QUERY_LEN);
816 snprintf(query, MAX_QUERY_LEN,
817 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
818 ret = __exec_query(query);
820 _LOGD("Package Info DB update Failed\n");
826 /* _PRODUCT_LAUNCHING_ENHANCED_
827 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
829 static int __insert_application_info(manifest_x *mfx)
834 char query[MAX_QUERY_LEN] = {'\0'};
835 for (tmp = mfx->application; tmp; tmp = tmp->next) {
836 app = (application_x *)tmp->data;
839 snprintf(query, MAX_QUERY_LEN,
840 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
841 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
842 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
843 "app_preload, app_submode, app_submode_mainid, app_launch_mode, app_ui_gadget, app_support_disable, component_type, package) " \
844 "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')",\
858 __get_str(app->recentimage),
859 app->launchcondition,
860 app->indicatordisplay,
861 __get_str(app->portraitimg),
862 __get_str(app->landscapeimg),
863 app->guestmode_visibility,
864 app->permission_type,
867 __get_str(app->submode_mainid),
870 mfx->support_disable,
874 ret = __exec_query(query);
876 _LOGD("Package UiApp Info DB Insert Failed\n");
879 memset(query, '\0', MAX_QUERY_LEN);
884 static int __insert_application_appcategory_info(manifest_x *mfx)
891 char query[MAX_QUERY_LEN] = {'\0'};
892 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
893 app = (application_x *)app_tmp->data;
896 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
897 ct = (const char *)ct_tmp->data;
900 snprintf(query, MAX_QUERY_LEN,
901 "insert into package_app_app_category(app_id, category) " \
902 "values('%s','%s')",\
904 ret = __exec_query(query);
906 _LOGD("Package UiApp Category Info DB Insert Failed\n");
909 memset(query, '\0', MAX_QUERY_LEN);
915 static int __insert_application_appmetadata_info(manifest_x *mfx)
922 char query[MAX_QUERY_LEN] = {'\0'};
923 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
924 app = (application_x *)app_tmp->data;
927 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
928 md = (metadata_x *)md_tmp->data;
932 snprintf(query, MAX_QUERY_LEN,
933 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
934 "values('%s','%s', '%s')",\
935 app->appid, md->key, md->value ? md->value : "");
936 ret = __exec_query(query);
938 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
942 memset(query, '\0', MAX_QUERY_LEN);
948 static int __insert_application_apppermission_info(manifest_x *mfx)
955 char query[MAX_QUERY_LEN] = {'\0'};
956 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
957 app = (application_x *)app_tmp->data;
960 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
961 pm = (permission_x *)pm_tmp->data;
964 snprintf(query, MAX_QUERY_LEN,
965 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
966 "values('%s','%s', '%s')",\
967 app->appid, pm->type, pm->value);
968 ret = __exec_query(query);
970 _LOGD("Package UiApp permission Info DB Insert Failed\n");
973 memset(query, '\0', MAX_QUERY_LEN);
979 static int __insert_application_appcontrol_info(manifest_x *mfx)
984 appcontrol_x *acontrol;
986 char query[MAX_QUERY_LEN] = {'\0'};
987 char buf[BUFSIZE] = {'\0'};
988 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
989 app = (application_x *)app_tmp->data;
992 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
993 acontrol = (appcontrol_x *)acontrol_tmp->data;
994 if (acontrol == NULL)
996 snprintf(buf, BUFSIZE, "%s|%s|%s",\
997 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
998 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
999 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1000 snprintf(query, MAX_QUERY_LEN,
1001 "insert into package_app_app_control(app_id, app_control) " \
1002 "values('%s', '%s')",\
1004 ret = __exec_query(query);
1006 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1009 memset(query, '\0', MAX_QUERY_LEN);
1015 static int __insert_application_datacontrol_info(manifest_x *mfx)
1022 char query[MAX_QUERY_LEN] = {'\0'};
1024 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1025 app = (application_x *)app_tmp->data;
1028 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1029 dc = (datacontrol_x *)dc_tmp->data;
1032 snprintf(query, MAX_QUERY_LEN,
1033 "insert into package_app_data_control(app_id, providerid, access, type) " \
1034 "values('%s', '%s', '%s', '%s')",\
1040 ret = __exec_query(query);
1042 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1045 memset(query, '\0', MAX_QUERY_LEN);
1051 static int __insert_application_share_request_info(manifest_x *mfx)
1060 char query[MAX_QUERY_LEN] = {'\0'};
1061 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1062 app = (application_x *)app_tmp->data;
1065 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1066 ds = (datashare_x *)ds_tmp->data;
1069 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1070 rq = (const char *)rq_tmp->data;
1073 snprintf(query, MAX_QUERY_LEN,
1074 "insert into package_app_share_request(app_id, data_share_request) " \
1075 "values('%s', '%s')",\
1077 ret = __exec_query(query);
1079 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1082 memset(query, '\0', MAX_QUERY_LEN);
1089 static int __insert_application_share_allowed_info(manifest_x *mfx)
1100 char query[MAX_QUERY_LEN] = {'\0'};
1101 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1102 app = (application_x *)app_tmp->data;
1105 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1106 ds = (datashare_x *)ds_tmp->data;
1109 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1110 df = (define_x *)df_tmp->data;
1113 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1114 al = (const char *)al_tmp->data;
1117 snprintf(query, MAX_QUERY_LEN,
1118 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1119 "values('%s', '%s', '%s')",\
1120 app->appid, df->path, al);
1121 ret = __exec_query(query);
1123 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1126 memset(query, '\0', MAX_QUERY_LEN);
1134 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1138 const char *pv = NULL;
1139 char query[MAX_QUERY_LEN] = { '\0' };
1142 const char *auth_name = NULL;
1143 const char *auth_email = NULL;
1144 const char *auth_href = NULL;
1146 GList *pkglocale = NULL;
1147 GList *applocale = NULL;
1148 GList *appicon = NULL;
1149 GList *appimage = NULL;
1151 if (mfx->author && mfx->author->data) {
1152 author = (author_x *)mfx->author->data;
1154 auth_name = author->text;
1156 auth_email = author->email;
1158 auth_href = author->href;
1160 /*Insert in the package_cert_info CERT_DB*/
1161 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1162 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1163 if (ret != PMINFO_R_OK) {
1164 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1165 _LOGE("Cert Info DB create handle failed\n");
1168 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1169 if (ret != PMINFO_R_OK) {
1170 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1171 _LOGE("Cert Info DB Insert Failed\n");
1175 /*Insert in the package_info DB*/
1176 snprintf(query, MAX_QUERY_LEN,
1177 "insert into package_info(package, package_type, package_version, package_api_version, install_location, package_size, " \
1178 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1179 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1180 "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')",\
1184 __get_str(mfx->api_version),
1185 __get_str(mfx->installlocation),
1186 __get_str(mfx->package_size),
1192 mfx->nodisplay_setting,
1194 __get_str(auth_name),
1195 __get_str(auth_email),
1196 __get_str(auth_href),
1197 mfx->installed_time,
1198 mfx->installed_storage,
1199 __get_str(mfx->storeclient_id),
1201 __get_str(mfx->package_url),
1203 __get_str(mfx->csc_path),
1204 mfx->support_disable);
1206 ret = __exec_query(query);
1208 _LOGD("Package Info DB Insert Failed\n");
1212 /*Insert in the package_privilege_info DB*/
1213 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1214 pv = (const char *)tmp->data;
1217 memset(query, '\0', MAX_QUERY_LEN);
1218 snprintf(query, MAX_QUERY_LEN,
1219 "insert into package_privilege_info(package, privilege) " \
1220 "values('%s','%s')",\
1222 ret = __exec_query(query);
1224 _LOGD("Package Privilege Info DB Insert Failed\n");
1229 if (mfx->application != NULL) {
1230 ret = __insert_mainapp_info(mfx);
1235 /*Insert the package locale*/
1236 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1237 /*remove duplicated data in pkglocale*/
1238 __trimfunc(pkglocale);
1240 /*Insert the app locale, icon, image info */
1241 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1242 app = (application_x *)tmp->data;
1245 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1246 appicon = __create_icon_list(appicon, app->icon);
1247 appimage = __create_image_list(appimage, app->image);
1249 /*remove duplicated data in applocale*/
1250 __trimfunc(applocale);
1251 __trimfunc(appicon);
1252 __trimfunc(appimage);
1254 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1256 /*native app locale info*/
1257 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1258 app = (application_x *)tmp->data;
1261 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1262 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1263 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1266 g_list_free(pkglocale);
1268 g_list_free(applocale);
1270 g_list_free(appicon);
1272 g_list_free(appimage);
1275 /*Insert in the package_app_info DB*/
1276 ret = __insert_application_info(mfx);
1279 /*Insert in the package_app_app_control DB*/
1280 ret = __insert_application_appcontrol_info(mfx);
1284 /*Insert in the package_app_app_category DB*/
1285 ret = __insert_application_appcategory_info(mfx);
1289 /*Insert in the package_app_app_metadata DB*/
1290 ret = __insert_application_appmetadata_info(mfx);
1294 /*Insert in the package_app_app_permission DB*/
1295 ret = __insert_application_apppermission_info(mfx);
1299 /*Insert in the package_app_share_allowed DB*/
1300 ret = __insert_application_share_allowed_info(mfx);
1304 /*Insert in the package_app_share_request DB*/
1305 ret = __insert_application_share_request_info(mfx);
1309 /*Insert in the package_app_data_control DB*/
1310 ret = __insert_application_datacontrol_info(mfx);
1318 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1320 char query[MAX_QUERY_LEN] = { '\0' };
1322 memset(query, '\0', MAX_QUERY_LEN);
1323 snprintf(query, MAX_QUERY_LEN,
1324 "delete from %s where app_id='%s'", db_table, appid);
1325 ret = __exec_query(query);
1327 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1333 static int __delete_subpkg_info_from_db(char *appid)
1337 ret = __delete_appinfo_from_db("package_app_info", appid);
1340 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1343 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1346 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1349 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1352 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1355 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1358 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1361 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1364 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1367 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1374 static int __delete_subpkg_from_db(manifest_x *mfx)
1376 char query[MAX_QUERY_LEN] = { '\0' };
1377 char *error_message = NULL;
1379 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1381 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1382 _LOGE("Don't execute query = %s error message = %s\n", query,
1384 sqlite3_free(error_message);
1387 sqlite3_free(error_message);
1392 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1394 char query[MAX_QUERY_LEN] = { '\0' };
1398 /*Delete from cert table*/
1399 if (uid != GLOBAL_USER)
1400 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1402 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1404 _LOGD("Cert Info DB Delete Failed\n");
1408 /*Delete from Package Info DB*/
1409 snprintf(query, MAX_QUERY_LEN,
1410 "delete from package_info where package='%s'", mfx->package);
1411 ret = __exec_query(query);
1413 _LOGD("Package Info DB Delete Failed\n");
1416 memset(query, '\0', MAX_QUERY_LEN);
1418 /*Delete from Package Localized Info*/
1419 snprintf(query, MAX_QUERY_LEN,
1420 "delete from package_localized_info where package='%s'", mfx->package);
1421 ret = __exec_query(query);
1423 _LOGD("Package Localized Info DB Delete Failed\n");
1427 /*Delete from Package Privilege Info*/
1428 snprintf(query, MAX_QUERY_LEN,
1429 "delete from package_privilege_info where package='%s'", mfx->package);
1430 ret = __exec_query(query);
1432 _LOGD("Package Privilege Info DB Delete Failed\n");
1436 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1437 app = (application_x *)tmp->data;
1440 ret = __delete_appinfo_from_db("package_app_info", app->appid);
1443 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
1446 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
1449 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
1452 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
1455 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
1458 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
1461 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
1464 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
1467 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
1470 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
1475 /* if main package has sub pkg, delete sub pkg data*/
1476 __delete_subpkg_from_db(mfx);
1481 static int __update_preload_condition_in_db()
1484 char query[MAX_QUERY_LEN] = {'\0'};
1486 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
1488 ret = __exec_query(query);
1490 _LOGD("Package preload_condition update failed\n");
1495 API int pkgmgr_parser_initialize_db(uid_t uid)
1499 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
1501 _LOGD("package info DB initialization failed\n");
1504 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
1506 _LOGD("package localized info DB initialization failed\n");
1509 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
1511 _LOGD("package app app privilege DB initialization failed\n");
1514 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
1516 _LOGD("package app info DB initialization failed\n");
1519 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
1521 _LOGD("package app localized info DB initialization failed\n");
1524 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
1526 _LOGD("package app icon localized info DB initialization failed\n");
1529 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
1531 _LOGD("package app image info DB initialization failed\n");
1534 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
1536 _LOGD("package app app control DB initialization failed\n");
1539 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
1541 _LOGD("package app app category DB initialization failed\n");
1544 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
1546 _LOGD("package app app category DB initialization failed\n");
1549 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
1551 _LOGD("package app app permission DB initialization failed\n");
1554 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
1556 _LOGD("package app share allowed DB initialization failed\n");
1559 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
1561 _LOGD("package app share request DB initialization failed\n");
1564 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
1566 _LOGD("package app data control DB initialization failed\n");
1570 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
1572 _LOGD("package cert info DB initialization failed\n");
1575 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
1577 _LOGD("package cert index info DB initialization failed\n");
1581 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
1582 _LOGD("Failed to change cert db permission\n");
1584 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
1585 _LOGD("Failed to change parser db permission\n");
1591 static int __parserdb_change_perm(const char *db_file, uid_t uid)
1594 char journal_file[BUFSIZE];
1597 struct passwd *userinfo = NULL;
1598 files[0] = (char *)db_file;
1599 files[1] = journal_file;
1602 if (db_file == NULL)
1605 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
1607 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
1608 if (uid == OWNER_ROOT)
1610 userinfo = getpwuid(uid);
1612 _LOGE("FAIL: user %d doesn't exist", uid);
1615 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
1617 for (i = 0; files[i]; i++) {
1618 ret = chown(files[i], uid, userinfo->pw_gid);
1620 if (strerror_r(errno, buf, sizeof(buf)))
1622 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
1623 userinfo->pw_gid, buf);
1627 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
1629 if (strerror_r(errno, buf, sizeof(buf)))
1631 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
1634 SET_SMACK_LABEL(files[i]);
1639 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
1643 if (getuid() != OWNER_ROOT) {
1644 _LOGE("Only root user is allowed");
1648 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
1649 _LOGE("Manifest db for user %d is already exists", uid);
1653 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
1654 _LOGE("Cert db for user %d is already exists", uid);
1658 ret = pkgmgr_parser_check_and_create_db(uid);
1661 ret = pkgmgr_parser_initialize_db(uid);
1663 pkgmgr_parser_close_db();
1666 pkgmgr_parser_close_db();
1671 API int pkgmgr_parser_check_and_create_db(uid_t uid)
1675 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
1677 _LOGD("Manifest DB creation Failed\n");
1682 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid));
1684 _LOGD("Cert DB creation Failed\n");
1690 void pkgmgr_parser_close_db(void)
1692 sqlite3_close(pkgmgr_parser_db);
1693 sqlite3_close(pkgmgr_cert_db);
1697 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
1699 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
1701 _LOGD("manifest pointer is NULL\n");
1705 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
1707 _LOGD("Failed to open DB\n");
1710 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
1713 /*Begin transaction*/
1714 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1715 if (ret != SQLITE_OK) {
1716 _LOGD("Failed to begin transaction\n");
1720 _LOGD("Transaction Begin\n");
1721 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
1723 _LOGD("Insert into DB failed. Rollback now\n");
1724 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1727 /*Commit transaction*/
1728 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1729 if (ret != SQLITE_OK) {
1730 _LOGD("Failed to commit transaction. Rollback now\n");
1731 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1735 _LOGD("Transaction Commit and End\n");
1737 pkgmgr_parser_close_db();
1741 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
1743 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
1745 _LOGD("manifest pointer is NULL\n");
1749 ret = pkgmgr_parser_check_and_create_db(uid);
1751 _LOGD("Failed to open DB\n");
1754 ret = pkgmgr_parser_initialize_db(uid);
1757 /*Begin transaction*/
1758 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1759 if (ret != SQLITE_OK) {
1760 _LOGD("Failed to begin transaction\n");
1764 _LOGD("Transaction Begin\n");
1765 ret = __insert_manifest_info_in_db(mfx, uid);
1767 _LOGD("Insert into DB failed. Rollback now\n");
1768 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1771 /*Commit transaction*/
1772 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1773 if (ret != SQLITE_OK) {
1774 _LOGD("Failed to commit transaction. Rollback now\n");
1775 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1779 _LOGD("Transaction Commit and End\n");
1781 pkgmgr_parser_close_db();
1785 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
1788 _LOGD("manifest pointer is NULL\n");
1792 ret = pkgmgr_parser_check_and_create_db(uid);
1794 _LOGD("Failed to open DB\n");
1797 ret = pkgmgr_parser_initialize_db(uid);
1800 /*Preserve guest mode visibility*/
1801 __preserve_guestmode_visibility_value( mfx);
1802 /*Begin transaction*/
1803 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1804 if (ret != SQLITE_OK) {
1805 _LOGD("Failed to begin transaction\n");
1809 _LOGD("Transaction Begin\n");
1810 ret = __delete_manifest_info_from_db(mfx, uid);
1812 _LOGD("Delete from DB failed. Rollback now\n");
1813 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1816 ret = __insert_manifest_info_in_db(mfx, uid);
1818 _LOGD("Insert into DB failed. Rollback now\n");
1819 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1823 /*Commit transaction*/
1824 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1825 if (ret != SQLITE_OK) {
1826 _LOGD("Failed to commit transaction. Rollback now\n");
1827 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1831 _LOGD("Transaction Commit and End\n");
1833 pkgmgr_parser_close_db();
1837 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
1839 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
1842 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
1845 _LOGD("manifest pointer is NULL\n");
1849 ret = pkgmgr_parser_check_and_create_db(uid);
1851 _LOGD("Failed to open DB\n");
1854 /*Begin transaction*/
1855 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1856 if (ret != SQLITE_OK) {
1857 _LOGD("Failed to begin transaction\n");
1861 _LOGD("Transaction Begin\n");
1862 ret = __delete_manifest_info_from_db(mfx, uid);
1864 _LOGD("Delete from DB failed. Rollback now\n");
1865 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1868 /*Commit transaction*/
1869 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1870 if (ret != SQLITE_OK) {
1871 _LOGD("Failed to commit transaction, Rollback now\n");
1872 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1876 _LOGD("Transaction Commit and End\n");
1878 pkgmgr_parser_close_db();
1882 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
1884 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
1887 API int pkgmgr_parser_update_preload_info_in_db()
1890 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
1892 _LOGD("Failed to open DB\n");
1895 /*Begin transaction*/
1896 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1897 if (ret != SQLITE_OK) {
1898 _LOGD("Failed to begin transaction\n");
1902 _LOGD("Transaction Begin\n");
1903 ret = __update_preload_condition_in_db();
1905 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
1906 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1909 /*Commit transaction*/
1910 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1911 if (ret != SQLITE_OK) {
1912 _LOGD("Failed to commit transaction, Rollback now\n");
1913 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1917 _LOGD("Transaction Commit and End\n");
1919 pkgmgr_parser_close_db();
1923 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
1926 ret = pkgmgr_parser_check_and_create_db(uid);
1928 _LOGD("Failed to open DB\n");
1931 /*Begin transaction*/
1932 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1933 if (ret != SQLITE_OK) {
1934 _LOGD("Failed to begin transaction\n");
1938 _LOGD("Transaction Begin\n");
1939 ret = __update_preload_condition_in_db();
1941 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
1942 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1945 /*Commit transaction*/
1946 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1947 if (ret != SQLITE_OK) {
1948 _LOGD("Failed to commit transaction, Rollback now\n");
1949 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1953 _LOGD("Transaction Commit and End\n");
1955 pkgmgr_parser_close_db();