Add new feature to change app's icon
[platform/core/appfw/pkgmgr-info.git] / parser / src / pkgmgr_parser_db.c
index 0163fae..7b9d10e 100644 (file)
@@ -2473,6 +2473,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[] =