4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
26 #include <sys/types.h>
27 #include <sys/smack.h>
35 /* For multi-user support */
36 #include <tzplatform_config.h>
38 #include "pkgmgr-info.h"
39 #include "pkgmgr-info-basic.h"
40 #include "pkgmgr-info-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," \
92 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
93 "(package text not null, " \
94 "package_locale text DEFAULT 'No Locale', " \
95 "package_label text, " \
96 "package_icon text, " \
97 "package_description text, " \
98 "package_license text, " \
100 "PRIMARY KEY(package, package_locale), " \
101 "FOREIGN KEY(package) " \
102 "REFERENCES package_info(package) " \
105 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
106 "(package text not null, " \
107 "privilege text not null, " \
108 "PRIMARY KEY(package, privilege) " \
109 "FOREIGN KEY(package) " \
110 "REFERENCES package_info(package) " \
113 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
114 "(app_id text primary key not null, " \
115 "app_component text, " \
117 "app_nodisplay text DEFAULT 'false', " \
119 "app_onboot text DEFAULT 'false', " \
120 "app_multiple text DEFAULT 'false', " \
121 "app_autorestart text DEFAULT 'false', " \
122 "app_taskmanage text DEFAULT 'false', " \
123 "app_enabled text DEFAULT 'true', " \
124 "app_hwacceleration text DEFAULT 'use-system-setting', " \
125 "app_screenreader text DEFAULT 'use-system-setting', " \
126 "app_mainapp text, " \
127 "app_recentimage text, " \
128 "app_launchcondition text, " \
129 "app_indicatordisplay text DEFAULT 'true', " \
130 "app_portraitimg text, " \
131 "app_landscapeimg text, " \
132 "app_guestmodevisibility text DEFAULT 'true', " \
133 "app_permissiontype text DEFAULT 'normal', " \
134 "app_preload text DEFAULT 'false', " \
135 "app_submode text DEFAULT 'false', " \
136 "app_submode_mainid text, " \
137 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
138 "component_type text, " \
139 "package text not null, " \
140 "FOREIGN KEY(package) " \
141 "REFERENCES package_info(package) " \
144 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
145 "(app_id text not null, " \
146 "app_locale text DEFAULT 'No Locale', " \
149 "PRIMARY KEY(app_id,app_locale) " \
150 "FOREIGN KEY(app_id) " \
151 "REFERENCES package_app_info(app_id) " \
154 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
155 "(app_id text not null, " \
157 "app_icon_section text, " \
158 "app_icon_resolution text, " \
159 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
160 "FOREIGN KEY(app_id) " \
161 "REFERENCES package_app_info(app_id) " \
164 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
165 "(app_id text not null, " \
166 "app_locale text DEFAULT 'No Locale', " \
167 "app_image_section text, " \
169 "PRIMARY KEY(app_id,app_image_section) " \
170 "FOREIGN KEY(app_id) " \
171 "REFERENCES package_app_info(app_id) " \
174 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
175 "(app_id text not null, " \
176 "app_control text not null, " \
177 "PRIMARY KEY(app_id,app_control) " \
178 "FOREIGN KEY(app_id) " \
179 "REFERENCES package_app_info(app_id) " \
182 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
183 "(app_id text not null, " \
184 "operation text not null, " \
185 "uri_scheme text, " \
187 "subapp_name text, " \
188 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
189 "FOREIGN KEY(app_id) " \
190 "REFERENCES package_app_info(app_id) " \
193 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
194 "(app_id text not null, " \
195 "category text not null, " \
196 "PRIMARY KEY(app_id,category) " \
197 "FOREIGN KEY(app_id) " \
198 "REFERENCES package_app_info(app_id) " \
201 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
202 "(app_id text not null, " \
203 "md_key text not null, " \
204 "md_value text not null, " \
205 "PRIMARY KEY(app_id, md_key, md_value) " \
206 "FOREIGN KEY(app_id) " \
207 "REFERENCES package_app_info(app_id) " \
210 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
211 "(app_id text not null, " \
212 "pm_type text not null, " \
213 "pm_value text not null, " \
214 "PRIMARY KEY(app_id, pm_type, pm_value) " \
215 "FOREIGN KEY(app_id) " \
216 "REFERENCES package_app_info(app_id) " \
219 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
220 "(app_id text not null, " \
221 "data_share_path text not null, " \
222 "data_share_allowed text not null, " \
223 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
224 "FOREIGN KEY(app_id) " \
225 "REFERENCES package_app_info(app_id) " \
228 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
229 "(app_id text not null, " \
230 "data_share_request text not null, " \
231 "PRIMARY KEY(app_id,data_share_request) " \
232 "FOREIGN KEY(app_id) " \
233 "REFERENCES package_app_info(app_id) " \
236 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
237 "(cert_info text not null, " \
238 "cert_id integer, " \
239 "cert_ref_count integer, " \
240 "PRIMARY KEY(cert_id)) "
242 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
243 "(package text not null, " \
244 "author_root_cert integer, " \
245 "author_im_cert integer, " \
246 "author_signer_cert integer, " \
247 "dist_root_cert integer, " \
248 "dist_im_cert integer, " \
249 "dist_signer_cert integer, " \
250 "dist2_root_cert integer, " \
251 "dist2_im_cert integer, " \
252 "dist2_signer_cert integer, " \
253 "PRIMARY KEY(package)) "
255 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
256 "(app_id text not null, " \
257 "providerid text not null, " \
258 "access text not null, " \
259 "type text not null, " \
260 "PRIMARY KEY(app_id, providerid, access, type) " \
261 "FOREIGN KEY(app_id) " \
262 "REFERENCES package_app_info(app_id) " \
264 #define QUERY_CREATE_TABLE_PACKAGE_RESOURCE_INFO "CREATE TABLE IF NOT EXISTS package_resource_info" \
265 "(pkg_id text NOT NULL," \
266 "group_folder text NOT NULL," \
267 "group_type text NOT NULL," \
268 "PRIMARY KEY(pkg_id, group_type))"
270 #define QUERY_CREATE_TABLE_PACKAGE_RESOURCE_DATA "CREATE TABLE IF NOT EXISTS package_resource_data" \
271 "(id integer REFERENCES package_resource_info(rowid)," \
272 "node_folder text NOT NULL," \
273 "attr_name text NOT NULL," \
274 "attr_value test NOT NULL," \
275 "PRIMARY KEY(id, node_folder, attr_name))"
277 static int __insert_uiapplication_info(manifest_x *mfx);
278 static int __insert_serviceapplication_info(manifest_x *mfx);
279 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
280 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
281 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
282 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
283 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
284 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
285 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
286 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
287 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
288 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
289 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
290 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
291 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx);
292 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx);
293 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
294 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
295 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
296 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
297 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
298 static int __delete_subpkg_info_from_db(char *appid);
299 static int __delete_appinfo_from_db(char *db_table, const char *appid);
300 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
301 static int __exec_query(char *query);
302 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
303 char **label, char **license, char **icon, char **description, char **author);
304 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
305 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
306 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
307 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
308 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
309 static int __parserdb_change_perm(const char *db_file, uid_t uid);
311 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
314 __delete_subpkg_info_from_db(coltxt[0]);
319 static const char *__get_str(const char *str)
323 return PKGMGR_PARSER_EMPTY_STR;
329 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
334 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
335 if (ret != SQLITE_OK) {
336 _LOGD("connect db [%s] failed!\n", db_path);
344 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
346 manifest_x *mfx = (manifest_x *)data;
350 uiapplication_x *uiapp = NULL;
351 for(i = 0; i < ncols; i++)
353 uiapp = mfx->uiapplication;
354 if (strcmp(colname[i], "app_id") == 0) {
356 appid = strdup(coltxt[i]);
357 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
359 status = strdup(coltxt[i]);
363 _LOGD("app id is NULL\n");
366 /*update guest mode visibility*/
367 for (; uiapp != NULL; uiapp = uiapp->next) {
368 if (strcmp(uiapp->appid, appid) == 0) {
369 free((void *)uiapp->guestmode_visibility);
370 uiapp->guestmode_visibility = strdup(status);
386 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
388 char *error_message = NULL;
389 char query[MAX_QUERY_LEN] = {'\0'};
390 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
392 sqlite3_exec(pkgmgr_parser_db, query,
393 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
394 _LOGD("Don't execute query = %s error message = %s\n",
395 query, error_message);
396 sqlite3_free(error_message);
401 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
403 char *error_message = NULL;
405 sqlite3_exec(db_handle, db_query,
406 NULL, NULL, &error_message)) {
407 _LOGD("Don't execute query = %s error message = %s\n",
408 db_query, error_message);
409 sqlite3_free(error_message);
412 sqlite3_free(error_message);
416 static int __exec_query(char *query)
418 char *error_message = NULL;
420 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
421 _LOGD("Don't execute query = %s error message = %s\n", query,
423 sqlite3_free(error_message);
426 sqlite3_free(error_message);
430 static int __exec_query_no_msg(char *query)
432 char *error_message = NULL;
434 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
435 sqlite3_free(error_message);
438 sqlite3_free(error_message);
442 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
448 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
454 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
460 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
466 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
472 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
479 static GList *__create_icon_list(GList *locale, icon_x *icn)
484 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
490 static GList *__create_image_list(GList *locale, image_x *image)
495 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
501 static void __trimfunc(GList* trim_list)
503 char *trim_data = NULL;
507 list = g_list_first(trim_list);
510 trim_data = (char *)list->data;
513 if (strcmp(trim_data, prev) == 0) {
514 trim_list = g_list_remove(trim_list, trim_data);
515 list = g_list_first(trim_list);
524 list = g_list_next(list);
528 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
530 if (a == NULL || b == NULL)
532 if (strcmp((char*)a, (char*)b) == 0)
534 if (strcmp((char*)a, (char*)b) < 0)
536 if (strcmp((char*)a, (char*)b) > 0)
541 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
542 char **label, char **license, char **icon, char **description, char **author)
547 if (strcmp(lbl->lang, (char *)data) == 0) {
548 *label = (char*)lbl->text;
557 if (strcmp(lcn->lang, (char *)data) == 0) {
558 *license = (char*)lcn->text;
567 if (strcmp(icn->lang, (char *)data) == 0) {
568 *icon = (char*)icn->text;
577 if (strcmp(dcn->lang, (char *)data) == 0) {
578 *description = (char*)dcn->text;
587 if (strcmp(ath->lang, (char *)data) == 0) {
588 *author = (char*)ath->text;
597 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
602 if (strcmp(icn->section, (char *)data) == 0) {
603 *icon = (char*)icn->text;
604 *resolution = (char*)icn->resolution;
612 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
616 if (image->section) {
617 if (strcmp(image->section, (char *)data) == 0) {
618 *lang = (char*)image->lang;
619 *img = (char*)image->text;
627 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
632 char *description = NULL;
633 char *license = NULL;
635 char query[MAX_QUERY_LEN] = {'\0'};
637 manifest_x *mfx = (manifest_x *)userdata;
638 label_x *lbl = mfx->label;
639 license_x *lcn = mfx->license;
640 icon_x *icn = mfx->icon;
641 description_x *dcn = mfx->description;
642 author_x *ath = mfx->author;
644 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
645 if (!label && !description && !icon && !license && !author)
648 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
649 "package_label, package_icon, package_description, package_license, package_author) values " \
650 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
655 __get_str(description),
659 ret = __exec_query(query);
661 _LOGD("Package Localized Info DB Insert failed\n");
664 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
669 char query[MAX_QUERY_LEN] = {'\0'};
671 uiapplication_x *up = (uiapplication_x*)userdata;
672 label_x *lbl = up->label;
673 icon_x *icn = up->icon;
675 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
678 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
679 "app_label, app_icon) values " \
680 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
682 ret = __exec_query(query);
684 _LOGD("Package UiApp Localized Info DB Insert failed\n");
686 /*insert ui app locale info to pkg locale to get mainapp data */
687 if (strcasecmp(up->mainapp, "true")==0) {
688 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
689 "package_label, package_icon, package_description, package_license, package_author) values " \
690 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
695 PKGMGR_PARSER_EMPTY_STR,
696 PKGMGR_PARSER_EMPTY_STR,
697 PKGMGR_PARSER_EMPTY_STR);
699 ret = __exec_query_no_msg(query);
702 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
703 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
704 ret = __exec_query_no_msg(query);
709 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
713 char *resolution = NULL;
714 char query[MAX_QUERY_LEN] = {'\0'};
716 uiapplication_x *up = (uiapplication_x*)userdata;
717 icon_x *icn = up->icon;
719 __extract_icon_data(data, icn, &icon, &resolution);
720 if (!icon && !resolution)
722 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
723 "app_icon, app_icon_section, app_icon_resolution) values " \
724 "('%q', '%q', '%q', '%q')", up->appid,
725 icon, (char*)data, resolution);
727 ret = __exec_query(query);
729 _LOGD("Package UiApp Localized Info DB Insert failed\n");
733 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
738 char query[MAX_QUERY_LEN] = {'\0'};
740 uiapplication_x *up = (uiapplication_x*)userdata;
741 image_x *image = up->image;
743 __extract_image_data(data, image, &lang, &img);
746 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
747 "app_image_section, app_image) values " \
748 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
750 ret = __exec_query(query);
752 _LOGD("Package UiApp image Info DB Insert failed\n");
757 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
762 char query[MAX_QUERY_LEN] = {'\0'};
764 serviceapplication_x *sp = (serviceapplication_x*)userdata;
765 label_x *lbl = sp->label;
766 icon_x *icn = sp->icon;
768 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
771 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
772 "app_label, app_icon) values " \
773 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
775 ret = __exec_query(query);
777 _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
780 static int __insert_ui_mainapp_info(manifest_x *mfx)
782 uiapplication_x *up = mfx->uiapplication;
784 char query[MAX_QUERY_LEN] = {'\0'};
787 snprintf(query, MAX_QUERY_LEN,
788 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
790 ret = __exec_query(query);
792 _LOGD("Package UiApp Info DB Insert Failed\n");
795 if (strcasecmp(up->mainapp, "True")==0)
796 mfx->mainapp_id = strdup(up->appid);
799 memset(query, '\0', MAX_QUERY_LEN);
802 if (mfx->mainapp_id == NULL){
803 if (mfx->uiapplication && mfx->uiapplication->appid) {
804 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
806 _LOGD("Not valid appid\n");
810 ret = __exec_query(query);
812 _LOGD("Package UiApp Info DB Insert Failed\n");
816 free((void *)mfx->uiapplication->mainapp);
817 mfx->uiapplication->mainapp= strdup("true");
818 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
821 memset(query, '\0', MAX_QUERY_LEN);
822 snprintf(query, MAX_QUERY_LEN,
823 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
824 ret = __exec_query(query);
826 _LOGD("Package Info DB update Failed\n");
832 /* _PRODUCT_LAUNCHING_ENHANCED_
833 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
835 static int __insert_uiapplication_info(manifest_x *mfx)
837 uiapplication_x *up = mfx->uiapplication;
839 char query[MAX_QUERY_LEN] = {'\0'};
842 snprintf(query, MAX_QUERY_LEN,
843 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
844 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
845 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
846 "app_preload, app_submode, app_submode_mainid, component_type, package, app_launch_mode) " \
847 "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')",\
853 PKGMGR_PARSER_EMPTY_STR,
855 PKGMGR_PARSER_EMPTY_STR,
861 __get_str(up->recentimage),
863 up->indicatordisplay,
864 __get_str(up->portraitimg),
865 __get_str(up->landscapeimg),
866 up->guestmode_visibility,
870 __get_str(up->submode_mainid),
875 ret = __exec_query(query);
877 _LOGD("Package UiApp Info DB Insert Failed\n");
881 memset(query, '\0', MAX_QUERY_LEN);
886 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
888 uiapplication_x *up = mfx->uiapplication;
889 category_x *ct = NULL;
891 char query[MAX_QUERY_LEN] = {'\0'};
897 snprintf(query, MAX_QUERY_LEN,
898 "insert into package_app_app_category(app_id, category) " \
899 "values('%s','%s')",\
900 up->appid, ct->name);
901 ret = __exec_query(query);
903 _LOGD("Package UiApp Category Info DB Insert Failed\n");
907 memset(query, '\0', MAX_QUERY_LEN);
914 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
916 uiapplication_x *up = mfx->uiapplication;
917 metadata_x *md = NULL;
919 char query[MAX_QUERY_LEN] = {'\0'};
926 snprintf(query, MAX_QUERY_LEN,
927 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
928 "values('%s','%s', '%s')",\
929 up->appid, md->key, md->value);
930 ret = __exec_query(query);
932 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
937 memset(query, '\0', MAX_QUERY_LEN);
944 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
946 uiapplication_x *up = mfx->uiapplication;
947 permission_x *pm = NULL;
949 char query[MAX_QUERY_LEN] = {'\0'};
955 snprintf(query, MAX_QUERY_LEN,
956 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
957 "values('%s','%s', '%s')",\
958 up->appid, pm->type, pm->value);
959 ret = __exec_query(query);
961 _LOGD("Package UiApp permission Info DB Insert Failed\n");
965 memset(query, '\0', MAX_QUERY_LEN);
972 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
974 uiapplication_x *up = mfx->uiapplication;
975 appcontrol_x *acontrol = NULL;
977 char query[MAX_QUERY_LEN] = {'\0'};
978 char buf[BUFSIZE] = {'\0'};
980 acontrol = up->appcontrol;
981 while (acontrol != NULL) {
982 snprintf(buf, BUFSIZE, "%s|%s|%s",\
983 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
984 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
985 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
986 snprintf(query, MAX_QUERY_LEN,
987 "insert into package_app_app_control(app_id, app_control) " \
988 "values('%s', '%s')",\
990 ret = __exec_query(query);
992 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
995 memset(query, '\0', MAX_QUERY_LEN);
996 acontrol = acontrol->next;
1003 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1005 uiapplication_x *up = mfx->uiapplication;
1006 appsvc_x *asvc = NULL;
1007 operation_x *op = NULL;
1010 subapp_x *sub = NULL;
1012 char query[MAX_QUERY_LEN] = {'\0'};
1013 const char *operation = NULL;
1014 const char *mime = NULL;
1015 const char *uri = NULL;
1016 const char *subapp = NULL;
1022 op = asvc->operation;
1026 operation = op->name;
1043 snprintf(query, MAX_QUERY_LEN,
1044 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1045 "values('%s', '%s', '%s', '%s', '%s')",\
1052 ret = __exec_query(query);
1054 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1057 memset(query, '\0', MAX_QUERY_LEN);
1061 } while(ui != NULL);
1065 }while(sub != NULL);
1081 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx)
1083 uiapplication_x *up = mfx->uiapplication;
1084 datacontrol_x *dc = NULL;
1086 char query[MAX_QUERY_LEN] = {'\0'};
1090 dc = up->datacontrol;
1093 snprintf(query, MAX_QUERY_LEN,
1094 "insert into package_app_data_control(app_id, providerid, access, type) " \
1095 "values('%s', '%s', '%s', '%s')",\
1096 mfx->uiapplication->appid,
1101 ret = __exec_query(query);
1103 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1106 memset(query, '\0', MAX_QUERY_LEN);
1114 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1116 uiapplication_x *up = mfx->uiapplication;
1117 datashare_x *ds = NULL;
1118 request_x *rq = NULL;
1120 char query[MAX_QUERY_LEN] = {'\0'};
1129 snprintf(query, MAX_QUERY_LEN,
1130 "insert into package_app_share_request(app_id, data_share_request) " \
1131 "values('%s', '%s')",\
1132 up->appid, rq->text);
1133 ret = __exec_query(query);
1135 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1138 memset(query, '\0', MAX_QUERY_LEN);
1148 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1150 uiapplication_x *up = mfx->uiapplication;
1151 datashare_x *ds = NULL;
1152 define_x *df = NULL;
1153 allowed_x *al = NULL;
1155 char query[MAX_QUERY_LEN] = {'\0'};
1167 snprintf(query, MAX_QUERY_LEN,
1168 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1169 "values('%s', '%s', '%s')",\
1170 up->appid, df->path, al->text);
1171 ret = __exec_query(query);
1173 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1176 memset(query, '\0', MAX_QUERY_LEN);
1188 static int __insert_serviceapplication_info(manifest_x *mfx)
1190 serviceapplication_x *sp = mfx->serviceapplication;
1192 char query[MAX_QUERY_LEN] = {'\0'};
1195 snprintf(query, MAX_QUERY_LEN,
1196 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1197 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1198 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1199 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1200 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1201 ret = __exec_query(query);
1203 _LOGD("Package ServiceApp Info DB Insert Failed\n");
1207 memset(query, '\0', MAX_QUERY_LEN);
1212 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1214 serviceapplication_x *sp = mfx->serviceapplication;
1215 category_x *ct = NULL;
1217 char query[MAX_QUERY_LEN] = {'\0'};
1223 snprintf(query, MAX_QUERY_LEN,
1224 "insert into package_app_app_category(app_id, category) " \
1225 "values('%s','%s')",\
1226 sp->appid, ct->name);
1227 ret = __exec_query(query);
1229 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1233 memset(query, '\0', MAX_QUERY_LEN);
1240 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1242 serviceapplication_x *sp = mfx->serviceapplication;
1243 metadata_x *md = NULL;
1245 char query[MAX_QUERY_LEN] = {'\0'};
1252 snprintf(query, MAX_QUERY_LEN,
1253 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1254 "values('%s','%s', '%s')",\
1255 sp->appid, md->key, md->value);
1256 ret = __exec_query(query);
1258 _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1263 memset(query, '\0', MAX_QUERY_LEN);
1270 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1272 serviceapplication_x *sp = mfx->serviceapplication;
1273 permission_x *pm = NULL;
1275 char query[MAX_QUERY_LEN] = {'\0'};
1278 pm = sp->permission;
1281 snprintf(query, MAX_QUERY_LEN,
1282 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1283 "values('%s','%s', '%s')",\
1284 sp->appid, pm->type, pm->value);
1285 ret = __exec_query(query);
1287 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1291 memset(query, '\0', MAX_QUERY_LEN);
1298 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1300 serviceapplication_x *sp = mfx->serviceapplication;
1301 appcontrol_x *acontrol = NULL;
1303 char query[MAX_QUERY_LEN] = {'\0'};
1304 char buf[BUFSIZE] = {'\0'};
1305 while (sp != NULL) {
1306 acontrol = sp->appcontrol;
1307 while (acontrol != NULL) {
1308 snprintf(buf, BUFSIZE, "%s|%s|%s",
1309 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1310 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1311 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1312 snprintf(query, MAX_QUERY_LEN,
1313 "insert into package_app_app_control(app_id, app_control) " \
1314 "values('%s', '%s')",\
1316 ret = __exec_query(query);
1318 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1321 memset(query, '\0', MAX_QUERY_LEN);
1322 acontrol = acontrol->next;
1329 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1331 serviceapplication_x *sp = mfx->serviceapplication;
1332 appsvc_x *asvc = NULL;
1334 char query[MAX_QUERY_LEN] = {'\0'};
1335 operation_x *op = NULL;
1338 subapp_x *sub = NULL;
1339 const char *operation = NULL;
1340 const char *mime = NULL;
1341 const char *uri = NULL;
1342 const char *subapp = NULL;
1348 op = asvc->operation;
1352 operation = op->name;
1368 snprintf(query, MAX_QUERY_LEN,
1369 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1370 "values('%s', '%s', '%s', '%s', '%s')",\
1376 ret = __exec_query(query);
1378 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1381 memset(query, '\0', MAX_QUERY_LEN);
1385 } while(ui != NULL);
1389 }while(sub != NULL);
1405 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx)
1407 serviceapplication_x *sp = mfx->serviceapplication;
1408 datacontrol_x *dc = NULL;
1410 char query[MAX_QUERY_LEN] = {'\0'};
1414 dc = sp->datacontrol;
1417 snprintf(query, MAX_QUERY_LEN,
1418 "insert into package_app_data_control(app_id, providerid, access, type) " \
1419 "values('%s', '%s', '%s', '%s')",\
1420 mfx->serviceapplication->appid,
1425 ret = __exec_query(query);
1427 _LOGD("Package ServiceApp Data Control DB Insert Failed\n");
1430 memset(query, '\0', MAX_QUERY_LEN);
1438 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1440 serviceapplication_x *sp = mfx->serviceapplication;
1441 datashare_x *ds = NULL;
1442 request_x *rq = NULL;
1444 char query[MAX_QUERY_LEN] = {'\0'};
1453 snprintf(query, MAX_QUERY_LEN,
1454 "insert into package_app_share_request(app_id, data_share_request) " \
1455 "values('%s', '%s')",\
1456 sp->appid, rq->text);
1457 ret = __exec_query(query);
1459 _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1462 memset(query, '\0', MAX_QUERY_LEN);
1474 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1476 serviceapplication_x *sp = mfx->serviceapplication;
1477 datashare_x *ds = NULL;
1478 define_x *df = NULL;
1479 allowed_x *al = NULL;
1481 char query[MAX_QUERY_LEN] = {'\0'};
1493 snprintf(query, MAX_QUERY_LEN,
1494 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1495 "values('%s', '%s', '%s')",\
1496 sp->appid, df->path, al->text);
1497 ret = __exec_query(query);
1499 _LOGD("Package App Share Allowed DB Insert Failed\n");
1502 memset(query, '\0', MAX_QUERY_LEN);
1514 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1516 label_x *lbl = mfx->label;
1517 license_x *lcn = mfx->license;
1518 icon_x *icn = mfx->icon;
1519 description_x *dcn = mfx->description;
1520 author_x *ath = mfx->author;
1521 uiapplication_x *up = mfx->uiapplication;
1522 uiapplication_x *up_icn = mfx->uiapplication;
1523 uiapplication_x *up_image = mfx->uiapplication;
1524 serviceapplication_x *sp = mfx->serviceapplication;
1525 privileges_x *pvs = NULL;
1526 privilege_x *pv = NULL;
1527 char query[MAX_QUERY_LEN] = { '\0' };
1529 const char *auth_name = NULL;
1530 const char *auth_email = NULL;
1531 const char *auth_href = NULL;
1533 GList *pkglocale = NULL;
1534 GList *applocale = NULL;
1535 GList *appicon = NULL;
1536 GList *appimage = NULL;
1540 auth_name = ath->text;
1542 auth_email = ath->email;
1544 auth_href = ath->href;
1546 /*Insert in the package_cert_info CERT_DB*/
1547 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1548 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1549 if (ret != PMINFO_R_OK) {
1550 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1551 _LOGE("Cert Info DB create handle failed\n");
1554 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1555 if (ret != PMINFO_R_OK) {
1556 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1557 _LOGE("Cert Info DB Insert Failed\n");
1561 /*Insert in the package_info DB*/
1562 snprintf(query, MAX_QUERY_LEN,
1563 "insert into package_info(package, package_type, package_version, package_api_version, install_location, package_size, " \
1564 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1565 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
1566 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1570 __get_str(mfx->api_version),
1571 __get_str(mfx->installlocation),
1572 __get_str(mfx->package_size),
1578 mfx->nodisplay_setting,
1580 __get_str(auth_name),
1581 __get_str(auth_email),
1582 __get_str(auth_href),
1583 mfx->installed_time,
1584 mfx->installed_storage,
1585 __get_str(mfx->storeclient_id),
1587 __get_str(mfx->package_url),
1589 __get_str(mfx->csc_path));
1591 ret = __exec_query(query);
1593 _LOGD("Package Info DB Insert Failed\n");
1597 /*Insert in the package_privilege_info DB*/
1598 pvs = mfx->privileges;
1599 while (pvs != NULL) {
1600 pv = pvs->privilege;
1601 while (pv != NULL) {
1602 memset(query, '\0', MAX_QUERY_LEN);
1603 snprintf(query, MAX_QUERY_LEN,
1604 "insert into package_privilege_info(package, privilege) " \
1605 "values('%s','%s')",\
1606 mfx->package, pv->text);
1607 ret = __exec_query(query);
1609 _LOGD("Package Privilege Info DB Insert Failed\n");
1618 ret = __insert_ui_mainapp_info(mfx);
1623 /*Insert the package locale*/
1624 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1625 /*remove duplicated data in pkglocale*/
1626 __trimfunc(pkglocale);
1628 /*Insert the app locale info */
1631 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1636 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1639 /*remove duplicated data in applocale*/
1640 __trimfunc(applocale);
1642 /*Insert the app icon info */
1643 while(up_icn != NULL)
1645 appicon = __create_icon_list(appicon, up_icn->icon);
1646 up_icn = up_icn->next;
1648 /*remove duplicated data in appicon*/
1649 __trimfunc(appicon);
1651 /*Insert the image info */
1652 while(up_image != NULL)
1654 appimage = __create_image_list(appimage, up_image->image);
1655 up_image = up_image->next;
1657 /*remove duplicated data in appimage*/
1658 __trimfunc(appimage);
1660 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1662 /*native app locale info*/
1663 up = mfx->uiapplication;
1666 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1669 /*agent app locale info*/
1670 sp = mfx->serviceapplication;
1673 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1677 /*app icon locale info*/
1678 up_icn = mfx->uiapplication;
1679 while(up_icn != NULL)
1681 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1682 up_icn = up_icn->next;
1686 up_image = mfx->uiapplication;
1687 while(up_image != NULL)
1689 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1690 up_image = up_image->next;
1693 g_list_free(pkglocale);
1695 g_list_free(applocale);
1697 g_list_free(appicon);
1699 g_list_free(appimage);
1702 /*Insert in the package_app_info DB*/
1703 ret = __insert_uiapplication_info(mfx);
1706 ret = __insert_serviceapplication_info(mfx);
1709 /*Insert in the package_app_app_control DB*/
1710 ret = __insert_uiapplication_appcontrol_info(mfx);
1713 ret = __insert_serviceapplication_appcontrol_info(mfx);
1717 /*Insert in the package_app_app_category DB*/
1718 ret = __insert_uiapplication_appcategory_info(mfx);
1721 ret = __insert_serviceapplication_appcategory_info(mfx);
1725 /*Insert in the package_app_app_metadata DB*/
1726 ret = __insert_uiapplication_appmetadata_info(mfx);
1729 ret = __insert_serviceapplication_appmetadata_info(mfx);
1733 /*Insert in the package_app_app_permission DB*/
1734 ret = __insert_uiapplication_apppermission_info(mfx);
1737 ret = __insert_serviceapplication_apppermission_info(mfx);
1741 /*Insert in the package_app_app_svc DB*/
1742 ret = __insert_uiapplication_appsvc_info(mfx);
1745 ret = __insert_serviceapplication_appsvc_info(mfx);
1749 /*Insert in the package_app_share_allowed DB*/
1750 ret = __insert_uiapplication_share_allowed_info(mfx);
1753 ret = __insert_serviceapplication_share_allowed_info(mfx);
1757 /*Insert in the package_app_share_request DB*/
1758 ret = __insert_uiapplication_share_request_info(mfx);
1761 ret = __insert_serviceapplication_share_request_info(mfx);
1765 /*Insert in the package_app_data_control DB*/
1766 ret = __insert_uiapplication_datacontrol_info(mfx);
1769 ret = __insert_serviceapplication_datacontrol_info(mfx);
1777 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1779 char query[MAX_QUERY_LEN] = { '\0' };
1781 memset(query, '\0', MAX_QUERY_LEN);
1782 snprintf(query, MAX_QUERY_LEN,
1783 "delete from %s where app_id='%s'", db_table, appid);
1784 ret = __exec_query(query);
1786 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1792 static int __delete_subpkg_info_from_db(char *appid)
1796 ret = __delete_appinfo_from_db("package_app_info", appid);
1799 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1802 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1805 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1808 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1811 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1814 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1817 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1820 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1823 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1826 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1829 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1836 static int __delete_subpkg_from_db(manifest_x *mfx)
1838 char query[MAX_QUERY_LEN] = { '\0' };
1839 char *error_message = NULL;
1841 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1843 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1844 _LOGE("Don't execute query = %s error message = %s\n", query,
1846 sqlite3_free(error_message);
1849 sqlite3_free(error_message);
1854 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1856 char query[MAX_QUERY_LEN] = { '\0' };
1858 uiapplication_x *up = mfx->uiapplication;
1859 serviceapplication_x *sp = mfx->serviceapplication;
1860 /*Delete from cert table*/
1861 if (uid != GLOBAL_USER)
1862 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1864 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1866 _LOGD("Cert Info DB Delete Failed\n");
1870 /*Delete from Package Info DB*/
1871 snprintf(query, MAX_QUERY_LEN,
1872 "delete from package_info where package='%s'", mfx->package);
1873 ret = __exec_query(query);
1875 _LOGD("Package Info DB Delete Failed\n");
1878 memset(query, '\0', MAX_QUERY_LEN);
1880 /*Delete from Package Localized Info*/
1881 snprintf(query, MAX_QUERY_LEN,
1882 "delete from package_localized_info where package='%s'", mfx->package);
1883 ret = __exec_query(query);
1885 _LOGD("Package Localized Info DB Delete Failed\n");
1889 /*Delete from Package Privilege Info*/
1890 snprintf(query, MAX_QUERY_LEN,
1891 "delete from package_privilege_info where package='%s'", mfx->package);
1892 ret = __exec_query(query);
1894 _LOGD("Package Privilege Info DB Delete Failed\n");
1898 while (up != NULL) {
1899 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1902 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1905 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
1908 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
1911 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
1914 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
1917 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
1920 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
1923 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
1926 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
1929 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
1932 ret = __delete_appinfo_from_db("package_app_data_control", up->appid);
1938 while (sp != NULL) {
1939 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
1942 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
1945 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
1948 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
1951 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
1954 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
1957 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
1960 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
1963 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
1966 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
1969 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
1972 ret = __delete_appinfo_from_db("package_app_data_control", sp->appid);
1978 /* if main package has sub pkg, delete sub pkg data*/
1979 __delete_subpkg_from_db(mfx);
1984 static int __update_preload_condition_in_db()
1987 char query[MAX_QUERY_LEN] = {'\0'};
1989 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
1991 ret = __exec_query(query);
1993 _LOGD("Package preload_condition update failed\n");
1998 API int pkgmgr_parser_initialize_db(uid_t uid)
2002 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2004 _LOGD("package info DB initialization failed\n");
2007 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2009 _LOGD("package localized info DB initialization failed\n");
2012 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2014 _LOGD("package app app privilege DB initialization failed\n");
2017 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2019 _LOGD("package app info DB initialization failed\n");
2022 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2024 _LOGD("package app localized info DB initialization failed\n");
2027 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2029 _LOGD("package app icon localized info DB initialization failed\n");
2032 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2034 _LOGD("package app image info DB initialization failed\n");
2037 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2039 _LOGD("package app app control DB initialization failed\n");
2042 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2044 _LOGD("package app app category DB initialization failed\n");
2047 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2049 _LOGD("package app app category DB initialization failed\n");
2052 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2054 _LOGD("package app app permission DB initialization failed\n");
2057 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2059 _LOGD("package app app svc DB initialization failed\n");
2062 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2064 _LOGD("package app share allowed DB initialization failed\n");
2067 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2069 _LOGD("package app share request DB initialization failed\n");
2072 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2074 _LOGD("package app data control DB initialization failed\n");
2078 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2080 _LOGD("package cert info DB initialization failed\n");
2083 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2085 _LOGD("package cert index info DB initialization failed\n");
2089 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_RESOURCE_INFO);
2091 _LOGD("package resource info DB initialization failed\n");
2094 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_RESOURCE_DATA);
2096 _LOGD("package resource data DB initialization failed\n");
2100 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
2101 _LOGD("Failed to change cert db permission\n");
2103 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2104 _LOGD("Failed to change parser db permission\n");
2110 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2113 char journal_file[BUFSIZE];
2116 struct passwd *userinfo = NULL;
2117 files[0] = (char *)db_file;
2118 files[1] = journal_file;
2121 if (db_file == NULL)
2124 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2126 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2127 if (uid == OWNER_ROOT)
2129 userinfo = getpwuid(uid);
2131 _LOGE("FAIL: user %d doesn't exist", uid);
2134 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2136 for (i = 0; files[i]; i++) {
2137 ret = chown(files[i], uid, userinfo->pw_gid);
2139 if (strerror_r(errno, buf, sizeof(buf)))
2141 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2142 userinfo->pw_gid, buf);
2146 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
2148 if (strerror_r(errno, buf, sizeof(buf)))
2150 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2153 SET_SMACK_LABEL(files[i]);
2158 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2162 if (getuid() != OWNER_ROOT) {
2163 _LOGE("Only root user is allowed");
2167 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2168 _LOGE("Manifest db for user %d is already exists", uid);
2172 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2173 _LOGE("Cert db for user %d is already exists", uid);
2177 ret = pkgmgr_parser_check_and_create_db(uid);
2180 ret = pkgmgr_parser_initialize_db(uid);
2182 pkgmgr_parser_close_db();
2185 pkgmgr_parser_close_db();
2190 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2194 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2196 _LOGD("Manifest DB creation Failed\n");
2201 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid));
2203 _LOGD("Cert DB creation Failed\n");
2209 void pkgmgr_parser_close_db(void)
2211 sqlite3_close(pkgmgr_parser_db);
2212 sqlite3_close(pkgmgr_cert_db);
2216 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2218 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2220 _LOGD("manifest pointer is NULL\n");
2224 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2226 _LOGD("Failed to open DB\n");
2229 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2232 /*Begin transaction*/
2233 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2234 if (ret != SQLITE_OK) {
2235 _LOGD("Failed to begin transaction\n");
2239 _LOGD("Transaction Begin\n");
2240 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2242 _LOGD("Insert into DB failed. Rollback now\n");
2243 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2246 /*Commit transaction*/
2247 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2248 if (ret != SQLITE_OK) {
2249 _LOGD("Failed to commit transaction. Rollback now\n");
2250 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2254 _LOGD("Transaction Commit and End\n");
2256 pkgmgr_parser_close_db();
2260 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2262 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2264 _LOGD("manifest pointer is NULL\n");
2268 ret = pkgmgr_parser_check_and_create_db(uid);
2270 _LOGD("Failed to open DB\n");
2273 ret = pkgmgr_parser_initialize_db(uid);
2276 /*Begin transaction*/
2277 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2278 if (ret != SQLITE_OK) {
2279 _LOGD("Failed to begin transaction\n");
2283 _LOGD("Transaction Begin\n");
2284 ret = __insert_manifest_info_in_db(mfx, uid);
2286 _LOGD("Insert into DB failed. Rollback now\n");
2287 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2290 /*Commit transaction*/
2291 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2292 if (ret != SQLITE_OK) {
2293 _LOGD("Failed to commit transaction. Rollback now\n");
2294 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2298 _LOGD("Transaction Commit and End\n");
2300 pkgmgr_parser_close_db();
2304 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2307 _LOGD("manifest pointer is NULL\n");
2311 ret = pkgmgr_parser_check_and_create_db(uid);
2313 _LOGD("Failed to open DB\n");
2316 ret = pkgmgr_parser_initialize_db(uid);
2319 /*Preserve guest mode visibility*/
2320 __preserve_guestmode_visibility_value( mfx);
2321 /*Begin transaction*/
2322 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2323 if (ret != SQLITE_OK) {
2324 _LOGD("Failed to begin transaction\n");
2328 _LOGD("Transaction Begin\n");
2329 ret = __delete_manifest_info_from_db(mfx, uid);
2331 _LOGD("Delete from DB failed. Rollback now\n");
2332 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2335 ret = __insert_manifest_info_in_db(mfx, uid);
2337 _LOGD("Insert into DB failed. Rollback now\n");
2338 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2342 /*Commit transaction*/
2343 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2344 if (ret != SQLITE_OK) {
2345 _LOGD("Failed to commit transaction. Rollback now\n");
2346 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2350 _LOGD("Transaction Commit and End\n");
2352 pkgmgr_parser_close_db();
2356 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2358 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2361 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2364 _LOGD("manifest pointer is NULL\n");
2368 ret = pkgmgr_parser_check_and_create_db(uid);
2370 _LOGD("Failed to open DB\n");
2373 /*Begin transaction*/
2374 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2375 if (ret != SQLITE_OK) {
2376 _LOGD("Failed to begin transaction\n");
2380 _LOGD("Transaction Begin\n");
2381 ret = __delete_manifest_info_from_db(mfx, uid);
2383 _LOGD("Delete from DB failed. Rollback now\n");
2384 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2387 /*Commit transaction*/
2388 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2389 if (ret != SQLITE_OK) {
2390 _LOGD("Failed to commit transaction, Rollback now\n");
2391 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2395 _LOGD("Transaction Commit and End\n");
2397 pkgmgr_parser_close_db();
2401 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2403 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2406 API int pkgmgr_parser_update_preload_info_in_db()
2409 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2411 _LOGD("Failed to open DB\n");
2414 /*Begin transaction*/
2415 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2416 if (ret != SQLITE_OK) {
2417 _LOGD("Failed to begin transaction\n");
2421 _LOGD("Transaction Begin\n");
2422 ret = __update_preload_condition_in_db();
2424 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2425 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2428 /*Commit transaction*/
2429 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2430 if (ret != SQLITE_OK) {
2431 _LOGD("Failed to commit transaction, Rollback now\n");
2432 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2436 _LOGD("Transaction Commit and End\n");
2438 pkgmgr_parser_close_db();
2442 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2445 ret = pkgmgr_parser_check_and_create_db(uid);
2447 _LOGD("Failed to open DB\n");
2450 /*Begin transaction*/
2451 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2452 if (ret != SQLITE_OK) {
2453 _LOGD("Failed to begin transaction\n");
2457 _LOGD("Transaction Begin\n");
2458 ret = __update_preload_condition_in_db();
2460 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2461 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2464 /*Commit transaction*/
2465 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2466 if (ret != SQLITE_OK) {
2467 _LOGD("Failed to commit transaction, Rollback now\n");
2468 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2472 _LOGD("Transaction Commit and End\n");
2474 pkgmgr_parser_close_db();