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 'rpm', " \
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 static int __insert_application_info(manifest_x *mfx);
328 static int __insert_application_appcategory_info(manifest_x *mfx);
329 static int __insert_application_appcontrol_info(manifest_x *mfx);
330 static int __insert_application_appmetadata_info(manifest_x *mfx);
331 static int __insert_application_share_allowed_info(manifest_x *mfx);
332 static int __insert_application_share_request_info(manifest_x *mfx);
333 static int __insert_application_datacontrol_info(manifest_x *mfx);
334 static void __insert_application_locale_info(gpointer data, gpointer userdata);
335 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
336 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
337 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
338 static int __delete_subpkg_info_from_db(char *appid);
339 static int __delete_appinfo_from_db(char *db_table, const char *appid);
340 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
341 static int __exec_query(char *query);
342 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
343 char **label, char **license, char **icon, char **description, char **author);
344 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
345 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
346 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
347 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
348 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
349 static int __parserdb_change_perm(const char *db_file, uid_t uid);
351 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
354 __delete_subpkg_info_from_db(coltxt[0]);
359 static const char *__get_str(const char *str)
363 return PKGMGR_PARSER_EMPTY_STR;
369 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
374 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
375 if (ret != SQLITE_OK) {
376 _LOGD("connect db [%s] failed!\n", db_path);
384 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
386 manifest_x *mfx = (manifest_x *)data;
392 if (mfx->application == NULL)
394 app = (application_x *)mfx->application->data;
395 for(i = 0; i < ncols; i++)
397 if (strcmp(colname[i], "app_id") == 0) {
399 appid = strdup(coltxt[i]);
400 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
402 status = strdup(coltxt[i]);
408 _LOGD("app id is NULL\n");
411 /*update guest mode visibility*/
412 for (tmp = mfx->application; tmp; tmp = tmp->next) {
413 app = (application_x *)tmp->data;
416 if (strcmp(app->appid, appid) == 0) {
417 free((void *)app->guestmode_visibility);
418 app->guestmode_visibility = strdup(status);
434 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
436 char *error_message = NULL;
437 char query[MAX_QUERY_LEN] = {'\0'};
438 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
440 sqlite3_exec(pkgmgr_parser_db, query,
441 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
442 _LOGD("Don't execute query = %s error message = %s\n",
443 query, error_message);
444 sqlite3_free(error_message);
449 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
451 char *error_message = NULL;
453 sqlite3_exec(db_handle, db_query,
454 NULL, NULL, &error_message)) {
455 _LOGD("Don't execute query = %s error message = %s\n",
456 db_query, error_message);
457 sqlite3_free(error_message);
460 sqlite3_free(error_message);
464 static int __exec_query(char *query)
466 char *error_message = NULL;
468 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
469 _LOGE("Don't execute query = %s error message = %s\n", query,
471 sqlite3_free(error_message);
474 sqlite3_free(error_message);
478 static int __exec_query_no_msg(char *query)
480 char *error_message = NULL;
482 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
483 sqlite3_free(error_message);
486 sqlite3_free(error_message);
490 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
498 for (tmp = lbls; tmp; tmp = tmp->next) {
499 lbl = (label_x *)tmp->data;
503 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
505 for (tmp = lcns; tmp; tmp = tmp->next) {
506 lcn = (license_x *)tmp->data;
510 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
512 for (tmp = icns; tmp; tmp = tmp->next) {
513 icn = (icon_x *)tmp->data;
517 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
519 for (tmp = dcns; tmp; tmp = tmp->next) {
520 dcn = (description_x *)tmp->data;
524 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
526 for (tmp = aths; tmp; tmp = tmp->next) {
527 ath = (author_x *)tmp->data;
531 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
537 static GList *__create_icon_list(GList *appicon, GList *icns)
542 for (tmp = icns; tmp; tmp = tmp->next) {
543 icn = (icon_x *)tmp->data;
547 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
552 static GList *__create_image_list(GList *appimage, GList *imgs)
557 for (tmp = imgs; tmp; tmp = tmp->next) {
558 img = (image_x *)tmp->data;
562 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
567 static void __trimfunc(GList* trim_list)
569 char *trim_data = NULL;
573 list = g_list_first(trim_list);
576 trim_data = (char *)list->data;
579 if (strcmp(trim_data, prev) == 0) {
580 trim_list = g_list_remove(trim_list, trim_data);
581 list = g_list_first(trim_list);
590 list = g_list_next(list);
594 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
596 if (a == NULL || b == NULL)
598 if (strcmp((char*)a, (char*)b) == 0)
600 if (strcmp((char*)a, (char*)b) < 0)
602 if (strcmp((char*)a, (char*)b) > 0)
607 static int __check_dpi(const char *dpi_char, int dpi_int)
609 if (dpi_char == NULL)
612 if (strcasecmp(dpi_char, LDPI) == 0) {
613 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
617 } else if (strcasecmp(dpi_char, MDPI) == 0) {
618 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
622 } else if (strcasecmp(dpi_char, HDPI) == 0) {
623 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
627 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
628 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
632 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
633 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
641 static gint __compare_icon(gconstpointer a, gconstpointer b)
643 icon_x *icon = (icon_x *)a;
645 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
648 if (icon->dpi != NULL)
654 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
656 icon_x *icon = (icon_x *)a;
657 int dpi = GPOINTER_TO_INT(b);
659 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
662 if (icon->dpi == NULL)
665 if (__check_dpi(icon->dpi, dpi) == 0)
671 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
673 icon_x *icon = (icon_x *)a;
674 char *lang = (char *)b;
676 if (icon->dpi != NULL)
679 if (strcasecmp(icon->lang, lang) == 0)
685 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
687 icon_x *icon = (icon_x *)a;
688 char *lang = (char *)b;
691 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
695 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
701 static char *__find_icon(GList *icons, const char *lang)
707 // first, find icon whose locale and dpi with given lang and system's dpi has matched
708 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
710 icon = (icon_x *)tmp->data;
711 return (char *)icon->text;
714 // if first has failed, find icon whose locale has matched
715 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
717 icon = (icon_x *)tmp->data;
718 return (char *)icon->text;
721 // if second has failed, find icon whose dpi has matched with system's dpi
722 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
725 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
727 icon = (icon_x *)tmp->data;
728 return (char *)icon->text;
731 // last, find default icon marked as "No Locale"
732 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
734 icon = (icon_x *)tmp->data;
735 return (char *)icon->text;
741 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
742 char **label, char **license, char **icon, char **description, char **author)
749 for (tmp = lbls; tmp; tmp = tmp->next) {
750 lbl = (label_x *)tmp->data;
754 if (strcmp(lbl->lang, (char *)data) == 0) {
755 *label = (char*)lbl->text;
760 for (tmp = lcns; tmp; tmp = tmp->next) {
761 lcn = (license_x *)tmp->data;
765 if (strcmp(lcn->lang, (char *)data) == 0) {
766 *license = (char*)lcn->text;
772 *icon = __find_icon(icns, (char *)data);
774 for (tmp = dcns; tmp; tmp = tmp->next) {
775 dcn = (description_x *)tmp->data;
779 if (strcmp(dcn->lang, (char *)data) == 0) {
780 *description = (char*)dcn->text;
785 for (tmp = aths; tmp; tmp = tmp->next) {
786 ath = (author_x *)tmp->data;
790 if (strcmp(ath->lang, (char *)data) == 0) {
791 *author = (char*)ath->text;
799 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
803 for (tmp = icns; tmp; tmp = tmp->next) {
804 icn = (icon_x *)tmp->data;
808 if (strcmp(icn->section, (char *)data) == 0) {
809 *icon = (char*)icn->text;
810 *resolution = (char*)icn->resolution;
817 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
821 for (tmp = imgs; tmp; tmp = tmp->next) {
822 img = (image_x *)tmp->data;
826 if (strcmp(img->section, (char *)data) == 0) {
827 *lang = (char*)img->lang;
828 *image = (char*)img->text;
835 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
840 char *description = NULL;
841 char *license = NULL;
845 manifest_x *mfx = (manifest_x *)userdata;
846 GList *lbl = mfx->label;
847 GList *lcn = mfx->license;
848 GList *icn = mfx->icon;
849 GList *dcn = mfx->description;
850 GList *ath = mfx->author;
852 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
853 if (!label && !description && !icon && !license && !author)
856 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
857 "package_label, package_icon, package_description, package_license, package_author) values " \
858 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
863 __get_str(description),
867 ret = __exec_query(query);
869 _LOGD("Package Localized Info DB Insert failed\n");
874 static void __insert_application_locale_info(gpointer data, gpointer userdata)
881 application_x *app = (application_x*)userdata;
882 GList *lbl = app->label;
883 GList *icn = app->icon;
885 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
889 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
890 "app_label, app_icon) values " \
891 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
892 __get_str(label), __get_str(icon));
893 ret = __exec_query(query);
895 _LOGD("Package UiApp Localized Info DB Insert failed\n");
899 /*insert ui app locale info to pkg locale to get mainapp data */
900 if (strcasecmp(app->mainapp, "true")==0) {
901 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
902 "package_label, package_icon, package_description, package_license, package_author) values " \
903 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
908 PKGMGR_PARSER_EMPTY_STR,
909 PKGMGR_PARSER_EMPTY_STR,
910 PKGMGR_PARSER_EMPTY_STR);
912 ret = __exec_query_no_msg(query);
916 query = sqlite3_mprintf("update package_localized_info set package_icon=%Q "\
917 "where package=%Q and package_locale=%Q", icon, app->package, (char*)data);
918 ret = __exec_query_no_msg(query);
924 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
928 char *resolution = NULL;
929 char query[MAX_QUERY_LEN] = {'\0'};
931 application_x *app = (application_x*)userdata;
932 GList *icn = app->icon;
934 __extract_icon_data(data, icn, &icon, &resolution);
935 if (!icon && !resolution)
937 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
938 "app_icon, app_icon_section, app_icon_resolution) values " \
939 "('%q', '%q', '%q', '%q')", app->appid,
940 icon, (char*)data, resolution);
942 ret = __exec_query(query);
944 _LOGD("Package UiApp Localized Info DB Insert failed\n");
948 static void __insert_application_image_info(gpointer data, gpointer userdata)
953 char query[MAX_QUERY_LEN] = {'\0'};
955 application_x *app = (application_x*)userdata;
956 GList *image = app->image;
958 __extract_image_data(data, image, &lang, &img);
961 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
962 "app_image_section, app_image) values " \
963 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
965 ret = __exec_query(query);
967 _LOGD("Package UiApp image Info DB Insert failed\n");
972 static int __insert_mainapp_info(manifest_x *mfx)
977 char query[MAX_QUERY_LEN] = {'\0'};
978 for (tmp = mfx->application; tmp; tmp = tmp->next) {
979 app = (application_x *)tmp->data;
982 snprintf(query, MAX_QUERY_LEN,
983 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
985 ret = __exec_query(query);
987 _LOGD("Package App Info DB Insert Failed\n");
990 if (strcasecmp(app->mainapp, "True")==0)
991 mfx->mainapp_id = strdup(app->appid);
994 if (mfx->mainapp_id == NULL) {
995 if (mfx->application == NULL)
997 app = (application_x *)mfx->application->data;
1001 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
1003 _LOGD("Not valid appid\n");
1007 ret = __exec_query(query);
1009 _LOGD("Package UiApp Info DB Insert Failed\n");
1013 free((void *)app->mainapp);
1014 app->mainapp= strdup("true");
1015 mfx->mainapp_id = strdup(app->appid);
1018 memset(query, '\0', MAX_QUERY_LEN);
1019 snprintf(query, MAX_QUERY_LEN,
1020 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
1021 ret = __exec_query(query);
1023 _LOGD("Package Info DB update Failed\n");
1030 static int __convert_background_category(GList *category_list)
1033 GList *tmp_list = category_list;
1034 char *category_data = NULL;
1036 if (category_list == NULL)
1039 while (tmp_list != NULL) {
1040 category_data = (char *)tmp_list->data;
1041 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1042 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1043 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1044 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1045 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1046 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1047 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1048 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1049 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1050 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1051 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1052 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1053 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1054 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1056 _LOGE("Unidentified category [%s]", category_data);
1058 tmp_list = g_list_next(tmp_list);
1064 /* _PRODUCT_LAUNCHING_ENHANCED_
1065 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1067 static int __insert_application_info(manifest_x *mfx)
1072 int background_value = 0;
1073 char query[MAX_QUERY_LEN] = {'\0'};
1077 type = strdup(mfx->type);
1079 type = strdup("tpk");
1081 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1082 app = (application_x *)tmp->data;
1086 background_value = __convert_background_category(app->background_category);
1087 if (background_value < 0) {
1088 _LOGE("Failed to retrieve background value[%d]", background_value);
1089 background_value = 0;
1092 snprintf(query, MAX_QUERY_LEN,
1093 "insert into package_app_info(" \
1094 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1095 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1096 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1097 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1098 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1099 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1100 "app_tep_name, app_background_category, app_package_type) " \
1102 "'%s', '%s', '%s', '%s', '%s', " \
1103 "'%s', '%s', '%s', '%s', '%s', " \
1104 "'%s', '%s', '%s', '%s', '%s', " \
1105 "'%s', '%s', '%s', '%s', '%s', " \
1106 "'%s', '%s', '%s', '%s', '%s', " \
1107 "'%s', '%s', '%s', '%s', '%s', " \
1108 "'%s', '%d', '%s')", \
1109 app->appid, app->component_type, app->exec, app->nodisplay, app->type,
1110 app->onboot, app->multiple, app->autorestart, app->taskmanage, app->enabled,
1111 app->hwacceleration, app->screenreader, app->mainapp, __get_str(app->recentimage), app->launchcondition,
1112 app->indicatordisplay, __get_str(app->portraitimg), __get_str(app->landscapeimg),
1113 app->guestmode_visibility, app->permission_type,
1114 mfx->preload, app->submode, __get_str(app->submode_mainid), mfx->installed_storage, app->process_pool,
1115 app->launch_mode, app->ui_gadget, mfx->support_disable, app->component_type, mfx->package,
1116 __get_str(mfx->tep_name), background_value, type);
1118 ret = __exec_query(query);
1120 _LOGD("Package UiApp Info DB Insert Failed\n");
1125 memset(query, '\0', MAX_QUERY_LEN);
1134 static int __insert_application_appcategory_info(manifest_x *mfx)
1141 char query[MAX_QUERY_LEN] = {'\0'};
1142 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1143 app = (application_x *)app_tmp->data;
1146 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1147 ct = (const char *)ct_tmp->data;
1150 snprintf(query, MAX_QUERY_LEN,
1151 "insert into package_app_app_category(app_id, category) " \
1152 "values('%s','%s')",\
1154 ret = __exec_query(query);
1156 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1159 memset(query, '\0', MAX_QUERY_LEN);
1165 static int __insert_application_appmetadata_info(manifest_x *mfx)
1172 char query[MAX_QUERY_LEN] = {'\0'};
1173 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1174 app = (application_x *)app_tmp->data;
1177 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1178 md = (metadata_x *)md_tmp->data;
1182 snprintf(query, MAX_QUERY_LEN,
1183 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1184 "values('%s','%s', '%s')",\
1185 app->appid, md->key, md->value ? md->value : "");
1186 ret = __exec_query(query);
1188 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1192 memset(query, '\0', MAX_QUERY_LEN);
1198 static int __insert_application_apppermission_info(manifest_x *mfx)
1205 char query[MAX_QUERY_LEN] = {'\0'};
1206 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1207 app = (application_x *)app_tmp->data;
1210 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1211 pm = (permission_x *)pm_tmp->data;
1214 snprintf(query, MAX_QUERY_LEN,
1215 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1216 "values('%s','%s', '%s')",\
1217 app->appid, pm->type, pm->value);
1218 ret = __exec_query(query);
1220 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1223 memset(query, '\0', MAX_QUERY_LEN);
1229 static int __insert_application_appcontrol_info(manifest_x *mfx)
1233 GList *acontrol_tmp;
1234 appcontrol_x *acontrol;
1236 char query[MAX_QUERY_LEN] = {'\0'};
1237 char buf[BUFSIZE] = {'\0'};
1238 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1239 app = (application_x *)app_tmp->data;
1242 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1243 acontrol = (appcontrol_x *)acontrol_tmp->data;
1244 if (acontrol == NULL)
1246 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1247 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1248 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1249 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1250 snprintf(query, MAX_QUERY_LEN,
1251 "insert into package_app_app_control(app_id, app_control) " \
1252 "values('%s', '%s')",\
1254 ret = __exec_query(query);
1256 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1259 memset(query, '\0', MAX_QUERY_LEN);
1265 static int __insert_application_datacontrol_info(manifest_x *mfx)
1272 char query[MAX_QUERY_LEN] = {'\0'};
1274 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1275 app = (application_x *)app_tmp->data;
1278 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1279 dc = (datacontrol_x *)dc_tmp->data;
1282 snprintf(query, MAX_QUERY_LEN,
1283 "insert into package_app_data_control(app_id, providerid, access, type) " \
1284 "values('%s', '%s', '%s', '%s')",\
1290 ret = __exec_query(query);
1292 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1295 memset(query, '\0', MAX_QUERY_LEN);
1301 static int __insert_application_share_request_info(manifest_x *mfx)
1310 char query[MAX_QUERY_LEN] = {'\0'};
1311 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1312 app = (application_x *)app_tmp->data;
1315 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1316 ds = (datashare_x *)ds_tmp->data;
1319 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1320 rq = (const char *)rq_tmp->data;
1323 snprintf(query, MAX_QUERY_LEN,
1324 "insert into package_app_share_request(app_id, data_share_request) " \
1325 "values('%s', '%s')",\
1327 ret = __exec_query(query);
1329 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1332 memset(query, '\0', MAX_QUERY_LEN);
1339 static int __insert_application_share_allowed_info(manifest_x *mfx)
1350 char query[MAX_QUERY_LEN] = {'\0'};
1351 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1352 app = (application_x *)app_tmp->data;
1355 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1356 ds = (datashare_x *)ds_tmp->data;
1359 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1360 df = (define_x *)df_tmp->data;
1363 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1364 al = (const char *)al_tmp->data;
1367 snprintf(query, MAX_QUERY_LEN,
1368 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1369 "values('%s', '%s', '%s')",\
1370 app->appid, df->path, al);
1371 ret = __exec_query(query);
1373 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1376 memset(query, '\0', MAX_QUERY_LEN);
1384 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1388 const char *pv = NULL;
1389 char query[MAX_QUERY_LEN] = { '\0' };
1392 const char *auth_name = NULL;
1393 const char *auth_email = NULL;
1394 const char *auth_href = NULL;
1396 GList *pkglocale = NULL;
1397 GList *applocale = NULL;
1398 GList *appicon = NULL;
1399 GList *appimage = NULL;
1401 if (mfx->author && mfx->author->data) {
1402 author = (author_x *)mfx->author->data;
1404 auth_name = author->text;
1406 auth_email = author->email;
1408 auth_href = author->href;
1410 /*Insert in the package_cert_info CERT_DB*/
1411 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1412 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1413 if (ret != PMINFO_R_OK) {
1414 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1415 _LOGE("Cert Info DB create handle failed\n");
1418 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1419 if (ret != PMINFO_R_OK) {
1420 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1421 _LOGE("Cert Info DB Insert Failed\n");
1425 /*Insert in the package_info DB*/
1426 snprintf(query, MAX_QUERY_LEN,
1427 "insert into package_info(" \
1428 "package, package_type, package_version, package_api_version, package_tep_name, " \
1429 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1430 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1431 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1432 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1434 "'%s', '%s', '%s', '%s', '%s', " \
1435 "'%s', '%s', '%s', '%s', '%s', " \
1436 "'%s', '%s', '%s', '%s', '%s', " \
1437 "'%s', '%s', '%s', '%s', '%s', " \
1438 "'%s', '%s', '%s', '%s', '%s')", \
1439 mfx->package, mfx->type, mfx->version, __get_str(mfx->api_version), __get_str(mfx->tep_name),
1440 __get_str(mfx->installlocation), __get_str(mfx->package_size), mfx->removable, mfx->preload, mfx->readonly,
1441 mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system, __get_str(auth_name),
1442 __get_str(auth_email), __get_str(auth_href), mfx->installed_time, mfx->installed_storage,
1443 __get_str(mfx->storeclient_id),
1444 mfx->mainapp_id, __get_str(mfx->package_url), mfx->root_path, __get_str(mfx->csc_path), mfx->support_disable);
1446 ret = __exec_query(query);
1448 _LOGD("Package Info DB Insert Failed\n");
1452 /*Insert in the package_privilege_info DB*/
1453 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1454 pv = (const char *)tmp->data;
1457 memset(query, '\0', MAX_QUERY_LEN);
1458 snprintf(query, MAX_QUERY_LEN,
1459 "insert into package_privilege_info(package, privilege) " \
1460 "values('%s','%s')",\
1462 ret = __exec_query(query);
1464 _LOGD("Package Privilege Info DB Insert Failed\n");
1469 if (mfx->application != NULL) {
1470 ret = __insert_mainapp_info(mfx);
1475 /*Insert the package locale*/
1476 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1477 /*remove duplicated data in pkglocale*/
1478 __trimfunc(pkglocale);
1480 /*Insert the app locale, icon, image info */
1481 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1482 app = (application_x *)tmp->data;
1485 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1486 appicon = __create_icon_list(appicon, app->icon);
1487 appimage = __create_image_list(appimage, app->image);
1489 /*remove duplicated data in applocale*/
1490 __trimfunc(applocale);
1491 __trimfunc(appicon);
1492 __trimfunc(appimage);
1494 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1496 /*native app locale info*/
1497 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1498 app = (application_x *)tmp->data;
1501 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1502 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1503 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1506 g_list_free(pkglocale);
1508 g_list_free(applocale);
1510 g_list_free(appicon);
1512 g_list_free(appimage);
1515 /*Insert in the package_app_info DB*/
1516 ret = __insert_application_info(mfx);
1519 /*Insert in the package_app_app_control DB*/
1520 ret = __insert_application_appcontrol_info(mfx);
1524 /*Insert in the package_app_app_category DB*/
1525 ret = __insert_application_appcategory_info(mfx);
1529 /*Insert in the package_app_app_metadata DB*/
1530 ret = __insert_application_appmetadata_info(mfx);
1534 /*Insert in the package_app_app_permission DB*/
1535 ret = __insert_application_apppermission_info(mfx);
1539 /*Insert in the package_app_share_allowed DB*/
1540 ret = __insert_application_share_allowed_info(mfx);
1544 /*Insert in the package_app_share_request DB*/
1545 ret = __insert_application_share_request_info(mfx);
1549 /*Insert in the package_app_data_control DB*/
1550 ret = __insert_application_datacontrol_info(mfx);
1558 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1560 char query[MAX_QUERY_LEN] = { '\0' };
1562 memset(query, '\0', MAX_QUERY_LEN);
1563 snprintf(query, MAX_QUERY_LEN,
1564 "delete from %s where app_id='%s'", db_table, appid);
1565 ret = __exec_query(query);
1567 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1573 static int __delete_subpkg_info_from_db(char *appid)
1577 ret = __delete_appinfo_from_db("package_app_info", appid);
1580 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1583 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1586 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1589 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1592 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1595 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1598 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1601 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1604 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1607 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1614 static int __delete_subpkg_from_db(manifest_x *mfx)
1616 char query[MAX_QUERY_LEN] = { '\0' };
1617 char *error_message = NULL;
1619 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1621 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1622 _LOGE("Don't execute query = %s error message = %s\n", query,
1624 sqlite3_free(error_message);
1627 sqlite3_free(error_message);
1632 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1634 char query[MAX_QUERY_LEN] = { '\0' };
1638 /*Delete from cert table*/
1639 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1641 _LOGD("Cert Info DB Delete Failed\n");
1645 /*Delete from Package Info DB*/
1646 snprintf(query, MAX_QUERY_LEN,
1647 "delete from package_info where package='%s'", mfx->package);
1648 ret = __exec_query(query);
1650 _LOGD("Package Info DB Delete Failed\n");
1653 memset(query, '\0', MAX_QUERY_LEN);
1655 /*Delete from Package Localized Info*/
1656 snprintf(query, MAX_QUERY_LEN,
1657 "delete from package_localized_info where package='%s'", mfx->package);
1658 ret = __exec_query(query);
1660 _LOGD("Package Localized Info DB Delete Failed\n");
1664 /*Delete from Package Privilege Info*/
1665 snprintf(query, MAX_QUERY_LEN,
1666 "delete from package_privilege_info where package='%s'", mfx->package);
1667 ret = __exec_query(query);
1669 _LOGD("Package Privilege Info DB Delete Failed\n");
1673 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1674 app = (application_x *)tmp->data;
1677 ret = __delete_appinfo_from_db("package_app_info", app->appid);
1680 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
1683 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
1686 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
1689 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
1692 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
1695 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
1698 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
1701 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
1704 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
1707 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
1712 /* if main package has sub pkg, delete sub pkg data*/
1713 __delete_subpkg_from_db(mfx);
1718 static int __disable_app(const char *appid)
1721 char query[MAX_QUERY_LEN] = {'\0'};
1722 sqlite3_snprintf(MAX_QUERY_LEN, query,
1723 "UPDATE package_app_info set app_disable='true' where app_id=%Q",
1725 ret = __exec_query(query);
1727 _LOGD("Insert global app disable failed\n");
1732 static int __enable_app(const char *appid)
1735 char query[MAX_QUERY_LEN] = {'\0'};
1736 sqlite3_snprintf(MAX_QUERY_LEN, query,
1737 "UPDATE package_app_info set app_disable='false' where app_id=%Q",
1739 ret = __exec_query(query);
1741 _LOGD("Insert global app disable failed\n");
1746 static int __disable_global_app_for_user(const char *appid, uid_t uid)
1749 char query[MAX_QUERY_LEN] = {'\0'};
1751 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO " \
1752 "package_app_disable_for_user(app_id, uid) VALUES(%Q, '%d')",
1754 ret = __exec_query(query);
1756 _LOGD("Insert global app disable failed\n");
1761 static int __enable_global_app_for_user(const char *appid, uid_t uid)
1764 char query[MAX_QUERY_LEN] = {'\0'};
1766 sqlite3_snprintf(MAX_QUERY_LEN, query, "DELETE FROM " \
1767 "package_app_disable_for_user WHERE app_id=%Q AND uid='%d'",
1769 ret = __exec_query(query);
1771 _LOGD("Delete global app disable failed\n");
1776 static int __update_preload_condition_in_db()
1779 char query[MAX_QUERY_LEN] = {'\0'};
1781 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
1783 ret = __exec_query(query);
1785 _LOGD("Package preload_condition update failed\n");
1790 API int pkgmgr_parser_initialize_db(uid_t uid)
1794 char query[MAX_QUERY_LEN];
1795 static const char *columns[] = {
1796 "author_root_cert", "author_im_cert", "author_signer_cert",
1797 "dist_root_cert", "dist_im_cert", "dist_signer_cert",
1798 "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
1802 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
1804 _LOGD("package info DB initialization failed\n");
1807 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
1809 _LOGD("package localized info DB initialization failed\n");
1812 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
1814 _LOGD("package app app privilege DB initialization failed\n");
1817 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
1819 _LOGD("package app info DB initialization failed\n");
1822 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
1824 _LOGD("package app localized info DB initialization failed\n");
1827 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
1829 _LOGD("package app icon localized info DB initialization failed\n");
1832 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
1834 _LOGD("package app image info DB initialization failed\n");
1837 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
1839 _LOGD("package app app control DB initialization failed\n");
1842 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
1844 _LOGD("package app app category DB initialization failed\n");
1847 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
1849 _LOGD("package app app category DB initialization failed\n");
1852 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
1854 _LOGD("package app app permission DB initialization failed\n");
1857 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
1859 _LOGD("package app share allowed DB initialization failed\n");
1862 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
1864 _LOGD("package app share request DB initialization failed\n");
1867 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
1869 _LOGD("package app data control DB initialization failed\n");
1873 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER);
1875 _LOGD("package app disable for user DB initialization failed\n");
1880 /* TODO: refactor this code */
1881 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
1883 _LOGD("package cert info DB initialization failed\n");
1886 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
1888 _LOGD("package cert index info DB initialization failed\n");
1891 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
1893 _LOGD("package cert info DB initialization failed\n");
1896 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
1898 _LOGD("package cert index info DB initialization failed\n");
1901 for (i = 0; columns[i] != NULL; i++) {
1902 snprintf(query, sizeof(query),
1903 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
1904 columns[i], columns[i], columns[i]);
1905 ret = __initialize_db(pkgmgr_cert_db, query);
1907 _LOGD("package cert index info DB initialization failed\n");
1912 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
1913 _LOGD("Failed to change cert db permission\n");
1915 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
1916 _LOGD("Failed to change parser db permission\n");
1922 static int __parserdb_change_perm(const char *db_file, uid_t uid)
1925 char journal_file[BUFSIZE];
1928 struct passwd *userinfo = NULL;
1929 files[0] = (char *)db_file;
1930 files[1] = journal_file;
1934 if (db_file == NULL)
1937 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
1939 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
1940 if (uid == OWNER_ROOT)
1942 userinfo = getpwuid(uid);
1944 _LOGE("FAIL: user %d doesn't exist", uid);
1947 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
1949 for (i = 0; files[i]; i++) {
1950 ret = chown(files[i], uid, userinfo->pw_gid);
1952 if (strerror_r(errno, buf, sizeof(buf)))
1954 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
1955 userinfo->pw_gid, buf);
1959 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
1960 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
1962 ret = chmod(files[i], mode);
1964 if (strerror_r(errno, buf, sizeof(buf)))
1966 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
1969 SET_SMACK_LABEL(files[i]);
1974 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
1978 if (getuid() != OWNER_ROOT) {
1979 _LOGE("Only root user is allowed");
1983 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
1984 _LOGE("Manifest db for user %d is already exists", uid);
1988 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
1989 _LOGE("Cert db for user %d is already exists", uid);
1993 ret = pkgmgr_parser_check_and_create_db(uid);
1996 ret = pkgmgr_parser_initialize_db(uid);
1998 pkgmgr_parser_close_db();
2001 pkgmgr_parser_close_db();
2006 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2010 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2012 _LOGD("Manifest DB creation Failed\n");
2017 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2019 _LOGD("Cert DB creation Failed\n");
2025 void pkgmgr_parser_close_db(void)
2027 sqlite3_close(pkgmgr_parser_db);
2028 sqlite3_close(pkgmgr_cert_db);
2032 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2034 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2036 _LOGD("manifest pointer is NULL\n");
2040 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2042 _LOGD("Failed to open DB\n");
2045 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2048 /*Begin transaction*/
2049 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2050 if (ret != SQLITE_OK) {
2051 _LOGD("Failed to begin transaction\n");
2055 _LOGD("Transaction Begin\n");
2056 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2058 _LOGD("Insert into DB failed. Rollback now\n");
2059 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2062 /*Commit transaction*/
2063 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2064 if (ret != SQLITE_OK) {
2065 _LOGD("Failed to commit transaction. Rollback now\n");
2066 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2070 _LOGD("Transaction Commit and End\n");
2072 pkgmgr_parser_close_db();
2076 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2078 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2080 _LOGD("manifest pointer is NULL\n");
2084 ret = pkgmgr_parser_check_and_create_db(uid);
2086 _LOGD("Failed to open DB\n");
2089 ret = pkgmgr_parser_initialize_db(uid);
2092 /*Begin transaction*/
2093 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2094 if (ret != SQLITE_OK) {
2095 _LOGD("Failed to begin transaction\n");
2099 _LOGD("Transaction Begin\n");
2100 ret = __insert_manifest_info_in_db(mfx, uid);
2102 _LOGD("Insert into DB failed. Rollback now\n");
2103 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2106 /*Commit transaction*/
2107 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2108 if (ret != SQLITE_OK) {
2109 _LOGD("Failed to commit transaction. Rollback now\n");
2110 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2114 _LOGD("Transaction Commit and End\n");
2116 pkgmgr_parser_close_db();
2120 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2122 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, GLOBAL_USER);
2125 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2127 if (pkgid == NULL || tep_path == NULL) {
2128 _LOGE("invalid parameter");
2135 ret = pkgmgr_parser_check_and_create_db(uid);
2137 _LOGD("Failed to open DB\n");
2140 ret = pkgmgr_parser_initialize_db(uid);
2144 /*Begin transaction*/
2145 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2146 if (ret != SQLITE_OK) {
2147 _LOGD("Failed to begin transaction\n");
2151 _LOGD("Transaction Begin\n");
2154 /* Updating TEP info in "package_info" table */
2155 query = sqlite3_mprintf("UPDATE package_info "\
2156 "SET package_tep_name = %Q "\
2157 "WHERE package = %Q", tep_path, pkgid);
2159 ret = __exec_query(query);
2160 sqlite3_free(query);
2161 if (ret != SQLITE_OK) {
2162 ret = PM_PARSER_R_ERROR;
2163 _LOGE("sqlite exec failed to insert entries into package_info!!");
2167 /* Updating TEP info in "package_app_info" table */
2168 query = sqlite3_mprintf("UPDATE package_app_info "\
2169 "SET app_tep_name = %Q "\
2170 "WHERE package = %Q", tep_path, pkgid);
2172 ret = __exec_query(query);
2173 sqlite3_free(query);
2174 if (ret != SQLITE_OK) {
2175 ret = PM_PARSER_R_ERROR;
2176 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2180 /*Commit transaction*/
2181 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2182 if (ret != SQLITE_OK) {
2183 _LOGE("Failed to commit transaction, Rollback now\n");
2184 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2185 if (ret != SQLITE_OK)
2186 _LOGE("Failed to Rollback\n");
2188 ret = PM_PARSER_R_ERROR;
2191 _LOGD("Transaction Commit and End\n");
2192 ret = PM_PARSER_R_OK;
2195 pkgmgr_parser_close_db();
2200 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2203 _LOGD("manifest pointer is NULL\n");
2207 ret = pkgmgr_parser_check_and_create_db(uid);
2209 _LOGD("Failed to open DB\n");
2212 ret = pkgmgr_parser_initialize_db(uid);
2215 /*Preserve guest mode visibility*/
2216 __preserve_guestmode_visibility_value( mfx);
2217 /*Begin transaction*/
2218 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2219 if (ret != SQLITE_OK) {
2220 _LOGD("Failed to begin transaction\n");
2224 _LOGD("Transaction Begin\n");
2225 ret = __delete_manifest_info_from_db(mfx, uid);
2227 _LOGD("Delete from DB failed. Rollback now\n");
2228 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2231 ret = __insert_manifest_info_in_db(mfx, uid);
2233 _LOGD("Insert into DB failed. Rollback now\n");
2234 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2238 /*Commit transaction*/
2239 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2240 if (ret != SQLITE_OK) {
2241 _LOGD("Failed to commit transaction. Rollback now\n");
2242 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2246 _LOGD("Transaction Commit and End\n");
2248 pkgmgr_parser_close_db();
2252 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2254 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2257 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2260 _LOGD("manifest pointer is NULL\n");
2264 ret = pkgmgr_parser_check_and_create_db(uid);
2266 _LOGD("Failed to open DB\n");
2269 /*Begin transaction*/
2270 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2271 if (ret != SQLITE_OK) {
2272 _LOGD("Failed to begin transaction\n");
2276 _LOGD("Transaction Begin\n");
2277 ret = __delete_manifest_info_from_db(mfx, uid);
2279 _LOGD("Delete from DB failed. Rollback now\n");
2280 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2283 /*Commit transaction*/
2284 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2285 if (ret != SQLITE_OK) {
2286 _LOGD("Failed to commit transaction, Rollback now\n");
2287 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2291 _LOGD("Transaction Commit and End\n");
2293 pkgmgr_parser_close_db();
2297 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2299 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2302 API int pkgmgr_parser_update_preload_info_in_db()
2305 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2307 _LOGD("Failed to open DB\n");
2310 /*Begin transaction*/
2311 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2312 if (ret != SQLITE_OK) {
2313 _LOGD("Failed to begin transaction\n");
2317 _LOGD("Transaction Begin\n");
2318 ret = __update_preload_condition_in_db();
2320 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2321 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2324 /*Commit transaction*/
2325 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2326 if (ret != SQLITE_OK) {
2327 _LOGD("Failed to commit transaction, Rollback now\n");
2328 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2332 _LOGD("Transaction Commit and End\n");
2334 pkgmgr_parser_close_db();
2338 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2341 ret = pkgmgr_parser_check_and_create_db(uid);
2343 _LOGD("Failed to open DB\n");
2346 /*Begin transaction*/
2347 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2348 if (ret != SQLITE_OK) {
2349 _LOGD("Failed to begin transaction\n");
2353 _LOGD("Transaction Begin\n");
2354 ret = __update_preload_condition_in_db();
2356 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2357 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2360 /*Commit transaction*/
2361 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2362 if (ret != SQLITE_OK) {
2363 _LOGD("Failed to commit transaction, Rollback now\n");
2364 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2368 _LOGD("Transaction Commit and End\n");
2370 pkgmgr_parser_close_db();
2374 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2378 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2380 _LOGD("Failed to open DB\n");
2384 /*Begin transaction*/
2385 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2386 if (ret != SQLITE_OK) {
2387 _LOGD("Failed to begin transaction\n");
2391 _LOGD("Transaction Begin\n");
2393 ret = __disable_global_app_for_user(appid, uid);
2395 ret = __enable_global_app_for_user(appid, uid);
2397 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2398 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2401 /*Commit transaction*/
2402 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2403 if (ret != SQLITE_OK) {
2404 _LOGD("Failed to commit transaction, Rollback now\n");
2405 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2409 _LOGD("Transaction Commit and End\n");
2411 pkgmgr_parser_close_db();
2416 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2418 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, GLOBAL_USER, is_disable);
2421 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2425 ret = pkgmgr_parser_check_and_create_db(uid);
2427 _LOGD("Failed to open DB\n");
2431 /*Begin transaction*/
2432 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2433 if (ret != SQLITE_OK) {
2434 _LOGD("Failed to begin transaction\n");
2438 _LOGD("Transaction Begin\n");
2440 ret = __disable_app(appid);
2442 ret = __enable_app(appid);
2444 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2445 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2448 /*Commit transaction*/
2449 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2450 if (ret != SQLITE_OK) {
2451 _LOGD("Failed to commit transaction, Rollback now\n");
2452 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2456 _LOGD("Transaction Commit and End\n");
2458 pkgmgr_parser_close_db();