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) \
57 if (smack_setlabel((x), "System::Shared", SMACK_LABEL_ACCESS)) \
58 _LOGE("failed chsmack -a \"System::Shared\" %s", x); \
60 _LOGD("chsmack -a \"System::Shared\" %s", x); \
63 sqlite3 *pkgmgr_parser_db;
64 sqlite3 *pkgmgr_cert_db;
67 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
68 "(package text primary key not null, " \
69 "package_type text DEFAULT 'rpm', " \
70 "package_version text, " \
71 "package_api_version text, " \
72 "install_location text, " \
73 "package_size text, " \
74 "package_removable text DEFAULT 'true', " \
75 "package_preload text DEFAULT 'false', " \
76 "package_readonly text DEFAULT 'false', " \
77 "package_update text DEFAULT 'false', " \
78 "package_appsetting text DEFAULT 'false', " \
79 "package_nodisplay text DEFAULT 'false', " \
80 "package_system text DEFAULT 'false', " \
81 "author_name text, " \
82 "author_email text, " \
84 "installed_time text," \
85 "installed_storage text," \
86 "storeclient_id text," \
92 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
93 "(package text not null, " \
94 "package_locale text DEFAULT 'No Locale', " \
95 "package_label text, " \
96 "package_icon text, " \
97 "package_description text, " \
98 "package_license text, " \
100 "PRIMARY KEY(package, package_locale), " \
101 "FOREIGN KEY(package) " \
102 "REFERENCES package_info(package) " \
105 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
106 "(package text not null, " \
107 "privilege text not null, " \
108 "PRIMARY KEY(package, privilege) " \
109 "FOREIGN KEY(package) " \
110 "REFERENCES package_info(package) " \
113 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
114 "(app_id text primary key not null, " \
115 "app_component text, " \
117 "app_nodisplay text DEFAULT 'false', " \
119 "app_onboot text DEFAULT 'false', " \
120 "app_multiple text DEFAULT 'false', " \
121 "app_autorestart text DEFAULT 'false', " \
122 "app_taskmanage text DEFAULT 'false', " \
123 "app_enabled text DEFAULT 'true', " \
124 "app_hwacceleration text DEFAULT 'use-system-setting', " \
125 "app_screenreader text DEFAULT 'use-system-setting', " \
126 "app_mainapp text, " \
127 "app_recentimage text, " \
128 "app_launchcondition text, " \
129 "app_indicatordisplay text DEFAULT 'true', " \
130 "app_portraitimg text, " \
131 "app_landscapeimg text, " \
132 "app_guestmodevisibility text DEFAULT 'true', " \
133 "app_permissiontype text DEFAULT 'normal', " \
134 "app_preload text DEFAULT 'false', " \
135 "app_submode text DEFAULT 'false', " \
136 "app_submode_mainid text, " \
137 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
138 "component_type text, " \
139 "package text not null, " \
140 "FOREIGN KEY(package) " \
141 "REFERENCES package_info(package) " \
144 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
145 "(app_id text not null, " \
146 "app_locale text DEFAULT 'No Locale', " \
149 "PRIMARY KEY(app_id,app_locale) " \
150 "FOREIGN KEY(app_id) " \
151 "REFERENCES package_app_info(app_id) " \
154 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
155 "(app_id text not null, " \
157 "app_icon_section text, " \
158 "app_icon_resolution text, " \
159 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
160 "FOREIGN KEY(app_id) " \
161 "REFERENCES package_app_info(app_id) " \
164 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
165 "(app_id text not null, " \
166 "app_locale text DEFAULT 'No Locale', " \
167 "app_image_section text, " \
169 "PRIMARY KEY(app_id,app_image_section) " \
170 "FOREIGN KEY(app_id) " \
171 "REFERENCES package_app_info(app_id) " \
174 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
175 "(app_id text not null, " \
176 "app_control text not null, " \
177 "PRIMARY KEY(app_id,app_control) " \
178 "FOREIGN KEY(app_id) " \
179 "REFERENCES package_app_info(app_id) " \
182 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
183 "(app_id text not null, " \
184 "operation text not null, " \
185 "uri_scheme text, " \
187 "subapp_name text, " \
188 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
189 "FOREIGN KEY(app_id) " \
190 "REFERENCES package_app_info(app_id) " \
193 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
194 "(app_id text not null, " \
195 "category text not null, " \
196 "PRIMARY KEY(app_id,category) " \
197 "FOREIGN KEY(app_id) " \
198 "REFERENCES package_app_info(app_id) " \
201 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
202 "(app_id text not null, " \
203 "md_key text not null, " \
204 "md_value text not null, " \
205 "PRIMARY KEY(app_id, md_key, md_value) " \
206 "FOREIGN KEY(app_id) " \
207 "REFERENCES package_app_info(app_id) " \
210 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
211 "(app_id text not null, " \
212 "pm_type text not null, " \
213 "pm_value text not null, " \
214 "PRIMARY KEY(app_id, pm_type, pm_value) " \
215 "FOREIGN KEY(app_id) " \
216 "REFERENCES package_app_info(app_id) " \
219 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
220 "(app_id text not null, " \
221 "data_share_path text not null, " \
222 "data_share_allowed text not null, " \
223 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
224 "FOREIGN KEY(app_id) " \
225 "REFERENCES package_app_info(app_id) " \
228 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
229 "(app_id text not null, " \
230 "data_share_request text not null, " \
231 "PRIMARY KEY(app_id,data_share_request) " \
232 "FOREIGN KEY(app_id) " \
233 "REFERENCES package_app_info(app_id) " \
236 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
237 "(cert_info text not null, " \
238 "cert_id integer, " \
239 "cert_ref_count integer, " \
240 "PRIMARY KEY(cert_id)) "
242 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
243 "(package text not null, " \
244 "author_root_cert integer, " \
245 "author_im_cert integer, " \
246 "author_signer_cert integer, " \
247 "dist_root_cert integer, " \
248 "dist_im_cert integer, " \
249 "dist_signer_cert integer, " \
250 "dist2_root_cert integer, " \
251 "dist2_im_cert integer, " \
252 "dist2_signer_cert integer, " \
253 "PRIMARY KEY(package)) "
255 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
256 "(app_id text not null, " \
257 "providerid text not null, " \
258 "access text not null, " \
259 "type text not null, " \
260 "PRIMARY KEY(app_id, providerid, access, type) " \
261 "FOREIGN KEY(app_id) " \
262 "REFERENCES package_app_info(app_id) " \
264 #define QUERY_CREATE_TABLE_PACKAGE_RESOURCE_INFO "CREATE TABLE IF NOT EXISTS package_resource_info" \
265 "(pkg_id text NOT NULL," \
266 "group_folder text NOT NULL," \
267 "group_type text NOT NULL," \
268 "PRIMARY KEY(pkg_id, group_type))"
270 #define QUERY_CREATE_TABLE_PACKAGE_RESOURCE_DATA "CREATE TABLE IF NOT EXISTS package_resource_data" \
271 "(id integer REFERENCES package_resource_info(rowid)," \
272 "node_folder text NOT NULL," \
273 "attr_name text NOT NULL," \
274 "attr_value test NOT NULL," \
275 "PRIMARY KEY(id, node_folder, attr_name))"
277 static int __insert_uiapplication_info(manifest_x *mfx);
278 static int __insert_serviceapplication_info(manifest_x *mfx);
279 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
280 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
281 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
282 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
283 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
284 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
285 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
286 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
287 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
288 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
289 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
290 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
291 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx);
292 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx);
293 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
294 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
295 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
296 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
297 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
298 static int __delete_subpkg_info_from_db(char *appid);
299 static int __delete_appinfo_from_db(char *db_table, const char *appid);
300 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
301 static int __exec_query(char *query);
302 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
303 char **label, char **license, char **icon, char **description, char **author);
304 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
305 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
306 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
307 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
308 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
309 static int __parserdb_change_perm(const char *db_file, uid_t uid);
311 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
314 __delete_subpkg_info_from_db(coltxt[0]);
319 static char *__get_str(const char *str)
323 return PKGMGR_PARSER_EMPTY_STR;
329 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
334 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
335 if (ret != SQLITE_OK) {
336 _LOGD("connect db [%s] failed!\n", db_path);
344 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
346 manifest_x *mfx = (manifest_x *)data;
350 uiapplication_x *uiapp = NULL;
351 for(i = 0; i < ncols; i++)
353 uiapp = mfx->uiapplication;
354 if (strcmp(colname[i], "app_id") == 0) {
356 appid = strdup(coltxt[i]);
357 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
359 status = strdup(coltxt[i]);
363 _LOGD("app id is NULL\n");
366 /*update guest mode visibility*/
367 for (; uiapp != NULL; uiapp = uiapp->next) {
368 if (strcmp(uiapp->appid, appid) == 0) {
369 free((void *)uiapp->guestmode_visibility);
370 uiapp->guestmode_visibility = strdup(status);
386 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
388 char *error_message = NULL;
389 char query[MAX_QUERY_LEN] = {'\0'};
390 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
392 sqlite3_exec(pkgmgr_parser_db, query,
393 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
394 _LOGD("Don't execute query = %s error message = %s\n",
395 query, error_message);
396 sqlite3_free(error_message);
401 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
403 char *error_message = NULL;
405 sqlite3_exec(db_handle, db_query,
406 NULL, NULL, &error_message)) {
407 _LOGD("Don't execute query = %s error message = %s\n",
408 db_query, error_message);
409 sqlite3_free(error_message);
412 sqlite3_free(error_message);
416 static int __exec_query(char *query)
418 char *error_message = NULL;
420 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
421 _LOGD("Don't execute query = %s error message = %s\n", query,
423 sqlite3_free(error_message);
426 sqlite3_free(error_message);
430 static int __exec_query_no_msg(char *query)
432 char *error_message = NULL;
434 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
435 sqlite3_free(error_message);
438 sqlite3_free(error_message);
442 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
448 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
454 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
460 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
466 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
472 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
479 static GList *__create_icon_list(GList *locale, icon_x *icn)
484 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
490 static GList *__create_image_list(GList *locale, image_x *image)
495 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
501 static void __printfunc(gpointer data, gpointer userdata)
503 _LOGD("%s ", (char*)data);
506 static void __trimfunc(GList* trim_list)
508 char *trim_data = NULL;
512 list = g_list_first(trim_list);
515 trim_data = (char *)list->data;
518 if (strcmp(trim_data, prev) == 0) {
519 trim_list = g_list_remove(trim_list, trim_data);
520 list = g_list_first(trim_list);
529 list = g_list_next(list);
533 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
535 if (a == NULL || b == NULL)
537 if (strcmp((char*)a, (char*)b) == 0)
539 if (strcmp((char*)a, (char*)b) < 0)
541 if (strcmp((char*)a, (char*)b) > 0)
546 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
547 char **label, char **license, char **icon, char **description, char **author)
552 if (strcmp(lbl->lang, (char *)data) == 0) {
553 *label = (char*)lbl->text;
562 if (strcmp(lcn->lang, (char *)data) == 0) {
563 *license = (char*)lcn->text;
572 if (strcmp(icn->lang, (char *)data) == 0) {
573 *icon = (char*)icn->text;
582 if (strcmp(dcn->lang, (char *)data) == 0) {
583 *description = (char*)dcn->text;
592 if (strcmp(ath->lang, (char *)data) == 0) {
593 *author = (char*)ath->text;
602 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
607 if (strcmp(icn->section, (char *)data) == 0) {
608 *icon = (char*)icn->text;
609 *resolution = (char*)icn->resolution;
617 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
621 if (image->section) {
622 if (strcmp(image->section, (char *)data) == 0) {
623 *lang = (char*)image->lang;
624 *img = (char*)image->text;
632 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
637 char *description = NULL;
638 char *license = NULL;
640 char query[MAX_QUERY_LEN] = {'\0'};
642 manifest_x *mfx = (manifest_x *)userdata;
643 label_x *lbl = mfx->label;
644 license_x *lcn = mfx->license;
645 icon_x *icn = mfx->icon;
646 description_x *dcn = mfx->description;
647 author_x *ath = mfx->author;
649 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
650 if (!label && !description && !icon && !license && !author)
653 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
654 "package_label, package_icon, package_description, package_license, package_author) values " \
655 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
660 __get_str(description),
664 ret = __exec_query(query);
666 _LOGD("Package Localized Info DB Insert failed\n");
669 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
674 char query[MAX_QUERY_LEN] = {'\0'};
676 uiapplication_x *up = (uiapplication_x*)userdata;
677 label_x *lbl = up->label;
678 icon_x *icn = up->icon;
680 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
683 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
684 "app_label, app_icon) values " \
685 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
687 ret = __exec_query(query);
689 _LOGD("Package UiApp Localized Info DB Insert failed\n");
691 /*insert ui app locale info to pkg locale to get mainapp data */
692 if (strcasecmp(up->mainapp, "true")==0) {
693 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
694 "package_label, package_icon, package_description, package_license, package_author) values " \
695 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
700 PKGMGR_PARSER_EMPTY_STR,
701 PKGMGR_PARSER_EMPTY_STR,
702 PKGMGR_PARSER_EMPTY_STR);
704 ret = __exec_query_no_msg(query);
707 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
708 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
709 ret = __exec_query_no_msg(query);
714 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
718 char *resolution = NULL;
719 char query[MAX_QUERY_LEN] = {'\0'};
721 uiapplication_x *up = (uiapplication_x*)userdata;
722 icon_x *icn = up->icon;
724 __extract_icon_data(data, icn, &icon, &resolution);
725 if (!icon && !resolution)
727 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
728 "app_icon, app_icon_section, app_icon_resolution) values " \
729 "('%q', '%q', '%q', '%q')", up->appid,
730 icon, (char*)data, resolution);
732 ret = __exec_query(query);
734 _LOGD("Package UiApp Localized Info DB Insert failed\n");
738 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
743 char query[MAX_QUERY_LEN] = {'\0'};
745 uiapplication_x *up = (uiapplication_x*)userdata;
746 image_x *image = up->image;
748 __extract_image_data(data, image, &lang, &img);
751 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
752 "app_image_section, app_image) values " \
753 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
755 ret = __exec_query(query);
757 _LOGD("Package UiApp image Info DB Insert failed\n");
762 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
767 char query[MAX_QUERY_LEN] = {'\0'};
769 serviceapplication_x *sp = (serviceapplication_x*)userdata;
770 label_x *lbl = sp->label;
771 icon_x *icn = sp->icon;
773 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
776 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
777 "app_label, app_icon) values " \
778 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
780 ret = __exec_query(query);
782 _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
785 static int __insert_ui_mainapp_info(manifest_x *mfx)
787 uiapplication_x *up = mfx->uiapplication;
789 char query[MAX_QUERY_LEN] = {'\0'};
792 snprintf(query, MAX_QUERY_LEN,
793 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
795 ret = __exec_query(query);
797 _LOGD("Package UiApp Info DB Insert Failed\n");
800 if (strcasecmp(up->mainapp, "True")==0)
801 mfx->mainapp_id = strdup(up->appid);
804 memset(query, '\0', MAX_QUERY_LEN);
807 if (mfx->mainapp_id == NULL){
808 if (mfx->uiapplication && mfx->uiapplication->appid) {
809 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
811 _LOGD("Not valid appid\n");
815 ret = __exec_query(query);
817 _LOGD("Package UiApp Info DB Insert Failed\n");
821 free((void *)mfx->uiapplication->mainapp);
822 mfx->uiapplication->mainapp= strdup("true");
823 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
826 memset(query, '\0', MAX_QUERY_LEN);
827 snprintf(query, MAX_QUERY_LEN,
828 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
829 ret = __exec_query(query);
831 _LOGD("Package Info DB update Failed\n");
837 /* _PRODUCT_LAUNCHING_ENHANCED_
838 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
840 static int __insert_uiapplication_info(manifest_x *mfx)
842 uiapplication_x *up = mfx->uiapplication;
844 char query[MAX_QUERY_LEN] = {'\0'};
847 snprintf(query, MAX_QUERY_LEN,
848 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
849 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
850 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
851 "app_preload, app_submode, app_submode_mainid, component_type, package, app_launch_mode) " \
852 "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')",\
858 PKGMGR_PARSER_EMPTY_STR,
860 PKGMGR_PARSER_EMPTY_STR,
866 __get_str(up->recentimage),
868 up->indicatordisplay,
869 __get_str(up->portraitimg),
870 __get_str(up->landscapeimg),
871 up->guestmode_visibility,
875 __get_str(up->submode_mainid),
880 ret = __exec_query(query);
882 _LOGD("Package UiApp Info DB Insert Failed\n");
886 memset(query, '\0', MAX_QUERY_LEN);
891 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
893 uiapplication_x *up = mfx->uiapplication;
894 category_x *ct = NULL;
896 char query[MAX_QUERY_LEN] = {'\0'};
902 snprintf(query, MAX_QUERY_LEN,
903 "insert into package_app_app_category(app_id, category) " \
904 "values('%s','%s')",\
905 up->appid, ct->name);
906 ret = __exec_query(query);
908 _LOGD("Package UiApp Category Info DB Insert Failed\n");
912 memset(query, '\0', MAX_QUERY_LEN);
919 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
921 uiapplication_x *up = mfx->uiapplication;
922 metadata_x *md = NULL;
924 char query[MAX_QUERY_LEN] = {'\0'};
931 snprintf(query, MAX_QUERY_LEN,
932 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
933 "values('%s','%s', '%s')",\
934 up->appid, md->key, md->value);
935 ret = __exec_query(query);
937 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
942 memset(query, '\0', MAX_QUERY_LEN);
949 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
951 uiapplication_x *up = mfx->uiapplication;
952 permission_x *pm = NULL;
954 char query[MAX_QUERY_LEN] = {'\0'};
960 snprintf(query, MAX_QUERY_LEN,
961 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
962 "values('%s','%s', '%s')",\
963 up->appid, pm->type, pm->value);
964 ret = __exec_query(query);
966 _LOGD("Package UiApp permission Info DB Insert Failed\n");
970 memset(query, '\0', MAX_QUERY_LEN);
977 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
979 uiapplication_x *up = mfx->uiapplication;
980 appcontrol_x *acontrol = NULL;
982 char query[MAX_QUERY_LEN] = {'\0'};
983 char buf[BUFSIZE] = {'\0'};
985 acontrol = up->appcontrol;
986 while (acontrol != NULL) {
987 snprintf(buf, BUFSIZE, "%s|%s|%s",\
988 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
989 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
990 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
991 snprintf(query, MAX_QUERY_LEN,
992 "insert into package_app_app_control(app_id, app_control) " \
993 "values('%s', '%s')",\
995 ret = __exec_query(query);
997 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1000 memset(query, '\0', MAX_QUERY_LEN);
1001 acontrol = acontrol->next;
1008 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1010 uiapplication_x *up = mfx->uiapplication;
1011 appsvc_x *asvc = NULL;
1012 operation_x *op = NULL;
1015 subapp_x *sub = NULL;
1017 char query[MAX_QUERY_LEN] = {'\0'};
1018 const char *operation = NULL;
1019 const char *mime = NULL;
1020 const char *uri = NULL;
1021 const char *subapp = NULL;
1027 op = asvc->operation;
1031 operation = op->name;
1048 snprintf(query, MAX_QUERY_LEN,
1049 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1050 "values('%s', '%s', '%s', '%s', '%s')",\
1057 ret = __exec_query(query);
1059 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1062 memset(query, '\0', MAX_QUERY_LEN);
1066 } while(ui != NULL);
1070 }while(sub != NULL);
1086 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx)
1088 uiapplication_x *up = mfx->uiapplication;
1089 datacontrol_x *dc = NULL;
1091 char query[MAX_QUERY_LEN] = {'\0'};
1095 dc = up->datacontrol;
1098 snprintf(query, MAX_QUERY_LEN,
1099 "insert into package_app_data_control(app_id, providerid, access, type) " \
1100 "values('%s', '%s', '%s', '%s')",\
1101 mfx->uiapplication->appid,
1106 ret = __exec_query(query);
1108 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1111 memset(query, '\0', MAX_QUERY_LEN);
1119 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1121 uiapplication_x *up = mfx->uiapplication;
1122 datashare_x *ds = NULL;
1123 request_x *rq = NULL;
1125 char query[MAX_QUERY_LEN] = {'\0'};
1134 snprintf(query, MAX_QUERY_LEN,
1135 "insert into package_app_share_request(app_id, data_share_request) " \
1136 "values('%s', '%s')",\
1137 up->appid, rq->text);
1138 ret = __exec_query(query);
1140 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1143 memset(query, '\0', MAX_QUERY_LEN);
1153 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1155 uiapplication_x *up = mfx->uiapplication;
1156 datashare_x *ds = NULL;
1157 define_x *df = NULL;
1158 allowed_x *al = NULL;
1160 char query[MAX_QUERY_LEN] = {'\0'};
1172 snprintf(query, MAX_QUERY_LEN,
1173 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1174 "values('%s', '%s', '%s')",\
1175 up->appid, df->path, al->text);
1176 ret = __exec_query(query);
1178 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1181 memset(query, '\0', MAX_QUERY_LEN);
1193 static int __insert_serviceapplication_info(manifest_x *mfx)
1195 serviceapplication_x *sp = mfx->serviceapplication;
1197 char query[MAX_QUERY_LEN] = {'\0'};
1200 snprintf(query, MAX_QUERY_LEN,
1201 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1202 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1203 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1204 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1205 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1206 ret = __exec_query(query);
1208 _LOGD("Package ServiceApp Info DB Insert Failed\n");
1212 memset(query, '\0', MAX_QUERY_LEN);
1217 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1219 serviceapplication_x *sp = mfx->serviceapplication;
1220 category_x *ct = NULL;
1222 char query[MAX_QUERY_LEN] = {'\0'};
1228 snprintf(query, MAX_QUERY_LEN,
1229 "insert into package_app_app_category(app_id, category) " \
1230 "values('%s','%s')",\
1231 sp->appid, ct->name);
1232 ret = __exec_query(query);
1234 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1238 memset(query, '\0', MAX_QUERY_LEN);
1245 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1247 serviceapplication_x *sp = mfx->serviceapplication;
1248 metadata_x *md = NULL;
1250 char query[MAX_QUERY_LEN] = {'\0'};
1257 snprintf(query, MAX_QUERY_LEN,
1258 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1259 "values('%s','%s', '%s')",\
1260 sp->appid, md->key, md->value);
1261 ret = __exec_query(query);
1263 _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1268 memset(query, '\0', MAX_QUERY_LEN);
1275 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1277 serviceapplication_x *sp = mfx->serviceapplication;
1278 permission_x *pm = NULL;
1280 char query[MAX_QUERY_LEN] = {'\0'};
1283 pm = sp->permission;
1286 snprintf(query, MAX_QUERY_LEN,
1287 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1288 "values('%s','%s', '%s')",\
1289 sp->appid, pm->type, pm->value);
1290 ret = __exec_query(query);
1292 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1296 memset(query, '\0', MAX_QUERY_LEN);
1303 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1305 serviceapplication_x *sp = mfx->serviceapplication;
1306 appcontrol_x *acontrol = NULL;
1308 char query[MAX_QUERY_LEN] = {'\0'};
1309 char buf[BUFSIZE] = {'\0'};
1310 while (sp != NULL) {
1311 acontrol = sp->appcontrol;
1312 while (acontrol != NULL) {
1313 snprintf(buf, BUFSIZE, "%s|%s|%s",
1314 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1315 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1316 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1317 snprintf(query, MAX_QUERY_LEN,
1318 "insert into package_app_app_control(app_id, app_control) " \
1319 "values('%s', '%s')",\
1321 ret = __exec_query(query);
1323 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1326 memset(query, '\0', MAX_QUERY_LEN);
1327 acontrol = acontrol->next;
1334 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1336 serviceapplication_x *sp = mfx->serviceapplication;
1337 appsvc_x *asvc = NULL;
1339 char query[MAX_QUERY_LEN] = {'\0'};
1340 operation_x *op = NULL;
1343 subapp_x *sub = NULL;
1344 const char *operation = NULL;
1345 const char *mime = NULL;
1346 const char *uri = NULL;
1347 const char *subapp = NULL;
1353 op = asvc->operation;
1357 operation = op->name;
1373 snprintf(query, MAX_QUERY_LEN,
1374 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1375 "values('%s', '%s', '%s', '%s', '%s')",\
1381 ret = __exec_query(query);
1383 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1386 memset(query, '\0', MAX_QUERY_LEN);
1390 } while(ui != NULL);
1394 }while(sub != NULL);
1410 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx)
1412 serviceapplication_x *sp = mfx->serviceapplication;
1413 datacontrol_x *dc = NULL;
1415 char query[MAX_QUERY_LEN] = {'\0'};
1419 dc = sp->datacontrol;
1422 snprintf(query, MAX_QUERY_LEN,
1423 "insert into package_app_data_control(app_id, providerid, access, type) " \
1424 "values('%s', '%s', '%s', '%s')",\
1425 mfx->serviceapplication->appid,
1430 ret = __exec_query(query);
1432 _LOGD("Package ServiceApp Data Control DB Insert Failed\n");
1435 memset(query, '\0', MAX_QUERY_LEN);
1443 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1445 serviceapplication_x *sp = mfx->serviceapplication;
1446 datashare_x *ds = NULL;
1447 request_x *rq = NULL;
1449 char query[MAX_QUERY_LEN] = {'\0'};
1458 snprintf(query, MAX_QUERY_LEN,
1459 "insert into package_app_share_request(app_id, data_share_request) " \
1460 "values('%s', '%s')",\
1461 sp->appid, rq->text);
1462 ret = __exec_query(query);
1464 _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1467 memset(query, '\0', MAX_QUERY_LEN);
1479 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1481 serviceapplication_x *sp = mfx->serviceapplication;
1482 datashare_x *ds = NULL;
1483 define_x *df = NULL;
1484 allowed_x *al = NULL;
1486 char query[MAX_QUERY_LEN] = {'\0'};
1498 snprintf(query, MAX_QUERY_LEN,
1499 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1500 "values('%s', '%s', '%s')",\
1501 sp->appid, df->path, al->text);
1502 ret = __exec_query(query);
1504 _LOGD("Package App Share Allowed DB Insert Failed\n");
1507 memset(query, '\0', MAX_QUERY_LEN);
1519 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1521 label_x *lbl = mfx->label;
1522 license_x *lcn = mfx->license;
1523 icon_x *icn = mfx->icon;
1524 description_x *dcn = mfx->description;
1525 author_x *ath = mfx->author;
1526 uiapplication_x *up = mfx->uiapplication;
1527 uiapplication_x *up_icn = mfx->uiapplication;
1528 uiapplication_x *up_image = mfx->uiapplication;
1529 serviceapplication_x *sp = mfx->serviceapplication;
1530 privileges_x *pvs = NULL;
1531 privilege_x *pv = NULL;
1532 char query[MAX_QUERY_LEN] = { '\0' };
1533 char root[MAX_QUERY_LEN] = { '\0' };
1535 const char *auth_name = NULL;
1536 const char *auth_email = NULL;
1537 const char *auth_href = NULL;
1538 const char *apps_path = NULL;
1540 GList *pkglocale = NULL;
1541 GList *applocale = NULL;
1542 GList *appicon = NULL;
1543 GList *appimage = NULL;
1547 auth_name = ath->text;
1549 auth_email = ath->email;
1551 auth_href = ath->href;
1553 /*Insert in the package_cert_info CERT_DB*/
1554 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1555 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1556 if (ret != PMINFO_R_OK) {
1557 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1558 _LOGE("Cert Info DB create handle failed\n");
1561 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1562 if (ret != PMINFO_R_OK) {
1563 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1564 _LOGE("Cert Info DB Insert Failed\n");
1568 /*Insert in the package_info DB*/
1569 snprintf(query, MAX_QUERY_LEN,
1570 "insert into package_info(package, package_type, package_version, package_api_version, install_location, package_size, " \
1571 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1572 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
1573 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1577 __get_str(mfx->api_version),
1578 __get_str(mfx->installlocation),
1579 __get_str(mfx->package_size),
1585 mfx->nodisplay_setting,
1587 __get_str(auth_name),
1588 __get_str(auth_email),
1589 __get_str(auth_href),
1590 mfx->installed_time,
1591 mfx->installed_storage,
1592 __get_str(mfx->storeclient_id),
1594 __get_str(mfx->package_url),
1596 __get_str(mfx->csc_path));
1598 ret = __exec_query(query);
1600 _LOGD("Package Info DB Insert Failed\n");
1604 /*Insert in the package_privilege_info DB*/
1605 pvs = mfx->privileges;
1606 while (pvs != NULL) {
1607 pv = pvs->privilege;
1608 while (pv != NULL) {
1609 memset(query, '\0', MAX_QUERY_LEN);
1610 snprintf(query, MAX_QUERY_LEN,
1611 "insert into package_privilege_info(package, privilege) " \
1612 "values('%s','%s')",\
1613 mfx->package, pv->text);
1614 ret = __exec_query(query);
1616 _LOGD("Package Privilege Info DB Insert Failed\n");
1625 ret = __insert_ui_mainapp_info(mfx);
1630 /*Insert the package locale*/
1631 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1632 /*remove duplicated data in pkglocale*/
1633 __trimfunc(pkglocale);
1635 /*Insert the app locale info */
1638 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1643 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1646 /*remove duplicated data in applocale*/
1647 __trimfunc(applocale);
1649 /*Insert the app icon info */
1650 while(up_icn != NULL)
1652 appicon = __create_icon_list(appicon, up_icn->icon);
1653 up_icn = up_icn->next;
1655 /*remove duplicated data in appicon*/
1656 __trimfunc(appicon);
1658 /*Insert the image info */
1659 while(up_image != NULL)
1661 appimage = __create_image_list(appimage, up_image->image);
1662 up_image = up_image->next;
1664 /*remove duplicated data in appimage*/
1665 __trimfunc(appimage);
1667 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1669 /*g_list_foreach(applocale, __printfunc, NULL);*/
1671 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1673 /*native app locale info*/
1674 up = mfx->uiapplication;
1677 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1680 /*agent app locale info*/
1681 sp = mfx->serviceapplication;
1684 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1688 /*app icon locale info*/
1689 up_icn = mfx->uiapplication;
1690 while(up_icn != NULL)
1692 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1693 up_icn = up_icn->next;
1697 up_image = mfx->uiapplication;
1698 while(up_image != NULL)
1700 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1701 up_image = up_image->next;
1704 g_list_free(pkglocale);
1706 g_list_free(applocale);
1708 g_list_free(appicon);
1710 g_list_free(appimage);
1713 /*Insert in the package_app_info DB*/
1714 ret = __insert_uiapplication_info(mfx);
1717 ret = __insert_serviceapplication_info(mfx);
1720 /*Insert in the package_app_app_control DB*/
1721 ret = __insert_uiapplication_appcontrol_info(mfx);
1724 ret = __insert_serviceapplication_appcontrol_info(mfx);
1728 /*Insert in the package_app_app_category DB*/
1729 ret = __insert_uiapplication_appcategory_info(mfx);
1732 ret = __insert_serviceapplication_appcategory_info(mfx);
1736 /*Insert in the package_app_app_metadata DB*/
1737 ret = __insert_uiapplication_appmetadata_info(mfx);
1740 ret = __insert_serviceapplication_appmetadata_info(mfx);
1744 /*Insert in the package_app_app_permission DB*/
1745 ret = __insert_uiapplication_apppermission_info(mfx);
1748 ret = __insert_serviceapplication_apppermission_info(mfx);
1752 /*Insert in the package_app_app_svc DB*/
1753 ret = __insert_uiapplication_appsvc_info(mfx);
1756 ret = __insert_serviceapplication_appsvc_info(mfx);
1760 /*Insert in the package_app_share_allowed DB*/
1761 ret = __insert_uiapplication_share_allowed_info(mfx);
1764 ret = __insert_serviceapplication_share_allowed_info(mfx);
1768 /*Insert in the package_app_share_request DB*/
1769 ret = __insert_uiapplication_share_request_info(mfx);
1772 ret = __insert_serviceapplication_share_request_info(mfx);
1776 /*Insert in the package_app_data_control DB*/
1777 ret = __insert_uiapplication_datacontrol_info(mfx);
1780 ret = __insert_serviceapplication_datacontrol_info(mfx);
1788 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1790 char query[MAX_QUERY_LEN] = { '\0' };
1792 memset(query, '\0', MAX_QUERY_LEN);
1793 snprintf(query, MAX_QUERY_LEN,
1794 "delete from %s where app_id='%s'", db_table, appid);
1795 ret = __exec_query(query);
1797 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1803 static int __delete_subpkg_info_from_db(char *appid)
1807 ret = __delete_appinfo_from_db("package_app_info", appid);
1810 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1813 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1816 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1819 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1822 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1825 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1828 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1831 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1834 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1837 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1840 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1847 static int __delete_subpkg_from_db(manifest_x *mfx)
1849 char query[MAX_QUERY_LEN] = { '\0' };
1850 char *error_message = NULL;
1852 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1854 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1855 _LOGE("Don't execute query = %s error message = %s\n", query,
1857 sqlite3_free(error_message);
1860 sqlite3_free(error_message);
1865 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1867 char query[MAX_QUERY_LEN] = { '\0' };
1869 uiapplication_x *up = mfx->uiapplication;
1870 serviceapplication_x *sp = mfx->serviceapplication;
1871 /*Delete from cert table*/
1872 if (uid != GLOBAL_USER)
1873 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1875 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1877 _LOGD("Cert Info DB Delete Failed\n");
1881 /*Delete from Package Info DB*/
1882 snprintf(query, MAX_QUERY_LEN,
1883 "delete from package_info where package='%s'", mfx->package);
1884 ret = __exec_query(query);
1886 _LOGD("Package Info DB Delete Failed\n");
1889 memset(query, '\0', MAX_QUERY_LEN);
1891 /*Delete from Package Localized Info*/
1892 snprintf(query, MAX_QUERY_LEN,
1893 "delete from package_localized_info where package='%s'", mfx->package);
1894 ret = __exec_query(query);
1896 _LOGD("Package Localized Info DB Delete Failed\n");
1900 /*Delete from Package Privilege Info*/
1901 snprintf(query, MAX_QUERY_LEN,
1902 "delete from package_privilege_info where package='%s'", mfx->package);
1903 ret = __exec_query(query);
1905 _LOGD("Package Privilege Info DB Delete Failed\n");
1909 while (up != NULL) {
1910 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1913 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1916 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
1919 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
1922 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
1925 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
1928 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
1931 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
1934 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
1937 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
1940 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
1943 ret = __delete_appinfo_from_db("package_app_data_control", up->appid);
1949 while (sp != NULL) {
1950 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
1953 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
1956 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
1959 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
1962 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
1965 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
1968 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
1971 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
1974 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
1977 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
1980 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
1983 ret = __delete_appinfo_from_db("package_app_data_control", sp->appid);
1989 /* if main package has sub pkg, delete sub pkg data*/
1990 __delete_subpkg_from_db(mfx);
1995 static int __update_preload_condition_in_db()
1998 char query[MAX_QUERY_LEN] = {'\0'};
2000 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2002 ret = __exec_query(query);
2004 _LOGD("Package preload_condition update failed\n");
2009 API int pkgmgr_parser_initialize_db(uid_t uid)
2013 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2015 _LOGD("package info DB initialization failed\n");
2018 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2020 _LOGD("package localized info DB initialization failed\n");
2023 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2025 _LOGD("package app app privilege DB initialization failed\n");
2028 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2030 _LOGD("package app info DB initialization failed\n");
2033 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2035 _LOGD("package app localized info DB initialization failed\n");
2038 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2040 _LOGD("package app icon localized info DB initialization failed\n");
2043 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2045 _LOGD("package app image info DB initialization failed\n");
2048 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2050 _LOGD("package app app control DB initialization failed\n");
2053 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2055 _LOGD("package app app category DB initialization failed\n");
2058 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2060 _LOGD("package app app category DB initialization failed\n");
2063 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2065 _LOGD("package app app permission DB initialization failed\n");
2068 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2070 _LOGD("package app app svc DB initialization failed\n");
2073 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2075 _LOGD("package app share allowed DB initialization failed\n");
2078 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2080 _LOGD("package app share request DB initialization failed\n");
2083 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2085 _LOGD("package app data control DB initialization failed\n");
2089 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2091 _LOGD("package cert info DB initialization failed\n");
2094 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2096 _LOGD("package cert index info DB initialization failed\n");
2100 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_RESOURCE_INFO);
2102 _LOGD("package resource info DB initialization failed\n");
2105 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_RESOURCE_DATA);
2107 _LOGD("package resource data DB initialization failed\n");
2111 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
2112 _LOGD("Failed to change cert db permission\n");
2114 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2115 _LOGD("Failed to change parser db permission\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;
2132 if (db_file == NULL)
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 if (uid == OWNER_ROOT)
2140 userinfo = getpwuid(uid);
2142 _LOGE("FAIL: user %d doesn't exist", uid);
2145 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2147 for (i = 0; files[i]; i++) {
2148 ret = chown(files[i], uid, userinfo->pw_gid);
2150 if (strerror_r(errno, buf, sizeof(buf)))
2152 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2153 userinfo->pw_gid, buf);
2157 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
2159 if (strerror_r(errno, buf, sizeof(buf)))
2161 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2164 SET_SMACK_LABEL(files[i]);
2169 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2173 if (getuid() != OWNER_ROOT) {
2174 _LOGE("Only root user is allowed");
2178 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2179 _LOGE("Manifest db for user %d is already exists", uid);
2183 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2184 _LOGE("Cert db for user %d is already exists", uid);
2188 ret = pkgmgr_parser_check_and_create_db(uid);
2191 ret = pkgmgr_parser_initialize_db(uid);
2193 pkgmgr_parser_close_db();
2196 pkgmgr_parser_close_db();
2201 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2205 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2207 _LOGD("Manifest DB creation Failed\n");
2212 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid));
2214 _LOGD("Cert DB creation Failed\n");
2220 void pkgmgr_parser_close_db()
2222 sqlite3_close(pkgmgr_parser_db);
2223 sqlite3_close(pkgmgr_cert_db);
2227 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2229 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2231 _LOGD("manifest pointer is NULL\n");
2235 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2237 _LOGD("Failed to open DB\n");
2240 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2243 /*Begin transaction*/
2244 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2245 if (ret != SQLITE_OK) {
2246 _LOGD("Failed to begin transaction\n");
2250 _LOGD("Transaction Begin\n");
2251 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2253 _LOGD("Insert into DB failed. Rollback now\n");
2254 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2257 /*Commit transaction*/
2258 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2259 if (ret != SQLITE_OK) {
2260 _LOGD("Failed to commit transaction. Rollback now\n");
2261 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2265 _LOGD("Transaction Commit and End\n");
2267 pkgmgr_parser_close_db();
2271 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2273 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2275 _LOGD("manifest pointer is NULL\n");
2279 ret = pkgmgr_parser_check_and_create_db(uid);
2281 _LOGD("Failed to open DB\n");
2284 ret = pkgmgr_parser_initialize_db(uid);
2287 /*Begin transaction*/
2288 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2289 if (ret != SQLITE_OK) {
2290 _LOGD("Failed to begin transaction\n");
2294 _LOGD("Transaction Begin\n");
2295 ret = __insert_manifest_info_in_db(mfx, uid);
2297 _LOGD("Insert into DB failed. Rollback now\n");
2298 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2301 /*Commit transaction*/
2302 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2303 if (ret != SQLITE_OK) {
2304 _LOGD("Failed to commit transaction. Rollback now\n");
2305 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2309 _LOGD("Transaction Commit and End\n");
2311 pkgmgr_parser_close_db();
2315 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2318 _LOGD("manifest pointer is NULL\n");
2322 ret = pkgmgr_parser_check_and_create_db(uid);
2324 _LOGD("Failed to open DB\n");
2327 ret = pkgmgr_parser_initialize_db(uid);
2330 /*Preserve guest mode visibility*/
2331 __preserve_guestmode_visibility_value( mfx);
2332 /*Begin transaction*/
2333 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2334 if (ret != SQLITE_OK) {
2335 _LOGD("Failed to begin transaction\n");
2339 _LOGD("Transaction Begin\n");
2340 ret = __delete_manifest_info_from_db(mfx, uid);
2342 _LOGD("Delete from DB failed. Rollback now\n");
2343 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2346 ret = __insert_manifest_info_in_db(mfx, uid);
2348 _LOGD("Insert into DB failed. Rollback now\n");
2349 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2353 /*Commit transaction*/
2354 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2355 if (ret != SQLITE_OK) {
2356 _LOGD("Failed to commit transaction. Rollback now\n");
2357 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2361 _LOGD("Transaction Commit and End\n");
2363 pkgmgr_parser_close_db();
2367 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2369 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2372 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2375 _LOGD("manifest pointer is NULL\n");
2379 ret = pkgmgr_parser_check_and_create_db(uid);
2381 _LOGD("Failed to open DB\n");
2384 /*Begin transaction*/
2385 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2386 if (ret != SQLITE_OK) {
2387 _LOGD("Failed to begin transaction\n");
2391 _LOGD("Transaction Begin\n");
2392 ret = __delete_manifest_info_from_db(mfx, uid);
2394 _LOGD("Delete from DB failed. Rollback now\n");
2395 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2398 /*Commit transaction*/
2399 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2400 if (ret != SQLITE_OK) {
2401 _LOGD("Failed to commit transaction, Rollback now\n");
2402 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2406 _LOGD("Transaction Commit and End\n");
2408 pkgmgr_parser_close_db();
2412 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2414 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2417 API int pkgmgr_parser_update_preload_info_in_db()
2420 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2422 _LOGD("Failed to open DB\n");
2425 /*Begin transaction*/
2426 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2427 if (ret != SQLITE_OK) {
2428 _LOGD("Failed to begin transaction\n");
2432 _LOGD("Transaction Begin\n");
2433 ret = __update_preload_condition_in_db();
2435 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2436 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2439 /*Commit transaction*/
2440 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2441 if (ret != SQLITE_OK) {
2442 _LOGD("Failed to commit transaction, Rollback now\n");
2443 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2447 _LOGD("Transaction Commit and End\n");
2449 pkgmgr_parser_close_db();
2453 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2456 ret = pkgmgr_parser_check_and_create_db(uid);
2458 _LOGD("Failed to open DB\n");
2461 /*Begin transaction*/
2462 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2463 if (ret != SQLITE_OK) {
2464 _LOGD("Failed to begin transaction\n");
2468 _LOGD("Transaction Begin\n");
2469 ret = __update_preload_condition_in_db();
2471 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2472 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2475 /*Commit transaction*/
2476 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2477 if (ret != SQLITE_OK) {
2478 _LOGD("Failed to commit transaction, Rollback now\n");
2479 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2483 _LOGD("Transaction Commit and End\n");
2485 pkgmgr_parser_close_db();