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 __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
656 char *icon_filename = NULL;
657 char modified_iconpath[BUFSIZE] = { '\0' };
658 char icon_path[BUFSIZE] = { '\0' };
662 if (orig_icon_path == NULL)
665 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
669 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
670 dpi_path[0] = "LDPI";
671 dpi_path[1] = "ldpi";
672 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
673 dpi_path[0] = "MDPI";
674 dpi_path[1] = "mdpi";
675 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
676 dpi_path[0] = "HDPI";
677 dpi_path[1] = "hdpi";
678 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
679 dpi_path[0] = "XHDPI";
680 dpi_path[1] = "xhdpi";
681 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
682 dpi_path[0] = "XXHDPI";
683 dpi_path[1] = "xxhdpi";
685 _LOGE("Unidentified dpi[%d]", dpi);
689 icon_filename = strrchr(orig_icon_path, '/');
690 if (icon_filename == NULL)
693 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), orig_icon_path);
694 for (i = 0; i < 2; i++) {
695 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
696 if (access(modified_iconpath, F_OK) != -1) {
697 // if exists, return modified icon path
698 *new_icon_path = strdup(modified_iconpath);
706 static gint __compare_icon(gconstpointer a, gconstpointer b)
708 icon_x *icon = (icon_x *)a;
710 char *icon_folder_path = NULL;
712 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
715 if (icon->dpi != NULL)
718 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
720 icon->text = icon_folder_path;
726 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
728 icon_x *icon = (icon_x *)a;
729 int dpi = GPOINTER_TO_INT(b);
731 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
734 if (icon->dpi == NULL)
737 if (__check_dpi(icon->dpi, dpi) == 0)
743 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
745 icon_x *icon = (icon_x *)a;
746 char *lang = (char *)b;
747 char *icon_folder_path = NULL;
749 if (icon->dpi != NULL)
752 if (strcasecmp(icon->lang, lang) == 0) {
753 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
754 //icon for no locale. check existance of folder-hierachied default icons
755 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
757 icon->text = icon_folder_path;
766 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
768 icon_x *icon = (icon_x *)a;
769 char *lang = (char *)b;
772 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
776 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
782 static char *__find_icon(GList *icons, const char *lang)
788 // first, find icon whose locale and dpi with given lang and system's dpi has matched
789 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
791 icon = (icon_x *)tmp->data;
792 return (char *)icon->text;
795 // if first has failed, find icon whose locale has matched
796 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
798 icon = (icon_x *)tmp->data;
799 return (char *)icon->text;
802 // if second has failed, find icon whose dpi has matched with system's dpi
803 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
806 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
808 icon = (icon_x *)tmp->data;
809 return (char *)icon->text;
812 // last, find default icon marked as "No Locale"
813 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
815 icon = (icon_x *)tmp->data;
816 return (char *)icon->text;
822 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
823 char **label, char **license, char **icon, char **description, char **author)
830 for (tmp = lbls; tmp; tmp = tmp->next) {
831 lbl = (label_x *)tmp->data;
835 if (strcmp(lbl->lang, (char *)data) == 0) {
836 *label = (char*)lbl->text;
841 for (tmp = lcns; tmp; tmp = tmp->next) {
842 lcn = (license_x *)tmp->data;
846 if (strcmp(lcn->lang, (char *)data) == 0) {
847 *license = (char*)lcn->text;
853 *icon = __find_icon(icns, (char *)data);
855 for (tmp = dcns; tmp; tmp = tmp->next) {
856 dcn = (description_x *)tmp->data;
860 if (strcmp(dcn->lang, (char *)data) == 0) {
861 *description = (char*)dcn->text;
866 for (tmp = aths; tmp; tmp = tmp->next) {
867 ath = (author_x *)tmp->data;
871 if (strcmp(ath->lang, (char *)data) == 0) {
872 *author = (char*)ath->text;
880 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
884 for (tmp = icns; tmp; tmp = tmp->next) {
885 icn = (icon_x *)tmp->data;
889 if (strcmp(icn->section, (char *)data) == 0) {
890 *icon = (char*)icn->text;
891 *resolution = (char*)icn->resolution;
898 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
902 for (tmp = imgs; tmp; tmp = tmp->next) {
903 img = (image_x *)tmp->data;
907 if (strcmp(img->section, (char *)data) == 0) {
908 *lang = (char*)img->lang;
909 *image = (char*)img->text;
916 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
921 char *description = NULL;
922 char *license = NULL;
926 manifest_x *mfx = (manifest_x *)userdata;
927 GList *lbl = mfx->label;
928 GList *lcn = mfx->license;
929 GList *icn = mfx->icon;
930 GList *dcn = mfx->description;
931 GList *ath = mfx->author;
933 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
934 if (!label && !description && !icon && !license && !author)
937 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
938 "package_label, package_icon, package_description, package_license, package_author) values " \
939 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
944 __get_str(description),
948 ret = __exec_query(query);
950 _LOGD("Package Localized Info DB Insert failed\n");
955 static void __insert_application_locale_info(gpointer data, gpointer userdata)
962 application_x *app = (application_x*)userdata;
963 GList *lbl = app->label;
964 GList *icn = app->icon;
966 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
970 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
971 "app_label, app_icon) values " \
972 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
973 __get_str(label), __get_str(icon));
974 ret = __exec_query(query);
976 _LOGD("Package UiApp Localized Info DB Insert failed\n");
980 /*insert ui app locale info to pkg locale to get mainapp data */
981 if (strcasecmp(app->mainapp, "true")==0) {
982 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
983 "package_label, package_icon, package_description, package_license, package_author) values " \
984 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
989 PKGMGR_PARSER_EMPTY_STR,
990 PKGMGR_PARSER_EMPTY_STR,
991 PKGMGR_PARSER_EMPTY_STR);
993 ret = __exec_query_no_msg(query);
997 query = sqlite3_mprintf("update package_localized_info set package_icon=%Q "\
998 "where package=%Q and package_locale=%Q", icon, app->package, (char*)data);
999 ret = __exec_query_no_msg(query);
1000 sqlite3_free(query);
1005 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1009 char *resolution = NULL;
1010 char query[MAX_QUERY_LEN] = {'\0'};
1012 application_x *app = (application_x*)userdata;
1013 GList *icn = app->icon;
1015 __extract_icon_data(data, icn, &icon, &resolution);
1016 if (!icon && !resolution)
1018 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
1019 "app_icon, app_icon_section, app_icon_resolution) values " \
1020 "('%q', '%q', '%q', '%q')", app->appid,
1021 icon, (char*)data, resolution);
1023 ret = __exec_query(query);
1025 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1029 static void __insert_application_image_info(gpointer data, gpointer userdata)
1034 char query[MAX_QUERY_LEN] = {'\0'};
1036 application_x *app = (application_x*)userdata;
1037 GList *image = app->image;
1039 __extract_image_data(data, image, &lang, &img);
1042 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
1043 "app_image_section, app_image) values " \
1044 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
1046 ret = __exec_query(query);
1048 _LOGD("Package UiApp image Info DB Insert failed\n");
1053 static int __insert_mainapp_info(manifest_x *mfx)
1058 char query[MAX_QUERY_LEN] = {'\0'};
1059 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1060 app = (application_x *)tmp->data;
1063 snprintf(query, MAX_QUERY_LEN,
1064 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
1066 ret = __exec_query(query);
1068 _LOGD("Package App Info DB Insert Failed\n");
1071 if (strcasecmp(app->mainapp, "True")==0)
1072 mfx->mainapp_id = strdup(app->appid);
1075 if (mfx->mainapp_id == NULL) {
1076 if (mfx->application == NULL)
1078 app = (application_x *)mfx->application->data;
1082 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
1084 _LOGD("Not valid appid\n");
1088 ret = __exec_query(query);
1090 _LOGD("Package UiApp Info DB Insert Failed\n");
1094 free((void *)app->mainapp);
1095 app->mainapp= strdup("true");
1096 mfx->mainapp_id = strdup(app->appid);
1099 memset(query, '\0', MAX_QUERY_LEN);
1100 snprintf(query, MAX_QUERY_LEN,
1101 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
1102 ret = __exec_query(query);
1104 _LOGD("Package Info DB update Failed\n");
1111 static int __convert_background_category(GList *category_list)
1114 GList *tmp_list = category_list;
1115 char *category_data = NULL;
1117 if (category_list == NULL)
1120 while (tmp_list != NULL) {
1121 category_data = (char *)tmp_list->data;
1122 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1123 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1124 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1125 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1126 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1127 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1128 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1129 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1130 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1131 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1132 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1133 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1134 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1135 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1137 _LOGE("Unidentified category [%s]", category_data);
1139 tmp_list = g_list_next(tmp_list);
1145 /* _PRODUCT_LAUNCHING_ENHANCED_
1146 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1148 static int __insert_application_info(manifest_x *mfx)
1153 int background_value = 0;
1154 char query[MAX_QUERY_LEN] = {'\0'};
1158 type = strdup(mfx->type);
1160 type = strdup("tpk");
1162 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1163 app = (application_x *)tmp->data;
1167 background_value = __convert_background_category(app->background_category);
1168 if (background_value < 0) {
1169 _LOGE("Failed to retrieve background value[%d]", background_value);
1170 background_value = 0;
1173 snprintf(query, MAX_QUERY_LEN,
1174 "insert into package_app_info(" \
1175 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1176 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1177 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1178 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1179 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1180 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1181 "app_tep_name, app_background_category, app_package_type) " \
1183 "'%s', '%s', '%s', '%s', '%s', " \
1184 "'%s', '%s', '%s', '%s', '%s', " \
1185 "'%s', '%s', '%s', '%s', '%s', " \
1186 "'%s', '%s', '%s', '%s', '%s', " \
1187 "'%s', '%s', '%s', '%s', '%s', " \
1188 "'%s', '%s', '%s', '%s', '%s', " \
1189 "'%s', '%d', '%s')", \
1190 app->appid, app->component_type, app->exec, app->nodisplay, app->type,
1191 app->onboot, app->multiple, app->autorestart, app->taskmanage, app->enabled,
1192 app->hwacceleration, app->screenreader, app->mainapp, __get_str(app->recentimage), app->launchcondition,
1193 app->indicatordisplay, __get_str(app->portraitimg), __get_str(app->landscapeimg),
1194 app->guestmode_visibility, app->permission_type,
1195 mfx->preload, app->submode, __get_str(app->submode_mainid), mfx->installed_storage, app->process_pool,
1196 app->launch_mode, app->ui_gadget, mfx->support_disable, app->component_type, mfx->package,
1197 __get_str(mfx->tep_name), background_value, type);
1199 ret = __exec_query(query);
1201 _LOGD("Package UiApp Info DB Insert Failed\n");
1206 memset(query, '\0', MAX_QUERY_LEN);
1215 static int __insert_application_appcategory_info(manifest_x *mfx)
1222 char query[MAX_QUERY_LEN] = {'\0'};
1223 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1224 app = (application_x *)app_tmp->data;
1227 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1228 ct = (const char *)ct_tmp->data;
1231 snprintf(query, MAX_QUERY_LEN,
1232 "insert into package_app_app_category(app_id, category) " \
1233 "values('%s','%s')",\
1235 ret = __exec_query(query);
1237 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1240 memset(query, '\0', MAX_QUERY_LEN);
1246 static int __insert_application_appmetadata_info(manifest_x *mfx)
1253 char query[MAX_QUERY_LEN] = {'\0'};
1254 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1255 app = (application_x *)app_tmp->data;
1258 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1259 md = (metadata_x *)md_tmp->data;
1263 snprintf(query, MAX_QUERY_LEN,
1264 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1265 "values('%s','%s', '%s')",\
1266 app->appid, md->key, md->value ? md->value : "");
1267 ret = __exec_query(query);
1269 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1273 memset(query, '\0', MAX_QUERY_LEN);
1279 static int __insert_application_apppermission_info(manifest_x *mfx)
1286 char query[MAX_QUERY_LEN] = {'\0'};
1287 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1288 app = (application_x *)app_tmp->data;
1291 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1292 pm = (permission_x *)pm_tmp->data;
1295 snprintf(query, MAX_QUERY_LEN,
1296 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1297 "values('%s','%s', '%s')",\
1298 app->appid, pm->type, pm->value);
1299 ret = __exec_query(query);
1301 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1304 memset(query, '\0', MAX_QUERY_LEN);
1310 static int __insert_application_appcontrol_info(manifest_x *mfx)
1314 GList *acontrol_tmp;
1315 appcontrol_x *acontrol;
1317 char query[MAX_QUERY_LEN] = {'\0'};
1318 char buf[BUFSIZE] = {'\0'};
1319 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1320 app = (application_x *)app_tmp->data;
1323 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1324 acontrol = (appcontrol_x *)acontrol_tmp->data;
1325 if (acontrol == NULL)
1327 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1328 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1329 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1330 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1331 snprintf(query, MAX_QUERY_LEN,
1332 "insert into package_app_app_control(app_id, app_control) " \
1333 "values('%s', '%s')",\
1335 ret = __exec_query(query);
1337 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1340 memset(query, '\0', MAX_QUERY_LEN);
1346 static int __insert_application_datacontrol_info(manifest_x *mfx)
1353 char query[MAX_QUERY_LEN] = {'\0'};
1355 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1356 app = (application_x *)app_tmp->data;
1359 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1360 dc = (datacontrol_x *)dc_tmp->data;
1363 snprintf(query, MAX_QUERY_LEN,
1364 "insert into package_app_data_control(app_id, providerid, access, type) " \
1365 "values('%s', '%s', '%s', '%s')",\
1371 ret = __exec_query(query);
1373 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1376 memset(query, '\0', MAX_QUERY_LEN);
1382 static int __insert_application_share_request_info(manifest_x *mfx)
1391 char query[MAX_QUERY_LEN] = {'\0'};
1392 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1393 app = (application_x *)app_tmp->data;
1396 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1397 ds = (datashare_x *)ds_tmp->data;
1400 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1401 rq = (const char *)rq_tmp->data;
1404 snprintf(query, MAX_QUERY_LEN,
1405 "insert into package_app_share_request(app_id, data_share_request) " \
1406 "values('%s', '%s')",\
1408 ret = __exec_query(query);
1410 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1413 memset(query, '\0', MAX_QUERY_LEN);
1420 static int __insert_application_share_allowed_info(manifest_x *mfx)
1431 char query[MAX_QUERY_LEN] = {'\0'};
1432 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1433 app = (application_x *)app_tmp->data;
1436 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1437 ds = (datashare_x *)ds_tmp->data;
1440 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1441 df = (define_x *)df_tmp->data;
1444 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1445 al = (const char *)al_tmp->data;
1448 snprintf(query, MAX_QUERY_LEN,
1449 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1450 "values('%s', '%s', '%s')",\
1451 app->appid, df->path, al);
1452 ret = __exec_query(query);
1454 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1457 memset(query, '\0', MAX_QUERY_LEN);
1465 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1467 splashscreen_x *ss = (splashscreen_x *)a;
1468 const char *orientation = (const char *)b;
1471 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1475 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1481 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1483 splashscreen_x *ss = (splashscreen_x *)a;
1484 const char *orientation = (const char *)b;
1486 if (strcasecmp(ss->orientation, orientation) == 0 && (ss->dpi == NULL))
1492 static splashscreen_x *__find_splashscreen(GList *splashscreens, const char *orientation)
1496 tmp = g_list_find_custom(splashscreens, orientation,
1497 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1499 return (splashscreen_x *)tmp->data;
1501 tmp = g_list_find_custom(splashscreens, orientation,
1502 (GCompareFunc)__compare_splashscreen_with_orientation);
1504 return (splashscreen_x *)tmp->data;
1509 static int __insert_application_splashscreen_info(manifest_x *mfx)
1515 char query[MAX_QUERY_LEN];
1517 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1518 app = (application_x *)app_tmp->data;
1519 if (app == NULL || app->splashscreens == NULL)
1522 ss = __find_splashscreen(app->splashscreens, "portrait");
1524 snprintf(query, sizeof(query),
1525 "insert into package_app_splash_screen" \
1526 "(app_id, src, type, orientation, indicatordisplay) " \
1527 "values('%s', '%s', '%s', '%s', '%s')",
1528 app->appid, ss->src, ss->type, ss->orientation,
1529 ss->indicatordisplay);
1530 ret = __exec_query(query);
1532 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1535 memset(query, '\0', MAX_QUERY_LEN);
1537 ss = __find_splashscreen(app->splashscreens, "landscape");
1539 snprintf(query, sizeof(query),
1540 "insert into package_app_splash_screen" \
1541 "(app_id, src, type, orientation, indicatordisplay) " \
1542 "values('%s', '%s', '%s', '%s', '%s')",
1543 app->appid, ss->src, ss->type, ss->orientation,
1544 ss->indicatordisplay);
1545 ret = __exec_query(query);
1547 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1550 memset(query, '\0', MAX_QUERY_LEN);
1556 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1561 char query[MAX_QUERY_LEN];
1563 const char *image_type;
1564 const char *indicatordisplay;
1565 const char *orientation;
1567 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1568 app = (application_x *)app_tmp->data;
1570 (app->portraitimg == NULL && app->landscapeimg == NULL))
1572 image_type = "img"; /* default */
1573 if (app->effectimage_type) {
1574 tmp = strstr(app->effectimage_type, "edj");
1578 indicatordisplay = "true"; /* default */
1579 if (app->indicatordisplay)
1580 indicatordisplay = app->indicatordisplay;
1581 if (app->portraitimg) {
1582 orientation = "portrait";
1583 snprintf(query, sizeof(query),
1584 "insert into package_app_splash_screen" \
1585 "(app_id, src, type, orientation, indicatordisplay) " \
1586 "values('%s', '%s', '%s', '%s', '%s')",
1587 app->appid, app->portraitimg, image_type,
1588 orientation, indicatordisplay);
1589 ret = __exec_query(query);
1591 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1594 memset(query, '\0', MAX_QUERY_LEN);
1595 } else if (app->landscapeimg) {
1596 orientation = "landscape";
1597 snprintf(query, sizeof(query),
1598 "insert into package_app_splash_screen" \
1599 "(app_id, src, type, orientation, indicatordisplay) " \
1600 "values('%s', '%s', '%s', '%s', '%s')",
1601 app->appid, app->landscapeimg, image_type,
1602 orientation, indicatordisplay);
1603 ret = __exec_query(query);
1605 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1608 memset(query, '\0', MAX_QUERY_LEN);
1614 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1618 const char *pv = NULL;
1619 char query[MAX_QUERY_LEN] = { '\0' };
1622 const char *auth_name = NULL;
1623 const char *auth_email = NULL;
1624 const char *auth_href = NULL;
1626 GList *pkglocale = NULL;
1627 GList *applocale = NULL;
1628 GList *appicon = NULL;
1629 GList *appimage = NULL;
1631 if (mfx->author && mfx->author->data) {
1632 author = (author_x *)mfx->author->data;
1634 auth_name = author->text;
1636 auth_email = author->email;
1638 auth_href = author->href;
1640 /*Insert in the package_cert_info CERT_DB*/
1641 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1642 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1643 if (ret != PMINFO_R_OK) {
1644 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1645 _LOGE("Cert Info DB create handle failed\n");
1648 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1649 if (ret != PMINFO_R_OK) {
1650 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1651 _LOGE("Cert Info DB Insert Failed\n");
1655 /*Insert in the package_info DB*/
1656 snprintf(query, MAX_QUERY_LEN,
1657 "insert into package_info(" \
1658 "package, package_type, package_version, package_api_version, package_tep_name, " \
1659 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1660 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1661 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1662 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1664 "'%s', '%s', '%s', '%s', '%s', " \
1665 "'%s', '%s', '%s', '%s', '%s', " \
1666 "'%s', '%s', '%s', '%s', '%s', " \
1667 "'%s', '%s', '%s', '%s', '%s', " \
1668 "'%s', '%s', '%s', '%s', '%s')", \
1669 mfx->package, mfx->type, mfx->version, __get_str(mfx->api_version), __get_str(mfx->tep_name),
1670 __get_str(mfx->installlocation), __get_str(mfx->package_size), mfx->removable, mfx->preload, mfx->readonly,
1671 mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system, __get_str(auth_name),
1672 __get_str(auth_email), __get_str(auth_href), mfx->installed_time, mfx->installed_storage,
1673 __get_str(mfx->storeclient_id),
1674 mfx->mainapp_id, __get_str(mfx->package_url), mfx->root_path, __get_str(mfx->csc_path), mfx->support_disable);
1676 ret = __exec_query(query);
1678 _LOGD("Package Info DB Insert Failed\n");
1682 /*Insert in the package_privilege_info DB*/
1683 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1684 pv = (const char *)tmp->data;
1687 memset(query, '\0', MAX_QUERY_LEN);
1688 snprintf(query, MAX_QUERY_LEN,
1689 "insert into package_privilege_info(package, privilege) " \
1690 "values('%s','%s')",\
1692 ret = __exec_query(query);
1694 _LOGD("Package Privilege Info DB Insert Failed\n");
1699 if (mfx->application != NULL) {
1700 ret = __insert_mainapp_info(mfx);
1705 /*Insert the package locale*/
1706 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1707 /*remove duplicated data in pkglocale*/
1708 __trimfunc(pkglocale);
1710 /*Insert the app locale, icon, image info */
1711 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1712 app = (application_x *)tmp->data;
1715 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1716 appicon = __create_icon_list(appicon, app->icon);
1717 appimage = __create_image_list(appimage, app->image);
1719 /*remove duplicated data in applocale*/
1720 __trimfunc(applocale);
1721 __trimfunc(appicon);
1722 __trimfunc(appimage);
1724 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1726 /*native app locale info*/
1727 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1728 app = (application_x *)tmp->data;
1731 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1732 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1733 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1736 g_list_free(pkglocale);
1738 g_list_free(applocale);
1740 g_list_free(appicon);
1742 g_list_free(appimage);
1745 /*Insert in the package_app_info DB*/
1746 ret = __insert_application_info(mfx);
1749 /*Insert in the package_app_app_control DB*/
1750 ret = __insert_application_appcontrol_info(mfx);
1754 /*Insert in the package_app_app_category DB*/
1755 ret = __insert_application_appcategory_info(mfx);
1759 /*Insert in the package_app_app_metadata DB*/
1760 ret = __insert_application_appmetadata_info(mfx);
1764 /*Insert in the package_app_app_permission DB*/
1765 ret = __insert_application_apppermission_info(mfx);
1769 /*Insert in the package_app_share_allowed DB*/
1770 ret = __insert_application_share_allowed_info(mfx);
1774 /*Insert in the package_app_share_request DB*/
1775 ret = __insert_application_share_request_info(mfx);
1779 /*Insert in the package_app_data_control DB*/
1780 ret = __insert_application_datacontrol_info(mfx);
1784 /*Insert in the package_app_splash_screen DB*/
1785 ret = __insert_application_legacy_splashscreen_info(mfx);
1789 /*Insert in the package_app_splash_screen DB*/
1790 ret = __insert_application_splashscreen_info(mfx);
1798 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1800 char query[MAX_QUERY_LEN] = { '\0' };
1802 memset(query, '\0', MAX_QUERY_LEN);
1803 snprintf(query, MAX_QUERY_LEN,
1804 "delete from %s where app_id='%s'", db_table, appid);
1805 ret = __exec_query(query);
1807 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1813 static int __delete_subpkg_info_from_db(char *appid)
1817 ret = __delete_appinfo_from_db("package_app_info", appid);
1820 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1823 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1826 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1829 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1832 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1835 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1838 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1841 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1844 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1847 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1850 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
1857 static int __delete_subpkg_from_db(manifest_x *mfx)
1859 char query[MAX_QUERY_LEN] = { '\0' };
1860 char *error_message = NULL;
1862 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1864 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1865 _LOGE("Don't execute query = %s error message = %s\n", query,
1867 sqlite3_free(error_message);
1870 sqlite3_free(error_message);
1875 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1877 char query[MAX_QUERY_LEN] = { '\0' };
1881 /*Delete from cert table*/
1882 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1884 _LOGD("Cert Info DB Delete Failed\n");
1888 /*Delete from Package Info DB*/
1889 snprintf(query, MAX_QUERY_LEN,
1890 "delete from package_info where package='%s'", mfx->package);
1891 ret = __exec_query(query);
1893 _LOGD("Package Info DB Delete Failed\n");
1896 memset(query, '\0', MAX_QUERY_LEN);
1898 /*Delete from Package Localized Info*/
1899 snprintf(query, MAX_QUERY_LEN,
1900 "delete from package_localized_info where package='%s'", mfx->package);
1901 ret = __exec_query(query);
1903 _LOGD("Package Localized Info DB Delete Failed\n");
1907 /*Delete from Package Privilege Info*/
1908 snprintf(query, MAX_QUERY_LEN,
1909 "delete from package_privilege_info where package='%s'", mfx->package);
1910 ret = __exec_query(query);
1912 _LOGD("Package Privilege Info DB Delete Failed\n");
1916 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1917 app = (application_x *)tmp->data;
1920 ret = __delete_appinfo_from_db("package_app_info", app->appid);
1923 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
1926 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
1929 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
1932 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
1935 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
1938 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
1941 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
1944 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
1947 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
1950 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
1953 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
1958 /* if main package has sub pkg, delete sub pkg data*/
1959 __delete_subpkg_from_db(mfx);
1964 static int __disable_app(const char *appid)
1967 char query[MAX_QUERY_LEN] = {'\0'};
1968 sqlite3_snprintf(MAX_QUERY_LEN, query,
1969 "UPDATE package_app_info set app_disable='true' where app_id=%Q",
1971 ret = __exec_query(query);
1973 _LOGD("Insert global app disable failed\n");
1978 static int __enable_app(const char *appid)
1981 char query[MAX_QUERY_LEN] = {'\0'};
1982 sqlite3_snprintf(MAX_QUERY_LEN, query,
1983 "UPDATE package_app_info set app_disable='false' where app_id=%Q",
1985 ret = __exec_query(query);
1987 _LOGD("Insert global app disable failed\n");
1992 static int __disable_global_app_for_user(const char *appid, uid_t uid)
1995 char query[MAX_QUERY_LEN] = {'\0'};
1997 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO " \
1998 "package_app_disable_for_user(app_id, uid) VALUES(%Q, '%d')",
2000 ret = __exec_query(query);
2002 _LOGD("Insert global app disable failed\n");
2007 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2010 char query[MAX_QUERY_LEN] = {'\0'};
2012 sqlite3_snprintf(MAX_QUERY_LEN, query, "DELETE FROM " \
2013 "package_app_disable_for_user WHERE app_id=%Q AND uid='%d'",
2015 ret = __exec_query(query);
2017 _LOGD("Delete global app disable failed\n");
2022 static int __update_preload_condition_in_db()
2025 char query[MAX_QUERY_LEN] = {'\0'};
2027 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2029 ret = __exec_query(query);
2031 _LOGD("Package preload_condition update failed\n");
2036 API int pkgmgr_parser_initialize_db(uid_t uid)
2040 char query[MAX_QUERY_LEN];
2041 static const char *columns[] = {
2042 "author_root_cert", "author_im_cert", "author_signer_cert",
2043 "dist_root_cert", "dist_im_cert", "dist_signer_cert",
2044 "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
2048 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2050 _LOGD("package info DB initialization failed\n");
2053 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2055 _LOGD("package localized info DB initialization failed\n");
2058 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2060 _LOGD("package app app privilege DB initialization failed\n");
2063 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2065 _LOGD("package app info DB initialization failed\n");
2068 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2070 _LOGD("package app localized info DB initialization failed\n");
2073 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2075 _LOGD("package app icon localized info DB initialization failed\n");
2078 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2080 _LOGD("package app image info DB initialization failed\n");
2083 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2085 _LOGD("package app app control DB initialization failed\n");
2088 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2090 _LOGD("package app app category DB initialization failed\n");
2093 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2095 _LOGD("package app app category DB initialization failed\n");
2098 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2100 _LOGD("package app app permission DB initialization failed\n");
2103 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2105 _LOGD("package app share allowed DB initialization failed\n");
2108 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2110 _LOGD("package app share request DB initialization failed\n");
2113 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2115 _LOGD("package app data control DB initialization failed\n");
2119 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER);
2121 _LOGD("package app disable for user DB initialization failed\n");
2125 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2127 _LOGD("package app splash screen DB initialization failed\n");
2132 /* TODO: refactor this code */
2133 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2135 _LOGD("package cert info DB initialization failed\n");
2138 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2140 _LOGD("package cert index info DB initialization failed\n");
2143 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2145 _LOGD("package cert info DB initialization failed\n");
2148 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2150 _LOGD("package cert index info DB initialization failed\n");
2153 for (i = 0; columns[i] != NULL; i++) {
2154 snprintf(query, sizeof(query),
2155 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
2156 columns[i], columns[i], columns[i]);
2157 ret = __initialize_db(pkgmgr_cert_db, query);
2159 _LOGD("package cert index info DB initialization failed\n");
2164 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
2165 _LOGD("Failed to change cert db permission\n");
2167 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2168 _LOGD("Failed to change parser db permission\n");
2174 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2177 char journal_file[BUFSIZE];
2180 struct passwd *userinfo = NULL;
2181 files[0] = (char *)db_file;
2182 files[1] = journal_file;
2186 if (db_file == NULL)
2189 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2191 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2192 if (uid == OWNER_ROOT)
2194 userinfo = getpwuid(uid);
2196 _LOGE("FAIL: user %d doesn't exist", uid);
2199 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2201 for (i = 0; files[i]; i++) {
2202 ret = chown(files[i], uid, userinfo->pw_gid);
2204 if (strerror_r(errno, buf, sizeof(buf)))
2206 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2207 userinfo->pw_gid, buf);
2211 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2212 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2214 ret = chmod(files[i], mode);
2216 if (strerror_r(errno, buf, sizeof(buf)))
2218 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2221 SET_SMACK_LABEL(files[i]);
2226 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2230 if (getuid() != OWNER_ROOT) {
2231 _LOGE("Only root user is allowed");
2235 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2236 _LOGE("Manifest db for user %d is already exists", uid);
2240 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2241 _LOGE("Cert db for user %d is already exists", uid);
2245 ret = pkgmgr_parser_check_and_create_db(uid);
2248 ret = pkgmgr_parser_initialize_db(uid);
2250 pkgmgr_parser_close_db();
2253 pkgmgr_parser_close_db();
2258 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2262 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2264 _LOGD("Manifest DB creation Failed\n");
2269 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2271 _LOGD("Cert DB creation Failed\n");
2277 void pkgmgr_parser_close_db(void)
2279 sqlite3_close(pkgmgr_parser_db);
2280 sqlite3_close(pkgmgr_cert_db);
2284 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2286 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2288 _LOGD("manifest pointer is NULL\n");
2292 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2294 _LOGD("Failed to open DB\n");
2297 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2300 /*Begin transaction*/
2301 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2302 if (ret != SQLITE_OK) {
2303 _LOGD("Failed to begin transaction\n");
2307 _LOGD("Transaction Begin\n");
2308 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2310 _LOGD("Insert into DB failed. Rollback now\n");
2311 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2314 /*Commit transaction*/
2315 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2316 if (ret != SQLITE_OK) {
2317 _LOGD("Failed to commit transaction. Rollback now\n");
2318 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2322 _LOGD("Transaction Commit and End\n");
2324 pkgmgr_parser_close_db();
2328 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2330 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2332 _LOGD("manifest pointer is NULL\n");
2336 ret = pkgmgr_parser_check_and_create_db(uid);
2338 _LOGD("Failed to open DB\n");
2341 ret = pkgmgr_parser_initialize_db(uid);
2344 /*Begin transaction*/
2345 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2346 if (ret != SQLITE_OK) {
2347 _LOGD("Failed to begin transaction\n");
2351 _LOGD("Transaction Begin\n");
2352 ret = __insert_manifest_info_in_db(mfx, uid);
2354 _LOGD("Insert into DB failed. Rollback now\n");
2355 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2358 /*Commit transaction*/
2359 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2360 if (ret != SQLITE_OK) {
2361 _LOGD("Failed to commit transaction. Rollback now\n");
2362 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2366 _LOGD("Transaction Commit and End\n");
2368 pkgmgr_parser_close_db();
2372 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2374 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, GLOBAL_USER);
2377 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2379 if (pkgid == NULL || tep_path == NULL) {
2380 _LOGE("invalid parameter");
2387 ret = pkgmgr_parser_check_and_create_db(uid);
2389 _LOGD("Failed to open DB\n");
2392 ret = pkgmgr_parser_initialize_db(uid);
2396 /*Begin transaction*/
2397 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2398 if (ret != SQLITE_OK) {
2399 _LOGD("Failed to begin transaction\n");
2403 _LOGD("Transaction Begin\n");
2406 /* Updating TEP info in "package_info" table */
2407 query = sqlite3_mprintf("UPDATE package_info "\
2408 "SET package_tep_name = %Q "\
2409 "WHERE package = %Q", tep_path, pkgid);
2411 ret = __exec_query(query);
2412 sqlite3_free(query);
2413 if (ret != SQLITE_OK) {
2414 ret = PM_PARSER_R_ERROR;
2415 _LOGE("sqlite exec failed to insert entries into package_info!!");
2419 /* Updating TEP info in "package_app_info" table */
2420 query = sqlite3_mprintf("UPDATE package_app_info "\
2421 "SET app_tep_name = %Q "\
2422 "WHERE package = %Q", tep_path, pkgid);
2424 ret = __exec_query(query);
2425 sqlite3_free(query);
2426 if (ret != SQLITE_OK) {
2427 ret = PM_PARSER_R_ERROR;
2428 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2432 /*Commit transaction*/
2433 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2434 if (ret != SQLITE_OK) {
2435 _LOGE("Failed to commit transaction, Rollback now\n");
2436 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2437 if (ret != SQLITE_OK)
2438 _LOGE("Failed to Rollback\n");
2440 ret = PM_PARSER_R_ERROR;
2443 _LOGD("Transaction Commit and End\n");
2444 ret = PM_PARSER_R_OK;
2447 pkgmgr_parser_close_db();
2452 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2455 _LOGD("manifest pointer is NULL\n");
2459 ret = pkgmgr_parser_check_and_create_db(uid);
2461 _LOGD("Failed to open DB\n");
2464 ret = pkgmgr_parser_initialize_db(uid);
2467 /*Preserve guest mode visibility*/
2468 __preserve_guestmode_visibility_value( mfx);
2469 /*Begin transaction*/
2470 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2471 if (ret != SQLITE_OK) {
2472 _LOGD("Failed to begin transaction\n");
2476 _LOGD("Transaction Begin\n");
2477 ret = __delete_manifest_info_from_db(mfx, uid);
2479 _LOGD("Delete from DB failed. Rollback now\n");
2480 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2483 ret = __insert_manifest_info_in_db(mfx, uid);
2485 _LOGD("Insert into DB failed. Rollback now\n");
2486 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2490 /*Commit transaction*/
2491 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2492 if (ret != SQLITE_OK) {
2493 _LOGD("Failed to commit transaction. Rollback now\n");
2494 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2498 _LOGD("Transaction Commit and End\n");
2500 pkgmgr_parser_close_db();
2504 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2506 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2509 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2512 _LOGD("manifest pointer is NULL\n");
2516 ret = pkgmgr_parser_check_and_create_db(uid);
2518 _LOGD("Failed to open DB\n");
2521 /*Begin transaction*/
2522 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2523 if (ret != SQLITE_OK) {
2524 _LOGD("Failed to begin transaction\n");
2528 _LOGD("Transaction Begin\n");
2529 ret = __delete_manifest_info_from_db(mfx, uid);
2531 _LOGD("Delete from DB failed. Rollback now\n");
2532 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2535 /*Commit transaction*/
2536 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2537 if (ret != SQLITE_OK) {
2538 _LOGD("Failed to commit transaction, Rollback now\n");
2539 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2543 _LOGD("Transaction Commit and End\n");
2545 pkgmgr_parser_close_db();
2549 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2551 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2554 API int pkgmgr_parser_update_preload_info_in_db()
2557 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2559 _LOGD("Failed to open DB\n");
2562 /*Begin transaction*/
2563 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2564 if (ret != SQLITE_OK) {
2565 _LOGD("Failed to begin transaction\n");
2569 _LOGD("Transaction Begin\n");
2570 ret = __update_preload_condition_in_db();
2572 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2573 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2576 /*Commit transaction*/
2577 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2578 if (ret != SQLITE_OK) {
2579 _LOGD("Failed to commit transaction, Rollback now\n");
2580 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2584 _LOGD("Transaction Commit and End\n");
2586 pkgmgr_parser_close_db();
2590 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2593 ret = pkgmgr_parser_check_and_create_db(uid);
2595 _LOGD("Failed to open DB\n");
2598 /*Begin transaction*/
2599 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2600 if (ret != SQLITE_OK) {
2601 _LOGD("Failed to begin transaction\n");
2605 _LOGD("Transaction Begin\n");
2606 ret = __update_preload_condition_in_db();
2608 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2609 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2612 /*Commit transaction*/
2613 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2614 if (ret != SQLITE_OK) {
2615 _LOGD("Failed to commit transaction, Rollback now\n");
2616 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2620 _LOGD("Transaction Commit and End\n");
2622 pkgmgr_parser_close_db();
2626 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2630 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2632 _LOGD("Failed to open DB\n");
2636 /*Begin transaction*/
2637 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2638 if (ret != SQLITE_OK) {
2639 _LOGD("Failed to begin transaction\n");
2643 _LOGD("Transaction Begin\n");
2645 ret = __disable_global_app_for_user(appid, uid);
2647 ret = __enable_global_app_for_user(appid, uid);
2649 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2650 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2653 /*Commit transaction*/
2654 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2655 if (ret != SQLITE_OK) {
2656 _LOGD("Failed to commit transaction, Rollback now\n");
2657 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2661 _LOGD("Transaction Commit and End\n");
2663 pkgmgr_parser_close_db();
2668 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2670 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, GLOBAL_USER, is_disable);
2673 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2677 ret = pkgmgr_parser_check_and_create_db(uid);
2679 _LOGD("Failed to open DB\n");
2683 /*Begin transaction*/
2684 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2685 if (ret != SQLITE_OK) {
2686 _LOGD("Failed to begin transaction\n");
2690 _LOGD("Transaction Begin\n");
2692 ret = __disable_app(appid);
2694 ret = __enable_app(appid);
2696 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2697 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2700 /*Commit transaction*/
2701 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2702 if (ret != SQLITE_OK) {
2703 _LOGD("Failed to commit transaction, Rollback now\n");
2704 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2708 _LOGD("Transaction Commit and End\n");
2710 pkgmgr_parser_close_db();