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 "pkgmgr-info-basic.h"
40 #include "pkgmgr-info-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 SET_SMACK_LABEL(x) \
57 if (smack_setlabel((x), "System::Shared", SMACK_LABEL_ACCESS)) \
58 _LOGE("failed chsmack -a \"System::Shared\" %s", x); \
60 _LOGD("chsmack -a \"System::Shared\" %s", x); \
63 sqlite3 *pkgmgr_parser_db;
64 sqlite3 *pkgmgr_cert_db;
67 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
68 "(package text primary key not null, " \
69 "package_type text DEFAULT 'rpm', " \
70 "package_version text, " \
71 "package_api_version text, " \
72 "install_location text, " \
73 "package_size text, " \
74 "package_removable text DEFAULT 'true', " \
75 "package_preload text DEFAULT 'false', " \
76 "package_readonly text DEFAULT 'false', " \
77 "package_update text DEFAULT 'false', " \
78 "package_appsetting text DEFAULT 'false', " \
79 "package_nodisplay text DEFAULT 'false', " \
80 "package_system text DEFAULT 'false', " \
81 "author_name text, " \
82 "author_email text, " \
84 "installed_time text," \
85 "installed_storage text," \
86 "storeclient_id text," \
92 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
93 "(package text not null, " \
94 "package_locale text DEFAULT 'No Locale', " \
95 "package_label text, " \
96 "package_icon text, " \
97 "package_description text, " \
98 "package_license text, " \
100 "PRIMARY KEY(package, package_locale), " \
101 "FOREIGN KEY(package) " \
102 "REFERENCES package_info(package) " \
105 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
106 "(package text not null, " \
107 "privilege text not null, " \
108 "PRIMARY KEY(package, privilege) " \
109 "FOREIGN KEY(package) " \
110 "REFERENCES package_info(package) " \
113 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
114 "(app_id text primary key not null, " \
115 "app_component text, " \
117 "app_nodisplay text DEFAULT 'false', " \
119 "app_onboot text DEFAULT 'false', " \
120 "app_multiple text DEFAULT 'false', " \
121 "app_autorestart text DEFAULT 'false', " \
122 "app_taskmanage text DEFAULT 'false', " \
123 "app_enabled text DEFAULT 'true', " \
124 "app_hwacceleration text DEFAULT 'use-system-setting', " \
125 "app_screenreader text DEFAULT 'use-system-setting', " \
126 "app_mainapp text, " \
127 "app_recentimage text, " \
128 "app_launchcondition text, " \
129 "app_indicatordisplay text DEFAULT 'true', " \
130 "app_portraitimg text, " \
131 "app_landscapeimg text, " \
132 "app_guestmodevisibility text DEFAULT 'true', " \
133 "app_permissiontype text DEFAULT 'normal', " \
134 "app_preload text DEFAULT 'false', " \
135 "app_submode text DEFAULT 'false', " \
136 "app_submode_mainid text, " \
137 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
138 "component_type text, " \
139 "package text not null, " \
140 "FOREIGN KEY(package) " \
141 "REFERENCES package_info(package) " \
144 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
145 "(app_id text not null, " \
146 "app_locale text DEFAULT 'No Locale', " \
149 "PRIMARY KEY(app_id,app_locale) " \
150 "FOREIGN KEY(app_id) " \
151 "REFERENCES package_app_info(app_id) " \
154 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
155 "(app_id text not null, " \
157 "app_icon_section text, " \
158 "app_icon_resolution text, " \
159 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
160 "FOREIGN KEY(app_id) " \
161 "REFERENCES package_app_info(app_id) " \
164 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
165 "(app_id text not null, " \
166 "app_locale text DEFAULT 'No Locale', " \
167 "app_image_section text, " \
169 "PRIMARY KEY(app_id,app_image_section) " \
170 "FOREIGN KEY(app_id) " \
171 "REFERENCES package_app_info(app_id) " \
174 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
175 "(app_id text not null, " \
176 "app_control text not null, " \
177 "PRIMARY KEY(app_id,app_control) " \
178 "FOREIGN KEY(app_id) " \
179 "REFERENCES package_app_info(app_id) " \
182 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
183 "(app_id text not null, " \
184 "operation text not null, " \
185 "uri_scheme text, " \
187 "subapp_name text, " \
188 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
189 "FOREIGN KEY(app_id) " \
190 "REFERENCES package_app_info(app_id) " \
193 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
194 "(app_id text not null, " \
195 "category text not null, " \
196 "PRIMARY KEY(app_id,category) " \
197 "FOREIGN KEY(app_id) " \
198 "REFERENCES package_app_info(app_id) " \
201 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
202 "(app_id text not null, " \
203 "md_key text not null, " \
204 "md_value text not null, " \
205 "PRIMARY KEY(app_id, md_key, md_value) " \
206 "FOREIGN KEY(app_id) " \
207 "REFERENCES package_app_info(app_id) " \
210 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
211 "(app_id text not null, " \
212 "pm_type text not null, " \
213 "pm_value text not null, " \
214 "PRIMARY KEY(app_id, pm_type, pm_value) " \
215 "FOREIGN KEY(app_id) " \
216 "REFERENCES package_app_info(app_id) " \
219 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
220 "(app_id text not null, " \
221 "data_share_path text not null, " \
222 "data_share_allowed text not null, " \
223 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
224 "FOREIGN KEY(app_id) " \
225 "REFERENCES package_app_info(app_id) " \
228 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
229 "(app_id text not null, " \
230 "data_share_request text not null, " \
231 "PRIMARY KEY(app_id,data_share_request) " \
232 "FOREIGN KEY(app_id) " \
233 "REFERENCES package_app_info(app_id) " \
236 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
237 "(cert_info text not null, " \
238 "cert_id integer, " \
239 "cert_ref_count integer, " \
240 "PRIMARY KEY(cert_id)) "
242 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
243 "(package text not null, " \
244 "author_root_cert integer, " \
245 "author_im_cert integer, " \
246 "author_signer_cert integer, " \
247 "dist_root_cert integer, " \
248 "dist_im_cert integer, " \
249 "dist_signer_cert integer, " \
250 "dist2_root_cert integer, " \
251 "dist2_im_cert integer, " \
252 "dist2_signer_cert integer, " \
253 "PRIMARY KEY(package)) "
255 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
256 "(app_id text not null, " \
257 "providerid text not null, " \
258 "access text not null, " \
259 "type text not null, " \
260 "PRIMARY KEY(app_id, providerid, access, type) " \
261 "FOREIGN KEY(app_id) " \
262 "REFERENCES package_app_info(app_id) " \
265 static int __insert_uiapplication_info(manifest_x *mfx);
266 static int __insert_serviceapplication_info(manifest_x *mfx);
267 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
268 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
269 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
270 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
271 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
272 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
273 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
274 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
275 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
276 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
277 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
278 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
279 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx);
280 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx);
281 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
282 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
283 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
284 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
285 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
286 static int __delete_subpkg_info_from_db(char *appid);
287 static int __delete_appinfo_from_db(char *db_table, const char *appid);
288 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
289 static int __exec_query(char *query);
290 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
291 char **label, char **license, char **icon, char **description, char **author);
292 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
293 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
294 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
295 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
296 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
297 static int __parserdb_change_perm(const char *db_file, uid_t uid);
299 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
302 __delete_subpkg_info_from_db(coltxt[0]);
307 static const char *__get_str(const char *str)
311 return PKGMGR_PARSER_EMPTY_STR;
317 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
322 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
323 if (ret != SQLITE_OK) {
324 _LOGD("connect db [%s] failed!\n", db_path);
332 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
334 manifest_x *mfx = (manifest_x *)data;
338 uiapplication_x *uiapp = NULL;
339 for(i = 0; i < ncols; i++)
341 uiapp = mfx->uiapplication;
342 if (strcmp(colname[i], "app_id") == 0) {
344 appid = strdup(coltxt[i]);
345 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
347 status = strdup(coltxt[i]);
351 _LOGD("app id is NULL\n");
354 /*update guest mode visibility*/
355 for (; uiapp != NULL; uiapp = uiapp->next) {
356 if (strcmp(uiapp->appid, appid) == 0) {
357 free((void *)uiapp->guestmode_visibility);
358 uiapp->guestmode_visibility = strdup(status);
374 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
376 char *error_message = NULL;
377 char query[MAX_QUERY_LEN] = {'\0'};
378 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
380 sqlite3_exec(pkgmgr_parser_db, query,
381 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
382 _LOGD("Don't execute query = %s error message = %s\n",
383 query, error_message);
384 sqlite3_free(error_message);
389 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
391 char *error_message = NULL;
393 sqlite3_exec(db_handle, db_query,
394 NULL, NULL, &error_message)) {
395 _LOGD("Don't execute query = %s error message = %s\n",
396 db_query, error_message);
397 sqlite3_free(error_message);
400 sqlite3_free(error_message);
404 static int __exec_query(char *query)
406 char *error_message = NULL;
408 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
409 _LOGD("Don't execute query = %s error message = %s\n", query,
411 sqlite3_free(error_message);
414 sqlite3_free(error_message);
418 static int __exec_query_no_msg(char *query)
420 char *error_message = NULL;
422 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
423 sqlite3_free(error_message);
426 sqlite3_free(error_message);
430 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
436 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
442 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
448 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
454 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
460 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
467 static GList *__create_icon_list(GList *locale, icon_x *icn)
472 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
478 static GList *__create_image_list(GList *locale, image_x *image)
483 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
489 static void __trimfunc(GList* trim_list)
491 char *trim_data = NULL;
495 list = g_list_first(trim_list);
498 trim_data = (char *)list->data;
501 if (strcmp(trim_data, prev) == 0) {
502 trim_list = g_list_remove(trim_list, trim_data);
503 list = g_list_first(trim_list);
512 list = g_list_next(list);
516 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
518 if (a == NULL || b == NULL)
520 if (strcmp((char*)a, (char*)b) == 0)
522 if (strcmp((char*)a, (char*)b) < 0)
524 if (strcmp((char*)a, (char*)b) > 0)
529 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
530 char **label, char **license, char **icon, char **description, char **author)
535 if (strcmp(lbl->lang, (char *)data) == 0) {
536 *label = (char*)lbl->text;
545 if (strcmp(lcn->lang, (char *)data) == 0) {
546 *license = (char*)lcn->text;
555 if (strcmp(icn->lang, (char *)data) == 0) {
556 *icon = (char*)icn->text;
565 if (strcmp(dcn->lang, (char *)data) == 0) {
566 *description = (char*)dcn->text;
575 if (strcmp(ath->lang, (char *)data) == 0) {
576 *author = (char*)ath->text;
585 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
590 if (strcmp(icn->section, (char *)data) == 0) {
591 *icon = (char*)icn->text;
592 *resolution = (char*)icn->resolution;
600 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
604 if (image->section) {
605 if (strcmp(image->section, (char *)data) == 0) {
606 *lang = (char*)image->lang;
607 *img = (char*)image->text;
615 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
620 char *description = NULL;
621 char *license = NULL;
623 char query[MAX_QUERY_LEN] = {'\0'};
625 manifest_x *mfx = (manifest_x *)userdata;
626 label_x *lbl = mfx->label;
627 license_x *lcn = mfx->license;
628 icon_x *icn = mfx->icon;
629 description_x *dcn = mfx->description;
630 author_x *ath = mfx->author;
632 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
633 if (!label && !description && !icon && !license && !author)
636 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
637 "package_label, package_icon, package_description, package_license, package_author) values " \
638 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
643 __get_str(description),
647 ret = __exec_query(query);
649 _LOGD("Package Localized Info DB Insert failed\n");
652 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
657 char query[MAX_QUERY_LEN] = {'\0'};
659 uiapplication_x *up = (uiapplication_x*)userdata;
660 label_x *lbl = up->label;
661 icon_x *icn = up->icon;
663 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
666 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
667 "app_label, app_icon) values " \
668 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
670 ret = __exec_query(query);
672 _LOGD("Package UiApp Localized Info DB Insert failed\n");
674 /*insert ui app locale info to pkg locale to get mainapp data */
675 if (strcasecmp(up->mainapp, "true")==0) {
676 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
677 "package_label, package_icon, package_description, package_license, package_author) values " \
678 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
683 PKGMGR_PARSER_EMPTY_STR,
684 PKGMGR_PARSER_EMPTY_STR,
685 PKGMGR_PARSER_EMPTY_STR);
687 ret = __exec_query_no_msg(query);
690 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
691 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
692 ret = __exec_query_no_msg(query);
697 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
701 char *resolution = NULL;
702 char query[MAX_QUERY_LEN] = {'\0'};
704 uiapplication_x *up = (uiapplication_x*)userdata;
705 icon_x *icn = up->icon;
707 __extract_icon_data(data, icn, &icon, &resolution);
708 if (!icon && !resolution)
710 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
711 "app_icon, app_icon_section, app_icon_resolution) values " \
712 "('%q', '%q', '%q', '%q')", up->appid,
713 icon, (char*)data, resolution);
715 ret = __exec_query(query);
717 _LOGD("Package UiApp Localized Info DB Insert failed\n");
721 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
726 char query[MAX_QUERY_LEN] = {'\0'};
728 uiapplication_x *up = (uiapplication_x*)userdata;
729 image_x *image = up->image;
731 __extract_image_data(data, image, &lang, &img);
734 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
735 "app_image_section, app_image) values " \
736 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
738 ret = __exec_query(query);
740 _LOGD("Package UiApp image Info DB Insert failed\n");
745 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
750 char query[MAX_QUERY_LEN] = {'\0'};
752 serviceapplication_x *sp = (serviceapplication_x*)userdata;
753 label_x *lbl = sp->label;
754 icon_x *icn = sp->icon;
756 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
759 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
760 "app_label, app_icon) values " \
761 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
763 ret = __exec_query(query);
765 _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
768 static int __insert_ui_mainapp_info(manifest_x *mfx)
770 uiapplication_x *up = mfx->uiapplication;
772 char query[MAX_QUERY_LEN] = {'\0'};
775 snprintf(query, MAX_QUERY_LEN,
776 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
778 ret = __exec_query(query);
780 _LOGD("Package UiApp Info DB Insert Failed\n");
783 if (strcasecmp(up->mainapp, "True")==0)
784 mfx->mainapp_id = strdup(up->appid);
787 memset(query, '\0', MAX_QUERY_LEN);
790 if (mfx->mainapp_id == NULL){
791 if (mfx->uiapplication && mfx->uiapplication->appid) {
792 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
794 _LOGD("Not valid appid\n");
798 ret = __exec_query(query);
800 _LOGD("Package UiApp Info DB Insert Failed\n");
804 free((void *)mfx->uiapplication->mainapp);
805 mfx->uiapplication->mainapp= strdup("true");
806 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
809 memset(query, '\0', MAX_QUERY_LEN);
810 snprintf(query, MAX_QUERY_LEN,
811 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
812 ret = __exec_query(query);
814 _LOGD("Package Info DB update Failed\n");
820 /* _PRODUCT_LAUNCHING_ENHANCED_
821 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
823 static int __insert_uiapplication_info(manifest_x *mfx)
825 uiapplication_x *up = mfx->uiapplication;
827 char query[MAX_QUERY_LEN] = {'\0'};
830 snprintf(query, MAX_QUERY_LEN,
831 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
832 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
833 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
834 "app_preload, app_submode, app_submode_mainid, component_type, package, app_launch_mode) " \
835 "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')",\
841 PKGMGR_PARSER_EMPTY_STR,
843 PKGMGR_PARSER_EMPTY_STR,
849 __get_str(up->recentimage),
851 up->indicatordisplay,
852 __get_str(up->portraitimg),
853 __get_str(up->landscapeimg),
854 up->guestmode_visibility,
858 __get_str(up->submode_mainid),
863 ret = __exec_query(query);
865 _LOGD("Package UiApp Info DB Insert Failed\n");
869 memset(query, '\0', MAX_QUERY_LEN);
874 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
876 uiapplication_x *up = mfx->uiapplication;
877 category_x *ct = NULL;
879 char query[MAX_QUERY_LEN] = {'\0'};
885 snprintf(query, MAX_QUERY_LEN,
886 "insert into package_app_app_category(app_id, category) " \
887 "values('%s','%s')",\
888 up->appid, ct->name);
889 ret = __exec_query(query);
891 _LOGD("Package UiApp Category Info DB Insert Failed\n");
895 memset(query, '\0', MAX_QUERY_LEN);
902 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
904 uiapplication_x *up = mfx->uiapplication;
905 metadata_x *md = NULL;
907 char query[MAX_QUERY_LEN] = {'\0'};
914 snprintf(query, MAX_QUERY_LEN,
915 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
916 "values('%s','%s', '%s')",\
917 up->appid, md->key, md->value);
918 ret = __exec_query(query);
920 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
925 memset(query, '\0', MAX_QUERY_LEN);
932 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
934 uiapplication_x *up = mfx->uiapplication;
935 permission_x *pm = NULL;
937 char query[MAX_QUERY_LEN] = {'\0'};
943 snprintf(query, MAX_QUERY_LEN,
944 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
945 "values('%s','%s', '%s')",\
946 up->appid, pm->type, pm->value);
947 ret = __exec_query(query);
949 _LOGD("Package UiApp permission Info DB Insert Failed\n");
953 memset(query, '\0', MAX_QUERY_LEN);
960 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
962 uiapplication_x *up = mfx->uiapplication;
963 appcontrol_x *acontrol = NULL;
965 char query[MAX_QUERY_LEN] = {'\0'};
966 char buf[BUFSIZE] = {'\0'};
968 acontrol = up->appcontrol;
969 while (acontrol != NULL) {
970 snprintf(buf, BUFSIZE, "%s|%s|%s",\
971 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
972 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
973 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
974 snprintf(query, MAX_QUERY_LEN,
975 "insert into package_app_app_control(app_id, app_control) " \
976 "values('%s', '%s')",\
978 ret = __exec_query(query);
980 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
983 memset(query, '\0', MAX_QUERY_LEN);
984 acontrol = acontrol->next;
991 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
993 uiapplication_x *up = mfx->uiapplication;
994 appsvc_x *asvc = NULL;
995 operation_x *op = NULL;
998 subapp_x *sub = NULL;
1000 char query[MAX_QUERY_LEN] = {'\0'};
1001 const char *operation = NULL;
1002 const char *mime = NULL;
1003 const char *uri = NULL;
1004 const char *subapp = NULL;
1010 op = asvc->operation;
1014 operation = op->name;
1031 snprintf(query, MAX_QUERY_LEN,
1032 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1033 "values('%s', '%s', '%s', '%s', '%s')",\
1040 ret = __exec_query(query);
1042 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1045 memset(query, '\0', MAX_QUERY_LEN);
1049 } while(ui != NULL);
1053 }while(sub != NULL);
1069 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx)
1071 uiapplication_x *up = mfx->uiapplication;
1072 datacontrol_x *dc = NULL;
1074 char query[MAX_QUERY_LEN] = {'\0'};
1078 dc = up->datacontrol;
1081 snprintf(query, MAX_QUERY_LEN,
1082 "insert into package_app_data_control(app_id, providerid, access, type) " \
1083 "values('%s', '%s', '%s', '%s')",\
1084 mfx->uiapplication->appid,
1089 ret = __exec_query(query);
1091 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1094 memset(query, '\0', MAX_QUERY_LEN);
1102 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1104 uiapplication_x *up = mfx->uiapplication;
1105 datashare_x *ds = NULL;
1106 request_x *rq = NULL;
1108 char query[MAX_QUERY_LEN] = {'\0'};
1117 snprintf(query, MAX_QUERY_LEN,
1118 "insert into package_app_share_request(app_id, data_share_request) " \
1119 "values('%s', '%s')",\
1120 up->appid, rq->text);
1121 ret = __exec_query(query);
1123 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1126 memset(query, '\0', MAX_QUERY_LEN);
1136 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1138 uiapplication_x *up = mfx->uiapplication;
1139 datashare_x *ds = NULL;
1140 define_x *df = NULL;
1141 allowed_x *al = NULL;
1143 char query[MAX_QUERY_LEN] = {'\0'};
1155 snprintf(query, MAX_QUERY_LEN,
1156 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1157 "values('%s', '%s', '%s')",\
1158 up->appid, df->path, al->text);
1159 ret = __exec_query(query);
1161 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1164 memset(query, '\0', MAX_QUERY_LEN);
1176 static int __insert_serviceapplication_info(manifest_x *mfx)
1178 serviceapplication_x *sp = mfx->serviceapplication;
1180 char query[MAX_QUERY_LEN] = {'\0'};
1183 snprintf(query, MAX_QUERY_LEN,
1184 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1185 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1186 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1187 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1188 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1189 ret = __exec_query(query);
1191 _LOGD("Package ServiceApp Info DB Insert Failed\n");
1195 memset(query, '\0', MAX_QUERY_LEN);
1200 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1202 serviceapplication_x *sp = mfx->serviceapplication;
1203 category_x *ct = NULL;
1205 char query[MAX_QUERY_LEN] = {'\0'};
1211 snprintf(query, MAX_QUERY_LEN,
1212 "insert into package_app_app_category(app_id, category) " \
1213 "values('%s','%s')",\
1214 sp->appid, ct->name);
1215 ret = __exec_query(query);
1217 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1221 memset(query, '\0', MAX_QUERY_LEN);
1228 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1230 serviceapplication_x *sp = mfx->serviceapplication;
1231 metadata_x *md = NULL;
1233 char query[MAX_QUERY_LEN] = {'\0'};
1240 snprintf(query, MAX_QUERY_LEN,
1241 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1242 "values('%s','%s', '%s')",\
1243 sp->appid, md->key, md->value);
1244 ret = __exec_query(query);
1246 _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1251 memset(query, '\0', MAX_QUERY_LEN);
1258 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1260 serviceapplication_x *sp = mfx->serviceapplication;
1261 permission_x *pm = NULL;
1263 char query[MAX_QUERY_LEN] = {'\0'};
1266 pm = sp->permission;
1269 snprintf(query, MAX_QUERY_LEN,
1270 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1271 "values('%s','%s', '%s')",\
1272 sp->appid, pm->type, pm->value);
1273 ret = __exec_query(query);
1275 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1279 memset(query, '\0', MAX_QUERY_LEN);
1286 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1288 serviceapplication_x *sp = mfx->serviceapplication;
1289 appcontrol_x *acontrol = NULL;
1291 char query[MAX_QUERY_LEN] = {'\0'};
1292 char buf[BUFSIZE] = {'\0'};
1293 while (sp != NULL) {
1294 acontrol = sp->appcontrol;
1295 while (acontrol != NULL) {
1296 snprintf(buf, BUFSIZE, "%s|%s|%s",
1297 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1298 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1299 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1300 snprintf(query, MAX_QUERY_LEN,
1301 "insert into package_app_app_control(app_id, app_control) " \
1302 "values('%s', '%s')",\
1304 ret = __exec_query(query);
1306 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1309 memset(query, '\0', MAX_QUERY_LEN);
1310 acontrol = acontrol->next;
1317 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1319 serviceapplication_x *sp = mfx->serviceapplication;
1320 appsvc_x *asvc = NULL;
1322 char query[MAX_QUERY_LEN] = {'\0'};
1323 operation_x *op = NULL;
1326 subapp_x *sub = NULL;
1327 const char *operation = NULL;
1328 const char *mime = NULL;
1329 const char *uri = NULL;
1330 const char *subapp = NULL;
1336 op = asvc->operation;
1340 operation = op->name;
1356 snprintf(query, MAX_QUERY_LEN,
1357 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1358 "values('%s', '%s', '%s', '%s', '%s')",\
1364 ret = __exec_query(query);
1366 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1369 memset(query, '\0', MAX_QUERY_LEN);
1373 } while(ui != NULL);
1377 }while(sub != NULL);
1393 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx)
1395 serviceapplication_x *sp = mfx->serviceapplication;
1396 datacontrol_x *dc = NULL;
1398 char query[MAX_QUERY_LEN] = {'\0'};
1402 dc = sp->datacontrol;
1405 snprintf(query, MAX_QUERY_LEN,
1406 "insert into package_app_data_control(app_id, providerid, access, type) " \
1407 "values('%s', '%s', '%s', '%s')",\
1408 mfx->serviceapplication->appid,
1413 ret = __exec_query(query);
1415 _LOGD("Package ServiceApp Data Control DB Insert Failed\n");
1418 memset(query, '\0', MAX_QUERY_LEN);
1426 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1428 serviceapplication_x *sp = mfx->serviceapplication;
1429 datashare_x *ds = NULL;
1430 request_x *rq = NULL;
1432 char query[MAX_QUERY_LEN] = {'\0'};
1441 snprintf(query, MAX_QUERY_LEN,
1442 "insert into package_app_share_request(app_id, data_share_request) " \
1443 "values('%s', '%s')",\
1444 sp->appid, rq->text);
1445 ret = __exec_query(query);
1447 _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1450 memset(query, '\0', MAX_QUERY_LEN);
1462 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1464 serviceapplication_x *sp = mfx->serviceapplication;
1465 datashare_x *ds = NULL;
1466 define_x *df = NULL;
1467 allowed_x *al = NULL;
1469 char query[MAX_QUERY_LEN] = {'\0'};
1481 snprintf(query, MAX_QUERY_LEN,
1482 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1483 "values('%s', '%s', '%s')",\
1484 sp->appid, df->path, al->text);
1485 ret = __exec_query(query);
1487 _LOGD("Package App Share Allowed DB Insert Failed\n");
1490 memset(query, '\0', MAX_QUERY_LEN);
1502 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1504 label_x *lbl = mfx->label;
1505 license_x *lcn = mfx->license;
1506 icon_x *icn = mfx->icon;
1507 description_x *dcn = mfx->description;
1508 author_x *ath = mfx->author;
1509 uiapplication_x *up = mfx->uiapplication;
1510 uiapplication_x *up_icn = mfx->uiapplication;
1511 uiapplication_x *up_image = mfx->uiapplication;
1512 serviceapplication_x *sp = mfx->serviceapplication;
1513 privileges_x *pvs = NULL;
1514 privilege_x *pv = NULL;
1515 char query[MAX_QUERY_LEN] = { '\0' };
1517 const char *auth_name = NULL;
1518 const char *auth_email = NULL;
1519 const char *auth_href = NULL;
1521 GList *pkglocale = NULL;
1522 GList *applocale = NULL;
1523 GList *appicon = NULL;
1524 GList *appimage = NULL;
1528 auth_name = ath->text;
1530 auth_email = ath->email;
1532 auth_href = ath->href;
1534 /*Insert in the package_cert_info CERT_DB*/
1535 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1536 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1537 if (ret != PMINFO_R_OK) {
1538 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1539 _LOGE("Cert Info DB create handle failed\n");
1542 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1543 if (ret != PMINFO_R_OK) {
1544 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1545 _LOGE("Cert Info DB Insert Failed\n");
1549 /*Insert in the package_info DB*/
1550 snprintf(query, MAX_QUERY_LEN,
1551 "insert into package_info(package, package_type, package_version, package_api_version, install_location, package_size, " \
1552 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1553 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
1554 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1558 __get_str(mfx->api_version),
1559 __get_str(mfx->installlocation),
1560 __get_str(mfx->package_size),
1566 mfx->nodisplay_setting,
1568 __get_str(auth_name),
1569 __get_str(auth_email),
1570 __get_str(auth_href),
1571 mfx->installed_time,
1572 mfx->installed_storage,
1573 __get_str(mfx->storeclient_id),
1575 __get_str(mfx->package_url),
1577 __get_str(mfx->csc_path));
1579 ret = __exec_query(query);
1581 _LOGD("Package Info DB Insert Failed\n");
1585 /*Insert in the package_privilege_info DB*/
1586 pvs = mfx->privileges;
1587 while (pvs != NULL) {
1588 pv = pvs->privilege;
1589 while (pv != NULL) {
1590 memset(query, '\0', MAX_QUERY_LEN);
1591 snprintf(query, MAX_QUERY_LEN,
1592 "insert into package_privilege_info(package, privilege) " \
1593 "values('%s','%s')",\
1594 mfx->package, pv->text);
1595 ret = __exec_query(query);
1597 _LOGD("Package Privilege Info DB Insert Failed\n");
1606 ret = __insert_ui_mainapp_info(mfx);
1611 /*Insert the package locale*/
1612 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1613 /*remove duplicated data in pkglocale*/
1614 __trimfunc(pkglocale);
1616 /*Insert the app locale info */
1619 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1624 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1627 /*remove duplicated data in applocale*/
1628 __trimfunc(applocale);
1630 /*Insert the app icon info */
1631 while(up_icn != NULL)
1633 appicon = __create_icon_list(appicon, up_icn->icon);
1634 up_icn = up_icn->next;
1636 /*remove duplicated data in appicon*/
1637 __trimfunc(appicon);
1639 /*Insert the image info */
1640 while(up_image != NULL)
1642 appimage = __create_image_list(appimage, up_image->image);
1643 up_image = up_image->next;
1645 /*remove duplicated data in appimage*/
1646 __trimfunc(appimage);
1648 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1650 /*native app locale info*/
1651 up = mfx->uiapplication;
1654 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1657 /*agent app locale info*/
1658 sp = mfx->serviceapplication;
1661 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1665 /*app icon locale info*/
1666 up_icn = mfx->uiapplication;
1667 while(up_icn != NULL)
1669 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1670 up_icn = up_icn->next;
1674 up_image = mfx->uiapplication;
1675 while(up_image != NULL)
1677 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1678 up_image = up_image->next;
1681 g_list_free(pkglocale);
1683 g_list_free(applocale);
1685 g_list_free(appicon);
1687 g_list_free(appimage);
1690 /*Insert in the package_app_info DB*/
1691 ret = __insert_uiapplication_info(mfx);
1694 ret = __insert_serviceapplication_info(mfx);
1697 /*Insert in the package_app_app_control DB*/
1698 ret = __insert_uiapplication_appcontrol_info(mfx);
1701 ret = __insert_serviceapplication_appcontrol_info(mfx);
1705 /*Insert in the package_app_app_category DB*/
1706 ret = __insert_uiapplication_appcategory_info(mfx);
1709 ret = __insert_serviceapplication_appcategory_info(mfx);
1713 /*Insert in the package_app_app_metadata DB*/
1714 ret = __insert_uiapplication_appmetadata_info(mfx);
1717 ret = __insert_serviceapplication_appmetadata_info(mfx);
1721 /*Insert in the package_app_app_permission DB*/
1722 ret = __insert_uiapplication_apppermission_info(mfx);
1725 ret = __insert_serviceapplication_apppermission_info(mfx);
1729 /*Insert in the package_app_app_svc DB*/
1730 ret = __insert_uiapplication_appsvc_info(mfx);
1733 ret = __insert_serviceapplication_appsvc_info(mfx);
1737 /*Insert in the package_app_share_allowed DB*/
1738 ret = __insert_uiapplication_share_allowed_info(mfx);
1741 ret = __insert_serviceapplication_share_allowed_info(mfx);
1745 /*Insert in the package_app_share_request DB*/
1746 ret = __insert_uiapplication_share_request_info(mfx);
1749 ret = __insert_serviceapplication_share_request_info(mfx);
1753 /*Insert in the package_app_data_control DB*/
1754 ret = __insert_uiapplication_datacontrol_info(mfx);
1757 ret = __insert_serviceapplication_datacontrol_info(mfx);
1765 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1767 char query[MAX_QUERY_LEN] = { '\0' };
1769 memset(query, '\0', MAX_QUERY_LEN);
1770 snprintf(query, MAX_QUERY_LEN,
1771 "delete from %s where app_id='%s'", db_table, appid);
1772 ret = __exec_query(query);
1774 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1780 static int __delete_subpkg_info_from_db(char *appid)
1784 ret = __delete_appinfo_from_db("package_app_info", appid);
1787 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1790 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1793 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1796 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1799 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1802 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1805 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1808 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1811 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1814 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1817 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1824 static int __delete_subpkg_from_db(manifest_x *mfx)
1826 char query[MAX_QUERY_LEN] = { '\0' };
1827 char *error_message = NULL;
1829 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1831 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1832 _LOGE("Don't execute query = %s error message = %s\n", query,
1834 sqlite3_free(error_message);
1837 sqlite3_free(error_message);
1842 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1844 char query[MAX_QUERY_LEN] = { '\0' };
1846 uiapplication_x *up = mfx->uiapplication;
1847 serviceapplication_x *sp = mfx->serviceapplication;
1848 /*Delete from cert table*/
1849 if (uid != GLOBAL_USER)
1850 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1852 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1854 _LOGD("Cert Info DB Delete Failed\n");
1858 /*Delete from Package Info DB*/
1859 snprintf(query, MAX_QUERY_LEN,
1860 "delete from package_info where package='%s'", mfx->package);
1861 ret = __exec_query(query);
1863 _LOGD("Package Info DB Delete Failed\n");
1866 memset(query, '\0', MAX_QUERY_LEN);
1868 /*Delete from Package Localized Info*/
1869 snprintf(query, MAX_QUERY_LEN,
1870 "delete from package_localized_info where package='%s'", mfx->package);
1871 ret = __exec_query(query);
1873 _LOGD("Package Localized Info DB Delete Failed\n");
1877 /*Delete from Package Privilege Info*/
1878 snprintf(query, MAX_QUERY_LEN,
1879 "delete from package_privilege_info where package='%s'", mfx->package);
1880 ret = __exec_query(query);
1882 _LOGD("Package Privilege Info DB Delete Failed\n");
1886 while (up != NULL) {
1887 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1890 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1893 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
1896 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
1899 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
1902 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
1905 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
1908 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
1911 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
1914 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
1917 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
1920 ret = __delete_appinfo_from_db("package_app_data_control", up->appid);
1926 while (sp != NULL) {
1927 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
1930 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
1933 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
1936 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
1939 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
1942 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
1945 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
1948 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
1951 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
1954 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
1957 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
1960 ret = __delete_appinfo_from_db("package_app_data_control", sp->appid);
1966 /* if main package has sub pkg, delete sub pkg data*/
1967 __delete_subpkg_from_db(mfx);
1972 static int __update_preload_condition_in_db()
1975 char query[MAX_QUERY_LEN] = {'\0'};
1977 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
1979 ret = __exec_query(query);
1981 _LOGD("Package preload_condition update failed\n");
1986 API int pkgmgr_parser_initialize_db(uid_t uid)
1990 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
1992 _LOGD("package info DB initialization failed\n");
1995 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
1997 _LOGD("package localized info DB initialization failed\n");
2000 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2002 _LOGD("package app app privilege DB initialization failed\n");
2005 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2007 _LOGD("package app info DB initialization failed\n");
2010 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2012 _LOGD("package app localized info DB initialization failed\n");
2015 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2017 _LOGD("package app icon localized info DB initialization failed\n");
2020 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2022 _LOGD("package app image info DB initialization failed\n");
2025 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2027 _LOGD("package app app control DB initialization failed\n");
2030 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2032 _LOGD("package app app category DB initialization failed\n");
2035 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2037 _LOGD("package app app category DB initialization failed\n");
2040 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2042 _LOGD("package app app permission DB initialization failed\n");
2045 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2047 _LOGD("package app app svc DB initialization failed\n");
2050 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2052 _LOGD("package app share allowed DB initialization failed\n");
2055 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2057 _LOGD("package app share request DB initialization failed\n");
2060 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2062 _LOGD("package app data control DB initialization failed\n");
2066 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2068 _LOGD("package cert info DB initialization failed\n");
2071 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2073 _LOGD("package cert index info DB initialization failed\n");
2077 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
2078 _LOGD("Failed to change cert db permission\n");
2080 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2081 _LOGD("Failed to change parser db permission\n");
2087 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2090 char journal_file[BUFSIZE];
2093 struct passwd *userinfo = NULL;
2094 files[0] = (char *)db_file;
2095 files[1] = journal_file;
2098 if (db_file == NULL)
2101 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2103 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2104 if (uid == OWNER_ROOT)
2106 userinfo = getpwuid(uid);
2108 _LOGE("FAIL: user %d doesn't exist", uid);
2111 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2113 for (i = 0; files[i]; i++) {
2114 ret = chown(files[i], uid, userinfo->pw_gid);
2116 if (strerror_r(errno, buf, sizeof(buf)))
2118 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2119 userinfo->pw_gid, buf);
2123 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
2125 if (strerror_r(errno, buf, sizeof(buf)))
2127 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2130 SET_SMACK_LABEL(files[i]);
2135 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2139 if (getuid() != OWNER_ROOT) {
2140 _LOGE("Only root user is allowed");
2144 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2145 _LOGE("Manifest db for user %d is already exists", uid);
2149 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2150 _LOGE("Cert db for user %d is already exists", uid);
2154 ret = pkgmgr_parser_check_and_create_db(uid);
2157 ret = pkgmgr_parser_initialize_db(uid);
2159 pkgmgr_parser_close_db();
2162 pkgmgr_parser_close_db();
2167 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2171 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2173 _LOGD("Manifest DB creation Failed\n");
2178 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid));
2180 _LOGD("Cert DB creation Failed\n");
2186 void pkgmgr_parser_close_db(void)
2188 sqlite3_close(pkgmgr_parser_db);
2189 sqlite3_close(pkgmgr_cert_db);
2193 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2195 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2197 _LOGD("manifest pointer is NULL\n");
2201 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2203 _LOGD("Failed to open DB\n");
2206 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2209 /*Begin transaction*/
2210 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2211 if (ret != SQLITE_OK) {
2212 _LOGD("Failed to begin transaction\n");
2216 _LOGD("Transaction Begin\n");
2217 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2219 _LOGD("Insert into DB failed. Rollback now\n");
2220 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2223 /*Commit transaction*/
2224 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2225 if (ret != SQLITE_OK) {
2226 _LOGD("Failed to commit transaction. Rollback now\n");
2227 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2231 _LOGD("Transaction Commit and End\n");
2233 pkgmgr_parser_close_db();
2237 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2239 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2241 _LOGD("manifest pointer is NULL\n");
2245 ret = pkgmgr_parser_check_and_create_db(uid);
2247 _LOGD("Failed to open DB\n");
2250 ret = pkgmgr_parser_initialize_db(uid);
2253 /*Begin transaction*/
2254 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2255 if (ret != SQLITE_OK) {
2256 _LOGD("Failed to begin transaction\n");
2260 _LOGD("Transaction Begin\n");
2261 ret = __insert_manifest_info_in_db(mfx, uid);
2263 _LOGD("Insert into DB failed. Rollback now\n");
2264 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2267 /*Commit transaction*/
2268 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2269 if (ret != SQLITE_OK) {
2270 _LOGD("Failed to commit transaction. Rollback now\n");
2271 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2275 _LOGD("Transaction Commit and End\n");
2277 pkgmgr_parser_close_db();
2281 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2284 _LOGD("manifest pointer is NULL\n");
2288 ret = pkgmgr_parser_check_and_create_db(uid);
2290 _LOGD("Failed to open DB\n");
2293 ret = pkgmgr_parser_initialize_db(uid);
2296 /*Preserve guest mode visibility*/
2297 __preserve_guestmode_visibility_value( mfx);
2298 /*Begin transaction*/
2299 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2300 if (ret != SQLITE_OK) {
2301 _LOGD("Failed to begin transaction\n");
2305 _LOGD("Transaction Begin\n");
2306 ret = __delete_manifest_info_from_db(mfx, uid);
2308 _LOGD("Delete from DB failed. Rollback now\n");
2309 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2312 ret = __insert_manifest_info_in_db(mfx, uid);
2314 _LOGD("Insert into DB failed. Rollback now\n");
2315 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2319 /*Commit transaction*/
2320 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2321 if (ret != SQLITE_OK) {
2322 _LOGD("Failed to commit transaction. Rollback now\n");
2323 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2327 _LOGD("Transaction Commit and End\n");
2329 pkgmgr_parser_close_db();
2333 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2335 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2338 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2341 _LOGD("manifest pointer is NULL\n");
2345 ret = pkgmgr_parser_check_and_create_db(uid);
2347 _LOGD("Failed to open DB\n");
2350 /*Begin transaction*/
2351 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2352 if (ret != SQLITE_OK) {
2353 _LOGD("Failed to begin transaction\n");
2357 _LOGD("Transaction Begin\n");
2358 ret = __delete_manifest_info_from_db(mfx, uid);
2360 _LOGD("Delete from DB failed. Rollback now\n");
2361 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2364 /*Commit transaction*/
2365 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2366 if (ret != SQLITE_OK) {
2367 _LOGD("Failed to commit transaction, Rollback now\n");
2368 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2372 _LOGD("Transaction Commit and End\n");
2374 pkgmgr_parser_close_db();
2378 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2380 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2383 API int pkgmgr_parser_update_preload_info_in_db()
2386 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2388 _LOGD("Failed to open DB\n");
2391 /*Begin transaction*/
2392 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2393 if (ret != SQLITE_OK) {
2394 _LOGD("Failed to begin transaction\n");
2398 _LOGD("Transaction Begin\n");
2399 ret = __update_preload_condition_in_db();
2401 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2402 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2405 /*Commit transaction*/
2406 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2407 if (ret != SQLITE_OK) {
2408 _LOGD("Failed to commit transaction, Rollback now\n");
2409 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2413 _LOGD("Transaction Commit and End\n");
2415 pkgmgr_parser_close_db();
2419 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2422 ret = pkgmgr_parser_check_and_create_db(uid);
2424 _LOGD("Failed to open DB\n");
2427 /*Begin transaction*/
2428 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2429 if (ret != SQLITE_OK) {
2430 _LOGD("Failed to begin transaction\n");
2434 _LOGD("Transaction Begin\n");
2435 ret = __update_preload_condition_in_db();
2437 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2438 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2441 /*Commit transaction*/
2442 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2443 if (ret != SQLITE_OK) {
2444 _LOGD("Failed to commit transaction, Rollback now\n");
2445 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2449 _LOGD("Transaction Commit and End\n");
2451 pkgmgr_parser_close_db();