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_installed_storage text, " \
141 "app_process_pool text DEFAULT 'false', " \
142 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
143 "app_ui_gadget text DEFAULT 'false', " \
144 "app_support_disable text DEFAULT 'false', " \
145 "component_type text, " \
146 "package text not null, " \
147 "app_tep_name text, " \
148 "FOREIGN KEY(package) " \
149 "REFERENCES package_info(package) " \
152 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
153 "(app_id text not null, " \
154 "app_locale text DEFAULT 'No Locale', " \
157 "PRIMARY KEY(app_id,app_locale) " \
158 "FOREIGN KEY(app_id) " \
159 "REFERENCES package_app_info(app_id) " \
162 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
163 "(app_id text not null, " \
165 "app_icon_section text, " \
166 "app_icon_resolution text, " \
167 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
168 "FOREIGN KEY(app_id) " \
169 "REFERENCES package_app_info(app_id) " \
172 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
173 "(app_id text not null, " \
174 "app_locale text DEFAULT 'No Locale', " \
175 "app_image_section text, " \
177 "PRIMARY KEY(app_id,app_image_section) " \
178 "FOREIGN KEY(app_id) " \
179 "REFERENCES package_app_info(app_id) " \
182 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
183 "(app_id text not null, " \
184 "app_control text not null, " \
185 "PRIMARY KEY(app_id,app_control) " \
186 "FOREIGN KEY(app_id) " \
187 "REFERENCES package_app_info(app_id) " \
190 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
191 "(app_id text not null, " \
192 "category text not null, " \
193 "PRIMARY KEY(app_id,category) " \
194 "FOREIGN KEY(app_id) " \
195 "REFERENCES package_app_info(app_id) " \
198 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
199 "(app_id text not null, " \
200 "md_key text not null, " \
201 "md_value text not null, " \
202 "PRIMARY KEY(app_id, md_key, md_value) " \
203 "FOREIGN KEY(app_id) " \
204 "REFERENCES package_app_info(app_id) " \
207 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
208 "(app_id text not null, " \
209 "pm_type text not null, " \
210 "pm_value text not null, " \
211 "PRIMARY KEY(app_id, pm_type, pm_value) " \
212 "FOREIGN KEY(app_id) " \
213 "REFERENCES package_app_info(app_id) " \
216 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
217 "(app_id text not null, " \
218 "data_share_path text not null, " \
219 "data_share_allowed text not null, " \
220 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
221 "FOREIGN KEY(app_id) " \
222 "REFERENCES package_app_info(app_id) " \
225 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
226 "(app_id text not null, " \
227 "data_share_request text not null, " \
228 "PRIMARY KEY(app_id,data_share_request) " \
229 "FOREIGN KEY(app_id) " \
230 "REFERENCES package_app_info(app_id) " \
233 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
234 "(cert_info text not null, " \
235 "cert_id integer, " \
236 "cert_ref_count integer, " \
237 "PRIMARY KEY(cert_id)) "
239 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
240 "(package text not null, " \
241 "author_root_cert integer, " \
242 "author_im_cert integer, " \
243 "author_signer_cert integer, " \
244 "dist_root_cert integer, " \
245 "dist_im_cert integer, " \
246 "dist_signer_cert integer, " \
247 "dist2_root_cert integer, " \
248 "dist2_im_cert integer, " \
249 "dist2_signer_cert integer, " \
250 "PRIMARY KEY(package)) "
252 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
253 "(app_id text not null, " \
254 "providerid text not null, " \
255 "access text not null, " \
256 "type text not null, " \
257 "PRIMARY KEY(app_id, providerid, access, type) " \
258 "FOREIGN KEY(app_id) " \
259 "REFERENCES package_app_info(app_id) " \
262 static int __insert_application_info(manifest_x *mfx);
263 static int __insert_application_appcategory_info(manifest_x *mfx);
264 static int __insert_application_appcontrol_info(manifest_x *mfx);
265 static int __insert_application_appmetadata_info(manifest_x *mfx);
266 static int __insert_application_share_allowed_info(manifest_x *mfx);
267 static int __insert_application_share_request_info(manifest_x *mfx);
268 static int __insert_application_datacontrol_info(manifest_x *mfx);
269 static void __insert_application_locale_info(gpointer data, gpointer userdata);
270 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
271 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
272 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
273 static int __delete_subpkg_info_from_db(char *appid);
274 static int __delete_appinfo_from_db(char *db_table, const char *appid);
275 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
276 static int __exec_query(char *query);
277 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
278 char **label, char **license, char **icon, char **description, char **author);
279 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
280 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
281 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
282 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
283 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
284 static int __parserdb_change_perm(const char *db_file, uid_t uid);
286 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
289 __delete_subpkg_info_from_db(coltxt[0]);
294 static const char *__get_str(const char *str)
298 return PKGMGR_PARSER_EMPTY_STR;
304 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
309 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
310 if (ret != SQLITE_OK) {
311 _LOGD("connect db [%s] failed!\n", db_path);
319 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
321 manifest_x *mfx = (manifest_x *)data;
327 if (mfx->application == NULL)
329 app = (application_x *)mfx->application->data;
330 for(i = 0; i < ncols; i++)
332 if (strcmp(colname[i], "app_id") == 0) {
334 appid = strdup(coltxt[i]);
335 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
337 status = strdup(coltxt[i]);
341 _LOGD("app id is NULL\n");
344 /*update guest mode visibility*/
345 for (tmp = mfx->application; tmp; tmp = tmp->next) {
346 app = (application_x *)tmp->data;
349 if (strcmp(app->appid, appid) == 0) {
350 free((void *)app->guestmode_visibility);
351 app->guestmode_visibility = strdup(status);
367 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
369 char *error_message = NULL;
370 char query[MAX_QUERY_LEN] = {'\0'};
371 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
373 sqlite3_exec(pkgmgr_parser_db, query,
374 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
375 _LOGD("Don't execute query = %s error message = %s\n",
376 query, error_message);
377 sqlite3_free(error_message);
382 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
384 char *error_message = NULL;
386 sqlite3_exec(db_handle, db_query,
387 NULL, NULL, &error_message)) {
388 _LOGD("Don't execute query = %s error message = %s\n",
389 db_query, error_message);
390 sqlite3_free(error_message);
393 sqlite3_free(error_message);
397 static int __exec_query(char *query)
399 char *error_message = NULL;
401 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
402 _LOGD("Don't execute query = %s error message = %s\n", query,
404 sqlite3_free(error_message);
407 sqlite3_free(error_message);
411 static int __exec_query_no_msg(char *query)
413 char *error_message = NULL;
415 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
416 sqlite3_free(error_message);
419 sqlite3_free(error_message);
423 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
431 for (tmp = lbls; tmp; tmp = tmp->next) {
432 lbl = (label_x *)tmp->data;
436 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
438 for (tmp = lcns; tmp; tmp = tmp->next) {
439 lcn = (license_x *)tmp->data;
443 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
445 for (tmp = icns; tmp; tmp = tmp->next) {
446 icn = (icon_x *)tmp->data;
450 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
452 for (tmp = dcns; tmp; tmp = tmp->next) {
453 dcn = (description_x *)tmp->data;
457 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
459 for (tmp = aths; tmp; tmp = tmp->next) {
460 ath = (author_x *)tmp->data;
464 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
470 static GList *__create_icon_list(GList *locale, GList *icns)
475 for (tmp = icns; tmp; tmp = tmp->next) {
476 icn = (icon_x *)tmp->data;
480 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
485 static GList *__create_image_list(GList *locale, GList *imgs)
490 for (tmp = imgs; tmp; tmp = tmp->next) {
491 img = (image_x *)tmp->data;
495 locale = g_list_insert_sorted_with_data(locale, (gpointer)img->section, __comparefunc, NULL);
500 static void __trimfunc(GList* trim_list)
502 char *trim_data = NULL;
506 list = g_list_first(trim_list);
509 trim_data = (char *)list->data;
512 if (strcmp(trim_data, prev) == 0) {
513 trim_list = g_list_remove(trim_list, trim_data);
514 list = g_list_first(trim_list);
523 list = g_list_next(list);
527 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
529 if (a == NULL || b == NULL)
531 if (strcmp((char*)a, (char*)b) == 0)
533 if (strcmp((char*)a, (char*)b) < 0)
535 if (strcmp((char*)a, (char*)b) > 0)
540 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
541 char **label, char **license, char **icon, char **description, char **author)
549 for (tmp = lbls; tmp; tmp = tmp->next) {
550 lbl = (label_x *)tmp->data;
554 if (strcmp(lbl->lang, (char *)data) == 0) {
555 *label = (char*)lbl->text;
560 for (tmp = lcns; tmp; tmp = tmp->next) {
561 lcn = (license_x *)tmp->data;
565 if (strcmp(lcn->lang, (char *)data) == 0) {
566 *license = (char*)lcn->text;
571 for (tmp = icns; tmp; tmp = tmp->next) {
572 icn = (icon_x *)tmp->data;
576 if (strcmp(icn->lang, (char *)data) == 0) {
577 *icon = (char*)icn->text;
582 for (tmp = dcns; tmp; tmp = tmp->next) {
583 dcn = (description_x *)tmp->data;
587 if (strcmp(dcn->lang, (char *)data) == 0) {
588 *description = (char*)dcn->text;
593 for (tmp = aths; tmp; tmp = tmp->next) {
594 ath = (author_x *)tmp->data;
598 if (strcmp(ath->lang, (char *)data) == 0) {
599 *author = (char*)ath->text;
607 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
611 for (tmp = icns; tmp; tmp = tmp->next) {
612 icn = (icon_x *)tmp->data;
616 if (strcmp(icn->section, (char *)data) == 0) {
617 *icon = (char*)icn->text;
618 *resolution = (char*)icn->resolution;
625 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
629 for (tmp = imgs; tmp; tmp = tmp->next) {
630 img = (image_x *)tmp->data;
634 if (strcmp(img->section, (char *)data) == 0) {
635 *lang = (char*)img->lang;
636 *image = (char*)img->text;
643 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
648 char *description = NULL;
649 char *license = NULL;
651 char query[MAX_QUERY_LEN] = {'\0'};
653 manifest_x *mfx = (manifest_x *)userdata;
654 GList *lbl = mfx->label;
655 GList *lcn = mfx->license;
656 GList *icn = mfx->icon;
657 GList *dcn = mfx->description;
658 GList *ath = mfx->author;
660 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
661 if (!label && !description && !icon && !license && !author)
664 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
665 "package_label, package_icon, package_description, package_license, package_author) values " \
666 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
671 __get_str(description),
675 ret = __exec_query(query);
677 _LOGD("Package Localized Info DB Insert failed\n");
680 static void __insert_application_locale_info(gpointer data, gpointer userdata)
685 char query[MAX_QUERY_LEN] = {'\0'};
687 application_x *app = (application_x*)userdata;
688 GList *lbl = app->label;
689 GList *icn = app->icon;
691 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
694 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
695 "app_label, app_icon) values " \
696 "('%q', '%q', '%q', '%q')", app->appid, (char*)data,
698 ret = __exec_query(query);
700 _LOGD("Package UiApp Localized Info DB Insert failed\n");
702 /*insert ui app locale info to pkg locale to get mainapp data */
703 if (strcasecmp(app->mainapp, "true")==0) {
704 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
705 "package_label, package_icon, package_description, package_license, package_author) values " \
706 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
711 PKGMGR_PARSER_EMPTY_STR,
712 PKGMGR_PARSER_EMPTY_STR,
713 PKGMGR_PARSER_EMPTY_STR);
715 ret = __exec_query_no_msg(query);
718 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
719 "where package='%s' and package_locale='%s'", icon, app->package, (char*)data);
720 ret = __exec_query_no_msg(query);
725 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
729 char *resolution = NULL;
730 char query[MAX_QUERY_LEN] = {'\0'};
732 application_x *app = (application_x*)userdata;
733 GList *icn = app->icon;
735 __extract_icon_data(data, icn, &icon, &resolution);
736 if (!icon && !resolution)
738 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
739 "app_icon, app_icon_section, app_icon_resolution) values " \
740 "('%q', '%q', '%q', '%q')", app->appid,
741 icon, (char*)data, resolution);
743 ret = __exec_query(query);
745 _LOGD("Package UiApp Localized Info DB Insert failed\n");
749 static void __insert_application_image_info(gpointer data, gpointer userdata)
754 char query[MAX_QUERY_LEN] = {'\0'};
756 application_x *app = (application_x*)userdata;
757 GList *image = app->image;
759 __extract_image_data(data, image, &lang, &img);
762 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
763 "app_image_section, app_image) values " \
764 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
766 ret = __exec_query(query);
768 _LOGD("Package UiApp image Info DB Insert failed\n");
773 static int __insert_mainapp_info(manifest_x *mfx)
778 char query[MAX_QUERY_LEN] = {'\0'};
779 for (tmp = mfx->application; tmp; tmp = tmp->next) {
780 app = (application_x *)tmp->data;
783 snprintf(query, MAX_QUERY_LEN,
784 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
786 ret = __exec_query(query);
788 _LOGD("Package App Info DB Insert Failed\n");
791 if (strcasecmp(app->mainapp, "True")==0)
792 mfx->mainapp_id = strdup(app->appid);
795 if (mfx->mainapp_id == NULL) {
796 if (mfx->application == NULL)
798 app = (application_x *)mfx->application->data;
802 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
804 _LOGD("Not valid appid\n");
808 ret = __exec_query(query);
810 _LOGD("Package UiApp Info DB Insert Failed\n");
814 free((void *)app->mainapp);
815 app->mainapp= strdup("true");
816 mfx->mainapp_id = strdup(app->appid);
819 memset(query, '\0', MAX_QUERY_LEN);
820 snprintf(query, MAX_QUERY_LEN,
821 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
822 ret = __exec_query(query);
824 _LOGD("Package Info DB update Failed\n");
830 /* _PRODUCT_LAUNCHING_ENHANCED_
831 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
833 static int __insert_application_info(manifest_x *mfx)
838 char query[MAX_QUERY_LEN] = {'\0'};
839 for (tmp = mfx->application; tmp; tmp = tmp->next) {
840 app = (application_x *)tmp->data;
844 snprintf(query, MAX_QUERY_LEN,
845 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
846 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
847 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
848 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, app_tep_name) " \
849 "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', '%s', '%s')",\
863 __get_str(app->recentimage),
864 app->launchcondition,
865 app->indicatordisplay,
866 __get_str(app->portraitimg),
867 __get_str(app->landscapeimg),
868 app->guestmode_visibility,
869 app->permission_type,
872 __get_str(app->submode_mainid),
873 mfx->installed_storage,
877 mfx->support_disable,
880 __get_str(mfx->tep_name));
882 ret = __exec_query(query);
884 _LOGD("Package UiApp Info DB Insert Failed\n");
887 memset(query, '\0', MAX_QUERY_LEN);
892 static int __insert_application_appcategory_info(manifest_x *mfx)
899 char query[MAX_QUERY_LEN] = {'\0'};
900 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
901 app = (application_x *)app_tmp->data;
904 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
905 ct = (const char *)ct_tmp->data;
908 snprintf(query, MAX_QUERY_LEN,
909 "insert into package_app_app_category(app_id, category) " \
910 "values('%s','%s')",\
912 ret = __exec_query(query);
914 _LOGD("Package UiApp Category Info DB Insert Failed\n");
917 memset(query, '\0', MAX_QUERY_LEN);
923 static int __insert_application_appmetadata_info(manifest_x *mfx)
930 char query[MAX_QUERY_LEN] = {'\0'};
931 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
932 app = (application_x *)app_tmp->data;
935 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
936 md = (metadata_x *)md_tmp->data;
940 snprintf(query, MAX_QUERY_LEN,
941 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
942 "values('%s','%s', '%s')",\
943 app->appid, md->key, md->value ? md->value : "");
944 ret = __exec_query(query);
946 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
950 memset(query, '\0', MAX_QUERY_LEN);
956 static int __insert_application_apppermission_info(manifest_x *mfx)
963 char query[MAX_QUERY_LEN] = {'\0'};
964 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
965 app = (application_x *)app_tmp->data;
968 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
969 pm = (permission_x *)pm_tmp->data;
972 snprintf(query, MAX_QUERY_LEN,
973 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
974 "values('%s','%s', '%s')",\
975 app->appid, pm->type, pm->value);
976 ret = __exec_query(query);
978 _LOGD("Package UiApp permission Info DB Insert Failed\n");
981 memset(query, '\0', MAX_QUERY_LEN);
987 static int __insert_application_appcontrol_info(manifest_x *mfx)
992 appcontrol_x *acontrol;
994 char query[MAX_QUERY_LEN] = {'\0'};
995 char buf[BUFSIZE] = {'\0'};
996 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
997 app = (application_x *)app_tmp->data;
1000 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1001 acontrol = (appcontrol_x *)acontrol_tmp->data;
1002 if (acontrol == NULL)
1004 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1005 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1006 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1007 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1008 snprintf(query, MAX_QUERY_LEN,
1009 "insert into package_app_app_control(app_id, app_control) " \
1010 "values('%s', '%s')",\
1012 ret = __exec_query(query);
1014 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1017 memset(query, '\0', MAX_QUERY_LEN);
1023 static int __insert_application_datacontrol_info(manifest_x *mfx)
1030 char query[MAX_QUERY_LEN] = {'\0'};
1032 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1033 app = (application_x *)app_tmp->data;
1036 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1037 dc = (datacontrol_x *)dc_tmp->data;
1040 snprintf(query, MAX_QUERY_LEN,
1041 "insert into package_app_data_control(app_id, providerid, access, type) " \
1042 "values('%s', '%s', '%s', '%s')",\
1048 ret = __exec_query(query);
1050 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1053 memset(query, '\0', MAX_QUERY_LEN);
1059 static int __insert_application_share_request_info(manifest_x *mfx)
1068 char query[MAX_QUERY_LEN] = {'\0'};
1069 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1070 app = (application_x *)app_tmp->data;
1073 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1074 ds = (datashare_x *)ds_tmp->data;
1077 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1078 rq = (const char *)rq_tmp->data;
1081 snprintf(query, MAX_QUERY_LEN,
1082 "insert into package_app_share_request(app_id, data_share_request) " \
1083 "values('%s', '%s')",\
1085 ret = __exec_query(query);
1087 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1090 memset(query, '\0', MAX_QUERY_LEN);
1097 static int __insert_application_share_allowed_info(manifest_x *mfx)
1108 char query[MAX_QUERY_LEN] = {'\0'};
1109 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1110 app = (application_x *)app_tmp->data;
1113 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1114 ds = (datashare_x *)ds_tmp->data;
1117 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1118 df = (define_x *)df_tmp->data;
1121 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1122 al = (const char *)al_tmp->data;
1125 snprintf(query, MAX_QUERY_LEN,
1126 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1127 "values('%s', '%s', '%s')",\
1128 app->appid, df->path, al);
1129 ret = __exec_query(query);
1131 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1134 memset(query, '\0', MAX_QUERY_LEN);
1142 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1146 const char *pv = NULL;
1147 char query[MAX_QUERY_LEN] = { '\0' };
1150 const char *auth_name = NULL;
1151 const char *auth_email = NULL;
1152 const char *auth_href = NULL;
1154 GList *pkglocale = NULL;
1155 GList *applocale = NULL;
1156 GList *appicon = NULL;
1157 GList *appimage = NULL;
1159 if (mfx->author && mfx->author->data) {
1160 author = (author_x *)mfx->author->data;
1162 auth_name = author->text;
1164 auth_email = author->email;
1166 auth_href = author->href;
1168 /*Insert in the package_cert_info CERT_DB*/
1169 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1170 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1171 if (ret != PMINFO_R_OK) {
1172 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1173 _LOGE("Cert Info DB create handle failed\n");
1176 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1177 if (ret != PMINFO_R_OK) {
1178 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1179 _LOGE("Cert Info DB Insert Failed\n");
1183 /*Insert in the package_info DB*/
1184 snprintf(query, MAX_QUERY_LEN,
1185 "insert into package_info(package, package_type, package_version, package_api_version, package_tep_name, install_location, package_size, " \
1186 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1187 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1188 "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')",\
1192 __get_str(mfx->api_version),
1193 __get_str(mfx->tep_name),
1194 __get_str(mfx->installlocation),
1195 __get_str(mfx->package_size),
1201 mfx->nodisplay_setting,
1203 __get_str(auth_name),
1204 __get_str(auth_email),
1205 __get_str(auth_href),
1206 mfx->installed_time,
1207 mfx->installed_storage,
1208 __get_str(mfx->storeclient_id),
1210 __get_str(mfx->package_url),
1212 __get_str(mfx->csc_path),
1213 mfx->support_disable);
1215 ret = __exec_query(query);
1217 _LOGD("Package Info DB Insert Failed\n");
1221 /*Insert in the package_privilege_info DB*/
1222 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1223 pv = (const char *)tmp->data;
1226 memset(query, '\0', MAX_QUERY_LEN);
1227 snprintf(query, MAX_QUERY_LEN,
1228 "insert into package_privilege_info(package, privilege) " \
1229 "values('%s','%s')",\
1231 ret = __exec_query(query);
1233 _LOGD("Package Privilege Info DB Insert Failed\n");
1238 if (mfx->application != NULL) {
1239 ret = __insert_mainapp_info(mfx);
1244 /*Insert the package locale*/
1245 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1246 /*remove duplicated data in pkglocale*/
1247 __trimfunc(pkglocale);
1249 /*Insert the app locale, icon, image info */
1250 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1251 app = (application_x *)tmp->data;
1254 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1255 appicon = __create_icon_list(appicon, app->icon);
1256 appimage = __create_image_list(appimage, app->image);
1258 /*remove duplicated data in applocale*/
1259 __trimfunc(applocale);
1260 __trimfunc(appicon);
1261 __trimfunc(appimage);
1263 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1265 /*native app locale info*/
1266 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1267 app = (application_x *)tmp->data;
1270 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1271 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1272 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1275 g_list_free(pkglocale);
1277 g_list_free(applocale);
1279 g_list_free(appicon);
1281 g_list_free(appimage);
1284 /*Insert in the package_app_info DB*/
1285 ret = __insert_application_info(mfx);
1288 /*Insert in the package_app_app_control DB*/
1289 ret = __insert_application_appcontrol_info(mfx);
1293 /*Insert in the package_app_app_category DB*/
1294 ret = __insert_application_appcategory_info(mfx);
1298 /*Insert in the package_app_app_metadata DB*/
1299 ret = __insert_application_appmetadata_info(mfx);
1303 /*Insert in the package_app_app_permission DB*/
1304 ret = __insert_application_apppermission_info(mfx);
1308 /*Insert in the package_app_share_allowed DB*/
1309 ret = __insert_application_share_allowed_info(mfx);
1313 /*Insert in the package_app_share_request DB*/
1314 ret = __insert_application_share_request_info(mfx);
1318 /*Insert in the package_app_data_control DB*/
1319 ret = __insert_application_datacontrol_info(mfx);
1327 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1329 char query[MAX_QUERY_LEN] = { '\0' };
1331 memset(query, '\0', MAX_QUERY_LEN);
1332 snprintf(query, MAX_QUERY_LEN,
1333 "delete from %s where app_id='%s'", db_table, appid);
1334 ret = __exec_query(query);
1336 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1342 static int __delete_subpkg_info_from_db(char *appid)
1346 ret = __delete_appinfo_from_db("package_app_info", appid);
1349 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1352 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1355 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1358 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1361 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1364 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1367 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1370 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1373 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1376 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1383 static int __delete_subpkg_from_db(manifest_x *mfx)
1385 char query[MAX_QUERY_LEN] = { '\0' };
1386 char *error_message = NULL;
1388 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1390 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1391 _LOGE("Don't execute query = %s error message = %s\n", query,
1393 sqlite3_free(error_message);
1396 sqlite3_free(error_message);
1401 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1403 char query[MAX_QUERY_LEN] = { '\0' };
1407 /*Delete from cert table*/
1408 if (uid != GLOBAL_USER)
1409 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1411 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1413 _LOGD("Cert Info DB Delete Failed\n");
1417 /*Delete from Package Info DB*/
1418 snprintf(query, MAX_QUERY_LEN,
1419 "delete from package_info where package='%s'", mfx->package);
1420 ret = __exec_query(query);
1422 _LOGD("Package Info DB Delete Failed\n");
1425 memset(query, '\0', MAX_QUERY_LEN);
1427 /*Delete from Package Localized Info*/
1428 snprintf(query, MAX_QUERY_LEN,
1429 "delete from package_localized_info where package='%s'", mfx->package);
1430 ret = __exec_query(query);
1432 _LOGD("Package Localized Info DB Delete Failed\n");
1436 /*Delete from Package Privilege Info*/
1437 snprintf(query, MAX_QUERY_LEN,
1438 "delete from package_privilege_info where package='%s'", mfx->package);
1439 ret = __exec_query(query);
1441 _LOGD("Package Privilege Info DB Delete Failed\n");
1445 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1446 app = (application_x *)tmp->data;
1449 ret = __delete_appinfo_from_db("package_app_info", app->appid);
1452 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
1455 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
1458 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
1461 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
1464 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
1467 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
1470 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
1473 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
1476 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
1479 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
1484 /* if main package has sub pkg, delete sub pkg data*/
1485 __delete_subpkg_from_db(mfx);
1490 static int __update_preload_condition_in_db()
1493 char query[MAX_QUERY_LEN] = {'\0'};
1495 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
1497 ret = __exec_query(query);
1499 _LOGD("Package preload_condition update failed\n");
1504 API int pkgmgr_parser_initialize_db(uid_t uid)
1508 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
1510 _LOGD("package info DB initialization failed\n");
1513 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
1515 _LOGD("package localized info DB initialization failed\n");
1518 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
1520 _LOGD("package app app privilege DB initialization failed\n");
1523 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
1525 _LOGD("package app info DB initialization failed\n");
1528 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
1530 _LOGD("package app localized info DB initialization failed\n");
1533 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
1535 _LOGD("package app icon localized info DB initialization failed\n");
1538 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
1540 _LOGD("package app image info DB initialization failed\n");
1543 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
1545 _LOGD("package app app control DB initialization failed\n");
1548 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
1550 _LOGD("package app app category DB initialization failed\n");
1553 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
1555 _LOGD("package app app category DB initialization failed\n");
1558 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
1560 _LOGD("package app app permission DB initialization failed\n");
1563 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
1565 _LOGD("package app share allowed DB initialization failed\n");
1568 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
1570 _LOGD("package app share request DB initialization failed\n");
1573 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
1575 _LOGD("package app data control DB initialization failed\n");
1579 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
1581 _LOGD("package cert info DB initialization failed\n");
1584 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
1586 _LOGD("package cert index info DB initialization failed\n");
1590 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
1591 _LOGD("Failed to change cert db permission\n");
1593 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
1594 _LOGD("Failed to change parser db permission\n");
1600 static int __parserdb_change_perm(const char *db_file, uid_t uid)
1603 char journal_file[BUFSIZE];
1606 struct passwd *userinfo = NULL;
1607 files[0] = (char *)db_file;
1608 files[1] = journal_file;
1611 if (db_file == NULL)
1614 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
1616 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
1617 if (uid == OWNER_ROOT)
1619 userinfo = getpwuid(uid);
1621 _LOGE("FAIL: user %d doesn't exist", uid);
1624 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
1626 for (i = 0; files[i]; i++) {
1627 ret = chown(files[i], uid, userinfo->pw_gid);
1629 if (strerror_r(errno, buf, sizeof(buf)))
1631 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
1632 userinfo->pw_gid, buf);
1636 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
1638 if (strerror_r(errno, buf, sizeof(buf)))
1640 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
1643 SET_SMACK_LABEL(files[i]);
1648 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
1652 if (getuid() != OWNER_ROOT) {
1653 _LOGE("Only root user is allowed");
1657 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
1658 _LOGE("Manifest db for user %d is already exists", uid);
1662 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
1663 _LOGE("Cert db for user %d is already exists", uid);
1667 ret = pkgmgr_parser_check_and_create_db(uid);
1670 ret = pkgmgr_parser_initialize_db(uid);
1672 pkgmgr_parser_close_db();
1675 pkgmgr_parser_close_db();
1680 API int pkgmgr_parser_check_and_create_db(uid_t uid)
1684 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
1686 _LOGD("Manifest DB creation Failed\n");
1691 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid));
1693 _LOGD("Cert DB creation Failed\n");
1699 void pkgmgr_parser_close_db(void)
1701 sqlite3_close(pkgmgr_parser_db);
1702 sqlite3_close(pkgmgr_cert_db);
1706 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
1708 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
1710 _LOGD("manifest pointer is NULL\n");
1714 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
1716 _LOGD("Failed to open DB\n");
1719 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
1722 /*Begin transaction*/
1723 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1724 if (ret != SQLITE_OK) {
1725 _LOGD("Failed to begin transaction\n");
1729 _LOGD("Transaction Begin\n");
1730 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
1732 _LOGD("Insert into DB failed. Rollback now\n");
1733 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1736 /*Commit transaction*/
1737 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1738 if (ret != SQLITE_OK) {
1739 _LOGD("Failed to commit transaction. Rollback now\n");
1740 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1744 _LOGD("Transaction Commit and End\n");
1746 pkgmgr_parser_close_db();
1750 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
1752 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
1754 _LOGD("manifest pointer is NULL\n");
1758 ret = pkgmgr_parser_check_and_create_db(uid);
1760 _LOGD("Failed to open DB\n");
1763 ret = pkgmgr_parser_initialize_db(uid);
1766 /*Begin transaction*/
1767 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1768 if (ret != SQLITE_OK) {
1769 _LOGD("Failed to begin transaction\n");
1773 _LOGD("Transaction Begin\n");
1774 ret = __insert_manifest_info_in_db(mfx, uid);
1776 _LOGD("Insert into DB failed. Rollback now\n");
1777 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1780 /*Commit transaction*/
1781 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1782 if (ret != SQLITE_OK) {
1783 _LOGD("Failed to commit transaction. Rollback now\n");
1784 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1788 _LOGD("Transaction Commit and End\n");
1790 pkgmgr_parser_close_db();
1794 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
1796 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, GLOBAL_USER);
1799 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
1801 if (pkgid == NULL || tep_path == NULL) {
1802 _LOGE("invalid parameter");
1809 ret = pkgmgr_parser_check_and_create_db(uid);
1811 _LOGD("Failed to open DB\n");
1814 ret = pkgmgr_parser_initialize_db(uid);
1818 /*Begin transaction*/
1819 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1820 if (ret != SQLITE_OK) {
1821 _LOGD("Failed to begin transaction\n");
1825 _LOGD("Transaction Begin\n");
1828 /* Updating TEP info in "package_info" table */
1829 query = sqlite3_mprintf("UPDATE package_info "\
1830 "SET package_tep_name = %Q "\
1831 "WHERE package = %Q", tep_path, pkgid);
1833 ret = __exec_query(query);
1834 sqlite3_free(query);
1835 if (ret != SQLITE_OK) {
1836 ret = PM_PARSER_R_ERROR;
1837 _LOGE("sqlite exec failed to insert entries into package_info!!");
1841 /* Updating TEP info in "package_app_info" table */
1842 query = sqlite3_mprintf("UPDATE package_app_info "\
1843 "SET app_tep_name = %Q "\
1844 "WHERE package = %Q", tep_path, pkgid);
1846 ret = __exec_query(query);
1847 sqlite3_free(query);
1848 if (ret != SQLITE_OK) {
1849 ret = PM_PARSER_R_ERROR;
1850 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
1854 /*Commit transaction*/
1855 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1856 if (ret != SQLITE_OK) {
1857 _LOGE("Failed to commit transaction, Rollback now\n");
1858 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1859 if (ret != SQLITE_OK)
1860 _LOGE("Failed to Rollback\n");
1862 ret = PM_PARSER_R_ERROR;
1865 _LOGD("Transaction Commit and End\n");
1866 ret = PM_PARSER_R_OK;
1869 pkgmgr_parser_close_db();
1874 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
1877 _LOGD("manifest pointer is NULL\n");
1881 ret = pkgmgr_parser_check_and_create_db(uid);
1883 _LOGD("Failed to open DB\n");
1886 ret = pkgmgr_parser_initialize_db(uid);
1889 /*Preserve guest mode visibility*/
1890 __preserve_guestmode_visibility_value( mfx);
1891 /*Begin transaction*/
1892 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1893 if (ret != SQLITE_OK) {
1894 _LOGD("Failed to begin transaction\n");
1898 _LOGD("Transaction Begin\n");
1899 ret = __delete_manifest_info_from_db(mfx, uid);
1901 _LOGD("Delete from DB failed. Rollback now\n");
1902 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1905 ret = __insert_manifest_info_in_db(mfx, uid);
1907 _LOGD("Insert into DB failed. Rollback now\n");
1908 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1912 /*Commit transaction*/
1913 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1914 if (ret != SQLITE_OK) {
1915 _LOGD("Failed to commit transaction. Rollback now\n");
1916 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1920 _LOGD("Transaction Commit and End\n");
1922 pkgmgr_parser_close_db();
1926 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
1928 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
1931 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
1934 _LOGD("manifest pointer is NULL\n");
1938 ret = pkgmgr_parser_check_and_create_db(uid);
1940 _LOGD("Failed to open DB\n");
1943 /*Begin transaction*/
1944 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1945 if (ret != SQLITE_OK) {
1946 _LOGD("Failed to begin transaction\n");
1950 _LOGD("Transaction Begin\n");
1951 ret = __delete_manifest_info_from_db(mfx, uid);
1953 _LOGD("Delete from DB failed. Rollback now\n");
1954 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1957 /*Commit transaction*/
1958 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1959 if (ret != SQLITE_OK) {
1960 _LOGD("Failed to commit transaction, Rollback now\n");
1961 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1965 _LOGD("Transaction Commit and End\n");
1967 pkgmgr_parser_close_db();
1971 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
1973 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
1976 API int pkgmgr_parser_update_preload_info_in_db()
1979 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
1981 _LOGD("Failed to open DB\n");
1984 /*Begin transaction*/
1985 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1986 if (ret != SQLITE_OK) {
1987 _LOGD("Failed to begin transaction\n");
1991 _LOGD("Transaction Begin\n");
1992 ret = __update_preload_condition_in_db();
1994 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
1995 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1998 /*Commit transaction*/
1999 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2000 if (ret != SQLITE_OK) {
2001 _LOGD("Failed to commit transaction, Rollback now\n");
2002 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2006 _LOGD("Transaction Commit and End\n");
2008 pkgmgr_parser_close_db();
2012 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2015 ret = pkgmgr_parser_check_and_create_db(uid);
2017 _LOGD("Failed to open DB\n");
2020 /*Begin transaction*/
2021 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2022 if (ret != SQLITE_OK) {
2023 _LOGD("Failed to begin transaction\n");
2027 _LOGD("Transaction Begin\n");
2028 ret = __update_preload_condition_in_db();
2030 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2031 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2034 /*Commit transaction*/
2035 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2036 if (ret != SQLITE_OK) {
2037 _LOGD("Failed to commit transaction, Rollback now\n");
2038 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2042 _LOGD("Transaction Commit and End\n");
2044 pkgmgr_parser_close_db();