diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2017-01-13 18:59:07 +0900 |
---|---|---|
committer | Hwankyu Jhun <h.jhun@samsung.com> | 2017-01-16 14:51:40 +0900 |
commit | ffe17597c6ee1090e0b9798f86132e005ccaa8b5 (patch) | |
tree | 00efb144e7b676f1a71f8b8024ac007b172b8b50 | |
parent | ab9c9a8657c7b84fbb447099056d87799f65666b (diff) | |
download | librua-ffe17597c6ee1090e0b9798f86132e005ccaa8b5.tar.gz librua-ffe17597c6ee1090e0b9798f86132e005ccaa8b5.tar.bz2 librua-ffe17597c6ee1090e0b9798f86132e005ccaa8b5.zip |
Support multiple instance launch
This patch adds the instance_id, instance_name, icon and uri column to
the rua_history table. The amd stores the information about apps
runs with multiple instance launch.
- Requires:
[aul] https://review.tizen.org/gerrit/#/c/108620/
[amd] https://review.tizen.org/gerrit/#/c/109746/
Change-Id: I510333b15a664ce36244722a4587c54495f8b7cc
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r-- | include/db-schema.h | 12 | ||||
-rwxr-xr-x | include/rua.h | 15 | ||||
-rw-r--r-- | src/rua.c | 61 | ||||
-rw-r--r-- | src/rua_internal.c | 66 |
4 files changed, 130 insertions, 24 deletions
diff --git a/include/db-schema.h b/include/db-schema.h index d7916e9..b2e322b 100644 --- a/include/db-schema.h +++ b/include/db-schema.h @@ -25,7 +25,11 @@ CREATE TABLE IF NOT EXISTS rua_history ( \ app_path TEXT, \ arg TEXT, \ launch_time INTEGER, \ - PRIMARY KEY(pkg_name) \ + instance_id TEXT, \ + instance_name TEXT, \ + icon TEXT, \ + uri TEXT, \ + PRIMARY KEY(pkg_name, instance_id) \ );" #define CREATE_RUA_STAT_TABLE " \ @@ -43,7 +47,11 @@ enum { RUA_COL_PKGNAME, RUA_COL_APPPATH, RUA_COL_ARG, - RUA_COL_LAUNCHTIME + RUA_COL_LAUNCHTIME, + RUA_COL_INSTANCE_ID, + RUA_COL_INSTANCE_NAME, + RUA_COL_ICON, + RUA_COL_URI, }; enum { diff --git a/include/rua.h b/include/rua.h index d9c7235..3bf79d1 100755 --- a/include/rua.h +++ b/include/rua.h @@ -66,11 +66,15 @@ extern "C" { * @brief RUA record info structure */ struct rua_rec { - int id; /**< primary key */ + int id; /**< primary key */ char *pkg_name; /**< package name */ char *app_path; /**< application path */ char *arg; /**< application launching argument */ time_t launch_time; /**< application launching time */ + char *instance_id; /**< Instance ID */ + char *instance_name; /**< Instance Name */ + char *icon; /**< Icon path */ + char *uri; /**< URI */ }; /** @@ -157,6 +161,15 @@ API int rua_is_latest_app(const char *pkg_name); API int rua_is_latest_app_for_uid(const char *pkg_name, uid_t uid); /** + * @brief Delete rua history with instance id + * @param[in] app_id The application ID + * @param[in] instance_id The instance ID + * @return 0 on success, otherwise a negative error value + */ +API int rua_delete_history_with_instance_id(const char *app_id, + const char *instance_id); + +/** * @brief Initialize rua * @return 0 on success, otherwise a nagative error value * @retval 0 on successful @@ -155,8 +155,10 @@ int rua_history_load_db_for_uid(char ***table, int *nrows, int *ncols, uid_t uid if (r != SQLITE_OK) return -1; - snprintf(query, QUERY_MAXLEN, - "select pkg_name, app_path, arg, launch_time from %s order by launch_time desc;", RUA_HISTORY); + snprintf(query, sizeof(query), + "SELECT pkg_name, app_path, arg, launch_time, instance_id, " + "instance_name, icon, uri FROM %s ORDER BY launch_time DESC;", + RUA_HISTORY); r = sqlite3_get_table(db, query, &db_result, nrows, ncols, &db_err); @@ -212,6 +214,30 @@ int rua_history_get_rec(struct rua_rec *rec, char **table, int nrows, int ncols, if (tmp) rec->launch_time = atoi(tmp); + tmp = db_result[RUA_COL_INSTANCE_ID]; + if (tmp && tmp[0] != '\0') + rec->instance_id = tmp; + else + rec->instance_id = NULL; + + tmp = db_result[RUA_COL_INSTANCE_NAME]; + if (tmp && tmp[0] != '\0') + rec->instance_name = tmp; + else + rec->instance_name = NULL; + + tmp = db_result[RUA_COL_ICON]; + if (tmp && tmp[0] != '\0') + rec->icon = tmp; + else + rec->icon = NULL; + + tmp = db_result[RUA_COL_URI]; + if (tmp && tmp[0] != '\0') + rec->uri = tmp; + else + rec->uri = NULL; + return 0; } @@ -277,3 +303,34 @@ int rua_fini(void) { return 0; } + +int rua_delete_history_with_instance_id(const char *app_id, + const char *instance_id) +{ + int ret; + bundle *b; + + if (app_id == NULL) { + LOGE("Invalid parameter"); + return -1; + } + + b = bundle_create(); + if (b == NULL) { + LOGE("Out of memory"); + return -1; + } + + bundle_add_str(b, AUL_K_RUA_PKGNAME, app_id); + if (instance_id) + bundle_add_str(b, AUL_K_RUA_INSTANCE_ID, instance_id); + + ret = aul_delete_rua_history_for_uid(b, getuid()); + bundle_free(b); + if (ret < 0) { + LOGE("Failed to delete rua history - result(%d)", ret); + return -1; + } + + return 0; +} diff --git a/src/rua_internal.c b/src/rua_internal.c index 1a0abd7..7995262 100644 --- a/src/rua_internal.c +++ b/src/rua_internal.c @@ -81,6 +81,7 @@ int rua_usr_db_delete_history(bundle *b, uid_t uid) char query[QUERY_MAXLEN]; char *pkg_name = NULL; char *app_path = NULL; + char *instance_id = NULL; char *errmsg = NULL; int result = 0; @@ -93,14 +94,22 @@ int rua_usr_db_delete_history(bundle *b, uid_t uid) if (b != NULL) { bundle_get_str(b, AUL_K_RUA_PKGNAME, &pkg_name); bundle_get_str(b, AUL_K_RUA_APPPATH, &app_path); + bundle_get_str(b, AUL_K_RUA_INSTANCE_ID, &instance_id); } - if (pkg_name != NULL) - snprintf(query, QUERY_MAXLEN, "delete from rua_history where pkg_name = '%s';", pkg_name); - else if (app_path != NULL) - snprintf(query, QUERY_MAXLEN, "delete from rua_history where app_path = '%s';", app_path); - else - snprintf(query, QUERY_MAXLEN, "delete from rua_history;"); + if (pkg_name) { + snprintf(query, sizeof(query), + "DELETE FROM rua_history WHERE pkg_name = '%s' " + "AND instance_id = '%s';", + pkg_name, instance_id ? instance_id : ""); + } else if (app_path) { + snprintf(query, sizeof(query), + "DELETE FROM rua_history WHERE app_path = '%s' " + "AND instance_id = '%s';", + app_path, instance_id ? instance_id : ""); + } else { + snprintf(query, sizeof(query), "DELETE FROM rua_history;"); + } LOGI("rua_delete_history_from_db : %s", query); r = sqlite3_exec(db, query, NULL, NULL, &errmsg); @@ -126,7 +135,12 @@ int rua_usr_db_add_history(struct rua_rec *rec, uid_t uid) { int r; char query[QUERY_MAXLEN]; - sqlite3 *db = NULL; + sqlite3 *db; + + if (rec == NULL || rec->pkg_name == NULL || rec->app_path == NULL) { + LOGE("Invalid parameter"); + return -1; + } db = __db_init(uid); if (db == NULL) { @@ -134,20 +148,34 @@ int rua_usr_db_add_history(struct rua_rec *rec, uid_t uid) return -1; } - if (rec == NULL) { - LOGE("Error rec null"); - db_util_close(db); - return -1; + if (rec->instance_id && + (rec->instance_name == NULL || rec->icon == NULL || + rec->uri == NULL)) { + snprintf(query, sizeof(query), + "UPDATE %s SET launch_time = %d " + "WHERE pkg_name = %s AND instance_id = %s;", + RUA_HISTORY, + (int)rec->launch_time, + rec->pkg_name, + rec->instance_id); + } else { + snprintf(query, sizeof(query), + "INSERT OR REPLACE INTO %s " + "(pkg_name, app_path, arg, launch_time, " + "instance_id, instance_name, icon, uri) " + "VALUES (\"%s\", \"%s\", \"%s\", %d, " + "\"%s\", \"%s\", \"%s\", \"%s\");", + RUA_HISTORY, + rec->pkg_name, + rec->app_path, + rec->arg ? rec->arg : "", + (int)rec->launch_time, + rec->instance_id ? rec->instance_id : "", + rec->instance_name ? rec->instance_name : "", + rec->icon ? rec->icon : "", + rec->uri ? rec->uri : ""); } - snprintf(query, QUERY_MAXLEN, - "insert or replace into %s ( pkg_name, app_path, arg, launch_time) " - " values ( \"%s\", \"%s\", \"%s\", %d) ", - RUA_HISTORY, - rec->pkg_name ? rec->pkg_name : "", - rec->app_path ? rec->app_path : "", - rec->arg ? rec->arg : "", (int)rec->launch_time); - r = __exec(db, query); if (r == -1) { LOGE("[RUA ADD HISTORY ERROR] %s\n", query); |