Add sending wakeup wakeup signal to resourced
[platform/core/appfw/pkgmgr-info.git] / parser / src / pkgmgr_parser_db.c
index 9394c87..8745594 100644 (file)
@@ -27,6 +27,7 @@
 #include <pwd.h>
 
 #include <glib.h>
+#include <gio/gio.h>
 #include <sqlite3.h>
 
 #include <tzplatform_config.h>
@@ -186,22 +187,36 @@ static const char *__get_cert_db_path(void)
        return tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
 }
 
+#define DB_VERSION_PATH SYSCONFDIR "/package-manager/pkg_db_version.txt"
 static int __set_db_version(sqlite3 *db)
 {
-       static const char query_raw[] = "PRAGMA user_version=";
-       char query[BUFSIZE];
        int ret;
-       int version;
+       FILE *fp = NULL;
+       char version[PKG_STRING_LEN_MAX] = { 0 };
+       char *query = NULL;
+
+       fp = fopen(DB_VERSION_PATH, "r");
+       retvm_if(fp == NULL, -1, "Failed to open db version file");
+       if (fgets(version, sizeof(version), fp) == NULL) {
+               _LOGE("Failed to get version information");
+               fclose(fp);
+               return -1;
+       }
+       fclose(fp);
 
-       version = atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 +
-               atoi(TIZEN_PATCH_VER);
-       snprintf(query, sizeof(query), "%s%d", query_raw, version);
+       query = sqlite3_mprintf("PRAGMA user_version=%Q", version);
+       if (!query) {
+               _LOGE("Out of memory");
+               return -1;
+       }
 
        ret = sqlite3_exec(db, query, NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
                _LOGE("exec failed: %s", sqlite3_errmsg(db));
+               sqlite3_free(query);
                return -1;
        }
+       sqlite3_free(query);
 
        return 0;
 }
@@ -301,18 +316,16 @@ static const char *parser_init_queries[] = {
        QUERY_CREATE_TABLE_PACKAGE_INFO,
        QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO,
        QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO,
+       QUERY_CREATE_TABLE_PACKAGE_APPDEFINED_PRIVILEGE_INFO,
        QUERY_CREATE_TABLE_PACKAGE_UPDATE_INFO,
        QUERY_CREATE_TABLE_PACKAGE_APP_INFO,
        QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO,
-       QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO, /* ? */
-       QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO, /* ? */
        QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL,
+       QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL_PRIVILEGE,
        QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY,
        QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA,
-       QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION, /* ? */
-       QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED, /* ? */
-       QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST, /* ? */
        QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL,
+       QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL_PRIVILEGE,
        QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID,
        QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID,
        QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN,
@@ -441,17 +454,121 @@ API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
        if (pkgmgr_parser_initialize_parser_db(uid))
                return PM_PARSER_R_ERROR;
 
-       if (pkgmgr_parser_initialize_cert_db())
-               return PM_PARSER_R_ERROR;
+       if (uid == OWNER_ROOT || uid == GLOBAL_USER)
+               if (pkgmgr_parser_initialize_cert_db())
+                       return PM_PARSER_R_ERROR;
 
        return PM_PARSER_R_OK;
 }
 
+#define RESOURCED_BUS_NAME "org.tizen.resourced"
+#define RESOURCED_PROC_PATH "/Org/Tizen/ResourceD/Process"
+#define RESOURCED_PROC_INTERFACE "org.tizen.resourced.process"
+#define RESOURCED_PROC_METHOD "ProcExclude"
+static void __send_wakeup_signal_to_resourced(pid_t pid)
+{
+       GError *error = NULL;
+       GDBusConnection *conn;
+       GDBusProxy *proxy;
+       GVariant *reply;
+
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (conn == NULL) {
+               _LOGE("Failed to connect to dbus: %s", error->message);
+               g_error_free(error);
+               return;
+       }
+
+       proxy = g_dbus_proxy_new_sync(conn,
+                       G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+                       NULL, RESOURCED_BUS_NAME,
+                       RESOURCED_PROC_PATH, RESOURCED_PROC_INTERFACE,
+                       NULL, &error);
+       if (proxy == NULL) {
+               _LOGE("failed to get proxy object: %s", error->message);
+               g_error_free(error);
+               g_object_unref(conn);
+               return;
+       }
+
+       reply = g_dbus_proxy_call_sync(proxy, RESOURCED_PROC_METHOD,
+                       g_variant_new("(si)", "wakeup", pid),
+                       G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (reply == NULL)
+               _LOGE("failed to get reply from resourced");
+       if (error) {
+               _LOGE("failed to send request: %s", error->message);
+               g_error_free(error);
+       }
+
+       g_object_unref(proxy);
+       g_object_unref(conn);
+}
+
+static void __check_db_lock(const char *dbpath)
+{
+       FILE *fp;
+       FILE *fp_cmdline;
+       struct stat sb;
+       int pid;
+       unsigned int maj;
+       unsigned int min;
+       ino_t ino;
+       char cmdline[BUFSIZE];
+       char name[BUFSIZE];
+       size_t len;
+
+       if (stat(dbpath, &sb) == -1) {
+               _LOGE("get db file(%s) status failed: %d", dbpath, errno);
+               return;
+       }
+
+       fp = fopen("/proc/locks", "r");
+       if (fp == NULL) {
+               _LOGE("Failed to open lock info: %d", errno);
+               return;
+       }
+
+       while (fscanf(fp, "%*s %*s %*s %*s %d %x:%x:%lu %*s %*s",
+                               &pid, &maj, &min, &ino) != EOF) {
+               if (maj != major(sb.st_dev) || min != minor(sb.st_dev) ||
+                               ino != sb.st_ino || pid == getpid())
+                       continue;
+
+               snprintf(cmdline, sizeof(cmdline), "/proc/%d/cmdline", pid);
+               fp_cmdline = fopen(cmdline, "r");
+               name[0] = '\0';
+               if (fp_cmdline != NULL) {
+                       len = fread(name, sizeof(char), sizeof(name) - 1,
+                                       fp_cmdline);
+                       if (len > 0) {
+                               if (name[len - 1] == '\n')
+                                       name[len - 1] = '\0';
+                               else
+                                       name[len] = '\0';
+                       }
+                       fclose(fp_cmdline);
+               }
+
+               _LOGE("%s (%d) has lock on pkgmgr db(%s)!", name, pid, dbpath);
+               __send_wakeup_signal_to_resourced(pid);
+       }
+
+       fclose(fp);
+}
+
 #define BUSY_WAITING_USEC (1000000 / 10 / 2) /* 0.05 sec */
-#define BUSY_WAITING_MAX 20 /* wait for max 1 sec */
+#define BUSY_WAITING_MAX 40 /* wait for max 2 sec */
 static int __db_busy_handler(void *data, int count)
 {
-       if (count < BUSY_WAITING_MAX) {
+       if (count < (BUSY_WAITING_MAX / 2)) {
+               usleep(BUSY_WAITING_USEC);
+               return 1;
+       } else if (count == (BUSY_WAITING_MAX / 2)) {
+               __check_db_lock((const char *)data);
+               usleep(BUSY_WAITING_USEC);
+               return 1;
+       } else if (count < BUSY_WAITING_MAX) {
                usleep(BUSY_WAITING_USEC);
                return 1;
        } else {
@@ -474,10 +591,18 @@ static int __open_db(uid_t uid, const char *path, sqlite3 **db, int flags)
        if (ret != SQLITE_OK)
                return ret;
 
+       ret = sqlite3_busy_handler(*db, __db_busy_handler, (void *)path);
+       if (ret != SQLITE_OK) {
+               _LOGE("failed to register busy handler: %s",
+                               sqlite3_errmsg(*db));
+               sqlite3_close_v2(*db);
+               return ret;
+       }
+
        if (flags & SQLITE_OPEN_CREATE) {
                ret = __initialize_db(*db, path, uid);
                if (ret) {
-                       _LOGE("failed to initialize db: %s\n");
+                       _LOGE("failed to initialize db: %s", path);
                        sqlite3_close_v2(*db);
                        return -1;
                }
@@ -491,14 +616,6 @@ static int __open_db(uid_t uid, const char *path, sqlite3 **db, int flags)
                return ret;
        }
 
-       ret = sqlite3_busy_handler(*db, __db_busy_handler, NULL);
-       if (ret != SQLITE_OK) {
-               _LOGE("failed to register busy handler: %s",
-                               sqlite3_errmsg(*db));
-               sqlite3_close_v2(*db);
-               return ret;
-       }
-
        return ret;
 }
 
@@ -557,11 +674,66 @@ static const char *__find_effective_appid(GList *metadata_list)
        return NULL;
 }
 
+static int __insert_appcontrol_privilege_info(sqlite3 *db, const char *appid,
+               appcontrol_x *ac)
+{
+       static const char query[] =
+               "INSERT INTO package_app_app_control_privilege (app_id,"
+               "  app_control, privilege) VALUES (?, ?, ?)";
+       int ret;
+       sqlite3_stmt *stmt;
+       int idx;
+       char app_control[BUFSIZE];
+       GList *tmp;
+       char *privilege;
+
+       if (ac == NULL)
+               return 0;
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               return -1;
+       }
+
+       for (tmp = ac->privileges; tmp; tmp = tmp->next) {
+               privilege = (char *)tmp->data;
+               if (privilege == NULL || !strlen(privilege))
+                       continue;
+
+               idx = 1;
+               snprintf(app_control, sizeof(app_control), "%s|%s|%s",
+                               ac->operation ? (strlen(ac->operation) > 0 ?
+                                       ac->operation : "NULL") : "NULL",
+                               ac->uri ? (strlen(ac->uri) > 0 ?
+                                       ac->uri : "NULL") : "NULL",
+                               ac->mime ? (strlen(ac->mime) > 0 ?
+                                       ac->mime : "NULL") : "NULL");
+               __BIND_TEXT(db, stmt, idx++, appid);
+               __BIND_TEXT(db, stmt, idx++, app_control);
+               __BIND_TEXT(db, stmt, idx++, privilege);
+
+               ret = sqlite3_step(stmt);
+               if (ret != SQLITE_DONE) {
+                       _LOGE("step failed: %s", sqlite3_errmsg(db));
+                       sqlite3_finalize(stmt);
+                       return -1;
+               }
+
+               sqlite3_reset(stmt);
+       }
+
+       sqlite3_finalize(stmt);
+
+       return 0;
+}
+
 static int __insert_appcontrol_info(sqlite3 *db, application_x *app)
 {
        static const char query[] =
-               "INSERT INTO package_app_app_control (app_id, app_control) "
-               "VALUES (?, ?)";
+               "INSERT INTO package_app_app_control (app_id, app_control,"
+               "  visibility) "
+               "VALUES (?, ?, ?)";
        int ret;
        sqlite3_stmt *stmt;
        int idx;
@@ -592,6 +764,7 @@ static int __insert_appcontrol_info(sqlite3 *db, application_x *app)
                                        ac->mime : "NULL") : "NULL");
                __BIND_TEXT(db, stmt, idx++, app->appid);
                __BIND_TEXT(db, stmt, idx++, app_control);
+               __BIND_TEXT(db, stmt, idx++, ac->visibility);
 
                ret = sqlite3_step(stmt);
                if (ret != SQLITE_DONE) {
@@ -600,6 +773,11 @@ static int __insert_appcontrol_info(sqlite3 *db, application_x *app)
                        return -1;
                }
 
+               if (__insert_appcontrol_privilege_info(db, app->appid, ac)) {
+                       sqlite3_finalize(stmt);
+                       return -1;
+               }
+
                sqlite3_reset(stmt);
        }
 
@@ -695,6 +873,53 @@ static int __insert_metadata_info(sqlite3 *db, application_x *app)
        return 0;
 }
 
+static int __insert_app_data_control_privilege_info(sqlite3 *db,
+               datacontrol_x *datacontrol)
+{
+       static const char query[] =
+               "INSERT INTO package_app_data_control_privilege (providerid,"
+               "  privilege, type) VALUES (?, ?, ?)";
+
+       int ret;
+       sqlite3_stmt *stmt;
+       int idx;
+       GList *privileges;
+       char *priv;
+
+       if (datacontrol == NULL)
+               return 0;
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               return -1;
+       }
+
+       for (privileges = datacontrol->privileges; privileges;
+                       privileges = privileges->next) {
+               priv = (char *)privileges->data;
+               if (priv == NULL)
+                       continue;
+
+               idx = 1;
+               __BIND_TEXT(db, stmt, idx++, datacontrol->providerid);
+               __BIND_TEXT(db, stmt, idx++, priv);
+               __BIND_TEXT(db, stmt, idx++, datacontrol->type);
+
+               ret = sqlite3_step(stmt);
+               if (ret != SQLITE_DONE) {
+                       _LOGE("step failed: %s", sqlite3_errmsg(db));
+                       sqlite3_finalize(stmt);
+                       return -1;
+               }
+
+               sqlite3_reset(stmt);
+       }
+
+       sqlite3_finalize(stmt);
+       return 0;
+}
+
 static int __insert_datacontrol_info(sqlite3 *db, application_x *app)
 {
        static const char query[] =
@@ -733,6 +958,12 @@ static int __insert_datacontrol_info(sqlite3 *db, application_x *app)
                        return -1;
                }
 
+               if (dc->privileges &&
+                               __insert_app_data_control_privilege_info(db, dc)) {
+                       sqlite3_finalize(stmt);
+                       return -1;
+               }
+
                sqlite3_reset(stmt);
        }
 
@@ -881,6 +1112,9 @@ static GList *__find_splashscreens(GList *splashscreens)
        GList *list = NULL;
        splashscreen_x *ss;
 
+       if (splashscreens == NULL)
+               return NULL;
+
        g_list_foreach(splashscreens,
                        __find_appcontrol_splashscreen_with_dpi, &list);
        g_list_foreach(splashscreens,
@@ -896,7 +1130,8 @@ static GList *__find_splashscreens(GList *splashscreens)
        return list;
 }
 
-static int __insert_splashscreen_info(sqlite3 *db, application_x *app)
+static int __insert_splashscreen_info(sqlite3 *db, application_x *app,
+               GList *ss_list)
 {
        static const char query[] =
                "INSERT INTO package_app_splash_screen (app_id, src, type,"
@@ -907,12 +1142,10 @@ static int __insert_splashscreen_info(sqlite3 *db, application_x *app)
        int idx;
        GList *tmp;
        splashscreen_x *ss;
-       GList *ss_list;
 
        if (app->splashscreens == NULL)
                return 0;
 
-       ss_list = __find_splashscreens(app->splashscreens);
        if (ss_list == NULL)
                return 0;
 
@@ -1400,7 +1633,7 @@ static int __insert_app_localized_info(sqlite3 *db, application_x *app)
 
                sqlite3_reset(stmt);
 
-               if (strcasecmp(app->mainapp, "true")) {
+               if (strcasecmp(app->mainapp, "true") == 0) {
                        if (__insert_mainapp_localized_info(db, app, locale,
                                                label, icon))
                                _LOGE("insert mainapp localized info failed");
@@ -1454,6 +1687,50 @@ static int __insert_package_privilege_info(sqlite3 *db, manifest_x *mfx)
        return 0;
 }
 
+static int __insert_package_appdefined_privilege_info(sqlite3 *db,
+               manifest_x *mfx)
+{
+       static const char query[] =
+               "INSERT INTO package_appdefined_privilege_info "
+               "(package, privilege, license, type) "
+               "VALUES (?, ?, ?, ?)";
+       int ret;
+       sqlite3_stmt *stmt;
+       int idx;
+       GList *tmp;
+       appdefined_privilege_x *priv;
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               return -1;
+       }
+
+       for (tmp = mfx->appdefined_privileges; tmp; tmp = tmp->next) {
+               priv = (appdefined_privilege_x *)tmp->data;
+               if (priv == NULL)
+                       continue;
+
+               idx = 1;
+               __BIND_TEXT(db, stmt, idx++, mfx->package);
+               __BIND_TEXT(db, stmt, idx++, priv->value);
+               __BIND_TEXT(db, stmt, idx++, priv->license);
+               __BIND_TEXT(db, stmt, idx++, priv->type);
+
+               ret = sqlite3_step(stmt);
+               if (ret != SQLITE_DONE) {
+                       _LOGE("step failed: %s", sqlite3_errmsg(db));
+                       sqlite3_finalize(stmt);
+                       return -1;
+               }
+               sqlite3_reset(stmt);
+       }
+
+       sqlite3_finalize(stmt);
+
+       return 0;
+}
+
 /* _PRODUCT_LAUNCHING_ENHANCED_
  *  app->indicatordisplay, app->portraitimg, app->landscapeimg,
  *  app->guestmode_appstatus
@@ -1476,7 +1753,7 @@ static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
                "  app_effective_appid, app_splash_screen_display,"
                "  app_package_system, app_removable,"
                "  app_package_installed_time, app_support_ambient,"
-               "  app_setup_appid) "
+               "  app_external_path, app_setup_appid) "
                "VALUES (?, ?, "
                "  ?, LOWER(?), ?, LOWER(?), LOWER(?),"
                "  LOWER(?), LOWER(?), ?,"
@@ -1492,7 +1769,7 @@ static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
                "  ?, LOWER(?),"
                "  LOWER(?), LOWER(?),"
                "  ?, LOWER(?),"
-               "  ?)";
+               "  ?, ?)";
        int ret;
        sqlite3_stmt *stmt;
        int idx;
@@ -1500,6 +1777,7 @@ static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
        application_x *app;
        int bg_category;
        const char *effective_appid;
+       GList *ss_list;
 
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
@@ -1561,12 +1839,13 @@ static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
                __BIND_TEXT(db, stmt, idx++, mfx->api_version);
                __BIND_TEXT(db, stmt, idx++, effective_appid);
                __BIND_TEXT(db, stmt, idx++,
-                               __get_bool(app->splash_screen_display, false));
+                               __get_bool(app->splash_screen_display, true));
                __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->system, false));
                __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->removable, false));
                __BIND_TEXT(db, stmt, idx++, mfx->installed_time);
                __BIND_TEXT(db, stmt, idx++,
                                __get_bool(app->support_ambient, false));
+               __BIND_TEXT(db, stmt, idx++, mfx->external_path);
                __BIND_TEXT(db, stmt, idx++, app->setup_appid);
 
                ret = sqlite3_step(stmt);
@@ -1594,10 +1873,13 @@ static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
                        sqlite3_finalize(stmt);
                        return -1;
                }
-               if (__insert_splashscreen_info(db, app)) {
+               ss_list = __find_splashscreens(app->splashscreens);
+               if (__insert_splashscreen_info(db, app, ss_list)) {
+                       g_list_free(ss_list);
                        sqlite3_finalize(stmt);
                        return -1;
                }
+               g_list_free(ss_list);
                if (__insert_app_localized_info(db, app)) {
                        sqlite3_finalize(stmt);
                        return -1;
@@ -1790,6 +2072,8 @@ static int __insert_package_info(sqlite3 *db, manifest_x *mfx)
                return -1;
        if (__insert_package_privilege_info(db, mfx))
                return -1;
+       if (__insert_package_appdefined_privilege_info(db, mfx))
+               return -1;
 
        return 0;
 }
@@ -1970,9 +2254,9 @@ API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(
                return PM_PARSER_R_EINVAL;
        }
 
-       dbpath = __get_parser_db_path(uid);
+       dbpath = __get_parser_db_path(GLOBAL_USER);
 
-       ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
+       ret = __open_db(GLOBAL_USER, dbpath, &db, SQLITE_OPEN_READWRITE);
        if (ret != SQLITE_OK) {
                _LOGE("open db failed: %d", ret);
                return PM_PARSER_R_ERROR;
@@ -2169,9 +2453,9 @@ API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(
                return PM_PARSER_R_EINVAL;
        }
 
-       dbpath = __get_parser_db_path(uid);
+       dbpath = __get_parser_db_path(GLOBAL_USER);
 
-       ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
+       ret = __open_db(GLOBAL_USER, dbpath, &db, SQLITE_OPEN_READWRITE);
        if (ret != SQLITE_OK) {
                _LOGE("open db failed: %d", ret);
                return PM_PARSER_R_ERROR;
@@ -2320,6 +2604,72 @@ API int pkgmgr_parser_update_app_label_info_in_db(const char *appid,
                        label);
 }
 
+static int __set_app_icon(sqlite3 *db, const char *appid, const char *icon_path)
+{
+       static const char query[] =
+               "UPDATE package_app_localized_info SET app_icon=? "
+               "WHERE app_id=? AND app_icon IS NOT NULL";
+       int ret;
+       sqlite3_stmt *stmt;
+       int idx = 1;
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               return -1;
+       }
+
+       __BIND_TEXT(db, stmt, idx++, icon_path);
+       __BIND_TEXT(db, stmt, idx++, appid);
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_DONE) {
+               _LOGE("step failed: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               return -1;
+       }
+
+       sqlite3_finalize(stmt);
+
+       return 0;
+}
+
+API int pkgmgr_parser_update_app_icon_info_in_usr_db(const char *appid,
+               uid_t uid, const char *icon_path)
+{
+       int ret;
+       const char *dbpath;
+       sqlite3 *db;
+
+       if (appid == NULL) {
+               _LOGE("invalid parameter");
+               return PM_PARSER_R_EINVAL;
+       }
+
+       dbpath = __get_parser_db_path(uid);
+
+       ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
+       if (ret != SQLITE_OK) {
+               _LOGE("open db failed: %d", ret);
+               return PM_PARSER_R_ERROR;
+       }
+
+       __BEGIN_TRANSACTION(db);
+       __DO_TRANSACTION(db, __set_app_icon(db, appid, icon_path));
+       __END_TRANSACTION(db);
+
+       sqlite3_close_v2(db);
+
+       return PM_PARSER_R_OK;
+}
+
+API int pkgmgr_parser_update_app_icon_info_in_db(const char *appid,
+               const char *icon_path)
+{
+       return pkgmgr_parser_update_app_icon_info_in_usr_db(appid, __getuid(),
+                       icon_path);
+}
+
 static int __set_tep_path(sqlite3 *db, const char *pkgid, const char *tep_path)
 {
        static const char query[] =