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 "app_root_path text, " \
172 "app_api_version text, " \
173 "app_effective_appid text, " \
174 "FOREIGN KEY(package) " \
175 "REFERENCES package_info(package) " \
178 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
179 "(app_id text not null, " \
180 "app_locale text DEFAULT 'No Locale', " \
183 "PRIMARY KEY(app_id,app_locale) " \
184 "FOREIGN KEY(app_id) " \
185 "REFERENCES package_app_info(app_id) " \
188 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
189 "(app_id text not null, " \
191 "app_icon_section text, " \
192 "app_icon_resolution text, " \
193 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
194 "FOREIGN KEY(app_id) " \
195 "REFERENCES package_app_info(app_id) " \
198 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
199 "(app_id text not null, " \
200 "app_locale text DEFAULT 'No Locale', " \
201 "app_image_section text, " \
203 "PRIMARY KEY(app_id,app_image_section) " \
204 "FOREIGN KEY(app_id) " \
205 "REFERENCES package_app_info(app_id) " \
208 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
209 "(app_id text not null, " \
210 "app_control text not null, " \
211 "PRIMARY KEY(app_id,app_control) " \
212 "FOREIGN KEY(app_id) " \
213 "REFERENCES package_app_info(app_id) " \
216 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
217 "(app_id text not null, " \
218 "category text not null, " \
219 "PRIMARY KEY(app_id,category) " \
220 "FOREIGN KEY(app_id) " \
221 "REFERENCES package_app_info(app_id) " \
224 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
225 "(app_id text not null, " \
226 "md_key text not null, " \
227 "md_value text not null, " \
228 "PRIMARY KEY(app_id, md_key, md_value) " \
229 "FOREIGN KEY(app_id) " \
230 "REFERENCES package_app_info(app_id) " \
233 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
234 "(app_id text not null, " \
235 "pm_type text not null, " \
236 "pm_value text not null, " \
237 "PRIMARY KEY(app_id, pm_type, pm_value) " \
238 "FOREIGN KEY(app_id) " \
239 "REFERENCES package_app_info(app_id) " \
242 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
243 "(app_id text not null, " \
244 "data_share_path text not null, " \
245 "data_share_allowed text not null, " \
246 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
247 "FOREIGN KEY(app_id) " \
248 "REFERENCES package_app_info(app_id) " \
251 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
252 "(app_id text not null, " \
253 "data_share_request text not null, " \
254 "PRIMARY KEY(app_id,data_share_request) " \
255 "FOREIGN KEY(app_id) " \
256 "REFERENCES package_app_info(app_id) " \
259 /* FIXME: duplicated at pkgmgrinfo_db.c */
260 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
261 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
262 " cert_info TEXT UNIQUE, " \
263 " cert_id INTEGER PRIMARY KEY, " \
264 " cert_ref_count INTEGER NOT NULL)"
266 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
267 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
268 " package TEXT PRIMARY KEY, " \
269 " author_root_cert INTEGER, " \
270 " author_im_cert INTEGER, " \
271 " author_signer_cert INTEGER, " \
272 " dist_root_cert INTEGER, " \
273 " dist_im_cert INTEGER, " \
274 " dist_signer_cert INTEGER, " \
275 " dist2_root_cert INTEGER, " \
276 " dist2_im_cert INTEGER, " \
277 " dist2_signer_cert INTEGER)"
279 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
280 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
281 "AFTER DELETE ON package_cert_info " \
283 " UPDATE package_cert_index_info SET" \
284 " cert_ref_count = cert_ref_count - 1" \
285 " WHERE cert_id = OLD.author_root_cert" \
286 " OR cert_id = OLD.author_im_cert" \
287 " OR cert_id = OLD.author_signer_cert" \
288 " OR cert_id = OLD.dist_root_cert" \
289 " OR cert_id = OLD.dist_im_cert" \
290 " OR cert_id = OLD.dist_signer_cert" \
291 " OR cert_id = OLD.dist2_root_cert" \
292 " OR cert_id = OLD.dist2_im_cert" \
293 " OR cert_id = OLD.dist2_signer_cert;" \
296 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
297 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
298 "AFTER UPDATE ON package_cert_index_info " \
299 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
300 " WHERE cert_id = OLD.cert_id) = 0) "\
302 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
305 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT \
306 "CREATE TRIGGER IF NOT EXISTS update_%s_info " \
307 "AFTER UPDATE ON package_cert_info " \
308 "WHEN (OLD.%s IS NOT NULL) " \
310 " UPDATE package_cert_index_info SET" \
311 " cert_ref_count = cert_ref_count - 1" \
312 " WHERE cert_id = OLD.%s;" \
315 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
316 "(app_id text not null, " \
317 "providerid text not null, " \
318 "access text not null, " \
319 "type text not null, " \
320 "PRIMARY KEY(app_id, providerid, access, type) " \
321 "FOREIGN KEY(app_id) " \
322 "REFERENCES package_app_info(app_id) " \
325 #define QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER "CREATE TABLE IF NOT EXISTS package_app_disable_for_user " \
326 "(app_id text not null, " \
327 "uid text not null, " \
328 "PRIMARY KEY(app_id, uid))"
330 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
331 "create table if not exists package_app_splash_screen " \
332 "(app_id text not null, " \
333 "src text not null, " \
334 "type text not null, " \
335 "orientation text not null, " \
336 "indicatordisplay text, " \
338 "PRIMARY KEY(app_id, orientation, operation) " \
339 "FOREIGN KEY(app_id) " \
340 "REFERENCES package_app_info(app_id) " \
343 static int __insert_application_info(manifest_x *mfx);
344 static int __insert_application_appcategory_info(manifest_x *mfx);
345 static int __insert_application_appcontrol_info(manifest_x *mfx);
346 static int __insert_application_appmetadata_info(manifest_x *mfx);
347 static int __insert_application_share_allowed_info(manifest_x *mfx);
348 static int __insert_application_share_request_info(manifest_x *mfx);
349 static int __insert_application_datacontrol_info(manifest_x *mfx);
350 static void __insert_application_locale_info(gpointer data, gpointer userdata);
351 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
352 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
353 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
354 static int __delete_subpkg_info_from_db(char *appid);
355 static int __delete_appinfo_from_db(char *db_table, const char *appid);
356 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
357 static int __exec_query(char *query);
358 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
359 char **label, char **license, char **icon, char **description, char **author);
360 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
361 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
362 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
363 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
364 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
365 static int __parserdb_change_perm(const char *db_file, uid_t uid);
367 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
370 __delete_subpkg_info_from_db(coltxt[0]);
375 static const char *__get_str(const char *str)
379 return PKGMGR_PARSER_EMPTY_STR;
385 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
390 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
391 if (ret != SQLITE_OK) {
392 _LOGD("connect db [%s] failed!\n", db_path);
400 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
402 manifest_x *mfx = (manifest_x *)data;
408 if (mfx->application == NULL)
410 app = (application_x *)mfx->application->data;
411 for(i = 0; i < ncols; i++)
413 if (strcmp(colname[i], "app_id") == 0) {
415 appid = strdup(coltxt[i]);
416 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
418 status = strdup(coltxt[i]);
424 _LOGD("app id is NULL\n");
427 /*update guest mode visibility*/
428 for (tmp = mfx->application; tmp; tmp = tmp->next) {
429 app = (application_x *)tmp->data;
432 if (strcmp(app->appid, appid) == 0) {
433 free((void *)app->guestmode_visibility);
434 app->guestmode_visibility = strdup(status);
450 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
452 char *error_message = NULL;
453 char query[MAX_QUERY_LEN] = {'\0'};
454 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
456 sqlite3_exec(pkgmgr_parser_db, query,
457 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
458 _LOGD("Don't execute query = %s error message = %s\n",
459 query, error_message);
460 sqlite3_free(error_message);
465 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
467 char *error_message = NULL;
469 sqlite3_exec(db_handle, db_query,
470 NULL, NULL, &error_message)) {
471 _LOGD("Don't execute query = %s error message = %s\n",
472 db_query, error_message);
473 sqlite3_free(error_message);
476 sqlite3_free(error_message);
480 static int __exec_query(char *query)
482 char *error_message = NULL;
484 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
485 _LOGE("Don't execute query = %s error message = %s\n", query,
487 sqlite3_free(error_message);
490 sqlite3_free(error_message);
494 static int __exec_query_no_msg(char *query)
496 char *error_message = NULL;
498 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
499 sqlite3_free(error_message);
502 sqlite3_free(error_message);
506 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
514 for (tmp = lbls; tmp; tmp = tmp->next) {
515 lbl = (label_x *)tmp->data;
519 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
521 for (tmp = lcns; tmp; tmp = tmp->next) {
522 lcn = (license_x *)tmp->data;
526 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
528 for (tmp = icns; tmp; tmp = tmp->next) {
529 icn = (icon_x *)tmp->data;
533 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
535 for (tmp = dcns; tmp; tmp = tmp->next) {
536 dcn = (description_x *)tmp->data;
540 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
542 for (tmp = aths; tmp; tmp = tmp->next) {
543 ath = (author_x *)tmp->data;
547 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
553 static GList *__create_icon_list(GList *appicon, GList *icns)
558 for (tmp = icns; tmp; tmp = tmp->next) {
559 icn = (icon_x *)tmp->data;
563 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
568 static GList *__create_image_list(GList *appimage, GList *imgs)
573 for (tmp = imgs; tmp; tmp = tmp->next) {
574 img = (image_x *)tmp->data;
578 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
583 static void __trimfunc(GList* trim_list)
585 char *trim_data = NULL;
589 list = g_list_first(trim_list);
592 trim_data = (char *)list->data;
595 if (strcmp(trim_data, prev) == 0) {
596 trim_list = g_list_remove(trim_list, trim_data);
597 list = g_list_first(trim_list);
606 list = g_list_next(list);
610 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
612 if (a == NULL || b == NULL)
614 if (strcmp((char*)a, (char*)b) == 0)
616 if (strcmp((char*)a, (char*)b) < 0)
618 if (strcmp((char*)a, (char*)b) > 0)
623 static int __check_dpi(const char *dpi_char, int dpi_int)
625 if (dpi_char == NULL)
628 if (strcasecmp(dpi_char, LDPI) == 0) {
629 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
633 } else if (strcasecmp(dpi_char, MDPI) == 0) {
634 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
638 } else if (strcasecmp(dpi_char, HDPI) == 0) {
639 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
643 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
644 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
648 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
649 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
657 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
660 char *icon_filename = NULL;
661 char modified_iconpath[BUFSIZE] = { '\0' };
662 char icon_path[BUFSIZE] = { '\0' };
666 if (orig_icon_path == NULL)
669 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
673 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
674 dpi_path[0] = "LDPI";
675 dpi_path[1] = "ldpi";
676 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
677 dpi_path[0] = "MDPI";
678 dpi_path[1] = "mdpi";
679 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
680 dpi_path[0] = "HDPI";
681 dpi_path[1] = "hdpi";
682 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
683 dpi_path[0] = "XHDPI";
684 dpi_path[1] = "xhdpi";
685 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
686 dpi_path[0] = "XXHDPI";
687 dpi_path[1] = "xxhdpi";
689 _LOGE("Unidentified dpi[%d]", dpi);
693 icon_filename = strrchr(orig_icon_path, '/');
694 if (icon_filename == NULL)
697 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
698 for (i = 0; i < 2; i++) {
699 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
700 if (access(modified_iconpath, F_OK) != -1) {
701 // if exists, return modified icon path
702 *new_icon_path = strdup(modified_iconpath);
710 static gint __compare_icon(gconstpointer a, gconstpointer b)
712 icon_x *icon = (icon_x *)a;
714 char *icon_folder_path = NULL;
716 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
719 if (icon->dpi != NULL)
722 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
724 icon->text = icon_folder_path;
730 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
732 icon_x *icon = (icon_x *)a;
733 int dpi = GPOINTER_TO_INT(b);
735 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
738 if (icon->dpi == NULL)
741 if (__check_dpi(icon->dpi, dpi) == 0)
747 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
749 icon_x *icon = (icon_x *)a;
750 char *lang = (char *)b;
751 char *icon_folder_path = NULL;
753 if (icon->dpi != NULL)
756 if (strcasecmp(icon->lang, lang) == 0) {
757 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
758 //icon for no locale. check existance of folder-hierachied default icons
759 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
761 icon->text = icon_folder_path;
770 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
772 icon_x *icon = (icon_x *)a;
773 char *lang = (char *)b;
776 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
780 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
786 static char *__find_icon(GList *icons, const char *lang)
792 // first, find icon whose locale and dpi with given lang and system's dpi has matched
793 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
795 icon = (icon_x *)tmp->data;
796 return (char *)icon->text;
799 // if first has failed, find icon whose locale has matched
800 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
802 icon = (icon_x *)tmp->data;
803 return (char *)icon->text;
806 // if second has failed, find icon whose dpi has matched with system's dpi
807 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
810 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
812 icon = (icon_x *)tmp->data;
813 return (char *)icon->text;
816 // last, find default icon marked as "No Locale"
817 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
819 icon = (icon_x *)tmp->data;
820 return (char *)icon->text;
826 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
827 char **label, char **license, char **icon, char **description, char **author)
834 for (tmp = lbls; tmp; tmp = tmp->next) {
835 lbl = (label_x *)tmp->data;
839 if (strcmp(lbl->lang, (char *)data) == 0) {
840 *label = (char*)lbl->text;
845 for (tmp = lcns; tmp; tmp = tmp->next) {
846 lcn = (license_x *)tmp->data;
850 if (strcmp(lcn->lang, (char *)data) == 0) {
851 *license = (char*)lcn->text;
857 *icon = __find_icon(icns, (char *)data);
859 for (tmp = dcns; tmp; tmp = tmp->next) {
860 dcn = (description_x *)tmp->data;
864 if (strcmp(dcn->lang, (char *)data) == 0) {
865 *description = (char*)dcn->text;
870 for (tmp = aths; tmp; tmp = tmp->next) {
871 ath = (author_x *)tmp->data;
875 if (strcmp(ath->lang, (char *)data) == 0) {
876 *author = (char*)ath->text;
884 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
888 for (tmp = icns; tmp; tmp = tmp->next) {
889 icn = (icon_x *)tmp->data;
893 if (strcmp(icn->section, (char *)data) == 0) {
894 *icon = (char*)icn->text;
895 *resolution = (char*)icn->resolution;
902 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
906 for (tmp = imgs; tmp; tmp = tmp->next) {
907 img = (image_x *)tmp->data;
911 if (strcmp(img->section, (char *)data) == 0) {
912 *lang = (char*)img->lang;
913 *image = (char*)img->text;
920 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
925 char *description = NULL;
926 char *license = NULL;
930 manifest_x *mfx = (manifest_x *)userdata;
931 GList *lbl = mfx->label;
932 GList *lcn = mfx->license;
933 GList *icn = mfx->icon;
934 GList *dcn = mfx->description;
935 GList *ath = mfx->author;
937 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
938 if (!label && !description && !icon && !license && !author)
941 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
942 "package_label, package_icon, package_description, package_license, package_author) values " \
943 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
948 __get_str(description),
952 ret = __exec_query(query);
954 _LOGD("Package Localized Info DB Insert failed\n");
959 static void __insert_application_locale_info(gpointer data, gpointer userdata)
966 application_x *app = (application_x*)userdata;
967 GList *lbl = app->label;
968 GList *icn = app->icon;
970 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
974 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
975 "app_label, app_icon) values " \
976 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
977 __get_str(label), __get_str(icon));
978 ret = __exec_query(query);
980 _LOGD("Package UiApp Localized Info DB Insert failed\n");
984 /*insert ui app locale info to pkg locale to get mainapp data */
985 if (strcasecmp(app->mainapp, "true")==0) {
986 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
987 "package_label, package_icon, package_description, package_license, package_author) values " \
988 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
993 PKGMGR_PARSER_EMPTY_STR,
994 PKGMGR_PARSER_EMPTY_STR,
995 PKGMGR_PARSER_EMPTY_STR);
997 ret = __exec_query_no_msg(query);
1001 query = sqlite3_mprintf("update package_localized_info set package_icon=%Q "\
1002 "where package=%Q and package_locale=%Q", icon, app->package, (char*)data);
1003 ret = __exec_query_no_msg(query);
1004 sqlite3_free(query);
1009 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1013 char *resolution = NULL;
1014 char query[MAX_QUERY_LEN] = {'\0'};
1016 application_x *app = (application_x*)userdata;
1017 GList *icn = app->icon;
1019 __extract_icon_data(data, icn, &icon, &resolution);
1020 if (!icon && !resolution)
1022 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
1023 "app_icon, app_icon_section, app_icon_resolution) values " \
1024 "('%q', '%q', '%q', '%q')", app->appid,
1025 icon, (char*)data, resolution);
1027 ret = __exec_query(query);
1029 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1033 static void __insert_application_image_info(gpointer data, gpointer userdata)
1038 char query[MAX_QUERY_LEN] = {'\0'};
1040 application_x *app = (application_x*)userdata;
1041 GList *image = app->image;
1043 __extract_image_data(data, image, &lang, &img);
1046 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
1047 "app_image_section, app_image) values " \
1048 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
1050 ret = __exec_query(query);
1052 _LOGD("Package UiApp image Info DB Insert failed\n");
1057 static int __insert_mainapp_info(manifest_x *mfx)
1062 char query[MAX_QUERY_LEN] = {'\0'};
1063 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1064 app = (application_x *)tmp->data;
1067 snprintf(query, MAX_QUERY_LEN,
1068 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
1070 ret = __exec_query(query);
1072 _LOGD("Package App Info DB Insert Failed\n");
1075 if (strcasecmp(app->mainapp, "True")==0)
1076 mfx->mainapp_id = strdup(app->appid);
1079 if (mfx->mainapp_id == NULL) {
1080 if (mfx->application == NULL)
1082 app = (application_x *)mfx->application->data;
1086 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
1088 _LOGD("Not valid appid\n");
1092 ret = __exec_query(query);
1094 _LOGD("Package UiApp Info DB Insert Failed\n");
1098 free((void *)app->mainapp);
1099 app->mainapp= strdup("true");
1100 mfx->mainapp_id = strdup(app->appid);
1103 memset(query, '\0', MAX_QUERY_LEN);
1104 snprintf(query, MAX_QUERY_LEN,
1105 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
1106 ret = __exec_query(query);
1108 _LOGD("Package Info DB update Failed\n");
1115 static int __convert_background_category(GList *category_list)
1118 GList *tmp_list = category_list;
1119 char *category_data = NULL;
1121 if (category_list == NULL)
1124 while (tmp_list != NULL) {
1125 category_data = (char *)tmp_list->data;
1126 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1127 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1128 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1129 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1130 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1131 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1132 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1133 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1134 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1135 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1136 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1137 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1138 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1139 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1141 _LOGE("Unidentified category [%s]", category_data);
1143 tmp_list = g_list_next(tmp_list);
1149 static const char *__find_effective_appid(GList *metadata_list)
1154 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1155 md = (metadata_x *)tmp_list->data;
1156 if (md == NULL || md->key == NULL)
1159 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1168 /* _PRODUCT_LAUNCHING_ENHANCED_
1169 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1171 static int __insert_application_info(manifest_x *mfx)
1176 int background_value = 0;
1177 char query[MAX_QUERY_LEN] = {'\0'};
1179 const char *effective_appid;
1182 type = strdup(mfx->type);
1184 type = strdup("tpk");
1186 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1187 app = (application_x *)tmp->data;
1191 background_value = __convert_background_category(app->background_category);
1192 if (background_value < 0) {
1193 _LOGE("Failed to retrieve background value[%d]", background_value);
1194 background_value = 0;
1197 effective_appid = __find_effective_appid(app->metadata);
1199 snprintf(query, MAX_QUERY_LEN,
1200 "insert into package_app_info(" \
1201 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1202 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1203 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1204 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1205 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1206 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1207 "app_tep_name, app_background_category, app_package_type, app_root_path, app_api_version, " \
1208 "app_effective_appid) " \
1210 "'%s', '%s', '%s', '%s', '%s', " \
1211 "'%s', '%s', '%s', '%s', '%s', " \
1212 "'%s', '%s', '%s', '%s', '%s', " \
1213 "'%s', '%s', '%s', '%s', '%s', " \
1214 "'%s', '%s', '%s', '%s', '%s', " \
1215 "'%s', '%s', '%s', '%s', '%s', " \
1216 "'%s', '%d', '%s', '%s', '%s', " \
1218 app->appid, app->component_type, app->exec, app->nodisplay, app->type,
1219 app->onboot, app->multiple, app->autorestart, app->taskmanage, app->enabled,
1220 app->hwacceleration, app->screenreader, app->mainapp, __get_str(app->recentimage), app->launchcondition,
1221 app->indicatordisplay, __get_str(app->portraitimg), __get_str(app->landscapeimg),
1222 app->guestmode_visibility, app->permission_type,
1223 mfx->preload, app->submode, __get_str(app->submode_mainid), mfx->installed_storage, app->process_pool,
1224 app->launch_mode, app->ui_gadget, mfx->support_disable, app->component_type, mfx->package,
1225 __get_str(mfx->tep_name), background_value, type, mfx->root_path, __get_str(mfx->api_version),
1226 __get_str(effective_appid));
1228 ret = __exec_query(query);
1230 _LOGD("Package UiApp Info DB Insert Failed\n");
1235 memset(query, '\0', MAX_QUERY_LEN);
1244 static int __insert_application_appcategory_info(manifest_x *mfx)
1251 char query[MAX_QUERY_LEN] = {'\0'};
1252 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1253 app = (application_x *)app_tmp->data;
1256 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1257 ct = (const char *)ct_tmp->data;
1260 snprintf(query, MAX_QUERY_LEN,
1261 "insert into package_app_app_category(app_id, category) " \
1262 "values('%s','%s')",\
1264 ret = __exec_query(query);
1266 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1269 memset(query, '\0', MAX_QUERY_LEN);
1275 static int __insert_application_appmetadata_info(manifest_x *mfx)
1282 char query[MAX_QUERY_LEN] = {'\0'};
1283 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1284 app = (application_x *)app_tmp->data;
1287 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1288 md = (metadata_x *)md_tmp->data;
1292 snprintf(query, MAX_QUERY_LEN,
1293 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1294 "values('%s','%s', '%s')",\
1295 app->appid, md->key, md->value ? md->value : "");
1296 ret = __exec_query(query);
1298 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1302 memset(query, '\0', MAX_QUERY_LEN);
1308 static int __insert_application_apppermission_info(manifest_x *mfx)
1315 char query[MAX_QUERY_LEN] = {'\0'};
1316 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1317 app = (application_x *)app_tmp->data;
1320 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1321 pm = (permission_x *)pm_tmp->data;
1324 snprintf(query, MAX_QUERY_LEN,
1325 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1326 "values('%s','%s', '%s')",\
1327 app->appid, pm->type, pm->value);
1328 ret = __exec_query(query);
1330 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1333 memset(query, '\0', MAX_QUERY_LEN);
1339 static int __insert_application_appcontrol_info(manifest_x *mfx)
1343 GList *acontrol_tmp;
1344 appcontrol_x *acontrol;
1346 char query[MAX_QUERY_LEN] = {'\0'};
1347 char buf[BUFSIZE] = {'\0'};
1348 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1349 app = (application_x *)app_tmp->data;
1352 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1353 acontrol = (appcontrol_x *)acontrol_tmp->data;
1354 if (acontrol == NULL)
1356 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1357 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1358 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1359 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1360 snprintf(query, MAX_QUERY_LEN,
1361 "insert into package_app_app_control(app_id, app_control) " \
1362 "values('%s', '%s')",\
1364 ret = __exec_query(query);
1366 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1369 memset(query, '\0', MAX_QUERY_LEN);
1375 static int __insert_application_datacontrol_info(manifest_x *mfx)
1382 char query[MAX_QUERY_LEN] = {'\0'};
1384 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1385 app = (application_x *)app_tmp->data;
1388 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1389 dc = (datacontrol_x *)dc_tmp->data;
1392 snprintf(query, MAX_QUERY_LEN,
1393 "insert into package_app_data_control(app_id, providerid, access, type) " \
1394 "values('%s', '%s', '%s', '%s')",\
1400 ret = __exec_query(query);
1402 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1405 memset(query, '\0', MAX_QUERY_LEN);
1411 static int __insert_application_share_request_info(manifest_x *mfx)
1420 char query[MAX_QUERY_LEN] = {'\0'};
1421 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1422 app = (application_x *)app_tmp->data;
1425 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1426 ds = (datashare_x *)ds_tmp->data;
1429 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1430 rq = (const char *)rq_tmp->data;
1433 snprintf(query, MAX_QUERY_LEN,
1434 "insert into package_app_share_request(app_id, data_share_request) " \
1435 "values('%s', '%s')",\
1437 ret = __exec_query(query);
1439 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1442 memset(query, '\0', MAX_QUERY_LEN);
1449 static int __insert_application_share_allowed_info(manifest_x *mfx)
1460 char query[MAX_QUERY_LEN] = {'\0'};
1461 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1462 app = (application_x *)app_tmp->data;
1465 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1466 ds = (datashare_x *)ds_tmp->data;
1469 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1470 df = (define_x *)df_tmp->data;
1473 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1474 al = (const char *)al_tmp->data;
1477 snprintf(query, MAX_QUERY_LEN,
1478 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1479 "values('%s', '%s', '%s')",\
1480 app->appid, df->path, al);
1481 ret = __exec_query(query);
1483 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1486 memset(query, '\0', MAX_QUERY_LEN);
1494 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1496 splashscreen_x *ss = (splashscreen_x *)a;
1497 const char *orientation = (const char *)b;
1500 if (ss->operation || ss->dpi == NULL)
1503 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1507 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1513 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1515 splashscreen_x *ss = (splashscreen_x *)a;
1516 const char *orientation = (const char *)b;
1518 if (ss->operation || ss->dpi)
1521 if (strcasecmp(ss->orientation, orientation) == 0)
1527 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1528 const char *orientation)
1532 tmp = g_list_find_custom(splashscreens, orientation,
1533 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1535 return (splashscreen_x *)tmp->data;
1537 tmp = g_list_find_custom(splashscreens, orientation,
1538 (GCompareFunc)__compare_splashscreen_with_orientation);
1540 return (splashscreen_x *)tmp->data;
1545 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1547 splashscreen_x *ss = (splashscreen_x *)data;
1548 GList **list = (GList **)user_data;
1551 if (ss->operation == NULL || ss->dpi == NULL)
1554 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1558 if (__check_dpi(ss->dpi, dpi) != 0)
1561 *list = g_list_append(*list, ss);
1564 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1566 splashscreen_x *ss = (splashscreen_x *)data;
1567 GList **list = (GList **)user_data;
1568 splashscreen_x *ss_tmp;
1571 if (ss->operation == NULL || ss->dpi)
1574 for (tmp = *list; tmp; tmp = tmp->next) {
1575 ss_tmp = (splashscreen_x *)tmp->data;
1576 if (ss_tmp->operation
1577 && strcmp(ss_tmp->operation, ss->operation) == 0
1578 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1582 *list = g_list_append(*list, ss);
1585 static GList *__find_splashscreens(GList *splashscreens)
1590 g_list_foreach(splashscreens,
1591 __find_appcontrol_splashscreen_with_dpi, &list);
1592 g_list_foreach(splashscreens,
1593 __find_appcontrol_splashscreen, &list);
1595 ss = __find_default_splashscreen(splashscreens, "portrait");
1597 list = g_list_append(list, ss);
1598 ss = __find_default_splashscreen(splashscreens, "landscape");
1600 list = g_list_append(list, ss);
1605 static int __insert_application_splashscreen_info(manifest_x *mfx)
1613 char query[MAX_QUERY_LEN];
1615 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1616 app = (application_x *)app_tmp->data;
1617 if (app == NULL || app->splashscreens == NULL)
1620 ss_tmp = __find_splashscreens(app->splashscreens);
1624 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1625 ss = (splashscreen_x *)tmp->data;
1626 snprintf(query, sizeof(query),
1627 "insert into package_app_splash_screen" \
1628 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1629 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1630 app->appid, ss->src, ss->type, ss->orientation,
1631 ss->indicatordisplay, __get_str(ss->operation));
1632 ret = __exec_query(query);
1634 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1637 memset(query, '\0', MAX_QUERY_LEN);
1639 g_list_free(ss_tmp);
1644 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1649 char query[MAX_QUERY_LEN];
1651 const char *image_type;
1652 const char *indicatordisplay;
1653 const char *orientation;
1654 const char *operation = NULL;
1656 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1657 app = (application_x *)app_tmp->data;
1659 (app->portraitimg == NULL && app->landscapeimg == NULL))
1661 image_type = "img"; /* default */
1662 if (app->effectimage_type) {
1663 tmp = strstr(app->effectimage_type, "edj");
1667 indicatordisplay = "true"; /* default */
1668 if (app->indicatordisplay)
1669 indicatordisplay = app->indicatordisplay;
1670 if (app->portraitimg) {
1671 orientation = "portrait";
1672 snprintf(query, sizeof(query),
1673 "insert into package_app_splash_screen" \
1674 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1675 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1676 app->appid, app->portraitimg, image_type,
1677 orientation, indicatordisplay, __get_str(operation));
1678 ret = __exec_query(query);
1680 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1683 memset(query, '\0', MAX_QUERY_LEN);
1684 } else if (app->landscapeimg) {
1685 orientation = "landscape";
1686 snprintf(query, sizeof(query),
1687 "insert into package_app_splash_screen" \
1688 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1689 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1690 app->appid, app->landscapeimg, image_type,
1691 orientation, indicatordisplay, __get_str(operation));
1692 ret = __exec_query(query);
1694 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1697 memset(query, '\0', MAX_QUERY_LEN);
1703 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1707 const char *pv = NULL;
1708 char query[MAX_QUERY_LEN] = { '\0' };
1711 const char *auth_name = NULL;
1712 const char *auth_email = NULL;
1713 const char *auth_href = NULL;
1715 GList *pkglocale = NULL;
1716 GList *applocale = NULL;
1717 GList *appicon = NULL;
1718 GList *appimage = NULL;
1720 if (mfx->author && mfx->author->data) {
1721 author = (author_x *)mfx->author->data;
1723 auth_name = author->text;
1725 auth_email = author->email;
1727 auth_href = author->href;
1730 /*Insert in the package_cert_info CERT_DB*/
1731 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1732 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1733 if (ret != PMINFO_R_OK) {
1734 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1735 _LOGE("Cert Info DB create handle failed\n");
1738 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1739 if (ret != PMINFO_R_OK) {
1740 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1741 _LOGE("Cert Info DB Insert Failed\n");
1745 /*Insert in the package_info DB*/
1746 snprintf(query, MAX_QUERY_LEN,
1747 "insert into package_info(" \
1748 "package, package_type, package_version, package_api_version, package_tep_name, " \
1749 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1750 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1751 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1752 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1754 "'%s', '%s', '%s', '%s', '%s', " \
1755 "'%s', '%s', '%s', '%s', '%s', " \
1756 "'%s', '%s', '%s', '%s', '%s', " \
1757 "'%s', '%s', '%s', '%s', '%s', " \
1758 "'%s', '%s', '%s', '%s', '%s')", \
1759 mfx->package, mfx->type, mfx->version, __get_str(mfx->api_version), __get_str(mfx->tep_name),
1760 __get_str(mfx->installlocation), __get_str(mfx->package_size), mfx->removable, mfx->preload, mfx->readonly,
1761 mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system, __get_str(auth_name),
1762 __get_str(auth_email), __get_str(auth_href), mfx->installed_time, mfx->installed_storage,
1763 __get_str(mfx->storeclient_id),
1764 mfx->mainapp_id, __get_str(mfx->package_url), mfx->root_path, __get_str(mfx->csc_path), mfx->support_disable);
1766 ret = __exec_query(query);
1768 _LOGD("Package Info DB Insert Failed\n");
1772 /*Insert in the package_privilege_info DB*/
1773 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1774 pv = (const char *)tmp->data;
1777 memset(query, '\0', MAX_QUERY_LEN);
1778 snprintf(query, MAX_QUERY_LEN,
1779 "insert into package_privilege_info(package, privilege) " \
1780 "values('%s','%s')",\
1782 ret = __exec_query(query);
1784 _LOGD("Package Privilege Info DB Insert Failed\n");
1789 if (mfx->application != NULL) {
1790 ret = __insert_mainapp_info(mfx);
1795 /*Insert the package locale*/
1796 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1797 /*remove duplicated data in pkglocale*/
1798 __trimfunc(pkglocale);
1800 /*Insert the app locale, icon, image info */
1801 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1802 app = (application_x *)tmp->data;
1805 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1806 appicon = __create_icon_list(appicon, app->icon);
1807 appimage = __create_image_list(appimage, app->image);
1809 /*remove duplicated data in applocale*/
1810 __trimfunc(applocale);
1811 __trimfunc(appicon);
1812 __trimfunc(appimage);
1814 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1816 /*native app locale info*/
1817 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1818 app = (application_x *)tmp->data;
1821 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1822 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1823 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1826 g_list_free(pkglocale);
1828 g_list_free(applocale);
1830 g_list_free(appicon);
1832 g_list_free(appimage);
1835 /*Insert in the package_app_info DB*/
1836 ret = __insert_application_info(mfx);
1839 /*Insert in the package_app_app_control DB*/
1840 ret = __insert_application_appcontrol_info(mfx);
1844 /*Insert in the package_app_app_category DB*/
1845 ret = __insert_application_appcategory_info(mfx);
1849 /*Insert in the package_app_app_metadata DB*/
1850 ret = __insert_application_appmetadata_info(mfx);
1854 /*Insert in the package_app_app_permission DB*/
1855 ret = __insert_application_apppermission_info(mfx);
1859 /*Insert in the package_app_share_allowed DB*/
1860 ret = __insert_application_share_allowed_info(mfx);
1864 /*Insert in the package_app_share_request DB*/
1865 ret = __insert_application_share_request_info(mfx);
1869 /*Insert in the package_app_data_control DB*/
1870 ret = __insert_application_datacontrol_info(mfx);
1874 /*Insert in the package_app_splash_screen DB*/
1875 ret = __insert_application_legacy_splashscreen_info(mfx);
1879 /*Insert in the package_app_splash_screen DB*/
1880 ret = __insert_application_splashscreen_info(mfx);
1888 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1890 char query[MAX_QUERY_LEN] = { '\0' };
1892 memset(query, '\0', MAX_QUERY_LEN);
1893 snprintf(query, MAX_QUERY_LEN,
1894 "delete from %s where app_id='%s'", db_table, appid);
1895 ret = __exec_query(query);
1897 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1903 static int __delete_subpkg_info_from_db(char *appid)
1907 ret = __delete_appinfo_from_db("package_app_info", appid);
1910 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1913 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1916 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1919 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1922 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1925 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1928 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1931 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1934 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1937 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1940 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
1947 static int __delete_subpkg_from_db(manifest_x *mfx)
1949 char query[MAX_QUERY_LEN] = { '\0' };
1950 char *error_message = NULL;
1952 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1954 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1955 _LOGE("Don't execute query = %s error message = %s\n", query,
1957 sqlite3_free(error_message);
1960 sqlite3_free(error_message);
1965 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1967 char query[MAX_QUERY_LEN] = { '\0' };
1971 /*Delete from cert table*/
1972 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1974 _LOGD("Cert Info DB Delete Failed\n");
1978 /*Delete from Package Info DB*/
1979 snprintf(query, MAX_QUERY_LEN,
1980 "delete from package_info where package='%s'", mfx->package);
1981 ret = __exec_query(query);
1983 _LOGD("Package Info DB Delete Failed\n");
1986 memset(query, '\0', MAX_QUERY_LEN);
1988 /*Delete from Package Localized Info*/
1989 snprintf(query, MAX_QUERY_LEN,
1990 "delete from package_localized_info where package='%s'", mfx->package);
1991 ret = __exec_query(query);
1993 _LOGD("Package Localized Info DB Delete Failed\n");
1997 /*Delete from Package Privilege Info*/
1998 snprintf(query, MAX_QUERY_LEN,
1999 "delete from package_privilege_info where package='%s'", mfx->package);
2000 ret = __exec_query(query);
2002 _LOGD("Package Privilege Info DB Delete Failed\n");
2006 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2007 app = (application_x *)tmp->data;
2010 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2013 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2016 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2019 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2022 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2025 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2028 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2031 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2034 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2037 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2040 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2043 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2048 /* if main package has sub pkg, delete sub pkg data*/
2049 __delete_subpkg_from_db(mfx);
2054 static int __disable_app(const char *appid)
2057 char query[MAX_QUERY_LEN] = {'\0'};
2058 sqlite3_snprintf(MAX_QUERY_LEN, query,
2059 "UPDATE package_app_info set app_disable='true' where app_id=%Q",
2061 ret = __exec_query(query);
2063 _LOGD("Insert global app disable failed\n");
2068 static int __enable_app(const char *appid)
2071 char query[MAX_QUERY_LEN] = {'\0'};
2072 sqlite3_snprintf(MAX_QUERY_LEN, query,
2073 "UPDATE package_app_info set app_disable='false' where app_id=%Q",
2075 ret = __exec_query(query);
2077 _LOGD("Insert global app disable failed\n");
2082 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2085 char query[MAX_QUERY_LEN] = {'\0'};
2087 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO " \
2088 "package_app_disable_for_user(app_id, uid) VALUES(%Q, '%d')",
2090 ret = __exec_query(query);
2092 _LOGD("Insert global app disable failed\n");
2097 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2100 char query[MAX_QUERY_LEN] = {'\0'};
2102 sqlite3_snprintf(MAX_QUERY_LEN, query, "DELETE FROM " \
2103 "package_app_disable_for_user WHERE app_id=%Q AND uid='%d'",
2105 ret = __exec_query(query);
2107 _LOGD("Delete global app disable failed\n");
2112 static int __update_preload_condition_in_db()
2115 char query[MAX_QUERY_LEN] = {'\0'};
2117 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2119 ret = __exec_query(query);
2121 _LOGD("Package preload_condition update failed\n");
2126 API int pkgmgr_parser_initialize_db(uid_t uid)
2130 char query[MAX_QUERY_LEN];
2131 static const char *columns[] = {
2132 "author_root_cert", "author_im_cert", "author_signer_cert",
2133 "dist_root_cert", "dist_im_cert", "dist_signer_cert",
2134 "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
2138 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2140 _LOGD("package info DB initialization failed\n");
2143 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2145 _LOGD("package localized info DB initialization failed\n");
2148 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2150 _LOGD("package app app privilege DB initialization failed\n");
2153 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2155 _LOGD("package app info DB initialization failed\n");
2158 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2160 _LOGD("package app localized info DB initialization failed\n");
2163 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2165 _LOGD("package app icon localized info DB initialization failed\n");
2168 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2170 _LOGD("package app image info DB initialization failed\n");
2173 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2175 _LOGD("package app app control DB initialization failed\n");
2178 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2180 _LOGD("package app app category DB initialization failed\n");
2183 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2185 _LOGD("package app app category DB initialization failed\n");
2188 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2190 _LOGD("package app app permission DB initialization failed\n");
2193 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2195 _LOGD("package app share allowed DB initialization failed\n");
2198 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2200 _LOGD("package app share request DB initialization failed\n");
2203 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2205 _LOGD("package app data control DB initialization failed\n");
2209 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER);
2211 _LOGD("package app disable for user DB initialization failed\n");
2215 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2217 _LOGD("package app splash screen DB initialization failed\n");
2222 /* TODO: refactor this code */
2223 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2225 _LOGD("package cert info DB initialization failed\n");
2228 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2230 _LOGD("package cert index info DB initialization failed\n");
2233 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2235 _LOGD("package cert info DB initialization failed\n");
2238 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2240 _LOGD("package cert index info DB initialization failed\n");
2243 for (i = 0; columns[i] != NULL; i++) {
2244 snprintf(query, sizeof(query),
2245 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
2246 columns[i], columns[i], columns[i]);
2247 ret = __initialize_db(pkgmgr_cert_db, query);
2249 _LOGD("package cert index info DB initialization failed\n");
2254 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
2255 _LOGD("Failed to change cert db permission\n");
2257 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2258 _LOGD("Failed to change parser db permission\n");
2264 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2267 char journal_file[BUFSIZE];
2270 struct passwd *userinfo = NULL;
2271 files[0] = (char *)db_file;
2272 files[1] = journal_file;
2276 if (db_file == NULL)
2279 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2281 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2282 if (uid == OWNER_ROOT)
2284 userinfo = getpwuid(uid);
2286 _LOGE("FAIL: user %d doesn't exist", uid);
2289 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2291 for (i = 0; files[i]; i++) {
2292 ret = chown(files[i], uid, userinfo->pw_gid);
2294 if (strerror_r(errno, buf, sizeof(buf)))
2295 strncpy(buf, "", BUFSIZE - 1);
2296 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2297 userinfo->pw_gid, buf);
2301 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2302 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2304 ret = chmod(files[i], mode);
2306 if (strerror_r(errno, buf, sizeof(buf)))
2307 strncpy(buf, "", BUFSIZE - 1);
2308 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2311 SET_SMACK_LABEL(files[i]);
2316 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2320 if (getuid() != OWNER_ROOT) {
2321 _LOGE("Only root user is allowed");
2325 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2326 _LOGE("Manifest db for user %d is already exists", uid);
2330 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2331 _LOGE("Cert db for user %d is already exists", uid);
2335 ret = pkgmgr_parser_check_and_create_db(uid);
2338 ret = pkgmgr_parser_initialize_db(uid);
2340 pkgmgr_parser_close_db();
2343 pkgmgr_parser_close_db();
2348 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2352 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2354 _LOGD("Manifest DB creation Failed\n");
2359 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2361 _LOGD("Cert DB creation Failed\n");
2367 void pkgmgr_parser_close_db(void)
2369 sqlite3_close(pkgmgr_parser_db);
2370 sqlite3_close(pkgmgr_cert_db);
2374 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2376 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2378 _LOGD("manifest pointer is NULL\n");
2382 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2384 _LOGD("Failed to open DB\n");
2387 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2390 /*Begin transaction*/
2391 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2392 if (ret != SQLITE_OK) {
2393 _LOGD("Failed to begin transaction\n");
2397 _LOGD("Transaction Begin\n");
2398 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2400 _LOGD("Insert into DB failed. Rollback now\n");
2401 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2404 /*Commit transaction*/
2405 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2406 if (ret != SQLITE_OK) {
2407 _LOGD("Failed to commit transaction. Rollback now\n");
2408 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2412 _LOGD("Transaction Commit and End\n");
2414 pkgmgr_parser_close_db();
2418 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2420 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2422 _LOGD("manifest pointer is NULL\n");
2426 ret = pkgmgr_parser_check_and_create_db(uid);
2428 _LOGD("Failed to open DB\n");
2431 ret = pkgmgr_parser_initialize_db(uid);
2434 /*Begin transaction*/
2435 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2436 if (ret != SQLITE_OK) {
2437 _LOGD("Failed to begin transaction\n");
2441 _LOGD("Transaction Begin\n");
2442 ret = __insert_manifest_info_in_db(mfx, uid);
2444 _LOGD("Insert into 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();
2462 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2464 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, GLOBAL_USER);
2467 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2469 if (pkgid == NULL || tep_path == NULL) {
2470 _LOGE("invalid parameter");
2477 ret = pkgmgr_parser_check_and_create_db(uid);
2479 _LOGD("Failed to open DB\n");
2482 ret = pkgmgr_parser_initialize_db(uid);
2486 /*Begin transaction*/
2487 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2488 if (ret != SQLITE_OK) {
2489 _LOGD("Failed to begin transaction\n");
2493 _LOGD("Transaction Begin\n");
2496 /* Updating TEP info in "package_info" table */
2497 query = sqlite3_mprintf("UPDATE package_info "\
2498 "SET package_tep_name = %Q "\
2499 "WHERE package = %Q", tep_path, pkgid);
2501 ret = __exec_query(query);
2502 sqlite3_free(query);
2503 if (ret != SQLITE_OK) {
2504 ret = PM_PARSER_R_ERROR;
2505 _LOGE("sqlite exec failed to insert entries into package_info!!");
2509 /* Updating TEP info in "package_app_info" table */
2510 query = sqlite3_mprintf("UPDATE package_app_info "\
2511 "SET app_tep_name = %Q "\
2512 "WHERE package = %Q", tep_path, pkgid);
2514 ret = __exec_query(query);
2515 sqlite3_free(query);
2516 if (ret != SQLITE_OK) {
2517 ret = PM_PARSER_R_ERROR;
2518 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2522 /*Commit transaction*/
2523 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2524 if (ret != SQLITE_OK) {
2525 _LOGE("Failed to commit transaction, Rollback now\n");
2526 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2527 if (ret != SQLITE_OK)
2528 _LOGE("Failed to Rollback\n");
2530 ret = PM_PARSER_R_ERROR;
2533 _LOGD("Transaction Commit and End\n");
2534 ret = PM_PARSER_R_OK;
2537 pkgmgr_parser_close_db();
2542 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2545 _LOGD("manifest pointer is NULL\n");
2549 ret = pkgmgr_parser_check_and_create_db(uid);
2551 _LOGD("Failed to open DB\n");
2554 ret = pkgmgr_parser_initialize_db(uid);
2557 /*Preserve guest mode visibility*/
2558 __preserve_guestmode_visibility_value( mfx);
2559 /*Begin transaction*/
2560 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2561 if (ret != SQLITE_OK) {
2562 _LOGD("Failed to begin transaction\n");
2566 _LOGD("Transaction Begin\n");
2567 ret = __delete_manifest_info_from_db(mfx, uid);
2569 _LOGD("Delete from DB failed. Rollback now\n");
2570 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2573 ret = __insert_manifest_info_in_db(mfx, uid);
2575 _LOGD("Insert into DB failed. Rollback now\n");
2576 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2580 /*Commit transaction*/
2581 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2582 if (ret != SQLITE_OK) {
2583 _LOGD("Failed to commit transaction. Rollback now\n");
2584 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2588 _LOGD("Transaction Commit and End\n");
2590 pkgmgr_parser_close_db();
2594 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2596 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2599 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2602 _LOGD("manifest pointer is NULL\n");
2606 ret = pkgmgr_parser_check_and_create_db(uid);
2608 _LOGD("Failed to open DB\n");
2611 /*Begin transaction*/
2612 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2613 if (ret != SQLITE_OK) {
2614 _LOGD("Failed to begin transaction\n");
2618 _LOGD("Transaction Begin\n");
2619 ret = __delete_manifest_info_from_db(mfx, uid);
2621 _LOGD("Delete from DB failed. Rollback now\n");
2622 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2625 /*Commit transaction*/
2626 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2627 if (ret != SQLITE_OK) {
2628 _LOGD("Failed to commit transaction, Rollback now\n");
2629 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2633 _LOGD("Transaction Commit and End\n");
2635 pkgmgr_parser_close_db();
2639 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2641 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2644 API int pkgmgr_parser_update_preload_info_in_db()
2647 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2649 _LOGD("Failed to open DB\n");
2652 /*Begin transaction*/
2653 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2654 if (ret != SQLITE_OK) {
2655 _LOGD("Failed to begin transaction\n");
2659 _LOGD("Transaction Begin\n");
2660 ret = __update_preload_condition_in_db();
2662 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2663 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2666 /*Commit transaction*/
2667 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2668 if (ret != SQLITE_OK) {
2669 _LOGD("Failed to commit transaction, Rollback now\n");
2670 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2674 _LOGD("Transaction Commit and End\n");
2676 pkgmgr_parser_close_db();
2680 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2683 ret = pkgmgr_parser_check_and_create_db(uid);
2685 _LOGD("Failed to open DB\n");
2688 /*Begin transaction*/
2689 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2690 if (ret != SQLITE_OK) {
2691 _LOGD("Failed to begin transaction\n");
2695 _LOGD("Transaction Begin\n");
2696 ret = __update_preload_condition_in_db();
2698 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2699 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2702 /*Commit transaction*/
2703 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2704 if (ret != SQLITE_OK) {
2705 _LOGD("Failed to commit transaction, Rollback now\n");
2706 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2710 _LOGD("Transaction Commit and End\n");
2712 pkgmgr_parser_close_db();
2716 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2720 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2722 _LOGD("Failed to open DB\n");
2726 /*Begin transaction*/
2727 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2728 if (ret != SQLITE_OK) {
2729 _LOGD("Failed to begin transaction\n");
2733 _LOGD("Transaction Begin\n");
2735 ret = __disable_global_app_for_user(appid, uid);
2737 ret = __enable_global_app_for_user(appid, uid);
2739 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2740 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2743 /*Commit transaction*/
2744 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2745 if (ret != SQLITE_OK) {
2746 _LOGD("Failed to commit transaction, Rollback now\n");
2747 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2751 _LOGD("Transaction Commit and End\n");
2753 pkgmgr_parser_close_db();
2758 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2760 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, GLOBAL_USER, is_disable);
2763 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2767 ret = pkgmgr_parser_check_and_create_db(uid);
2769 _LOGD("Failed to open DB\n");
2773 /*Begin transaction*/
2774 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2775 if (ret != SQLITE_OK) {
2776 _LOGD("Failed to begin transaction\n");
2780 _LOGD("Transaction Begin\n");
2782 ret = __disable_app(appid);
2784 ret = __enable_app(appid);
2786 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2787 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2790 /*Commit transaction*/
2791 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2792 if (ret != SQLITE_OK) {
2793 _LOGD("Failed to commit transaction, Rollback now\n");
2794 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2798 _LOGD("Transaction Commit and End\n");
2800 pkgmgr_parser_close_db();