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) " \
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++)
463 if (strcmp(colname[i], "app_id") == 0) {
465 appid = strdup(coltxt[i]);
466 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
468 status = strdup(coltxt[i]);
474 _LOGD("app id is NULL\n");
477 /*update guest mode visibility*/
478 for (tmp = mfx->application; tmp; tmp = tmp->next) {
479 app = (application_x *)tmp->data;
482 if (strcmp(app->appid, appid) == 0) {
483 free((void *)app->guestmode_visibility);
484 app->guestmode_visibility = strdup(status);
500 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
502 char *error_message = NULL;
503 char query[MAX_QUERY_LEN] = {'\0'};
504 sqlite3_snprintf(MAX_QUERY_LEN, query,
505 "SELECT app_id, app_guestmodevisibility FROM package_app_info " \
506 "WHERE package=%Q", mfx->package);
508 sqlite3_exec(pkgmgr_parser_db, query,
509 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
510 _LOGD("Don't execute query = %s error message = %s\n",
511 query, error_message);
512 sqlite3_free(error_message);
517 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
519 char *error_message = NULL;
521 sqlite3_exec(db_handle, db_query,
522 NULL, NULL, &error_message)) {
523 _LOGD("Don't execute query = %s error message = %s\n",
524 db_query, error_message);
525 sqlite3_free(error_message);
528 sqlite3_free(error_message);
532 static int __exec_query(char *query)
534 char *error_message = NULL;
536 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
537 _LOGE("Don't execute query = %s error message = %s\n", query,
539 sqlite3_free(error_message);
542 sqlite3_free(error_message);
546 static int __exec_query_no_msg(char *query)
548 char *error_message = NULL;
550 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
551 sqlite3_free(error_message);
554 sqlite3_free(error_message);
558 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
566 for (tmp = lbls; tmp; tmp = tmp->next) {
567 lbl = (label_x *)tmp->data;
571 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
573 for (tmp = lcns; tmp; tmp = tmp->next) {
574 lcn = (license_x *)tmp->data;
578 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
580 for (tmp = icns; tmp; tmp = tmp->next) {
581 icn = (icon_x *)tmp->data;
585 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
587 for (tmp = dcns; tmp; tmp = tmp->next) {
588 dcn = (description_x *)tmp->data;
592 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
594 for (tmp = aths; tmp; tmp = tmp->next) {
595 ath = (author_x *)tmp->data;
599 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
605 static GList *__create_icon_list(GList *appicon, GList *icns)
610 for (tmp = icns; tmp; tmp = tmp->next) {
611 icn = (icon_x *)tmp->data;
615 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
620 static GList *__create_image_list(GList *appimage, GList *imgs)
625 for (tmp = imgs; tmp; tmp = tmp->next) {
626 img = (image_x *)tmp->data;
630 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
635 static void __trimfunc(GList* trim_list)
637 char *trim_data = NULL;
641 list = g_list_first(trim_list);
644 trim_data = (char *)list->data;
647 if (strcmp(trim_data, prev) == 0) {
648 trim_list = g_list_remove(trim_list, trim_data);
649 list = g_list_first(trim_list);
658 list = g_list_next(list);
662 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
664 if (a == NULL || b == NULL)
666 if (strcmp((char*)a, (char*)b) == 0)
668 if (strcmp((char*)a, (char*)b) < 0)
670 if (strcmp((char*)a, (char*)b) > 0)
675 static int __check_dpi(const char *dpi_char, int dpi_int)
677 if (dpi_char == NULL)
680 if (strcasecmp(dpi_char, LDPI) == 0) {
681 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
685 } else if (strcasecmp(dpi_char, MDPI) == 0) {
686 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
690 } else if (strcasecmp(dpi_char, HDPI) == 0) {
691 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
695 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
696 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
700 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
701 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
709 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
712 char *icon_filename = NULL;
713 char modified_iconpath[BUFSIZE] = { '\0' };
714 char icon_path[BUFSIZE] = { '\0' };
718 if (orig_icon_path == NULL)
721 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
725 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
726 dpi_path[0] = "LDPI";
727 dpi_path[1] = "ldpi";
728 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
729 dpi_path[0] = "MDPI";
730 dpi_path[1] = "mdpi";
731 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
732 dpi_path[0] = "HDPI";
733 dpi_path[1] = "hdpi";
734 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
735 dpi_path[0] = "XHDPI";
736 dpi_path[1] = "xhdpi";
737 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
738 dpi_path[0] = "XXHDPI";
739 dpi_path[1] = "xxhdpi";
741 _LOGE("Unidentified dpi[%d]", dpi);
745 icon_filename = strrchr(orig_icon_path, '/');
746 if (icon_filename == NULL)
749 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
750 for (i = 0; i < 2; i++) {
751 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
752 if (access(modified_iconpath, F_OK) != -1) {
753 // if exists, return modified icon path
754 *new_icon_path = strdup(modified_iconpath);
762 static gint __compare_icon(gconstpointer a, gconstpointer b)
764 icon_x *icon = (icon_x *)a;
766 char *icon_folder_path = NULL;
768 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
771 if (icon->dpi != NULL)
774 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
776 icon->text = icon_folder_path;
782 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
784 icon_x *icon = (icon_x *)a;
785 int dpi = GPOINTER_TO_INT(b);
787 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
790 if (icon->dpi == NULL)
793 if (__check_dpi(icon->dpi, dpi) == 0)
799 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
801 icon_x *icon = (icon_x *)a;
802 char *lang = (char *)b;
803 char *icon_folder_path = NULL;
805 if (icon->dpi != NULL)
808 if (strcasecmp(icon->lang, lang) == 0) {
809 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
810 //icon for no locale. check existance of folder-hierachied default icons
811 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
813 icon->text = icon_folder_path;
822 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
824 icon_x *icon = (icon_x *)a;
825 char *lang = (char *)b;
828 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
832 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
838 static char *__find_icon(GList *icons, const char *lang)
845 // first, find icon whose locale and dpi with given lang and system's dpi has matched
846 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
848 icon = (icon_x *)tmp->data;
849 return (char *)icon->text;
852 // if first has failed, find icon whose locale has matched
853 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
855 icon = (icon_x *)tmp->data;
856 return (char *)icon->text;
859 // if second has failed, find icon whose dpi has matched with system's dpi
860 ret = system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
861 if (ret == SYSTEM_INFO_ERROR_NONE) {
862 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
864 icon = (icon_x *)tmp->data;
865 return (char *)icon->text;
869 // last, find default icon marked as "No Locale"
870 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
872 icon = (icon_x *)tmp->data;
873 return (char *)icon->text;
879 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
880 char **label, char **license, char **icon, char **description, char **author)
887 for (tmp = lbls; tmp; tmp = tmp->next) {
888 lbl = (label_x *)tmp->data;
892 if (strcmp(lbl->lang, (char *)data) == 0) {
893 *label = (char*)lbl->text;
898 for (tmp = lcns; tmp; tmp = tmp->next) {
899 lcn = (license_x *)tmp->data;
903 if (strcmp(lcn->lang, (char *)data) == 0) {
904 *license = (char*)lcn->text;
910 *icon = __find_icon(icns, (char *)data);
912 for (tmp = dcns; tmp; tmp = tmp->next) {
913 dcn = (description_x *)tmp->data;
917 if (strcmp(dcn->lang, (char *)data) == 0) {
918 *description = (char*)dcn->text;
923 for (tmp = aths; tmp; tmp = tmp->next) {
924 ath = (author_x *)tmp->data;
928 if (strcmp(ath->lang, (char *)data) == 0) {
929 *author = (char*)ath->text;
937 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
941 for (tmp = icns; tmp; tmp = tmp->next) {
942 icn = (icon_x *)tmp->data;
946 if (strcmp(icn->section, (char *)data) == 0) {
947 *icon = (char*)icn->text;
948 *resolution = (char*)icn->resolution;
955 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
959 for (tmp = imgs; tmp; tmp = tmp->next) {
960 img = (image_x *)tmp->data;
964 if (strcmp(img->section, (char *)data) == 0) {
965 *lang = (char*)img->lang;
966 *image = (char*)img->text;
973 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
978 char *description = NULL;
979 char *license = NULL;
983 manifest_x *mfx = (manifest_x *)userdata;
984 GList *lbl = mfx->label;
985 GList *lcn = mfx->license;
986 GList *icn = mfx->icon;
987 GList *dcn = mfx->description;
988 GList *ath = mfx->author;
990 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
991 if (!label && !description && !icon && !license && !author)
994 query = sqlite3_mprintf("INSERT INTO package_localized_info(package, package_locale, " \
995 "package_label, package_icon, package_description, package_license, package_author) VALUES" \
996 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1005 ret = __exec_query(query);
1007 _LOGD("Package Localized Info DB Insert failed\n");
1009 sqlite3_free(query);
1012 static void __insert_application_locale_info(gpointer data, gpointer userdata)
1019 application_x *app = (application_x*)userdata;
1020 GList *lbl = app->label;
1021 GList *icn = app->icon;
1023 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1024 if (!label && !icon)
1027 query = sqlite3_mprintf("INSERT INTO package_app_localized_info(app_id, app_locale, " \
1028 "app_label, app_icon) VALUES" \
1029 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
1031 ret = __exec_query(query);
1033 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1035 sqlite3_free(query);
1037 /*insert ui app locale info to pkg locale to get mainapp data */
1038 if (strcasecmp(app->mainapp, "true")==0) {
1039 query = sqlite3_mprintf("INSERT INTO package_localized_info(package, package_locale, " \
1040 "package_label, package_icon, package_description, package_license, package_author) VALUES" \
1041 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1050 ret = __exec_query_no_msg(query);
1051 sqlite3_free(query);
1054 query = sqlite3_mprintf("UPDATE package_localized_info SET package_icon=%Q "\
1055 "WHERE package=%Q AND package_locale=%Q", icon, app->package, (char*)data);
1056 ret = __exec_query_no_msg(query);
1057 sqlite3_free(query);
1062 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1066 char *resolution = NULL;
1067 char query[MAX_QUERY_LEN] = {'\0'};
1069 application_x *app = (application_x*)userdata;
1070 GList *icn = app->icon;
1072 __extract_icon_data(data, icn, &icon, &resolution);
1073 if (!icon && !resolution)
1075 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO package_app_icon_section_info(app_id, " \
1076 "app_icon, app_icon_section, app_icon_resolution) VALUES " \
1077 "(%Q, %Q, %Q, %Q)", app->appid,
1078 icon, (char*)data, resolution);
1080 ret = __exec_query(query);
1082 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1086 static void __insert_application_image_info(gpointer data, gpointer userdata)
1091 char query[MAX_QUERY_LEN] = {'\0'};
1093 application_x *app = (application_x*)userdata;
1094 GList *image = app->image;
1096 __extract_image_data(data, image, &lang, &img);
1099 sqlite3_snprintf(MAX_QUERY_LEN, query,
1100 "INSERT INTO package_app_image_info(app_id, app_locale, " \
1101 "app_image_section, app_image) VALUES" \
1102 "(%Q, %Q, %Q, %Q)", app->appid, lang, (char*)data, img);
1104 ret = __exec_query(query);
1106 _LOGD("Package UiApp image Info DB Insert failed\n");
1111 static int __insert_mainapp_info(manifest_x *mfx)
1116 char query[MAX_QUERY_LEN] = {'\0'};
1117 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1118 app = (application_x *)tmp->data;
1122 sqlite3_snprintf(MAX_QUERY_LEN, query,
1123 "UPDATE package_app_info SET app_mainapp=%Q WHERE app_id=%Q",
1124 app->mainapp, app->appid);
1125 ret = __exec_query(query);
1127 _LOGD("Package App Info DB Insert Failed\n");
1130 if (strcasecmp(app->mainapp, "True")==0)
1131 mfx->mainapp_id = strdup(app->appid);
1134 if (mfx->mainapp_id == NULL) {
1135 if (mfx->application == NULL)
1137 app = (application_x *)mfx->application->data;
1141 sqlite3_snprintf(MAX_QUERY_LEN, query,
1142 "UPDATE package_app_info SET app_mainapp='true' WHERE app_id=%Q",
1145 _LOGD("Not valid appid\n");
1149 ret = __exec_query(query);
1151 _LOGD("Package UiApp Info DB Insert Failed\n");
1155 free((void *)app->mainapp);
1156 app->mainapp= strdup("true");
1157 mfx->mainapp_id = strdup(app->appid);
1160 memset(query, '\0', MAX_QUERY_LEN);
1161 sqlite3_snprintf(MAX_QUERY_LEN, query,
1162 "UPDATE package_info SET mainapp_id=%Q WHERE package=%Q", mfx->mainapp_id, mfx->package);
1163 ret = __exec_query(query);
1165 _LOGD("Package Info DB update Failed\n");
1172 static int __convert_background_category(GList *category_list)
1175 GList *tmp_list = category_list;
1176 char *category_data = NULL;
1178 if (category_list == NULL)
1181 while (tmp_list != NULL) {
1182 category_data = (char *)tmp_list->data;
1183 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1184 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1185 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1186 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1187 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1188 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1189 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1190 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1191 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1192 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1193 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1194 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1195 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1196 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1198 _LOGE("Unidentified category [%s]", category_data);
1200 tmp_list = g_list_next(tmp_list);
1206 static const char *__find_effective_appid(GList *metadata_list)
1211 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1212 md = (metadata_x *)tmp_list->data;
1213 if (md == NULL || md->key == NULL)
1216 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1225 static char *__get_bool(char *value, bool is_true)
1227 if (value != NULL) {
1228 if (!strcmp(value, ""))
1229 return (is_true) ? "true" : "false";
1233 return (is_true) ? "true" : "false";
1236 /* _PRODUCT_LAUNCHING_ENHANCED_
1237 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1239 static int __insert_application_info(manifest_x *mfx)
1244 int background_value = 0;
1245 char query[MAX_QUERY_LEN] = {'\0'};
1247 const char *effective_appid;
1250 type = strdup(mfx->type);
1252 type = strdup("tpk");
1254 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1255 app = (application_x *)tmp->data;
1259 background_value = __convert_background_category(app->background_category);
1260 if (background_value < 0) {
1261 _LOGE("Failed to retrieve background value[%d]", background_value);
1262 background_value = 0;
1265 effective_appid = __find_effective_appid(app->metadata);
1267 sqlite3_snprintf(MAX_QUERY_LEN, query,
1268 "INSERT INTO package_app_info(" \
1269 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1270 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1271 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1272 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1273 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1274 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1275 "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, " \
1276 "app_api_version, app_effective_appid, app_splash_screen_display) " \
1278 "%Q, %Q, %Q, LOWER(%Q), %Q, " \
1279 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1280 "%Q, %Q, %Q, %Q, %Q, " \
1281 "LOWER(%Q), %Q, %Q, LOWER(%Q), %Q, " \
1282 "LOWER(%Q), LOWER(%Q), %Q, %Q, LOWER(%Q), " \
1283 "COALESCE(%Q, 'caller'), LOWER(%Q), LOWER(%Q), %Q, %Q, " \
1284 "%Q, %Q, %d, %Q, %Q, " \
1285 "%Q, %Q, LOWER(%Q))", \
1286 app->appid, app->component_type, app->exec, __get_bool(app->nodisplay, false), app->type,
1287 __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),
1288 app->hwacceleration, app->screenreader, app->mainapp, app->recentimage, app->launchcondition,
1289 __get_bool(app->indicatordisplay, true), app->portraitimg, app->landscapeimg,
1290 __get_bool(app->guestmode_visibility, true), app->permission_type,
1291 __get_bool(mfx->preload, false), __get_bool(app->submode, false), app->submode_mainid, mfx->installed_storage, __get_bool(app->process_pool, false),
1292 app->launch_mode, __get_bool(app->ui_gadget, false), __get_bool(mfx->support_disable, false), app->component_type, mfx->package,
1293 mfx->tep_name, mfx->zip_mount_file, background_value, type, mfx->root_path, mfx->api_version,
1294 effective_appid, __get_bool(app->splash_screen_display, false));
1296 ret = __exec_query(query);
1298 _LOGD("Package UiApp Info DB Insert Failed\n");
1303 memset(query, '\0', MAX_QUERY_LEN);
1312 static int __insert_application_appcategory_info(manifest_x *mfx)
1319 char query[MAX_QUERY_LEN] = {'\0'};
1320 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1321 app = (application_x *)app_tmp->data;
1324 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1325 ct = (const char *)ct_tmp->data;
1328 sqlite3_snprintf(MAX_QUERY_LEN, query,
1329 "INSERT INTO package_app_app_category(app_id, category) " \
1332 ret = __exec_query(query);
1334 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1337 memset(query, '\0', MAX_QUERY_LEN);
1343 static int __insert_application_appmetadata_info(manifest_x *mfx)
1350 char query[MAX_QUERY_LEN] = {'\0'};
1351 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1352 app = (application_x *)app_tmp->data;
1355 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1356 md = (metadata_x *)md_tmp->data;
1360 sqlite3_snprintf(MAX_QUERY_LEN, query,
1361 "INSERT INTO package_app_app_metadata(app_id, md_key, md_value) " \
1362 "VALUES(%Q, %Q, %Q)",\
1363 app->appid, md->key, md->value ? md->value : NULL);
1364 ret = __exec_query(query);
1366 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1370 memset(query, '\0', MAX_QUERY_LEN);
1376 static int __insert_application_apppermission_info(manifest_x *mfx)
1383 char query[MAX_QUERY_LEN] = {'\0'};
1384 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1385 app = (application_x *)app_tmp->data;
1388 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1389 pm = (permission_x *)pm_tmp->data;
1392 sqlite3_snprintf(MAX_QUERY_LEN, query,
1393 "INSERT INTO package_app_app_permission(app_id, pm_type, pm_value) " \
1394 "VALUES(%Q, %Q, %Q)",\
1395 app->appid, pm->type, pm->value);
1396 ret = __exec_query(query);
1398 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1401 memset(query, '\0', MAX_QUERY_LEN);
1407 static int __insert_application_appcontrol_info(manifest_x *mfx)
1411 GList *acontrol_tmp;
1412 appcontrol_x *acontrol;
1414 char query[MAX_QUERY_LEN] = {'\0'};
1415 char buf[BUFSIZE] = {'\0'};
1416 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1417 app = (application_x *)app_tmp->data;
1420 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1421 acontrol = (appcontrol_x *)acontrol_tmp->data;
1422 if (acontrol == NULL)
1424 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1425 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1426 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1427 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1428 sqlite3_snprintf(MAX_QUERY_LEN, query,
1429 "INSERT INTO package_app_app_control(app_id, app_control) " \
1432 ret = __exec_query(query);
1434 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1437 memset(query, '\0', MAX_QUERY_LEN);
1443 static int __insert_application_datacontrol_info(manifest_x *mfx)
1450 char query[MAX_QUERY_LEN] = {'\0'};
1452 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1453 app = (application_x *)app_tmp->data;
1456 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1457 dc = (datacontrol_x *)dc_tmp->data;
1460 sqlite3_snprintf(MAX_QUERY_LEN, query,
1461 "INSERT INTO package_app_data_control(app_id, providerid, access, type) " \
1462 "VALUES(%Q, %Q, %Q, %Q)",\
1468 ret = __exec_query(query);
1470 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1473 memset(query, '\0', MAX_QUERY_LEN);
1479 static int __insert_application_share_request_info(manifest_x *mfx)
1488 char query[MAX_QUERY_LEN] = {'\0'};
1489 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1490 app = (application_x *)app_tmp->data;
1493 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1494 ds = (datashare_x *)ds_tmp->data;
1497 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1498 rq = (const char *)rq_tmp->data;
1501 sqlite3_snprintf(MAX_QUERY_LEN, query,
1502 "INSERT INTO package_app_share_request(app_id, data_share_request) " \
1505 ret = __exec_query(query);
1507 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1510 memset(query, '\0', MAX_QUERY_LEN);
1517 static int __insert_application_share_allowed_info(manifest_x *mfx)
1528 char query[MAX_QUERY_LEN] = {'\0'};
1529 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1530 app = (application_x *)app_tmp->data;
1533 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1534 ds = (datashare_x *)ds_tmp->data;
1537 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1538 df = (define_x *)df_tmp->data;
1541 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1542 al = (const char *)al_tmp->data;
1545 sqlite3_snprintf(MAX_QUERY_LEN, query,
1546 "INSERT INTO package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1547 "VALUES(%Q, %Q, %Q)",\
1548 app->appid, df->path, al);
1549 ret = __exec_query(query);
1551 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1554 memset(query, '\0', MAX_QUERY_LEN);
1562 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1564 splashscreen_x *ss = (splashscreen_x *)a;
1565 const char *orientation = (const char *)b;
1568 if (ss->operation || ss->dpi == NULL)
1571 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1575 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1581 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1583 splashscreen_x *ss = (splashscreen_x *)a;
1584 const char *orientation = (const char *)b;
1586 if (ss->operation || ss->dpi)
1589 if (strcasecmp(ss->orientation, orientation) == 0)
1595 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1596 const char *orientation)
1600 tmp = g_list_find_custom(splashscreens, orientation,
1601 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1603 return (splashscreen_x *)tmp->data;
1605 tmp = g_list_find_custom(splashscreens, orientation,
1606 (GCompareFunc)__compare_splashscreen_with_orientation);
1608 return (splashscreen_x *)tmp->data;
1613 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1615 splashscreen_x *ss = (splashscreen_x *)data;
1616 GList **list = (GList **)user_data;
1619 if (ss->operation == NULL || ss->dpi == NULL)
1622 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1626 if (__check_dpi(ss->dpi, dpi) != 0)
1629 *list = g_list_append(*list, ss);
1632 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1634 splashscreen_x *ss = (splashscreen_x *)data;
1635 GList **list = (GList **)user_data;
1636 splashscreen_x *ss_tmp;
1639 if (ss->operation == NULL || ss->dpi)
1642 for (tmp = *list; tmp; tmp = tmp->next) {
1643 ss_tmp = (splashscreen_x *)tmp->data;
1644 if (ss_tmp->operation
1645 && strcmp(ss_tmp->operation, ss->operation) == 0
1646 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1650 *list = g_list_append(*list, ss);
1653 static GList *__find_splashscreens(GList *splashscreens)
1658 g_list_foreach(splashscreens,
1659 __find_appcontrol_splashscreen_with_dpi, &list);
1660 g_list_foreach(splashscreens,
1661 __find_appcontrol_splashscreen, &list);
1663 ss = __find_default_splashscreen(splashscreens, "portrait");
1665 list = g_list_append(list, ss);
1666 ss = __find_default_splashscreen(splashscreens, "landscape");
1668 list = g_list_append(list, ss);
1673 static int __insert_application_splashscreen_info(manifest_x *mfx)
1681 char query[MAX_QUERY_LEN] = {'\0'};
1683 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1684 app = (application_x *)app_tmp->data;
1685 if (app == NULL || app->splashscreens == NULL)
1688 ss_tmp = __find_splashscreens(app->splashscreens);
1692 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1693 ss = (splashscreen_x *)tmp->data;
1694 sqlite3_snprintf(MAX_QUERY_LEN, query,
1695 "INSERT INTO package_app_splash_screen" \
1696 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1697 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1698 app->appid, ss->src, ss->type, ss->orientation,
1699 ss->indicatordisplay, ss->operation,
1701 ret = __exec_query(query);
1703 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1706 memset(query, '\0', MAX_QUERY_LEN);
1708 g_list_free(ss_tmp);
1713 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1718 char query[MAX_QUERY_LEN] = {'\0'};
1720 const char *image_type;
1721 const char *indicatordisplay;
1722 const char *orientation;
1723 const char *operation = NULL;
1724 const char *color_depth = "24"; /* default */
1726 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1727 app = (application_x *)app_tmp->data;
1729 (app->portraitimg == NULL && app->landscapeimg == NULL))
1731 image_type = "img"; /* default */
1732 if (app->effectimage_type) {
1733 tmp = strstr(app->effectimage_type, "edj");
1737 indicatordisplay = "true"; /* default */
1738 if (app->indicatordisplay)
1739 indicatordisplay = app->indicatordisplay;
1740 if (app->portraitimg) {
1741 orientation = "portrait";
1742 sqlite3_snprintf(MAX_QUERY_LEN, query,
1743 "INSERT INTO package_app_splash_screen" \
1744 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1745 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1746 app->appid, app->portraitimg, image_type,
1747 orientation, indicatordisplay, operation,
1749 ret = __exec_query(query);
1751 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1754 memset(query, '\0', MAX_QUERY_LEN);
1756 if (app->landscapeimg) {
1757 orientation = "landscape";
1758 sqlite3_snprintf(MAX_QUERY_LEN, query,
1759 "INSERT INTO package_app_splash_screen" \
1760 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1761 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1762 app->appid, app->landscapeimg, image_type,
1763 orientation, indicatordisplay, operation,
1765 ret = __exec_query(query);
1767 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1770 memset(query, '\0', MAX_QUERY_LEN);
1776 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1783 char query[MAX_QUERY_LEN] = {'\0'};
1785 char *tmpptr = NULL;
1786 const char *operation;
1787 const char *portraitimg;
1788 const char *landscapeimg;
1789 const char *indicatordisplay;
1790 const char *orientation;
1791 const char *image_type;
1792 const char *color_depth = "24"; /* default */
1794 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1795 app = (application_x *)app_tmp->data;
1799 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1800 md = (metadata_x *)md_tmp->data;
1801 if (md == NULL || md->key == NULL || md->value == NULL)
1804 if (strcasestr(md->key, "operation_effect=")) {
1805 operation = index(md->key, '=');
1806 if (operation && operation[1] != '\0')
1810 } else if (strcasestr(md->key, "launch_effect")) {
1817 landscapeimg = NULL;
1818 indicatordisplay = "true"; /* default */
1819 token = strtok_r(md->value, "|", &tmpptr);
1820 while (token != NULL) {
1821 if (strcasestr(token, "portrait-effectimage=")) {
1822 portraitimg = index(token, '=');
1823 if (portraitimg && portraitimg[1] != '\0')
1827 } else if (strcasestr(token, "landscape-effectimage=")) {
1828 landscapeimg = index(token, '=');
1829 if (landscapeimg && landscapeimg[1] != '\0')
1832 landscapeimg = NULL;
1833 } else if (strcasestr(token, "indicatordisplay=")) {
1834 indicatordisplay = index(token, '=');
1835 if (indicatordisplay && indicatordisplay[1] != '\0')
1838 indicatordisplay = "true";
1841 token = strtok_r(NULL, "|", &tmpptr);
1845 orientation = "portrait";
1847 if (strcasestr(portraitimg, "edj"))
1849 sqlite3_snprintf(MAX_QUERY_LEN, query,
1850 "INSERT INTO package_app_splash_screen" \
1851 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1852 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1853 app->appid, portraitimg, image_type,
1854 orientation, indicatordisplay, operation,
1856 ret = __exec_query(query);
1858 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1861 memset(query, '\0', MAX_QUERY_LEN);
1864 orientation = "landscape";
1866 if (strcasestr(landscapeimg, "edj"))
1868 sqlite3_snprintf(MAX_QUERY_LEN, query,
1869 "INSERT INTO package_app_splash_screen" \
1870 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1871 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1872 app->appid, landscapeimg, image_type,
1873 orientation, indicatordisplay, operation,
1875 ret = __exec_query(query);
1877 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1880 memset(query, '\0', MAX_QUERY_LEN);
1888 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1892 const char *pv = NULL;
1893 char query[MAX_QUERY_LEN] = { '\0' };
1896 const char *auth_name = NULL;
1897 const char *auth_email = NULL;
1898 const char *auth_href = NULL;
1900 GList *pkglocale = NULL;
1901 GList *applocale = NULL;
1902 GList *appicon = NULL;
1903 GList *appimage = NULL;
1905 if (mfx->author && mfx->author->data) {
1906 author = (author_x *)mfx->author->data;
1908 auth_name = author->text;
1910 auth_email = author->email;
1912 auth_href = author->href;
1915 /*Insert in the package_info DB*/
1916 sqlite3_snprintf(MAX_QUERY_LEN, query,
1917 "INSERT INTO package_info(" \
1918 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1919 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1920 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1921 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1922 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1924 "%Q, %Q, %Q, %Q, %Q, %Q, " \
1925 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1926 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), %Q, " \
1927 "%Q, %Q, %Q, %Q, %Q, " \
1928 "%Q, %Q, %Q, %Q, LOWER(%Q))",
1929 mfx->package, mfx->type, mfx->version, mfx->api_version, mfx->tep_name, mfx->zip_mount_file,
1930 mfx->installlocation, mfx->package_size, __get_bool(mfx->removable, true), __get_bool(mfx->preload, false), __get_bool(mfx->readonly, false),
1931 __get_bool(mfx->update, false), __get_bool(mfx->appsetting, false), __get_bool(mfx->nodisplay_setting, false), __get_bool(mfx->system, false), auth_name,
1932 auth_email, auth_href, mfx->installed_time, mfx->installed_storage,
1933 mfx->storeclient_id,
1934 mfx->mainapp_id, mfx->package_url, mfx->root_path, mfx->csc_path, __get_bool(mfx->support_disable, false));
1936 ret = __exec_query(query);
1938 _LOGD("Package Info DB Insert Failed\n");
1942 /*Insert in the package_privilege_info DB*/
1943 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1944 pv = (const char *)tmp->data;
1947 memset(query, '\0', MAX_QUERY_LEN);
1948 sqlite3_snprintf(MAX_QUERY_LEN, query,
1949 "INSERT INTO package_privilege_info(package, privilege) " \
1952 ret = __exec_query(query);
1954 _LOGD("Package Privilege Info DB Insert Failed\n");
1959 if (mfx->application != NULL) {
1960 ret = __insert_mainapp_info(mfx);
1965 /*Insert the package locale*/
1966 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1967 /*remove duplicated data in pkglocale*/
1968 __trimfunc(pkglocale);
1970 /*Insert the app locale, icon, image info */
1971 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1972 app = (application_x *)tmp->data;
1975 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1976 appicon = __create_icon_list(appicon, app->icon);
1977 appimage = __create_image_list(appimage, app->image);
1979 /*remove duplicated data in applocale*/
1980 __trimfunc(applocale);
1981 __trimfunc(appicon);
1982 __trimfunc(appimage);
1984 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1986 /*native app locale info*/
1987 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1988 app = (application_x *)tmp->data;
1991 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1992 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1993 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1996 g_list_free(pkglocale);
1998 g_list_free(applocale);
2000 g_list_free(appicon);
2002 g_list_free(appimage);
2005 /*Insert in the package_app_info DB*/
2006 ret = __insert_application_info(mfx);
2009 /*Insert in the package_app_app_control DB*/
2010 ret = __insert_application_appcontrol_info(mfx);
2014 /*Insert in the package_app_app_category DB*/
2015 ret = __insert_application_appcategory_info(mfx);
2019 /*Insert in the package_app_app_metadata DB*/
2020 ret = __insert_application_appmetadata_info(mfx);
2024 /*Insert in the package_app_app_permission DB*/
2025 ret = __insert_application_apppermission_info(mfx);
2029 /*Insert in the package_app_share_allowed DB*/
2030 ret = __insert_application_share_allowed_info(mfx);
2034 /*Insert in the package_app_share_request DB*/
2035 ret = __insert_application_share_request_info(mfx);
2039 /*Insert in the package_app_data_control DB*/
2040 ret = __insert_application_datacontrol_info(mfx);
2044 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2045 ret = __insert_application_legacy_splashscreen_info(mfx);
2049 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2050 ret = __insert_application_metadata_splashscreen_info(mfx);
2054 /*Insert in the package_app_splash_screen DB*/
2055 ret = __insert_application_splashscreen_info(mfx);
2063 static int __delete_appinfo_from_db(char *db_table, const char *appid)
2065 char query[MAX_QUERY_LEN] = { '\0' };
2068 sqlite3_snprintf(MAX_QUERY_LEN, query,
2069 "DELETE FROM %q where app_id=%Q", db_table, appid);
2070 ret = __exec_query(query);
2072 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
2078 static int __delete_subpkg_info_from_db(char *appid)
2082 ret = __delete_appinfo_from_db("package_app_info", appid);
2085 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
2088 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
2091 ret = __delete_appinfo_from_db("package_app_image_info", appid);
2094 ret = __delete_appinfo_from_db("package_app_app_control", appid);
2097 ret = __delete_appinfo_from_db("package_app_app_category", appid);
2100 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
2103 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
2106 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
2109 ret = __delete_appinfo_from_db("package_app_share_request", appid);
2112 ret = __delete_appinfo_from_db("package_app_data_control", appid);
2115 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
2122 static int __delete_subpkg_from_db(manifest_x *mfx)
2124 char query[MAX_QUERY_LEN] = { '\0' };
2125 char *error_message = NULL;
2127 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT app_id FROM package_app_info WHERE package=%Q", mfx->package);
2129 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
2130 _LOGE("Don't execute query = %s error message = %s\n", query,
2132 sqlite3_free(error_message);
2135 sqlite3_free(error_message);
2140 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
2142 char query[MAX_QUERY_LEN] = { '\0' };
2147 /*Delete from Package Info DB*/
2148 sqlite3_snprintf(MAX_QUERY_LEN, query,
2149 "DELETE FROM package_info WHERE package=%Q", mfx->package);
2150 ret = __exec_query(query);
2152 _LOGD("Package Info DB Delete Failed\n");
2155 memset(query, '\0', MAX_QUERY_LEN);
2157 /*Delete from Package Localized Info*/
2158 sqlite3_snprintf(MAX_QUERY_LEN, query,
2159 "DELETE FROM package_localized_info WHERE package=%Q", mfx->package);
2160 ret = __exec_query(query);
2162 _LOGD("Package Localized Info DB Delete Failed\n");
2166 /*Delete from Package Privilege Info*/
2167 sqlite3_snprintf(MAX_QUERY_LEN, query,
2168 "DELETE FROM package_privilege_info WHERE package=%Q", mfx->package);
2169 ret = __exec_query(query);
2171 _LOGD("Package Privilege Info DB Delete Failed\n");
2175 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2176 app = (application_x *)tmp->data;
2179 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2182 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2185 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2188 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2191 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2194 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2197 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2200 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2203 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2206 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2209 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2212 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2217 /* if main package has sub pkg, delete sub pkg data*/
2218 __delete_subpkg_from_db(mfx);
2223 static int __disable_app(const char *appid)
2226 char query[MAX_QUERY_LEN] = {'\0'};
2227 sqlite3_snprintf(MAX_QUERY_LEN, query,
2228 "UPDATE package_app_info SET app_disable='true' WHERE app_id=%Q",
2230 ret = __exec_query(query);
2232 _LOGD("Insert global app disable failed\n");
2237 static int __enable_app(const char *appid)
2240 char query[MAX_QUERY_LEN] = {'\0'};
2241 sqlite3_snprintf(MAX_QUERY_LEN, query,
2242 "UPDATE package_app_info SET app_disable='false' WHERE app_id=%Q",
2244 ret = __exec_query(query);
2246 _LOGD("Insert global app disable failed\n");
2251 static int __disable_pkg(const char *pkgid)
2254 char query[MAX_QUERY_LEN] = {'\0'};
2255 sqlite3_snprintf(MAX_QUERY_LEN, query,
2256 "UPDATE package_info SET package_disable='true' WHERE package=%Q",
2258 ret = __exec_query(query);
2260 _LOGD("Update pkg disable info has failed\n");
2265 static int __enable_pkg(const char *pkgid)
2268 char query[MAX_QUERY_LEN] = {'\0'};
2269 sqlite3_snprintf(MAX_QUERY_LEN, query,
2270 "UPDATE package_info SET package_disable='false' WHERE package=%Q",
2272 ret = __exec_query(query);
2274 _LOGD("Update pkg disable info has failed\n");
2279 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2282 char query[MAX_QUERY_LEN] = { '\0', };
2284 const char *val = NULL;
2289 sqlite3_snprintf(MAX_QUERY_LEN, query,
2290 "SELECT COUNT(*) FROM "
2291 "package_app_info_for_uid WHERE app_id=%Q "
2292 "AND uid=%d", appid, (int)uid);
2294 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2295 if (ret != SQLITE_OK) {
2296 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2297 return PMINFO_R_ERROR;
2300 if (sqlite3_step(stmt) != SQLITE_ROW) {
2301 LOGE("failed to step");
2302 sqlite3_finalize(stmt);
2303 return PMINFO_R_ERROR;
2306 val = (const char *)sqlite3_column_text(stmt, 0);
2308 sqlite3_finalize(stmt);
2313 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2316 char query[MAX_QUERY_LEN] = { '\0', };
2318 ret = __check_appinfo_for_uid_table(appid, uid);
2320 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2323 } else if (ret == 0) {
2324 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2325 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2326 "VALUES(%Q, %d, 'true', "
2327 "(SELECT app_splash_screen_display FROM package_app_info WHERE appid='%Q'))",
2328 appid, (int)uid, appid);
2330 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2331 "package_app_info_for_uid SET is_disabled='true' "
2332 "WHERE app_id=%Q AND uid=%d", appid, (int)uid);
2335 ret = __exec_query(query);
2337 _LOGD("Add global app disable info failed\n");
2342 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2345 char query[MAX_QUERY_LEN] = {'\0'};
2347 ret = __check_appinfo_for_uid_table(appid, uid);
2349 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2352 } else if (ret > 0) {
2353 sqlite3_snprintf(MAX_QUERY_LEN, query,
2354 "UPDATE package_app_info_for_uid SET "
2355 "is_disabled='false' WHERE app_id=%Q AND "
2356 "uid=%d", appid, (int)uid);
2359 ret = __exec_query(query);
2361 _LOGD("Remove global app disable info failed\n");
2366 static int __update_global_app_splash_screen_for_user(const char *appid,
2367 uid_t uid, int flag)
2370 char query[MAX_QUERY_LEN] = { '\0', };
2372 ret = __check_appinfo_for_uid_table(appid, uid);
2374 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2377 } else if (ret == 0) {
2378 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2379 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2380 "VALUES(%Q, %d, %Q)", appid, (int)uid,
2381 flag ? "true" : "false");
2383 sqlite3_snprintf(MAX_QUERY_LEN, query,
2384 "UPDATE package_app_info_for_uid SET "
2385 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2386 "uid=%d", flag ? "true" : "false", appid, (int)uid);
2389 ret = __exec_query(query);
2391 _LOGD("update global app splash screen info failed\n");
2396 static int __disable_app_splash_screen(const char *appid)
2399 char query[MAX_QUERY_LEN] = {'\0'};
2401 sqlite3_snprintf(MAX_QUERY_LEN, query,
2402 "UPDATE package_app_info SET app_splash_screen_display='false' WHERE app_id=%Q",
2404 ret = __exec_query(query);
2406 _LOGD("Failed to update app_palsh_screen_display");
2411 static int __enable_app_splash_screen(const char *appid)
2414 char query[MAX_QUERY_LEN] = {'\0'};
2416 sqlite3_snprintf(MAX_QUERY_LEN, query,
2417 "UPDATE package_app_info SET app_splash_screen_display='true' WHERE app_id=%Q",
2419 ret = __exec_query(query);
2421 _LOGD("Failed to update app_splash_screen_display");
2426 API int pkgmgr_parser_initialize_db(uid_t uid)
2431 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2433 _LOGD("package info DB initialization failed\n");
2436 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2438 _LOGD("package localized info DB initialization failed\n");
2441 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2443 _LOGD("package app app privilege DB initialization failed\n");
2446 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2448 _LOGD("package app info DB initialization failed\n");
2451 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2453 _LOGD("package app localized info DB initialization failed\n");
2456 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2458 _LOGD("package app icon localized info DB initialization failed\n");
2461 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2463 _LOGD("package app image info DB initialization failed\n");
2466 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2468 _LOGD("package app app control DB initialization failed\n");
2471 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2473 _LOGD("package app app category DB initialization failed\n");
2476 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2478 _LOGD("package app app category DB initialization failed\n");
2481 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2483 _LOGD("package app app permission DB initialization failed\n");
2486 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2488 _LOGD("package app share allowed DB initialization failed\n");
2491 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2493 _LOGD("package app share request DB initialization failed\n");
2496 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2498 _LOGD("package app data control DB initialization failed\n");
2502 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2504 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2508 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2510 _LOGD("package app splash screen DB initialization failed\n");
2514 /* Trigger package_app_info_for_uid */
2515 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2517 _LOGD("package app info for uid DB initialization failed\n");
2522 /* TODO: refactor this code */
2523 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2525 _LOGD("package cert info DB initialization failed\n");
2528 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2530 _LOGD("package cert index info DB initialization failed\n");
2533 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO);
2535 _LOGD("package cert info DB initialization failed\n");
2538 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2);
2540 _LOGD("package cert info DB initialization failed\n");
2543 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2545 _LOGD("package cert info DB initialization failed\n");
2548 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2550 _LOGD("package cert index info DB initialization failed\n");
2554 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
2555 _LOGD("Failed to change cert db permission\n");
2557 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2558 _LOGD("Failed to change parser db permission\n");
2564 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2567 char pwuid_buf[1024];
2568 char journal_file[BUFSIZE];
2573 struct passwd userinfo, *result = NULL;
2574 files[0] = (char *)db_file;
2575 files[1] = journal_file;
2579 if (db_file == NULL)
2582 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2584 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2585 if (uid == OWNER_ROOT)
2587 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2588 if (ret != 0 || result == NULL) {
2589 _LOGE("FAIL: user %d doesn't exist", uid);
2592 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2594 for (i = 0; files[i]; i++) {
2595 fd = open(files[i], O_RDONLY);
2597 if (strerror_r(errno, buf, sizeof(buf)))
2598 strncpy(buf, "", BUFSIZE - 1);
2599 _LOGD("FAIL : open %s : %s", files[i], buf);
2602 ret = fstat(fd, &sb);
2604 if (strerror_r(errno, buf, sizeof(buf)))
2605 strncpy(buf, "", BUFSIZE - 1);
2606 _LOGD("FAIL : fstat %s : %s", files[i], buf);
2610 if (S_ISLNK(sb.st_mode)) {
2611 _LOGE("FAIL : %s is symlink!", files[i]);
2615 ret = fchown(fd, uid, userinfo.pw_gid);
2617 if (strerror_r(errno, buf, sizeof(buf)))
2618 strncpy(buf, "", BUFSIZE - 1);
2619 _LOGD("FAIL : fchown %s %d.%d : %s", files[i], uid,
2620 userinfo.pw_gid, buf);
2625 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2626 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2628 ret = fchmod(fd, mode);
2630 if (strerror_r(errno, buf, sizeof(buf)))
2631 strncpy(buf, "", BUFSIZE - 1);
2632 _LOGD("FAIL : fchmod %s 0664 : %s", files[i], buf);
2637 SET_SMACK_LABEL(files[i]);
2642 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2646 if (getuid() != OWNER_ROOT) {
2647 _LOGE("Only root user is allowed");
2651 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2652 _LOGE("Manifest db for user %d is already exists", uid);
2656 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2657 _LOGE("Cert db for user %d is already exists", uid);
2661 ret = pkgmgr_parser_check_and_create_db(uid);
2664 ret = pkgmgr_parser_initialize_db(uid);
2666 pkgmgr_parser_close_db();
2669 pkgmgr_parser_close_db();
2674 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2678 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2680 _LOGD("Manifest DB creation Failed\n");
2685 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2687 _LOGD("Cert DB creation Failed\n");
2693 void pkgmgr_parser_close_db(void)
2695 sqlite3_close(pkgmgr_parser_db);
2696 sqlite3_close(pkgmgr_cert_db);
2700 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2702 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2704 _LOGD("manifest pointer is NULL\n");
2708 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2710 _LOGD("Failed to open DB\n");
2713 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2716 /*Begin transaction*/
2717 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2718 if (ret != SQLITE_OK) {
2719 _LOGD("Failed to begin transaction\n");
2723 _LOGD("Transaction Begin\n");
2724 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2726 _LOGD("Insert into DB failed. Rollback now\n");
2727 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2730 /*Commit transaction*/
2731 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2732 if (ret != SQLITE_OK) {
2733 _LOGD("Failed to commit transaction. Rollback now\n");
2734 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2738 _LOGD("Transaction Commit and End\n");
2740 pkgmgr_parser_close_db();
2744 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2746 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2748 _LOGD("manifest pointer is NULL\n");
2752 ret = pkgmgr_parser_check_and_create_db(uid);
2754 _LOGD("Failed to open DB\n");
2757 ret = pkgmgr_parser_initialize_db(uid);
2760 /*Begin transaction*/
2761 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2762 if (ret != SQLITE_OK) {
2763 _LOGD("Failed to begin transaction\n");
2767 _LOGD("Transaction Begin\n");
2768 ret = __insert_manifest_info_in_db(mfx, uid);
2770 _LOGD("Insert into DB failed. Rollback now\n");
2771 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2774 /*Commit transaction*/
2775 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2776 if (ret != SQLITE_OK) {
2777 _LOGD("Failed to commit transaction. Rollback now\n");
2778 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2782 _LOGD("Transaction Commit and End\n");
2784 pkgmgr_parser_close_db();
2788 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2790 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, _getuid());
2793 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2795 if (pkgid == NULL || tep_path == NULL) {
2796 _LOGE("invalid parameter");
2803 ret = pkgmgr_parser_check_and_create_db(uid);
2805 _LOGD("Failed to open DB\n");
2808 ret = pkgmgr_parser_initialize_db(uid);
2812 /*Begin transaction*/
2813 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2814 if (ret != SQLITE_OK) {
2815 _LOGD("Failed to begin transaction\n");
2819 _LOGD("Transaction Begin\n");
2822 /* Updating TEP info in "package_info" table */
2823 query = sqlite3_mprintf("UPDATE package_info "\
2824 "SET package_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_info!!");
2835 /* Updating TEP info in "package_app_info" table */
2836 query = sqlite3_mprintf("UPDATE package_app_info "\
2837 "SET app_tep_name = %Q "\
2838 "WHERE package = %Q", tep_path, pkgid);
2840 ret = __exec_query(query);
2841 sqlite3_free(query);
2842 if (ret != SQLITE_OK) {
2843 ret = PM_PARSER_R_ERROR;
2844 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2848 /*Commit transaction*/
2849 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2850 if (ret != SQLITE_OK) {
2851 _LOGE("Failed to commit transaction, Rollback now\n");
2852 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2853 if (ret != SQLITE_OK)
2854 _LOGE("Failed to Rollback\n");
2856 ret = PM_PARSER_R_ERROR;
2859 _LOGD("Transaction Commit and End\n");
2860 ret = PM_PARSER_R_OK;
2863 pkgmgr_parser_close_db();
2868 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2871 _LOGD("manifest pointer is NULL\n");
2875 ret = pkgmgr_parser_check_and_create_db(uid);
2877 _LOGD("Failed to open DB\n");
2880 ret = pkgmgr_parser_initialize_db(uid);
2883 /*Preserve guest mode visibility*/
2884 __preserve_guestmode_visibility_value( mfx);
2885 /*Begin transaction*/
2886 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2887 if (ret != SQLITE_OK) {
2888 _LOGD("Failed to begin transaction\n");
2892 _LOGD("Transaction Begin\n");
2893 ret = __delete_manifest_info_from_db(mfx, uid);
2895 _LOGD("Delete from DB failed. Rollback now\n");
2896 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2899 ret = __insert_manifest_info_in_db(mfx, uid);
2901 _LOGD("Insert into DB failed. Rollback now\n");
2902 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2906 /*Commit transaction*/
2907 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2908 if (ret != SQLITE_OK) {
2909 _LOGD("Failed to commit transaction. Rollback now\n");
2910 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2914 _LOGD("Transaction Commit and End\n");
2916 pkgmgr_parser_close_db();
2920 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2922 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2925 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2928 _LOGD("manifest pointer is NULL\n");
2932 ret = pkgmgr_parser_check_and_create_db(uid);
2934 _LOGD("Failed to open DB\n");
2937 /*Begin transaction*/
2938 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2939 if (ret != SQLITE_OK) {
2940 _LOGD("Failed to begin transaction\n");
2944 _LOGD("Transaction Begin\n");
2945 ret = __delete_manifest_info_from_db(mfx, uid);
2947 _LOGD("Delete from 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();
2965 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2967 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
2970 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2974 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2976 _LOGD("Failed to open DB\n");
2980 /*Begin transaction*/
2981 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2982 if (ret != SQLITE_OK) {
2983 _LOGD("Failed to begin transaction\n");
2987 _LOGD("Transaction Begin\n");
2989 ret = __disable_global_app_for_user(appid, uid);
2991 ret = __enable_global_app_for_user(appid, uid);
2993 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2994 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2997 /*Commit transaction*/
2998 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2999 if (ret != SQLITE_OK) {
3000 _LOGD("Failed to commit transaction, Rollback now\n");
3001 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3005 _LOGD("Transaction Commit and End\n");
3007 pkgmgr_parser_close_db();
3012 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
3014 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
3017 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid, uid_t uid, int is_disable)
3021 ret = pkgmgr_parser_check_and_create_db(uid);
3023 _LOGD("Failed to open DB\n");
3027 /*Begin transaction*/
3028 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3029 if (ret != SQLITE_OK) {
3030 _LOGD("Failed to begin transaction\n");
3035 _LOGD("Transaction Begin\n");
3037 ret = __disable_pkg(pkgid);
3039 ret = __enable_pkg(pkgid);
3042 _LOGD("__update_pkg_disable_condition_in_db failed. Rollback now\n");
3043 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3047 /*Commit transaction*/
3048 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3049 if (ret != SQLITE_OK) {
3050 _LOGD("Failed to commit transaction, Rollback now\n");
3051 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3055 _LOGD("Transaction Commit and End\n");
3058 pkgmgr_parser_close_db();
3062 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid, int is_disable)
3064 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid, _getuid(), is_disable);
3067 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
3071 ret = pkgmgr_parser_check_and_create_db(uid);
3073 _LOGD("Failed to open DB\n");
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\n");
3084 _LOGD("Transaction Begin\n");
3086 ret = __disable_app(appid);
3088 ret = __enable_app(appid);
3090 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
3091 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3094 /*Commit transaction*/
3095 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3096 if (ret != SQLITE_OK) {
3097 _LOGD("Failed to commit transaction, Rollback now\n");
3098 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3102 _LOGD("Transaction Commit and End\n");
3104 pkgmgr_parser_close_db();
3109 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3113 if (appid == NULL) {
3114 _LOGD("Invalid parameter");
3118 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3120 _LOGD("Failed to open DB\n");
3124 /* Begin transaction */
3125 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3126 if (ret != SQLITE_OK) {
3127 _LOGD("Failed to begin transaction\n");
3131 _LOGD("Transaction Begin\n");
3133 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3135 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3136 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3139 /* Commit transaction */
3140 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3141 if (ret != SQLITE_OK) {
3142 _LOGD("Failed to commit transaction, Rollback now\n");
3143 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3147 _LOGD("Transaction Commit and End\n");
3149 pkgmgr_parser_close_db();
3153 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3155 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3158 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3162 if (appid == NULL) {
3163 _LOGD("Invalid parameter");
3167 ret = pkgmgr_parser_check_and_create_db(uid);
3169 _LOGD("Failed to open DB");
3173 /* Begin transaction */
3174 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3175 if (ret != SQLITE_OK) {
3176 _LOGD("Failed to begin transaction");
3180 _LOGD("Transaction Begin");
3183 ret = __enable_app_splash_screen(appid);
3185 ret = __disable_app_splash_screen(appid);
3187 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3188 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3191 /* Commit transaction */
3192 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3193 if (ret != SQLITE_OK) {
3194 _LOGD("Failed to commit transaction, Rollback now");
3195 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3199 _LOGD("Transaction Commit and End");
3202 pkgmgr_parser_close_db();