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 "FOREIGN KEY(package) " \
185 "REFERENCES package_info(package) " \
188 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_app_localized_info " \
189 "(app_id TEXT NOT NULL, " \
190 "app_locale TEXT NOT NULL DEFAULT 'No Locale', " \
193 "PRIMARY KEY(app_id,app_locale) " \
194 "FOREIGN KEY(app_id) " \
195 "REFERENCES package_app_info(app_id) " \
198 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "CREATE TABLE IF NOT EXISTS package_app_icon_section_info " \
199 "(app_id TEXT NOT NULL, " \
201 "app_icon_section TEXT NOT NULL, " \
202 "app_icon_resolution TEXT NOT NULL, " \
203 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
204 "FOREIGN KEY(app_id) " \
205 "REFERENCES package_app_info(app_id) " \
208 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "CREATE TABLE IF NOT EXISTS package_app_image_info " \
209 "(app_id TEXT NOT NULL, " \
210 "app_locale TEXT DEFAULT 'No Locale', " \
211 "app_image_section TEXT NOT NULL, " \
213 "PRIMARY KEY(app_id,app_image_section) " \
214 "FOREIGN KEY(app_id) " \
215 "REFERENCES package_app_info(app_id) " \
218 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "CREATE TABLE IF NOT EXISTS package_app_app_control " \
219 "(app_id TEXT NOT NULL, " \
220 "app_control TEXT NOT NULL, " \
221 "PRIMARY KEY(app_id,app_control) " \
222 "FOREIGN KEY(app_id) " \
223 "REFERENCES package_app_info(app_id) " \
226 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "CREATE TABLE IF NOT EXISTS package_app_app_category " \
227 "(app_id TEXT NOT NULL, " \
228 "category TEXT NOT NULL, " \
229 "PRIMARY KEY(app_id,category) " \
230 "FOREIGN KEY(app_id) " \
231 "REFERENCES package_app_info(app_id) " \
234 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "CREATE TABLE IF NOT EXISTS package_app_app_metadata " \
235 "(app_id TEXT NOT NULL, " \
236 "md_key TEXT NOT NULL, " \
238 "PRIMARY KEY(app_id, md_key, md_value) " \
239 "FOREIGN KEY(app_id) " \
240 "REFERENCES package_app_info(app_id) " \
243 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "CREATE TABLE IF NOT EXISTS package_app_app_permission " \
244 "(app_id TEXT NOT NULL, " \
245 "pm_type TEXT NOT NULL, " \
246 "pm_value TEXT NOT NULL, " \
247 "PRIMARY KEY(app_id, pm_type, pm_value) " \
248 "FOREIGN KEY(app_id) " \
249 "REFERENCES package_app_info(app_id) " \
252 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "CREATE TABLE IF NOT EXISTS package_app_share_allowed " \
253 "(app_id TEXT NOT NULL, " \
254 "data_share_path TEXT NOT NULL, " \
255 "data_share_allowed TEXT NOT NULL, " \
256 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
257 "FOREIGN KEY(app_id) " \
258 "REFERENCES package_app_info(app_id) " \
261 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "CREATE TABLE IF NOT EXISTS package_app_share_request " \
262 "(app_id TEXT NOT NULL, " \
263 "data_share_request TEXT NOT NULL, " \
264 "PRIMARY KEY(app_id,data_share_request) " \
265 "FOREIGN KEY(app_id) " \
266 "REFERENCES package_app_info(app_id) " \
269 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "CREATE TABLE IF NOT EXISTS package_app_data_control " \
270 "(app_id TEXT NOT NULL, " \
271 "providerid TEXT NOT NULL, " \
272 "access TEXT NOT NULL, " \
273 "type TEXT NOT NULL, " \
274 "PRIMARY KEY(app_id, providerid, access, type) " \
275 "FOREIGN KEY(app_id) " \
276 "REFERENCES package_app_info(app_id) " \
279 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
280 "(app_id TEXT NOT NULL, " \
281 "uid INTEGER NOT NULL, " \
282 "is_disabled TEXT NOT NULL DEFAULT 'false', " \
283 "is_splash_screen_enabled TEXT NOT NULL, " \
284 "PRIMARY KEY(app_id, uid))"
286 #define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
287 "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
288 "AFTER UPDATE ON package_app_info_for_uid " \
290 " DELETE FROM package_app_info_for_uid WHERE " \
291 " is_splash_screen_enabled=" \
292 " (SELECT package_app_info.app_splash_screen_display FROM " \
293 " package_app_info, package_app_info_for_uid WHERE " \
294 " package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
297 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
298 "CREATE TABLE IF NOT EXISTS package_app_splash_screen " \
299 "(app_id TEXT NOT NULL, " \
300 "src TEXT NOT NULL, " \
301 "type TEXT NOT NULL, " \
302 "orientation TEXT NOT NULL, " \
303 "indicatordisplay TEXT, " \
304 "operation TEXT NOT NULL, " \
305 "color_depth TEXT NOT NULL DEFAULT '24', " \
306 "PRIMARY KEY(app_id, orientation, operation) " \
307 "FOREIGN KEY(app_id) " \
308 "REFERENCES package_app_info(app_id) " \
312 /* FIXME: duplicated at pkgmgrinfo_db.c */
313 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
314 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
315 " cert_info TEXT UNIQUE, " \
316 " cert_id INTEGER PRIMARY KEY, " \
317 " cert_ref_count INTEGER NOT NULL)"
319 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
320 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
321 " package TEXT PRIMARY KEY, " \
322 " package_count INTEGER, " \
323 " author_root_cert INTEGER, " \
324 " author_im_cert INTEGER, " \
325 " author_signer_cert INTEGER, " \
326 " dist_root_cert INTEGER, " \
327 " dist_im_cert INTEGER, " \
328 " dist_signer_cert INTEGER, " \
329 " dist2_root_cert INTEGER, " \
330 " dist2_im_cert INTEGER, " \
331 " dist2_signer_cert INTEGER)"
333 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO \
334 "CREATE TRIGGER IF NOT EXISTS update_cert_info " \
335 "AFTER UPDATE ON package_cert_info " \
336 "WHEN (NEW.package_count = 0) " \
338 " DELETE FROM package_cert_info WHERE package=OLD.package;" \
341 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2 \
342 "CREATE TRIGGER IF NOT EXISTS update_cert_info2 " \
343 "AFTER UPDATE ON package_cert_info " \
344 "WHEN (NEW.package_count = OLD.package_count + 1) " \
346 " UPDATE package_cert_index_info SET" \
347 " cert_ref_count = cert_ref_count - 1" \
348 " WHERE cert_id = OLD.author_root_cert" \
349 " OR cert_id = OLD.author_im_cert" \
350 " OR cert_id = OLD.author_signer_cert" \
351 " OR cert_id = OLD.dist_root_cert" \
352 " OR cert_id = OLD.dist_im_cert" \
353 " OR cert_id = OLD.dist_signer_cert" \
354 " OR cert_id = OLD.dist2_root_cert" \
355 " OR cert_id = OLD.dist2_im_cert" \
356 " OR cert_id = OLD.dist2_signer_cert;" \
359 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
360 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
361 "AFTER DELETE ON package_cert_info " \
363 " UPDATE package_cert_index_info SET" \
364 " cert_ref_count = cert_ref_count - 1" \
365 " WHERE cert_id = OLD.author_root_cert" \
366 " OR cert_id = OLD.author_im_cert" \
367 " OR cert_id = OLD.author_signer_cert" \
368 " OR cert_id = OLD.dist_root_cert" \
369 " OR cert_id = OLD.dist_im_cert" \
370 " OR cert_id = OLD.dist_signer_cert" \
371 " OR cert_id = OLD.dist2_root_cert" \
372 " OR cert_id = OLD.dist2_im_cert" \
373 " OR cert_id = OLD.dist2_signer_cert;" \
376 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
377 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
378 "AFTER UPDATE ON package_cert_index_info " \
379 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
380 " WHERE cert_id = OLD.cert_id) = 0) "\
382 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
385 static int __insert_application_info(manifest_x *mfx);
386 static int __insert_application_appcategory_info(manifest_x *mfx);
387 static int __insert_application_appcontrol_info(manifest_x *mfx);
388 static int __insert_application_appmetadata_info(manifest_x *mfx);
389 static int __insert_application_share_allowed_info(manifest_x *mfx);
390 static int __insert_application_share_request_info(manifest_x *mfx);
391 static int __insert_application_datacontrol_info(manifest_x *mfx);
392 static void __insert_application_locale_info(gpointer data, gpointer userdata);
393 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
394 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
395 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
396 static int __delete_subpkg_info_from_db(char *appid);
397 static int __delete_appinfo_from_db(char *db_table, const char *appid);
398 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
399 static int __exec_query(char *query);
400 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
401 char **label, char **license, char **icon, char **description, char **author);
402 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
403 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
404 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
405 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
406 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
407 static int __parserdb_change_perm(const char *db_file, uid_t uid);
409 #define REGULAR_USER 5000
410 static inline uid_t _getuid(void)
412 uid_t uid = getuid();
414 if (uid < REGULAR_USER)
415 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
420 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
423 __delete_subpkg_info_from_db(coltxt[0]);
428 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
433 char *error_message = NULL;
435 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
436 if (ret != SQLITE_OK) {
437 _LOGD("connect db [%s] failed!\n", db_path);
442 /* add user_version for db upgrade*/
443 query = sqlite3_mprintf("PRAGMA user_version=%d", (atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 + atoi(TIZEN_PATCH_VER)));
445 sqlite3_exec(handle, query, NULL, NULL, &error_message)) {
446 _LOGE("Don't execute query = %s error message = %s\n", query,
449 sqlite3_free(error_message);
455 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
457 manifest_x *mfx = (manifest_x *)data;
463 if (mfx->application == NULL)
465 app = (application_x *)mfx->application->data;
466 for (i = 0; i < ncols; i++) {
467 if (strcmp(colname[i], "app_id") == 0) {
469 appid = strdup(coltxt[i]);
470 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
472 status = strdup(coltxt[i]);
478 _LOGD("app id is NULL\n");
481 /*update guest mode visibility*/
482 for (tmp = mfx->application; tmp; tmp = tmp->next) {
483 app = (application_x *)tmp->data;
486 if (strcmp(app->appid, appid) == 0) {
487 free((void *)app->guestmode_visibility);
488 app->guestmode_visibility = strdup(status);
504 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
506 char *error_message = NULL;
507 char query[MAX_QUERY_LEN] = {'\0'};
508 sqlite3_snprintf(MAX_QUERY_LEN, query,
509 "SELECT app_id, app_guestmodevisibility FROM package_app_info " \
510 "WHERE package=%Q", mfx->package);
512 sqlite3_exec(pkgmgr_parser_db, query,
513 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
514 _LOGD("Don't execute query = %s error message = %s\n",
515 query, error_message);
516 sqlite3_free(error_message);
521 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
523 char *error_message = NULL;
525 sqlite3_exec(db_handle, db_query,
526 NULL, NULL, &error_message)) {
527 _LOGD("Don't execute query = %s error message = %s\n",
528 db_query, error_message);
529 sqlite3_free(error_message);
532 sqlite3_free(error_message);
536 static int __exec_query(char *query)
538 char *error_message = NULL;
540 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
541 _LOGE("Don't execute query = %s error message = %s\n", query,
543 sqlite3_free(error_message);
546 sqlite3_free(error_message);
548 if (strncmp(query, "DELETE", 6) && sqlite3_changes(pkgmgr_parser_db) == 0) {
549 _LOGE("No such record matches with given query : %s\n", query);
555 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
563 for (tmp = lbls; tmp; tmp = tmp->next) {
564 lbl = (label_x *)tmp->data;
568 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
570 for (tmp = lcns; tmp; tmp = tmp->next) {
571 lcn = (license_x *)tmp->data;
575 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
577 for (tmp = icns; tmp; tmp = tmp->next) {
578 icn = (icon_x *)tmp->data;
582 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
584 for (tmp = dcns; tmp; tmp = tmp->next) {
585 dcn = (description_x *)tmp->data;
589 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
591 for (tmp = aths; tmp; tmp = tmp->next) {
592 ath = (author_x *)tmp->data;
596 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
602 static GList *__create_icon_list(GList *appicon, GList *icns)
607 for (tmp = icns; tmp; tmp = tmp->next) {
608 icn = (icon_x *)tmp->data;
612 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
617 static GList *__create_image_list(GList *appimage, GList *imgs)
622 for (tmp = imgs; tmp; tmp = tmp->next) {
623 img = (image_x *)tmp->data;
627 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
632 static void __trimfunc(GList *trim_list)
634 char *trim_data = NULL;
638 list = g_list_first(trim_list);
641 trim_data = (char *)list->data;
644 if (strcmp(trim_data, prev) == 0) {
645 trim_list = g_list_remove(trim_list, trim_data);
646 list = g_list_first(trim_list);
655 list = g_list_next(list);
659 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
661 if (a == NULL || b == NULL)
663 if (strcmp((char *)a, (char *)b) == 0)
665 if (strcmp((char *)a, (char *)b) < 0)
667 if (strcmp((char *)a, (char *)b) > 0)
672 static int __check_dpi(const char *dpi_char, int dpi_int)
674 if (dpi_char == NULL)
677 if (strcasecmp(dpi_char, LDPI) == 0) {
678 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
682 } else if (strcasecmp(dpi_char, MDPI) == 0) {
683 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
687 } else if (strcasecmp(dpi_char, HDPI) == 0) {
688 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
692 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
693 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
697 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
698 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
706 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
709 char *icon_filename = NULL;
710 char modified_iconpath[BUFSIZE] = { '\0' };
711 char icon_path[BUFSIZE] = { '\0' };
715 if (orig_icon_path == NULL)
718 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
722 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
723 dpi_path[0] = "LDPI";
724 dpi_path[1] = "ldpi";
725 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
726 dpi_path[0] = "MDPI";
727 dpi_path[1] = "mdpi";
728 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
729 dpi_path[0] = "HDPI";
730 dpi_path[1] = "hdpi";
731 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
732 dpi_path[0] = "XHDPI";
733 dpi_path[1] = "xhdpi";
734 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
735 dpi_path[0] = "XXHDPI";
736 dpi_path[1] = "xxhdpi";
738 _LOGE("Unidentified dpi[%d]", dpi);
742 icon_filename = strrchr(orig_icon_path, '/');
743 if (icon_filename == NULL)
746 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
747 for (i = 0; i < 2; i++) {
748 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
749 if (access(modified_iconpath, F_OK) != -1) {
750 /* if exists, return modified icon path */
751 *new_icon_path = strdup(modified_iconpath);
759 static gint __compare_icon(gconstpointer a, gconstpointer b)
761 icon_x *icon = (icon_x *)a;
763 char *icon_folder_path = NULL;
765 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
768 if (icon->dpi != NULL)
771 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
773 icon->text = icon_folder_path;
779 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
781 icon_x *icon = (icon_x *)a;
782 int dpi = GPOINTER_TO_INT(b);
784 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
787 if (icon->dpi == NULL)
790 if (__check_dpi(icon->dpi, dpi) == 0)
796 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
798 icon_x *icon = (icon_x *)a;
799 char *lang = (char *)b;
800 char *icon_folder_path = NULL;
802 if (icon->dpi != NULL)
805 if (strcasecmp(icon->lang, lang) == 0) {
806 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
807 /* icon for no locale. check existance of folder-hierachied default icons */
808 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
810 icon->text = icon_folder_path;
819 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
821 icon_x *icon = (icon_x *)a;
822 char *lang = (char *)b;
825 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
829 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
835 static char *__find_icon(GList *icons, const char *lang)
842 /* first, find icon whose locale and dpi with given lang and system's dpi has matched */
843 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
845 icon = (icon_x *)tmp->data;
846 return (char *)icon->text;
849 /* if first has failed, find icon whose locale has matched */
850 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
852 icon = (icon_x *)tmp->data;
853 return (char *)icon->text;
856 /* if second has failed, find icon whose dpi has matched with system's dpi */
857 ret = system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
858 if (ret == SYSTEM_INFO_ERROR_NONE) {
859 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
861 icon = (icon_x *)tmp->data;
862 return (char *)icon->text;
866 /* last, find default icon marked as "No Locale" */
867 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
869 icon = (icon_x *)tmp->data;
870 return (char *)icon->text;
876 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
877 char **label, char **license, char **icon, char **description, char **author)
884 for (tmp = lbls; tmp; tmp = tmp->next) {
885 lbl = (label_x *)tmp->data;
889 if (strcmp(lbl->lang, (char *)data) == 0) {
890 *label = (char *)lbl->text;
895 for (tmp = lcns; tmp; tmp = tmp->next) {
896 lcn = (license_x *)tmp->data;
900 if (strcmp(lcn->lang, (char *)data) == 0) {
901 *license = (char *)lcn->text;
907 *icon = __find_icon(icns, (char *)data);
909 for (tmp = dcns; tmp; tmp = tmp->next) {
910 dcn = (description_x *)tmp->data;
914 if (strcmp(dcn->lang, (char *)data) == 0) {
915 *description = (char *)dcn->text;
920 for (tmp = aths; tmp; tmp = tmp->next) {
921 ath = (author_x *)tmp->data;
925 if (strcmp(ath->lang, (char *)data) == 0) {
926 *author = (char *)ath->text;
934 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
938 for (tmp = icns; tmp; tmp = tmp->next) {
939 icn = (icon_x *)tmp->data;
943 if (strcmp(icn->section, (char *)data) == 0) {
944 *icon = (char *)icn->text;
945 *resolution = (char *)icn->resolution;
952 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
956 for (tmp = imgs; tmp; tmp = tmp->next) {
957 img = (image_x *)tmp->data;
961 if (strcmp(img->section, (char *)data) == 0) {
962 *lang = (char *)img->lang;
963 *image = (char *)img->text;
970 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
975 char *description = NULL;
976 char *license = NULL;
980 manifest_x *mfx = (manifest_x *)userdata;
981 GList *lbl = mfx->label;
982 GList *lcn = mfx->license;
983 GList *icn = mfx->icon;
984 GList *dcn = mfx->description;
985 GList *ath = mfx->author;
987 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
988 if (!label && !description && !icon && !license && !author)
991 query = sqlite3_mprintf("INSERT INTO package_localized_info(package, package_locale, " \
992 "package_label, package_icon, package_description, package_license, package_author) VALUES" \
993 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1002 ret = __exec_query(query);
1004 _LOGD("Package Localized Info DB Insert failed\n");
1006 sqlite3_free(query);
1009 static void __insert_application_locale_info(gpointer data, gpointer userdata)
1015 char *locale = (char *)data;
1017 application_x *app = (application_x *)userdata;
1018 GList *lbl = app->label;
1019 GList *icn = app->icon;
1021 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1022 if (!label && !icon)
1025 query = sqlite3_mprintf("INSERT INTO package_app_localized_info(app_id, app_locale, " \
1026 "app_label, app_icon) VALUES" \
1027 "(%Q, %Q, %Q, %Q)", app->appid, (char *)data,
1029 ret = __exec_query(query);
1031 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1033 sqlite3_free(query);
1035 /*insert ui app locale info to pkg locale to get mainapp data */
1036 if (strcasecmp(app->mainapp, "true") == 0) {
1037 query = sqlite3_mprintf("INSERT OR REPLACE INTO package_localized_info(package, package_locale, "
1038 "package_label, package_icon, package_description, package_license, package_author) VALUES"
1040 "COALESCE((SELECT package_label FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1041 "COALESCE((SELECT package_icon FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1042 "(SELECT package_description FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1043 "(SELECT package_license FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1044 "(SELECT package_author FROM package_localized_info WHERE package=%Q AND package_locale=%Q))",
1045 app->package, locale,
1046 app->package, locale, label,
1047 app->package, locale, icon,
1048 app->package, locale,
1049 app->package, locale,
1050 app->package, locale);
1052 ret = __exec_query(query);
1054 _LOGE("Package Localized Info DB Insert failed");
1055 sqlite3_free(query);
1059 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1063 char *resolution = NULL;
1064 char query[MAX_QUERY_LEN] = {'\0'};
1066 application_x *app = (application_x *)userdata;
1067 GList *icn = app->icon;
1069 __extract_icon_data(data, icn, &icon, &resolution);
1070 if (!icon && !resolution)
1072 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO package_app_icon_section_info(app_id, " \
1073 "app_icon, app_icon_section, app_icon_resolution) VALUES " \
1074 "(%Q, %Q, %Q, %Q)", app->appid,
1075 icon, (char *)data, resolution);
1077 ret = __exec_query(query);
1079 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1083 static void __insert_application_image_info(gpointer data, gpointer userdata)
1088 char query[MAX_QUERY_LEN] = {'\0'};
1090 application_x *app = (application_x *)userdata;
1091 GList *image = app->image;
1093 __extract_image_data(data, image, &lang, &img);
1096 sqlite3_snprintf(MAX_QUERY_LEN, query,
1097 "INSERT INTO package_app_image_info(app_id, app_locale, " \
1098 "app_image_section, app_image) VALUES" \
1099 "(%Q, %Q, %Q, %Q)", app->appid, lang, (char *)data, img);
1101 ret = __exec_query(query);
1103 _LOGD("Package UiApp image Info DB Insert failed\n");
1108 static int __insert_mainapp_info(manifest_x *mfx)
1113 char query[MAX_QUERY_LEN] = {'\0'};
1114 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1115 app = (application_x *)tmp->data;
1118 if (strcasecmp(app->mainapp, "True") == 0)
1119 mfx->mainapp_id = strdup(app->appid);
1122 if (mfx->mainapp_id == NULL) {
1123 if (mfx->application == NULL)
1125 app = (application_x *)mfx->application->data;
1128 free((void *)app->mainapp);
1129 app->mainapp = strdup("true");
1130 mfx->mainapp_id = strdup(app->appid);
1133 memset(query, '\0', MAX_QUERY_LEN);
1134 sqlite3_snprintf(MAX_QUERY_LEN, query,
1135 "UPDATE package_info SET mainapp_id=%Q WHERE package=%Q", mfx->mainapp_id, mfx->package);
1136 ret = __exec_query(query);
1138 _LOGD("Package Info DB update Failed\n");
1145 static int __convert_background_category(GList *category_list)
1148 GList *tmp_list = category_list;
1149 char *category_data = NULL;
1151 if (category_list == NULL)
1154 while (tmp_list != NULL) {
1155 category_data = (char *)tmp_list->data;
1156 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0)
1157 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1158 else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0)
1159 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1160 else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0)
1161 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1162 else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0)
1163 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1164 else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0)
1165 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1166 else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0)
1167 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1168 else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0)
1169 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1171 _LOGE("Unidentified category [%s]", category_data);
1172 tmp_list = g_list_next(tmp_list);
1178 static const char *__find_effective_appid(GList *metadata_list)
1183 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1184 md = (metadata_x *)tmp_list->data;
1185 if (md == NULL || md->key == NULL)
1188 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1197 static char *__get_bool(char *value, bool is_true)
1199 if (value != NULL) {
1200 if (!strcmp(value, ""))
1201 return (is_true) ? "true" : "false";
1205 return (is_true) ? "true" : "false";
1208 /* _PRODUCT_LAUNCHING_ENHANCED_
1209 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1211 static int __insert_application_info(manifest_x *mfx)
1216 int background_value = 0;
1217 char query[MAX_QUERY_LEN] = {'\0'};
1219 const char *effective_appid;
1222 type = strdup(mfx->type);
1224 type = strdup("tpk");
1226 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1227 app = (application_x *)tmp->data;
1231 background_value = __convert_background_category(app->background_category);
1232 if (background_value < 0) {
1233 _LOGE("Failed to retrieve background value[%d]", background_value);
1234 background_value = 0;
1237 effective_appid = __find_effective_appid(app->metadata);
1239 sqlite3_snprintf(MAX_QUERY_LEN, query,
1240 "INSERT INTO package_app_info(" \
1241 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1242 "app_onboot, app_multiple, app_autorestart, app_taskmanage, " \
1243 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1244 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1245 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1246 "app_launch_mode, app_ui_gadget, app_support_mode, app_support_disable, component_type, package, " \
1247 "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, " \
1248 "app_api_version, app_effective_appid, app_splash_screen_display, app_package_system, app_removable, " \
1249 "app_package_installed_time, app_support_ambient) " \
1251 "%Q, %Q, %Q, LOWER(%Q), %Q, " \
1252 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1253 "%Q, %Q, %Q, %Q, %Q, " \
1254 "LOWER(%Q), %Q, %Q, LOWER(%Q), %Q, " \
1255 "LOWER(%Q), LOWER(%Q), %Q, %Q, LOWER(%Q), " \
1256 "COALESCE(%Q, 'caller'), LOWER(%Q), %Q, LOWER(%Q), %Q, %Q, " \
1257 "%Q, %Q, %d, %Q, %Q, " \
1258 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1260 app->appid, app->component_type, app->exec, __get_bool(app->nodisplay, false), app->type,
1261 __get_bool(app->onboot, false), __get_bool(app->multiple, false), __get_bool(app->autorestart, false), __get_bool(app->taskmanage, false),
1262 app->hwacceleration, app->screenreader, app->mainapp, app->recentimage, app->launchcondition,
1263 __get_bool(app->indicatordisplay, true), app->portraitimg, app->landscapeimg,
1264 __get_bool(app->guestmode_visibility, true), app->permission_type,
1265 __get_bool(mfx->preload, false), __get_bool(app->submode, false), app->submode_mainid, mfx->installed_storage, __get_bool(app->process_pool, false),
1266 app->launch_mode, __get_bool(app->ui_gadget, false), mfx->support_mode, __get_bool(mfx->support_disable, false), app->component_type, mfx->package,
1267 mfx->tep_name, mfx->zip_mount_file, background_value, type, mfx->root_path, mfx->api_version,
1268 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));
1270 ret = __exec_query(query);
1272 _LOGD("Package UiApp Info DB Insert Failed\n");
1277 memset(query, '\0', MAX_QUERY_LEN);
1286 static int __insert_application_appcategory_info(manifest_x *mfx)
1293 char query[MAX_QUERY_LEN] = {'\0'};
1294 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1295 app = (application_x *)app_tmp->data;
1298 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1299 ct = (const char *)ct_tmp->data;
1302 sqlite3_snprintf(MAX_QUERY_LEN, query,
1303 "INSERT INTO package_app_app_category(app_id, category) " \
1306 ret = __exec_query(query);
1308 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1311 memset(query, '\0', MAX_QUERY_LEN);
1317 static int __insert_application_appmetadata_info(manifest_x *mfx)
1324 char query[MAX_QUERY_LEN] = {'\0'};
1325 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1326 app = (application_x *)app_tmp->data;
1329 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1330 md = (metadata_x *)md_tmp->data;
1334 sqlite3_snprintf(MAX_QUERY_LEN, query,
1335 "INSERT INTO package_app_app_metadata(app_id, md_key, md_value) " \
1336 "VALUES(%Q, %Q, %Q)",\
1337 app->appid, md->key, md->value ? md->value : NULL);
1338 ret = __exec_query(query);
1340 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1344 memset(query, '\0', MAX_QUERY_LEN);
1350 static int __insert_application_apppermission_info(manifest_x *mfx)
1357 char query[MAX_QUERY_LEN] = {'\0'};
1358 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1359 app = (application_x *)app_tmp->data;
1362 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1363 pm = (permission_x *)pm_tmp->data;
1366 sqlite3_snprintf(MAX_QUERY_LEN, query,
1367 "INSERT INTO package_app_app_permission(app_id, pm_type, pm_value) " \
1368 "VALUES(%Q, %Q, %Q)",\
1369 app->appid, pm->type, pm->value);
1370 ret = __exec_query(query);
1372 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1375 memset(query, '\0', MAX_QUERY_LEN);
1381 static int __insert_application_appcontrol_info(manifest_x *mfx)
1385 GList *acontrol_tmp;
1386 appcontrol_x *acontrol;
1388 char query[MAX_QUERY_LEN] = {'\0'};
1389 char buf[BUFSIZE] = {'\0'};
1390 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1391 app = (application_x *)app_tmp->data;
1394 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1395 acontrol = (appcontrol_x *)acontrol_tmp->data;
1396 if (acontrol == NULL)
1398 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1399 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1400 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1401 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1402 sqlite3_snprintf(MAX_QUERY_LEN, query,
1403 "INSERT INTO package_app_app_control(app_id, app_control) " \
1406 ret = __exec_query(query);
1408 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1411 memset(query, '\0', MAX_QUERY_LEN);
1417 static int __insert_application_datacontrol_info(manifest_x *mfx)
1424 char query[MAX_QUERY_LEN] = {'\0'};
1426 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1427 app = (application_x *)app_tmp->data;
1430 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1431 dc = (datacontrol_x *)dc_tmp->data;
1434 sqlite3_snprintf(MAX_QUERY_LEN, query,
1435 "INSERT INTO package_app_data_control(app_id, providerid, access, type) " \
1436 "VALUES(%Q, %Q, %Q, %Q)",\
1442 ret = __exec_query(query);
1444 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1447 memset(query, '\0', MAX_QUERY_LEN);
1453 static int __insert_application_share_request_info(manifest_x *mfx)
1462 char query[MAX_QUERY_LEN] = {'\0'};
1463 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1464 app = (application_x *)app_tmp->data;
1467 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1468 ds = (datashare_x *)ds_tmp->data;
1471 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1472 rq = (const char *)rq_tmp->data;
1475 sqlite3_snprintf(MAX_QUERY_LEN, query,
1476 "INSERT INTO package_app_share_request(app_id, data_share_request) " \
1479 ret = __exec_query(query);
1481 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1484 memset(query, '\0', MAX_QUERY_LEN);
1491 static int __insert_application_share_allowed_info(manifest_x *mfx)
1502 char query[MAX_QUERY_LEN] = {'\0'};
1503 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1504 app = (application_x *)app_tmp->data;
1507 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1508 ds = (datashare_x *)ds_tmp->data;
1511 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1512 df = (define_x *)df_tmp->data;
1515 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1516 al = (const char *)al_tmp->data;
1519 sqlite3_snprintf(MAX_QUERY_LEN, query,
1520 "INSERT INTO package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1521 "VALUES(%Q, %Q, %Q)",\
1522 app->appid, df->path, al);
1523 ret = __exec_query(query);
1525 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1528 memset(query, '\0', MAX_QUERY_LEN);
1536 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1538 splashscreen_x *ss = (splashscreen_x *)a;
1539 const char *orientation = (const char *)b;
1542 if (ss->operation || ss->dpi == NULL)
1545 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1549 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1555 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1557 splashscreen_x *ss = (splashscreen_x *)a;
1558 const char *orientation = (const char *)b;
1560 if (ss->operation || ss->dpi)
1563 if (strcasecmp(ss->orientation, orientation) == 0)
1569 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1570 const char *orientation)
1574 tmp = g_list_find_custom(splashscreens, orientation,
1575 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1577 return (splashscreen_x *)tmp->data;
1579 tmp = g_list_find_custom(splashscreens, orientation,
1580 (GCompareFunc)__compare_splashscreen_with_orientation);
1582 return (splashscreen_x *)tmp->data;
1587 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1589 splashscreen_x *ss = (splashscreen_x *)data;
1590 GList **list = (GList **)user_data;
1593 if (ss->operation == NULL || ss->dpi == NULL)
1596 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1600 if (__check_dpi(ss->dpi, dpi) != 0)
1603 *list = g_list_append(*list, ss);
1606 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1608 splashscreen_x *ss = (splashscreen_x *)data;
1609 GList **list = (GList **)user_data;
1610 splashscreen_x *ss_tmp;
1613 if (ss->operation == NULL || ss->dpi)
1616 for (tmp = *list; tmp; tmp = tmp->next) {
1617 ss_tmp = (splashscreen_x *)tmp->data;
1618 if (ss_tmp->operation
1619 && strcmp(ss_tmp->operation, ss->operation) == 0
1620 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1624 *list = g_list_append(*list, ss);
1627 static GList *__find_splashscreens(GList *splashscreens)
1632 g_list_foreach(splashscreens,
1633 __find_appcontrol_splashscreen_with_dpi, &list);
1634 g_list_foreach(splashscreens,
1635 __find_appcontrol_splashscreen, &list);
1637 ss = __find_default_splashscreen(splashscreens, "portrait");
1639 list = g_list_append(list, ss);
1640 ss = __find_default_splashscreen(splashscreens, "landscape");
1642 list = g_list_append(list, ss);
1647 static int __insert_application_splashscreen_info(manifest_x *mfx)
1655 char query[MAX_QUERY_LEN] = {'\0'};
1657 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1658 app = (application_x *)app_tmp->data;
1659 if (app == NULL || app->splashscreens == NULL)
1662 ss_tmp = __find_splashscreens(app->splashscreens);
1666 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1667 ss = (splashscreen_x *)tmp->data;
1668 sqlite3_snprintf(MAX_QUERY_LEN, query,
1669 "INSERT INTO package_app_splash_screen" \
1670 "(app_id, src, type, orientation, indicatordisplay, " \
1671 "operation, color_depth) " \
1672 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1673 app->appid, ss->src, ss->type, ss->orientation,
1674 ss->indicatordisplay, ss->operation,
1677 ret = __exec_query(query);
1679 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1682 memset(query, '\0', MAX_QUERY_LEN);
1684 g_list_free(ss_tmp);
1689 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1693 privilege_x *pv = NULL;
1694 char query[MAX_QUERY_LEN] = { '\0' };
1697 const char *auth_name = NULL;
1698 const char *auth_email = NULL;
1699 const char *auth_href = NULL;
1701 GList *pkglocale = NULL;
1702 GList *applocale = NULL;
1703 GList *appicon = NULL;
1704 GList *appimage = NULL;
1706 int temp_pkg_mode = 0;
1707 int temp_app_mode = 0;
1708 char pkg_mode[MAX_INTEGER_LENGTH] = {'\0'};
1709 application_x *up_support_mode = NULL;
1710 GList *list_up = NULL;
1712 if (mfx->author && mfx->author->data) {
1713 author = (author_x *)mfx->author->data;
1715 auth_name = author->text;
1717 auth_email = author->email;
1719 auth_href = author->href;
1722 if (mfx->support_mode)
1723 temp_pkg_mode = atoi(mfx->support_mode);
1725 /* FIXME : OR-ing should be fixed to not to store whole support mode */
1726 list_up = mfx->application;
1727 while (list_up != NULL) {
1728 up_support_mode = (application_x *)list_up->data;
1729 if (up_support_mode->support_mode) {
1730 temp_app_mode = atoi(up_support_mode->support_mode);
1731 temp_pkg_mode |= temp_app_mode;
1733 list_up = list_up->next;
1735 snprintf(pkg_mode, MAX_INTEGER_LENGTH, "%d", temp_pkg_mode);
1737 if (mfx->support_mode)
1738 free((void *)mfx->support_mode);
1739 mfx->support_mode = strdup(pkg_mode);
1741 /*Insert in the package_info DB*/
1742 sqlite3_snprintf(MAX_QUERY_LEN, query,
1743 "INSERT INTO package_info(" \
1744 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1745 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1746 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1747 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1748 "mainapp_id, package_url, root_path, csc_path, package_support_mode, package_support_disable) " \
1750 "%Q, %Q, %Q, %Q, %Q, %Q, " \
1751 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1752 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), %Q, " \
1753 "%Q, %Q, %Q, %Q, %Q, " \
1754 "%Q, %Q, %Q, %Q, %Q, LOWER(%Q))",
1755 mfx->package, mfx->type, mfx->version, mfx->api_version, mfx->tep_name, mfx->zip_mount_file,
1756 mfx->installlocation, mfx->package_size, __get_bool(mfx->removable, true), __get_bool(mfx->preload, false), __get_bool(mfx->readonly, false),
1757 __get_bool(mfx->update, false), __get_bool(mfx->appsetting, false), __get_bool(mfx->nodisplay_setting, false), __get_bool(mfx->system, false), auth_name,
1758 auth_email, auth_href, mfx->installed_time, mfx->installed_storage,
1759 mfx->storeclient_id,
1760 mfx->mainapp_id, mfx->package_url, mfx->root_path, mfx->csc_path, mfx->support_mode, __get_bool(mfx->support_disable, false));
1762 ret = __exec_query(query);
1764 _LOGD("Package Info DB Insert Failed\n");
1768 /*Insert in the package_privilege_info DB*/
1769 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1770 pv = (privilege_x *)tmp->data;
1773 memset(query, '\0', MAX_QUERY_LEN);
1774 sqlite3_snprintf(MAX_QUERY_LEN, query,
1775 "INSERT INTO package_privilege_info(package, privilege, type) " \
1776 "VALUES(%Q, %Q, %Q)",\
1777 mfx->package, pv->value, pv->type);
1778 ret = __exec_query(query);
1780 _LOGD("Package Privilege Info DB Insert Failed\n");
1785 if (mfx->application != NULL) {
1786 ret = __insert_mainapp_info(mfx);
1791 /*Insert the package locale*/
1792 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1793 /*remove duplicated data in pkglocale*/
1794 __trimfunc(pkglocale);
1796 /*Insert the app locale, icon, image info */
1797 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1798 app = (application_x *)tmp->data;
1801 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1802 appicon = __create_icon_list(appicon, app->icon);
1803 appimage = __create_image_list(appimage, app->image);
1805 /*remove duplicated data in applocale*/
1806 __trimfunc(applocale);
1807 __trimfunc(appicon);
1808 __trimfunc(appimage);
1810 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1812 /*native app locale info*/
1813 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1814 app = (application_x *)tmp->data;
1817 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1818 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1819 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1822 g_list_free(pkglocale);
1824 g_list_free(applocale);
1826 g_list_free(appicon);
1828 g_list_free(appimage);
1831 /*Insert in the package_app_info DB*/
1832 ret = __insert_application_info(mfx);
1835 /*Insert in the package_app_app_control DB*/
1836 ret = __insert_application_appcontrol_info(mfx);
1840 /*Insert in the package_app_app_category DB*/
1841 ret = __insert_application_appcategory_info(mfx);
1845 /*Insert in the package_app_app_metadata DB*/
1846 ret = __insert_application_appmetadata_info(mfx);
1850 /*Insert in the package_app_app_permission DB*/
1851 ret = __insert_application_apppermission_info(mfx);
1855 /*Insert in the package_app_share_allowed DB*/
1856 ret = __insert_application_share_allowed_info(mfx);
1860 /*Insert in the package_app_share_request DB*/
1861 ret = __insert_application_share_request_info(mfx);
1865 /*Insert in the package_app_data_control DB*/
1866 ret = __insert_application_datacontrol_info(mfx);
1870 /*Insert in the package_app_splash_screen DB*/
1871 ret = __insert_application_splashscreen_info(mfx);
1879 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1881 char query[MAX_QUERY_LEN] = { '\0' };
1884 sqlite3_snprintf(MAX_QUERY_LEN, query,
1885 "DELETE FROM %q where app_id=%Q", db_table, appid);
1886 ret = __exec_query(query);
1888 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1894 static int __delete_subpkg_info_from_db(char *appid)
1898 ret = __delete_appinfo_from_db("package_app_info", appid);
1901 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1904 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1907 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1910 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1913 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1916 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1919 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1922 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1925 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1928 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1931 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
1938 static int __delete_subpkg_from_db(manifest_x *mfx)
1940 char query[MAX_QUERY_LEN] = { '\0' };
1941 char *error_message = NULL;
1943 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT app_id FROM package_app_info WHERE package=%Q", mfx->package);
1945 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1946 _LOGE("Don't execute query = %s error message = %s\n", query,
1948 sqlite3_free(error_message);
1951 sqlite3_free(error_message);
1956 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1958 char query[MAX_QUERY_LEN] = { '\0' };
1963 /*Delete from Package Info DB*/
1964 sqlite3_snprintf(MAX_QUERY_LEN, query,
1965 "DELETE FROM package_info WHERE package=%Q", mfx->package);
1966 ret = __exec_query(query);
1968 _LOGD("Package Info DB Delete Failed\n");
1971 memset(query, '\0', MAX_QUERY_LEN);
1973 /*Delete from Package Localized Info*/
1974 sqlite3_snprintf(MAX_QUERY_LEN, query,
1975 "DELETE FROM package_localized_info WHERE package=%Q", mfx->package);
1976 ret = __exec_query(query);
1978 _LOGD("Package Localized Info DB Delete Failed\n");
1982 /*Delete from Package Privilege Info*/
1983 sqlite3_snprintf(MAX_QUERY_LEN, query,
1984 "DELETE FROM package_privilege_info WHERE package=%Q", mfx->package);
1985 ret = __exec_query(query);
1987 _LOGD("Package Privilege Info DB Delete Failed\n");
1991 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1992 app = (application_x *)tmp->data;
1995 ret = __delete_appinfo_from_db("package_app_info", app->appid);
1998 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2001 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2004 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2007 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2010 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2013 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2016 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2019 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2022 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2025 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2028 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2033 /* if main package has sub pkg, delete sub pkg data*/
2034 __delete_subpkg_from_db(mfx);
2039 static int __disable_app(const char *appid)
2042 char query[MAX_QUERY_LEN] = {'\0'};
2043 sqlite3_snprintf(MAX_QUERY_LEN, query,
2044 "UPDATE package_app_info SET app_disable='true' WHERE app_id=%Q",
2046 ret = __exec_query(query);
2048 _LOGD("Insert global app disable failed\n");
2053 static int __enable_app(const char *appid)
2056 char query[MAX_QUERY_LEN] = {'\0'};
2057 sqlite3_snprintf(MAX_QUERY_LEN, query,
2058 "UPDATE package_app_info SET app_disable='false' WHERE app_id=%Q",
2060 ret = __exec_query(query);
2062 _LOGD("Insert global app disable failed\n");
2067 static int __disable_pkg(const char *pkgid)
2070 char query[MAX_QUERY_LEN] = {'\0'};
2071 sqlite3_snprintf(MAX_QUERY_LEN, query,
2072 "UPDATE package_info SET package_disable='true' WHERE package=%Q",
2074 ret = __exec_query(query);
2076 _LOGD("Update pkg disable info has failed\n");
2081 static int __enable_pkg(const char *pkgid)
2084 char query[MAX_QUERY_LEN] = {'\0'};
2085 sqlite3_snprintf(MAX_QUERY_LEN, query,
2086 "UPDATE package_info SET package_disable='false' WHERE package=%Q",
2088 ret = __exec_query(query);
2090 _LOGD("Update pkg disable info has failed\n");
2095 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2098 char query[MAX_QUERY_LEN] = { '\0', };
2100 const char *val = NULL;
2105 sqlite3_snprintf(MAX_QUERY_LEN, query,
2106 "SELECT COUNT(*) FROM "
2107 "package_app_info_for_uid WHERE app_id=%Q "
2108 "AND uid=%d", appid, (int)uid);
2110 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2111 if (ret != SQLITE_OK) {
2112 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2113 return PMINFO_R_ERROR;
2116 if (sqlite3_step(stmt) != SQLITE_ROW) {
2117 LOGE("failed to step");
2118 sqlite3_finalize(stmt);
2119 return PMINFO_R_ERROR;
2122 val = (const char *)sqlite3_column_text(stmt, 0);
2124 sqlite3_finalize(stmt);
2129 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2132 char query[MAX_QUERY_LEN] = { '\0', };
2134 ret = __check_appinfo_for_uid_table(appid, uid);
2136 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2139 } else if (ret == 0) {
2140 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2141 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2142 "VALUES(%Q, %d, 'true', "
2143 "(SELECT app_splash_screen_display FROM package_app_info WHERE app_id=%Q))",
2144 appid, (int)uid, appid);
2146 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2147 "package_app_info_for_uid SET is_disabled='true' "
2148 "WHERE app_id=%Q AND uid=%d", appid, (int)uid);
2151 ret = __exec_query(query);
2153 _LOGD("Add global app disable info failed\n");
2158 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2161 char query[MAX_QUERY_LEN] = {'\0'};
2163 ret = __check_appinfo_for_uid_table(appid, uid);
2165 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2168 } else if (ret > 0) {
2169 sqlite3_snprintf(MAX_QUERY_LEN, query,
2170 "UPDATE package_app_info_for_uid SET "
2171 "is_disabled='false' WHERE app_id=%Q AND "
2172 "uid=%d", appid, (int)uid);
2175 ret = __exec_query(query);
2177 _LOGD("Remove global app disable info failed\n");
2182 static int __update_global_app_splash_screen_for_user(const char *appid,
2183 uid_t uid, int flag)
2186 char query[MAX_QUERY_LEN] = { '\0', };
2188 ret = __check_appinfo_for_uid_table(appid, uid);
2190 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2193 } else if (ret == 0) {
2194 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2195 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2196 "VALUES(%Q, %d, %Q)", appid, (int)uid,
2197 flag ? "true" : "false");
2199 sqlite3_snprintf(MAX_QUERY_LEN, query,
2200 "UPDATE package_app_info_for_uid SET "
2201 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2202 "uid=%d", flag ? "true" : "false", appid, (int)uid);
2205 ret = __exec_query(query);
2207 _LOGD("update global app splash screen info failed\n");
2212 static int __disable_app_splash_screen(const char *appid)
2215 char query[MAX_QUERY_LEN] = {'\0'};
2217 sqlite3_snprintf(MAX_QUERY_LEN, query,
2218 "UPDATE package_app_info SET app_splash_screen_display='false' WHERE app_id=%Q",
2220 ret = __exec_query(query);
2222 _LOGD("Failed to update app_palsh_screen_display");
2227 static int __enable_app_splash_screen(const char *appid)
2230 char query[MAX_QUERY_LEN] = {'\0'};
2232 sqlite3_snprintf(MAX_QUERY_LEN, query,
2233 "UPDATE package_app_info SET app_splash_screen_display='true' WHERE app_id=%Q",
2235 ret = __exec_query(query);
2237 _LOGD("Failed to update app_splash_screen_display");
2242 API int pkgmgr_parser_initialize_db(uid_t uid)
2248 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2250 _LOGD("package info DB initialization failed\n");
2253 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2255 _LOGD("package localized info DB initialization failed\n");
2258 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2260 _LOGD("package app app privilege DB initialization failed\n");
2263 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2265 _LOGD("package app info DB initialization failed\n");
2268 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2270 _LOGD("package app localized info DB initialization failed\n");
2273 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2275 _LOGD("package app icon localized info DB initialization failed\n");
2278 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2280 _LOGD("package app image info DB initialization failed\n");
2283 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2285 _LOGD("package app app control DB initialization failed\n");
2288 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2290 _LOGD("package app app category DB initialization failed\n");
2293 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2295 _LOGD("package app app category DB initialization failed\n");
2298 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2300 _LOGD("package app app permission DB initialization failed\n");
2303 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2305 _LOGD("package app share allowed DB initialization failed\n");
2308 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2310 _LOGD("package app share request DB initialization failed\n");
2313 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2315 _LOGD("package app data control DB initialization failed\n");
2319 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2321 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2325 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2327 _LOGD("package app splash screen DB initialization failed\n");
2331 /* Trigger package_app_info_for_uid */
2332 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2334 _LOGD("package app info for uid DB initialization failed\n");
2339 /* TODO: refactor this code */
2340 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2342 _LOGD("package cert info DB initialization failed\n");
2345 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2347 _LOGD("package cert index info DB initialization failed\n");
2350 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO);
2352 _LOGD("package cert info DB initialization failed\n");
2355 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2);
2357 _LOGD("package cert info DB initialization failed\n");
2360 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2362 _LOGD("package cert info DB initialization failed\n");
2365 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2367 _LOGD("package cert index info DB initialization failed\n");
2371 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2372 if (db_path == NULL) {
2373 _LOGD("Failed to get user cert db path - GLOBAL_USER");
2375 ret = __parserdb_change_perm(db_path, GLOBAL_USER);
2377 _LOGD("Failed to change cert db permission");
2381 db_path = getUserPkgParserDBPathUID(uid);
2382 if (db_path == NULL) {
2383 _LOGD("Failed to get user pkg parser db path - %d", uid);
2385 ret = __parserdb_change_perm(db_path, uid);
2387 _LOGD("Failed to change parser db permission\n");
2394 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2397 char pwuid_buf[1024];
2398 char journal_file[BUFSIZE];
2403 struct passwd userinfo, *result = NULL;
2404 files[0] = (char *)db_file;
2405 files[1] = journal_file;
2409 if (db_file == NULL)
2412 if (getuid() != OWNER_ROOT) /* At this time we should be root to apply this */
2414 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2415 if (uid == OWNER_ROOT || uid == GLOBAL_USER) {
2416 ret = getpwnam_r(APPFW_USER, &userinfo, buf, sizeof(buf), &result);
2417 if (ret != 0 || result == NULL)
2419 uid = userinfo.pw_uid;
2422 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2423 if (ret != 0 || result == NULL) {
2424 _LOGE("FAIL: user %d doesn't exist", uid);
2427 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2429 for (i = 0; files[i]; i++) {
2430 fd = open(files[i], O_RDONLY);
2432 if (strerror_r(errno, buf, sizeof(buf)))
2433 strncpy(buf, "", BUFSIZE - 1);
2434 _LOGD("FAIL : open %s : %s", files[i], buf);
2437 ret = fstat(fd, &sb);
2439 if (strerror_r(errno, buf, sizeof(buf)))
2440 strncpy(buf, "", BUFSIZE - 1);
2441 _LOGD("FAIL : fstat %s : %s", files[i], buf);
2445 if (S_ISLNK(sb.st_mode)) {
2446 _LOGE("FAIL : %s is symlink!", files[i]);
2450 ret = fchown(fd, uid, userinfo.pw_gid);
2452 if (strerror_r(errno, buf, sizeof(buf)))
2453 strncpy(buf, "", BUFSIZE - 1);
2454 _LOGD("FAIL : fchown %s %d.%d : %s", files[i], uid,
2455 userinfo.pw_gid, buf);
2460 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2461 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2463 ret = fchmod(fd, mode);
2465 if (strerror_r(errno, buf, sizeof(buf)))
2466 strncpy(buf, "", BUFSIZE - 1);
2467 _LOGD("FAIL : fchmod %s 0664 : %s", files[i], buf);
2472 SET_SMACK_LABEL(files[i]);
2477 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2482 if (getuid() != OWNER_ROOT) {
2483 _LOGE("Only root user is allowed");
2487 db_path = getUserPkgParserDBPathUID(uid);
2488 if (db_path == NULL) {
2489 _LOGE("Failed to get pkg parser db path - %d", uid);
2493 if (access(db_path, F_OK) != -1) {
2494 _LOGE("Manifest db for user %d is already exists", uid);
2500 db_path = getUserPkgCertDBPathUID(uid);
2501 if (db_path == NULL) {
2502 _LOGE("Failed to get pkg cert db path - %d", uid);
2506 if (access(db_path, F_OK) != -1) {
2507 _LOGE("Cert db for user %d is already exists", uid);
2513 ret = pkgmgr_parser_check_and_create_db(uid);
2516 ret = pkgmgr_parser_initialize_db(uid);
2518 pkgmgr_parser_close_db();
2521 pkgmgr_parser_close_db();
2526 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2531 db_path = getUserPkgParserDBPathUID(uid);
2532 if (db_path == NULL) {
2533 _LOGD("Failed to get pkg parser db path - %d", uid);
2538 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, db_path);
2540 _LOGD("Manifest DB creation Failed\n");
2546 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2547 if (db_path == NULL) {
2548 _LOGE("Failed to get pkg cert db path - GLOBAL_USER");
2553 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, db_path);
2555 _LOGD("Cert DB creation Failed\n");
2565 void pkgmgr_parser_close_db(void)
2567 sqlite3_close(pkgmgr_parser_db);
2568 sqlite3_close(pkgmgr_cert_db);
2572 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2574 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2576 _LOGD("manifest pointer is NULL\n");
2580 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2582 _LOGD("Failed to open DB\n");
2585 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2588 /*Begin transaction*/
2589 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2590 if (ret != SQLITE_OK) {
2591 _LOGD("Failed to begin transaction\n");
2595 _LOGD("Transaction Begin\n");
2596 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2598 _LOGD("Insert into DB failed. Rollback now\n");
2599 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2602 /*Commit transaction*/
2603 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2604 if (ret != SQLITE_OK) {
2605 _LOGD("Failed to commit transaction. Rollback now\n");
2606 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2610 _LOGD("Transaction Commit and End\n");
2612 pkgmgr_parser_close_db();
2616 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2618 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2620 _LOGD("manifest pointer is NULL\n");
2624 ret = pkgmgr_parser_check_and_create_db(uid);
2626 _LOGD("Failed to open DB\n");
2629 ret = pkgmgr_parser_initialize_db(uid);
2632 /*Begin transaction*/
2633 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2634 if (ret != SQLITE_OK) {
2635 _LOGD("Failed to begin transaction\n");
2639 _LOGD("Transaction Begin\n");
2640 ret = __insert_manifest_info_in_db(mfx, uid);
2642 _LOGD("Insert into DB failed. Rollback now\n");
2643 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2646 /*Commit transaction*/
2647 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2648 if (ret != SQLITE_OK) {
2649 _LOGD("Failed to commit transaction. Rollback now\n");
2650 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2654 _LOGD("Transaction Commit and End\n");
2656 pkgmgr_parser_close_db();
2660 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2662 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, _getuid());
2665 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2667 if (pkgid == NULL || tep_path == NULL) {
2668 _LOGE("invalid parameter");
2675 ret = pkgmgr_parser_check_and_create_db(uid);
2677 _LOGD("Failed to open DB\n");
2680 ret = pkgmgr_parser_initialize_db(uid);
2684 /*Begin transaction*/
2685 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2686 if (ret != SQLITE_OK) {
2687 _LOGD("Failed to begin transaction\n");
2691 _LOGD("Transaction Begin\n");
2694 /* Updating TEP info in "package_info" table */
2695 query = sqlite3_mprintf("UPDATE package_info "\
2696 "SET package_tep_name = %Q "\
2697 "WHERE package = %Q", tep_path, pkgid);
2699 ret = __exec_query(query);
2700 sqlite3_free(query);
2701 if (ret != SQLITE_OK) {
2702 ret = PM_PARSER_R_ERROR;
2703 _LOGE("sqlite exec failed to insert entries into package_info!!");
2707 /* Updating TEP info in "package_app_info" table */
2708 query = sqlite3_mprintf("UPDATE package_app_info "\
2709 "SET app_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_app_info!!");
2720 /*Commit transaction*/
2721 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2722 if (ret != SQLITE_OK) {
2723 _LOGE("Failed to commit transaction, Rollback now\n");
2724 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2725 if (ret != SQLITE_OK)
2726 _LOGE("Failed to Rollback\n");
2728 ret = PM_PARSER_R_ERROR;
2731 _LOGD("Transaction Commit and End\n");
2732 ret = PM_PARSER_R_OK;
2735 pkgmgr_parser_close_db();
2740 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2743 _LOGD("manifest pointer is NULL\n");
2747 ret = pkgmgr_parser_check_and_create_db(uid);
2749 _LOGD("Failed to open DB\n");
2752 ret = pkgmgr_parser_initialize_db(uid);
2755 /*Preserve guest mode visibility*/
2756 __preserve_guestmode_visibility_value(mfx);
2757 /*Begin transaction*/
2758 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2759 if (ret != SQLITE_OK) {
2760 _LOGD("Failed to begin transaction\n");
2764 _LOGD("Transaction Begin\n");
2765 ret = __delete_manifest_info_from_db(mfx, uid);
2767 _LOGD("Delete from DB failed. Rollback now\n");
2768 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2771 ret = __insert_manifest_info_in_db(mfx, uid);
2773 _LOGD("Insert into DB failed. Rollback now\n");
2774 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2778 /*Commit transaction*/
2779 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2780 if (ret != SQLITE_OK) {
2781 _LOGD("Failed to commit transaction. Rollback now\n");
2782 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2786 _LOGD("Transaction Commit and End\n");
2788 pkgmgr_parser_close_db();
2792 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2794 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2797 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2800 _LOGD("manifest pointer is NULL\n");
2804 ret = pkgmgr_parser_check_and_create_db(uid);
2806 _LOGD("Failed to open DB\n");
2809 /*Begin transaction*/
2810 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2811 if (ret != SQLITE_OK) {
2812 _LOGD("Failed to begin transaction\n");
2816 _LOGD("Transaction Begin\n");
2817 ret = __delete_manifest_info_from_db(mfx, uid);
2819 _LOGD("Delete from DB failed. Rollback now\n");
2820 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2823 /*Commit transaction*/
2824 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2825 if (ret != SQLITE_OK) {
2826 _LOGD("Failed to commit transaction, Rollback now\n");
2827 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2831 _LOGD("Transaction Commit and End\n");
2833 pkgmgr_parser_close_db();
2837 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2839 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
2842 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2846 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2848 _LOGD("Failed to open DB\n");
2852 /*Begin transaction*/
2853 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2854 if (ret != SQLITE_OK) {
2855 _LOGD("Failed to begin transaction\n");
2859 _LOGD("Transaction Begin\n");
2861 ret = __disable_global_app_for_user(appid, uid);
2863 ret = __enable_global_app_for_user(appid, uid);
2865 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2866 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2869 /*Commit transaction*/
2870 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2871 if (ret != SQLITE_OK) {
2872 _LOGD("Failed to commit transaction, Rollback now\n");
2873 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2877 _LOGD("Transaction Commit and End\n");
2879 pkgmgr_parser_close_db();
2884 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2886 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
2889 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid, uid_t uid, int is_disable)
2893 ret = pkgmgr_parser_check_and_create_db(uid);
2895 _LOGD("Failed to open DB\n");
2899 /*Begin transaction*/
2900 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2901 if (ret != SQLITE_OK) {
2902 _LOGD("Failed to begin transaction\n");
2907 _LOGD("Transaction Begin\n");
2909 ret = __disable_pkg(pkgid);
2911 ret = __enable_pkg(pkgid);
2914 _LOGD("__update_pkg_disable_condition_in_db failed. Rollback now\n");
2915 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2919 /*Commit transaction*/
2920 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2921 if (ret != SQLITE_OK) {
2922 _LOGD("Failed to commit transaction, Rollback now\n");
2923 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2927 _LOGD("Transaction Commit and End\n");
2930 pkgmgr_parser_close_db();
2934 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid, int is_disable)
2936 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid, _getuid(), is_disable);
2939 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2943 ret = pkgmgr_parser_check_and_create_db(uid);
2945 _LOGD("Failed to open DB\n");
2949 /*Begin transaction*/
2950 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2951 if (ret != SQLITE_OK) {
2952 _LOGD("Failed to begin transaction\n");
2956 _LOGD("Transaction Begin\n");
2958 ret = __disable_app(appid);
2960 ret = __enable_app(appid);
2962 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2963 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2966 /*Commit transaction*/
2967 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2968 if (ret != SQLITE_OK) {
2969 _LOGD("Failed to commit transaction, Rollback now\n");
2970 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2974 _LOGD("Transaction Commit and End\n");
2976 pkgmgr_parser_close_db();
2981 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
2985 if (appid == NULL) {
2986 _LOGD("Invalid parameter");
2990 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2992 _LOGD("Failed to open DB\n");
2996 /* Begin transaction */
2997 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2998 if (ret != SQLITE_OK) {
2999 _LOGD("Failed to begin transaction\n");
3003 _LOGD("Transaction Begin\n");
3005 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3007 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3008 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3011 /* Commit transaction */
3012 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3013 if (ret != SQLITE_OK) {
3014 _LOGD("Failed to commit transaction, Rollback now\n");
3015 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3019 _LOGD("Transaction Commit and End\n");
3021 pkgmgr_parser_close_db();
3025 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3027 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3030 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3034 if (appid == NULL) {
3035 _LOGD("Invalid parameter");
3039 ret = pkgmgr_parser_check_and_create_db(uid);
3041 _LOGD("Failed to open DB");
3045 /* Begin transaction */
3046 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3047 if (ret != SQLITE_OK) {
3048 _LOGD("Failed to begin transaction");
3052 _LOGD("Transaction Begin");
3055 ret = __enable_app_splash_screen(appid);
3057 ret = __disable_app_splash_screen(appid);
3059 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3060 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3063 /* Commit transaction */
3064 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3065 if (ret != SQLITE_OK) {
3066 _LOGD("Failed to commit transaction, Rollback now");
3067 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3071 _LOGD("Transaction Commit and End");
3074 pkgmgr_parser_close_db();
3078 API int pkgmgr_parser_update_app_label_info_in_usr_db(const char *appid, uid_t uid, const char *label)
3081 char query[MAX_QUERY_LEN] = {'\0'};
3083 if (appid == NULL || label == NULL) {
3084 _LOGE("Invalid parameter");
3088 ret = pkgmgr_parser_check_and_create_db(uid);
3090 _LOGD("Failed to open DB");
3094 /*Begin transaction*/
3095 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3096 if (ret != SQLITE_OK) {
3097 _LOGD("Failed to begin transaction\n");
3102 sqlite3_snprintf(MAX_QUERY_LEN, query,
3103 "UPDATE package_app_localized_info SET app_label=%Q WHERE " \
3104 "app_id=%Q AND app_label IS NOT NULL",
3106 ret = __exec_query(query);
3108 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3112 /* Commit transaction */
3113 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3114 if (ret != SQLITE_OK) {
3115 _LOGD("Failed to commit transaction, Rollback now");
3116 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3120 _LOGD("Transaction Commit and End");
3123 pkgmgr_parser_close_db();
3127 API int pkgmgr_parser_update_app_label_info_in_db(const char *appid, const char *label)
3129 return pkgmgr_parser_update_app_label_info_in_usr_db(appid, _getuid(), label);