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 "pkgmgr_parser_internal.h"
45 #include "pkgmgr_parser_db.h"
46 #include "pkgmgr_parser_debug.h"
48 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
49 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
50 #define MAX_QUERY_LEN 4096
58 #define XXHDPI "xxhdpi"
68 #define XXHDPI_MIN 481
69 #define XXHDPI_MAX 600
71 #define DB_LABEL "User::Home"
72 #define SET_SMACK_LABEL(x) \
74 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
75 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
77 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
80 sqlite3 *pkgmgr_parser_db;
81 sqlite3 *pkgmgr_cert_db;
84 #define QUERY_CREATE_TABLE_PACKAGE_INFO "CREATE TABLE IF NOT EXISTS package_info " \
85 "(package TEXT PRIMARY KEY NOT NULL, " \
86 "package_type TEXT DEFAULT 'tpk', " \
87 "package_version TEXT, " \
88 "package_api_version TEXT, " \
89 "package_tep_name TEXT, " \
90 "package_zip_mount_file TEXT, " \
91 "install_location TEXT NOT NULL , " \
92 "package_size TEXT, " \
93 "package_removable TEXT NOT NULL DEFAULT 'true', " \
94 "package_preload TEXT NOT NULL DEFAULT 'false', " \
95 "package_readonly TEXT NOT NULL DEFAULT 'false', " \
96 "package_update TEXT NOT NULL DEFAULT 'false', " \
97 "package_appsetting TEXT NOT NULL DEFAULT 'false', " \
98 "package_nodisplay TEXT NOT NULL DEFAULT 'false', " \
99 "package_system TEXT NOT NULL DEFAULT 'false', " \
100 "author_name TEXT, " \
101 "author_email TEXT, " \
102 "author_href TEXT," \
103 "installed_time TEXT, " \
104 "installed_storage TEXT, " \
105 "storeclient_id TEXT, " \
106 "mainapp_id TEXT, " \
107 "package_url TEXT, " \
109 "external_path TEXT, " \
111 "package_support_mode TEXT, " \
112 "package_support_disable TEXT NOT NULL DEFAULT 'false', " \
113 "package_disable TEXT NOT NULL DEFAULT 'false')"
115 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_localized_info " \
116 "(package TEXT NOT NULL, " \
117 "package_locale TEXT NOT NULL DEFAULT 'No Locale', " \
118 "package_label TEXT, " \
119 "package_icon TEXT, " \
120 "package_description TEXT, " \
121 "package_license TEXT, " \
122 "package_author TEXT, " \
123 "PRIMARY KEY(package, package_locale), " \
124 "FOREIGN KEY(package) " \
125 "REFERENCES package_info(package) " \
128 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "CREATE TABLE IF NOT EXISTS package_privilege_info " \
129 "(package TEXT NOT NULL, " \
130 "privilege TEXT NOT NULL, " \
131 "type TEXT NOT NULL, " \
132 "PRIMARY KEY(package, privilege, type) " \
133 "FOREIGN KEY(package) " \
134 "REFERENCES package_info(package) " \
137 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "CREATE TABLE IF NOT EXISTS package_app_info " \
138 "(app_id TEXT PRIMARY KEY NOT NULL, " \
139 "app_component TEXT NOT NULL, " \
141 "app_nodisplay TEXT NOT NULL DEFAULT 'false', " \
143 "app_onboot TEXT NOT NULL DEFAULT 'false', " \
144 "app_multiple TEXT NOT NULL DEFAULT 'false', " \
145 "app_autorestart TEXT NOT NULL DEFAULT 'false', " \
146 "app_taskmanage TEXT NOT NULL DEFAULT 'false', " \
147 "app_enabled TEXT NOT NULL DEFAULT 'true', " \
148 "app_hwacceleration TEXT NOT NULL DEFAULT 'use-system-setting', " \
149 "app_screenreader TEXT NOT NULL DEFAULT 'use-system-setting', " \
150 "app_mainapp TEXT NOT NULL, " \
151 "app_recentimage TEXT NOT NULL DEFAULT 'false', " \
152 "app_launchcondition TEXT, " \
153 "app_indicatordisplay TEXT NOT NULL DEFAULT 'true', " \
154 "app_portraitimg TEXT, " \
155 "app_landscapeimg TEXT, " \
156 "app_guestmodevisibility TEXT NOT NULL DEFAULT 'true', " \
157 "app_permissiontype TEXT NOT NULL DEFAULT 'normal', " \
158 "app_preload TEXT NOT NULL DEFAULT 'false', " \
159 "app_submode TEXT NOT NULL DEFAULT 'false', " \
160 "app_submode_mainid TEXT, " \
161 "app_installed_storage TEXT NOT NULL, " \
162 "app_process_pool TEXT NOT NULL DEFAULT 'false', " \
163 "app_launch_mode TEXT NOT NULL DEFAULT 'caller', " \
164 "app_ui_gadget TEXT NOT NULL DEFAULT 'false', " \
165 "app_support_mode TEXT, " \
166 "app_support_disable TEXT NOT NULL DEFAULT 'false', " \
167 "app_disable TEXT NOT NULL DEFAULT 'false', " \
168 "app_package_type TEXT DEFAULT 'tpk', " \
169 "app_package_system TEXT NOT NULL, " \
170 "app_removable TEXT NOT NULL DEFAULT 'false', " \
171 "app_package_installed_time TEXT, " \
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_mode, 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, app_package_system, app_removable, " \
1266 "app_package_installed_time, app_support_mode) " \
1268 "%Q, %Q, %Q, LOWER(%Q), %Q, " \
1269 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1270 "%Q, %Q, %Q, %Q, %Q, " \
1271 "LOWER(%Q), %Q, %Q, LOWER(%Q), %Q, " \
1272 "LOWER(%Q), LOWER(%Q), %Q, %Q, LOWER(%Q), " \
1273 "COALESCE(%Q, 'caller'), LOWER(%Q), %Q, LOWER(%Q), %Q, %Q, " \
1274 "%Q, %Q, %d, %Q, %Q, " \
1275 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1277 app->appid, app->component_type, app->exec, __get_bool(app->nodisplay, false), app->type,
1278 __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),
1279 app->hwacceleration, app->screenreader, app->mainapp, app->recentimage, app->launchcondition,
1280 __get_bool(app->indicatordisplay, true), app->portraitimg, app->landscapeimg,
1281 __get_bool(app->guestmode_visibility, true), app->permission_type,
1282 __get_bool(mfx->preload, false), __get_bool(app->submode, false), app->submode_mainid, mfx->installed_storage, __get_bool(app->process_pool, false),
1283 app->launch_mode, __get_bool(app->ui_gadget, false), mfx->support_mode, __get_bool(mfx->support_disable, false), app->component_type, mfx->package,
1284 mfx->tep_name, mfx->zip_mount_file, background_value, type, mfx->root_path, mfx->api_version,
1285 effective_appid, __get_bool(app->splash_screen_display, false), __get_bool(mfx->system, false), __get_bool(mfx->removable, true), mfx->installed_time, mfx->support_mode);
1287 ret = __exec_query(query);
1289 _LOGD("Package UiApp Info DB Insert Failed\n");
1294 memset(query, '\0', MAX_QUERY_LEN);
1303 static int __insert_application_appcategory_info(manifest_x *mfx)
1310 char query[MAX_QUERY_LEN] = {'\0'};
1311 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1312 app = (application_x *)app_tmp->data;
1315 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1316 ct = (const char *)ct_tmp->data;
1319 sqlite3_snprintf(MAX_QUERY_LEN, query,
1320 "INSERT INTO package_app_app_category(app_id, category) " \
1323 ret = __exec_query(query);
1325 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1328 memset(query, '\0', MAX_QUERY_LEN);
1334 static int __insert_application_appmetadata_info(manifest_x *mfx)
1341 char query[MAX_QUERY_LEN] = {'\0'};
1342 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1343 app = (application_x *)app_tmp->data;
1346 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1347 md = (metadata_x *)md_tmp->data;
1351 sqlite3_snprintf(MAX_QUERY_LEN, query,
1352 "INSERT INTO package_app_app_metadata(app_id, md_key, md_value) " \
1353 "VALUES(%Q, %Q, %Q)",\
1354 app->appid, md->key, md->value ? md->value : NULL);
1355 ret = __exec_query(query);
1357 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1361 memset(query, '\0', MAX_QUERY_LEN);
1367 static int __insert_application_apppermission_info(manifest_x *mfx)
1374 char query[MAX_QUERY_LEN] = {'\0'};
1375 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1376 app = (application_x *)app_tmp->data;
1379 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1380 pm = (permission_x *)pm_tmp->data;
1383 sqlite3_snprintf(MAX_QUERY_LEN, query,
1384 "INSERT INTO package_app_app_permission(app_id, pm_type, pm_value) " \
1385 "VALUES(%Q, %Q, %Q)",\
1386 app->appid, pm->type, pm->value);
1387 ret = __exec_query(query);
1389 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1392 memset(query, '\0', MAX_QUERY_LEN);
1398 static int __insert_application_appcontrol_info(manifest_x *mfx)
1402 GList *acontrol_tmp;
1403 appcontrol_x *acontrol;
1405 char query[MAX_QUERY_LEN] = {'\0'};
1406 char buf[BUFSIZE] = {'\0'};
1407 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1408 app = (application_x *)app_tmp->data;
1411 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1412 acontrol = (appcontrol_x *)acontrol_tmp->data;
1413 if (acontrol == NULL)
1415 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1416 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1417 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1418 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1419 sqlite3_snprintf(MAX_QUERY_LEN, query,
1420 "INSERT INTO package_app_app_control(app_id, app_control) " \
1423 ret = __exec_query(query);
1425 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1428 memset(query, '\0', MAX_QUERY_LEN);
1434 static int __insert_application_datacontrol_info(manifest_x *mfx)
1441 char query[MAX_QUERY_LEN] = {'\0'};
1443 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1444 app = (application_x *)app_tmp->data;
1447 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1448 dc = (datacontrol_x *)dc_tmp->data;
1451 sqlite3_snprintf(MAX_QUERY_LEN, query,
1452 "INSERT INTO package_app_data_control(app_id, providerid, access, type) " \
1453 "VALUES(%Q, %Q, %Q, %Q)",\
1459 ret = __exec_query(query);
1461 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1464 memset(query, '\0', MAX_QUERY_LEN);
1470 static int __insert_application_share_request_info(manifest_x *mfx)
1479 char query[MAX_QUERY_LEN] = {'\0'};
1480 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1481 app = (application_x *)app_tmp->data;
1484 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1485 ds = (datashare_x *)ds_tmp->data;
1488 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1489 rq = (const char *)rq_tmp->data;
1492 sqlite3_snprintf(MAX_QUERY_LEN, query,
1493 "INSERT INTO package_app_share_request(app_id, data_share_request) " \
1496 ret = __exec_query(query);
1498 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1501 memset(query, '\0', MAX_QUERY_LEN);
1508 static int __insert_application_share_allowed_info(manifest_x *mfx)
1519 char query[MAX_QUERY_LEN] = {'\0'};
1520 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1521 app = (application_x *)app_tmp->data;
1524 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1525 ds = (datashare_x *)ds_tmp->data;
1528 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1529 df = (define_x *)df_tmp->data;
1532 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1533 al = (const char *)al_tmp->data;
1536 sqlite3_snprintf(MAX_QUERY_LEN, query,
1537 "INSERT INTO package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1538 "VALUES(%Q, %Q, %Q)",\
1539 app->appid, df->path, al);
1540 ret = __exec_query(query);
1542 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1545 memset(query, '\0', MAX_QUERY_LEN);
1553 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1555 splashscreen_x *ss = (splashscreen_x *)a;
1556 const char *orientation = (const char *)b;
1559 if (ss->operation || ss->dpi == NULL)
1562 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1566 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1572 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1574 splashscreen_x *ss = (splashscreen_x *)a;
1575 const char *orientation = (const char *)b;
1577 if (ss->operation || ss->dpi)
1580 if (strcasecmp(ss->orientation, orientation) == 0)
1586 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1587 const char *orientation)
1591 tmp = g_list_find_custom(splashscreens, orientation,
1592 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1594 return (splashscreen_x *)tmp->data;
1596 tmp = g_list_find_custom(splashscreens, orientation,
1597 (GCompareFunc)__compare_splashscreen_with_orientation);
1599 return (splashscreen_x *)tmp->data;
1604 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1606 splashscreen_x *ss = (splashscreen_x *)data;
1607 GList **list = (GList **)user_data;
1610 if (ss->operation == NULL || ss->dpi == NULL)
1613 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1617 if (__check_dpi(ss->dpi, dpi) != 0)
1620 *list = g_list_append(*list, ss);
1623 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1625 splashscreen_x *ss = (splashscreen_x *)data;
1626 GList **list = (GList **)user_data;
1627 splashscreen_x *ss_tmp;
1630 if (ss->operation == NULL || ss->dpi)
1633 for (tmp = *list; tmp; tmp = tmp->next) {
1634 ss_tmp = (splashscreen_x *)tmp->data;
1635 if (ss_tmp->operation
1636 && strcmp(ss_tmp->operation, ss->operation) == 0
1637 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1641 *list = g_list_append(*list, ss);
1644 static GList *__find_splashscreens(GList *splashscreens)
1649 g_list_foreach(splashscreens,
1650 __find_appcontrol_splashscreen_with_dpi, &list);
1651 g_list_foreach(splashscreens,
1652 __find_appcontrol_splashscreen, &list);
1654 ss = __find_default_splashscreen(splashscreens, "portrait");
1656 list = g_list_append(list, ss);
1657 ss = __find_default_splashscreen(splashscreens, "landscape");
1659 list = g_list_append(list, ss);
1664 static int __insert_application_splashscreen_info(manifest_x *mfx)
1672 char query[MAX_QUERY_LEN] = {'\0'};
1674 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1675 app = (application_x *)app_tmp->data;
1676 if (app == NULL || app->splashscreens == NULL)
1679 ss_tmp = __find_splashscreens(app->splashscreens);
1683 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1684 ss = (splashscreen_x *)tmp->data;
1685 sqlite3_snprintf(MAX_QUERY_LEN, query,
1686 "INSERT INTO package_app_splash_screen" \
1687 "(app_id, src, type, orientation, indicatordisplay, " \
1688 "operation, color_depth) " \
1689 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1690 app->appid, ss->src, ss->type, ss->orientation,
1691 ss->indicatordisplay, ss->operation,
1694 ret = __exec_query(query);
1696 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1699 memset(query, '\0', MAX_QUERY_LEN);
1701 g_list_free(ss_tmp);
1706 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1711 char query[MAX_QUERY_LEN] = {'\0'};
1713 const char *image_type;
1714 const char *indicatordisplay;
1715 const char *orientation;
1716 const char *operation = "launch-effect";
1717 const char *color_depth = "24"; /* default */
1719 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1720 app = (application_x *)app_tmp->data;
1722 (app->portraitimg == NULL && app->landscapeimg == NULL))
1724 image_type = "img"; /* default */
1725 if (app->effectimage_type) {
1726 tmp = strstr(app->effectimage_type, "edj");
1730 indicatordisplay = "true"; /* default */
1731 if (app->indicatordisplay)
1732 indicatordisplay = app->indicatordisplay;
1733 if (app->portraitimg) {
1734 orientation = "portrait";
1735 sqlite3_snprintf(MAX_QUERY_LEN, query,
1736 "INSERT INTO package_app_splash_screen" \
1737 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1738 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1739 app->appid, app->portraitimg, image_type,
1740 orientation, indicatordisplay, operation,
1742 ret = __exec_query(query);
1744 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1747 memset(query, '\0', MAX_QUERY_LEN);
1749 if (app->landscapeimg) {
1750 orientation = "landscape";
1751 sqlite3_snprintf(MAX_QUERY_LEN, query,
1752 "INSERT INTO package_app_splash_screen" \
1753 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1754 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1755 app->appid, app->landscapeimg, image_type,
1756 orientation, indicatordisplay, operation,
1758 ret = __exec_query(query);
1760 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1763 memset(query, '\0', MAX_QUERY_LEN);
1769 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1776 char query[MAX_QUERY_LEN] = {'\0'};
1778 char *tmpptr = NULL;
1779 const char *operation;
1780 const char *portraitimg;
1781 const char *landscapeimg;
1782 const char *indicatordisplay;
1783 const char *orientation;
1784 const char *image_type;
1785 const char *color_depth = "24"; /* default */
1787 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1788 app = (application_x *)app_tmp->data;
1792 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1793 md = (metadata_x *)md_tmp->data;
1794 if (md == NULL || md->key == NULL || md->value == NULL)
1797 if (strcasestr(md->key, "operation_effect=")) {
1798 operation = index(md->key, '=');
1799 if (operation && operation[1] != '\0')
1802 operation = "launch-effect";
1803 } else if (strcasestr(md->key, "launch_effect")) {
1804 operation = "launch-effect";
1810 landscapeimg = NULL;
1811 indicatordisplay = "true"; /* default */
1812 token = strtok_r(md->value, "|", &tmpptr);
1813 while (token != NULL) {
1814 if (strcasestr(token, "portrait-effectimage=")) {
1815 portraitimg = index(token, '=');
1816 if (portraitimg && portraitimg[1] != '\0')
1820 } else if (strcasestr(token, "landscape-effectimage=")) {
1821 landscapeimg = index(token, '=');
1822 if (landscapeimg && landscapeimg[1] != '\0')
1825 landscapeimg = NULL;
1826 } else if (strcasestr(token, "indicatordisplay=")) {
1827 indicatordisplay = index(token, '=');
1828 if (indicatordisplay && indicatordisplay[1] != '\0')
1831 indicatordisplay = "true";
1834 token = strtok_r(NULL, "|", &tmpptr);
1838 orientation = "portrait";
1840 if (strcasestr(portraitimg, "edj"))
1842 sqlite3_snprintf(MAX_QUERY_LEN, query,
1843 "INSERT INTO package_app_splash_screen" \
1844 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1845 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1846 app->appid, portraitimg, image_type,
1847 orientation, indicatordisplay, operation,
1849 ret = __exec_query(query);
1851 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1854 memset(query, '\0', MAX_QUERY_LEN);
1857 orientation = "landscape";
1859 if (strcasestr(landscapeimg, "edj"))
1861 sqlite3_snprintf(MAX_QUERY_LEN, query,
1862 "INSERT INTO package_app_splash_screen" \
1863 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1864 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1865 app->appid, landscapeimg, image_type,
1866 orientation, indicatordisplay, operation,
1868 ret = __exec_query(query);
1870 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1873 memset(query, '\0', MAX_QUERY_LEN);
1881 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1885 privilege_x *pv = NULL;
1886 char query[MAX_QUERY_LEN] = { '\0' };
1889 const char *auth_name = NULL;
1890 const char *auth_email = NULL;
1891 const char *auth_href = NULL;
1893 GList *pkglocale = NULL;
1894 GList *applocale = NULL;
1895 GList *appicon = NULL;
1896 GList *appimage = NULL;
1898 int temp_pkg_mode = 0;
1899 int temp_app_mode = 0;
1900 char pkg_mode[10] = {'\0'};
1901 application_x *up_support_mode = NULL;
1902 GList *list_up = NULL;
1904 if (mfx->author && mfx->author->data) {
1905 author = (author_x *)mfx->author->data;
1907 auth_name = author->text;
1909 auth_email = author->email;
1911 auth_href = author->href;
1914 if (mfx->support_mode)
1915 temp_pkg_mode = atoi(mfx->support_mode);
1917 list_up = mfx->application;
1918 while (list_up != NULL) {
1919 up_support_mode = (application_x *)list_up->data;
1920 if (up_support_mode->support_mode) {
1921 temp_app_mode = atoi(up_support_mode->support_mode);
1922 temp_pkg_mode |= temp_app_mode;
1924 list_up = list_up->next;
1926 sprintf(pkg_mode, "%d", temp_pkg_mode);
1928 if(mfx->support_mode)
1929 free((void *)mfx->support_mode);
1930 mfx->support_mode = strdup(pkg_mode);
1932 /*Insert in the package_info DB*/
1933 sqlite3_snprintf(MAX_QUERY_LEN, query,
1934 "INSERT INTO package_info(" \
1935 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1936 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1937 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1938 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1939 "mainapp_id, package_url, root_path, csc_path, package_support_mode, package_support_disable, package_support_mode) " \
1941 "%Q, %Q, %Q, %Q, %Q, %Q, " \
1942 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1943 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), %Q, " \
1944 "%Q, %Q, %Q, %Q, %Q, " \
1945 "%Q, %Q, %Q, %Q, %Q, LOWER(%Q), %Q)",
1946 mfx->package, mfx->type, mfx->version, mfx->api_version, mfx->tep_name, mfx->zip_mount_file,
1947 mfx->installlocation, mfx->package_size, __get_bool(mfx->removable, true), __get_bool(mfx->preload, false), __get_bool(mfx->readonly, false),
1948 __get_bool(mfx->update, false), __get_bool(mfx->appsetting, false), __get_bool(mfx->nodisplay_setting, false), __get_bool(mfx->system, false), auth_name,
1949 auth_email, auth_href, mfx->installed_time, mfx->installed_storage,
1950 mfx->storeclient_id,
1951 mfx->mainapp_id, mfx->package_url, mfx->root_path, mfx->csc_path, mfx->support_mode, __get_bool(mfx->support_disable, false), mfx->support_mode);
1953 ret = __exec_query(query);
1955 _LOGD("Package Info DB Insert Failed\n");
1959 /*Insert in the package_privilege_info DB*/
1960 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1961 pv = (privilege_x *)tmp->data;
1964 memset(query, '\0', MAX_QUERY_LEN);
1965 sqlite3_snprintf(MAX_QUERY_LEN, query,
1966 "INSERT INTO package_privilege_info(package, privilege, type) " \
1967 "VALUES(%Q, %Q, %Q)",\
1968 mfx->package, pv->value, pv->type);
1969 ret = __exec_query(query);
1971 _LOGD("Package Privilege Info DB Insert Failed\n");
1976 if (mfx->application != NULL) {
1977 ret = __insert_mainapp_info(mfx);
1982 /*Insert the package locale*/
1983 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1984 /*remove duplicated data in pkglocale*/
1985 __trimfunc(pkglocale);
1987 /*Insert the app locale, icon, image info */
1988 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1989 app = (application_x *)tmp->data;
1992 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1993 appicon = __create_icon_list(appicon, app->icon);
1994 appimage = __create_image_list(appimage, app->image);
1996 /*remove duplicated data in applocale*/
1997 __trimfunc(applocale);
1998 __trimfunc(appicon);
1999 __trimfunc(appimage);
2001 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
2003 /*native app locale info*/
2004 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2005 app = (application_x *)tmp->data;
2008 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
2009 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
2010 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
2013 g_list_free(pkglocale);
2015 g_list_free(applocale);
2017 g_list_free(appicon);
2019 g_list_free(appimage);
2022 /*Insert in the package_app_info DB*/
2023 ret = __insert_application_info(mfx);
2026 /*Insert in the package_app_app_control DB*/
2027 ret = __insert_application_appcontrol_info(mfx);
2031 /*Insert in the package_app_app_category DB*/
2032 ret = __insert_application_appcategory_info(mfx);
2036 /*Insert in the package_app_app_metadata DB*/
2037 ret = __insert_application_appmetadata_info(mfx);
2041 /*Insert in the package_app_app_permission DB*/
2042 ret = __insert_application_apppermission_info(mfx);
2046 /*Insert in the package_app_share_allowed DB*/
2047 ret = __insert_application_share_allowed_info(mfx);
2051 /*Insert in the package_app_share_request DB*/
2052 ret = __insert_application_share_request_info(mfx);
2056 /*Insert in the package_app_data_control DB*/
2057 ret = __insert_application_datacontrol_info(mfx);
2061 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2062 ret = __insert_application_legacy_splashscreen_info(mfx);
2066 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2067 ret = __insert_application_metadata_splashscreen_info(mfx);
2071 /*Insert in the package_app_splash_screen DB*/
2072 ret = __insert_application_splashscreen_info(mfx);
2080 static int __delete_appinfo_from_db(char *db_table, const char *appid)
2082 char query[MAX_QUERY_LEN] = { '\0' };
2085 sqlite3_snprintf(MAX_QUERY_LEN, query,
2086 "DELETE FROM %q where app_id=%Q", db_table, appid);
2087 ret = __exec_query(query);
2089 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
2095 static int __delete_subpkg_info_from_db(char *appid)
2099 ret = __delete_appinfo_from_db("package_app_info", appid);
2102 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
2105 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
2108 ret = __delete_appinfo_from_db("package_app_image_info", appid);
2111 ret = __delete_appinfo_from_db("package_app_app_control", appid);
2114 ret = __delete_appinfo_from_db("package_app_app_category", appid);
2117 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
2120 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
2123 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
2126 ret = __delete_appinfo_from_db("package_app_share_request", appid);
2129 ret = __delete_appinfo_from_db("package_app_data_control", appid);
2132 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
2139 static int __delete_subpkg_from_db(manifest_x *mfx)
2141 char query[MAX_QUERY_LEN] = { '\0' };
2142 char *error_message = NULL;
2144 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT app_id FROM package_app_info WHERE package=%Q", mfx->package);
2146 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
2147 _LOGE("Don't execute query = %s error message = %s\n", query,
2149 sqlite3_free(error_message);
2152 sqlite3_free(error_message);
2157 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
2159 char query[MAX_QUERY_LEN] = { '\0' };
2164 /*Delete from Package Info DB*/
2165 sqlite3_snprintf(MAX_QUERY_LEN, query,
2166 "DELETE FROM package_info WHERE package=%Q", mfx->package);
2167 ret = __exec_query(query);
2169 _LOGD("Package Info DB Delete Failed\n");
2172 memset(query, '\0', MAX_QUERY_LEN);
2174 /*Delete from Package Localized Info*/
2175 sqlite3_snprintf(MAX_QUERY_LEN, query,
2176 "DELETE FROM package_localized_info WHERE package=%Q", mfx->package);
2177 ret = __exec_query(query);
2179 _LOGD("Package Localized Info DB Delete Failed\n");
2183 /*Delete from Package Privilege Info*/
2184 sqlite3_snprintf(MAX_QUERY_LEN, query,
2185 "DELETE FROM package_privilege_info WHERE package=%Q", mfx->package);
2186 ret = __exec_query(query);
2188 _LOGD("Package Privilege Info DB Delete Failed\n");
2192 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2193 app = (application_x *)tmp->data;
2196 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2199 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2202 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2205 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2208 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2211 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2214 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2217 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2220 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2223 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2226 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2229 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2234 /* if main package has sub pkg, delete sub pkg data*/
2235 __delete_subpkg_from_db(mfx);
2240 static int __disable_app(const char *appid)
2243 char query[MAX_QUERY_LEN] = {'\0'};
2244 sqlite3_snprintf(MAX_QUERY_LEN, query,
2245 "UPDATE package_app_info SET app_disable='true' WHERE app_id=%Q",
2247 ret = __exec_query(query);
2249 _LOGD("Insert global app disable failed\n");
2254 static int __enable_app(const char *appid)
2257 char query[MAX_QUERY_LEN] = {'\0'};
2258 sqlite3_snprintf(MAX_QUERY_LEN, query,
2259 "UPDATE package_app_info SET app_disable='false' WHERE app_id=%Q",
2261 ret = __exec_query(query);
2263 _LOGD("Insert global app disable failed\n");
2268 static int __disable_pkg(const char *pkgid)
2271 char query[MAX_QUERY_LEN] = {'\0'};
2272 sqlite3_snprintf(MAX_QUERY_LEN, query,
2273 "UPDATE package_info SET package_disable='true' WHERE package=%Q",
2275 ret = __exec_query(query);
2277 _LOGD("Update pkg disable info has failed\n");
2282 static int __enable_pkg(const char *pkgid)
2285 char query[MAX_QUERY_LEN] = {'\0'};
2286 sqlite3_snprintf(MAX_QUERY_LEN, query,
2287 "UPDATE package_info SET package_disable='false' WHERE package=%Q",
2289 ret = __exec_query(query);
2291 _LOGD("Update pkg disable info has failed\n");
2296 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2299 char query[MAX_QUERY_LEN] = { '\0', };
2301 const char *val = NULL;
2306 sqlite3_snprintf(MAX_QUERY_LEN, query,
2307 "SELECT COUNT(*) FROM "
2308 "package_app_info_for_uid WHERE app_id=%Q "
2309 "AND uid=%d", appid, (int)uid);
2311 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2312 if (ret != SQLITE_OK) {
2313 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2314 return PMINFO_R_ERROR;
2317 if (sqlite3_step(stmt) != SQLITE_ROW) {
2318 LOGE("failed to step");
2319 sqlite3_finalize(stmt);
2320 return PMINFO_R_ERROR;
2323 val = (const char *)sqlite3_column_text(stmt, 0);
2325 sqlite3_finalize(stmt);
2330 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2333 char query[MAX_QUERY_LEN] = { '\0', };
2335 ret = __check_appinfo_for_uid_table(appid, uid);
2337 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2340 } else if (ret == 0) {
2341 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2342 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2343 "VALUES(%Q, %d, 'true', "
2344 "(SELECT app_splash_screen_display FROM package_app_info WHERE appid='%Q'))",
2345 appid, (int)uid, appid);
2347 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2348 "package_app_info_for_uid SET is_disabled='true' "
2349 "WHERE app_id=%Q AND uid=%d", appid, (int)uid);
2352 ret = __exec_query(query);
2354 _LOGD("Add global app disable info failed\n");
2359 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2362 char query[MAX_QUERY_LEN] = {'\0'};
2364 ret = __check_appinfo_for_uid_table(appid, uid);
2366 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2369 } else if (ret > 0) {
2370 sqlite3_snprintf(MAX_QUERY_LEN, query,
2371 "UPDATE package_app_info_for_uid SET "
2372 "is_disabled='false' WHERE app_id=%Q AND "
2373 "uid=%d", appid, (int)uid);
2376 ret = __exec_query(query);
2378 _LOGD("Remove global app disable info failed\n");
2383 static int __update_global_app_splash_screen_for_user(const char *appid,
2384 uid_t uid, int flag)
2387 char query[MAX_QUERY_LEN] = { '\0', };
2389 ret = __check_appinfo_for_uid_table(appid, uid);
2391 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2394 } else if (ret == 0) {
2395 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2396 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2397 "VALUES(%Q, %d, %Q)", appid, (int)uid,
2398 flag ? "true" : "false");
2400 sqlite3_snprintf(MAX_QUERY_LEN, query,
2401 "UPDATE package_app_info_for_uid SET "
2402 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2403 "uid=%d", flag ? "true" : "false", appid, (int)uid);
2406 ret = __exec_query(query);
2408 _LOGD("update global app splash screen info failed\n");
2413 static int __disable_app_splash_screen(const char *appid)
2416 char query[MAX_QUERY_LEN] = {'\0'};
2418 sqlite3_snprintf(MAX_QUERY_LEN, query,
2419 "UPDATE package_app_info SET app_splash_screen_display='false' WHERE app_id=%Q",
2421 ret = __exec_query(query);
2423 _LOGD("Failed to update app_palsh_screen_display");
2428 static int __enable_app_splash_screen(const char *appid)
2431 char query[MAX_QUERY_LEN] = {'\0'};
2433 sqlite3_snprintf(MAX_QUERY_LEN, query,
2434 "UPDATE package_app_info SET app_splash_screen_display='true' WHERE app_id=%Q",
2436 ret = __exec_query(query);
2438 _LOGD("Failed to update app_splash_screen_display");
2443 API int pkgmgr_parser_initialize_db(uid_t uid)
2449 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2451 _LOGD("package info DB initialization failed\n");
2454 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2456 _LOGD("package localized info DB initialization failed\n");
2459 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2461 _LOGD("package app app privilege DB initialization failed\n");
2464 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2466 _LOGD("package app info DB initialization failed\n");
2469 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2471 _LOGD("package app localized info DB initialization failed\n");
2474 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2476 _LOGD("package app icon localized info DB initialization failed\n");
2479 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2481 _LOGD("package app image info DB initialization failed\n");
2484 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2486 _LOGD("package app app control DB initialization failed\n");
2489 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2491 _LOGD("package app app category DB initialization failed\n");
2494 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2496 _LOGD("package app app category DB initialization failed\n");
2499 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2501 _LOGD("package app app permission DB initialization failed\n");
2504 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2506 _LOGD("package app share allowed DB initialization failed\n");
2509 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2511 _LOGD("package app share request DB initialization failed\n");
2514 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2516 _LOGD("package app data control DB initialization failed\n");
2520 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2522 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2526 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2528 _LOGD("package app splash screen DB initialization failed\n");
2532 /* Trigger package_app_info_for_uid */
2533 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2535 _LOGD("package app info for uid DB initialization failed\n");
2540 /* TODO: refactor this code */
2541 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2543 _LOGD("package cert info DB initialization failed\n");
2546 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2548 _LOGD("package cert index info DB initialization failed\n");
2551 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO);
2553 _LOGD("package cert info DB initialization failed\n");
2556 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2);
2558 _LOGD("package cert info DB initialization failed\n");
2561 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2563 _LOGD("package cert info DB initialization failed\n");
2566 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2568 _LOGD("package cert index info DB initialization failed\n");
2572 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2573 if (db_path == NULL) {
2574 _LOGD("Failed to get user cert db path - GLOBAL_USER");
2576 ret = __parserdb_change_perm(db_path, GLOBAL_USER);
2578 _LOGD("Failed to change cert db permission");
2582 db_path = getUserPkgParserDBPathUID(uid);
2583 if (db_path == NULL) {
2584 _LOGD("Failed to get user pkg parser db path - %d", uid);
2586 ret = __parserdb_change_perm(db_path, uid);
2588 _LOGD("Failed to change parser db permission\n");
2595 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2598 char pwuid_buf[1024];
2599 char journal_file[BUFSIZE];
2604 struct passwd userinfo, *result = NULL;
2605 files[0] = (char *)db_file;
2606 files[1] = journal_file;
2610 if (db_file == NULL)
2613 if (getuid() != OWNER_ROOT) /* At this time we should be root to apply this */
2615 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2616 if (uid == OWNER_ROOT)
2618 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2619 if (ret != 0 || result == NULL) {
2620 _LOGE("FAIL: user %d doesn't exist", uid);
2623 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2625 for (i = 0; files[i]; i++) {
2626 fd = open(files[i], O_RDONLY);
2628 if (strerror_r(errno, buf, sizeof(buf)))
2629 strncpy(buf, "", BUFSIZE - 1);
2630 _LOGD("FAIL : open %s : %s", files[i], buf);
2633 ret = fstat(fd, &sb);
2635 if (strerror_r(errno, buf, sizeof(buf)))
2636 strncpy(buf, "", BUFSIZE - 1);
2637 _LOGD("FAIL : fstat %s : %s", files[i], buf);
2641 if (S_ISLNK(sb.st_mode)) {
2642 _LOGE("FAIL : %s is symlink!", files[i]);
2646 ret = fchown(fd, uid, userinfo.pw_gid);
2648 if (strerror_r(errno, buf, sizeof(buf)))
2649 strncpy(buf, "", BUFSIZE - 1);
2650 _LOGD("FAIL : fchown %s %d.%d : %s", files[i], uid,
2651 userinfo.pw_gid, buf);
2656 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2657 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2659 ret = fchmod(fd, mode);
2661 if (strerror_r(errno, buf, sizeof(buf)))
2662 strncpy(buf, "", BUFSIZE - 1);
2663 _LOGD("FAIL : fchmod %s 0664 : %s", files[i], buf);
2668 SET_SMACK_LABEL(files[i]);
2673 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2678 if (getuid() != OWNER_ROOT) {
2679 _LOGE("Only root user is allowed");
2683 db_path = getUserPkgParserDBPathUID(uid);
2684 if (db_path == NULL) {
2685 _LOGE("Failed to get pkg parser db path - %d", uid);
2689 if (access(db_path, F_OK) != -1) {
2690 _LOGE("Manifest db for user %d is already exists", uid);
2696 db_path = getUserPkgCertDBPathUID(uid);
2697 if (db_path == NULL) {
2698 _LOGE("Failed to get pkg cert db path - %d", uid);
2702 if (access(db_path, F_OK) != -1) {
2703 _LOGE("Cert db for user %d is already exists", uid);
2709 ret = pkgmgr_parser_check_and_create_db(uid);
2712 ret = pkgmgr_parser_initialize_db(uid);
2714 pkgmgr_parser_close_db();
2717 pkgmgr_parser_close_db();
2722 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2727 db_path = getUserPkgParserDBPathUID(uid);
2728 if (db_path == NULL) {
2729 _LOGD("Failed to get pkg parser db path - %d", uid);
2734 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, db_path);
2736 _LOGD("Manifest DB creation Failed\n");
2742 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2743 if (db_path == NULL) {
2744 _LOGE("Failed to get pkg cert db path - GLOBAL_USER");
2749 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, db_path);
2751 _LOGD("Cert DB creation Failed\n");
2761 void pkgmgr_parser_close_db(void)
2763 sqlite3_close(pkgmgr_parser_db);
2764 sqlite3_close(pkgmgr_cert_db);
2768 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2770 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2772 _LOGD("manifest pointer is NULL\n");
2776 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2778 _LOGD("Failed to open DB\n");
2781 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2784 /*Begin transaction*/
2785 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2786 if (ret != SQLITE_OK) {
2787 _LOGD("Failed to begin transaction\n");
2791 _LOGD("Transaction Begin\n");
2792 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2794 _LOGD("Insert into DB failed. Rollback now\n");
2795 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2798 /*Commit transaction*/
2799 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2800 if (ret != SQLITE_OK) {
2801 _LOGD("Failed to commit transaction. Rollback now\n");
2802 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2806 _LOGD("Transaction Commit and End\n");
2808 pkgmgr_parser_close_db();
2812 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2814 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2816 _LOGD("manifest pointer is NULL\n");
2820 ret = pkgmgr_parser_check_and_create_db(uid);
2822 _LOGD("Failed to open DB\n");
2825 ret = pkgmgr_parser_initialize_db(uid);
2828 /*Begin transaction*/
2829 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2830 if (ret != SQLITE_OK) {
2831 _LOGD("Failed to begin transaction\n");
2835 _LOGD("Transaction Begin\n");
2836 ret = __insert_manifest_info_in_db(mfx, uid);
2838 _LOGD("Insert into DB failed. Rollback now\n");
2839 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2842 /*Commit transaction*/
2843 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2844 if (ret != SQLITE_OK) {
2845 _LOGD("Failed to commit transaction. Rollback now\n");
2846 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2850 _LOGD("Transaction Commit and End\n");
2852 pkgmgr_parser_close_db();
2856 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2858 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, _getuid());
2861 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2863 if (pkgid == NULL || tep_path == NULL) {
2864 _LOGE("invalid parameter");
2871 ret = pkgmgr_parser_check_and_create_db(uid);
2873 _LOGD("Failed to open DB\n");
2876 ret = pkgmgr_parser_initialize_db(uid);
2880 /*Begin transaction*/
2881 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2882 if (ret != SQLITE_OK) {
2883 _LOGD("Failed to begin transaction\n");
2887 _LOGD("Transaction Begin\n");
2890 /* Updating TEP info in "package_info" table */
2891 query = sqlite3_mprintf("UPDATE package_info "\
2892 "SET package_tep_name = %Q "\
2893 "WHERE package = %Q", tep_path, pkgid);
2895 ret = __exec_query(query);
2896 sqlite3_free(query);
2897 if (ret != SQLITE_OK) {
2898 ret = PM_PARSER_R_ERROR;
2899 _LOGE("sqlite exec failed to insert entries into package_info!!");
2903 /* Updating TEP info in "package_app_info" table */
2904 query = sqlite3_mprintf("UPDATE package_app_info "\
2905 "SET app_tep_name = %Q "\
2906 "WHERE package = %Q", tep_path, pkgid);
2908 ret = __exec_query(query);
2909 sqlite3_free(query);
2910 if (ret != SQLITE_OK) {
2911 ret = PM_PARSER_R_ERROR;
2912 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2916 /*Commit transaction*/
2917 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2918 if (ret != SQLITE_OK) {
2919 _LOGE("Failed to commit transaction, Rollback now\n");
2920 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2921 if (ret != SQLITE_OK)
2922 _LOGE("Failed to Rollback\n");
2924 ret = PM_PARSER_R_ERROR;
2927 _LOGD("Transaction Commit and End\n");
2928 ret = PM_PARSER_R_OK;
2931 pkgmgr_parser_close_db();
2936 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2939 _LOGD("manifest pointer is NULL\n");
2943 ret = pkgmgr_parser_check_and_create_db(uid);
2945 _LOGD("Failed to open DB\n");
2948 ret = pkgmgr_parser_initialize_db(uid);
2951 /*Preserve guest mode visibility*/
2952 __preserve_guestmode_visibility_value(mfx);
2953 /*Begin transaction*/
2954 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2955 if (ret != SQLITE_OK) {
2956 _LOGD("Failed to begin transaction\n");
2960 _LOGD("Transaction Begin\n");
2961 ret = __delete_manifest_info_from_db(mfx, uid);
2963 _LOGD("Delete from DB failed. Rollback now\n");
2964 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2967 ret = __insert_manifest_info_in_db(mfx, uid);
2969 _LOGD("Insert into DB failed. Rollback now\n");
2970 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2974 /*Commit transaction*/
2975 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2976 if (ret != SQLITE_OK) {
2977 _LOGD("Failed to commit transaction. Rollback now\n");
2978 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2982 _LOGD("Transaction Commit and End\n");
2984 pkgmgr_parser_close_db();
2988 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2990 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2993 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2996 _LOGD("manifest pointer is NULL\n");
3000 ret = pkgmgr_parser_check_and_create_db(uid);
3002 _LOGD("Failed to open DB\n");
3005 /*Begin transaction*/
3006 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3007 if (ret != SQLITE_OK) {
3008 _LOGD("Failed to begin transaction\n");
3012 _LOGD("Transaction Begin\n");
3013 ret = __delete_manifest_info_from_db(mfx, uid);
3015 _LOGD("Delete from DB failed. Rollback now\n");
3016 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3019 /*Commit transaction*/
3020 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3021 if (ret != SQLITE_OK) {
3022 _LOGD("Failed to commit transaction, Rollback now\n");
3023 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3027 _LOGD("Transaction Commit and End\n");
3029 pkgmgr_parser_close_db();
3033 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
3035 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
3038 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
3042 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3044 _LOGD("Failed to open DB\n");
3048 /*Begin transaction*/
3049 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3050 if (ret != SQLITE_OK) {
3051 _LOGD("Failed to begin transaction\n");
3055 _LOGD("Transaction Begin\n");
3057 ret = __disable_global_app_for_user(appid, uid);
3059 ret = __enable_global_app_for_user(appid, uid);
3061 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
3062 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3065 /*Commit transaction*/
3066 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3067 if (ret != SQLITE_OK) {
3068 _LOGD("Failed to commit transaction, Rollback now\n");
3069 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3073 _LOGD("Transaction Commit and End\n");
3075 pkgmgr_parser_close_db();
3080 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
3082 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
3085 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid, uid_t uid, int is_disable)
3089 ret = pkgmgr_parser_check_and_create_db(uid);
3091 _LOGD("Failed to open DB\n");
3095 /*Begin transaction*/
3096 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3097 if (ret != SQLITE_OK) {
3098 _LOGD("Failed to begin transaction\n");
3103 _LOGD("Transaction Begin\n");
3105 ret = __disable_pkg(pkgid);
3107 ret = __enable_pkg(pkgid);
3110 _LOGD("__update_pkg_disable_condition_in_db failed. Rollback now\n");
3111 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3115 /*Commit transaction*/
3116 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3117 if (ret != SQLITE_OK) {
3118 _LOGD("Failed to commit transaction, Rollback now\n");
3119 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3123 _LOGD("Transaction Commit and End\n");
3126 pkgmgr_parser_close_db();
3130 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid, int is_disable)
3132 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid, _getuid(), is_disable);
3135 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
3139 ret = pkgmgr_parser_check_and_create_db(uid);
3141 _LOGD("Failed to open DB\n");
3145 /*Begin transaction*/
3146 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3147 if (ret != SQLITE_OK) {
3148 _LOGD("Failed to begin transaction\n");
3152 _LOGD("Transaction Begin\n");
3154 ret = __disable_app(appid);
3156 ret = __enable_app(appid);
3158 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
3159 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3162 /*Commit transaction*/
3163 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3164 if (ret != SQLITE_OK) {
3165 _LOGD("Failed to commit transaction, Rollback now\n");
3166 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3170 _LOGD("Transaction Commit and End\n");
3172 pkgmgr_parser_close_db();
3177 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3181 if (appid == NULL) {
3182 _LOGD("Invalid parameter");
3186 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3188 _LOGD("Failed to open DB\n");
3192 /* Begin transaction */
3193 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3194 if (ret != SQLITE_OK) {
3195 _LOGD("Failed to begin transaction\n");
3199 _LOGD("Transaction Begin\n");
3201 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3203 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3204 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3207 /* Commit transaction */
3208 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3209 if (ret != SQLITE_OK) {
3210 _LOGD("Failed to commit transaction, Rollback now\n");
3211 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3215 _LOGD("Transaction Commit and End\n");
3217 pkgmgr_parser_close_db();
3221 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3223 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3226 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3230 if (appid == NULL) {
3231 _LOGD("Invalid parameter");
3235 ret = pkgmgr_parser_check_and_create_db(uid);
3237 _LOGD("Failed to open DB");
3241 /* Begin transaction */
3242 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3243 if (ret != SQLITE_OK) {
3244 _LOGD("Failed to begin transaction");
3248 _LOGD("Transaction Begin");
3251 ret = __enable_app_splash_screen(appid);
3253 ret = __disable_app_splash_screen(appid);
3255 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3256 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3259 /* Commit transaction */
3260 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3261 if (ret != SQLITE_OK) {
3262 _LOGD("Failed to commit transaction, Rollback now");
3263 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3267 _LOGD("Transaction Commit and End");
3270 pkgmgr_parser_close_db();
3274 API int pkgmgr_parser_update_app_label_info_in_usr_db(const char *appid, uid_t uid, const char *label)
3277 char query[MAX_QUERY_LEN] = {'\0'};
3279 if (appid == NULL || label == NULL) {
3280 _LOGE("Invalid parameter");
3284 ret = pkgmgr_parser_check_and_create_db(uid);
3286 _LOGD("Failed to open DB");
3290 /*Begin transaction*/
3291 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3292 if (ret != SQLITE_OK) {
3293 _LOGD("Failed to begin transaction\n");
3298 sqlite3_snprintf(MAX_QUERY_LEN, query,
3299 "UPDATE package_app_localized_info SET app_label=%Q WHERE " \
3300 "app_id=%Q AND app_label IS NOT NULL",
3302 ret = __exec_query(query);
3304 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3308 /* Commit transaction */
3309 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3310 if (ret != SQLITE_OK) {
3311 _LOGD("Failed to commit transaction, Rollback now");
3312 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3316 _LOGD("Transaction Commit and End");
3319 pkgmgr_parser_close_db();
3323 API int pkgmgr_parser_update_app_label_info_in_db(const char *appid, const char *label)
3325 return pkgmgr_parser_update_app_label_info_in_usr_db(appid, _getuid(), label);