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 APPFW_USER "app_fw"
54 #define MAX_INTEGER_LENGTH 10
60 #define XXHDPI "xxhdpi"
70 #define XXHDPI_MIN 481
71 #define XXHDPI_MAX 600
73 #define DB_LABEL "User::Home"
74 #define SET_SMACK_LABEL(x) \
76 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
77 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
79 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
82 sqlite3 *pkgmgr_parser_db;
83 sqlite3 *pkgmgr_cert_db;
86 #define QUERY_CREATE_TABLE_PACKAGE_INFO "CREATE TABLE IF NOT EXISTS package_info " \
87 "(package TEXT PRIMARY KEY NOT NULL, " \
88 "package_type TEXT DEFAULT 'tpk', " \
89 "package_version TEXT, " \
90 "package_api_version TEXT, " \
91 "package_tep_name TEXT, " \
92 "package_zip_mount_file TEXT, " \
93 "install_location TEXT NOT NULL , " \
94 "package_size TEXT, " \
95 "package_removable TEXT NOT NULL DEFAULT 'true', " \
96 "package_preload TEXT NOT NULL DEFAULT 'false', " \
97 "package_readonly TEXT NOT NULL DEFAULT 'false', " \
98 "package_update TEXT NOT NULL DEFAULT 'false', " \
99 "package_appsetting TEXT NOT NULL DEFAULT 'false', " \
100 "package_nodisplay TEXT NOT NULL DEFAULT 'false', " \
101 "package_system TEXT NOT NULL DEFAULT 'false', " \
102 "author_name TEXT, " \
103 "author_email TEXT, " \
104 "author_href TEXT," \
105 "installed_time TEXT, " \
106 "installed_storage TEXT, " \
107 "storeclient_id TEXT, " \
108 "mainapp_id TEXT, " \
109 "package_url TEXT, " \
111 "external_path TEXT, " \
113 "package_support_mode TEXT, " \
114 "package_support_disable TEXT NOT NULL DEFAULT 'false', " \
115 "package_disable TEXT NOT NULL DEFAULT 'false')"
117 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_localized_info " \
118 "(package TEXT NOT NULL, " \
119 "package_locale TEXT NOT NULL DEFAULT 'No Locale', " \
120 "package_label TEXT, " \
121 "package_icon TEXT, " \
122 "package_description TEXT, " \
123 "package_license TEXT, " \
124 "package_author TEXT, " \
125 "PRIMARY KEY(package, package_locale), " \
126 "FOREIGN KEY(package) " \
127 "REFERENCES package_info(package) " \
130 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "CREATE TABLE IF NOT EXISTS package_privilege_info " \
131 "(package TEXT NOT NULL, " \
132 "privilege TEXT NOT NULL, " \
133 "type TEXT NOT NULL, " \
134 "PRIMARY KEY(package, privilege, type) " \
135 "FOREIGN KEY(package) " \
136 "REFERENCES package_info(package) " \
139 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "CREATE TABLE IF NOT EXISTS package_app_info " \
140 "(app_id TEXT PRIMARY KEY NOT NULL, " \
141 "app_component TEXT NOT NULL, " \
143 "app_nodisplay TEXT NOT NULL DEFAULT 'false', " \
145 "app_onboot TEXT NOT NULL DEFAULT 'false', " \
146 "app_multiple TEXT NOT NULL DEFAULT 'false', " \
147 "app_autorestart TEXT NOT NULL DEFAULT 'false', " \
148 "app_taskmanage TEXT NOT NULL DEFAULT 'false', " \
149 "app_hwacceleration TEXT NOT NULL DEFAULT 'use-system-setting', " \
150 "app_screenreader TEXT NOT NULL DEFAULT 'use-system-setting', " \
151 "app_mainapp TEXT NOT NULL, " \
152 "app_recentimage TEXT NOT NULL DEFAULT 'false', " \
153 "app_launchcondition TEXT, " \
154 "app_indicatordisplay TEXT NOT NULL DEFAULT 'true', " \
155 "app_portraitimg TEXT, " \
156 "app_landscapeimg TEXT, " \
157 "app_guestmodevisibility TEXT NOT NULL DEFAULT 'true', " \
158 "app_permissiontype TEXT NOT NULL DEFAULT 'normal', " \
159 "app_preload TEXT NOT NULL DEFAULT 'false', " \
160 "app_submode TEXT NOT NULL DEFAULT 'false', " \
161 "app_submode_mainid TEXT, " \
162 "app_installed_storage TEXT NOT NULL, " \
163 "app_process_pool TEXT NOT NULL DEFAULT 'false', " \
164 "app_launch_mode TEXT NOT NULL DEFAULT 'caller', " \
165 "app_ui_gadget TEXT NOT NULL DEFAULT 'false', " \
166 "app_support_mode TEXT, " \
167 "app_support_disable TEXT NOT NULL DEFAULT 'false', " \
168 "app_disable TEXT NOT NULL DEFAULT 'false', " \
169 "app_package_type TEXT DEFAULT 'tpk', " \
170 "app_package_system TEXT NOT NULL, " \
171 "app_removable TEXT NOT NULL DEFAULT 'false', " \
172 "app_package_installed_time TEXT, " \
173 "app_support_ambient TEXT NOT NULL DEFAULT 'false', " \
174 "component_type TEXT, " \
175 "package TEXT NOT NULL, " \
176 "app_tep_name TEXT, " \
177 "app_zip_mount_file TEXT, " \
178 "app_background_category INTEGER DEFAULT 0, " \
179 "app_root_path TEXT, " \
180 "app_api_version TEXT, " \
181 "app_effective_appid TEXT, " \
182 "app_splash_screen_display TEXT NOT NULL DEFAULT 'true', " \
183 "app_external_path TEXT, " \
184 "app_setup_appid TEXT, " \
185 "FOREIGN KEY(package) " \
186 "REFERENCES package_info(package) " \
189 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_app_localized_info " \
190 "(app_id TEXT NOT NULL, " \
191 "app_locale TEXT NOT NULL DEFAULT 'No Locale', " \
194 "PRIMARY KEY(app_id,app_locale) " \
195 "FOREIGN KEY(app_id) " \
196 "REFERENCES package_app_info(app_id) " \
199 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "CREATE TABLE IF NOT EXISTS package_app_icon_section_info " \
200 "(app_id TEXT NOT NULL, " \
202 "app_icon_section TEXT NOT NULL, " \
203 "app_icon_resolution TEXT NOT NULL, " \
204 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
205 "FOREIGN KEY(app_id) " \
206 "REFERENCES package_app_info(app_id) " \
209 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "CREATE TABLE IF NOT EXISTS package_app_image_info " \
210 "(app_id TEXT NOT NULL, " \
211 "app_locale TEXT DEFAULT 'No Locale', " \
212 "app_image_section TEXT NOT NULL, " \
214 "PRIMARY KEY(app_id,app_image_section) " \
215 "FOREIGN KEY(app_id) " \
216 "REFERENCES package_app_info(app_id) " \
219 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "CREATE TABLE IF NOT EXISTS package_app_app_control " \
220 "(app_id TEXT NOT NULL, " \
221 "app_control TEXT NOT NULL, " \
222 "PRIMARY KEY(app_id,app_control) " \
223 "FOREIGN KEY(app_id) " \
224 "REFERENCES package_app_info(app_id) " \
227 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "CREATE TABLE IF NOT EXISTS package_app_app_category " \
228 "(app_id TEXT NOT NULL, " \
229 "category TEXT NOT NULL, " \
230 "PRIMARY KEY(app_id,category) " \
231 "FOREIGN KEY(app_id) " \
232 "REFERENCES package_app_info(app_id) " \
235 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "CREATE TABLE IF NOT EXISTS package_app_app_metadata " \
236 "(app_id TEXT NOT NULL, " \
237 "md_key TEXT NOT NULL, " \
239 "PRIMARY KEY(app_id, md_key, md_value) " \
240 "FOREIGN KEY(app_id) " \
241 "REFERENCES package_app_info(app_id) " \
244 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "CREATE TABLE IF NOT EXISTS package_app_app_permission " \
245 "(app_id TEXT NOT NULL, " \
246 "pm_type TEXT NOT NULL, " \
247 "pm_value TEXT NOT NULL, " \
248 "PRIMARY KEY(app_id, pm_type, pm_value) " \
249 "FOREIGN KEY(app_id) " \
250 "REFERENCES package_app_info(app_id) " \
253 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "CREATE TABLE IF NOT EXISTS package_app_share_allowed " \
254 "(app_id TEXT NOT NULL, " \
255 "data_share_path TEXT NOT NULL, " \
256 "data_share_allowed TEXT NOT NULL, " \
257 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
258 "FOREIGN KEY(app_id) " \
259 "REFERENCES package_app_info(app_id) " \
262 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "CREATE TABLE IF NOT EXISTS package_app_share_request " \
263 "(app_id TEXT NOT NULL, " \
264 "data_share_request TEXT NOT NULL, " \
265 "PRIMARY KEY(app_id,data_share_request) " \
266 "FOREIGN KEY(app_id) " \
267 "REFERENCES package_app_info(app_id) " \
270 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "CREATE TABLE IF NOT EXISTS package_app_data_control " \
271 "(app_id TEXT NOT NULL, " \
272 "providerid TEXT NOT NULL, " \
273 "access TEXT NOT NULL, " \
274 "type TEXT NOT NULL, " \
275 "PRIMARY KEY(app_id, providerid, access, type) " \
276 "FOREIGN KEY(app_id) " \
277 "REFERENCES package_app_info(app_id) " \
280 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
281 "(app_id TEXT NOT NULL, " \
282 "uid INTEGER NOT NULL, " \
283 "is_disabled TEXT NOT NULL DEFAULT 'false', " \
284 "is_splash_screen_enabled TEXT NOT NULL, " \
285 "PRIMARY KEY(app_id, uid))"
287 #define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
288 "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
289 "AFTER UPDATE ON package_app_info_for_uid " \
291 " DELETE FROM package_app_info_for_uid WHERE " \
292 " is_splash_screen_enabled=" \
293 " (SELECT package_app_info.app_splash_screen_display FROM " \
294 " package_app_info, package_app_info_for_uid WHERE " \
295 " package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
298 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
299 "CREATE TABLE IF NOT EXISTS package_app_splash_screen " \
300 "(app_id TEXT NOT NULL, " \
301 "src TEXT NOT NULL, " \
302 "type TEXT NOT NULL, " \
303 "orientation TEXT NOT NULL, " \
304 "indicatordisplay TEXT, " \
305 "operation TEXT NOT NULL, " \
306 "color_depth TEXT NOT NULL DEFAULT '24', " \
307 "PRIMARY KEY(app_id, orientation, operation) " \
308 "FOREIGN KEY(app_id) " \
309 "REFERENCES package_app_info(app_id) " \
313 /* FIXME: duplicated at pkgmgrinfo_db.c */
314 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
315 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
316 " cert_info TEXT UNIQUE, " \
317 " cert_id INTEGER PRIMARY KEY, " \
318 " cert_ref_count INTEGER NOT NULL)"
320 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
321 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
322 " package TEXT PRIMARY KEY, " \
323 " package_count INTEGER, " \
324 " author_root_cert INTEGER, " \
325 " author_im_cert INTEGER, " \
326 " author_signer_cert INTEGER, " \
327 " dist_root_cert INTEGER, " \
328 " dist_im_cert INTEGER, " \
329 " dist_signer_cert INTEGER, " \
330 " dist2_root_cert INTEGER, " \
331 " dist2_im_cert INTEGER, " \
332 " dist2_signer_cert INTEGER)"
334 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO \
335 "CREATE TRIGGER IF NOT EXISTS update_cert_info " \
336 "AFTER UPDATE ON package_cert_info " \
337 "WHEN (NEW.package_count = 0) " \
339 " DELETE FROM package_cert_info WHERE package=OLD.package;" \
342 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2 \
343 "CREATE TRIGGER IF NOT EXISTS update_cert_info2 " \
344 "AFTER UPDATE ON package_cert_info " \
345 "WHEN (NEW.package_count = OLD.package_count + 1) " \
347 " UPDATE package_cert_index_info SET" \
348 " cert_ref_count = cert_ref_count - 1" \
349 " WHERE cert_id = OLD.author_root_cert" \
350 " OR cert_id = OLD.author_im_cert" \
351 " OR cert_id = OLD.author_signer_cert" \
352 " OR cert_id = OLD.dist_root_cert" \
353 " OR cert_id = OLD.dist_im_cert" \
354 " OR cert_id = OLD.dist_signer_cert" \
355 " OR cert_id = OLD.dist2_root_cert" \
356 " OR cert_id = OLD.dist2_im_cert" \
357 " OR cert_id = OLD.dist2_signer_cert;" \
360 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
361 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
362 "AFTER DELETE ON package_cert_info " \
364 " UPDATE package_cert_index_info SET" \
365 " cert_ref_count = cert_ref_count - 1" \
366 " WHERE cert_id = OLD.author_root_cert" \
367 " OR cert_id = OLD.author_im_cert" \
368 " OR cert_id = OLD.author_signer_cert" \
369 " OR cert_id = OLD.dist_root_cert" \
370 " OR cert_id = OLD.dist_im_cert" \
371 " OR cert_id = OLD.dist_signer_cert" \
372 " OR cert_id = OLD.dist2_root_cert" \
373 " OR cert_id = OLD.dist2_im_cert" \
374 " OR cert_id = OLD.dist2_signer_cert;" \
377 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
378 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
379 "AFTER UPDATE ON package_cert_index_info " \
380 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
381 " WHERE cert_id = OLD.cert_id) = 0) "\
383 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
386 static int __insert_application_info(manifest_x *mfx);
387 static int __insert_application_appcategory_info(manifest_x *mfx);
388 static int __insert_application_appcontrol_info(manifest_x *mfx);
389 static int __insert_application_appmetadata_info(manifest_x *mfx);
390 static int __insert_application_share_allowed_info(manifest_x *mfx);
391 static int __insert_application_share_request_info(manifest_x *mfx);
392 static int __insert_application_datacontrol_info(manifest_x *mfx);
393 static void __insert_application_locale_info(gpointer data, gpointer userdata);
394 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
395 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
396 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
397 static int __delete_subpkg_info_from_db(char *appid);
398 static int __delete_appinfo_from_db(char *db_table, const char *appid);
399 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
400 static int __exec_query(char *query);
401 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
402 char **label, char **license, char **icon, char **description, char **author);
403 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
404 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
405 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
406 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
407 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
408 static int __parserdb_change_perm(const char *db_file, uid_t uid);
410 #define REGULAR_USER 5000
411 static inline uid_t _getuid(void)
413 uid_t uid = getuid();
415 if (uid < REGULAR_USER)
416 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
421 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
424 __delete_subpkg_info_from_db(coltxt[0]);
429 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
434 char *error_message = NULL;
436 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
437 if (ret != SQLITE_OK) {
438 _LOGD("connect db [%s] failed!\n", db_path);
443 /* add user_version for db upgrade*/
444 query = sqlite3_mprintf("PRAGMA user_version=%d", (atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 + atoi(TIZEN_PATCH_VER)));
446 sqlite3_exec(handle, query, NULL, NULL, &error_message)) {
447 _LOGE("Don't execute query = %s error message = %s\n", query,
450 sqlite3_free(error_message);
456 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
458 manifest_x *mfx = (manifest_x *)data;
464 if (mfx->application == NULL)
466 app = (application_x *)mfx->application->data;
467 for (i = 0; i < ncols; i++) {
468 if (strcmp(colname[i], "app_id") == 0) {
470 appid = strdup(coltxt[i]);
471 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
473 status = strdup(coltxt[i]);
479 _LOGD("app id is NULL\n");
482 /*update guest mode visibility*/
483 for (tmp = mfx->application; tmp; tmp = tmp->next) {
484 app = (application_x *)tmp->data;
487 if (strcmp(app->appid, appid) == 0) {
488 free((void *)app->guestmode_visibility);
489 app->guestmode_visibility = strdup(status);
505 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
507 char *error_message = NULL;
508 char query[MAX_QUERY_LEN] = {'\0'};
509 sqlite3_snprintf(MAX_QUERY_LEN, query,
510 "SELECT app_id, app_guestmodevisibility FROM package_app_info " \
511 "WHERE package=%Q", mfx->package);
513 sqlite3_exec(pkgmgr_parser_db, query,
514 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
515 _LOGD("Don't execute query = %s error message = %s\n",
516 query, error_message);
517 sqlite3_free(error_message);
522 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
524 char *error_message = NULL;
526 sqlite3_exec(db_handle, db_query,
527 NULL, NULL, &error_message)) {
528 _LOGD("Don't execute query = %s error message = %s\n",
529 db_query, error_message);
530 sqlite3_free(error_message);
533 sqlite3_free(error_message);
537 static int __exec_query(char *query)
539 char *error_message = NULL;
541 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
542 _LOGE("Don't execute query = %s error message = %s\n", query,
544 sqlite3_free(error_message);
547 sqlite3_free(error_message);
549 if (strncmp(query, "DELETE", 6) && sqlite3_changes(pkgmgr_parser_db) == 0) {
550 _LOGE("No such record matches with given query : %s\n", query);
556 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
564 for (tmp = lbls; tmp; tmp = tmp->next) {
565 lbl = (label_x *)tmp->data;
569 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
571 for (tmp = lcns; tmp; tmp = tmp->next) {
572 lcn = (license_x *)tmp->data;
576 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
578 for (tmp = icns; tmp; tmp = tmp->next) {
579 icn = (icon_x *)tmp->data;
583 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
585 for (tmp = dcns; tmp; tmp = tmp->next) {
586 dcn = (description_x *)tmp->data;
590 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
592 for (tmp = aths; tmp; tmp = tmp->next) {
593 ath = (author_x *)tmp->data;
597 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
603 static GList *__create_icon_list(GList *appicon, GList *icns)
608 for (tmp = icns; tmp; tmp = tmp->next) {
609 icn = (icon_x *)tmp->data;
613 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
618 static GList *__create_image_list(GList *appimage, GList *imgs)
623 for (tmp = imgs; tmp; tmp = tmp->next) {
624 img = (image_x *)tmp->data;
628 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
633 static void __trimfunc(GList *trim_list)
635 char *trim_data = NULL;
639 list = g_list_first(trim_list);
642 trim_data = (char *)list->data;
645 if (strcmp(trim_data, prev) == 0) {
646 trim_list = g_list_remove(trim_list, trim_data);
647 list = g_list_first(trim_list);
656 list = g_list_next(list);
660 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
662 if (a == NULL || b == NULL)
664 if (strcmp((char *)a, (char *)b) == 0)
666 if (strcmp((char *)a, (char *)b) < 0)
668 if (strcmp((char *)a, (char *)b) > 0)
673 static int __check_dpi(const char *dpi_char, int dpi_int)
675 if (dpi_char == NULL)
678 if (strcasecmp(dpi_char, LDPI) == 0) {
679 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
683 } else if (strcasecmp(dpi_char, MDPI) == 0) {
684 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
688 } else if (strcasecmp(dpi_char, HDPI) == 0) {
689 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
693 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
694 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
698 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
699 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
707 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
710 char *icon_filename = NULL;
711 char modified_iconpath[BUFSIZE] = { '\0' };
712 char icon_path[BUFSIZE] = { '\0' };
716 if (orig_icon_path == NULL)
719 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
723 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
724 dpi_path[0] = "LDPI";
725 dpi_path[1] = "ldpi";
726 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
727 dpi_path[0] = "MDPI";
728 dpi_path[1] = "mdpi";
729 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
730 dpi_path[0] = "HDPI";
731 dpi_path[1] = "hdpi";
732 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
733 dpi_path[0] = "XHDPI";
734 dpi_path[1] = "xhdpi";
735 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
736 dpi_path[0] = "XXHDPI";
737 dpi_path[1] = "xxhdpi";
739 _LOGE("Unidentified dpi[%d]", dpi);
743 icon_filename = strrchr(orig_icon_path, '/');
744 if (icon_filename == NULL)
747 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
748 for (i = 0; i < 2; i++) {
749 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
750 if (access(modified_iconpath, F_OK) != -1) {
751 /* if exists, return modified icon path */
752 *new_icon_path = strdup(modified_iconpath);
760 static gint __compare_icon(gconstpointer a, gconstpointer b)
762 icon_x *icon = (icon_x *)a;
764 char *icon_folder_path = NULL;
766 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
769 if (icon->dpi != NULL)
772 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
774 icon->text = icon_folder_path;
780 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
782 icon_x *icon = (icon_x *)a;
783 int dpi = GPOINTER_TO_INT(b);
785 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
788 if (icon->dpi == NULL)
791 if (__check_dpi(icon->dpi, dpi) == 0)
797 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
799 icon_x *icon = (icon_x *)a;
800 char *lang = (char *)b;
801 char *icon_folder_path = NULL;
803 if (icon->dpi != NULL)
806 if (strcasecmp(icon->lang, lang) == 0) {
807 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
808 /* icon for no locale. check existance of folder-hierachied default icons */
809 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
811 icon->text = icon_folder_path;
820 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
822 icon_x *icon = (icon_x *)a;
823 char *lang = (char *)b;
826 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
830 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
836 static char *__find_icon(GList *icons, const char *lang)
843 /* first, find icon whose locale and dpi with given lang and system's dpi has matched */
844 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
846 icon = (icon_x *)tmp->data;
847 return (char *)icon->text;
850 /* if first has failed, find icon whose locale has matched */
851 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
853 icon = (icon_x *)tmp->data;
854 return (char *)icon->text;
857 /* if second has failed, find icon whose dpi has matched with system's dpi */
858 ret = system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
859 if (ret == SYSTEM_INFO_ERROR_NONE) {
860 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
862 icon = (icon_x *)tmp->data;
863 return (char *)icon->text;
867 /* last, find default icon marked as "No Locale" */
868 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
870 icon = (icon_x *)tmp->data;
871 return (char *)icon->text;
877 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
878 char **label, char **license, char **icon, char **description, char **author)
885 for (tmp = lbls; tmp; tmp = tmp->next) {
886 lbl = (label_x *)tmp->data;
890 if (strcmp(lbl->lang, (char *)data) == 0) {
891 *label = (char *)lbl->text;
896 for (tmp = lcns; tmp; tmp = tmp->next) {
897 lcn = (license_x *)tmp->data;
901 if (strcmp(lcn->lang, (char *)data) == 0) {
902 *license = (char *)lcn->text;
908 *icon = __find_icon(icns, (char *)data);
910 for (tmp = dcns; tmp; tmp = tmp->next) {
911 dcn = (description_x *)tmp->data;
915 if (strcmp(dcn->lang, (char *)data) == 0) {
916 *description = (char *)dcn->text;
921 for (tmp = aths; tmp; tmp = tmp->next) {
922 ath = (author_x *)tmp->data;
926 if (strcmp(ath->lang, (char *)data) == 0) {
927 *author = (char *)ath->text;
935 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
939 for (tmp = icns; tmp; tmp = tmp->next) {
940 icn = (icon_x *)tmp->data;
944 if (strcmp(icn->section, (char *)data) == 0) {
945 *icon = (char *)icn->text;
946 *resolution = (char *)icn->resolution;
953 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
957 for (tmp = imgs; tmp; tmp = tmp->next) {
958 img = (image_x *)tmp->data;
962 if (strcmp(img->section, (char *)data) == 0) {
963 *lang = (char *)img->lang;
964 *image = (char *)img->text;
971 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
976 char *description = NULL;
977 char *license = NULL;
981 manifest_x *mfx = (manifest_x *)userdata;
982 GList *lbl = mfx->label;
983 GList *lcn = mfx->license;
984 GList *icn = mfx->icon;
985 GList *dcn = mfx->description;
986 GList *ath = mfx->author;
988 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
989 if (!label && !description && !icon && !license && !author)
992 query = sqlite3_mprintf("INSERT INTO package_localized_info(package, package_locale, " \
993 "package_label, package_icon, package_description, package_license, package_author) VALUES" \
994 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1003 ret = __exec_query(query);
1005 _LOGD("Package Localized Info DB Insert failed\n");
1007 sqlite3_free(query);
1010 static void __insert_application_locale_info(gpointer data, gpointer userdata)
1016 char *locale = (char *)data;
1018 application_x *app = (application_x *)userdata;
1019 GList *lbl = app->label;
1020 GList *icn = app->icon;
1022 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1023 if (!label && !icon)
1026 query = sqlite3_mprintf("INSERT INTO package_app_localized_info(app_id, app_locale, " \
1027 "app_label, app_icon) VALUES" \
1028 "(%Q, %Q, %Q, %Q)", app->appid, (char *)data,
1030 ret = __exec_query(query);
1032 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1034 sqlite3_free(query);
1036 /*insert ui app locale info to pkg locale to get mainapp data */
1037 if (strcasecmp(app->mainapp, "true") == 0) {
1038 query = sqlite3_mprintf("INSERT OR REPLACE INTO package_localized_info(package, package_locale, "
1039 "package_label, package_icon, package_description, package_license, package_author) VALUES"
1041 "COALESCE((SELECT package_label FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1042 "COALESCE((SELECT package_icon FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1043 "(SELECT package_description FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1044 "(SELECT package_license FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1045 "(SELECT package_author FROM package_localized_info WHERE package=%Q AND package_locale=%Q))",
1046 app->package, locale,
1047 app->package, locale, label,
1048 app->package, locale, icon,
1049 app->package, locale,
1050 app->package, locale,
1051 app->package, locale);
1053 ret = __exec_query(query);
1055 _LOGE("Package Localized Info DB Insert failed");
1056 sqlite3_free(query);
1060 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1064 char *resolution = NULL;
1065 char query[MAX_QUERY_LEN] = {'\0'};
1067 application_x *app = (application_x *)userdata;
1068 GList *icn = app->icon;
1070 __extract_icon_data(data, icn, &icon, &resolution);
1071 if (!icon && !resolution)
1073 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO package_app_icon_section_info(app_id, " \
1074 "app_icon, app_icon_section, app_icon_resolution) VALUES " \
1075 "(%Q, %Q, %Q, %Q)", app->appid,
1076 icon, (char *)data, resolution);
1078 ret = __exec_query(query);
1080 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1084 static void __insert_application_image_info(gpointer data, gpointer userdata)
1089 char query[MAX_QUERY_LEN] = {'\0'};
1091 application_x *app = (application_x *)userdata;
1092 GList *image = app->image;
1094 __extract_image_data(data, image, &lang, &img);
1097 sqlite3_snprintf(MAX_QUERY_LEN, query,
1098 "INSERT INTO package_app_image_info(app_id, app_locale, " \
1099 "app_image_section, app_image) VALUES" \
1100 "(%Q, %Q, %Q, %Q)", app->appid, lang, (char *)data, img);
1102 ret = __exec_query(query);
1104 _LOGD("Package UiApp image Info DB Insert failed\n");
1109 static int __insert_mainapp_info(manifest_x *mfx)
1114 char query[MAX_QUERY_LEN] = {'\0'};
1115 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1116 app = (application_x *)tmp->data;
1119 if (strcasecmp(app->mainapp, "True") == 0)
1120 mfx->mainapp_id = strdup(app->appid);
1123 if (mfx->mainapp_id == NULL) {
1124 if (mfx->application == NULL)
1126 app = (application_x *)mfx->application->data;
1129 free((void *)app->mainapp);
1130 app->mainapp = strdup("true");
1131 mfx->mainapp_id = strdup(app->appid);
1134 memset(query, '\0', MAX_QUERY_LEN);
1135 sqlite3_snprintf(MAX_QUERY_LEN, query,
1136 "UPDATE package_info SET mainapp_id=%Q WHERE package=%Q", mfx->mainapp_id, mfx->package);
1137 ret = __exec_query(query);
1139 _LOGD("Package Info DB update Failed\n");
1146 static int __convert_background_category(GList *category_list)
1149 GList *tmp_list = category_list;
1150 char *category_data = NULL;
1152 if (category_list == NULL)
1155 while (tmp_list != NULL) {
1156 category_data = (char *)tmp_list->data;
1157 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0)
1158 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1159 else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0)
1160 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1161 else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0)
1162 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1163 else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0)
1164 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1165 else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0)
1166 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1167 else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0)
1168 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1169 else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0)
1170 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1172 _LOGE("Unidentified category [%s]", category_data);
1173 tmp_list = g_list_next(tmp_list);
1179 static const char *__find_effective_appid(GList *metadata_list)
1184 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1185 md = (metadata_x *)tmp_list->data;
1186 if (md == NULL || md->key == NULL)
1189 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1198 static char *__get_bool(char *value, bool is_true)
1200 if (value != NULL) {
1201 if (!strcmp(value, ""))
1202 return (is_true) ? "true" : "false";
1206 return (is_true) ? "true" : "false";
1209 /* _PRODUCT_LAUNCHING_ENHANCED_
1210 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1212 static int __insert_application_info(manifest_x *mfx)
1217 int background_value = 0;
1218 char query[MAX_QUERY_LEN] = {'\0'};
1220 const char *effective_appid;
1223 type = strdup(mfx->type);
1225 type = strdup("tpk");
1227 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1228 app = (application_x *)tmp->data;
1232 background_value = __convert_background_category(app->background_category);
1233 if (background_value < 0) {
1234 _LOGE("Failed to retrieve background value[%d]", background_value);
1235 background_value = 0;
1238 effective_appid = __find_effective_appid(app->metadata);
1240 sqlite3_snprintf(MAX_QUERY_LEN, query,
1241 "INSERT INTO package_app_info(" \
1242 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1243 "app_onboot, app_multiple, app_autorestart, app_taskmanage, " \
1244 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1245 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1246 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1247 "app_launch_mode, app_ui_gadget, app_support_mode, app_support_disable, component_type, package, " \
1248 "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, " \
1249 "app_api_version, app_effective_appid, app_splash_screen_display, app_package_system, app_removable, " \
1250 "app_package_installed_time, app_support_ambient, app_setup_appid) " \
1252 "%Q, %Q, %Q, LOWER(%Q), %Q, " \
1253 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1254 "%Q, %Q, %Q, %Q, %Q, " \
1255 "LOWER(%Q), %Q, %Q, LOWER(%Q), %Q, " \
1256 "LOWER(%Q), LOWER(%Q), %Q, %Q, LOWER(%Q), " \
1257 "COALESCE(%Q, 'caller'), LOWER(%Q), %Q, LOWER(%Q), %Q, %Q, " \
1258 "%Q, %Q, %d, %Q, %Q, " \
1259 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1260 "%Q, LOWER(%Q), %Q)", \
1261 app->appid, app->component_type, app->exec, __get_bool(app->nodisplay, false), app->type,
1262 __get_bool(app->onboot, false), __get_bool(app->multiple, false), __get_bool(app->autorestart, false), __get_bool(app->taskmanage, false),
1263 app->hwacceleration, app->screenreader, app->mainapp, app->recentimage, app->launchcondition,
1264 __get_bool(app->indicatordisplay, true), app->portraitimg, app->landscapeimg,
1265 __get_bool(app->guestmode_visibility, true), app->permission_type,
1266 __get_bool(mfx->preload, false), __get_bool(app->submode, false), app->submode_mainid, mfx->installed_storage, __get_bool(app->process_pool, false),
1267 app->launch_mode, __get_bool(app->ui_gadget, false), mfx->support_mode, __get_bool(mfx->support_disable, false), app->component_type, mfx->package,
1268 mfx->tep_name, mfx->zip_mount_file, background_value, type, mfx->root_path, mfx->api_version,
1269 effective_appid, __get_bool(app->splash_screen_display, false), __get_bool(mfx->system, false), __get_bool(mfx->removable, true),
1270 mfx->installed_time, __get_bool(app->support_ambient, false), app->setup_appid);
1272 ret = __exec_query(query);
1274 _LOGD("Package UiApp Info DB Insert Failed\n");
1279 memset(query, '\0', MAX_QUERY_LEN);
1288 static int __insert_application_appcategory_info(manifest_x *mfx)
1295 char query[MAX_QUERY_LEN] = {'\0'};
1296 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1297 app = (application_x *)app_tmp->data;
1300 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1301 ct = (const char *)ct_tmp->data;
1304 sqlite3_snprintf(MAX_QUERY_LEN, query,
1305 "INSERT INTO package_app_app_category(app_id, category) " \
1308 ret = __exec_query(query);
1310 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1313 memset(query, '\0', MAX_QUERY_LEN);
1319 static int __insert_application_appmetadata_info(manifest_x *mfx)
1326 char query[MAX_QUERY_LEN] = {'\0'};
1327 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1328 app = (application_x *)app_tmp->data;
1331 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1332 md = (metadata_x *)md_tmp->data;
1336 sqlite3_snprintf(MAX_QUERY_LEN, query,
1337 "INSERT INTO package_app_app_metadata(app_id, md_key, md_value) " \
1338 "VALUES(%Q, %Q, %Q)",\
1339 app->appid, md->key, md->value ? md->value : NULL);
1340 ret = __exec_query(query);
1342 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1346 memset(query, '\0', MAX_QUERY_LEN);
1352 static int __insert_application_apppermission_info(manifest_x *mfx)
1359 char query[MAX_QUERY_LEN] = {'\0'};
1360 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1361 app = (application_x *)app_tmp->data;
1364 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1365 pm = (permission_x *)pm_tmp->data;
1368 sqlite3_snprintf(MAX_QUERY_LEN, query,
1369 "INSERT INTO package_app_app_permission(app_id, pm_type, pm_value) " \
1370 "VALUES(%Q, %Q, %Q)",\
1371 app->appid, pm->type, pm->value);
1372 ret = __exec_query(query);
1374 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1377 memset(query, '\0', MAX_QUERY_LEN);
1383 static int __insert_application_appcontrol_info(manifest_x *mfx)
1387 GList *acontrol_tmp;
1388 appcontrol_x *acontrol;
1390 char query[MAX_QUERY_LEN] = {'\0'};
1391 char buf[BUFSIZE] = {'\0'};
1392 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1393 app = (application_x *)app_tmp->data;
1396 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1397 acontrol = (appcontrol_x *)acontrol_tmp->data;
1398 if (acontrol == NULL)
1400 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1401 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1402 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1403 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1404 sqlite3_snprintf(MAX_QUERY_LEN, query,
1405 "INSERT INTO package_app_app_control(app_id, app_control) " \
1408 ret = __exec_query(query);
1410 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1413 memset(query, '\0', MAX_QUERY_LEN);
1419 static int __insert_application_datacontrol_info(manifest_x *mfx)
1426 char query[MAX_QUERY_LEN] = {'\0'};
1428 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1429 app = (application_x *)app_tmp->data;
1432 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1433 dc = (datacontrol_x *)dc_tmp->data;
1436 sqlite3_snprintf(MAX_QUERY_LEN, query,
1437 "INSERT INTO package_app_data_control(app_id, providerid, access, type) " \
1438 "VALUES(%Q, %Q, %Q, %Q)",\
1444 ret = __exec_query(query);
1446 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1449 memset(query, '\0', MAX_QUERY_LEN);
1455 static int __insert_application_share_request_info(manifest_x *mfx)
1464 char query[MAX_QUERY_LEN] = {'\0'};
1465 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1466 app = (application_x *)app_tmp->data;
1469 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1470 ds = (datashare_x *)ds_tmp->data;
1473 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1474 rq = (const char *)rq_tmp->data;
1477 sqlite3_snprintf(MAX_QUERY_LEN, query,
1478 "INSERT INTO package_app_share_request(app_id, data_share_request) " \
1481 ret = __exec_query(query);
1483 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1486 memset(query, '\0', MAX_QUERY_LEN);
1493 static int __insert_application_share_allowed_info(manifest_x *mfx)
1504 char query[MAX_QUERY_LEN] = {'\0'};
1505 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1506 app = (application_x *)app_tmp->data;
1509 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1510 ds = (datashare_x *)ds_tmp->data;
1513 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1514 df = (define_x *)df_tmp->data;
1517 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1518 al = (const char *)al_tmp->data;
1521 sqlite3_snprintf(MAX_QUERY_LEN, query,
1522 "INSERT INTO package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1523 "VALUES(%Q, %Q, %Q)",\
1524 app->appid, df->path, al);
1525 ret = __exec_query(query);
1527 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1530 memset(query, '\0', MAX_QUERY_LEN);
1538 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1540 splashscreen_x *ss = (splashscreen_x *)a;
1541 const char *orientation = (const char *)b;
1544 if (ss->operation || ss->dpi == NULL)
1547 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1551 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1557 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1559 splashscreen_x *ss = (splashscreen_x *)a;
1560 const char *orientation = (const char *)b;
1562 if (ss->operation || ss->dpi)
1565 if (strcasecmp(ss->orientation, orientation) == 0)
1571 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1572 const char *orientation)
1576 tmp = g_list_find_custom(splashscreens, orientation,
1577 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1579 return (splashscreen_x *)tmp->data;
1581 tmp = g_list_find_custom(splashscreens, orientation,
1582 (GCompareFunc)__compare_splashscreen_with_orientation);
1584 return (splashscreen_x *)tmp->data;
1589 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1591 splashscreen_x *ss = (splashscreen_x *)data;
1592 GList **list = (GList **)user_data;
1595 if (ss->operation == NULL || ss->dpi == NULL)
1598 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1602 if (__check_dpi(ss->dpi, dpi) != 0)
1605 *list = g_list_append(*list, ss);
1608 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1610 splashscreen_x *ss = (splashscreen_x *)data;
1611 GList **list = (GList **)user_data;
1612 splashscreen_x *ss_tmp;
1615 if (ss->operation == NULL || ss->dpi)
1618 for (tmp = *list; tmp; tmp = tmp->next) {
1619 ss_tmp = (splashscreen_x *)tmp->data;
1620 if (ss_tmp->operation
1621 && strcmp(ss_tmp->operation, ss->operation) == 0
1622 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1626 *list = g_list_append(*list, ss);
1629 static GList *__find_splashscreens(GList *splashscreens)
1634 g_list_foreach(splashscreens,
1635 __find_appcontrol_splashscreen_with_dpi, &list);
1636 g_list_foreach(splashscreens,
1637 __find_appcontrol_splashscreen, &list);
1639 ss = __find_default_splashscreen(splashscreens, "portrait");
1641 list = g_list_append(list, ss);
1642 ss = __find_default_splashscreen(splashscreens, "landscape");
1644 list = g_list_append(list, ss);
1649 static int __insert_application_splashscreen_info(manifest_x *mfx)
1657 char query[MAX_QUERY_LEN] = {'\0'};
1659 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1660 app = (application_x *)app_tmp->data;
1661 if (app == NULL || app->splashscreens == NULL)
1664 ss_tmp = __find_splashscreens(app->splashscreens);
1668 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1669 ss = (splashscreen_x *)tmp->data;
1670 sqlite3_snprintf(MAX_QUERY_LEN, query,
1671 "INSERT INTO package_app_splash_screen" \
1672 "(app_id, src, type, orientation, indicatordisplay, " \
1673 "operation, color_depth) " \
1674 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1675 app->appid, ss->src, ss->type, ss->orientation,
1676 ss->indicatordisplay, ss->operation,
1679 ret = __exec_query(query);
1681 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1684 memset(query, '\0', MAX_QUERY_LEN);
1686 g_list_free(ss_tmp);
1691 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1695 privilege_x *pv = NULL;
1696 char query[MAX_QUERY_LEN] = { '\0' };
1699 const char *auth_name = NULL;
1700 const char *auth_email = NULL;
1701 const char *auth_href = NULL;
1703 GList *pkglocale = NULL;
1704 GList *applocale = NULL;
1705 GList *appicon = NULL;
1706 GList *appimage = NULL;
1708 int temp_pkg_mode = 0;
1709 int temp_app_mode = 0;
1710 char pkg_mode[MAX_INTEGER_LENGTH] = {'\0'};
1711 application_x *up_support_mode = NULL;
1712 GList *list_up = NULL;
1714 if (mfx->author && mfx->author->data) {
1715 author = (author_x *)mfx->author->data;
1717 auth_name = author->text;
1719 auth_email = author->email;
1721 auth_href = author->href;
1724 if (mfx->support_mode)
1725 temp_pkg_mode = atoi(mfx->support_mode);
1727 /* FIXME : OR-ing should be fixed to not to store whole support mode */
1728 list_up = mfx->application;
1729 while (list_up != NULL) {
1730 up_support_mode = (application_x *)list_up->data;
1731 if (up_support_mode->support_mode) {
1732 temp_app_mode = atoi(up_support_mode->support_mode);
1733 temp_pkg_mode |= temp_app_mode;
1735 list_up = list_up->next;
1737 snprintf(pkg_mode, MAX_INTEGER_LENGTH, "%d", temp_pkg_mode);
1739 if (mfx->support_mode)
1740 free((void *)mfx->support_mode);
1741 mfx->support_mode = strdup(pkg_mode);
1743 /*Insert in the package_info DB*/
1744 sqlite3_snprintf(MAX_QUERY_LEN, query,
1745 "INSERT INTO package_info(" \
1746 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1747 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1748 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1749 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1750 "mainapp_id, package_url, root_path, csc_path, package_support_mode, package_support_disable) " \
1752 "%Q, %Q, %Q, %Q, %Q, %Q, " \
1753 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1754 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), %Q, " \
1755 "%Q, %Q, %Q, %Q, %Q, " \
1756 "%Q, %Q, %Q, %Q, %Q, LOWER(%Q))",
1757 mfx->package, mfx->type, mfx->version, mfx->api_version, mfx->tep_name, mfx->zip_mount_file,
1758 mfx->installlocation, mfx->package_size, __get_bool(mfx->removable, true), __get_bool(mfx->preload, false), __get_bool(mfx->readonly, false),
1759 __get_bool(mfx->update, false), __get_bool(mfx->appsetting, false), __get_bool(mfx->nodisplay_setting, false), __get_bool(mfx->system, false), auth_name,
1760 auth_email, auth_href, mfx->installed_time, mfx->installed_storage,
1761 mfx->storeclient_id,
1762 mfx->mainapp_id, mfx->package_url, mfx->root_path, mfx->csc_path, mfx->support_mode, __get_bool(mfx->support_disable, false));
1764 ret = __exec_query(query);
1766 _LOGD("Package Info DB Insert Failed\n");
1770 /*Insert in the package_privilege_info DB*/
1771 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1772 pv = (privilege_x *)tmp->data;
1775 memset(query, '\0', MAX_QUERY_LEN);
1776 sqlite3_snprintf(MAX_QUERY_LEN, query,
1777 "INSERT INTO package_privilege_info(package, privilege, type) " \
1778 "VALUES(%Q, %Q, %Q)",\
1779 mfx->package, pv->value, pv->type);
1780 ret = __exec_query(query);
1782 _LOGD("Package Privilege Info DB Insert Failed\n");
1787 if (mfx->application != NULL) {
1788 ret = __insert_mainapp_info(mfx);
1793 /*Insert the package locale*/
1794 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1795 /*remove duplicated data in pkglocale*/
1796 __trimfunc(pkglocale);
1798 /*Insert the app locale, icon, image info */
1799 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1800 app = (application_x *)tmp->data;
1803 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1804 appicon = __create_icon_list(appicon, app->icon);
1805 appimage = __create_image_list(appimage, app->image);
1807 /*remove duplicated data in applocale*/
1808 __trimfunc(applocale);
1809 __trimfunc(appicon);
1810 __trimfunc(appimage);
1812 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1814 /*native app locale info*/
1815 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1816 app = (application_x *)tmp->data;
1819 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1820 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1821 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1824 g_list_free(pkglocale);
1826 g_list_free(applocale);
1828 g_list_free(appicon);
1830 g_list_free(appimage);
1833 /*Insert in the package_app_info DB*/
1834 ret = __insert_application_info(mfx);
1837 /*Insert in the package_app_app_control DB*/
1838 ret = __insert_application_appcontrol_info(mfx);
1842 /*Insert in the package_app_app_category DB*/
1843 ret = __insert_application_appcategory_info(mfx);
1847 /*Insert in the package_app_app_metadata DB*/
1848 ret = __insert_application_appmetadata_info(mfx);
1852 /*Insert in the package_app_app_permission DB*/
1853 ret = __insert_application_apppermission_info(mfx);
1857 /*Insert in the package_app_share_allowed DB*/
1858 ret = __insert_application_share_allowed_info(mfx);
1862 /*Insert in the package_app_share_request DB*/
1863 ret = __insert_application_share_request_info(mfx);
1867 /*Insert in the package_app_data_control DB*/
1868 ret = __insert_application_datacontrol_info(mfx);
1872 /*Insert in the package_app_splash_screen DB*/
1873 ret = __insert_application_splashscreen_info(mfx);
1881 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1883 char query[MAX_QUERY_LEN] = { '\0' };
1886 sqlite3_snprintf(MAX_QUERY_LEN, query,
1887 "DELETE FROM %q where app_id=%Q", db_table, appid);
1888 ret = __exec_query(query);
1890 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1896 static int __delete_subpkg_info_from_db(char *appid)
1900 ret = __delete_appinfo_from_db("package_app_info", appid);
1903 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1906 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1909 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1912 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1915 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1918 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1921 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1924 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1927 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1930 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1933 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
1940 static int __delete_subpkg_from_db(manifest_x *mfx)
1942 char query[MAX_QUERY_LEN] = { '\0' };
1943 char *error_message = NULL;
1945 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT app_id FROM package_app_info WHERE package=%Q", mfx->package);
1947 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1948 _LOGE("Don't execute query = %s error message = %s\n", query,
1950 sqlite3_free(error_message);
1953 sqlite3_free(error_message);
1958 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1960 char query[MAX_QUERY_LEN] = { '\0' };
1965 /*Delete from Package Info DB*/
1966 sqlite3_snprintf(MAX_QUERY_LEN, query,
1967 "DELETE FROM package_info WHERE package=%Q", mfx->package);
1968 ret = __exec_query(query);
1970 _LOGD("Package Info DB Delete Failed\n");
1973 memset(query, '\0', MAX_QUERY_LEN);
1975 /*Delete from Package Localized Info*/
1976 sqlite3_snprintf(MAX_QUERY_LEN, query,
1977 "DELETE FROM package_localized_info WHERE package=%Q", mfx->package);
1978 ret = __exec_query(query);
1980 _LOGD("Package Localized Info DB Delete Failed\n");
1984 /*Delete from Package Privilege Info*/
1985 sqlite3_snprintf(MAX_QUERY_LEN, query,
1986 "DELETE FROM package_privilege_info WHERE package=%Q", mfx->package);
1987 ret = __exec_query(query);
1989 _LOGD("Package Privilege Info DB Delete Failed\n");
1993 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1994 app = (application_x *)tmp->data;
1997 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2000 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2003 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2006 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2009 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2012 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2015 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2018 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2021 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2024 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2027 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2030 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2035 /* if main package has sub pkg, delete sub pkg data*/
2036 __delete_subpkg_from_db(mfx);
2041 static int __disable_app(const char *appid)
2044 char query[MAX_QUERY_LEN] = {'\0'};
2045 sqlite3_snprintf(MAX_QUERY_LEN, query,
2046 "UPDATE package_app_info SET app_disable='true' WHERE app_id=%Q",
2048 ret = __exec_query(query);
2050 _LOGD("Insert global app disable failed\n");
2055 static int __enable_app(const char *appid)
2058 char query[MAX_QUERY_LEN] = {'\0'};
2059 sqlite3_snprintf(MAX_QUERY_LEN, query,
2060 "UPDATE package_app_info SET app_disable='false' WHERE app_id=%Q",
2062 ret = __exec_query(query);
2064 _LOGD("Insert global app disable failed\n");
2069 static int __disable_pkg(const char *pkgid)
2072 char query[MAX_QUERY_LEN] = {'\0'};
2073 sqlite3_snprintf(MAX_QUERY_LEN, query,
2074 "UPDATE package_info SET package_disable='true' WHERE package=%Q",
2076 ret = __exec_query(query);
2078 _LOGD("Update pkg disable info has failed\n");
2083 static int __enable_pkg(const char *pkgid)
2086 char query[MAX_QUERY_LEN] = {'\0'};
2087 sqlite3_snprintf(MAX_QUERY_LEN, query,
2088 "UPDATE package_info SET package_disable='false' WHERE package=%Q",
2090 ret = __exec_query(query);
2092 _LOGD("Update pkg disable info has failed\n");
2097 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2100 char query[MAX_QUERY_LEN] = { '\0', };
2102 const char *val = NULL;
2107 sqlite3_snprintf(MAX_QUERY_LEN, query,
2108 "SELECT COUNT(*) FROM "
2109 "package_app_info_for_uid WHERE app_id=%Q "
2110 "AND uid=%d", appid, (int)uid);
2112 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2113 if (ret != SQLITE_OK) {
2114 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2115 return PMINFO_R_ERROR;
2118 if (sqlite3_step(stmt) != SQLITE_ROW) {
2119 LOGE("failed to step");
2120 sqlite3_finalize(stmt);
2121 return PMINFO_R_ERROR;
2124 val = (const char *)sqlite3_column_text(stmt, 0);
2126 sqlite3_finalize(stmt);
2131 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2134 char query[MAX_QUERY_LEN] = { '\0', };
2136 ret = __check_appinfo_for_uid_table(appid, uid);
2138 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2141 } else if (ret == 0) {
2142 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2143 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2144 "VALUES(%Q, %d, 'true', "
2145 "(SELECT app_splash_screen_display FROM package_app_info WHERE app_id=%Q))",
2146 appid, (int)uid, appid);
2148 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2149 "package_app_info_for_uid SET is_disabled='true' "
2150 "WHERE app_id=%Q AND uid=%d", appid, (int)uid);
2153 ret = __exec_query(query);
2155 _LOGD("Add global app disable info failed\n");
2160 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2163 char query[MAX_QUERY_LEN] = {'\0'};
2165 ret = __check_appinfo_for_uid_table(appid, uid);
2167 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2170 } else if (ret > 0) {
2171 sqlite3_snprintf(MAX_QUERY_LEN, query,
2172 "UPDATE package_app_info_for_uid SET "
2173 "is_disabled='false' WHERE app_id=%Q AND "
2174 "uid=%d", appid, (int)uid);
2177 ret = __exec_query(query);
2179 _LOGD("Remove global app disable info failed\n");
2184 static int __update_global_app_splash_screen_for_user(const char *appid,
2185 uid_t uid, int flag)
2188 char query[MAX_QUERY_LEN] = { '\0', };
2190 ret = __check_appinfo_for_uid_table(appid, uid);
2192 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2195 } else if (ret == 0) {
2196 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2197 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2198 "VALUES(%Q, %d, %Q)", appid, (int)uid,
2199 flag ? "true" : "false");
2201 sqlite3_snprintf(MAX_QUERY_LEN, query,
2202 "UPDATE package_app_info_for_uid SET "
2203 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2204 "uid=%d", flag ? "true" : "false", appid, (int)uid);
2207 ret = __exec_query(query);
2209 _LOGD("update global app splash screen info failed\n");
2214 static int __disable_app_splash_screen(const char *appid)
2217 char query[MAX_QUERY_LEN] = {'\0'};
2219 sqlite3_snprintf(MAX_QUERY_LEN, query,
2220 "UPDATE package_app_info SET app_splash_screen_display='false' WHERE app_id=%Q",
2222 ret = __exec_query(query);
2224 _LOGD("Failed to update app_palsh_screen_display");
2229 static int __enable_app_splash_screen(const char *appid)
2232 char query[MAX_QUERY_LEN] = {'\0'};
2234 sqlite3_snprintf(MAX_QUERY_LEN, query,
2235 "UPDATE package_app_info SET app_splash_screen_display='true' WHERE app_id=%Q",
2237 ret = __exec_query(query);
2239 _LOGD("Failed to update app_splash_screen_display");
2244 API int pkgmgr_parser_initialize_db(uid_t uid)
2250 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2252 _LOGD("package info DB initialization failed\n");
2255 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2257 _LOGD("package localized info DB initialization failed\n");
2260 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2262 _LOGD("package app app privilege DB initialization failed\n");
2265 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2267 _LOGD("package app info DB initialization failed\n");
2270 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2272 _LOGD("package app localized info DB initialization failed\n");
2275 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2277 _LOGD("package app icon localized info DB initialization failed\n");
2280 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2282 _LOGD("package app image info DB initialization failed\n");
2285 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2287 _LOGD("package app app control DB initialization failed\n");
2290 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2292 _LOGD("package app app category DB initialization failed\n");
2295 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2297 _LOGD("package app app category DB initialization failed\n");
2300 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2302 _LOGD("package app app permission DB initialization failed\n");
2305 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2307 _LOGD("package app share allowed DB initialization failed\n");
2310 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2312 _LOGD("package app share request DB initialization failed\n");
2315 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2317 _LOGD("package app data control DB initialization failed\n");
2321 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2323 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2327 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2329 _LOGD("package app splash screen DB initialization failed\n");
2333 /* Trigger package_app_info_for_uid */
2334 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2336 _LOGD("package app info for uid DB initialization failed\n");
2341 /* TODO: refactor this code */
2342 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2344 _LOGD("package cert info DB initialization failed\n");
2347 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2349 _LOGD("package cert index info DB initialization failed\n");
2352 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO);
2354 _LOGD("package cert info DB initialization failed\n");
2357 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2);
2359 _LOGD("package cert info DB initialization failed\n");
2362 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2364 _LOGD("package cert info DB initialization failed\n");
2367 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2369 _LOGD("package cert index info DB initialization failed\n");
2373 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2374 if (db_path == NULL) {
2375 _LOGD("Failed to get user cert db path - GLOBAL_USER");
2377 ret = __parserdb_change_perm(db_path, GLOBAL_USER);
2379 _LOGD("Failed to change cert db permission");
2383 db_path = getUserPkgParserDBPathUID(uid);
2384 if (db_path == NULL) {
2385 _LOGD("Failed to get user pkg parser db path - %d", uid);
2387 ret = __parserdb_change_perm(db_path, uid);
2389 _LOGD("Failed to change parser db permission\n");
2396 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2399 char pwuid_buf[1024];
2400 char journal_file[BUFSIZE];
2405 struct passwd userinfo, *result = NULL;
2406 files[0] = (char *)db_file;
2407 files[1] = journal_file;
2411 if (db_file == NULL)
2414 if (getuid() != OWNER_ROOT) /* At this time we should be root to apply this */
2416 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2417 if (uid == OWNER_ROOT || uid == GLOBAL_USER) {
2418 ret = getpwnam_r(APPFW_USER, &userinfo, buf, sizeof(buf), &result);
2419 if (ret != 0 || result == NULL)
2421 uid = userinfo.pw_uid;
2424 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2425 if (ret != 0 || result == NULL) {
2426 _LOGE("FAIL: user %d doesn't exist", uid);
2429 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2431 for (i = 0; files[i]; i++) {
2432 fd = open(files[i], O_RDONLY);
2434 if (strerror_r(errno, buf, sizeof(buf)))
2435 strncpy(buf, "", BUFSIZE - 1);
2436 _LOGD("FAIL : open %s : %s", files[i], buf);
2439 ret = fstat(fd, &sb);
2441 if (strerror_r(errno, buf, sizeof(buf)))
2442 strncpy(buf, "", BUFSIZE - 1);
2443 _LOGD("FAIL : fstat %s : %s", files[i], buf);
2447 if (S_ISLNK(sb.st_mode)) {
2448 _LOGE("FAIL : %s is symlink!", files[i]);
2452 ret = fchown(fd, uid, userinfo.pw_gid);
2454 if (strerror_r(errno, buf, sizeof(buf)))
2455 strncpy(buf, "", BUFSIZE - 1);
2456 _LOGD("FAIL : fchown %s %d.%d : %s", files[i], uid,
2457 userinfo.pw_gid, buf);
2462 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2463 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2465 ret = fchmod(fd, mode);
2467 if (strerror_r(errno, buf, sizeof(buf)))
2468 strncpy(buf, "", BUFSIZE - 1);
2469 _LOGD("FAIL : fchmod %s 0664 : %s", files[i], buf);
2474 SET_SMACK_LABEL(files[i]);
2479 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2484 if (getuid() != OWNER_ROOT) {
2485 _LOGE("Only root user is allowed");
2489 db_path = getUserPkgParserDBPathUID(uid);
2490 if (db_path == NULL) {
2491 _LOGE("Failed to get pkg parser db path - %d", uid);
2495 if (access(db_path, F_OK) != -1) {
2496 _LOGE("Manifest db for user %d is already exists", uid);
2502 db_path = getUserPkgCertDBPathUID(uid);
2503 if (db_path == NULL) {
2504 _LOGE("Failed to get pkg cert db path - %d", uid);
2508 if (access(db_path, F_OK) != -1) {
2509 _LOGE("Cert db for user %d is already exists", uid);
2515 ret = pkgmgr_parser_check_and_create_db(uid);
2518 ret = pkgmgr_parser_initialize_db(uid);
2520 pkgmgr_parser_close_db();
2523 pkgmgr_parser_close_db();
2528 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2533 db_path = getUserPkgParserDBPathUID(uid);
2534 if (db_path == NULL) {
2535 _LOGD("Failed to get pkg parser db path - %d", uid);
2540 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, db_path);
2542 _LOGD("Manifest DB creation Failed\n");
2548 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2549 if (db_path == NULL) {
2550 _LOGE("Failed to get pkg cert db path - GLOBAL_USER");
2555 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, db_path);
2557 _LOGD("Cert DB creation Failed\n");
2567 void pkgmgr_parser_close_db(void)
2569 sqlite3_close(pkgmgr_parser_db);
2570 sqlite3_close(pkgmgr_cert_db);
2574 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2576 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2578 _LOGD("manifest pointer is NULL\n");
2582 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2584 _LOGD("Failed to open DB\n");
2587 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2590 /*Begin transaction*/
2591 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2592 if (ret != SQLITE_OK) {
2593 _LOGD("Failed to begin transaction\n");
2597 _LOGD("Transaction Begin\n");
2598 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2600 _LOGD("Insert into DB failed. Rollback now\n");
2601 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2604 /*Commit transaction*/
2605 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2606 if (ret != SQLITE_OK) {
2607 _LOGD("Failed to commit transaction. Rollback now\n");
2608 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2612 _LOGD("Transaction Commit and End\n");
2614 pkgmgr_parser_close_db();
2618 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2620 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2622 _LOGD("manifest pointer is NULL\n");
2626 ret = pkgmgr_parser_check_and_create_db(uid);
2628 _LOGD("Failed to open DB\n");
2631 ret = pkgmgr_parser_initialize_db(uid);
2634 /*Begin transaction*/
2635 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2636 if (ret != SQLITE_OK) {
2637 _LOGD("Failed to begin transaction\n");
2641 _LOGD("Transaction Begin\n");
2642 ret = __insert_manifest_info_in_db(mfx, uid);
2644 _LOGD("Insert into DB failed. Rollback now\n");
2645 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2648 /*Commit transaction*/
2649 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2650 if (ret != SQLITE_OK) {
2651 _LOGD("Failed to commit transaction. Rollback now\n");
2652 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2656 _LOGD("Transaction Commit and End\n");
2658 pkgmgr_parser_close_db();
2662 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2664 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, _getuid());
2667 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2669 if (pkgid == NULL || tep_path == NULL) {
2670 _LOGE("invalid parameter");
2677 ret = pkgmgr_parser_check_and_create_db(uid);
2679 _LOGD("Failed to open DB\n");
2682 ret = pkgmgr_parser_initialize_db(uid);
2686 /*Begin transaction*/
2687 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2688 if (ret != SQLITE_OK) {
2689 _LOGD("Failed to begin transaction\n");
2693 _LOGD("Transaction Begin\n");
2696 /* Updating TEP info in "package_info" table */
2697 query = sqlite3_mprintf("UPDATE package_info "\
2698 "SET package_tep_name = %Q "\
2699 "WHERE package = %Q", tep_path, pkgid);
2701 ret = __exec_query(query);
2702 sqlite3_free(query);
2703 if (ret != SQLITE_OK) {
2704 ret = PM_PARSER_R_ERROR;
2705 _LOGE("sqlite exec failed to insert entries into package_info!!");
2709 /* Updating TEP info in "package_app_info" table */
2710 query = sqlite3_mprintf("UPDATE package_app_info "\
2711 "SET app_tep_name = %Q "\
2712 "WHERE package = %Q", tep_path, pkgid);
2714 ret = __exec_query(query);
2715 sqlite3_free(query);
2716 if (ret != SQLITE_OK) {
2717 ret = PM_PARSER_R_ERROR;
2718 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2722 /*Commit transaction*/
2723 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2724 if (ret != SQLITE_OK) {
2725 _LOGE("Failed to commit transaction, Rollback now\n");
2726 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2727 if (ret != SQLITE_OK)
2728 _LOGE("Failed to Rollback\n");
2730 ret = PM_PARSER_R_ERROR;
2733 _LOGD("Transaction Commit and End\n");
2734 ret = PM_PARSER_R_OK;
2737 pkgmgr_parser_close_db();
2742 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2745 _LOGD("manifest pointer is NULL\n");
2749 ret = pkgmgr_parser_check_and_create_db(uid);
2751 _LOGD("Failed to open DB\n");
2754 ret = pkgmgr_parser_initialize_db(uid);
2757 /*Preserve guest mode visibility*/
2758 __preserve_guestmode_visibility_value(mfx);
2759 /*Begin transaction*/
2760 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2761 if (ret != SQLITE_OK) {
2762 _LOGD("Failed to begin transaction\n");
2766 _LOGD("Transaction Begin\n");
2767 ret = __delete_manifest_info_from_db(mfx, uid);
2769 _LOGD("Delete from DB failed. Rollback now\n");
2770 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2773 ret = __insert_manifest_info_in_db(mfx, uid);
2775 _LOGD("Insert into DB failed. Rollback now\n");
2776 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2780 /*Commit transaction*/
2781 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2782 if (ret != SQLITE_OK) {
2783 _LOGD("Failed to commit transaction. Rollback now\n");
2784 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2788 _LOGD("Transaction Commit and End\n");
2790 pkgmgr_parser_close_db();
2794 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2796 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2799 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2802 _LOGD("manifest pointer is NULL\n");
2806 ret = pkgmgr_parser_check_and_create_db(uid);
2808 _LOGD("Failed to open DB\n");
2811 /*Begin transaction*/
2812 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2813 if (ret != SQLITE_OK) {
2814 _LOGD("Failed to begin transaction\n");
2818 _LOGD("Transaction Begin\n");
2819 ret = __delete_manifest_info_from_db(mfx, uid);
2821 _LOGD("Delete from DB failed. Rollback now\n");
2822 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2825 /*Commit transaction*/
2826 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2827 if (ret != SQLITE_OK) {
2828 _LOGD("Failed to commit transaction, Rollback now\n");
2829 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2833 _LOGD("Transaction Commit and End\n");
2835 pkgmgr_parser_close_db();
2839 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2841 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
2844 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2848 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2850 _LOGD("Failed to open DB\n");
2854 /*Begin transaction*/
2855 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2856 if (ret != SQLITE_OK) {
2857 _LOGD("Failed to begin transaction\n");
2861 _LOGD("Transaction Begin\n");
2863 ret = __disable_global_app_for_user(appid, uid);
2865 ret = __enable_global_app_for_user(appid, uid);
2867 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2868 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2871 /*Commit transaction*/
2872 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2873 if (ret != SQLITE_OK) {
2874 _LOGD("Failed to commit transaction, Rollback now\n");
2875 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2879 _LOGD("Transaction Commit and End\n");
2881 pkgmgr_parser_close_db();
2886 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2888 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
2891 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid, uid_t uid, int is_disable)
2895 ret = pkgmgr_parser_check_and_create_db(uid);
2897 _LOGD("Failed to open DB\n");
2901 /*Begin transaction*/
2902 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2903 if (ret != SQLITE_OK) {
2904 _LOGD("Failed to begin transaction\n");
2909 _LOGD("Transaction Begin\n");
2911 ret = __disable_pkg(pkgid);
2913 ret = __enable_pkg(pkgid);
2916 _LOGD("__update_pkg_disable_condition_in_db failed. Rollback now\n");
2917 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2921 /*Commit transaction*/
2922 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2923 if (ret != SQLITE_OK) {
2924 _LOGD("Failed to commit transaction, Rollback now\n");
2925 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2929 _LOGD("Transaction Commit and End\n");
2932 pkgmgr_parser_close_db();
2936 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid, int is_disable)
2938 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid, _getuid(), is_disable);
2941 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2945 ret = pkgmgr_parser_check_and_create_db(uid);
2947 _LOGD("Failed to open DB\n");
2951 /*Begin transaction*/
2952 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2953 if (ret != SQLITE_OK) {
2954 _LOGD("Failed to begin transaction\n");
2958 _LOGD("Transaction Begin\n");
2960 ret = __disable_app(appid);
2962 ret = __enable_app(appid);
2964 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2965 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2968 /*Commit transaction*/
2969 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2970 if (ret != SQLITE_OK) {
2971 _LOGD("Failed to commit transaction, Rollback now\n");
2972 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2976 _LOGD("Transaction Commit and End\n");
2978 pkgmgr_parser_close_db();
2983 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
2987 if (appid == NULL) {
2988 _LOGD("Invalid parameter");
2992 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2994 _LOGD("Failed to open DB\n");
2998 /* Begin transaction */
2999 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3000 if (ret != SQLITE_OK) {
3001 _LOGD("Failed to begin transaction\n");
3005 _LOGD("Transaction Begin\n");
3007 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3009 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3010 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3013 /* Commit transaction */
3014 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3015 if (ret != SQLITE_OK) {
3016 _LOGD("Failed to commit transaction, Rollback now\n");
3017 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3021 _LOGD("Transaction Commit and End\n");
3023 pkgmgr_parser_close_db();
3027 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3029 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3032 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3036 if (appid == NULL) {
3037 _LOGD("Invalid parameter");
3041 ret = pkgmgr_parser_check_and_create_db(uid);
3043 _LOGD("Failed to open DB");
3047 /* Begin transaction */
3048 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3049 if (ret != SQLITE_OK) {
3050 _LOGD("Failed to begin transaction");
3054 _LOGD("Transaction Begin");
3057 ret = __enable_app_splash_screen(appid);
3059 ret = __disable_app_splash_screen(appid);
3061 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
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");
3069 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3073 _LOGD("Transaction Commit and End");
3076 pkgmgr_parser_close_db();
3080 API int pkgmgr_parser_update_app_label_info_in_usr_db(const char *appid, uid_t uid, const char *label)
3083 char query[MAX_QUERY_LEN] = {'\0'};
3085 if (appid == NULL || label == NULL) {
3086 _LOGE("Invalid parameter");
3090 ret = pkgmgr_parser_check_and_create_db(uid);
3092 _LOGD("Failed to open DB");
3096 /*Begin transaction*/
3097 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3098 if (ret != SQLITE_OK) {
3099 _LOGD("Failed to begin transaction\n");
3104 sqlite3_snprintf(MAX_QUERY_LEN, query,
3105 "UPDATE package_app_localized_info SET app_label=%Q WHERE " \
3106 "app_id=%Q AND app_label IS NOT NULL",
3108 ret = __exec_query(query);
3110 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3114 /* Commit transaction */
3115 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3116 if (ret != SQLITE_OK) {
3117 _LOGD("Failed to commit transaction, Rollback now");
3118 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3122 _LOGD("Transaction Commit and End");
3125 pkgmgr_parser_close_db();
3129 API int pkgmgr_parser_update_app_label_info_in_db(const char *appid, const char *label)
3131 return pkgmgr_parser_update_app_label_info_in_usr_db(appid, _getuid(), label);