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 "package_tep_name text, " \
74 "install_location text, " \
75 "package_size text, " \
76 "package_removable text DEFAULT 'true', " \
77 "package_preload text DEFAULT 'false', " \
78 "package_readonly text DEFAULT 'false', " \
79 "package_update text DEFAULT 'false', " \
80 "package_appsetting text DEFAULT 'false', " \
81 "package_nodisplay text DEFAULT 'false', " \
82 "package_system text DEFAULT 'false', " \
83 "author_name text, " \
84 "author_email text, " \
86 "installed_time text," \
87 "installed_storage text," \
88 "storeclient_id text," \
93 "package_support_disable text DEFAULT 'false')"
95 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
96 "(package text not null, " \
97 "package_locale text DEFAULT 'No Locale', " \
98 "package_label text, " \
99 "package_icon text, " \
100 "package_description text, " \
101 "package_license text, " \
103 "PRIMARY KEY(package, package_locale), " \
104 "FOREIGN KEY(package) " \
105 "REFERENCES package_info(package) " \
108 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
109 "(package text not null, " \
110 "privilege text not null, " \
111 "PRIMARY KEY(package, privilege) " \
112 "FOREIGN KEY(package) " \
113 "REFERENCES package_info(package) " \
116 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
117 "(app_id text primary key not null, " \
118 "app_component text, " \
120 "app_nodisplay text DEFAULT 'false', " \
122 "app_onboot text DEFAULT 'false', " \
123 "app_multiple text DEFAULT 'false', " \
124 "app_autorestart text DEFAULT 'false', " \
125 "app_taskmanage text DEFAULT 'false', " \
126 "app_enabled text DEFAULT 'true', " \
127 "app_hwacceleration text DEFAULT 'use-system-setting', " \
128 "app_screenreader text DEFAULT 'use-system-setting', " \
129 "app_mainapp text, " \
130 "app_recentimage text, " \
131 "app_launchcondition text, " \
132 "app_indicatordisplay text DEFAULT 'true', " \
133 "app_portraitimg text, " \
134 "app_landscapeimg text, " \
135 "app_guestmodevisibility text DEFAULT 'true', " \
136 "app_permissiontype text DEFAULT 'normal', " \
137 "app_preload text DEFAULT 'false', " \
138 "app_submode text DEFAULT 'false', " \
139 "app_submode_mainid text, " \
140 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
141 "app_ui_gadget text DEFAULT 'false', " \
142 "app_support_disable text DEFAULT 'false', " \
143 "component_type text, " \
144 "package text not null, " \
145 "app_tep_name text, " \
146 "FOREIGN KEY(package) " \
147 "REFERENCES package_info(package) " \
150 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
151 "(app_id text not null, " \
152 "app_locale text DEFAULT 'No Locale', " \
155 "PRIMARY KEY(app_id,app_locale) " \
156 "FOREIGN KEY(app_id) " \
157 "REFERENCES package_app_info(app_id) " \
160 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
161 "(app_id text not null, " \
163 "app_icon_section text, " \
164 "app_icon_resolution text, " \
165 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
166 "FOREIGN KEY(app_id) " \
167 "REFERENCES package_app_info(app_id) " \
170 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
171 "(app_id text not null, " \
172 "app_locale text DEFAULT 'No Locale', " \
173 "app_image_section text, " \
175 "PRIMARY KEY(app_id,app_image_section) " \
176 "FOREIGN KEY(app_id) " \
177 "REFERENCES package_app_info(app_id) " \
180 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
181 "(app_id text not null, " \
182 "app_control text not null, " \
183 "PRIMARY KEY(app_id,app_control) " \
184 "FOREIGN KEY(app_id) " \
185 "REFERENCES package_app_info(app_id) " \
188 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
189 "(app_id text not null, " \
190 "category text not null, " \
191 "PRIMARY KEY(app_id,category) " \
192 "FOREIGN KEY(app_id) " \
193 "REFERENCES package_app_info(app_id) " \
196 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
197 "(app_id text not null, " \
198 "md_key text not null, " \
199 "md_value text not null, " \
200 "PRIMARY KEY(app_id, md_key, md_value) " \
201 "FOREIGN KEY(app_id) " \
202 "REFERENCES package_app_info(app_id) " \
205 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
206 "(app_id text not null, " \
207 "pm_type text not null, " \
208 "pm_value text not null, " \
209 "PRIMARY KEY(app_id, pm_type, pm_value) " \
210 "FOREIGN KEY(app_id) " \
211 "REFERENCES package_app_info(app_id) " \
214 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
215 "(app_id text not null, " \
216 "data_share_path text not null, " \
217 "data_share_allowed text not null, " \
218 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
219 "FOREIGN KEY(app_id) " \
220 "REFERENCES package_app_info(app_id) " \
223 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
224 "(app_id text not null, " \
225 "data_share_request text not null, " \
226 "PRIMARY KEY(app_id,data_share_request) " \
227 "FOREIGN KEY(app_id) " \
228 "REFERENCES package_app_info(app_id) " \
231 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
232 "(cert_info text not null, " \
233 "cert_id integer, " \
234 "cert_ref_count integer, " \
235 "PRIMARY KEY(cert_id)) "
237 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
238 "(package text not null, " \
239 "author_root_cert integer, " \
240 "author_im_cert integer, " \
241 "author_signer_cert integer, " \
242 "dist_root_cert integer, " \
243 "dist_im_cert integer, " \
244 "dist_signer_cert integer, " \
245 "dist2_root_cert integer, " \
246 "dist2_im_cert integer, " \
247 "dist2_signer_cert integer, " \
248 "PRIMARY KEY(package)) "
250 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
251 "(app_id text not null, " \
252 "providerid text not null, " \
253 "access text not null, " \
254 "type text not null, " \
255 "PRIMARY KEY(app_id, providerid, access, type) " \
256 "FOREIGN KEY(app_id) " \
257 "REFERENCES package_app_info(app_id) " \
260 static int __insert_application_info(manifest_x *mfx);
261 static int __insert_application_appcategory_info(manifest_x *mfx);
262 static int __insert_application_appcontrol_info(manifest_x *mfx);
263 static int __insert_application_appmetadata_info(manifest_x *mfx);
264 static int __insert_application_share_allowed_info(manifest_x *mfx);
265 static int __insert_application_share_request_info(manifest_x *mfx);
266 static int __insert_application_datacontrol_info(manifest_x *mfx);
267 static void __insert_application_locale_info(gpointer data, gpointer userdata);
268 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
269 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
270 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
271 static int __delete_subpkg_info_from_db(char *appid);
272 static int __delete_appinfo_from_db(char *db_table, const char *appid);
273 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
274 static int __exec_query(char *query);
275 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
276 char **label, char **license, char **icon, char **description, char **author);
277 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
278 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
279 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
280 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
281 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
282 static int __parserdb_change_perm(const char *db_file, uid_t uid);
284 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
287 __delete_subpkg_info_from_db(coltxt[0]);
292 static const char *__get_str(const char *str)
296 return PKGMGR_PARSER_EMPTY_STR;
302 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
307 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
308 if (ret != SQLITE_OK) {
309 _LOGD("connect db [%s] failed!\n", db_path);
317 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
319 manifest_x *mfx = (manifest_x *)data;
325 if (mfx->application == NULL)
327 app = (application_x *)mfx->application->data;
328 for(i = 0; i < ncols; i++)
330 if (strcmp(colname[i], "app_id") == 0) {
332 appid = strdup(coltxt[i]);
333 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
335 status = strdup(coltxt[i]);
339 _LOGD("app id is NULL\n");
342 /*update guest mode visibility*/
343 for (tmp = mfx->application; tmp; tmp = tmp->next) {
344 app = (application_x *)tmp->data;
347 if (strcmp(app->appid, appid) == 0) {
348 free((void *)app->guestmode_visibility);
349 app->guestmode_visibility = strdup(status);
365 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
367 char *error_message = NULL;
368 char query[MAX_QUERY_LEN] = {'\0'};
369 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
371 sqlite3_exec(pkgmgr_parser_db, query,
372 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
373 _LOGD("Don't execute query = %s error message = %s\n",
374 query, error_message);
375 sqlite3_free(error_message);
380 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
382 char *error_message = NULL;
384 sqlite3_exec(db_handle, db_query,
385 NULL, NULL, &error_message)) {
386 _LOGD("Don't execute query = %s error message = %s\n",
387 db_query, error_message);
388 sqlite3_free(error_message);
391 sqlite3_free(error_message);
395 static int __exec_query(char *query)
397 char *error_message = NULL;
399 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
400 _LOGD("Don't execute query = %s error message = %s\n", query,
402 sqlite3_free(error_message);
405 sqlite3_free(error_message);
409 static int __exec_query_no_msg(char *query)
411 char *error_message = NULL;
413 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
414 sqlite3_free(error_message);
417 sqlite3_free(error_message);
421 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
429 for (tmp = lbls; tmp; tmp = tmp->next) {
430 lbl = (label_x *)tmp->data;
434 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
436 for (tmp = lcns; tmp; tmp = tmp->next) {
437 lcn = (license_x *)tmp->data;
441 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
443 for (tmp = icns; tmp; tmp = tmp->next) {
444 icn = (icon_x *)tmp->data;
448 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
450 for (tmp = dcns; tmp; tmp = tmp->next) {
451 dcn = (description_x *)tmp->data;
455 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
457 for (tmp = aths; tmp; tmp = tmp->next) {
458 ath = (author_x *)tmp->data;
462 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
468 static GList *__create_icon_list(GList *locale, GList *icns)
473 for (tmp = icns; tmp; tmp = tmp->next) {
474 icn = (icon_x *)tmp->data;
478 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
483 static GList *__create_image_list(GList *locale, GList *imgs)
488 for (tmp = imgs; tmp; tmp = tmp->next) {
489 img = (image_x *)tmp->data;
493 locale = g_list_insert_sorted_with_data(locale, (gpointer)img->section, __comparefunc, NULL);
498 static void __trimfunc(GList* trim_list)
500 char *trim_data = NULL;
504 list = g_list_first(trim_list);
507 trim_data = (char *)list->data;
510 if (strcmp(trim_data, prev) == 0) {
511 trim_list = g_list_remove(trim_list, trim_data);
512 list = g_list_first(trim_list);
521 list = g_list_next(list);
525 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
527 if (a == NULL || b == NULL)
529 if (strcmp((char*)a, (char*)b) == 0)
531 if (strcmp((char*)a, (char*)b) < 0)
533 if (strcmp((char*)a, (char*)b) > 0)
538 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
539 char **label, char **license, char **icon, char **description, char **author)
547 for (tmp = lbls; tmp; tmp = tmp->next) {
548 lbl = (label_x *)tmp->data;
552 if (strcmp(lbl->lang, (char *)data) == 0) {
553 *label = (char*)lbl->text;
558 for (tmp = lcns; tmp; tmp = tmp->next) {
559 lcn = (license_x *)tmp->data;
563 if (strcmp(lcn->lang, (char *)data) == 0) {
564 *license = (char*)lcn->text;
569 for (tmp = icns; tmp; tmp = tmp->next) {
570 icn = (icon_x *)tmp->data;
574 if (strcmp(icn->lang, (char *)data) == 0) {
575 *icon = (char*)icn->text;
580 for (tmp = dcns; tmp; tmp = tmp->next) {
581 dcn = (description_x *)tmp->data;
585 if (strcmp(dcn->lang, (char *)data) == 0) {
586 *description = (char*)dcn->text;
591 for (tmp = aths; tmp; tmp = tmp->next) {
592 ath = (author_x *)tmp->data;
596 if (strcmp(ath->lang, (char *)data) == 0) {
597 *author = (char*)ath->text;
605 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
609 for (tmp = icns; tmp; tmp = tmp->next) {
610 icn = (icon_x *)tmp->data;
614 if (strcmp(icn->section, (char *)data) == 0) {
615 *icon = (char*)icn->text;
616 *resolution = (char*)icn->resolution;
623 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
627 for (tmp = imgs; tmp; tmp = tmp->next) {
628 img = (image_x *)tmp->data;
632 if (strcmp(img->section, (char *)data) == 0) {
633 *lang = (char*)img->lang;
634 *image = (char*)img->text;
641 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
646 char *description = NULL;
647 char *license = NULL;
649 char query[MAX_QUERY_LEN] = {'\0'};
651 manifest_x *mfx = (manifest_x *)userdata;
652 GList *lbl = mfx->label;
653 GList *lcn = mfx->license;
654 GList *icn = mfx->icon;
655 GList *dcn = mfx->description;
656 GList *ath = mfx->author;
658 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
659 if (!label && !description && !icon && !license && !author)
662 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
663 "package_label, package_icon, package_description, package_license, package_author) values " \
664 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
669 __get_str(description),
673 ret = __exec_query(query);
675 _LOGD("Package Localized Info DB Insert failed\n");
678 static void __insert_application_locale_info(gpointer data, gpointer userdata)
683 char query[MAX_QUERY_LEN] = {'\0'};
685 application_x *app = (application_x*)userdata;
686 GList *lbl = app->label;
687 GList *icn = app->icon;
689 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
692 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
693 "app_label, app_icon) values " \
694 "('%q', '%q', '%q', '%q')", app->appid, (char*)data,
696 ret = __exec_query(query);
698 _LOGD("Package UiApp Localized Info DB Insert failed\n");
700 /*insert ui app locale info to pkg locale to get mainapp data */
701 if (strcasecmp(app->mainapp, "true")==0) {
702 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
703 "package_label, package_icon, package_description, package_license, package_author) values " \
704 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
709 PKGMGR_PARSER_EMPTY_STR,
710 PKGMGR_PARSER_EMPTY_STR,
711 PKGMGR_PARSER_EMPTY_STR);
713 ret = __exec_query_no_msg(query);
716 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
717 "where package='%s' and package_locale='%s'", icon, app->package, (char*)data);
718 ret = __exec_query_no_msg(query);
723 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
727 char *resolution = NULL;
728 char query[MAX_QUERY_LEN] = {'\0'};
730 application_x *app = (application_x*)userdata;
731 GList *icn = app->icon;
733 __extract_icon_data(data, icn, &icon, &resolution);
734 if (!icon && !resolution)
736 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
737 "app_icon, app_icon_section, app_icon_resolution) values " \
738 "('%q', '%q', '%q', '%q')", app->appid,
739 icon, (char*)data, resolution);
741 ret = __exec_query(query);
743 _LOGD("Package UiApp Localized Info DB Insert failed\n");
747 static void __insert_application_image_info(gpointer data, gpointer userdata)
752 char query[MAX_QUERY_LEN] = {'\0'};
754 application_x *app = (application_x*)userdata;
755 GList *image = app->image;
757 __extract_image_data(data, image, &lang, &img);
760 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
761 "app_image_section, app_image) values " \
762 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
764 ret = __exec_query(query);
766 _LOGD("Package UiApp image Info DB Insert failed\n");
771 static int __insert_mainapp_info(manifest_x *mfx)
776 char query[MAX_QUERY_LEN] = {'\0'};
777 for (tmp = mfx->application; tmp; tmp = tmp->next) {
778 app = (application_x *)tmp->data;
781 snprintf(query, MAX_QUERY_LEN,
782 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
784 ret = __exec_query(query);
786 _LOGD("Package App Info DB Insert Failed\n");
789 if (strcasecmp(app->mainapp, "True")==0)
790 mfx->mainapp_id = strdup(app->appid);
793 if (mfx->mainapp_id == NULL) {
794 if (mfx->application == NULL)
796 app = (application_x *)mfx->application->data;
800 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
802 _LOGD("Not valid appid\n");
806 ret = __exec_query(query);
808 _LOGD("Package UiApp Info DB Insert Failed\n");
812 free((void *)app->mainapp);
813 app->mainapp= strdup("true");
814 mfx->mainapp_id = strdup(app->appid);
817 memset(query, '\0', MAX_QUERY_LEN);
818 snprintf(query, MAX_QUERY_LEN,
819 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
820 ret = __exec_query(query);
822 _LOGD("Package Info DB update Failed\n");
828 /* _PRODUCT_LAUNCHING_ENHANCED_
829 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
831 static int __insert_application_info(manifest_x *mfx)
836 char query[MAX_QUERY_LEN] = {'\0'};
837 for (tmp = mfx->application; tmp; tmp = tmp->next) {
838 app = (application_x *)tmp->data;
842 snprintf(query, MAX_QUERY_LEN,
843 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
844 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
845 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
846 "app_preload, app_submode, app_submode_mainid, app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, app_tep_name) " \
847 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
861 __get_str(app->recentimage),
862 app->launchcondition,
863 app->indicatordisplay,
864 __get_str(app->portraitimg),
865 __get_str(app->landscapeimg),
866 app->guestmode_visibility,
867 app->permission_type,
870 __get_str(app->submode_mainid),
873 mfx->support_disable,
876 __get_str(mfx->tep_name));
878 ret = __exec_query(query);
880 _LOGD("Package UiApp Info DB Insert Failed\n");
883 memset(query, '\0', MAX_QUERY_LEN);
888 static int __insert_application_appcategory_info(manifest_x *mfx)
895 char query[MAX_QUERY_LEN] = {'\0'};
896 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
897 app = (application_x *)app_tmp->data;
900 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
901 ct = (const char *)ct_tmp->data;
904 snprintf(query, MAX_QUERY_LEN,
905 "insert into package_app_app_category(app_id, category) " \
906 "values('%s','%s')",\
908 ret = __exec_query(query);
910 _LOGD("Package UiApp Category Info DB Insert Failed\n");
913 memset(query, '\0', MAX_QUERY_LEN);
919 static int __insert_application_appmetadata_info(manifest_x *mfx)
926 char query[MAX_QUERY_LEN] = {'\0'};
927 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
928 app = (application_x *)app_tmp->data;
931 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
932 md = (metadata_x *)md_tmp->data;
936 snprintf(query, MAX_QUERY_LEN,
937 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
938 "values('%s','%s', '%s')",\
939 app->appid, md->key, md->value ? md->value : "");
940 ret = __exec_query(query);
942 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
946 memset(query, '\0', MAX_QUERY_LEN);
952 static int __insert_application_apppermission_info(manifest_x *mfx)
959 char query[MAX_QUERY_LEN] = {'\0'};
960 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
961 app = (application_x *)app_tmp->data;
964 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
965 pm = (permission_x *)pm_tmp->data;
968 snprintf(query, MAX_QUERY_LEN,
969 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
970 "values('%s','%s', '%s')",\
971 app->appid, pm->type, pm->value);
972 ret = __exec_query(query);
974 _LOGD("Package UiApp permission Info DB Insert Failed\n");
977 memset(query, '\0', MAX_QUERY_LEN);
983 static int __insert_application_appcontrol_info(manifest_x *mfx)
988 appcontrol_x *acontrol;
990 char query[MAX_QUERY_LEN] = {'\0'};
991 char buf[BUFSIZE] = {'\0'};
992 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
993 app = (application_x *)app_tmp->data;
996 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
997 acontrol = (appcontrol_x *)acontrol_tmp->data;
998 if (acontrol == NULL)
1000 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1001 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1002 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1003 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1004 snprintf(query, MAX_QUERY_LEN,
1005 "insert into package_app_app_control(app_id, app_control) " \
1006 "values('%s', '%s')",\
1008 ret = __exec_query(query);
1010 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1013 memset(query, '\0', MAX_QUERY_LEN);
1019 static int __insert_application_datacontrol_info(manifest_x *mfx)
1026 char query[MAX_QUERY_LEN] = {'\0'};
1028 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1029 app = (application_x *)app_tmp->data;
1032 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1033 dc = (datacontrol_x *)dc_tmp->data;
1036 snprintf(query, MAX_QUERY_LEN,
1037 "insert into package_app_data_control(app_id, providerid, access, type) " \
1038 "values('%s', '%s', '%s', '%s')",\
1044 ret = __exec_query(query);
1046 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1049 memset(query, '\0', MAX_QUERY_LEN);
1055 static int __insert_application_share_request_info(manifest_x *mfx)
1064 char query[MAX_QUERY_LEN] = {'\0'};
1065 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1066 app = (application_x *)app_tmp->data;
1069 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1070 ds = (datashare_x *)ds_tmp->data;
1073 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1074 rq = (const char *)rq_tmp->data;
1077 snprintf(query, MAX_QUERY_LEN,
1078 "insert into package_app_share_request(app_id, data_share_request) " \
1079 "values('%s', '%s')",\
1081 ret = __exec_query(query);
1083 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1086 memset(query, '\0', MAX_QUERY_LEN);
1093 static int __insert_application_share_allowed_info(manifest_x *mfx)
1104 char query[MAX_QUERY_LEN] = {'\0'};
1105 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1106 app = (application_x *)app_tmp->data;
1109 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1110 ds = (datashare_x *)ds_tmp->data;
1113 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1114 df = (define_x *)df_tmp->data;
1117 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1118 al = (const char *)al_tmp->data;
1121 snprintf(query, MAX_QUERY_LEN,
1122 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1123 "values('%s', '%s', '%s')",\
1124 app->appid, df->path, al);
1125 ret = __exec_query(query);
1127 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1130 memset(query, '\0', MAX_QUERY_LEN);
1138 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1142 const char *pv = NULL;
1143 char query[MAX_QUERY_LEN] = { '\0' };
1146 const char *auth_name = NULL;
1147 const char *auth_email = NULL;
1148 const char *auth_href = NULL;
1150 GList *pkglocale = NULL;
1151 GList *applocale = NULL;
1152 GList *appicon = NULL;
1153 GList *appimage = NULL;
1155 if (mfx->author && mfx->author->data) {
1156 author = (author_x *)mfx->author->data;
1158 auth_name = author->text;
1160 auth_email = author->email;
1162 auth_href = author->href;
1164 /*Insert in the package_cert_info CERT_DB*/
1165 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1166 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1167 if (ret != PMINFO_R_OK) {
1168 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1169 _LOGE("Cert Info DB create handle failed\n");
1172 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1173 if (ret != PMINFO_R_OK) {
1174 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1175 _LOGE("Cert Info DB Insert Failed\n");
1179 /*Insert in the package_info DB*/
1180 snprintf(query, MAX_QUERY_LEN,
1181 "insert into package_info(package, package_type, package_version, package_api_version, package_tep_name, install_location, package_size, " \
1182 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1183 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1184 "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')",\
1188 __get_str(mfx->api_version),
1189 __get_str(mfx->tep_name),
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 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1219 pv = (const char *)tmp->data;
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')",\
1227 ret = __exec_query(query);
1229 _LOGD("Package Privilege Info DB Insert Failed\n");
1234 if (mfx->application != NULL) {
1235 ret = __insert_mainapp_info(mfx);
1240 /*Insert the package locale*/
1241 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1242 /*remove duplicated data in pkglocale*/
1243 __trimfunc(pkglocale);
1245 /*Insert the app locale, icon, image info */
1246 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1247 app = (application_x *)tmp->data;
1250 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1251 appicon = __create_icon_list(appicon, app->icon);
1252 appimage = __create_image_list(appimage, app->image);
1254 /*remove duplicated data in applocale*/
1255 __trimfunc(applocale);
1256 __trimfunc(appicon);
1257 __trimfunc(appimage);
1259 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1261 /*native app locale info*/
1262 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1263 app = (application_x *)tmp->data;
1266 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1267 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1268 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1271 g_list_free(pkglocale);
1273 g_list_free(applocale);
1275 g_list_free(appicon);
1277 g_list_free(appimage);
1280 /*Insert in the package_app_info DB*/
1281 ret = __insert_application_info(mfx);
1284 /*Insert in the package_app_app_control DB*/
1285 ret = __insert_application_appcontrol_info(mfx);
1289 /*Insert in the package_app_app_category DB*/
1290 ret = __insert_application_appcategory_info(mfx);
1294 /*Insert in the package_app_app_metadata DB*/
1295 ret = __insert_application_appmetadata_info(mfx);
1299 /*Insert in the package_app_app_permission DB*/
1300 ret = __insert_application_apppermission_info(mfx);
1304 /*Insert in the package_app_share_allowed DB*/
1305 ret = __insert_application_share_allowed_info(mfx);
1309 /*Insert in the package_app_share_request DB*/
1310 ret = __insert_application_share_request_info(mfx);
1314 /*Insert in the package_app_data_control DB*/
1315 ret = __insert_application_datacontrol_info(mfx);
1323 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1325 char query[MAX_QUERY_LEN] = { '\0' };
1327 memset(query, '\0', MAX_QUERY_LEN);
1328 snprintf(query, MAX_QUERY_LEN,
1329 "delete from %s where app_id='%s'", db_table, appid);
1330 ret = __exec_query(query);
1332 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1338 static int __delete_subpkg_info_from_db(char *appid)
1342 ret = __delete_appinfo_from_db("package_app_info", appid);
1345 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1348 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1351 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1354 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1357 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1360 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1363 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1366 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1369 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1372 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1379 static int __delete_subpkg_from_db(manifest_x *mfx)
1381 char query[MAX_QUERY_LEN] = { '\0' };
1382 char *error_message = NULL;
1384 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1386 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1387 _LOGE("Don't execute query = %s error message = %s\n", query,
1389 sqlite3_free(error_message);
1392 sqlite3_free(error_message);
1397 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1399 char query[MAX_QUERY_LEN] = { '\0' };
1403 /*Delete from cert table*/
1404 if (uid != GLOBAL_USER)
1405 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1407 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1409 _LOGD("Cert Info DB Delete Failed\n");
1413 /*Delete from Package Info DB*/
1414 snprintf(query, MAX_QUERY_LEN,
1415 "delete from package_info where package='%s'", mfx->package);
1416 ret = __exec_query(query);
1418 _LOGD("Package Info DB Delete Failed\n");
1421 memset(query, '\0', MAX_QUERY_LEN);
1423 /*Delete from Package Localized Info*/
1424 snprintf(query, MAX_QUERY_LEN,
1425 "delete from package_localized_info where package='%s'", mfx->package);
1426 ret = __exec_query(query);
1428 _LOGD("Package Localized Info DB Delete Failed\n");
1432 /*Delete from Package Privilege Info*/
1433 snprintf(query, MAX_QUERY_LEN,
1434 "delete from package_privilege_info where package='%s'", mfx->package);
1435 ret = __exec_query(query);
1437 _LOGD("Package Privilege Info DB Delete Failed\n");
1441 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1442 app = (application_x *)tmp->data;
1445 ret = __delete_appinfo_from_db("package_app_info", app->appid);
1448 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
1451 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
1454 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
1457 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
1460 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
1463 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
1466 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
1469 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
1472 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
1475 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
1480 /* if main package has sub pkg, delete sub pkg data*/
1481 __delete_subpkg_from_db(mfx);
1486 static int __update_preload_condition_in_db()
1489 char query[MAX_QUERY_LEN] = {'\0'};
1491 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
1493 ret = __exec_query(query);
1495 _LOGD("Package preload_condition update failed\n");
1500 API int pkgmgr_parser_initialize_db(uid_t uid)
1504 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
1506 _LOGD("package info DB initialization failed\n");
1509 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
1511 _LOGD("package localized info DB initialization failed\n");
1514 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
1516 _LOGD("package app app privilege DB initialization failed\n");
1519 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
1521 _LOGD("package app info DB initialization failed\n");
1524 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
1526 _LOGD("package app localized info DB initialization failed\n");
1529 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
1531 _LOGD("package app icon localized info DB initialization failed\n");
1534 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
1536 _LOGD("package app image info DB initialization failed\n");
1539 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
1541 _LOGD("package app app control DB initialization failed\n");
1544 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
1546 _LOGD("package app app category DB initialization failed\n");
1549 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
1551 _LOGD("package app app category DB initialization failed\n");
1554 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
1556 _LOGD("package app app permission DB initialization failed\n");
1559 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
1561 _LOGD("package app share allowed DB initialization failed\n");
1564 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
1566 _LOGD("package app share request DB initialization failed\n");
1569 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
1571 _LOGD("package app data control DB initialization failed\n");
1575 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
1577 _LOGD("package cert info DB initialization failed\n");
1580 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
1582 _LOGD("package cert index info DB initialization failed\n");
1586 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
1587 _LOGD("Failed to change cert db permission\n");
1589 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
1590 _LOGD("Failed to change parser db permission\n");
1596 static int __parserdb_change_perm(const char *db_file, uid_t uid)
1599 char journal_file[BUFSIZE];
1602 struct passwd *userinfo = NULL;
1603 files[0] = (char *)db_file;
1604 files[1] = journal_file;
1607 if (db_file == NULL)
1610 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
1612 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
1613 if (uid == OWNER_ROOT)
1615 userinfo = getpwuid(uid);
1617 _LOGE("FAIL: user %d doesn't exist", uid);
1620 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
1622 for (i = 0; files[i]; i++) {
1623 ret = chown(files[i], uid, userinfo->pw_gid);
1625 if (strerror_r(errno, buf, sizeof(buf)))
1627 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
1628 userinfo->pw_gid, buf);
1632 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
1634 if (strerror_r(errno, buf, sizeof(buf)))
1636 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
1639 SET_SMACK_LABEL(files[i]);
1644 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
1648 if (getuid() != OWNER_ROOT) {
1649 _LOGE("Only root user is allowed");
1653 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
1654 _LOGE("Manifest db for user %d is already exists", uid);
1658 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
1659 _LOGE("Cert db for user %d is already exists", uid);
1663 ret = pkgmgr_parser_check_and_create_db(uid);
1666 ret = pkgmgr_parser_initialize_db(uid);
1668 pkgmgr_parser_close_db();
1671 pkgmgr_parser_close_db();
1676 API int pkgmgr_parser_check_and_create_db(uid_t uid)
1680 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
1682 _LOGD("Manifest DB creation Failed\n");
1687 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid));
1689 _LOGD("Cert DB creation Failed\n");
1695 void pkgmgr_parser_close_db(void)
1697 sqlite3_close(pkgmgr_parser_db);
1698 sqlite3_close(pkgmgr_cert_db);
1702 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
1704 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
1706 _LOGD("manifest pointer is NULL\n");
1710 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
1712 _LOGD("Failed to open DB\n");
1715 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
1718 /*Begin transaction*/
1719 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1720 if (ret != SQLITE_OK) {
1721 _LOGD("Failed to begin transaction\n");
1725 _LOGD("Transaction Begin\n");
1726 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
1728 _LOGD("Insert into DB failed. Rollback now\n");
1729 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1732 /*Commit transaction*/
1733 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1734 if (ret != SQLITE_OK) {
1735 _LOGD("Failed to commit transaction. Rollback now\n");
1736 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1740 _LOGD("Transaction Commit and End\n");
1742 pkgmgr_parser_close_db();
1746 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
1748 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
1750 _LOGD("manifest pointer is NULL\n");
1754 ret = pkgmgr_parser_check_and_create_db(uid);
1756 _LOGD("Failed to open DB\n");
1759 ret = pkgmgr_parser_initialize_db(uid);
1762 /*Begin transaction*/
1763 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1764 if (ret != SQLITE_OK) {
1765 _LOGD("Failed to begin transaction\n");
1769 _LOGD("Transaction Begin\n");
1770 ret = __insert_manifest_info_in_db(mfx, uid);
1772 _LOGD("Insert into DB failed. Rollback now\n");
1773 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1776 /*Commit transaction*/
1777 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1778 if (ret != SQLITE_OK) {
1779 _LOGD("Failed to commit transaction. Rollback now\n");
1780 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1784 _LOGD("Transaction Commit and End\n");
1786 pkgmgr_parser_close_db();
1790 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
1792 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, GLOBAL_USER);
1795 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
1797 if (pkgid == NULL || tep_path == NULL) {
1798 _LOGE("invalid parameter");
1805 ret = pkgmgr_parser_check_and_create_db(uid);
1807 _LOGD("Failed to open DB\n");
1810 ret = pkgmgr_parser_initialize_db(uid);
1814 /*Begin transaction*/
1815 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1816 if (ret != SQLITE_OK) {
1817 _LOGD("Failed to begin transaction\n");
1821 _LOGD("Transaction Begin\n");
1824 /* Updating TEP info in "package_info" table */
1825 query = sqlite3_mprintf("UPDATE package_info "\
1826 "SET package_tep_name = %Q "\
1827 "WHERE package = %Q", tep_path, pkgid);
1829 ret = __exec_query(query);
1830 sqlite3_free(query);
1831 if (ret != SQLITE_OK) {
1832 ret = PM_PARSER_R_ERROR;
1833 _LOGE("sqlite exec failed to insert entries into package_info!!");
1837 /* Updating TEP info in "package_app_info" table */
1838 query = sqlite3_mprintf("UPDATE package_app_info "\
1839 "SET app_tep_name = %Q "\
1840 "WHERE package = %Q", tep_path, pkgid);
1842 ret = __exec_query(query);
1843 sqlite3_free(query);
1844 if (ret != SQLITE_OK) {
1845 ret = PM_PARSER_R_ERROR;
1846 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
1850 /*Commit transaction*/
1851 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1852 if (ret != SQLITE_OK) {
1853 _LOGE("Failed to commit transaction, Rollback now\n");
1854 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1855 if (ret != SQLITE_OK)
1856 _LOGE("Failed to Rollback\n");
1858 ret = PM_PARSER_R_ERROR;
1861 _LOGD("Transaction Commit and End\n");
1862 ret = PM_PARSER_R_OK;
1865 pkgmgr_parser_close_db();
1870 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
1873 _LOGD("manifest pointer is NULL\n");
1877 ret = pkgmgr_parser_check_and_create_db(uid);
1879 _LOGD("Failed to open DB\n");
1882 ret = pkgmgr_parser_initialize_db(uid);
1885 /*Preserve guest mode visibility*/
1886 __preserve_guestmode_visibility_value( mfx);
1887 /*Begin transaction*/
1888 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1889 if (ret != SQLITE_OK) {
1890 _LOGD("Failed to begin transaction\n");
1894 _LOGD("Transaction Begin\n");
1895 ret = __delete_manifest_info_from_db(mfx, uid);
1897 _LOGD("Delete from DB failed. Rollback now\n");
1898 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1901 ret = __insert_manifest_info_in_db(mfx, uid);
1903 _LOGD("Insert into DB failed. Rollback now\n");
1904 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1908 /*Commit transaction*/
1909 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1910 if (ret != SQLITE_OK) {
1911 _LOGD("Failed to commit transaction. Rollback now\n");
1912 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1916 _LOGD("Transaction Commit and End\n");
1918 pkgmgr_parser_close_db();
1922 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
1924 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
1927 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
1930 _LOGD("manifest pointer is NULL\n");
1934 ret = pkgmgr_parser_check_and_create_db(uid);
1936 _LOGD("Failed to open DB\n");
1939 /*Begin transaction*/
1940 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1941 if (ret != SQLITE_OK) {
1942 _LOGD("Failed to begin transaction\n");
1946 _LOGD("Transaction Begin\n");
1947 ret = __delete_manifest_info_from_db(mfx, uid);
1949 _LOGD("Delete from DB failed. Rollback now\n");
1950 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1953 /*Commit transaction*/
1954 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1955 if (ret != SQLITE_OK) {
1956 _LOGD("Failed to commit transaction, Rollback now\n");
1957 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1961 _LOGD("Transaction Commit and End\n");
1963 pkgmgr_parser_close_db();
1967 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
1969 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
1972 API int pkgmgr_parser_update_preload_info_in_db()
1975 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
1977 _LOGD("Failed to open DB\n");
1980 /*Begin transaction*/
1981 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1982 if (ret != SQLITE_OK) {
1983 _LOGD("Failed to begin transaction\n");
1987 _LOGD("Transaction Begin\n");
1988 ret = __update_preload_condition_in_db();
1990 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
1991 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1994 /*Commit transaction*/
1995 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1996 if (ret != SQLITE_OK) {
1997 _LOGD("Failed to commit transaction, Rollback now\n");
1998 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2002 _LOGD("Transaction Commit and End\n");
2004 pkgmgr_parser_close_db();
2008 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2011 ret = pkgmgr_parser_check_and_create_db(uid);
2013 _LOGD("Failed to open DB\n");
2016 /*Begin transaction*/
2017 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2018 if (ret != SQLITE_OK) {
2019 _LOGD("Failed to begin transaction\n");
2023 _LOGD("Transaction Begin\n");
2024 ret = __update_preload_condition_in_db();
2026 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2027 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2030 /*Commit transaction*/
2031 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2032 if (ret != SQLITE_OK) {
2033 _LOGD("Failed to commit transaction, Rollback now\n");
2034 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2038 _LOGD("Transaction Commit and End\n");
2040 pkgmgr_parser_close_db();