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, " \
114 "external_path TEXT, " \
116 "package_support_disable TEXT NOT NULL DEFAULT 'false', " \
117 "package_disable TEXT NOT NULL DEFAULT 'false')"
119 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_localized_info " \
120 "(package TEXT NOT NULL, " \
121 "package_locale TEXT NOT NULL DEFAULT 'No Locale', " \
122 "package_label TEXT, " \
123 "package_icon TEXT, " \
124 "package_description TEXT, " \
125 "package_license TEXT, " \
126 "package_author TEXT, " \
127 "PRIMARY KEY(package, package_locale), " \
128 "FOREIGN KEY(package) " \
129 "REFERENCES package_info(package) " \
132 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "CREATE TABLE IF NOT EXISTS package_privilege_info " \
133 "(package TEXT NOT NULL, " \
134 "privilege TEXT NOT NULL, " \
135 "type TEXT NOT NULL, " \
136 "PRIMARY KEY(package, privilege, type) " \
137 "FOREIGN KEY(package) " \
138 "REFERENCES package_info(package) " \
141 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "CREATE TABLE IF NOT EXISTS package_app_info " \
142 "(app_id TEXT PRIMARY KEY NOT NULL, " \
143 "app_component TEXT NOT NULL, " \
145 "app_nodisplay TEXT NOT NULL DEFAULT 'false', " \
147 "app_onboot TEXT NOT NULL DEFAULT 'false', " \
148 "app_multiple TEXT NOT NULL DEFAULT 'false', " \
149 "app_autorestart TEXT NOT NULL DEFAULT 'false', " \
150 "app_taskmanage TEXT NOT NULL DEFAULT 'false', " \
151 "app_enabled TEXT NOT NULL DEFAULT 'true', " \
152 "app_hwacceleration TEXT NOT NULL DEFAULT 'use-system-setting', " \
153 "app_screenreader TEXT NOT NULL DEFAULT 'use-system-setting', " \
154 "app_mainapp TEXT NOT NULL, " \
155 "app_recentimage TEXT NOT NULL DEFAULT 'false', " \
156 "app_launchcondition TEXT, " \
157 "app_indicatordisplay TEXT NOT NULL DEFAULT 'true', " \
158 "app_portraitimg TEXT, " \
159 "app_landscapeimg TEXT, " \
160 "app_guestmodevisibility TEXT NOT NULL DEFAULT 'true', " \
161 "app_permissiontype TEXT NOT NULL DEFAULT 'normal', " \
162 "app_preload TEXT NOT NULL DEFAULT 'false', " \
163 "app_submode TEXT NOT NULL DEFAULT 'false', " \
164 "app_submode_mainid TEXT, " \
165 "app_installed_storage TEXT NOT NULL, " \
166 "app_process_pool TEXT NOT NULL DEFAULT 'false', " \
167 "app_launch_mode TEXT NOT NULL DEFAULT 'caller', " \
168 "app_ui_gadget TEXT NOT NULL DEFAULT 'false', " \
169 "app_support_disable TEXT NOT NULL DEFAULT 'false', " \
170 "app_disable TEXT NOT NULL DEFAULT 'false', " \
171 "app_package_type TEXT DEFAULT 'tpk', " \
172 "component_type TEXT, " \
173 "package TEXT NOT NULL, " \
174 "app_tep_name TEXT, " \
175 "app_zip_mount_file TEXT, " \
176 "app_background_category INTEGER DEFAULT 0, " \
177 "app_root_path TEXT, " \
178 "app_api_version TEXT, " \
179 "app_effective_appid TEXT, " \
180 "app_splash_screen_display TEXT NOT NULL DEFAULT 'true', " \
181 "app_external_path TEXT, " \
182 "FOREIGN KEY(package) " \
183 "REFERENCES package_info(package) " \
186 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_app_localized_info " \
187 "(app_id TEXT NOT NULL, " \
188 "app_locale TEXT NOT NULL DEFAULT 'No Locale', " \
191 "PRIMARY KEY(app_id,app_locale) " \
192 "FOREIGN KEY(app_id) " \
193 "REFERENCES package_app_info(app_id) " \
196 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "CREATE TABLE IF NOT EXISTS package_app_icon_section_info " \
197 "(app_id TEXT NOT NULL, " \
199 "app_icon_section TEXT NOT NULL, " \
200 "app_icon_resolution TEXT NOT NULL, " \
201 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
202 "FOREIGN KEY(app_id) " \
203 "REFERENCES package_app_info(app_id) " \
206 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "CREATE TABLE IF NOT EXISTS package_app_image_info " \
207 "(app_id TEXT NOT NULL, " \
208 "app_locale TEXT DEFAULT 'No Locale', " \
209 "app_image_section TEXT NOT NULL, " \
211 "PRIMARY KEY(app_id,app_image_section) " \
212 "FOREIGN KEY(app_id) " \
213 "REFERENCES package_app_info(app_id) " \
216 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "CREATE TABLE IF NOT EXISTS package_app_app_control " \
217 "(app_id TEXT NOT NULL, " \
218 "app_control TEXT NOT NULL, " \
219 "PRIMARY KEY(app_id,app_control) " \
220 "FOREIGN KEY(app_id) " \
221 "REFERENCES package_app_info(app_id) " \
224 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "CREATE TABLE IF NOT EXISTS package_app_app_category " \
225 "(app_id TEXT NOT NULL, " \
226 "category TEXT NOT NULL, " \
227 "PRIMARY KEY(app_id,category) " \
228 "FOREIGN KEY(app_id) " \
229 "REFERENCES package_app_info(app_id) " \
232 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "CREATE TABLE IF NOT EXISTS package_app_app_metadata " \
233 "(app_id TEXT NOT NULL, " \
234 "md_key TEXT NOT NULL, " \
236 "PRIMARY KEY(app_id, md_key, md_value) " \
237 "FOREIGN KEY(app_id) " \
238 "REFERENCES package_app_info(app_id) " \
241 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "CREATE TABLE IF NOT EXISTS package_app_app_permission " \
242 "(app_id TEXT NOT NULL, " \
243 "pm_type TEXT NOT NULL, " \
244 "pm_value TEXT NOT NULL, " \
245 "PRIMARY KEY(app_id, pm_type, pm_value) " \
246 "FOREIGN KEY(app_id) " \
247 "REFERENCES package_app_info(app_id) " \
250 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "CREATE TABLE IF NOT EXISTS package_app_share_allowed " \
251 "(app_id TEXT NOT NULL, " \
252 "data_share_path TEXT NOT NULL, " \
253 "data_share_allowed TEXT NOT NULL, " \
254 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
255 "FOREIGN KEY(app_id) " \
256 "REFERENCES package_app_info(app_id) " \
259 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "CREATE TABLE IF NOT EXISTS package_app_share_request " \
260 "(app_id TEXT NOT NULL, " \
261 "data_share_request TEXT NOT NULL, " \
262 "PRIMARY KEY(app_id,data_share_request) " \
263 "FOREIGN KEY(app_id) " \
264 "REFERENCES package_app_info(app_id) " \
267 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "CREATE TABLE IF NOT EXISTS package_app_data_control " \
268 "(app_id TEXT NOT NULL, " \
269 "providerid TEXT NOT NULL, " \
270 "access TEXT NOT NULL, " \
271 "type TEXT NOT NULL, " \
272 "PRIMARY KEY(app_id, providerid, access, type) " \
273 "FOREIGN KEY(app_id) " \
274 "REFERENCES package_app_info(app_id) " \
277 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
278 "(app_id TEXT NOT NULL, " \
279 "uid INTEGER NOT NULL, " \
280 "is_disabled TEXT NOT NULL DEFAULT 'false', " \
281 "is_splash_screen_enabled TEXT NOT NULL, " \
282 "PRIMARY KEY(app_id, uid))"
284 #define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
285 "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
286 "AFTER UPDATE ON package_app_info_for_uid " \
288 " DELETE FROM package_app_info_for_uid WHERE " \
289 " is_splash_screen_enabled=" \
290 " (SELECT package_app_info.app_splash_screen_display FROM " \
291 " package_app_info, package_app_info_for_uid WHERE " \
292 " package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
295 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
296 "CREATE TABLE IF NOT EXISTS package_app_splash_screen " \
297 "(app_id TEXT NOT NULL, " \
298 "src TEXT NOT NULL, " \
299 "type TEXT NOT NULL, " \
300 "orientation TEXT NOT NULL, " \
301 "indicatordisplay TEXT, " \
302 "operation TEXT NOT NULL, " \
303 "color_depth TEXT NOT NULL DEFAULT '24', " \
304 "PRIMARY KEY(app_id, orientation, operation) " \
305 "FOREIGN KEY(app_id) " \
306 "REFERENCES package_app_info(app_id) " \
310 /* FIXME: duplicated at pkgmgrinfo_db.c */
311 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
312 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
313 " cert_info TEXT UNIQUE, " \
314 " cert_id INTEGER PRIMARY KEY, " \
315 " cert_ref_count INTEGER NOT NULL)"
317 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
318 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
319 " package TEXT PRIMARY KEY, " \
320 " package_count INTEGER, " \
321 " author_root_cert INTEGER, " \
322 " author_im_cert INTEGER, " \
323 " author_signer_cert INTEGER, " \
324 " dist_root_cert INTEGER, " \
325 " dist_im_cert INTEGER, " \
326 " dist_signer_cert INTEGER, " \
327 " dist2_root_cert INTEGER, " \
328 " dist2_im_cert INTEGER, " \
329 " dist2_signer_cert INTEGER)"
331 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO \
332 "CREATE TRIGGER IF NOT EXISTS update_cert_info " \
333 "AFTER UPDATE ON package_cert_info " \
334 "WHEN (NEW.package_count = 0) " \
336 " DELETE FROM package_cert_info WHERE package=OLD.package;" \
339 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2 \
340 "CREATE TRIGGER IF NOT EXISTS update_cert_info2 " \
341 "AFTER UPDATE ON package_cert_info " \
342 "WHEN (NEW.package_count = OLD.package_count + 1) " \
344 " UPDATE package_cert_index_info SET" \
345 " cert_ref_count = cert_ref_count - 1" \
346 " WHERE cert_id = OLD.author_root_cert" \
347 " OR cert_id = OLD.author_im_cert" \
348 " OR cert_id = OLD.author_signer_cert" \
349 " OR cert_id = OLD.dist_root_cert" \
350 " OR cert_id = OLD.dist_im_cert" \
351 " OR cert_id = OLD.dist_signer_cert" \
352 " OR cert_id = OLD.dist2_root_cert" \
353 " OR cert_id = OLD.dist2_im_cert" \
354 " OR cert_id = OLD.dist2_signer_cert;" \
357 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
358 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
359 "AFTER DELETE ON package_cert_info " \
361 " UPDATE package_cert_index_info SET" \
362 " cert_ref_count = cert_ref_count - 1" \
363 " WHERE cert_id = OLD.author_root_cert" \
364 " OR cert_id = OLD.author_im_cert" \
365 " OR cert_id = OLD.author_signer_cert" \
366 " OR cert_id = OLD.dist_root_cert" \
367 " OR cert_id = OLD.dist_im_cert" \
368 " OR cert_id = OLD.dist_signer_cert" \
369 " OR cert_id = OLD.dist2_root_cert" \
370 " OR cert_id = OLD.dist2_im_cert" \
371 " OR cert_id = OLD.dist2_signer_cert;" \
374 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
375 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
376 "AFTER UPDATE ON package_cert_index_info " \
377 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
378 " WHERE cert_id = OLD.cert_id) = 0) "\
380 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
383 static int __insert_application_info(manifest_x *mfx);
384 static int __insert_application_appcategory_info(manifest_x *mfx);
385 static int __insert_application_appcontrol_info(manifest_x *mfx);
386 static int __insert_application_appmetadata_info(manifest_x *mfx);
387 static int __insert_application_share_allowed_info(manifest_x *mfx);
388 static int __insert_application_share_request_info(manifest_x *mfx);
389 static int __insert_application_datacontrol_info(manifest_x *mfx);
390 static void __insert_application_locale_info(gpointer data, gpointer userdata);
391 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
392 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
393 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
394 static int __delete_subpkg_info_from_db(char *appid);
395 static int __delete_appinfo_from_db(char *db_table, const char *appid);
396 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
397 static int __exec_query(char *query);
398 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
399 char **label, char **license, char **icon, char **description, char **author);
400 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
401 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
402 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
403 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
404 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
405 static int __parserdb_change_perm(const char *db_file, uid_t uid);
407 #define REGULAR_USER 5000
408 static inline uid_t _getuid(void)
410 uid_t uid = getuid();
412 if (uid < REGULAR_USER)
413 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
418 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
421 __delete_subpkg_info_from_db(coltxt[0]);
426 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
431 char *error_message = NULL;
433 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
434 if (ret != SQLITE_OK) {
435 _LOGD("connect db [%s] failed!\n", db_path);
440 /* add user_version for db upgrade*/
441 query = sqlite3_mprintf("PRAGMA user_version=%d", (atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 + atoi(TIZEN_PATCH_VER)));
443 sqlite3_exec(handle, query, NULL, NULL, &error_message)) {
444 _LOGE("Don't execute query = %s error message = %s\n", query,
447 sqlite3_free(error_message);
453 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
455 manifest_x *mfx = (manifest_x *)data;
461 if (mfx->application == NULL)
463 app = (application_x *)mfx->application->data;
464 for (i = 0; i < ncols; i++) {
465 if (strcmp(colname[i], "app_id") == 0) {
467 appid = strdup(coltxt[i]);
468 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
470 status = strdup(coltxt[i]);
476 _LOGD("app id is NULL\n");
479 /*update guest mode visibility*/
480 for (tmp = mfx->application; tmp; tmp = tmp->next) {
481 app = (application_x *)tmp->data;
484 if (strcmp(app->appid, appid) == 0) {
485 free((void *)app->guestmode_visibility);
486 app->guestmode_visibility = strdup(status);
502 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
504 char *error_message = NULL;
505 char query[MAX_QUERY_LEN] = {'\0'};
506 sqlite3_snprintf(MAX_QUERY_LEN, query,
507 "SELECT app_id, app_guestmodevisibility FROM package_app_info " \
508 "WHERE package=%Q", mfx->package);
510 sqlite3_exec(pkgmgr_parser_db, query,
511 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
512 _LOGD("Don't execute query = %s error message = %s\n",
513 query, error_message);
514 sqlite3_free(error_message);
519 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
521 char *error_message = NULL;
523 sqlite3_exec(db_handle, db_query,
524 NULL, NULL, &error_message)) {
525 _LOGD("Don't execute query = %s error message = %s\n",
526 db_query, error_message);
527 sqlite3_free(error_message);
530 sqlite3_free(error_message);
534 static int __exec_query(char *query)
536 char *error_message = NULL;
538 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
539 _LOGE("Don't execute query = %s error message = %s\n", query,
541 sqlite3_free(error_message);
544 sqlite3_free(error_message);
548 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
556 for (tmp = lbls; tmp; tmp = tmp->next) {
557 lbl = (label_x *)tmp->data;
561 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
563 for (tmp = lcns; tmp; tmp = tmp->next) {
564 lcn = (license_x *)tmp->data;
568 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
570 for (tmp = icns; tmp; tmp = tmp->next) {
571 icn = (icon_x *)tmp->data;
575 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
577 for (tmp = dcns; tmp; tmp = tmp->next) {
578 dcn = (description_x *)tmp->data;
582 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
584 for (tmp = aths; tmp; tmp = tmp->next) {
585 ath = (author_x *)tmp->data;
589 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
595 static GList *__create_icon_list(GList *appicon, GList *icns)
600 for (tmp = icns; tmp; tmp = tmp->next) {
601 icn = (icon_x *)tmp->data;
605 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
610 static GList *__create_image_list(GList *appimage, GList *imgs)
615 for (tmp = imgs; tmp; tmp = tmp->next) {
616 img = (image_x *)tmp->data;
620 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
625 static void __trimfunc(GList* trim_list)
627 char *trim_data = NULL;
631 list = g_list_first(trim_list);
634 trim_data = (char *)list->data;
637 if (strcmp(trim_data, prev) == 0) {
638 trim_list = g_list_remove(trim_list, trim_data);
639 list = g_list_first(trim_list);
648 list = g_list_next(list);
652 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
654 if (a == NULL || b == NULL)
656 if (strcmp((char*)a, (char*)b) == 0)
658 if (strcmp((char*)a, (char*)b) < 0)
660 if (strcmp((char*)a, (char*)b) > 0)
665 static int __check_dpi(const char *dpi_char, int dpi_int)
667 if (dpi_char == NULL)
670 if (strcasecmp(dpi_char, LDPI) == 0) {
671 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
675 } else if (strcasecmp(dpi_char, MDPI) == 0) {
676 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
680 } else if (strcasecmp(dpi_char, HDPI) == 0) {
681 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
685 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
686 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
690 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
691 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
699 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
702 char *icon_filename = NULL;
703 char modified_iconpath[BUFSIZE] = { '\0' };
704 char icon_path[BUFSIZE] = { '\0' };
708 if (orig_icon_path == NULL)
711 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
715 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
716 dpi_path[0] = "LDPI";
717 dpi_path[1] = "ldpi";
718 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
719 dpi_path[0] = "MDPI";
720 dpi_path[1] = "mdpi";
721 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
722 dpi_path[0] = "HDPI";
723 dpi_path[1] = "hdpi";
724 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
725 dpi_path[0] = "XHDPI";
726 dpi_path[1] = "xhdpi";
727 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
728 dpi_path[0] = "XXHDPI";
729 dpi_path[1] = "xxhdpi";
731 _LOGE("Unidentified dpi[%d]", dpi);
735 icon_filename = strrchr(orig_icon_path, '/');
736 if (icon_filename == NULL)
739 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
740 for (i = 0; i < 2; i++) {
741 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
742 if (access(modified_iconpath, F_OK) != -1) {
743 /* if exists, return modified icon path */
744 *new_icon_path = strdup(modified_iconpath);
752 static gint __compare_icon(gconstpointer a, gconstpointer b)
754 icon_x *icon = (icon_x *)a;
756 char *icon_folder_path = NULL;
758 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
761 if (icon->dpi != NULL)
764 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
766 icon->text = icon_folder_path;
772 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
774 icon_x *icon = (icon_x *)a;
775 int dpi = GPOINTER_TO_INT(b);
777 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
780 if (icon->dpi == NULL)
783 if (__check_dpi(icon->dpi, dpi) == 0)
789 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
791 icon_x *icon = (icon_x *)a;
792 char *lang = (char *)b;
793 char *icon_folder_path = NULL;
795 if (icon->dpi != NULL)
798 if (strcasecmp(icon->lang, lang) == 0) {
799 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
800 /* icon for no locale. check existance of folder-hierachied default icons */
801 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
803 icon->text = icon_folder_path;
812 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
814 icon_x *icon = (icon_x *)a;
815 char *lang = (char *)b;
818 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
822 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
828 static char *__find_icon(GList *icons, const char *lang)
835 /* first, find icon whose locale and dpi with given lang and system's dpi has matched */
836 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
838 icon = (icon_x *)tmp->data;
839 return (char *)icon->text;
842 /* if first has failed, find icon whose locale has matched */
843 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
845 icon = (icon_x *)tmp->data;
846 return (char *)icon->text;
849 /* if second has failed, find icon whose dpi has matched with system's dpi */
850 ret = system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
851 if (ret == SYSTEM_INFO_ERROR_NONE) {
852 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
854 icon = (icon_x *)tmp->data;
855 return (char *)icon->text;
859 /* last, find default icon marked as "No Locale" */
860 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
862 icon = (icon_x *)tmp->data;
863 return (char *)icon->text;
869 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
870 char **label, char **license, char **icon, char **description, char **author)
877 for (tmp = lbls; tmp; tmp = tmp->next) {
878 lbl = (label_x *)tmp->data;
882 if (strcmp(lbl->lang, (char *)data) == 0) {
883 *label = (char*)lbl->text;
888 for (tmp = lcns; tmp; tmp = tmp->next) {
889 lcn = (license_x *)tmp->data;
893 if (strcmp(lcn->lang, (char *)data) == 0) {
894 *license = (char*)lcn->text;
900 *icon = __find_icon(icns, (char *)data);
902 for (tmp = dcns; tmp; tmp = tmp->next) {
903 dcn = (description_x *)tmp->data;
907 if (strcmp(dcn->lang, (char *)data) == 0) {
908 *description = (char*)dcn->text;
913 for (tmp = aths; tmp; tmp = tmp->next) {
914 ath = (author_x *)tmp->data;
918 if (strcmp(ath->lang, (char *)data) == 0) {
919 *author = (char*)ath->text;
927 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
931 for (tmp = icns; tmp; tmp = tmp->next) {
932 icn = (icon_x *)tmp->data;
936 if (strcmp(icn->section, (char *)data) == 0) {
937 *icon = (char*)icn->text;
938 *resolution = (char*)icn->resolution;
945 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
949 for (tmp = imgs; tmp; tmp = tmp->next) {
950 img = (image_x *)tmp->data;
954 if (strcmp(img->section, (char *)data) == 0) {
955 *lang = (char*)img->lang;
956 *image = (char*)img->text;
963 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
968 char *description = NULL;
969 char *license = NULL;
973 manifest_x *mfx = (manifest_x *)userdata;
974 GList *lbl = mfx->label;
975 GList *lcn = mfx->license;
976 GList *icn = mfx->icon;
977 GList *dcn = mfx->description;
978 GList *ath = mfx->author;
980 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
981 if (!label && !description && !icon && !license && !author)
984 query = sqlite3_mprintf("INSERT INTO package_localized_info(package, package_locale, " \
985 "package_label, package_icon, package_description, package_license, package_author) VALUES" \
986 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
995 ret = __exec_query(query);
997 _LOGD("Package Localized Info DB Insert failed\n");
1002 static void __insert_application_locale_info(gpointer data, gpointer userdata)
1008 char *locale = (char *)data;
1010 application_x *app = (application_x*)userdata;
1011 GList *lbl = app->label;
1012 GList *icn = app->icon;
1014 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1015 if (!label && !icon)
1018 query = sqlite3_mprintf("INSERT INTO package_app_localized_info(app_id, app_locale, " \
1019 "app_label, app_icon) VALUES" \
1020 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
1022 ret = __exec_query(query);
1024 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1026 sqlite3_free(query);
1028 /*insert ui app locale info to pkg locale to get mainapp data */
1029 if (strcasecmp(app->mainapp, "true") == 0) {
1030 query = sqlite3_mprintf("INSERT OR REPLACE INTO package_localized_info(package, package_locale, "
1031 "package_label, package_icon, package_description, package_license, package_author) VALUES"
1033 "COALESCE((SELECT package_label FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1034 "COALESCE((SELECT package_icon FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1035 "(SELECT package_description FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1036 "(SELECT package_license FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1037 "(SELECT package_author FROM package_localized_info WHERE package=%Q AND package_locale=%Q))",
1038 app->package, locale,
1039 app->package, locale, label,
1040 app->package, locale, icon,
1041 app->package, locale,
1042 app->package, locale,
1043 app->package, locale);
1045 ret = __exec_query(query);
1047 _LOGE("Package Localized Info DB Insert failed");
1048 sqlite3_free(query);
1052 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1056 char *resolution = NULL;
1057 char query[MAX_QUERY_LEN] = {'\0'};
1059 application_x *app = (application_x*)userdata;
1060 GList *icn = app->icon;
1062 __extract_icon_data(data, icn, &icon, &resolution);
1063 if (!icon && !resolution)
1065 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO package_app_icon_section_info(app_id, " \
1066 "app_icon, app_icon_section, app_icon_resolution) VALUES " \
1067 "(%Q, %Q, %Q, %Q)", app->appid,
1068 icon, (char*)data, resolution);
1070 ret = __exec_query(query);
1072 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1076 static void __insert_application_image_info(gpointer data, gpointer userdata)
1081 char query[MAX_QUERY_LEN] = {'\0'};
1083 application_x *app = (application_x*)userdata;
1084 GList *image = app->image;
1086 __extract_image_data(data, image, &lang, &img);
1089 sqlite3_snprintf(MAX_QUERY_LEN, query,
1090 "INSERT INTO package_app_image_info(app_id, app_locale, " \
1091 "app_image_section, app_image) VALUES" \
1092 "(%Q, %Q, %Q, %Q)", app->appid, lang, (char*)data, img);
1094 ret = __exec_query(query);
1096 _LOGD("Package UiApp image Info DB Insert failed\n");
1101 static int __insert_mainapp_info(manifest_x *mfx)
1106 char query[MAX_QUERY_LEN] = {'\0'};
1107 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1108 app = (application_x *)tmp->data;
1112 sqlite3_snprintf(MAX_QUERY_LEN, query,
1113 "UPDATE package_app_info SET app_mainapp=%Q WHERE app_id=%Q",
1114 app->mainapp, app->appid);
1115 ret = __exec_query(query);
1117 _LOGD("Package App Info DB Insert Failed\n");
1120 if (strcasecmp(app->mainapp, "True") == 0)
1121 mfx->mainapp_id = strdup(app->appid);
1124 if (mfx->mainapp_id == NULL) {
1125 if (mfx->application == NULL)
1127 app = (application_x *)mfx->application->data;
1131 sqlite3_snprintf(MAX_QUERY_LEN, query,
1132 "UPDATE package_app_info SET app_mainapp='true' WHERE app_id=%Q",
1135 _LOGD("Not valid appid\n");
1139 ret = __exec_query(query);
1141 _LOGD("Package UiApp Info DB Insert Failed\n");
1145 free((void *)app->mainapp);
1146 app->mainapp = strdup("true");
1147 mfx->mainapp_id = strdup(app->appid);
1150 memset(query, '\0', MAX_QUERY_LEN);
1151 sqlite3_snprintf(MAX_QUERY_LEN, query,
1152 "UPDATE package_info SET mainapp_id=%Q WHERE package=%Q", mfx->mainapp_id, mfx->package);
1153 ret = __exec_query(query);
1155 _LOGD("Package Info DB update Failed\n");
1162 static int __convert_background_category(GList *category_list)
1165 GList *tmp_list = category_list;
1166 char *category_data = NULL;
1168 if (category_list == NULL)
1171 while (tmp_list != NULL) {
1172 category_data = (char *)tmp_list->data;
1173 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0)
1174 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1175 else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0)
1176 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1177 else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0)
1178 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1179 else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0)
1180 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1181 else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0)
1182 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1183 else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0)
1184 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1185 else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0)
1186 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1188 _LOGE("Unidentified category [%s]", category_data);
1189 tmp_list = g_list_next(tmp_list);
1195 static const char *__find_effective_appid(GList *metadata_list)
1200 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1201 md = (metadata_x *)tmp_list->data;
1202 if (md == NULL || md->key == NULL)
1205 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1214 static char *__get_bool(char *value, bool is_true)
1216 if (value != NULL) {
1217 if (!strcmp(value, ""))
1218 return (is_true) ? "true" : "false";
1222 return (is_true) ? "true" : "false";
1225 /* _PRODUCT_LAUNCHING_ENHANCED_
1226 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1228 static int __insert_application_info(manifest_x *mfx)
1233 int background_value = 0;
1234 char query[MAX_QUERY_LEN] = {'\0'};
1236 const char *effective_appid;
1239 type = strdup(mfx->type);
1241 type = strdup("tpk");
1243 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1244 app = (application_x *)tmp->data;
1248 background_value = __convert_background_category(app->background_category);
1249 if (background_value < 0) {
1250 _LOGE("Failed to retrieve background value[%d]", background_value);
1251 background_value = 0;
1254 effective_appid = __find_effective_appid(app->metadata);
1256 sqlite3_snprintf(MAX_QUERY_LEN, query,
1257 "INSERT INTO package_app_info(" \
1258 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1259 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1260 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1261 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1262 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1263 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1264 "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, " \
1265 "app_api_version, app_effective_appid, app_splash_screen_display) " \
1267 "%Q, %Q, %Q, LOWER(%Q), %Q, " \
1268 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1269 "%Q, %Q, %Q, %Q, %Q, " \
1270 "LOWER(%Q), %Q, %Q, LOWER(%Q), %Q, " \
1271 "LOWER(%Q), LOWER(%Q), %Q, %Q, LOWER(%Q), " \
1272 "COALESCE(%Q, 'caller'), LOWER(%Q), LOWER(%Q), %Q, %Q, " \
1273 "%Q, %Q, %d, %Q, %Q, " \
1274 "%Q, %Q, LOWER(%Q))", \
1275 app->appid, app->component_type, app->exec, __get_bool(app->nodisplay, false), app->type,
1276 __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),
1277 app->hwacceleration, app->screenreader, app->mainapp, app->recentimage, app->launchcondition,
1278 __get_bool(app->indicatordisplay, true), app->portraitimg, app->landscapeimg,
1279 __get_bool(app->guestmode_visibility, true), app->permission_type,
1280 __get_bool(mfx->preload, false), __get_bool(app->submode, false), app->submode_mainid, mfx->installed_storage, __get_bool(app->process_pool, false),
1281 app->launch_mode, __get_bool(app->ui_gadget, false), __get_bool(mfx->support_disable, false), app->component_type, mfx->package,
1282 mfx->tep_name, mfx->zip_mount_file, background_value, type, mfx->root_path, mfx->api_version,
1283 effective_appid, __get_bool(app->splash_screen_display, false));
1285 ret = __exec_query(query);
1287 _LOGD("Package UiApp Info DB Insert Failed\n");
1292 memset(query, '\0', MAX_QUERY_LEN);
1301 static int __insert_application_appcategory_info(manifest_x *mfx)
1308 char query[MAX_QUERY_LEN] = {'\0'};
1309 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1310 app = (application_x *)app_tmp->data;
1313 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1314 ct = (const char *)ct_tmp->data;
1317 sqlite3_snprintf(MAX_QUERY_LEN, query,
1318 "INSERT INTO package_app_app_category(app_id, category) " \
1321 ret = __exec_query(query);
1323 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1326 memset(query, '\0', MAX_QUERY_LEN);
1332 static int __insert_application_appmetadata_info(manifest_x *mfx)
1339 char query[MAX_QUERY_LEN] = {'\0'};
1340 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1341 app = (application_x *)app_tmp->data;
1344 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1345 md = (metadata_x *)md_tmp->data;
1349 sqlite3_snprintf(MAX_QUERY_LEN, query,
1350 "INSERT INTO package_app_app_metadata(app_id, md_key, md_value) " \
1351 "VALUES(%Q, %Q, %Q)",\
1352 app->appid, md->key, md->value ? md->value : NULL);
1353 ret = __exec_query(query);
1355 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1359 memset(query, '\0', MAX_QUERY_LEN);
1365 static int __insert_application_apppermission_info(manifest_x *mfx)
1372 char query[MAX_QUERY_LEN] = {'\0'};
1373 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1374 app = (application_x *)app_tmp->data;
1377 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1378 pm = (permission_x *)pm_tmp->data;
1381 sqlite3_snprintf(MAX_QUERY_LEN, query,
1382 "INSERT INTO package_app_app_permission(app_id, pm_type, pm_value) " \
1383 "VALUES(%Q, %Q, %Q)",\
1384 app->appid, pm->type, pm->value);
1385 ret = __exec_query(query);
1387 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1390 memset(query, '\0', MAX_QUERY_LEN);
1396 static int __insert_application_appcontrol_info(manifest_x *mfx)
1400 GList *acontrol_tmp;
1401 appcontrol_x *acontrol;
1403 char query[MAX_QUERY_LEN] = {'\0'};
1404 char buf[BUFSIZE] = {'\0'};
1405 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1406 app = (application_x *)app_tmp->data;
1409 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1410 acontrol = (appcontrol_x *)acontrol_tmp->data;
1411 if (acontrol == NULL)
1413 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1414 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1415 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1416 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1417 sqlite3_snprintf(MAX_QUERY_LEN, query,
1418 "INSERT INTO package_app_app_control(app_id, app_control) " \
1421 ret = __exec_query(query);
1423 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1426 memset(query, '\0', MAX_QUERY_LEN);
1432 static int __insert_application_datacontrol_info(manifest_x *mfx)
1439 char query[MAX_QUERY_LEN] = {'\0'};
1441 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1442 app = (application_x *)app_tmp->data;
1445 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1446 dc = (datacontrol_x *)dc_tmp->data;
1449 sqlite3_snprintf(MAX_QUERY_LEN, query,
1450 "INSERT INTO package_app_data_control(app_id, providerid, access, type) " \
1451 "VALUES(%Q, %Q, %Q, %Q)",\
1457 ret = __exec_query(query);
1459 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1462 memset(query, '\0', MAX_QUERY_LEN);
1468 static int __insert_application_share_request_info(manifest_x *mfx)
1477 char query[MAX_QUERY_LEN] = {'\0'};
1478 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1479 app = (application_x *)app_tmp->data;
1482 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1483 ds = (datashare_x *)ds_tmp->data;
1486 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1487 rq = (const char *)rq_tmp->data;
1490 sqlite3_snprintf(MAX_QUERY_LEN, query,
1491 "INSERT INTO package_app_share_request(app_id, data_share_request) " \
1494 ret = __exec_query(query);
1496 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1499 memset(query, '\0', MAX_QUERY_LEN);
1506 static int __insert_application_share_allowed_info(manifest_x *mfx)
1517 char query[MAX_QUERY_LEN] = {'\0'};
1518 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1519 app = (application_x *)app_tmp->data;
1522 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1523 ds = (datashare_x *)ds_tmp->data;
1526 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1527 df = (define_x *)df_tmp->data;
1530 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1531 al = (const char *)al_tmp->data;
1534 sqlite3_snprintf(MAX_QUERY_LEN, query,
1535 "INSERT INTO package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1536 "VALUES(%Q, %Q, %Q)",\
1537 app->appid, df->path, al);
1538 ret = __exec_query(query);
1540 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1543 memset(query, '\0', MAX_QUERY_LEN);
1551 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1553 splashscreen_x *ss = (splashscreen_x *)a;
1554 const char *orientation = (const char *)b;
1557 if (ss->operation || ss->dpi == NULL)
1560 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1564 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1570 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1572 splashscreen_x *ss = (splashscreen_x *)a;
1573 const char *orientation = (const char *)b;
1575 if (ss->operation || ss->dpi)
1578 if (strcasecmp(ss->orientation, orientation) == 0)
1584 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1585 const char *orientation)
1589 tmp = g_list_find_custom(splashscreens, orientation,
1590 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1592 return (splashscreen_x *)tmp->data;
1594 tmp = g_list_find_custom(splashscreens, orientation,
1595 (GCompareFunc)__compare_splashscreen_with_orientation);
1597 return (splashscreen_x *)tmp->data;
1602 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1604 splashscreen_x *ss = (splashscreen_x *)data;
1605 GList **list = (GList **)user_data;
1608 if (ss->operation == NULL || ss->dpi == NULL)
1611 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1615 if (__check_dpi(ss->dpi, dpi) != 0)
1618 *list = g_list_append(*list, ss);
1621 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1623 splashscreen_x *ss = (splashscreen_x *)data;
1624 GList **list = (GList **)user_data;
1625 splashscreen_x *ss_tmp;
1628 if (ss->operation == NULL || ss->dpi)
1631 for (tmp = *list; tmp; tmp = tmp->next) {
1632 ss_tmp = (splashscreen_x *)tmp->data;
1633 if (ss_tmp->operation
1634 && strcmp(ss_tmp->operation, ss->operation) == 0
1635 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1639 *list = g_list_append(*list, ss);
1642 static GList *__find_splashscreens(GList *splashscreens)
1647 g_list_foreach(splashscreens,
1648 __find_appcontrol_splashscreen_with_dpi, &list);
1649 g_list_foreach(splashscreens,
1650 __find_appcontrol_splashscreen, &list);
1652 ss = __find_default_splashscreen(splashscreens, "portrait");
1654 list = g_list_append(list, ss);
1655 ss = __find_default_splashscreen(splashscreens, "landscape");
1657 list = g_list_append(list, ss);
1662 static int __insert_application_splashscreen_info(manifest_x *mfx)
1670 char query[MAX_QUERY_LEN] = {'\0'};
1672 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1673 app = (application_x *)app_tmp->data;
1674 if (app == NULL || app->splashscreens == NULL)
1677 ss_tmp = __find_splashscreens(app->splashscreens);
1681 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1682 ss = (splashscreen_x *)tmp->data;
1683 sqlite3_snprintf(MAX_QUERY_LEN, query,
1684 "INSERT INTO package_app_splash_screen" \
1685 "(app_id, src, type, orientation, indicatordisplay, " \
1686 "operation, color_depth) " \
1687 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1688 app->appid, ss->src, ss->type, ss->orientation,
1689 ss->indicatordisplay, ss->operation,
1692 ret = __exec_query(query);
1694 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1697 memset(query, '\0', MAX_QUERY_LEN);
1699 g_list_free(ss_tmp);
1704 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1709 char query[MAX_QUERY_LEN] = {'\0'};
1711 const char *image_type;
1712 const char *indicatordisplay;
1713 const char *orientation;
1714 const char *operation = "launch-effect";
1715 const char *color_depth = "24"; /* default */
1717 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1718 app = (application_x *)app_tmp->data;
1720 (app->portraitimg == NULL && app->landscapeimg == NULL))
1722 image_type = "img"; /* default */
1723 if (app->effectimage_type) {
1724 tmp = strstr(app->effectimage_type, "edj");
1728 indicatordisplay = "true"; /* default */
1729 if (app->indicatordisplay)
1730 indicatordisplay = app->indicatordisplay;
1731 if (app->portraitimg) {
1732 orientation = "portrait";
1733 sqlite3_snprintf(MAX_QUERY_LEN, query,
1734 "INSERT INTO package_app_splash_screen" \
1735 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1736 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1737 app->appid, app->portraitimg, image_type,
1738 orientation, indicatordisplay, operation,
1740 ret = __exec_query(query);
1742 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1745 memset(query, '\0', MAX_QUERY_LEN);
1747 if (app->landscapeimg) {
1748 orientation = "landscape";
1749 sqlite3_snprintf(MAX_QUERY_LEN, query,
1750 "INSERT INTO package_app_splash_screen" \
1751 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1752 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1753 app->appid, app->landscapeimg, image_type,
1754 orientation, indicatordisplay, operation,
1756 ret = __exec_query(query);
1758 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1761 memset(query, '\0', MAX_QUERY_LEN);
1767 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1774 char query[MAX_QUERY_LEN] = {'\0'};
1776 char *tmpptr = NULL;
1777 const char *operation;
1778 const char *portraitimg;
1779 const char *landscapeimg;
1780 const char *indicatordisplay;
1781 const char *orientation;
1782 const char *image_type;
1783 const char *color_depth = "24"; /* default */
1785 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1786 app = (application_x *)app_tmp->data;
1790 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1791 md = (metadata_x *)md_tmp->data;
1792 if (md == NULL || md->key == NULL || md->value == NULL)
1795 if (strcasestr(md->key, "operation_effect=")) {
1796 operation = index(md->key, '=');
1797 if (operation && operation[1] != '\0')
1800 operation = "launch-effect";
1801 } else if (strcasestr(md->key, "launch_effect")) {
1802 operation = "launch-effect";
1808 landscapeimg = NULL;
1809 indicatordisplay = "true"; /* default */
1810 token = strtok_r(md->value, "|", &tmpptr);
1811 while (token != NULL) {
1812 if (strcasestr(token, "portrait-effectimage=")) {
1813 portraitimg = index(token, '=');
1814 if (portraitimg && portraitimg[1] != '\0')
1818 } else if (strcasestr(token, "landscape-effectimage=")) {
1819 landscapeimg = index(token, '=');
1820 if (landscapeimg && landscapeimg[1] != '\0')
1823 landscapeimg = NULL;
1824 } else if (strcasestr(token, "indicatordisplay=")) {
1825 indicatordisplay = index(token, '=');
1826 if (indicatordisplay && indicatordisplay[1] != '\0')
1829 indicatordisplay = "true";
1832 token = strtok_r(NULL, "|", &tmpptr);
1836 orientation = "portrait";
1838 if (strcasestr(portraitimg, "edj"))
1840 sqlite3_snprintf(MAX_QUERY_LEN, query,
1841 "INSERT INTO package_app_splash_screen" \
1842 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1843 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1844 app->appid, portraitimg, image_type,
1845 orientation, indicatordisplay, operation,
1847 ret = __exec_query(query);
1849 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1852 memset(query, '\0', MAX_QUERY_LEN);
1855 orientation = "landscape";
1857 if (strcasestr(landscapeimg, "edj"))
1859 sqlite3_snprintf(MAX_QUERY_LEN, query,
1860 "INSERT INTO package_app_splash_screen" \
1861 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1862 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1863 app->appid, landscapeimg, image_type,
1864 orientation, indicatordisplay, operation,
1866 ret = __exec_query(query);
1868 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1871 memset(query, '\0', MAX_QUERY_LEN);
1879 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1883 privilege_x *pv = NULL;
1884 char query[MAX_QUERY_LEN] = { '\0' };
1887 const char *auth_name = NULL;
1888 const char *auth_email = NULL;
1889 const char *auth_href = NULL;
1891 GList *pkglocale = NULL;
1892 GList *applocale = NULL;
1893 GList *appicon = NULL;
1894 GList *appimage = NULL;
1896 if (mfx->author && mfx->author->data) {
1897 author = (author_x *)mfx->author->data;
1899 auth_name = author->text;
1901 auth_email = author->email;
1903 auth_href = author->href;
1906 /*Insert in the package_info DB*/
1907 sqlite3_snprintf(MAX_QUERY_LEN, query,
1908 "INSERT INTO package_info(" \
1909 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1910 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1911 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1912 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1913 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1915 "%Q, %Q, %Q, %Q, %Q, %Q, " \
1916 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1917 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), %Q, " \
1918 "%Q, %Q, %Q, %Q, %Q, " \
1919 "%Q, %Q, %Q, %Q, LOWER(%Q))",
1920 mfx->package, mfx->type, mfx->version, mfx->api_version, mfx->tep_name, mfx->zip_mount_file,
1921 mfx->installlocation, mfx->package_size, __get_bool(mfx->removable, true), __get_bool(mfx->preload, false), __get_bool(mfx->readonly, false),
1922 __get_bool(mfx->update, false), __get_bool(mfx->appsetting, false), __get_bool(mfx->nodisplay_setting, false), __get_bool(mfx->system, false), auth_name,
1923 auth_email, auth_href, mfx->installed_time, mfx->installed_storage,
1924 mfx->storeclient_id,
1925 mfx->mainapp_id, mfx->package_url, mfx->root_path, mfx->csc_path, __get_bool(mfx->support_disable, false));
1927 ret = __exec_query(query);
1929 _LOGD("Package Info DB Insert Failed\n");
1933 /*Insert in the package_privilege_info DB*/
1934 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1935 pv = (privilege_x *)tmp->data;
1938 memset(query, '\0', MAX_QUERY_LEN);
1939 sqlite3_snprintf(MAX_QUERY_LEN, query,
1940 "INSERT INTO package_privilege_info(package, privilege, type) " \
1941 "VALUES(%Q, %Q, %Q)",\
1942 mfx->package, pv->value, pv->type);
1943 ret = __exec_query(query);
1945 _LOGD("Package Privilege Info DB Insert Failed\n");
1950 if (mfx->application != NULL) {
1951 ret = __insert_mainapp_info(mfx);
1956 /*Insert the package locale*/
1957 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1958 /*remove duplicated data in pkglocale*/
1959 __trimfunc(pkglocale);
1961 /*Insert the app locale, icon, image info */
1962 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1963 app = (application_x *)tmp->data;
1966 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1967 appicon = __create_icon_list(appicon, app->icon);
1968 appimage = __create_image_list(appimage, app->image);
1970 /*remove duplicated data in applocale*/
1971 __trimfunc(applocale);
1972 __trimfunc(appicon);
1973 __trimfunc(appimage);
1975 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1977 /*native app locale info*/
1978 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1979 app = (application_x *)tmp->data;
1982 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1983 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1984 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1987 g_list_free(pkglocale);
1989 g_list_free(applocale);
1991 g_list_free(appicon);
1993 g_list_free(appimage);
1996 /*Insert in the package_app_info DB*/
1997 ret = __insert_application_info(mfx);
2000 /*Insert in the package_app_app_control DB*/
2001 ret = __insert_application_appcontrol_info(mfx);
2005 /*Insert in the package_app_app_category DB*/
2006 ret = __insert_application_appcategory_info(mfx);
2010 /*Insert in the package_app_app_metadata DB*/
2011 ret = __insert_application_appmetadata_info(mfx);
2015 /*Insert in the package_app_app_permission DB*/
2016 ret = __insert_application_apppermission_info(mfx);
2020 /*Insert in the package_app_share_allowed DB*/
2021 ret = __insert_application_share_allowed_info(mfx);
2025 /*Insert in the package_app_share_request DB*/
2026 ret = __insert_application_share_request_info(mfx);
2030 /*Insert in the package_app_data_control DB*/
2031 ret = __insert_application_datacontrol_info(mfx);
2035 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2036 ret = __insert_application_legacy_splashscreen_info(mfx);
2040 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2041 ret = __insert_application_metadata_splashscreen_info(mfx);
2045 /*Insert in the package_app_splash_screen DB*/
2046 ret = __insert_application_splashscreen_info(mfx);
2054 static int __delete_appinfo_from_db(char *db_table, const char *appid)
2056 char query[MAX_QUERY_LEN] = { '\0' };
2059 sqlite3_snprintf(MAX_QUERY_LEN, query,
2060 "DELETE FROM %q where app_id=%Q", db_table, appid);
2061 ret = __exec_query(query);
2063 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
2069 static int __delete_subpkg_info_from_db(char *appid)
2073 ret = __delete_appinfo_from_db("package_app_info", appid);
2076 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
2079 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
2082 ret = __delete_appinfo_from_db("package_app_image_info", appid);
2085 ret = __delete_appinfo_from_db("package_app_app_control", appid);
2088 ret = __delete_appinfo_from_db("package_app_app_category", appid);
2091 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
2094 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
2097 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
2100 ret = __delete_appinfo_from_db("package_app_share_request", appid);
2103 ret = __delete_appinfo_from_db("package_app_data_control", appid);
2106 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
2113 static int __delete_subpkg_from_db(manifest_x *mfx)
2115 char query[MAX_QUERY_LEN] = { '\0' };
2116 char *error_message = NULL;
2118 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT app_id FROM package_app_info WHERE package=%Q", mfx->package);
2120 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
2121 _LOGE("Don't execute query = %s error message = %s\n", query,
2123 sqlite3_free(error_message);
2126 sqlite3_free(error_message);
2131 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
2133 char query[MAX_QUERY_LEN] = { '\0' };
2138 /*Delete from Package Info DB*/
2139 sqlite3_snprintf(MAX_QUERY_LEN, query,
2140 "DELETE FROM package_info WHERE package=%Q", mfx->package);
2141 ret = __exec_query(query);
2143 _LOGD("Package Info DB Delete Failed\n");
2146 memset(query, '\0', MAX_QUERY_LEN);
2148 /*Delete from Package Localized Info*/
2149 sqlite3_snprintf(MAX_QUERY_LEN, query,
2150 "DELETE FROM package_localized_info WHERE package=%Q", mfx->package);
2151 ret = __exec_query(query);
2153 _LOGD("Package Localized Info DB Delete Failed\n");
2157 /*Delete from Package Privilege Info*/
2158 sqlite3_snprintf(MAX_QUERY_LEN, query,
2159 "DELETE FROM package_privilege_info WHERE package=%Q", mfx->package);
2160 ret = __exec_query(query);
2162 _LOGD("Package Privilege Info DB Delete Failed\n");
2166 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2167 app = (application_x *)tmp->data;
2170 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2173 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2176 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2179 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2182 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2185 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2188 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2191 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2194 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2197 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2200 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2203 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2208 /* if main package has sub pkg, delete sub pkg data*/
2209 __delete_subpkg_from_db(mfx);
2214 static int __disable_app(const char *appid)
2217 char query[MAX_QUERY_LEN] = {'\0'};
2218 sqlite3_snprintf(MAX_QUERY_LEN, query,
2219 "UPDATE package_app_info SET app_disable='true' WHERE app_id=%Q",
2221 ret = __exec_query(query);
2223 _LOGD("Insert global app disable failed\n");
2228 static int __enable_app(const char *appid)
2231 char query[MAX_QUERY_LEN] = {'\0'};
2232 sqlite3_snprintf(MAX_QUERY_LEN, query,
2233 "UPDATE package_app_info SET app_disable='false' WHERE app_id=%Q",
2235 ret = __exec_query(query);
2237 _LOGD("Insert global app disable failed\n");
2242 static int __disable_pkg(const char *pkgid)
2245 char query[MAX_QUERY_LEN] = {'\0'};
2246 sqlite3_snprintf(MAX_QUERY_LEN, query,
2247 "UPDATE package_info SET package_disable='true' WHERE package=%Q",
2249 ret = __exec_query(query);
2251 _LOGD("Update pkg disable info has failed\n");
2256 static int __enable_pkg(const char *pkgid)
2259 char query[MAX_QUERY_LEN] = {'\0'};
2260 sqlite3_snprintf(MAX_QUERY_LEN, query,
2261 "UPDATE package_info SET package_disable='false' WHERE package=%Q",
2263 ret = __exec_query(query);
2265 _LOGD("Update pkg disable info has failed\n");
2270 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2273 char query[MAX_QUERY_LEN] = { '\0', };
2275 const char *val = NULL;
2280 sqlite3_snprintf(MAX_QUERY_LEN, query,
2281 "SELECT COUNT(*) FROM "
2282 "package_app_info_for_uid WHERE app_id=%Q "
2283 "AND uid=%d", appid, (int)uid);
2285 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2286 if (ret != SQLITE_OK) {
2287 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2288 return PMINFO_R_ERROR;
2291 if (sqlite3_step(stmt) != SQLITE_ROW) {
2292 LOGE("failed to step");
2293 sqlite3_finalize(stmt);
2294 return PMINFO_R_ERROR;
2297 val = (const char *)sqlite3_column_text(stmt, 0);
2299 sqlite3_finalize(stmt);
2304 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2307 char query[MAX_QUERY_LEN] = { '\0', };
2309 ret = __check_appinfo_for_uid_table(appid, uid);
2311 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2314 } else if (ret == 0) {
2315 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2316 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2317 "VALUES(%Q, %d, 'true', "
2318 "(SELECT app_splash_screen_display FROM package_app_info WHERE appid='%Q'))",
2319 appid, (int)uid, appid);
2321 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2322 "package_app_info_for_uid SET is_disabled='true' "
2323 "WHERE app_id=%Q AND uid=%d", appid, (int)uid);
2326 ret = __exec_query(query);
2328 _LOGD("Add global app disable info failed\n");
2333 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2336 char query[MAX_QUERY_LEN] = {'\0'};
2338 ret = __check_appinfo_for_uid_table(appid, uid);
2340 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2343 } else if (ret > 0) {
2344 sqlite3_snprintf(MAX_QUERY_LEN, query,
2345 "UPDATE package_app_info_for_uid SET "
2346 "is_disabled='false' WHERE app_id=%Q AND "
2347 "uid=%d", appid, (int)uid);
2350 ret = __exec_query(query);
2352 _LOGD("Remove global app disable info failed\n");
2357 static int __update_global_app_splash_screen_for_user(const char *appid,
2358 uid_t uid, int flag)
2361 char query[MAX_QUERY_LEN] = { '\0', };
2363 ret = __check_appinfo_for_uid_table(appid, uid);
2365 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2368 } else if (ret == 0) {
2369 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2370 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2371 "VALUES(%Q, %d, %Q)", appid, (int)uid,
2372 flag ? "true" : "false");
2374 sqlite3_snprintf(MAX_QUERY_LEN, query,
2375 "UPDATE package_app_info_for_uid SET "
2376 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2377 "uid=%d", flag ? "true" : "false", appid, (int)uid);
2380 ret = __exec_query(query);
2382 _LOGD("update global app splash screen info failed\n");
2387 static int __disable_app_splash_screen(const char *appid)
2390 char query[MAX_QUERY_LEN] = {'\0'};
2392 sqlite3_snprintf(MAX_QUERY_LEN, query,
2393 "UPDATE package_app_info SET app_splash_screen_display='false' WHERE app_id=%Q",
2395 ret = __exec_query(query);
2397 _LOGD("Failed to update app_palsh_screen_display");
2402 static int __enable_app_splash_screen(const char *appid)
2405 char query[MAX_QUERY_LEN] = {'\0'};
2407 sqlite3_snprintf(MAX_QUERY_LEN, query,
2408 "UPDATE package_app_info SET app_splash_screen_display='true' WHERE app_id=%Q",
2410 ret = __exec_query(query);
2412 _LOGD("Failed to update app_splash_screen_display");
2417 API int pkgmgr_parser_initialize_db(uid_t uid)
2423 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2425 _LOGD("package info DB initialization failed\n");
2428 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2430 _LOGD("package localized info DB initialization failed\n");
2433 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2435 _LOGD("package app app privilege DB initialization failed\n");
2438 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2440 _LOGD("package app info DB initialization failed\n");
2443 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2445 _LOGD("package app localized info DB initialization failed\n");
2448 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2450 _LOGD("package app icon localized info DB initialization failed\n");
2453 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2455 _LOGD("package app image info DB initialization failed\n");
2458 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2460 _LOGD("package app app control DB initialization failed\n");
2463 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2465 _LOGD("package app app category DB initialization failed\n");
2468 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2470 _LOGD("package app app category DB initialization failed\n");
2473 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2475 _LOGD("package app app permission DB initialization failed\n");
2478 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2480 _LOGD("package app share allowed DB initialization failed\n");
2483 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2485 _LOGD("package app share request DB initialization failed\n");
2488 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2490 _LOGD("package app data control DB initialization failed\n");
2494 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2496 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2500 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2502 _LOGD("package app splash screen DB initialization failed\n");
2506 /* Trigger package_app_info_for_uid */
2507 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2509 _LOGD("package app info for uid DB initialization failed\n");
2514 /* TODO: refactor this code */
2515 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2517 _LOGD("package cert info DB initialization failed\n");
2520 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2522 _LOGD("package cert index info DB initialization failed\n");
2525 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO);
2527 _LOGD("package cert info DB initialization failed\n");
2530 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2);
2532 _LOGD("package cert info DB initialization failed\n");
2535 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2537 _LOGD("package cert info DB initialization failed\n");
2540 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2542 _LOGD("package cert index info DB initialization failed\n");
2546 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2547 if (db_path == NULL) {
2548 _LOGD("Failed to get user cert db path - GLOBAL_USER");
2550 ret = __parserdb_change_perm(db_path, GLOBAL_USER);
2552 _LOGD("Failed to change cert db permission");
2556 db_path = getUserPkgParserDBPathUID(uid);
2557 if (db_path == NULL) {
2558 _LOGD("Failed to get user pkg parser db path - %d", uid);
2560 ret = __parserdb_change_perm(db_path, uid);
2562 _LOGD("Failed to change parser db permission\n");
2569 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2572 char pwuid_buf[1024];
2573 char journal_file[BUFSIZE];
2578 struct passwd userinfo, *result = NULL;
2579 files[0] = (char *)db_file;
2580 files[1] = journal_file;
2584 if (db_file == NULL)
2587 if (getuid() != OWNER_ROOT) /* At this time we should be root to apply this */
2589 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2590 if (uid == OWNER_ROOT)
2592 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2593 if (ret != 0 || result == NULL) {
2594 _LOGE("FAIL: user %d doesn't exist", uid);
2597 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2599 for (i = 0; files[i]; i++) {
2600 fd = open(files[i], O_RDONLY);
2602 if (strerror_r(errno, buf, sizeof(buf)))
2603 strncpy(buf, "", BUFSIZE - 1);
2604 _LOGD("FAIL : open %s : %s", files[i], buf);
2607 ret = fstat(fd, &sb);
2609 if (strerror_r(errno, buf, sizeof(buf)))
2610 strncpy(buf, "", BUFSIZE - 1);
2611 _LOGD("FAIL : fstat %s : %s", files[i], buf);
2615 if (S_ISLNK(sb.st_mode)) {
2616 _LOGE("FAIL : %s is symlink!", files[i]);
2620 ret = fchown(fd, uid, userinfo.pw_gid);
2622 if (strerror_r(errno, buf, sizeof(buf)))
2623 strncpy(buf, "", BUFSIZE - 1);
2624 _LOGD("FAIL : fchown %s %d.%d : %s", files[i], uid,
2625 userinfo.pw_gid, buf);
2630 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2631 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2633 ret = fchmod(fd, mode);
2635 if (strerror_r(errno, buf, sizeof(buf)))
2636 strncpy(buf, "", BUFSIZE - 1);
2637 _LOGD("FAIL : fchmod %s 0664 : %s", files[i], buf);
2642 SET_SMACK_LABEL(files[i]);
2647 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2652 if (getuid() != OWNER_ROOT) {
2653 _LOGE("Only root user is allowed");
2657 db_path = getUserPkgParserDBPathUID(uid);
2658 if (db_path == NULL) {
2659 _LOGE("Failed to get pkg parser db path - %d", uid);
2663 if (access(db_path, F_OK) != -1) {
2664 _LOGE("Manifest db for user %d is already exists", uid);
2670 db_path = getUserPkgCertDBPathUID(uid);
2671 if (db_path == NULL) {
2672 _LOGE("Failed to get pkg cert db path - %d", uid);
2676 if (access(db_path, F_OK) != -1) {
2677 _LOGE("Cert db for user %d is already exists", uid);
2683 ret = pkgmgr_parser_check_and_create_db(uid);
2686 ret = pkgmgr_parser_initialize_db(uid);
2688 pkgmgr_parser_close_db();
2691 pkgmgr_parser_close_db();
2696 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2701 db_path = getUserPkgParserDBPathUID(uid);
2702 if (db_path == NULL) {
2703 _LOGD("Failed to get pkg parser db path - %d", uid);
2708 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, db_path);
2710 _LOGD("Manifest DB creation Failed\n");
2716 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2717 if (db_path == NULL) {
2718 _LOGE("Failed to get pkg cert db path - GLOBAL_USER");
2723 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, db_path);
2725 _LOGD("Cert DB creation Failed\n");
2735 void pkgmgr_parser_close_db(void)
2737 sqlite3_close(pkgmgr_parser_db);
2738 sqlite3_close(pkgmgr_cert_db);
2742 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2744 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2746 _LOGD("manifest pointer is NULL\n");
2750 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2752 _LOGD("Failed to open DB\n");
2755 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2758 /*Begin transaction*/
2759 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2760 if (ret != SQLITE_OK) {
2761 _LOGD("Failed to begin transaction\n");
2765 _LOGD("Transaction Begin\n");
2766 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2768 _LOGD("Insert into DB failed. Rollback now\n");
2769 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2772 /*Commit transaction*/
2773 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2774 if (ret != SQLITE_OK) {
2775 _LOGD("Failed to commit transaction. Rollback now\n");
2776 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2780 _LOGD("Transaction Commit and End\n");
2782 pkgmgr_parser_close_db();
2786 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2788 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2790 _LOGD("manifest pointer is NULL\n");
2794 ret = pkgmgr_parser_check_and_create_db(uid);
2796 _LOGD("Failed to open DB\n");
2799 ret = pkgmgr_parser_initialize_db(uid);
2802 /*Begin transaction*/
2803 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2804 if (ret != SQLITE_OK) {
2805 _LOGD("Failed to begin transaction\n");
2809 _LOGD("Transaction Begin\n");
2810 ret = __insert_manifest_info_in_db(mfx, uid);
2812 _LOGD("Insert into DB failed. Rollback now\n");
2813 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2816 /*Commit transaction*/
2817 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2818 if (ret != SQLITE_OK) {
2819 _LOGD("Failed to commit transaction. Rollback now\n");
2820 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2824 _LOGD("Transaction Commit and End\n");
2826 pkgmgr_parser_close_db();
2830 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2832 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, _getuid());
2835 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2837 if (pkgid == NULL || tep_path == NULL) {
2838 _LOGE("invalid parameter");
2845 ret = pkgmgr_parser_check_and_create_db(uid);
2847 _LOGD("Failed to open DB\n");
2850 ret = pkgmgr_parser_initialize_db(uid);
2854 /*Begin transaction*/
2855 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2856 if (ret != SQLITE_OK) {
2857 _LOGD("Failed to begin transaction\n");
2861 _LOGD("Transaction Begin\n");
2864 /* Updating TEP info in "package_info" table */
2865 query = sqlite3_mprintf("UPDATE package_info "\
2866 "SET package_tep_name = %Q "\
2867 "WHERE package = %Q", tep_path, pkgid);
2869 ret = __exec_query(query);
2870 sqlite3_free(query);
2871 if (ret != SQLITE_OK) {
2872 ret = PM_PARSER_R_ERROR;
2873 _LOGE("sqlite exec failed to insert entries into package_info!!");
2877 /* Updating TEP info in "package_app_info" table */
2878 query = sqlite3_mprintf("UPDATE package_app_info "\
2879 "SET app_tep_name = %Q "\
2880 "WHERE package = %Q", tep_path, pkgid);
2882 ret = __exec_query(query);
2883 sqlite3_free(query);
2884 if (ret != SQLITE_OK) {
2885 ret = PM_PARSER_R_ERROR;
2886 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2890 /*Commit transaction*/
2891 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2892 if (ret != SQLITE_OK) {
2893 _LOGE("Failed to commit transaction, Rollback now\n");
2894 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2895 if (ret != SQLITE_OK)
2896 _LOGE("Failed to Rollback\n");
2898 ret = PM_PARSER_R_ERROR;
2901 _LOGD("Transaction Commit and End\n");
2902 ret = PM_PARSER_R_OK;
2905 pkgmgr_parser_close_db();
2910 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2913 _LOGD("manifest pointer is NULL\n");
2917 ret = pkgmgr_parser_check_and_create_db(uid);
2919 _LOGD("Failed to open DB\n");
2922 ret = pkgmgr_parser_initialize_db(uid);
2925 /*Preserve guest mode visibility*/
2926 __preserve_guestmode_visibility_value(mfx);
2927 /*Begin transaction*/
2928 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2929 if (ret != SQLITE_OK) {
2930 _LOGD("Failed to begin transaction\n");
2934 _LOGD("Transaction Begin\n");
2935 ret = __delete_manifest_info_from_db(mfx, uid);
2937 _LOGD("Delete from DB failed. Rollback now\n");
2938 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2941 ret = __insert_manifest_info_in_db(mfx, uid);
2943 _LOGD("Insert into DB failed. Rollback now\n");
2944 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2948 /*Commit transaction*/
2949 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2950 if (ret != SQLITE_OK) {
2951 _LOGD("Failed to commit transaction. Rollback now\n");
2952 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2956 _LOGD("Transaction Commit and End\n");
2958 pkgmgr_parser_close_db();
2962 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2964 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2967 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2970 _LOGD("manifest pointer is NULL\n");
2974 ret = pkgmgr_parser_check_and_create_db(uid);
2976 _LOGD("Failed to open DB\n");
2979 /*Begin transaction*/
2980 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2981 if (ret != SQLITE_OK) {
2982 _LOGD("Failed to begin transaction\n");
2986 _LOGD("Transaction Begin\n");
2987 ret = __delete_manifest_info_from_db(mfx, uid);
2989 _LOGD("Delete from DB failed. Rollback now\n");
2990 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2993 /*Commit transaction*/
2994 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2995 if (ret != SQLITE_OK) {
2996 _LOGD("Failed to commit transaction, Rollback now\n");
2997 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3001 _LOGD("Transaction Commit and End\n");
3003 pkgmgr_parser_close_db();
3007 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
3009 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
3012 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
3016 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3018 _LOGD("Failed to open DB\n");
3022 /*Begin transaction*/
3023 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3024 if (ret != SQLITE_OK) {
3025 _LOGD("Failed to begin transaction\n");
3029 _LOGD("Transaction Begin\n");
3031 ret = __disable_global_app_for_user(appid, uid);
3033 ret = __enable_global_app_for_user(appid, uid);
3035 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
3036 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3039 /*Commit transaction*/
3040 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3041 if (ret != SQLITE_OK) {
3042 _LOGD("Failed to commit transaction, Rollback now\n");
3043 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3047 _LOGD("Transaction Commit and End\n");
3049 pkgmgr_parser_close_db();
3054 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
3056 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
3059 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid, uid_t uid, int is_disable)
3063 ret = pkgmgr_parser_check_and_create_db(uid);
3065 _LOGD("Failed to open DB\n");
3069 /*Begin transaction*/
3070 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3071 if (ret != SQLITE_OK) {
3072 _LOGD("Failed to begin transaction\n");
3077 _LOGD("Transaction Begin\n");
3079 ret = __disable_pkg(pkgid);
3081 ret = __enable_pkg(pkgid);
3084 _LOGD("__update_pkg_disable_condition_in_db failed. Rollback now\n");
3085 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3089 /*Commit transaction*/
3090 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3091 if (ret != SQLITE_OK) {
3092 _LOGD("Failed to commit transaction, Rollback now\n");
3093 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3097 _LOGD("Transaction Commit and End\n");
3100 pkgmgr_parser_close_db();
3104 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid, int is_disable)
3106 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid, _getuid(), is_disable);
3109 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
3113 ret = pkgmgr_parser_check_and_create_db(uid);
3115 _LOGD("Failed to open DB\n");
3119 /*Begin transaction*/
3120 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3121 if (ret != SQLITE_OK) {
3122 _LOGD("Failed to begin transaction\n");
3126 _LOGD("Transaction Begin\n");
3128 ret = __disable_app(appid);
3130 ret = __enable_app(appid);
3132 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
3133 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3136 /*Commit transaction*/
3137 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3138 if (ret != SQLITE_OK) {
3139 _LOGD("Failed to commit transaction, Rollback now\n");
3140 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3144 _LOGD("Transaction Commit and End\n");
3146 pkgmgr_parser_close_db();
3151 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3155 if (appid == NULL) {
3156 _LOGD("Invalid parameter");
3160 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3162 _LOGD("Failed to open DB\n");
3166 /* Begin transaction */
3167 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3168 if (ret != SQLITE_OK) {
3169 _LOGD("Failed to begin transaction\n");
3173 _LOGD("Transaction Begin\n");
3175 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3177 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3178 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3181 /* Commit transaction */
3182 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3183 if (ret != SQLITE_OK) {
3184 _LOGD("Failed to commit transaction, Rollback now\n");
3185 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3189 _LOGD("Transaction Commit and End\n");
3191 pkgmgr_parser_close_db();
3195 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3197 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3200 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3204 if (appid == NULL) {
3205 _LOGD("Invalid parameter");
3209 ret = pkgmgr_parser_check_and_create_db(uid);
3211 _LOGD("Failed to open DB");
3215 /* Begin transaction */
3216 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3217 if (ret != SQLITE_OK) {
3218 _LOGD("Failed to begin transaction");
3222 _LOGD("Transaction Begin");
3225 ret = __enable_app_splash_screen(appid);
3227 ret = __disable_app_splash_screen(appid);
3229 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3230 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3233 /* Commit transaction */
3234 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3235 if (ret != SQLITE_OK) {
3236 _LOGD("Failed to commit transaction, Rollback now");
3237 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3241 _LOGD("Transaction Commit and End");
3244 pkgmgr_parser_close_db();