+
+static int __update_image(sqlite3 *db, const char *pkg_name,
+ const char *instance_id, const char *image)
+{
+ static const char query[] =
+ "UPDATE rua_history SET image=? "
+ "WHERE pkg_name=? AND instance_id=?";
+ sqlite3_stmt *stmt;
+ int idx = 1;
+ int r;
+
+ r = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+ if (r != SQLITE_OK) {
+ LOGE("Prepare failed: %s", sqlite3_errmsg(db));
+ return -1;
+ }
+
+ __BIND_TEXT(db, stmt, idx++, image);
+ __BIND_TEXT(db, stmt, idx++, pkg_name);
+ __BIND_TEXT(db, stmt, idx++, instance_id ? instance_id : "");
+
+ r = sqlite3_step(stmt);
+ if (r != SQLITE_DONE) {
+ LOGE("Step failed: %s", sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ return -1;
+ }
+ sqlite3_finalize(stmt);
+
+ return 0;
+}
+
+API int rua_usr_db_update_image(const char *pkg_name, const char *instance_id,
+ const char *image, uid_t uid)
+{
+ int r;
+ sqlite3 *db;
+
+ if (pkg_name == NULL || image == NULL) {
+ LOGE("Invalid parameter");
+ return -1;
+ }
+
+ db = __db_init(uid);
+ if (db == NULL) {
+ LOGE("Error db null");
+ return -1;
+ }
+
+ r = __update_image(db, pkg_name, instance_id, image);
+ if (r < 0) {
+ LOGE("Failed to update image - appid(%s)", pkg_name);
+ sqlite3_close_v2(db);
+ return -1;
+ }
+ sqlite3_close_v2(db);
+
+ r = rua_dbus_send_update_signal(UPDATE);
+ if (r < 0) {
+ LOGE("[RUA SEND SIGNAL ERROR]");
+ return -1;
+ }
+
+ return r;
+}
+
+API int rua_db_update_image(const char *pkg_name, const char *instance_id,
+ const char *image)
+{
+ return rua_usr_db_update_image(pkg_name, instance_id, image, getuid());
+}