remove useless APIs and added global app check code. 32/78732/3 submit/tizen/20160706.144108
authorKyoungyong Lee <bluevox@naver.com>
Wed, 6 Jul 2016 14:07:29 +0000 (23:07 +0900)
committerKyoungyong Lee <bluevox@naver.com>
Wed, 6 Jul 2016 14:34:27 +0000 (23:34 +0900)
Change-Id: I7b581c63fc36cd813a433386250a75c362dd2721

client/inc/PrivacyGuardClient.h
client/src/PrivacyGuardClient.cpp
client/src/privacy_guard_client.cpp
common/inc/PrivacyGuardTypes.h
server/inc/PrivacyInfoService.h
server/src/CynaraService.cpp
server/src/PrivacyGuardDb.cpp
server/src/service/PrivacyInfoService.cpp

index 6e08104..49ecdf2 100755 (executable)
@@ -54,10 +54,6 @@ public:
 
        int PgAddMonitorPolicyOffline(const int userId, const std::string packageId, const std::list < std::string > privacyList, bool monitorPolicy);
 
-       int PgAddPrivacyAccessLog(const int userId, const std::string packageId, const std::string privacyId);
-
-       int PgAddPrivacyAccessLogTest(const int userId, const std::string packageId, const std::string privacyId);
-
        int PgAddPrivacyAccessLogBeforeTerminate(void);
 
        int PgAddMonitorPolicy(const int userId, const std::string pkgId, const std::list < std::string >& list, int monitorPolicy);
index b6f3f38..f7d7b59 100755 (executable)
@@ -107,46 +107,6 @@ PrivacyGuardClient::PgAddMonitorPolicyOffline(const int userId, const std::strin
        return PRIV_GUARD_ERROR_SUCCESS;
 }
 
-
-int
-PrivacyGuardClient::PgAddPrivacyAccessLog(const int userId, const std::string packageId, const std::string privacyId)
-{
-       int result = PRIV_GUARD_ERROR_SUCCESS;
-       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(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, 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);
-               m_logInfoList.clear();
-       }
-
-       return result;
-}
-
-int
-PrivacyGuardClient::PgAddPrivacyAccessLogTest(const int userId, const std::string packageId, const std::string privacyId)
-{
-       int result = PRIV_GUARD_ERROR_SUCCESS;
-
-       int res = m_pSocketClient->connect();
-       TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "connect : %d", res);
-
-       res = m_pSocketClient->call("PgAddPrivacyAccessLogTest", userId, packageId, privacyId, &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);
-
-       return result;
-}
-
 int
 PrivacyGuardClient::PgAddPrivacyAccessLogBeforeTerminate(void)
 {
index 25c6e41..4831429 100755 (executable)
@@ -17,6 +17,7 @@
 #include <string.h>
 #include <string>
 #include <memory>
+#include <pkgmgr-info.h>
 #include "PrivacyChecker.h"
 #include "PrivacyGuardClient.h"
 #include "privacy_guard_client.h"
 #define TIZEN_PATH_MAX 1024
 #endif
 
-int privacy_guard_client_add_privacy_access_log(const int user_id, const char *package_id, const char *privilege_id)
-{
-       if (user_id < 0 || package_id == NULL || privilege_id == NULL) {
-               PG_LOGE("Invalid parameters.");
-               return PRIV_GUARD_ERROR_INVALID_PARAMETER;
-       }
-
-       int monitor_policy = 0;
-       std::string privacy_id;
-
-       PG_LOGD("user_id : %d, package_id : %s, privilege_id : %s", user_id, package_id, privilege_id);
-
-       int retval = PrivacyChecker::checkMonitorPolicyWithPrivilege(user_id, std::string(package_id), std::string(privilege_id), privacy_id, monitor_policy);
-       if (retval != PRIV_GUARD_ERROR_SUCCESS) {
-               PG_LOGE("Failed to do PrivacyChecker::checkMonitorPolicyWithPrivilege() [%d]", retval);
-               return retval;
-       }
-
-       if (monitor_policy == MONITOR_POLICY_ON) {
-               PrivacyGuardClient *pInst = PrivacyGuardClient::getInstance();
-               retval = pInst->PgAddPrivacyAccessLog(user_id, std::string(package_id), std::string(privacy_id));
-               if (retval != PRIV_GUARD_ERROR_SUCCESS) {
-                       PG_LOGE("Failed to do PrivacyChecker::checkMonitorPolicyWithPrivilege() [%d]", retval);
-                       return retval;
-               }
-       }
-
-       return PRIV_GUARD_ERROR_SUCCESS;
-}
-
 int privacy_guard_client_delete_all_logs_and_monitor_policy(void)
 {
        PrivacyGuardClient *pInst = PrivacyGuardClient::getInstance();
@@ -255,7 +226,7 @@ int privacy_guard_client_add_monitor_policy(const int user_id, const char *packa
 
     int retval = pInst->PgAddMonitorPolicy(user_id, std::string(package_id), privilegeList, monitor_policy);
        if (retval != PRIV_GUARD_ERROR_SUCCESS) {
-               PG_LOGE("Failed to do PrivacyGuardClient::PgAddMonitorPolicy() [%d]", retval); 
+               PG_LOGE("Failed to do PrivacyGuardClient::PgAddMonitorPolicy() [%d]", retval);
                return retval;
        }
 
@@ -269,11 +240,36 @@ int privacy_guard_client_update_monitor_policy(const int user_id, const char *pa
                return PRIV_GUARD_ERROR_INVALID_PARAMETER;
        }
 
-    PrivacyGuardClient *pInst = PrivacyGuardClient::getInstance();
+       PrivacyGuardClient *pInst = PrivacyGuardClient::getInstance();
+
+       pkgmgrinfo_pkginfo_h pkg_handle;
+       bool is_global = false;
+       int fixed_user_id = -1;
+
+       int retval = pkgmgrinfo_pkginfo_get_pkginfo(package_id, &pkg_handle);
+       if (retval != PMINFO_R_OK) {
+               PG_LOGE("Failed to do pkgmgrinfo_pkginfo_get_pkginfo [%d]", retval);
+               return retval;
+       }
+
+       retval = pkgmgrinfo_pkginfo_is_global(pkg_handle, &is_global);
+       if (retval != PMINFO_R_OK) {
+               PG_LOGE("Failed to do pkgmgrinfo_pkginfo_is_global [%d]", retval);
+               return retval;
+       }
+
+       pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
+
+       if (is_global == true) {
+               PG_LOGD("[%s] is global app.", package_id);
+               fixed_user_id = 0;
+       } else {
+               fixed_user_id = user_id;
+       }
 
-    int retval = pInst->PgUpdateMonitorPolicy(user_id, std::string(package_id), std::string(privacy_id), monitor_policy);
+    retval = pInst->PgUpdateMonitorPolicy(fixed_user_id, std::string(package_id), std::string(privacy_id), monitor_policy);
        if (retval != PRIV_GUARD_ERROR_SUCCESS) {
-               PG_LOGE("Failed to do PrivacyGuardClient::PgUpdateMonitorPolicy() [%d]", retval); 
+               PG_LOGE("Failed to do PrivacyGuardClient::PgUpdateMonitorPolicy() [%d]", retval);
                return retval;
        }
 
index bd7658e..8f1809f 100755 (executable)
@@ -26,7 +26,7 @@
 #define CYNARA_BUFFER_SIZE 100
 #define USER_APP_PREFIX "User::App::"
 #define USER_APP_PREFIX_LEN 11
-#define ROOT_USER_ID 0
+#define GLOBAL_APP_USER_ID 0
 
 typedef struct _privacy_data_s {
        char *privacy_id;
index af9b32e..4fc33c5 100755 (executable)
@@ -30,8 +30,6 @@ private:
 public:
        static void registerCallbacks(SocketService* pSocketService)
        {
-               pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgAddPrivacyAccessLog"), PgAddPrivacyAccessLog);
-               pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgAddPrivacyAccessLogTest"), PgAddPrivacyAccessLogTest);
                pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgAddMonitorPolicy"), PgAddMonitorPolicy);
                pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgDeleteAllLogsAndMonitorPolicy"), PgDeleteAllLogsAndMonitorPolicy);
                pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgDeleteLogsByPackageId"), PgDeleteLogsByPackageId);
@@ -52,8 +50,6 @@ public:
                pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgDeleteMainMonitorPolicyByUserId"), PgDeleteMainMonitorPolicyByUserId);
        }
 
-       static void PgAddPrivacyAccessLog(SocketConnection* pConnector);
-       static void PgAddPrivacyAccessLogTest(SocketConnection* pConnector);
        static void PgAddMonitorPolicy(SocketConnection* pConnector);
        static void PgDeleteAllLogsAndMonitorPolicy(SocketConnection* pConnector);
        static void PgDeleteLogsByPackageId(SocketConnection* pConnector);
index b036e2a..0716e4f 100755 (executable)
@@ -26,6 +26,7 @@
 #include <memory>
 #include <thread>
 #include <cynara-monitor.h>
+#include <pkgmgr-info.h>
 #include "PrivacyGuardTypes.h"
 #include "Utils.h"
 #include "CynaraService.h"
@@ -183,6 +184,9 @@ CynaraService::updateDb(cynara_monitor_entry **monitor_entries)
        time_t date;
        int res = -1;
 
+       pkgmgrinfo_pkginfo_h pkg_handle;
+       bool is_global = false;
+
        while (*entryIter != nullptr) {
                privilege = cynara_monitor_entry_get_privilege(*entryIter);
                TryReturn(privilege != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "Privilege Id in the entry is NULL");
@@ -216,6 +220,23 @@ CynaraService::updateDb(cynara_monitor_entry **monitor_entries)
                                PG_LOGD("Fixed Package ID: [%s]", client);
                        }
 
+                       // check this package is global app
+                       res = pkgmgrinfo_pkginfo_get_pkginfo(packageId.c_str(), &pkg_handle);
+                       if (res != PMINFO_R_OK) {
+                               PG_LOGE("Failed to do pkgmgrinfo_pkginfo_get_pkginfo [%d]", res);
+                       } else {
+                               res = pkgmgrinfo_pkginfo_is_global(pkg_handle, &is_global);
+                               if (res != PMINFO_R_OK) {
+                                       PG_LOGE("Failed to do pkgmgrinfo_pkginfo_is_global [%d]", res);
+                               } else {
+                                       if (is_global == true) {
+                                               PG_LOGD("[%s] is a global app. So set the user_id to 0.", packageId.c_str());
+                                               userId = GLOBAL_APP_USER_ID;
+                                       }
+                               }
+                               pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
+                       }
+
                        // datetime
                        date = timestamp->tv_sec;
 
index 6cdba2f..dd60f8b 100755 (executable)
@@ -866,8 +866,8 @@ int
 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, 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<=?");
+       static const std::string query = std::string("SELECT DISTINCT PKG_ID, MONITOR_POLICY FROM MonitorPolicy WHERE (USER_ID=? OR USER_ID=0) AND PRIVACY_ID=?");
+       static const std::string PKGINFO_SELECT = std::string("SELECT COUNT(*) FROM StatisticsMonitorInfo WHERE (USER_ID=? OR USER_ID=0) 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;
index e2649bf..df42777 100755 (executable)
 #include "Utils.h"
 
 void
-PrivacyInfoService::PgAddPrivacyAccessLog(SocketConnection* pConnector)
-{
-       int userId = 0;
-       std::list <std::pair<std::string, std::string>> logInfoList;
-
-       pConnector->read(&userId, &logInfoList);
-
-       int result = PrivacyGuardDb::getInstance()->PgAddPrivacyAccessLog(userId, logInfoList);
-
-       pConnector->write(result);
-}
-
-void
-PrivacyInfoService::PgAddPrivacyAccessLogTest(SocketConnection* pConnector)
-{
-       int userId = 0;
-       std::string packageId;
-       std::string privacyId;
-
-       pConnector->read(&userId, &packageId, &privacyId);
-
-       int result = PrivacyGuardDb::getInstance()->PgAddPrivacyAccessLogTest(userId, packageId, privacyId);
-
-       pConnector->write(result);
-}
-
-void
 PrivacyInfoService::PgAddMonitorPolicy(SocketConnection* pConnector)
 {
        int userId = 0;