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.
27 #include <sys/types.h>
28 #include <sys/smack.h>
36 #include <system_info.h>
38 /* For multi-user support */
39 #include <tzplatform_config.h>
41 #include "pkgmgr-info.h"
42 #include "pkgmgrinfo_basic.h"
43 #include "pkgmgrinfo_debug.h"
44 #include "pkgmgr_parser_internal.h"
45 #include "pkgmgr_parser_db.h"
50 #define LOG_TAG "PKGMGR_PARSER"
52 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
53 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
54 #define MAX_QUERY_LEN 4096
62 #define XXHDPI "xxhdpi"
72 #define XXHDPI_MIN 481
73 #define XXHDPI_MAX 600
75 #define DB_LABEL "User::Home"
76 #define SET_SMACK_LABEL(x) \
78 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
79 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
81 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
84 sqlite3 *pkgmgr_parser_db;
85 sqlite3 *pkgmgr_cert_db;
88 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
89 "(package text primary key not null, " \
90 "package_type text DEFAULT 'tpk', " \
91 "package_version text, " \
92 "package_api_version text, " \
93 "package_tep_name text, " \
94 "install_location text, " \
95 "package_size text, " \
96 "package_removable text DEFAULT 'true', " \
97 "package_preload text DEFAULT 'false', " \
98 "package_readonly text DEFAULT 'false', " \
99 "package_update text DEFAULT 'false', " \
100 "package_appsetting text DEFAULT 'false', " \
101 "package_nodisplay text DEFAULT 'false', " \
102 "package_system text DEFAULT 'false', " \
103 "author_name text, " \
104 "author_email text, " \
105 "author_href text," \
106 "installed_time text," \
107 "installed_storage text," \
108 "storeclient_id text," \
110 "package_url text," \
113 "package_support_disable text DEFAULT 'false', " \
114 "package_disable text DEFAULT 'false')"
116 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
117 "(package text not null, " \
118 "package_locale text DEFAULT 'No Locale', " \
119 "package_label text, " \
120 "package_icon text, " \
121 "package_description text, " \
122 "package_license text, " \
124 "PRIMARY KEY(package, package_locale), " \
125 "FOREIGN KEY(package) " \
126 "REFERENCES package_info(package) " \
129 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
130 "(package text not null, " \
131 "privilege text not null, " \
132 "PRIMARY KEY(package, privilege) " \
133 "FOREIGN KEY(package) " \
134 "REFERENCES package_info(package) " \
137 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
138 "(app_id text primary key not null, " \
139 "app_component text, " \
141 "app_nodisplay text DEFAULT 'false', " \
143 "app_onboot text DEFAULT 'false', " \
144 "app_multiple text DEFAULT 'false', " \
145 "app_autorestart text DEFAULT 'false', " \
146 "app_taskmanage text DEFAULT 'false', " \
147 "app_enabled text DEFAULT 'true', " \
148 "app_hwacceleration text DEFAULT 'use-system-setting', " \
149 "app_screenreader text DEFAULT 'use-system-setting', " \
150 "app_mainapp text, " \
151 "app_recentimage text, " \
152 "app_launchcondition text, " \
153 "app_indicatordisplay text DEFAULT 'true', " \
154 "app_portraitimg text, " \
155 "app_landscapeimg text, " \
156 "app_guestmodevisibility text DEFAULT 'true', " \
157 "app_permissiontype text DEFAULT 'normal', " \
158 "app_preload text DEFAULT 'false', " \
159 "app_submode text DEFAULT 'false', " \
160 "app_submode_mainid text, " \
161 "app_installed_storage text, " \
162 "app_process_pool text DEFAULT 'false', " \
163 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
164 "app_ui_gadget text DEFAULT 'false', " \
165 "app_support_disable text DEFAULT 'false', " \
166 "app_disable text DEFAULT 'false', " \
167 "app_package_type text DEFAULT 'tpk', " \
168 "component_type text, " \
169 "package text not null, " \
170 "app_tep_name text, " \
171 "app_background_category INTEGER DEFAULT 0, " \
172 "app_root_path text, " \
173 "app_api_version text, " \
174 "app_effective_appid text, " \
175 "FOREIGN KEY(package) " \
176 "REFERENCES package_info(package) " \
179 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
180 "(app_id text not null, " \
181 "app_locale text DEFAULT 'No Locale', " \
184 "PRIMARY KEY(app_id,app_locale) " \
185 "FOREIGN KEY(app_id) " \
186 "REFERENCES package_app_info(app_id) " \
189 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
190 "(app_id text not null, " \
192 "app_icon_section text, " \
193 "app_icon_resolution text, " \
194 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
195 "FOREIGN KEY(app_id) " \
196 "REFERENCES package_app_info(app_id) " \
199 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
200 "(app_id text not null, " \
201 "app_locale text DEFAULT 'No Locale', " \
202 "app_image_section text, " \
204 "PRIMARY KEY(app_id,app_image_section) " \
205 "FOREIGN KEY(app_id) " \
206 "REFERENCES package_app_info(app_id) " \
209 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
210 "(app_id text not null, " \
211 "app_control text not null, " \
212 "PRIMARY KEY(app_id,app_control) " \
213 "FOREIGN KEY(app_id) " \
214 "REFERENCES package_app_info(app_id) " \
217 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
218 "(app_id text not null, " \
219 "category text not null, " \
220 "PRIMARY KEY(app_id,category) " \
221 "FOREIGN KEY(app_id) " \
222 "REFERENCES package_app_info(app_id) " \
225 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
226 "(app_id text not null, " \
227 "md_key text not null, " \
228 "md_value text not null, " \
229 "PRIMARY KEY(app_id, md_key, md_value) " \
230 "FOREIGN KEY(app_id) " \
231 "REFERENCES package_app_info(app_id) " \
234 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
235 "(app_id text not null, " \
236 "pm_type text not null, " \
237 "pm_value text not null, " \
238 "PRIMARY KEY(app_id, pm_type, pm_value) " \
239 "FOREIGN KEY(app_id) " \
240 "REFERENCES package_app_info(app_id) " \
243 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
244 "(app_id text not null, " \
245 "data_share_path text not null, " \
246 "data_share_allowed text not null, " \
247 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
248 "FOREIGN KEY(app_id) " \
249 "REFERENCES package_app_info(app_id) " \
252 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
253 "(app_id text not null, " \
254 "data_share_request text not null, " \
255 "PRIMARY KEY(app_id,data_share_request) " \
256 "FOREIGN KEY(app_id) " \
257 "REFERENCES package_app_info(app_id) " \
260 /* FIXME: duplicated at pkgmgrinfo_db.c */
261 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
262 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
263 " cert_info TEXT UNIQUE, " \
264 " cert_id INTEGER PRIMARY KEY, " \
265 " cert_ref_count INTEGER NOT NULL)"
267 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
268 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
269 " package TEXT PRIMARY KEY, " \
270 " author_root_cert INTEGER, " \
271 " author_im_cert INTEGER, " \
272 " author_signer_cert INTEGER, " \
273 " dist_root_cert INTEGER, " \
274 " dist_im_cert INTEGER, " \
275 " dist_signer_cert INTEGER, " \
276 " dist2_root_cert INTEGER, " \
277 " dist2_im_cert INTEGER, " \
278 " dist2_signer_cert INTEGER)"
280 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
281 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
282 "AFTER DELETE ON package_cert_info " \
284 " UPDATE package_cert_index_info SET" \
285 " cert_ref_count = cert_ref_count - 1" \
286 " WHERE cert_id = OLD.author_root_cert" \
287 " OR cert_id = OLD.author_im_cert" \
288 " OR cert_id = OLD.author_signer_cert" \
289 " OR cert_id = OLD.dist_root_cert" \
290 " OR cert_id = OLD.dist_im_cert" \
291 " OR cert_id = OLD.dist_signer_cert" \
292 " OR cert_id = OLD.dist2_root_cert" \
293 " OR cert_id = OLD.dist2_im_cert" \
294 " OR cert_id = OLD.dist2_signer_cert;" \
297 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
298 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
299 "AFTER UPDATE ON package_cert_index_info " \
300 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
301 " WHERE cert_id = OLD.cert_id) = 0) "\
303 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
306 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT \
307 "CREATE TRIGGER IF NOT EXISTS update_%s_info " \
308 "AFTER UPDATE ON package_cert_info " \
309 "WHEN (OLD.%s IS NOT NULL) " \
311 " UPDATE package_cert_index_info SET" \
312 " cert_ref_count = cert_ref_count - 1" \
313 " WHERE cert_id = OLD.%s;" \
316 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
317 "(app_id text not null, " \
318 "providerid text not null, " \
319 "access text not null, " \
320 "type text not null, " \
321 "PRIMARY KEY(app_id, providerid, access, type) " \
322 "FOREIGN KEY(app_id) " \
323 "REFERENCES package_app_info(app_id) " \
326 #define QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER "CREATE TABLE IF NOT EXISTS package_app_disable_for_user " \
327 "(app_id text not null, " \
328 "uid text not null, " \
329 "PRIMARY KEY(app_id, uid))"
331 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
332 "create table if not exists package_app_splash_screen " \
333 "(app_id text not null, " \
334 "src text not null, " \
335 "type text not null, " \
336 "orientation text not null, " \
337 "indicatordisplay text, " \
339 "PRIMARY KEY(app_id, orientation, operation) " \
340 "FOREIGN KEY(app_id) " \
341 "REFERENCES package_app_info(app_id) " \
344 static int __insert_application_info(manifest_x *mfx);
345 static int __insert_application_appcategory_info(manifest_x *mfx);
346 static int __insert_application_appcontrol_info(manifest_x *mfx);
347 static int __insert_application_appmetadata_info(manifest_x *mfx);
348 static int __insert_application_share_allowed_info(manifest_x *mfx);
349 static int __insert_application_share_request_info(manifest_x *mfx);
350 static int __insert_application_datacontrol_info(manifest_x *mfx);
351 static void __insert_application_locale_info(gpointer data, gpointer userdata);
352 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
353 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
354 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
355 static int __delete_subpkg_info_from_db(char *appid);
356 static int __delete_appinfo_from_db(char *db_table, const char *appid);
357 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
358 static int __exec_query(char *query);
359 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
360 char **label, char **license, char **icon, char **description, char **author);
361 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
362 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
363 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
364 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
365 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
366 static int __parserdb_change_perm(const char *db_file, uid_t uid);
368 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
371 __delete_subpkg_info_from_db(coltxt[0]);
376 static const char *__get_str(const char *str)
380 return PKGMGR_PARSER_EMPTY_STR;
386 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
391 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
392 if (ret != SQLITE_OK) {
393 _LOGD("connect db [%s] failed!\n", db_path);
401 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
403 manifest_x *mfx = (manifest_x *)data;
409 if (mfx->application == NULL)
411 app = (application_x *)mfx->application->data;
412 for(i = 0; i < ncols; i++)
414 if (strcmp(colname[i], "app_id") == 0) {
416 appid = strdup(coltxt[i]);
417 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
419 status = strdup(coltxt[i]);
425 _LOGD("app id is NULL\n");
428 /*update guest mode visibility*/
429 for (tmp = mfx->application; tmp; tmp = tmp->next) {
430 app = (application_x *)tmp->data;
433 if (strcmp(app->appid, appid) == 0) {
434 free((void *)app->guestmode_visibility);
435 app->guestmode_visibility = strdup(status);
451 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
453 char *error_message = NULL;
454 char query[MAX_QUERY_LEN] = {'\0'};
455 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
457 sqlite3_exec(pkgmgr_parser_db, query,
458 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
459 _LOGD("Don't execute query = %s error message = %s\n",
460 query, error_message);
461 sqlite3_free(error_message);
466 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
468 char *error_message = NULL;
470 sqlite3_exec(db_handle, db_query,
471 NULL, NULL, &error_message)) {
472 _LOGD("Don't execute query = %s error message = %s\n",
473 db_query, error_message);
474 sqlite3_free(error_message);
477 sqlite3_free(error_message);
481 static int __exec_query(char *query)
483 char *error_message = NULL;
485 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
486 _LOGE("Don't execute query = %s error message = %s\n", query,
488 sqlite3_free(error_message);
491 sqlite3_free(error_message);
495 static int __exec_query_no_msg(char *query)
497 char *error_message = NULL;
499 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
500 sqlite3_free(error_message);
503 sqlite3_free(error_message);
507 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
515 for (tmp = lbls; tmp; tmp = tmp->next) {
516 lbl = (label_x *)tmp->data;
520 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
522 for (tmp = lcns; tmp; tmp = tmp->next) {
523 lcn = (license_x *)tmp->data;
527 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
529 for (tmp = icns; tmp; tmp = tmp->next) {
530 icn = (icon_x *)tmp->data;
534 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
536 for (tmp = dcns; tmp; tmp = tmp->next) {
537 dcn = (description_x *)tmp->data;
541 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
543 for (tmp = aths; tmp; tmp = tmp->next) {
544 ath = (author_x *)tmp->data;
548 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
554 static GList *__create_icon_list(GList *appicon, GList *icns)
559 for (tmp = icns; tmp; tmp = tmp->next) {
560 icn = (icon_x *)tmp->data;
564 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
569 static GList *__create_image_list(GList *appimage, GList *imgs)
574 for (tmp = imgs; tmp; tmp = tmp->next) {
575 img = (image_x *)tmp->data;
579 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
584 static void __trimfunc(GList* trim_list)
586 char *trim_data = NULL;
590 list = g_list_first(trim_list);
593 trim_data = (char *)list->data;
596 if (strcmp(trim_data, prev) == 0) {
597 trim_list = g_list_remove(trim_list, trim_data);
598 list = g_list_first(trim_list);
607 list = g_list_next(list);
611 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
613 if (a == NULL || b == NULL)
615 if (strcmp((char*)a, (char*)b) == 0)
617 if (strcmp((char*)a, (char*)b) < 0)
619 if (strcmp((char*)a, (char*)b) > 0)
624 static int __check_dpi(const char *dpi_char, int dpi_int)
626 if (dpi_char == NULL)
629 if (strcasecmp(dpi_char, LDPI) == 0) {
630 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
634 } else if (strcasecmp(dpi_char, MDPI) == 0) {
635 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
639 } else if (strcasecmp(dpi_char, HDPI) == 0) {
640 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
644 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
645 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
649 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
650 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
658 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
661 char *icon_filename = NULL;
662 char modified_iconpath[BUFSIZE] = { '\0' };
663 char icon_path[BUFSIZE] = { '\0' };
667 if (orig_icon_path == NULL)
670 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
674 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
675 dpi_path[0] = "LDPI";
676 dpi_path[1] = "ldpi";
677 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
678 dpi_path[0] = "MDPI";
679 dpi_path[1] = "mdpi";
680 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
681 dpi_path[0] = "HDPI";
682 dpi_path[1] = "hdpi";
683 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
684 dpi_path[0] = "XHDPI";
685 dpi_path[1] = "xhdpi";
686 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
687 dpi_path[0] = "XXHDPI";
688 dpi_path[1] = "xxhdpi";
690 _LOGE("Unidentified dpi[%d]", dpi);
694 icon_filename = strrchr(orig_icon_path, '/');
695 if (icon_filename == NULL)
698 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
699 for (i = 0; i < 2; i++) {
700 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
701 if (access(modified_iconpath, F_OK) != -1) {
702 // if exists, return modified icon path
703 *new_icon_path = strdup(modified_iconpath);
711 static gint __compare_icon(gconstpointer a, gconstpointer b)
713 icon_x *icon = (icon_x *)a;
715 char *icon_folder_path = NULL;
717 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
720 if (icon->dpi != NULL)
723 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
725 icon->text = icon_folder_path;
731 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
733 icon_x *icon = (icon_x *)a;
734 int dpi = GPOINTER_TO_INT(b);
736 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
739 if (icon->dpi == NULL)
742 if (__check_dpi(icon->dpi, dpi) == 0)
748 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
750 icon_x *icon = (icon_x *)a;
751 char *lang = (char *)b;
752 char *icon_folder_path = NULL;
754 if (icon->dpi != NULL)
757 if (strcasecmp(icon->lang, lang) == 0) {
758 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
759 //icon for no locale. check existance of folder-hierachied default icons
760 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
762 icon->text = icon_folder_path;
771 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
773 icon_x *icon = (icon_x *)a;
774 char *lang = (char *)b;
777 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
781 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
787 static char *__find_icon(GList *icons, const char *lang)
793 // first, find icon whose locale and dpi with given lang and system's dpi has matched
794 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
796 icon = (icon_x *)tmp->data;
797 return (char *)icon->text;
800 // if first has failed, find icon whose locale has matched
801 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
803 icon = (icon_x *)tmp->data;
804 return (char *)icon->text;
807 // if second has failed, find icon whose dpi has matched with system's dpi
808 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
811 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
813 icon = (icon_x *)tmp->data;
814 return (char *)icon->text;
817 // last, find default icon marked as "No Locale"
818 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
820 icon = (icon_x *)tmp->data;
821 return (char *)icon->text;
827 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
828 char **label, char **license, char **icon, char **description, char **author)
835 for (tmp = lbls; tmp; tmp = tmp->next) {
836 lbl = (label_x *)tmp->data;
840 if (strcmp(lbl->lang, (char *)data) == 0) {
841 *label = (char*)lbl->text;
846 for (tmp = lcns; tmp; tmp = tmp->next) {
847 lcn = (license_x *)tmp->data;
851 if (strcmp(lcn->lang, (char *)data) == 0) {
852 *license = (char*)lcn->text;
858 *icon = __find_icon(icns, (char *)data);
860 for (tmp = dcns; tmp; tmp = tmp->next) {
861 dcn = (description_x *)tmp->data;
865 if (strcmp(dcn->lang, (char *)data) == 0) {
866 *description = (char*)dcn->text;
871 for (tmp = aths; tmp; tmp = tmp->next) {
872 ath = (author_x *)tmp->data;
876 if (strcmp(ath->lang, (char *)data) == 0) {
877 *author = (char*)ath->text;
885 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
889 for (tmp = icns; tmp; tmp = tmp->next) {
890 icn = (icon_x *)tmp->data;
894 if (strcmp(icn->section, (char *)data) == 0) {
895 *icon = (char*)icn->text;
896 *resolution = (char*)icn->resolution;
903 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
907 for (tmp = imgs; tmp; tmp = tmp->next) {
908 img = (image_x *)tmp->data;
912 if (strcmp(img->section, (char *)data) == 0) {
913 *lang = (char*)img->lang;
914 *image = (char*)img->text;
921 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
926 char *description = NULL;
927 char *license = NULL;
931 manifest_x *mfx = (manifest_x *)userdata;
932 GList *lbl = mfx->label;
933 GList *lcn = mfx->license;
934 GList *icn = mfx->icon;
935 GList *dcn = mfx->description;
936 GList *ath = mfx->author;
938 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
939 if (!label && !description && !icon && !license && !author)
942 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
943 "package_label, package_icon, package_description, package_license, package_author) values " \
944 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
949 __get_str(description),
953 ret = __exec_query(query);
955 _LOGD("Package Localized Info DB Insert failed\n");
960 static void __insert_application_locale_info(gpointer data, gpointer userdata)
967 application_x *app = (application_x*)userdata;
968 GList *lbl = app->label;
969 GList *icn = app->icon;
971 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
975 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
976 "app_label, app_icon) values " \
977 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
978 __get_str(label), __get_str(icon));
979 ret = __exec_query(query);
981 _LOGD("Package UiApp Localized Info DB Insert failed\n");
985 /*insert ui app locale info to pkg locale to get mainapp data */
986 if (strcasecmp(app->mainapp, "true")==0) {
987 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
988 "package_label, package_icon, package_description, package_license, package_author) values " \
989 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
994 PKGMGR_PARSER_EMPTY_STR,
995 PKGMGR_PARSER_EMPTY_STR,
996 PKGMGR_PARSER_EMPTY_STR);
998 ret = __exec_query_no_msg(query);
1002 query = sqlite3_mprintf("update package_localized_info set package_icon=%Q "\
1003 "where package=%Q and package_locale=%Q", icon, app->package, (char*)data);
1004 ret = __exec_query_no_msg(query);
1005 sqlite3_free(query);
1010 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1014 char *resolution = NULL;
1015 char query[MAX_QUERY_LEN] = {'\0'};
1017 application_x *app = (application_x*)userdata;
1018 GList *icn = app->icon;
1020 __extract_icon_data(data, icn, &icon, &resolution);
1021 if (!icon && !resolution)
1023 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
1024 "app_icon, app_icon_section, app_icon_resolution) values " \
1025 "('%q', '%q', '%q', '%q')", app->appid,
1026 icon, (char*)data, resolution);
1028 ret = __exec_query(query);
1030 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1034 static void __insert_application_image_info(gpointer data, gpointer userdata)
1039 char query[MAX_QUERY_LEN] = {'\0'};
1041 application_x *app = (application_x*)userdata;
1042 GList *image = app->image;
1044 __extract_image_data(data, image, &lang, &img);
1047 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
1048 "app_image_section, app_image) values " \
1049 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
1051 ret = __exec_query(query);
1053 _LOGD("Package UiApp image Info DB Insert failed\n");
1058 static int __insert_mainapp_info(manifest_x *mfx)
1063 char query[MAX_QUERY_LEN] = {'\0'};
1064 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1065 app = (application_x *)tmp->data;
1068 snprintf(query, MAX_QUERY_LEN,
1069 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
1071 ret = __exec_query(query);
1073 _LOGD("Package App Info DB Insert Failed\n");
1076 if (strcasecmp(app->mainapp, "True")==0)
1077 mfx->mainapp_id = strdup(app->appid);
1080 if (mfx->mainapp_id == NULL) {
1081 if (mfx->application == NULL)
1083 app = (application_x *)mfx->application->data;
1087 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
1089 _LOGD("Not valid appid\n");
1093 ret = __exec_query(query);
1095 _LOGD("Package UiApp Info DB Insert Failed\n");
1099 free((void *)app->mainapp);
1100 app->mainapp= strdup("true");
1101 mfx->mainapp_id = strdup(app->appid);
1104 memset(query, '\0', MAX_QUERY_LEN);
1105 snprintf(query, MAX_QUERY_LEN,
1106 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
1107 ret = __exec_query(query);
1109 _LOGD("Package Info DB update Failed\n");
1116 static int __convert_background_category(GList *category_list)
1119 GList *tmp_list = category_list;
1120 char *category_data = NULL;
1122 if (category_list == NULL)
1125 while (tmp_list != NULL) {
1126 category_data = (char *)tmp_list->data;
1127 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1128 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1129 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1130 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1131 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1132 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1133 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1134 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1135 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1136 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1137 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1138 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1139 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1140 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1142 _LOGE("Unidentified category [%s]", category_data);
1144 tmp_list = g_list_next(tmp_list);
1150 static const char *__find_effective_appid(GList *metadata_list)
1155 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1156 md = (metadata_x *)tmp_list->data;
1157 if (md == NULL || md->key == NULL)
1160 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1169 /* _PRODUCT_LAUNCHING_ENHANCED_
1170 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1172 static int __insert_application_info(manifest_x *mfx)
1177 int background_value = 0;
1178 char query[MAX_QUERY_LEN] = {'\0'};
1180 const char *effective_appid;
1183 type = strdup(mfx->type);
1185 type = strdup("tpk");
1187 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1188 app = (application_x *)tmp->data;
1192 background_value = __convert_background_category(app->background_category);
1193 if (background_value < 0) {
1194 _LOGE("Failed to retrieve background value[%d]", background_value);
1195 background_value = 0;
1198 effective_appid = __find_effective_appid(app->metadata);
1200 snprintf(query, MAX_QUERY_LEN,
1201 "insert into package_app_info(" \
1202 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1203 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1204 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1205 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1206 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1207 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1208 "app_tep_name, app_background_category, app_package_type, app_root_path, app_api_version, " \
1209 "app_effective_appid) " \
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', '%s', '%s', '%s', '%s', " \
1217 "'%s', '%d', '%s', '%s', '%s', " \
1219 app->appid, app->component_type, app->exec, app->nodisplay, app->type,
1220 app->onboot, app->multiple, app->autorestart, app->taskmanage, app->enabled,
1221 app->hwacceleration, app->screenreader, app->mainapp, __get_str(app->recentimage), app->launchcondition,
1222 app->indicatordisplay, __get_str(app->portraitimg), __get_str(app->landscapeimg),
1223 app->guestmode_visibility, app->permission_type,
1224 mfx->preload, app->submode, __get_str(app->submode_mainid), mfx->installed_storage, app->process_pool,
1225 app->launch_mode, app->ui_gadget, mfx->support_disable, app->component_type, mfx->package,
1226 __get_str(mfx->tep_name), background_value, type, mfx->root_path, __get_str(mfx->api_version),
1227 __get_str(effective_appid));
1229 ret = __exec_query(query);
1231 _LOGD("Package UiApp Info DB Insert Failed\n");
1236 memset(query, '\0', MAX_QUERY_LEN);
1245 static int __insert_application_appcategory_info(manifest_x *mfx)
1252 char query[MAX_QUERY_LEN] = {'\0'};
1253 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1254 app = (application_x *)app_tmp->data;
1257 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1258 ct = (const char *)ct_tmp->data;
1261 snprintf(query, MAX_QUERY_LEN,
1262 "insert into package_app_app_category(app_id, category) " \
1263 "values('%s','%s')",\
1265 ret = __exec_query(query);
1267 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1270 memset(query, '\0', MAX_QUERY_LEN);
1276 static int __insert_application_appmetadata_info(manifest_x *mfx)
1283 char query[MAX_QUERY_LEN] = {'\0'};
1284 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1285 app = (application_x *)app_tmp->data;
1288 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1289 md = (metadata_x *)md_tmp->data;
1293 snprintf(query, MAX_QUERY_LEN,
1294 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1295 "values('%s','%s', '%s')",\
1296 app->appid, md->key, md->value ? md->value : "");
1297 ret = __exec_query(query);
1299 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1303 memset(query, '\0', MAX_QUERY_LEN);
1309 static int __insert_application_apppermission_info(manifest_x *mfx)
1316 char query[MAX_QUERY_LEN] = {'\0'};
1317 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1318 app = (application_x *)app_tmp->data;
1321 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1322 pm = (permission_x *)pm_tmp->data;
1325 snprintf(query, MAX_QUERY_LEN,
1326 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1327 "values('%s','%s', '%s')",\
1328 app->appid, pm->type, pm->value);
1329 ret = __exec_query(query);
1331 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1334 memset(query, '\0', MAX_QUERY_LEN);
1340 static int __insert_application_appcontrol_info(manifest_x *mfx)
1344 GList *acontrol_tmp;
1345 appcontrol_x *acontrol;
1347 char query[MAX_QUERY_LEN] = {'\0'};
1348 char buf[BUFSIZE] = {'\0'};
1349 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1350 app = (application_x *)app_tmp->data;
1353 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1354 acontrol = (appcontrol_x *)acontrol_tmp->data;
1355 if (acontrol == NULL)
1357 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1358 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1359 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1360 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1361 snprintf(query, MAX_QUERY_LEN,
1362 "insert into package_app_app_control(app_id, app_control) " \
1363 "values('%s', '%s')",\
1365 ret = __exec_query(query);
1367 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1370 memset(query, '\0', MAX_QUERY_LEN);
1376 static int __insert_application_datacontrol_info(manifest_x *mfx)
1383 char query[MAX_QUERY_LEN] = {'\0'};
1385 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1386 app = (application_x *)app_tmp->data;
1389 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1390 dc = (datacontrol_x *)dc_tmp->data;
1393 snprintf(query, MAX_QUERY_LEN,
1394 "insert into package_app_data_control(app_id, providerid, access, type) " \
1395 "values('%s', '%s', '%s', '%s')",\
1401 ret = __exec_query(query);
1403 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1406 memset(query, '\0', MAX_QUERY_LEN);
1412 static int __insert_application_share_request_info(manifest_x *mfx)
1421 char query[MAX_QUERY_LEN] = {'\0'};
1422 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1423 app = (application_x *)app_tmp->data;
1426 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1427 ds = (datashare_x *)ds_tmp->data;
1430 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1431 rq = (const char *)rq_tmp->data;
1434 snprintf(query, MAX_QUERY_LEN,
1435 "insert into package_app_share_request(app_id, data_share_request) " \
1436 "values('%s', '%s')",\
1438 ret = __exec_query(query);
1440 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1443 memset(query, '\0', MAX_QUERY_LEN);
1450 static int __insert_application_share_allowed_info(manifest_x *mfx)
1461 char query[MAX_QUERY_LEN] = {'\0'};
1462 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1463 app = (application_x *)app_tmp->data;
1466 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1467 ds = (datashare_x *)ds_tmp->data;
1470 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1471 df = (define_x *)df_tmp->data;
1474 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1475 al = (const char *)al_tmp->data;
1478 snprintf(query, MAX_QUERY_LEN,
1479 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1480 "values('%s', '%s', '%s')",\
1481 app->appid, df->path, al);
1482 ret = __exec_query(query);
1484 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1487 memset(query, '\0', MAX_QUERY_LEN);
1495 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1497 splashscreen_x *ss = (splashscreen_x *)a;
1498 const char *orientation = (const char *)b;
1501 if (ss->operation || ss->dpi == NULL)
1504 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1508 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1514 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1516 splashscreen_x *ss = (splashscreen_x *)a;
1517 const char *orientation = (const char *)b;
1519 if (ss->operation || ss->dpi)
1522 if (strcasecmp(ss->orientation, orientation) == 0)
1528 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1529 const char *orientation)
1533 tmp = g_list_find_custom(splashscreens, orientation,
1534 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1536 return (splashscreen_x *)tmp->data;
1538 tmp = g_list_find_custom(splashscreens, orientation,
1539 (GCompareFunc)__compare_splashscreen_with_orientation);
1541 return (splashscreen_x *)tmp->data;
1546 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1548 splashscreen_x *ss = (splashscreen_x *)data;
1549 GList **list = (GList **)user_data;
1552 if (ss->operation == NULL || ss->dpi == NULL)
1555 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1559 if (__check_dpi(ss->dpi, dpi) != 0)
1562 *list = g_list_append(*list, ss);
1565 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1567 splashscreen_x *ss = (splashscreen_x *)data;
1568 GList **list = (GList **)user_data;
1569 splashscreen_x *ss_tmp;
1572 if (ss->operation == NULL || ss->dpi)
1575 for (tmp = *list; tmp; tmp = tmp->next) {
1576 ss_tmp = (splashscreen_x *)tmp->data;
1577 if (ss_tmp->operation
1578 && strcmp(ss_tmp->operation, ss->operation) == 0
1579 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1583 *list = g_list_append(*list, ss);
1586 static GList *__find_splashscreens(GList *splashscreens)
1591 g_list_foreach(splashscreens,
1592 __find_appcontrol_splashscreen_with_dpi, &list);
1593 g_list_foreach(splashscreens,
1594 __find_appcontrol_splashscreen, &list);
1596 ss = __find_default_splashscreen(splashscreens, "portrait");
1598 list = g_list_append(list, ss);
1599 ss = __find_default_splashscreen(splashscreens, "landscape");
1601 list = g_list_append(list, ss);
1606 static int __insert_application_splashscreen_info(manifest_x *mfx)
1614 char query[MAX_QUERY_LEN];
1616 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1617 app = (application_x *)app_tmp->data;
1618 if (app == NULL || app->splashscreens == NULL)
1621 ss_tmp = __find_splashscreens(app->splashscreens);
1625 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1626 ss = (splashscreen_x *)tmp->data;
1627 snprintf(query, sizeof(query),
1628 "insert into package_app_splash_screen" \
1629 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1630 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1631 app->appid, ss->src, ss->type, ss->orientation,
1632 ss->indicatordisplay, __get_str(ss->operation));
1633 ret = __exec_query(query);
1635 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1638 memset(query, '\0', MAX_QUERY_LEN);
1640 g_list_free(ss_tmp);
1645 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1650 char query[MAX_QUERY_LEN];
1652 const char *image_type;
1653 const char *indicatordisplay;
1654 const char *orientation;
1655 const char *operation = NULL;
1657 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1658 app = (application_x *)app_tmp->data;
1660 (app->portraitimg == NULL && app->landscapeimg == NULL))
1662 image_type = "img"; /* default */
1663 if (app->effectimage_type) {
1664 tmp = strstr(app->effectimage_type, "edj");
1668 indicatordisplay = "true"; /* default */
1669 if (app->indicatordisplay)
1670 indicatordisplay = app->indicatordisplay;
1671 if (app->portraitimg) {
1672 orientation = "portrait";
1673 snprintf(query, sizeof(query),
1674 "insert into package_app_splash_screen" \
1675 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1676 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1677 app->appid, app->portraitimg, image_type,
1678 orientation, indicatordisplay, __get_str(operation));
1679 ret = __exec_query(query);
1681 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1684 memset(query, '\0', MAX_QUERY_LEN);
1686 if (app->landscapeimg) {
1687 orientation = "landscape";
1688 snprintf(query, sizeof(query),
1689 "insert into package_app_splash_screen" \
1690 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1691 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1692 app->appid, app->landscapeimg, image_type,
1693 orientation, indicatordisplay, __get_str(operation));
1694 ret = __exec_query(query);
1696 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1699 memset(query, '\0', MAX_QUERY_LEN);
1705 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1712 char query[MAX_QUERY_LEN];
1714 const char *operation;
1715 const char *portraitimg;
1716 const char *landscapeimg;
1717 const char *indicatordisplay;
1718 const char *orientation;
1719 const char *image_type;
1721 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1722 app = (application_x *)app_tmp->data;
1726 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1727 md = (metadata_x *)md_tmp->data;
1728 if (md == NULL || md->key == NULL || md->value == NULL)
1731 if (strcasestr(md->key, "operation_effect=")) {
1732 operation = index(md->key, '=');
1733 if ((operation + 1) != NULL)
1737 } else if (strcasestr(md->key, "launch_effect")) {
1744 landscapeimg = NULL;
1745 indicatordisplay = "true"; /* default */
1746 token = strtok(md->value, "|");
1747 while (token != NULL) {
1748 if (strcasestr(token, "portrait-effectimage=")) {
1749 portraitimg = index(token, '=');
1750 if ((portraitimg + 1) != NULL)
1754 } else if (strcasestr(token, "landscape-effectimage=")) {
1755 landscapeimg = index(token, '=');
1756 if ((landscapeimg + 1) != NULL)
1759 landscapeimg = NULL;
1760 } else if (strcasestr(token, "indicatordisplay=")) {
1761 indicatordisplay = index(token, '=');
1762 if ((indicatordisplay + 1) != NULL)
1765 indicatordisplay = "true";
1768 token = strtok(NULL, "|");
1772 orientation = "portrait";
1774 if (strcasestr(portraitimg, "edj"))
1776 snprintf(query, sizeof(query),
1777 "insert into package_app_splash_screen" \
1778 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1779 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1780 app->appid, portraitimg, image_type,
1781 orientation, indicatordisplay, __get_str(operation));
1782 ret = __exec_query(query);
1784 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1787 memset(query, '\0', MAX_QUERY_LEN);
1790 orientation = "landscape";
1792 if (strcasestr(landscapeimg, "edj"))
1794 snprintf(query, sizeof(query),
1795 "insert into package_app_splash_screen" \
1796 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1797 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1798 app->appid, landscapeimg, image_type,
1799 orientation, indicatordisplay, __get_str(operation));
1800 ret = __exec_query(query);
1802 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1805 memset(query, '\0', MAX_QUERY_LEN);
1813 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1817 const char *pv = NULL;
1818 char query[MAX_QUERY_LEN] = { '\0' };
1821 const char *auth_name = NULL;
1822 const char *auth_email = NULL;
1823 const char *auth_href = NULL;
1825 GList *pkglocale = NULL;
1826 GList *applocale = NULL;
1827 GList *appicon = NULL;
1828 GList *appimage = NULL;
1830 if (mfx->author && mfx->author->data) {
1831 author = (author_x *)mfx->author->data;
1833 auth_name = author->text;
1835 auth_email = author->email;
1837 auth_href = author->href;
1840 /*Insert in the package_cert_info CERT_DB*/
1841 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1842 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1843 if (ret != PMINFO_R_OK) {
1844 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1845 _LOGE("Cert Info DB create handle failed\n");
1848 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1849 if (ret != PMINFO_R_OK) {
1850 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1851 _LOGE("Cert Info DB Insert Failed\n");
1855 /*Insert in the package_info DB*/
1856 snprintf(query, MAX_QUERY_LEN,
1857 "insert into package_info(" \
1858 "package, package_type, package_version, package_api_version, package_tep_name, " \
1859 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1860 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1861 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1862 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1864 "'%s', '%s', '%s', '%s', '%s', " \
1865 "'%s', '%s', '%s', '%s', '%s', " \
1866 "'%s', '%s', '%s', '%s', '%s', " \
1867 "'%s', '%s', '%s', '%s', '%s', " \
1868 "'%s', '%s', '%s', '%s', '%s')", \
1869 mfx->package, mfx->type, mfx->version, __get_str(mfx->api_version), __get_str(mfx->tep_name),
1870 __get_str(mfx->installlocation), __get_str(mfx->package_size), mfx->removable, mfx->preload, mfx->readonly,
1871 mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system, __get_str(auth_name),
1872 __get_str(auth_email), __get_str(auth_href), mfx->installed_time, mfx->installed_storage,
1873 __get_str(mfx->storeclient_id),
1874 mfx->mainapp_id, __get_str(mfx->package_url), mfx->root_path, __get_str(mfx->csc_path), mfx->support_disable);
1876 ret = __exec_query(query);
1878 _LOGD("Package Info DB Insert Failed\n");
1882 /*Insert in the package_privilege_info DB*/
1883 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1884 pv = (const char *)tmp->data;
1887 memset(query, '\0', MAX_QUERY_LEN);
1888 snprintf(query, MAX_QUERY_LEN,
1889 "insert into package_privilege_info(package, privilege) " \
1890 "values('%s','%s')",\
1892 ret = __exec_query(query);
1894 _LOGD("Package Privilege Info DB Insert Failed\n");
1899 if (mfx->application != NULL) {
1900 ret = __insert_mainapp_info(mfx);
1905 /*Insert the package locale*/
1906 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1907 /*remove duplicated data in pkglocale*/
1908 __trimfunc(pkglocale);
1910 /*Insert the app locale, icon, image info */
1911 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1912 app = (application_x *)tmp->data;
1915 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1916 appicon = __create_icon_list(appicon, app->icon);
1917 appimage = __create_image_list(appimage, app->image);
1919 /*remove duplicated data in applocale*/
1920 __trimfunc(applocale);
1921 __trimfunc(appicon);
1922 __trimfunc(appimage);
1924 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1926 /*native app locale info*/
1927 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1928 app = (application_x *)tmp->data;
1931 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1932 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1933 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1936 g_list_free(pkglocale);
1938 g_list_free(applocale);
1940 g_list_free(appicon);
1942 g_list_free(appimage);
1945 /*Insert in the package_app_info DB*/
1946 ret = __insert_application_info(mfx);
1949 /*Insert in the package_app_app_control DB*/
1950 ret = __insert_application_appcontrol_info(mfx);
1954 /*Insert in the package_app_app_category DB*/
1955 ret = __insert_application_appcategory_info(mfx);
1959 /*Insert in the package_app_app_metadata DB*/
1960 ret = __insert_application_appmetadata_info(mfx);
1964 /*Insert in the package_app_app_permission DB*/
1965 ret = __insert_application_apppermission_info(mfx);
1969 /*Insert in the package_app_share_allowed DB*/
1970 ret = __insert_application_share_allowed_info(mfx);
1974 /*Insert in the package_app_share_request DB*/
1975 ret = __insert_application_share_request_info(mfx);
1979 /*Insert in the package_app_data_control DB*/
1980 ret = __insert_application_datacontrol_info(mfx);
1984 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
1985 ret = __insert_application_legacy_splashscreen_info(mfx);
1989 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
1990 ret = __insert_application_metadata_splashscreen_info(mfx);
1994 /*Insert in the package_app_splash_screen DB*/
1995 ret = __insert_application_splashscreen_info(mfx);
2003 static int __delete_appinfo_from_db(char *db_table, const char *appid)
2005 char query[MAX_QUERY_LEN] = { '\0' };
2007 memset(query, '\0', MAX_QUERY_LEN);
2008 snprintf(query, MAX_QUERY_LEN,
2009 "delete from %s where app_id='%s'", db_table, appid);
2010 ret = __exec_query(query);
2012 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
2018 static int __delete_subpkg_info_from_db(char *appid)
2022 ret = __delete_appinfo_from_db("package_app_info", appid);
2025 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
2028 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
2031 ret = __delete_appinfo_from_db("package_app_image_info", appid);
2034 ret = __delete_appinfo_from_db("package_app_app_control", appid);
2037 ret = __delete_appinfo_from_db("package_app_app_category", appid);
2040 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
2043 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
2046 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
2049 ret = __delete_appinfo_from_db("package_app_share_request", appid);
2052 ret = __delete_appinfo_from_db("package_app_data_control", appid);
2055 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
2062 static int __delete_subpkg_from_db(manifest_x *mfx)
2064 char query[MAX_QUERY_LEN] = { '\0' };
2065 char *error_message = NULL;
2067 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
2069 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
2070 _LOGE("Don't execute query = %s error message = %s\n", query,
2072 sqlite3_free(error_message);
2075 sqlite3_free(error_message);
2080 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
2082 char query[MAX_QUERY_LEN] = { '\0' };
2086 /*Delete from cert table*/
2087 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2089 _LOGD("Cert Info DB Delete Failed\n");
2093 /*Delete from Package Info DB*/
2094 snprintf(query, MAX_QUERY_LEN,
2095 "delete from package_info where package='%s'", mfx->package);
2096 ret = __exec_query(query);
2098 _LOGD("Package Info DB Delete Failed\n");
2101 memset(query, '\0', MAX_QUERY_LEN);
2103 /*Delete from Package Localized Info*/
2104 snprintf(query, MAX_QUERY_LEN,
2105 "delete from package_localized_info where package='%s'", mfx->package);
2106 ret = __exec_query(query);
2108 _LOGD("Package Localized Info DB Delete Failed\n");
2112 /*Delete from Package Privilege Info*/
2113 snprintf(query, MAX_QUERY_LEN,
2114 "delete from package_privilege_info where package='%s'", mfx->package);
2115 ret = __exec_query(query);
2117 _LOGD("Package Privilege Info DB Delete Failed\n");
2121 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2122 app = (application_x *)tmp->data;
2125 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2128 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2131 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2134 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2137 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2140 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2143 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2146 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2149 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2152 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2155 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2158 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2163 /* if main package has sub pkg, delete sub pkg data*/
2164 __delete_subpkg_from_db(mfx);
2169 static int __disable_app(const char *appid)
2172 char query[MAX_QUERY_LEN] = {'\0'};
2173 sqlite3_snprintf(MAX_QUERY_LEN, query,
2174 "UPDATE package_app_info set app_disable='true' where app_id=%Q",
2176 ret = __exec_query(query);
2178 _LOGD("Insert global app disable failed\n");
2183 static int __enable_app(const char *appid)
2186 char query[MAX_QUERY_LEN] = {'\0'};
2187 sqlite3_snprintf(MAX_QUERY_LEN, query,
2188 "UPDATE package_app_info set app_disable='false' where app_id=%Q",
2190 ret = __exec_query(query);
2192 _LOGD("Insert global app disable failed\n");
2197 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2200 char query[MAX_QUERY_LEN] = {'\0'};
2202 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO " \
2203 "package_app_disable_for_user(app_id, uid) VALUES(%Q, '%d')",
2205 ret = __exec_query(query);
2207 _LOGD("Insert global app disable failed\n");
2212 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2215 char query[MAX_QUERY_LEN] = {'\0'};
2217 sqlite3_snprintf(MAX_QUERY_LEN, query, "DELETE FROM " \
2218 "package_app_disable_for_user WHERE app_id=%Q AND uid='%d'",
2220 ret = __exec_query(query);
2222 _LOGD("Delete global app disable failed\n");
2227 static int __update_preload_condition_in_db()
2230 char query[MAX_QUERY_LEN] = {'\0'};
2232 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2234 ret = __exec_query(query);
2236 _LOGD("Package preload_condition update failed\n");
2241 API int pkgmgr_parser_initialize_db(uid_t uid)
2245 char query[MAX_QUERY_LEN];
2246 static const char *columns[] = {
2247 "author_root_cert", "author_im_cert", "author_signer_cert",
2248 "dist_root_cert", "dist_im_cert", "dist_signer_cert",
2249 "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
2253 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2255 _LOGD("package info DB initialization failed\n");
2258 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2260 _LOGD("package localized info DB initialization failed\n");
2263 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2265 _LOGD("package app app privilege DB initialization failed\n");
2268 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2270 _LOGD("package app info DB initialization failed\n");
2273 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2275 _LOGD("package app localized info DB initialization failed\n");
2278 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2280 _LOGD("package app icon localized info DB initialization failed\n");
2283 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2285 _LOGD("package app image info DB initialization failed\n");
2288 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2290 _LOGD("package app app control DB initialization failed\n");
2293 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2295 _LOGD("package app app category DB initialization failed\n");
2298 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2300 _LOGD("package app app category DB initialization failed\n");
2303 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2305 _LOGD("package app app permission DB initialization failed\n");
2308 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2310 _LOGD("package app share allowed DB initialization failed\n");
2313 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2315 _LOGD("package app share request DB initialization failed\n");
2318 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2320 _LOGD("package app data control DB initialization failed\n");
2324 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER);
2326 _LOGD("package app disable for user DB initialization failed\n");
2330 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2332 _LOGD("package app splash screen DB initialization failed\n");
2337 /* TODO: refactor this code */
2338 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2340 _LOGD("package cert info DB initialization failed\n");
2343 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2345 _LOGD("package cert index info DB initialization failed\n");
2348 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2350 _LOGD("package cert info DB initialization failed\n");
2353 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2355 _LOGD("package cert index info DB initialization failed\n");
2358 for (i = 0; columns[i] != NULL; i++) {
2359 snprintf(query, sizeof(query),
2360 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
2361 columns[i], columns[i], columns[i]);
2362 ret = __initialize_db(pkgmgr_cert_db, query);
2364 _LOGD("package cert index info DB initialization failed\n");
2369 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
2370 _LOGD("Failed to change cert db permission\n");
2372 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2373 _LOGD("Failed to change parser db permission\n");
2379 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2382 char journal_file[BUFSIZE];
2385 struct passwd *userinfo = NULL;
2386 files[0] = (char *)db_file;
2387 files[1] = journal_file;
2391 if (db_file == NULL)
2394 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2396 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2397 if (uid == OWNER_ROOT)
2399 userinfo = getpwuid(uid);
2401 _LOGE("FAIL: user %d doesn't exist", uid);
2404 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2406 for (i = 0; files[i]; i++) {
2407 ret = chown(files[i], uid, userinfo->pw_gid);
2409 if (strerror_r(errno, buf, sizeof(buf)))
2410 strncpy(buf, "", BUFSIZE - 1);
2411 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2412 userinfo->pw_gid, buf);
2416 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2417 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2419 ret = chmod(files[i], mode);
2421 if (strerror_r(errno, buf, sizeof(buf)))
2422 strncpy(buf, "", BUFSIZE - 1);
2423 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2426 SET_SMACK_LABEL(files[i]);
2431 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2435 if (getuid() != OWNER_ROOT) {
2436 _LOGE("Only root user is allowed");
2440 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2441 _LOGE("Manifest db for user %d is already exists", uid);
2445 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2446 _LOGE("Cert db for user %d is already exists", uid);
2450 ret = pkgmgr_parser_check_and_create_db(uid);
2453 ret = pkgmgr_parser_initialize_db(uid);
2455 pkgmgr_parser_close_db();
2458 pkgmgr_parser_close_db();
2463 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2467 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2469 _LOGD("Manifest DB creation Failed\n");
2474 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2476 _LOGD("Cert DB creation Failed\n");
2482 void pkgmgr_parser_close_db(void)
2484 sqlite3_close(pkgmgr_parser_db);
2485 sqlite3_close(pkgmgr_cert_db);
2489 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2491 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2493 _LOGD("manifest pointer is NULL\n");
2497 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2499 _LOGD("Failed to open DB\n");
2502 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2505 /*Begin transaction*/
2506 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2507 if (ret != SQLITE_OK) {
2508 _LOGD("Failed to begin transaction\n");
2512 _LOGD("Transaction Begin\n");
2513 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2515 _LOGD("Insert into DB failed. Rollback now\n");
2516 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2519 /*Commit transaction*/
2520 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2521 if (ret != SQLITE_OK) {
2522 _LOGD("Failed to commit transaction. Rollback now\n");
2523 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2527 _LOGD("Transaction Commit and End\n");
2529 pkgmgr_parser_close_db();
2533 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2535 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2537 _LOGD("manifest pointer is NULL\n");
2541 ret = pkgmgr_parser_check_and_create_db(uid);
2543 _LOGD("Failed to open DB\n");
2546 ret = pkgmgr_parser_initialize_db(uid);
2549 /*Begin transaction*/
2550 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2551 if (ret != SQLITE_OK) {
2552 _LOGD("Failed to begin transaction\n");
2556 _LOGD("Transaction Begin\n");
2557 ret = __insert_manifest_info_in_db(mfx, uid);
2559 _LOGD("Insert into DB failed. Rollback now\n");
2560 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2563 /*Commit transaction*/
2564 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2565 if (ret != SQLITE_OK) {
2566 _LOGD("Failed to commit transaction. Rollback now\n");
2567 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2571 _LOGD("Transaction Commit and End\n");
2573 pkgmgr_parser_close_db();
2577 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2579 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, GLOBAL_USER);
2582 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2584 if (pkgid == NULL || tep_path == NULL) {
2585 _LOGE("invalid parameter");
2592 ret = pkgmgr_parser_check_and_create_db(uid);
2594 _LOGD("Failed to open DB\n");
2597 ret = pkgmgr_parser_initialize_db(uid);
2601 /*Begin transaction*/
2602 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2603 if (ret != SQLITE_OK) {
2604 _LOGD("Failed to begin transaction\n");
2608 _LOGD("Transaction Begin\n");
2611 /* Updating TEP info in "package_info" table */
2612 query = sqlite3_mprintf("UPDATE package_info "\
2613 "SET package_tep_name = %Q "\
2614 "WHERE package = %Q", tep_path, pkgid);
2616 ret = __exec_query(query);
2617 sqlite3_free(query);
2618 if (ret != SQLITE_OK) {
2619 ret = PM_PARSER_R_ERROR;
2620 _LOGE("sqlite exec failed to insert entries into package_info!!");
2624 /* Updating TEP info in "package_app_info" table */
2625 query = sqlite3_mprintf("UPDATE package_app_info "\
2626 "SET app_tep_name = %Q "\
2627 "WHERE package = %Q", tep_path, pkgid);
2629 ret = __exec_query(query);
2630 sqlite3_free(query);
2631 if (ret != SQLITE_OK) {
2632 ret = PM_PARSER_R_ERROR;
2633 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2637 /*Commit transaction*/
2638 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2639 if (ret != SQLITE_OK) {
2640 _LOGE("Failed to commit transaction, Rollback now\n");
2641 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2642 if (ret != SQLITE_OK)
2643 _LOGE("Failed to Rollback\n");
2645 ret = PM_PARSER_R_ERROR;
2648 _LOGD("Transaction Commit and End\n");
2649 ret = PM_PARSER_R_OK;
2652 pkgmgr_parser_close_db();
2657 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2660 _LOGD("manifest pointer is NULL\n");
2664 ret = pkgmgr_parser_check_and_create_db(uid);
2666 _LOGD("Failed to open DB\n");
2669 ret = pkgmgr_parser_initialize_db(uid);
2672 /*Preserve guest mode visibility*/
2673 __preserve_guestmode_visibility_value( mfx);
2674 /*Begin transaction*/
2675 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2676 if (ret != SQLITE_OK) {
2677 _LOGD("Failed to begin transaction\n");
2681 _LOGD("Transaction Begin\n");
2682 ret = __delete_manifest_info_from_db(mfx, uid);
2684 _LOGD("Delete from DB failed. Rollback now\n");
2685 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2688 ret = __insert_manifest_info_in_db(mfx, uid);
2690 _LOGD("Insert into DB failed. Rollback now\n");
2691 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2695 /*Commit transaction*/
2696 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2697 if (ret != SQLITE_OK) {
2698 _LOGD("Failed to commit transaction. Rollback now\n");
2699 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2703 _LOGD("Transaction Commit and End\n");
2705 pkgmgr_parser_close_db();
2709 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2711 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2714 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2717 _LOGD("manifest pointer is NULL\n");
2721 ret = pkgmgr_parser_check_and_create_db(uid);
2723 _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");
2734 ret = __delete_manifest_info_from_db(mfx, uid);
2736 _LOGD("Delete from DB failed. Rollback now\n");
2737 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2740 /*Commit transaction*/
2741 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2742 if (ret != SQLITE_OK) {
2743 _LOGD("Failed to commit transaction, Rollback now\n");
2744 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2748 _LOGD("Transaction Commit and End\n");
2750 pkgmgr_parser_close_db();
2754 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2756 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2759 API int pkgmgr_parser_update_preload_info_in_db()
2762 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2764 _LOGD("Failed to open DB\n");
2767 /*Begin transaction*/
2768 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2769 if (ret != SQLITE_OK) {
2770 _LOGD("Failed to begin transaction\n");
2774 _LOGD("Transaction Begin\n");
2775 ret = __update_preload_condition_in_db();
2777 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2778 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2781 /*Commit transaction*/
2782 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2783 if (ret != SQLITE_OK) {
2784 _LOGD("Failed to commit transaction, Rollback now\n");
2785 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2789 _LOGD("Transaction Commit and End\n");
2791 pkgmgr_parser_close_db();
2795 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2798 ret = pkgmgr_parser_check_and_create_db(uid);
2800 _LOGD("Failed to open DB\n");
2803 /*Begin transaction*/
2804 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2805 if (ret != SQLITE_OK) {
2806 _LOGD("Failed to begin transaction\n");
2810 _LOGD("Transaction Begin\n");
2811 ret = __update_preload_condition_in_db();
2813 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2814 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2817 /*Commit transaction*/
2818 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2819 if (ret != SQLITE_OK) {
2820 _LOGD("Failed to commit transaction, Rollback now\n");
2821 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2825 _LOGD("Transaction Commit and End\n");
2827 pkgmgr_parser_close_db();
2831 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2835 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2837 _LOGD("Failed to open DB\n");
2841 /*Begin transaction*/
2842 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2843 if (ret != SQLITE_OK) {
2844 _LOGD("Failed to begin transaction\n");
2848 _LOGD("Transaction Begin\n");
2850 ret = __disable_global_app_for_user(appid, uid);
2852 ret = __enable_global_app_for_user(appid, uid);
2854 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2855 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2858 /*Commit transaction*/
2859 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2860 if (ret != SQLITE_OK) {
2861 _LOGD("Failed to commit transaction, Rollback now\n");
2862 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2866 _LOGD("Transaction Commit and End\n");
2868 pkgmgr_parser_close_db();
2873 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2875 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, GLOBAL_USER, is_disable);
2878 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2882 ret = pkgmgr_parser_check_and_create_db(uid);
2884 _LOGD("Failed to open DB\n");
2888 /*Begin transaction*/
2889 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2890 if (ret != SQLITE_OK) {
2891 _LOGD("Failed to begin transaction\n");
2895 _LOGD("Transaction Begin\n");
2897 ret = __disable_app(appid);
2899 ret = __enable_app(appid);
2901 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2902 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2905 /*Commit transaction*/
2906 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2907 if (ret != SQLITE_OK) {
2908 _LOGD("Failed to commit transaction, Rollback now\n");
2909 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2913 _LOGD("Transaction Commit and End\n");
2915 pkgmgr_parser_close_db();