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>
37 #include <system_info.h>
39 /* For multi-user support */
40 #include <tzplatform_config.h>
42 #include "pkgmgr-info.h"
43 #include "pkgmgrinfo_basic.h"
44 #include "pkgmgrinfo_debug.h"
45 #include "pkgmgr_parser_internal.h"
46 #include "pkgmgr_parser_db.h"
51 #define LOG_TAG "PKGMGR_PARSER"
53 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
54 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
55 #define MAX_QUERY_LEN 4096
63 #define XXHDPI "xxhdpi"
73 #define XXHDPI_MIN 481
74 #define XXHDPI_MAX 600
76 #define DB_LABEL "User::Home"
77 #define SET_SMACK_LABEL(x) \
79 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
80 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
82 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
85 sqlite3 *pkgmgr_parser_db;
86 sqlite3 *pkgmgr_cert_db;
89 #define QUERY_CREATE_TABLE_PACKAGE_INFO "CREATE TABLE IF NOT EXISTS package_info " \
90 "(package TEXT PRIMARY KEY NOT NULL, " \
91 "package_type TEXT DEFAULT 'tpk', " \
92 "package_version TEXT, " \
93 "package_api_version TEXT, " \
94 "package_tep_name TEXT, " \
95 "package_zip_mount_file TEXT, " \
96 "install_location TEXT NOT NULL , " \
97 "package_size TEXT, " \
98 "package_removable TEXT NOT NULL DEFAULT 'true', " \
99 "package_preload TEXT NOT NULL DEFAULT 'false', " \
100 "package_readonly TEXT NOT NULL DEFAULT 'false', " \
101 "package_update TEXT NOT NULL DEFAULT 'false', " \
102 "package_appsetting TEXT NOT NULL DEFAULT 'false', " \
103 "package_nodisplay TEXT NOT NULL DEFAULT 'false', " \
104 "package_system TEXT NOT NULL DEFAULT 'false', " \
105 "author_name TEXT, " \
106 "author_email TEXT, " \
107 "author_href TEXT," \
108 "installed_time TEXT, " \
109 "installed_storage TEXT, " \
110 "storeclient_id TEXT, " \
111 "mainapp_id TEXT, " \
112 "package_url TEXT, " \
115 "package_support_disable TEXT NOT NULL DEFAULT 'false', " \
116 "package_disable TEXT NOT NULL DEFAULT 'false')"
118 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_localized_info " \
119 "(package TEXT NOT NULL, " \
120 "package_locale TEXT NOT NULL DEFAULT 'No Locale', " \
121 "package_label TEXT, " \
122 "package_icon TEXT, " \
123 "package_description TEXT, " \
124 "package_license TEXT, " \
125 "package_author TEXT, " \
126 "PRIMARY KEY(package, package_locale), " \
127 "FOREIGN KEY(package) " \
128 "REFERENCES package_info(package) " \
131 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "CREATE TABLE IF NOT EXISTS package_privilege_info " \
132 "(package TEXT NOT NULL, " \
133 "privilege TEXT NOT NULL, " \
134 "PRIMARY KEY(package, privilege) " \
135 "FOREIGN KEY(package) " \
136 "REFERENCES package_info(package) " \
139 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "CREATE TABLE IF NOT EXISTS package_app_info " \
140 "(app_id TEXT PRIMARY KEY NOT NULL, " \
141 "app_component TEXT NOT NULL, " \
143 "app_nodisplay TEXT NOT NULL DEFAULT 'false', " \
145 "app_onboot TEXT NOT NULL DEFAULT 'false', " \
146 "app_multiple TEXT NOT NULL DEFAULT 'false', " \
147 "app_autorestart TEXT NOT NULL DEFAULT 'false', " \
148 "app_taskmanage TEXT NOT NULL DEFAULT 'false', " \
149 "app_enabled TEXT NOT NULL DEFAULT 'true', " \
150 "app_hwacceleration TEXT NOT NULL DEFAULT 'use-system-setting', " \
151 "app_screenreader TEXT NOT NULL DEFAULT 'use-system-setting', " \
152 "app_mainapp TEXT NOT NULL, " \
153 "app_recentimage TEXT NOT NULL DEFAULT 'false', " \
154 "app_launchcondition TEXT, " \
155 "app_indicatordisplay TEXT NOT NULL DEFAULT 'true', " \
156 "app_portraitimg TEXT, " \
157 "app_landscapeimg TEXT, " \
158 "app_guestmodevisibility TEXT NOT NULL DEFAULT 'true', " \
159 "app_permissiontype TEXT NOT NULL DEFAULT 'normal', " \
160 "app_preload TEXT NOT NULL DEFAULT 'false', " \
161 "app_submode TEXT NOT NULL DEFAULT 'false', " \
162 "app_submode_mainid TEXT, " \
163 "app_installed_storage TEXT NOT NULL, " \
164 "app_process_pool TEXT NOT NULL DEFAULT 'false', " \
165 "app_launch_mode TEXT NOT NULL DEFAULT 'caller', " \
166 "app_ui_gadget TEXT NOT NULL DEFAULT 'false', " \
167 "app_support_disable TEXT NOT NULL DEFAULT 'false', " \
168 "app_disable TEXT NOT NULL DEFAULT 'false', " \
169 "app_package_type TEXT DEFAULT 'tpk', " \
170 "component_type TEXT, " \
171 "package TEXT NOT NULL, " \
172 "app_tep_name TEXT, " \
173 "app_zip_mount_file TEXT, " \
174 "app_background_category INTEGER DEFAULT 0, " \
175 "app_root_path TEXT, " \
176 "app_api_version TEXT, " \
177 "app_effective_appid TEXT, " \
178 "app_splash_screen_display TEXT NOT NULL DEFAULT 'true', " \
179 "FOREIGN KEY(package) " \
180 "REFERENCES package_info(package) " \
183 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_app_localized_info " \
184 "(app_id TEXT NOT NULL, " \
185 "app_locale TEXT NOT NULL DEFAULT 'No Locale', " \
188 "PRIMARY KEY(app_id,app_locale) " \
189 "FOREIGN KEY(app_id) " \
190 "REFERENCES package_app_info(app_id) " \
193 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "CREATE TABLE IF NOT EXISTS package_app_icon_section_info " \
194 "(app_id TEXT NOT NULL, " \
196 "app_icon_section TEXT NOT NULL, " \
197 "app_icon_resolution TEXT NOT NULL, " \
198 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
199 "FOREIGN KEY(app_id) " \
200 "REFERENCES package_app_info(app_id) " \
203 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "CREATE TABLE IF NOT EXISTS package_app_image_info " \
204 "(app_id TEXT NOT NULL, " \
205 "app_locale TEXT DEFAULT 'No Locale', " \
206 "app_image_section TEXT NOT NULL, " \
208 "PRIMARY KEY(app_id,app_image_section) " \
209 "FOREIGN KEY(app_id) " \
210 "REFERENCES package_app_info(app_id) " \
213 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "CREATE TABLE IF NOT EXISTS package_app_app_control " \
214 "(app_id TEXT NOT NULL, " \
215 "app_control TEXT NOT NULL, " \
216 "PRIMARY KEY(app_id,app_control) " \
217 "FOREIGN KEY(app_id) " \
218 "REFERENCES package_app_info(app_id) " \
221 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "CREATE TABLE IF NOT EXISTS package_app_app_category " \
222 "(app_id TEXT NOT NULL, " \
223 "category TEXT NOT NULL, " \
224 "PRIMARY KEY(app_id,category) " \
225 "FOREIGN KEY(app_id) " \
226 "REFERENCES package_app_info(app_id) " \
229 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "CREATE TABLE IF NOT EXISTS package_app_app_metadata " \
230 "(app_id TEXT NOT NULL, " \
231 "md_key TEXT NOT NULL, " \
233 "PRIMARY KEY(app_id, md_key) " \
234 "FOREIGN KEY(app_id) " \
235 "REFERENCES package_app_info(app_id) " \
238 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "CREATE TABLE IF NOT EXISTS package_app_app_permission " \
239 "(app_id TEXT NOT NULL, " \
240 "pm_type TEXT NOT NULL, " \
241 "pm_value TEXT NOT NULL, " \
242 "PRIMARY KEY(app_id, pm_type, pm_value) " \
243 "FOREIGN KEY(app_id) " \
244 "REFERENCES package_app_info(app_id) " \
247 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "CREATE TABLE IF NOT EXISTS package_app_share_allowed " \
248 "(app_id TEXT NOT NULL, " \
249 "data_share_path TEXT NOT NULL, " \
250 "data_share_allowed TEXT NOT NULL, " \
251 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
252 "FOREIGN KEY(app_id) " \
253 "REFERENCES package_app_info(app_id) " \
256 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "CREATE TABLE IF NOT EXISTS package_app_share_request " \
257 "(app_id TEXT NOT NULL, " \
258 "data_share_request TEXT NOT NULL, " \
259 "PRIMARY KEY(app_id,data_share_request) " \
260 "FOREIGN KEY(app_id) " \
261 "REFERENCES package_app_info(app_id) " \
264 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "CREATE TABLE IF NOT EXISTS package_app_data_control " \
265 "(app_id TEXT NOT NULL, " \
266 "providerid TEXT NOT NULL, " \
267 "access TEXT NOT NULL, " \
268 "type TEXT NOT NULL, " \
269 "PRIMARY KEY(app_id, providerid, access, type) " \
270 "FOREIGN KEY(app_id) " \
271 "REFERENCES package_app_info(app_id) " \
274 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
275 "(app_id TEXT NOT NULL, " \
276 "uid INTEGER NOT NULL, " \
277 "is_disabled TEXT NOT NULL DEFAULT 'false', " \
278 "is_splash_screen_enabled TEXT NOT NULL, " \
279 "PRIMARY KEY(app_id, uid))"
281 #define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
282 "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
283 "AFTER UPDATE ON package_app_info_for_uid " \
285 " DELETE FROM package_app_info_for_uid WHERE " \
286 " is_splash_screen_enabled=" \
287 " (SELECT package_app_info.app_splash_screen_display FROM " \
288 " package_app_info, package_app_info_for_uid WHERE " \
289 " package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
292 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
293 "CREATE TABLE IF NOT EXISTS package_app_splash_screen " \
294 "(app_id TEXT NOT NULL, " \
295 "src TEXT NOT NULL, " \
296 "type TEXT NOT NULL, " \
297 "orientation TEXT NOT NULL, " \
298 "indicatordisplay TEXT, " \
300 "color_depth TEXT NOT NULL DEFAULT '24', " \
301 "PRIMARY KEY(app_id, orientation, operation) " \
302 "FOREIGN KEY(app_id) " \
303 "REFERENCES package_app_info(app_id) " \
307 /* FIXME: duplicated at pkgmgrinfo_db.c */
308 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
309 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
310 " cert_info TEXT UNIQUE, " \
311 " cert_id INTEGER PRIMARY KEY, " \
312 " cert_ref_count INTEGER NOT NULL)"
314 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
315 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
316 " package TEXT PRIMARY KEY, " \
317 " package_count INTEGER, " \
318 " author_root_cert INTEGER, " \
319 " author_im_cert INTEGER, " \
320 " author_signer_cert INTEGER, " \
321 " dist_root_cert INTEGER, " \
322 " dist_im_cert INTEGER, " \
323 " dist_signer_cert INTEGER, " \
324 " dist2_root_cert INTEGER, " \
325 " dist2_im_cert INTEGER, " \
326 " dist2_signer_cert INTEGER)"
328 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO \
329 "CREATE TRIGGER IF NOT EXISTS update_cert_info " \
330 "AFTER UPDATE ON package_cert_info " \
331 "WHEN (NEW.package_count = 0) " \
333 " DELETE FROM package_cert_info WHERE package=OLD.package;" \
336 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2 \
337 "CREATE TRIGGER IF NOT EXISTS update_cert_info2 " \
338 "AFTER UPDATE ON package_cert_info " \
339 "WHEN (NEW.package_count = OLD.package_count + 1) " \
341 " UPDATE package_cert_index_info SET" \
342 " cert_ref_count = cert_ref_count - 1" \
343 " WHERE cert_id = OLD.author_root_cert" \
344 " OR cert_id = OLD.author_im_cert" \
345 " OR cert_id = OLD.author_signer_cert" \
346 " OR cert_id = OLD.dist_root_cert" \
347 " OR cert_id = OLD.dist_im_cert" \
348 " OR cert_id = OLD.dist_signer_cert" \
349 " OR cert_id = OLD.dist2_root_cert" \
350 " OR cert_id = OLD.dist2_im_cert" \
351 " OR cert_id = OLD.dist2_signer_cert;" \
354 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
355 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
356 "AFTER DELETE ON package_cert_info " \
358 " UPDATE package_cert_index_info SET" \
359 " cert_ref_count = cert_ref_count - 1" \
360 " WHERE cert_id = OLD.author_root_cert" \
361 " OR cert_id = OLD.author_im_cert" \
362 " OR cert_id = OLD.author_signer_cert" \
363 " OR cert_id = OLD.dist_root_cert" \
364 " OR cert_id = OLD.dist_im_cert" \
365 " OR cert_id = OLD.dist_signer_cert" \
366 " OR cert_id = OLD.dist2_root_cert" \
367 " OR cert_id = OLD.dist2_im_cert" \
368 " OR cert_id = OLD.dist2_signer_cert;" \
371 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
372 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
373 "AFTER UPDATE ON package_cert_index_info " \
374 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
375 " WHERE cert_id = OLD.cert_id) = 0) "\
377 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
380 static int __insert_application_info(manifest_x *mfx);
381 static int __insert_application_appcategory_info(manifest_x *mfx);
382 static int __insert_application_appcontrol_info(manifest_x *mfx);
383 static int __insert_application_appmetadata_info(manifest_x *mfx);
384 static int __insert_application_share_allowed_info(manifest_x *mfx);
385 static int __insert_application_share_request_info(manifest_x *mfx);
386 static int __insert_application_datacontrol_info(manifest_x *mfx);
387 static void __insert_application_locale_info(gpointer data, gpointer userdata);
388 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
389 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
390 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
391 static int __delete_subpkg_info_from_db(char *appid);
392 static int __delete_appinfo_from_db(char *db_table, const char *appid);
393 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
394 static int __exec_query(char *query);
395 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
396 char **label, char **license, char **icon, char **description, char **author);
397 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
398 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
399 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
400 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
401 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
402 static int __parserdb_change_perm(const char *db_file, uid_t uid);
404 #define REGULAR_USER 5000
405 static inline uid_t _getuid(void)
407 uid_t uid = getuid();
409 if (uid < REGULAR_USER)
410 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
415 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
418 __delete_subpkg_info_from_db(coltxt[0]);
423 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
428 char *error_message = NULL;
430 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
431 if (ret != SQLITE_OK) {
432 _LOGD("connect db [%s] failed!\n", db_path);
437 /* add user_version for db upgrade*/
438 query = sqlite3_mprintf("PRAGMA user_version=%d", (atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 + atoi(TIZEN_PATCH_VER)));
440 sqlite3_exec(handle, query, NULL, NULL, &error_message)) {
441 _LOGE("Don't execute query = %s error message = %s\n", query,
444 sqlite3_free(error_message);
450 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
452 manifest_x *mfx = (manifest_x *)data;
458 if (mfx->application == NULL)
460 app = (application_x *)mfx->application->data;
461 for (i = 0; i < ncols; i++) {
462 if (strcmp(colname[i], "app_id") == 0) {
464 appid = strdup(coltxt[i]);
465 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
467 status = strdup(coltxt[i]);
473 _LOGD("app id is NULL\n");
476 /*update guest mode visibility*/
477 for (tmp = mfx->application; tmp; tmp = tmp->next) {
478 app = (application_x *)tmp->data;
481 if (strcmp(app->appid, appid) == 0) {
482 free((void *)app->guestmode_visibility);
483 app->guestmode_visibility = strdup(status);
499 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
501 char *error_message = NULL;
502 char query[MAX_QUERY_LEN] = {'\0'};
503 sqlite3_snprintf(MAX_QUERY_LEN, query,
504 "SELECT app_id, app_guestmodevisibility FROM package_app_info " \
505 "WHERE package=%Q", mfx->package);
507 sqlite3_exec(pkgmgr_parser_db, query,
508 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
509 _LOGD("Don't execute query = %s error message = %s\n",
510 query, error_message);
511 sqlite3_free(error_message);
516 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
518 char *error_message = NULL;
520 sqlite3_exec(db_handle, db_query,
521 NULL, NULL, &error_message)) {
522 _LOGD("Don't execute query = %s error message = %s\n",
523 db_query, error_message);
524 sqlite3_free(error_message);
527 sqlite3_free(error_message);
531 static int __exec_query(char *query)
533 char *error_message = NULL;
535 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
536 _LOGE("Don't execute query = %s error message = %s\n", query,
538 sqlite3_free(error_message);
541 sqlite3_free(error_message);
545 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
553 for (tmp = lbls; tmp; tmp = tmp->next) {
554 lbl = (label_x *)tmp->data;
558 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
560 for (tmp = lcns; tmp; tmp = tmp->next) {
561 lcn = (license_x *)tmp->data;
565 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
567 for (tmp = icns; tmp; tmp = tmp->next) {
568 icn = (icon_x *)tmp->data;
572 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
574 for (tmp = dcns; tmp; tmp = tmp->next) {
575 dcn = (description_x *)tmp->data;
579 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
581 for (tmp = aths; tmp; tmp = tmp->next) {
582 ath = (author_x *)tmp->data;
586 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
592 static GList *__create_icon_list(GList *appicon, GList *icns)
597 for (tmp = icns; tmp; tmp = tmp->next) {
598 icn = (icon_x *)tmp->data;
602 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
607 static GList *__create_image_list(GList *appimage, GList *imgs)
612 for (tmp = imgs; tmp; tmp = tmp->next) {
613 img = (image_x *)tmp->data;
617 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
622 static void __trimfunc(GList* trim_list)
624 char *trim_data = NULL;
628 list = g_list_first(trim_list);
631 trim_data = (char *)list->data;
634 if (strcmp(trim_data, prev) == 0) {
635 trim_list = g_list_remove(trim_list, trim_data);
636 list = g_list_first(trim_list);
645 list = g_list_next(list);
649 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
651 if (a == NULL || b == NULL)
653 if (strcmp((char*)a, (char*)b) == 0)
655 if (strcmp((char*)a, (char*)b) < 0)
657 if (strcmp((char*)a, (char*)b) > 0)
662 static int __check_dpi(const char *dpi_char, int dpi_int)
664 if (dpi_char == NULL)
667 if (strcasecmp(dpi_char, LDPI) == 0) {
668 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
672 } else if (strcasecmp(dpi_char, MDPI) == 0) {
673 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
677 } else if (strcasecmp(dpi_char, HDPI) == 0) {
678 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
682 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
683 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
687 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
688 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
696 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
699 char *icon_filename = NULL;
700 char modified_iconpath[BUFSIZE] = { '\0' };
701 char icon_path[BUFSIZE] = { '\0' };
705 if (orig_icon_path == NULL)
708 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
712 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
713 dpi_path[0] = "LDPI";
714 dpi_path[1] = "ldpi";
715 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
716 dpi_path[0] = "MDPI";
717 dpi_path[1] = "mdpi";
718 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
719 dpi_path[0] = "HDPI";
720 dpi_path[1] = "hdpi";
721 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
722 dpi_path[0] = "XHDPI";
723 dpi_path[1] = "xhdpi";
724 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
725 dpi_path[0] = "XXHDPI";
726 dpi_path[1] = "xxhdpi";
728 _LOGE("Unidentified dpi[%d]", dpi);
732 icon_filename = strrchr(orig_icon_path, '/');
733 if (icon_filename == NULL)
736 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
737 for (i = 0; i < 2; i++) {
738 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
739 if (access(modified_iconpath, F_OK) != -1) {
740 /* if exists, return modified icon path */
741 *new_icon_path = strdup(modified_iconpath);
749 static gint __compare_icon(gconstpointer a, gconstpointer b)
751 icon_x *icon = (icon_x *)a;
753 char *icon_folder_path = NULL;
755 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
758 if (icon->dpi != NULL)
761 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
763 icon->text = icon_folder_path;
769 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
771 icon_x *icon = (icon_x *)a;
772 int dpi = GPOINTER_TO_INT(b);
774 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
777 if (icon->dpi == NULL)
780 if (__check_dpi(icon->dpi, dpi) == 0)
786 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
788 icon_x *icon = (icon_x *)a;
789 char *lang = (char *)b;
790 char *icon_folder_path = NULL;
792 if (icon->dpi != NULL)
795 if (strcasecmp(icon->lang, lang) == 0) {
796 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
797 /* icon for no locale. check existance of folder-hierachied default icons */
798 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
800 icon->text = icon_folder_path;
809 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
811 icon_x *icon = (icon_x *)a;
812 char *lang = (char *)b;
815 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
819 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
825 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 ret = system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
848 if (ret == SYSTEM_INFO_ERROR_NONE) {
849 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
851 icon = (icon_x *)tmp->data;
852 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)",
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)
1005 char *locale = (char *)data;
1007 application_x *app = (application_x*)userdata;
1008 GList *lbl = app->label;
1009 GList *icn = app->icon;
1011 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1012 if (!label && !icon)
1015 query = sqlite3_mprintf("INSERT INTO package_app_localized_info(app_id, app_locale, " \
1016 "app_label, app_icon) VALUES" \
1017 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
1019 ret = __exec_query(query);
1021 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1023 sqlite3_free(query);
1025 /*insert ui app locale info to pkg locale to get mainapp data */
1026 if (strcasecmp(app->mainapp, "true") == 0) {
1027 query = sqlite3_mprintf("INSERT OR REPLACE INTO package_localized_info(package, package_locale, "
1028 "package_label, package_icon, package_description, package_license, package_author) VALUES"
1030 "COALESCE((SELECT package_label FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1031 "COALESCE((SELECT package_icon FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1032 "(SELECT package_description FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1033 "(SELECT package_license FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1034 "(SELECT package_author FROM package_localized_info WHERE package=%Q AND package_locale=%Q))",
1035 app->package, locale,
1036 app->package, locale, label,
1037 app->package, locale, icon,
1038 app->package, locale,
1039 app->package, locale,
1040 app->package, locale);
1042 ret = __exec_query(query);
1044 _LOGE("Package Localized Info DB Insert failed");
1045 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,
1087 "INSERT INTO package_app_image_info(app_id, app_locale, " \
1088 "app_image_section, app_image) VALUES" \
1089 "(%Q, %Q, %Q, %Q)", app->appid, lang, (char*)data, img);
1091 ret = __exec_query(query);
1093 _LOGD("Package UiApp image Info DB Insert failed\n");
1098 static int __insert_mainapp_info(manifest_x *mfx)
1103 char query[MAX_QUERY_LEN] = {'\0'};
1104 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1105 app = (application_x *)tmp->data;
1109 sqlite3_snprintf(MAX_QUERY_LEN, query,
1110 "UPDATE package_app_info SET app_mainapp=%Q WHERE app_id=%Q",
1111 app->mainapp, app->appid);
1112 ret = __exec_query(query);
1114 _LOGD("Package App Info DB Insert Failed\n");
1117 if (strcasecmp(app->mainapp, "True") == 0)
1118 mfx->mainapp_id = strdup(app->appid);
1121 if (mfx->mainapp_id == NULL) {
1122 if (mfx->application == NULL)
1124 app = (application_x *)mfx->application->data;
1128 sqlite3_snprintf(MAX_QUERY_LEN, query,
1129 "UPDATE package_app_info SET app_mainapp='true' WHERE app_id=%Q",
1132 _LOGD("Not valid appid\n");
1136 ret = __exec_query(query);
1138 _LOGD("Package UiApp Info DB Insert Failed\n");
1142 free((void *)app->mainapp);
1143 app->mainapp = strdup("true");
1144 mfx->mainapp_id = strdup(app->appid);
1147 memset(query, '\0', MAX_QUERY_LEN);
1148 sqlite3_snprintf(MAX_QUERY_LEN, query,
1149 "UPDATE package_info SET mainapp_id=%Q WHERE package=%Q", mfx->mainapp_id, mfx->package);
1150 ret = __exec_query(query);
1152 _LOGD("Package Info DB update Failed\n");
1159 static int __convert_background_category(GList *category_list)
1162 GList *tmp_list = category_list;
1163 char *category_data = NULL;
1165 if (category_list == NULL)
1168 while (tmp_list != NULL) {
1169 category_data = (char *)tmp_list->data;
1170 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0)
1171 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1172 else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0)
1173 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1174 else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0)
1175 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1176 else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0)
1177 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1178 else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0)
1179 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1180 else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0)
1181 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1182 else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0)
1183 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1185 _LOGE("Unidentified category [%s]", category_data);
1186 tmp_list = g_list_next(tmp_list);
1192 static const char *__find_effective_appid(GList *metadata_list)
1197 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1198 md = (metadata_x *)tmp_list->data;
1199 if (md == NULL || md->key == NULL)
1202 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1211 static char *__get_bool(char *value, bool is_true)
1213 if (value != NULL) {
1214 if (!strcmp(value, ""))
1215 return (is_true) ? "true" : "false";
1219 return (is_true) ? "true" : "false";
1222 /* _PRODUCT_LAUNCHING_ENHANCED_
1223 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1225 static int __insert_application_info(manifest_x *mfx)
1230 int background_value = 0;
1231 char query[MAX_QUERY_LEN] = {'\0'};
1233 const char *effective_appid;
1236 type = strdup(mfx->type);
1238 type = strdup("tpk");
1240 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1241 app = (application_x *)tmp->data;
1245 background_value = __convert_background_category(app->background_category);
1246 if (background_value < 0) {
1247 _LOGE("Failed to retrieve background value[%d]", background_value);
1248 background_value = 0;
1251 effective_appid = __find_effective_appid(app->metadata);
1253 sqlite3_snprintf(MAX_QUERY_LEN, query,
1254 "INSERT INTO package_app_info(" \
1255 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1256 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1257 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1258 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1259 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1260 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1261 "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, " \
1262 "app_api_version, app_effective_appid, app_splash_screen_display) " \
1264 "%Q, %Q, %Q, LOWER(%Q), %Q, " \
1265 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1266 "%Q, %Q, %Q, %Q, %Q, " \
1267 "LOWER(%Q), %Q, %Q, LOWER(%Q), %Q, " \
1268 "LOWER(%Q), LOWER(%Q), %Q, %Q, LOWER(%Q), " \
1269 "COALESCE(%Q, 'caller'), LOWER(%Q), LOWER(%Q), %Q, %Q, " \
1270 "%Q, %Q, %d, %Q, %Q, " \
1271 "%Q, %Q, LOWER(%Q))", \
1272 app->appid, app->component_type, app->exec, __get_bool(app->nodisplay, false), app->type,
1273 __get_bool(app->onboot, false), __get_bool(app->multiple, false), __get_bool(app->autorestart, false), __get_bool(app->taskmanage, false), __get_bool(app->enabled, true),
1274 app->hwacceleration, app->screenreader, app->mainapp, app->recentimage, app->launchcondition,
1275 __get_bool(app->indicatordisplay, true), app->portraitimg, app->landscapeimg,
1276 __get_bool(app->guestmode_visibility, true), app->permission_type,
1277 __get_bool(mfx->preload, false), __get_bool(app->submode, false), app->submode_mainid, mfx->installed_storage, __get_bool(app->process_pool, false),
1278 app->launch_mode, __get_bool(app->ui_gadget, false), __get_bool(mfx->support_disable, false), app->component_type, mfx->package,
1279 mfx->tep_name, mfx->zip_mount_file, background_value, type, mfx->root_path, mfx->api_version,
1280 effective_appid, __get_bool(app->splash_screen_display, false));
1282 ret = __exec_query(query);
1284 _LOGD("Package UiApp Info DB Insert Failed\n");
1289 memset(query, '\0', MAX_QUERY_LEN);
1298 static int __insert_application_appcategory_info(manifest_x *mfx)
1305 char query[MAX_QUERY_LEN] = {'\0'};
1306 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1307 app = (application_x *)app_tmp->data;
1310 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1311 ct = (const char *)ct_tmp->data;
1314 sqlite3_snprintf(MAX_QUERY_LEN, query,
1315 "INSERT INTO package_app_app_category(app_id, category) " \
1318 ret = __exec_query(query);
1320 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1323 memset(query, '\0', MAX_QUERY_LEN);
1329 static int __insert_application_appmetadata_info(manifest_x *mfx)
1336 char query[MAX_QUERY_LEN] = {'\0'};
1337 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1338 app = (application_x *)app_tmp->data;
1341 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1342 md = (metadata_x *)md_tmp->data;
1346 sqlite3_snprintf(MAX_QUERY_LEN, query,
1347 "INSERT INTO package_app_app_metadata(app_id, md_key, md_value) " \
1348 "VALUES(%Q, %Q, %Q)",\
1349 app->appid, md->key, md->value ? md->value : NULL);
1350 ret = __exec_query(query);
1352 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1356 memset(query, '\0', MAX_QUERY_LEN);
1362 static int __insert_application_apppermission_info(manifest_x *mfx)
1369 char query[MAX_QUERY_LEN] = {'\0'};
1370 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1371 app = (application_x *)app_tmp->data;
1374 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1375 pm = (permission_x *)pm_tmp->data;
1378 sqlite3_snprintf(MAX_QUERY_LEN, query,
1379 "INSERT INTO package_app_app_permission(app_id, pm_type, pm_value) " \
1380 "VALUES(%Q, %Q, %Q)",\
1381 app->appid, pm->type, pm->value);
1382 ret = __exec_query(query);
1384 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1387 memset(query, '\0', MAX_QUERY_LEN);
1393 static int __insert_application_appcontrol_info(manifest_x *mfx)
1397 GList *acontrol_tmp;
1398 appcontrol_x *acontrol;
1400 char query[MAX_QUERY_LEN] = {'\0'};
1401 char buf[BUFSIZE] = {'\0'};
1402 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1403 app = (application_x *)app_tmp->data;
1406 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1407 acontrol = (appcontrol_x *)acontrol_tmp->data;
1408 if (acontrol == NULL)
1410 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1411 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1412 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1413 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1414 sqlite3_snprintf(MAX_QUERY_LEN, query,
1415 "INSERT INTO package_app_app_control(app_id, app_control) " \
1418 ret = __exec_query(query);
1420 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1423 memset(query, '\0', MAX_QUERY_LEN);
1429 static int __insert_application_datacontrol_info(manifest_x *mfx)
1436 char query[MAX_QUERY_LEN] = {'\0'};
1438 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1439 app = (application_x *)app_tmp->data;
1442 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1443 dc = (datacontrol_x *)dc_tmp->data;
1446 sqlite3_snprintf(MAX_QUERY_LEN, query,
1447 "INSERT INTO package_app_data_control(app_id, providerid, access, type) " \
1448 "VALUES(%Q, %Q, %Q, %Q)",\
1454 ret = __exec_query(query);
1456 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1459 memset(query, '\0', MAX_QUERY_LEN);
1465 static int __insert_application_share_request_info(manifest_x *mfx)
1474 char query[MAX_QUERY_LEN] = {'\0'};
1475 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1476 app = (application_x *)app_tmp->data;
1479 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1480 ds = (datashare_x *)ds_tmp->data;
1483 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1484 rq = (const char *)rq_tmp->data;
1487 sqlite3_snprintf(MAX_QUERY_LEN, query,
1488 "INSERT INTO package_app_share_request(app_id, data_share_request) " \
1491 ret = __exec_query(query);
1493 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1496 memset(query, '\0', MAX_QUERY_LEN);
1503 static int __insert_application_share_allowed_info(manifest_x *mfx)
1514 char query[MAX_QUERY_LEN] = {'\0'};
1515 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1516 app = (application_x *)app_tmp->data;
1519 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1520 ds = (datashare_x *)ds_tmp->data;
1523 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1524 df = (define_x *)df_tmp->data;
1527 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1528 al = (const char *)al_tmp->data;
1531 sqlite3_snprintf(MAX_QUERY_LEN, query,
1532 "INSERT INTO package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1533 "VALUES(%Q, %Q, %Q)",\
1534 app->appid, df->path, al);
1535 ret = __exec_query(query);
1537 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1540 memset(query, '\0', MAX_QUERY_LEN);
1548 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1550 splashscreen_x *ss = (splashscreen_x *)a;
1551 const char *orientation = (const char *)b;
1554 if (ss->operation || ss->dpi == NULL)
1557 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1561 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1567 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1569 splashscreen_x *ss = (splashscreen_x *)a;
1570 const char *orientation = (const char *)b;
1572 if (ss->operation || ss->dpi)
1575 if (strcasecmp(ss->orientation, orientation) == 0)
1581 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1582 const char *orientation)
1586 tmp = g_list_find_custom(splashscreens, orientation,
1587 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1589 return (splashscreen_x *)tmp->data;
1591 tmp = g_list_find_custom(splashscreens, orientation,
1592 (GCompareFunc)__compare_splashscreen_with_orientation);
1594 return (splashscreen_x *)tmp->data;
1599 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1601 splashscreen_x *ss = (splashscreen_x *)data;
1602 GList **list = (GList **)user_data;
1605 if (ss->operation == NULL || ss->dpi == NULL)
1608 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1612 if (__check_dpi(ss->dpi, dpi) != 0)
1615 *list = g_list_append(*list, ss);
1618 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1620 splashscreen_x *ss = (splashscreen_x *)data;
1621 GList **list = (GList **)user_data;
1622 splashscreen_x *ss_tmp;
1625 if (ss->operation == NULL || ss->dpi)
1628 for (tmp = *list; tmp; tmp = tmp->next) {
1629 ss_tmp = (splashscreen_x *)tmp->data;
1630 if (ss_tmp->operation
1631 && strcmp(ss_tmp->operation, ss->operation) == 0
1632 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1636 *list = g_list_append(*list, ss);
1639 static GList *__find_splashscreens(GList *splashscreens)
1644 g_list_foreach(splashscreens,
1645 __find_appcontrol_splashscreen_with_dpi, &list);
1646 g_list_foreach(splashscreens,
1647 __find_appcontrol_splashscreen, &list);
1649 ss = __find_default_splashscreen(splashscreens, "portrait");
1651 list = g_list_append(list, ss);
1652 ss = __find_default_splashscreen(splashscreens, "landscape");
1654 list = g_list_append(list, ss);
1659 static int __insert_application_splashscreen_info(manifest_x *mfx)
1667 char query[MAX_QUERY_LEN] = {'\0'};
1669 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1670 app = (application_x *)app_tmp->data;
1671 if (app == NULL || app->splashscreens == NULL)
1674 ss_tmp = __find_splashscreens(app->splashscreens);
1678 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1679 ss = (splashscreen_x *)tmp->data;
1680 sqlite3_snprintf(MAX_QUERY_LEN, query,
1681 "INSERT INTO package_app_splash_screen" \
1682 "(app_id, src, type, orientation, indicatordisplay, " \
1683 "operation, color_depth) " \
1684 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1685 app->appid, ss->src, ss->type, ss->orientation,
1686 ss->indicatordisplay, ss->operation,
1689 ret = __exec_query(query);
1691 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1694 memset(query, '\0', MAX_QUERY_LEN);
1696 g_list_free(ss_tmp);
1701 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1706 char query[MAX_QUERY_LEN] = {'\0'};
1708 const char *image_type;
1709 const char *indicatordisplay;
1710 const char *orientation;
1711 const char *operation = NULL;
1712 const char *color_depth = "24"; /* default */
1714 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1715 app = (application_x *)app_tmp->data;
1717 (app->portraitimg == NULL && app->landscapeimg == NULL))
1719 image_type = "img"; /* default */
1720 if (app->effectimage_type) {
1721 tmp = strstr(app->effectimage_type, "edj");
1725 indicatordisplay = "true"; /* default */
1726 if (app->indicatordisplay)
1727 indicatordisplay = app->indicatordisplay;
1728 if (app->portraitimg) {
1729 orientation = "portrait";
1730 sqlite3_snprintf(MAX_QUERY_LEN, query,
1731 "INSERT INTO package_app_splash_screen" \
1732 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1733 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1734 app->appid, app->portraitimg, image_type,
1735 orientation, indicatordisplay, operation,
1737 ret = __exec_query(query);
1739 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1742 memset(query, '\0', MAX_QUERY_LEN);
1744 if (app->landscapeimg) {
1745 orientation = "landscape";
1746 sqlite3_snprintf(MAX_QUERY_LEN, query,
1747 "INSERT INTO package_app_splash_screen" \
1748 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1749 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1750 app->appid, app->landscapeimg, image_type,
1751 orientation, indicatordisplay, operation,
1753 ret = __exec_query(query);
1755 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1758 memset(query, '\0', MAX_QUERY_LEN);
1764 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1771 char query[MAX_QUERY_LEN] = {'\0'};
1773 char *tmpptr = NULL;
1774 const char *operation;
1775 const char *portraitimg;
1776 const char *landscapeimg;
1777 const char *indicatordisplay;
1778 const char *orientation;
1779 const char *image_type;
1780 const char *color_depth = "24"; /* default */
1782 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1783 app = (application_x *)app_tmp->data;
1787 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1788 md = (metadata_x *)md_tmp->data;
1789 if (md == NULL || md->key == NULL || md->value == NULL)
1792 if (strcasestr(md->key, "operation_effect=")) {
1793 operation = index(md->key, '=');
1794 if (operation && operation[1] != '\0')
1798 } else if (strcasestr(md->key, "launch_effect")) {
1805 landscapeimg = NULL;
1806 indicatordisplay = "true"; /* default */
1807 token = strtok_r(md->value, "|", &tmpptr);
1808 while (token != NULL) {
1809 if (strcasestr(token, "portrait-effectimage=")) {
1810 portraitimg = index(token, '=');
1811 if (portraitimg && portraitimg[1] != '\0')
1815 } else if (strcasestr(token, "landscape-effectimage=")) {
1816 landscapeimg = index(token, '=');
1817 if (landscapeimg && landscapeimg[1] != '\0')
1820 landscapeimg = NULL;
1821 } else if (strcasestr(token, "indicatordisplay=")) {
1822 indicatordisplay = index(token, '=');
1823 if (indicatordisplay && indicatordisplay[1] != '\0')
1826 indicatordisplay = "true";
1829 token = strtok_r(NULL, "|", &tmpptr);
1833 orientation = "portrait";
1835 if (strcasestr(portraitimg, "edj"))
1837 sqlite3_snprintf(MAX_QUERY_LEN, query,
1838 "INSERT INTO package_app_splash_screen" \
1839 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1840 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1841 app->appid, portraitimg, image_type,
1842 orientation, indicatordisplay, operation,
1844 ret = __exec_query(query);
1846 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1849 memset(query, '\0', MAX_QUERY_LEN);
1852 orientation = "landscape";
1854 if (strcasestr(landscapeimg, "edj"))
1856 sqlite3_snprintf(MAX_QUERY_LEN, query,
1857 "INSERT INTO package_app_splash_screen" \
1858 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1859 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1860 app->appid, landscapeimg, image_type,
1861 orientation, indicatordisplay, operation,
1863 ret = __exec_query(query);
1865 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1868 memset(query, '\0', MAX_QUERY_LEN);
1876 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1880 const char *pv = NULL;
1881 char query[MAX_QUERY_LEN] = { '\0' };
1884 const char *auth_name = NULL;
1885 const char *auth_email = NULL;
1886 const char *auth_href = NULL;
1888 GList *pkglocale = NULL;
1889 GList *applocale = NULL;
1890 GList *appicon = NULL;
1891 GList *appimage = NULL;
1893 if (mfx->author && mfx->author->data) {
1894 author = (author_x *)mfx->author->data;
1896 auth_name = author->text;
1898 auth_email = author->email;
1900 auth_href = author->href;
1903 /*Insert in the package_info DB*/
1904 sqlite3_snprintf(MAX_QUERY_LEN, query,
1905 "INSERT INTO package_info(" \
1906 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1907 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1908 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1909 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1910 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1912 "%Q, %Q, %Q, %Q, %Q, %Q, " \
1913 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1914 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), %Q, " \
1915 "%Q, %Q, %Q, %Q, %Q, " \
1916 "%Q, %Q, %Q, %Q, LOWER(%Q))",
1917 mfx->package, mfx->type, mfx->version, mfx->api_version, mfx->tep_name, mfx->zip_mount_file,
1918 mfx->installlocation, mfx->package_size, __get_bool(mfx->removable, true), __get_bool(mfx->preload, false), __get_bool(mfx->readonly, false),
1919 __get_bool(mfx->update, false), __get_bool(mfx->appsetting, false), __get_bool(mfx->nodisplay_setting, false), __get_bool(mfx->system, false), auth_name,
1920 auth_email, auth_href, mfx->installed_time, mfx->installed_storage,
1921 mfx->storeclient_id,
1922 mfx->mainapp_id, mfx->package_url, mfx->root_path, mfx->csc_path, __get_bool(mfx->support_disable, false));
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 sqlite3_snprintf(MAX_QUERY_LEN, query,
1937 "INSERT INTO package_privilege_info(package, privilege) " \
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' };
2056 sqlite3_snprintf(MAX_QUERY_LEN, query,
2057 "DELETE FROM %q where app_id=%Q", 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 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT app_id FROM package_app_info WHERE package=%Q", 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' };
2135 /*Delete from Package Info DB*/
2136 sqlite3_snprintf(MAX_QUERY_LEN, query,
2137 "DELETE FROM package_info WHERE package=%Q", mfx->package);
2138 ret = __exec_query(query);
2140 _LOGD("Package Info DB Delete Failed\n");
2143 memset(query, '\0', MAX_QUERY_LEN);
2145 /*Delete from Package Localized Info*/
2146 sqlite3_snprintf(MAX_QUERY_LEN, query,
2147 "DELETE FROM package_localized_info WHERE package=%Q", mfx->package);
2148 ret = __exec_query(query);
2150 _LOGD("Package Localized Info DB Delete Failed\n");
2154 /*Delete from Package Privilege Info*/
2155 sqlite3_snprintf(MAX_QUERY_LEN, query,
2156 "DELETE FROM package_privilege_info WHERE package=%Q", mfx->package);
2157 ret = __exec_query(query);
2159 _LOGD("Package Privilege Info DB Delete Failed\n");
2163 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2164 app = (application_x *)tmp->data;
2167 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2170 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2173 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2176 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2179 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2182 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2185 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2188 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2191 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2194 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2197 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2200 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2205 /* if main package has sub pkg, delete sub pkg data*/
2206 __delete_subpkg_from_db(mfx);
2211 static int __disable_app(const char *appid)
2214 char query[MAX_QUERY_LEN] = {'\0'};
2215 sqlite3_snprintf(MAX_QUERY_LEN, query,
2216 "UPDATE package_app_info SET app_disable='true' WHERE app_id=%Q",
2218 ret = __exec_query(query);
2220 _LOGD("Insert global app disable failed\n");
2225 static int __enable_app(const char *appid)
2228 char query[MAX_QUERY_LEN] = {'\0'};
2229 sqlite3_snprintf(MAX_QUERY_LEN, query,
2230 "UPDATE package_app_info SET app_disable='false' WHERE app_id=%Q",
2232 ret = __exec_query(query);
2234 _LOGD("Insert global app disable failed\n");
2239 static int __disable_pkg(const char *pkgid)
2242 char query[MAX_QUERY_LEN] = {'\0'};
2243 sqlite3_snprintf(MAX_QUERY_LEN, query,
2244 "UPDATE package_info SET package_disable='true' WHERE package=%Q",
2246 ret = __exec_query(query);
2248 _LOGD("Update pkg disable info has failed\n");
2253 static int __enable_pkg(const char *pkgid)
2256 char query[MAX_QUERY_LEN] = {'\0'};
2257 sqlite3_snprintf(MAX_QUERY_LEN, query,
2258 "UPDATE package_info SET package_disable='false' WHERE package=%Q",
2260 ret = __exec_query(query);
2262 _LOGD("Update pkg disable info has failed\n");
2267 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2270 char query[MAX_QUERY_LEN] = { '\0', };
2272 const char *val = NULL;
2277 sqlite3_snprintf(MAX_QUERY_LEN, query,
2278 "SELECT COUNT(*) FROM "
2279 "package_app_info_for_uid WHERE app_id=%Q "
2280 "AND uid=%d", appid, (int)uid);
2282 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2283 if (ret != SQLITE_OK) {
2284 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2285 return PMINFO_R_ERROR;
2288 if (sqlite3_step(stmt) != SQLITE_ROW) {
2289 LOGE("failed to step");
2290 sqlite3_finalize(stmt);
2291 return PMINFO_R_ERROR;
2294 val = (const char *)sqlite3_column_text(stmt, 0);
2296 sqlite3_finalize(stmt);
2301 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2304 char query[MAX_QUERY_LEN] = { '\0', };
2306 ret = __check_appinfo_for_uid_table(appid, uid);
2308 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2311 } else if (ret == 0) {
2312 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2313 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2314 "VALUES(%Q, %d, 'true', "
2315 "(SELECT app_splash_screen_display FROM package_app_info WHERE appid='%Q'))",
2316 appid, (int)uid, appid);
2318 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2319 "package_app_info_for_uid SET is_disabled='true' "
2320 "WHERE app_id=%Q AND uid=%d", appid, (int)uid);
2323 ret = __exec_query(query);
2325 _LOGD("Add global app disable info failed\n");
2330 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2333 char query[MAX_QUERY_LEN] = {'\0'};
2335 ret = __check_appinfo_for_uid_table(appid, uid);
2337 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2340 } else if (ret > 0) {
2341 sqlite3_snprintf(MAX_QUERY_LEN, query,
2342 "UPDATE package_app_info_for_uid SET "
2343 "is_disabled='false' WHERE app_id=%Q AND "
2344 "uid=%d", appid, (int)uid);
2347 ret = __exec_query(query);
2349 _LOGD("Remove global app disable info failed\n");
2354 static int __update_global_app_splash_screen_for_user(const char *appid,
2355 uid_t uid, int flag)
2358 char query[MAX_QUERY_LEN] = { '\0', };
2360 ret = __check_appinfo_for_uid_table(appid, uid);
2362 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2365 } else if (ret == 0) {
2366 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2367 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2368 "VALUES(%Q, %d, %Q)", appid, (int)uid,
2369 flag ? "true" : "false");
2371 sqlite3_snprintf(MAX_QUERY_LEN, query,
2372 "UPDATE package_app_info_for_uid SET "
2373 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2374 "uid=%d", flag ? "true" : "false", appid, (int)uid);
2377 ret = __exec_query(query);
2379 _LOGD("update global app splash screen info failed\n");
2384 static int __disable_app_splash_screen(const char *appid)
2387 char query[MAX_QUERY_LEN] = {'\0'};
2389 sqlite3_snprintf(MAX_QUERY_LEN, query,
2390 "UPDATE package_app_info SET app_splash_screen_display='false' WHERE app_id=%Q",
2392 ret = __exec_query(query);
2394 _LOGD("Failed to update app_palsh_screen_display");
2399 static int __enable_app_splash_screen(const char *appid)
2402 char query[MAX_QUERY_LEN] = {'\0'};
2404 sqlite3_snprintf(MAX_QUERY_LEN, query,
2405 "UPDATE package_app_info SET app_splash_screen_display='true' WHERE app_id=%Q",
2407 ret = __exec_query(query);
2409 _LOGD("Failed to update app_splash_screen_display");
2414 API int pkgmgr_parser_initialize_db(uid_t uid)
2419 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2421 _LOGD("package info DB initialization failed\n");
2424 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2426 _LOGD("package localized info DB initialization failed\n");
2429 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2431 _LOGD("package app app privilege DB initialization failed\n");
2434 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2436 _LOGD("package app info DB initialization failed\n");
2439 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2441 _LOGD("package app localized info DB initialization failed\n");
2444 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2446 _LOGD("package app icon localized info DB initialization failed\n");
2449 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2451 _LOGD("package app image info DB initialization failed\n");
2454 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2456 _LOGD("package app app control DB initialization failed\n");
2459 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2461 _LOGD("package app app category DB initialization failed\n");
2464 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2466 _LOGD("package app app category DB initialization failed\n");
2469 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2471 _LOGD("package app app permission DB initialization failed\n");
2474 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2476 _LOGD("package app share allowed DB initialization failed\n");
2479 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2481 _LOGD("package app share request DB initialization failed\n");
2484 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2486 _LOGD("package app data control DB initialization failed\n");
2490 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2492 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2496 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2498 _LOGD("package app splash screen DB initialization failed\n");
2502 /* Trigger package_app_info_for_uid */
2503 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2505 _LOGD("package app info for uid DB initialization failed\n");
2510 /* TODO: refactor this code */
2511 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2513 _LOGD("package cert info DB initialization failed\n");
2516 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2518 _LOGD("package cert index info DB initialization failed\n");
2521 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO);
2523 _LOGD("package cert info DB initialization failed\n");
2526 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2);
2528 _LOGD("package cert info DB initialization failed\n");
2531 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2533 _LOGD("package cert info DB initialization failed\n");
2536 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2538 _LOGD("package cert index info DB initialization failed\n");
2542 if (0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER))
2543 _LOGD("Failed to change cert db permission\n");
2545 if (0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid))
2546 _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];
2560 struct passwd userinfo, *result = NULL;
2561 files[0] = (char *)db_file;
2562 files[1] = journal_file;
2566 if (db_file == NULL)
2569 if (getuid() != OWNER_ROOT) /* At this time we should be root to apply this */
2571 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2572 if (uid == OWNER_ROOT)
2574 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2575 if (ret != 0 || result == NULL) {
2576 _LOGE("FAIL: user %d doesn't exist", uid);
2579 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2581 for (i = 0; files[i]; i++) {
2582 fd = open(files[i], O_RDONLY);
2584 if (strerror_r(errno, buf, sizeof(buf)))
2585 strncpy(buf, "", BUFSIZE - 1);
2586 _LOGD("FAIL : open %s : %s", files[i], buf);
2589 ret = fstat(fd, &sb);
2591 if (strerror_r(errno, buf, sizeof(buf)))
2592 strncpy(buf, "", BUFSIZE - 1);
2593 _LOGD("FAIL : fstat %s : %s", files[i], buf);
2597 if (S_ISLNK(sb.st_mode)) {
2598 _LOGE("FAIL : %s is symlink!", files[i]);
2602 ret = fchown(fd, uid, userinfo.pw_gid);
2604 if (strerror_r(errno, buf, sizeof(buf)))
2605 strncpy(buf, "", BUFSIZE - 1);
2606 _LOGD("FAIL : fchown %s %d.%d : %s", files[i], uid,
2607 userinfo.pw_gid, buf);
2612 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2613 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2615 ret = fchmod(fd, mode);
2617 if (strerror_r(errno, buf, sizeof(buf)))
2618 strncpy(buf, "", BUFSIZE - 1);
2619 _LOGD("FAIL : fchmod %s 0664 : %s", files[i], buf);
2624 SET_SMACK_LABEL(files[i]);
2629 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2633 if (getuid() != OWNER_ROOT) {
2634 _LOGE("Only root user is allowed");
2638 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2639 _LOGE("Manifest db for user %d is already exists", uid);
2643 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2644 _LOGE("Cert db for user %d is already exists", uid);
2648 ret = pkgmgr_parser_check_and_create_db(uid);
2651 ret = pkgmgr_parser_initialize_db(uid);
2653 pkgmgr_parser_close_db();
2656 pkgmgr_parser_close_db();
2661 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2665 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2667 _LOGD("Manifest DB creation Failed\n");
2672 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2674 _LOGD("Cert DB creation Failed\n");
2680 void pkgmgr_parser_close_db(void)
2682 sqlite3_close(pkgmgr_parser_db);
2683 sqlite3_close(pkgmgr_cert_db);
2687 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2689 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2691 _LOGD("manifest pointer is NULL\n");
2695 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2697 _LOGD("Failed to open DB\n");
2700 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2703 /*Begin transaction*/
2704 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2705 if (ret != SQLITE_OK) {
2706 _LOGD("Failed to begin transaction\n");
2710 _LOGD("Transaction Begin\n");
2711 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2713 _LOGD("Insert into DB failed. Rollback now\n");
2714 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2717 /*Commit transaction*/
2718 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2719 if (ret != SQLITE_OK) {
2720 _LOGD("Failed to commit transaction. Rollback now\n");
2721 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2725 _LOGD("Transaction Commit and End\n");
2727 pkgmgr_parser_close_db();
2731 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2733 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2735 _LOGD("manifest pointer is NULL\n");
2739 ret = pkgmgr_parser_check_and_create_db(uid);
2741 _LOGD("Failed to open DB\n");
2744 ret = pkgmgr_parser_initialize_db(uid);
2747 /*Begin transaction*/
2748 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2749 if (ret != SQLITE_OK) {
2750 _LOGD("Failed to begin transaction\n");
2754 _LOGD("Transaction Begin\n");
2755 ret = __insert_manifest_info_in_db(mfx, uid);
2757 _LOGD("Insert into DB failed. Rollback now\n");
2758 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2761 /*Commit transaction*/
2762 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2763 if (ret != SQLITE_OK) {
2764 _LOGD("Failed to commit transaction. Rollback now\n");
2765 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2769 _LOGD("Transaction Commit and End\n");
2771 pkgmgr_parser_close_db();
2775 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2777 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, _getuid());
2780 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2782 if (pkgid == NULL || tep_path == NULL) {
2783 _LOGE("invalid parameter");
2790 ret = pkgmgr_parser_check_and_create_db(uid);
2792 _LOGD("Failed to open DB\n");
2795 ret = pkgmgr_parser_initialize_db(uid);
2799 /*Begin transaction*/
2800 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2801 if (ret != SQLITE_OK) {
2802 _LOGD("Failed to begin transaction\n");
2806 _LOGD("Transaction Begin\n");
2809 /* Updating TEP info in "package_info" table */
2810 query = sqlite3_mprintf("UPDATE package_info "\
2811 "SET package_tep_name = %Q "\
2812 "WHERE package = %Q", tep_path, pkgid);
2814 ret = __exec_query(query);
2815 sqlite3_free(query);
2816 if (ret != SQLITE_OK) {
2817 ret = PM_PARSER_R_ERROR;
2818 _LOGE("sqlite exec failed to insert entries into package_info!!");
2822 /* Updating TEP info in "package_app_info" table */
2823 query = sqlite3_mprintf("UPDATE package_app_info "\
2824 "SET app_tep_name = %Q "\
2825 "WHERE package = %Q", tep_path, pkgid);
2827 ret = __exec_query(query);
2828 sqlite3_free(query);
2829 if (ret != SQLITE_OK) {
2830 ret = PM_PARSER_R_ERROR;
2831 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2835 /*Commit transaction*/
2836 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2837 if (ret != SQLITE_OK) {
2838 _LOGE("Failed to commit transaction, Rollback now\n");
2839 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2840 if (ret != SQLITE_OK)
2841 _LOGE("Failed to Rollback\n");
2843 ret = PM_PARSER_R_ERROR;
2846 _LOGD("Transaction Commit and End\n");
2847 ret = PM_PARSER_R_OK;
2850 pkgmgr_parser_close_db();
2855 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2858 _LOGD("manifest pointer is NULL\n");
2862 ret = pkgmgr_parser_check_and_create_db(uid);
2864 _LOGD("Failed to open DB\n");
2867 ret = pkgmgr_parser_initialize_db(uid);
2870 /*Preserve guest mode visibility*/
2871 __preserve_guestmode_visibility_value(mfx);
2872 /*Begin transaction*/
2873 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2874 if (ret != SQLITE_OK) {
2875 _LOGD("Failed to begin transaction\n");
2879 _LOGD("Transaction Begin\n");
2880 ret = __delete_manifest_info_from_db(mfx, uid);
2882 _LOGD("Delete from DB failed. Rollback now\n");
2883 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2886 ret = __insert_manifest_info_in_db(mfx, uid);
2888 _LOGD("Insert into DB failed. Rollback now\n");
2889 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2893 /*Commit transaction*/
2894 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2895 if (ret != SQLITE_OK) {
2896 _LOGD("Failed to commit transaction. Rollback now\n");
2897 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2901 _LOGD("Transaction Commit and End\n");
2903 pkgmgr_parser_close_db();
2907 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2909 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2912 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2915 _LOGD("manifest pointer is NULL\n");
2919 ret = pkgmgr_parser_check_and_create_db(uid);
2921 _LOGD("Failed to open DB\n");
2924 /*Begin transaction*/
2925 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2926 if (ret != SQLITE_OK) {
2927 _LOGD("Failed to begin transaction\n");
2931 _LOGD("Transaction Begin\n");
2932 ret = __delete_manifest_info_from_db(mfx, uid);
2934 _LOGD("Delete from DB failed. Rollback now\n");
2935 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2938 /*Commit transaction*/
2939 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2940 if (ret != SQLITE_OK) {
2941 _LOGD("Failed to commit transaction, Rollback now\n");
2942 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2946 _LOGD("Transaction Commit and End\n");
2948 pkgmgr_parser_close_db();
2952 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2954 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
2957 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2961 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2963 _LOGD("Failed to open DB\n");
2967 /*Begin transaction*/
2968 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2969 if (ret != SQLITE_OK) {
2970 _LOGD("Failed to begin transaction\n");
2974 _LOGD("Transaction Begin\n");
2976 ret = __disable_global_app_for_user(appid, uid);
2978 ret = __enable_global_app_for_user(appid, uid);
2980 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2981 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2984 /*Commit transaction*/
2985 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2986 if (ret != SQLITE_OK) {
2987 _LOGD("Failed to commit transaction, Rollback now\n");
2988 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2992 _LOGD("Transaction Commit and End\n");
2994 pkgmgr_parser_close_db();
2999 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
3001 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
3004 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid, uid_t uid, int is_disable)
3008 ret = pkgmgr_parser_check_and_create_db(uid);
3010 _LOGD("Failed to open DB\n");
3014 /*Begin transaction*/
3015 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3016 if (ret != SQLITE_OK) {
3017 _LOGD("Failed to begin transaction\n");
3022 _LOGD("Transaction Begin\n");
3024 ret = __disable_pkg(pkgid);
3026 ret = __enable_pkg(pkgid);
3029 _LOGD("__update_pkg_disable_condition_in_db failed. Rollback now\n");
3030 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3034 /*Commit transaction*/
3035 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3036 if (ret != SQLITE_OK) {
3037 _LOGD("Failed to commit transaction, Rollback now\n");
3038 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3042 _LOGD("Transaction Commit and End\n");
3045 pkgmgr_parser_close_db();
3049 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid, int is_disable)
3051 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid, _getuid(), is_disable);
3054 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
3058 ret = pkgmgr_parser_check_and_create_db(uid);
3060 _LOGD("Failed to open DB\n");
3064 /*Begin transaction*/
3065 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3066 if (ret != SQLITE_OK) {
3067 _LOGD("Failed to begin transaction\n");
3071 _LOGD("Transaction Begin\n");
3073 ret = __disable_app(appid);
3075 ret = __enable_app(appid);
3077 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
3078 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3081 /*Commit transaction*/
3082 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3083 if (ret != SQLITE_OK) {
3084 _LOGD("Failed to commit transaction, Rollback now\n");
3085 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3089 _LOGD("Transaction Commit and End\n");
3091 pkgmgr_parser_close_db();
3096 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3100 if (appid == NULL) {
3101 _LOGD("Invalid parameter");
3105 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3107 _LOGD("Failed to open DB\n");
3111 /* Begin transaction */
3112 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3113 if (ret != SQLITE_OK) {
3114 _LOGD("Failed to begin transaction\n");
3118 _LOGD("Transaction Begin\n");
3120 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3122 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3123 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3126 /* Commit transaction */
3127 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3128 if (ret != SQLITE_OK) {
3129 _LOGD("Failed to commit transaction, Rollback now\n");
3130 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3134 _LOGD("Transaction Commit and End\n");
3136 pkgmgr_parser_close_db();
3140 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3142 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3145 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3149 if (appid == NULL) {
3150 _LOGD("Invalid parameter");
3154 ret = pkgmgr_parser_check_and_create_db(uid);
3156 _LOGD("Failed to open DB");
3160 /* Begin transaction */
3161 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3162 if (ret != SQLITE_OK) {
3163 _LOGD("Failed to begin transaction");
3167 _LOGD("Transaction Begin");
3170 ret = __enable_app_splash_screen(appid);
3172 ret = __disable_app_splash_screen(appid);
3174 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3175 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3178 /* Commit transaction */
3179 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3180 if (ret != SQLITE_OK) {
3181 _LOGD("Failed to commit transaction, Rollback now");
3182 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3186 _LOGD("Transaction Commit and End");
3189 pkgmgr_parser_close_db();