modified the name of the api privacy_guard_client_foreach_package_by_package_id to... 53/69653/2 accepted/tizen/common/20160517.174010 accepted/tizen/mobile/20160517.033051 submit/tizen/20160517.004843
authorKyoungyong Lee <bluevox@naver.com>
Mon, 16 May 2016 08:53:44 +0000 (17:53 +0900)
committerKyoungyong Lee <bluevox@naver.com>
Mon, 16 May 2016 11:15:10 +0000 (20:15 +0900)
Change-Id: I06d56fdc11dd8ff4c63fb6fb065615cf720073b7

14 files changed:
client/inc/PrivacyGuardClient.h
client/src/PrivacyChecker.cpp
client/src/PrivacyGuardClient.cpp
client/src/privacy_guard_client.cpp
common/inc/PrivacyGuardTypes.h
common/inc/SocketConnection.h
common/src/PrivacyIdInfo.cpp
include/privacy_guard_client.h
packaging/privacy-guard.spec
server/CMakeLists.txt
server/inc/PrivacyGuardDb.h
server/inc/PrivacyInfoService.h
server/src/PrivacyGuardDb.cpp
server/src/service/PrivacyInfoService.cpp

index 4950d8e..894bcdd 100755 (executable)
@@ -36,7 +36,7 @@ private:
 
        static std::mutex m_singletonMutex;
 
-       std::list <std::pair<std::string, std::string>> logInfoList;
+       std::list <std::pair<std::string, std::string>> m_logInfoList;
 
        PrivacyGuardClient();
        ~PrivacyGuardClient();
@@ -68,7 +68,7 @@ public:
 
        int PgForeachPrivacyPackageId(const int userId, std::list < std::string > & packageList) const;
 
-       int PgForeachPackageByPrivacyId(const int userId, const std::string privacyId, std::list < std::string > & packageList) const;
+       int PgForeachPackageInfoByPrivacyId(const int userId, const std::string privacyId, std::list < package_data_s > & packageList) const;
 
        int PgForeachMonitorPolicyByPackageId(const int userId, const std::string packageId,
                std::list <privacy_data_s> & privacyInfoList) const;
index b469858..5e04ee5 100755 (executable)
@@ -20,6 +20,7 @@
 #include <dbus/dbus-glib-lowlevel.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <privilege_info.h>
 #include "PrivacyChecker.h"
 #include "PrivacyIdInfo.h"
 #include "PrivacyGuardClient.h"
@@ -96,20 +97,22 @@ PrivacyChecker::printMonitorPolicyCache(void)
 int
 PrivacyChecker::initMonitorPolicyCache(void)
 {
-       PG_LOGD("PrivacyChecker::initCache");
-
        std::list < std::pair < std::string, int > > monitorPolicyList;
+
        int retval = PrivacyGuardClient::getInstance()->PgGetAllMonitorPolicy(monitorPolicyList);
        if(retval == PRIV_GUARD_ERROR_SUCCESS && !monitorPolicyList.empty()) {
                m_monitorPolicyCache.insert(monitorPolicyList.begin(), monitorPolicyList.end());
+       } else {
+               PG_LOGD("ret: [%d], monitorPolicyList size: [%d]", retval, monitorPolicyList.size());
        }
+
        return retval;
 }
 
 int
 PrivacyChecker::getMonitorPolicy(const int userId, const std::string packageId, const std::string privacyId, int &monitorPolicy)
 {
-       PG_LOGD("getMonitorPolicy m_isInitialized : %d", m_isInitialized);
+       PG_LOGD("m_isInitialized: %d", m_isInitialized);
 
        if (m_isInitialized == false) {
                initialize();
@@ -117,7 +120,7 @@ PrivacyChecker::getMonitorPolicy(const int userId, const std::string packageId,
 //     printMonitorPolicyCache();
 
        std::string userPkgIdPrivacyId = std::to_string(userId) + std::string("|") + packageId + std::string("|") + privacyId;
-       PG_LOGD("key : %s", userPkgIdPrivacyId.c_str());
+       PG_LOGD("key: %s", userPkgIdPrivacyId.c_str());
        std::map<std::string, int>::iterator itr = m_monitorPolicyCache.find(userPkgIdPrivacyId);
        int res = PRIV_GUARD_ERROR_SUCCESS;
        if(itr != m_monitorPolicyCache.end()) {
@@ -134,22 +137,13 @@ PrivacyChecker::getMonitorPolicy(const int userId, const std::string packageId,
 void
 PrivacyChecker::checkMonitorByPrivilege(const std::string privilegeId)
 {
-       PG_LOGD("checkMonitorByPrivilege");
-
-       if(privilegeId.compare("http://tizen.org/privilege/calendar.read") == 0 ||
-                       privilegeId.compare("http://tizen.org/privilege/calendar.write") == 0 ||
-                       privilegeId.compare("http://tizen.org/privilege/contact.read") == 0 ||
-                       privilegeId.compare("http://tizen.org/privilege/contact.write") == 0 ||
-                       privilegeId.compare("http://tizen.org/privilege/location") == 0 ||
-                       privilegeId.compare("http://tizen.org/privilege/messaging.write") == 0 ||
-                       privilegeId.compare("http://tizen.org/privilege/messaging.read") == 0 ||
-                       privilegeId.compare("http://tizen.org/privilege/messaging.send") == 0 ||
-                       privilegeId.compare("http://tizen.org/privilege/messaging.sms") == 0 ||
-                       privilegeId.compare("http://tizen.org/privilege/messaging.mms") == 0 ||
-                       privilegeId.compare("http://tizen.org/privilege/messaging.email") == 0) {
+       PG_LOGD("checkMonitorByPrivilege called with privilege: [%s]", privilegeId.c_str());
+
+       if (privilege_info_is_privacy(privilegeId.c_str())) {
                m_isMonitorEnable = true;
        }
        else {
+               PG_LOGD("[%s] is not related to a privacy.", privilegeId.c_str());
                m_isMonitorEnable = false;
        }
 }
index fbac6f2..a9b8a80 100755 (executable)
@@ -21,7 +21,8 @@
 #include "SocketClient.h"
 #include "PrivacyIdInfo.h"
 
-#define COUNT 10
+//#define COUNT 10
+#define COUNT 1
 
 #undef __READ_DB_IPC__
 
@@ -48,19 +49,19 @@ int
 PrivacyGuardClient::PgAddPrivacyAccessLog(const int userId, const std::string packageId, const std::string privacyId)
 {
        int result = PRIV_GUARD_ERROR_SUCCESS;
-       logInfoList.push_back(std::pair <std::string, std::string> (packageId, privacyId));
-       PG_LOGD("PrivacyGuardClient userId : %d, PgAddPrivacyAccessLog logInfoList.size() : %d", userId, logInfoList.size());
+       m_logInfoList.push_back(std::pair <std::string, std::string> (packageId, privacyId));
+       PG_LOGD("PrivacyGuardClient userId : %d, PgAddPrivacyAccessLog m_logInfoList.size() : %d", userId, m_logInfoList.size());
 
-       if(logInfoList.size() >= COUNT) {
+       if(m_logInfoList.size() >= COUNT) {
                int res = m_pSocketClient->connect();
                TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "connect : %d", res);
 
-               res = m_pSocketClient->call("PgAddPrivacyAccessLog", userId, logInfoList, &result);
+               res = m_pSocketClient->call("PgAddPrivacyAccessLog", userId, m_logInfoList, &result);
                TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
 
                res = m_pSocketClient->disconnect();
                TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "disconnect : %d", res);
-               logInfoList.clear();
+               m_logInfoList.clear();
        }
 
        return result;
@@ -87,18 +88,18 @@ int
 PrivacyGuardClient::PgAddPrivacyAccessLogBeforeTerminate(void)
 {
        int result = PRIV_GUARD_ERROR_SUCCESS;
-       PG_LOGD("PgAddPrivacyAccessLogBeforeTerminate, logInfoList.size() : %d", logInfoList.size());
+       PG_LOGD("PgAddPrivacyAccessLogBeforeTerminate, m_logInfoList.size() : %d", m_logInfoList.size());
 
-       if(logInfoList.size() > 0) {
+       if(m_logInfoList.size() > 0) {
                int res = m_pSocketClient->connect();
                TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "connect : %d", res);
 
-               res = m_pSocketClient->call("PgAddPrivacyAccessLog", logInfoList, &result);
+               res = m_pSocketClient->call("PgAddPrivacyAccessLog", m_logInfoList, &result);
                TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
 
                res = m_pSocketClient->disconnect();
                TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "disconnect : %d", res);
-               logInfoList.clear();
+               m_logInfoList.clear();
        }
 
        return result;
@@ -107,6 +108,8 @@ PrivacyGuardClient::PgAddPrivacyAccessLogBeforeTerminate(void)
 int
 PrivacyGuardClient::PgAddMonitorPolicy(const int userId, const std::string pkgId, const std::list < std::string >& list, int monitorPolicy)
 {
+       PG_LOGD("userID: [%d], packageID[%s], monitorPolicy: [%d]", userId, pkgId.c_str(), monitorPolicy);
+
        std::list < std::string > privacyList;
 
        int res = PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(list, privacyList);
@@ -276,7 +279,7 @@ PrivacyGuardClient::PgForeachPrivacyPackageId(const int userId, std::list < std:
 }
 
 int
-PrivacyGuardClient::PgForeachPackageByPrivacyId(const int userId, const std::string privacyId, std::list < std::string > & packageList) const
+PrivacyGuardClient::PgForeachPackageInfoByPrivacyId(const int userId, const std::string privacyId, std::list < package_data_s > & packageInfoList) const
 {
        int result = PRIV_GUARD_ERROR_SUCCESS;
 
@@ -288,7 +291,7 @@ PrivacyGuardClient::PgForeachPackageByPrivacyId(const int userId, const std::str
        int res = m_pSocketClient->connect();
        TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "connect : %d", res);
 
-       res = m_pSocketClient->call("PgForeachPackageByPrivacyId", userId, privacyId, &result, &packageList);
+       res = m_pSocketClient->call("PgForeachPackageInfoByPrivacyId", userId, privacyId, &result, &packageInfoList);
        TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
 
        res = m_pSocketClient->disconnect();
index 0b7c8cd..e347226 100755 (executable)
@@ -238,7 +238,9 @@ int privacy_guard_client_foreach_privacy_count_by_package_id(const int user_id,
 
 int privacy_guard_client_add_monitor_policy(const int user_id, const char *package_id, const char **privilege_list, const int monitor_policy)
 {
-       if (user_id < 0 || package_id == NULL) {
+       PG_LOGD("user_id: [%d], package_id: [%s], monitor_policy: [%d]", user_id, package_id, monitor_policy);
+
+       if (user_id < 0 || package_id == NULL || privilege_list == NULL) {
                PG_LOGE("Invalid parameters.");
                return PRIV_GUARD_ERROR_INVALID_PARAMETER;
        }
@@ -359,7 +361,7 @@ int privacy_guard_client_foreach_privacy_package_id(const int user_id, privacy_g
        return PRIV_GUARD_ERROR_SUCCESS;
 }
 
-int privacy_guard_client_foreach_package_by_privacy_id(const int user_id, const char *privacy_id, privacy_guard_client_package_id_cb callback, void *user_data)
+int privacy_guard_client_foreach_package_info_by_privacy_id(const int user_id, const char *privacy_id, privacy_guard_client_package_info_cb callback, void *user_data)
 {
        if (user_id < 0 || privacy_id == NULL) {
                PG_LOGE("Invalid parameters.");
@@ -368,20 +370,19 @@ int privacy_guard_client_foreach_package_by_privacy_id(const int user_id, const
 
        PrivacyGuardClient* pInst = PrivacyGuardClient::getInstance();
 
-       std::list < std::string > packageList;
+       std::list <package_data_s> packageInfoList;
 
-       int retval = pInst->PgForeachPackageByPrivacyId(user_id, std::string(privacy_id), packageList);
+       int retval = pInst->PgForeachPackageInfoByPrivacyId(user_id, std::string(privacy_id), packageInfoList);
        if (retval != PRIV_GUARD_ERROR_SUCCESS) {
-               PG_LOGE("Failed to do PrivacyGuardClient::PgForeachPackageByPrivacyId(). [%d]", retval);
+               PG_LOGE("Failed to do PrivacyGuardClient::PgForeachPackageInfoByPrivacyId(). [%d]", retval);
                return retval;
        }
 
-       if (packageList.size() == 0)
+       if (packageInfoList.size() == 0)
                return PRIV_GUARD_ERROR_NO_DATA;
 
-       for (std::list < std::string >::iterator iter = packageList.begin(); iter != packageList.end(); ++iter) {
-               PG_LOGD("package_id: %s", iter->c_str());
-               bool ret = callback(iter->c_str(), user_data);
+       for (std::list < package_data_s >::iterator iter = packageInfoList.begin(); iter != packageInfoList.end(); ++iter) {
+               bool ret = callback(iter->package_id, iter->count, iter->monitor_policy, user_data);
                if (ret == false)
                        break;
        }
index d55e7fc..c241987 100755 (executable)
 #define PRIVACY_DB_PATH         tzplatform_mkpath(TZ_SYS_DB,".privacy_guard.db")
 
 typedef struct _privacy_data_s {
-       charprivacy_id;
+       char *privacy_id;
        int monitor_policy;
 } privacy_data_s;
 
+typedef struct _package_data_s {
+       char *package_id;
+       int count;
+       int monitor_policy;
+} package_data_s;
+
+
 static const std::string SERVER_ADDRESS ("/tmp/privacy_guard_server");
 static const std::string DBUS_PATH("/privacy_guard/dbus_notification");
 static const std::string DBUS_SIGNAL_INTERFACE("org.tizen.privacy_guard.signal");
index c8c743c..5e24bb5 100755 (executable)
@@ -195,6 +195,35 @@ public:
 
                return PRIV_GUARD_ERROR_SUCCESS;
        }
+
+       int read(package_data_s& out)
+       {
+               int length = 0;
+               int res = 0;
+               char* pBuf;
+
+               // package id
+               res = m_socketStream.readStream(sizeof(length), &length);
+               TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "readStream : %d", res);
+               pBuf = new (std::nothrow) char[length + 1];
+               TryReturn(pBuf != NULL, PRIV_GUARD_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_GUARD_ERROR_OUT_OF_MEMORY);
+               m_socketStream.readStream(length, pBuf);
+               TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res);
+               pBuf[length] = 0;
+               out.package_id = strdup(pBuf);
+               delete[] pBuf;
+
+               // monitor policy
+               res = read(&(out.monitor_policy));
+               TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "readStream : %d", res);
+
+               // count
+               res = read(&(out.count));
+               TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "readStream : %d", res);
+
+               return PRIV_GUARD_ERROR_SUCCESS;
+       }
+
        template < typename T >
        int  read (std::list<T>& list)
        {
@@ -330,6 +359,28 @@ public:
 
                return PRIV_GUARD_ERROR_SUCCESS;
        }
+
+       int write(const package_data_s& in)
+       {
+               // package id
+               int length = strlen(in.package_id);
+               int res = 0;
+               res = m_socketStream.writeStream(sizeof(length), &length);
+               TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "writeStream : %d", res);
+               res = m_socketStream.writeStream(length, in.package_id);
+               TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "writeStream : %d", res);
+
+               // monitor policy
+               res = write(in.monitor_policy);
+               TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "write : %d", res);
+
+               // count
+               res = write(in.count);
+               TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "write : %d", res);
+
+               return PRIV_GUARD_ERROR_SUCCESS;
+       }
+
        template<typename T, typename ...Args>
        int write(const T* in, const Args&... args)
        {
index d8cab99..d42dc93 100755 (executable)
@@ -40,8 +40,6 @@ PrivacyIdInfo::initialize(void)
 
        for (l = privacy_list; l != NULL; l = l->next) {
                char *privacy_id = (char*)l->data;
-               PG_LOGD("privacy_id: %s", privacy_id);
-
                ret = privilege_info_get_privilege_list_by_privacy(privacy_id, &privilege_list);
                if (ret != PRVMGR_ERR_NONE) {
                        PG_LOGE("Failed to get privilege list from security-privilege-manager [%d] using privacy[%s].", ret, privacy_id);
@@ -120,7 +118,7 @@ PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(const std::list< std::string >
                std::string privacyId;
                int res = getPrivacyIdFromPrivilege(*iter, privacyId);
                if (res == PRIV_GUARD_ERROR_SUCCESS) {
-                       PG_LOGD("Privacy[%s] from Privilege[%s]", privacyId.c_str(), iter->c_str());
+                       PG_LOGD("Privacy ID [%s] from Privilege [%s]", privacyId.c_str(), iter->c_str());
                        privacyIdSet.insert(privacyId);
                }
        }
index a0f935c..be7c74f 100755 (executable)
@@ -57,6 +57,22 @@ typedef bool (*privacy_guard_client_monitor_policy_cb) (const char *privacy_id,
 typedef bool (*privacy_guard_client_package_id_cb) (const char *package_id, void *user_data);
 
 /**
+ * @brief      Called when the reply of the package id request is delivered.
+ * @since      tizen 3.0
+ *
+ * @param[in] package_id               The package ID
+ * @param[in] count                            The privacy count
+ * @param[in] monitor_policy   The monitor policy (0 or 1)
+ * @param[in] user_data        The user data passed from the callback registration function
+ *
+ * @returns: true to continue with the next iteration of the loop, otherwise return false to break out of the loop
+ *
+ * @see        privacy_guard_client_foreach_package_info_by_privacy_id()
+ */
+typedef bool (*privacy_guard_client_package_info_cb) (const char *package_id, const int count, const int monitor_policy, void *user_data);
+
+
+/**
  * @brief      Called when the reply of the privacy count request is delivered.
  * @since      tizen 3.0
  *
@@ -172,13 +188,13 @@ EXTERN_API int privacy_guard_client_foreach_privacy_package_id(const int user_id
 
 /**
  * @fn int privacy_guard_client_foreach_package_by_privacy_id(const int user_id, const char *privacy_id, privacy_guard_client_package_id_cb callback, void *user_data)
- * @brief get package using specified privacy
+ * @brief get package info (package_id, count, monitor_enable) using specified privacy
  * @param[in] user_id          The user ID
  * @param[in] privacy_id       The privacy ID
  * @param[in] callback                 The callback function to invoke
  * @param[in] user_data The user data to be passed to the callback function
  */
-EXTERN_API int privacy_guard_client_foreach_package_by_privacy_id(const int user_id, const char *privacy_id, privacy_guard_client_package_id_cb callback, void *user_data);
+EXTERN_API int privacy_guard_client_foreach_package_info_by_privacy_id(const int user_id, const char *privacy_id, privacy_guard_client_package_info_cb callback, void *user_data);
 
 /**
  * @fn int privacy_guard_client_update_main_monitor_policy(const int user_id, const bool main_monitor_policy)
index 6ef1ab0..30a23d9 100755 (executable)
@@ -25,7 +25,7 @@ BuildRequires:  pkgconfig(sqlite3)
 BuildRequires: pkgconfig(capi-system-info)
 BuildRequires: pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(security-privilege-manager)
-#BuildRequires:        pkgconfig(cynara-monitor)
+BuildRequires: pkgconfig(cynara-monitor)
 
 Requires(post):   /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
index 8e56308..20c9d64 100755 (executable)
@@ -7,8 +7,7 @@ SET(EXEC_PREFIX "\${prefix}")
 SET(INCLUDEDIR "\${prefix}/include")
 
 INCLUDE(FindPkgConfig)
-#pkg_check_modules(pkgs REQUIRED dlog sqlite3 dbus-1 dbus-glib-1 db-util pkgmgr-info capi-system-info libtzplatform-config security-privilege-manager cynara-monitor)
-pkg_check_modules(pkgs REQUIRED dlog sqlite3 dbus-1 dbus-glib-1 db-util pkgmgr-info capi-system-info libtzplatform-config security-privilege-manager)
+pkg_check_modules(pkgs REQUIRED dlog sqlite3 dbus-1 dbus-glib-1 db-util pkgmgr-info capi-system-info libtzplatform-config security-privilege-manager cynara-monitor)
 
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index e137bae..c3e6b9f 100755 (executable)
@@ -80,7 +80,7 @@ public:
 
        int PgForeachPrivacyPackageId(const int userId, std::list < std::string > & packageList);
 
-       int PgForeachPackageByPrivacyId(const int userId, const std::string privacyId, std::list < std::string > &packageList);
+       int PgForeachPackageInfoByPrivacyId(const int userId, const std::string privacyId, std::list < package_data_s > &packageList);
 
        int PgUpdateMonitorPolicy(const int userId, const std::string packageId, const std::string privacyId, const int monitorPolicy);
 
index 9edea84..af9b32e 100755 (executable)
@@ -41,7 +41,7 @@ public:
                pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgForeachPrivacyCountByPrivacyId"), PgForeachPrivacyCountByPrivacyId);
                pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgForeachPrivacyCountByPackageId"), PgForeachPrivacyCountByPackageId);
                pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgForeachPrivacyPackageId"), PgForeachPrivacyPackageId);
-               pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgForeachPackageByPrivacyId"), PgForeachPackageByPrivacyId);
+               pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgForeachPackageInfoByPrivacyId"), PgForeachPackageInfoByPrivacyId);
                pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgForeachMonitorPolicyByPackageId"), PgForeachMonitorPolicyByPackageId);
                pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgGetMonitorPolicy"), PgGetMonitorPolicy);
                pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgGetAllMonitorPolicy"), PgGetAllMonitorPolicy);
@@ -63,7 +63,7 @@ public:
        static void PgForeachPrivacyCountByPrivacyId(SocketConnection* pConnector);
        static void PgForeachPrivacyCountByPackageId(SocketConnection* pConnector);
        static void PgForeachPrivacyPackageId(SocketConnection* pConnector);
-       static void PgForeachPackageByPrivacyId(SocketConnection* pConnector);
+       static void PgForeachPackageInfoByPrivacyId(SocketConnection* pConnector);
        static void PgForeachMonitorPolicyByPackageId(SocketConnection* pConnector);
        static void PgGetMonitorPolicy(SocketConnection* pConnector);
        static void PgGetAllMonitorPolicy(SocketConnection* pConnector);
index f175698..5d6fe5c 100755 (executable)
@@ -24,6 +24,9 @@
 #include "PrivacyGuardDb.h"
 #include "PrivacyIdInfo.h"
 
+#define PRIVACY_GUARD_DAYS 7
+#define UNIX_TIME_ONE_DAY (24 * 60 * 60) // 86400 secs
+
 #if 0
 // [CYNARA]
 #include "CynaraService.h"
@@ -281,7 +284,7 @@ PrivacyGuardDb::PgAddMonitorPolicy(const int userId, const std::string packageId
        TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_prepare_v2 : %d", res);
 
        for (std::list <std::string>::const_iterator iter = privacyList.begin(); iter != privacyList.end(); ++iter) {
-               PG_LOGD("PrivacyID : %s", iter->c_str());
+               PG_LOGD("User ID: [%d], Package ID: [%s], PrivacyID: [%s], Monitor Policy: [%d]", userId, packageId.c_str(), iter->c_str(), monitorPolicy);
 
                // bind
                res = sqlite3_bind_int(m_stmt, 1, userId);
@@ -829,7 +832,6 @@ PrivacyGuardDb::PgForeachPrivacyCountByPackageId(const int userId, const int sta
                                continue;
                        }
                        const char* privacyId = (char*)l->data;
-                       PG_LOGD("[kylee] privacy ID: %s", privacyId);
                        privacyInfoList.push_back(std::pair <std::string, int> (std::string(privacyId), count));
                }
                sqlite3_reset(m_stmt);
@@ -927,6 +929,7 @@ PrivacyGuardDb::PgGetAllMonitorPolicy(std::list < std::pair < std::string, int >
        }
 
        m_dbMutex.unlock();
+       PG_LOGD("monitorPolicyList.size() is [%d]", monitorPolicyList.size());
        if(monitorPolicyList.size() > 0) {
                res = PRIV_GUARD_ERROR_SUCCESS;
        }
@@ -1028,10 +1031,26 @@ PrivacyGuardDb::PgForeachPrivacyPackageId(const int userId, std::list < std::str
 }
 
 int
-PrivacyGuardDb::PgForeachPackageByPrivacyId(const int userId, const std::string privacyId, std::list < std::string > &packageList)
+PrivacyGuardDb::PgForeachPackageInfoByPrivacyId(const int userId, const std::string privacyId, std::list < package_data_s > &packageInfoList)
 {
        int res = -1;
-       static const std::string query = std::string("SELECT DISTINCT PKG_ID FROM MonitorPolicy WHERE USER_ID=? AND PRIVACY_ID=?");
+       static const std::string query = std::string("SELECT DISTINCT PKG_ID, MONITOR_POLICY FROM MonitorPolicy WHERE USER_ID=? AND PRIVACY_ID=?");
+       static const std::string PKGINFO_SELECT = std::string("SELECT COUNT(*) FROM StatisticsMonitorInfo WHERE USER_ID=? AND PKG_ID=? AND PRIVACY_ID=? AND USE_DATE>=? AND USE_DATE<=?");
+       sqlite3_stmt* infoStmt;
+       time_t start_date, today_midnight, end_date;
+       struct tm *date = NULL;
+
+       // get start~end date (for 7 days)
+       end_date = time(NULL);
+       date = localtime(&end_date);
+       PG_LOGD("current (end) time [%d]: %4d/%2d/%2d %2d:%2d", end_date, date->tm_year + 1900, date->tm_mon + 1, date->tm_mday, date->tm_hour, date->tm_min);
+       date->tm_hour = 0;
+       date->tm_min = 0;
+       date->tm_sec = 0;
+       today_midnight = mktime(date);
+       start_date = today_midnight - (UNIX_TIME_ONE_DAY * (PRIVACY_GUARD_DAYS - 1));
+       date = localtime(&start_date);
+       PG_LOGD("start time [%d]: %4d/%2d/%2d %2d:%2d", start_date, date->tm_year + 1900, date->tm_mon + 1, date->tm_mday, date->tm_hour, date->tm_min);
 
        m_dbMutex.lock();
 
@@ -1060,12 +1079,47 @@ PrivacyGuardDb::PgForeachPackageByPrivacyId(const int userId, const std::string
 
        // step
        while ((res = sqlite3_step(m_stmt)) == SQLITE_ROW) {
-               char* p_data = (char*)sqlite3_column_text(m_stmt, 0);
-               if(p_data == NULL) {
+               char* tmp_data = (char*)sqlite3_column_text(m_stmt, 0);
+               if(tmp_data == NULL) {
                        continue;
                }
-               packageList.push_back(std::string(p_data));
+               package_data_s p_data;
+               p_data.package_id = strdup(tmp_data);
+               p_data.monitor_policy = sqlite3_column_int(m_stmt, 1);
+               PG_LOGD("## package_id[%s]", p_data.package_id);
+               PG_LOGD("## monitor_policy[%d]", p_data.monitor_policy);
+
+               // prepare
+               res = sqlite3_prepare_v2(m_sqlHandler, PKGINFO_SELECT.c_str(), -1, &infoStmt, NULL);
+               TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_prepare_v2 : %d", res);
+
+               // bind
+               res = sqlite3_bind_int(infoStmt, 1, userId);
+               TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_int : %d", res);
+
+               res = sqlite3_bind_text(infoStmt, 2, p_data.package_id, -1, SQLITE_TRANSIENT);
+               TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_text : %d", res);
+
+               res = sqlite3_bind_text(infoStmt, 3, privacyId.c_str(), -1, SQLITE_TRANSIENT);
+               TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_text : %d", res);
+
+               res = sqlite3_bind_int(infoStmt, 4, start_date);
+               TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_int : %d", res);
+
+               res = sqlite3_bind_int(infoStmt, 5, end_date);
+               TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_int : %d", res);
+
+               if ((res = sqlite3_step(infoStmt)) == SQLITE_ROW) {
+                       int count = sqlite3_column_int(infoStmt, 0);
+                       PG_LOGD("## count[%d]", count);
+//                     if (count == 0)
+//                             continue;
+                       p_data.count = count;
+                       packageInfoList.push_back(p_data);
+               }
+               sqlite3_reset(infoStmt);
        }
+
        m_dbMutex.unlock();
 
        return PRIV_GUARD_ERROR_SUCCESS;
index 637cb13..e2649bf 100755 (executable)
@@ -215,18 +215,18 @@ PrivacyInfoService::PgGetAllMonitorPolicy(SocketConnection* pConnector)
 }
 
 void
-PrivacyInfoService::PgForeachPackageByPrivacyId(SocketConnection* pConnector)
+PrivacyInfoService::PgForeachPackageInfoByPrivacyId(SocketConnection* pConnector)
 {
        int userId = 0;
        std::string privacyId;
-       std::list < std::string > packageList;
+       std::list < package_data_s > packageInfoList;
 
        pConnector->read(&userId, &privacyId);
 
-       int result = PrivacyGuardDb::getInstance()->PgForeachPackageByPrivacyId(userId, privacyId, packageList);
+       int result = PrivacyGuardDb::getInstance()->PgForeachPackageInfoByPrivacyId(userId, privacyId, packageInfoList);
 
        pConnector->write(result);
-       pConnector->write(packageList);
+       pConnector->write(packageInfoList);
 }
 
 void