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 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
133 "component_type text, " \
134 "package text not null, " \
135 "FOREIGN KEY(package) " \
136 "REFERENCES package_info(package) " \
139 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
140 "(app_id text not null, " \
141 "app_locale text DEFAULT 'No Locale', " \
144 "PRIMARY KEY(app_id,app_locale) " \
145 "FOREIGN KEY(app_id) " \
146 "REFERENCES package_app_info(app_id) " \
149 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
150 "(app_id text not null, " \
152 "app_icon_section text, " \
153 "app_icon_resolution text, " \
154 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
155 "FOREIGN KEY(app_id) " \
156 "REFERENCES package_app_info(app_id) " \
159 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
160 "(app_id text not null, " \
161 "app_locale text DEFAULT 'No Locale', " \
162 "app_image_section text, " \
164 "PRIMARY KEY(app_id,app_image_section) " \
165 "FOREIGN KEY(app_id) " \
166 "REFERENCES package_app_info(app_id) " \
169 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
170 "(app_id text not null, " \
171 "app_control text not null, " \
172 "PRIMARY KEY(app_id,app_control) " \
173 "FOREIGN KEY(app_id) " \
174 "REFERENCES package_app_info(app_id) " \
177 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
178 "(app_id text not null, " \
179 "operation text not null, " \
180 "uri_scheme text, " \
182 "subapp_name text, " \
183 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
184 "FOREIGN KEY(app_id) " \
185 "REFERENCES package_app_info(app_id) " \
188 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
189 "(app_id text not null, " \
190 "category text not null, " \
191 "PRIMARY KEY(app_id,category) " \
192 "FOREIGN KEY(app_id) " \
193 "REFERENCES package_app_info(app_id) " \
196 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
197 "(app_id text not null, " \
198 "md_key text not null, " \
199 "md_value text not null, " \
200 "PRIMARY KEY(app_id, md_key, md_value) " \
201 "FOREIGN KEY(app_id) " \
202 "REFERENCES package_app_info(app_id) " \
205 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
206 "(app_id text not null, " \
207 "pm_type text not null, " \
208 "pm_value text not null, " \
209 "PRIMARY KEY(app_id, pm_type, pm_value) " \
210 "FOREIGN KEY(app_id) " \
211 "REFERENCES package_app_info(app_id) " \
214 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
215 "(app_id text not null, " \
216 "data_share_path text not null, " \
217 "data_share_allowed text not null, " \
218 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
219 "FOREIGN KEY(app_id) " \
220 "REFERENCES package_app_info(app_id) " \
223 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
224 "(app_id text not null, " \
225 "data_share_request text not null, " \
226 "PRIMARY KEY(app_id,data_share_request) " \
227 "FOREIGN KEY(app_id) " \
228 "REFERENCES package_app_info(app_id) " \
231 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
232 "(cert_info text not null, " \
233 "cert_id integer, " \
234 "cert_ref_count integer, " \
235 "PRIMARY KEY(cert_id)) "
237 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
238 "(package text not null, " \
239 "author_root_cert integer, " \
240 "author_im_cert integer, " \
241 "author_signer_cert integer, " \
242 "dist_root_cert integer, " \
243 "dist_im_cert integer, " \
244 "dist_signer_cert integer, " \
245 "dist2_root_cert integer, " \
246 "dist2_im_cert integer, " \
247 "dist2_signer_cert integer, " \
248 "PRIMARY KEY(package)) "
250 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
251 "(app_id text not null, " \
252 "providerid text not null, " \
253 "access text not null, " \
254 "type text not null, " \
255 "PRIMARY KEY(app_id, providerid, access, type) " \
256 "FOREIGN KEY(app_id) " \
257 "REFERENCES package_app_info(app_id) " \
259 #define QUERY_CREATE_TABLE_PACKAGE_RESOURCE_INFO "CREATE TABLE IF NOT EXISTS package_resource_info" \
260 "(pkg_id text NOT NULL," \
261 "group_folder text NOT NULL," \
262 "group_type text NOT NULL," \
263 "PRIMARY KEY(pkg_id, group_type))"
265 #define QUERY_CREATE_TABLE_PACKAGE_RESOURCE_DATA "CREATE TABLE IF NOT EXISTS package_resource_data" \
266 "(id integer REFERENCES package_resource_info(rowid)," \
267 "node_folder text NOT NULL," \
268 "attr_name text NOT NULL," \
269 "attr_value test NOT NULL," \
270 "PRIMARY KEY(id, node_folder, attr_name))"
272 static int __insert_uiapplication_info(manifest_x *mfx);
273 static int __insert_serviceapplication_info(manifest_x *mfx);
274 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
275 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
276 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
277 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
278 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
279 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
280 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
281 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
282 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
283 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
284 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
285 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
286 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx);
287 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
288 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
289 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
290 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
291 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
292 static int __delete_subpkg_info_from_db(char *appid);
293 static int __delete_appinfo_from_db(char *db_table, const char *appid);
294 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
295 static int __exec_query(char *query);
296 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
297 char **label, char **license, char **icon, char **description, char **author);
298 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
299 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
300 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
301 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
302 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
304 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
307 __delete_subpkg_info_from_db(coltxt[0]);
312 static char *__get_str(const char *str)
316 return PKGMGR_PARSER_EMPTY_STR;
322 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
327 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
328 if (ret != SQLITE_OK) {
329 _LOGD("connect db [%s] failed!\n", db_path);
337 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
339 manifest_x *mfx = (manifest_x *)data;
343 uiapplication_x *uiapp = NULL;
344 for(i = 0; i < ncols; i++)
346 uiapp = mfx->uiapplication;
347 if (strcmp(colname[i], "app_id") == 0) {
349 appid = strdup(coltxt[i]);
350 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
352 status = strdup(coltxt[i]);
356 _LOGD("app id is NULL\n");
359 /*update guest mode visibility*/
360 for (; uiapp != NULL; uiapp = uiapp->next) {
361 if (strcmp(uiapp->appid, appid) == 0) {
362 free((void *)uiapp->guestmode_visibility);
363 uiapp->guestmode_visibility = strdup(status);
379 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
381 char *error_message = NULL;
382 char query[MAX_QUERY_LEN] = {'\0'};
383 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
385 sqlite3_exec(pkgmgr_parser_db, query,
386 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
387 _LOGD("Don't execute query = %s error message = %s\n",
388 query, error_message);
389 sqlite3_free(error_message);
394 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
396 char *error_message = NULL;
398 sqlite3_exec(db_handle, db_query,
399 NULL, NULL, &error_message)) {
400 _LOGD("Don't execute query = %s error message = %s\n",
401 db_query, error_message);
402 sqlite3_free(error_message);
405 sqlite3_free(error_message);
409 static int __exec_query(char *query)
411 char *error_message = NULL;
413 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
414 _LOGD("Don't execute query = %s error message = %s\n", query,
416 sqlite3_free(error_message);
419 sqlite3_free(error_message);
423 static int __exec_query_no_msg(char *query)
425 char *error_message = NULL;
427 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
428 sqlite3_free(error_message);
431 sqlite3_free(error_message);
435 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
441 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
447 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
453 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
459 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
465 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
472 static GList *__create_icon_list(GList *locale, icon_x *icn)
477 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
483 static GList *__create_image_list(GList *locale, image_x *image)
488 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
494 static void __printfunc(gpointer data, gpointer userdata)
496 _LOGD("%s ", (char*)data);
499 static void __trimfunc(GList* trim_list)
501 char *trim_data = NULL;
505 list = g_list_first(trim_list);
508 trim_data = (char *)list->data;
511 if (strcmp(trim_data, prev) == 0) {
512 trim_list = g_list_remove(trim_list, trim_data);
513 list = g_list_first(trim_list);
522 list = g_list_next(list);
526 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
528 if (a == NULL || b == NULL)
530 if (strcmp((char*)a, (char*)b) == 0)
532 if (strcmp((char*)a, (char*)b) < 0)
534 if (strcmp((char*)a, (char*)b) > 0)
539 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
540 char **label, char **license, char **icon, char **description, char **author)
545 if (strcmp(lbl->lang, (char *)data) == 0) {
546 *label = (char*)lbl->text;
555 if (strcmp(lcn->lang, (char *)data) == 0) {
556 *license = (char*)lcn->text;
565 if (strcmp(icn->lang, (char *)data) == 0) {
566 *icon = (char*)icn->text;
575 if (strcmp(dcn->lang, (char *)data) == 0) {
576 *description = (char*)dcn->text;
585 if (strcmp(ath->lang, (char *)data) == 0) {
586 *author = (char*)ath->text;
595 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
600 if (strcmp(icn->section, (char *)data) == 0) {
601 *icon = (char*)icn->text;
602 *resolution = (char*)icn->resolution;
610 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
614 if (image->section) {
615 if (strcmp(image->section, (char *)data) == 0) {
616 *lang = (char*)image->lang;
617 *img = (char*)image->text;
625 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
630 char *description = NULL;
631 char *license = NULL;
633 char query[MAX_QUERY_LEN] = {'\0'};
635 manifest_x *mfx = (manifest_x *)userdata;
636 label_x *lbl = mfx->label;
637 license_x *lcn = mfx->license;
638 icon_x *icn = mfx->icon;
639 description_x *dcn = mfx->description;
640 author_x *ath = mfx->author;
642 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
643 if (!label && !description && !icon && !license && !author)
646 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
647 "package_label, package_icon, package_description, package_license, package_author) values " \
648 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
653 __get_str(description),
657 ret = __exec_query(query);
659 _LOGD("Package Localized Info DB Insert failed\n");
662 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
667 char query[MAX_QUERY_LEN] = {'\0'};
669 uiapplication_x *up = (uiapplication_x*)userdata;
670 label_x *lbl = up->label;
671 icon_x *icn = up->icon;
673 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
676 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
677 "app_label, app_icon) values " \
678 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
680 ret = __exec_query(query);
682 _LOGD("Package UiApp Localized Info DB Insert failed\n");
684 /*insert ui app locale info to pkg locale to get mainapp data */
685 if (strcasecmp(up->mainapp, "true")==0) {
686 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
687 "package_label, package_icon, package_description, package_license, package_author) values " \
688 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
693 PKGMGR_PARSER_EMPTY_STR,
694 PKGMGR_PARSER_EMPTY_STR,
695 PKGMGR_PARSER_EMPTY_STR);
697 ret = __exec_query_no_msg(query);
700 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
701 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
702 ret = __exec_query_no_msg(query);
707 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
711 char *resolution = NULL;
712 char query[MAX_QUERY_LEN] = {'\0'};
714 uiapplication_x *up = (uiapplication_x*)userdata;
715 icon_x *icn = up->icon;
717 __extract_icon_data(data, icn, &icon, &resolution);
718 if (!icon && !resolution)
720 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
721 "app_icon, app_icon_section, app_icon_resolution) values " \
722 "('%q', '%q', '%q', '%q')", up->appid,
723 icon, (char*)data, resolution);
725 ret = __exec_query(query);
727 _LOGD("Package UiApp Localized Info DB Insert failed\n");
731 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
736 char query[MAX_QUERY_LEN] = {'\0'};
738 uiapplication_x *up = (uiapplication_x*)userdata;
739 image_x *image = up->image;
741 __extract_image_data(data, image, &lang, &img);
744 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
745 "app_image_section, app_image) values " \
746 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
748 ret = __exec_query(query);
750 _LOGD("Package UiApp image Info DB Insert failed\n");
755 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
760 char query[MAX_QUERY_LEN] = {'\0'};
762 serviceapplication_x *sp = (serviceapplication_x*)userdata;
763 label_x *lbl = sp->label;
764 icon_x *icn = sp->icon;
766 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
769 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
770 "app_label, app_icon) values " \
771 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
773 ret = __exec_query(query);
775 _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
778 static int __insert_ui_mainapp_info(manifest_x *mfx)
780 uiapplication_x *up = mfx->uiapplication;
782 char query[MAX_QUERY_LEN] = {'\0'};
785 snprintf(query, MAX_QUERY_LEN,
786 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
788 ret = __exec_query(query);
790 _LOGD("Package UiApp Info DB Insert Failed\n");
793 if (strcasecmp(up->mainapp, "True")==0)
794 mfx->mainapp_id = strdup(up->appid);
797 memset(query, '\0', MAX_QUERY_LEN);
800 if (mfx->mainapp_id == NULL){
801 if (mfx->uiapplication && mfx->uiapplication->appid) {
802 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
804 _LOGD("Not valid appid\n");
808 ret = __exec_query(query);
810 _LOGD("Package UiApp Info DB Insert Failed\n");
814 free((void *)mfx->uiapplication->mainapp);
815 mfx->uiapplication->mainapp= strdup("true");
816 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
819 memset(query, '\0', MAX_QUERY_LEN);
820 snprintf(query, MAX_QUERY_LEN,
821 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
822 ret = __exec_query(query);
824 _LOGD("Package Info DB update Failed\n");
830 /* _PRODUCT_LAUNCHING_ENHANCED_
831 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
833 static int __insert_uiapplication_info(manifest_x *mfx)
835 uiapplication_x *up = mfx->uiapplication;
837 char query[MAX_QUERY_LEN] = {'\0'};
840 snprintf(query, MAX_QUERY_LEN,
841 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
842 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
843 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
844 "app_preload, app_submode, app_submode_mainid, component_type, package, app_launch_mode) " \
845 "values('%s', '%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
851 PKGMGR_PARSER_EMPTY_STR,
853 PKGMGR_PARSER_EMPTY_STR,
859 __get_str(up->recentimage),
861 up->indicatordisplay,
862 __get_str(up->portraitimg),
863 __get_str(up->landscapeimg),
864 up->guestmode_visibility,
868 __get_str(up->submode_mainid),
873 ret = __exec_query(query);
875 _LOGD("Package UiApp Info DB Insert Failed\n");
879 memset(query, '\0', MAX_QUERY_LEN);
884 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
886 uiapplication_x *up = mfx->uiapplication;
887 category_x *ct = NULL;
889 char query[MAX_QUERY_LEN] = {'\0'};
895 snprintf(query, MAX_QUERY_LEN,
896 "insert into package_app_app_category(app_id, category) " \
897 "values('%s','%s')",\
898 up->appid, ct->name);
899 ret = __exec_query(query);
901 _LOGD("Package UiApp Category Info DB Insert Failed\n");
905 memset(query, '\0', MAX_QUERY_LEN);
912 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
914 uiapplication_x *up = mfx->uiapplication;
915 metadata_x *md = NULL;
917 char query[MAX_QUERY_LEN] = {'\0'};
924 snprintf(query, MAX_QUERY_LEN,
925 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
926 "values('%s','%s', '%s')",\
927 up->appid, md->key, md->value);
928 ret = __exec_query(query);
930 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
935 memset(query, '\0', MAX_QUERY_LEN);
942 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
944 uiapplication_x *up = mfx->uiapplication;
945 permission_x *pm = NULL;
947 char query[MAX_QUERY_LEN] = {'\0'};
953 snprintf(query, MAX_QUERY_LEN,
954 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
955 "values('%s','%s', '%s')",\
956 up->appid, pm->type, pm->value);
957 ret = __exec_query(query);
959 _LOGD("Package UiApp permission Info DB Insert Failed\n");
963 memset(query, '\0', MAX_QUERY_LEN);
970 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
972 uiapplication_x *up = mfx->uiapplication;
973 appcontrol_x *acontrol = NULL;
975 char query[MAX_QUERY_LEN] = {'\0'};
976 char buf[BUFSIZE] = {'\0'};
978 acontrol = up->appcontrol;
979 while (acontrol != NULL) {
980 snprintf(buf, BUFSIZE, "%s|%s|%s",\
981 acontrol->operation ? acontrol->operation : "NULL",
982 acontrol->uri ? acontrol->uri : "NULL",
983 acontrol->mime ? acontrol->mime : "NULL");
984 snprintf(query, MAX_QUERY_LEN,
985 "insert into package_app_app_control(app_id, app_control) " \
986 "values('%s', '%s')",\
988 ret = __exec_query(query);
990 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
993 memset(query, '\0', MAX_QUERY_LEN);
994 acontrol = acontrol->next;
1001 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1003 uiapplication_x *up = mfx->uiapplication;
1004 appsvc_x *asvc = NULL;
1005 operation_x *op = NULL;
1008 subapp_x *sub = NULL;
1010 char query[MAX_QUERY_LEN] = {'\0'};
1011 const char *operation = NULL;
1012 const char *mime = NULL;
1013 const char *uri = NULL;
1014 const char *subapp = NULL;
1020 op = asvc->operation;
1024 operation = op->name;
1041 snprintf(query, MAX_QUERY_LEN,
1042 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1043 "values('%s', '%s', '%s', '%s', '%s')",\
1050 ret = __exec_query(query);
1052 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1055 memset(query, '\0', MAX_QUERY_LEN);
1059 } while(ui != NULL);
1063 }while(sub != NULL);
1079 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1081 uiapplication_x *up = mfx->uiapplication;
1082 datashare_x *ds = NULL;
1083 request_x *rq = NULL;
1085 char query[MAX_QUERY_LEN] = {'\0'};
1094 snprintf(query, MAX_QUERY_LEN,
1095 "insert into package_app_share_request(app_id, data_share_request) " \
1096 "values('%s', '%s')",\
1097 up->appid, rq->text);
1098 ret = __exec_query(query);
1100 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1103 memset(query, '\0', MAX_QUERY_LEN);
1113 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1115 uiapplication_x *up = mfx->uiapplication;
1116 datashare_x *ds = NULL;
1117 define_x *df = NULL;
1118 allowed_x *al = NULL;
1120 char query[MAX_QUERY_LEN] = {'\0'};
1132 snprintf(query, MAX_QUERY_LEN,
1133 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1134 "values('%s', '%s', '%s')",\
1135 up->appid, df->path, al->text);
1136 ret = __exec_query(query);
1138 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1141 memset(query, '\0', MAX_QUERY_LEN);
1153 static int __insert_serviceapplication_info(manifest_x *mfx)
1155 serviceapplication_x *sp = mfx->serviceapplication;
1157 char query[MAX_QUERY_LEN] = {'\0'};
1160 snprintf(query, MAX_QUERY_LEN,
1161 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1162 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1163 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1164 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1165 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1166 ret = __exec_query(query);
1168 _LOGD("Package ServiceApp Info DB Insert Failed\n");
1172 memset(query, '\0', MAX_QUERY_LEN);
1177 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1179 serviceapplication_x *sp = mfx->serviceapplication;
1180 category_x *ct = NULL;
1182 char query[MAX_QUERY_LEN] = {'\0'};
1188 snprintf(query, MAX_QUERY_LEN,
1189 "insert into package_app_app_category(app_id, category) " \
1190 "values('%s','%s')",\
1191 sp->appid, ct->name);
1192 ret = __exec_query(query);
1194 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1198 memset(query, '\0', MAX_QUERY_LEN);
1205 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1207 serviceapplication_x *sp = mfx->serviceapplication;
1208 metadata_x *md = NULL;
1210 char query[MAX_QUERY_LEN] = {'\0'};
1217 snprintf(query, MAX_QUERY_LEN,
1218 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1219 "values('%s','%s', '%s')",\
1220 sp->appid, md->key, md->value);
1221 ret = __exec_query(query);
1223 _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1228 memset(query, '\0', MAX_QUERY_LEN);
1235 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1237 serviceapplication_x *sp = mfx->serviceapplication;
1238 permission_x *pm = NULL;
1240 char query[MAX_QUERY_LEN] = {'\0'};
1243 pm = sp->permission;
1246 snprintf(query, MAX_QUERY_LEN,
1247 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1248 "values('%s','%s', '%s')",\
1249 sp->appid, pm->type, pm->value);
1250 ret = __exec_query(query);
1252 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1256 memset(query, '\0', MAX_QUERY_LEN);
1263 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1265 serviceapplication_x *sp = mfx->serviceapplication;
1266 appcontrol_x *acontrol = NULL;
1268 char query[MAX_QUERY_LEN] = {'\0'};
1269 char buf[BUFSIZE] = {'\0'};
1270 while (sp != NULL) {
1271 acontrol = sp->appcontrol;
1272 while (acontrol != NULL) {
1273 snprintf(buf, BUFSIZE, "%s|%s|%s",
1274 acontrol->operation ? acontrol->operation : "NULL",
1275 acontrol->uri ? acontrol->uri : "NULL",
1276 acontrol->mime ? acontrol->mime : "NULL");
1277 snprintf(query, MAX_QUERY_LEN,
1278 "insert into package_app_app_control(app_id, app_control) " \
1279 "values('%s', '%s')",\
1281 ret = __exec_query(query);
1283 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1286 memset(query, '\0', MAX_QUERY_LEN);
1287 acontrol = acontrol->next;
1294 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1296 serviceapplication_x *sp = mfx->serviceapplication;
1297 appsvc_x *asvc = NULL;
1299 char query[MAX_QUERY_LEN] = {'\0'};
1300 operation_x *op = NULL;
1303 subapp_x *sub = NULL;
1304 const char *operation = NULL;
1305 const char *mime = NULL;
1306 const char *uri = NULL;
1307 const char *subapp = NULL;
1313 op = asvc->operation;
1317 operation = op->name;
1333 snprintf(query, MAX_QUERY_LEN,
1334 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1335 "values('%s', '%s', '%s', '%s', '%s')",\
1341 ret = __exec_query(query);
1343 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1346 memset(query, '\0', MAX_QUERY_LEN);
1350 } while(ui != NULL);
1354 }while(sub != NULL);
1370 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx)
1372 serviceapplication_x *sp = mfx->serviceapplication;
1373 datacontrol_x *dc = NULL;
1375 char query[MAX_QUERY_LEN] = {'\0'};
1379 dc = sp->datacontrol;
1382 snprintf(query, MAX_QUERY_LEN,
1383 "insert into package_app_data_control(app_id, providerid, access, type) " \
1384 "values('%s', '%s', '%s', '%s')",\
1385 mfx->serviceapplication->appid,
1390 ret = __exec_query(query);
1392 _LOGD("Package ServiceApp Data Control DB Insert Failed\n");
1395 memset(query, '\0', MAX_QUERY_LEN);
1403 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1405 serviceapplication_x *sp = mfx->serviceapplication;
1406 datashare_x *ds = NULL;
1407 request_x *rq = NULL;
1409 char query[MAX_QUERY_LEN] = {'\0'};
1418 snprintf(query, MAX_QUERY_LEN,
1419 "insert into package_app_share_request(app_id, data_share_request) " \
1420 "values('%s', '%s')",\
1421 sp->appid, rq->text);
1422 ret = __exec_query(query);
1424 _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1427 memset(query, '\0', MAX_QUERY_LEN);
1439 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1441 serviceapplication_x *sp = mfx->serviceapplication;
1442 datashare_x *ds = NULL;
1443 define_x *df = NULL;
1444 allowed_x *al = NULL;
1446 char query[MAX_QUERY_LEN] = {'\0'};
1458 snprintf(query, MAX_QUERY_LEN,
1459 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1460 "values('%s', '%s', '%s')",\
1461 sp->appid, df->path, al->text);
1462 ret = __exec_query(query);
1464 _LOGD("Package App Share Allowed DB Insert Failed\n");
1467 memset(query, '\0', MAX_QUERY_LEN);
1479 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1481 label_x *lbl = mfx->label;
1482 license_x *lcn = mfx->license;
1483 icon_x *icn = mfx->icon;
1484 description_x *dcn = mfx->description;
1485 author_x *ath = mfx->author;
1486 uiapplication_x *up = mfx->uiapplication;
1487 uiapplication_x *up_icn = mfx->uiapplication;
1488 uiapplication_x *up_image = mfx->uiapplication;
1489 serviceapplication_x *sp = mfx->serviceapplication;
1490 privileges_x *pvs = NULL;
1491 privilege_x *pv = NULL;
1492 char query[MAX_QUERY_LEN] = { '\0' };
1493 char root[MAX_QUERY_LEN] = { '\0' };
1497 const char *auth_name = NULL;
1498 const char *auth_email = NULL;
1499 const char *auth_href = NULL;
1500 const char *apps_path = NULL;
1502 GList *pkglocale = NULL;
1503 GList *applocale = NULL;
1504 GList *appicon = NULL;
1505 GList *appimage = NULL;
1509 auth_name = ath->text;
1511 auth_email = ath->email;
1513 auth_href = ath->href;
1515 /*Insert in the package_cert_info CERT_DB*/
1516 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1517 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1518 if (ret != PMINFO_R_OK) {
1519 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1520 _LOGE("Cert Info DB create handle failed\n");
1523 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1524 if (ret != PMINFO_R_OK) {
1525 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1526 _LOGE("Cert Info DB Insert Failed\n");
1530 /*Insert in the package_info DB*/
1532 type = strdup(mfx->type);
1534 type = strdup("rpm");
1535 /*Insert in the package_info DB*/
1537 path = strdup(mfx->root_path);
1539 if (strcmp(type,"rpm")==0) {
1540 apps_path = tzplatform_getenv(TZ_SYS_RO_APP);
1541 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1543 apps_path = tzplatform_getenv(TZ_USER_APP);
1544 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1546 path = strdup(root);
1548 snprintf(query, MAX_QUERY_LEN,
1549 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1550 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1551 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
1552 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1556 __get_str(mfx->installlocation),
1557 __get_str(mfx->package_size),
1563 mfx->nodisplay_setting,
1565 __get_str(auth_name),
1566 __get_str(auth_email),
1567 __get_str(auth_href),
1568 mfx->installed_time,
1569 mfx->installed_storage,
1570 __get_str(mfx->storeclient_id),
1572 __get_str(mfx->package_url),
1574 __get_str(mfx->csc_path));
1575 /*If package dont have main_package tag, this package is main package.*/
1576 if (mfx->main_package == NULL) {
1577 ret = __exec_query(query);
1579 _LOGD("Package Info DB Insert Failed\n");
1591 /*If package has main_package tag, this package is sub package(ug, efl).
1592 skip __exec_query for package_info and change pkgid with main_package*/
1593 memset(root, '\0', MAX_QUERY_LEN);
1594 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->main_package);
1595 if (access(root, F_OK) == 0) {
1596 free((void *)mfx->package);
1597 mfx->package = strdup(mfx->main_package);
1599 _LOGE("main package[%s] is not installed\n", root);
1612 /*Insert in the package_privilege_info DB*/
1613 pvs = mfx->privileges;
1614 while (pvs != NULL) {
1615 pv = pvs->privilege;
1616 while (pv != NULL) {
1617 memset(query, '\0', MAX_QUERY_LEN);
1618 snprintf(query, MAX_QUERY_LEN,
1619 "insert into package_privilege_info(package, privilege) " \
1620 "values('%s','%s')",\
1621 mfx->package, pv->text);
1622 ret = __exec_query(query);
1624 _LOGD("Package Privilege Info DB Insert Failed\n");
1633 ret = __insert_ui_mainapp_info(mfx);
1638 /*Insert the package locale*/
1639 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1640 /*remove duplicated data in pkglocale*/
1641 __trimfunc(pkglocale);
1643 /*Insert the app locale info */
1646 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1651 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1654 /*remove duplicated data in applocale*/
1655 __trimfunc(applocale);
1657 /*Insert the app icon info */
1658 while(up_icn != NULL)
1660 appicon = __create_icon_list(appicon, up_icn->icon);
1661 up_icn = up_icn->next;
1663 /*remove duplicated data in appicon*/
1664 __trimfunc(appicon);
1666 /*Insert the image info */
1667 while(up_image != NULL)
1669 appimage = __create_image_list(appimage, up_image->image);
1670 up_image = up_image->next;
1672 /*remove duplicated data in appimage*/
1673 __trimfunc(appimage);
1675 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1677 /*g_list_foreach(applocale, __printfunc, NULL);*/
1679 /*package locale info, it is only for main package.*/
1680 if (mfx->main_package == NULL)
1681 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1683 /*native app locale info*/
1684 up = mfx->uiapplication;
1687 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1690 /*agent app locale info*/
1691 sp = mfx->serviceapplication;
1694 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1698 /*app icon locale info*/
1699 up_icn = mfx->uiapplication;
1700 while(up_icn != NULL)
1702 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1703 up_icn = up_icn->next;
1707 up_image = mfx->uiapplication;
1708 while(up_image != NULL)
1710 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1711 up_image = up_image->next;
1714 g_list_free(pkglocale);
1716 g_list_free(applocale);
1718 g_list_free(appicon);
1720 g_list_free(appimage);
1723 /*Insert in the package_app_info DB*/
1724 ret = __insert_uiapplication_info(mfx);
1727 ret = __insert_serviceapplication_info(mfx);
1730 /*Insert in the package_app_app_control DB*/
1731 ret = __insert_uiapplication_appcontrol_info(mfx);
1734 ret = __insert_serviceapplication_appcontrol_info(mfx);
1738 /*Insert in the package_app_app_category DB*/
1739 ret = __insert_uiapplication_appcategory_info(mfx);
1742 ret = __insert_serviceapplication_appcategory_info(mfx);
1746 /*Insert in the package_app_app_metadata DB*/
1747 ret = __insert_uiapplication_appmetadata_info(mfx);
1750 ret = __insert_serviceapplication_appmetadata_info(mfx);
1754 /*Insert in the package_app_app_permission DB*/
1755 ret = __insert_uiapplication_apppermission_info(mfx);
1758 ret = __insert_serviceapplication_apppermission_info(mfx);
1762 /*Insert in the package_app_app_svc DB*/
1763 ret = __insert_uiapplication_appsvc_info(mfx);
1766 ret = __insert_serviceapplication_appsvc_info(mfx);
1770 /*Insert in the package_app_share_allowed DB*/
1771 ret = __insert_uiapplication_share_allowed_info(mfx);
1774 ret = __insert_serviceapplication_share_allowed_info(mfx);
1778 /*Insert in the package_app_share_request DB*/
1779 ret = __insert_uiapplication_share_request_info(mfx);
1782 ret = __insert_serviceapplication_share_request_info(mfx);
1786 /*Insert in the package_app_data_control DB*/
1787 ret = __insert_serviceapplication_datacontrol_info(mfx);
1795 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1797 char query[MAX_QUERY_LEN] = { '\0' };
1799 memset(query, '\0', MAX_QUERY_LEN);
1800 snprintf(query, MAX_QUERY_LEN,
1801 "delete from %s where app_id='%s'", db_table, appid);
1802 ret = __exec_query(query);
1804 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1810 static int __delete_subpkg_info_from_db(char *appid)
1814 ret = __delete_appinfo_from_db("package_app_info", appid);
1817 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1820 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1823 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1826 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1829 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1832 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1835 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1838 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1841 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1844 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1847 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1854 static int __delete_subpkg_from_db(manifest_x *mfx)
1856 char query[MAX_QUERY_LEN] = { '\0' };
1857 char *error_message = NULL;
1859 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1861 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1862 _LOGE("Don't execute query = %s error message = %s\n", query,
1864 sqlite3_free(error_message);
1867 sqlite3_free(error_message);
1872 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1874 char query[MAX_QUERY_LEN] = { '\0' };
1876 uiapplication_x *up = mfx->uiapplication;
1877 serviceapplication_x *sp = mfx->serviceapplication;
1878 /*Delete from cert table*/
1879 if (uid != GLOBAL_USER)
1880 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1882 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1884 _LOGD("Cert Info DB Delete Failed\n");
1888 /*Delete from Package Info DB*/
1889 snprintf(query, MAX_QUERY_LEN,
1890 "delete from package_info where package='%s'", mfx->package);
1891 ret = __exec_query(query);
1893 _LOGD("Package Info DB Delete Failed\n");
1896 memset(query, '\0', MAX_QUERY_LEN);
1898 /*Delete from Package Localized Info*/
1899 snprintf(query, MAX_QUERY_LEN,
1900 "delete from package_localized_info where package='%s'", mfx->package);
1901 ret = __exec_query(query);
1903 _LOGD("Package Localized Info DB Delete Failed\n");
1907 /*Delete from Package Privilege Info*/
1908 snprintf(query, MAX_QUERY_LEN,
1909 "delete from package_privilege_info where package='%s'", mfx->package);
1910 ret = __exec_query(query);
1912 _LOGD("Package Privilege Info DB Delete Failed\n");
1916 while (up != NULL) {
1917 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1920 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1923 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
1926 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
1929 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
1932 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
1935 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
1938 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
1941 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
1944 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
1947 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
1950 ret = __delete_appinfo_from_db("package_app_data_control", up->appid);
1956 while (sp != NULL) {
1957 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
1960 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
1963 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
1966 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
1969 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
1972 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
1975 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
1978 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
1981 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
1984 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
1987 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
1990 ret = __delete_appinfo_from_db("package_app_data_control", sp->appid);
1996 /* if main package has sub pkg, delete sub pkg data*/
1997 __delete_subpkg_from_db(mfx);
2002 static int __update_preload_condition_in_db()
2005 char query[MAX_QUERY_LEN] = {'\0'};
2007 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2009 ret = __exec_query(query);
2011 _LOGD("Package preload_condition update failed\n");
2016 API int pkgmgr_parser_initialize_db(void)
2020 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2022 _LOGD("package info DB initialization failed\n");
2025 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2027 _LOGD("package localized info DB initialization failed\n");
2030 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2032 _LOGD("package app app privilege DB initialization failed\n");
2035 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2037 _LOGD("package app info DB initialization failed\n");
2040 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2042 _LOGD("package app localized info DB initialization failed\n");
2045 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2047 _LOGD("package app icon localized info DB initialization failed\n");
2050 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2052 _LOGD("package app image info DB initialization failed\n");
2055 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2057 _LOGD("package app app control DB initialization failed\n");
2060 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2062 _LOGD("package app app category DB initialization failed\n");
2065 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2067 _LOGD("package app app category DB initialization failed\n");
2070 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2072 _LOGD("package app app permission DB initialization failed\n");
2075 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2077 _LOGD("package app app svc DB initialization failed\n");
2080 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2082 _LOGD("package app share allowed DB initialization failed\n");
2085 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2087 _LOGD("package app share request DB initialization failed\n");
2090 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2092 _LOGD("package app data control DB initialization failed\n");
2096 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2098 _LOGD("package cert info DB initialization failed\n");
2101 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2103 _LOGD("package cert index info DB initialization failed\n");
2107 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_RESOURCE_INFO);
2109 _LOGD("package resource info DB initialization failed\n");
2112 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_RESOURCE_DATA);
2114 _LOGD("package resource data DB initialization failed\n");
2121 static int parserdb_change_perm(const char *db_file, uid_t uid)
2124 char journal_file[BUFSIZE];
2127 struct passwd *userinfo = NULL;
2128 files[0] = (char *)db_file;
2129 files[1] = journal_file;
2135 if(getuid() != OWNER_ROOT) //At this time we should be root to apply this
2137 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2138 userinfo = getpwuid(uid);
2140 _LOGE("FAIL: user %d doesn't exist", uid);
2143 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2145 for (i = 0; files[i]; i++) {
2146 ret = chown(files[i], uid, userinfo->pw_gid);
2147 SET_SMACK_LABEL(files[i],uid)
2149 strerror_r(errno, buf, sizeof(buf));
2150 _LOGD("FAIL : chown %s %d.%d, because %s", db_file, uid, userinfo->pw_gid, buf);
2154 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
2156 strerror_r(errno, buf, sizeof(buf));
2157 _LOGD("FAIL : chmod %s 0664, because %s", db_file, buf);
2164 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2168 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2170 _LOGD("Manifest DB creation Failed\n");
2175 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid));
2177 _LOGD("Cert DB creation Failed\n");
2180 if( 0 != parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
2181 _LOGD("Failed to change cert db permission\n");
2183 if( 0 != parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2184 _LOGD("Failed to change parser db permission\n");
2189 void pkgmgr_parser_close_db()
2191 sqlite3_close(pkgmgr_parser_db);
2192 sqlite3_close(pkgmgr_cert_db);
2196 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2198 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2200 _LOGD("manifest pointer is NULL\n");
2204 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2206 _LOGD("Failed to open DB\n");
2209 ret = pkgmgr_parser_initialize_db();
2212 /*Begin transaction*/
2213 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2214 if (ret != SQLITE_OK) {
2215 _LOGD("Failed to begin transaction\n");
2219 _LOGD("Transaction Begin\n");
2220 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2222 _LOGD("Insert into DB failed. Rollback now\n");
2223 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2226 /*Commit transaction*/
2227 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2228 if (ret != SQLITE_OK) {
2229 _LOGD("Failed to commit transaction. Rollback now\n");
2230 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2234 _LOGD("Transaction Commit and End\n");
2236 pkgmgr_parser_close_db();
2240 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2242 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2244 _LOGD("manifest pointer is NULL\n");
2248 ret = pkgmgr_parser_check_and_create_db(uid);
2250 _LOGD("Failed to open DB\n");
2253 ret = pkgmgr_parser_initialize_db();
2256 /*Begin transaction*/
2257 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2258 if (ret != SQLITE_OK) {
2259 _LOGD("Failed to begin transaction\n");
2263 _LOGD("Transaction Begin\n");
2264 ret = __insert_manifest_info_in_db(mfx, uid);
2266 _LOGD("Insert into DB failed. Rollback now\n");
2267 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2270 /*Commit transaction*/
2271 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2272 if (ret != SQLITE_OK) {
2273 _LOGD("Failed to commit transaction. Rollback now\n");
2274 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2278 _LOGD("Transaction Commit and End\n");
2280 pkgmgr_parser_close_db();
2284 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2287 _LOGD("manifest pointer is NULL\n");
2291 ret = pkgmgr_parser_check_and_create_db(uid);
2293 _LOGD("Failed to open DB\n");
2296 ret = pkgmgr_parser_initialize_db();
2299 /*Preserve guest mode visibility*/
2300 __preserve_guestmode_visibility_value( mfx);
2301 /*Begin transaction*/
2302 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2303 if (ret != SQLITE_OK) {
2304 _LOGD("Failed to begin transaction\n");
2308 _LOGD("Transaction Begin\n");
2309 ret = __delete_manifest_info_from_db(mfx, uid);
2311 _LOGD("Delete from DB failed. Rollback now\n");
2312 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2315 ret = __insert_manifest_info_in_db(mfx, uid);
2317 _LOGD("Insert into DB failed. Rollback now\n");
2318 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2322 /*Commit transaction*/
2323 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2324 if (ret != SQLITE_OK) {
2325 _LOGD("Failed to commit transaction. Rollback now\n");
2326 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2330 _LOGD("Transaction Commit and End\n");
2332 pkgmgr_parser_close_db();
2336 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2338 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2341 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2344 _LOGD("manifest pointer is NULL\n");
2348 ret = pkgmgr_parser_check_and_create_db(uid);
2350 _LOGD("Failed to open DB\n");
2353 /*Begin transaction*/
2354 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2355 if (ret != SQLITE_OK) {
2356 _LOGD("Failed to begin transaction\n");
2360 _LOGD("Transaction Begin\n");
2361 ret = __delete_manifest_info_from_db(mfx, uid);
2363 _LOGD("Delete from DB failed. Rollback now\n");
2364 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2367 /*Commit transaction*/
2368 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2369 if (ret != SQLITE_OK) {
2370 _LOGD("Failed to commit transaction, Rollback now\n");
2371 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2375 _LOGD("Transaction Commit and End\n");
2377 pkgmgr_parser_close_db();
2381 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2383 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2386 API int pkgmgr_parser_update_preload_info_in_db()
2389 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2391 _LOGD("Failed to open DB\n");
2394 /*Begin transaction*/
2395 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2396 if (ret != SQLITE_OK) {
2397 _LOGD("Failed to begin transaction\n");
2401 _LOGD("Transaction Begin\n");
2402 ret = __update_preload_condition_in_db();
2404 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2405 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2408 /*Commit transaction*/
2409 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2410 if (ret != SQLITE_OK) {
2411 _LOGD("Failed to commit transaction, Rollback now\n");
2412 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2416 _LOGD("Transaction Commit and End\n");
2418 pkgmgr_parser_close_db();
2422 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2425 ret = pkgmgr_parser_check_and_create_db(uid);
2427 _LOGD("Failed to open DB\n");
2430 /*Begin transaction*/
2431 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2432 if (ret != SQLITE_OK) {
2433 _LOGD("Failed to begin transaction\n");
2437 _LOGD("Transaction Begin\n");
2438 ret = __update_preload_condition_in_db();
2440 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2441 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2444 /*Commit transaction*/
2445 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2446 if (ret != SQLITE_OK) {
2447 _LOGD("Failed to commit transaction, Rollback now\n");
2448 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2452 _LOGD("Transaction Commit and End\n");
2454 pkgmgr_parser_close_db();