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 "app_control text not null, " \
171 "PRIMARY KEY(app_id,app_control) " \
172 "FOREIGN KEY(app_id) " \
173 "REFERENCES package_app_info(app_id) " \
176 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
177 "(app_id text not null, " \
178 "operation text not null, " \
179 "uri_scheme text, " \
181 "subapp_name text, " \
182 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
183 "FOREIGN KEY(app_id) " \
184 "REFERENCES package_app_info(app_id) " \
187 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
188 "(app_id text not null, " \
189 "category text not null, " \
190 "PRIMARY KEY(app_id,category) " \
191 "FOREIGN KEY(app_id) " \
192 "REFERENCES package_app_info(app_id) " \
195 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
196 "(app_id text not null, " \
197 "md_key text not null, " \
198 "md_value text not null, " \
199 "PRIMARY KEY(app_id, md_key, md_value) " \
200 "FOREIGN KEY(app_id) " \
201 "REFERENCES package_app_info(app_id) " \
204 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
205 "(app_id text not null, " \
206 "pm_type text not null, " \
207 "pm_value text not null, " \
208 "PRIMARY KEY(app_id, pm_type, pm_value) " \
209 "FOREIGN KEY(app_id) " \
210 "REFERENCES package_app_info(app_id) " \
213 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
214 "(app_id text not null, " \
215 "data_share_path text not null, " \
216 "data_share_allowed text not null, " \
217 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
218 "FOREIGN KEY(app_id) " \
219 "REFERENCES package_app_info(app_id) " \
222 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
223 "(app_id text not null, " \
224 "data_share_request text not null, " \
225 "PRIMARY KEY(app_id,data_share_request) " \
226 "FOREIGN KEY(app_id) " \
227 "REFERENCES package_app_info(app_id) " \
230 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
231 "(cert_info text not null, " \
232 "cert_id integer, " \
233 "cert_ref_count integer, " \
234 "PRIMARY KEY(cert_id)) "
236 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
237 "(package text not null, " \
238 "author_root_cert integer, " \
239 "author_im_cert integer, " \
240 "author_signer_cert integer, " \
241 "dist_root_cert integer, " \
242 "dist_im_cert integer, " \
243 "dist_signer_cert integer, " \
244 "dist2_root_cert integer, " \
245 "dist2_im_cert integer, " \
246 "dist2_signer_cert integer, " \
247 "PRIMARY KEY(package)) "
249 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
250 "(app_id text not null, " \
251 "providerid text not null, " \
252 "access text not null, " \
253 "type text not null, " \
254 "PRIMARY KEY(app_id, providerid, access, type) " \
255 "FOREIGN KEY(app_id) " \
256 "REFERENCES package_app_info(app_id) " \
259 static int __insert_uiapplication_info(manifest_x *mfx);
260 static int __insert_serviceapplication_info(manifest_x *mfx);
261 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
262 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
263 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
264 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
265 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
266 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
267 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
268 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
269 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
270 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
271 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
272 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
273 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx);
274 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
275 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
276 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
277 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
278 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
279 static int __delete_subpkg_info_from_db(char *appid);
280 static int __delete_appinfo_from_db(char *db_table, const char *appid);
281 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
282 static int __exec_query(char *query);
283 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
284 char **label, char **license, char **icon, char **description, char **author);
285 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
286 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
287 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
288 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
289 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
291 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
294 __delete_subpkg_info_from_db(coltxt[0]);
299 static char *__get_str(const char *str)
303 return PKGMGR_PARSER_EMPTY_STR;
309 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
314 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
315 if (ret != SQLITE_OK) {
316 _LOGD("connect db [%s] failed!\n", db_path);
324 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
326 manifest_x *mfx = (manifest_x *)data;
330 uiapplication_x *uiapp = NULL;
331 for(i = 0; i < ncols; i++)
333 uiapp = mfx->uiapplication;
334 if (strcmp(colname[i], "app_id") == 0) {
336 appid = strdup(coltxt[i]);
337 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
339 status = strdup(coltxt[i]);
343 _LOGD("app id is NULL\n");
346 /*update guest mode visibility*/
347 for (; uiapp != NULL; uiapp = uiapp->next) {
348 if (strcmp(uiapp->appid, appid) == 0) {
349 free((void *)uiapp->guestmode_visibility);
350 uiapp->guestmode_visibility = strdup(status);
366 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
368 char *error_message = NULL;
369 char query[MAX_QUERY_LEN] = {'\0'};
370 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
372 sqlite3_exec(pkgmgr_parser_db, query,
373 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
374 _LOGD("Don't execute query = %s error message = %s\n",
375 query, error_message);
376 sqlite3_free(error_message);
381 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
383 char *error_message = NULL;
385 sqlite3_exec(db_handle, db_query,
386 NULL, NULL, &error_message)) {
387 _LOGD("Don't execute query = %s error message = %s\n",
388 db_query, error_message);
389 sqlite3_free(error_message);
392 sqlite3_free(error_message);
396 static int __exec_query(char *query)
398 char *error_message = NULL;
400 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
401 _LOGD("Don't execute query = %s error message = %s\n", query,
403 sqlite3_free(error_message);
406 sqlite3_free(error_message);
410 static int __exec_query_no_msg(char *query)
412 char *error_message = NULL;
414 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
415 sqlite3_free(error_message);
418 sqlite3_free(error_message);
422 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
428 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
434 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
440 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
446 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
452 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
459 static GList *__create_icon_list(GList *locale, icon_x *icn)
464 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
470 static GList *__create_image_list(GList *locale, image_x *image)
475 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
481 static void __printfunc(gpointer data, gpointer userdata)
483 _LOGD("%s ", (char*)data);
486 static void __trimfunc(GList* trim_list)
488 char *trim_data = NULL;
492 list = g_list_first(trim_list);
495 trim_data = (char *)list->data;
498 if (strcmp(trim_data, prev) == 0) {
499 trim_list = g_list_remove(trim_list, trim_data);
500 list = g_list_first(trim_list);
509 list = g_list_next(list);
513 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
515 if (a == NULL || b == NULL)
517 if (strcmp((char*)a, (char*)b) == 0)
519 if (strcmp((char*)a, (char*)b) < 0)
521 if (strcmp((char*)a, (char*)b) > 0)
526 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
527 char **label, char **license, char **icon, char **description, char **author)
532 if (strcmp(lbl->lang, (char *)data) == 0) {
533 *label = (char*)lbl->text;
542 if (strcmp(lcn->lang, (char *)data) == 0) {
543 *license = (char*)lcn->text;
552 if (strcmp(icn->lang, (char *)data) == 0) {
553 *icon = (char*)icn->text;
562 if (strcmp(dcn->lang, (char *)data) == 0) {
563 *description = (char*)dcn->text;
572 if (strcmp(ath->lang, (char *)data) == 0) {
573 *author = (char*)ath->text;
582 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
587 if (strcmp(icn->section, (char *)data) == 0) {
588 *icon = (char*)icn->text;
589 *resolution = (char*)icn->resolution;
597 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
601 if (image->section) {
602 if (strcmp(image->section, (char *)data) == 0) {
603 *lang = (char*)image->lang;
604 *img = (char*)image->text;
612 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
617 char *description = NULL;
618 char *license = NULL;
620 char query[MAX_QUERY_LEN] = {'\0'};
622 manifest_x *mfx = (manifest_x *)userdata;
623 label_x *lbl = mfx->label;
624 license_x *lcn = mfx->license;
625 icon_x *icn = mfx->icon;
626 description_x *dcn = mfx->description;
627 author_x *ath = mfx->author;
629 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
630 if (!label && !description && !icon && !license && !author)
633 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
634 "package_label, package_icon, package_description, package_license, package_author) values " \
635 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
640 __get_str(description),
644 ret = __exec_query(query);
646 _LOGD("Package Localized Info DB Insert failed\n");
649 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
654 char query[MAX_QUERY_LEN] = {'\0'};
656 uiapplication_x *up = (uiapplication_x*)userdata;
657 label_x *lbl = up->label;
658 icon_x *icn = up->icon;
660 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
663 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
664 "app_label, app_icon) values " \
665 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
667 ret = __exec_query(query);
669 _LOGD("Package UiApp Localized Info DB Insert failed\n");
671 /*insert ui app locale info to pkg locale to get mainapp data */
672 if (strcasecmp(up->mainapp, "true")==0) {
673 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
674 "package_label, package_icon, package_description, package_license, package_author) values " \
675 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
680 PKGMGR_PARSER_EMPTY_STR,
681 PKGMGR_PARSER_EMPTY_STR,
682 PKGMGR_PARSER_EMPTY_STR);
684 ret = __exec_query_no_msg(query);
687 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
688 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
689 ret = __exec_query_no_msg(query);
694 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
698 char *resolution = NULL;
699 char query[MAX_QUERY_LEN] = {'\0'};
701 uiapplication_x *up = (uiapplication_x*)userdata;
702 icon_x *icn = up->icon;
704 __extract_icon_data(data, icn, &icon, &resolution);
705 if (!icon && !resolution)
707 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
708 "app_icon, app_icon_section, app_icon_resolution) values " \
709 "('%q', '%q', '%q', '%q')", up->appid,
710 icon, (char*)data, resolution);
712 ret = __exec_query(query);
714 _LOGD("Package UiApp Localized Info DB Insert failed\n");
718 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
723 char query[MAX_QUERY_LEN] = {'\0'};
725 uiapplication_x *up = (uiapplication_x*)userdata;
726 image_x *image = up->image;
728 __extract_image_data(data, image, &lang, &img);
731 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
732 "app_image_section, app_image) values " \
733 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
735 ret = __exec_query(query);
737 _LOGD("Package UiApp image Info DB Insert failed\n");
742 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
747 char query[MAX_QUERY_LEN] = {'\0'};
749 serviceapplication_x *sp = (serviceapplication_x*)userdata;
750 label_x *lbl = sp->label;
751 icon_x *icn = sp->icon;
753 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
756 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
757 "app_label, app_icon) values " \
758 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
760 ret = __exec_query(query);
762 _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
765 static int __insert_ui_mainapp_info(manifest_x *mfx)
767 uiapplication_x *up = mfx->uiapplication;
769 char query[MAX_QUERY_LEN] = {'\0'};
772 snprintf(query, MAX_QUERY_LEN,
773 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
775 ret = __exec_query(query);
777 _LOGD("Package UiApp Info DB Insert Failed\n");
780 if (strcasecmp(up->mainapp, "True")==0)
781 mfx->mainapp_id = strdup(up->appid);
784 memset(query, '\0', MAX_QUERY_LEN);
787 if (mfx->mainapp_id == NULL){
788 if (mfx->uiapplication && mfx->uiapplication->appid) {
789 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
791 _LOGD("Not valid appid\n");
795 ret = __exec_query(query);
797 _LOGD("Package UiApp Info DB Insert Failed\n");
801 free((void *)mfx->uiapplication->mainapp);
802 mfx->uiapplication->mainapp= strdup("true");
803 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
806 memset(query, '\0', MAX_QUERY_LEN);
807 snprintf(query, MAX_QUERY_LEN,
808 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
809 ret = __exec_query(query);
811 _LOGD("Package Info DB update Failed\n");
817 /* _PRODUCT_LAUNCHING_ENHANCED_
818 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
820 static int __insert_uiapplication_info(manifest_x *mfx)
822 uiapplication_x *up = mfx->uiapplication;
824 char query[MAX_QUERY_LEN] = {'\0'};
827 snprintf(query, MAX_QUERY_LEN,
828 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
829 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
830 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
831 "app_preload, app_submode, app_submode_mainid, component_type, package) " \
832 "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')",\
838 PKGMGR_PARSER_EMPTY_STR,
840 PKGMGR_PARSER_EMPTY_STR,
846 __get_str(up->recentimage),
848 up->indicatordisplay,
849 __get_str(up->portraitimg),
850 __get_str(up->landscapeimg),
851 up->guestmode_visibility,
855 __get_str(up->submode_mainid),
859 ret = __exec_query(query);
861 _LOGD("Package UiApp Info DB Insert Failed\n");
865 memset(query, '\0', MAX_QUERY_LEN);
870 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
872 uiapplication_x *up = mfx->uiapplication;
873 category_x *ct = NULL;
875 char query[MAX_QUERY_LEN] = {'\0'};
881 snprintf(query, MAX_QUERY_LEN,
882 "insert into package_app_app_category(app_id, category) " \
883 "values('%s','%s')",\
884 up->appid, ct->name);
885 ret = __exec_query(query);
887 _LOGD("Package UiApp Category Info DB Insert Failed\n");
891 memset(query, '\0', MAX_QUERY_LEN);
898 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
900 uiapplication_x *up = mfx->uiapplication;
901 metadata_x *md = NULL;
903 char query[MAX_QUERY_LEN] = {'\0'};
910 snprintf(query, MAX_QUERY_LEN,
911 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
912 "values('%s','%s', '%s')",\
913 up->appid, md->key, md->value);
914 ret = __exec_query(query);
916 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
921 memset(query, '\0', MAX_QUERY_LEN);
928 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
930 uiapplication_x *up = mfx->uiapplication;
931 permission_x *pm = NULL;
933 char query[MAX_QUERY_LEN] = {'\0'};
939 snprintf(query, MAX_QUERY_LEN,
940 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
941 "values('%s','%s', '%s')",\
942 up->appid, pm->type, pm->value);
943 ret = __exec_query(query);
945 _LOGD("Package UiApp permission Info DB Insert Failed\n");
949 memset(query, '\0', MAX_QUERY_LEN);
956 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
958 uiapplication_x *up = mfx->uiapplication;
959 appcontrol_x *acontrol = NULL;
960 operation_x *op = NULL;
963 subapp_x *sub = NULL;
965 char query[MAX_QUERY_LEN] = {'\0'};
966 char buf[BUFSIZE] = {'\0'};
967 const char *operation = NULL;
968 const char *mime = NULL;
969 const char *uri = NULL;
970 const char *subapp = NULL;
972 acontrol = up->appcontrol;
973 while (acontrol != NULL) {
974 op = acontrol->operation;
977 operation = op->name;
983 sub = acontrol->subapp;
991 snprintf(buf, BUFSIZE, "%s|%s|%s|%s",
992 operation ? operation : "NULL",
994 mime ? mime : "NULL",
995 subapp ? subapp : "NULL");
996 snprintf(query, MAX_QUERY_LEN,
997 "insert into package_app_app_control(app_id, app_control) " \
998 "values('%s', '%s')",\
1000 ret = __exec_query(query);
1002 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1005 memset(query, '\0', MAX_QUERY_LEN);
1009 } while (ui != NULL);
1013 } while (sub != NULL);
1017 } while (mi != NULL);
1022 acontrol = acontrol->next;
1029 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1031 uiapplication_x *up = mfx->uiapplication;
1032 appsvc_x *asvc = NULL;
1033 operation_x *op = NULL;
1036 subapp_x *sub = NULL;
1038 char query[MAX_QUERY_LEN] = {'\0'};
1039 const char *operation = NULL;
1040 const char *mime = NULL;
1041 const char *uri = NULL;
1042 const char *subapp = NULL;
1048 op = asvc->operation;
1052 operation = op->name;
1069 snprintf(query, MAX_QUERY_LEN,
1070 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1071 "values('%s', '%s', '%s', '%s', '%s')",\
1078 ret = __exec_query(query);
1080 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1083 memset(query, '\0', MAX_QUERY_LEN);
1087 } while(ui != NULL);
1091 }while(sub != NULL);
1107 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1109 uiapplication_x *up = mfx->uiapplication;
1110 datashare_x *ds = NULL;
1111 request_x *rq = NULL;
1113 char query[MAX_QUERY_LEN] = {'\0'};
1122 snprintf(query, MAX_QUERY_LEN,
1123 "insert into package_app_share_request(app_id, data_share_request) " \
1124 "values('%s', '%s')",\
1125 up->appid, rq->text);
1126 ret = __exec_query(query);
1128 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1131 memset(query, '\0', MAX_QUERY_LEN);
1141 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1143 uiapplication_x *up = mfx->uiapplication;
1144 datashare_x *ds = NULL;
1145 define_x *df = NULL;
1146 allowed_x *al = NULL;
1148 char query[MAX_QUERY_LEN] = {'\0'};
1160 snprintf(query, MAX_QUERY_LEN,
1161 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1162 "values('%s', '%s', '%s')",\
1163 up->appid, df->path, al->text);
1164 ret = __exec_query(query);
1166 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1169 memset(query, '\0', MAX_QUERY_LEN);
1181 static int __insert_serviceapplication_info(manifest_x *mfx)
1183 serviceapplication_x *sp = mfx->serviceapplication;
1185 char query[MAX_QUERY_LEN] = {'\0'};
1188 snprintf(query, MAX_QUERY_LEN,
1189 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1190 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1191 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1192 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1193 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1194 ret = __exec_query(query);
1196 _LOGD("Package ServiceApp Info DB Insert Failed\n");
1200 memset(query, '\0', MAX_QUERY_LEN);
1205 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1207 serviceapplication_x *sp = mfx->serviceapplication;
1208 category_x *ct = NULL;
1210 char query[MAX_QUERY_LEN] = {'\0'};
1216 snprintf(query, MAX_QUERY_LEN,
1217 "insert into package_app_app_category(app_id, category) " \
1218 "values('%s','%s')",\
1219 sp->appid, ct->name);
1220 ret = __exec_query(query);
1222 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1226 memset(query, '\0', MAX_QUERY_LEN);
1233 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1235 serviceapplication_x *sp = mfx->serviceapplication;
1236 metadata_x *md = NULL;
1238 char query[MAX_QUERY_LEN] = {'\0'};
1245 snprintf(query, MAX_QUERY_LEN,
1246 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1247 "values('%s','%s', '%s')",\
1248 sp->appid, md->key, md->value);
1249 ret = __exec_query(query);
1251 _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1256 memset(query, '\0', MAX_QUERY_LEN);
1263 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1265 serviceapplication_x *sp = mfx->serviceapplication;
1266 permission_x *pm = NULL;
1268 char query[MAX_QUERY_LEN] = {'\0'};
1271 pm = sp->permission;
1274 snprintf(query, MAX_QUERY_LEN,
1275 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1276 "values('%s','%s', '%s')",\
1277 sp->appid, pm->type, pm->value);
1278 ret = __exec_query(query);
1280 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1284 memset(query, '\0', MAX_QUERY_LEN);
1291 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1293 serviceapplication_x *sp = mfx->serviceapplication;
1294 appcontrol_x *acontrol = NULL;
1296 char query[MAX_QUERY_LEN] = {'\0'};
1297 char buf[BUFSIZE] = {'\0'};
1298 operation_x *op = NULL;
1301 subapp_x *sub = NULL;
1302 const char *operation = NULL;
1303 const char *mime = NULL;
1304 const char *uri = NULL;
1305 const char *subapp = NULL;
1306 while (sp != NULL) {
1307 acontrol = sp->appcontrol;
1308 while (acontrol != NULL) {
1309 op = acontrol->operation;
1310 while (op != NULL) {
1312 operation = op->name;
1313 mi = acontrol->mime;
1317 sub = acontrol->subapp;
1325 snprintf(buf, BUFSIZE, "%s|%s|%s|%s",
1326 operation ? operation : "NULL",
1328 mime ? mime : "NULL",
1329 subapp ? subapp : "NULL");
1330 snprintf(query, MAX_QUERY_LEN,
1331 "insert into package_app_app_control(app_id, app_control) " \
1332 "values('%s', '%s')",\
1334 ret = __exec_query(query);
1336 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1339 memset(query, '\0', MAX_QUERY_LEN);
1343 } while (ui != NULL);
1347 } while (sub != NULL);
1351 } while (mi != NULL);
1356 acontrol = acontrol->next;
1363 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1365 serviceapplication_x *sp = mfx->serviceapplication;
1366 appsvc_x *asvc = NULL;
1368 char query[MAX_QUERY_LEN] = {'\0'};
1369 operation_x *op = NULL;
1372 subapp_x *sub = NULL;
1373 const char *operation = NULL;
1374 const char *mime = NULL;
1375 const char *uri = NULL;
1376 const char *subapp = NULL;
1382 op = asvc->operation;
1386 operation = op->name;
1402 snprintf(query, MAX_QUERY_LEN,
1403 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1404 "values('%s', '%s', '%s', '%s', '%s')",\
1410 ret = __exec_query(query);
1412 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1415 memset(query, '\0', MAX_QUERY_LEN);
1419 } while(ui != NULL);
1423 }while(sub != NULL);
1439 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx)
1441 serviceapplication_x *sp = mfx->serviceapplication;
1442 datacontrol_x *dc = NULL;
1444 char query[MAX_QUERY_LEN] = {'\0'};
1448 dc = sp->datacontrol;
1451 snprintf(query, MAX_QUERY_LEN,
1452 "insert into package_app_data_control(app_id, providerid, access, type) " \
1453 "values('%s', '%s', '%s', '%s')",\
1454 mfx->serviceapplication->appid,
1459 ret = __exec_query(query);
1461 _LOGD("Package ServiceApp Data Control DB Insert Failed\n");
1464 memset(query, '\0', MAX_QUERY_LEN);
1472 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1474 serviceapplication_x *sp = mfx->serviceapplication;
1475 datashare_x *ds = NULL;
1476 request_x *rq = NULL;
1478 char query[MAX_QUERY_LEN] = {'\0'};
1487 snprintf(query, MAX_QUERY_LEN,
1488 "insert into package_app_share_request(app_id, data_share_request) " \
1489 "values('%s', '%s')",\
1490 sp->appid, rq->text);
1491 ret = __exec_query(query);
1493 _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1496 memset(query, '\0', MAX_QUERY_LEN);
1508 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1510 serviceapplication_x *sp = mfx->serviceapplication;
1511 datashare_x *ds = NULL;
1512 define_x *df = NULL;
1513 allowed_x *al = NULL;
1515 char query[MAX_QUERY_LEN] = {'\0'};
1527 snprintf(query, MAX_QUERY_LEN,
1528 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1529 "values('%s', '%s', '%s')",\
1530 sp->appid, df->path, al->text);
1531 ret = __exec_query(query);
1533 _LOGD("Package App Share Allowed DB Insert Failed\n");
1536 memset(query, '\0', MAX_QUERY_LEN);
1548 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1550 label_x *lbl = mfx->label;
1551 license_x *lcn = mfx->license;
1552 icon_x *icn = mfx->icon;
1553 description_x *dcn = mfx->description;
1554 author_x *ath = mfx->author;
1555 uiapplication_x *up = mfx->uiapplication;
1556 uiapplication_x *up_icn = mfx->uiapplication;
1557 uiapplication_x *up_image = mfx->uiapplication;
1558 serviceapplication_x *sp = mfx->serviceapplication;
1559 privileges_x *pvs = NULL;
1560 privilege_x *pv = NULL;
1561 char query[MAX_QUERY_LEN] = { '\0' };
1562 char root[MAX_QUERY_LEN] = { '\0' };
1566 const char *auth_name = NULL;
1567 const char *auth_email = NULL;
1568 const char *auth_href = NULL;
1569 const char *apps_path = NULL;
1571 GList *pkglocale = NULL;
1572 GList *applocale = NULL;
1573 GList *appicon = NULL;
1574 GList *appimage = NULL;
1578 auth_name = ath->text;
1580 auth_email = ath->email;
1582 auth_href = ath->href;
1584 /*Insert in the package_cert_info CERT_DB*/
1585 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1586 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1587 if (ret != PMINFO_R_OK) {
1588 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1589 _LOGE("Cert Info DB create handle failed\n");
1592 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1593 if (ret != PMINFO_R_OK) {
1594 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1595 _LOGE("Cert Info DB Insert Failed\n");
1599 /*Insert in the package_info DB*/
1601 type = strdup(mfx->type);
1603 type = strdup("rpm");
1604 /*Insert in the package_info DB*/
1606 path = strdup(mfx->root_path);
1608 if (strcmp(type,"rpm")==0) {
1609 apps_path = tzplatform_getenv(TZ_SYS_RO_APP);
1610 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1612 apps_path = tzplatform_getenv(TZ_USER_APP);
1613 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1615 path = strdup(root);
1617 snprintf(query, MAX_QUERY_LEN,
1618 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1619 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1620 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
1621 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1625 __get_str(mfx->installlocation),
1626 __get_str(mfx->package_size),
1632 mfx->nodisplay_setting,
1634 __get_str(auth_name),
1635 __get_str(auth_email),
1636 __get_str(auth_href),
1637 mfx->installed_time,
1638 mfx->installed_storage,
1639 __get_str(mfx->storeclient_id),
1641 __get_str(mfx->package_url),
1643 __get_str(mfx->csc_path));
1644 /*If package dont have main_package tag, this package is main package.*/
1645 if (mfx->main_package == NULL) {
1646 ret = __exec_query(query);
1648 _LOGD("Package Info DB Insert Failed\n");
1660 /*If package has main_package tag, this package is sub package(ug, efl).
1661 skip __exec_query for package_info and change pkgid with main_package*/
1662 memset(root, '\0', MAX_QUERY_LEN);
1663 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->main_package);
1664 if (access(root, F_OK) == 0) {
1665 free((void *)mfx->package);
1666 mfx->package = strdup(mfx->main_package);
1668 _LOGE("main package[%s] is not installed\n", root);
1681 /*Insert in the package_privilege_info DB*/
1682 pvs = mfx->privileges;
1683 while (pvs != NULL) {
1684 pv = pvs->privilege;
1685 while (pv != NULL) {
1686 memset(query, '\0', MAX_QUERY_LEN);
1687 snprintf(query, MAX_QUERY_LEN,
1688 "insert into package_privilege_info(package, privilege) " \
1689 "values('%s','%s')",\
1690 mfx->package, pv->text);
1691 ret = __exec_query(query);
1693 _LOGD("Package Privilege Info DB Insert Failed\n");
1702 ret = __insert_ui_mainapp_info(mfx);
1707 /*Insert the package locale*/
1708 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1709 /*remove duplicated data in pkglocale*/
1710 __trimfunc(pkglocale);
1712 /*Insert the app locale info */
1715 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1720 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1723 /*remove duplicated data in applocale*/
1724 __trimfunc(applocale);
1726 /*Insert the app icon info */
1727 while(up_icn != NULL)
1729 appicon = __create_icon_list(appicon, up_icn->icon);
1730 up_icn = up_icn->next;
1732 /*remove duplicated data in appicon*/
1733 __trimfunc(appicon);
1735 /*Insert the image info */
1736 while(up_image != NULL)
1738 appimage = __create_image_list(appimage, up_image->image);
1739 up_image = up_image->next;
1741 /*remove duplicated data in appimage*/
1742 __trimfunc(appimage);
1744 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1746 /*g_list_foreach(applocale, __printfunc, NULL);*/
1748 /*package locale info, it is only for main package.*/
1749 if (mfx->main_package == NULL)
1750 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1752 /*native app locale info*/
1753 up = mfx->uiapplication;
1756 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1759 /*agent app locale info*/
1760 sp = mfx->serviceapplication;
1763 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1767 /*app icon locale info*/
1768 up_icn = mfx->uiapplication;
1769 while(up_icn != NULL)
1771 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1772 up_icn = up_icn->next;
1776 up_image = mfx->uiapplication;
1777 while(up_image != NULL)
1779 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1780 up_image = up_image->next;
1783 g_list_free(pkglocale);
1785 g_list_free(applocale);
1787 g_list_free(appicon);
1789 g_list_free(appimage);
1792 /*Insert in the package_app_info DB*/
1793 ret = __insert_uiapplication_info(mfx);
1796 ret = __insert_serviceapplication_info(mfx);
1799 /*Insert in the package_app_app_control DB*/
1800 ret = __insert_uiapplication_appcontrol_info(mfx);
1803 ret = __insert_serviceapplication_appcontrol_info(mfx);
1807 /*Insert in the package_app_app_category DB*/
1808 ret = __insert_uiapplication_appcategory_info(mfx);
1811 ret = __insert_serviceapplication_appcategory_info(mfx);
1815 /*Insert in the package_app_app_metadata DB*/
1816 ret = __insert_uiapplication_appmetadata_info(mfx);
1819 ret = __insert_serviceapplication_appmetadata_info(mfx);
1823 /*Insert in the package_app_app_permission DB*/
1824 ret = __insert_uiapplication_apppermission_info(mfx);
1827 ret = __insert_serviceapplication_apppermission_info(mfx);
1831 /*Insert in the package_app_app_svc DB*/
1832 ret = __insert_uiapplication_appsvc_info(mfx);
1835 ret = __insert_serviceapplication_appsvc_info(mfx);
1839 /*Insert in the package_app_share_allowed DB*/
1840 ret = __insert_uiapplication_share_allowed_info(mfx);
1843 ret = __insert_serviceapplication_share_allowed_info(mfx);
1847 /*Insert in the package_app_share_request DB*/
1848 ret = __insert_uiapplication_share_request_info(mfx);
1851 ret = __insert_serviceapplication_share_request_info(mfx);
1855 /*Insert in the package_app_data_control DB*/
1856 ret = __insert_serviceapplication_datacontrol_info(mfx);
1864 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1866 char query[MAX_QUERY_LEN] = { '\0' };
1868 memset(query, '\0', MAX_QUERY_LEN);
1869 snprintf(query, MAX_QUERY_LEN,
1870 "delete from %s where app_id='%s'", db_table, appid);
1871 ret = __exec_query(query);
1873 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1879 static int __delete_subpkg_info_from_db(char *appid)
1883 ret = __delete_appinfo_from_db("package_app_info", appid);
1886 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1889 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1892 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1895 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1898 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1901 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1904 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1907 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1910 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1913 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1916 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1923 static int __delete_subpkg_from_db(manifest_x *mfx)
1925 char query[MAX_QUERY_LEN] = { '\0' };
1926 char *error_message = NULL;
1928 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1930 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1931 _LOGE("Don't execute query = %s error message = %s\n", query,
1933 sqlite3_free(error_message);
1936 sqlite3_free(error_message);
1941 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1943 char query[MAX_QUERY_LEN] = { '\0' };
1945 uiapplication_x *up = mfx->uiapplication;
1946 serviceapplication_x *sp = mfx->serviceapplication;
1947 /*Delete from cert table*/
1948 if (uid != GLOBAL_USER)
1949 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1951 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1953 _LOGD("Cert Info DB Delete Failed\n");
1957 /*Delete from Package Info DB*/
1958 snprintf(query, MAX_QUERY_LEN,
1959 "delete from package_info where package='%s'", mfx->package);
1960 ret = __exec_query(query);
1962 _LOGD("Package Info DB Delete Failed\n");
1965 memset(query, '\0', MAX_QUERY_LEN);
1967 /*Delete from Package Localized Info*/
1968 snprintf(query, MAX_QUERY_LEN,
1969 "delete from package_localized_info where package='%s'", mfx->package);
1970 ret = __exec_query(query);
1972 _LOGD("Package Localized Info DB Delete Failed\n");
1976 /*Delete from Package Privilege Info*/
1977 snprintf(query, MAX_QUERY_LEN,
1978 "delete from package_privilege_info where package='%s'", mfx->package);
1979 ret = __exec_query(query);
1981 _LOGD("Package Privilege Info DB Delete Failed\n");
1985 while (up != NULL) {
1986 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1989 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1992 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
1995 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
1998 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
2001 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
2004 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
2007 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
2010 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
2013 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
2016 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
2019 ret = __delete_appinfo_from_db("package_app_data_control", up->appid);
2025 while (sp != NULL) {
2026 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
2029 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
2032 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
2035 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
2038 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
2041 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
2044 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
2047 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
2050 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
2053 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
2056 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
2059 ret = __delete_appinfo_from_db("package_app_data_control", sp->appid);
2065 /* if main package has sub pkg, delete sub pkg data*/
2066 __delete_subpkg_from_db(mfx);
2071 static int __update_preload_condition_in_db()
2074 char query[MAX_QUERY_LEN] = {'\0'};
2076 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2078 ret = __exec_query(query);
2080 _LOGD("Package preload_condition update failed\n");
2085 API int pkgmgr_parser_initialize_db(void)
2089 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2091 _LOGD("package info DB initialization failed\n");
2094 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2096 _LOGD("package localized info DB initialization failed\n");
2099 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2101 _LOGD("package app app privilege DB initialization failed\n");
2104 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2106 _LOGD("package app info DB initialization failed\n");
2109 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2111 _LOGD("package app localized info DB initialization failed\n");
2114 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2116 _LOGD("package app icon localized info DB initialization failed\n");
2119 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2121 _LOGD("package app image info DB initialization failed\n");
2124 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2126 _LOGD("package app app control DB initialization failed\n");
2129 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2131 _LOGD("package app app category DB initialization failed\n");
2134 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2136 _LOGD("package app app category DB initialization failed\n");
2139 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2141 _LOGD("package app app permission DB initialization failed\n");
2144 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2146 _LOGD("package app app svc DB initialization failed\n");
2149 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2151 _LOGD("package app share allowed DB initialization failed\n");
2154 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2156 _LOGD("package app share request DB initialization failed\n");
2159 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2161 _LOGD("package app data control DB initialization failed\n");
2165 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2167 _LOGD("package cert info DB initialization failed\n");
2170 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2172 _LOGD("package cert index info DB initialization failed\n");
2179 static int parserdb_change_perm(const char *db_file, uid_t uid)
2182 char journal_file[BUFSIZE];
2185 struct passwd *userinfo = NULL;
2186 files[0] = (char *)db_file;
2187 files[1] = journal_file;
2193 if(getuid() != OWNER_ROOT) //At this time we should be root to apply this
2195 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2196 userinfo = getpwuid(uid);
2198 _LOGE("FAIL: user %d doesn't exist", uid);
2201 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2203 for (i = 0; files[i]; i++) {
2204 ret = chown(files[i], uid, userinfo->pw_gid);
2205 SET_SMACK_LABEL(files[i],uid)
2207 strerror_r(errno, buf, sizeof(buf));
2208 _LOGD("FAIL : chown %s %d.%d, because %s", db_file, uid, userinfo->pw_gid, buf);
2212 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
2214 strerror_r(errno, buf, sizeof(buf));
2215 _LOGD("FAIL : chmod %s 0664, because %s", db_file, buf);
2222 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2226 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2228 _LOGD("Manifest DB creation Failed\n");
2233 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid));
2235 _LOGD("Cert DB creation Failed\n");
2238 if( 0 != parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
2239 _LOGD("Failed to change cert db permission\n");
2241 if( 0 != parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2242 _LOGD("Failed to change parser db permission\n");
2247 void pkgmgr_parser_close_db()
2249 sqlite3_close(pkgmgr_parser_db);
2250 sqlite3_close(pkgmgr_cert_db);
2254 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2256 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2258 _LOGD("manifest pointer is NULL\n");
2262 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2264 _LOGD("Failed to open DB\n");
2267 ret = pkgmgr_parser_initialize_db();
2270 /*Begin transaction*/
2271 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2272 if (ret != SQLITE_OK) {
2273 _LOGD("Failed to begin transaction\n");
2277 _LOGD("Transaction Begin\n");
2278 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2280 _LOGD("Insert into DB failed. Rollback now\n");
2281 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2284 /*Commit transaction*/
2285 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2286 if (ret != SQLITE_OK) {
2287 _LOGD("Failed to commit transaction. Rollback now\n");
2288 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2292 _LOGD("Transaction Commit and End\n");
2294 pkgmgr_parser_close_db();
2298 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2300 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2302 _LOGD("manifest pointer is NULL\n");
2306 ret = pkgmgr_parser_check_and_create_db(uid);
2308 _LOGD("Failed to open DB\n");
2311 ret = pkgmgr_parser_initialize_db();
2314 /*Begin transaction*/
2315 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2316 if (ret != SQLITE_OK) {
2317 _LOGD("Failed to begin transaction\n");
2321 _LOGD("Transaction Begin\n");
2322 ret = __insert_manifest_info_in_db(mfx, uid);
2324 _LOGD("Insert into DB failed. Rollback now\n");
2325 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2328 /*Commit transaction*/
2329 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2330 if (ret != SQLITE_OK) {
2331 _LOGD("Failed to commit transaction. Rollback now\n");
2332 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2336 _LOGD("Transaction Commit and End\n");
2338 pkgmgr_parser_close_db();
2342 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2345 _LOGD("manifest pointer is NULL\n");
2349 ret = pkgmgr_parser_check_and_create_db(uid);
2351 _LOGD("Failed to open DB\n");
2354 ret = pkgmgr_parser_initialize_db();
2357 /*Preserve guest mode visibility*/
2358 __preserve_guestmode_visibility_value( mfx);
2359 /*Begin transaction*/
2360 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2361 if (ret != SQLITE_OK) {
2362 _LOGD("Failed to begin transaction\n");
2366 _LOGD("Transaction Begin\n");
2367 ret = __delete_manifest_info_from_db(mfx, uid);
2369 _LOGD("Delete from DB failed. Rollback now\n");
2370 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2373 ret = __insert_manifest_info_in_db(mfx, uid);
2375 _LOGD("Insert into DB failed. Rollback now\n");
2376 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2380 /*Commit transaction*/
2381 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2382 if (ret != SQLITE_OK) {
2383 _LOGD("Failed to commit transaction. Rollback now\n");
2384 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2388 _LOGD("Transaction Commit and End\n");
2390 pkgmgr_parser_close_db();
2394 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2396 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2399 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2402 _LOGD("manifest pointer is NULL\n");
2406 ret = pkgmgr_parser_check_and_create_db(uid);
2408 _LOGD("Failed to open DB\n");
2411 /*Begin transaction*/
2412 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2413 if (ret != SQLITE_OK) {
2414 _LOGD("Failed to begin transaction\n");
2418 _LOGD("Transaction Begin\n");
2419 ret = __delete_manifest_info_from_db(mfx, uid);
2421 _LOGD("Delete from DB failed. Rollback now\n");
2422 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2425 /*Commit transaction*/
2426 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2427 if (ret != SQLITE_OK) {
2428 _LOGD("Failed to commit transaction, Rollback now\n");
2429 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2433 _LOGD("Transaction Commit and End\n");
2435 pkgmgr_parser_close_db();
2439 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2441 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2444 API int pkgmgr_parser_update_preload_info_in_db()
2447 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2449 _LOGD("Failed to open DB\n");
2452 /*Begin transaction*/
2453 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2454 if (ret != SQLITE_OK) {
2455 _LOGD("Failed to begin transaction\n");
2459 _LOGD("Transaction Begin\n");
2460 ret = __update_preload_condition_in_db();
2462 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2463 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2466 /*Commit transaction*/
2467 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2468 if (ret != SQLITE_OK) {
2469 _LOGD("Failed to commit transaction, Rollback now\n");
2470 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2474 _LOGD("Transaction Commit and End\n");
2476 pkgmgr_parser_close_db();
2480 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2483 ret = pkgmgr_parser_check_and_create_db(uid);
2485 _LOGD("Failed to open DB\n");
2488 /*Begin transaction*/
2489 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2490 if (ret != SQLITE_OK) {
2491 _LOGD("Failed to begin transaction\n");
2495 _LOGD("Transaction Begin\n");
2496 ret = __update_preload_condition_in_db();
2498 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2499 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2502 /*Commit transaction*/
2503 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2504 if (ret != SQLITE_OK) {
2505 _LOGD("Failed to commit transaction, Rollback now\n");
2506 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2510 _LOGD("Transaction Commit and End\n");
2512 pkgmgr_parser_close_db();