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 "trusted TEXT NOT NULL, " \
276 "PRIMARY KEY(providerid, type) " \
277 "FOREIGN KEY(app_id) " \
278 "REFERENCES package_app_info(app_id) " \
281 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
282 "(app_id TEXT NOT NULL, " \
283 "uid INTEGER NOT NULL, " \
284 "is_disabled TEXT NOT NULL DEFAULT 'false', " \
285 "is_splash_screen_enabled TEXT NOT NULL, " \
286 "PRIMARY KEY(app_id, uid))"
288 #define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
289 "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
290 "AFTER UPDATE ON package_app_info_for_uid " \
292 " DELETE FROM package_app_info_for_uid WHERE " \
293 " is_splash_screen_enabled=" \
294 " (SELECT package_app_info.app_splash_screen_display FROM " \
295 " package_app_info, package_app_info_for_uid WHERE " \
296 " package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
299 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
300 "CREATE TABLE IF NOT EXISTS package_app_splash_screen " \
301 "(app_id TEXT NOT NULL, " \
302 "src TEXT NOT NULL, " \
303 "type TEXT NOT NULL, " \
304 "orientation TEXT NOT NULL, " \
305 "indicatordisplay TEXT, " \
306 "operation TEXT NOT NULL, " \
307 "color_depth TEXT NOT NULL DEFAULT '24', " \
308 "PRIMARY KEY(app_id, orientation, operation) " \
309 "FOREIGN KEY(app_id) " \
310 "REFERENCES package_app_info(app_id) " \
314 /* FIXME: duplicated at pkgmgrinfo_db.c */
315 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
316 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
317 " cert_info TEXT UNIQUE, " \
318 " cert_id INTEGER PRIMARY KEY, " \
319 " cert_ref_count INTEGER NOT NULL)"
321 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
322 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
323 " package TEXT PRIMARY KEY, " \
324 " package_count INTEGER, " \
325 " author_root_cert INTEGER, " \
326 " author_im_cert INTEGER, " \
327 " author_signer_cert INTEGER, " \
328 " dist_root_cert INTEGER, " \
329 " dist_im_cert INTEGER, " \
330 " dist_signer_cert INTEGER, " \
331 " dist2_root_cert INTEGER, " \
332 " dist2_im_cert INTEGER, " \
333 " dist2_signer_cert INTEGER)"
335 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO \
336 "CREATE TRIGGER IF NOT EXISTS update_cert_info " \
337 "AFTER UPDATE ON package_cert_info " \
338 "WHEN (NEW.package_count = 0) " \
340 " DELETE FROM package_cert_info WHERE package=OLD.package;" \
343 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2 \
344 "CREATE TRIGGER IF NOT EXISTS update_cert_info2 " \
345 "AFTER UPDATE ON package_cert_info " \
346 "WHEN (NEW.package_count = OLD.package_count + 1) " \
348 " UPDATE package_cert_index_info SET" \
349 " cert_ref_count = cert_ref_count - 1" \
350 " WHERE cert_id = OLD.author_root_cert" \
351 " OR cert_id = OLD.author_im_cert" \
352 " OR cert_id = OLD.author_signer_cert" \
353 " OR cert_id = OLD.dist_root_cert" \
354 " OR cert_id = OLD.dist_im_cert" \
355 " OR cert_id = OLD.dist_signer_cert" \
356 " OR cert_id = OLD.dist2_root_cert" \
357 " OR cert_id = OLD.dist2_im_cert" \
358 " OR cert_id = OLD.dist2_signer_cert;" \
361 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
362 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
363 "AFTER DELETE ON package_cert_info " \
365 " UPDATE package_cert_index_info SET" \
366 " cert_ref_count = cert_ref_count - 1" \
367 " WHERE cert_id = OLD.author_root_cert" \
368 " OR cert_id = OLD.author_im_cert" \
369 " OR cert_id = OLD.author_signer_cert" \
370 " OR cert_id = OLD.dist_root_cert" \
371 " OR cert_id = OLD.dist_im_cert" \
372 " OR cert_id = OLD.dist_signer_cert" \
373 " OR cert_id = OLD.dist2_root_cert" \
374 " OR cert_id = OLD.dist2_im_cert" \
375 " OR cert_id = OLD.dist2_signer_cert;" \
378 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
379 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
380 "AFTER UPDATE ON package_cert_index_info " \
381 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
382 " WHERE cert_id = OLD.cert_id) = 0) "\
384 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
387 static int __insert_application_info(manifest_x *mfx);
388 static int __insert_application_appcategory_info(manifest_x *mfx);
389 static int __insert_application_appcontrol_info(manifest_x *mfx);
390 static int __insert_application_appmetadata_info(manifest_x *mfx);
391 static int __insert_application_share_allowed_info(manifest_x *mfx);
392 static int __insert_application_share_request_info(manifest_x *mfx);
393 static int __insert_application_datacontrol_info(manifest_x *mfx);
394 static void __insert_application_locale_info(gpointer data, gpointer userdata);
395 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
396 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
397 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
398 static int __delete_subpkg_info_from_db(char *appid);
399 static int __delete_appinfo_from_db(char *db_table, const char *appid);
400 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
401 static int __exec_query(char *query);
402 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
403 char **label, char **license, char **icon, char **description, char **author);
404 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
405 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
406 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
407 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
408 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
409 static int __parserdb_change_perm(const char *db_file, uid_t uid);
411 #define REGULAR_USER 5000
412 static inline uid_t _getuid(void)
414 uid_t uid = getuid();
416 if (uid < REGULAR_USER)
417 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
422 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
425 __delete_subpkg_info_from_db(coltxt[0]);
430 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
435 char *error_message = NULL;
437 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
438 if (ret != SQLITE_OK) {
439 _LOGD("connect db [%s] failed!\n", db_path);
444 /* add user_version for db upgrade*/
445 query = sqlite3_mprintf("PRAGMA user_version=%d", (atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 + atoi(TIZEN_PATCH_VER)));
447 sqlite3_exec(handle, query, NULL, NULL, &error_message)) {
448 _LOGE("Don't execute query = %s error message = %s\n", query,
451 sqlite3_free(error_message);
457 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
459 manifest_x *mfx = (manifest_x *)data;
465 if (mfx->application == NULL)
467 app = (application_x *)mfx->application->data;
468 for (i = 0; i < ncols; i++) {
469 if (strcmp(colname[i], "app_id") == 0) {
471 appid = strdup(coltxt[i]);
472 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
474 status = strdup(coltxt[i]);
480 _LOGD("app id is NULL\n");
483 /*update guest mode visibility*/
484 for (tmp = mfx->application; tmp; tmp = tmp->next) {
485 app = (application_x *)tmp->data;
488 if (strcmp(app->appid, appid) == 0) {
489 free((void *)app->guestmode_visibility);
490 app->guestmode_visibility = strdup(status);
506 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
508 char *error_message = NULL;
509 char query[MAX_QUERY_LEN] = {'\0'};
510 sqlite3_snprintf(MAX_QUERY_LEN, query,
511 "SELECT app_id, app_guestmodevisibility FROM package_app_info " \
512 "WHERE package=%Q", mfx->package);
514 sqlite3_exec(pkgmgr_parser_db, query,
515 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
516 _LOGD("Don't execute query = %s error message = %s\n",
517 query, error_message);
518 sqlite3_free(error_message);
523 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
525 char *error_message = NULL;
527 sqlite3_exec(db_handle, db_query,
528 NULL, NULL, &error_message)) {
529 _LOGD("Don't execute query = %s error message = %s\n",
530 db_query, error_message);
531 sqlite3_free(error_message);
534 sqlite3_free(error_message);
538 static int __exec_query(char *query)
540 char *error_message = NULL;
542 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
543 _LOGE("Don't execute query = %s error message = %s\n", query,
545 sqlite3_free(error_message);
548 sqlite3_free(error_message);
550 if (strncmp(query, "DELETE", 6) && sqlite3_changes(pkgmgr_parser_db) == 0) {
551 _LOGE("No such record matches with given query : %s\n", query);
557 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
565 for (tmp = lbls; tmp; tmp = tmp->next) {
566 lbl = (label_x *)tmp->data;
570 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
572 for (tmp = lcns; tmp; tmp = tmp->next) {
573 lcn = (license_x *)tmp->data;
577 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
579 for (tmp = icns; tmp; tmp = tmp->next) {
580 icn = (icon_x *)tmp->data;
584 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
586 for (tmp = dcns; tmp; tmp = tmp->next) {
587 dcn = (description_x *)tmp->data;
591 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
593 for (tmp = aths; tmp; tmp = tmp->next) {
594 ath = (author_x *)tmp->data;
598 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
604 static GList *__create_icon_list(GList *appicon, GList *icns)
609 for (tmp = icns; tmp; tmp = tmp->next) {
610 icn = (icon_x *)tmp->data;
614 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
619 static GList *__create_image_list(GList *appimage, GList *imgs)
624 for (tmp = imgs; tmp; tmp = tmp->next) {
625 img = (image_x *)tmp->data;
629 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
634 static void __trimfunc(GList *trim_list)
636 char *trim_data = NULL;
640 list = g_list_first(trim_list);
643 trim_data = (char *)list->data;
646 if (strcmp(trim_data, prev) == 0) {
647 trim_list = g_list_remove(trim_list, trim_data);
648 list = g_list_first(trim_list);
657 list = g_list_next(list);
661 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
663 if (a == NULL || b == NULL)
665 if (strcmp((char *)a, (char *)b) == 0)
667 if (strcmp((char *)a, (char *)b) < 0)
669 if (strcmp((char *)a, (char *)b) > 0)
674 static int __check_dpi(const char *dpi_char, int dpi_int)
676 if (dpi_char == NULL)
679 if (strcasecmp(dpi_char, LDPI) == 0) {
680 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
684 } else if (strcasecmp(dpi_char, MDPI) == 0) {
685 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
689 } else if (strcasecmp(dpi_char, HDPI) == 0) {
690 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
694 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
695 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
699 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
700 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
708 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
711 char *icon_filename = NULL;
712 char modified_iconpath[BUFSIZE] = { '\0' };
713 char icon_path[BUFSIZE] = { '\0' };
717 if (orig_icon_path == NULL)
720 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
724 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
725 dpi_path[0] = "LDPI";
726 dpi_path[1] = "ldpi";
727 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
728 dpi_path[0] = "MDPI";
729 dpi_path[1] = "mdpi";
730 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
731 dpi_path[0] = "HDPI";
732 dpi_path[1] = "hdpi";
733 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
734 dpi_path[0] = "XHDPI";
735 dpi_path[1] = "xhdpi";
736 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
737 dpi_path[0] = "XXHDPI";
738 dpi_path[1] = "xxhdpi";
740 _LOGE("Unidentified dpi[%d]", dpi);
744 icon_filename = strrchr(orig_icon_path, '/');
745 if (icon_filename == NULL)
748 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
749 for (i = 0; i < 2; i++) {
750 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
751 if (access(modified_iconpath, F_OK) != -1) {
752 /* if exists, return modified icon path */
753 *new_icon_path = strdup(modified_iconpath);
761 static gint __compare_icon(gconstpointer a, gconstpointer b)
763 icon_x *icon = (icon_x *)a;
765 char *icon_folder_path = NULL;
767 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
770 if (icon->dpi != NULL)
773 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
775 icon->text = icon_folder_path;
781 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
783 icon_x *icon = (icon_x *)a;
784 int dpi = GPOINTER_TO_INT(b);
786 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
789 if (icon->dpi == NULL)
792 if (__check_dpi(icon->dpi, dpi) == 0)
798 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
800 icon_x *icon = (icon_x *)a;
801 char *lang = (char *)b;
802 char *icon_folder_path = NULL;
804 if (icon->dpi != NULL)
807 if (strcasecmp(icon->lang, lang) == 0) {
808 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
809 /* icon for no locale. check existance of folder-hierachied default icons */
810 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
812 icon->text = icon_folder_path;
821 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
823 icon_x *icon = (icon_x *)a;
824 char *lang = (char *)b;
827 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
831 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
837 static char *__find_icon(GList *icons, const char *lang)
844 /* first, find icon whose locale and dpi with given lang and system's dpi has matched */
845 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
847 icon = (icon_x *)tmp->data;
848 return (char *)icon->text;
851 /* if first has failed, find icon whose locale has matched */
852 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
854 icon = (icon_x *)tmp->data;
855 return (char *)icon->text;
858 /* if second has failed, find icon whose dpi has matched with system's dpi */
859 ret = system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
860 if (ret == SYSTEM_INFO_ERROR_NONE) {
861 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
863 icon = (icon_x *)tmp->data;
864 return (char *)icon->text;
868 /* last, find default icon marked as "No Locale" */
869 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
871 icon = (icon_x *)tmp->data;
872 return (char *)icon->text;
878 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
879 char **label, char **license, char **icon, char **description, char **author)
886 for (tmp = lbls; tmp; tmp = tmp->next) {
887 lbl = (label_x *)tmp->data;
891 if (strcmp(lbl->lang, (char *)data) == 0) {
892 *label = (char *)lbl->text;
897 for (tmp = lcns; tmp; tmp = tmp->next) {
898 lcn = (license_x *)tmp->data;
902 if (strcmp(lcn->lang, (char *)data) == 0) {
903 *license = (char *)lcn->text;
909 *icon = __find_icon(icns, (char *)data);
911 for (tmp = dcns; tmp; tmp = tmp->next) {
912 dcn = (description_x *)tmp->data;
916 if (strcmp(dcn->lang, (char *)data) == 0) {
917 *description = (char *)dcn->text;
922 for (tmp = aths; tmp; tmp = tmp->next) {
923 ath = (author_x *)tmp->data;
927 if (strcmp(ath->lang, (char *)data) == 0) {
928 *author = (char *)ath->text;
936 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
940 for (tmp = icns; tmp; tmp = tmp->next) {
941 icn = (icon_x *)tmp->data;
945 if (strcmp(icn->section, (char *)data) == 0) {
946 *icon = (char *)icn->text;
947 *resolution = (char *)icn->resolution;
954 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
958 for (tmp = imgs; tmp; tmp = tmp->next) {
959 img = (image_x *)tmp->data;
963 if (strcmp(img->section, (char *)data) == 0) {
964 *lang = (char *)img->lang;
965 *image = (char *)img->text;
972 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
977 char *description = NULL;
978 char *license = NULL;
982 manifest_x *mfx = (manifest_x *)userdata;
983 GList *lbl = mfx->label;
984 GList *lcn = mfx->license;
985 GList *icn = mfx->icon;
986 GList *dcn = mfx->description;
987 GList *ath = mfx->author;
989 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
990 if (!label && !description && !icon && !license && !author)
993 query = sqlite3_mprintf("INSERT INTO package_localized_info(package, package_locale, " \
994 "package_label, package_icon, package_description, package_license, package_author) VALUES" \
995 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1004 ret = __exec_query(query);
1006 _LOGD("Package Localized Info DB Insert failed\n");
1008 sqlite3_free(query);
1011 static void __insert_application_locale_info(gpointer data, gpointer userdata)
1017 char *locale = (char *)data;
1019 application_x *app = (application_x *)userdata;
1020 GList *lbl = app->label;
1021 GList *icn = app->icon;
1023 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1024 if (!label && !icon)
1027 query = sqlite3_mprintf("INSERT INTO package_app_localized_info(app_id, app_locale, " \
1028 "app_label, app_icon) VALUES" \
1029 "(%Q, %Q, %Q, %Q)", app->appid, (char *)data,
1031 ret = __exec_query(query);
1033 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1035 sqlite3_free(query);
1037 /*insert ui app locale info to pkg locale to get mainapp data */
1038 if (strcasecmp(app->mainapp, "true") == 0) {
1039 query = sqlite3_mprintf("INSERT OR REPLACE INTO package_localized_info(package, package_locale, "
1040 "package_label, package_icon, package_description, package_license, package_author) VALUES"
1042 "COALESCE((SELECT package_label FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1043 "COALESCE((SELECT package_icon FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1044 "(SELECT package_description FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1045 "(SELECT package_license FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1046 "(SELECT package_author FROM package_localized_info WHERE package=%Q AND package_locale=%Q))",
1047 app->package, locale,
1048 app->package, locale, label,
1049 app->package, locale, icon,
1050 app->package, locale,
1051 app->package, locale,
1052 app->package, locale);
1054 ret = __exec_query(query);
1056 _LOGE("Package Localized Info DB Insert failed");
1057 sqlite3_free(query);
1061 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1065 char *resolution = NULL;
1066 char query[MAX_QUERY_LEN] = {'\0'};
1068 application_x *app = (application_x *)userdata;
1069 GList *icn = app->icon;
1071 __extract_icon_data(data, icn, &icon, &resolution);
1072 if (!icon && !resolution)
1074 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO package_app_icon_section_info(app_id, " \
1075 "app_icon, app_icon_section, app_icon_resolution) VALUES " \
1076 "(%Q, %Q, %Q, %Q)", app->appid,
1077 icon, (char *)data, resolution);
1079 ret = __exec_query(query);
1081 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1085 static void __insert_application_image_info(gpointer data, gpointer userdata)
1090 char query[MAX_QUERY_LEN] = {'\0'};
1092 application_x *app = (application_x *)userdata;
1093 GList *image = app->image;
1095 __extract_image_data(data, image, &lang, &img);
1098 sqlite3_snprintf(MAX_QUERY_LEN, query,
1099 "INSERT INTO package_app_image_info(app_id, app_locale, " \
1100 "app_image_section, app_image) VALUES" \
1101 "(%Q, %Q, %Q, %Q)", app->appid, lang, (char *)data, img);
1103 ret = __exec_query(query);
1105 _LOGD("Package UiApp image Info DB Insert failed\n");
1110 static int __insert_mainapp_info(manifest_x *mfx)
1115 char query[MAX_QUERY_LEN] = {'\0'};
1116 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1117 app = (application_x *)tmp->data;
1120 if (strcasecmp(app->mainapp, "True") == 0)
1121 mfx->mainapp_id = strdup(app->appid);
1124 if (mfx->mainapp_id == NULL) {
1125 if (mfx->application == NULL)
1127 app = (application_x *)mfx->application->data;
1130 free((void *)app->mainapp);
1131 app->mainapp = strdup("true");
1132 mfx->mainapp_id = strdup(app->appid);
1135 memset(query, '\0', MAX_QUERY_LEN);
1136 sqlite3_snprintf(MAX_QUERY_LEN, query,
1137 "UPDATE package_info SET mainapp_id=%Q WHERE package=%Q", mfx->mainapp_id, mfx->package);
1138 ret = __exec_query(query);
1140 _LOGD("Package Info DB update Failed\n");
1147 static int __convert_background_category(GList *category_list)
1150 GList *tmp_list = category_list;
1151 char *category_data = NULL;
1153 if (category_list == NULL)
1156 while (tmp_list != NULL) {
1157 category_data = (char *)tmp_list->data;
1158 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0)
1159 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1160 else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0)
1161 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1162 else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0)
1163 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1164 else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0)
1165 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1166 else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0)
1167 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1168 else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0)
1169 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1170 else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0)
1171 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1173 _LOGE("Unidentified category [%s]", category_data);
1174 tmp_list = g_list_next(tmp_list);
1180 static const char *__find_effective_appid(GList *metadata_list)
1185 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1186 md = (metadata_x *)tmp_list->data;
1187 if (md == NULL || md->key == NULL)
1190 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1199 static char *__get_bool(char *value, bool is_true)
1201 if (value != NULL) {
1202 if (!strcmp(value, ""))
1203 return (is_true) ? "true" : "false";
1207 return (is_true) ? "true" : "false";
1210 /* _PRODUCT_LAUNCHING_ENHANCED_
1211 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1213 static int __insert_application_info(manifest_x *mfx)
1218 int background_value = 0;
1219 char query[MAX_QUERY_LEN] = {'\0'};
1221 const char *effective_appid;
1224 type = strdup(mfx->type);
1226 type = strdup("tpk");
1228 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1229 app = (application_x *)tmp->data;
1233 background_value = __convert_background_category(app->background_category);
1234 if (background_value < 0) {
1235 _LOGE("Failed to retrieve background value[%d]", background_value);
1236 background_value = 0;
1239 effective_appid = __find_effective_appid(app->metadata);
1241 sqlite3_snprintf(MAX_QUERY_LEN, query,
1242 "INSERT INTO package_app_info(" \
1243 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1244 "app_onboot, app_multiple, app_autorestart, app_taskmanage, " \
1245 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1246 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1247 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1248 "app_launch_mode, app_ui_gadget, app_support_mode, app_support_disable, component_type, package, " \
1249 "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, " \
1250 "app_api_version, app_effective_appid, app_splash_screen_display, app_package_system, app_removable, " \
1251 "app_package_installed_time, app_support_ambient, app_setup_appid) " \
1253 "%Q, %Q, %Q, LOWER(%Q), %Q, " \
1254 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1255 "%Q, %Q, %Q, %Q, %Q, " \
1256 "LOWER(%Q), %Q, %Q, LOWER(%Q), %Q, " \
1257 "LOWER(%Q), LOWER(%Q), %Q, %Q, LOWER(%Q), " \
1258 "COALESCE(%Q, 'caller'), LOWER(%Q), %Q, LOWER(%Q), %Q, %Q, " \
1259 "%Q, %Q, %d, %Q, %Q, " \
1260 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1261 "%Q, LOWER(%Q), %Q)", \
1262 app->appid, app->component_type, app->exec, __get_bool(app->nodisplay, false), app->type,
1263 __get_bool(app->onboot, false), __get_bool(app->multiple, false), __get_bool(app->autorestart, false), __get_bool(app->taskmanage, false),
1264 app->hwacceleration, app->screenreader, app->mainapp, app->recentimage, app->launchcondition,
1265 __get_bool(app->indicatordisplay, true), app->portraitimg, app->landscapeimg,
1266 __get_bool(app->guestmode_visibility, true), app->permission_type,
1267 __get_bool(mfx->preload, false), __get_bool(app->submode, false), app->submode_mainid, mfx->installed_storage, __get_bool(app->process_pool, false),
1268 app->launch_mode, __get_bool(app->ui_gadget, false), mfx->support_mode, __get_bool(mfx->support_disable, false), app->component_type, mfx->package,
1269 mfx->tep_name, mfx->zip_mount_file, background_value, type, mfx->root_path, mfx->api_version,
1270 effective_appid, __get_bool(app->splash_screen_display, false), __get_bool(mfx->system, false), __get_bool(mfx->removable, true),
1271 mfx->installed_time, __get_bool(app->support_ambient, false), app->setup_appid);
1273 ret = __exec_query(query);
1275 _LOGD("Package UiApp Info DB Insert Failed\n");
1280 memset(query, '\0', MAX_QUERY_LEN);
1289 static int __insert_application_appcategory_info(manifest_x *mfx)
1296 char query[MAX_QUERY_LEN] = {'\0'};
1297 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1298 app = (application_x *)app_tmp->data;
1301 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1302 ct = (const char *)ct_tmp->data;
1305 sqlite3_snprintf(MAX_QUERY_LEN, query,
1306 "INSERT INTO package_app_app_category(app_id, category) " \
1309 ret = __exec_query(query);
1311 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1314 memset(query, '\0', MAX_QUERY_LEN);
1320 static int __insert_application_appmetadata_info(manifest_x *mfx)
1327 char query[MAX_QUERY_LEN] = {'\0'};
1328 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1329 app = (application_x *)app_tmp->data;
1332 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1333 md = (metadata_x *)md_tmp->data;
1337 sqlite3_snprintf(MAX_QUERY_LEN, query,
1338 "INSERT INTO package_app_app_metadata(app_id, md_key, md_value) " \
1339 "VALUES(%Q, %Q, %Q)",\
1340 app->appid, md->key, md->value ? md->value : NULL);
1341 ret = __exec_query(query);
1343 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1347 memset(query, '\0', MAX_QUERY_LEN);
1353 static int __insert_application_apppermission_info(manifest_x *mfx)
1360 char query[MAX_QUERY_LEN] = {'\0'};
1361 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1362 app = (application_x *)app_tmp->data;
1365 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1366 pm = (permission_x *)pm_tmp->data;
1369 sqlite3_snprintf(MAX_QUERY_LEN, query,
1370 "INSERT INTO package_app_app_permission(app_id, pm_type, pm_value) " \
1371 "VALUES(%Q, %Q, %Q)",\
1372 app->appid, pm->type, pm->value);
1373 ret = __exec_query(query);
1375 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1378 memset(query, '\0', MAX_QUERY_LEN);
1384 static int __insert_application_appcontrol_info(manifest_x *mfx)
1388 GList *acontrol_tmp;
1389 appcontrol_x *acontrol;
1391 char query[MAX_QUERY_LEN] = {'\0'};
1392 char buf[BUFSIZE] = {'\0'};
1393 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1394 app = (application_x *)app_tmp->data;
1397 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1398 acontrol = (appcontrol_x *)acontrol_tmp->data;
1399 if (acontrol == NULL)
1401 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1402 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1403 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1404 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1405 sqlite3_snprintf(MAX_QUERY_LEN, query,
1406 "INSERT INTO package_app_app_control(app_id, app_control) " \
1409 ret = __exec_query(query);
1411 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1414 memset(query, '\0', MAX_QUERY_LEN);
1420 static int __insert_application_datacontrol_info(manifest_x *mfx)
1427 char query[MAX_QUERY_LEN] = {'\0'};
1429 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1430 app = (application_x *)app_tmp->data;
1433 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1434 dc = (datacontrol_x *)dc_tmp->data;
1437 sqlite3_snprintf(MAX_QUERY_LEN, query,
1438 "INSERT INTO package_app_data_control(app_id, providerid, access, type, trusted) " \
1439 "VALUES(%Q, %Q, %Q, %Q, %Q)",\
1444 __get_bool(dc->trusted, false));
1446 ret = __exec_query(query);
1448 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1451 memset(query, '\0', MAX_QUERY_LEN);
1457 static int __insert_application_share_request_info(manifest_x *mfx)
1466 char query[MAX_QUERY_LEN] = {'\0'};
1467 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1468 app = (application_x *)app_tmp->data;
1471 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1472 ds = (datashare_x *)ds_tmp->data;
1475 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1476 rq = (const char *)rq_tmp->data;
1479 sqlite3_snprintf(MAX_QUERY_LEN, query,
1480 "INSERT INTO package_app_share_request(app_id, data_share_request) " \
1483 ret = __exec_query(query);
1485 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1488 memset(query, '\0', MAX_QUERY_LEN);
1495 static int __insert_application_share_allowed_info(manifest_x *mfx)
1506 char query[MAX_QUERY_LEN] = {'\0'};
1507 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1508 app = (application_x *)app_tmp->data;
1511 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1512 ds = (datashare_x *)ds_tmp->data;
1515 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1516 df = (define_x *)df_tmp->data;
1519 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1520 al = (const char *)al_tmp->data;
1523 sqlite3_snprintf(MAX_QUERY_LEN, query,
1524 "INSERT INTO package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1525 "VALUES(%Q, %Q, %Q)",\
1526 app->appid, df->path, al);
1527 ret = __exec_query(query);
1529 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1532 memset(query, '\0', MAX_QUERY_LEN);
1540 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1542 splashscreen_x *ss = (splashscreen_x *)a;
1543 const char *orientation = (const char *)b;
1546 if (ss->operation || ss->dpi == NULL)
1549 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1553 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1559 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1561 splashscreen_x *ss = (splashscreen_x *)a;
1562 const char *orientation = (const char *)b;
1564 if (ss->operation || ss->dpi)
1567 if (strcasecmp(ss->orientation, orientation) == 0)
1573 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1574 const char *orientation)
1578 tmp = g_list_find_custom(splashscreens, orientation,
1579 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1581 return (splashscreen_x *)tmp->data;
1583 tmp = g_list_find_custom(splashscreens, orientation,
1584 (GCompareFunc)__compare_splashscreen_with_orientation);
1586 return (splashscreen_x *)tmp->data;
1591 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1593 splashscreen_x *ss = (splashscreen_x *)data;
1594 GList **list = (GList **)user_data;
1597 if (ss->operation == NULL || ss->dpi == NULL)
1600 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1604 if (__check_dpi(ss->dpi, dpi) != 0)
1607 *list = g_list_append(*list, ss);
1610 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1612 splashscreen_x *ss = (splashscreen_x *)data;
1613 GList **list = (GList **)user_data;
1614 splashscreen_x *ss_tmp;
1617 if (ss->operation == NULL || ss->dpi)
1620 for (tmp = *list; tmp; tmp = tmp->next) {
1621 ss_tmp = (splashscreen_x *)tmp->data;
1622 if (ss_tmp->operation
1623 && strcmp(ss_tmp->operation, ss->operation) == 0
1624 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1628 *list = g_list_append(*list, ss);
1631 static GList *__find_splashscreens(GList *splashscreens)
1636 g_list_foreach(splashscreens,
1637 __find_appcontrol_splashscreen_with_dpi, &list);
1638 g_list_foreach(splashscreens,
1639 __find_appcontrol_splashscreen, &list);
1641 ss = __find_default_splashscreen(splashscreens, "portrait");
1643 list = g_list_append(list, ss);
1644 ss = __find_default_splashscreen(splashscreens, "landscape");
1646 list = g_list_append(list, ss);
1651 static int __insert_application_splashscreen_info(manifest_x *mfx)
1659 char query[MAX_QUERY_LEN] = {'\0'};
1661 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1662 app = (application_x *)app_tmp->data;
1663 if (app == NULL || app->splashscreens == NULL)
1666 ss_tmp = __find_splashscreens(app->splashscreens);
1670 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1671 ss = (splashscreen_x *)tmp->data;
1672 sqlite3_snprintf(MAX_QUERY_LEN, query,
1673 "INSERT INTO package_app_splash_screen" \
1674 "(app_id, src, type, orientation, indicatordisplay, " \
1675 "operation, color_depth) " \
1676 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1677 app->appid, ss->src, ss->type, ss->orientation,
1678 ss->indicatordisplay, ss->operation,
1681 ret = __exec_query(query);
1683 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1686 memset(query, '\0', MAX_QUERY_LEN);
1688 g_list_free(ss_tmp);
1693 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1697 privilege_x *pv = NULL;
1698 char query[MAX_QUERY_LEN] = { '\0' };
1701 const char *auth_name = NULL;
1702 const char *auth_email = NULL;
1703 const char *auth_href = NULL;
1705 GList *pkglocale = NULL;
1706 GList *applocale = NULL;
1707 GList *appicon = NULL;
1708 GList *appimage = NULL;
1710 int temp_pkg_mode = 0;
1711 int temp_app_mode = 0;
1712 char pkg_mode[MAX_INTEGER_LENGTH] = {'\0'};
1713 application_x *up_support_mode = NULL;
1714 GList *list_up = NULL;
1716 if (mfx->author && mfx->author->data) {
1717 author = (author_x *)mfx->author->data;
1719 auth_name = author->text;
1721 auth_email = author->email;
1723 auth_href = author->href;
1726 if (mfx->support_mode)
1727 temp_pkg_mode = atoi(mfx->support_mode);
1729 /* FIXME : OR-ing should be fixed to not to store whole support mode */
1730 list_up = mfx->application;
1731 while (list_up != NULL) {
1732 up_support_mode = (application_x *)list_up->data;
1733 if (up_support_mode->support_mode) {
1734 temp_app_mode = atoi(up_support_mode->support_mode);
1735 temp_pkg_mode |= temp_app_mode;
1737 list_up = list_up->next;
1739 snprintf(pkg_mode, MAX_INTEGER_LENGTH, "%d", temp_pkg_mode);
1741 if (mfx->support_mode)
1742 free((void *)mfx->support_mode);
1743 mfx->support_mode = strdup(pkg_mode);
1745 /*Insert in the package_info DB*/
1746 sqlite3_snprintf(MAX_QUERY_LEN, query,
1747 "INSERT INTO package_info(" \
1748 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1749 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1750 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1751 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1752 "mainapp_id, package_url, root_path, csc_path, package_support_mode, package_support_disable) " \
1754 "%Q, %Q, %Q, %Q, %Q, %Q, " \
1755 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1756 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), %Q, " \
1757 "%Q, %Q, %Q, %Q, %Q, " \
1758 "%Q, %Q, %Q, %Q, %Q, LOWER(%Q))",
1759 mfx->package, mfx->type, mfx->version, mfx->api_version, mfx->tep_name, mfx->zip_mount_file,
1760 mfx->installlocation, mfx->package_size, __get_bool(mfx->removable, true), __get_bool(mfx->preload, false), __get_bool(mfx->readonly, false),
1761 __get_bool(mfx->update, false), __get_bool(mfx->appsetting, false), __get_bool(mfx->nodisplay_setting, false), __get_bool(mfx->system, false), auth_name,
1762 auth_email, auth_href, mfx->installed_time, mfx->installed_storage,
1763 mfx->storeclient_id,
1764 mfx->mainapp_id, mfx->package_url, mfx->root_path, mfx->csc_path, mfx->support_mode, __get_bool(mfx->support_disable, false));
1766 ret = __exec_query(query);
1768 _LOGD("Package Info DB Insert Failed\n");
1772 /*Insert in the package_privilege_info DB*/
1773 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1774 pv = (privilege_x *)tmp->data;
1777 memset(query, '\0', MAX_QUERY_LEN);
1778 sqlite3_snprintf(MAX_QUERY_LEN, query,
1779 "INSERT INTO package_privilege_info(package, privilege, type) " \
1780 "VALUES(%Q, %Q, %Q)",\
1781 mfx->package, pv->value, pv->type);
1782 ret = __exec_query(query);
1784 _LOGD("Package Privilege Info DB Insert Failed\n");
1789 if (mfx->application != NULL) {
1790 ret = __insert_mainapp_info(mfx);
1795 /*Insert the package locale*/
1796 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1797 /*remove duplicated data in pkglocale*/
1798 __trimfunc(pkglocale);
1800 /*Insert the app locale, icon, image info */
1801 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1802 app = (application_x *)tmp->data;
1805 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1806 appicon = __create_icon_list(appicon, app->icon);
1807 appimage = __create_image_list(appimage, app->image);
1809 /*remove duplicated data in applocale*/
1810 __trimfunc(applocale);
1811 __trimfunc(appicon);
1812 __trimfunc(appimage);
1814 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1816 /*native app locale info*/
1817 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1818 app = (application_x *)tmp->data;
1821 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1822 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1823 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1826 g_list_free(pkglocale);
1828 g_list_free(applocale);
1830 g_list_free(appicon);
1832 g_list_free(appimage);
1835 /*Insert in the package_app_info DB*/
1836 ret = __insert_application_info(mfx);
1839 /*Insert in the package_app_app_control DB*/
1840 ret = __insert_application_appcontrol_info(mfx);
1844 /*Insert in the package_app_app_category DB*/
1845 ret = __insert_application_appcategory_info(mfx);
1849 /*Insert in the package_app_app_metadata DB*/
1850 ret = __insert_application_appmetadata_info(mfx);
1854 /*Insert in the package_app_app_permission DB*/
1855 ret = __insert_application_apppermission_info(mfx);
1859 /*Insert in the package_app_share_allowed DB*/
1860 ret = __insert_application_share_allowed_info(mfx);
1864 /*Insert in the package_app_share_request DB*/
1865 ret = __insert_application_share_request_info(mfx);
1869 /*Insert in the package_app_data_control DB*/
1870 ret = __insert_application_datacontrol_info(mfx);
1874 /*Insert in the package_app_splash_screen DB*/
1875 ret = __insert_application_splashscreen_info(mfx);
1883 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1885 char query[MAX_QUERY_LEN] = { '\0' };
1888 sqlite3_snprintf(MAX_QUERY_LEN, query,
1889 "DELETE FROM %q where app_id=%Q", db_table, appid);
1890 ret = __exec_query(query);
1892 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1898 static int __delete_subpkg_info_from_db(char *appid)
1902 ret = __delete_appinfo_from_db("package_app_info", appid);
1905 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1908 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1911 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1914 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1917 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1920 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1923 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1926 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1929 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1932 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1935 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
1942 static int __delete_subpkg_from_db(manifest_x *mfx)
1944 char query[MAX_QUERY_LEN] = { '\0' };
1945 char *error_message = NULL;
1947 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT app_id FROM package_app_info WHERE package=%Q", mfx->package);
1949 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1950 _LOGE("Don't execute query = %s error message = %s\n", query,
1952 sqlite3_free(error_message);
1955 sqlite3_free(error_message);
1960 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1962 char query[MAX_QUERY_LEN] = { '\0' };
1967 /*Delete from Package Info DB*/
1968 sqlite3_snprintf(MAX_QUERY_LEN, query,
1969 "DELETE FROM package_info WHERE package=%Q", mfx->package);
1970 ret = __exec_query(query);
1972 _LOGD("Package Info DB Delete Failed\n");
1975 memset(query, '\0', MAX_QUERY_LEN);
1977 /*Delete from Package Localized Info*/
1978 sqlite3_snprintf(MAX_QUERY_LEN, query,
1979 "DELETE FROM package_localized_info WHERE package=%Q", mfx->package);
1980 ret = __exec_query(query);
1982 _LOGD("Package Localized Info DB Delete Failed\n");
1986 /*Delete from Package Privilege Info*/
1987 sqlite3_snprintf(MAX_QUERY_LEN, query,
1988 "DELETE FROM package_privilege_info WHERE package=%Q", mfx->package);
1989 ret = __exec_query(query);
1991 _LOGD("Package Privilege Info DB Delete Failed\n");
1995 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1996 app = (application_x *)tmp->data;
1999 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2002 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2005 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2008 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2011 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2014 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2017 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2020 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2023 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2026 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2029 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2032 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2037 /* if main package has sub pkg, delete sub pkg data*/
2038 __delete_subpkg_from_db(mfx);
2043 static int __disable_app(const char *appid)
2046 char query[MAX_QUERY_LEN] = {'\0'};
2047 sqlite3_snprintf(MAX_QUERY_LEN, query,
2048 "UPDATE package_app_info SET app_disable='true' WHERE app_id=%Q",
2050 ret = __exec_query(query);
2052 _LOGD("Insert global app disable failed\n");
2057 static int __enable_app(const char *appid)
2060 char query[MAX_QUERY_LEN] = {'\0'};
2061 sqlite3_snprintf(MAX_QUERY_LEN, query,
2062 "UPDATE package_app_info SET app_disable='false' WHERE app_id=%Q",
2064 ret = __exec_query(query);
2066 _LOGD("Insert global app disable failed\n");
2071 static int __disable_pkg(const char *pkgid)
2074 char query[MAX_QUERY_LEN] = {'\0'};
2075 sqlite3_snprintf(MAX_QUERY_LEN, query,
2076 "UPDATE package_info SET package_disable='true' WHERE package=%Q",
2078 ret = __exec_query(query);
2080 _LOGD("Update pkg disable info has failed\n");
2085 static int __enable_pkg(const char *pkgid)
2088 char query[MAX_QUERY_LEN] = {'\0'};
2089 sqlite3_snprintf(MAX_QUERY_LEN, query,
2090 "UPDATE package_info SET package_disable='false' WHERE package=%Q",
2092 ret = __exec_query(query);
2094 _LOGD("Update pkg disable info has failed\n");
2099 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2102 char query[MAX_QUERY_LEN] = { '\0', };
2104 const char *val = NULL;
2109 sqlite3_snprintf(MAX_QUERY_LEN, query,
2110 "SELECT COUNT(*) FROM "
2111 "package_app_info_for_uid WHERE app_id=%Q "
2112 "AND uid=%d", appid, (int)uid);
2114 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2115 if (ret != SQLITE_OK) {
2116 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2117 return PMINFO_R_ERROR;
2120 if (sqlite3_step(stmt) != SQLITE_ROW) {
2121 LOGE("failed to step");
2122 sqlite3_finalize(stmt);
2123 return PMINFO_R_ERROR;
2126 val = (const char *)sqlite3_column_text(stmt, 0);
2128 sqlite3_finalize(stmt);
2133 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2136 char query[MAX_QUERY_LEN] = { '\0', };
2138 ret = __check_appinfo_for_uid_table(appid, uid);
2140 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2143 } else if (ret == 0) {
2144 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2145 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2146 "VALUES(%Q, %d, 'true', "
2147 "(SELECT app_splash_screen_display FROM package_app_info WHERE app_id=%Q))",
2148 appid, (int)uid, appid);
2150 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2151 "package_app_info_for_uid SET is_disabled='true' "
2152 "WHERE app_id=%Q AND uid=%d", appid, (int)uid);
2155 ret = __exec_query(query);
2157 _LOGD("Add global app disable info failed\n");
2162 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2165 char query[MAX_QUERY_LEN] = {'\0'};
2167 ret = __check_appinfo_for_uid_table(appid, uid);
2169 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2172 } else if (ret > 0) {
2173 sqlite3_snprintf(MAX_QUERY_LEN, query,
2174 "UPDATE package_app_info_for_uid SET "
2175 "is_disabled='false' WHERE app_id=%Q AND "
2176 "uid=%d", appid, (int)uid);
2179 ret = __exec_query(query);
2181 _LOGD("Remove global app disable info failed\n");
2186 static int __update_global_app_splash_screen_for_user(const char *appid,
2187 uid_t uid, int flag)
2190 char query[MAX_QUERY_LEN] = { '\0', };
2192 ret = __check_appinfo_for_uid_table(appid, uid);
2194 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2197 } else if (ret == 0) {
2198 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2199 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2200 "VALUES(%Q, %d, %Q)", appid, (int)uid,
2201 flag ? "true" : "false");
2203 sqlite3_snprintf(MAX_QUERY_LEN, query,
2204 "UPDATE package_app_info_for_uid SET "
2205 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2206 "uid=%d", flag ? "true" : "false", appid, (int)uid);
2209 ret = __exec_query(query);
2211 _LOGD("update global app splash screen info failed\n");
2216 static int __disable_app_splash_screen(const char *appid)
2219 char query[MAX_QUERY_LEN] = {'\0'};
2221 sqlite3_snprintf(MAX_QUERY_LEN, query,
2222 "UPDATE package_app_info SET app_splash_screen_display='false' WHERE app_id=%Q",
2224 ret = __exec_query(query);
2226 _LOGD("Failed to update app_palsh_screen_display");
2231 static int __enable_app_splash_screen(const char *appid)
2234 char query[MAX_QUERY_LEN] = {'\0'};
2236 sqlite3_snprintf(MAX_QUERY_LEN, query,
2237 "UPDATE package_app_info SET app_splash_screen_display='true' WHERE app_id=%Q",
2239 ret = __exec_query(query);
2241 _LOGD("Failed to update app_splash_screen_display");
2246 API int pkgmgr_parser_initialize_db(uid_t uid)
2252 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2254 _LOGD("package info DB initialization failed\n");
2257 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2259 _LOGD("package localized info DB initialization failed\n");
2262 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2264 _LOGD("package app app privilege DB initialization failed\n");
2267 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2269 _LOGD("package app info DB initialization failed\n");
2272 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2274 _LOGD("package app localized info DB initialization failed\n");
2277 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2279 _LOGD("package app icon localized info DB initialization failed\n");
2282 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2284 _LOGD("package app image info DB initialization failed\n");
2287 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2289 _LOGD("package app app control DB initialization failed\n");
2292 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2294 _LOGD("package app app category DB initialization failed\n");
2297 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2299 _LOGD("package app app category DB initialization failed\n");
2302 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2304 _LOGD("package app app permission DB initialization failed\n");
2307 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2309 _LOGD("package app share allowed DB initialization failed\n");
2312 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2314 _LOGD("package app share request DB initialization failed\n");
2317 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2319 _LOGD("package app data control DB initialization failed\n");
2323 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2325 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2329 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2331 _LOGD("package app splash screen DB initialization failed\n");
2335 /* Trigger package_app_info_for_uid */
2336 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2338 _LOGD("package app info for uid DB initialization failed\n");
2343 /* TODO: refactor this code */
2344 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2346 _LOGD("package cert info DB initialization failed\n");
2349 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2351 _LOGD("package cert index info DB initialization failed\n");
2354 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO);
2356 _LOGD("package cert info DB initialization failed\n");
2359 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2);
2361 _LOGD("package cert info DB initialization failed\n");
2364 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2366 _LOGD("package cert info DB initialization failed\n");
2369 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2371 _LOGD("package cert index info DB initialization failed\n");
2375 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2376 if (db_path == NULL) {
2377 _LOGD("Failed to get user cert db path - GLOBAL_USER");
2379 ret = __parserdb_change_perm(db_path, GLOBAL_USER);
2381 _LOGD("Failed to change cert db permission");
2385 db_path = getUserPkgParserDBPathUID(uid);
2386 if (db_path == NULL) {
2387 _LOGD("Failed to get user pkg parser db path - %d", uid);
2389 ret = __parserdb_change_perm(db_path, uid);
2391 _LOGD("Failed to change parser db permission\n");
2398 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2401 char pwuid_buf[1024];
2402 char journal_file[BUFSIZE];
2407 struct passwd userinfo, *result = NULL;
2408 files[0] = (char *)db_file;
2409 files[1] = journal_file;
2413 if (db_file == NULL)
2416 if (getuid() != OWNER_ROOT) /* At this time we should be root to apply this */
2418 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2419 if (uid == OWNER_ROOT || uid == GLOBAL_USER) {
2420 ret = getpwnam_r(APPFW_USER, &userinfo, buf, sizeof(buf), &result);
2421 if (ret != 0 || result == NULL)
2423 uid = userinfo.pw_uid;
2426 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2427 if (ret != 0 || result == NULL) {
2428 _LOGE("FAIL: user %d doesn't exist", uid);
2431 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2433 for (i = 0; files[i]; i++) {
2434 fd = open(files[i], O_RDONLY);
2436 if (strerror_r(errno, buf, sizeof(buf)))
2437 strncpy(buf, "", BUFSIZE - 1);
2438 _LOGD("FAIL : open %s : %s", files[i], buf);
2441 ret = fstat(fd, &sb);
2443 if (strerror_r(errno, buf, sizeof(buf)))
2444 strncpy(buf, "", BUFSIZE - 1);
2445 _LOGD("FAIL : fstat %s : %s", files[i], buf);
2449 if (S_ISLNK(sb.st_mode)) {
2450 _LOGE("FAIL : %s is symlink!", files[i]);
2454 ret = fchown(fd, uid, userinfo.pw_gid);
2456 if (strerror_r(errno, buf, sizeof(buf)))
2457 strncpy(buf, "", BUFSIZE - 1);
2458 _LOGD("FAIL : fchown %s %d.%d : %s", files[i], uid,
2459 userinfo.pw_gid, buf);
2464 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2465 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2467 ret = fchmod(fd, mode);
2469 if (strerror_r(errno, buf, sizeof(buf)))
2470 strncpy(buf, "", BUFSIZE - 1);
2471 _LOGD("FAIL : fchmod %s 0664 : %s", files[i], buf);
2476 SET_SMACK_LABEL(files[i]);
2481 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2486 if (getuid() != OWNER_ROOT) {
2487 _LOGE("Only root user is allowed");
2491 db_path = getUserPkgParserDBPathUID(uid);
2492 if (db_path == NULL) {
2493 _LOGE("Failed to get pkg parser db path - %d", uid);
2497 if (access(db_path, F_OK) != -1) {
2498 _LOGE("Manifest db for user %d is already exists", uid);
2504 db_path = getUserPkgCertDBPathUID(uid);
2505 if (db_path == NULL) {
2506 _LOGE("Failed to get pkg cert db path - %d", uid);
2510 if (access(db_path, F_OK) != -1) {
2511 _LOGE("Cert db for user %d is already exists", uid);
2517 ret = pkgmgr_parser_check_and_create_db(uid);
2520 ret = pkgmgr_parser_initialize_db(uid);
2522 pkgmgr_parser_close_db();
2525 pkgmgr_parser_close_db();
2530 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2535 db_path = getUserPkgParserDBPathUID(uid);
2536 if (db_path == NULL) {
2537 _LOGD("Failed to get pkg parser db path - %d", uid);
2542 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, db_path);
2544 _LOGD("Manifest DB creation Failed\n");
2550 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2551 if (db_path == NULL) {
2552 _LOGE("Failed to get pkg cert db path - GLOBAL_USER");
2557 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, db_path);
2559 _LOGD("Cert DB creation Failed\n");
2569 void pkgmgr_parser_close_db(void)
2571 sqlite3_close(pkgmgr_parser_db);
2572 sqlite3_close(pkgmgr_cert_db);
2576 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2578 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2580 _LOGD("manifest pointer is NULL\n");
2584 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2586 _LOGD("Failed to open DB\n");
2589 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2592 /*Begin transaction*/
2593 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2594 if (ret != SQLITE_OK) {
2595 _LOGD("Failed to begin transaction\n");
2599 _LOGD("Transaction Begin\n");
2600 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2602 _LOGD("Insert into DB failed. Rollback now\n");
2603 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2606 /*Commit transaction*/
2607 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2608 if (ret != SQLITE_OK) {
2609 _LOGD("Failed to commit transaction. Rollback now\n");
2610 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2614 _LOGD("Transaction Commit and End\n");
2616 pkgmgr_parser_close_db();
2620 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2622 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2624 _LOGD("manifest pointer is NULL\n");
2628 ret = pkgmgr_parser_check_and_create_db(uid);
2630 _LOGD("Failed to open DB\n");
2633 ret = pkgmgr_parser_initialize_db(uid);
2636 /*Begin transaction*/
2637 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2638 if (ret != SQLITE_OK) {
2639 _LOGD("Failed to begin transaction\n");
2643 _LOGD("Transaction Begin\n");
2644 ret = __insert_manifest_info_in_db(mfx, uid);
2646 _LOGD("Insert into DB failed. Rollback now\n");
2647 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2650 /*Commit transaction*/
2651 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2652 if (ret != SQLITE_OK) {
2653 _LOGD("Failed to commit transaction. Rollback now\n");
2654 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2658 _LOGD("Transaction Commit and End\n");
2660 pkgmgr_parser_close_db();
2664 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2666 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, _getuid());
2669 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2671 if (pkgid == NULL || tep_path == NULL) {
2672 _LOGE("invalid parameter");
2679 ret = pkgmgr_parser_check_and_create_db(uid);
2681 _LOGD("Failed to open DB\n");
2684 ret = pkgmgr_parser_initialize_db(uid);
2688 /*Begin transaction*/
2689 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2690 if (ret != SQLITE_OK) {
2691 _LOGD("Failed to begin transaction\n");
2695 _LOGD("Transaction Begin\n");
2698 /* Updating TEP info in "package_info" table */
2699 query = sqlite3_mprintf("UPDATE package_info "\
2700 "SET package_tep_name = %Q "\
2701 "WHERE package = %Q", tep_path, pkgid);
2703 ret = __exec_query(query);
2704 sqlite3_free(query);
2705 if (ret != SQLITE_OK) {
2706 ret = PM_PARSER_R_ERROR;
2707 _LOGE("sqlite exec failed to insert entries into package_info!!");
2711 /* Updating TEP info in "package_app_info" table */
2712 query = sqlite3_mprintf("UPDATE package_app_info "\
2713 "SET app_tep_name = %Q "\
2714 "WHERE package = %Q", tep_path, pkgid);
2716 ret = __exec_query(query);
2717 sqlite3_free(query);
2718 if (ret != SQLITE_OK) {
2719 ret = PM_PARSER_R_ERROR;
2720 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2724 /*Commit transaction*/
2725 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2726 if (ret != SQLITE_OK) {
2727 _LOGE("Failed to commit transaction, Rollback now\n");
2728 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2729 if (ret != SQLITE_OK)
2730 _LOGE("Failed to Rollback\n");
2732 ret = PM_PARSER_R_ERROR;
2735 _LOGD("Transaction Commit and End\n");
2736 ret = PM_PARSER_R_OK;
2739 pkgmgr_parser_close_db();
2744 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2747 _LOGD("manifest pointer is NULL\n");
2751 ret = pkgmgr_parser_check_and_create_db(uid);
2753 _LOGD("Failed to open DB\n");
2756 ret = pkgmgr_parser_initialize_db(uid);
2759 /*Preserve guest mode visibility*/
2760 __preserve_guestmode_visibility_value(mfx);
2761 /*Begin transaction*/
2762 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2763 if (ret != SQLITE_OK) {
2764 _LOGD("Failed to begin transaction\n");
2768 _LOGD("Transaction Begin\n");
2769 ret = __delete_manifest_info_from_db(mfx, uid);
2771 _LOGD("Delete from DB failed. Rollback now\n");
2772 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2775 ret = __insert_manifest_info_in_db(mfx, uid);
2777 _LOGD("Insert into DB failed. Rollback now\n");
2778 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2782 /*Commit transaction*/
2783 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2784 if (ret != SQLITE_OK) {
2785 _LOGD("Failed to commit transaction. Rollback now\n");
2786 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2790 _LOGD("Transaction Commit and End\n");
2792 pkgmgr_parser_close_db();
2796 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2798 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2801 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2804 _LOGD("manifest pointer is NULL\n");
2808 ret = pkgmgr_parser_check_and_create_db(uid);
2810 _LOGD("Failed to open DB\n");
2813 /*Begin transaction*/
2814 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2815 if (ret != SQLITE_OK) {
2816 _LOGD("Failed to begin transaction\n");
2820 _LOGD("Transaction Begin\n");
2821 ret = __delete_manifest_info_from_db(mfx, uid);
2823 _LOGD("Delete from DB failed. Rollback now\n");
2824 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2827 /*Commit transaction*/
2828 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2829 if (ret != SQLITE_OK) {
2830 _LOGD("Failed to commit transaction, Rollback now\n");
2831 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2835 _LOGD("Transaction Commit and End\n");
2837 pkgmgr_parser_close_db();
2841 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2843 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
2846 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2850 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2852 _LOGD("Failed to open DB\n");
2856 /*Begin transaction*/
2857 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2858 if (ret != SQLITE_OK) {
2859 _LOGD("Failed to begin transaction\n");
2863 _LOGD("Transaction Begin\n");
2865 ret = __disable_global_app_for_user(appid, uid);
2867 ret = __enable_global_app_for_user(appid, uid);
2869 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2870 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2873 /*Commit transaction*/
2874 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2875 if (ret != SQLITE_OK) {
2876 _LOGD("Failed to commit transaction, Rollback now\n");
2877 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2881 _LOGD("Transaction Commit and End\n");
2883 pkgmgr_parser_close_db();
2888 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2890 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
2893 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid, uid_t uid, int is_disable)
2897 ret = pkgmgr_parser_check_and_create_db(uid);
2899 _LOGD("Failed to open DB\n");
2903 /*Begin transaction*/
2904 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2905 if (ret != SQLITE_OK) {
2906 _LOGD("Failed to begin transaction\n");
2911 _LOGD("Transaction Begin\n");
2913 ret = __disable_pkg(pkgid);
2915 ret = __enable_pkg(pkgid);
2918 _LOGD("__update_pkg_disable_condition_in_db failed. Rollback now\n");
2919 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2923 /*Commit transaction*/
2924 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2925 if (ret != SQLITE_OK) {
2926 _LOGD("Failed to commit transaction, Rollback now\n");
2927 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2931 _LOGD("Transaction Commit and End\n");
2934 pkgmgr_parser_close_db();
2938 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid, int is_disable)
2940 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid, _getuid(), is_disable);
2943 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2947 ret = pkgmgr_parser_check_and_create_db(uid);
2949 _LOGD("Failed to open DB\n");
2953 /*Begin transaction*/
2954 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2955 if (ret != SQLITE_OK) {
2956 _LOGD("Failed to begin transaction\n");
2960 _LOGD("Transaction Begin\n");
2962 ret = __disable_app(appid);
2964 ret = __enable_app(appid);
2966 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2967 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2970 /*Commit transaction*/
2971 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2972 if (ret != SQLITE_OK) {
2973 _LOGD("Failed to commit transaction, Rollback now\n");
2974 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2978 _LOGD("Transaction Commit and End\n");
2980 pkgmgr_parser_close_db();
2985 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
2989 if (appid == NULL) {
2990 _LOGD("Invalid parameter");
2994 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2996 _LOGD("Failed to open DB\n");
3000 /* Begin transaction */
3001 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3002 if (ret != SQLITE_OK) {
3003 _LOGD("Failed to begin transaction\n");
3007 _LOGD("Transaction Begin\n");
3009 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3011 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3012 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3015 /* Commit transaction */
3016 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3017 if (ret != SQLITE_OK) {
3018 _LOGD("Failed to commit transaction, Rollback now\n");
3019 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3023 _LOGD("Transaction Commit and End\n");
3025 pkgmgr_parser_close_db();
3029 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3031 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3034 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3038 if (appid == NULL) {
3039 _LOGD("Invalid parameter");
3043 ret = pkgmgr_parser_check_and_create_db(uid);
3045 _LOGD("Failed to open DB");
3049 /* Begin transaction */
3050 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3051 if (ret != SQLITE_OK) {
3052 _LOGD("Failed to begin transaction");
3056 _LOGD("Transaction Begin");
3059 ret = __enable_app_splash_screen(appid);
3061 ret = __disable_app_splash_screen(appid);
3063 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3064 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3067 /* Commit transaction */
3068 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3069 if (ret != SQLITE_OK) {
3070 _LOGD("Failed to commit transaction, Rollback now");
3071 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3075 _LOGD("Transaction Commit and End");
3078 pkgmgr_parser_close_db();
3082 API int pkgmgr_parser_update_app_label_info_in_usr_db(const char *appid, uid_t uid, const char *label)
3085 char query[MAX_QUERY_LEN] = {'\0'};
3087 if (appid == NULL || label == NULL) {
3088 _LOGE("Invalid parameter");
3092 ret = pkgmgr_parser_check_and_create_db(uid);
3094 _LOGD("Failed to open DB");
3098 /*Begin transaction*/
3099 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3100 if (ret != SQLITE_OK) {
3101 _LOGD("Failed to begin transaction\n");
3106 sqlite3_snprintf(MAX_QUERY_LEN, query,
3107 "UPDATE package_app_localized_info SET app_label=%Q WHERE " \
3108 "app_id=%Q AND app_label IS NOT NULL",
3110 ret = __exec_query(query);
3112 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3116 /* Commit transaction */
3117 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3118 if (ret != SQLITE_OK) {
3119 _LOGD("Failed to commit transaction, Rollback now");
3120 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3124 _LOGD("Transaction Commit and End");
3127 pkgmgr_parser_close_db();
3131 API int pkgmgr_parser_update_app_label_info_in_db(const char *appid, const char *label)
3133 return pkgmgr_parser_update_app_label_info_in_usr_db(appid, _getuid(), label);