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 DB_LABEL "User::Home"
56 #define SET_SMACK_LABEL(x) \
58 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
59 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
61 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
64 sqlite3 *pkgmgr_parser_db;
65 sqlite3 *pkgmgr_cert_db;
68 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
69 "(package text primary key not null, " \
70 "package_type text DEFAULT 'rpm', " \
71 "package_version text, " \
72 "package_api_version text, " \
73 "install_location text, " \
74 "package_size text, " \
75 "package_removable text DEFAULT 'true', " \
76 "package_preload text DEFAULT 'false', " \
77 "package_readonly text DEFAULT 'false', " \
78 "package_update text DEFAULT 'false', " \
79 "package_appsetting text DEFAULT 'false', " \
80 "package_nodisplay text DEFAULT 'false', " \
81 "package_system text DEFAULT 'false', " \
82 "author_name text, " \
83 "author_email text, " \
85 "installed_time text," \
86 "installed_storage text," \
87 "storeclient_id text," \
92 "package_support_disable text DEFAULT 'false')"
94 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
95 "(package text not null, " \
96 "package_locale text DEFAULT 'No Locale', " \
97 "package_label text, " \
98 "package_icon text, " \
99 "package_description text, " \
100 "package_license text, " \
102 "PRIMARY KEY(package, package_locale), " \
103 "FOREIGN KEY(package) " \
104 "REFERENCES package_info(package) " \
107 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
108 "(package text not null, " \
109 "privilege text not null, " \
110 "PRIMARY KEY(package, privilege) " \
111 "FOREIGN KEY(package) " \
112 "REFERENCES package_info(package) " \
115 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
116 "(app_id text primary key not null, " \
117 "app_component text, " \
119 "app_nodisplay text DEFAULT 'false', " \
121 "app_onboot text DEFAULT 'false', " \
122 "app_multiple text DEFAULT 'false', " \
123 "app_autorestart text DEFAULT 'false', " \
124 "app_taskmanage text DEFAULT 'false', " \
125 "app_enabled text DEFAULT 'true', " \
126 "app_hwacceleration text DEFAULT 'use-system-setting', " \
127 "app_screenreader text DEFAULT 'use-system-setting', " \
128 "app_mainapp text, " \
129 "app_recentimage text, " \
130 "app_launchcondition text, " \
131 "app_indicatordisplay text DEFAULT 'true', " \
132 "app_portraitimg text, " \
133 "app_landscapeimg text, " \
134 "app_guestmodevisibility text DEFAULT 'true', " \
135 "app_permissiontype text DEFAULT 'normal', " \
136 "app_preload text DEFAULT 'false', " \
137 "app_submode text DEFAULT 'false', " \
138 "app_submode_mainid text, " \
139 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
140 "app_ui_gadget text DEFAULT 'false', " \
141 "app_support_disable text DEFAULT 'false', " \
142 "component_type text, " \
143 "package text not null, " \
144 "FOREIGN KEY(package) " \
145 "REFERENCES package_info(package) " \
148 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
149 "(app_id text not null, " \
150 "app_locale text DEFAULT 'No Locale', " \
153 "PRIMARY KEY(app_id,app_locale) " \
154 "FOREIGN KEY(app_id) " \
155 "REFERENCES package_app_info(app_id) " \
158 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
159 "(app_id text not null, " \
161 "app_icon_section text, " \
162 "app_icon_resolution text, " \
163 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
164 "FOREIGN KEY(app_id) " \
165 "REFERENCES package_app_info(app_id) " \
168 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
169 "(app_id text not null, " \
170 "app_locale text DEFAULT 'No Locale', " \
171 "app_image_section text, " \
173 "PRIMARY KEY(app_id,app_image_section) " \
174 "FOREIGN KEY(app_id) " \
175 "REFERENCES package_app_info(app_id) " \
178 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
179 "(app_id text not null, " \
180 "app_control text not null, " \
181 "PRIMARY KEY(app_id,app_control) " \
182 "FOREIGN KEY(app_id) " \
183 "REFERENCES package_app_info(app_id) " \
186 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
187 "(app_id text not null, " \
188 "operation text not null, " \
189 "uri_scheme text, " \
191 "subapp_name text, " \
192 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
193 "FOREIGN KEY(app_id) " \
194 "REFERENCES package_app_info(app_id) " \
197 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
198 "(app_id text not null, " \
199 "category text not null, " \
200 "PRIMARY KEY(app_id,category) " \
201 "FOREIGN KEY(app_id) " \
202 "REFERENCES package_app_info(app_id) " \
205 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
206 "(app_id text not null, " \
207 "md_key text not null, " \
208 "md_value text not null, " \
209 "PRIMARY KEY(app_id, md_key, md_value) " \
210 "FOREIGN KEY(app_id) " \
211 "REFERENCES package_app_info(app_id) " \
214 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
215 "(app_id text not null, " \
216 "pm_type text not null, " \
217 "pm_value text not null, " \
218 "PRIMARY KEY(app_id, pm_type, pm_value) " \
219 "FOREIGN KEY(app_id) " \
220 "REFERENCES package_app_info(app_id) " \
223 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
224 "(app_id text not null, " \
225 "data_share_path text not null, " \
226 "data_share_allowed text not null, " \
227 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
228 "FOREIGN KEY(app_id) " \
229 "REFERENCES package_app_info(app_id) " \
232 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
233 "(app_id text not null, " \
234 "data_share_request text not null, " \
235 "PRIMARY KEY(app_id,data_share_request) " \
236 "FOREIGN KEY(app_id) " \
237 "REFERENCES package_app_info(app_id) " \
240 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
241 "(cert_info text not null, " \
242 "cert_id integer, " \
243 "cert_ref_count integer, " \
244 "PRIMARY KEY(cert_id)) "
246 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
247 "(package text not null, " \
248 "author_root_cert integer, " \
249 "author_im_cert integer, " \
250 "author_signer_cert integer, " \
251 "dist_root_cert integer, " \
252 "dist_im_cert integer, " \
253 "dist_signer_cert integer, " \
254 "dist2_root_cert integer, " \
255 "dist2_im_cert integer, " \
256 "dist2_signer_cert integer, " \
257 "PRIMARY KEY(package)) "
259 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
260 "(app_id text not null, " \
261 "providerid text not null, " \
262 "access text not null, " \
263 "type text not null, " \
264 "PRIMARY KEY(app_id, providerid, access, type) " \
265 "FOREIGN KEY(app_id) " \
266 "REFERENCES package_app_info(app_id) " \
269 static int __insert_uiapplication_info(manifest_x *mfx);
270 static int __insert_serviceapplication_info(manifest_x *mfx);
271 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
272 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
273 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
274 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
275 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
276 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
277 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
278 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
279 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
280 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
281 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
282 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
283 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx);
284 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx);
285 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
286 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
287 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
288 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
289 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
290 static int __delete_subpkg_info_from_db(char *appid);
291 static int __delete_appinfo_from_db(char *db_table, const char *appid);
292 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
293 static int __exec_query(char *query);
294 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
295 char **label, char **license, char **icon, char **description, char **author);
296 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
297 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
298 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
299 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
300 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
301 static int __parserdb_change_perm(const char *db_file, uid_t uid);
303 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
306 __delete_subpkg_info_from_db(coltxt[0]);
311 static const char *__get_str(const char *str)
315 return PKGMGR_PARSER_EMPTY_STR;
321 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
326 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
327 if (ret != SQLITE_OK) {
328 _LOGD("connect db [%s] failed!\n", db_path);
336 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
338 manifest_x *mfx = (manifest_x *)data;
342 uiapplication_x *uiapp = NULL;
343 for(i = 0; i < ncols; i++)
345 uiapp = mfx->uiapplication;
346 if (strcmp(colname[i], "app_id") == 0) {
348 appid = strdup(coltxt[i]);
349 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
351 status = strdup(coltxt[i]);
355 _LOGD("app id is NULL\n");
358 /*update guest mode visibility*/
359 for (; uiapp != NULL; uiapp = uiapp->next) {
360 if (strcmp(uiapp->appid, appid) == 0) {
361 free((void *)uiapp->guestmode_visibility);
362 uiapp->guestmode_visibility = strdup(status);
378 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
380 char *error_message = NULL;
381 char query[MAX_QUERY_LEN] = {'\0'};
382 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
384 sqlite3_exec(pkgmgr_parser_db, query,
385 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
386 _LOGD("Don't execute query = %s error message = %s\n",
387 query, error_message);
388 sqlite3_free(error_message);
393 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
395 char *error_message = NULL;
397 sqlite3_exec(db_handle, db_query,
398 NULL, NULL, &error_message)) {
399 _LOGD("Don't execute query = %s error message = %s\n",
400 db_query, error_message);
401 sqlite3_free(error_message);
404 sqlite3_free(error_message);
408 static int __exec_query(char *query)
410 char *error_message = NULL;
412 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
413 _LOGD("Don't execute query = %s error message = %s\n", query,
415 sqlite3_free(error_message);
418 sqlite3_free(error_message);
422 static int __exec_query_no_msg(char *query)
424 char *error_message = NULL;
426 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
427 sqlite3_free(error_message);
430 sqlite3_free(error_message);
434 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
440 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
446 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
452 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
458 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
464 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
471 static GList *__create_icon_list(GList *locale, icon_x *icn)
476 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
482 static GList *__create_image_list(GList *locale, image_x *image)
487 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
493 static void __trimfunc(GList* trim_list)
495 char *trim_data = NULL;
499 list = g_list_first(trim_list);
502 trim_data = (char *)list->data;
505 if (strcmp(trim_data, prev) == 0) {
506 trim_list = g_list_remove(trim_list, trim_data);
507 list = g_list_first(trim_list);
516 list = g_list_next(list);
520 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
522 if (a == NULL || b == NULL)
524 if (strcmp((char*)a, (char*)b) == 0)
526 if (strcmp((char*)a, (char*)b) < 0)
528 if (strcmp((char*)a, (char*)b) > 0)
533 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
534 char **label, char **license, char **icon, char **description, char **author)
539 if (strcmp(lbl->lang, (char *)data) == 0) {
540 *label = (char*)lbl->text;
549 if (strcmp(lcn->lang, (char *)data) == 0) {
550 *license = (char*)lcn->text;
559 if (strcmp(icn->lang, (char *)data) == 0) {
560 *icon = (char*)icn->text;
569 if (strcmp(dcn->lang, (char *)data) == 0) {
570 *description = (char*)dcn->text;
579 if (strcmp(ath->lang, (char *)data) == 0) {
580 *author = (char*)ath->text;
589 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
594 if (strcmp(icn->section, (char *)data) == 0) {
595 *icon = (char*)icn->text;
596 *resolution = (char*)icn->resolution;
604 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
608 if (image->section) {
609 if (strcmp(image->section, (char *)data) == 0) {
610 *lang = (char*)image->lang;
611 *img = (char*)image->text;
619 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
624 char *description = NULL;
625 char *license = NULL;
627 char query[MAX_QUERY_LEN] = {'\0'};
629 manifest_x *mfx = (manifest_x *)userdata;
630 label_x *lbl = mfx->label;
631 license_x *lcn = mfx->license;
632 icon_x *icn = mfx->icon;
633 description_x *dcn = mfx->description;
634 author_x *ath = mfx->author;
636 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
637 if (!label && !description && !icon && !license && !author)
640 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
641 "package_label, package_icon, package_description, package_license, package_author) values " \
642 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
647 __get_str(description),
651 ret = __exec_query(query);
653 _LOGD("Package Localized Info DB Insert failed\n");
656 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
661 char query[MAX_QUERY_LEN] = {'\0'};
663 uiapplication_x *up = (uiapplication_x*)userdata;
664 label_x *lbl = up->label;
665 icon_x *icn = up->icon;
667 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
670 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
671 "app_label, app_icon) values " \
672 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
674 ret = __exec_query(query);
676 _LOGD("Package UiApp Localized Info DB Insert failed\n");
678 /*insert ui app locale info to pkg locale to get mainapp data */
679 if (strcasecmp(up->mainapp, "true")==0) {
680 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
681 "package_label, package_icon, package_description, package_license, package_author) values " \
682 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
687 PKGMGR_PARSER_EMPTY_STR,
688 PKGMGR_PARSER_EMPTY_STR,
689 PKGMGR_PARSER_EMPTY_STR);
691 ret = __exec_query_no_msg(query);
694 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
695 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
696 ret = __exec_query_no_msg(query);
701 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
705 char *resolution = NULL;
706 char query[MAX_QUERY_LEN] = {'\0'};
708 uiapplication_x *up = (uiapplication_x*)userdata;
709 icon_x *icn = up->icon;
711 __extract_icon_data(data, icn, &icon, &resolution);
712 if (!icon && !resolution)
714 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
715 "app_icon, app_icon_section, app_icon_resolution) values " \
716 "('%q', '%q', '%q', '%q')", up->appid,
717 icon, (char*)data, resolution);
719 ret = __exec_query(query);
721 _LOGD("Package UiApp Localized Info DB Insert failed\n");
725 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
730 char query[MAX_QUERY_LEN] = {'\0'};
732 uiapplication_x *up = (uiapplication_x*)userdata;
733 image_x *image = up->image;
735 __extract_image_data(data, image, &lang, &img);
738 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
739 "app_image_section, app_image) values " \
740 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
742 ret = __exec_query(query);
744 _LOGD("Package UiApp image Info DB Insert failed\n");
749 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
754 char query[MAX_QUERY_LEN] = {'\0'};
756 serviceapplication_x *sp = (serviceapplication_x*)userdata;
757 label_x *lbl = sp->label;
758 icon_x *icn = sp->icon;
760 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
763 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
764 "app_label, app_icon) values " \
765 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
767 ret = __exec_query(query);
769 _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
772 static int __insert_ui_mainapp_info(manifest_x *mfx)
774 uiapplication_x *up = mfx->uiapplication;
776 char query[MAX_QUERY_LEN] = {'\0'};
779 snprintf(query, MAX_QUERY_LEN,
780 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
782 ret = __exec_query(query);
784 _LOGD("Package UiApp Info DB Insert Failed\n");
787 if (strcasecmp(up->mainapp, "True")==0)
788 mfx->mainapp_id = strdup(up->appid);
791 memset(query, '\0', MAX_QUERY_LEN);
794 if (mfx->mainapp_id == NULL){
795 if (mfx->uiapplication && mfx->uiapplication->appid) {
796 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
798 _LOGD("Not valid appid\n");
802 ret = __exec_query(query);
804 _LOGD("Package UiApp Info DB Insert Failed\n");
808 free((void *)mfx->uiapplication->mainapp);
809 mfx->uiapplication->mainapp= strdup("true");
810 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
813 memset(query, '\0', MAX_QUERY_LEN);
814 snprintf(query, MAX_QUERY_LEN,
815 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
816 ret = __exec_query(query);
818 _LOGD("Package Info DB update Failed\n");
824 /* _PRODUCT_LAUNCHING_ENHANCED_
825 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
827 static int __insert_uiapplication_info(manifest_x *mfx)
829 uiapplication_x *up = mfx->uiapplication;
831 char query[MAX_QUERY_LEN] = {'\0'};
834 snprintf(query, MAX_QUERY_LEN,
835 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
836 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
837 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
838 "app_preload, app_submode, app_submode_mainid, app_launch_mode, app_ui_gadget, app_support_disable, component_type, package) " \
839 "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')",\
845 PKGMGR_PARSER_EMPTY_STR,
847 PKGMGR_PARSER_EMPTY_STR,
853 __get_str(up->recentimage),
855 up->indicatordisplay,
856 __get_str(up->portraitimg),
857 __get_str(up->landscapeimg),
858 up->guestmode_visibility,
862 __get_str(up->submode_mainid),
865 mfx->support_disable,
869 ret = __exec_query(query);
871 _LOGD("Package UiApp Info DB Insert Failed\n");
875 memset(query, '\0', MAX_QUERY_LEN);
880 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
882 uiapplication_x *up = mfx->uiapplication;
883 category_x *ct = NULL;
885 char query[MAX_QUERY_LEN] = {'\0'};
891 snprintf(query, MAX_QUERY_LEN,
892 "insert into package_app_app_category(app_id, category) " \
893 "values('%s','%s')",\
894 up->appid, ct->name);
895 ret = __exec_query(query);
897 _LOGD("Package UiApp Category Info DB Insert Failed\n");
901 memset(query, '\0', MAX_QUERY_LEN);
908 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
910 uiapplication_x *up = mfx->uiapplication;
911 metadata_x *md = NULL;
913 char query[MAX_QUERY_LEN] = {'\0'};
920 snprintf(query, MAX_QUERY_LEN,
921 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
922 "values('%s','%s', '%s')",\
923 up->appid, md->key, md->value ? md->value : "");
924 ret = __exec_query(query);
926 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
931 memset(query, '\0', MAX_QUERY_LEN);
938 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
940 uiapplication_x *up = mfx->uiapplication;
941 permission_x *pm = NULL;
943 char query[MAX_QUERY_LEN] = {'\0'};
949 snprintf(query, MAX_QUERY_LEN,
950 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
951 "values('%s','%s', '%s')",\
952 up->appid, pm->type, pm->value);
953 ret = __exec_query(query);
955 _LOGD("Package UiApp permission Info DB Insert Failed\n");
959 memset(query, '\0', MAX_QUERY_LEN);
966 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
968 uiapplication_x *up = mfx->uiapplication;
969 appcontrol_x *acontrol = NULL;
971 char query[MAX_QUERY_LEN] = {'\0'};
972 char buf[BUFSIZE] = {'\0'};
974 acontrol = up->appcontrol;
975 while (acontrol != NULL) {
976 snprintf(buf, BUFSIZE, "%s|%s|%s",\
977 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
978 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
979 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
980 snprintf(query, MAX_QUERY_LEN,
981 "insert into package_app_app_control(app_id, app_control) " \
982 "values('%s', '%s')",\
984 ret = __exec_query(query);
986 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
989 memset(query, '\0', MAX_QUERY_LEN);
990 acontrol = acontrol->next;
997 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
999 uiapplication_x *up = mfx->uiapplication;
1000 appsvc_x *asvc = NULL;
1001 operation_x *op = NULL;
1004 subapp_x *sub = NULL;
1006 char query[MAX_QUERY_LEN] = {'\0'};
1007 const char *operation = NULL;
1008 const char *mime = NULL;
1009 const char *uri = NULL;
1010 const char *subapp = NULL;
1016 op = asvc->operation;
1020 operation = op->name;
1037 snprintf(query, MAX_QUERY_LEN,
1038 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1039 "values('%s', '%s', '%s', '%s', '%s')",\
1046 ret = __exec_query(query);
1048 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1051 memset(query, '\0', MAX_QUERY_LEN);
1055 } while(ui != NULL);
1059 }while(sub != NULL);
1075 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx)
1077 uiapplication_x *up = mfx->uiapplication;
1078 datacontrol_x *dc = NULL;
1080 char query[MAX_QUERY_LEN] = {'\0'};
1084 dc = up->datacontrol;
1087 snprintf(query, MAX_QUERY_LEN,
1088 "insert into package_app_data_control(app_id, providerid, access, type) " \
1089 "values('%s', '%s', '%s', '%s')",\
1090 mfx->uiapplication->appid,
1095 ret = __exec_query(query);
1097 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1100 memset(query, '\0', MAX_QUERY_LEN);
1108 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1110 uiapplication_x *up = mfx->uiapplication;
1111 datashare_x *ds = NULL;
1112 request_x *rq = NULL;
1114 char query[MAX_QUERY_LEN] = {'\0'};
1123 snprintf(query, MAX_QUERY_LEN,
1124 "insert into package_app_share_request(app_id, data_share_request) " \
1125 "values('%s', '%s')",\
1126 up->appid, rq->text);
1127 ret = __exec_query(query);
1129 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1132 memset(query, '\0', MAX_QUERY_LEN);
1142 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1144 uiapplication_x *up = mfx->uiapplication;
1145 datashare_x *ds = NULL;
1146 define_x *df = NULL;
1147 allowed_x *al = NULL;
1149 char query[MAX_QUERY_LEN] = {'\0'};
1161 snprintf(query, MAX_QUERY_LEN,
1162 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1163 "values('%s', '%s', '%s')",\
1164 up->appid, df->path, al->text);
1165 ret = __exec_query(query);
1167 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1170 memset(query, '\0', MAX_QUERY_LEN);
1182 static int __insert_serviceapplication_info(manifest_x *mfx)
1184 serviceapplication_x *sp = mfx->serviceapplication;
1186 char query[MAX_QUERY_LEN] = {'\0'};
1189 snprintf(query, MAX_QUERY_LEN,
1190 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1191 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1192 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1193 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1194 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1195 ret = __exec_query(query);
1197 _LOGD("Package ServiceApp Info DB Insert Failed\n");
1201 memset(query, '\0', MAX_QUERY_LEN);
1206 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1208 serviceapplication_x *sp = mfx->serviceapplication;
1209 category_x *ct = NULL;
1211 char query[MAX_QUERY_LEN] = {'\0'};
1217 snprintf(query, MAX_QUERY_LEN,
1218 "insert into package_app_app_category(app_id, category) " \
1219 "values('%s','%s')",\
1220 sp->appid, ct->name);
1221 ret = __exec_query(query);
1223 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1227 memset(query, '\0', MAX_QUERY_LEN);
1234 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1236 serviceapplication_x *sp = mfx->serviceapplication;
1237 metadata_x *md = NULL;
1239 char query[MAX_QUERY_LEN] = {'\0'};
1246 snprintf(query, MAX_QUERY_LEN,
1247 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1248 "values('%s','%s', '%s')",\
1249 sp->appid, md->key, md->value ? md->value : "");
1250 ret = __exec_query(query);
1252 _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1257 memset(query, '\0', MAX_QUERY_LEN);
1264 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1266 serviceapplication_x *sp = mfx->serviceapplication;
1267 permission_x *pm = NULL;
1269 char query[MAX_QUERY_LEN] = {'\0'};
1272 pm = sp->permission;
1275 snprintf(query, MAX_QUERY_LEN,
1276 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1277 "values('%s','%s', '%s')",\
1278 sp->appid, pm->type, pm->value);
1279 ret = __exec_query(query);
1281 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1285 memset(query, '\0', MAX_QUERY_LEN);
1292 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1294 serviceapplication_x *sp = mfx->serviceapplication;
1295 appcontrol_x *acontrol = NULL;
1297 char query[MAX_QUERY_LEN] = {'\0'};
1298 char buf[BUFSIZE] = {'\0'};
1299 while (sp != NULL) {
1300 acontrol = sp->appcontrol;
1301 while (acontrol != NULL) {
1302 snprintf(buf, BUFSIZE, "%s|%s|%s",
1303 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1304 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1305 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1306 snprintf(query, MAX_QUERY_LEN,
1307 "insert into package_app_app_control(app_id, app_control) " \
1308 "values('%s', '%s')",\
1310 ret = __exec_query(query);
1312 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1315 memset(query, '\0', MAX_QUERY_LEN);
1316 acontrol = acontrol->next;
1323 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1325 serviceapplication_x *sp = mfx->serviceapplication;
1326 appsvc_x *asvc = NULL;
1328 char query[MAX_QUERY_LEN] = {'\0'};
1329 operation_x *op = NULL;
1332 subapp_x *sub = NULL;
1333 const char *operation = NULL;
1334 const char *mime = NULL;
1335 const char *uri = NULL;
1336 const char *subapp = NULL;
1342 op = asvc->operation;
1346 operation = op->name;
1362 snprintf(query, MAX_QUERY_LEN,
1363 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1364 "values('%s', '%s', '%s', '%s', '%s')",\
1370 ret = __exec_query(query);
1372 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1375 memset(query, '\0', MAX_QUERY_LEN);
1379 } while(ui != NULL);
1383 }while(sub != NULL);
1399 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx)
1401 serviceapplication_x *sp = mfx->serviceapplication;
1402 datacontrol_x *dc = NULL;
1404 char query[MAX_QUERY_LEN] = {'\0'};
1408 dc = sp->datacontrol;
1411 snprintf(query, MAX_QUERY_LEN,
1412 "insert into package_app_data_control(app_id, providerid, access, type) " \
1413 "values('%s', '%s', '%s', '%s')",\
1414 mfx->serviceapplication->appid,
1419 ret = __exec_query(query);
1421 _LOGD("Package ServiceApp Data Control DB Insert Failed\n");
1424 memset(query, '\0', MAX_QUERY_LEN);
1432 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1434 serviceapplication_x *sp = mfx->serviceapplication;
1435 datashare_x *ds = NULL;
1436 request_x *rq = NULL;
1438 char query[MAX_QUERY_LEN] = {'\0'};
1447 snprintf(query, MAX_QUERY_LEN,
1448 "insert into package_app_share_request(app_id, data_share_request) " \
1449 "values('%s', '%s')",\
1450 sp->appid, rq->text);
1451 ret = __exec_query(query);
1453 _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1456 memset(query, '\0', MAX_QUERY_LEN);
1468 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1470 serviceapplication_x *sp = mfx->serviceapplication;
1471 datashare_x *ds = NULL;
1472 define_x *df = NULL;
1473 allowed_x *al = NULL;
1475 char query[MAX_QUERY_LEN] = {'\0'};
1487 snprintf(query, MAX_QUERY_LEN,
1488 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1489 "values('%s', '%s', '%s')",\
1490 sp->appid, df->path, al->text);
1491 ret = __exec_query(query);
1493 _LOGD("Package App Share Allowed DB Insert Failed\n");
1496 memset(query, '\0', MAX_QUERY_LEN);
1508 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1510 label_x *lbl = mfx->label;
1511 license_x *lcn = mfx->license;
1512 icon_x *icn = mfx->icon;
1513 description_x *dcn = mfx->description;
1514 author_x *ath = mfx->author;
1515 uiapplication_x *up = mfx->uiapplication;
1516 uiapplication_x *up_icn = mfx->uiapplication;
1517 uiapplication_x *up_image = mfx->uiapplication;
1518 serviceapplication_x *sp = mfx->serviceapplication;
1519 privileges_x *pvs = NULL;
1520 privilege_x *pv = NULL;
1521 char query[MAX_QUERY_LEN] = { '\0' };
1523 const char *auth_name = NULL;
1524 const char *auth_email = NULL;
1525 const char *auth_href = NULL;
1527 GList *pkglocale = NULL;
1528 GList *applocale = NULL;
1529 GList *appicon = NULL;
1530 GList *appimage = NULL;
1534 auth_name = ath->text;
1536 auth_email = ath->email;
1538 auth_href = ath->href;
1540 /*Insert in the package_cert_info CERT_DB*/
1541 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1542 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1543 if (ret != PMINFO_R_OK) {
1544 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1545 _LOGE("Cert Info DB create handle failed\n");
1548 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1549 if (ret != PMINFO_R_OK) {
1550 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1551 _LOGE("Cert Info DB Insert Failed\n");
1555 /*Insert in the package_info DB*/
1556 snprintf(query, MAX_QUERY_LEN,
1557 "insert into package_info(package, package_type, package_version, package_api_version, install_location, package_size, " \
1558 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1559 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1560 "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')",\
1564 __get_str(mfx->api_version),
1565 __get_str(mfx->installlocation),
1566 __get_str(mfx->package_size),
1572 mfx->nodisplay_setting,
1574 __get_str(auth_name),
1575 __get_str(auth_email),
1576 __get_str(auth_href),
1577 mfx->installed_time,
1578 mfx->installed_storage,
1579 __get_str(mfx->storeclient_id),
1581 __get_str(mfx->package_url),
1583 __get_str(mfx->csc_path),
1584 mfx->support_disable);
1586 ret = __exec_query(query);
1588 _LOGD("Package Info DB Insert Failed\n");
1592 /*Insert in the package_privilege_info DB*/
1593 pvs = mfx->privileges;
1594 while (pvs != NULL) {
1595 pv = pvs->privilege;
1596 while (pv != NULL) {
1597 memset(query, '\0', MAX_QUERY_LEN);
1598 snprintf(query, MAX_QUERY_LEN,
1599 "insert into package_privilege_info(package, privilege) " \
1600 "values('%s','%s')",\
1601 mfx->package, pv->text);
1602 ret = __exec_query(query);
1604 _LOGD("Package Privilege Info DB Insert Failed\n");
1613 ret = __insert_ui_mainapp_info(mfx);
1618 /*Insert the package locale*/
1619 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1620 /*remove duplicated data in pkglocale*/
1621 __trimfunc(pkglocale);
1623 /*Insert the app locale info */
1626 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1631 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1634 /*remove duplicated data in applocale*/
1635 __trimfunc(applocale);
1637 /*Insert the app icon info */
1638 while(up_icn != NULL)
1640 appicon = __create_icon_list(appicon, up_icn->icon);
1641 up_icn = up_icn->next;
1643 /*remove duplicated data in appicon*/
1644 __trimfunc(appicon);
1646 /*Insert the image info */
1647 while(up_image != NULL)
1649 appimage = __create_image_list(appimage, up_image->image);
1650 up_image = up_image->next;
1652 /*remove duplicated data in appimage*/
1653 __trimfunc(appimage);
1655 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1657 /*native app locale info*/
1658 up = mfx->uiapplication;
1661 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1664 /*agent app locale info*/
1665 sp = mfx->serviceapplication;
1668 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1672 /*app icon locale info*/
1673 up_icn = mfx->uiapplication;
1674 while(up_icn != NULL)
1676 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1677 up_icn = up_icn->next;
1681 up_image = mfx->uiapplication;
1682 while(up_image != NULL)
1684 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1685 up_image = up_image->next;
1688 g_list_free(pkglocale);
1690 g_list_free(applocale);
1692 g_list_free(appicon);
1694 g_list_free(appimage);
1697 /*Insert in the package_app_info DB*/
1698 ret = __insert_uiapplication_info(mfx);
1701 ret = __insert_serviceapplication_info(mfx);
1704 /*Insert in the package_app_app_control DB*/
1705 ret = __insert_uiapplication_appcontrol_info(mfx);
1708 ret = __insert_serviceapplication_appcontrol_info(mfx);
1712 /*Insert in the package_app_app_category DB*/
1713 ret = __insert_uiapplication_appcategory_info(mfx);
1716 ret = __insert_serviceapplication_appcategory_info(mfx);
1720 /*Insert in the package_app_app_metadata DB*/
1721 ret = __insert_uiapplication_appmetadata_info(mfx);
1724 ret = __insert_serviceapplication_appmetadata_info(mfx);
1728 /*Insert in the package_app_app_permission DB*/
1729 ret = __insert_uiapplication_apppermission_info(mfx);
1732 ret = __insert_serviceapplication_apppermission_info(mfx);
1736 /*Insert in the package_app_app_svc DB*/
1737 ret = __insert_uiapplication_appsvc_info(mfx);
1740 ret = __insert_serviceapplication_appsvc_info(mfx);
1744 /*Insert in the package_app_share_allowed DB*/
1745 ret = __insert_uiapplication_share_allowed_info(mfx);
1748 ret = __insert_serviceapplication_share_allowed_info(mfx);
1752 /*Insert in the package_app_share_request DB*/
1753 ret = __insert_uiapplication_share_request_info(mfx);
1756 ret = __insert_serviceapplication_share_request_info(mfx);
1760 /*Insert in the package_app_data_control DB*/
1761 ret = __insert_uiapplication_datacontrol_info(mfx);
1764 ret = __insert_serviceapplication_datacontrol_info(mfx);
1772 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1774 char query[MAX_QUERY_LEN] = { '\0' };
1776 memset(query, '\0', MAX_QUERY_LEN);
1777 snprintf(query, MAX_QUERY_LEN,
1778 "delete from %s where app_id='%s'", db_table, appid);
1779 ret = __exec_query(query);
1781 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1787 static int __delete_subpkg_info_from_db(char *appid)
1791 ret = __delete_appinfo_from_db("package_app_info", appid);
1794 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1797 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1800 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1803 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1806 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1809 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1812 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1815 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1818 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1821 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1824 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1831 static int __delete_subpkg_from_db(manifest_x *mfx)
1833 char query[MAX_QUERY_LEN] = { '\0' };
1834 char *error_message = NULL;
1836 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1838 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1839 _LOGE("Don't execute query = %s error message = %s\n", query,
1841 sqlite3_free(error_message);
1844 sqlite3_free(error_message);
1849 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1851 char query[MAX_QUERY_LEN] = { '\0' };
1853 uiapplication_x *up = mfx->uiapplication;
1854 serviceapplication_x *sp = mfx->serviceapplication;
1855 /*Delete from cert table*/
1856 if (uid != GLOBAL_USER)
1857 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1859 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1861 _LOGD("Cert Info DB Delete Failed\n");
1865 /*Delete from Package Info DB*/
1866 snprintf(query, MAX_QUERY_LEN,
1867 "delete from package_info where package='%s'", mfx->package);
1868 ret = __exec_query(query);
1870 _LOGD("Package Info DB Delete Failed\n");
1873 memset(query, '\0', MAX_QUERY_LEN);
1875 /*Delete from Package Localized Info*/
1876 snprintf(query, MAX_QUERY_LEN,
1877 "delete from package_localized_info where package='%s'", mfx->package);
1878 ret = __exec_query(query);
1880 _LOGD("Package Localized Info DB Delete Failed\n");
1884 /*Delete from Package Privilege Info*/
1885 snprintf(query, MAX_QUERY_LEN,
1886 "delete from package_privilege_info where package='%s'", mfx->package);
1887 ret = __exec_query(query);
1889 _LOGD("Package Privilege Info DB Delete Failed\n");
1893 while (up != NULL) {
1894 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1897 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1900 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
1903 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
1906 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
1909 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
1912 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
1915 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
1918 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
1921 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
1924 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
1927 ret = __delete_appinfo_from_db("package_app_data_control", up->appid);
1933 while (sp != NULL) {
1934 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
1937 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
1940 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
1943 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
1946 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
1949 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
1952 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
1955 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
1958 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
1961 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
1964 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
1967 ret = __delete_appinfo_from_db("package_app_data_control", sp->appid);
1973 /* if main package has sub pkg, delete sub pkg data*/
1974 __delete_subpkg_from_db(mfx);
1979 static int __update_preload_condition_in_db()
1982 char query[MAX_QUERY_LEN] = {'\0'};
1984 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
1986 ret = __exec_query(query);
1988 _LOGD("Package preload_condition update failed\n");
1993 API int pkgmgr_parser_initialize_db(uid_t uid)
1997 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
1999 _LOGD("package info DB initialization failed\n");
2002 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2004 _LOGD("package localized info DB initialization failed\n");
2007 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2009 _LOGD("package app app privilege DB initialization failed\n");
2012 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2014 _LOGD("package app info DB initialization failed\n");
2017 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2019 _LOGD("package app localized info DB initialization failed\n");
2022 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2024 _LOGD("package app icon localized info DB initialization failed\n");
2027 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2029 _LOGD("package app image info DB initialization failed\n");
2032 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2034 _LOGD("package app app control DB initialization failed\n");
2037 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2039 _LOGD("package app app category DB initialization failed\n");
2042 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2044 _LOGD("package app app category DB initialization failed\n");
2047 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2049 _LOGD("package app app permission DB initialization failed\n");
2052 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2054 _LOGD("package app app svc DB initialization failed\n");
2057 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2059 _LOGD("package app share allowed DB initialization failed\n");
2062 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2064 _LOGD("package app share request DB initialization failed\n");
2067 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2069 _LOGD("package app data control DB initialization failed\n");
2073 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2075 _LOGD("package cert info DB initialization failed\n");
2078 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2080 _LOGD("package cert index info DB initialization failed\n");
2084 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
2085 _LOGD("Failed to change cert db permission\n");
2087 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2088 _LOGD("Failed to change parser db permission\n");
2094 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2097 char journal_file[BUFSIZE];
2100 struct passwd *userinfo = NULL;
2101 files[0] = (char *)db_file;
2102 files[1] = journal_file;
2105 if (db_file == NULL)
2108 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2110 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2111 if (uid == OWNER_ROOT)
2113 userinfo = getpwuid(uid);
2115 _LOGE("FAIL: user %d doesn't exist", uid);
2118 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2120 for (i = 0; files[i]; i++) {
2121 ret = chown(files[i], uid, userinfo->pw_gid);
2123 if (strerror_r(errno, buf, sizeof(buf)))
2125 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2126 userinfo->pw_gid, buf);
2130 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
2132 if (strerror_r(errno, buf, sizeof(buf)))
2134 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2137 SET_SMACK_LABEL(files[i]);
2142 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2146 if (getuid() != OWNER_ROOT) {
2147 _LOGE("Only root user is allowed");
2151 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2152 _LOGE("Manifest db for user %d is already exists", uid);
2156 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2157 _LOGE("Cert db for user %d is already exists", uid);
2161 ret = pkgmgr_parser_check_and_create_db(uid);
2164 ret = pkgmgr_parser_initialize_db(uid);
2166 pkgmgr_parser_close_db();
2169 pkgmgr_parser_close_db();
2174 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2178 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2180 _LOGD("Manifest DB creation Failed\n");
2185 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid));
2187 _LOGD("Cert DB creation Failed\n");
2193 void pkgmgr_parser_close_db(void)
2195 sqlite3_close(pkgmgr_parser_db);
2196 sqlite3_close(pkgmgr_cert_db);
2200 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2202 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2204 _LOGD("manifest pointer is NULL\n");
2208 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2210 _LOGD("Failed to open DB\n");
2213 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2216 /*Begin transaction*/
2217 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2218 if (ret != SQLITE_OK) {
2219 _LOGD("Failed to begin transaction\n");
2223 _LOGD("Transaction Begin\n");
2224 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2226 _LOGD("Insert into DB failed. Rollback now\n");
2227 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2230 /*Commit transaction*/
2231 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2232 if (ret != SQLITE_OK) {
2233 _LOGD("Failed to commit transaction. Rollback now\n");
2234 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2238 _LOGD("Transaction Commit and End\n");
2240 pkgmgr_parser_close_db();
2244 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2246 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2248 _LOGD("manifest pointer is NULL\n");
2252 ret = pkgmgr_parser_check_and_create_db(uid);
2254 _LOGD("Failed to open DB\n");
2257 ret = pkgmgr_parser_initialize_db(uid);
2260 /*Begin transaction*/
2261 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2262 if (ret != SQLITE_OK) {
2263 _LOGD("Failed to begin transaction\n");
2267 _LOGD("Transaction Begin\n");
2268 ret = __insert_manifest_info_in_db(mfx, uid);
2270 _LOGD("Insert into DB failed. Rollback now\n");
2271 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2274 /*Commit transaction*/
2275 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2276 if (ret != SQLITE_OK) {
2277 _LOGD("Failed to commit transaction. Rollback now\n");
2278 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2282 _LOGD("Transaction Commit and End\n");
2284 pkgmgr_parser_close_db();
2288 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2291 _LOGD("manifest pointer is NULL\n");
2295 ret = pkgmgr_parser_check_and_create_db(uid);
2297 _LOGD("Failed to open DB\n");
2300 ret = pkgmgr_parser_initialize_db(uid);
2303 /*Preserve guest mode visibility*/
2304 __preserve_guestmode_visibility_value( mfx);
2305 /*Begin transaction*/
2306 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2307 if (ret != SQLITE_OK) {
2308 _LOGD("Failed to begin transaction\n");
2312 _LOGD("Transaction Begin\n");
2313 ret = __delete_manifest_info_from_db(mfx, uid);
2315 _LOGD("Delete from DB failed. Rollback now\n");
2316 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2319 ret = __insert_manifest_info_in_db(mfx, uid);
2321 _LOGD("Insert into DB failed. Rollback now\n");
2322 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2326 /*Commit transaction*/
2327 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2328 if (ret != SQLITE_OK) {
2329 _LOGD("Failed to commit transaction. Rollback now\n");
2330 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2334 _LOGD("Transaction Commit and End\n");
2336 pkgmgr_parser_close_db();
2340 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2342 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2345 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2348 _LOGD("manifest pointer is NULL\n");
2352 ret = pkgmgr_parser_check_and_create_db(uid);
2354 _LOGD("Failed to open DB\n");
2357 /*Begin transaction*/
2358 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2359 if (ret != SQLITE_OK) {
2360 _LOGD("Failed to begin transaction\n");
2364 _LOGD("Transaction Begin\n");
2365 ret = __delete_manifest_info_from_db(mfx, uid);
2367 _LOGD("Delete from DB failed. Rollback now\n");
2368 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2371 /*Commit transaction*/
2372 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2373 if (ret != SQLITE_OK) {
2374 _LOGD("Failed to commit transaction, Rollback now\n");
2375 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2379 _LOGD("Transaction Commit and End\n");
2381 pkgmgr_parser_close_db();
2385 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2387 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2390 API int pkgmgr_parser_update_preload_info_in_db()
2393 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2395 _LOGD("Failed to open DB\n");
2398 /*Begin transaction*/
2399 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2400 if (ret != SQLITE_OK) {
2401 _LOGD("Failed to begin transaction\n");
2405 _LOGD("Transaction Begin\n");
2406 ret = __update_preload_condition_in_db();
2408 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2409 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2412 /*Commit transaction*/
2413 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2414 if (ret != SQLITE_OK) {
2415 _LOGD("Failed to commit transaction, Rollback now\n");
2416 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2420 _LOGD("Transaction Commit and End\n");
2422 pkgmgr_parser_close_db();
2426 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2429 ret = pkgmgr_parser_check_and_create_db(uid);
2431 _LOGD("Failed to open DB\n");
2434 /*Begin transaction*/
2435 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2436 if (ret != SQLITE_OK) {
2437 _LOGD("Failed to begin transaction\n");
2441 _LOGD("Transaction Begin\n");
2442 ret = __update_preload_condition_in_db();
2444 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2445 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2448 /*Commit transaction*/
2449 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2450 if (ret != SQLITE_OK) {
2451 _LOGD("Failed to commit transaction, Rollback now\n");
2452 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2456 _LOGD("Transaction Commit and End\n");
2458 pkgmgr_parser_close_db();