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_parser_internal.h"
40 #include "pkgmgr_parser_db.h"
42 #include "pkgmgr-info-debug.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,uid) \
56 if(smack_setlabel((x), (((uid) == GLOBAL_USER)?"*":"User"), SMACK_LABEL_ACCESS)) _LOGE("failed chsmack -a \"User/*\" %s", x); \
57 else _LOGD("chsmack -a \"User/*\" %s", x);
59 sqlite3 *pkgmgr_parser_db;
60 sqlite3 *pkgmgr_cert_db;
63 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
64 "(package text primary key not null, " \
65 "package_type text DEFAULT 'rpm', " \
66 "package_version text, " \
67 "install_location text, " \
68 "package_size text, " \
69 "package_removable text DEFAULT 'true', " \
70 "package_preload text DEFAULT 'false', " \
71 "package_readonly text DEFAULT 'false', " \
72 "package_update text DEFAULT 'false', " \
73 "package_appsetting text DEFAULT 'false', " \
74 "package_nodisplay text DEFAULT 'false', " \
75 "package_system text DEFAULT 'false', " \
76 "author_name text, " \
77 "author_email text, " \
79 "installed_time text," \
80 "installed_storage text," \
81 "storeclient_id text," \
87 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
88 "(package text not null, " \
89 "package_locale text DEFAULT 'No Locale', " \
90 "package_label text, " \
91 "package_icon text, " \
92 "package_description text, " \
93 "package_license text, " \
95 "PRIMARY KEY(package, package_locale), " \
96 "FOREIGN KEY(package) " \
97 "REFERENCES package_info(package) " \
100 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
101 "(package text not null, " \
102 "privilege text not null, " \
103 "PRIMARY KEY(package, privilege) " \
104 "FOREIGN KEY(package) " \
105 "REFERENCES package_info(package) " \
108 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
109 "(app_id text primary key not null, " \
110 "app_component text, " \
112 "app_nodisplay text DEFAULT 'false', " \
114 "app_onboot text DEFAULT 'false', " \
115 "app_multiple text DEFAULT 'false', " \
116 "app_autorestart text DEFAULT 'false', " \
117 "app_taskmanage text DEFAULT 'false', " \
118 "app_enabled text DEFAULT 'true', " \
119 "app_hwacceleration text DEFAULT 'use-system-setting', " \
120 "app_screenreader text DEFAULT 'use-system-setting', " \
121 "app_mainapp text, " \
122 "app_recentimage text, " \
123 "app_launchcondition text, " \
124 "app_indicatordisplay text DEFAULT 'true', " \
125 "app_portraitimg text, " \
126 "app_landscapeimg text, " \
127 "app_guestmodevisibility text DEFAULT 'true', " \
128 "app_permissiontype text DEFAULT 'normal', " \
129 "app_preload text DEFAULT 'false', " \
130 "app_submode text DEFAULT 'false', " \
131 "app_submode_mainid text, " \
132 "component_type text, " \
133 "package text not null, " \
134 "FOREIGN KEY(package) " \
135 "REFERENCES package_info(package) " \
138 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
139 "(app_id text not null, " \
140 "app_locale text DEFAULT 'No Locale', " \
143 "PRIMARY KEY(app_id,app_locale) " \
144 "FOREIGN KEY(app_id) " \
145 "REFERENCES package_app_info(app_id) " \
148 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
149 "(app_id text not null, " \
151 "app_icon_section text, " \
152 "app_icon_resolution text, " \
153 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
154 "FOREIGN KEY(app_id) " \
155 "REFERENCES package_app_info(app_id) " \
158 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
159 "(app_id text not null, " \
160 "app_locale text DEFAULT 'No Locale', " \
161 "app_image_section text, " \
163 "PRIMARY KEY(app_id,app_image_section) " \
164 "FOREIGN KEY(app_id) " \
165 "REFERENCES package_app_info(app_id) " \
168 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
169 "(app_id text not null, " \
170 "operation text not null, " \
171 "uri_scheme text, " \
173 "subapp_name text, " \
174 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
175 "FOREIGN KEY(app_id) " \
176 "REFERENCES package_app_info(app_id) " \
179 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
180 "(app_id text not null, " \
181 "operation text not null, " \
182 "uri_scheme text, " \
184 "subapp_name text, " \
185 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
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 "provider_id text not null, " \
255 "access text not null, " \
256 "type text not null, " \
257 "PRIMARY KEY(app_id, provider_id, access, type) " \
258 "FOREIGN KEY(app_id) " \
259 "REFERENCES package_app_info(app_id) " \
262 static int __insert_uiapplication_info(manifest_x *mfx);
263 static int __insert_serviceapplication_info(manifest_x *mfx);
264 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
265 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
266 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
267 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
268 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
269 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
270 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
271 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
272 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
273 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
274 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
275 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
276 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx);
277 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
278 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
279 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
280 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
281 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
282 static int __delete_subpkg_info_from_db(char *appid);
283 static int __delete_appinfo_from_db(char *db_table, const char *appid);
284 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
285 static int __exec_query(char *query);
286 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
287 char **label, char **license, char **icon, char **description, char **author);
288 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
289 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
290 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
291 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
292 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
294 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
297 __delete_subpkg_info_from_db(coltxt[0]);
302 static char *__get_str(const char *str)
306 return PKGMGR_PARSER_EMPTY_STR;
312 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
317 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
318 if (ret != SQLITE_OK) {
319 _LOGD("connect db [%s] failed!\n", db_path);
327 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
329 manifest_x *mfx = (manifest_x *)data;
333 uiapplication_x *uiapp = NULL;
334 for(i = 0; i < ncols; i++)
336 uiapp = mfx->uiapplication;
337 if (strcmp(colname[i], "app_id") == 0) {
339 appid = strdup(coltxt[i]);
340 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
342 status = strdup(coltxt[i]);
346 _LOGD("app id is NULL\n");
349 /*update guest mode visibility*/
350 for (; uiapp != NULL; uiapp = uiapp->next) {
351 if (strcmp(uiapp->appid, appid) == 0) {
352 free((void *)uiapp->guestmode_visibility);
353 uiapp->guestmode_visibility = strdup(status);
369 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
371 char *error_message = NULL;
372 char query[MAX_QUERY_LEN] = {'\0'};
373 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
375 sqlite3_exec(pkgmgr_parser_db, query,
376 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
377 _LOGD("Don't execute query = %s error message = %s\n",
378 query, error_message);
379 sqlite3_free(error_message);
384 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
386 char *error_message = NULL;
388 sqlite3_exec(db_handle, db_query,
389 NULL, NULL, &error_message)) {
390 _LOGD("Don't execute query = %s error message = %s\n",
391 db_query, error_message);
392 sqlite3_free(error_message);
395 sqlite3_free(error_message);
399 static int __exec_query(char *query)
401 char *error_message = NULL;
403 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
404 _LOGD("Don't execute query = %s error message = %s\n", query,
406 sqlite3_free(error_message);
409 sqlite3_free(error_message);
413 static int __exec_query_no_msg(char *query)
415 char *error_message = NULL;
417 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
418 sqlite3_free(error_message);
421 sqlite3_free(error_message);
425 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
431 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
437 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
443 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
449 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
455 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
462 static GList *__create_icon_list(GList *locale, icon_x *icn)
467 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
473 static GList *__create_image_list(GList *locale, image_x *image)
478 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
484 static void __printfunc(gpointer data, gpointer userdata)
486 _LOGD("%s ", (char*)data);
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) " \
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')",\
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),
862 ret = __exec_query(query);
864 _LOGD("Package UiApp Info DB Insert Failed\n");
868 memset(query, '\0', MAX_QUERY_LEN);
873 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
875 uiapplication_x *up = mfx->uiapplication;
876 category_x *ct = NULL;
878 char query[MAX_QUERY_LEN] = {'\0'};
884 snprintf(query, MAX_QUERY_LEN,
885 "insert into package_app_app_category(app_id, category) " \
886 "values('%s','%s')",\
887 up->appid, ct->name);
888 ret = __exec_query(query);
890 _LOGD("Package UiApp Category Info DB Insert Failed\n");
894 memset(query, '\0', MAX_QUERY_LEN);
901 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
903 uiapplication_x *up = mfx->uiapplication;
904 metadata_x *md = NULL;
906 char query[MAX_QUERY_LEN] = {'\0'};
913 snprintf(query, MAX_QUERY_LEN,
914 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
915 "values('%s','%s', '%s')",\
916 up->appid, md->key, md->value);
917 ret = __exec_query(query);
919 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
924 memset(query, '\0', MAX_QUERY_LEN);
931 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
933 uiapplication_x *up = mfx->uiapplication;
934 permission_x *pm = NULL;
936 char query[MAX_QUERY_LEN] = {'\0'};
942 snprintf(query, MAX_QUERY_LEN,
943 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
944 "values('%s','%s', '%s')",\
945 up->appid, pm->type, pm->value);
946 ret = __exec_query(query);
948 _LOGD("Package UiApp permission Info DB Insert Failed\n");
952 memset(query, '\0', MAX_QUERY_LEN);
959 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
961 uiapplication_x *up = mfx->uiapplication;
962 appcontrol_x *acontrol = NULL;
963 operation_x *op = NULL;
966 subapp_x *sub = NULL;
968 char query[MAX_QUERY_LEN] = {'\0'};
969 const char *operation = NULL;
970 const char *mime = NULL;
971 const char *uri = NULL;
972 const char *subapp = NULL;
975 acontrol = up->appcontrol;
976 while(acontrol != NULL)
978 op = acontrol->operation;
982 operation = op->name;
989 sub = acontrol->subapp;
999 snprintf(query, MAX_QUERY_LEN,
1000 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1001 "values('%s', '%s', '%s', '%s', '%s')",\
1002 up->appid, operation, uri, mime, subapp);
1004 ret = __exec_query(query);
1006 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1009 memset(query, '\0', MAX_QUERY_LEN);
1013 } while(ui != NULL);
1017 }while(sub != NULL);
1026 acontrol = acontrol->next;
1033 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1035 uiapplication_x *up = mfx->uiapplication;
1036 appsvc_x *asvc = NULL;
1037 operation_x *op = NULL;
1040 subapp_x *sub = NULL;
1042 char query[MAX_QUERY_LEN] = {'\0'};
1043 const char *operation = NULL;
1044 const char *mime = NULL;
1045 const char *uri = NULL;
1046 const char *subapp = NULL;
1052 op = asvc->operation;
1056 operation = op->name;
1073 snprintf(query, MAX_QUERY_LEN,
1074 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1075 "values('%s', '%s', '%s', '%s', '%s')",\
1082 ret = __exec_query(query);
1084 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1087 memset(query, '\0', MAX_QUERY_LEN);
1091 } while(ui != NULL);
1095 }while(sub != NULL);
1111 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1113 uiapplication_x *up = mfx->uiapplication;
1114 datashare_x *ds = NULL;
1115 request_x *rq = NULL;
1117 char query[MAX_QUERY_LEN] = {'\0'};
1126 snprintf(query, MAX_QUERY_LEN,
1127 "insert into package_app_share_request(app_id, data_share_request) " \
1128 "values('%s', '%s')",\
1129 up->appid, rq->text);
1130 ret = __exec_query(query);
1132 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1135 memset(query, '\0', MAX_QUERY_LEN);
1145 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1147 uiapplication_x *up = mfx->uiapplication;
1148 datashare_x *ds = NULL;
1149 define_x *df = NULL;
1150 allowed_x *al = NULL;
1152 char query[MAX_QUERY_LEN] = {'\0'};
1164 snprintf(query, MAX_QUERY_LEN,
1165 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1166 "values('%s', '%s', '%s')",\
1167 up->appid, df->path, al->text);
1168 ret = __exec_query(query);
1170 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1173 memset(query, '\0', MAX_QUERY_LEN);
1185 static int __insert_serviceapplication_info(manifest_x *mfx)
1187 serviceapplication_x *sp = mfx->serviceapplication;
1189 char query[MAX_QUERY_LEN] = {'\0'};
1192 snprintf(query, MAX_QUERY_LEN,
1193 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1194 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1195 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1196 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1197 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1198 ret = __exec_query(query);
1200 _LOGD("Package ServiceApp Info DB Insert Failed\n");
1204 memset(query, '\0', MAX_QUERY_LEN);
1209 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1211 serviceapplication_x *sp = mfx->serviceapplication;
1212 category_x *ct = NULL;
1214 char query[MAX_QUERY_LEN] = {'\0'};
1220 snprintf(query, MAX_QUERY_LEN,
1221 "insert into package_app_app_category(app_id, category) " \
1222 "values('%s','%s')",\
1223 sp->appid, ct->name);
1224 ret = __exec_query(query);
1226 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1230 memset(query, '\0', MAX_QUERY_LEN);
1237 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1239 serviceapplication_x *sp = mfx->serviceapplication;
1240 metadata_x *md = NULL;
1242 char query[MAX_QUERY_LEN] = {'\0'};
1249 snprintf(query, MAX_QUERY_LEN,
1250 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1251 "values('%s','%s', '%s')",\
1252 sp->appid, md->key, md->value);
1253 ret = __exec_query(query);
1255 _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1260 memset(query, '\0', MAX_QUERY_LEN);
1267 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1269 serviceapplication_x *sp = mfx->serviceapplication;
1270 permission_x *pm = NULL;
1272 char query[MAX_QUERY_LEN] = {'\0'};
1275 pm = sp->permission;
1278 snprintf(query, MAX_QUERY_LEN,
1279 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1280 "values('%s','%s', '%s')",\
1281 sp->appid, pm->type, pm->value);
1282 ret = __exec_query(query);
1284 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1288 memset(query, '\0', MAX_QUERY_LEN);
1295 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1297 serviceapplication_x *sp = mfx->serviceapplication;
1298 appcontrol_x *acontrol = NULL;
1300 char query[MAX_QUERY_LEN] = {'\0'};
1301 operation_x *op = NULL;
1304 subapp_x *sub = NULL;
1305 const char *operation = NULL;
1306 const char *mime = NULL;
1307 const char *uri = NULL;
1308 const char *subapp = NULL;
1311 acontrol = sp->appcontrol;
1312 while(acontrol != NULL)
1314 op = acontrol->operation;
1318 operation = op->name;
1319 mi = acontrol->mime;
1324 sub = acontrol->subapp;
1334 snprintf(query, MAX_QUERY_LEN,
1335 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type,subapp_name) " \
1336 "values('%s', '%s', '%s', '%s', '%s')",\
1337 sp->appid, operation, uri, mime, subapp);
1338 ret = __exec_query(query);
1340 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1343 memset(query, '\0', MAX_QUERY_LEN);
1347 } while(ui != NULL);
1351 }while(sub != NULL);
1360 acontrol = acontrol->next;
1367 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1369 serviceapplication_x *sp = mfx->serviceapplication;
1370 appsvc_x *asvc = NULL;
1372 char query[MAX_QUERY_LEN] = {'\0'};
1373 operation_x *op = NULL;
1376 subapp_x *sub = NULL;
1377 const char *operation = NULL;
1378 const char *mime = NULL;
1379 const char *uri = NULL;
1380 const char *subapp = NULL;
1386 op = asvc->operation;
1390 operation = op->name;
1406 snprintf(query, MAX_QUERY_LEN,
1407 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1408 "values('%s', '%s', '%s', '%s', '%s')",\
1414 ret = __exec_query(query);
1416 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1419 memset(query, '\0', MAX_QUERY_LEN);
1423 } while(ui != NULL);
1427 }while(sub != NULL);
1443 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx)
1445 serviceapplication_x *sp = mfx->serviceapplication;
1446 datacontrol_x *dc = NULL;
1448 char query[MAX_QUERY_LEN] = {'\0'};
1452 dc = sp->datacontrol;
1455 snprintf(query, MAX_QUERY_LEN,
1456 "insert into package_app_data_control(app_id, provider_id, access, type) " \
1457 "values('%s', '%s', '%s', '%s')",\
1458 mfx->serviceapplication->appid,
1463 ret = __exec_query(query);
1465 _LOGD("Package ServiceApp Data Control DB Insert Failed\n");
1468 memset(query, '\0', MAX_QUERY_LEN);
1476 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1478 serviceapplication_x *sp = mfx->serviceapplication;
1479 datashare_x *ds = NULL;
1480 request_x *rq = NULL;
1482 char query[MAX_QUERY_LEN] = {'\0'};
1491 snprintf(query, MAX_QUERY_LEN,
1492 "insert into package_app_share_request(app_id, data_share_request) " \
1493 "values('%s', '%s')",\
1494 sp->appid, rq->text);
1495 ret = __exec_query(query);
1497 _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1500 memset(query, '\0', MAX_QUERY_LEN);
1512 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1514 serviceapplication_x *sp = mfx->serviceapplication;
1515 datashare_x *ds = NULL;
1516 define_x *df = NULL;
1517 allowed_x *al = NULL;
1519 char query[MAX_QUERY_LEN] = {'\0'};
1531 snprintf(query, MAX_QUERY_LEN,
1532 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1533 "values('%s', '%s', '%s')",\
1534 sp->appid, df->path, al->text);
1535 ret = __exec_query(query);
1537 _LOGD("Package App Share Allowed DB Insert Failed\n");
1540 memset(query, '\0', MAX_QUERY_LEN);
1552 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1554 label_x *lbl = mfx->label;
1555 license_x *lcn = mfx->license;
1556 icon_x *icn = mfx->icon;
1557 description_x *dcn = mfx->description;
1558 author_x *ath = mfx->author;
1559 uiapplication_x *up = mfx->uiapplication;
1560 uiapplication_x *up_icn = mfx->uiapplication;
1561 uiapplication_x *up_image = mfx->uiapplication;
1562 serviceapplication_x *sp = mfx->serviceapplication;
1563 privileges_x *pvs = NULL;
1564 privilege_x *pv = NULL;
1565 char query[MAX_QUERY_LEN] = { '\0' };
1566 char root[MAX_QUERY_LEN] = { '\0' };
1570 const char *auth_name = NULL;
1571 const char *auth_email = NULL;
1572 const char *auth_href = NULL;
1573 const char *apps_path = NULL;
1575 GList *pkglocale = NULL;
1576 GList *applocale = NULL;
1577 GList *appicon = NULL;
1578 GList *appimage = NULL;
1582 auth_name = ath->text;
1584 auth_email = ath->email;
1586 auth_href = ath->href;
1588 /*Insert in the package_cert_info CERT_DB*/
1589 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1590 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1591 if (ret != PMINFO_R_OK) {
1592 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1593 _LOGE("Cert Info DB create handle failed\n");
1596 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1597 if (ret != PMINFO_R_OK) {
1598 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1599 _LOGE("Cert Info DB Insert Failed\n");
1603 /*Insert in the package_info DB*/
1605 type = strdup(mfx->type);
1607 type = strdup("rpm");
1608 /*Insert in the package_info DB*/
1610 path = strdup(mfx->root_path);
1612 if (strcmp(type,"rpm")==0) {
1613 apps_path = tzplatform_getenv(TZ_SYS_RO_APP);
1614 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1616 apps_path = tzplatform_getenv(TZ_USER_APP);
1617 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1619 path = strdup(root);
1621 snprintf(query, MAX_QUERY_LEN,
1622 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1623 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1624 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
1625 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1629 __get_str(mfx->installlocation),
1630 __get_str(mfx->package_size),
1636 mfx->nodisplay_setting,
1638 __get_str(auth_name),
1639 __get_str(auth_email),
1640 __get_str(auth_href),
1641 mfx->installed_time,
1642 mfx->installed_storage,
1643 __get_str(mfx->storeclient_id),
1645 __get_str(mfx->package_url),
1647 __get_str(mfx->csc_path));
1648 /*If package dont have main_package tag, this package is main package.*/
1649 if (mfx->main_package == NULL) {
1650 ret = __exec_query(query);
1652 _LOGD("Package Info DB Insert Failed\n");
1664 /*If package has main_package tag, this package is sub package(ug, efl).
1665 skip __exec_query for package_info and change pkgid with main_package*/
1666 memset(root, '\0', MAX_QUERY_LEN);
1667 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->main_package);
1668 if (access(root, F_OK) == 0) {
1669 free((void *)mfx->package);
1670 mfx->package = strdup(mfx->main_package);
1672 _LOGE("main package[%s] is not installed\n", root);
1685 /*Insert in the package_privilege_info DB*/
1686 pvs = mfx->privileges;
1687 while (pvs != NULL) {
1688 pv = pvs->privilege;
1689 while (pv != NULL) {
1690 memset(query, '\0', MAX_QUERY_LEN);
1691 snprintf(query, MAX_QUERY_LEN,
1692 "insert into package_privilege_info(package, privilege) " \
1693 "values('%s','%s')",\
1694 mfx->package, pv->text);
1695 ret = __exec_query(query);
1697 _LOGD("Package Privilege Info DB Insert Failed\n");
1706 ret = __insert_ui_mainapp_info(mfx);
1711 /*Insert the package locale*/
1712 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1713 /*remove duplicated data in pkglocale*/
1714 __trimfunc(pkglocale);
1716 /*Insert the app locale info */
1719 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1724 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1727 /*remove duplicated data in applocale*/
1728 __trimfunc(applocale);
1730 /*Insert the app icon info */
1731 while(up_icn != NULL)
1733 appicon = __create_icon_list(appicon, up_icn->icon);
1734 up_icn = up_icn->next;
1736 /*remove duplicated data in appicon*/
1737 __trimfunc(appicon);
1739 /*Insert the image info */
1740 while(up_image != NULL)
1742 appimage = __create_image_list(appimage, up_image->image);
1743 up_image = up_image->next;
1745 /*remove duplicated data in appimage*/
1746 __trimfunc(appimage);
1748 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1750 /*g_list_foreach(applocale, __printfunc, NULL);*/
1752 /*package locale info, it is only for main package.*/
1753 if (mfx->main_package == NULL)
1754 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1756 /*native app locale info*/
1757 up = mfx->uiapplication;
1760 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1763 /*agent app locale info*/
1764 sp = mfx->serviceapplication;
1767 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1771 /*app icon locale info*/
1772 up_icn = mfx->uiapplication;
1773 while(up_icn != NULL)
1775 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1776 up_icn = up_icn->next;
1780 up_image = mfx->uiapplication;
1781 while(up_image != NULL)
1783 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1784 up_image = up_image->next;
1787 g_list_free(pkglocale);
1789 g_list_free(applocale);
1791 g_list_free(appicon);
1793 g_list_free(appimage);
1796 /*Insert in the package_app_info DB*/
1797 ret = __insert_uiapplication_info(mfx);
1800 ret = __insert_serviceapplication_info(mfx);
1803 /*Insert in the package_app_app_control DB*/
1804 ret = __insert_uiapplication_appcontrol_info(mfx);
1807 ret = __insert_serviceapplication_appcontrol_info(mfx);
1811 /*Insert in the package_app_app_category DB*/
1812 ret = __insert_uiapplication_appcategory_info(mfx);
1815 ret = __insert_serviceapplication_appcategory_info(mfx);
1819 /*Insert in the package_app_app_metadata DB*/
1820 ret = __insert_uiapplication_appmetadata_info(mfx);
1823 ret = __insert_serviceapplication_appmetadata_info(mfx);
1827 /*Insert in the package_app_app_permission DB*/
1828 ret = __insert_uiapplication_apppermission_info(mfx);
1831 ret = __insert_serviceapplication_apppermission_info(mfx);
1835 /*Insert in the package_app_app_svc DB*/
1836 ret = __insert_uiapplication_appsvc_info(mfx);
1839 ret = __insert_serviceapplication_appsvc_info(mfx);
1843 /*Insert in the package_app_share_allowed DB*/
1844 ret = __insert_uiapplication_share_allowed_info(mfx);
1847 ret = __insert_serviceapplication_share_allowed_info(mfx);
1851 /*Insert in the package_app_share_request DB*/
1852 ret = __insert_uiapplication_share_request_info(mfx);
1855 ret = __insert_serviceapplication_share_request_info(mfx);
1859 /*Insert in the package_app_data_control DB*/
1860 ret = __insert_serviceapplication_datacontrol_info(mfx);
1868 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1870 char query[MAX_QUERY_LEN] = { '\0' };
1872 memset(query, '\0', MAX_QUERY_LEN);
1873 snprintf(query, MAX_QUERY_LEN,
1874 "delete from %s where app_id='%s'", db_table, appid);
1875 ret = __exec_query(query);
1877 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1883 static int __delete_subpkg_info_from_db(char *appid)
1887 ret = __delete_appinfo_from_db("package_app_info", appid);
1890 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1893 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1896 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1899 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1902 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1905 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1908 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1911 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1914 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1917 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1920 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1927 static int __delete_subpkg_from_db(manifest_x *mfx)
1929 char query[MAX_QUERY_LEN] = { '\0' };
1931 char *error_message = NULL;
1933 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1935 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1936 _LOGE("Don't execute query = %s error message = %s\n", query,
1938 sqlite3_free(error_message);
1941 sqlite3_free(error_message);
1946 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1948 char query[MAX_QUERY_LEN] = { '\0' };
1950 uiapplication_x *up = mfx->uiapplication;
1951 serviceapplication_x *sp = mfx->serviceapplication;
1952 /*Delete from cert table*/
1953 if (uid != GLOBAL_USER)
1954 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1956 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1958 _LOGD("Cert Info DB Delete Failed\n");
1962 /*Delete from Package Info DB*/
1963 snprintf(query, MAX_QUERY_LEN,
1964 "delete from package_info where package='%s'", mfx->package);
1965 ret = __exec_query(query);
1967 _LOGD("Package Info DB Delete Failed\n");
1970 memset(query, '\0', MAX_QUERY_LEN);
1972 /*Delete from Package Localized Info*/
1973 snprintf(query, MAX_QUERY_LEN,
1974 "delete from package_localized_info where package='%s'", mfx->package);
1975 ret = __exec_query(query);
1977 _LOGD("Package Localized Info DB Delete Failed\n");
1981 /*Delete from Package Privilege Info*/
1982 snprintf(query, MAX_QUERY_LEN,
1983 "delete from package_privilege_info where package='%s'", mfx->package);
1984 ret = __exec_query(query);
1986 _LOGD("Package Privilege Info DB Delete Failed\n");
1990 while (up != NULL) {
1991 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1994 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1997 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
2000 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
2003 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
2006 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
2009 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
2012 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
2015 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
2018 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
2021 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
2024 ret = __delete_appinfo_from_db("package_app_data_control", up->appid);
2030 while (sp != NULL) {
2031 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
2034 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
2037 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
2040 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
2043 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
2046 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
2049 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
2052 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
2055 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
2058 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
2061 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
2064 ret = __delete_appinfo_from_db("package_app_data_control", sp->appid);
2070 /* if main package has sub pkg, delete sub pkg data*/
2071 __delete_subpkg_from_db(mfx);
2076 static int __update_preload_condition_in_db()
2079 char query[MAX_QUERY_LEN] = {'\0'};
2081 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2083 ret = __exec_query(query);
2085 _LOGD("Package preload_condition update failed\n");
2090 int pkgmgr_parser_initialize_db()
2094 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2096 _LOGD("package info DB initialization failed\n");
2099 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2101 _LOGD("package localized info DB initialization failed\n");
2104 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2106 _LOGD("package app app privilege DB initialization failed\n");
2109 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2111 _LOGD("package app info DB initialization failed\n");
2114 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2116 _LOGD("package app localized info DB initialization failed\n");
2119 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2121 _LOGD("package app icon localized info DB initialization failed\n");
2124 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2126 _LOGD("package app image info DB initialization failed\n");
2129 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2131 _LOGD("package app app control DB initialization failed\n");
2134 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2136 _LOGD("package app app category DB initialization failed\n");
2139 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2141 _LOGD("package app app category DB initialization failed\n");
2144 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2146 _LOGD("package app app permission DB initialization failed\n");
2149 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2151 _LOGD("package app app svc DB initialization failed\n");
2154 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2156 _LOGD("package app share allowed DB initialization failed\n");
2159 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2161 _LOGD("package app share request DB initialization failed\n");
2164 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2166 _LOGD("package app data control DB initialization failed\n");
2170 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2172 _LOGD("package cert info DB initialization failed\n");
2175 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2177 _LOGD("package cert index info DB initialization failed\n");
2184 static int parserdb_change_perm(const char *db_file, uid_t uid)
2187 char journal_file[BUFSIZE];
2190 struct passwd *userinfo = NULL;
2191 files[0] = (char *)db_file;
2192 files[1] = journal_file;
2198 if(getuid() != OWNER_ROOT) //At this time we should be root to apply this
2200 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2201 userinfo = getpwuid(uid);
2203 _LOGE("FAIL: user %d doesn't exist", uid);
2206 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2208 for (i = 0; files[i]; i++) {
2209 ret = chown(files[i], uid, userinfo->pw_gid);
2210 SET_SMACK_LABEL(files[i],uid)
2212 strerror_r(errno, buf, sizeof(buf));
2213 _LOGD("FAIL : chown %s %d.%d, because %s", db_file, uid, userinfo->pw_gid, buf);
2217 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
2219 strerror_r(errno, buf, sizeof(buf));
2220 _LOGD("FAIL : chmod %s 0664, because %s", db_file, buf);
2227 int pkgmgr_parser_check_and_create_db(uid_t uid)
2231 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2233 _LOGD("Manifest DB creation Failed\n");
2238 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid));
2240 _LOGD("Cert DB creation Failed\n");
2243 if( 0 != parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
2244 _LOGD("Failed to change cert db permission\n");
2246 if( 0 != parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2247 _LOGD("Failed to change parser db permission\n");
2252 void pkgmgr_parser_close_db()
2254 sqlite3_close(pkgmgr_parser_db);
2255 sqlite3_close(pkgmgr_cert_db);
2259 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2261 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2263 _LOGD("manifest pointer is NULL\n");
2267 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2269 _LOGD("Failed to open DB\n");
2272 ret = pkgmgr_parser_initialize_db();
2275 /*Begin transaction*/
2276 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2277 if (ret != SQLITE_OK) {
2278 _LOGD("Failed to begin transaction\n");
2282 _LOGD("Transaction Begin\n");
2283 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2285 _LOGD("Insert into DB failed. Rollback now\n");
2286 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2289 /*Commit transaction*/
2290 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2291 if (ret != SQLITE_OK) {
2292 _LOGD("Failed to commit transaction. Rollback now\n");
2293 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2297 _LOGD("Transaction Commit and End\n");
2299 pkgmgr_parser_close_db();
2303 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2305 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2307 _LOGD("manifest pointer is NULL\n");
2311 ret = pkgmgr_parser_check_and_create_db(uid);
2313 _LOGD("Failed to open DB\n");
2316 ret = pkgmgr_parser_initialize_db();
2319 /*Begin transaction*/
2320 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2321 if (ret != SQLITE_OK) {
2322 _LOGD("Failed to begin transaction\n");
2326 _LOGD("Transaction Begin\n");
2327 ret = __insert_manifest_info_in_db(mfx, uid);
2329 _LOGD("Insert into DB failed. Rollback now\n");
2330 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2333 /*Commit transaction*/
2334 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2335 if (ret != SQLITE_OK) {
2336 _LOGD("Failed to commit transaction. Rollback now\n");
2337 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2341 _LOGD("Transaction Commit and End\n");
2343 pkgmgr_parser_close_db();
2347 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2350 _LOGD("manifest pointer is NULL\n");
2354 ret = pkgmgr_parser_check_and_create_db(uid);
2356 _LOGD("Failed to open DB\n");
2359 ret = pkgmgr_parser_initialize_db();
2362 /*Preserve guest mode visibility*/
2363 __preserve_guestmode_visibility_value( mfx);
2364 /*Begin transaction*/
2365 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2366 if (ret != SQLITE_OK) {
2367 _LOGD("Failed to begin transaction\n");
2371 _LOGD("Transaction Begin\n");
2372 ret = __delete_manifest_info_from_db(mfx, uid);
2374 _LOGD("Delete from DB failed. Rollback now\n");
2375 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2378 ret = __insert_manifest_info_in_db(mfx, uid);
2380 _LOGD("Insert into DB failed. Rollback now\n");
2381 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2385 /*Commit transaction*/
2386 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2387 if (ret != SQLITE_OK) {
2388 _LOGD("Failed to commit transaction. Rollback now\n");
2389 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2393 _LOGD("Transaction Commit and End\n");
2395 pkgmgr_parser_close_db();
2399 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2401 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2404 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2407 _LOGD("manifest pointer is NULL\n");
2411 ret = pkgmgr_parser_check_and_create_db(uid);
2413 _LOGD("Failed to open DB\n");
2416 /*Begin transaction*/
2417 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2418 if (ret != SQLITE_OK) {
2419 _LOGD("Failed to begin transaction\n");
2423 _LOGD("Transaction Begin\n");
2424 ret = __delete_manifest_info_from_db(mfx, uid);
2426 _LOGD("Delete from DB failed. Rollback now\n");
2427 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2430 /*Commit transaction*/
2431 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2432 if (ret != SQLITE_OK) {
2433 _LOGD("Failed to commit transaction, Rollback now\n");
2434 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2438 _LOGD("Transaction Commit and End\n");
2440 pkgmgr_parser_close_db();
2444 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2446 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2449 API int pkgmgr_parser_update_preload_info_in_db()
2452 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2454 _LOGD("Failed to open DB\n");
2457 /*Begin transaction*/
2458 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2459 if (ret != SQLITE_OK) {
2460 _LOGD("Failed to begin transaction\n");
2464 _LOGD("Transaction Begin\n");
2465 ret = __update_preload_condition_in_db();
2467 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2468 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2471 /*Commit transaction*/
2472 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2473 if (ret != SQLITE_OK) {
2474 _LOGD("Failed to commit transaction, Rollback now\n");
2475 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2479 _LOGD("Transaction Commit and End\n");
2481 pkgmgr_parser_close_db();
2485 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2488 ret = pkgmgr_parser_check_and_create_db(uid);
2490 _LOGD("Failed to open DB\n");
2493 /*Begin transaction*/
2494 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2495 if (ret != SQLITE_OK) {
2496 _LOGD("Failed to begin transaction\n");
2500 _LOGD("Transaction Begin\n");
2501 ret = __update_preload_condition_in_db();
2503 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2504 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2507 /*Commit transaction*/
2508 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2509 if (ret != SQLITE_OK) {
2510 _LOGD("Failed to commit transaction, Rollback now\n");
2511 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2515 _LOGD("Transaction Commit and End\n");
2517 pkgmgr_parser_close_db();