4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
27 #include <sys/types.h>
28 #include <sys/smack.h>
37 #include <system_info.h>
39 /* For multi-user support */
40 #include <tzplatform_config.h>
42 #include "pkgmgr-info.h"
43 #include "pkgmgrinfo_basic.h"
44 #include "pkgmgr_parser_internal.h"
45 #include "pkgmgr_parser_db.h"
46 #include "pkgmgr_parser_debug.h"
48 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
49 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
50 #define MAX_QUERY_LEN 4096
53 #define MAX_INTEGER_LENGTH 10
59 #define XXHDPI "xxhdpi"
69 #define XXHDPI_MIN 481
70 #define XXHDPI_MAX 600
72 #define DB_LABEL "User::Home"
73 #define SET_SMACK_LABEL(x) \
75 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
76 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
78 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
81 sqlite3 *pkgmgr_parser_db;
82 sqlite3 *pkgmgr_cert_db;
85 #define QUERY_CREATE_TABLE_PACKAGE_INFO "CREATE TABLE IF NOT EXISTS package_info " \
86 "(package TEXT PRIMARY KEY NOT NULL, " \
87 "package_type TEXT DEFAULT 'tpk', " \
88 "package_version TEXT, " \
89 "package_api_version TEXT, " \
90 "package_tep_name TEXT, " \
91 "package_zip_mount_file TEXT, " \
92 "install_location TEXT NOT NULL , " \
93 "package_size TEXT, " \
94 "package_removable TEXT NOT NULL DEFAULT 'true', " \
95 "package_preload TEXT NOT NULL DEFAULT 'false', " \
96 "package_readonly TEXT NOT NULL DEFAULT 'false', " \
97 "package_update TEXT NOT NULL DEFAULT 'false', " \
98 "package_appsetting TEXT NOT NULL DEFAULT 'false', " \
99 "package_nodisplay TEXT NOT NULL DEFAULT 'false', " \
100 "package_system TEXT NOT NULL DEFAULT 'false', " \
101 "author_name TEXT, " \
102 "author_email TEXT, " \
103 "author_href TEXT," \
104 "installed_time TEXT, " \
105 "installed_storage TEXT, " \
106 "storeclient_id TEXT, " \
107 "mainapp_id TEXT, " \
108 "package_url TEXT, " \
110 "external_path TEXT, " \
112 "package_support_mode TEXT, " \
113 "package_support_disable TEXT NOT NULL DEFAULT 'false', " \
114 "package_disable TEXT NOT NULL DEFAULT 'false')"
116 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_localized_info " \
117 "(package TEXT NOT NULL, " \
118 "package_locale TEXT NOT NULL DEFAULT 'No Locale', " \
119 "package_label TEXT, " \
120 "package_icon TEXT, " \
121 "package_description TEXT, " \
122 "package_license TEXT, " \
123 "package_author TEXT, " \
124 "PRIMARY KEY(package, package_locale), " \
125 "FOREIGN KEY(package) " \
126 "REFERENCES package_info(package) " \
129 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "CREATE TABLE IF NOT EXISTS package_privilege_info " \
130 "(package TEXT NOT NULL, " \
131 "privilege TEXT NOT NULL, " \
132 "type TEXT NOT NULL, " \
133 "PRIMARY KEY(package, privilege, type) " \
134 "FOREIGN KEY(package) " \
135 "REFERENCES package_info(package) " \
138 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "CREATE TABLE IF NOT EXISTS package_app_info " \
139 "(app_id TEXT PRIMARY KEY NOT NULL, " \
140 "app_component TEXT NOT NULL, " \
142 "app_nodisplay TEXT NOT NULL DEFAULT 'false', " \
144 "app_onboot TEXT NOT NULL DEFAULT 'false', " \
145 "app_multiple TEXT NOT NULL DEFAULT 'false', " \
146 "app_autorestart TEXT NOT NULL DEFAULT 'false', " \
147 "app_taskmanage TEXT NOT NULL DEFAULT 'false', " \
148 "app_hwacceleration TEXT NOT NULL DEFAULT 'use-system-setting', " \
149 "app_screenreader TEXT NOT NULL DEFAULT 'use-system-setting', " \
150 "app_mainapp TEXT NOT NULL, " \
151 "app_recentimage TEXT NOT NULL DEFAULT 'false', " \
152 "app_launchcondition TEXT, " \
153 "app_indicatordisplay TEXT NOT NULL DEFAULT 'true', " \
154 "app_portraitimg TEXT, " \
155 "app_landscapeimg TEXT, " \
156 "app_guestmodevisibility TEXT NOT NULL DEFAULT 'true', " \
157 "app_permissiontype TEXT NOT NULL DEFAULT 'normal', " \
158 "app_preload TEXT NOT NULL DEFAULT 'false', " \
159 "app_submode TEXT NOT NULL DEFAULT 'false', " \
160 "app_submode_mainid TEXT, " \
161 "app_installed_storage TEXT NOT NULL, " \
162 "app_process_pool TEXT NOT NULL DEFAULT 'false', " \
163 "app_launch_mode TEXT NOT NULL DEFAULT 'caller', " \
164 "app_ui_gadget TEXT NOT NULL DEFAULT 'false', " \
165 "app_support_mode TEXT, " \
166 "app_support_disable TEXT NOT NULL DEFAULT 'false', " \
167 "app_disable TEXT NOT NULL DEFAULT 'false', " \
168 "app_package_type TEXT DEFAULT 'tpk', " \
169 "app_package_system TEXT NOT NULL, " \
170 "app_removable TEXT NOT NULL DEFAULT 'false', " \
171 "app_package_installed_time TEXT, " \
172 "app_support_ambient TEXT NOT NULL DEFAULT 'false', " \
173 "component_type TEXT, " \
174 "package TEXT NOT NULL, " \
175 "app_tep_name TEXT, " \
176 "app_zip_mount_file TEXT, " \
177 "app_background_category INTEGER DEFAULT 0, " \
178 "app_root_path TEXT, " \
179 "app_api_version TEXT, " \
180 "app_effective_appid TEXT, " \
181 "app_splash_screen_display TEXT NOT NULL DEFAULT 'true', " \
182 "app_external_path TEXT, " \
183 "FOREIGN KEY(package) " \
184 "REFERENCES package_info(package) " \
187 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_app_localized_info " \
188 "(app_id TEXT NOT NULL, " \
189 "app_locale TEXT NOT NULL DEFAULT 'No Locale', " \
192 "PRIMARY KEY(app_id,app_locale) " \
193 "FOREIGN KEY(app_id) " \
194 "REFERENCES package_app_info(app_id) " \
197 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "CREATE TABLE IF NOT EXISTS package_app_icon_section_info " \
198 "(app_id TEXT NOT NULL, " \
200 "app_icon_section TEXT NOT NULL, " \
201 "app_icon_resolution TEXT NOT NULL, " \
202 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
203 "FOREIGN KEY(app_id) " \
204 "REFERENCES package_app_info(app_id) " \
207 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "CREATE TABLE IF NOT EXISTS package_app_image_info " \
208 "(app_id TEXT NOT NULL, " \
209 "app_locale TEXT DEFAULT 'No Locale', " \
210 "app_image_section TEXT NOT NULL, " \
212 "PRIMARY KEY(app_id,app_image_section) " \
213 "FOREIGN KEY(app_id) " \
214 "REFERENCES package_app_info(app_id) " \
217 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "CREATE TABLE IF NOT EXISTS package_app_app_control " \
218 "(app_id TEXT NOT NULL, " \
219 "app_control TEXT NOT NULL, " \
220 "PRIMARY KEY(app_id,app_control) " \
221 "FOREIGN KEY(app_id) " \
222 "REFERENCES package_app_info(app_id) " \
225 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "CREATE TABLE IF NOT EXISTS package_app_app_category " \
226 "(app_id TEXT NOT NULL, " \
227 "category TEXT NOT NULL, " \
228 "PRIMARY KEY(app_id,category) " \
229 "FOREIGN KEY(app_id) " \
230 "REFERENCES package_app_info(app_id) " \
233 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "CREATE TABLE IF NOT EXISTS package_app_app_metadata " \
234 "(app_id TEXT NOT NULL, " \
235 "md_key TEXT NOT NULL, " \
237 "PRIMARY KEY(app_id, md_key, md_value) " \
238 "FOREIGN KEY(app_id) " \
239 "REFERENCES package_app_info(app_id) " \
242 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "CREATE TABLE IF NOT EXISTS package_app_app_permission " \
243 "(app_id TEXT NOT NULL, " \
244 "pm_type TEXT NOT NULL, " \
245 "pm_value TEXT NOT NULL, " \
246 "PRIMARY KEY(app_id, pm_type, pm_value) " \
247 "FOREIGN KEY(app_id) " \
248 "REFERENCES package_app_info(app_id) " \
251 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "CREATE TABLE IF NOT EXISTS package_app_share_allowed " \
252 "(app_id TEXT NOT NULL, " \
253 "data_share_path TEXT NOT NULL, " \
254 "data_share_allowed TEXT NOT NULL, " \
255 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
256 "FOREIGN KEY(app_id) " \
257 "REFERENCES package_app_info(app_id) " \
260 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "CREATE TABLE IF NOT EXISTS package_app_share_request " \
261 "(app_id TEXT NOT NULL, " \
262 "data_share_request TEXT NOT NULL, " \
263 "PRIMARY KEY(app_id,data_share_request) " \
264 "FOREIGN KEY(app_id) " \
265 "REFERENCES package_app_info(app_id) " \
268 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "CREATE TABLE IF NOT EXISTS package_app_data_control " \
269 "(app_id TEXT NOT NULL, " \
270 "providerid TEXT NOT NULL, " \
271 "access TEXT NOT NULL, " \
272 "type TEXT NOT NULL, " \
273 "PRIMARY KEY(app_id, providerid, access, type) " \
274 "FOREIGN KEY(app_id) " \
275 "REFERENCES package_app_info(app_id) " \
278 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
279 "(app_id TEXT NOT NULL, " \
280 "uid INTEGER NOT NULL, " \
281 "is_disabled TEXT NOT NULL DEFAULT 'false', " \
282 "is_splash_screen_enabled TEXT NOT NULL, " \
283 "PRIMARY KEY(app_id, uid))"
285 #define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
286 "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
287 "AFTER UPDATE ON package_app_info_for_uid " \
289 " DELETE FROM package_app_info_for_uid WHERE " \
290 " is_splash_screen_enabled=" \
291 " (SELECT package_app_info.app_splash_screen_display FROM " \
292 " package_app_info, package_app_info_for_uid WHERE " \
293 " package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
296 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
297 "CREATE TABLE IF NOT EXISTS package_app_splash_screen " \
298 "(app_id TEXT NOT NULL, " \
299 "src TEXT NOT NULL, " \
300 "type TEXT NOT NULL, " \
301 "orientation TEXT NOT NULL, " \
302 "indicatordisplay TEXT, " \
303 "operation TEXT NOT NULL, " \
304 "color_depth TEXT NOT NULL DEFAULT '24', " \
305 "PRIMARY KEY(app_id, orientation, operation) " \
306 "FOREIGN KEY(app_id) " \
307 "REFERENCES package_app_info(app_id) " \
311 /* FIXME: duplicated at pkgmgrinfo_db.c */
312 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
313 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
314 " cert_info TEXT UNIQUE, " \
315 " cert_id INTEGER PRIMARY KEY, " \
316 " cert_ref_count INTEGER NOT NULL)"
318 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
319 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
320 " package TEXT PRIMARY KEY, " \
321 " package_count INTEGER, " \
322 " author_root_cert INTEGER, " \
323 " author_im_cert INTEGER, " \
324 " author_signer_cert INTEGER, " \
325 " dist_root_cert INTEGER, " \
326 " dist_im_cert INTEGER, " \
327 " dist_signer_cert INTEGER, " \
328 " dist2_root_cert INTEGER, " \
329 " dist2_im_cert INTEGER, " \
330 " dist2_signer_cert INTEGER)"
332 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO \
333 "CREATE TRIGGER IF NOT EXISTS update_cert_info " \
334 "AFTER UPDATE ON package_cert_info " \
335 "WHEN (NEW.package_count = 0) " \
337 " DELETE FROM package_cert_info WHERE package=OLD.package;" \
340 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2 \
341 "CREATE TRIGGER IF NOT EXISTS update_cert_info2 " \
342 "AFTER UPDATE ON package_cert_info " \
343 "WHEN (NEW.package_count = OLD.package_count + 1) " \
345 " UPDATE package_cert_index_info SET" \
346 " cert_ref_count = cert_ref_count - 1" \
347 " WHERE cert_id = OLD.author_root_cert" \
348 " OR cert_id = OLD.author_im_cert" \
349 " OR cert_id = OLD.author_signer_cert" \
350 " OR cert_id = OLD.dist_root_cert" \
351 " OR cert_id = OLD.dist_im_cert" \
352 " OR cert_id = OLD.dist_signer_cert" \
353 " OR cert_id = OLD.dist2_root_cert" \
354 " OR cert_id = OLD.dist2_im_cert" \
355 " OR cert_id = OLD.dist2_signer_cert;" \
358 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
359 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
360 "AFTER DELETE ON package_cert_info " \
362 " UPDATE package_cert_index_info SET" \
363 " cert_ref_count = cert_ref_count - 1" \
364 " WHERE cert_id = OLD.author_root_cert" \
365 " OR cert_id = OLD.author_im_cert" \
366 " OR cert_id = OLD.author_signer_cert" \
367 " OR cert_id = OLD.dist_root_cert" \
368 " OR cert_id = OLD.dist_im_cert" \
369 " OR cert_id = OLD.dist_signer_cert" \
370 " OR cert_id = OLD.dist2_root_cert" \
371 " OR cert_id = OLD.dist2_im_cert" \
372 " OR cert_id = OLD.dist2_signer_cert;" \
375 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
376 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
377 "AFTER UPDATE ON package_cert_index_info " \
378 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
379 " WHERE cert_id = OLD.cert_id) = 0) "\
381 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
384 static int __insert_application_info(manifest_x *mfx);
385 static int __insert_application_appcategory_info(manifest_x *mfx);
386 static int __insert_application_appcontrol_info(manifest_x *mfx);
387 static int __insert_application_appmetadata_info(manifest_x *mfx);
388 static int __insert_application_share_allowed_info(manifest_x *mfx);
389 static int __insert_application_share_request_info(manifest_x *mfx);
390 static int __insert_application_datacontrol_info(manifest_x *mfx);
391 static void __insert_application_locale_info(gpointer data, gpointer userdata);
392 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
393 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
394 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
395 static int __delete_subpkg_info_from_db(char *appid);
396 static int __delete_appinfo_from_db(char *db_table, const char *appid);
397 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
398 static int __exec_query(char *query);
399 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
400 char **label, char **license, char **icon, char **description, char **author);
401 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
402 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
403 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
404 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
405 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
406 static int __parserdb_change_perm(const char *db_file, uid_t uid);
408 #define REGULAR_USER 5000
409 static inline uid_t _getuid(void)
411 uid_t uid = getuid();
413 if (uid < REGULAR_USER)
414 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
419 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
422 __delete_subpkg_info_from_db(coltxt[0]);
427 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
432 char *error_message = NULL;
434 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
435 if (ret != SQLITE_OK) {
436 _LOGD("connect db [%s] failed!\n", db_path);
441 /* add user_version for db upgrade*/
442 query = sqlite3_mprintf("PRAGMA user_version=%d", (atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 + atoi(TIZEN_PATCH_VER)));
444 sqlite3_exec(handle, query, NULL, NULL, &error_message)) {
445 _LOGE("Don't execute query = %s error message = %s\n", query,
448 sqlite3_free(error_message);
454 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
456 manifest_x *mfx = (manifest_x *)data;
462 if (mfx->application == NULL)
464 app = (application_x *)mfx->application->data;
465 for (i = 0; i < ncols; i++) {
466 if (strcmp(colname[i], "app_id") == 0) {
468 appid = strdup(coltxt[i]);
469 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
471 status = strdup(coltxt[i]);
477 _LOGD("app id is NULL\n");
480 /*update guest mode visibility*/
481 for (tmp = mfx->application; tmp; tmp = tmp->next) {
482 app = (application_x *)tmp->data;
485 if (strcmp(app->appid, appid) == 0) {
486 free((void *)app->guestmode_visibility);
487 app->guestmode_visibility = strdup(status);
503 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
505 char *error_message = NULL;
506 char query[MAX_QUERY_LEN] = {'\0'};
507 sqlite3_snprintf(MAX_QUERY_LEN, query,
508 "SELECT app_id, app_guestmodevisibility FROM package_app_info " \
509 "WHERE package=%Q", mfx->package);
511 sqlite3_exec(pkgmgr_parser_db, query,
512 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
513 _LOGD("Don't execute query = %s error message = %s\n",
514 query, error_message);
515 sqlite3_free(error_message);
520 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
522 char *error_message = NULL;
524 sqlite3_exec(db_handle, db_query,
525 NULL, NULL, &error_message)) {
526 _LOGD("Don't execute query = %s error message = %s\n",
527 db_query, error_message);
528 sqlite3_free(error_message);
531 sqlite3_free(error_message);
535 static int __exec_query(char *query)
537 char *error_message = NULL;
539 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
540 _LOGE("Don't execute query = %s error message = %s\n", query,
542 sqlite3_free(error_message);
545 sqlite3_free(error_message);
547 if (sqlite3_changes(pkgmgr_parser_db) == 0) {
548 _LOGE("No such record matches with given query : %s\n", query);
554 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
562 for (tmp = lbls; tmp; tmp = tmp->next) {
563 lbl = (label_x *)tmp->data;
567 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
569 for (tmp = lcns; tmp; tmp = tmp->next) {
570 lcn = (license_x *)tmp->data;
574 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
576 for (tmp = icns; tmp; tmp = tmp->next) {
577 icn = (icon_x *)tmp->data;
581 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
583 for (tmp = dcns; tmp; tmp = tmp->next) {
584 dcn = (description_x *)tmp->data;
588 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
590 for (tmp = aths; tmp; tmp = tmp->next) {
591 ath = (author_x *)tmp->data;
595 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
601 static GList *__create_icon_list(GList *appicon, GList *icns)
606 for (tmp = icns; tmp; tmp = tmp->next) {
607 icn = (icon_x *)tmp->data;
611 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
616 static GList *__create_image_list(GList *appimage, GList *imgs)
621 for (tmp = imgs; tmp; tmp = tmp->next) {
622 img = (image_x *)tmp->data;
626 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
631 static void __trimfunc(GList *trim_list)
633 char *trim_data = NULL;
637 list = g_list_first(trim_list);
640 trim_data = (char *)list->data;
643 if (strcmp(trim_data, prev) == 0) {
644 trim_list = g_list_remove(trim_list, trim_data);
645 list = g_list_first(trim_list);
654 list = g_list_next(list);
658 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
660 if (a == NULL || b == NULL)
662 if (strcmp((char *)a, (char *)b) == 0)
664 if (strcmp((char *)a, (char *)b) < 0)
666 if (strcmp((char *)a, (char *)b) > 0)
671 static int __check_dpi(const char *dpi_char, int dpi_int)
673 if (dpi_char == NULL)
676 if (strcasecmp(dpi_char, LDPI) == 0) {
677 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
681 } else if (strcasecmp(dpi_char, MDPI) == 0) {
682 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
686 } else if (strcasecmp(dpi_char, HDPI) == 0) {
687 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
691 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
692 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
696 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
697 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
705 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
708 char *icon_filename = NULL;
709 char modified_iconpath[BUFSIZE] = { '\0' };
710 char icon_path[BUFSIZE] = { '\0' };
714 if (orig_icon_path == NULL)
717 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
721 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
722 dpi_path[0] = "LDPI";
723 dpi_path[1] = "ldpi";
724 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
725 dpi_path[0] = "MDPI";
726 dpi_path[1] = "mdpi";
727 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
728 dpi_path[0] = "HDPI";
729 dpi_path[1] = "hdpi";
730 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
731 dpi_path[0] = "XHDPI";
732 dpi_path[1] = "xhdpi";
733 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
734 dpi_path[0] = "XXHDPI";
735 dpi_path[1] = "xxhdpi";
737 _LOGE("Unidentified dpi[%d]", dpi);
741 icon_filename = strrchr(orig_icon_path, '/');
742 if (icon_filename == NULL)
745 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
746 for (i = 0; i < 2; i++) {
747 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
748 if (access(modified_iconpath, F_OK) != -1) {
749 /* if exists, return modified icon path */
750 *new_icon_path = strdup(modified_iconpath);
758 static gint __compare_icon(gconstpointer a, gconstpointer b)
760 icon_x *icon = (icon_x *)a;
762 char *icon_folder_path = NULL;
764 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
767 if (icon->dpi != NULL)
770 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
772 icon->text = icon_folder_path;
778 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
780 icon_x *icon = (icon_x *)a;
781 int dpi = GPOINTER_TO_INT(b);
783 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
786 if (icon->dpi == NULL)
789 if (__check_dpi(icon->dpi, dpi) == 0)
795 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
797 icon_x *icon = (icon_x *)a;
798 char *lang = (char *)b;
799 char *icon_folder_path = NULL;
801 if (icon->dpi != NULL)
804 if (strcasecmp(icon->lang, lang) == 0) {
805 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
806 /* icon for no locale. check existance of folder-hierachied default icons */
807 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
809 icon->text = icon_folder_path;
818 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
820 icon_x *icon = (icon_x *)a;
821 char *lang = (char *)b;
824 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
828 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
834 static char *__find_icon(GList *icons, const char *lang)
841 /* first, find icon whose locale and dpi with given lang and system's dpi has matched */
842 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
844 icon = (icon_x *)tmp->data;
845 return (char *)icon->text;
848 /* if first has failed, find icon whose locale has matched */
849 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
851 icon = (icon_x *)tmp->data;
852 return (char *)icon->text;
855 /* if second has failed, find icon whose dpi has matched with system's dpi */
856 ret = system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
857 if (ret == SYSTEM_INFO_ERROR_NONE) {
858 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
860 icon = (icon_x *)tmp->data;
861 return (char *)icon->text;
865 /* last, find default icon marked as "No Locale" */
866 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
868 icon = (icon_x *)tmp->data;
869 return (char *)icon->text;
875 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
876 char **label, char **license, char **icon, char **description, char **author)
883 for (tmp = lbls; tmp; tmp = tmp->next) {
884 lbl = (label_x *)tmp->data;
888 if (strcmp(lbl->lang, (char *)data) == 0) {
889 *label = (char *)lbl->text;
894 for (tmp = lcns; tmp; tmp = tmp->next) {
895 lcn = (license_x *)tmp->data;
899 if (strcmp(lcn->lang, (char *)data) == 0) {
900 *license = (char *)lcn->text;
906 *icon = __find_icon(icns, (char *)data);
908 for (tmp = dcns; tmp; tmp = tmp->next) {
909 dcn = (description_x *)tmp->data;
913 if (strcmp(dcn->lang, (char *)data) == 0) {
914 *description = (char *)dcn->text;
919 for (tmp = aths; tmp; tmp = tmp->next) {
920 ath = (author_x *)tmp->data;
924 if (strcmp(ath->lang, (char *)data) == 0) {
925 *author = (char *)ath->text;
933 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
937 for (tmp = icns; tmp; tmp = tmp->next) {
938 icn = (icon_x *)tmp->data;
942 if (strcmp(icn->section, (char *)data) == 0) {
943 *icon = (char *)icn->text;
944 *resolution = (char *)icn->resolution;
951 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
955 for (tmp = imgs; tmp; tmp = tmp->next) {
956 img = (image_x *)tmp->data;
960 if (strcmp(img->section, (char *)data) == 0) {
961 *lang = (char *)img->lang;
962 *image = (char *)img->text;
969 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
974 char *description = NULL;
975 char *license = NULL;
979 manifest_x *mfx = (manifest_x *)userdata;
980 GList *lbl = mfx->label;
981 GList *lcn = mfx->license;
982 GList *icn = mfx->icon;
983 GList *dcn = mfx->description;
984 GList *ath = mfx->author;
986 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
987 if (!label && !description && !icon && !license && !author)
990 query = sqlite3_mprintf("INSERT INTO package_localized_info(package, package_locale, " \
991 "package_label, package_icon, package_description, package_license, package_author) VALUES" \
992 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1001 ret = __exec_query(query);
1003 _LOGD("Package Localized Info DB Insert failed\n");
1005 sqlite3_free(query);
1008 static void __insert_application_locale_info(gpointer data, gpointer userdata)
1014 char *locale = (char *)data;
1016 application_x *app = (application_x *)userdata;
1017 GList *lbl = app->label;
1018 GList *icn = app->icon;
1020 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1021 if (!label && !icon)
1024 query = sqlite3_mprintf("INSERT INTO package_app_localized_info(app_id, app_locale, " \
1025 "app_label, app_icon) VALUES" \
1026 "(%Q, %Q, %Q, %Q)", app->appid, (char *)data,
1028 ret = __exec_query(query);
1030 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1032 sqlite3_free(query);
1034 /*insert ui app locale info to pkg locale to get mainapp data */
1035 if (strcasecmp(app->mainapp, "true") == 0) {
1036 query = sqlite3_mprintf("INSERT OR REPLACE INTO package_localized_info(package, package_locale, "
1037 "package_label, package_icon, package_description, package_license, package_author) VALUES"
1039 "COALESCE((SELECT package_label FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1040 "COALESCE((SELECT package_icon FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1041 "(SELECT package_description FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1042 "(SELECT package_license FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1043 "(SELECT package_author FROM package_localized_info WHERE package=%Q AND package_locale=%Q))",
1044 app->package, locale,
1045 app->package, locale, label,
1046 app->package, locale, icon,
1047 app->package, locale,
1048 app->package, locale,
1049 app->package, locale);
1051 ret = __exec_query(query);
1053 _LOGE("Package Localized Info DB Insert failed");
1054 sqlite3_free(query);
1058 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1062 char *resolution = NULL;
1063 char query[MAX_QUERY_LEN] = {'\0'};
1065 application_x *app = (application_x *)userdata;
1066 GList *icn = app->icon;
1068 __extract_icon_data(data, icn, &icon, &resolution);
1069 if (!icon && !resolution)
1071 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO package_app_icon_section_info(app_id, " \
1072 "app_icon, app_icon_section, app_icon_resolution) VALUES " \
1073 "(%Q, %Q, %Q, %Q)", app->appid,
1074 icon, (char *)data, resolution);
1076 ret = __exec_query(query);
1078 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1082 static void __insert_application_image_info(gpointer data, gpointer userdata)
1087 char query[MAX_QUERY_LEN] = {'\0'};
1089 application_x *app = (application_x *)userdata;
1090 GList *image = app->image;
1092 __extract_image_data(data, image, &lang, &img);
1095 sqlite3_snprintf(MAX_QUERY_LEN, query,
1096 "INSERT INTO package_app_image_info(app_id, app_locale, " \
1097 "app_image_section, app_image) VALUES" \
1098 "(%Q, %Q, %Q, %Q)", app->appid, lang, (char *)data, img);
1100 ret = __exec_query(query);
1102 _LOGD("Package UiApp image Info DB Insert failed\n");
1107 static int __insert_mainapp_info(manifest_x *mfx)
1112 char query[MAX_QUERY_LEN] = {'\0'};
1113 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1114 app = (application_x *)tmp->data;
1117 if (strcasecmp(app->mainapp, "True") == 0)
1118 mfx->mainapp_id = strdup(app->appid);
1121 if (mfx->mainapp_id == NULL) {
1122 if (mfx->application == NULL)
1124 app = (application_x *)mfx->application->data;
1127 free((void *)app->mainapp);
1128 app->mainapp = strdup("true");
1129 mfx->mainapp_id = strdup(app->appid);
1132 memset(query, '\0', MAX_QUERY_LEN);
1133 sqlite3_snprintf(MAX_QUERY_LEN, query,
1134 "UPDATE package_info SET mainapp_id=%Q WHERE package=%Q", mfx->mainapp_id, mfx->package);
1135 ret = __exec_query(query);
1137 _LOGD("Package Info DB update Failed\n");
1144 static int __convert_background_category(GList *category_list)
1147 GList *tmp_list = category_list;
1148 char *category_data = NULL;
1150 if (category_list == NULL)
1153 while (tmp_list != NULL) {
1154 category_data = (char *)tmp_list->data;
1155 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0)
1156 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1157 else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0)
1158 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1159 else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0)
1160 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1161 else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0)
1162 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1163 else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0)
1164 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1165 else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0)
1166 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1167 else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0)
1168 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1170 _LOGE("Unidentified category [%s]", category_data);
1171 tmp_list = g_list_next(tmp_list);
1177 static const char *__find_effective_appid(GList *metadata_list)
1182 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1183 md = (metadata_x *)tmp_list->data;
1184 if (md == NULL || md->key == NULL)
1187 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1196 static char *__get_bool(char *value, bool is_true)
1198 if (value != NULL) {
1199 if (!strcmp(value, ""))
1200 return (is_true) ? "true" : "false";
1204 return (is_true) ? "true" : "false";
1207 /* _PRODUCT_LAUNCHING_ENHANCED_
1208 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1210 static int __insert_application_info(manifest_x *mfx)
1215 int background_value = 0;
1216 char query[MAX_QUERY_LEN] = {'\0'};
1218 const char *effective_appid;
1221 type = strdup(mfx->type);
1223 type = strdup("tpk");
1225 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1226 app = (application_x *)tmp->data;
1230 background_value = __convert_background_category(app->background_category);
1231 if (background_value < 0) {
1232 _LOGE("Failed to retrieve background value[%d]", background_value);
1233 background_value = 0;
1236 effective_appid = __find_effective_appid(app->metadata);
1238 sqlite3_snprintf(MAX_QUERY_LEN, query,
1239 "INSERT INTO package_app_info(" \
1240 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1241 "app_onboot, app_multiple, app_autorestart, app_taskmanage, " \
1242 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1243 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1244 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1245 "app_launch_mode, app_ui_gadget, app_support_mode, app_support_disable, component_type, package, " \
1246 "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, " \
1247 "app_api_version, app_effective_appid, app_splash_screen_display, app_package_system, app_removable, " \
1248 "app_package_installed_time, app_support_ambient) " \
1250 "%Q, %Q, %Q, LOWER(%Q), %Q, " \
1251 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1252 "%Q, %Q, %Q, %Q, %Q, " \
1253 "LOWER(%Q), %Q, %Q, LOWER(%Q), %Q, " \
1254 "LOWER(%Q), LOWER(%Q), %Q, %Q, LOWER(%Q), " \
1255 "COALESCE(%Q, 'caller'), LOWER(%Q), %Q, LOWER(%Q), %Q, %Q, " \
1256 "%Q, %Q, %d, %Q, %Q, " \
1257 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1259 app->appid, app->component_type, app->exec, __get_bool(app->nodisplay, false), app->type,
1260 __get_bool(app->onboot, false), __get_bool(app->multiple, false), __get_bool(app->autorestart, false), __get_bool(app->taskmanage, false),
1261 app->hwacceleration, app->screenreader, app->mainapp, app->recentimage, app->launchcondition,
1262 __get_bool(app->indicatordisplay, true), app->portraitimg, app->landscapeimg,
1263 __get_bool(app->guestmode_visibility, true), app->permission_type,
1264 __get_bool(mfx->preload, false), __get_bool(app->submode, false), app->submode_mainid, mfx->installed_storage, __get_bool(app->process_pool, false),
1265 app->launch_mode, __get_bool(app->ui_gadget, false), mfx->support_mode, __get_bool(mfx->support_disable, false), app->component_type, mfx->package,
1266 mfx->tep_name, mfx->zip_mount_file, background_value, type, mfx->root_path, mfx->api_version,
1267 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));
1269 ret = __exec_query(query);
1271 _LOGD("Package UiApp Info DB Insert Failed\n");
1276 memset(query, '\0', MAX_QUERY_LEN);
1285 static int __insert_application_appcategory_info(manifest_x *mfx)
1292 char query[MAX_QUERY_LEN] = {'\0'};
1293 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1294 app = (application_x *)app_tmp->data;
1297 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1298 ct = (const char *)ct_tmp->data;
1301 sqlite3_snprintf(MAX_QUERY_LEN, query,
1302 "INSERT INTO package_app_app_category(app_id, category) " \
1305 ret = __exec_query(query);
1307 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1310 memset(query, '\0', MAX_QUERY_LEN);
1316 static int __insert_application_appmetadata_info(manifest_x *mfx)
1323 char query[MAX_QUERY_LEN] = {'\0'};
1324 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1325 app = (application_x *)app_tmp->data;
1328 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1329 md = (metadata_x *)md_tmp->data;
1333 sqlite3_snprintf(MAX_QUERY_LEN, query,
1334 "INSERT INTO package_app_app_metadata(app_id, md_key, md_value) " \
1335 "VALUES(%Q, %Q, %Q)",\
1336 app->appid, md->key, md->value ? md->value : NULL);
1337 ret = __exec_query(query);
1339 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1343 memset(query, '\0', MAX_QUERY_LEN);
1349 static int __insert_application_apppermission_info(manifest_x *mfx)
1356 char query[MAX_QUERY_LEN] = {'\0'};
1357 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1358 app = (application_x *)app_tmp->data;
1361 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1362 pm = (permission_x *)pm_tmp->data;
1365 sqlite3_snprintf(MAX_QUERY_LEN, query,
1366 "INSERT INTO package_app_app_permission(app_id, pm_type, pm_value) " \
1367 "VALUES(%Q, %Q, %Q)",\
1368 app->appid, pm->type, pm->value);
1369 ret = __exec_query(query);
1371 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1374 memset(query, '\0', MAX_QUERY_LEN);
1380 static int __insert_application_appcontrol_info(manifest_x *mfx)
1384 GList *acontrol_tmp;
1385 appcontrol_x *acontrol;
1387 char query[MAX_QUERY_LEN] = {'\0'};
1388 char buf[BUFSIZE] = {'\0'};
1389 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1390 app = (application_x *)app_tmp->data;
1393 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1394 acontrol = (appcontrol_x *)acontrol_tmp->data;
1395 if (acontrol == NULL)
1397 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1398 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1399 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1400 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1401 sqlite3_snprintf(MAX_QUERY_LEN, query,
1402 "INSERT INTO package_app_app_control(app_id, app_control) " \
1405 ret = __exec_query(query);
1407 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1410 memset(query, '\0', MAX_QUERY_LEN);
1416 static int __insert_application_datacontrol_info(manifest_x *mfx)
1423 char query[MAX_QUERY_LEN] = {'\0'};
1425 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1426 app = (application_x *)app_tmp->data;
1429 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1430 dc = (datacontrol_x *)dc_tmp->data;
1433 sqlite3_snprintf(MAX_QUERY_LEN, query,
1434 "INSERT INTO package_app_data_control(app_id, providerid, access, type) " \
1435 "VALUES(%Q, %Q, %Q, %Q)",\
1441 ret = __exec_query(query);
1443 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1446 memset(query, '\0', MAX_QUERY_LEN);
1452 static int __insert_application_share_request_info(manifest_x *mfx)
1461 char query[MAX_QUERY_LEN] = {'\0'};
1462 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1463 app = (application_x *)app_tmp->data;
1466 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1467 ds = (datashare_x *)ds_tmp->data;
1470 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1471 rq = (const char *)rq_tmp->data;
1474 sqlite3_snprintf(MAX_QUERY_LEN, query,
1475 "INSERT INTO package_app_share_request(app_id, data_share_request) " \
1478 ret = __exec_query(query);
1480 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1483 memset(query, '\0', MAX_QUERY_LEN);
1490 static int __insert_application_share_allowed_info(manifest_x *mfx)
1501 char query[MAX_QUERY_LEN] = {'\0'};
1502 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1503 app = (application_x *)app_tmp->data;
1506 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1507 ds = (datashare_x *)ds_tmp->data;
1510 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1511 df = (define_x *)df_tmp->data;
1514 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1515 al = (const char *)al_tmp->data;
1518 sqlite3_snprintf(MAX_QUERY_LEN, query,
1519 "INSERT INTO package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1520 "VALUES(%Q, %Q, %Q)",\
1521 app->appid, df->path, al);
1522 ret = __exec_query(query);
1524 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1527 memset(query, '\0', MAX_QUERY_LEN);
1535 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1537 splashscreen_x *ss = (splashscreen_x *)a;
1538 const char *orientation = (const char *)b;
1541 if (ss->operation || ss->dpi == NULL)
1544 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1548 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1554 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1556 splashscreen_x *ss = (splashscreen_x *)a;
1557 const char *orientation = (const char *)b;
1559 if (ss->operation || ss->dpi)
1562 if (strcasecmp(ss->orientation, orientation) == 0)
1568 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1569 const char *orientation)
1573 tmp = g_list_find_custom(splashscreens, orientation,
1574 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1576 return (splashscreen_x *)tmp->data;
1578 tmp = g_list_find_custom(splashscreens, orientation,
1579 (GCompareFunc)__compare_splashscreen_with_orientation);
1581 return (splashscreen_x *)tmp->data;
1586 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1588 splashscreen_x *ss = (splashscreen_x *)data;
1589 GList **list = (GList **)user_data;
1592 if (ss->operation == NULL || ss->dpi == NULL)
1595 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1599 if (__check_dpi(ss->dpi, dpi) != 0)
1602 *list = g_list_append(*list, ss);
1605 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1607 splashscreen_x *ss = (splashscreen_x *)data;
1608 GList **list = (GList **)user_data;
1609 splashscreen_x *ss_tmp;
1612 if (ss->operation == NULL || ss->dpi)
1615 for (tmp = *list; tmp; tmp = tmp->next) {
1616 ss_tmp = (splashscreen_x *)tmp->data;
1617 if (ss_tmp->operation
1618 && strcmp(ss_tmp->operation, ss->operation) == 0
1619 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1623 *list = g_list_append(*list, ss);
1626 static GList *__find_splashscreens(GList *splashscreens)
1631 g_list_foreach(splashscreens,
1632 __find_appcontrol_splashscreen_with_dpi, &list);
1633 g_list_foreach(splashscreens,
1634 __find_appcontrol_splashscreen, &list);
1636 ss = __find_default_splashscreen(splashscreens, "portrait");
1638 list = g_list_append(list, ss);
1639 ss = __find_default_splashscreen(splashscreens, "landscape");
1641 list = g_list_append(list, ss);
1646 static int __insert_application_splashscreen_info(manifest_x *mfx)
1654 char query[MAX_QUERY_LEN] = {'\0'};
1656 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1657 app = (application_x *)app_tmp->data;
1658 if (app == NULL || app->splashscreens == NULL)
1661 ss_tmp = __find_splashscreens(app->splashscreens);
1665 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1666 ss = (splashscreen_x *)tmp->data;
1667 sqlite3_snprintf(MAX_QUERY_LEN, query,
1668 "INSERT INTO package_app_splash_screen" \
1669 "(app_id, src, type, orientation, indicatordisplay, " \
1670 "operation, color_depth) " \
1671 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1672 app->appid, ss->src, ss->type, ss->orientation,
1673 ss->indicatordisplay, ss->operation,
1676 ret = __exec_query(query);
1678 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1681 memset(query, '\0', MAX_QUERY_LEN);
1683 g_list_free(ss_tmp);
1688 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1692 privilege_x *pv = NULL;
1693 char query[MAX_QUERY_LEN] = { '\0' };
1696 const char *auth_name = NULL;
1697 const char *auth_email = NULL;
1698 const char *auth_href = NULL;
1700 GList *pkglocale = NULL;
1701 GList *applocale = NULL;
1702 GList *appicon = NULL;
1703 GList *appimage = NULL;
1705 int temp_pkg_mode = 0;
1706 int temp_app_mode = 0;
1707 char pkg_mode[MAX_INTEGER_LENGTH] = {'\0'};
1708 application_x *up_support_mode = NULL;
1709 GList *list_up = NULL;
1711 if (mfx->author && mfx->author->data) {
1712 author = (author_x *)mfx->author->data;
1714 auth_name = author->text;
1716 auth_email = author->email;
1718 auth_href = author->href;
1721 if (mfx->support_mode)
1722 temp_pkg_mode = atoi(mfx->support_mode);
1724 /* FIXME : OR-ing should be fixed to not to store whole support mode */
1725 list_up = mfx->application;
1726 while (list_up != NULL) {
1727 up_support_mode = (application_x *)list_up->data;
1728 if (up_support_mode->support_mode) {
1729 temp_app_mode = atoi(up_support_mode->support_mode);
1730 temp_pkg_mode |= temp_app_mode;
1732 list_up = list_up->next;
1734 snprintf(pkg_mode, MAX_INTEGER_LENGTH, "%d", temp_pkg_mode);
1736 if (mfx->support_mode)
1737 free((void *)mfx->support_mode);
1738 mfx->support_mode = strdup(pkg_mode);
1740 /*Insert in the package_info DB*/
1741 sqlite3_snprintf(MAX_QUERY_LEN, query,
1742 "INSERT INTO package_info(" \
1743 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1744 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1745 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1746 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1747 "mainapp_id, package_url, root_path, csc_path, package_support_mode, package_support_disable) " \
1749 "%Q, %Q, %Q, %Q, %Q, %Q, " \
1750 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1751 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), %Q, " \
1752 "%Q, %Q, %Q, %Q, %Q, " \
1753 "%Q, %Q, %Q, %Q, %Q, LOWER(%Q))",
1754 mfx->package, mfx->type, mfx->version, mfx->api_version, mfx->tep_name, mfx->zip_mount_file,
1755 mfx->installlocation, mfx->package_size, __get_bool(mfx->removable, true), __get_bool(mfx->preload, false), __get_bool(mfx->readonly, false),
1756 __get_bool(mfx->update, false), __get_bool(mfx->appsetting, false), __get_bool(mfx->nodisplay_setting, false), __get_bool(mfx->system, false), auth_name,
1757 auth_email, auth_href, mfx->installed_time, mfx->installed_storage,
1758 mfx->storeclient_id,
1759 mfx->mainapp_id, mfx->package_url, mfx->root_path, mfx->csc_path, mfx->support_mode, __get_bool(mfx->support_disable, false));
1761 ret = __exec_query(query);
1763 _LOGD("Package Info DB Insert Failed\n");
1767 /*Insert in the package_privilege_info DB*/
1768 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1769 pv = (privilege_x *)tmp->data;
1772 memset(query, '\0', MAX_QUERY_LEN);
1773 sqlite3_snprintf(MAX_QUERY_LEN, query,
1774 "INSERT INTO package_privilege_info(package, privilege, type) " \
1775 "VALUES(%Q, %Q, %Q)",\
1776 mfx->package, pv->value, pv->type);
1777 ret = __exec_query(query);
1779 _LOGD("Package Privilege Info DB Insert Failed\n");
1784 if (mfx->application != NULL) {
1785 ret = __insert_mainapp_info(mfx);
1790 /*Insert the package locale*/
1791 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1792 /*remove duplicated data in pkglocale*/
1793 __trimfunc(pkglocale);
1795 /*Insert the app locale, icon, image info */
1796 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1797 app = (application_x *)tmp->data;
1800 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1801 appicon = __create_icon_list(appicon, app->icon);
1802 appimage = __create_image_list(appimage, app->image);
1804 /*remove duplicated data in applocale*/
1805 __trimfunc(applocale);
1806 __trimfunc(appicon);
1807 __trimfunc(appimage);
1809 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1811 /*native app locale info*/
1812 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1813 app = (application_x *)tmp->data;
1816 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1817 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1818 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1821 g_list_free(pkglocale);
1823 g_list_free(applocale);
1825 g_list_free(appicon);
1827 g_list_free(appimage);
1830 /*Insert in the package_app_info DB*/
1831 ret = __insert_application_info(mfx);
1834 /*Insert in the package_app_app_control DB*/
1835 ret = __insert_application_appcontrol_info(mfx);
1839 /*Insert in the package_app_app_category DB*/
1840 ret = __insert_application_appcategory_info(mfx);
1844 /*Insert in the package_app_app_metadata DB*/
1845 ret = __insert_application_appmetadata_info(mfx);
1849 /*Insert in the package_app_app_permission DB*/
1850 ret = __insert_application_apppermission_info(mfx);
1854 /*Insert in the package_app_share_allowed DB*/
1855 ret = __insert_application_share_allowed_info(mfx);
1859 /*Insert in the package_app_share_request DB*/
1860 ret = __insert_application_share_request_info(mfx);
1864 /*Insert in the package_app_data_control DB*/
1865 ret = __insert_application_datacontrol_info(mfx);
1869 /*Insert in the package_app_splash_screen DB*/
1870 ret = __insert_application_splashscreen_info(mfx);
1878 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1880 char query[MAX_QUERY_LEN] = { '\0' };
1883 sqlite3_snprintf(MAX_QUERY_LEN, query,
1884 "DELETE FROM %q where app_id=%Q", db_table, appid);
1885 ret = __exec_query(query);
1887 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1893 static int __delete_subpkg_info_from_db(char *appid)
1897 ret = __delete_appinfo_from_db("package_app_info", appid);
1900 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1903 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1906 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1909 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1912 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1915 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1918 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1921 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1924 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1927 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1930 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
1937 static int __delete_subpkg_from_db(manifest_x *mfx)
1939 char query[MAX_QUERY_LEN] = { '\0' };
1940 char *error_message = NULL;
1942 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT app_id FROM package_app_info WHERE package=%Q", mfx->package);
1944 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1945 _LOGE("Don't execute query = %s error message = %s\n", query,
1947 sqlite3_free(error_message);
1950 sqlite3_free(error_message);
1955 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1957 char query[MAX_QUERY_LEN] = { '\0' };
1962 /*Delete from Package Info DB*/
1963 sqlite3_snprintf(MAX_QUERY_LEN, query,
1964 "DELETE FROM package_info WHERE package=%Q", mfx->package);
1965 ret = __exec_query(query);
1967 _LOGD("Package Info DB Delete Failed\n");
1970 memset(query, '\0', MAX_QUERY_LEN);
1972 /*Delete from Package Localized Info*/
1973 sqlite3_snprintf(MAX_QUERY_LEN, query,
1974 "DELETE FROM package_localized_info WHERE package=%Q", mfx->package);
1975 ret = __exec_query(query);
1977 _LOGD("Package Localized Info DB Delete Failed\n");
1981 /*Delete from Package Privilege Info*/
1982 sqlite3_snprintf(MAX_QUERY_LEN, query,
1983 "DELETE FROM package_privilege_info WHERE package=%Q", mfx->package);
1984 ret = __exec_query(query);
1986 _LOGD("Package Privilege Info DB Delete Failed\n");
1990 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1991 app = (application_x *)tmp->data;
1994 ret = __delete_appinfo_from_db("package_app_info", app->appid);
1997 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2000 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2003 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2006 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2009 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2012 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2015 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2018 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2021 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2024 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2027 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2032 /* if main package has sub pkg, delete sub pkg data*/
2033 __delete_subpkg_from_db(mfx);
2038 static int __disable_app(const char *appid)
2041 char query[MAX_QUERY_LEN] = {'\0'};
2042 sqlite3_snprintf(MAX_QUERY_LEN, query,
2043 "UPDATE package_app_info SET app_disable='true' WHERE app_id=%Q",
2045 ret = __exec_query(query);
2047 _LOGD("Insert global app disable failed\n");
2052 static int __enable_app(const char *appid)
2055 char query[MAX_QUERY_LEN] = {'\0'};
2056 sqlite3_snprintf(MAX_QUERY_LEN, query,
2057 "UPDATE package_app_info SET app_disable='false' WHERE app_id=%Q",
2059 ret = __exec_query(query);
2061 _LOGD("Insert global app disable failed\n");
2066 static int __disable_pkg(const char *pkgid)
2069 char query[MAX_QUERY_LEN] = {'\0'};
2070 sqlite3_snprintf(MAX_QUERY_LEN, query,
2071 "UPDATE package_info SET package_disable='true' WHERE package=%Q",
2073 ret = __exec_query(query);
2075 _LOGD("Update pkg disable info has failed\n");
2080 static int __enable_pkg(const char *pkgid)
2083 char query[MAX_QUERY_LEN] = {'\0'};
2084 sqlite3_snprintf(MAX_QUERY_LEN, query,
2085 "UPDATE package_info SET package_disable='false' WHERE package=%Q",
2087 ret = __exec_query(query);
2089 _LOGD("Update pkg disable info has failed\n");
2094 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2097 char query[MAX_QUERY_LEN] = { '\0', };
2099 const char *val = NULL;
2104 sqlite3_snprintf(MAX_QUERY_LEN, query,
2105 "SELECT COUNT(*) FROM "
2106 "package_app_info_for_uid WHERE app_id=%Q "
2107 "AND uid=%d", appid, (int)uid);
2109 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2110 if (ret != SQLITE_OK) {
2111 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2112 return PMINFO_R_ERROR;
2115 if (sqlite3_step(stmt) != SQLITE_ROW) {
2116 LOGE("failed to step");
2117 sqlite3_finalize(stmt);
2118 return PMINFO_R_ERROR;
2121 val = (const char *)sqlite3_column_text(stmt, 0);
2123 sqlite3_finalize(stmt);
2128 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2131 char query[MAX_QUERY_LEN] = { '\0', };
2133 ret = __check_appinfo_for_uid_table(appid, uid);
2135 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2138 } else if (ret == 0) {
2139 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2140 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2141 "VALUES(%Q, %d, 'true', "
2142 "(SELECT app_splash_screen_display FROM package_app_info WHERE app_id=%Q))",
2143 appid, (int)uid, appid);
2145 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2146 "package_app_info_for_uid SET is_disabled='true' "
2147 "WHERE app_id=%Q AND uid=%d", appid, (int)uid);
2150 ret = __exec_query(query);
2152 _LOGD("Add global app disable info failed\n");
2157 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2160 char query[MAX_QUERY_LEN] = {'\0'};
2162 ret = __check_appinfo_for_uid_table(appid, uid);
2164 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2167 } else if (ret > 0) {
2168 sqlite3_snprintf(MAX_QUERY_LEN, query,
2169 "UPDATE package_app_info_for_uid SET "
2170 "is_disabled='false' WHERE app_id=%Q AND "
2171 "uid=%d", appid, (int)uid);
2174 ret = __exec_query(query);
2176 _LOGD("Remove global app disable info failed\n");
2181 static int __update_global_app_splash_screen_for_user(const char *appid,
2182 uid_t uid, int flag)
2185 char query[MAX_QUERY_LEN] = { '\0', };
2187 ret = __check_appinfo_for_uid_table(appid, uid);
2189 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2192 } else if (ret == 0) {
2193 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2194 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2195 "VALUES(%Q, %d, %Q)", appid, (int)uid,
2196 flag ? "true" : "false");
2198 sqlite3_snprintf(MAX_QUERY_LEN, query,
2199 "UPDATE package_app_info_for_uid SET "
2200 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2201 "uid=%d", flag ? "true" : "false", appid, (int)uid);
2204 ret = __exec_query(query);
2206 _LOGD("update global app splash screen info failed\n");
2211 static int __disable_app_splash_screen(const char *appid)
2214 char query[MAX_QUERY_LEN] = {'\0'};
2216 sqlite3_snprintf(MAX_QUERY_LEN, query,
2217 "UPDATE package_app_info SET app_splash_screen_display='false' WHERE app_id=%Q",
2219 ret = __exec_query(query);
2221 _LOGD("Failed to update app_palsh_screen_display");
2226 static int __enable_app_splash_screen(const char *appid)
2229 char query[MAX_QUERY_LEN] = {'\0'};
2231 sqlite3_snprintf(MAX_QUERY_LEN, query,
2232 "UPDATE package_app_info SET app_splash_screen_display='true' WHERE app_id=%Q",
2234 ret = __exec_query(query);
2236 _LOGD("Failed to update app_splash_screen_display");
2241 API int pkgmgr_parser_initialize_db(uid_t uid)
2247 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2249 _LOGD("package info DB initialization failed\n");
2252 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2254 _LOGD("package localized info DB initialization failed\n");
2257 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2259 _LOGD("package app app privilege DB initialization failed\n");
2262 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2264 _LOGD("package app info DB initialization failed\n");
2267 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2269 _LOGD("package app localized info DB initialization failed\n");
2272 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2274 _LOGD("package app icon localized info DB initialization failed\n");
2277 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2279 _LOGD("package app image info DB initialization failed\n");
2282 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2284 _LOGD("package app app control DB initialization failed\n");
2287 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2289 _LOGD("package app app category DB initialization failed\n");
2292 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2294 _LOGD("package app app category DB initialization failed\n");
2297 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2299 _LOGD("package app app permission DB initialization failed\n");
2302 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2304 _LOGD("package app share allowed DB initialization failed\n");
2307 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2309 _LOGD("package app share request DB initialization failed\n");
2312 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2314 _LOGD("package app data control DB initialization failed\n");
2318 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2320 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2324 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2326 _LOGD("package app splash screen DB initialization failed\n");
2330 /* Trigger package_app_info_for_uid */
2331 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2333 _LOGD("package app info for uid DB initialization failed\n");
2338 /* TODO: refactor this code */
2339 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2341 _LOGD("package cert info DB initialization failed\n");
2344 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2346 _LOGD("package cert index info DB initialization failed\n");
2349 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO);
2351 _LOGD("package cert info DB initialization failed\n");
2354 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2);
2356 _LOGD("package cert info DB initialization failed\n");
2359 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2361 _LOGD("package cert info DB initialization failed\n");
2364 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2366 _LOGD("package cert index info DB initialization failed\n");
2370 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2371 if (db_path == NULL) {
2372 _LOGD("Failed to get user cert db path - GLOBAL_USER");
2374 ret = __parserdb_change_perm(db_path, GLOBAL_USER);
2376 _LOGD("Failed to change cert db permission");
2380 db_path = getUserPkgParserDBPathUID(uid);
2381 if (db_path == NULL) {
2382 _LOGD("Failed to get user pkg parser db path - %d", uid);
2384 ret = __parserdb_change_perm(db_path, uid);
2386 _LOGD("Failed to change parser db permission\n");
2393 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2396 char pwuid_buf[1024];
2397 char journal_file[BUFSIZE];
2402 struct passwd userinfo, *result = NULL;
2403 files[0] = (char *)db_file;
2404 files[1] = journal_file;
2408 if (db_file == NULL)
2411 if (getuid() != OWNER_ROOT) /* At this time we should be root to apply this */
2413 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2414 if (uid == OWNER_ROOT)
2416 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2417 if (ret != 0 || result == NULL) {
2418 _LOGE("FAIL: user %d doesn't exist", uid);
2421 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2423 for (i = 0; files[i]; i++) {
2424 fd = open(files[i], O_RDONLY);
2426 if (strerror_r(errno, buf, sizeof(buf)))
2427 strncpy(buf, "", BUFSIZE - 1);
2428 _LOGD("FAIL : open %s : %s", files[i], buf);
2431 ret = fstat(fd, &sb);
2433 if (strerror_r(errno, buf, sizeof(buf)))
2434 strncpy(buf, "", BUFSIZE - 1);
2435 _LOGD("FAIL : fstat %s : %s", files[i], buf);
2439 if (S_ISLNK(sb.st_mode)) {
2440 _LOGE("FAIL : %s is symlink!", files[i]);
2444 ret = fchown(fd, uid, userinfo.pw_gid);
2446 if (strerror_r(errno, buf, sizeof(buf)))
2447 strncpy(buf, "", BUFSIZE - 1);
2448 _LOGD("FAIL : fchown %s %d.%d : %s", files[i], uid,
2449 userinfo.pw_gid, buf);
2454 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2455 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2457 ret = fchmod(fd, mode);
2459 if (strerror_r(errno, buf, sizeof(buf)))
2460 strncpy(buf, "", BUFSIZE - 1);
2461 _LOGD("FAIL : fchmod %s 0664 : %s", files[i], buf);
2466 SET_SMACK_LABEL(files[i]);
2471 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2476 if (getuid() != OWNER_ROOT) {
2477 _LOGE("Only root user is allowed");
2481 db_path = getUserPkgParserDBPathUID(uid);
2482 if (db_path == NULL) {
2483 _LOGE("Failed to get pkg parser db path - %d", uid);
2487 if (access(db_path, F_OK) != -1) {
2488 _LOGE("Manifest db for user %d is already exists", uid);
2494 db_path = getUserPkgCertDBPathUID(uid);
2495 if (db_path == NULL) {
2496 _LOGE("Failed to get pkg cert db path - %d", uid);
2500 if (access(db_path, F_OK) != -1) {
2501 _LOGE("Cert db for user %d is already exists", uid);
2507 ret = pkgmgr_parser_check_and_create_db(uid);
2510 ret = pkgmgr_parser_initialize_db(uid);
2512 pkgmgr_parser_close_db();
2515 pkgmgr_parser_close_db();
2520 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2525 db_path = getUserPkgParserDBPathUID(uid);
2526 if (db_path == NULL) {
2527 _LOGD("Failed to get pkg parser db path - %d", uid);
2532 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, db_path);
2534 _LOGD("Manifest DB creation Failed\n");
2540 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2541 if (db_path == NULL) {
2542 _LOGE("Failed to get pkg cert db path - GLOBAL_USER");
2547 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, db_path);
2549 _LOGD("Cert DB creation Failed\n");
2559 void pkgmgr_parser_close_db(void)
2561 sqlite3_close(pkgmgr_parser_db);
2562 sqlite3_close(pkgmgr_cert_db);
2566 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2568 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2570 _LOGD("manifest pointer is NULL\n");
2574 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2576 _LOGD("Failed to open DB\n");
2579 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2582 /*Begin transaction*/
2583 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2584 if (ret != SQLITE_OK) {
2585 _LOGD("Failed to begin transaction\n");
2589 _LOGD("Transaction Begin\n");
2590 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2592 _LOGD("Insert into DB failed. Rollback now\n");
2593 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2596 /*Commit transaction*/
2597 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2598 if (ret != SQLITE_OK) {
2599 _LOGD("Failed to commit transaction. Rollback now\n");
2600 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2604 _LOGD("Transaction Commit and End\n");
2606 pkgmgr_parser_close_db();
2610 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2612 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2614 _LOGD("manifest pointer is NULL\n");
2618 ret = pkgmgr_parser_check_and_create_db(uid);
2620 _LOGD("Failed to open DB\n");
2623 ret = pkgmgr_parser_initialize_db(uid);
2626 /*Begin transaction*/
2627 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2628 if (ret != SQLITE_OK) {
2629 _LOGD("Failed to begin transaction\n");
2633 _LOGD("Transaction Begin\n");
2634 ret = __insert_manifest_info_in_db(mfx, uid);
2636 _LOGD("Insert into DB failed. Rollback now\n");
2637 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2640 /*Commit transaction*/
2641 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2642 if (ret != SQLITE_OK) {
2643 _LOGD("Failed to commit transaction. Rollback now\n");
2644 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2648 _LOGD("Transaction Commit and End\n");
2650 pkgmgr_parser_close_db();
2654 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2656 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, _getuid());
2659 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2661 if (pkgid == NULL || tep_path == NULL) {
2662 _LOGE("invalid parameter");
2669 ret = pkgmgr_parser_check_and_create_db(uid);
2671 _LOGD("Failed to open DB\n");
2674 ret = pkgmgr_parser_initialize_db(uid);
2678 /*Begin transaction*/
2679 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2680 if (ret != SQLITE_OK) {
2681 _LOGD("Failed to begin transaction\n");
2685 _LOGD("Transaction Begin\n");
2688 /* Updating TEP info in "package_info" table */
2689 query = sqlite3_mprintf("UPDATE package_info "\
2690 "SET package_tep_name = %Q "\
2691 "WHERE package = %Q", tep_path, pkgid);
2693 ret = __exec_query(query);
2694 sqlite3_free(query);
2695 if (ret != SQLITE_OK) {
2696 ret = PM_PARSER_R_ERROR;
2697 _LOGE("sqlite exec failed to insert entries into package_info!!");
2701 /* Updating TEP info in "package_app_info" table */
2702 query = sqlite3_mprintf("UPDATE package_app_info "\
2703 "SET app_tep_name = %Q "\
2704 "WHERE package = %Q", tep_path, pkgid);
2706 ret = __exec_query(query);
2707 sqlite3_free(query);
2708 if (ret != SQLITE_OK) {
2709 ret = PM_PARSER_R_ERROR;
2710 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2714 /*Commit transaction*/
2715 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2716 if (ret != SQLITE_OK) {
2717 _LOGE("Failed to commit transaction, Rollback now\n");
2718 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2719 if (ret != SQLITE_OK)
2720 _LOGE("Failed to Rollback\n");
2722 ret = PM_PARSER_R_ERROR;
2725 _LOGD("Transaction Commit and End\n");
2726 ret = PM_PARSER_R_OK;
2729 pkgmgr_parser_close_db();
2734 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2737 _LOGD("manifest pointer is NULL\n");
2741 ret = pkgmgr_parser_check_and_create_db(uid);
2743 _LOGD("Failed to open DB\n");
2746 ret = pkgmgr_parser_initialize_db(uid);
2749 /*Preserve guest mode visibility*/
2750 __preserve_guestmode_visibility_value(mfx);
2751 /*Begin transaction*/
2752 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2753 if (ret != SQLITE_OK) {
2754 _LOGD("Failed to begin transaction\n");
2758 _LOGD("Transaction Begin\n");
2759 ret = __delete_manifest_info_from_db(mfx, uid);
2761 _LOGD("Delete from DB failed. Rollback now\n");
2762 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2765 ret = __insert_manifest_info_in_db(mfx, uid);
2767 _LOGD("Insert into DB failed. Rollback now\n");
2768 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2772 /*Commit transaction*/
2773 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2774 if (ret != SQLITE_OK) {
2775 _LOGD("Failed to commit transaction. Rollback now\n");
2776 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2780 _LOGD("Transaction Commit and End\n");
2782 pkgmgr_parser_close_db();
2786 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2788 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2791 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2794 _LOGD("manifest pointer is NULL\n");
2798 ret = pkgmgr_parser_check_and_create_db(uid);
2800 _LOGD("Failed to open DB\n");
2803 /*Begin transaction*/
2804 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2805 if (ret != SQLITE_OK) {
2806 _LOGD("Failed to begin transaction\n");
2810 _LOGD("Transaction Begin\n");
2811 ret = __delete_manifest_info_from_db(mfx, uid);
2813 _LOGD("Delete from DB failed. Rollback now\n");
2814 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2817 /*Commit transaction*/
2818 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2819 if (ret != SQLITE_OK) {
2820 _LOGD("Failed to commit transaction, Rollback now\n");
2821 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2825 _LOGD("Transaction Commit and End\n");
2827 pkgmgr_parser_close_db();
2831 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2833 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
2836 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2840 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2842 _LOGD("Failed to open DB\n");
2846 /*Begin transaction*/
2847 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2848 if (ret != SQLITE_OK) {
2849 _LOGD("Failed to begin transaction\n");
2853 _LOGD("Transaction Begin\n");
2855 ret = __disable_global_app_for_user(appid, uid);
2857 ret = __enable_global_app_for_user(appid, uid);
2859 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2860 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2863 /*Commit transaction*/
2864 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2865 if (ret != SQLITE_OK) {
2866 _LOGD("Failed to commit transaction, Rollback now\n");
2867 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2871 _LOGD("Transaction Commit and End\n");
2873 pkgmgr_parser_close_db();
2878 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2880 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
2883 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid, uid_t uid, int is_disable)
2887 ret = pkgmgr_parser_check_and_create_db(uid);
2889 _LOGD("Failed to open DB\n");
2893 /*Begin transaction*/
2894 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2895 if (ret != SQLITE_OK) {
2896 _LOGD("Failed to begin transaction\n");
2901 _LOGD("Transaction Begin\n");
2903 ret = __disable_pkg(pkgid);
2905 ret = __enable_pkg(pkgid);
2908 _LOGD("__update_pkg_disable_condition_in_db failed. Rollback now\n");
2909 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2913 /*Commit transaction*/
2914 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2915 if (ret != SQLITE_OK) {
2916 _LOGD("Failed to commit transaction, Rollback now\n");
2917 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2921 _LOGD("Transaction Commit and End\n");
2924 pkgmgr_parser_close_db();
2928 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid, int is_disable)
2930 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid, _getuid(), is_disable);
2933 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2937 ret = pkgmgr_parser_check_and_create_db(uid);
2939 _LOGD("Failed to open DB\n");
2943 /*Begin transaction*/
2944 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2945 if (ret != SQLITE_OK) {
2946 _LOGD("Failed to begin transaction\n");
2950 _LOGD("Transaction Begin\n");
2952 ret = __disable_app(appid);
2954 ret = __enable_app(appid);
2956 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2957 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2960 /*Commit transaction*/
2961 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2962 if (ret != SQLITE_OK) {
2963 _LOGD("Failed to commit transaction, Rollback now\n");
2964 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2968 _LOGD("Transaction Commit and End\n");
2970 pkgmgr_parser_close_db();
2975 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
2979 if (appid == NULL) {
2980 _LOGD("Invalid parameter");
2984 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2986 _LOGD("Failed to open DB\n");
2990 /* Begin transaction */
2991 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2992 if (ret != SQLITE_OK) {
2993 _LOGD("Failed to begin transaction\n");
2997 _LOGD("Transaction Begin\n");
2999 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3001 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3002 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3005 /* Commit transaction */
3006 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3007 if (ret != SQLITE_OK) {
3008 _LOGD("Failed to commit transaction, Rollback now\n");
3009 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3013 _LOGD("Transaction Commit and End\n");
3015 pkgmgr_parser_close_db();
3019 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3021 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3024 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3028 if (appid == NULL) {
3029 _LOGD("Invalid parameter");
3033 ret = pkgmgr_parser_check_and_create_db(uid);
3035 _LOGD("Failed to open DB");
3039 /* Begin transaction */
3040 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3041 if (ret != SQLITE_OK) {
3042 _LOGD("Failed to begin transaction");
3046 _LOGD("Transaction Begin");
3049 ret = __enable_app_splash_screen(appid);
3051 ret = __disable_app_splash_screen(appid);
3053 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3054 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3057 /* Commit transaction */
3058 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3059 if (ret != SQLITE_OK) {
3060 _LOGD("Failed to commit transaction, Rollback now");
3061 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3065 _LOGD("Transaction Commit and End");
3068 pkgmgr_parser_close_db();
3072 API int pkgmgr_parser_update_app_label_info_in_usr_db(const char *appid, uid_t uid, const char *label)
3075 char query[MAX_QUERY_LEN] = {'\0'};
3077 if (appid == NULL || label == NULL) {
3078 _LOGE("Invalid parameter");
3082 ret = pkgmgr_parser_check_and_create_db(uid);
3084 _LOGD("Failed to open DB");
3088 /*Begin transaction*/
3089 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3090 if (ret != SQLITE_OK) {
3091 _LOGD("Failed to begin transaction\n");
3096 sqlite3_snprintf(MAX_QUERY_LEN, query,
3097 "UPDATE package_app_localized_info SET app_label=%Q WHERE " \
3098 "app_id=%Q AND app_label IS NOT NULL",
3100 ret = __exec_query(query);
3102 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3106 /* Commit transaction */
3107 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3108 if (ret != SQLITE_OK) {
3109 _LOGD("Failed to commit transaction, Rollback now");
3110 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3114 _LOGD("Transaction Commit and End");
3117 pkgmgr_parser_close_db();
3121 API int pkgmgr_parser_update_app_label_info_in_db(const char *appid, const char *label)
3123 return pkgmgr_parser_update_app_label_info_in_usr_db(appid, _getuid(), label);