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
53 #define MAX_INTEGER_LENGTH 10
59 #define XXHDPI "xxhdpi"
69 #define XXHDPI_MIN 481
70 #define XXHDPI_MAX 600
72 #define DB_LABEL "User::Home"
73 #define SET_SMACK_LABEL(x) \
75 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
76 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
78 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
81 sqlite3 *pkgmgr_parser_db;
82 sqlite3 *pkgmgr_cert_db;
85 #define QUERY_CREATE_TABLE_PACKAGE_INFO "CREATE TABLE IF NOT EXISTS package_info " \
86 "(package TEXT PRIMARY KEY NOT NULL, " \
87 "package_type TEXT DEFAULT 'tpk', " \
88 "package_version TEXT, " \
89 "package_api_version TEXT, " \
90 "package_tep_name TEXT, " \
91 "package_zip_mount_file TEXT, " \
92 "install_location TEXT NOT NULL , " \
93 "package_size TEXT, " \
94 "package_removable TEXT NOT NULL DEFAULT 'true', " \
95 "package_preload TEXT NOT NULL DEFAULT 'false', " \
96 "package_readonly TEXT NOT NULL DEFAULT 'false', " \
97 "package_update TEXT NOT NULL DEFAULT 'false', " \
98 "package_appsetting TEXT NOT NULL DEFAULT 'false', " \
99 "package_nodisplay TEXT NOT NULL DEFAULT 'false', " \
100 "package_system TEXT NOT NULL DEFAULT 'false', " \
101 "author_name TEXT, " \
102 "author_email TEXT, " \
103 "author_href TEXT," \
104 "installed_time TEXT, " \
105 "installed_storage TEXT, " \
106 "storeclient_id TEXT, " \
107 "mainapp_id TEXT, " \
108 "package_url TEXT, " \
110 "external_path TEXT, " \
112 "package_support_mode TEXT, " \
113 "package_support_disable TEXT NOT NULL DEFAULT 'false', " \
114 "package_disable TEXT NOT NULL DEFAULT 'false')"
116 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_localized_info " \
117 "(package TEXT NOT NULL, " \
118 "package_locale TEXT NOT NULL DEFAULT 'No Locale', " \
119 "package_label TEXT, " \
120 "package_icon TEXT, " \
121 "package_description TEXT, " \
122 "package_license TEXT, " \
123 "package_author TEXT, " \
124 "PRIMARY KEY(package, package_locale), " \
125 "FOREIGN KEY(package) " \
126 "REFERENCES package_info(package) " \
129 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "CREATE TABLE IF NOT EXISTS package_privilege_info " \
130 "(package TEXT NOT NULL, " \
131 "privilege TEXT NOT NULL, " \
132 "type TEXT NOT NULL, " \
133 "PRIMARY KEY(package, privilege, type) " \
134 "FOREIGN KEY(package) " \
135 "REFERENCES package_info(package) " \
138 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "CREATE TABLE IF NOT EXISTS package_app_info " \
139 "(app_id TEXT PRIMARY KEY NOT NULL, " \
140 "app_component TEXT NOT NULL, " \
142 "app_nodisplay TEXT NOT NULL DEFAULT 'false', " \
144 "app_onboot TEXT NOT NULL DEFAULT 'false', " \
145 "app_multiple TEXT NOT NULL DEFAULT 'false', " \
146 "app_autorestart TEXT NOT NULL DEFAULT 'false', " \
147 "app_taskmanage TEXT NOT NULL DEFAULT 'false', " \
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 "app_support_ambient TEXT NOT NULL DEFAULT 'false', " \
173 "component_type TEXT, " \
174 "package TEXT NOT NULL, " \
175 "app_tep_name TEXT, " \
176 "app_zip_mount_file TEXT, " \
177 "app_background_category INTEGER DEFAULT 0, " \
178 "app_root_path TEXT, " \
179 "app_api_version TEXT, " \
180 "app_effective_appid TEXT, " \
181 "app_splash_screen_display TEXT NOT NULL DEFAULT 'true', " \
182 "app_external_path TEXT, " \
183 "FOREIGN KEY(package) " \
184 "REFERENCES package_info(package) " \
187 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_app_localized_info " \
188 "(app_id TEXT NOT NULL, " \
189 "app_locale TEXT NOT NULL DEFAULT 'No Locale', " \
192 "PRIMARY KEY(app_id,app_locale) " \
193 "FOREIGN KEY(app_id) " \
194 "REFERENCES package_app_info(app_id) " \
197 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "CREATE TABLE IF NOT EXISTS package_app_icon_section_info " \
198 "(app_id TEXT NOT NULL, " \
200 "app_icon_section TEXT NOT NULL, " \
201 "app_icon_resolution TEXT NOT NULL, " \
202 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
203 "FOREIGN KEY(app_id) " \
204 "REFERENCES package_app_info(app_id) " \
207 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "CREATE TABLE IF NOT EXISTS package_app_image_info " \
208 "(app_id TEXT NOT NULL, " \
209 "app_locale TEXT DEFAULT 'No Locale', " \
210 "app_image_section TEXT NOT NULL, " \
212 "PRIMARY KEY(app_id,app_image_section) " \
213 "FOREIGN KEY(app_id) " \
214 "REFERENCES package_app_info(app_id) " \
217 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "CREATE TABLE IF NOT EXISTS package_app_app_control " \
218 "(app_id TEXT NOT NULL, " \
219 "app_control TEXT NOT NULL, " \
220 "PRIMARY KEY(app_id,app_control) " \
221 "FOREIGN KEY(app_id) " \
222 "REFERENCES package_app_info(app_id) " \
225 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "CREATE TABLE IF NOT EXISTS package_app_app_category " \
226 "(app_id TEXT NOT NULL, " \
227 "category TEXT NOT NULL, " \
228 "PRIMARY KEY(app_id,category) " \
229 "FOREIGN KEY(app_id) " \
230 "REFERENCES package_app_info(app_id) " \
233 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "CREATE TABLE IF NOT EXISTS package_app_app_metadata " \
234 "(app_id TEXT NOT NULL, " \
235 "md_key TEXT NOT NULL, " \
237 "PRIMARY KEY(app_id, md_key, md_value) " \
238 "FOREIGN KEY(app_id) " \
239 "REFERENCES package_app_info(app_id) " \
242 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "CREATE TABLE IF NOT EXISTS package_app_app_permission " \
243 "(app_id TEXT NOT NULL, " \
244 "pm_type TEXT NOT NULL, " \
245 "pm_value TEXT NOT NULL, " \
246 "PRIMARY KEY(app_id, pm_type, pm_value) " \
247 "FOREIGN KEY(app_id) " \
248 "REFERENCES package_app_info(app_id) " \
251 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "CREATE TABLE IF NOT EXISTS package_app_share_allowed " \
252 "(app_id TEXT NOT NULL, " \
253 "data_share_path TEXT NOT NULL, " \
254 "data_share_allowed TEXT NOT NULL, " \
255 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
256 "FOREIGN KEY(app_id) " \
257 "REFERENCES package_app_info(app_id) " \
260 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "CREATE TABLE IF NOT EXISTS package_app_share_request " \
261 "(app_id TEXT NOT NULL, " \
262 "data_share_request TEXT NOT NULL, " \
263 "PRIMARY KEY(app_id,data_share_request) " \
264 "FOREIGN KEY(app_id) " \
265 "REFERENCES package_app_info(app_id) " \
268 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "CREATE TABLE IF NOT EXISTS package_app_data_control " \
269 "(app_id TEXT NOT NULL, " \
270 "providerid TEXT NOT NULL, " \
271 "access TEXT NOT NULL, " \
272 "type TEXT NOT NULL, " \
273 "PRIMARY KEY(app_id, providerid, access, type) " \
274 "FOREIGN KEY(app_id) " \
275 "REFERENCES package_app_info(app_id) " \
278 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
279 "(app_id TEXT NOT NULL, " \
280 "uid INTEGER NOT NULL, " \
281 "is_disabled TEXT NOT NULL DEFAULT 'false', " \
282 "is_splash_screen_enabled TEXT NOT NULL, " \
283 "PRIMARY KEY(app_id, uid))"
285 #define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
286 "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
287 "AFTER UPDATE ON package_app_info_for_uid " \
289 " DELETE FROM package_app_info_for_uid WHERE " \
290 " is_splash_screen_enabled=" \
291 " (SELECT package_app_info.app_splash_screen_display FROM " \
292 " package_app_info, package_app_info_for_uid WHERE " \
293 " package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
296 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
297 "CREATE TABLE IF NOT EXISTS package_app_splash_screen " \
298 "(app_id TEXT NOT NULL, " \
299 "src TEXT NOT NULL, " \
300 "type TEXT NOT NULL, " \
301 "orientation TEXT NOT NULL, " \
302 "indicatordisplay TEXT, " \
303 "operation TEXT NOT NULL, " \
304 "color_depth TEXT NOT NULL DEFAULT '24', " \
305 "PRIMARY KEY(app_id, orientation, operation) " \
306 "FOREIGN KEY(app_id) " \
307 "REFERENCES package_app_info(app_id) " \
311 /* FIXME: duplicated at pkgmgrinfo_db.c */
312 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
313 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
314 " cert_info TEXT UNIQUE, " \
315 " cert_id INTEGER PRIMARY KEY, " \
316 " cert_ref_count INTEGER NOT NULL)"
318 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
319 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
320 " package TEXT PRIMARY KEY, " \
321 " package_count INTEGER, " \
322 " author_root_cert INTEGER, " \
323 " author_im_cert INTEGER, " \
324 " author_signer_cert INTEGER, " \
325 " dist_root_cert INTEGER, " \
326 " dist_im_cert INTEGER, " \
327 " dist_signer_cert INTEGER, " \
328 " dist2_root_cert INTEGER, " \
329 " dist2_im_cert INTEGER, " \
330 " dist2_signer_cert INTEGER)"
332 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO \
333 "CREATE TRIGGER IF NOT EXISTS update_cert_info " \
334 "AFTER UPDATE ON package_cert_info " \
335 "WHEN (NEW.package_count = 0) " \
337 " DELETE FROM package_cert_info WHERE package=OLD.package;" \
340 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2 \
341 "CREATE TRIGGER IF NOT EXISTS update_cert_info2 " \
342 "AFTER UPDATE ON package_cert_info " \
343 "WHEN (NEW.package_count = OLD.package_count + 1) " \
345 " UPDATE package_cert_index_info SET" \
346 " cert_ref_count = cert_ref_count - 1" \
347 " WHERE cert_id = OLD.author_root_cert" \
348 " OR cert_id = OLD.author_im_cert" \
349 " OR cert_id = OLD.author_signer_cert" \
350 " OR cert_id = OLD.dist_root_cert" \
351 " OR cert_id = OLD.dist_im_cert" \
352 " OR cert_id = OLD.dist_signer_cert" \
353 " OR cert_id = OLD.dist2_root_cert" \
354 " OR cert_id = OLD.dist2_im_cert" \
355 " OR cert_id = OLD.dist2_signer_cert;" \
358 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
359 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
360 "AFTER DELETE ON package_cert_info " \
362 " UPDATE package_cert_index_info SET" \
363 " cert_ref_count = cert_ref_count - 1" \
364 " WHERE cert_id = OLD.author_root_cert" \
365 " OR cert_id = OLD.author_im_cert" \
366 " OR cert_id = OLD.author_signer_cert" \
367 " OR cert_id = OLD.dist_root_cert" \
368 " OR cert_id = OLD.dist_im_cert" \
369 " OR cert_id = OLD.dist_signer_cert" \
370 " OR cert_id = OLD.dist2_root_cert" \
371 " OR cert_id = OLD.dist2_im_cert" \
372 " OR cert_id = OLD.dist2_signer_cert;" \
375 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
376 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
377 "AFTER UPDATE ON package_cert_index_info " \
378 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
379 " WHERE cert_id = OLD.cert_id) = 0) "\
381 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
384 static int __insert_application_info(manifest_x *mfx);
385 static int __insert_application_appcategory_info(manifest_x *mfx);
386 static int __insert_application_appcontrol_info(manifest_x *mfx);
387 static int __insert_application_appmetadata_info(manifest_x *mfx);
388 static int __insert_application_share_allowed_info(manifest_x *mfx);
389 static int __insert_application_share_request_info(manifest_x *mfx);
390 static int __insert_application_datacontrol_info(manifest_x *mfx);
391 static void __insert_application_locale_info(gpointer data, gpointer userdata);
392 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
393 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
394 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
395 static int __delete_subpkg_info_from_db(char *appid);
396 static int __delete_appinfo_from_db(char *db_table, const char *appid);
397 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
398 static int __exec_query(char *query);
399 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
400 char **label, char **license, char **icon, char **description, char **author);
401 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
402 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
403 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
404 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
405 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
406 static int __parserdb_change_perm(const char *db_file, uid_t uid);
408 #define REGULAR_USER 5000
409 static inline uid_t _getuid(void)
411 uid_t uid = getuid();
413 if (uid < REGULAR_USER)
414 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
419 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
422 __delete_subpkg_info_from_db(coltxt[0]);
427 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
432 char *error_message = NULL;
434 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
435 if (ret != SQLITE_OK) {
436 _LOGD("connect db [%s] failed!\n", db_path);
441 /* add user_version for db upgrade*/
442 query = sqlite3_mprintf("PRAGMA user_version=%d", (atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 + atoi(TIZEN_PATCH_VER)));
444 sqlite3_exec(handle, query, NULL, NULL, &error_message)) {
445 _LOGE("Don't execute query = %s error message = %s\n", query,
448 sqlite3_free(error_message);
454 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
456 manifest_x *mfx = (manifest_x *)data;
462 if (mfx->application == NULL)
464 app = (application_x *)mfx->application->data;
465 for (i = 0; i < ncols; i++) {
466 if (strcmp(colname[i], "app_id") == 0) {
468 appid = strdup(coltxt[i]);
469 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
471 status = strdup(coltxt[i]);
477 _LOGD("app id is NULL\n");
480 /*update guest mode visibility*/
481 for (tmp = mfx->application; tmp; tmp = tmp->next) {
482 app = (application_x *)tmp->data;
485 if (strcmp(app->appid, appid) == 0) {
486 free((void *)app->guestmode_visibility);
487 app->guestmode_visibility = strdup(status);
503 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
505 char *error_message = NULL;
506 char query[MAX_QUERY_LEN] = {'\0'};
507 sqlite3_snprintf(MAX_QUERY_LEN, query,
508 "SELECT app_id, app_guestmodevisibility FROM package_app_info " \
509 "WHERE package=%Q", mfx->package);
511 sqlite3_exec(pkgmgr_parser_db, query,
512 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
513 _LOGD("Don't execute query = %s error message = %s\n",
514 query, error_message);
515 sqlite3_free(error_message);
520 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
522 char *error_message = NULL;
524 sqlite3_exec(db_handle, db_query,
525 NULL, NULL, &error_message)) {
526 _LOGD("Don't execute query = %s error message = %s\n",
527 db_query, error_message);
528 sqlite3_free(error_message);
531 sqlite3_free(error_message);
535 static int __exec_query(char *query)
537 char *error_message = NULL;
539 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
540 _LOGE("Don't execute query = %s error message = %s\n", query,
542 sqlite3_free(error_message);
545 sqlite3_free(error_message);
549 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
557 for (tmp = lbls; tmp; tmp = tmp->next) {
558 lbl = (label_x *)tmp->data;
562 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
564 for (tmp = lcns; tmp; tmp = tmp->next) {
565 lcn = (license_x *)tmp->data;
569 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
571 for (tmp = icns; tmp; tmp = tmp->next) {
572 icn = (icon_x *)tmp->data;
576 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
578 for (tmp = dcns; tmp; tmp = tmp->next) {
579 dcn = (description_x *)tmp->data;
583 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
585 for (tmp = aths; tmp; tmp = tmp->next) {
586 ath = (author_x *)tmp->data;
590 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
596 static GList *__create_icon_list(GList *appicon, GList *icns)
601 for (tmp = icns; tmp; tmp = tmp->next) {
602 icn = (icon_x *)tmp->data;
606 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
611 static GList *__create_image_list(GList *appimage, GList *imgs)
616 for (tmp = imgs; tmp; tmp = tmp->next) {
617 img = (image_x *)tmp->data;
621 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
626 static void __trimfunc(GList *trim_list)
628 char *trim_data = NULL;
632 list = g_list_first(trim_list);
635 trim_data = (char *)list->data;
638 if (strcmp(trim_data, prev) == 0) {
639 trim_list = g_list_remove(trim_list, trim_data);
640 list = g_list_first(trim_list);
649 list = g_list_next(list);
653 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
655 if (a == NULL || b == NULL)
657 if (strcmp((char *)a, (char *)b) == 0)
659 if (strcmp((char *)a, (char *)b) < 0)
661 if (strcmp((char *)a, (char *)b) > 0)
666 static int __check_dpi(const char *dpi_char, int dpi_int)
668 if (dpi_char == NULL)
671 if (strcasecmp(dpi_char, LDPI) == 0) {
672 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
676 } else if (strcasecmp(dpi_char, MDPI) == 0) {
677 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
681 } else if (strcasecmp(dpi_char, HDPI) == 0) {
682 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
686 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
687 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
691 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
692 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
700 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
703 char *icon_filename = NULL;
704 char modified_iconpath[BUFSIZE] = { '\0' };
705 char icon_path[BUFSIZE] = { '\0' };
709 if (orig_icon_path == NULL)
712 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
716 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
717 dpi_path[0] = "LDPI";
718 dpi_path[1] = "ldpi";
719 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
720 dpi_path[0] = "MDPI";
721 dpi_path[1] = "mdpi";
722 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
723 dpi_path[0] = "HDPI";
724 dpi_path[1] = "hdpi";
725 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
726 dpi_path[0] = "XHDPI";
727 dpi_path[1] = "xhdpi";
728 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
729 dpi_path[0] = "XXHDPI";
730 dpi_path[1] = "xxhdpi";
732 _LOGE("Unidentified dpi[%d]", dpi);
736 icon_filename = strrchr(orig_icon_path, '/');
737 if (icon_filename == NULL)
740 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
741 for (i = 0; i < 2; i++) {
742 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
743 if (access(modified_iconpath, F_OK) != -1) {
744 /* if exists, return modified icon path */
745 *new_icon_path = strdup(modified_iconpath);
753 static gint __compare_icon(gconstpointer a, gconstpointer b)
755 icon_x *icon = (icon_x *)a;
757 char *icon_folder_path = NULL;
759 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
762 if (icon->dpi != NULL)
765 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
767 icon->text = icon_folder_path;
773 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
775 icon_x *icon = (icon_x *)a;
776 int dpi = GPOINTER_TO_INT(b);
778 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
781 if (icon->dpi == NULL)
784 if (__check_dpi(icon->dpi, dpi) == 0)
790 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
792 icon_x *icon = (icon_x *)a;
793 char *lang = (char *)b;
794 char *icon_folder_path = NULL;
796 if (icon->dpi != NULL)
799 if (strcasecmp(icon->lang, lang) == 0) {
800 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
801 /* icon for no locale. check existance of folder-hierachied default icons */
802 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
804 icon->text = icon_folder_path;
813 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
815 icon_x *icon = (icon_x *)a;
816 char *lang = (char *)b;
819 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
823 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
829 static char *__find_icon(GList *icons, const char *lang)
836 /* first, find icon whose locale and dpi with given lang and system's dpi has matched */
837 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
839 icon = (icon_x *)tmp->data;
840 return (char *)icon->text;
843 /* if first has failed, find icon whose locale has matched */
844 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
846 icon = (icon_x *)tmp->data;
847 return (char *)icon->text;
850 /* if second has failed, find icon whose dpi has matched with system's dpi */
851 ret = system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
852 if (ret == SYSTEM_INFO_ERROR_NONE) {
853 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
855 icon = (icon_x *)tmp->data;
856 return (char *)icon->text;
860 /* last, find default icon marked as "No Locale" */
861 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
863 icon = (icon_x *)tmp->data;
864 return (char *)icon->text;
870 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
871 char **label, char **license, char **icon, char **description, char **author)
878 for (tmp = lbls; tmp; tmp = tmp->next) {
879 lbl = (label_x *)tmp->data;
883 if (strcmp(lbl->lang, (char *)data) == 0) {
884 *label = (char *)lbl->text;
889 for (tmp = lcns; tmp; tmp = tmp->next) {
890 lcn = (license_x *)tmp->data;
894 if (strcmp(lcn->lang, (char *)data) == 0) {
895 *license = (char *)lcn->text;
901 *icon = __find_icon(icns, (char *)data);
903 for (tmp = dcns; tmp; tmp = tmp->next) {
904 dcn = (description_x *)tmp->data;
908 if (strcmp(dcn->lang, (char *)data) == 0) {
909 *description = (char *)dcn->text;
914 for (tmp = aths; tmp; tmp = tmp->next) {
915 ath = (author_x *)tmp->data;
919 if (strcmp(ath->lang, (char *)data) == 0) {
920 *author = (char *)ath->text;
928 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
932 for (tmp = icns; tmp; tmp = tmp->next) {
933 icn = (icon_x *)tmp->data;
937 if (strcmp(icn->section, (char *)data) == 0) {
938 *icon = (char *)icn->text;
939 *resolution = (char *)icn->resolution;
946 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
950 for (tmp = imgs; tmp; tmp = tmp->next) {
951 img = (image_x *)tmp->data;
955 if (strcmp(img->section, (char *)data) == 0) {
956 *lang = (char *)img->lang;
957 *image = (char *)img->text;
964 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
969 char *description = NULL;
970 char *license = NULL;
974 manifest_x *mfx = (manifest_x *)userdata;
975 GList *lbl = mfx->label;
976 GList *lcn = mfx->license;
977 GList *icn = mfx->icon;
978 GList *dcn = mfx->description;
979 GList *ath = mfx->author;
981 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
982 if (!label && !description && !icon && !license && !author)
985 query = sqlite3_mprintf("INSERT INTO package_localized_info(package, package_locale, " \
986 "package_label, package_icon, package_description, package_license, package_author) VALUES" \
987 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
996 ret = __exec_query(query);
998 _LOGD("Package Localized Info DB Insert failed\n");
1000 sqlite3_free(query);
1003 static void __insert_application_locale_info(gpointer data, gpointer userdata)
1009 char *locale = (char *)data;
1011 application_x *app = (application_x *)userdata;
1012 GList *lbl = app->label;
1013 GList *icn = app->icon;
1015 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1016 if (!label && !icon)
1019 query = sqlite3_mprintf("INSERT INTO package_app_localized_info(app_id, app_locale, " \
1020 "app_label, app_icon) VALUES" \
1021 "(%Q, %Q, %Q, %Q)", app->appid, (char *)data,
1023 ret = __exec_query(query);
1025 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1027 sqlite3_free(query);
1029 /*insert ui app locale info to pkg locale to get mainapp data */
1030 if (strcasecmp(app->mainapp, "true") == 0) {
1031 query = sqlite3_mprintf("INSERT OR REPLACE INTO package_localized_info(package, package_locale, "
1032 "package_label, package_icon, package_description, package_license, package_author) VALUES"
1034 "COALESCE((SELECT package_label FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1035 "COALESCE((SELECT package_icon FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1036 "(SELECT package_description FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1037 "(SELECT package_license FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1038 "(SELECT package_author FROM package_localized_info WHERE package=%Q AND package_locale=%Q))",
1039 app->package, locale,
1040 app->package, locale, label,
1041 app->package, locale, icon,
1042 app->package, locale,
1043 app->package, locale,
1044 app->package, locale);
1046 ret = __exec_query(query);
1048 _LOGE("Package Localized Info DB Insert failed");
1049 sqlite3_free(query);
1053 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1057 char *resolution = NULL;
1058 char query[MAX_QUERY_LEN] = {'\0'};
1060 application_x *app = (application_x *)userdata;
1061 GList *icn = app->icon;
1063 __extract_icon_data(data, icn, &icon, &resolution);
1064 if (!icon && !resolution)
1066 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO package_app_icon_section_info(app_id, " \
1067 "app_icon, app_icon_section, app_icon_resolution) VALUES " \
1068 "(%Q, %Q, %Q, %Q)", app->appid,
1069 icon, (char *)data, resolution);
1071 ret = __exec_query(query);
1073 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1077 static void __insert_application_image_info(gpointer data, gpointer userdata)
1082 char query[MAX_QUERY_LEN] = {'\0'};
1084 application_x *app = (application_x *)userdata;
1085 GList *image = app->image;
1087 __extract_image_data(data, image, &lang, &img);
1090 sqlite3_snprintf(MAX_QUERY_LEN, query,
1091 "INSERT INTO package_app_image_info(app_id, app_locale, " \
1092 "app_image_section, app_image) VALUES" \
1093 "(%Q, %Q, %Q, %Q)", app->appid, lang, (char *)data, img);
1095 ret = __exec_query(query);
1097 _LOGD("Package UiApp image Info DB Insert failed\n");
1102 static int __insert_mainapp_info(manifest_x *mfx)
1107 char query[MAX_QUERY_LEN] = {'\0'};
1108 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1109 app = (application_x *)tmp->data;
1113 sqlite3_snprintf(MAX_QUERY_LEN, query,
1114 "UPDATE package_app_info SET app_mainapp=%Q WHERE app_id=%Q",
1115 app->mainapp, app->appid);
1116 ret = __exec_query(query);
1118 _LOGD("Package App Info DB Insert Failed\n");
1121 if (strcasecmp(app->mainapp, "True") == 0)
1122 mfx->mainapp_id = strdup(app->appid);
1125 if (mfx->mainapp_id == NULL) {
1126 if (mfx->application == NULL)
1128 app = (application_x *)mfx->application->data;
1132 sqlite3_snprintf(MAX_QUERY_LEN, query,
1133 "UPDATE package_app_info SET app_mainapp='true' WHERE app_id=%Q",
1136 _LOGD("Not valid appid\n");
1140 ret = __exec_query(query);
1142 _LOGD("Package UiApp Info DB Insert Failed\n");
1146 free((void *)app->mainapp);
1147 app->mainapp = strdup("true");
1148 mfx->mainapp_id = strdup(app->appid);
1151 memset(query, '\0', MAX_QUERY_LEN);
1152 sqlite3_snprintf(MAX_QUERY_LEN, query,
1153 "UPDATE package_info SET mainapp_id=%Q WHERE package=%Q", mfx->mainapp_id, mfx->package);
1154 ret = __exec_query(query);
1156 _LOGD("Package Info DB update Failed\n");
1163 static int __convert_background_category(GList *category_list)
1166 GList *tmp_list = category_list;
1167 char *category_data = NULL;
1169 if (category_list == NULL)
1172 while (tmp_list != NULL) {
1173 category_data = (char *)tmp_list->data;
1174 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0)
1175 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1176 else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0)
1177 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1178 else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0)
1179 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1180 else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0)
1181 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1182 else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0)
1183 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1184 else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0)
1185 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1186 else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0)
1187 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1189 _LOGE("Unidentified category [%s]", category_data);
1190 tmp_list = g_list_next(tmp_list);
1196 static const char *__find_effective_appid(GList *metadata_list)
1201 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1202 md = (metadata_x *)tmp_list->data;
1203 if (md == NULL || md->key == NULL)
1206 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1215 static char *__get_bool(char *value, bool is_true)
1217 if (value != NULL) {
1218 if (!strcmp(value, ""))
1219 return (is_true) ? "true" : "false";
1223 return (is_true) ? "true" : "false";
1226 /* _PRODUCT_LAUNCHING_ENHANCED_
1227 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1229 static int __insert_application_info(manifest_x *mfx)
1234 int background_value = 0;
1235 char query[MAX_QUERY_LEN] = {'\0'};
1237 const char *effective_appid;
1240 type = strdup(mfx->type);
1242 type = strdup("tpk");
1244 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1245 app = (application_x *)tmp->data;
1249 background_value = __convert_background_category(app->background_category);
1250 if (background_value < 0) {
1251 _LOGE("Failed to retrieve background value[%d]", background_value);
1252 background_value = 0;
1255 effective_appid = __find_effective_appid(app->metadata);
1257 sqlite3_snprintf(MAX_QUERY_LEN, query,
1258 "INSERT INTO package_app_info(" \
1259 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1260 "app_onboot, app_multiple, app_autorestart, app_taskmanage, " \
1261 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1262 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1263 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1264 "app_launch_mode, app_ui_gadget, app_support_mode, app_support_disable, component_type, package, " \
1265 "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, " \
1266 "app_api_version, app_effective_appid, app_splash_screen_display, app_package_system, app_removable, " \
1267 "app_package_installed_time, app_support_ambient) " \
1269 "%Q, %Q, %Q, LOWER(%Q), %Q, " \
1270 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1271 "%Q, %Q, %Q, %Q, %Q, " \
1272 "LOWER(%Q), %Q, %Q, LOWER(%Q), %Q, " \
1273 "LOWER(%Q), LOWER(%Q), %Q, %Q, LOWER(%Q), " \
1274 "COALESCE(%Q, 'caller'), LOWER(%Q), %Q, LOWER(%Q), %Q, %Q, " \
1275 "%Q, %Q, %d, %Q, %Q, " \
1276 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1278 app->appid, app->component_type, app->exec, __get_bool(app->nodisplay, false), app->type,
1279 __get_bool(app->onboot, false), __get_bool(app->multiple, false), __get_bool(app->autorestart, false), __get_bool(app->taskmanage, false),
1280 app->hwacceleration, app->screenreader, app->mainapp, app->recentimage, app->launchcondition,
1281 __get_bool(app->indicatordisplay, true), app->portraitimg, app->landscapeimg,
1282 __get_bool(app->guestmode_visibility, true), app->permission_type,
1283 __get_bool(mfx->preload, false), __get_bool(app->submode, false), app->submode_mainid, mfx->installed_storage, __get_bool(app->process_pool, false),
1284 app->launch_mode, __get_bool(app->ui_gadget, false), mfx->support_mode, __get_bool(mfx->support_disable, false), app->component_type, mfx->package,
1285 mfx->tep_name, mfx->zip_mount_file, background_value, type, mfx->root_path, mfx->api_version,
1286 effective_appid, __get_bool(app->splash_screen_display, false), __get_bool(mfx->system, false), __get_bool(mfx->removable, true), mfx->installed_time, __get_bool(app->support_ambient, false));
1288 ret = __exec_query(query);
1290 _LOGD("Package UiApp Info DB Insert Failed\n");
1295 memset(query, '\0', MAX_QUERY_LEN);
1304 static int __insert_application_appcategory_info(manifest_x *mfx)
1311 char query[MAX_QUERY_LEN] = {'\0'};
1312 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1313 app = (application_x *)app_tmp->data;
1316 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1317 ct = (const char *)ct_tmp->data;
1320 sqlite3_snprintf(MAX_QUERY_LEN, query,
1321 "INSERT INTO package_app_app_category(app_id, category) " \
1324 ret = __exec_query(query);
1326 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1329 memset(query, '\0', MAX_QUERY_LEN);
1335 static int __insert_application_appmetadata_info(manifest_x *mfx)
1342 char query[MAX_QUERY_LEN] = {'\0'};
1343 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1344 app = (application_x *)app_tmp->data;
1347 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1348 md = (metadata_x *)md_tmp->data;
1352 sqlite3_snprintf(MAX_QUERY_LEN, query,
1353 "INSERT INTO package_app_app_metadata(app_id, md_key, md_value) " \
1354 "VALUES(%Q, %Q, %Q)",\
1355 app->appid, md->key, md->value ? md->value : NULL);
1356 ret = __exec_query(query);
1358 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1362 memset(query, '\0', MAX_QUERY_LEN);
1368 static int __insert_application_apppermission_info(manifest_x *mfx)
1375 char query[MAX_QUERY_LEN] = {'\0'};
1376 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1377 app = (application_x *)app_tmp->data;
1380 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1381 pm = (permission_x *)pm_tmp->data;
1384 sqlite3_snprintf(MAX_QUERY_LEN, query,
1385 "INSERT INTO package_app_app_permission(app_id, pm_type, pm_value) " \
1386 "VALUES(%Q, %Q, %Q)",\
1387 app->appid, pm->type, pm->value);
1388 ret = __exec_query(query);
1390 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1393 memset(query, '\0', MAX_QUERY_LEN);
1399 static int __insert_application_appcontrol_info(manifest_x *mfx)
1403 GList *acontrol_tmp;
1404 appcontrol_x *acontrol;
1406 char query[MAX_QUERY_LEN] = {'\0'};
1407 char buf[BUFSIZE] = {'\0'};
1408 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1409 app = (application_x *)app_tmp->data;
1412 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1413 acontrol = (appcontrol_x *)acontrol_tmp->data;
1414 if (acontrol == NULL)
1416 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1417 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1418 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1419 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1420 sqlite3_snprintf(MAX_QUERY_LEN, query,
1421 "INSERT INTO package_app_app_control(app_id, app_control) " \
1424 ret = __exec_query(query);
1426 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1429 memset(query, '\0', MAX_QUERY_LEN);
1435 static int __insert_application_datacontrol_info(manifest_x *mfx)
1442 char query[MAX_QUERY_LEN] = {'\0'};
1444 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1445 app = (application_x *)app_tmp->data;
1448 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1449 dc = (datacontrol_x *)dc_tmp->data;
1452 sqlite3_snprintf(MAX_QUERY_LEN, query,
1453 "INSERT INTO package_app_data_control(app_id, providerid, access, type) " \
1454 "VALUES(%Q, %Q, %Q, %Q)",\
1460 ret = __exec_query(query);
1462 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1465 memset(query, '\0', MAX_QUERY_LEN);
1471 static int __insert_application_share_request_info(manifest_x *mfx)
1480 char query[MAX_QUERY_LEN] = {'\0'};
1481 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1482 app = (application_x *)app_tmp->data;
1485 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1486 ds = (datashare_x *)ds_tmp->data;
1489 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1490 rq = (const char *)rq_tmp->data;
1493 sqlite3_snprintf(MAX_QUERY_LEN, query,
1494 "INSERT INTO package_app_share_request(app_id, data_share_request) " \
1497 ret = __exec_query(query);
1499 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1502 memset(query, '\0', MAX_QUERY_LEN);
1509 static int __insert_application_share_allowed_info(manifest_x *mfx)
1520 char query[MAX_QUERY_LEN] = {'\0'};
1521 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1522 app = (application_x *)app_tmp->data;
1525 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1526 ds = (datashare_x *)ds_tmp->data;
1529 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1530 df = (define_x *)df_tmp->data;
1533 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1534 al = (const char *)al_tmp->data;
1537 sqlite3_snprintf(MAX_QUERY_LEN, query,
1538 "INSERT INTO package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1539 "VALUES(%Q, %Q, %Q)",\
1540 app->appid, df->path, al);
1541 ret = __exec_query(query);
1543 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1546 memset(query, '\0', MAX_QUERY_LEN);
1554 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1556 splashscreen_x *ss = (splashscreen_x *)a;
1557 const char *orientation = (const char *)b;
1560 if (ss->operation || ss->dpi == NULL)
1563 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1567 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1573 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1575 splashscreen_x *ss = (splashscreen_x *)a;
1576 const char *orientation = (const char *)b;
1578 if (ss->operation || ss->dpi)
1581 if (strcasecmp(ss->orientation, orientation) == 0)
1587 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1588 const char *orientation)
1592 tmp = g_list_find_custom(splashscreens, orientation,
1593 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1595 return (splashscreen_x *)tmp->data;
1597 tmp = g_list_find_custom(splashscreens, orientation,
1598 (GCompareFunc)__compare_splashscreen_with_orientation);
1600 return (splashscreen_x *)tmp->data;
1605 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1607 splashscreen_x *ss = (splashscreen_x *)data;
1608 GList **list = (GList **)user_data;
1611 if (ss->operation == NULL || ss->dpi == NULL)
1614 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1618 if (__check_dpi(ss->dpi, dpi) != 0)
1621 *list = g_list_append(*list, ss);
1624 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1626 splashscreen_x *ss = (splashscreen_x *)data;
1627 GList **list = (GList **)user_data;
1628 splashscreen_x *ss_tmp;
1631 if (ss->operation == NULL || ss->dpi)
1634 for (tmp = *list; tmp; tmp = tmp->next) {
1635 ss_tmp = (splashscreen_x *)tmp->data;
1636 if (ss_tmp->operation
1637 && strcmp(ss_tmp->operation, ss->operation) == 0
1638 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1642 *list = g_list_append(*list, ss);
1645 static GList *__find_splashscreens(GList *splashscreens)
1650 g_list_foreach(splashscreens,
1651 __find_appcontrol_splashscreen_with_dpi, &list);
1652 g_list_foreach(splashscreens,
1653 __find_appcontrol_splashscreen, &list);
1655 ss = __find_default_splashscreen(splashscreens, "portrait");
1657 list = g_list_append(list, ss);
1658 ss = __find_default_splashscreen(splashscreens, "landscape");
1660 list = g_list_append(list, ss);
1665 static int __insert_application_splashscreen_info(manifest_x *mfx)
1673 char query[MAX_QUERY_LEN] = {'\0'};
1675 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1676 app = (application_x *)app_tmp->data;
1677 if (app == NULL || app->splashscreens == NULL)
1680 ss_tmp = __find_splashscreens(app->splashscreens);
1684 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1685 ss = (splashscreen_x *)tmp->data;
1686 sqlite3_snprintf(MAX_QUERY_LEN, query,
1687 "INSERT INTO package_app_splash_screen" \
1688 "(app_id, src, type, orientation, indicatordisplay, " \
1689 "operation, color_depth) " \
1690 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1691 app->appid, ss->src, ss->type, ss->orientation,
1692 ss->indicatordisplay, ss->operation,
1695 ret = __exec_query(query);
1697 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1700 memset(query, '\0', MAX_QUERY_LEN);
1702 g_list_free(ss_tmp);
1707 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1711 privilege_x *pv = NULL;
1712 char query[MAX_QUERY_LEN] = { '\0' };
1715 const char *auth_name = NULL;
1716 const char *auth_email = NULL;
1717 const char *auth_href = NULL;
1719 GList *pkglocale = NULL;
1720 GList *applocale = NULL;
1721 GList *appicon = NULL;
1722 GList *appimage = NULL;
1724 int temp_pkg_mode = 0;
1725 int temp_app_mode = 0;
1726 char pkg_mode[MAX_INTEGER_LENGTH] = {'\0'};
1727 application_x *up_support_mode = NULL;
1728 GList *list_up = NULL;
1730 if (mfx->author && mfx->author->data) {
1731 author = (author_x *)mfx->author->data;
1733 auth_name = author->text;
1735 auth_email = author->email;
1737 auth_href = author->href;
1740 if (mfx->support_mode)
1741 temp_pkg_mode = atoi(mfx->support_mode);
1743 /* FIXME : OR-ing should be fixed to not to store whole support mode */
1744 list_up = mfx->application;
1745 while (list_up != NULL) {
1746 up_support_mode = (application_x *)list_up->data;
1747 if (up_support_mode->support_mode) {
1748 temp_app_mode = atoi(up_support_mode->support_mode);
1749 temp_pkg_mode |= temp_app_mode;
1751 list_up = list_up->next;
1753 snprintf(pkg_mode, MAX_INTEGER_LENGTH, "%d", temp_pkg_mode);
1755 if (mfx->support_mode)
1756 free((void *)mfx->support_mode);
1757 mfx->support_mode = strdup(pkg_mode);
1759 /*Insert in the package_info DB*/
1760 sqlite3_snprintf(MAX_QUERY_LEN, query,
1761 "INSERT INTO package_info(" \
1762 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1763 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1764 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1765 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1766 "mainapp_id, package_url, root_path, csc_path, package_support_mode, package_support_disable) " \
1768 "%Q, %Q, %Q, %Q, %Q, %Q, " \
1769 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1770 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), %Q, " \
1771 "%Q, %Q, %Q, %Q, %Q, " \
1772 "%Q, %Q, %Q, %Q, %Q, LOWER(%Q))",
1773 mfx->package, mfx->type, mfx->version, mfx->api_version, mfx->tep_name, mfx->zip_mount_file,
1774 mfx->installlocation, mfx->package_size, __get_bool(mfx->removable, true), __get_bool(mfx->preload, false), __get_bool(mfx->readonly, false),
1775 __get_bool(mfx->update, false), __get_bool(mfx->appsetting, false), __get_bool(mfx->nodisplay_setting, false), __get_bool(mfx->system, false), auth_name,
1776 auth_email, auth_href, mfx->installed_time, mfx->installed_storage,
1777 mfx->storeclient_id,
1778 mfx->mainapp_id, mfx->package_url, mfx->root_path, mfx->csc_path, mfx->support_mode, __get_bool(mfx->support_disable, false));
1780 ret = __exec_query(query);
1782 _LOGD("Package Info DB Insert Failed\n");
1786 /*Insert in the package_privilege_info DB*/
1787 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1788 pv = (privilege_x *)tmp->data;
1791 memset(query, '\0', MAX_QUERY_LEN);
1792 sqlite3_snprintf(MAX_QUERY_LEN, query,
1793 "INSERT INTO package_privilege_info(package, privilege, type) " \
1794 "VALUES(%Q, %Q, %Q)",\
1795 mfx->package, pv->value, pv->type);
1796 ret = __exec_query(query);
1798 _LOGD("Package Privilege Info DB Insert Failed\n");
1803 if (mfx->application != NULL) {
1804 ret = __insert_mainapp_info(mfx);
1809 /*Insert the package locale*/
1810 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1811 /*remove duplicated data in pkglocale*/
1812 __trimfunc(pkglocale);
1814 /*Insert the app locale, icon, image info */
1815 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1816 app = (application_x *)tmp->data;
1819 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1820 appicon = __create_icon_list(appicon, app->icon);
1821 appimage = __create_image_list(appimage, app->image);
1823 /*remove duplicated data in applocale*/
1824 __trimfunc(applocale);
1825 __trimfunc(appicon);
1826 __trimfunc(appimage);
1828 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1830 /*native app locale info*/
1831 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1832 app = (application_x *)tmp->data;
1835 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1836 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1837 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1840 g_list_free(pkglocale);
1842 g_list_free(applocale);
1844 g_list_free(appicon);
1846 g_list_free(appimage);
1849 /*Insert in the package_app_info DB*/
1850 ret = __insert_application_info(mfx);
1853 /*Insert in the package_app_app_control DB*/
1854 ret = __insert_application_appcontrol_info(mfx);
1858 /*Insert in the package_app_app_category DB*/
1859 ret = __insert_application_appcategory_info(mfx);
1863 /*Insert in the package_app_app_metadata DB*/
1864 ret = __insert_application_appmetadata_info(mfx);
1868 /*Insert in the package_app_app_permission DB*/
1869 ret = __insert_application_apppermission_info(mfx);
1873 /*Insert in the package_app_share_allowed DB*/
1874 ret = __insert_application_share_allowed_info(mfx);
1878 /*Insert in the package_app_share_request DB*/
1879 ret = __insert_application_share_request_info(mfx);
1883 /*Insert in the package_app_data_control DB*/
1884 ret = __insert_application_datacontrol_info(mfx);
1888 /*Insert in the package_app_splash_screen DB*/
1889 ret = __insert_application_splashscreen_info(mfx);
1897 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1899 char query[MAX_QUERY_LEN] = { '\0' };
1902 sqlite3_snprintf(MAX_QUERY_LEN, query,
1903 "DELETE FROM %q where app_id=%Q", db_table, appid);
1904 ret = __exec_query(query);
1906 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1912 static int __delete_subpkg_info_from_db(char *appid)
1916 ret = __delete_appinfo_from_db("package_app_info", appid);
1919 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1922 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1925 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1928 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1931 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1934 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1937 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1940 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1943 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1946 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1949 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
1956 static int __delete_subpkg_from_db(manifest_x *mfx)
1958 char query[MAX_QUERY_LEN] = { '\0' };
1959 char *error_message = NULL;
1961 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT app_id FROM package_app_info WHERE package=%Q", mfx->package);
1963 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1964 _LOGE("Don't execute query = %s error message = %s\n", query,
1966 sqlite3_free(error_message);
1969 sqlite3_free(error_message);
1974 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1976 char query[MAX_QUERY_LEN] = { '\0' };
1981 /*Delete from Package Info DB*/
1982 sqlite3_snprintf(MAX_QUERY_LEN, query,
1983 "DELETE FROM package_info WHERE package=%Q", mfx->package);
1984 ret = __exec_query(query);
1986 _LOGD("Package Info DB Delete Failed\n");
1989 memset(query, '\0', MAX_QUERY_LEN);
1991 /*Delete from Package Localized Info*/
1992 sqlite3_snprintf(MAX_QUERY_LEN, query,
1993 "DELETE FROM package_localized_info WHERE package=%Q", mfx->package);
1994 ret = __exec_query(query);
1996 _LOGD("Package Localized Info DB Delete Failed\n");
2000 /*Delete from Package Privilege Info*/
2001 sqlite3_snprintf(MAX_QUERY_LEN, query,
2002 "DELETE FROM package_privilege_info WHERE package=%Q", mfx->package);
2003 ret = __exec_query(query);
2005 _LOGD("Package Privilege Info DB Delete Failed\n");
2009 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2010 app = (application_x *)tmp->data;
2013 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2016 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2019 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2022 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2025 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2028 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2031 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2034 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2037 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2040 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2043 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2046 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2051 /* if main package has sub pkg, delete sub pkg data*/
2052 __delete_subpkg_from_db(mfx);
2057 static int __disable_app(const char *appid)
2060 char query[MAX_QUERY_LEN] = {'\0'};
2061 sqlite3_snprintf(MAX_QUERY_LEN, query,
2062 "UPDATE package_app_info SET app_disable='true' WHERE app_id=%Q",
2064 ret = __exec_query(query);
2066 _LOGD("Insert global app disable failed\n");
2071 static int __enable_app(const char *appid)
2074 char query[MAX_QUERY_LEN] = {'\0'};
2075 sqlite3_snprintf(MAX_QUERY_LEN, query,
2076 "UPDATE package_app_info SET app_disable='false' WHERE app_id=%Q",
2078 ret = __exec_query(query);
2080 _LOGD("Insert global app disable failed\n");
2085 static int __disable_pkg(const char *pkgid)
2088 char query[MAX_QUERY_LEN] = {'\0'};
2089 sqlite3_snprintf(MAX_QUERY_LEN, query,
2090 "UPDATE package_info SET package_disable='true' WHERE package=%Q",
2092 ret = __exec_query(query);
2094 _LOGD("Update pkg disable info has failed\n");
2099 static int __enable_pkg(const char *pkgid)
2102 char query[MAX_QUERY_LEN] = {'\0'};
2103 sqlite3_snprintf(MAX_QUERY_LEN, query,
2104 "UPDATE package_info SET package_disable='false' WHERE package=%Q",
2106 ret = __exec_query(query);
2108 _LOGD("Update pkg disable info has failed\n");
2113 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2116 char query[MAX_QUERY_LEN] = { '\0', };
2118 const char *val = NULL;
2123 sqlite3_snprintf(MAX_QUERY_LEN, query,
2124 "SELECT COUNT(*) FROM "
2125 "package_app_info_for_uid WHERE app_id=%Q "
2126 "AND uid=%d", appid, (int)uid);
2128 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2129 if (ret != SQLITE_OK) {
2130 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2131 return PMINFO_R_ERROR;
2134 if (sqlite3_step(stmt) != SQLITE_ROW) {
2135 LOGE("failed to step");
2136 sqlite3_finalize(stmt);
2137 return PMINFO_R_ERROR;
2140 val = (const char *)sqlite3_column_text(stmt, 0);
2142 sqlite3_finalize(stmt);
2147 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2150 char query[MAX_QUERY_LEN] = { '\0', };
2152 ret = __check_appinfo_for_uid_table(appid, uid);
2154 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2157 } else if (ret == 0) {
2158 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2159 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2160 "VALUES(%Q, %d, 'true', "
2161 "(SELECT app_splash_screen_display FROM package_app_info WHERE appid='%Q'))",
2162 appid, (int)uid, appid);
2164 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2165 "package_app_info_for_uid SET is_disabled='true' "
2166 "WHERE app_id=%Q AND uid=%d", appid, (int)uid);
2169 ret = __exec_query(query);
2171 _LOGD("Add global app disable info failed\n");
2176 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2179 char query[MAX_QUERY_LEN] = {'\0'};
2181 ret = __check_appinfo_for_uid_table(appid, uid);
2183 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2186 } else if (ret > 0) {
2187 sqlite3_snprintf(MAX_QUERY_LEN, query,
2188 "UPDATE package_app_info_for_uid SET "
2189 "is_disabled='false' WHERE app_id=%Q AND "
2190 "uid=%d", appid, (int)uid);
2193 ret = __exec_query(query);
2195 _LOGD("Remove global app disable info failed\n");
2200 static int __update_global_app_splash_screen_for_user(const char *appid,
2201 uid_t uid, int flag)
2204 char query[MAX_QUERY_LEN] = { '\0', };
2206 ret = __check_appinfo_for_uid_table(appid, uid);
2208 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2211 } else if (ret == 0) {
2212 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2213 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2214 "VALUES(%Q, %d, %Q)", appid, (int)uid,
2215 flag ? "true" : "false");
2217 sqlite3_snprintf(MAX_QUERY_LEN, query,
2218 "UPDATE package_app_info_for_uid SET "
2219 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2220 "uid=%d", flag ? "true" : "false", appid, (int)uid);
2223 ret = __exec_query(query);
2225 _LOGD("update global app splash screen info failed\n");
2230 static int __disable_app_splash_screen(const char *appid)
2233 char query[MAX_QUERY_LEN] = {'\0'};
2235 sqlite3_snprintf(MAX_QUERY_LEN, query,
2236 "UPDATE package_app_info SET app_splash_screen_display='false' WHERE app_id=%Q",
2238 ret = __exec_query(query);
2240 _LOGD("Failed to update app_palsh_screen_display");
2245 static int __enable_app_splash_screen(const char *appid)
2248 char query[MAX_QUERY_LEN] = {'\0'};
2250 sqlite3_snprintf(MAX_QUERY_LEN, query,
2251 "UPDATE package_app_info SET app_splash_screen_display='true' WHERE app_id=%Q",
2253 ret = __exec_query(query);
2255 _LOGD("Failed to update app_splash_screen_display");
2260 API int pkgmgr_parser_initialize_db(uid_t uid)
2266 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2268 _LOGD("package info DB initialization failed\n");
2271 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2273 _LOGD("package localized info DB initialization failed\n");
2276 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2278 _LOGD("package app app privilege DB initialization failed\n");
2281 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2283 _LOGD("package app info DB initialization failed\n");
2286 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2288 _LOGD("package app localized info DB initialization failed\n");
2291 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2293 _LOGD("package app icon localized info DB initialization failed\n");
2296 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2298 _LOGD("package app image info DB initialization failed\n");
2301 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2303 _LOGD("package app app control DB initialization failed\n");
2306 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2308 _LOGD("package app app category DB initialization failed\n");
2311 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2313 _LOGD("package app app category DB initialization failed\n");
2316 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2318 _LOGD("package app app permission DB initialization failed\n");
2321 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2323 _LOGD("package app share allowed DB initialization failed\n");
2326 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2328 _LOGD("package app share request DB initialization failed\n");
2331 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2333 _LOGD("package app data control DB initialization failed\n");
2337 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2339 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2343 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2345 _LOGD("package app splash screen DB initialization failed\n");
2349 /* Trigger package_app_info_for_uid */
2350 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2352 _LOGD("package app info for uid DB initialization failed\n");
2357 /* TODO: refactor this code */
2358 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2360 _LOGD("package cert info DB initialization failed\n");
2363 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2365 _LOGD("package cert index info DB initialization failed\n");
2368 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO);
2370 _LOGD("package cert info DB initialization failed\n");
2373 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2);
2375 _LOGD("package cert info DB initialization failed\n");
2378 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2380 _LOGD("package cert info DB initialization failed\n");
2383 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2385 _LOGD("package cert index info DB initialization failed\n");
2389 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2390 if (db_path == NULL) {
2391 _LOGD("Failed to get user cert db path - GLOBAL_USER");
2393 ret = __parserdb_change_perm(db_path, GLOBAL_USER);
2395 _LOGD("Failed to change cert db permission");
2399 db_path = getUserPkgParserDBPathUID(uid);
2400 if (db_path == NULL) {
2401 _LOGD("Failed to get user pkg parser db path - %d", uid);
2403 ret = __parserdb_change_perm(db_path, uid);
2405 _LOGD("Failed to change parser db permission\n");
2412 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2415 char pwuid_buf[1024];
2416 char journal_file[BUFSIZE];
2421 struct passwd userinfo, *result = NULL;
2422 files[0] = (char *)db_file;
2423 files[1] = journal_file;
2427 if (db_file == NULL)
2430 if (getuid() != OWNER_ROOT) /* At this time we should be root to apply this */
2432 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2433 if (uid == OWNER_ROOT)
2435 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2436 if (ret != 0 || result == NULL) {
2437 _LOGE("FAIL: user %d doesn't exist", uid);
2440 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2442 for (i = 0; files[i]; i++) {
2443 fd = open(files[i], O_RDONLY);
2445 if (strerror_r(errno, buf, sizeof(buf)))
2446 strncpy(buf, "", BUFSIZE - 1);
2447 _LOGD("FAIL : open %s : %s", files[i], buf);
2450 ret = fstat(fd, &sb);
2452 if (strerror_r(errno, buf, sizeof(buf)))
2453 strncpy(buf, "", BUFSIZE - 1);
2454 _LOGD("FAIL : fstat %s : %s", files[i], buf);
2458 if (S_ISLNK(sb.st_mode)) {
2459 _LOGE("FAIL : %s is symlink!", files[i]);
2463 ret = fchown(fd, uid, userinfo.pw_gid);
2465 if (strerror_r(errno, buf, sizeof(buf)))
2466 strncpy(buf, "", BUFSIZE - 1);
2467 _LOGD("FAIL : fchown %s %d.%d : %s", files[i], uid,
2468 userinfo.pw_gid, buf);
2473 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2474 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2476 ret = fchmod(fd, mode);
2478 if (strerror_r(errno, buf, sizeof(buf)))
2479 strncpy(buf, "", BUFSIZE - 1);
2480 _LOGD("FAIL : fchmod %s 0664 : %s", files[i], buf);
2485 SET_SMACK_LABEL(files[i]);
2490 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2495 if (getuid() != OWNER_ROOT) {
2496 _LOGE("Only root user is allowed");
2500 db_path = getUserPkgParserDBPathUID(uid);
2501 if (db_path == NULL) {
2502 _LOGE("Failed to get pkg parser db path - %d", uid);
2506 if (access(db_path, F_OK) != -1) {
2507 _LOGE("Manifest db for user %d is already exists", uid);
2513 db_path = getUserPkgCertDBPathUID(uid);
2514 if (db_path == NULL) {
2515 _LOGE("Failed to get pkg cert db path - %d", uid);
2519 if (access(db_path, F_OK) != -1) {
2520 _LOGE("Cert db for user %d is already exists", uid);
2526 ret = pkgmgr_parser_check_and_create_db(uid);
2529 ret = pkgmgr_parser_initialize_db(uid);
2531 pkgmgr_parser_close_db();
2534 pkgmgr_parser_close_db();
2539 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2544 db_path = getUserPkgParserDBPathUID(uid);
2545 if (db_path == NULL) {
2546 _LOGD("Failed to get pkg parser db path - %d", uid);
2551 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, db_path);
2553 _LOGD("Manifest DB creation Failed\n");
2559 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2560 if (db_path == NULL) {
2561 _LOGE("Failed to get pkg cert db path - GLOBAL_USER");
2566 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, db_path);
2568 _LOGD("Cert DB creation Failed\n");
2578 void pkgmgr_parser_close_db(void)
2580 sqlite3_close(pkgmgr_parser_db);
2581 sqlite3_close(pkgmgr_cert_db);
2585 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2587 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2589 _LOGD("manifest pointer is NULL\n");
2593 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2595 _LOGD("Failed to open DB\n");
2598 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2601 /*Begin transaction*/
2602 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2603 if (ret != SQLITE_OK) {
2604 _LOGD("Failed to begin transaction\n");
2608 _LOGD("Transaction Begin\n");
2609 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2611 _LOGD("Insert into DB failed. Rollback now\n");
2612 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2615 /*Commit transaction*/
2616 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2617 if (ret != SQLITE_OK) {
2618 _LOGD("Failed to commit transaction. Rollback now\n");
2619 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2623 _LOGD("Transaction Commit and End\n");
2625 pkgmgr_parser_close_db();
2629 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2631 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2633 _LOGD("manifest pointer is NULL\n");
2637 ret = pkgmgr_parser_check_and_create_db(uid);
2639 _LOGD("Failed to open DB\n");
2642 ret = pkgmgr_parser_initialize_db(uid);
2645 /*Begin transaction*/
2646 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2647 if (ret != SQLITE_OK) {
2648 _LOGD("Failed to begin transaction\n");
2652 _LOGD("Transaction Begin\n");
2653 ret = __insert_manifest_info_in_db(mfx, uid);
2655 _LOGD("Insert into DB failed. Rollback now\n");
2656 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2659 /*Commit transaction*/
2660 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2661 if (ret != SQLITE_OK) {
2662 _LOGD("Failed to commit transaction. Rollback now\n");
2663 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2667 _LOGD("Transaction Commit and End\n");
2669 pkgmgr_parser_close_db();
2673 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2675 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, _getuid());
2678 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2680 if (pkgid == NULL || tep_path == NULL) {
2681 _LOGE("invalid parameter");
2688 ret = pkgmgr_parser_check_and_create_db(uid);
2690 _LOGD("Failed to open DB\n");
2693 ret = pkgmgr_parser_initialize_db(uid);
2697 /*Begin transaction*/
2698 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2699 if (ret != SQLITE_OK) {
2700 _LOGD("Failed to begin transaction\n");
2704 _LOGD("Transaction Begin\n");
2707 /* Updating TEP info in "package_info" table */
2708 query = sqlite3_mprintf("UPDATE package_info "\
2709 "SET package_tep_name = %Q "\
2710 "WHERE package = %Q", tep_path, pkgid);
2712 ret = __exec_query(query);
2713 sqlite3_free(query);
2714 if (ret != SQLITE_OK) {
2715 ret = PM_PARSER_R_ERROR;
2716 _LOGE("sqlite exec failed to insert entries into package_info!!");
2720 /* Updating TEP info in "package_app_info" table */
2721 query = sqlite3_mprintf("UPDATE package_app_info "\
2722 "SET app_tep_name = %Q "\
2723 "WHERE package = %Q", tep_path, pkgid);
2725 ret = __exec_query(query);
2726 sqlite3_free(query);
2727 if (ret != SQLITE_OK) {
2728 ret = PM_PARSER_R_ERROR;
2729 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2733 /*Commit transaction*/
2734 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2735 if (ret != SQLITE_OK) {
2736 _LOGE("Failed to commit transaction, Rollback now\n");
2737 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2738 if (ret != SQLITE_OK)
2739 _LOGE("Failed to Rollback\n");
2741 ret = PM_PARSER_R_ERROR;
2744 _LOGD("Transaction Commit and End\n");
2745 ret = PM_PARSER_R_OK;
2748 pkgmgr_parser_close_db();
2753 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2756 _LOGD("manifest pointer is NULL\n");
2760 ret = pkgmgr_parser_check_and_create_db(uid);
2762 _LOGD("Failed to open DB\n");
2765 ret = pkgmgr_parser_initialize_db(uid);
2768 /*Preserve guest mode visibility*/
2769 __preserve_guestmode_visibility_value(mfx);
2770 /*Begin transaction*/
2771 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2772 if (ret != SQLITE_OK) {
2773 _LOGD("Failed to begin transaction\n");
2777 _LOGD("Transaction Begin\n");
2778 ret = __delete_manifest_info_from_db(mfx, uid);
2780 _LOGD("Delete from DB failed. Rollback now\n");
2781 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2784 ret = __insert_manifest_info_in_db(mfx, uid);
2786 _LOGD("Insert into DB failed. Rollback now\n");
2787 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2791 /*Commit transaction*/
2792 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2793 if (ret != SQLITE_OK) {
2794 _LOGD("Failed to commit transaction. Rollback now\n");
2795 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2799 _LOGD("Transaction Commit and End\n");
2801 pkgmgr_parser_close_db();
2805 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2807 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2810 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2813 _LOGD("manifest pointer is NULL\n");
2817 ret = pkgmgr_parser_check_and_create_db(uid);
2819 _LOGD("Failed to open DB\n");
2822 /*Begin transaction*/
2823 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2824 if (ret != SQLITE_OK) {
2825 _LOGD("Failed to begin transaction\n");
2829 _LOGD("Transaction Begin\n");
2830 ret = __delete_manifest_info_from_db(mfx, uid);
2832 _LOGD("Delete from DB failed. Rollback now\n");
2833 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2836 /*Commit transaction*/
2837 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2838 if (ret != SQLITE_OK) {
2839 _LOGD("Failed to commit transaction, Rollback now\n");
2840 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2844 _LOGD("Transaction Commit and End\n");
2846 pkgmgr_parser_close_db();
2850 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2852 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
2855 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2859 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2861 _LOGD("Failed to open DB\n");
2865 /*Begin transaction*/
2866 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2867 if (ret != SQLITE_OK) {
2868 _LOGD("Failed to begin transaction\n");
2872 _LOGD("Transaction Begin\n");
2874 ret = __disable_global_app_for_user(appid, uid);
2876 ret = __enable_global_app_for_user(appid, uid);
2878 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2879 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2882 /*Commit transaction*/
2883 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2884 if (ret != SQLITE_OK) {
2885 _LOGD("Failed to commit transaction, Rollback now\n");
2886 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2890 _LOGD("Transaction Commit and End\n");
2892 pkgmgr_parser_close_db();
2897 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2899 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
2902 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid, uid_t uid, int is_disable)
2906 ret = pkgmgr_parser_check_and_create_db(uid);
2908 _LOGD("Failed to open DB\n");
2912 /*Begin transaction*/
2913 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2914 if (ret != SQLITE_OK) {
2915 _LOGD("Failed to begin transaction\n");
2920 _LOGD("Transaction Begin\n");
2922 ret = __disable_pkg(pkgid);
2924 ret = __enable_pkg(pkgid);
2927 _LOGD("__update_pkg_disable_condition_in_db failed. Rollback now\n");
2928 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2932 /*Commit transaction*/
2933 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2934 if (ret != SQLITE_OK) {
2935 _LOGD("Failed to commit transaction, Rollback now\n");
2936 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2940 _LOGD("Transaction Commit and End\n");
2943 pkgmgr_parser_close_db();
2947 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid, int is_disable)
2949 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid, _getuid(), is_disable);
2952 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2956 ret = pkgmgr_parser_check_and_create_db(uid);
2958 _LOGD("Failed to open DB\n");
2962 /*Begin transaction*/
2963 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2964 if (ret != SQLITE_OK) {
2965 _LOGD("Failed to begin transaction\n");
2969 _LOGD("Transaction Begin\n");
2971 ret = __disable_app(appid);
2973 ret = __enable_app(appid);
2975 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2976 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2979 /*Commit transaction*/
2980 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2981 if (ret != SQLITE_OK) {
2982 _LOGD("Failed to commit transaction, Rollback now\n");
2983 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2987 _LOGD("Transaction Commit and End\n");
2989 pkgmgr_parser_close_db();
2994 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
2998 if (appid == NULL) {
2999 _LOGD("Invalid parameter");
3003 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3005 _LOGD("Failed to open DB\n");
3009 /* Begin transaction */
3010 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3011 if (ret != SQLITE_OK) {
3012 _LOGD("Failed to begin transaction\n");
3016 _LOGD("Transaction Begin\n");
3018 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3020 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3021 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3024 /* Commit transaction */
3025 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3026 if (ret != SQLITE_OK) {
3027 _LOGD("Failed to commit transaction, Rollback now\n");
3028 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3032 _LOGD("Transaction Commit and End\n");
3034 pkgmgr_parser_close_db();
3038 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3040 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3043 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3047 if (appid == NULL) {
3048 _LOGD("Invalid parameter");
3052 ret = pkgmgr_parser_check_and_create_db(uid);
3054 _LOGD("Failed to open DB");
3058 /* Begin transaction */
3059 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3060 if (ret != SQLITE_OK) {
3061 _LOGD("Failed to begin transaction");
3065 _LOGD("Transaction Begin");
3068 ret = __enable_app_splash_screen(appid);
3070 ret = __disable_app_splash_screen(appid);
3072 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3073 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3076 /* Commit transaction */
3077 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3078 if (ret != SQLITE_OK) {
3079 _LOGD("Failed to commit transaction, Rollback now");
3080 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3084 _LOGD("Transaction Commit and End");
3087 pkgmgr_parser_close_db();
3091 API int pkgmgr_parser_update_app_label_info_in_usr_db(const char *appid, uid_t uid, const char *label)
3094 char query[MAX_QUERY_LEN] = {'\0'};
3096 if (appid == NULL || label == NULL) {
3097 _LOGE("Invalid parameter");
3101 ret = pkgmgr_parser_check_and_create_db(uid);
3103 _LOGD("Failed to open DB");
3107 /*Begin transaction*/
3108 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3109 if (ret != SQLITE_OK) {
3110 _LOGD("Failed to begin transaction\n");
3115 sqlite3_snprintf(MAX_QUERY_LEN, query,
3116 "UPDATE package_app_localized_info SET app_label=%Q WHERE " \
3117 "app_id=%Q AND app_label IS NOT NULL",
3119 ret = __exec_query(query);
3121 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3125 /* Commit transaction */
3126 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3127 if (ret != SQLITE_OK) {
3128 _LOGD("Failed to commit transaction, Rollback now");
3129 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3133 _LOGD("Transaction Commit and End");
3136 pkgmgr_parser_close_db();
3140 API int pkgmgr_parser_update_app_label_info_in_db(const char *appid, const char *label)
3142 return pkgmgr_parser_update_app_label_info_in_usr_db(appid, _getuid(), label);