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 #include <system_info.h>
37 /* For multi-user support */
38 #include <tzplatform_config.h>
40 #include "pkgmgr-info.h"
41 #include "pkgmgrinfo_basic.h"
42 #include "pkgmgrinfo_debug.h"
43 #include "pkgmgr_parser_internal.h"
44 #include "pkgmgr_parser_db.h"
49 #define LOG_TAG "PKGMGR_PARSER"
51 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
52 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
53 #define MAX_QUERY_LEN 4096
61 #define XXHDPI "xxhdpi"
71 #define XXHDPI_MIN 481
72 #define XXHDPI_MAX 600
74 #define DB_LABEL "User::Home"
75 #define SET_SMACK_LABEL(x) \
77 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
78 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
80 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
83 sqlite3 *pkgmgr_parser_db;
84 sqlite3 *pkgmgr_cert_db;
87 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
88 "(package text primary key not null, " \
89 "package_type text DEFAULT 'tpk', " \
90 "package_version text, " \
91 "package_api_version text, " \
92 "package_tep_name text, " \
93 "install_location text, " \
94 "package_size text, " \
95 "package_removable text DEFAULT 'true', " \
96 "package_preload text DEFAULT 'false', " \
97 "package_readonly text DEFAULT 'false', " \
98 "package_update text DEFAULT 'false', " \
99 "package_appsetting text DEFAULT 'false', " \
100 "package_nodisplay text DEFAULT 'false', " \
101 "package_system text DEFAULT 'false', " \
102 "author_name text, " \
103 "author_email text, " \
104 "author_href text," \
105 "installed_time text," \
106 "installed_storage text," \
107 "storeclient_id text," \
109 "package_url text," \
112 "package_support_disable text DEFAULT 'false', " \
113 "package_disable text DEFAULT 'false')"
115 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
116 "(package text not null, " \
117 "package_locale text DEFAULT 'No Locale', " \
118 "package_label text, " \
119 "package_icon text, " \
120 "package_description text, " \
121 "package_license text, " \
123 "PRIMARY KEY(package, package_locale), " \
124 "FOREIGN KEY(package) " \
125 "REFERENCES package_info(package) " \
128 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
129 "(package text not null, " \
130 "privilege text not null, " \
131 "PRIMARY KEY(package, privilege) " \
132 "FOREIGN KEY(package) " \
133 "REFERENCES package_info(package) " \
136 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
137 "(app_id text primary key not null, " \
138 "app_component text, " \
140 "app_nodisplay text DEFAULT 'false', " \
142 "app_onboot text DEFAULT 'false', " \
143 "app_multiple text DEFAULT 'false', " \
144 "app_autorestart text DEFAULT 'false', " \
145 "app_taskmanage text DEFAULT 'false', " \
146 "app_enabled text DEFAULT 'true', " \
147 "app_hwacceleration text DEFAULT 'use-system-setting', " \
148 "app_screenreader text DEFAULT 'use-system-setting', " \
149 "app_mainapp text, " \
150 "app_recentimage text, " \
151 "app_launchcondition text, " \
152 "app_indicatordisplay text DEFAULT 'true', " \
153 "app_portraitimg text, " \
154 "app_landscapeimg text, " \
155 "app_guestmodevisibility text DEFAULT 'true', " \
156 "app_permissiontype text DEFAULT 'normal', " \
157 "app_preload text DEFAULT 'false', " \
158 "app_submode text DEFAULT 'false', " \
159 "app_submode_mainid text, " \
160 "app_installed_storage text, " \
161 "app_process_pool text DEFAULT 'false', " \
162 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
163 "app_ui_gadget text DEFAULT 'false', " \
164 "app_support_disable text DEFAULT 'false', " \
165 "app_disable text DEFAULT 'false', " \
166 "app_package_type text DEFAULT 'tpk', " \
167 "component_type text, " \
168 "package text not null, " \
169 "app_tep_name text, " \
170 "app_background_category INTEGER DEFAULT 0, " \
171 "FOREIGN KEY(package) " \
172 "REFERENCES package_info(package) " \
175 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
176 "(app_id text not null, " \
177 "app_locale text DEFAULT 'No Locale', " \
180 "PRIMARY KEY(app_id,app_locale) " \
181 "FOREIGN KEY(app_id) " \
182 "REFERENCES package_app_info(app_id) " \
185 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
186 "(app_id text not null, " \
188 "app_icon_section text, " \
189 "app_icon_resolution text, " \
190 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
191 "FOREIGN KEY(app_id) " \
192 "REFERENCES package_app_info(app_id) " \
195 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
196 "(app_id text not null, " \
197 "app_locale text DEFAULT 'No Locale', " \
198 "app_image_section text, " \
200 "PRIMARY KEY(app_id,app_image_section) " \
201 "FOREIGN KEY(app_id) " \
202 "REFERENCES package_app_info(app_id) " \
205 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
206 "(app_id text not null, " \
207 "app_control text not null, " \
208 "PRIMARY KEY(app_id,app_control) " \
209 "FOREIGN KEY(app_id) " \
210 "REFERENCES package_app_info(app_id) " \
213 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
214 "(app_id text not null, " \
215 "category text not null, " \
216 "PRIMARY KEY(app_id,category) " \
217 "FOREIGN KEY(app_id) " \
218 "REFERENCES package_app_info(app_id) " \
221 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
222 "(app_id text not null, " \
223 "md_key text not null, " \
224 "md_value text not null, " \
225 "PRIMARY KEY(app_id, md_key, md_value) " \
226 "FOREIGN KEY(app_id) " \
227 "REFERENCES package_app_info(app_id) " \
230 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
231 "(app_id text not null, " \
232 "pm_type text not null, " \
233 "pm_value text not null, " \
234 "PRIMARY KEY(app_id, pm_type, pm_value) " \
235 "FOREIGN KEY(app_id) " \
236 "REFERENCES package_app_info(app_id) " \
239 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
240 "(app_id text not null, " \
241 "data_share_path text not null, " \
242 "data_share_allowed text not null, " \
243 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
244 "FOREIGN KEY(app_id) " \
245 "REFERENCES package_app_info(app_id) " \
248 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
249 "(app_id text not null, " \
250 "data_share_request text not null, " \
251 "PRIMARY KEY(app_id,data_share_request) " \
252 "FOREIGN KEY(app_id) " \
253 "REFERENCES package_app_info(app_id) " \
256 /* FIXME: duplicated at pkgmgrinfo_db.c */
257 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
258 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
259 " cert_info TEXT UNIQUE, " \
260 " cert_id INTEGER PRIMARY KEY, " \
261 " cert_ref_count INTEGER NOT NULL)"
263 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
264 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
265 " package TEXT PRIMARY KEY, " \
266 " author_root_cert INTEGER, " \
267 " author_im_cert INTEGER, " \
268 " author_signer_cert INTEGER, " \
269 " dist_root_cert INTEGER, " \
270 " dist_im_cert INTEGER, " \
271 " dist_signer_cert INTEGER, " \
272 " dist2_root_cert INTEGER, " \
273 " dist2_im_cert INTEGER, " \
274 " dist2_signer_cert INTEGER)"
276 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
277 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
278 "AFTER DELETE ON package_cert_info " \
280 " UPDATE package_cert_index_info SET" \
281 " cert_ref_count = cert_ref_count - 1" \
282 " WHERE cert_id = OLD.author_root_cert" \
283 " OR cert_id = OLD.author_im_cert" \
284 " OR cert_id = OLD.author_signer_cert" \
285 " OR cert_id = OLD.dist_root_cert" \
286 " OR cert_id = OLD.dist_im_cert" \
287 " OR cert_id = OLD.dist_signer_cert" \
288 " OR cert_id = OLD.dist2_root_cert" \
289 " OR cert_id = OLD.dist2_im_cert" \
290 " OR cert_id = OLD.dist2_signer_cert;" \
293 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
294 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
295 "AFTER UPDATE ON package_cert_index_info " \
296 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
297 " WHERE cert_id = OLD.cert_id) = 0) "\
299 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
302 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT \
303 "CREATE TRIGGER IF NOT EXISTS update_%s_info " \
304 "AFTER UPDATE ON package_cert_info " \
305 "WHEN (OLD.%s IS NOT NULL) " \
307 " UPDATE package_cert_index_info SET" \
308 " cert_ref_count = cert_ref_count - 1" \
309 " WHERE cert_id = OLD.%s;" \
312 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
313 "(app_id text not null, " \
314 "providerid text not null, " \
315 "access text not null, " \
316 "type text not null, " \
317 "PRIMARY KEY(app_id, providerid, access, type) " \
318 "FOREIGN KEY(app_id) " \
319 "REFERENCES package_app_info(app_id) " \
322 #define QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER "CREATE TABLE IF NOT EXISTS package_app_disable_for_user " \
323 "(app_id text not null, " \
324 "uid text not null, " \
325 "PRIMARY KEY(app_id, uid))"
327 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
328 "create table if not exists package_app_splash_screen " \
329 "(app_id text not null, " \
330 "src text not null, " \
331 "type text not null, " \
332 "orientation text not null, " \
333 "indicatordisplay text, " \
334 "PRIMARY KEY(app_id, orientation) " \
335 "FOREIGN KEY(app_id) " \
336 "REFERENCES package_app_info(app_id) " \
339 static int __insert_application_info(manifest_x *mfx);
340 static int __insert_application_appcategory_info(manifest_x *mfx);
341 static int __insert_application_appcontrol_info(manifest_x *mfx);
342 static int __insert_application_appmetadata_info(manifest_x *mfx);
343 static int __insert_application_share_allowed_info(manifest_x *mfx);
344 static int __insert_application_share_request_info(manifest_x *mfx);
345 static int __insert_application_datacontrol_info(manifest_x *mfx);
346 static void __insert_application_locale_info(gpointer data, gpointer userdata);
347 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
348 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
349 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
350 static int __delete_subpkg_info_from_db(char *appid);
351 static int __delete_appinfo_from_db(char *db_table, const char *appid);
352 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
353 static int __exec_query(char *query);
354 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
355 char **label, char **license, char **icon, char **description, char **author);
356 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
357 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
358 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
359 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
360 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
361 static int __parserdb_change_perm(const char *db_file, uid_t uid);
363 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
366 __delete_subpkg_info_from_db(coltxt[0]);
371 static const char *__get_str(const char *str)
375 return PKGMGR_PARSER_EMPTY_STR;
381 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
386 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
387 if (ret != SQLITE_OK) {
388 _LOGD("connect db [%s] failed!\n", db_path);
396 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
398 manifest_x *mfx = (manifest_x *)data;
404 if (mfx->application == NULL)
406 app = (application_x *)mfx->application->data;
407 for(i = 0; i < ncols; i++)
409 if (strcmp(colname[i], "app_id") == 0) {
411 appid = strdup(coltxt[i]);
412 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
414 status = strdup(coltxt[i]);
420 _LOGD("app id is NULL\n");
423 /*update guest mode visibility*/
424 for (tmp = mfx->application; tmp; tmp = tmp->next) {
425 app = (application_x *)tmp->data;
428 if (strcmp(app->appid, appid) == 0) {
429 free((void *)app->guestmode_visibility);
430 app->guestmode_visibility = strdup(status);
446 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
448 char *error_message = NULL;
449 char query[MAX_QUERY_LEN] = {'\0'};
450 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
452 sqlite3_exec(pkgmgr_parser_db, query,
453 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
454 _LOGD("Don't execute query = %s error message = %s\n",
455 query, error_message);
456 sqlite3_free(error_message);
461 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
463 char *error_message = NULL;
465 sqlite3_exec(db_handle, db_query,
466 NULL, NULL, &error_message)) {
467 _LOGD("Don't execute query = %s error message = %s\n",
468 db_query, error_message);
469 sqlite3_free(error_message);
472 sqlite3_free(error_message);
476 static int __exec_query(char *query)
478 char *error_message = NULL;
480 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
481 _LOGE("Don't execute query = %s error message = %s\n", query,
483 sqlite3_free(error_message);
486 sqlite3_free(error_message);
490 static int __exec_query_no_msg(char *query)
492 char *error_message = NULL;
494 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
495 sqlite3_free(error_message);
498 sqlite3_free(error_message);
502 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
510 for (tmp = lbls; tmp; tmp = tmp->next) {
511 lbl = (label_x *)tmp->data;
515 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
517 for (tmp = lcns; tmp; tmp = tmp->next) {
518 lcn = (license_x *)tmp->data;
522 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
524 for (tmp = icns; tmp; tmp = tmp->next) {
525 icn = (icon_x *)tmp->data;
529 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
531 for (tmp = dcns; tmp; tmp = tmp->next) {
532 dcn = (description_x *)tmp->data;
536 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
538 for (tmp = aths; tmp; tmp = tmp->next) {
539 ath = (author_x *)tmp->data;
543 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
549 static GList *__create_icon_list(GList *appicon, GList *icns)
554 for (tmp = icns; tmp; tmp = tmp->next) {
555 icn = (icon_x *)tmp->data;
559 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
564 static GList *__create_image_list(GList *appimage, GList *imgs)
569 for (tmp = imgs; tmp; tmp = tmp->next) {
570 img = (image_x *)tmp->data;
574 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
579 static void __trimfunc(GList* trim_list)
581 char *trim_data = NULL;
585 list = g_list_first(trim_list);
588 trim_data = (char *)list->data;
591 if (strcmp(trim_data, prev) == 0) {
592 trim_list = g_list_remove(trim_list, trim_data);
593 list = g_list_first(trim_list);
602 list = g_list_next(list);
606 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
608 if (a == NULL || b == NULL)
610 if (strcmp((char*)a, (char*)b) == 0)
612 if (strcmp((char*)a, (char*)b) < 0)
614 if (strcmp((char*)a, (char*)b) > 0)
619 static int __check_dpi(const char *dpi_char, int dpi_int)
621 if (dpi_char == NULL)
624 if (strcasecmp(dpi_char, LDPI) == 0) {
625 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
629 } else if (strcasecmp(dpi_char, MDPI) == 0) {
630 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
634 } else if (strcasecmp(dpi_char, HDPI) == 0) {
635 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
639 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
640 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
644 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
645 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
653 static gint __compare_icon(gconstpointer a, gconstpointer b)
655 icon_x *icon = (icon_x *)a;
657 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
660 if (icon->dpi != NULL)
666 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
668 icon_x *icon = (icon_x *)a;
669 int dpi = GPOINTER_TO_INT(b);
671 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
674 if (icon->dpi == NULL)
677 if (__check_dpi(icon->dpi, dpi) == 0)
683 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
685 icon_x *icon = (icon_x *)a;
686 char *lang = (char *)b;
688 if (icon->dpi != NULL)
691 if (strcasecmp(icon->lang, lang) == 0)
697 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
699 icon_x *icon = (icon_x *)a;
700 char *lang = (char *)b;
703 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
707 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
713 static char *__find_icon(GList *icons, const char *lang)
719 // first, find icon whose locale and dpi with given lang and system's dpi has matched
720 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
722 icon = (icon_x *)tmp->data;
723 return (char *)icon->text;
726 // if first has failed, find icon whose locale has matched
727 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
729 icon = (icon_x *)tmp->data;
730 return (char *)icon->text;
733 // if second has failed, find icon whose dpi has matched with system's dpi
734 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
737 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
739 icon = (icon_x *)tmp->data;
740 return (char *)icon->text;
743 // last, find default icon marked as "No Locale"
744 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
746 icon = (icon_x *)tmp->data;
747 return (char *)icon->text;
753 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
754 char **label, char **license, char **icon, char **description, char **author)
761 for (tmp = lbls; tmp; tmp = tmp->next) {
762 lbl = (label_x *)tmp->data;
766 if (strcmp(lbl->lang, (char *)data) == 0) {
767 *label = (char*)lbl->text;
772 for (tmp = lcns; tmp; tmp = tmp->next) {
773 lcn = (license_x *)tmp->data;
777 if (strcmp(lcn->lang, (char *)data) == 0) {
778 *license = (char*)lcn->text;
784 *icon = __find_icon(icns, (char *)data);
786 for (tmp = dcns; tmp; tmp = tmp->next) {
787 dcn = (description_x *)tmp->data;
791 if (strcmp(dcn->lang, (char *)data) == 0) {
792 *description = (char*)dcn->text;
797 for (tmp = aths; tmp; tmp = tmp->next) {
798 ath = (author_x *)tmp->data;
802 if (strcmp(ath->lang, (char *)data) == 0) {
803 *author = (char*)ath->text;
811 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
815 for (tmp = icns; tmp; tmp = tmp->next) {
816 icn = (icon_x *)tmp->data;
820 if (strcmp(icn->section, (char *)data) == 0) {
821 *icon = (char*)icn->text;
822 *resolution = (char*)icn->resolution;
829 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
833 for (tmp = imgs; tmp; tmp = tmp->next) {
834 img = (image_x *)tmp->data;
838 if (strcmp(img->section, (char *)data) == 0) {
839 *lang = (char*)img->lang;
840 *image = (char*)img->text;
847 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
852 char *description = NULL;
853 char *license = NULL;
857 manifest_x *mfx = (manifest_x *)userdata;
858 GList *lbl = mfx->label;
859 GList *lcn = mfx->license;
860 GList *icn = mfx->icon;
861 GList *dcn = mfx->description;
862 GList *ath = mfx->author;
864 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
865 if (!label && !description && !icon && !license && !author)
868 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
869 "package_label, package_icon, package_description, package_license, package_author) values " \
870 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
875 __get_str(description),
879 ret = __exec_query(query);
881 _LOGD("Package Localized Info DB Insert failed\n");
886 static void __insert_application_locale_info(gpointer data, gpointer userdata)
893 application_x *app = (application_x*)userdata;
894 GList *lbl = app->label;
895 GList *icn = app->icon;
897 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
901 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
902 "app_label, app_icon) values " \
903 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
904 __get_str(label), __get_str(icon));
905 ret = __exec_query(query);
907 _LOGD("Package UiApp Localized Info DB Insert failed\n");
911 /*insert ui app locale info to pkg locale to get mainapp data */
912 if (strcasecmp(app->mainapp, "true")==0) {
913 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
914 "package_label, package_icon, package_description, package_license, package_author) values " \
915 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
920 PKGMGR_PARSER_EMPTY_STR,
921 PKGMGR_PARSER_EMPTY_STR,
922 PKGMGR_PARSER_EMPTY_STR);
924 ret = __exec_query_no_msg(query);
928 query = sqlite3_mprintf("update package_localized_info set package_icon=%Q "\
929 "where package=%Q and package_locale=%Q", icon, app->package, (char*)data);
930 ret = __exec_query_no_msg(query);
936 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
940 char *resolution = NULL;
941 char query[MAX_QUERY_LEN] = {'\0'};
943 application_x *app = (application_x*)userdata;
944 GList *icn = app->icon;
946 __extract_icon_data(data, icn, &icon, &resolution);
947 if (!icon && !resolution)
949 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
950 "app_icon, app_icon_section, app_icon_resolution) values " \
951 "('%q', '%q', '%q', '%q')", app->appid,
952 icon, (char*)data, resolution);
954 ret = __exec_query(query);
956 _LOGD("Package UiApp Localized Info DB Insert failed\n");
960 static void __insert_application_image_info(gpointer data, gpointer userdata)
965 char query[MAX_QUERY_LEN] = {'\0'};
967 application_x *app = (application_x*)userdata;
968 GList *image = app->image;
970 __extract_image_data(data, image, &lang, &img);
973 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
974 "app_image_section, app_image) values " \
975 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
977 ret = __exec_query(query);
979 _LOGD("Package UiApp image Info DB Insert failed\n");
984 static int __insert_mainapp_info(manifest_x *mfx)
989 char query[MAX_QUERY_LEN] = {'\0'};
990 for (tmp = mfx->application; tmp; tmp = tmp->next) {
991 app = (application_x *)tmp->data;
994 snprintf(query, MAX_QUERY_LEN,
995 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
997 ret = __exec_query(query);
999 _LOGD("Package App Info DB Insert Failed\n");
1002 if (strcasecmp(app->mainapp, "True")==0)
1003 mfx->mainapp_id = strdup(app->appid);
1006 if (mfx->mainapp_id == NULL) {
1007 if (mfx->application == NULL)
1009 app = (application_x *)mfx->application->data;
1013 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
1015 _LOGD("Not valid appid\n");
1019 ret = __exec_query(query);
1021 _LOGD("Package UiApp Info DB Insert Failed\n");
1025 free((void *)app->mainapp);
1026 app->mainapp= strdup("true");
1027 mfx->mainapp_id = strdup(app->appid);
1030 memset(query, '\0', MAX_QUERY_LEN);
1031 snprintf(query, MAX_QUERY_LEN,
1032 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
1033 ret = __exec_query(query);
1035 _LOGD("Package Info DB update Failed\n");
1042 static int __convert_background_category(GList *category_list)
1045 GList *tmp_list = category_list;
1046 char *category_data = NULL;
1048 if (category_list == NULL)
1051 while (tmp_list != NULL) {
1052 category_data = (char *)tmp_list->data;
1053 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1054 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1055 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1056 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1057 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1058 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1059 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1060 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1061 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1062 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1063 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1064 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1065 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1066 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1068 _LOGE("Unidentified category [%s]", category_data);
1070 tmp_list = g_list_next(tmp_list);
1076 /* _PRODUCT_LAUNCHING_ENHANCED_
1077 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1079 static int __insert_application_info(manifest_x *mfx)
1084 int background_value = 0;
1085 char query[MAX_QUERY_LEN] = {'\0'};
1089 type = strdup(mfx->type);
1091 type = strdup("tpk");
1093 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1094 app = (application_x *)tmp->data;
1098 background_value = __convert_background_category(app->background_category);
1099 if (background_value < 0) {
1100 _LOGE("Failed to retrieve background value[%d]", background_value);
1101 background_value = 0;
1104 snprintf(query, MAX_QUERY_LEN,
1105 "insert into package_app_info(" \
1106 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1107 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1108 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1109 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1110 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1111 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1112 "app_tep_name, app_background_category, app_package_type) " \
1114 "'%s', '%s', '%s', '%s', '%s', " \
1115 "'%s', '%s', '%s', '%s', '%s', " \
1116 "'%s', '%s', '%s', '%s', '%s', " \
1117 "'%s', '%s', '%s', '%s', '%s', " \
1118 "'%s', '%s', '%s', '%s', '%s', " \
1119 "'%s', '%s', '%s', '%s', '%s', " \
1120 "'%s', '%d', '%s')", \
1121 app->appid, app->component_type, app->exec, app->nodisplay, app->type,
1122 app->onboot, app->multiple, app->autorestart, app->taskmanage, app->enabled,
1123 app->hwacceleration, app->screenreader, app->mainapp, __get_str(app->recentimage), app->launchcondition,
1124 app->indicatordisplay, __get_str(app->portraitimg), __get_str(app->landscapeimg),
1125 app->guestmode_visibility, app->permission_type,
1126 mfx->preload, app->submode, __get_str(app->submode_mainid), mfx->installed_storage, app->process_pool,
1127 app->launch_mode, app->ui_gadget, mfx->support_disable, app->component_type, mfx->package,
1128 __get_str(mfx->tep_name), background_value, type);
1130 ret = __exec_query(query);
1132 _LOGD("Package UiApp Info DB Insert Failed\n");
1137 memset(query, '\0', MAX_QUERY_LEN);
1146 static int __insert_application_appcategory_info(manifest_x *mfx)
1153 char query[MAX_QUERY_LEN] = {'\0'};
1154 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1155 app = (application_x *)app_tmp->data;
1158 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1159 ct = (const char *)ct_tmp->data;
1162 snprintf(query, MAX_QUERY_LEN,
1163 "insert into package_app_app_category(app_id, category) " \
1164 "values('%s','%s')",\
1166 ret = __exec_query(query);
1168 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1171 memset(query, '\0', MAX_QUERY_LEN);
1177 static int __insert_application_appmetadata_info(manifest_x *mfx)
1184 char query[MAX_QUERY_LEN] = {'\0'};
1185 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1186 app = (application_x *)app_tmp->data;
1189 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1190 md = (metadata_x *)md_tmp->data;
1194 snprintf(query, MAX_QUERY_LEN,
1195 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1196 "values('%s','%s', '%s')",\
1197 app->appid, md->key, md->value ? md->value : "");
1198 ret = __exec_query(query);
1200 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1204 memset(query, '\0', MAX_QUERY_LEN);
1210 static int __insert_application_apppermission_info(manifest_x *mfx)
1217 char query[MAX_QUERY_LEN] = {'\0'};
1218 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1219 app = (application_x *)app_tmp->data;
1222 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1223 pm = (permission_x *)pm_tmp->data;
1226 snprintf(query, MAX_QUERY_LEN,
1227 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1228 "values('%s','%s', '%s')",\
1229 app->appid, pm->type, pm->value);
1230 ret = __exec_query(query);
1232 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1235 memset(query, '\0', MAX_QUERY_LEN);
1241 static int __insert_application_appcontrol_info(manifest_x *mfx)
1245 GList *acontrol_tmp;
1246 appcontrol_x *acontrol;
1248 char query[MAX_QUERY_LEN] = {'\0'};
1249 char buf[BUFSIZE] = {'\0'};
1250 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1251 app = (application_x *)app_tmp->data;
1254 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1255 acontrol = (appcontrol_x *)acontrol_tmp->data;
1256 if (acontrol == NULL)
1258 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1259 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1260 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1261 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1262 snprintf(query, MAX_QUERY_LEN,
1263 "insert into package_app_app_control(app_id, app_control) " \
1264 "values('%s', '%s')",\
1266 ret = __exec_query(query);
1268 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1271 memset(query, '\0', MAX_QUERY_LEN);
1277 static int __insert_application_datacontrol_info(manifest_x *mfx)
1284 char query[MAX_QUERY_LEN] = {'\0'};
1286 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1287 app = (application_x *)app_tmp->data;
1290 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1291 dc = (datacontrol_x *)dc_tmp->data;
1294 snprintf(query, MAX_QUERY_LEN,
1295 "insert into package_app_data_control(app_id, providerid, access, type) " \
1296 "values('%s', '%s', '%s', '%s')",\
1302 ret = __exec_query(query);
1304 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1307 memset(query, '\0', MAX_QUERY_LEN);
1313 static int __insert_application_share_request_info(manifest_x *mfx)
1322 char query[MAX_QUERY_LEN] = {'\0'};
1323 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1324 app = (application_x *)app_tmp->data;
1327 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1328 ds = (datashare_x *)ds_tmp->data;
1331 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1332 rq = (const char *)rq_tmp->data;
1335 snprintf(query, MAX_QUERY_LEN,
1336 "insert into package_app_share_request(app_id, data_share_request) " \
1337 "values('%s', '%s')",\
1339 ret = __exec_query(query);
1341 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1344 memset(query, '\0', MAX_QUERY_LEN);
1351 static int __insert_application_share_allowed_info(manifest_x *mfx)
1362 char query[MAX_QUERY_LEN] = {'\0'};
1363 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1364 app = (application_x *)app_tmp->data;
1367 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1368 ds = (datashare_x *)ds_tmp->data;
1371 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1372 df = (define_x *)df_tmp->data;
1375 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1376 al = (const char *)al_tmp->data;
1379 snprintf(query, MAX_QUERY_LEN,
1380 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1381 "values('%s', '%s', '%s')",\
1382 app->appid, df->path, al);
1383 ret = __exec_query(query);
1385 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1388 memset(query, '\0', MAX_QUERY_LEN);
1396 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1398 splashscreen_x *ss = (splashscreen_x *)a;
1399 const char *orientation = (const char *)b;
1402 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1406 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1412 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1414 splashscreen_x *ss = (splashscreen_x *)a;
1415 const char *orientation = (const char *)b;
1417 if (strcasecmp(ss->orientation, orientation) == 0 && (ss->dpi == NULL))
1423 static splashscreen_x *__find_splashscreen(GList *splashscreens, const char *orientation)
1427 tmp = g_list_find_custom(splashscreens, orientation,
1428 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1430 return (splashscreen_x *)tmp->data;
1432 tmp = g_list_find_custom(splashscreens, orientation,
1433 (GCompareFunc)__compare_splashscreen_with_orientation);
1435 return (splashscreen_x *)tmp->data;
1440 static int __insert_application_splashscreen_info(manifest_x *mfx)
1446 char query[MAX_QUERY_LEN];
1448 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1449 app = (application_x *)app_tmp->data;
1450 if (app == NULL || app->splashscreens == NULL)
1453 ss = __find_splashscreen(app->splashscreens, "portrait");
1455 snprintf(query, sizeof(query),
1456 "insert into package_app_splash_screen" \
1457 "(app_id, src, type, orientation, indicatordisplay) " \
1458 "values('%s', '%s', '%s', '%s', '%s')",
1459 app->appid, ss->src, ss->type, ss->orientation,
1460 ss->indicatordisplay);
1461 ret = __exec_query(query);
1463 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1466 memset(query, '\0', MAX_QUERY_LEN);
1468 ss = __find_splashscreen(app->splashscreens, "landscape");
1470 snprintf(query, sizeof(query),
1471 "insert into package_app_splash_screen" \
1472 "(app_id, src, type, orientation, indicatordisplay) " \
1473 "values('%s', '%s', '%s', '%s', '%s')",
1474 app->appid, ss->src, ss->type, ss->orientation,
1475 ss->indicatordisplay);
1476 ret = __exec_query(query);
1478 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1481 memset(query, '\0', MAX_QUERY_LEN);
1487 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1492 char query[MAX_QUERY_LEN];
1494 const char *image_type;
1495 const char *indicatordisplay;
1496 const char *orientation;
1498 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1499 app = (application_x *)app_tmp->data;
1501 (app->portraitimg == NULL && app->landscapeimg == NULL))
1503 image_type = "img"; /* default */
1504 if (app->effectimage_type) {
1505 tmp = strstr(app->effectimage_type, "edj");
1509 indicatordisplay = "true"; /* default */
1510 if (app->indicatordisplay)
1511 indicatordisplay = app->indicatordisplay;
1512 if (app->portraitimg) {
1513 orientation = "portrait";
1514 snprintf(query, sizeof(query),
1515 "insert into package_app_splash_screen" \
1516 "(app_id, src, type, orientation, indicatordisplay) " \
1517 "values('%s', '%s', '%s', '%s', '%s')",
1518 app->appid, app->portraitimg, image_type,
1519 orientation, indicatordisplay);
1520 ret = __exec_query(query);
1522 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1525 memset(query, '\0', MAX_QUERY_LEN);
1526 } else if (app->landscapeimg) {
1527 orientation = "landscape";
1528 snprintf(query, sizeof(query),
1529 "insert into package_app_splash_screen" \
1530 "(app_id, src, type, orientation, indicatordisplay) " \
1531 "values('%s', '%s', '%s', '%s', '%s')",
1532 app->appid, app->landscapeimg, image_type,
1533 orientation, indicatordisplay);
1534 ret = __exec_query(query);
1536 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1539 memset(query, '\0', MAX_QUERY_LEN);
1545 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1549 const char *pv = NULL;
1550 char query[MAX_QUERY_LEN] = { '\0' };
1553 const char *auth_name = NULL;
1554 const char *auth_email = NULL;
1555 const char *auth_href = NULL;
1557 GList *pkglocale = NULL;
1558 GList *applocale = NULL;
1559 GList *appicon = NULL;
1560 GList *appimage = NULL;
1562 if (mfx->author && mfx->author->data) {
1563 author = (author_x *)mfx->author->data;
1565 auth_name = author->text;
1567 auth_email = author->email;
1569 auth_href = author->href;
1571 /*Insert in the package_cert_info CERT_DB*/
1572 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1573 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1574 if (ret != PMINFO_R_OK) {
1575 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1576 _LOGE("Cert Info DB create handle failed\n");
1579 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1580 if (ret != PMINFO_R_OK) {
1581 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1582 _LOGE("Cert Info DB Insert Failed\n");
1586 /*Insert in the package_info DB*/
1587 snprintf(query, MAX_QUERY_LEN,
1588 "insert into package_info(" \
1589 "package, package_type, package_version, package_api_version, package_tep_name, " \
1590 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1591 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1592 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1593 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1595 "'%s', '%s', '%s', '%s', '%s', " \
1596 "'%s', '%s', '%s', '%s', '%s', " \
1597 "'%s', '%s', '%s', '%s', '%s', " \
1598 "'%s', '%s', '%s', '%s', '%s', " \
1599 "'%s', '%s', '%s', '%s', '%s')", \
1600 mfx->package, mfx->type, mfx->version, __get_str(mfx->api_version), __get_str(mfx->tep_name),
1601 __get_str(mfx->installlocation), __get_str(mfx->package_size), mfx->removable, mfx->preload, mfx->readonly,
1602 mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system, __get_str(auth_name),
1603 __get_str(auth_email), __get_str(auth_href), mfx->installed_time, mfx->installed_storage,
1604 __get_str(mfx->storeclient_id),
1605 mfx->mainapp_id, __get_str(mfx->package_url), mfx->root_path, __get_str(mfx->csc_path), mfx->support_disable);
1607 ret = __exec_query(query);
1609 _LOGD("Package Info DB Insert Failed\n");
1613 /*Insert in the package_privilege_info DB*/
1614 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1615 pv = (const char *)tmp->data;
1618 memset(query, '\0', MAX_QUERY_LEN);
1619 snprintf(query, MAX_QUERY_LEN,
1620 "insert into package_privilege_info(package, privilege) " \
1621 "values('%s','%s')",\
1623 ret = __exec_query(query);
1625 _LOGD("Package Privilege Info DB Insert Failed\n");
1630 if (mfx->application != NULL) {
1631 ret = __insert_mainapp_info(mfx);
1636 /*Insert the package locale*/
1637 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1638 /*remove duplicated data in pkglocale*/
1639 __trimfunc(pkglocale);
1641 /*Insert the app locale, icon, image info */
1642 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1643 app = (application_x *)tmp->data;
1646 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1647 appicon = __create_icon_list(appicon, app->icon);
1648 appimage = __create_image_list(appimage, app->image);
1650 /*remove duplicated data in applocale*/
1651 __trimfunc(applocale);
1652 __trimfunc(appicon);
1653 __trimfunc(appimage);
1655 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1657 /*native app locale info*/
1658 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1659 app = (application_x *)tmp->data;
1662 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1663 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1664 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1667 g_list_free(pkglocale);
1669 g_list_free(applocale);
1671 g_list_free(appicon);
1673 g_list_free(appimage);
1676 /*Insert in the package_app_info DB*/
1677 ret = __insert_application_info(mfx);
1680 /*Insert in the package_app_app_control DB*/
1681 ret = __insert_application_appcontrol_info(mfx);
1685 /*Insert in the package_app_app_category DB*/
1686 ret = __insert_application_appcategory_info(mfx);
1690 /*Insert in the package_app_app_metadata DB*/
1691 ret = __insert_application_appmetadata_info(mfx);
1695 /*Insert in the package_app_app_permission DB*/
1696 ret = __insert_application_apppermission_info(mfx);
1700 /*Insert in the package_app_share_allowed DB*/
1701 ret = __insert_application_share_allowed_info(mfx);
1705 /*Insert in the package_app_share_request DB*/
1706 ret = __insert_application_share_request_info(mfx);
1710 /*Insert in the package_app_data_control DB*/
1711 ret = __insert_application_datacontrol_info(mfx);
1715 /*Insert in the package_app_splash_screen DB*/
1716 ret = __insert_application_legacy_splashscreen_info(mfx);
1720 /*Insert in the package_app_splash_screen DB*/
1721 ret = __insert_application_splashscreen_info(mfx);
1729 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1731 char query[MAX_QUERY_LEN] = { '\0' };
1733 memset(query, '\0', MAX_QUERY_LEN);
1734 snprintf(query, MAX_QUERY_LEN,
1735 "delete from %s where app_id='%s'", db_table, appid);
1736 ret = __exec_query(query);
1738 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1744 static int __delete_subpkg_info_from_db(char *appid)
1748 ret = __delete_appinfo_from_db("package_app_info", appid);
1751 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1754 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1757 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1760 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1763 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1766 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1769 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1772 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1775 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1778 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1781 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
1788 static int __delete_subpkg_from_db(manifest_x *mfx)
1790 char query[MAX_QUERY_LEN] = { '\0' };
1791 char *error_message = NULL;
1793 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1795 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1796 _LOGE("Don't execute query = %s error message = %s\n", query,
1798 sqlite3_free(error_message);
1801 sqlite3_free(error_message);
1806 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1808 char query[MAX_QUERY_LEN] = { '\0' };
1812 /*Delete from cert table*/
1813 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1815 _LOGD("Cert Info DB Delete Failed\n");
1819 /*Delete from Package Info DB*/
1820 snprintf(query, MAX_QUERY_LEN,
1821 "delete from package_info where package='%s'", mfx->package);
1822 ret = __exec_query(query);
1824 _LOGD("Package Info DB Delete Failed\n");
1827 memset(query, '\0', MAX_QUERY_LEN);
1829 /*Delete from Package Localized Info*/
1830 snprintf(query, MAX_QUERY_LEN,
1831 "delete from package_localized_info where package='%s'", mfx->package);
1832 ret = __exec_query(query);
1834 _LOGD("Package Localized Info DB Delete Failed\n");
1838 /*Delete from Package Privilege Info*/
1839 snprintf(query, MAX_QUERY_LEN,
1840 "delete from package_privilege_info where package='%s'", mfx->package);
1841 ret = __exec_query(query);
1843 _LOGD("Package Privilege Info DB Delete Failed\n");
1847 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1848 app = (application_x *)tmp->data;
1851 ret = __delete_appinfo_from_db("package_app_info", app->appid);
1854 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
1857 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
1860 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
1863 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
1866 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
1869 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
1872 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
1875 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
1878 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
1881 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
1884 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
1889 /* if main package has sub pkg, delete sub pkg data*/
1890 __delete_subpkg_from_db(mfx);
1895 static int __disable_app(const char *appid)
1898 char query[MAX_QUERY_LEN] = {'\0'};
1899 sqlite3_snprintf(MAX_QUERY_LEN, query,
1900 "UPDATE package_app_info set app_disable='true' where app_id=%Q",
1902 ret = __exec_query(query);
1904 _LOGD("Insert global app disable failed\n");
1909 static int __enable_app(const char *appid)
1912 char query[MAX_QUERY_LEN] = {'\0'};
1913 sqlite3_snprintf(MAX_QUERY_LEN, query,
1914 "UPDATE package_app_info set app_disable='false' where app_id=%Q",
1916 ret = __exec_query(query);
1918 _LOGD("Insert global app disable failed\n");
1923 static int __disable_global_app_for_user(const char *appid, uid_t uid)
1926 char query[MAX_QUERY_LEN] = {'\0'};
1928 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO " \
1929 "package_app_disable_for_user(app_id, uid) VALUES(%Q, '%d')",
1931 ret = __exec_query(query);
1933 _LOGD("Insert global app disable failed\n");
1938 static int __enable_global_app_for_user(const char *appid, uid_t uid)
1941 char query[MAX_QUERY_LEN] = {'\0'};
1943 sqlite3_snprintf(MAX_QUERY_LEN, query, "DELETE FROM " \
1944 "package_app_disable_for_user WHERE app_id=%Q AND uid='%d'",
1946 ret = __exec_query(query);
1948 _LOGD("Delete global app disable failed\n");
1953 static int __update_preload_condition_in_db()
1956 char query[MAX_QUERY_LEN] = {'\0'};
1958 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
1960 ret = __exec_query(query);
1962 _LOGD("Package preload_condition update failed\n");
1967 API int pkgmgr_parser_initialize_db(uid_t uid)
1971 char query[MAX_QUERY_LEN];
1972 static const char *columns[] = {
1973 "author_root_cert", "author_im_cert", "author_signer_cert",
1974 "dist_root_cert", "dist_im_cert", "dist_signer_cert",
1975 "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
1979 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
1981 _LOGD("package info DB initialization failed\n");
1984 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
1986 _LOGD("package localized info DB initialization failed\n");
1989 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
1991 _LOGD("package app app privilege DB initialization failed\n");
1994 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
1996 _LOGD("package app info DB initialization failed\n");
1999 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2001 _LOGD("package app localized info DB initialization failed\n");
2004 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2006 _LOGD("package app icon localized info DB initialization failed\n");
2009 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2011 _LOGD("package app image info DB initialization failed\n");
2014 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2016 _LOGD("package app app control DB initialization failed\n");
2019 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2021 _LOGD("package app app category DB initialization failed\n");
2024 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2026 _LOGD("package app app category DB initialization failed\n");
2029 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2031 _LOGD("package app app permission DB initialization failed\n");
2034 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2036 _LOGD("package app share allowed DB initialization failed\n");
2039 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2041 _LOGD("package app share request DB initialization failed\n");
2044 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2046 _LOGD("package app data control DB initialization failed\n");
2050 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER);
2052 _LOGD("package app disable for user DB initialization failed\n");
2056 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2058 _LOGD("package app splash screen DB initialization failed\n");
2063 /* TODO: refactor this code */
2064 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2066 _LOGD("package cert info DB initialization failed\n");
2069 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2071 _LOGD("package cert index info DB initialization failed\n");
2074 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2076 _LOGD("package cert info DB initialization failed\n");
2079 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2081 _LOGD("package cert index info DB initialization failed\n");
2084 for (i = 0; columns[i] != NULL; i++) {
2085 snprintf(query, sizeof(query),
2086 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
2087 columns[i], columns[i], columns[i]);
2088 ret = __initialize_db(pkgmgr_cert_db, query);
2090 _LOGD("package cert index info DB initialization failed\n");
2095 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
2096 _LOGD("Failed to change cert db permission\n");
2098 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2099 _LOGD("Failed to change parser db permission\n");
2105 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2108 char journal_file[BUFSIZE];
2111 struct passwd *userinfo = NULL;
2112 files[0] = (char *)db_file;
2113 files[1] = journal_file;
2117 if (db_file == NULL)
2120 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2122 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2123 if (uid == OWNER_ROOT)
2125 userinfo = getpwuid(uid);
2127 _LOGE("FAIL: user %d doesn't exist", uid);
2130 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2132 for (i = 0; files[i]; i++) {
2133 ret = chown(files[i], uid, userinfo->pw_gid);
2135 if (strerror_r(errno, buf, sizeof(buf)))
2137 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2138 userinfo->pw_gid, buf);
2142 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2143 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2145 ret = chmod(files[i], mode);
2147 if (strerror_r(errno, buf, sizeof(buf)))
2149 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2152 SET_SMACK_LABEL(files[i]);
2157 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2161 if (getuid() != OWNER_ROOT) {
2162 _LOGE("Only root user is allowed");
2166 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2167 _LOGE("Manifest db for user %d is already exists", uid);
2171 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2172 _LOGE("Cert db for user %d is already exists", uid);
2176 ret = pkgmgr_parser_check_and_create_db(uid);
2179 ret = pkgmgr_parser_initialize_db(uid);
2181 pkgmgr_parser_close_db();
2184 pkgmgr_parser_close_db();
2189 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2193 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2195 _LOGD("Manifest DB creation Failed\n");
2200 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2202 _LOGD("Cert DB creation Failed\n");
2208 void pkgmgr_parser_close_db(void)
2210 sqlite3_close(pkgmgr_parser_db);
2211 sqlite3_close(pkgmgr_cert_db);
2215 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2217 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2219 _LOGD("manifest pointer is NULL\n");
2223 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2225 _LOGD("Failed to open DB\n");
2228 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2231 /*Begin transaction*/
2232 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2233 if (ret != SQLITE_OK) {
2234 _LOGD("Failed to begin transaction\n");
2238 _LOGD("Transaction Begin\n");
2239 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2241 _LOGD("Insert into DB failed. Rollback now\n");
2242 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2245 /*Commit transaction*/
2246 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2247 if (ret != SQLITE_OK) {
2248 _LOGD("Failed to commit transaction. Rollback now\n");
2249 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2253 _LOGD("Transaction Commit and End\n");
2255 pkgmgr_parser_close_db();
2259 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2261 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2263 _LOGD("manifest pointer is NULL\n");
2267 ret = pkgmgr_parser_check_and_create_db(uid);
2269 _LOGD("Failed to open DB\n");
2272 ret = pkgmgr_parser_initialize_db(uid);
2275 /*Begin transaction*/
2276 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2277 if (ret != SQLITE_OK) {
2278 _LOGD("Failed to begin transaction\n");
2282 _LOGD("Transaction Begin\n");
2283 ret = __insert_manifest_info_in_db(mfx, uid);
2285 _LOGD("Insert into DB failed. Rollback now\n");
2286 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2289 /*Commit transaction*/
2290 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2291 if (ret != SQLITE_OK) {
2292 _LOGD("Failed to commit transaction. Rollback now\n");
2293 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2297 _LOGD("Transaction Commit and End\n");
2299 pkgmgr_parser_close_db();
2303 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2305 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, GLOBAL_USER);
2308 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2310 if (pkgid == NULL || tep_path == NULL) {
2311 _LOGE("invalid parameter");
2318 ret = pkgmgr_parser_check_and_create_db(uid);
2320 _LOGD("Failed to open DB\n");
2323 ret = pkgmgr_parser_initialize_db(uid);
2327 /*Begin transaction*/
2328 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2329 if (ret != SQLITE_OK) {
2330 _LOGD("Failed to begin transaction\n");
2334 _LOGD("Transaction Begin\n");
2337 /* Updating TEP info in "package_info" table */
2338 query = sqlite3_mprintf("UPDATE package_info "\
2339 "SET package_tep_name = %Q "\
2340 "WHERE package = %Q", tep_path, pkgid);
2342 ret = __exec_query(query);
2343 sqlite3_free(query);
2344 if (ret != SQLITE_OK) {
2345 ret = PM_PARSER_R_ERROR;
2346 _LOGE("sqlite exec failed to insert entries into package_info!!");
2350 /* Updating TEP info in "package_app_info" table */
2351 query = sqlite3_mprintf("UPDATE package_app_info "\
2352 "SET app_tep_name = %Q "\
2353 "WHERE package = %Q", tep_path, pkgid);
2355 ret = __exec_query(query);
2356 sqlite3_free(query);
2357 if (ret != SQLITE_OK) {
2358 ret = PM_PARSER_R_ERROR;
2359 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2363 /*Commit transaction*/
2364 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2365 if (ret != SQLITE_OK) {
2366 _LOGE("Failed to commit transaction, Rollback now\n");
2367 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2368 if (ret != SQLITE_OK)
2369 _LOGE("Failed to Rollback\n");
2371 ret = PM_PARSER_R_ERROR;
2374 _LOGD("Transaction Commit and End\n");
2375 ret = PM_PARSER_R_OK;
2378 pkgmgr_parser_close_db();
2383 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2386 _LOGD("manifest pointer is NULL\n");
2390 ret = pkgmgr_parser_check_and_create_db(uid);
2392 _LOGD("Failed to open DB\n");
2395 ret = pkgmgr_parser_initialize_db(uid);
2398 /*Preserve guest mode visibility*/
2399 __preserve_guestmode_visibility_value( mfx);
2400 /*Begin transaction*/
2401 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2402 if (ret != SQLITE_OK) {
2403 _LOGD("Failed to begin transaction\n");
2407 _LOGD("Transaction Begin\n");
2408 ret = __delete_manifest_info_from_db(mfx, uid);
2410 _LOGD("Delete from DB failed. Rollback now\n");
2411 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2414 ret = __insert_manifest_info_in_db(mfx, uid);
2416 _LOGD("Insert into DB failed. Rollback now\n");
2417 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2421 /*Commit transaction*/
2422 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2423 if (ret != SQLITE_OK) {
2424 _LOGD("Failed to commit transaction. Rollback now\n");
2425 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2429 _LOGD("Transaction Commit and End\n");
2431 pkgmgr_parser_close_db();
2435 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2437 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2440 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2443 _LOGD("manifest pointer is NULL\n");
2447 ret = pkgmgr_parser_check_and_create_db(uid);
2449 _LOGD("Failed to open DB\n");
2452 /*Begin transaction*/
2453 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2454 if (ret != SQLITE_OK) {
2455 _LOGD("Failed to begin transaction\n");
2459 _LOGD("Transaction Begin\n");
2460 ret = __delete_manifest_info_from_db(mfx, uid);
2462 _LOGD("Delete from DB failed. Rollback now\n");
2463 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2466 /*Commit transaction*/
2467 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2468 if (ret != SQLITE_OK) {
2469 _LOGD("Failed to commit transaction, Rollback now\n");
2470 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2474 _LOGD("Transaction Commit and End\n");
2476 pkgmgr_parser_close_db();
2480 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2482 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2485 API int pkgmgr_parser_update_preload_info_in_db()
2488 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2490 _LOGD("Failed to open DB\n");
2493 /*Begin transaction*/
2494 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2495 if (ret != SQLITE_OK) {
2496 _LOGD("Failed to begin transaction\n");
2500 _LOGD("Transaction Begin\n");
2501 ret = __update_preload_condition_in_db();
2503 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2504 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2507 /*Commit transaction*/
2508 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2509 if (ret != SQLITE_OK) {
2510 _LOGD("Failed to commit transaction, Rollback now\n");
2511 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2515 _LOGD("Transaction Commit and End\n");
2517 pkgmgr_parser_close_db();
2521 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2524 ret = pkgmgr_parser_check_and_create_db(uid);
2526 _LOGD("Failed to open DB\n");
2529 /*Begin transaction*/
2530 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2531 if (ret != SQLITE_OK) {
2532 _LOGD("Failed to begin transaction\n");
2536 _LOGD("Transaction Begin\n");
2537 ret = __update_preload_condition_in_db();
2539 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2540 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2543 /*Commit transaction*/
2544 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2545 if (ret != SQLITE_OK) {
2546 _LOGD("Failed to commit transaction, Rollback now\n");
2547 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2551 _LOGD("Transaction Commit and End\n");
2553 pkgmgr_parser_close_db();
2557 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2561 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2563 _LOGD("Failed to open DB\n");
2567 /*Begin transaction*/
2568 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2569 if (ret != SQLITE_OK) {
2570 _LOGD("Failed to begin transaction\n");
2574 _LOGD("Transaction Begin\n");
2576 ret = __disable_global_app_for_user(appid, uid);
2578 ret = __enable_global_app_for_user(appid, uid);
2580 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2581 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2584 /*Commit transaction*/
2585 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2586 if (ret != SQLITE_OK) {
2587 _LOGD("Failed to commit transaction, Rollback now\n");
2588 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2592 _LOGD("Transaction Commit and End\n");
2594 pkgmgr_parser_close_db();
2599 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2601 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, GLOBAL_USER, is_disable);
2604 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2608 ret = pkgmgr_parser_check_and_create_db(uid);
2610 _LOGD("Failed to open DB\n");
2614 /*Begin transaction*/
2615 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2616 if (ret != SQLITE_OK) {
2617 _LOGD("Failed to begin transaction\n");
2621 _LOGD("Transaction Begin\n");
2623 ret = __disable_app(appid);
2625 ret = __enable_app(appid);
2627 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2628 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2631 /*Commit transaction*/
2632 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2633 if (ret != SQLITE_OK) {
2634 _LOGD("Failed to commit transaction, Rollback now\n");
2635 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2639 _LOGD("Transaction Commit and End\n");
2641 pkgmgr_parser_close_db();