Support screenshot feature 82/136682/1
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 28 Jun 2017 11:25:54 +0000 (20:25 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Sun, 2 Jul 2017 23:07:56 +0000 (23:07 +0000)
- Adds a new column of the image path
- Adds a new APIs to update the image path

Change-Id: Idd4e4a1e474360ee618c8994059796cbd3dcae34
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
(cherry picked from commit ad448ddd37cfaf556cd58d92c5d58c5d0d2edaf4)

include/rua.h
include/rua_internal.h
src/db-schema.h
src/rua.c
src/rua_dbus.h
src/rua_internal.c

index eb27c07..a2dfe34 100644 (file)
@@ -60,6 +60,7 @@ struct rua_rec {
        char *instance_name;    /**< Instance Name */
        char *icon;             /**< Icon path */
        char *uri;              /**< URI */
+       char *image;            /**< Image path */
 };
 
 /**
index 4140a25..ec496d8 100644 (file)
@@ -53,6 +53,18 @@ int rua_usr_db_delete_history(bundle *b, uid_t uid);
 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
index b2e322b..eb64cfd 100644 (file)
@@ -29,6 +29,7 @@ CREATE TABLE IF NOT EXISTS rua_history ( \
        instance_name TEXT, \
        icon TEXT, \
        uri TEXT, \
+       image TEXT, \
        PRIMARY KEY(pkg_name, instance_id) \
 );"
 
@@ -52,6 +53,7 @@ enum {
        RUA_COL_INSTANCE_NAME,
        RUA_COL_ICON,
        RUA_COL_URI,
+       RUA_COL_IMAGE,
 };
 
 enum {
index 2612817..ff921b6 100644 (file)
--- a/src/rua.c
+++ b/src/rua.c
@@ -135,7 +135,7 @@ API int rua_history_load_db_for_uid(char ***table, int *nrows, int *ncols, uid_t
 {
        static const char query[] =
                "SELECT pkg_name, app_path, arg, launch_time, instance_id,"
-               "  instance_name, icon, uri "
+               "  instance_name, icon, uri, image "
                "FROM rua_history ORDER BY launch_time DESC";
        int r;
        char *db_err = NULL;
@@ -269,6 +269,12 @@ API int rua_history_get_rec(struct rua_rec *rec, char **table, int nrows, int nc
        else
                rec->uri = NULL;
 
+       tmp = db_result[RUA_COL_IMAGE];
+       if (tmp && tmp[0] != '\0')
+               rec->image = tmp;
+       else
+               rec->image = NULL;
+
        return 0;
 }
 
index 1b53963..76789a9 100644 (file)
@@ -20,7 +20,8 @@
 typedef enum
 {
        ADD,
-       DELETE
+       DELETE,
+       UPDATE
 } update_type;
 
 int rua_dbus_send_update_signal(update_type type);
index f39df16..8ce257c 100644 (file)
@@ -217,8 +217,9 @@ static int __insert_history(sqlite3 *db, struct rua_rec *rec)
        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;
@@ -238,6 +239,7 @@ static int __insert_history(sqlite3 *db, struct rua_rec *rec)
                        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) {
@@ -320,3 +322,74 @@ API int rua_db_add_history(struct rua_rec *rec)
 {
        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());
+}