Resolve remove history APIs permission problem 73/54073/10 accepted/tizen/mobile/20160104.224128 accepted/tizen/tv/20160104.224146 accepted/tizen/wearable/20160104.224203 submit/tizen/20160104.043748
authorhyunho kang <hhstark.kang@samsung.com>
Fri, 11 Dec 2015 07:13:15 +0000 (16:13 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Mon, 4 Jan 2016 00:40:29 +0000 (16:40 -0800)
- Access rua db indirectly using aul_svc_delete_rua_history.

Change-Id: I5f347ee01b477135d40304b64009e7d78436d6e1
Signed-off-by: hyunho kang <hhstark.kang@samsung.com>
CMakeLists.txt
include/rua.h
packaging/librua.spec
src/rua.c
test/rua-test.c

index 4ea97f8..c8be007 100644 (file)
@@ -15,7 +15,7 @@ SET(SRCS
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED sqlite3 db-util libtzplatform-config)
+pkg_check_modules(pkgs REQUIRED sqlite3 db-util libtzplatform-config bundle aul)
 
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index 2bd8f51..710d471 100755 (executable)
@@ -31,6 +31,7 @@
 #define __RUA_H__
 
 #include <sqlite3.h>
+#include <bundle.h>
 #include <time.h>
 
 #ifndef API
@@ -67,6 +68,16 @@ struct rua_rec {
        time_t launch_time;             /**< application launching time */
 };
 
+
+
+/**
+ * @brief      Delete history from DB
+ * @return     0 on success, otherwise a nagative error value
+ * @retval     0 on successful
+ * @retval     -1 on failed
+ */
+API int rua_delete_history_from_db(bundle *b);
+
 /**
  * @brief      Clear history
  * @return     0 on success, otherwise a nagative error value
index f2545cf..1234963 100644 (file)
@@ -8,6 +8,8 @@ Source0:        librua-%{version}.tar.gz
 Source1001:     librua.manifest
 BuildRequires:  cmake
 BuildRequires:  sqlite3
+BuildRequires:  pkgconfig(bundle)
+BuildRequires:  pkgconfig(aul)
 BuildRequires:  pkgconfig(db-util)
 BuildRequires:  pkgconfig(sqlite3)
 BuildRequires:  pkgconfig(libtzplatform-config)
index 2c0c0ad..e0d93e2 100644 (file)
--- a/src/rua.c
+++ b/src/rua.c
@@ -27,8 +27,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-
 #include <db-util.h>
+#include <aul.h>
 
 /* For multi-user support */
 #include <tzplatform_config.h>
@@ -55,11 +55,16 @@ static int __exec(sqlite3 *db, char *query);
 static int __create_table(sqlite3 *db);
 static sqlite3 *__db_init();
 
-int rua_clear_history(void)
+int rua_delete_history_from_db(bundle *b)
 {
        int r;
-       char query[QUERY_MAXLEN];
        sqlite3 *db = NULL;
+       char query[QUERY_MAXLEN];
+
+       char *pkg_name = NULL;
+       char *app_path = NULL;
+       char *errmsg = NULL;
+       int result = 0;
 
        db = __db_init();
        if (db == NULL) {
@@ -67,61 +72,72 @@ int rua_clear_history(void)
                return -1;
        }
 
-       snprintf(query, QUERY_MAXLEN, "delete from %s;", RUA_HISTORY);
-
-       r = __exec(db, query);
-       db_util_close(db);
-       return r;
-}
+       if (b != NULL) {
+               bundle_get_str(b, AUL_K_RUA_PKGNAME, &pkg_name);
+               bundle_get_str(b, AUL_K_RUA_APPPATH, &app_path);
+       }
 
-int rua_delete_history_with_pkgname(char *pkg_name)
-{
-       int r;
-       char query[QUERY_MAXLEN];
+       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;");
 
-       sqlite3 *db = NULL;
+       LOGI("rua_delete_history_from_db : %s", query);
+       r = sqlite3_exec(db, query, NULL, NULL, &errmsg);
 
-       db = __db_init();
-       if (db == NULL) {
-               LOGE("Error db null");
-               return -1;
+       if (r != SQLITE_OK) {
+               LOGE("fail to exec delete query %s : %s", query, errmsg);
+               sqlite3_free(errmsg);
+               result = -1;
        }
 
-       if (pkg_name == NULL) {
+       if (db != NULL)
                db_util_close(db);
-               return -1;
-       }
 
-       snprintf(query, QUERY_MAXLEN, "delete from %s where pkg_name = '%s';",
-               RUA_HISTORY, pkg_name);
+       return result;
 
-       r = __exec(db, query);
-       db_util_close(db);
-       return r;
 }
 
-int rua_delete_history_with_apppath(char *app_path)
+int rua_clear_history(void)
 {
        int r;
-       char query[QUERY_MAXLEN];
-       sqlite3 *db = NULL;
+       r = aul_delete_rua_history(NULL);
+       LOGI("rua_clear_history result : %d ", r);
+       return r;
+}
 
-       db = __db_init();
-       if (db == NULL) {
-               LOGE("Error db null");
+int rua_delete_history_with_pkgname(char *pkg_name)
+{
+       int r;
+       bundle *b = bundle_create();
+       if (b == NULL) {
+               LOGE("bundle_create fail out of memory.");
                return -1;
        }
 
-       if (app_path == NULL) {
-               db_util_close(db);
+       bundle_add_str(b, AUL_K_RUA_PKGNAME, pkg_name);
+       r = aul_delete_rua_history(b);
+       LOGI("rua_delete_history_with_pkgname result : %d ", r);
+       bundle_free(b);
+       return r;
+}
+
+int rua_delete_history_with_apppath(char *app_path)
+{
+       int r;
+       bundle *b = bundle_create();
+       if (b == NULL) {
+               LOGE("bundle_create fail out of memory.");
                return -1;
        }
 
-       snprintf(query, QUERY_MAXLEN, "delete from %s where app_path = '%s';",
-               RUA_HISTORY, app_path);
+       bundle_add_str(b, AUL_K_RUA_APPPATH, app_path);
+       r = aul_delete_rua_history(b);
+       LOGI("rua_delete_history_with_apppath result : %d ", r);
+       bundle_free(b);
 
-       r = __exec(db, query);
-       db_util_close(db);
        return r;
 }
 
index 03a7032..bfd72c7 100644 (file)
@@ -60,5 +60,5 @@ int main(int argc, char* argv[])
        if (argc != 2)
                return 0;
        ret = __add_history(argv[1]);
-       return 0;
+       return ret;
 }