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 "package_zip_mount_file text, " \
95 "install_location text, " \
96 "package_size text, " \
97 "package_removable text DEFAULT 'true', " \
98 "package_preload text DEFAULT 'false', " \
99 "package_readonly text DEFAULT 'false', " \
100 "package_update text DEFAULT 'false', " \
101 "package_appsetting text DEFAULT 'false', " \
102 "package_nodisplay text DEFAULT 'false', " \
103 "package_system text DEFAULT 'false', " \
104 "author_name text, " \
105 "author_email text, " \
106 "author_href text," \
107 "installed_time text," \
108 "installed_storage text," \
109 "storeclient_id text," \
111 "package_url text," \
114 "package_support_disable text DEFAULT 'false', " \
115 "package_disable text DEFAULT 'false')"
117 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
118 "(package text not null, " \
119 "package_locale text DEFAULT 'No Locale', " \
120 "package_label text, " \
121 "package_icon text, " \
122 "package_description text, " \
123 "package_license text, " \
125 "PRIMARY KEY(package, package_locale), " \
126 "FOREIGN KEY(package) " \
127 "REFERENCES package_info(package) " \
130 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
131 "(package text not null, " \
132 "privilege text not null, " \
133 "PRIMARY KEY(package, privilege) " \
134 "FOREIGN KEY(package) " \
135 "REFERENCES package_info(package) " \
138 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
139 "(app_id text primary key not null, " \
140 "app_component text, " \
142 "app_nodisplay text DEFAULT 'false', " \
144 "app_onboot text DEFAULT 'false', " \
145 "app_multiple text DEFAULT 'false', " \
146 "app_autorestart text DEFAULT 'false', " \
147 "app_taskmanage text DEFAULT 'false', " \
148 "app_enabled text DEFAULT 'true', " \
149 "app_hwacceleration text DEFAULT 'use-system-setting', " \
150 "app_screenreader text DEFAULT 'use-system-setting', " \
151 "app_mainapp text, " \
152 "app_recentimage text, " \
153 "app_launchcondition text, " \
154 "app_indicatordisplay text DEFAULT 'true', " \
155 "app_portraitimg text, " \
156 "app_landscapeimg text, " \
157 "app_guestmodevisibility text DEFAULT 'true', " \
158 "app_permissiontype text DEFAULT 'normal', " \
159 "app_preload text DEFAULT 'false', " \
160 "app_submode text DEFAULT 'false', " \
161 "app_submode_mainid text, " \
162 "app_installed_storage text, " \
163 "app_process_pool text DEFAULT 'false', " \
164 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
165 "app_ui_gadget text DEFAULT 'false', " \
166 "app_support_disable text DEFAULT 'false', " \
167 "app_disable text DEFAULT 'false', " \
168 "app_package_type text DEFAULT 'tpk', " \
169 "component_type text, " \
170 "package text not null, " \
171 "app_tep_name text, " \
172 "app_zip_mount_file text, " \
173 "app_background_category INTEGER DEFAULT 0, " \
174 "app_root_path text, " \
175 "app_api_version text, " \
176 "app_effective_appid text, " \
177 "app_splash_screen_display text DEFAULT 'true', " \
178 "FOREIGN KEY(package) " \
179 "REFERENCES package_info(package) " \
182 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
183 "(app_id text not null, " \
184 "app_locale text DEFAULT 'No Locale', " \
187 "PRIMARY KEY(app_id,app_locale) " \
188 "FOREIGN KEY(app_id) " \
189 "REFERENCES package_app_info(app_id) " \
192 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
193 "(app_id text not null, " \
195 "app_icon_section text, " \
196 "app_icon_resolution text, " \
197 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
198 "FOREIGN KEY(app_id) " \
199 "REFERENCES package_app_info(app_id) " \
202 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
203 "(app_id text not null, " \
204 "app_locale text DEFAULT 'No Locale', " \
205 "app_image_section text, " \
207 "PRIMARY KEY(app_id,app_image_section) " \
208 "FOREIGN KEY(app_id) " \
209 "REFERENCES package_app_info(app_id) " \
212 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
213 "(app_id text not null, " \
214 "app_control text not null, " \
215 "PRIMARY KEY(app_id,app_control) " \
216 "FOREIGN KEY(app_id) " \
217 "REFERENCES package_app_info(app_id) " \
220 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
221 "(app_id text not null, " \
222 "category text not null, " \
223 "PRIMARY KEY(app_id,category) " \
224 "FOREIGN KEY(app_id) " \
225 "REFERENCES package_app_info(app_id) " \
228 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
229 "(app_id text not null, " \
230 "md_key text not null, " \
231 "md_value text not null, " \
232 "PRIMARY KEY(app_id, md_key, md_value) " \
233 "FOREIGN KEY(app_id) " \
234 "REFERENCES package_app_info(app_id) " \
237 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
238 "(app_id text not null, " \
239 "pm_type text not null, " \
240 "pm_value text not null, " \
241 "PRIMARY KEY(app_id, pm_type, pm_value) " \
242 "FOREIGN KEY(app_id) " \
243 "REFERENCES package_app_info(app_id) " \
246 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
247 "(app_id text not null, " \
248 "data_share_path text not null, " \
249 "data_share_allowed text not null, " \
250 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
251 "FOREIGN KEY(app_id) " \
252 "REFERENCES package_app_info(app_id) " \
255 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
256 "(app_id text not null, " \
257 "data_share_request text not null, " \
258 "PRIMARY KEY(app_id,data_share_request) " \
259 "FOREIGN KEY(app_id) " \
260 "REFERENCES package_app_info(app_id) " \
263 /* FIXME: duplicated at pkgmgrinfo_db.c */
264 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
265 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
266 " cert_info TEXT UNIQUE, " \
267 " cert_id INTEGER PRIMARY KEY, " \
268 " cert_ref_count INTEGER NOT NULL)"
270 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
271 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
272 " package TEXT PRIMARY KEY, " \
273 " author_root_cert INTEGER, " \
274 " author_im_cert INTEGER, " \
275 " author_signer_cert INTEGER, " \
276 " dist_root_cert INTEGER, " \
277 " dist_im_cert INTEGER, " \
278 " dist_signer_cert INTEGER, " \
279 " dist2_root_cert INTEGER, " \
280 " dist2_im_cert INTEGER, " \
281 " dist2_signer_cert INTEGER)"
283 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
284 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
285 "AFTER DELETE ON package_cert_info " \
287 " UPDATE package_cert_index_info SET" \
288 " cert_ref_count = cert_ref_count - 1" \
289 " WHERE cert_id = OLD.author_root_cert" \
290 " OR cert_id = OLD.author_im_cert" \
291 " OR cert_id = OLD.author_signer_cert" \
292 " OR cert_id = OLD.dist_root_cert" \
293 " OR cert_id = OLD.dist_im_cert" \
294 " OR cert_id = OLD.dist_signer_cert" \
295 " OR cert_id = OLD.dist2_root_cert" \
296 " OR cert_id = OLD.dist2_im_cert" \
297 " OR cert_id = OLD.dist2_signer_cert;" \
300 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
301 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
302 "AFTER UPDATE ON package_cert_index_info " \
303 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
304 " WHERE cert_id = OLD.cert_id) = 0) "\
306 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
309 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT \
310 "CREATE TRIGGER IF NOT EXISTS update_%s_info " \
311 "AFTER UPDATE ON package_cert_info " \
312 "WHEN (OLD.%s IS NOT NULL) " \
314 " UPDATE package_cert_index_info SET" \
315 " cert_ref_count = cert_ref_count - 1" \
316 " WHERE cert_id = OLD.%s;" \
319 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
320 "(app_id text not null, " \
321 "providerid text not null, " \
322 "access text not null, " \
323 "type text not null, " \
324 "PRIMARY KEY(app_id, providerid, access, type) " \
325 "FOREIGN KEY(app_id) " \
326 "REFERENCES package_app_info(app_id) " \
329 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
330 "(app_id TEXT NOT NULL, " \
331 "uid TEXT NOT NULL, " \
332 "is_disabled TEXT NOT NULL DEFAULT 'false', " \
333 "is_splash_screen_enabled TEXT NOT NULL, " \
334 "PRIMARY KEY(app_id, uid))"
335 #define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
336 "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
337 "AFTER UPDATE ON package_app_info_for_uid " \
339 " DELETE FROM package_app_info_for_uid WHERE " \
340 " is_splash_screen_enabled=" \
341 " (SELECT package_app_info.app_splash_screen_display FROM " \
342 " package_app_info, package_app_info_for_uid WHERE " \
343 " package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
346 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
347 "create table if not exists package_app_splash_screen " \
348 "(app_id text not null, " \
349 "src text not null, " \
350 "type text not null, " \
351 "orientation text not null, " \
352 "indicatordisplay text, " \
354 "color_depth text not null DEFAULT '24', " \
355 "PRIMARY KEY(app_id, orientation, operation) " \
356 "FOREIGN KEY(app_id) " \
357 "REFERENCES package_app_info(app_id) " \
360 static int __insert_application_info(manifest_x *mfx);
361 static int __insert_application_appcategory_info(manifest_x *mfx);
362 static int __insert_application_appcontrol_info(manifest_x *mfx);
363 static int __insert_application_appmetadata_info(manifest_x *mfx);
364 static int __insert_application_share_allowed_info(manifest_x *mfx);
365 static int __insert_application_share_request_info(manifest_x *mfx);
366 static int __insert_application_datacontrol_info(manifest_x *mfx);
367 static void __insert_application_locale_info(gpointer data, gpointer userdata);
368 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
369 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
370 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
371 static int __delete_subpkg_info_from_db(char *appid);
372 static int __delete_appinfo_from_db(char *db_table, const char *appid);
373 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
374 static int __exec_query(char *query);
375 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
376 char **label, char **license, char **icon, char **description, char **author);
377 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
378 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
379 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
380 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
381 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
382 static int __parserdb_change_perm(const char *db_file, uid_t uid);
384 #define REGULAR_USER 5000
385 static inline uid_t _getuid(void)
387 uid_t uid = getuid();
389 if (uid < REGULAR_USER)
390 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
395 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
398 __delete_subpkg_info_from_db(coltxt[0]);
403 static const char *__get_str(const char *str)
407 return PKGMGR_PARSER_EMPTY_STR;
413 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
418 char *error_message = NULL;
420 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
421 if (ret != SQLITE_OK) {
422 _LOGD("connect db [%s] failed!\n", db_path);
427 /* add user_version for db upgrade*/
428 query = sqlite3_mprintf("PRAGMA user_version=%d", (atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 + atoi(TIZEN_PATCH_VER)));
430 sqlite3_exec(handle, query, NULL, NULL, &error_message)) {
431 _LOGE("Don't execute query = %s error message = %s\n", query,
434 sqlite3_free(error_message);
440 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
442 manifest_x *mfx = (manifest_x *)data;
448 if (mfx->application == NULL)
450 app = (application_x *)mfx->application->data;
451 for(i = 0; i < ncols; i++)
453 if (strcmp(colname[i], "app_id") == 0) {
455 appid = strdup(coltxt[i]);
456 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
458 status = strdup(coltxt[i]);
464 _LOGD("app id is NULL\n");
467 /*update guest mode visibility*/
468 for (tmp = mfx->application; tmp; tmp = tmp->next) {
469 app = (application_x *)tmp->data;
472 if (strcmp(app->appid, appid) == 0) {
473 free((void *)app->guestmode_visibility);
474 app->guestmode_visibility = strdup(status);
490 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
492 char *error_message = NULL;
493 char query[MAX_QUERY_LEN] = {'\0'};
494 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
496 sqlite3_exec(pkgmgr_parser_db, query,
497 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
498 _LOGD("Don't execute query = %s error message = %s\n",
499 query, error_message);
500 sqlite3_free(error_message);
505 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
507 char *error_message = NULL;
509 sqlite3_exec(db_handle, db_query,
510 NULL, NULL, &error_message)) {
511 _LOGD("Don't execute query = %s error message = %s\n",
512 db_query, error_message);
513 sqlite3_free(error_message);
516 sqlite3_free(error_message);
520 static int __exec_query(char *query)
522 char *error_message = NULL;
524 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
525 _LOGE("Don't execute query = %s error message = %s\n", query,
527 sqlite3_free(error_message);
530 sqlite3_free(error_message);
534 static int __exec_query_no_msg(char *query)
536 char *error_message = NULL;
538 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
539 sqlite3_free(error_message);
542 sqlite3_free(error_message);
546 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
554 for (tmp = lbls; tmp; tmp = tmp->next) {
555 lbl = (label_x *)tmp->data;
559 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
561 for (tmp = lcns; tmp; tmp = tmp->next) {
562 lcn = (license_x *)tmp->data;
566 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
568 for (tmp = icns; tmp; tmp = tmp->next) {
569 icn = (icon_x *)tmp->data;
573 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
575 for (tmp = dcns; tmp; tmp = tmp->next) {
576 dcn = (description_x *)tmp->data;
580 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
582 for (tmp = aths; tmp; tmp = tmp->next) {
583 ath = (author_x *)tmp->data;
587 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
593 static GList *__create_icon_list(GList *appicon, GList *icns)
598 for (tmp = icns; tmp; tmp = tmp->next) {
599 icn = (icon_x *)tmp->data;
603 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
608 static GList *__create_image_list(GList *appimage, GList *imgs)
613 for (tmp = imgs; tmp; tmp = tmp->next) {
614 img = (image_x *)tmp->data;
618 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
623 static void __trimfunc(GList* trim_list)
625 char *trim_data = NULL;
629 list = g_list_first(trim_list);
632 trim_data = (char *)list->data;
635 if (strcmp(trim_data, prev) == 0) {
636 trim_list = g_list_remove(trim_list, trim_data);
637 list = g_list_first(trim_list);
646 list = g_list_next(list);
650 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
652 if (a == NULL || b == NULL)
654 if (strcmp((char*)a, (char*)b) == 0)
656 if (strcmp((char*)a, (char*)b) < 0)
658 if (strcmp((char*)a, (char*)b) > 0)
663 static int __check_dpi(const char *dpi_char, int dpi_int)
665 if (dpi_char == NULL)
668 if (strcasecmp(dpi_char, LDPI) == 0) {
669 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
673 } else if (strcasecmp(dpi_char, MDPI) == 0) {
674 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
678 } else if (strcasecmp(dpi_char, HDPI) == 0) {
679 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
683 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
684 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
688 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
689 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
697 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
700 char *icon_filename = NULL;
701 char modified_iconpath[BUFSIZE] = { '\0' };
702 char icon_path[BUFSIZE] = { '\0' };
706 if (orig_icon_path == NULL)
709 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
713 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
714 dpi_path[0] = "LDPI";
715 dpi_path[1] = "ldpi";
716 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
717 dpi_path[0] = "MDPI";
718 dpi_path[1] = "mdpi";
719 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
720 dpi_path[0] = "HDPI";
721 dpi_path[1] = "hdpi";
722 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
723 dpi_path[0] = "XHDPI";
724 dpi_path[1] = "xhdpi";
725 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
726 dpi_path[0] = "XXHDPI";
727 dpi_path[1] = "xxhdpi";
729 _LOGE("Unidentified dpi[%d]", dpi);
733 icon_filename = strrchr(orig_icon_path, '/');
734 if (icon_filename == NULL)
737 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
738 for (i = 0; i < 2; i++) {
739 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
740 if (access(modified_iconpath, F_OK) != -1) {
741 // if exists, return modified icon path
742 *new_icon_path = strdup(modified_iconpath);
750 static gint __compare_icon(gconstpointer a, gconstpointer b)
752 icon_x *icon = (icon_x *)a;
754 char *icon_folder_path = NULL;
756 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
759 if (icon->dpi != NULL)
762 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
764 icon->text = icon_folder_path;
770 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
772 icon_x *icon = (icon_x *)a;
773 int dpi = GPOINTER_TO_INT(b);
775 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
778 if (icon->dpi == NULL)
781 if (__check_dpi(icon->dpi, dpi) == 0)
787 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
789 icon_x *icon = (icon_x *)a;
790 char *lang = (char *)b;
791 char *icon_folder_path = NULL;
793 if (icon->dpi != NULL)
796 if (strcasecmp(icon->lang, lang) == 0) {
797 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
798 //icon for no locale. check existance of folder-hierachied default icons
799 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
801 icon->text = icon_folder_path;
810 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
812 icon_x *icon = (icon_x *)a;
813 char *lang = (char *)b;
816 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
820 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
826 static char *__find_icon(GList *icons, const char *lang)
832 // first, find icon whose locale and dpi with given lang and system's dpi has matched
833 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
835 icon = (icon_x *)tmp->data;
836 return (char *)icon->text;
839 // if first has failed, find icon whose locale has matched
840 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
842 icon = (icon_x *)tmp->data;
843 return (char *)icon->text;
846 // if second has failed, find icon whose dpi has matched with system's dpi
847 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
850 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
852 icon = (icon_x *)tmp->data;
853 return (char *)icon->text;
856 // last, find default icon marked as "No Locale"
857 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
859 icon = (icon_x *)tmp->data;
860 return (char *)icon->text;
866 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
867 char **label, char **license, char **icon, char **description, char **author)
874 for (tmp = lbls; tmp; tmp = tmp->next) {
875 lbl = (label_x *)tmp->data;
879 if (strcmp(lbl->lang, (char *)data) == 0) {
880 *label = (char*)lbl->text;
885 for (tmp = lcns; tmp; tmp = tmp->next) {
886 lcn = (license_x *)tmp->data;
890 if (strcmp(lcn->lang, (char *)data) == 0) {
891 *license = (char*)lcn->text;
897 *icon = __find_icon(icns, (char *)data);
899 for (tmp = dcns; tmp; tmp = tmp->next) {
900 dcn = (description_x *)tmp->data;
904 if (strcmp(dcn->lang, (char *)data) == 0) {
905 *description = (char*)dcn->text;
910 for (tmp = aths; tmp; tmp = tmp->next) {
911 ath = (author_x *)tmp->data;
915 if (strcmp(ath->lang, (char *)data) == 0) {
916 *author = (char*)ath->text;
924 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
928 for (tmp = icns; tmp; tmp = tmp->next) {
929 icn = (icon_x *)tmp->data;
933 if (strcmp(icn->section, (char *)data) == 0) {
934 *icon = (char*)icn->text;
935 *resolution = (char*)icn->resolution;
942 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
946 for (tmp = imgs; tmp; tmp = tmp->next) {
947 img = (image_x *)tmp->data;
951 if (strcmp(img->section, (char *)data) == 0) {
952 *lang = (char*)img->lang;
953 *image = (char*)img->text;
960 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
965 char *description = NULL;
966 char *license = NULL;
970 manifest_x *mfx = (manifest_x *)userdata;
971 GList *lbl = mfx->label;
972 GList *lcn = mfx->license;
973 GList *icn = mfx->icon;
974 GList *dcn = mfx->description;
975 GList *ath = mfx->author;
977 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
978 if (!label && !description && !icon && !license && !author)
981 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
982 "package_label, package_icon, package_description, package_license, package_author) values " \
983 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
988 __get_str(description),
992 ret = __exec_query(query);
994 _LOGD("Package Localized Info DB Insert failed\n");
999 static void __insert_application_locale_info(gpointer data, gpointer userdata)
1006 application_x *app = (application_x*)userdata;
1007 GList *lbl = app->label;
1008 GList *icn = app->icon;
1010 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1011 if (!label && !icon)
1014 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
1015 "app_label, app_icon) values " \
1016 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
1017 __get_str(label), __get_str(icon));
1018 ret = __exec_query(query);
1020 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1022 sqlite3_free(query);
1024 /*insert ui app locale info to pkg locale to get mainapp data */
1025 if (strcasecmp(app->mainapp, "true")==0) {
1026 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
1027 "package_label, package_icon, package_description, package_license, package_author) values " \
1028 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1033 PKGMGR_PARSER_EMPTY_STR,
1034 PKGMGR_PARSER_EMPTY_STR,
1035 PKGMGR_PARSER_EMPTY_STR);
1037 ret = __exec_query_no_msg(query);
1038 sqlite3_free(query);
1041 query = sqlite3_mprintf("update package_localized_info set package_icon=%Q "\
1042 "where package=%Q and package_locale=%Q", icon, app->package, (char*)data);
1043 ret = __exec_query_no_msg(query);
1044 sqlite3_free(query);
1049 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1053 char *resolution = NULL;
1054 char query[MAX_QUERY_LEN] = {'\0'};
1056 application_x *app = (application_x*)userdata;
1057 GList *icn = app->icon;
1059 __extract_icon_data(data, icn, &icon, &resolution);
1060 if (!icon && !resolution)
1062 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
1063 "app_icon, app_icon_section, app_icon_resolution) values " \
1064 "('%q', '%q', '%q', '%q')", app->appid,
1065 icon, (char*)data, resolution);
1067 ret = __exec_query(query);
1069 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1073 static void __insert_application_image_info(gpointer data, gpointer userdata)
1078 char query[MAX_QUERY_LEN] = {'\0'};
1080 application_x *app = (application_x*)userdata;
1081 GList *image = app->image;
1083 __extract_image_data(data, image, &lang, &img);
1086 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
1087 "app_image_section, app_image) values " \
1088 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
1090 ret = __exec_query(query);
1092 _LOGD("Package UiApp image Info DB Insert failed\n");
1097 static int __insert_mainapp_info(manifest_x *mfx)
1102 char query[MAX_QUERY_LEN] = {'\0'};
1103 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1104 app = (application_x *)tmp->data;
1107 snprintf(query, MAX_QUERY_LEN,
1108 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
1110 ret = __exec_query(query);
1112 _LOGD("Package App Info DB Insert Failed\n");
1115 if (strcasecmp(app->mainapp, "True")==0)
1116 mfx->mainapp_id = strdup(app->appid);
1119 if (mfx->mainapp_id == NULL) {
1120 if (mfx->application == NULL)
1122 app = (application_x *)mfx->application->data;
1126 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
1128 _LOGD("Not valid appid\n");
1132 ret = __exec_query(query);
1134 _LOGD("Package UiApp Info DB Insert Failed\n");
1138 free((void *)app->mainapp);
1139 app->mainapp= strdup("true");
1140 mfx->mainapp_id = strdup(app->appid);
1143 memset(query, '\0', MAX_QUERY_LEN);
1144 snprintf(query, MAX_QUERY_LEN,
1145 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
1146 ret = __exec_query(query);
1148 _LOGD("Package Info DB update Failed\n");
1155 static int __convert_background_category(GList *category_list)
1158 GList *tmp_list = category_list;
1159 char *category_data = NULL;
1161 if (category_list == NULL)
1164 while (tmp_list != NULL) {
1165 category_data = (char *)tmp_list->data;
1166 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1167 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1168 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1169 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1170 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1171 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1172 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1173 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1174 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1175 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1176 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1177 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1178 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1179 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1181 _LOGE("Unidentified category [%s]", category_data);
1183 tmp_list = g_list_next(tmp_list);
1189 static const char *__find_effective_appid(GList *metadata_list)
1194 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1195 md = (metadata_x *)tmp_list->data;
1196 if (md == NULL || md->key == NULL)
1199 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1208 /* _PRODUCT_LAUNCHING_ENHANCED_
1209 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1211 static int __insert_application_info(manifest_x *mfx)
1216 int background_value = 0;
1217 char query[MAX_QUERY_LEN] = {'\0'};
1219 const char *effective_appid;
1222 type = strdup(mfx->type);
1224 type = strdup("tpk");
1226 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1227 app = (application_x *)tmp->data;
1231 background_value = __convert_background_category(app->background_category);
1232 if (background_value < 0) {
1233 _LOGE("Failed to retrieve background value[%d]", background_value);
1234 background_value = 0;
1237 effective_appid = __find_effective_appid(app->metadata);
1239 snprintf(query, MAX_QUERY_LEN,
1240 "insert into package_app_info(" \
1241 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1242 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1243 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1244 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1245 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1246 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1247 "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, app_api_version, " \
1248 "app_effective_appid, app_splash_screen_display) " \
1250 "'%s', '%s', '%s', '%s', '%s', " \
1251 "'%s', '%s', '%s', '%s', '%s', " \
1252 "'%s', '%s', '%s', '%s', '%s', " \
1253 "'%s', '%s', '%s', '%s', '%s', " \
1254 "'%s', '%s', '%s', '%s', '%s', " \
1255 "'%s', '%s', '%s', '%s', '%s', " \
1256 "'%s', '%s', '%d', '%s', '%s', " \
1257 "'%s', '%s', '%s')", \
1258 app->appid, app->component_type, app->exec, app->nodisplay, app->type,
1259 app->onboot, app->multiple, app->autorestart, app->taskmanage, app->enabled,
1260 app->hwacceleration, app->screenreader, app->mainapp, __get_str(app->recentimage), app->launchcondition,
1261 app->indicatordisplay, __get_str(app->portraitimg), __get_str(app->landscapeimg),
1262 app->guestmode_visibility, app->permission_type,
1263 mfx->preload, app->submode, __get_str(app->submode_mainid), mfx->installed_storage, app->process_pool,
1264 app->launch_mode, app->ui_gadget, mfx->support_disable, app->component_type, mfx->package,
1265 __get_str(mfx->tep_name), __get_str(mfx->zip_mount_file), background_value, type, mfx->root_path, __get_str(mfx->api_version),
1266 __get_str(effective_appid), app->splash_screen_display);
1268 ret = __exec_query(query);
1270 _LOGD("Package UiApp Info DB Insert Failed\n");
1275 memset(query, '\0', MAX_QUERY_LEN);
1284 static int __insert_application_appcategory_info(manifest_x *mfx)
1291 char query[MAX_QUERY_LEN] = {'\0'};
1292 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1293 app = (application_x *)app_tmp->data;
1296 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1297 ct = (const char *)ct_tmp->data;
1300 snprintf(query, MAX_QUERY_LEN,
1301 "insert into package_app_app_category(app_id, category) " \
1302 "values('%s','%s')",\
1304 ret = __exec_query(query);
1306 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1309 memset(query, '\0', MAX_QUERY_LEN);
1315 static int __insert_application_appmetadata_info(manifest_x *mfx)
1322 char query[MAX_QUERY_LEN] = {'\0'};
1323 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1324 app = (application_x *)app_tmp->data;
1327 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1328 md = (metadata_x *)md_tmp->data;
1332 snprintf(query, MAX_QUERY_LEN,
1333 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1334 "values('%s','%s', '%s')",\
1335 app->appid, md->key, md->value ? md->value : "");
1336 ret = __exec_query(query);
1338 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1342 memset(query, '\0', MAX_QUERY_LEN);
1348 static int __insert_application_apppermission_info(manifest_x *mfx)
1355 char query[MAX_QUERY_LEN] = {'\0'};
1356 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1357 app = (application_x *)app_tmp->data;
1360 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1361 pm = (permission_x *)pm_tmp->data;
1364 snprintf(query, MAX_QUERY_LEN,
1365 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1366 "values('%s','%s', '%s')",\
1367 app->appid, pm->type, pm->value);
1368 ret = __exec_query(query);
1370 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1373 memset(query, '\0', MAX_QUERY_LEN);
1379 static int __insert_application_appcontrol_info(manifest_x *mfx)
1383 GList *acontrol_tmp;
1384 appcontrol_x *acontrol;
1386 char query[MAX_QUERY_LEN] = {'\0'};
1387 char buf[BUFSIZE] = {'\0'};
1388 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1389 app = (application_x *)app_tmp->data;
1392 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1393 acontrol = (appcontrol_x *)acontrol_tmp->data;
1394 if (acontrol == NULL)
1396 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1397 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1398 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1399 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1400 snprintf(query, MAX_QUERY_LEN,
1401 "insert into package_app_app_control(app_id, app_control) " \
1402 "values('%s', '%s')",\
1404 ret = __exec_query(query);
1406 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1409 memset(query, '\0', MAX_QUERY_LEN);
1415 static int __insert_application_datacontrol_info(manifest_x *mfx)
1422 char query[MAX_QUERY_LEN] = {'\0'};
1424 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1425 app = (application_x *)app_tmp->data;
1428 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1429 dc = (datacontrol_x *)dc_tmp->data;
1432 snprintf(query, MAX_QUERY_LEN,
1433 "insert into package_app_data_control(app_id, providerid, access, type) " \
1434 "values('%s', '%s', '%s', '%s')",\
1440 ret = __exec_query(query);
1442 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1445 memset(query, '\0', MAX_QUERY_LEN);
1451 static int __insert_application_share_request_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 (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1470 rq = (const char *)rq_tmp->data;
1473 snprintf(query, MAX_QUERY_LEN,
1474 "insert into package_app_share_request(app_id, data_share_request) " \
1475 "values('%s', '%s')",\
1477 ret = __exec_query(query);
1479 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1482 memset(query, '\0', MAX_QUERY_LEN);
1489 static int __insert_application_share_allowed_info(manifest_x *mfx)
1500 char query[MAX_QUERY_LEN] = {'\0'};
1501 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1502 app = (application_x *)app_tmp->data;
1505 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1506 ds = (datashare_x *)ds_tmp->data;
1509 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1510 df = (define_x *)df_tmp->data;
1513 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1514 al = (const char *)al_tmp->data;
1517 snprintf(query, MAX_QUERY_LEN,
1518 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1519 "values('%s', '%s', '%s')",\
1520 app->appid, df->path, al);
1521 ret = __exec_query(query);
1523 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1526 memset(query, '\0', MAX_QUERY_LEN);
1534 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1536 splashscreen_x *ss = (splashscreen_x *)a;
1537 const char *orientation = (const char *)b;
1540 if (ss->operation || ss->dpi == NULL)
1543 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1547 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1553 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1555 splashscreen_x *ss = (splashscreen_x *)a;
1556 const char *orientation = (const char *)b;
1558 if (ss->operation || ss->dpi)
1561 if (strcasecmp(ss->orientation, orientation) == 0)
1567 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1568 const char *orientation)
1572 tmp = g_list_find_custom(splashscreens, orientation,
1573 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1575 return (splashscreen_x *)tmp->data;
1577 tmp = g_list_find_custom(splashscreens, orientation,
1578 (GCompareFunc)__compare_splashscreen_with_orientation);
1580 return (splashscreen_x *)tmp->data;
1585 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1587 splashscreen_x *ss = (splashscreen_x *)data;
1588 GList **list = (GList **)user_data;
1591 if (ss->operation == NULL || ss->dpi == NULL)
1594 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1598 if (__check_dpi(ss->dpi, dpi) != 0)
1601 *list = g_list_append(*list, ss);
1604 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1606 splashscreen_x *ss = (splashscreen_x *)data;
1607 GList **list = (GList **)user_data;
1608 splashscreen_x *ss_tmp;
1611 if (ss->operation == NULL || ss->dpi)
1614 for (tmp = *list; tmp; tmp = tmp->next) {
1615 ss_tmp = (splashscreen_x *)tmp->data;
1616 if (ss_tmp->operation
1617 && strcmp(ss_tmp->operation, ss->operation) == 0
1618 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1622 *list = g_list_append(*list, ss);
1625 static GList *__find_splashscreens(GList *splashscreens)
1630 g_list_foreach(splashscreens,
1631 __find_appcontrol_splashscreen_with_dpi, &list);
1632 g_list_foreach(splashscreens,
1633 __find_appcontrol_splashscreen, &list);
1635 ss = __find_default_splashscreen(splashscreens, "portrait");
1637 list = g_list_append(list, ss);
1638 ss = __find_default_splashscreen(splashscreens, "landscape");
1640 list = g_list_append(list, ss);
1645 static int __insert_application_splashscreen_info(manifest_x *mfx)
1653 char query[MAX_QUERY_LEN];
1655 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1656 app = (application_x *)app_tmp->data;
1657 if (app == NULL || app->splashscreens == NULL)
1660 ss_tmp = __find_splashscreens(app->splashscreens);
1664 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1665 ss = (splashscreen_x *)tmp->data;
1666 snprintf(query, sizeof(query),
1667 "insert into package_app_splash_screen" \
1668 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1669 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1670 app->appid, ss->src, ss->type, ss->orientation,
1671 ss->indicatordisplay, __get_str(ss->operation),
1673 ret = __exec_query(query);
1675 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1678 memset(query, '\0', MAX_QUERY_LEN);
1680 g_list_free(ss_tmp);
1685 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1690 char query[MAX_QUERY_LEN];
1692 const char *image_type;
1693 const char *indicatordisplay;
1694 const char *orientation;
1695 const char *operation = NULL;
1696 const char *color_depth = "24"; /* default */
1698 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1699 app = (application_x *)app_tmp->data;
1701 (app->portraitimg == NULL && app->landscapeimg == NULL))
1703 image_type = "img"; /* default */
1704 if (app->effectimage_type) {
1705 tmp = strstr(app->effectimage_type, "edj");
1709 indicatordisplay = "true"; /* default */
1710 if (app->indicatordisplay)
1711 indicatordisplay = app->indicatordisplay;
1712 if (app->portraitimg) {
1713 orientation = "portrait";
1714 snprintf(query, sizeof(query),
1715 "insert into package_app_splash_screen" \
1716 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1717 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1718 app->appid, app->portraitimg, image_type,
1719 orientation, indicatordisplay, __get_str(operation),
1721 ret = __exec_query(query);
1723 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1726 memset(query, '\0', MAX_QUERY_LEN);
1728 if (app->landscapeimg) {
1729 orientation = "landscape";
1730 snprintf(query, sizeof(query),
1731 "insert into package_app_splash_screen" \
1732 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1733 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1734 app->appid, app->landscapeimg, image_type,
1735 orientation, indicatordisplay, __get_str(operation),
1737 ret = __exec_query(query);
1739 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1742 memset(query, '\0', MAX_QUERY_LEN);
1748 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1755 char query[MAX_QUERY_LEN];
1757 char *tmpptr = NULL;
1758 const char *operation;
1759 const char *portraitimg;
1760 const char *landscapeimg;
1761 const char *indicatordisplay;
1762 const char *orientation;
1763 const char *image_type;
1764 const char *color_depth = "24"; /* default */
1766 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1767 app = (application_x *)app_tmp->data;
1771 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1772 md = (metadata_x *)md_tmp->data;
1773 if (md == NULL || md->key == NULL || md->value == NULL)
1776 if (strcasestr(md->key, "operation_effect=")) {
1777 operation = index(md->key, '=');
1778 if ((operation + 1) != NULL)
1782 } else if (strcasestr(md->key, "launch_effect")) {
1789 landscapeimg = NULL;
1790 indicatordisplay = "true"; /* default */
1791 token = strtok_r(md->value, "|", &tmpptr);
1792 while (token != NULL) {
1793 if (strcasestr(token, "portrait-effectimage=")) {
1794 portraitimg = index(token, '=');
1795 if ((portraitimg + 1) != NULL)
1799 } else if (strcasestr(token, "landscape-effectimage=")) {
1800 landscapeimg = index(token, '=');
1801 if ((landscapeimg + 1) != NULL)
1804 landscapeimg = NULL;
1805 } else if (strcasestr(token, "indicatordisplay=")) {
1806 indicatordisplay = index(token, '=');
1807 if ((indicatordisplay + 1) != NULL)
1810 indicatordisplay = "true";
1813 token = strtok_r(NULL, "|", &tmpptr);
1817 orientation = "portrait";
1819 if (strcasestr(portraitimg, "edj"))
1821 snprintf(query, sizeof(query),
1822 "insert into package_app_splash_screen" \
1823 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1824 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1825 app->appid, portraitimg, image_type,
1826 orientation, indicatordisplay, __get_str(operation),
1828 ret = __exec_query(query);
1830 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1833 memset(query, '\0', MAX_QUERY_LEN);
1836 orientation = "landscape";
1838 if (strcasestr(landscapeimg, "edj"))
1840 snprintf(query, sizeof(query),
1841 "insert into package_app_splash_screen" \
1842 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1843 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1844 app->appid, landscapeimg, image_type,
1845 orientation, indicatordisplay, __get_str(operation),
1847 ret = __exec_query(query);
1849 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1852 memset(query, '\0', MAX_QUERY_LEN);
1860 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1864 const char *pv = NULL;
1865 char query[MAX_QUERY_LEN] = { '\0' };
1868 const char *auth_name = NULL;
1869 const char *auth_email = NULL;
1870 const char *auth_href = NULL;
1872 GList *pkglocale = NULL;
1873 GList *applocale = NULL;
1874 GList *appicon = NULL;
1875 GList *appimage = NULL;
1877 if (mfx->author && mfx->author->data) {
1878 author = (author_x *)mfx->author->data;
1880 auth_name = author->text;
1882 auth_email = author->email;
1884 auth_href = author->href;
1887 /*Insert in the package_cert_info CERT_DB*/
1888 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1889 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1890 if (ret != PMINFO_R_OK) {
1891 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1892 _LOGE("Cert Info DB create handle failed\n");
1895 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1896 if (ret != PMINFO_R_OK) {
1897 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1898 _LOGE("Cert Info DB Insert Failed\n");
1902 /*Insert in the package_info DB*/
1903 snprintf(query, MAX_QUERY_LEN,
1904 "insert into package_info(" \
1905 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1906 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1907 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1908 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1909 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1911 "'%s', '%s', '%s', '%s', '%s', " \
1912 "'%s', '%s', '%s', '%s', '%s', " \
1913 "'%s', '%s', '%s', '%s', '%s', " \
1914 "'%s', '%s', '%s', '%s', '%s', " \
1915 "'%s', '%s', '%s', '%s', '%s', " \
1917 mfx->package, mfx->type, mfx->version, __get_str(mfx->api_version), __get_str(mfx->tep_name), __get_str(mfx->zip_mount_file),
1918 __get_str(mfx->installlocation), __get_str(mfx->package_size), mfx->removable, mfx->preload, mfx->readonly,
1919 mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system, __get_str(auth_name),
1920 __get_str(auth_email), __get_str(auth_href), mfx->installed_time, mfx->installed_storage,
1921 __get_str(mfx->storeclient_id),
1922 mfx->mainapp_id, __get_str(mfx->package_url), mfx->root_path, __get_str(mfx->csc_path), mfx->support_disable);
1924 ret = __exec_query(query);
1926 _LOGD("Package Info DB Insert Failed\n");
1930 /*Insert in the package_privilege_info DB*/
1931 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1932 pv = (const char *)tmp->data;
1935 memset(query, '\0', MAX_QUERY_LEN);
1936 snprintf(query, MAX_QUERY_LEN,
1937 "insert into package_privilege_info(package, privilege) " \
1938 "values('%s','%s')",\
1940 ret = __exec_query(query);
1942 _LOGD("Package Privilege Info DB Insert Failed\n");
1947 if (mfx->application != NULL) {
1948 ret = __insert_mainapp_info(mfx);
1953 /*Insert the package locale*/
1954 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1955 /*remove duplicated data in pkglocale*/
1956 __trimfunc(pkglocale);
1958 /*Insert the app locale, icon, image info */
1959 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1960 app = (application_x *)tmp->data;
1963 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1964 appicon = __create_icon_list(appicon, app->icon);
1965 appimage = __create_image_list(appimage, app->image);
1967 /*remove duplicated data in applocale*/
1968 __trimfunc(applocale);
1969 __trimfunc(appicon);
1970 __trimfunc(appimage);
1972 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1974 /*native app locale info*/
1975 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1976 app = (application_x *)tmp->data;
1979 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1980 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1981 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1984 g_list_free(pkglocale);
1986 g_list_free(applocale);
1988 g_list_free(appicon);
1990 g_list_free(appimage);
1993 /*Insert in the package_app_info DB*/
1994 ret = __insert_application_info(mfx);
1997 /*Insert in the package_app_app_control DB*/
1998 ret = __insert_application_appcontrol_info(mfx);
2002 /*Insert in the package_app_app_category DB*/
2003 ret = __insert_application_appcategory_info(mfx);
2007 /*Insert in the package_app_app_metadata DB*/
2008 ret = __insert_application_appmetadata_info(mfx);
2012 /*Insert in the package_app_app_permission DB*/
2013 ret = __insert_application_apppermission_info(mfx);
2017 /*Insert in the package_app_share_allowed DB*/
2018 ret = __insert_application_share_allowed_info(mfx);
2022 /*Insert in the package_app_share_request DB*/
2023 ret = __insert_application_share_request_info(mfx);
2027 /*Insert in the package_app_data_control DB*/
2028 ret = __insert_application_datacontrol_info(mfx);
2032 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2033 ret = __insert_application_legacy_splashscreen_info(mfx);
2037 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2038 ret = __insert_application_metadata_splashscreen_info(mfx);
2042 /*Insert in the package_app_splash_screen DB*/
2043 ret = __insert_application_splashscreen_info(mfx);
2051 static int __delete_appinfo_from_db(char *db_table, const char *appid)
2053 char query[MAX_QUERY_LEN] = { '\0' };
2055 memset(query, '\0', MAX_QUERY_LEN);
2056 snprintf(query, MAX_QUERY_LEN,
2057 "delete from %s where app_id='%s'", db_table, appid);
2058 ret = __exec_query(query);
2060 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
2066 static int __delete_subpkg_info_from_db(char *appid)
2070 ret = __delete_appinfo_from_db("package_app_info", appid);
2073 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
2076 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
2079 ret = __delete_appinfo_from_db("package_app_image_info", appid);
2082 ret = __delete_appinfo_from_db("package_app_app_control", appid);
2085 ret = __delete_appinfo_from_db("package_app_app_category", appid);
2088 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
2091 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
2094 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
2097 ret = __delete_appinfo_from_db("package_app_share_request", appid);
2100 ret = __delete_appinfo_from_db("package_app_data_control", appid);
2103 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
2110 static int __delete_subpkg_from_db(manifest_x *mfx)
2112 char query[MAX_QUERY_LEN] = { '\0' };
2113 char *error_message = NULL;
2115 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
2117 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
2118 _LOGE("Don't execute query = %s error message = %s\n", query,
2120 sqlite3_free(error_message);
2123 sqlite3_free(error_message);
2128 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
2130 char query[MAX_QUERY_LEN] = { '\0' };
2134 /*Delete from cert table*/
2135 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2137 _LOGD("Cert Info DB Delete Failed\n");
2141 /*Delete from Package Info DB*/
2142 snprintf(query, MAX_QUERY_LEN,
2143 "delete from package_info where package='%s'", mfx->package);
2144 ret = __exec_query(query);
2146 _LOGD("Package Info DB Delete Failed\n");
2149 memset(query, '\0', MAX_QUERY_LEN);
2151 /*Delete from Package Localized Info*/
2152 snprintf(query, MAX_QUERY_LEN,
2153 "delete from package_localized_info where package='%s'", mfx->package);
2154 ret = __exec_query(query);
2156 _LOGD("Package Localized Info DB Delete Failed\n");
2160 /*Delete from Package Privilege Info*/
2161 snprintf(query, MAX_QUERY_LEN,
2162 "delete from package_privilege_info where package='%s'", mfx->package);
2163 ret = __exec_query(query);
2165 _LOGD("Package Privilege Info DB Delete Failed\n");
2169 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2170 app = (application_x *)tmp->data;
2173 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2176 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2179 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2182 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2185 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2188 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2191 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2194 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2197 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2200 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2203 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2206 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2211 /* if main package has sub pkg, delete sub pkg data*/
2212 __delete_subpkg_from_db(mfx);
2217 static int __disable_app(const char *appid)
2220 char query[MAX_QUERY_LEN] = {'\0'};
2221 sqlite3_snprintf(MAX_QUERY_LEN, query,
2222 "UPDATE package_app_info set app_disable='true' where app_id=%Q",
2224 ret = __exec_query(query);
2226 _LOGD("Insert global app disable failed\n");
2231 static int __enable_app(const char *appid)
2234 char query[MAX_QUERY_LEN] = {'\0'};
2235 sqlite3_snprintf(MAX_QUERY_LEN, query,
2236 "UPDATE package_app_info set app_disable='false' where app_id=%Q",
2238 ret = __exec_query(query);
2240 _LOGD("Insert global app disable failed\n");
2245 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2248 char query[MAX_QUERY_LEN] = { '\0', };
2250 const char *val = NULL;
2255 sqlite3_snprintf(MAX_QUERY_LEN, query,
2256 "SELECT COUNT(*) FROM "
2257 "package_app_info_for_uid WHERE app_id=%Q "
2258 "AND uid='%d'", appid, (int)uid);
2260 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2261 if (ret != SQLITE_OK) {
2262 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2263 return PMINFO_R_ERROR;
2266 if (sqlite3_step(stmt) != SQLITE_ROW) {
2267 LOGE("failed to step");
2268 sqlite3_finalize(stmt);
2269 return PMINFO_R_ERROR;
2272 val = (const char *)sqlite3_column_text(stmt, 0);
2274 sqlite3_finalize(stmt);
2279 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2282 char query[MAX_QUERY_LEN] = { '\0', };
2284 ret = __check_appinfo_for_uid_table(appid, uid);
2286 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2289 } else if (ret == 0) {
2290 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2291 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2292 "VALUES(%Q, '%d', 'true', "
2293 "(SELECT app_splash_screen_display FROM package_app_info WHERE appid='%Q'))",
2294 appid, (int)uid, appid);
2296 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2297 "package_app_info_for_uid SET is_disabled='true' "
2298 "WHERE app_id=%Q AND uid='%d'", appid, (int)uid);
2301 ret = __exec_query(query);
2303 _LOGD("Add global app disable info failed\n");
2308 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2311 char query[MAX_QUERY_LEN] = {'\0'};
2313 ret = __check_appinfo_for_uid_table(appid, uid);
2315 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2318 } else if (ret > 0) {
2319 sqlite3_snprintf(MAX_QUERY_LEN, query,
2320 "UPDATE package_app_info_for_uid SET "
2321 "is_disabled='false' WHERE app_id=%Q AND "
2322 "uid='%d'", appid, (int)uid);
2325 ret = __exec_query(query);
2327 _LOGD("Remove global app disable info failed\n");
2332 static int __update_global_app_splash_screen_for_user(const char *appid,
2333 uid_t uid, int flag)
2336 char query[MAX_QUERY_LEN] = { '\0', };
2338 ret = __check_appinfo_for_uid_table(appid, uid);
2340 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2343 } else if (ret == 0) {
2344 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2345 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2346 "VALUES(%Q, '%d', %Q)", appid, (int)uid,
2347 flag ? "true" : "false");
2349 sqlite3_snprintf(MAX_QUERY_LEN, query,
2350 "UPDATE package_app_info_for_uid SET "
2351 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2352 "uid='%d'", flag ? "true" : "false", appid, (int)uid);
2355 ret = __exec_query(query);
2357 _LOGD("update global app splash screen info failed\n");
2362 static int __disable_app_splash_screen(const char *appid)
2365 char query[MAX_QUERY_LEN] = {'\0'};
2367 sqlite3_snprintf(MAX_QUERY_LEN, query,
2368 "UPDATE package_app_info set app_splash_screen_display='false' where app_id=%Q",
2370 ret = __exec_query(query);
2372 _LOGD("Failed to update app_palsh_screen_display");
2377 static int __enable_app_splash_screen(const char *appid)
2380 char query[MAX_QUERY_LEN] = {'\0'};
2382 sqlite3_snprintf(MAX_QUERY_LEN, query,
2383 "UPDATE package_app_info set app_splash_screen_display='true' where app_id=%Q",
2385 ret = __exec_query(query);
2387 _LOGD("Failed to update app_splash_screen_display");
2392 static int __update_preload_condition_in_db()
2395 char query[MAX_QUERY_LEN] = {'\0'};
2397 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2399 ret = __exec_query(query);
2401 _LOGD("Package preload_condition update failed\n");
2406 API int pkgmgr_parser_initialize_db(uid_t uid)
2410 char query[MAX_QUERY_LEN];
2411 static const char *columns[] = {
2412 "author_root_cert", "author_im_cert", "author_signer_cert",
2413 "dist_root_cert", "dist_im_cert", "dist_signer_cert",
2414 "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
2418 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2420 _LOGD("package info DB initialization failed\n");
2423 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2425 _LOGD("package localized info DB initialization failed\n");
2428 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2430 _LOGD("package app app privilege DB initialization failed\n");
2433 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2435 _LOGD("package app info DB initialization failed\n");
2438 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2440 _LOGD("package app localized info DB initialization failed\n");
2443 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2445 _LOGD("package app icon localized info DB initialization failed\n");
2448 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2450 _LOGD("package app image info DB initialization failed\n");
2453 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2455 _LOGD("package app app control DB initialization failed\n");
2458 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2460 _LOGD("package app app category DB initialization failed\n");
2463 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2465 _LOGD("package app app category DB initialization failed\n");
2468 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2470 _LOGD("package app app permission DB initialization failed\n");
2473 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2475 _LOGD("package app share allowed DB initialization failed\n");
2478 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2480 _LOGD("package app share request DB initialization failed\n");
2483 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2485 _LOGD("package app data control DB initialization failed\n");
2489 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2491 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2495 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2497 _LOGD("package app splash screen DB initialization failed\n");
2501 /* Trigger package_app_info_for_uid */
2502 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2504 _LOGD("package app info for uid DB initialization failed\n");
2509 /* TODO: refactor this code */
2510 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2512 _LOGD("package cert info DB initialization failed\n");
2515 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2517 _LOGD("package cert index info DB initialization failed\n");
2520 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2522 _LOGD("package cert info DB initialization failed\n");
2525 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2527 _LOGD("package cert index info DB initialization failed\n");
2530 for (i = 0; columns[i] != NULL; i++) {
2531 snprintf(query, sizeof(query),
2532 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
2533 columns[i], columns[i], columns[i]);
2534 ret = __initialize_db(pkgmgr_cert_db, query);
2536 _LOGD("package cert index info DB initialization failed\n");
2541 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
2542 _LOGD("Failed to change cert db permission\n");
2544 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2545 _LOGD("Failed to change parser db permission\n");
2551 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2554 char pwuid_buf[1024];
2555 char journal_file[BUFSIZE];
2558 struct passwd userinfo, *result = NULL;
2559 files[0] = (char *)db_file;
2560 files[1] = journal_file;
2564 if (db_file == NULL)
2567 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2569 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2570 if (uid == OWNER_ROOT)
2572 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2573 if (ret != 0 || result == NULL) {
2574 _LOGE("FAIL: user %d doesn't exist", uid);
2577 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2579 for (i = 0; files[i]; i++) {
2580 ret = chown(files[i], uid, userinfo.pw_gid);
2582 if (strerror_r(errno, buf, sizeof(buf)))
2583 strncpy(buf, "", BUFSIZE - 1);
2584 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2585 userinfo.pw_gid, buf);
2589 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2590 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2592 ret = chmod(files[i], mode);
2594 if (strerror_r(errno, buf, sizeof(buf)))
2595 strncpy(buf, "", BUFSIZE - 1);
2596 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2599 SET_SMACK_LABEL(files[i]);
2604 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2608 if (getuid() != OWNER_ROOT) {
2609 _LOGE("Only root user is allowed");
2613 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2614 _LOGE("Manifest db for user %d is already exists", uid);
2618 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2619 _LOGE("Cert db for user %d is already exists", uid);
2623 ret = pkgmgr_parser_check_and_create_db(uid);
2626 ret = pkgmgr_parser_initialize_db(uid);
2628 pkgmgr_parser_close_db();
2631 pkgmgr_parser_close_db();
2636 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2640 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2642 _LOGD("Manifest DB creation Failed\n");
2647 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2649 _LOGD("Cert DB creation Failed\n");
2655 void pkgmgr_parser_close_db(void)
2657 sqlite3_close(pkgmgr_parser_db);
2658 sqlite3_close(pkgmgr_cert_db);
2662 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2664 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2666 _LOGD("manifest pointer is NULL\n");
2670 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2672 _LOGD("Failed to open DB\n");
2675 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2678 /*Begin transaction*/
2679 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2680 if (ret != SQLITE_OK) {
2681 _LOGD("Failed to begin transaction\n");
2685 _LOGD("Transaction Begin\n");
2686 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2688 _LOGD("Insert into DB failed. Rollback now\n");
2689 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2692 /*Commit transaction*/
2693 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2694 if (ret != SQLITE_OK) {
2695 _LOGD("Failed to commit transaction. Rollback now\n");
2696 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2700 _LOGD("Transaction Commit and End\n");
2702 pkgmgr_parser_close_db();
2706 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2708 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2710 _LOGD("manifest pointer is NULL\n");
2714 ret = pkgmgr_parser_check_and_create_db(uid);
2716 _LOGD("Failed to open DB\n");
2719 ret = pkgmgr_parser_initialize_db(uid);
2722 /*Begin transaction*/
2723 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2724 if (ret != SQLITE_OK) {
2725 _LOGD("Failed to begin transaction\n");
2729 _LOGD("Transaction Begin\n");
2730 ret = __insert_manifest_info_in_db(mfx, uid);
2732 _LOGD("Insert into DB failed. Rollback now\n");
2733 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2736 /*Commit transaction*/
2737 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2738 if (ret != SQLITE_OK) {
2739 _LOGD("Failed to commit transaction. Rollback now\n");
2740 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2744 _LOGD("Transaction Commit and End\n");
2746 pkgmgr_parser_close_db();
2750 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2753 _LOGD("manifest pointer is NULL\n");
2757 ret = pkgmgr_parser_check_and_create_db(uid);
2759 _LOGD("Failed to open DB\n");
2762 ret = pkgmgr_parser_initialize_db(uid);
2765 /*Preserve guest mode visibility*/
2766 __preserve_guestmode_visibility_value( mfx);
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 = __delete_manifest_info_from_db(mfx, uid);
2777 _LOGD("Delete from DB failed. Rollback now\n");
2778 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2781 ret = __insert_manifest_info_in_db(mfx, uid);
2783 _LOGD("Insert into DB failed. Rollback now\n");
2784 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2788 /*Commit transaction*/
2789 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2790 if (ret != SQLITE_OK) {
2791 _LOGD("Failed to commit transaction. Rollback now\n");
2792 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2796 _LOGD("Transaction Commit and End\n");
2798 pkgmgr_parser_close_db();
2802 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2804 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2807 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2810 _LOGD("manifest pointer is NULL\n");
2814 ret = pkgmgr_parser_check_and_create_db(uid);
2816 _LOGD("Failed to open DB\n");
2819 /*Begin transaction*/
2820 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2821 if (ret != SQLITE_OK) {
2822 _LOGD("Failed to begin transaction\n");
2826 _LOGD("Transaction Begin\n");
2827 ret = __delete_manifest_info_from_db(mfx, uid);
2829 _LOGD("Delete from DB failed. Rollback now\n");
2830 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2833 /*Commit transaction*/
2834 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2835 if (ret != SQLITE_OK) {
2836 _LOGD("Failed to commit transaction, Rollback now\n");
2837 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2841 _LOGD("Transaction Commit and End\n");
2843 pkgmgr_parser_close_db();
2847 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2849 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
2852 API int pkgmgr_parser_update_preload_info_in_db()
2855 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2857 _LOGD("Failed to open DB\n");
2860 /*Begin transaction*/
2861 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2862 if (ret != SQLITE_OK) {
2863 _LOGD("Failed to begin transaction\n");
2867 _LOGD("Transaction Begin\n");
2868 ret = __update_preload_condition_in_db();
2870 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2871 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2874 /*Commit transaction*/
2875 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2876 if (ret != SQLITE_OK) {
2877 _LOGD("Failed to commit transaction, Rollback now\n");
2878 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2882 _LOGD("Transaction Commit and End\n");
2884 pkgmgr_parser_close_db();
2888 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2891 ret = pkgmgr_parser_check_and_create_db(uid);
2893 _LOGD("Failed to open DB\n");
2896 /*Begin transaction*/
2897 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2898 if (ret != SQLITE_OK) {
2899 _LOGD("Failed to begin transaction\n");
2903 _LOGD("Transaction Begin\n");
2904 ret = __update_preload_condition_in_db();
2906 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2907 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2910 /*Commit transaction*/
2911 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2912 if (ret != SQLITE_OK) {
2913 _LOGD("Failed to commit transaction, Rollback now\n");
2914 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2918 _LOGD("Transaction Commit and End\n");
2920 pkgmgr_parser_close_db();
2924 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2928 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2930 _LOGD("Failed to open DB\n");
2934 /*Begin transaction*/
2935 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2936 if (ret != SQLITE_OK) {
2937 _LOGD("Failed to begin transaction\n");
2941 _LOGD("Transaction Begin\n");
2943 ret = __disable_global_app_for_user(appid, uid);
2945 ret = __enable_global_app_for_user(appid, uid);
2947 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2948 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2951 /*Commit transaction*/
2952 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2953 if (ret != SQLITE_OK) {
2954 _LOGD("Failed to commit transaction, Rollback now\n");
2955 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2959 _LOGD("Transaction Commit and End\n");
2961 pkgmgr_parser_close_db();
2966 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2968 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
2971 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2975 ret = pkgmgr_parser_check_and_create_db(uid);
2977 _LOGD("Failed to open DB\n");
2981 /*Begin transaction*/
2982 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2983 if (ret != SQLITE_OK) {
2984 _LOGD("Failed to begin transaction\n");
2988 _LOGD("Transaction Begin\n");
2990 ret = __disable_app(appid);
2992 ret = __enable_app(appid);
2994 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2995 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2998 /*Commit transaction*/
2999 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3000 if (ret != SQLITE_OK) {
3001 _LOGD("Failed to commit transaction, Rollback now\n");
3002 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3006 _LOGD("Transaction Commit and End\n");
3008 pkgmgr_parser_close_db();
3013 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3017 if (appid == NULL) {
3018 _LOGD("Invalid parameter");
3022 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3024 _LOGD("Failed to open DB\n");
3028 /* Begin transaction */
3029 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3030 if (ret != SQLITE_OK) {
3031 _LOGD("Failed to begin transaction\n");
3035 _LOGD("Transaction Begin\n");
3037 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3039 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3040 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3043 /* Commit transaction */
3044 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3045 if (ret != SQLITE_OK) {
3046 _LOGD("Failed to commit transaction, Rollback now\n");
3047 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3051 _LOGD("Transaction Commit and End\n");
3053 pkgmgr_parser_close_db();
3057 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3059 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3062 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3066 if (appid == NULL) {
3067 _LOGD("Invalid parameter");
3071 ret = pkgmgr_parser_check_and_create_db(uid);
3073 _LOGD("Failed to open DB");
3077 /* Begin transaction */
3078 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3079 if (ret != SQLITE_OK) {
3080 _LOGD("Failed to begin transaction");
3084 _LOGD("Transaction Begin");
3087 ret = __enable_app_splash_screen(appid);
3089 ret = __disable_app_splash_screen(appid);
3091 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3092 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3095 /* Commit transaction */
3096 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3097 if (ret != SQLITE_OK) {
3098 _LOGD("Failed to commit transaction, Rollback now");
3099 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3103 _LOGD("Transaction Commit and End");
3106 pkgmgr_parser_close_db();