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 "pkgmgrinfo_basic.h"
40 #include "pkgmgrinfo_debug.h"
41 #include "pkgmgr_parser_internal.h"
42 #include "pkgmgr_parser_db.h"
47 #define LOG_TAG "PKGMGR_PARSER"
49 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
50 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
51 #define MAX_QUERY_LEN 4096
55 #define SET_SMACK_LABEL(x) \
57 if (smack_setlabel((x), "System::Shared", SMACK_LABEL_ACCESS)) \
58 _LOGE("failed chsmack -a \"System::Shared\" %s", x); \
60 _LOGD("chsmack -a \"System::Shared\" %s", x); \
63 sqlite3 *pkgmgr_parser_db;
64 sqlite3 *pkgmgr_cert_db;
67 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
68 "(package text primary key not null, " \
69 "package_type text DEFAULT 'rpm', " \
70 "package_version text, " \
71 "package_api_version text, " \
72 "install_location text, " \
73 "package_size text, " \
74 "package_removable text DEFAULT 'true', " \
75 "package_preload text DEFAULT 'false', " \
76 "package_readonly text DEFAULT 'false', " \
77 "package_update text DEFAULT 'false', " \
78 "package_appsetting text DEFAULT 'false', " \
79 "package_nodisplay text DEFAULT 'false', " \
80 "package_system text DEFAULT 'false', " \
81 "author_name text, " \
82 "author_email text, " \
84 "installed_time text," \
85 "installed_storage text," \
86 "storeclient_id text," \
91 "package_support_disable text DEFAULT 'false')"
93 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
94 "(package text not null, " \
95 "package_locale text DEFAULT 'No Locale', " \
96 "package_label text, " \
97 "package_icon text, " \
98 "package_description text, " \
99 "package_license text, " \
101 "PRIMARY KEY(package, package_locale), " \
102 "FOREIGN KEY(package) " \
103 "REFERENCES package_info(package) " \
106 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
107 "(package text not null, " \
108 "privilege text not null, " \
109 "PRIMARY KEY(package, privilege) " \
110 "FOREIGN KEY(package) " \
111 "REFERENCES package_info(package) " \
114 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
115 "(app_id text primary key not null, " \
116 "app_component text, " \
118 "app_nodisplay text DEFAULT 'false', " \
120 "app_onboot text DEFAULT 'false', " \
121 "app_multiple text DEFAULT 'false', " \
122 "app_autorestart text DEFAULT 'false', " \
123 "app_taskmanage text DEFAULT 'false', " \
124 "app_enabled text DEFAULT 'true', " \
125 "app_hwacceleration text DEFAULT 'use-system-setting', " \
126 "app_screenreader text DEFAULT 'use-system-setting', " \
127 "app_mainapp text, " \
128 "app_recentimage text, " \
129 "app_launchcondition text, " \
130 "app_indicatordisplay text DEFAULT 'true', " \
131 "app_portraitimg text, " \
132 "app_landscapeimg text, " \
133 "app_guestmodevisibility text DEFAULT 'true', " \
134 "app_permissiontype text DEFAULT 'normal', " \
135 "app_preload text DEFAULT 'false', " \
136 "app_submode text DEFAULT 'false', " \
137 "app_submode_mainid text, " \
138 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
139 "app_ui_gadget text DEFAULT 'false', " \
140 "app_support_disable text DEFAULT 'false', " \
141 "component_type text, " \
142 "package text not null, " \
143 "FOREIGN KEY(package) " \
144 "REFERENCES package_info(package) " \
147 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
148 "(app_id text not null, " \
149 "app_locale text DEFAULT 'No Locale', " \
152 "PRIMARY KEY(app_id,app_locale) " \
153 "FOREIGN KEY(app_id) " \
154 "REFERENCES package_app_info(app_id) " \
157 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
158 "(app_id text not null, " \
160 "app_icon_section text, " \
161 "app_icon_resolution text, " \
162 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
163 "FOREIGN KEY(app_id) " \
164 "REFERENCES package_app_info(app_id) " \
167 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
168 "(app_id text not null, " \
169 "app_locale text DEFAULT 'No Locale', " \
170 "app_image_section text, " \
172 "PRIMARY KEY(app_id,app_image_section) " \
173 "FOREIGN KEY(app_id) " \
174 "REFERENCES package_app_info(app_id) " \
177 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
178 "(app_id text not null, " \
179 "app_control text not null, " \
180 "PRIMARY KEY(app_id,app_control) " \
181 "FOREIGN KEY(app_id) " \
182 "REFERENCES package_app_info(app_id) " \
185 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
186 "(app_id text not null, " \
187 "operation text not null, " \
188 "uri_scheme text, " \
190 "subapp_name text, " \
191 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
192 "FOREIGN KEY(app_id) " \
193 "REFERENCES package_app_info(app_id) " \
196 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
197 "(app_id text not null, " \
198 "category text not null, " \
199 "PRIMARY KEY(app_id,category) " \
200 "FOREIGN KEY(app_id) " \
201 "REFERENCES package_app_info(app_id) " \
204 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
205 "(app_id text not null, " \
206 "md_key text not null, " \
207 "md_value text not null, " \
208 "PRIMARY KEY(app_id, md_key, md_value) " \
209 "FOREIGN KEY(app_id) " \
210 "REFERENCES package_app_info(app_id) " \
213 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
214 "(app_id text not null, " \
215 "pm_type text not null, " \
216 "pm_value text not null, " \
217 "PRIMARY KEY(app_id, pm_type, pm_value) " \
218 "FOREIGN KEY(app_id) " \
219 "REFERENCES package_app_info(app_id) " \
222 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
223 "(app_id text not null, " \
224 "data_share_path text not null, " \
225 "data_share_allowed text not null, " \
226 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
227 "FOREIGN KEY(app_id) " \
228 "REFERENCES package_app_info(app_id) " \
231 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
232 "(app_id text not null, " \
233 "data_share_request text not null, " \
234 "PRIMARY KEY(app_id,data_share_request) " \
235 "FOREIGN KEY(app_id) " \
236 "REFERENCES package_app_info(app_id) " \
239 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
240 "(cert_info text not null, " \
241 "cert_id integer, " \
242 "cert_ref_count integer, " \
243 "PRIMARY KEY(cert_id)) "
245 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
246 "(package text not null, " \
247 "author_root_cert integer, " \
248 "author_im_cert integer, " \
249 "author_signer_cert integer, " \
250 "dist_root_cert integer, " \
251 "dist_im_cert integer, " \
252 "dist_signer_cert integer, " \
253 "dist2_root_cert integer, " \
254 "dist2_im_cert integer, " \
255 "dist2_signer_cert integer, " \
256 "PRIMARY KEY(package)) "
258 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
259 "(app_id text not null, " \
260 "providerid text not null, " \
261 "access text not null, " \
262 "type text not null, " \
263 "PRIMARY KEY(app_id, providerid, access, type) " \
264 "FOREIGN KEY(app_id) " \
265 "REFERENCES package_app_info(app_id) " \
268 static int __insert_uiapplication_info(manifest_x *mfx);
269 static int __insert_serviceapplication_info(manifest_x *mfx);
270 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
271 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
272 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
273 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
274 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
275 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
276 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
277 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
278 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
279 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
280 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
281 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
282 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx);
283 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx);
284 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
285 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
286 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
287 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
288 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
289 static int __delete_subpkg_info_from_db(char *appid);
290 static int __delete_appinfo_from_db(char *db_table, const char *appid);
291 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
292 static int __exec_query(char *query);
293 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
294 char **label, char **license, char **icon, char **description, char **author);
295 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
296 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
297 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
298 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
299 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
300 static int __parserdb_change_perm(const char *db_file, uid_t uid);
302 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
305 __delete_subpkg_info_from_db(coltxt[0]);
310 static const char *__get_str(const char *str)
314 return PKGMGR_PARSER_EMPTY_STR;
320 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
325 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
326 if (ret != SQLITE_OK) {
327 _LOGD("connect db [%s] failed!\n", db_path);
335 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
337 manifest_x *mfx = (manifest_x *)data;
341 uiapplication_x *uiapp = NULL;
342 for(i = 0; i < ncols; i++)
344 uiapp = mfx->uiapplication;
345 if (strcmp(colname[i], "app_id") == 0) {
347 appid = strdup(coltxt[i]);
348 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
350 status = strdup(coltxt[i]);
354 _LOGD("app id is NULL\n");
357 /*update guest mode visibility*/
358 for (; uiapp != NULL; uiapp = uiapp->next) {
359 if (strcmp(uiapp->appid, appid) == 0) {
360 free((void *)uiapp->guestmode_visibility);
361 uiapp->guestmode_visibility = strdup(status);
377 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
379 char *error_message = NULL;
380 char query[MAX_QUERY_LEN] = {'\0'};
381 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
383 sqlite3_exec(pkgmgr_parser_db, query,
384 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
385 _LOGD("Don't execute query = %s error message = %s\n",
386 query, error_message);
387 sqlite3_free(error_message);
392 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
394 char *error_message = NULL;
396 sqlite3_exec(db_handle, db_query,
397 NULL, NULL, &error_message)) {
398 _LOGD("Don't execute query = %s error message = %s\n",
399 db_query, error_message);
400 sqlite3_free(error_message);
403 sqlite3_free(error_message);
407 static int __exec_query(char *query)
409 char *error_message = NULL;
411 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
412 _LOGD("Don't execute query = %s error message = %s\n", query,
414 sqlite3_free(error_message);
417 sqlite3_free(error_message);
421 static int __exec_query_no_msg(char *query)
423 char *error_message = NULL;
425 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
426 sqlite3_free(error_message);
429 sqlite3_free(error_message);
433 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
439 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
445 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
451 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
457 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
463 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
470 static GList *__create_icon_list(GList *locale, icon_x *icn)
475 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
481 static GList *__create_image_list(GList *locale, image_x *image)
486 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
492 static void __trimfunc(GList* trim_list)
494 char *trim_data = NULL;
498 list = g_list_first(trim_list);
501 trim_data = (char *)list->data;
504 if (strcmp(trim_data, prev) == 0) {
505 trim_list = g_list_remove(trim_list, trim_data);
506 list = g_list_first(trim_list);
515 list = g_list_next(list);
519 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
521 if (a == NULL || b == NULL)
523 if (strcmp((char*)a, (char*)b) == 0)
525 if (strcmp((char*)a, (char*)b) < 0)
527 if (strcmp((char*)a, (char*)b) > 0)
532 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
533 char **label, char **license, char **icon, char **description, char **author)
538 if (strcmp(lbl->lang, (char *)data) == 0) {
539 *label = (char*)lbl->text;
548 if (strcmp(lcn->lang, (char *)data) == 0) {
549 *license = (char*)lcn->text;
558 if (strcmp(icn->lang, (char *)data) == 0) {
559 *icon = (char*)icn->text;
568 if (strcmp(dcn->lang, (char *)data) == 0) {
569 *description = (char*)dcn->text;
578 if (strcmp(ath->lang, (char *)data) == 0) {
579 *author = (char*)ath->text;
588 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
593 if (strcmp(icn->section, (char *)data) == 0) {
594 *icon = (char*)icn->text;
595 *resolution = (char*)icn->resolution;
603 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
607 if (image->section) {
608 if (strcmp(image->section, (char *)data) == 0) {
609 *lang = (char*)image->lang;
610 *img = (char*)image->text;
618 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
623 char *description = NULL;
624 char *license = NULL;
626 char query[MAX_QUERY_LEN] = {'\0'};
628 manifest_x *mfx = (manifest_x *)userdata;
629 label_x *lbl = mfx->label;
630 license_x *lcn = mfx->license;
631 icon_x *icn = mfx->icon;
632 description_x *dcn = mfx->description;
633 author_x *ath = mfx->author;
635 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
636 if (!label && !description && !icon && !license && !author)
639 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
640 "package_label, package_icon, package_description, package_license, package_author) values " \
641 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
646 __get_str(description),
650 ret = __exec_query(query);
652 _LOGD("Package Localized Info DB Insert failed\n");
655 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
660 char query[MAX_QUERY_LEN] = {'\0'};
662 uiapplication_x *up = (uiapplication_x*)userdata;
663 label_x *lbl = up->label;
664 icon_x *icn = up->icon;
666 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
669 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
670 "app_label, app_icon) values " \
671 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
673 ret = __exec_query(query);
675 _LOGD("Package UiApp Localized Info DB Insert failed\n");
677 /*insert ui app locale info to pkg locale to get mainapp data */
678 if (strcasecmp(up->mainapp, "true")==0) {
679 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
680 "package_label, package_icon, package_description, package_license, package_author) values " \
681 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
686 PKGMGR_PARSER_EMPTY_STR,
687 PKGMGR_PARSER_EMPTY_STR,
688 PKGMGR_PARSER_EMPTY_STR);
690 ret = __exec_query_no_msg(query);
693 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
694 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
695 ret = __exec_query_no_msg(query);
700 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
704 char *resolution = NULL;
705 char query[MAX_QUERY_LEN] = {'\0'};
707 uiapplication_x *up = (uiapplication_x*)userdata;
708 icon_x *icn = up->icon;
710 __extract_icon_data(data, icn, &icon, &resolution);
711 if (!icon && !resolution)
713 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
714 "app_icon, app_icon_section, app_icon_resolution) values " \
715 "('%q', '%q', '%q', '%q')", up->appid,
716 icon, (char*)data, resolution);
718 ret = __exec_query(query);
720 _LOGD("Package UiApp Localized Info DB Insert failed\n");
724 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
729 char query[MAX_QUERY_LEN] = {'\0'};
731 uiapplication_x *up = (uiapplication_x*)userdata;
732 image_x *image = up->image;
734 __extract_image_data(data, image, &lang, &img);
737 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
738 "app_image_section, app_image) values " \
739 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
741 ret = __exec_query(query);
743 _LOGD("Package UiApp image Info DB Insert failed\n");
748 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
753 char query[MAX_QUERY_LEN] = {'\0'};
755 serviceapplication_x *sp = (serviceapplication_x*)userdata;
756 label_x *lbl = sp->label;
757 icon_x *icn = sp->icon;
759 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
762 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
763 "app_label, app_icon) values " \
764 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
766 ret = __exec_query(query);
768 _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
771 static int __insert_ui_mainapp_info(manifest_x *mfx)
773 uiapplication_x *up = mfx->uiapplication;
775 char query[MAX_QUERY_LEN] = {'\0'};
778 snprintf(query, MAX_QUERY_LEN,
779 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
781 ret = __exec_query(query);
783 _LOGD("Package UiApp Info DB Insert Failed\n");
786 if (strcasecmp(up->mainapp, "True")==0)
787 mfx->mainapp_id = strdup(up->appid);
790 memset(query, '\0', MAX_QUERY_LEN);
793 if (mfx->mainapp_id == NULL){
794 if (mfx->uiapplication && mfx->uiapplication->appid) {
795 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
797 _LOGD("Not valid appid\n");
801 ret = __exec_query(query);
803 _LOGD("Package UiApp Info DB Insert Failed\n");
807 free((void *)mfx->uiapplication->mainapp);
808 mfx->uiapplication->mainapp= strdup("true");
809 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
812 memset(query, '\0', MAX_QUERY_LEN);
813 snprintf(query, MAX_QUERY_LEN,
814 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
815 ret = __exec_query(query);
817 _LOGD("Package Info DB update Failed\n");
823 /* _PRODUCT_LAUNCHING_ENHANCED_
824 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
826 static int __insert_uiapplication_info(manifest_x *mfx)
828 uiapplication_x *up = mfx->uiapplication;
830 char query[MAX_QUERY_LEN] = {'\0'};
833 snprintf(query, MAX_QUERY_LEN,
834 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
835 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
836 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
837 "app_preload, app_submode, app_submode_mainid, app_launch_mode, app_ui_gadget, app_support_disable, component_type, package) " \
838 "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', '%s', '%s')",\
844 PKGMGR_PARSER_EMPTY_STR,
846 PKGMGR_PARSER_EMPTY_STR,
852 __get_str(up->recentimage),
854 up->indicatordisplay,
855 __get_str(up->portraitimg),
856 __get_str(up->landscapeimg),
857 up->guestmode_visibility,
861 __get_str(up->submode_mainid),
864 mfx->support_disable,
868 ret = __exec_query(query);
870 _LOGD("Package UiApp Info DB Insert Failed\n");
874 memset(query, '\0', MAX_QUERY_LEN);
879 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
881 uiapplication_x *up = mfx->uiapplication;
882 category_x *ct = NULL;
884 char query[MAX_QUERY_LEN] = {'\0'};
890 snprintf(query, MAX_QUERY_LEN,
891 "insert into package_app_app_category(app_id, category) " \
892 "values('%s','%s')",\
893 up->appid, ct->name);
894 ret = __exec_query(query);
896 _LOGD("Package UiApp Category Info DB Insert Failed\n");
900 memset(query, '\0', MAX_QUERY_LEN);
907 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
909 uiapplication_x *up = mfx->uiapplication;
910 metadata_x *md = NULL;
912 char query[MAX_QUERY_LEN] = {'\0'};
919 snprintf(query, MAX_QUERY_LEN,
920 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
921 "values('%s','%s', '%s')",\
922 up->appid, md->key, md->value);
923 ret = __exec_query(query);
925 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
930 memset(query, '\0', MAX_QUERY_LEN);
937 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
939 uiapplication_x *up = mfx->uiapplication;
940 permission_x *pm = NULL;
942 char query[MAX_QUERY_LEN] = {'\0'};
948 snprintf(query, MAX_QUERY_LEN,
949 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
950 "values('%s','%s', '%s')",\
951 up->appid, pm->type, pm->value);
952 ret = __exec_query(query);
954 _LOGD("Package UiApp permission Info DB Insert Failed\n");
958 memset(query, '\0', MAX_QUERY_LEN);
965 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
967 uiapplication_x *up = mfx->uiapplication;
968 appcontrol_x *acontrol = NULL;
970 char query[MAX_QUERY_LEN] = {'\0'};
971 char buf[BUFSIZE] = {'\0'};
973 acontrol = up->appcontrol;
974 while (acontrol != NULL) {
975 snprintf(buf, BUFSIZE, "%s|%s|%s",\
976 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
977 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
978 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
979 snprintf(query, MAX_QUERY_LEN,
980 "insert into package_app_app_control(app_id, app_control) " \
981 "values('%s', '%s')",\
983 ret = __exec_query(query);
985 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
988 memset(query, '\0', MAX_QUERY_LEN);
989 acontrol = acontrol->next;
996 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
998 uiapplication_x *up = mfx->uiapplication;
999 appsvc_x *asvc = NULL;
1000 operation_x *op = NULL;
1003 subapp_x *sub = NULL;
1005 char query[MAX_QUERY_LEN] = {'\0'};
1006 const char *operation = NULL;
1007 const char *mime = NULL;
1008 const char *uri = NULL;
1009 const char *subapp = NULL;
1015 op = asvc->operation;
1019 operation = op->name;
1036 snprintf(query, MAX_QUERY_LEN,
1037 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1038 "values('%s', '%s', '%s', '%s', '%s')",\
1045 ret = __exec_query(query);
1047 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1050 memset(query, '\0', MAX_QUERY_LEN);
1054 } while(ui != NULL);
1058 }while(sub != NULL);
1074 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx)
1076 uiapplication_x *up = mfx->uiapplication;
1077 datacontrol_x *dc = NULL;
1079 char query[MAX_QUERY_LEN] = {'\0'};
1083 dc = up->datacontrol;
1086 snprintf(query, MAX_QUERY_LEN,
1087 "insert into package_app_data_control(app_id, providerid, access, type) " \
1088 "values('%s', '%s', '%s', '%s')",\
1089 mfx->uiapplication->appid,
1094 ret = __exec_query(query);
1096 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1099 memset(query, '\0', MAX_QUERY_LEN);
1107 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1109 uiapplication_x *up = mfx->uiapplication;
1110 datashare_x *ds = NULL;
1111 request_x *rq = NULL;
1113 char query[MAX_QUERY_LEN] = {'\0'};
1122 snprintf(query, MAX_QUERY_LEN,
1123 "insert into package_app_share_request(app_id, data_share_request) " \
1124 "values('%s', '%s')",\
1125 up->appid, rq->text);
1126 ret = __exec_query(query);
1128 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1131 memset(query, '\0', MAX_QUERY_LEN);
1141 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1143 uiapplication_x *up = mfx->uiapplication;
1144 datashare_x *ds = NULL;
1145 define_x *df = NULL;
1146 allowed_x *al = NULL;
1148 char query[MAX_QUERY_LEN] = {'\0'};
1160 snprintf(query, MAX_QUERY_LEN,
1161 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1162 "values('%s', '%s', '%s')",\
1163 up->appid, df->path, al->text);
1164 ret = __exec_query(query);
1166 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1169 memset(query, '\0', MAX_QUERY_LEN);
1181 static int __insert_serviceapplication_info(manifest_x *mfx)
1183 serviceapplication_x *sp = mfx->serviceapplication;
1185 char query[MAX_QUERY_LEN] = {'\0'};
1188 snprintf(query, MAX_QUERY_LEN,
1189 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1190 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1191 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1192 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1193 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1194 ret = __exec_query(query);
1196 _LOGD("Package ServiceApp Info DB Insert Failed\n");
1200 memset(query, '\0', MAX_QUERY_LEN);
1205 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1207 serviceapplication_x *sp = mfx->serviceapplication;
1208 category_x *ct = NULL;
1210 char query[MAX_QUERY_LEN] = {'\0'};
1216 snprintf(query, MAX_QUERY_LEN,
1217 "insert into package_app_app_category(app_id, category) " \
1218 "values('%s','%s')",\
1219 sp->appid, ct->name);
1220 ret = __exec_query(query);
1222 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1226 memset(query, '\0', MAX_QUERY_LEN);
1233 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1235 serviceapplication_x *sp = mfx->serviceapplication;
1236 metadata_x *md = NULL;
1238 char query[MAX_QUERY_LEN] = {'\0'};
1245 snprintf(query, MAX_QUERY_LEN,
1246 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1247 "values('%s','%s', '%s')",\
1248 sp->appid, md->key, md->value);
1249 ret = __exec_query(query);
1251 _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1256 memset(query, '\0', MAX_QUERY_LEN);
1263 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1265 serviceapplication_x *sp = mfx->serviceapplication;
1266 permission_x *pm = NULL;
1268 char query[MAX_QUERY_LEN] = {'\0'};
1271 pm = sp->permission;
1274 snprintf(query, MAX_QUERY_LEN,
1275 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1276 "values('%s','%s', '%s')",\
1277 sp->appid, pm->type, pm->value);
1278 ret = __exec_query(query);
1280 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1284 memset(query, '\0', MAX_QUERY_LEN);
1291 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1293 serviceapplication_x *sp = mfx->serviceapplication;
1294 appcontrol_x *acontrol = NULL;
1296 char query[MAX_QUERY_LEN] = {'\0'};
1297 char buf[BUFSIZE] = {'\0'};
1298 while (sp != NULL) {
1299 acontrol = sp->appcontrol;
1300 while (acontrol != NULL) {
1301 snprintf(buf, BUFSIZE, "%s|%s|%s",
1302 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1303 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1304 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1305 snprintf(query, MAX_QUERY_LEN,
1306 "insert into package_app_app_control(app_id, app_control) " \
1307 "values('%s', '%s')",\
1309 ret = __exec_query(query);
1311 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1314 memset(query, '\0', MAX_QUERY_LEN);
1315 acontrol = acontrol->next;
1322 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1324 serviceapplication_x *sp = mfx->serviceapplication;
1325 appsvc_x *asvc = NULL;
1327 char query[MAX_QUERY_LEN] = {'\0'};
1328 operation_x *op = NULL;
1331 subapp_x *sub = NULL;
1332 const char *operation = NULL;
1333 const char *mime = NULL;
1334 const char *uri = NULL;
1335 const char *subapp = NULL;
1341 op = asvc->operation;
1345 operation = op->name;
1361 snprintf(query, MAX_QUERY_LEN,
1362 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1363 "values('%s', '%s', '%s', '%s', '%s')",\
1369 ret = __exec_query(query);
1371 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1374 memset(query, '\0', MAX_QUERY_LEN);
1378 } while(ui != NULL);
1382 }while(sub != NULL);
1398 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx)
1400 serviceapplication_x *sp = mfx->serviceapplication;
1401 datacontrol_x *dc = NULL;
1403 char query[MAX_QUERY_LEN] = {'\0'};
1407 dc = sp->datacontrol;
1410 snprintf(query, MAX_QUERY_LEN,
1411 "insert into package_app_data_control(app_id, providerid, access, type) " \
1412 "values('%s', '%s', '%s', '%s')",\
1413 mfx->serviceapplication->appid,
1418 ret = __exec_query(query);
1420 _LOGD("Package ServiceApp Data Control DB Insert Failed\n");
1423 memset(query, '\0', MAX_QUERY_LEN);
1431 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1433 serviceapplication_x *sp = mfx->serviceapplication;
1434 datashare_x *ds = NULL;
1435 request_x *rq = NULL;
1437 char query[MAX_QUERY_LEN] = {'\0'};
1446 snprintf(query, MAX_QUERY_LEN,
1447 "insert into package_app_share_request(app_id, data_share_request) " \
1448 "values('%s', '%s')",\
1449 sp->appid, rq->text);
1450 ret = __exec_query(query);
1452 _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1455 memset(query, '\0', MAX_QUERY_LEN);
1467 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1469 serviceapplication_x *sp = mfx->serviceapplication;
1470 datashare_x *ds = NULL;
1471 define_x *df = NULL;
1472 allowed_x *al = NULL;
1474 char query[MAX_QUERY_LEN] = {'\0'};
1486 snprintf(query, MAX_QUERY_LEN,
1487 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1488 "values('%s', '%s', '%s')",\
1489 sp->appid, df->path, al->text);
1490 ret = __exec_query(query);
1492 _LOGD("Package App Share Allowed DB Insert Failed\n");
1495 memset(query, '\0', MAX_QUERY_LEN);
1507 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1509 label_x *lbl = mfx->label;
1510 license_x *lcn = mfx->license;
1511 icon_x *icn = mfx->icon;
1512 description_x *dcn = mfx->description;
1513 author_x *ath = mfx->author;
1514 uiapplication_x *up = mfx->uiapplication;
1515 uiapplication_x *up_icn = mfx->uiapplication;
1516 uiapplication_x *up_image = mfx->uiapplication;
1517 serviceapplication_x *sp = mfx->serviceapplication;
1518 privileges_x *pvs = NULL;
1519 privilege_x *pv = NULL;
1520 char query[MAX_QUERY_LEN] = { '\0' };
1522 const char *auth_name = NULL;
1523 const char *auth_email = NULL;
1524 const char *auth_href = NULL;
1526 GList *pkglocale = NULL;
1527 GList *applocale = NULL;
1528 GList *appicon = NULL;
1529 GList *appimage = NULL;
1533 auth_name = ath->text;
1535 auth_email = ath->email;
1537 auth_href = ath->href;
1539 /*Insert in the package_cert_info CERT_DB*/
1540 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1541 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1542 if (ret != PMINFO_R_OK) {
1543 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1544 _LOGE("Cert Info DB create handle failed\n");
1547 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1548 if (ret != PMINFO_R_OK) {
1549 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1550 _LOGE("Cert Info DB Insert Failed\n");
1554 /*Insert in the package_info DB*/
1555 snprintf(query, MAX_QUERY_LEN,
1556 "insert into package_info(package, package_type, package_version, package_api_version, install_location, package_size, " \
1557 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1558 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1559 "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')",\
1563 __get_str(mfx->api_version),
1564 __get_str(mfx->installlocation),
1565 __get_str(mfx->package_size),
1571 mfx->nodisplay_setting,
1573 __get_str(auth_name),
1574 __get_str(auth_email),
1575 __get_str(auth_href),
1576 mfx->installed_time,
1577 mfx->installed_storage,
1578 __get_str(mfx->storeclient_id),
1580 __get_str(mfx->package_url),
1582 __get_str(mfx->csc_path),
1583 mfx->support_disable);
1585 ret = __exec_query(query);
1587 _LOGD("Package Info DB Insert Failed\n");
1591 /*Insert in the package_privilege_info DB*/
1592 pvs = mfx->privileges;
1593 while (pvs != NULL) {
1594 pv = pvs->privilege;
1595 while (pv != NULL) {
1596 memset(query, '\0', MAX_QUERY_LEN);
1597 snprintf(query, MAX_QUERY_LEN,
1598 "insert into package_privilege_info(package, privilege) " \
1599 "values('%s','%s')",\
1600 mfx->package, pv->text);
1601 ret = __exec_query(query);
1603 _LOGD("Package Privilege Info DB Insert Failed\n");
1612 ret = __insert_ui_mainapp_info(mfx);
1617 /*Insert the package locale*/
1618 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1619 /*remove duplicated data in pkglocale*/
1620 __trimfunc(pkglocale);
1622 /*Insert the app locale info */
1625 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1630 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1633 /*remove duplicated data in applocale*/
1634 __trimfunc(applocale);
1636 /*Insert the app icon info */
1637 while(up_icn != NULL)
1639 appicon = __create_icon_list(appicon, up_icn->icon);
1640 up_icn = up_icn->next;
1642 /*remove duplicated data in appicon*/
1643 __trimfunc(appicon);
1645 /*Insert the image info */
1646 while(up_image != NULL)
1648 appimage = __create_image_list(appimage, up_image->image);
1649 up_image = up_image->next;
1651 /*remove duplicated data in appimage*/
1652 __trimfunc(appimage);
1654 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1656 /*native app locale info*/
1657 up = mfx->uiapplication;
1660 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1663 /*agent app locale info*/
1664 sp = mfx->serviceapplication;
1667 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1671 /*app icon locale info*/
1672 up_icn = mfx->uiapplication;
1673 while(up_icn != NULL)
1675 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1676 up_icn = up_icn->next;
1680 up_image = mfx->uiapplication;
1681 while(up_image != NULL)
1683 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1684 up_image = up_image->next;
1687 g_list_free(pkglocale);
1689 g_list_free(applocale);
1691 g_list_free(appicon);
1693 g_list_free(appimage);
1696 /*Insert in the package_app_info DB*/
1697 ret = __insert_uiapplication_info(mfx);
1700 ret = __insert_serviceapplication_info(mfx);
1703 /*Insert in the package_app_app_control DB*/
1704 ret = __insert_uiapplication_appcontrol_info(mfx);
1707 ret = __insert_serviceapplication_appcontrol_info(mfx);
1711 /*Insert in the package_app_app_category DB*/
1712 ret = __insert_uiapplication_appcategory_info(mfx);
1715 ret = __insert_serviceapplication_appcategory_info(mfx);
1719 /*Insert in the package_app_app_metadata DB*/
1720 ret = __insert_uiapplication_appmetadata_info(mfx);
1723 ret = __insert_serviceapplication_appmetadata_info(mfx);
1727 /*Insert in the package_app_app_permission DB*/
1728 ret = __insert_uiapplication_apppermission_info(mfx);
1731 ret = __insert_serviceapplication_apppermission_info(mfx);
1735 /*Insert in the package_app_app_svc DB*/
1736 ret = __insert_uiapplication_appsvc_info(mfx);
1739 ret = __insert_serviceapplication_appsvc_info(mfx);
1743 /*Insert in the package_app_share_allowed DB*/
1744 ret = __insert_uiapplication_share_allowed_info(mfx);
1747 ret = __insert_serviceapplication_share_allowed_info(mfx);
1751 /*Insert in the package_app_share_request DB*/
1752 ret = __insert_uiapplication_share_request_info(mfx);
1755 ret = __insert_serviceapplication_share_request_info(mfx);
1759 /*Insert in the package_app_data_control DB*/
1760 ret = __insert_uiapplication_datacontrol_info(mfx);
1763 ret = __insert_serviceapplication_datacontrol_info(mfx);
1771 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1773 char query[MAX_QUERY_LEN] = { '\0' };
1775 memset(query, '\0', MAX_QUERY_LEN);
1776 snprintf(query, MAX_QUERY_LEN,
1777 "delete from %s where app_id='%s'", db_table, appid);
1778 ret = __exec_query(query);
1780 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1786 static int __delete_subpkg_info_from_db(char *appid)
1790 ret = __delete_appinfo_from_db("package_app_info", appid);
1793 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1796 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1799 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1802 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1805 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1808 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1811 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1814 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1817 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1820 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1823 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1830 static int __delete_subpkg_from_db(manifest_x *mfx)
1832 char query[MAX_QUERY_LEN] = { '\0' };
1833 char *error_message = NULL;
1835 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1837 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1838 _LOGE("Don't execute query = %s error message = %s\n", query,
1840 sqlite3_free(error_message);
1843 sqlite3_free(error_message);
1848 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1850 char query[MAX_QUERY_LEN] = { '\0' };
1852 uiapplication_x *up = mfx->uiapplication;
1853 serviceapplication_x *sp = mfx->serviceapplication;
1854 /*Delete from cert table*/
1855 if (uid != GLOBAL_USER)
1856 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1858 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1860 _LOGD("Cert Info DB Delete Failed\n");
1864 /*Delete from Package Info DB*/
1865 snprintf(query, MAX_QUERY_LEN,
1866 "delete from package_info where package='%s'", mfx->package);
1867 ret = __exec_query(query);
1869 _LOGD("Package Info DB Delete Failed\n");
1872 memset(query, '\0', MAX_QUERY_LEN);
1874 /*Delete from Package Localized Info*/
1875 snprintf(query, MAX_QUERY_LEN,
1876 "delete from package_localized_info where package='%s'", mfx->package);
1877 ret = __exec_query(query);
1879 _LOGD("Package Localized Info DB Delete Failed\n");
1883 /*Delete from Package Privilege Info*/
1884 snprintf(query, MAX_QUERY_LEN,
1885 "delete from package_privilege_info where package='%s'", mfx->package);
1886 ret = __exec_query(query);
1888 _LOGD("Package Privilege Info DB Delete Failed\n");
1892 while (up != NULL) {
1893 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1896 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1899 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
1902 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
1905 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
1908 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
1911 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
1914 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
1917 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
1920 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
1923 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
1926 ret = __delete_appinfo_from_db("package_app_data_control", up->appid);
1932 while (sp != NULL) {
1933 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
1936 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
1939 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
1942 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
1945 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
1948 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
1951 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
1954 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
1957 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
1960 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
1963 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
1966 ret = __delete_appinfo_from_db("package_app_data_control", sp->appid);
1972 /* if main package has sub pkg, delete sub pkg data*/
1973 __delete_subpkg_from_db(mfx);
1978 static int __update_preload_condition_in_db()
1981 char query[MAX_QUERY_LEN] = {'\0'};
1983 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
1985 ret = __exec_query(query);
1987 _LOGD("Package preload_condition update failed\n");
1992 API int pkgmgr_parser_initialize_db(uid_t uid)
1996 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
1998 _LOGD("package info DB initialization failed\n");
2001 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2003 _LOGD("package localized info DB initialization failed\n");
2006 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2008 _LOGD("package app app privilege DB initialization failed\n");
2011 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2013 _LOGD("package app info DB initialization failed\n");
2016 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2018 _LOGD("package app localized info DB initialization failed\n");
2021 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2023 _LOGD("package app icon localized info DB initialization failed\n");
2026 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2028 _LOGD("package app image info DB initialization failed\n");
2031 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2033 _LOGD("package app app control DB initialization failed\n");
2036 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2038 _LOGD("package app app category DB initialization failed\n");
2041 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2043 _LOGD("package app app category DB initialization failed\n");
2046 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2048 _LOGD("package app app permission DB initialization failed\n");
2051 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2053 _LOGD("package app app svc DB initialization failed\n");
2056 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2058 _LOGD("package app share allowed DB initialization failed\n");
2061 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2063 _LOGD("package app share request DB initialization failed\n");
2066 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2068 _LOGD("package app data control DB initialization failed\n");
2072 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2074 _LOGD("package cert info DB initialization failed\n");
2077 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2079 _LOGD("package cert index info DB initialization failed\n");
2083 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
2084 _LOGD("Failed to change cert db permission\n");
2086 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2087 _LOGD("Failed to change parser db permission\n");
2093 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2096 char journal_file[BUFSIZE];
2099 struct passwd *userinfo = NULL;
2100 files[0] = (char *)db_file;
2101 files[1] = journal_file;
2104 if (db_file == NULL)
2107 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2109 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2110 if (uid == OWNER_ROOT)
2112 userinfo = getpwuid(uid);
2114 _LOGE("FAIL: user %d doesn't exist", uid);
2117 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2119 for (i = 0; files[i]; i++) {
2120 ret = chown(files[i], uid, userinfo->pw_gid);
2122 if (strerror_r(errno, buf, sizeof(buf)))
2124 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2125 userinfo->pw_gid, buf);
2129 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
2131 if (strerror_r(errno, buf, sizeof(buf)))
2133 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2136 SET_SMACK_LABEL(files[i]);
2141 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2145 if (getuid() != OWNER_ROOT) {
2146 _LOGE("Only root user is allowed");
2150 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2151 _LOGE("Manifest db for user %d is already exists", uid);
2155 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2156 _LOGE("Cert db for user %d is already exists", uid);
2160 ret = pkgmgr_parser_check_and_create_db(uid);
2163 ret = pkgmgr_parser_initialize_db(uid);
2165 pkgmgr_parser_close_db();
2168 pkgmgr_parser_close_db();
2173 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2177 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2179 _LOGD("Manifest DB creation Failed\n");
2184 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid));
2186 _LOGD("Cert DB creation Failed\n");
2192 void pkgmgr_parser_close_db(void)
2194 sqlite3_close(pkgmgr_parser_db);
2195 sqlite3_close(pkgmgr_cert_db);
2199 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2201 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2203 _LOGD("manifest pointer is NULL\n");
2207 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2209 _LOGD("Failed to open DB\n");
2212 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2215 /*Begin transaction*/
2216 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2217 if (ret != SQLITE_OK) {
2218 _LOGD("Failed to begin transaction\n");
2222 _LOGD("Transaction Begin\n");
2223 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2225 _LOGD("Insert into DB failed. Rollback now\n");
2226 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2229 /*Commit transaction*/
2230 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2231 if (ret != SQLITE_OK) {
2232 _LOGD("Failed to commit transaction. Rollback now\n");
2233 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2237 _LOGD("Transaction Commit and End\n");
2239 pkgmgr_parser_close_db();
2243 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2245 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2247 _LOGD("manifest pointer is NULL\n");
2251 ret = pkgmgr_parser_check_and_create_db(uid);
2253 _LOGD("Failed to open DB\n");
2256 ret = pkgmgr_parser_initialize_db(uid);
2259 /*Begin transaction*/
2260 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2261 if (ret != SQLITE_OK) {
2262 _LOGD("Failed to begin transaction\n");
2266 _LOGD("Transaction Begin\n");
2267 ret = __insert_manifest_info_in_db(mfx, uid);
2269 _LOGD("Insert into DB failed. Rollback now\n");
2270 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2273 /*Commit transaction*/
2274 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2275 if (ret != SQLITE_OK) {
2276 _LOGD("Failed to commit transaction. Rollback now\n");
2277 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2281 _LOGD("Transaction Commit and End\n");
2283 pkgmgr_parser_close_db();
2287 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2290 _LOGD("manifest pointer is NULL\n");
2294 ret = pkgmgr_parser_check_and_create_db(uid);
2296 _LOGD("Failed to open DB\n");
2299 ret = pkgmgr_parser_initialize_db(uid);
2302 /*Preserve guest mode visibility*/
2303 __preserve_guestmode_visibility_value( mfx);
2304 /*Begin transaction*/
2305 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2306 if (ret != SQLITE_OK) {
2307 _LOGD("Failed to begin transaction\n");
2311 _LOGD("Transaction Begin\n");
2312 ret = __delete_manifest_info_from_db(mfx, uid);
2314 _LOGD("Delete from DB failed. Rollback now\n");
2315 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2318 ret = __insert_manifest_info_in_db(mfx, uid);
2320 _LOGD("Insert into DB failed. Rollback now\n");
2321 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2325 /*Commit transaction*/
2326 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2327 if (ret != SQLITE_OK) {
2328 _LOGD("Failed to commit transaction. Rollback now\n");
2329 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2333 _LOGD("Transaction Commit and End\n");
2335 pkgmgr_parser_close_db();
2339 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2341 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2344 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2347 _LOGD("manifest pointer is NULL\n");
2351 ret = pkgmgr_parser_check_and_create_db(uid);
2353 _LOGD("Failed to open DB\n");
2356 /*Begin transaction*/
2357 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2358 if (ret != SQLITE_OK) {
2359 _LOGD("Failed to begin transaction\n");
2363 _LOGD("Transaction Begin\n");
2364 ret = __delete_manifest_info_from_db(mfx, uid);
2366 _LOGD("Delete from DB failed. Rollback now\n");
2367 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2370 /*Commit transaction*/
2371 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2372 if (ret != SQLITE_OK) {
2373 _LOGD("Failed to commit transaction, Rollback now\n");
2374 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2378 _LOGD("Transaction Commit and End\n");
2380 pkgmgr_parser_close_db();
2384 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2386 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2389 API int pkgmgr_parser_update_preload_info_in_db()
2392 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2394 _LOGD("Failed to open DB\n");
2397 /*Begin transaction*/
2398 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2399 if (ret != SQLITE_OK) {
2400 _LOGD("Failed to begin transaction\n");
2404 _LOGD("Transaction Begin\n");
2405 ret = __update_preload_condition_in_db();
2407 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2408 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2411 /*Commit transaction*/
2412 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2413 if (ret != SQLITE_OK) {
2414 _LOGD("Failed to commit transaction, Rollback now\n");
2415 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2419 _LOGD("Transaction Commit and End\n");
2421 pkgmgr_parser_close_db();
2425 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2428 ret = pkgmgr_parser_check_and_create_db(uid);
2430 _LOGD("Failed to open DB\n");
2433 /*Begin transaction*/
2434 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2435 if (ret != SQLITE_OK) {
2436 _LOGD("Failed to begin transaction\n");
2440 _LOGD("Transaction Begin\n");
2441 ret = __update_preload_condition_in_db();
2443 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2444 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2447 /*Commit transaction*/
2448 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2449 if (ret != SQLITE_OK) {
2450 _LOGD("Failed to commit transaction, Rollback now\n");
2451 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2455 _LOGD("Transaction Commit and End\n");
2457 pkgmgr_parser_close_db();