From b3d010cbf995bd1a21c01c86b56c53f0e1812570 Mon Sep 17 00:00:00 2001 From: hyunho kang Date: Fri, 11 Dec 2015 16:12:02 +0900 Subject: [PATCH] Add delete rua history feature To resolve librua APIs permission problem, provide indirect DB access method to librua. Change-Id: Iffa94fd9da1331f464ae1ff0b3fa6666fc09a90b Signed-off-by: hyunho kang --- am_daemon/amd_request.c | 16 ++++++++++++++++ include/app_sock.h | 1 + include/aul.h | 36 ++++++++++++++++++++++++++++++++++++ src/app_sock.c | 3 ++- src/pkginfo.c | 28 ++++++++++++++++++++++++++++ src/service.c | 1 + 6 files changed, 84 insertions(+), 1 deletion(-) diff --git a/am_daemon/amd_request.c b/am_daemon/amd_request.c index f1a788e..a9722ab 100644 --- a/am_daemon/amd_request.c +++ b/am_daemon/amd_request.c @@ -625,6 +625,21 @@ err_out: return -1; } +static int __dispatch_remove_history(int clifd, const app_pkt_t *pkt, struct ucred *cr) +{ +/* + int result = 0; + bundle *b = NULL; + b = bundle_decode(pkt->data, pkt->len); + result = rua_delete_history_from_db(b); + bundle_free(b); + + __send_result_data(clifd, APP_REMOVE_HISTORY, + (unsigned char *)&result, sizeof(int)); +*/ + return 0; +} + static int __dispatch_app_group_get_window(int clifd, const app_pkt_t *pkt, struct ucred *cr) { bundle *b; @@ -1141,6 +1156,7 @@ static app_cmd_dispatch_func dispatch_table[APP_CMD_MAX] = { [APP_CANCEL] = __dispatch_app_result, [APP_KILL_BY_PID] = __dispatch_app_term, [APP_ADD_HISTORY] = NULL, + [APP_REMOVE_HISTORY] = __dispatch_remove_history, [APP_RUNNING_INFO] = __dispatch_app_running_info, [APP_RUNNING_INFO_RESULT] = NULL, [APP_IS_RUNNING] = __dispatch_app_is_running, diff --git a/include/app_sock.h b/include/app_sock.h index 1bedcfd..0a0065c 100644 --- a/include/app_sock.h +++ b/include/app_sock.h @@ -40,6 +40,7 @@ enum app_cmd { APP_CANCEL, APP_KILL_BY_PID, APP_ADD_HISTORY, + APP_REMOVE_HISTORY, APP_RUNNING_INFO, APP_RUNNING_INFO_RESULT, APP_IS_RUNNING, diff --git a/include/aul.h b/include/aul.h index 0176d76..0ff2c5e 100644 --- a/include/aul.h +++ b/include/aul.h @@ -113,6 +113,11 @@ typedef enum _aul_type{ /** AUL public key - To support rua stat */ #define AUL_SVC_K_RUA_STAT_CALLER "__K_RUA_STAT_CALLER__" #define AUL_SVC_K_RUA_STAT_TAG "__K_RUA_STAT_TAG__" +/** AUL public key - To support rua delete */ +#define AUL_K_RUA_PKGNAME "__K_RUA_PKGNAME" +/** AUL public key - To support rua delete */ +#define AUL_K_RUA_APPPATH "__K_RUA_APPPATH" + /** AUL internal private key */ @@ -1966,6 +1971,37 @@ int aul_remove_loader(int loader_id); */ int aul_app_get_pid(const char *appid); + +/** + * @par Description: + * This function delete rua history. + * + * @param[in] b Bundle object Target Package name or app path. If NULL or has no value, delete all rua history. + * + * @return 0 if success, negative value(<0) if fail + * @see None + * @remarks This API is only for Appfw internally. + * + * @par Sample code: + * @code +#include + +... +{ + int r; + bundle *b = bundle_create(); + if (pkg_name) + bundle_add_str(b, AUL_K_RUA_PKGNAME, pkg_name); + else if (app_path) + bundle_add_str(b, AUL_K_RUA_APPPATH, app_path); + + r = aul_delete_rua_history(b); +} + + * @endcode + **/ +int aul_delete_rua_history(bundle *b); + #ifdef __cplusplus } #endif diff --git a/src/app_sock.c b/src/app_sock.c index a0862b5..0297492 100644 --- a/src/app_sock.c +++ b/src/app_sock.c @@ -909,7 +909,8 @@ app_pkt_t *__app_send_cmd_with_result_for_uid(int pid, uid_t uid, int cmd, unsig } pkt->cmd = cmd; pkt->len = datalen; - memcpy(pkt->data, kb_data, pkt->len); + if (kb_data) + memcpy(pkt->data, kb_data, pkt->len); while (sent != AUL_PKT_HEADER_SIZE + pkt->len) { len = send(fd, pkt, AUL_PKT_HEADER_SIZE + pkt->len - sent, 0); diff --git a/src/pkginfo.c b/src/pkginfo.c index fc6ea6a..82d8e35 100644 --- a/src/pkginfo.c +++ b/src/pkginfo.c @@ -255,3 +255,31 @@ SLPAPI int aul_app_get_pkgid_bypid(int pid, char *pkgid, int len) return aul_app_get_pkgid_bypid_for_uid(pid, pkgid, len, getuid()); } +SLPAPI int aul_delete_rua_history(bundle *b) +{ + app_pkt_t *ret = NULL; + bundle_raw *br = NULL; + int datalen = 0; + int result = 0; + + /* b can be NULL if b is NULL delete all rua history */ + if (b != NULL) + bundle_encode(b, &br, &datalen); + + ret = __app_send_cmd_with_result(AUL_UTIL_PID, APP_REMOVE_HISTORY, br, + datalen); + + if (ret != NULL) { + if (ret->len > 0) { + memcpy(&result, ret->data, ret->len); + } else { + if (br != NULL) + free(br); + return -1; + } + } + if (br != NULL) + free(br); + return result; +} + diff --git a/src/service.c b/src/service.c index c7b9cc1..73d9d14 100755 --- a/src/service.c +++ b/src/service.c @@ -31,6 +31,7 @@ #include "aul.h" #include "aul_api.h" #include "aul_svc.h" +#include "app_sock.h" #include "aul_svc_db.h" #include "simple_util.h" #include "aul_svc_priv_key.h" -- 2.7.4