int rua_db_add_history(struct rua_rec *rec);
int rua_usr_db_add_history(struct rua_rec *rec, uid_t uid);
+/**
+ * @brief Update the image of the application
+ * @param[in] pkg_name The application ID
+ * @param[in] instance_id The instance ID
+ * @param[in] image The image of the application
+ * @return 0 on success, otherwise a nagative error value
+ */
+int rua_db_update_image(const char *pkg_name, const char *instance_id,
+ const char *image);
+int rua_usr_db_update_image(const char *pkg_name, const char *instance_id,
+ const char *image, uid_t uid);
+
#ifdef __cplusplus
}
#endif
static const char query[] =
"INSERT OR REPLACE INTO rua_history ("
" pkg_name, app_path, arg, launch_time,"
- " instance_id, instance_name, icon, uri) "
- "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
+ " instance_id, instance_name, icon, uri,"
+ " image) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
int r;
sqlite3_stmt *stmt;
int idx = 1;
rec->instance_name ? rec->instance_name : "");
__BIND_TEXT(db, stmt, idx++, rec->icon ? rec->icon : "");
__BIND_TEXT(db, stmt, idx++, rec->uri ? rec->uri : "");
+ __BIND_TEXT(db, stmt, idx++, rec->image ? rec->image : "");
r = sqlite3_step(stmt);
if (r != SQLITE_DONE) {
{
return rua_usr_db_add_history(rec, getuid());
}
+
+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());
+}