ADD_SUBDIRECTORY(server)
ADD_SUBDIRECTORY(client)
ADD_SUBDIRECTORY(pkgmgr_plugin)
+ADD_SUBDIRECTORY(test)
ADD_DEFINITIONS("-Wall -Werror")
ADD_DEFINITIONS("-DDLOG_ERROR_ENABLED")
ADD_DEFINITIONS("-D_PRIVACY_GUARD_DEBUG")
-OPTION (FILTER_LISTED_PKG "FILTER PKG BY LIST" ON)
-IF(FILTER_LISTED_PKG)
- MESSAGE("FILTER PKGs BY FILTERING LIST")
- ADD_DEFINITIONS("-D__FILTER_LISTED_PKG")
-ENDIF(FILTER_LISTED_PKG)
-## SET PRIVACY_POPUP FLAG
-OPTION (PRIVACY_POPUP "PRIVACY_POPUP" ON)
-IF(PRIVACY_POPUP)
- MESSAGE("PRIVACY_POPUP IS ENABLED")
- ADD_DEFINITIONS("-D__PRIVACY_POPUP")
-ENDIF(PRIVACY_POPUP)
###################################################################################################
## for libprivacy-guard-client
${common_src_dir}/SocketConnection.cpp
${common_src_dir}/SocketStream.cpp
${common_src_dir}/PrivacyIdInfo.cpp
+ ${common_src_dir}/Utils.cpp
${client_src_dir}/SocketClient.cpp
${client_src_dir}/PrivacyChecker.cpp
${client_src_dir}/PrivacyGuardClient.cpp
static std::mutex m_singletonMutex;
- std::list <std::pair<std::string, std::string>> m_logInfoList;
-
PrivacyGuardClient();
~PrivacyGuardClient();
int PgAddMonitorPolicyOffline(const int userId, const std::string packageId, const std::list < std::string > privacyList, bool monitorPolicy);
- int PgAddPrivacyAccessLogBeforeTerminate(void);
+ int PgAddPrivacyAccessLog(const int userId, const std::string packageId, const std::string privacyId, const time_t accessTime);
+
+ int PgAddMonitorPolicy(const int userId, const std::string packageId, const std::list < std::string >& list, int monitorPolicy);
- int PgAddMonitorPolicy(const int userId, const std::string pkgId, const std::list < std::string >& list, int monitorPolicy);
+ int PgAddMonitorPolicy(const int userId, const std::string packageId, const std::string privacyId, int monitorPolicy);
- int PgDeleteAllLogsAndMonitorPolicy(void);
+ int PgDeleteAllLogs(void);
int PgDeleteLogsByPackageId(const std::string packageId);
int PgForeachPrivacyCountByPackageId(const int userId, const int startDate, const int endDate, const std::string packageId, std::list < std::pair <std::string, int > > & privacyInfoList) const;
- int PgForeachPrivacyPackageId(const int userId, std::list < std::string > & packageList) const;
+ int PgForeachPackageIdUsingPrivacy(const int userId, std::list < std::string > & packageList) const;
int PgForeachPackageInfoByPrivacyId(const int userId, const std::string privacyId, std::list < package_data_s > & packageList) const;
int PgUpdateMonitorPolicy(const int userId, const std::string packageId, const std::string privacyId, const int monitorPolicy);
- int PgGetMainMonitorPolicy(const int userId, bool &mainMonitorPolicy) const;
-
- int PgUpdateMainMonitorPolicy(const int userId, const bool mainMonitorPolicy);
+ int PgGetMainMonitorPolicy(const int userId, int &mainMonitorPolicy) const;
- int PgDeleteMainMonitorPolicyByUserId(const int userId);
+ int PgUpdateMainMonitorPolicy(const int userId, const int mainMonitorPolicy);
};
#endif // _PRIVACYGUARDCLIENT_H_
\ No newline at end of file
#ifndef _PRIVACY_GUARD_CLIENT_INTERNAL_H_
#define _PRIVACY_GUARD_CLIENT_INTERNAL_H_
-#include <time.h>
#include "privacy_guard_client_types.h"
#ifdef __cplusplus
* @param[in] user_id user ID
* @param[in] package_id package ID
* @param[in] privacy_id privacy ID [e.g. http://tizen.org/privacy/contact]
+ * @param[in] access_time access time for the privacy
* @return the result of operation (ERRORCODE : success, ....)
*/
-EXTERN_API int privacy_guard_client_add_privacy_access_log(const int user_id, const char *package_id, const char *privacy_id);
+EXTERN_API int privacy_guard_client_add_privacy_access_log(const int user_id, const char *package_id, const char *privacy_id, const time_t access_time);
/**
- * @fn int privacy_guard_client_delete_all_logs_and_monitor_policy(void)
- * @brief clear all data from StatisticsMonitor and MonitorPolicy DB
+ * @fn int privacy_guard_client_delete_all_logs(void)
+ * @brief clear all data from StatisticsMonitor DB
*/
-EXTERN_API int privacy_guard_client_delete_all_logs_and_monitor_policy(void);
+EXTERN_API int privacy_guard_client_delete_all_logs(void);
/**
- * @fn int privacy_guard_client_add_monitor_policy(const int user_id, const char *package_id, const char **privilege_list, const int monitor_policy)
+ * @fn int privacy_guard_client_add_monitor_policy(const int user_id, const char *package_id, const char *privacy_id, const int monitor_policy)
* @brief add monitor policy by user id and specified package to MonitorPolicy DB
* @param[in] user_id The user ID
* @param[in] package_id The package ID
- * @param[in] privilege_list The privilege list
+ * @param[in] privacy_id The privacy ID
* @param[in] monitor_policy The monitor policy (0 or 1)
*/
-EXTERN_API int privacy_guard_client_add_monitor_policy(const int user_id, const char *package_id, const char **privilege_list, const int monitor_policy);
+EXTERN_API int privacy_guard_client_add_monitor_policy(const int user_id, const char *package_id, const char *privacy_id, const int monitor_policy);
/**
* @fn int privacy_guard_client_delete_logs_by_package_id(const char *package_id)
*/
EXTERN_API int privacy_guard_client_delete_logs_by_package_id(const char *package_id);
-/**
- * @fn int privacy_guard_client_delete_monitor_policy_by_package_id(const char *package_id)
- * @brief remove statistics info by specified package from MonitorPolicy DB
- * @param[in] package_id The package ID
- */
-EXTERN_API int privacy_guard_client_delete_monitor_policy_by_package_id(const char *package_id);
-
#ifdef __cplusplus
}
#endif
#include "SocketClient.h"
#include "PrivacyIdInfo.h"
-//#define COUNT 10
-#define COUNT 1
-
#undef __READ_DB_IPC__
std::mutex PrivacyGuardClient::m_singletonMutex;
const std::string PrivacyGuardClient::INTERFACE_NAME("PrivacyInfoService");
PrivacyGuardClient::PrivacyGuardClient(void)
+ : m_sqlHandler(NULL)
+ , m_stmt(NULL)
+ , m_bDBOpen(false)
{
std::unique_ptr<SocketClient> pSocketClient(new SocketClient(INTERFACE_NAME));
m_pSocketClient = std::move(pSocketClient);
}
int
-PrivacyGuardClient::PgAddPrivacyAccessLogBeforeTerminate(void)
+PrivacyGuardClient::PgAddPrivacyAccessLog(const int userId, const std::string packageId, const std::string privacyId, const time_t accessTime)
{
int result = PRIV_GUARD_ERROR_SUCCESS;
- PG_LOGD("PgAddPrivacyAccessLogBeforeTerminate, m_logInfoList.size() : %d", m_logInfoList.size());
- if(m_logInfoList.size() > 0) {
- int res = m_pSocketClient->connect();
- TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "connect : %d", res);
+ int res = m_pSocketClient->connect();
+ TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "connect : %d", res);
- res = m_pSocketClient->call("PgAddPrivacyAccessLog", m_logInfoList, &result);
- TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
+ res = m_pSocketClient->call("PgAddPrivacyAccessLog", userId, packageId, privacyId, accessTime, &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();
- }
+ res = m_pSocketClient->disconnect();
+ TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "disconnect : %d", res);
return result;
}
int
-PrivacyGuardClient::PgAddMonitorPolicy(const int userId, const std::string pkgId, const std::list < std::string >& list, int monitorPolicy)
+PrivacyGuardClient::PgAddMonitorPolicy(const int userId, const std::string packageId, const std::list < std::string >& list, int monitorPolicy)
{
- PG_LOGD("userID: [%d], packageID[%s], monitorPolicy: [%d]", userId, pkgId.c_str(), monitorPolicy);
+ PG_LOGD("userID: [%d], packageID[%s], monitorPolicy: [%d]", userId, packageId.c_str(), monitorPolicy);
std::list < std::string > privacyList;
if (isServerOperation == true) {
int result = PRIV_GUARD_ERROR_SUCCESS;
- res = m_pSocketClient->call("PgAddMonitorPolicy", userId, pkgId, privacyList, monitorPolicy, &result);
+ res = m_pSocketClient->call("PgAddMonitorPolicy", userId, packageId, privacyList, monitorPolicy, &result);
TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
res = m_pSocketClient->disconnect();
return result;
} else {
- return PgAddMonitorPolicyOffline(userId, pkgId, privacyList, monitorPolicy);
+ return PgAddMonitorPolicyOffline(userId, packageId, privacyList, monitorPolicy);
}
}
int
+PrivacyGuardClient::PgAddMonitorPolicy(const int userId, const std::string packageId, const std::string privacyId, int monitorPolicy)
+{
+ PG_LOGD("userID: [%d], packageID[%s], privacyID[%s], monitorPolicy: [%d]", userId, packageId.c_str(), privacyId.c_str(), monitorPolicy);
+
+ std::list < std::string > privacyList;
+ privacyList.push_back(privacyId);
+
+ int res = m_pSocketClient->connect();
+ TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "connect : %d", res);
+
+ int result = PRIV_GUARD_ERROR_SUCCESS;
+ res = m_pSocketClient->call("PgAddMonitorPolicy", userId, packageId, privacyList, monitorPolicy, &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::PgDeleteAllLogsAndMonitorPolicy(void)
{
int result = PRIV_GUARD_ERROR_SUCCESS;
TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "disconnect : %d", res);
return result;
+}*/
+
+int
+PrivacyGuardClient::PgDeleteAllLogs(void)
+{
+ 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("PgDeleteAllLogs", &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
}
int
-PrivacyGuardClient::PgForeachPrivacyPackageId(const int userId, std::list < std::string > & packageList) const
+PrivacyGuardClient::PgForeachPackageIdUsingPrivacy(const int userId, std::list < std::string > & packageList) const
{
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("PgForeachPrivacyPackageId", userId, &result, &packageList);
+ res = m_pSocketClient->call("PgForeachPackageIdUsingPrivacy", userId, &result, &packageList);
TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
res = m_pSocketClient->disconnect();
}
int
-PrivacyGuardClient::PgGetMainMonitorPolicy(const int userId, bool &mainMonitorPolicy) const
+PrivacyGuardClient::PgGetMainMonitorPolicy(const int userId, int &mainMonitorPolicy) const
{
int result = PRIV_GUARD_ERROR_SUCCESS;
}
int
-PrivacyGuardClient::PgUpdateMainMonitorPolicy(const int userId, const bool mainMonitorPolicy)
+PrivacyGuardClient::PgUpdateMainMonitorPolicy(const int userId, const int mainMonitorPolicy)
{
int result = PRIV_GUARD_ERROR_SUCCESS;
return result;
}
-
-int
-PrivacyGuardClient::PgDeleteMainMonitorPolicyByUserId(const int userId)
-{
- 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("PgDeleteMainMonitorPolicyByUserId", userId, &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;
-}
} while(0)
SocketClient::SocketClient(const std::string& interfaceName)
+ : m_socketFd(-1)
{
m_interfaceName = interfaceName;
m_serverAddress = SERVER_ADDRESS;
#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_delete_all_logs_and_monitor_policy(void)
+/*int privacy_guard_client_delete_all_logs_and_monitor_policy(void)
{
PrivacyGuardClient *pInst = PrivacyGuardClient::getInstance();
}
return PRIV_GUARD_ERROR_SUCCESS;
-}
+}*/
-int privacy_guard_client_delete_logs_by_package_id(const char *package_id)
+int privacy_guard_client_delete_all_logs(void)
{
- if (package_id == NULL) {
- PG_LOGE("Invalid parameters. (package_id)");
- return PRIV_GUARD_ERROR_INVALID_PARAMETER;
- }
-
PrivacyGuardClient *pInst = PrivacyGuardClient::getInstance();
- int retval = pInst->PgDeleteLogsByPackageId(std::string(package_id));
+ int retval = pInst->PgDeleteAllLogs();
if (retval != PRIV_GUARD_ERROR_SUCCESS) {
- PG_LOGE("Failed to do PrivacyGuardClient::PgDeleteLogsByPackageId() [%d]", retval);
+ PG_LOGE("Failed to do PrivacyGuardClient::PgDeleteAllLogs() [%d]", retval);
return retval;
}
return PRIV_GUARD_ERROR_SUCCESS;
}
-int privacy_guard_client_delete_monitor_policy_by_package_id(const char *package_id)
+int privacy_guard_client_delete_logs_by_package_id(const char *package_id)
{
if (package_id == NULL) {
PG_LOGE("Invalid parameters. (package_id)");
PrivacyGuardClient *pInst = PrivacyGuardClient::getInstance();
- int retval = pInst->PgDeleteMonitorPolicyByPackageId(std::string(package_id));
+ int retval = pInst->PgDeleteLogsByPackageId(std::string(package_id));
if (retval != PRIV_GUARD_ERROR_SUCCESS) {
- PG_LOGE("Failed to do PrivacyGuardClient::PgDeleteMonitorPolicyByPackageId() [%d]", retval);
+ PG_LOGE("Failed to do PrivacyGuardClient::PgDeleteLogsByPackageId() [%d]", retval);
return retval;
}
return retval;
}
- if (list.size() == 0)
- return PRIV_GUARD_ERROR_NO_DATA;
-
for (std::list <std::pair <std::string, int>>::iterator iter = list.begin(); iter != list.end(); ++iter) {
//PG_LOGD("result > package_id : %s, count : %d", iter->first.c_str(), iter->second);
bool ret = callback(iter->first.c_str(), iter->second, user_data);
return retval;
}
- if (list.size() == 0)
- return PRIV_GUARD_ERROR_NO_DATA;
-
for (std::list <std::pair <std::string, int>>::iterator iter = list.begin(); iter != list.end(); ++iter) {
PG_LOGD("privacy_id: %s, count: %d", iter->first.c_str(), iter->second);
bool ret = callback(iter->first.c_str(), iter->second, user_data);
return retval;
}
- if (list.size() == 0)
- return PRIV_GUARD_ERROR_NO_DATA;
-
for (std::list <std::pair <std::string, int>>::iterator iter = list.begin(); iter != list.end(); ++iter) {
PG_LOGD("package_id: %s, count: %d", iter->first.c_str(), iter->second);
bool ret = callback(iter->first.c_str(), iter->second, user_data);
return retval;
}
- if (list.size() == 0)
- return PRIV_GUARD_ERROR_NO_DATA;
-
for (std::list <std::pair <std::string, int>>::iterator iter = list.begin(); iter != list.end(); ++iter) {
PG_LOGD("privacy_id: %s, count: %d", iter->first.c_str(), iter->second);
bool ret = callback(iter->first.c_str(), iter->second, user_data);
return retval;
}
-int privacy_guard_client_add_monitor_policy(const int user_id, const char *package_id, const char **privilege_list, const int monitor_policy)
-{
- 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;
- }
-
- PrivacyGuardClient *pInst = PrivacyGuardClient::getInstance();
- std::list < std::string > privilegeList;
-
- while (*privilege_list[0] != '\0') {
- PG_LOGD("Privilege in the list: %s", *privilege_list);
- privilegeList.push_back(std::string(*privilege_list++));
- }
-
- 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);
- return retval;
- }
-
- return PRIV_GUARD_ERROR_SUCCESS;
-}
-
int privacy_guard_client_update_monitor_policy(const int user_id, const char *package_id, const char *privacy_id, const int monitor_policy)
{
- if (user_id < 0 || package_id == NULL || privacy_id == NULL) {
- PG_LOGE("Invalid parameters.");
+ if (user_id < 0 || package_id == NULL || privacy_id == NULL || monitor_policy < 0) {
+ PG_LOGE("Invalid parameters. UserID[%d], PkgID[%s], PrivacyID[%s], Policy[%d]", user_id, package_id, privacy_id, monitor_policy);
return PRIV_GUARD_ERROR_INVALID_PARAMETER;
}
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;
- }
-
- retval = pInst->PgUpdateMonitorPolicy(fixed_user_id, std::string(package_id), std::string(privacy_id), monitor_policy);
+ int retval = pInst->PgUpdateMonitorPolicy(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);
return retval;
return retval;
}
- if (privacyInfoList.size() == 0)
- return PRIV_GUARD_ERROR_NO_DATA;
-
for (std::list <privacy_data_s>::iterator iter = privacyInfoList.begin(); iter != privacyInfoList.end(); ++iter) {
PG_LOGD("privacy_id: %s, monitor_policy: %d", iter->privacy_id, iter->monitor_policy);
bool ret = callback(iter->privacy_id, iter->monitor_policy, user_data);
return PRIV_GUARD_ERROR_SUCCESS;
}
-int privacy_guard_client_foreach_privacy_package_id(const int user_id, privacy_guard_client_package_id_cb callback, void *user_data)
+int privacy_guard_client_foreach_package_id_using_privacy(const int user_id, privacy_guard_client_package_id_cb callback, void *user_data)
{
if (user_id < 0) {
PG_LOGE("Invalid parameters. (user_id: %d)", user_id);
std::list < std::string > packageList;
- int retval = pInst->PgForeachPrivacyPackageId(user_id, packageList);
+ int retval = pInst->PgForeachPackageIdUsingPrivacy(user_id, packageList);
if (retval != PRIV_GUARD_ERROR_SUCCESS) {
PG_LOGE("Failed to do PrivacyGuardClient::PgForeachPrivacyPackageId(). [%d]", retval);
return retval;
}
- if (packageList.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);
return PRIV_GUARD_ERROR_INVALID_PARAMETER;
}
+// int res = Utils::PgCheckAccess();
+// if(res != PRIV_GUARD_ERROR_SUCCESS) {
+// PG_LOGE("PgCheckAccess() is failed. [%d]", res);
+// return res;
+// }
+
PrivacyGuardClient* pInst = PrivacyGuardClient::getInstance();
std::list <package_data_s> packageInfoList;
return retval;
}
- if (packageInfoList.size() == 0) {
- PG_LOGE("The size of package info list is 0.");
- return PRIV_GUARD_ERROR_NO_DATA;
- }
-
for (std::list < package_data_s >::iterator iter = packageInfoList.begin(); iter != packageInfoList.end(); ++iter) {
bool ret = callback(iter->package_id, iter->count, iter->time, iter->monitor_policy, user_data);
if (ret == false)
return PRIV_GUARD_ERROR_SUCCESS;
}
-int privacy_guard_client_update_main_monitor_policy(const int user_id, const bool main_monitor_policy)
+//////////////////////// INTERNAL APIs ////////////////////////////////////
+int privacy_guard_client_add_privacy_access_log(const int user_id, const char *package_id, const char *privacy_id, const time_t access_time)
{
- if (user_id < 0) {
- PG_LOGE("Invalid parameters. (user_id: %d)", user_id);
+ if (user_id < 0 || package_id == NULL || privacy_id == NULL || access_time < 0) {
+ PG_LOGE("Invalid parameters. [user_id: %d, package_id: %s, privacy_id: %s, time: %ld", user_id, package_id, privacy_id, access_time);
return PRIV_GUARD_ERROR_INVALID_PARAMETER;
}
- PrivacyGuardClient *pInst = PrivacyGuardClient::getInstance();
+ PrivacyGuardClient *pInst = PrivacyGuardClient::getInstance();
- int retval = pInst->PgUpdateMainMonitorPolicy(user_id, main_monitor_policy);
+ int retval = pInst->PgAddPrivacyAccessLog(user_id, package_id, privacy_id, access_time);
if (retval != PRIV_GUARD_ERROR_SUCCESS) {
- PG_LOGE("Failed to do PrivacyGuardClient::PgUpdateMainMonitorPolicy() [%d]", retval);
+ PG_LOGE("Failed to do PrivacyGuardClient::PgAddPrivacyAccessLog() [%d]", retval);
return retval;
}
- return PRIV_GUARD_ERROR_SUCCESS;
+ return PRIV_GUARD_ERROR_SUCCESS;
}
-int privacy_guard_client_get_main_monitor_policy(const int user_id, bool *main_monitor_policy)
+int privacy_guard_client_add_monitor_policy(const int user_id, const char *package_id, const char *privacy_id, const int monitor_policy)
{
- if (user_id < 0) {
- PG_LOGE("Invalid parameters. (user_id: %d)", user_id);
+ if (user_id < 0 || package_id == NULL || privacy_id == NULL || monitor_policy < 0 || monitor_policy > 1) {
+ PG_LOGE("Invalid parameters.");
return PRIV_GUARD_ERROR_INVALID_PARAMETER;
}
- PrivacyGuardClient* pInst = PrivacyGuardClient::getInstance();
+ PrivacyGuardClient *pInst = PrivacyGuardClient::getInstance();
- int retval = pInst->PgGetMainMonitorPolicy(user_id, *main_monitor_policy);
+ int retval = pInst->PgAddMonitorPolicy(user_id, package_id, privacy_id, monitor_policy);
if (retval != PRIV_GUARD_ERROR_SUCCESS) {
- PG_LOGE("Failed to do PrivacyGuardClient::PgGetMainMonitorPolicy(). [%d]", retval);
+ PG_LOGE("Failed to do PrivacyGuardClient::PgAddMonitorPolicy() [%d]", retval);
return retval;
}
- return PRIV_GUARD_ERROR_SUCCESS;
+ return PRIV_GUARD_ERROR_SUCCESS;
}
-int privacy_guard_client_delete_main_monitor_policy_by_user_id(const int user_id)
-{
- if (user_id < 0) {
- PG_LOGE("Invalid parameters. (user_id: %d)", user_id);
- return PRIV_GUARD_ERROR_INVALID_PARAMETER;
- }
-
- PrivacyGuardClient *pInst = PrivacyGuardClient::getInstance();
- int retval = pInst->PgDeleteMainMonitorPolicyByUserId(user_id);
- if (retval != PRIV_GUARD_ERROR_SUCCESS) {
- PG_LOGE("Failed to do PrivacyGuardClient::PgDeleteMainMonitorPolicyByUserId(). [%d]", retval);
- return retval;
- }
-
- return PRIV_GUARD_ERROR_SUCCESS;
-}
#include <tzplatform_config.h>
#include "privacy_guard_client_types.h"
-#define PRIVACY_DB_PATH tzplatform_mkpath(TZ_SYS_DB,".privacy_guard.db")
-
-#define CYNARA_BUFFER_SIZE 100
-#define USER_APP_PREFIX "User::App::"
-#define USER_APP_PREFIX_LEN 11
-#define USER_PKG_PREFIX "User::Pkg::"
-#define USER_PKG_PREFIX_LEN 11
-#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+#define PRIVACY_DB_PATH tzplatform_mkpath(TZ_SYS_DB,".privacy_guard.db")
+#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+#define LEN_PRIVACY_ID 128
+#define LEN_PACKAGE_ID 128
+#define CYNARA_BUFFER_SIZE 100
+#define DEFAULT_MONITOR_POLICY 0
typedef struct _privacy_data_s {
- char *privacy_id;
+ char privacy_id[LEN_PRIVACY_ID];
int monitor_policy;
} privacy_data_s;
typedef struct _package_data_s {
- char *package_id;
+ char package_id[LEN_PACKAGE_ID];
int count;
time_t time;
int monitor_policy;
} package_data_s;
+typedef struct _package_privacy_data_s {
+ char package_id[LEN_PACKAGE_ID];
+ char privacy_id[LEN_PRIVACY_ID];
+} package_privacy_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");
m_socketStream.readStream(length, pBuf);
TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res);
pBuf[length] = 0;
- out.privacy_id = strdup(pBuf);
+ memset(out.privacy_id, 0x0, LEN_PRIVACY_ID);
+ strncpy(out.privacy_id, pBuf, length + 1);
delete[] pBuf;
// monitor policy
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);
+ memset(out.package_id, 0x0, LEN_PACKAGE_ID);
+ strncpy(out.package_id, pBuf, length + 1);
delete[] pBuf;
// monitor policy
class Utils
{
public:
- static std::string toHash (std::string src);
+ static int PgCheckAccess(void);
};
#endif //_UTILS_H_
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);
- g_list_free(privacy_list);
+ g_list_free_full(privacy_list, g_free);
return PRIV_GUARD_ERROR_INTERNAL_ERROR;
}
//PG_LOGD("(privacy, privilege): (%s, %s)", privacy_id, privilege_id);
m_privilegeToPrivacyMap.insert(std::map< std::string, std::string >::value_type(std::string(privilege_id), std::string(privacy_id)));
}
+
+ g_list_free_full(privilege_list, g_free);
+ privilege_list = NULL;
}
- g_list_free(privacy_list);
- g_list_free(privilege_list);
+ g_list_free_full(privacy_list, g_free);
+ privacy_list = NULL;
m_isInitialized = true;
initialize();
}
+#if 0 // the below API "privilege_info_get_privacy_by_privilege" accesses DB on every call. This may degrade entire performance.
int ret;
-
char *privacy_id = NULL;
+
ret = privilege_info_get_privacy_by_privilege(privilege.c_str(), &privacy_id);
if (ret != PRVMGR_ERR_NONE) {
//PG_LOGE("Failed to do privilege_info_get_privacy_by_privilege [%d]", ret);
privacyId = privacy_id;
free(privacy_id);
+#else
+ std::map< std::string, std::string >::iterator iter = m_privilegeToPrivacyMap.find(privilege);
+ if (iter == m_privilegeToPrivacyMap.end()) {
+ //PG_LOGD("There is no matching privacy to privilege [%s]", privilege.c_str());
+ return PRIV_GUARD_ERROR_NO_DATA;
+ }
+
+ privacyId = iter->second;
+#endif
return PRIV_GUARD_ERROR_SUCCESS;
}
for (l = privacy_list; l != NULL; l = l->next) {
char *privacy_id = (char*)l->data;
- PG_LOGD("[kylee] privacy_id: %s", privacy_id);
+ PG_LOGD("privacy_id: %s", privacy_id);
privacyIdList.push_back(std::string(privacy_id));
}
+ g_list_free_full(privacy_list, g_free);
+ privacy_list = NULL;
+
return PRIV_GUARD_ERROR_SUCCESS;
}
*/
#include "Utils.h"
+#include "privacy_guard_client_types.h"
+#include <aul.h>
-std::string Utils::toHash(std::string src)
+const char pApprovedAppList[][64] = {
+ "org.tizen.privacy-setting",
+ "tc-privacy-guard"
+ };
+
+int Utils::PgCheckAccess(void)
{
- return src;
+ pid_t pid = getpid();
+ PG_LOGD("Process ID: %d", pid);
+
+ char appId[128] = {0, };
+
+ aul_app_get_appid_bypid_for_uid(pid, appId, sizeof(appId), getuid());
+ PG_LOGD("App ID: %s", appId);
+
+ bool isApprovedApp = false;
+ int len = sizeof(pApprovedAppList) / sizeof(pApprovedAppList[0]);
+
+ for(int i = 0; i < len; i++ ) {
+ if(strncmp(appId, pApprovedAppList[i], strlen(pApprovedAppList[i])) == 0) {
+ isApprovedApp = true;
+ }
+ }
+
+ if(isApprovedApp == false) {
+ PG_LOGE("Abnormal Access");
+ return PRIV_GUARD_ERROR_NOT_PERMITTED;
+ }
+ PG_LOGD("Normal Access");
+
+ return PRIV_GUARD_ERROR_SUCCESS;
}
\ No newline at end of file
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
#PROJECT(privacy-guard-client)
-SET(PF_INCLUDE_PATH ${PROJECT_SOURCE_DIR}/include)
+SET(PG_INCLUDE_PATH ${PROJECT_SOURCE_DIR}/include)
SET(PRIVACY_GUARD_CLIENT_HEADERS
- ${PF_INCLUDE_PATH}/privacy_guard_client.h
- ${PF_INCLUDE_PATH}/privacy_guard_client_types.h
+ ${PG_INCLUDE_PATH}/privacy_guard_client.h
+ ${PG_INCLUDE_PATH}/privacy_guard_client_types.h
)
INSTALL(FILES ${PRIVACY_GUARD_CLIENT_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/privacy_guard)
#ifndef _PRIVACY_GUARD_CLIENT_H_
#define _PRIVACY_GUARD_CLIENT_H_
-#include <time.h>
#include "privacy_guard_client_types.h"
#ifdef __cplusplus
* @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] time The latest access time
- * @param[in] monitor_policy The monitor policy (0 or 1)
+ * @param[in] package_id The package ID
+ * @param[in] count The privacy count
+ * @param[in] latest_access_time The latest access time
+ * @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 time_t time, const int monitor_policy, void *user_data);
-
+typedef bool (*privacy_guard_client_package_info_cb) (const char *package_id, const int count, const time_t latest_access_time, const int monitor_policy, void *user_data);
/**
* @brief Called when the reply of the privacy count request is delivered.
* @param[in] package_id The package ID
* @param[in] callback The callback function to invoke
*/
-EXTERN_API int privacy_guard_client_foreach_monitor_policy_by_package_id(const int user_id, const char *package_id,
- privacy_guard_client_monitor_policy_cb callback, void *user_data);
+EXTERN_API int privacy_guard_client_foreach_monitor_policy_by_package_id(const int user_id, const char *package_id, privacy_guard_client_monitor_policy_cb callback, void *user_data);
/**
* @fn int privacy_guard_client_check_privacy_package(const int user_id, const char *package_id, bool *is_privacy_package)
* @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_privacy_package_id(const int user_id, privacy_guard_client_package_id_cb callback, void *user_data);
+EXTERN_API int privacy_guard_client_foreach_package_id_using_privacy(const int user_id, privacy_guard_client_package_id_cb callback, void *user_data);
/**
- * @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)
+ * @fn int privacy_guard_client_foreach_package_info_by_privacy_id(const int user_id, const char *privacy_id, privacy_guard_client_package_id_cb callback, void *user_data)
* @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
*/
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)
- * @brief update main monitor policy
- * @param[in] user_id The user ID
- * @param[in] main_monitor_policy The main monitor policy (false or true) to be set
- */
-EXTERN_API int privacy_guard_client_update_main_monitor_policy(const int user_id, const bool main_monitor_policy);
-
-/**
- * @fn int privacy_guard_client_update_main_monitor_policy(const int user_id, const bool main_monitor_policy)
- * @brief get main monitor policy
- * @param[in] user_id The user ID
- * @param[out] main_monitor_policy The value of main monitor policy
- */
-EXTERN_API int privacy_guard_client_get_main_monitor_policy(const int user_id, bool *main_monitor_policy);
-
-/**
- * @fn int privacy_guard_client_update_main_monitor_policy(const int user_id, const bool main_monitor_policy)
- * @brief Delete main monitor policy
- * @param[in] user_id The user ID to be deleted
- */
-EXTERN_API int privacy_guard_client_delete_main_monitor_policy_by_user_id(const int user_id);
#ifdef __cplusplus
}
#endif
-
#endif //_PRIVACY_GUARD_CLIENT_H_
#ifndef _PRIVACY_GUARD_CLIENT_TYPES_H_
#define _PRIVACY_GUARD_CLIENT_TYPES_H_
+#include <time.h>
+#include <stdbool.h>
+
#ifdef __cplusplus
extern "C" {
#endif
PRIV_GUARD_ERROR_SYSTEM_ERROR = -18,
PRIV_GUARD_ERROR_USER_NOT_CONSENTED = -19,
PRIV_GUARD_ERROR_INTERNAL_ERROR = -20,
+ PRIV_GUARD_ERROR_NOT_PERMITTED = -21,
PRIV_GUARD_ERROR_UNKNOWN = -(0x99),
};
-
#ifdef __cplusplus
}
#endif
Name: privacy-guard-server
-Version: 0.0.5
+Version: 0.5.0
Release: 1
License: Apache-2.0
Summary: Privacy Management
BuildRequires: pkgconfig(cynara-monitor)
BuildRequires: pkgconfig(pkgmgr-installer)
BuildRequires: pkgconfig(security-manager)
+BuildRequires: pkgconfig(aul)
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
privacy-guard server devel
%package -n privacy-guard-client
-Summary: Privacy Guard client
+Summary: Privacy Guard Client
Requires: privacy-guard-server = %{version}
%description -n privacy-guard-client
%description -n privacy-guard-client-devel
Privacy Management(development files)
+%package -n tc-privacy-guard
+Summary: Test Case for Privacy Guard
+
+%description -n tc-privacy-guard
+test cases for privacy-guard package
%prep
%setup -q
/usr/sbin/setcap cap_chown,cap_dac_override,cap_lease+eip /usr/bin/privacy-guard-server
-
%files -n privacy-guard-server
%defattr(-,root,root,-)
%license LICENSE.APLv2
%manifest privacy-guard-client-devel.manifest
%{_includedir}/*
%{_libdir}/pkgconfig/privacy-guard-client.pc
+
+%files -n tc-privacy-guard
+%{_bindir}/tc-privacy-guard
\ No newline at end of file
#include "PrivacyGuardClient.h"
#include <pkgmgr_installer_info.h>
-#define DEFAULT_MONITOR_POLICY 0
-
-//static const xmlChar _NODE_PRIVILEGES[] = "privileges";
static const xmlChar _NODE_PRIVILEGE[] = "privilege";
void destroy_char_list(char** ppList, int size)
LOGD("PKGMGR_PARSER_PLUGIN_INSTALL() called with [%s].", packageId);
uid_t user_id;
- if (pkgmgr_installer_info_get_target_uid(&user_id) < 0) {
- LOGE("Failed to get target user id");
- }
+ pkgmgr_installer_info_get_target_uid(&user_id);
LOGD("user_id is %d.", user_id);
int ret = 0;
curPtr = curPtr->next;
}
- char **ppPrivilegeList = (char**) calloc(privilegeList.size() + 1, sizeof(char*));
+ char **ppPrivilegeList = (char**)calloc(privilegeList.size() + 1, sizeof(char*));
char **temp = ppPrivilegeList;
std::list <std::string>::iterator iter = privilegeList.begin();
for (size_t i = 0; i < privilegeList.size(); ++i) {
memcpy(ppPrivilegeList[privilegeList.size()], "\0", 1);
PrivacyGuardClient *pInst = PrivacyGuardClient::getInstance();
- std::list < std::string > privilege_List;
+ std::list < std::string > privilege_list;
while (*ppPrivilegeList[0] != '\0') {
LOGD("privilege in the List: %s", *ppPrivilegeList);
- privilege_List.push_back(std::string(*ppPrivilegeList++));
+ privilege_list.push_back(std::string(*ppPrivilegeList++));
}
int monitor_policy = DEFAULT_MONITOR_POLICY;
- ret = pInst->PgAddMonitorPolicy(user_id, std::string(packageId), privilege_List, monitor_policy);
+ ret = pInst->PgAddMonitorPolicy(user_id, std::string(packageId), privilege_list, monitor_policy);
if (ret != PRIV_GUARD_ERROR_SUCCESS) {
- LOGE("Failed to add monitor policy: [%d]", ret);
-// return -EIO;
-// return 0;
+ LOGE("Failed to add monitor policy for user [%d]. Error code: [%d]", user_id, ret);
+ } else {
+ // in case of GLOBAL USER (376), add policy for owner (5001) additionally.
+ if (user_id == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) { // global app (376)
+ uid_t owner_user_id = tzplatform_getuid(TZ_SYS_DEFAULT_USER); // owner (5001)
+ ret = pInst->PgAddMonitorPolicy(owner_user_id, std::string(packageId), privilege_list, monitor_policy);
+ if (ret != PRIV_GUARD_ERROR_SUCCESS) {
+ LOGE("Failed to add monitor policy for user [%d]. Error code: [%d]", owner_user_id, ret);
+ }
+ }
}
if (temp)
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 security-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)
+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 security-manager aul)
FOREACH(flag ${pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ADD_DEFINITIONS("-Wall -Werror")
ADD_DEFINITIONS("-DDLOG_ERROR_ENABLED")
ADD_DEFINITIONS("-D_PRIVACY_GUARD_DEBUG")
-OPTION (FILTER_LISTED_PKG "FILTER PKG BY LIST" ON)
-IF(FILTER_LISTED_PKG)
- MESSAGE("FILTER PKGs BY FILTERING LIST")
- ADD_DEFINITIONS("-D__FILTER_LISTED_PKG")
-ENDIF(FILTER_LISTED_PKG)
###################################################################################################
## for privacy-guard-server (executable)
${server_src_dir}/CynaraService.cpp
${server_src_dir}/PrivacyGuardDaemon.cpp
${server_src_dir}/service/PrivacyInfoService.cpp
- ${server_src_dir}/NotificationServer.cpp
)
SET(PRIVACY_GUARD_SERVER_LDFLAGS " -module -avoid-version ")
SET(PRIVACY_GUARD_SERVER_CFLAGS " ${CFLAGS} -fPIE ")
INSTALL(TARGETS privacy-guard-server DESTINATION /usr/bin COMPONENT RuntimeLibraries)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/privacy-guard-server.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-#INSTALL(FILES ${PRIVACY_GUARD_SERVER_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/privacy_guard/server)
+++ /dev/null
-/*
- * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _NOTIFICATIONSERVER_H_
-#define _NOTIFICATIONSERVER_H_
-
-#include <string>
-#include <memory>
-#include <list>
-#include <sqlite3.h>
-#include <mutex>
-#include <dbus/dbus.h>
-
-class NotificationServer
-{
-private:
- bool m_initialized;
- DBusConnection* m_pDBusConnection;
-public:
-
- NotificationServer(void);
- ~NotificationServer(void);
- int initialize(void);
- int notifySettingChanged(const std::string pkgId, const std::string privacyId);
- int notifyPkgRemoved(const std::string pkgId);
-};
-
-
-#endif // _NOTIFICATIONSERVER_H_
\ No newline at end of file
static std::mutex m_singletonMutex;
static PrivacyGuardDb* m_pInstance;
static GList *m_privacy_list;
+ static GList *m_prepared_user_id_list;
bool m_bInitialized;
private:
PrivacyGuardDb(void);
void initialize(void);
+ int prepareGlobalPackagePolicy(const int userId);
~PrivacyGuardDb(void);
public:
virtual void openSqliteDB(void);
- int PgAddPrivacyAccessLogForCynara(const int userId, const std::string packageId, const std::string privacyId, const time_t timestamp);
+ int PgAddPrivacyAccessLog(const int userId, const std::string packageId, const std::string privacyId, const time_t timestamp);
int PgAddMonitorPolicy(const int userId, const std::string packageId, const std::list < std::string > privacyList, bool monitorPolicy);
+ int PgAddMonitorPolicy(const int userId, const std::string packageId, const std::string privacyId, bool monitorPolicy);
+
int PgCheckPrivacyPackage(const int userId, const std::string packageId, bool &isPrivacyPackage);
int PgDeleteAllLogsAndMonitorPolicy(void);
+ int PgDeleteAllLogs(void);
+
int PgDeleteLogsByPackageId(const std::string packageId);
int PgDeleteMonitorPolicyByPackageId(const std::string packageId);
- int PgForeachTotalPrivacyCountOfPackage(const int userId, const int startDate, const int endDate,
- std::list < std::pair < std::string, int > >& packageInfoList);
+ int PgForeachTotalPrivacyCountOfPackage(const int userId, const int startDate, const int endDate, std::list < std::pair < std::string, int > >& packageInfoList);
- int PgForeachTotalPrivacyCountOfPrivacy(const int userId, const int startDate, const int endDate,
- std::list < std::pair < std::string, int > >& privacyInfoList);
+ int PgForeachTotalPrivacyCountOfPrivacy(const int userId, const int startDate, const int endDate, std::list < std::pair < std::string, int > >& privacyInfoList);
- int PgForeachPrivacyCountByPrivacyId(const int userId, const int startDate, const int endDate,
- const std::string privacyId, std::list < std::pair < std::string, int > >& packageInfoList);
+ int PgForeachPrivacyCountByPrivacyId(const int userId, const int startDate, const int endDate, const std::string privacyId, std::list < std::pair < std::string, int > >& packageInfoList);
- int PgForeachPrivacyCountByPackageId(const int userId, const int startDate, const int endDate,
- const std::string packageId, std::list < std::pair < std::string, int > >& privacyInfoList);
+ int PgForeachPrivacyCountByPackageId(const int userId, const int startDate, const int endDate, const std::string packageId, std::list < std::pair < std::string, int > >& privacyInfoList);
- int PgGetMonitorPolicy(const int userId, const std::string packageId, const std::string privacyId, int& monitorPolicy);
+ int PgGetMonitorPolicy(const int userId, const std::string packageId, const std::string privacyId, int &monitorPolicy);
int PgGetAllMonitorPolicy(std::list < std::pair < std::string, int > >& monitorPolicyList);
int PgForeachMonitorPolicyByPackageId(const int userId, const std::string packageId, std::list <privacy_data_s>& privacyInfoList);
- int PgForeachPrivacyPackageId(const int userId, std::list < std::string > & packageList);
+ int PgForeachPackageIdUsingPrivacy(const int userId, std::list < std::string > & packageList);
int PgForeachPackageInfoByPrivacyId(const int userId, const std::string privacyId, std::list < package_data_s > &packageList);
int PgAddMainMonitorPolicy(const int userId);
- int PgUpdateMainMonitorPolicy(const int userId, const bool mainMonitorPolicy);
+ int PgUpdateMainMonitorPolicy(const int userId, const int mainMonitorPolicy);
- int PgGetMainMonitorPolicy(const int userId, bool &mainMonitorPolicy);
+ int PgGetMainMonitorPolicy(const int userId, int &mainMonitorPolicy);
int PgDeleteMainMonitorPolicyByUserId(const int userId);
};
public:
static void registerCallbacks(SocketService* pSocketService)
{
+ pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgAddPrivacyAccessLog"), PgAddPrivacyAccessLog);
pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgAddMonitorPolicy"), PgAddMonitorPolicy);
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgDeleteAllLogsAndMonitorPolicy"), PgDeleteAllLogsAndMonitorPolicy);
+ //pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgDeleteAllLogsAndMonitorPolicy"), PgDeleteAllLogsAndMonitorPolicy);
pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgDeleteLogsByPackageId"), PgDeleteLogsByPackageId);
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgDeleteMonitorPolicyByPackageId"), PgDeleteMonitorPolicyByPackageId);
+ //pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgDeleteMonitorPolicyByPackageId"), PgDeleteMonitorPolicyByPackageId);
pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgForeachTotalPrivacyCountOfPackage"), PgForeachTotalPrivacyCountOfPackage);
pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgForeachTotalPrivacyCountOfPrivacy"), PgForeachTotalPrivacyCountOfPrivacy);
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("PgForeachPackageIdUsingPrivacy"), PgForeachPackageIdUsingPrivacy);
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("PgUpdateMonitorPolicy"), PgUpdateMonitorPolicy);
pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgGetMainMonitorPolicy"), PgGetMainMonitorPolicy);
pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgUpdateMainMonitorPolicy"), PgUpdateMainMonitorPolicy);
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgDeleteMainMonitorPolicyByUserId"), PgDeleteMainMonitorPolicyByUserId);
+ pSocketService->registerServiceCallback(getInterfaceName(), std::string("PgDeleteAllLogs"), PgDeleteAllLogs);
}
+ static void PgAddPrivacyAccessLog(SocketConnection* pConnector);
static void PgAddMonitorPolicy(SocketConnection* pConnector);
- static void PgDeleteAllLogsAndMonitorPolicy(SocketConnection* pConnector);
+ //static void PgDeleteAllLogsAndMonitorPolicy(SocketConnection* pConnector);
static void PgDeleteLogsByPackageId(SocketConnection* pConnector);
- static void PgDeleteMonitorPolicyByPackageId(SocketConnection* pConnector);
+ //static void PgDeleteMonitorPolicyByPackageId(SocketConnection* pConnector);
static void PgForeachTotalPrivacyCountOfPackage(SocketConnection* pConnector);
static void PgForeachTotalPrivacyCountOfPrivacy(SocketConnection* pConnector);
static void PgForeachPrivacyCountByPrivacyId(SocketConnection* pConnector);
static void PgForeachPrivacyCountByPackageId(SocketConnection* pConnector);
- static void PgForeachPrivacyPackageId(SocketConnection* pConnector);
+ static void PgForeachPackageIdUsingPrivacy(SocketConnection* pConnector);
static void PgForeachPackageInfoByPrivacyId(SocketConnection* pConnector);
static void PgForeachMonitorPolicyByPackageId(SocketConnection* pConnector);
static void PgGetMonitorPolicy(SocketConnection* pConnector);
static void PgUpdateMonitorPolicy(SocketConnection* pConnector);
static void PgGetMainMonitorPolicy(SocketConnection* pConnector);
static void PgUpdateMainMonitorPolicy(SocketConnection* pConnector);
- static void PgDeleteMainMonitorPolicyByUserId(SocketConnection* pConnector);
+ static void PgDeleteAllLogs(SocketConnection* pConnector);
};
#endif // _PRIVACYINFOSERVICE_H_
\ No newline at end of file
#include <memory>
#include <thread>
#include <cynara-monitor.h>
-#include <pkgmgr-info.h>
#include <security-manager.h>
#include "PrivacyGuardTypes.h"
#include "PrivacyGuardDb.h"
#include "PrivacyIdInfo.h"
-#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
-
#define BUF_SIZE 256
#define ONE_SEC (SLEEP_TIME * 20)
int
CynaraService::initialize(void)
{
- PG_LOGD("initializing CynaraService..");
+ //PG_LOGD("initializing CynaraService..");
int res = cynara_monitor_configuration_create(&p_conf);
if(res != CYNARA_API_SUCCESS){
return PRIV_GUARD_ERROR_SYSTEM_ERROR;
}
-// cynara_monitor_configuration_set_filter
+ // cynara_monitor_configuration_set_filter
- PG_LOGI("CynaraService initialized");
+ //PG_LOGI("CynaraService initialized");
return PRIV_GUARD_ERROR_SUCCESS;
}
int
CynaraService::start(void)
{
- PG_LOGI("starting CynaraService..");
+ //PG_LOGI("starting CynaraService..");
int res = 0;
char buf[256];
#endif
pthread_t cynaraThread;
- PG_LOGD("starting new thread (getEntriesThread)");
+ //PG_LOGD("starting new thread (getEntriesThread)");
res = pthread_create(&cynaraThread, NULL, &getEntriesThread, this);
TryReturn( res >= 0, PRIV_GUARD_ERROR_SYSTEM_ERROR, errno = res, "pthread_create : %s", strerror_r(errno, buf, sizeof(buf)));
- PG_LOGD("new thread (getEntriesThread) started");
+ //PG_LOGD("new thread (getEntriesThread) started");
m_cynaraThread = cynaraThread;
exit_flag = false;
- PG_LOGD("CynaraService started");
+ //PG_LOGD("CynaraService started");
return PRIV_GUARD_ERROR_SUCCESS;
}
void*
CynaraService::getEntriesThread(void* pData)
{
- PG_LOGD("Running get entries thread");
+ //PG_LOGD("Running get entries thread");
int res = -1;
const char *user = NULL, *client = NULL, *privilege = NULL;
const timespec *timestamp = NULL;
uid_t user_id;
- std::string privacyId;//appId, packageId;
+ std::string privacyId;
time_t date;
int res = -1;
- pkgmgrinfo_pkginfo_h pkg_handle;
- bool is_global = false;
char *pkg_name = NULL, *app_name = NULL;
while (*entryIter != nullptr) {
res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId);
//PG_LOGD("########## res: [%d] privilege: [%s] privacy: [%s]", res, privilege, privacyId.c_str());
if (res != PRIV_GUARD_ERROR_NO_DATA) {
- PG_LOGD("#Privilege: [%s]", privilege);
- PG_LOGD("#Privacy : [%s]", privacyId.c_str());
+ //PG_LOGD("#Privilege: [%s]", privilege);
+ //PG_LOGD("#Privacy : [%s]", privacyId.c_str());
// User ID - string
user = cynara_monitor_entry_get_user(*entryIter);
// App ID - string
client = cynara_monitor_entry_get_client(*entryIter);
- //PG_LOGD("client: [%s]", client);
TryReturn(client != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "App Id in the entry is NULL");
// timestamp
// get pkgname from cynara-style app ID
res = security_manager_identify_app_from_cynara_client(client, &pkg_name, &app_name);
if (res != SECURITY_MANAGER_SUCCESS) {
- PG_LOGD("Failed to do security_manager_identify_app_from_cynara_client [%d]", res);
- PG_LOGD("So use [%s] as a package name instead.", client);
+ //PG_LOGD("Failed to do security_manager_identify_app_from_cynara_client [%d]", res);
+ //PG_LOGD("So use [%s] as a package name instead.", client);
pkg_name = strdup(client);
- } else {
- PG_LOGD("#Package : [%s]", pkg_name);
- // check this package is global app
- if (user_id == GLOBAL_USER) {
- res = pkgmgrinfo_pkginfo_get_pkginfo(pkg_name, &pkg_handle);
- } else {
- res = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkg_name, user_id, &pkg_handle);
- }
- if (res != PMINFO_R_OK) {
- PG_LOGE("Failed to do pkgmgrinfo_pkginfo_get_pkginfo or pkgmgrinfo_pkginfo_get_usr_pkginfo [%d] for the package [%s] with user [%d]", res, pkg_name, user_id);
- } 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) {
- user_id = GLOBAL_USER;
- }
- }
- pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
- }
}
// datetime
date = timestamp->tv_sec;
// add access log
- PG_LOGD("Insert [%s, %s] to DB.", pkg_name, privacyId.c_str());
- int ret = PrivacyGuardDb::getInstance()->PgAddPrivacyAccessLogForCynara(user_id, pkg_name, privacyId, date);
+ PG_LOGD("Try to insert [%d, %s, %s] to DB.", user_id, pkg_name, privacyId.c_str());
+ int ret = PrivacyGuardDb::getInstance()->PgAddPrivacyAccessLog(user_id, pkg_name, privacyId, date);
if(ret != PRIV_GUARD_ERROR_SUCCESS){
PG_LOGE("Failed to add access log to DB. UserID:[%d], PackageID:[%s], Privacy:[%s]", user_id, pkg_name, privacyId.c_str());
}
// deallocation
if (pkg_name) {
//PG_LOGD("freeing a pkg_name: [%s].", pkg_name);
- free(pkg_name);
+ SAFE_FREE(pkg_name);
}
if (app_name) {
//PG_LOGD("freeing an app_name: [%s].", app_name);
- free(app_name);
+ SAFE_FREE(app_name);
}
}
++entryIter;
+++ /dev/null
-/*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include "NotificationServer.h"
-#include "PrivacyGuardTypes.h"
-#include "Utils.h"
-
-auto DBusConnectionDeleter = [&](DBusConnection* pPtr) { dbus_connection_close(pPtr); pPtr = NULL;};
-const int MAX_LOCAL_BUF_SIZE = 128;
-
-NotificationServer::NotificationServer(void)
- : m_initialized(false)
- , m_pDBusConnection(NULL)
-{
-
-}
-
-NotificationServer::~NotificationServer(void)
-{
- if (m_pDBusConnection)
- {
- dbus_connection_close(m_pDBusConnection);
- m_pDBusConnection = NULL;
- }
-}
-
-int
-NotificationServer::initialize(void)
-{
- if (m_initialized)
- return PRIV_GUARD_ERROR_SUCCESS;
-
- DBusError error;
- dbus_error_init(&error);
-
- m_pDBusConnection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
- TryReturn(m_pDBusConnection != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_get_private : %s", error.message);
-
- dbus_connection_setup_with_g_main(m_pDBusConnection, NULL);
- std::unique_ptr < char[] > pRule(new char[MAX_LOCAL_BUF_SIZE]);
-
- snprintf(pRule.get(), MAX_LOCAL_BUF_SIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str());
-
- dbus_bus_add_match(m_pDBusConnection, pRule.get(), &error);
- TryReturn(!dbus_error_is_set(&error), PRIV_GUARD_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_add_match : %s", error.message);
-
- m_initialized = true;
-
- return PRIV_GUARD_ERROR_SUCCESS;
-}
-
-int
-NotificationServer::notifySettingChanged(const std::string pkgId, const std::string privacyId)
-{
- if (!m_initialized)
- return PRIV_GUARD_ERROR_INVALID_STATE;
-
- char* pPkgId = const_cast <char*> (pkgId.c_str());
- char* pPrivacyId = const_cast <char*> (privacyId.c_str());
-
- DBusMessage* pMessage = dbus_message_new_signal(DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_SETTING_CHANGED.c_str());
- TryReturn(pMessage != NULL, PRIV_GUARD_ERROR_IPC_ERROR, , "dbus_message_new_signal");
-
- dbus_bool_t r;
- r = dbus_message_append_args(pMessage,
- DBUS_TYPE_STRING, &pPkgId,
- DBUS_TYPE_STRING, &pPrivacyId,
- DBUS_TYPE_INVALID);
- TryReturn(r, PRIV_GUARD_ERROR_IPC_ERROR, , "dbus_message_append_args");
-
- r = dbus_connection_send(m_pDBusConnection, pMessage, NULL);
- TryReturn(r, PRIV_GUARD_ERROR_IPC_ERROR, dbus_message_unref(pMessage);, "dbus_connection_send");
-
- dbus_connection_flush(m_pDBusConnection);
- dbus_message_unref(pMessage);
-
- return PRIV_GUARD_ERROR_SUCCESS;
-}
-
-int
-NotificationServer::notifyPkgRemoved(const std::string pkgId)
-{
- if (!m_initialized)
- return PRIV_GUARD_ERROR_INVALID_STATE;
-
- char* pPkgId = const_cast <char*> (pkgId.c_str());
-
- DBusMessage* pMessage = dbus_message_new_signal(DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_PKG_REMOVED.c_str());
- TryReturn(pMessage != NULL, PRIV_GUARD_ERROR_IPC_ERROR, , "dbus_message_new_signal");
-
- dbus_bool_t r;
- r = dbus_message_append_args(pMessage,
- DBUS_TYPE_STRING, &pPkgId,
- DBUS_TYPE_INVALID);
- TryReturn(r, PRIV_GUARD_ERROR_IPC_ERROR, , "dbus_message_append_args");
-
- r = dbus_connection_send(m_pDBusConnection, pMessage, NULL);
- TryReturn(r, PRIV_GUARD_ERROR_IPC_ERROR, dbus_message_unref(pMessage);, "dbus_connection_send");
-
- dbus_connection_flush(m_pDBusConnection);
- dbus_message_unref(pMessage);
-
- return PRIV_GUARD_ERROR_SUCCESS;
-}
PrivacyGuardDaemon::PrivacyGuardDaemon(void)
: pSocketService(NULL)
+ , pCynaraService(NULL)
{
}
#include <sstream>
#include <fstream>
#include <sqlite3.h>
-#include <time.h>
#include <privilege_info.h>
#include <cynara-monitor.h>
#include "Utils.h"
#include "PrivacyGuardDb.h"
#include "PrivacyIdInfo.h"
-
#define PRIVACY_GUARD_DAYS 7
#define UNIX_TIME_ONE_DAY (24 * 60 * 60) // 86400 secs
#define BUF_SIZE 256
std::mutex PrivacyGuardDb::m_singletonMutex;
PrivacyGuardDb* PrivacyGuardDb::m_pInstance = NULL;
GList *PrivacyGuardDb::m_privacy_list = NULL;
+GList *PrivacyGuardDb::m_prepared_user_id_list = NULL;
static cynara_monitor_configuration *p_conf;
static cynara_monitor *p_cynara_monitor;
res = cynara_monitor_configuration_create(&p_conf);
if(res != CYNARA_API_SUCCESS){
PG_LOGE("cynara_monitor_configuration_create() is failed.");
- //return PRIV_GUARD_ERROR_SYSTEM_ERROR;
+ g_list_free_full(m_privacy_list, g_free);
+ m_privacy_list = NULL;
return;
}
res = cynara_monitor_initialize(&p_cynara_monitor, p_conf);
if(res != CYNARA_API_SUCCESS){
PG_LOGE("cynara_monitor_initialize() is failed.");
- //return PRIV_GUARD_ERROR_SYSTEM_ERROR;
+ g_list_free_full(m_privacy_list, g_free);
+ m_privacy_list = NULL;
+ cynara_monitor_configuration_destroy(p_conf);
return;
}
+ cynara_monitor_configuration_destroy(p_conf);
+
m_bInitialized = true;
}
}
int
-PrivacyGuardDb::PgAddPrivacyAccessLogForCynara(const int userId, const std::string packageId, const std::string privacyId, const time_t date)
+PrivacyGuardDb::PgAddPrivacyAccessLog(const int userId, const std::string packageId, const std::string privacyId, const time_t date)
{
if(userId < 0 || date <= 0) {
PG_LOGE("Invalid parameter: userId: [%d], date: [%d]", userId, date);
res = PgGetMonitorPolicy(userId, packageId, privacyId, monitorPolicy);
TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "PgGetMonitorPolicy is failed: [%d]", res);
if (monitorPolicy == 0) {
- //PG_LOGD("Monitor Policy is 0. So skip it. UserId:[%d], PrivacyId:[%s], PackageId:[%s], Policy:[%d]", userId, privacyId.c_str(), packageId.c_str(), monitorPolicy);
+ PG_LOGD("Monitor Policy is 0. So skip it. UserId:[%d], PrivacyId:[%s], PackageId:[%s], Policy:[%d]", userId, privacyId.c_str(), packageId.c_str(), monitorPolicy);
return PRIV_GUARD_ERROR_SUCCESS;
}
+ //PG_LOGD("Monitor Policy is 1. So write it. UserId:[%d], PrivacyId:[%s], PackageId:[%s], Policy:[%d]", userId, privacyId.c_str(), packageId.c_str(), monitorPolicy);
static const std::string QUERY_INSERT = std::string("INSERT INTO StatisticsMonitorInfo(USER_ID, PKG_ID, PRIVACY_ID, USE_DATE) VALUES(?, ?, ?, ?)");
res = sqlite3_step(m_stmt);
TryCatchResLogReturn(res == SQLITE_DONE, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_step : %d", res);
- sqlite3_reset(m_stmt);
+ sqlite3_finalize(m_stmt);
m_dbMutex.unlock();
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("User ID: [%d], Package ID: [%s], PrivacyID: [%s], Monitor Policy: [%d]", userId, packageId.c_str(), iter->c_str(), monitorPolicy);
+ //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);
sqlite3_reset(m_stmt);
}
+
+ sqlite3_finalize(m_stmt);
+
+ m_dbMutex.unlock();
+
+ return PRIV_GUARD_ERROR_SUCCESS;
+}
+
+int
+PrivacyGuardDb::PgAddMonitorPolicy(const int userId, const std::string packageId, const std::string privacyId, bool monitorPolicy)
+{
+ int res = -1;
+
+ static const std::string QUERY_INSERT = std::string("INSERT INTO MonitorPolicy(USER_ID, PKG_ID, PRIVACY_ID, MONITOR_POLICY) VALUES(?, ?, ?, ?)");
+
+ m_dbMutex.lock();
+
+ // initialize
+ if (m_bInitialized == false) {
+ initialize();
+ }
+ TryCatchResLogReturn(m_bInitialized == true, m_dbMutex.unlock(), PRIV_GUARD_ERROR_NOT_INITIALIZED, "Failed to initialize", res);
+
+ // open db
+ if(m_bDBOpen == false) {
+ openSqliteDB();
+ }
+ TryCatchResLogReturn(m_bDBOpen == true, m_dbMutex.unlock(), PRIV_GUARD_ERROR_IO_ERROR, "openSqliteDB : %d", res);
+
+ // prepare
+ res = sqlite3_prepare_v2(m_sqlHandler, QUERY_INSERT.c_str(), -1, &m_stmt, NULL);
+ TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_prepare_v2 : %d", res);
+
+ // bind
+ res = sqlite3_bind_int(m_stmt, 1, userId);
+ TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_int : %d", res);
+
+ res = sqlite3_bind_text(m_stmt, 2, packageId.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_text(m_stmt, 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(m_stmt, 4, monitorPolicy);
+ TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_int : %d", res);
+
+ res = sqlite3_step(m_stmt);
+ TryCatchResLogReturn(res == SQLITE_DONE, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_step : %d", res);
+
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
return PRIV_GUARD_ERROR_SUCCESS;
int res = -1;
char buf[BUF_SIZE];
- snprintf(buf, BUF_SIZE, "SELECT COUNT(*) FROM MonitorPolicy WHERE (USER_ID=? OR USER_ID=%d) AND PKG_ID=?", GLOBAL_USER);
+ snprintf(buf, BUF_SIZE, "SELECT COUNT(*) FROM MonitorPolicy WHERE USER_ID=? AND PKG_ID=?");
static const std::string query = std::string(buf);
+ ///////////////////////////////////////////////////
+ // prepare privacy monitor policy for global apps
+ ///////////////////////////////////////////////////
+ res = prepareGlobalPackagePolicy(userId);
+ TryCatchResLogReturn(res == PRIV_GUARD_ERROR_SUCCESS, m_dbMutex.unlock();, PRIV_GUARD_ERROR_INTERNAL_ERROR, "PgPrepareGlobalPackagePolicy: %d", res);
+
m_dbMutex.lock();
// initialize
if ((res = sqlite3_step(m_stmt)) == SQLITE_ROW) {
count = sqlite3_column_int(m_stmt, 0);
}
+
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
if (count > 0) {
res = sqlite3_step(m_stmt);
TryCatchResLogReturn(res == SQLITE_DONE, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_step : %d", res);
+ sqlite3_reset(m_stmt);
+
res = sqlite3_prepare_v2(m_sqlHandler, POLICY_DELETE.c_str(), -1, &m_stmt, NULL);
TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_prepare_v2 : %d", res);
res = sqlite3_step(m_stmt);
TryCatchResLogReturn(res == SQLITE_DONE, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_step : %d", res);
+ sqlite3_reset(m_stmt);
+
res = sqlite3_prepare_v2(m_sqlHandler, MAIN_POLICY_DELETE.c_str(), -1, &m_stmt, NULL);
TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_prepare_v2 : %d", res);
res = sqlite3_step(m_stmt);
TryCatchResLogReturn(res == SQLITE_DONE, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_step : %d", res);
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
return PRIV_GUARD_ERROR_SUCCESS;
}
+int
+PrivacyGuardDb::PgDeleteAllLogs(void)
+{
+ int res = -1;
+ static const std::string LOG_DELETE = std::string("DELETE FROM StatisticsMonitorInfo");
+
+ m_dbMutex.lock();
+
+ // initialize
+ if (m_bInitialized == false) {
+ initialize();
+ }
+ TryCatchResLogReturn(m_bInitialized == true, m_dbMutex.unlock(), PRIV_GUARD_ERROR_NOT_INITIALIZED, "Failed to initialize", res);
+
+ // open db
+ if(m_bDBOpen == false) {
+ openSqliteDB();
+ }
+ TryCatchResLogReturn(m_bDBOpen == true, m_dbMutex.unlock(), PRIV_GUARD_ERROR_IO_ERROR, "openSqliteDB : %d", res);
+
+ // prepare
+ res = sqlite3_prepare_v2(m_sqlHandler, LOG_DELETE.c_str(), -1, &m_stmt, NULL);
+ TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_prepare_v2 : %d", res);
+
+ res = sqlite3_step(m_stmt);
+ TryCatchResLogReturn(res == SQLITE_DONE, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_step : %d", res);
+
+ sqlite3_finalize(m_stmt);
+
+ m_dbMutex.unlock();
+
+ return PRIV_GUARD_ERROR_SUCCESS;
+}
int
PrivacyGuardDb::PgDeleteLogsByPackageId(const std::string packageId)
res = sqlite3_step(m_stmt);
TryCatchResLogReturn(res == SQLITE_DONE, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_step : %d", res);
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
return PRIV_GUARD_ERROR_SUCCESS;
res = sqlite3_step(m_stmt);
TryCatchResLogReturn(res == SQLITE_DONE, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_step : %d", res);
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
return PRIV_GUARD_ERROR_SUCCESS;
char buf[BUF_SIZE];
sqlite3_stmt* infoStmt;
+ ///////////////////////////////////////////////////
+ // prepare privacy monitor policy for global apps
+ ///////////////////////////////////////////////////
+ res = prepareGlobalPackagePolicy(userId);
+ TryCatchResLogReturn(res == PRIV_GUARD_ERROR_SUCCESS, m_dbMutex.unlock();, PRIV_GUARD_ERROR_INTERNAL_ERROR, "PgPrepareGlobalPackagePolicy: %d", res);
+
// [CYNARA] Flush Entries
res = cynara_monitor_entries_flush(p_cynara_monitor);
if(res != CYNARA_API_SUCCESS){
}
}
- snprintf(buf, BUF_SIZE, "SELECT DISTINCT PKG_ID FROM StatisticsMonitorInfo WHERE (USER_ID=? OR USER_ID=%d) AND USE_DATE>=? AND USE_DATE<=?", GLOBAL_USER);
+ snprintf(buf, BUF_SIZE, "SELECT DISTINCT PKG_ID FROM StatisticsMonitorInfo WHERE USER_ID=? AND USE_DATE>=? AND USE_DATE<=?");
static const std::string PKGID_SELECT = std::string(buf);
- snprintf(buf, BUF_SIZE, "SELECT COUNT(*) FROM StatisticsMonitorInfo WHERE (USER_ID=? OR USER_ID=%d) AND PKG_ID=? AND USE_DATE>=? AND USE_DATE<=?", GLOBAL_USER);
+ snprintf(buf, BUF_SIZE, "SELECT COUNT(*) FROM StatisticsMonitorInfo WHERE USER_ID=? AND PKG_ID=? AND USE_DATE>=? AND USE_DATE<=?");
static const std::string PKGINFO_SELECT = std::string(buf);
m_dbMutex.lock();
}
packageInfoList.push_back(std::pair <std::string, int> (std::string(packageId), count));
}
- sqlite3_reset(infoStmt);
+ sqlite3_finalize(infoStmt);
}
+
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
return PRIV_GUARD_ERROR_SUCCESS;
int res = -1;
char buf[BUF_SIZE];
+ ///////////////////////////////////////////////////
+ // prepare privacy monitor policy for global apps
+ ///////////////////////////////////////////////////
+ res = prepareGlobalPackagePolicy(userId);
+ TryCatchResLogReturn(res == PRIV_GUARD_ERROR_SUCCESS, m_dbMutex.unlock();, PRIV_GUARD_ERROR_INTERNAL_ERROR, "PgPrepareGlobalPackagePolicy: %d", res);
+
// [CYNARA] Flush Entries
res = cynara_monitor_entries_flush(p_cynara_monitor);
if(res != CYNARA_API_SUCCESS){
}
}
- snprintf(buf, BUF_SIZE, "SELECT COUNT(*) FROM StatisticsMonitorInfo WHERE (USER_ID=? OR USER_ID=%d) AND PRIVACY_ID=? AND USE_DATE>=? AND USE_DATE<=?", GLOBAL_USER);
+ snprintf(buf, BUF_SIZE, "SELECT COUNT(*) FROM StatisticsMonitorInfo WHERE USER_ID=? AND PRIVACY_ID=? AND USE_DATE>=? AND USE_DATE<=?");
static const std::string PRIVACY_SELECT = std::string(buf);
m_dbMutex.lock();
sqlite3_reset(m_stmt);
}
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
return PRIV_GUARD_ERROR_SUCCESS;
sqlite3_stmt* infoStmt;
char buf[BUF_SIZE];
+ ///////////////////////////////////////////////////
+ // prepare privacy monitor policy for global apps
+ ///////////////////////////////////////////////////
+ res = prepareGlobalPackagePolicy(userId);
+ TryCatchResLogReturn(res == PRIV_GUARD_ERROR_SUCCESS, m_dbMutex.unlock();, PRIV_GUARD_ERROR_INTERNAL_ERROR, "PgPrepareGlobalPackagePolicy: %d", res);
+
// [CYNARA] Flush Entries
res = cynara_monitor_entries_flush(p_cynara_monitor);
if(res != CYNARA_API_SUCCESS){
}
}
- snprintf(buf, BUF_SIZE, "SELECT DISTINCT PKG_ID FROM StatisticsMonitorInfo WHERE (USER_ID=? OR USER_ID=%d) AND PRIVACY_ID=? AND USE_DATE>=? AND USE_DATE<=?", GLOBAL_USER);
+ snprintf(buf, BUF_SIZE, "SELECT DISTINCT PKG_ID FROM StatisticsMonitorInfo WHERE USER_ID=? AND PRIVACY_ID=? AND USE_DATE>=? AND USE_DATE<=?");
static const std::string PKGID_SELECT = std::string(buf);
- snprintf(buf, BUF_SIZE, "SELECT COUNT(*) FROM StatisticsMonitorInfo WHERE (USER_ID=? OR USER_ID=%d) AND PKG_ID=? AND PRIVACY_ID=? AND USE_DATE>=? AND USE_DATE<=?", GLOBAL_USER);
+ snprintf(buf, BUF_SIZE, "SELECT COUNT(*) FROM StatisticsMonitorInfo WHERE USER_ID=? AND PKG_ID=? AND PRIVACY_ID=? AND USE_DATE>=? AND USE_DATE<=?");
static const std::string PKGINFO_SELECT = std::string(buf);
m_dbMutex.lock();
continue;
packageInfoList.push_back(std::pair <std::string, int> (std::string(packageId), count));
}
- sqlite3_reset(infoStmt);
+ sqlite3_finalize(infoStmt);
}
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
return PRIV_GUARD_ERROR_SUCCESS;
int res = -1;
char buf[BUF_SIZE];
+ ///////////////////////////////////////////////////
+ // prepare privacy monitor policy for global apps
+ ///////////////////////////////////////////////////
+ res = prepareGlobalPackagePolicy(userId);
+ TryCatchResLogReturn(res == PRIV_GUARD_ERROR_SUCCESS, m_dbMutex.unlock();, PRIV_GUARD_ERROR_INTERNAL_ERROR, "PgPrepareGlobalPackagePolicy: %d", res);
+
// [CYNARA] Flush Entries
res = cynara_monitor_entries_flush(p_cynara_monitor);
if(res != CYNARA_API_SUCCESS){
}
}
- snprintf(buf, BUF_SIZE, "SELECT COUNT(*) FROM StatisticsMonitorInfo WHERE (USER_ID=? OR USER_ID=%d) AND PKG_ID=? AND PRIVACY_ID=? AND USE_DATE>=? AND USE_DATE<=?", GLOBAL_USER);
+ snprintf(buf, BUF_SIZE, "SELECT COUNT(*) FROM StatisticsMonitorInfo WHERE USER_ID=? AND PKG_ID=? AND PRIVACY_ID=? AND USE_DATE>=? AND USE_DATE<=?");
static const std::string PRIVACY_SELECT = std::string(buf);
m_dbMutex.lock();
sqlite3_reset(m_stmt);
}
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
return PRIV_GUARD_ERROR_SUCCESS;
int
PrivacyGuardDb::PgGetMonitorPolicy(const int userId, const std::string packageId, const std::string privacyId, int& monitorPolicy)
{
-
int res = -1;
char buf[BUF_SIZE];
- snprintf(buf, BUF_SIZE, "SELECT MONITOR_POLICY FROM MonitorPolicy WHERE (USER_ID=? OR USER_ID=%d) AND PKG_ID=? AND PRIVACY_ID=?", GLOBAL_USER);
+ ///////////////////////////////////////////////////
+ // prepare privacy monitor policy for global apps
+ ///////////////////////////////////////////////////
+ res = prepareGlobalPackagePolicy(userId);
+ TryCatchResLogReturn(res == PRIV_GUARD_ERROR_SUCCESS, m_dbMutex.unlock();, PRIV_GUARD_ERROR_INTERNAL_ERROR, "PgPrepareGlobalPackagePolicy: %d", res);
+
+ snprintf(buf, BUF_SIZE, "SELECT MONITOR_POLICY FROM MonitorPolicy WHERE USER_ID=? AND PKG_ID=? AND PRIVACY_ID=?");
static const std::string query = std::string(buf);
m_dbMutex.lock();
if ((res = sqlite3_step(m_stmt)) == SQLITE_ROW) {
monitorPolicy = sqlite3_column_int(m_stmt, 0);
}
+
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
return PRIV_GUARD_ERROR_SUCCESS;
monitorPolicyList.push_back(std::pair < std::string, int > (userPkgIdPrivacyId, monitorPolicy));
}
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
PG_LOGD("monitorPolicyList.size() is [%d]", monitorPolicyList.size());
if(monitorPolicyList.size() > 0) {
int res = -1;
char buf[BUF_SIZE];
- snprintf(buf, BUF_SIZE, "SELECT DISTINCT PRIVACY_ID, MONITOR_POLICY FROM MonitorPolicy WHERE (USER_ID=? OR USER_ID=%d) AND PKG_ID=?", GLOBAL_USER);
+ ///////////////////////////////////////////////////
+ // prepare privacy monitor policy for global apps
+ ///////////////////////////////////////////////////
+ res = prepareGlobalPackagePolicy(userId);
+ TryCatchResLogReturn(res == PRIV_GUARD_ERROR_SUCCESS, m_dbMutex.unlock();, PRIV_GUARD_ERROR_INTERNAL_ERROR, "PgPrepareGlobalPackagePolicy: %d", res);
+
+ snprintf(buf, BUF_SIZE, "SELECT DISTINCT PRIVACY_ID, MONITOR_POLICY FROM MonitorPolicy WHERE USER_ID=? AND PKG_ID=?");
static const std::string query = std::string(buf);
m_dbMutex.lock();
// step
while ((res = sqlite3_step(m_stmt)) == SQLITE_ROW) {
-
char* tmp_data = (char*)sqlite3_column_text(m_stmt, 0);
if(tmp_data == NULL) {
continue;
}
privacy_data_s p_data;
- p_data.privacy_id = strdup(tmp_data);
+ memset(p_data.privacy_id, 0x0, LEN_PRIVACY_ID);
+ strncpy(p_data.privacy_id, tmp_data, strlen(tmp_data));
p_data.monitor_policy= sqlite3_column_int(m_stmt, 1);
privacyInfoList.push_back(p_data);
}
+
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
return PRIV_GUARD_ERROR_SUCCESS;
}
int
-PrivacyGuardDb::PgForeachPrivacyPackageId(const int userId, std::list < std::string > &packageList)
+PrivacyGuardDb::PgForeachPackageIdUsingPrivacy(const int userId, std::list < std::string > &packageList)
{
int res = -1;
char buf[BUF_SIZE];
- snprintf(buf, BUF_SIZE, "SELECT DISTINCT PKG_ID FROM MonitorPolicy WHERE (USER_ID=? OR USER_ID=%d)", GLOBAL_USER);
+ snprintf(buf, BUF_SIZE, "SELECT DISTINCT PKG_ID FROM MonitorPolicy WHERE USER_ID=?");
static const std::string query = std::string(buf);
+ ///////////////////////////////////////////////////
+ // prepare privacy monitor policy for global apps
+ ///////////////////////////////////////////////////
+ res = prepareGlobalPackagePolicy(userId);
+ TryCatchResLogReturn(res == PRIV_GUARD_ERROR_SUCCESS, m_dbMutex.unlock();, PRIV_GUARD_ERROR_INTERNAL_ERROR, "PgPrepareGlobalPackagePolicy: %d", res);
+
m_dbMutex.lock();
// initialize
}
packageList.push_back(std::string(p_data));
}
+
+ sqlite3_finalize(m_stmt);
+
+ m_dbMutex.unlock();
+
+ return PRIV_GUARD_ERROR_SUCCESS;
+}
+
+int
+PrivacyGuardDb::prepareGlobalPackagePolicy(const int userId)
+{
+ int res = -1;
+ char buf[BUF_SIZE];
+ std::list<package_privacy_data_s> dataList;
+
+ // parameter check
+ if (userId < 0) {
+ PG_LOGE("Invalid UserID [%d]", userId);
+ return PRIV_GUARD_ERROR_INVALID_PARAMETER;
+ }
+
+ // parameter check
+ if ((uid_t)userId == GLOBAL_USER) {
+ PG_LOGD("Not need to prepare global package policy for Global User ID [%d]", userId);
+ return PRIV_GUARD_ERROR_SUCCESS;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////
+ // Building-up cache for USER IDs
+ ///////////////////////////////////////////////////////////////////////////////////////////////
+ if (m_prepared_user_id_list == NULL) {
+ PG_LOGD("user id cache is not exist. Start to create user id cache.");
+
+ m_dbMutex.lock();
+
+ // open db
+ if(m_bDBOpen == false) {
+ openSqliteDB();
+ }
+ TryCatchResLogReturn(m_bDBOpen == true, m_dbMutex.unlock(), PRIV_GUARD_ERROR_IO_ERROR, "openSqliteDB : %d", res);
+
+ // query
+ snprintf(buf, BUF_SIZE, "SELECT DISTINCT USER_ID FROM MonitorPolicy");
+ static const std::string query_user_id = std::string(buf);
+
+ // prepare
+ res = sqlite3_prepare_v2(m_sqlHandler, query_user_id.c_str(), -1, &m_stmt, NULL);
+ TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_prepare_v2 : %d", res);
+
+ // step
+ while ((res = sqlite3_step(m_stmt)) == SQLITE_ROW) {
+ int temp_uid = sqlite3_column_int(m_stmt, 0);
+ //PG_LOGD("######### USER ID: [%d]", temp_uid);
+ // insert the user id to the cache
+ m_prepared_user_id_list = g_list_append(m_prepared_user_id_list, GINT_TO_POINTER(temp_uid));
+ }
+
+ sqlite3_finalize(m_stmt);
+
+ m_dbMutex.unlock();
+ }
+
+ // finding input user id from the cache
+ PG_LOGD("Finding input user id (%d) from the cache.", userId);
+ GList *node = g_list_find(m_prepared_user_id_list, GINT_TO_POINTER(userId));
+ if (node != NULL && GPOINTER_TO_INT(node->data) == userId) {
+ PG_LOGD("Global Package Policy for User ID [%d] is already created.", GPOINTER_TO_INT(node->data));
+ return PRIV_GUARD_ERROR_SUCCESS;
+ } else {
+ PG_LOGD("There is no such User ID [%d] in the cache. Start to create Global Package Policy for User ID [%d].", userId, userId);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////
+ // getting the list of all packages of GLOBALUSER and insert them into DB for input user_id
+ ///////////////////////////////////////////////////////////////////////////////////////////////
+ // query for getting the list of (package, privacy) of GLOBAL USER
+ snprintf(buf, BUF_SIZE, "SELECT DISTINCT PKG_ID, PRIVACY_ID FROM MonitorPolicy WHERE USER_ID=%d", GLOBAL_USER);
+ static const std::string query = std::string(buf);
+
+ m_dbMutex.lock();
+
+ // open db
+ if(m_bDBOpen == false) {
+ openSqliteDB();
+ }
+ TryCatchResLogReturn(m_bDBOpen == true, m_dbMutex.unlock(), PRIV_GUARD_ERROR_IO_ERROR, "openSqliteDB : %d", res);
+
+ // prepare
+ res = sqlite3_prepare_v2(m_sqlHandler, query.c_str(), -1, &m_stmt, NULL);
+ TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock();, PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_prepare_v2 : %d", res);
+
+ // step
+ while ((res = sqlite3_step(m_stmt)) == SQLITE_ROW) {
+ char *temp1 = (char*)sqlite3_column_text(m_stmt, 0); // package_id
+ char *temp2 = (char*)sqlite3_column_text(m_stmt, 1); // privacy_id
+ if(temp1 == NULL || temp2 == NULL) {
+ //PG_LOGD("PackageID: [%s], PrivacyID: [%s]", temp1, temp2);
+ continue;
+ }
+ package_privacy_data_s p_data;
+ memset(p_data.package_id, 0x0, LEN_PACKAGE_ID);
+ memset(p_data.privacy_id, 0x0, LEN_PRIVACY_ID);
+ strncpy(p_data.package_id, temp1, strlen(temp1));
+ strncpy(p_data.privacy_id, temp2, strlen(temp2));
+ dataList.push_back(p_data);
+ }
+
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
+ // insert privacy monitor policy of global packages for input userId
+ for (std::list<package_privacy_data_s>::const_iterator iter = dataList.begin(); iter != dataList.end(); ++iter) {
+ char *temp_package_id = (char*)iter->package_id;
+ char *temp_privacy_id = (char*)iter->privacy_id;
+ //PG_LOGD("Adding [%d | %s | %s | %d] to the DB.", userId, temp_package_id, temp_privacy_id, DEFAULT_MONITOR_POLICY);
+ PgAddMonitorPolicy(userId, temp_package_id, temp_privacy_id, DEFAULT_MONITOR_POLICY);
+ }
+
+ dataList.clear();
+
+ // add this User ID to the checked list
+ PG_LOGD("Adding User ID [%d] to the user id cache.", userId);
+ m_prepared_user_id_list = g_list_append(m_prepared_user_id_list, GINT_TO_POINTER(userId));
+
return PRIV_GUARD_ERROR_SUCCESS;
}
+
int
PrivacyGuardDb::PgForeachPackageInfoByPrivacyId(const int userId, const std::string privacyId, std::list < package_data_s > &packageInfoList)
{
struct tm date;
char buf[BUF_SIZE];
- snprintf(buf, BUF_SIZE, "SELECT DISTINCT PKG_ID, MONITOR_POLICY FROM MonitorPolicy WHERE (USER_ID=? OR USER_ID=%d) AND PRIVACY_ID=?", GLOBAL_USER);
+ ///////////////////////////////////////////////////
+ // prepare privacy monitor policy for global apps
+ ///////////////////////////////////////////////////
+ res = prepareGlobalPackagePolicy(userId);
+ TryCatchResLogReturn(res == PRIV_GUARD_ERROR_SUCCESS, m_dbMutex.unlock();, PRIV_GUARD_ERROR_INTERNAL_ERROR, "PgPrepareGlobalPackagePolicy: %d", res);
+
+
+ snprintf(buf, BUF_SIZE, "SELECT DISTINCT PKG_ID, MONITOR_POLICY FROM MonitorPolicy WHERE USER_ID=? AND PRIVACY_ID=?");
static const std::string query = std::string(buf);
- snprintf(buf, BUF_SIZE, "SELECT COUNT(*), MAX(USE_DATE) FROM StatisticsMonitorInfo WHERE (USER_ID=? OR USER_ID=%d) AND PKG_ID=? AND PRIVACY_ID=? AND USE_DATE>=? AND USE_DATE<=?", GLOBAL_USER);
+ snprintf(buf, BUF_SIZE, "SELECT COUNT(*), MAX(USE_DATE) FROM StatisticsMonitorInfo WHERE USER_ID=? AND PKG_ID=? AND PRIVACY_ID=? AND USE_DATE>=? AND USE_DATE<=?");
static const std::string PKGINFO_SELECT = std::string(buf);
// get start~end date (for 7 days)
continue;
}
package_data_s p_data;
- p_data.package_id = strdup(tmp_data);
+ memset(p_data.package_id, 0x0, LEN_PACKAGE_ID);
+ strncpy(p_data.package_id, tmp_data, strlen(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, SAFE_FREE(p_data.package_id); m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_prepare_v2 : %d", res);
+ 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, SAFE_FREE(p_data.package_id); m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_int : %d", res);
+ 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, SAFE_FREE(p_data.package_id); m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_text : %d", res);
+ 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, SAFE_FREE(p_data.package_id); m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_text : %d", res);
+ 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, SAFE_FREE(p_data.package_id); m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_int : %d", res);
+ 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, SAFE_FREE(p_data.package_id); m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_int : %d", res);
+ 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);
packageInfoList.push_back(p_data);
}
- sqlite3_reset(infoStmt);
+ sqlite3_finalize(infoStmt);
}
+
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
return PRIV_GUARD_ERROR_SUCCESS;
int res = -1;
char buf[BUF_SIZE];
- snprintf(buf, BUF_SIZE, "UPDATE MonitorPolicy SET MONITOR_POLICY=? WHERE (USER_ID=? OR USER_ID=%d) AND PKG_ID=? AND PRIVACY_ID=?", GLOBAL_USER);
+ snprintf(buf, BUF_SIZE, "UPDATE MonitorPolicy SET MONITOR_POLICY=? WHERE USER_ID=? AND PKG_ID=? AND PRIVACY_ID=?");
static const std::string query = std::string(buf);
+ ///////////////////////////////////////////////////
+ // prepare privacy monitor policy for global apps
+ ///////////////////////////////////////////////////
+ res = prepareGlobalPackagePolicy(userId);
+ TryCatchResLogReturn(res == PRIV_GUARD_ERROR_SUCCESS, m_dbMutex.unlock();, PRIV_GUARD_ERROR_INTERNAL_ERROR, "PgPrepareGlobalPackagePolicy: %d", res);
+
m_dbMutex.lock();
// initialize
res = sqlite3_step(m_stmt);
TryCatchResLogReturn(res == SQLITE_DONE, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_step : %d", res);
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
return PRIV_GUARD_ERROR_SUCCESS;
static const std::string QUERY_INSERT = std::string("INSERT INTO MainMonitorPolicy(USER_ID) VALUES(?)");
+ ///////////////////////////////////////////////////
+ // prepare privacy monitor policy for global apps
+ ///////////////////////////////////////////////////
+ res = prepareGlobalPackagePolicy(userId);
+ TryCatchResLogReturn(res == PRIV_GUARD_ERROR_SUCCESS, m_dbMutex.unlock();, PRIV_GUARD_ERROR_INTERNAL_ERROR, "PgPrepareGlobalPackagePolicy: %d", res);
+
m_dbMutex.lock();
// initialize
res = sqlite3_step(m_stmt);
TryCatchResLogReturn(res == SQLITE_DONE, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_step : %d", res);
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
return PRIV_GUARD_ERROR_SUCCESS;
}
int
-PrivacyGuardDb::PgUpdateMainMonitorPolicy(const int userId, const bool mainMonitorPolicy)
+PrivacyGuardDb::PgUpdateMainMonitorPolicy(const int userId, const int mainMonitorPolicy)
{
int res = -1;
char buf[BUF_SIZE];
- snprintf(buf, BUF_SIZE, "UPDATE MainMonitorPolicy SET MAIN_MONITOR_POLICY=? WHERE (USER_ID=? OR USER_ID=%d)", GLOBAL_USER);
+ snprintf(buf, BUF_SIZE, "UPDATE MainMonitorPolicy SET MAIN_MONITOR_POLICY=? WHERE USER_ID=? ");
static const std::string query = std::string(buf);
+ ///////////////////////////////////////////////////
+ // prepare privacy monitor policy for global apps
+ ///////////////////////////////////////////////////
+ res = prepareGlobalPackagePolicy(userId);
+ TryCatchResLogReturn(res == PRIV_GUARD_ERROR_SUCCESS, m_dbMutex.unlock();, PRIV_GUARD_ERROR_INTERNAL_ERROR, "PgPrepareGlobalPackagePolicy: %d", res);
+
m_dbMutex.lock();
// initialize
res = sqlite3_step(m_stmt);
TryCatchResLogReturn(res == SQLITE_DONE, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_step : %d", res);
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
#if 0
}
int
-PrivacyGuardDb::PgGetMainMonitorPolicy(const int userId, bool &mainMonitorPolicy)
+PrivacyGuardDb::PgGetMainMonitorPolicy(const int userId, int &mainMonitorPolicy)
{
int res = -1;
char buf[BUF_SIZE];
- snprintf(buf, BUF_SIZE, "SELECT MAIN_MONITOR_POLICY FROM MainMonitorPolicy WHERE (USER_ID=? OR USER_ID=%d)", GLOBAL_USER);
+ snprintf(buf, BUF_SIZE, "SELECT MAIN_MONITOR_POLICY FROM MainMonitorPolicy WHERE USER_ID=?");
static const std::string query = std::string(buf);
+ ///////////////////////////////////////////////////
+ // prepare privacy monitor policy for global apps
+ ///////////////////////////////////////////////////
+ res = prepareGlobalPackagePolicy(userId);
+ TryCatchResLogReturn(res == PRIV_GUARD_ERROR_SUCCESS, m_dbMutex.unlock();, PRIV_GUARD_ERROR_INTERNAL_ERROR, "PgPrepareGlobalPackagePolicy: %d", res);
+
m_dbMutex.lock();
// initialize
TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_int : %d", res);
// step
- mainMonitorPolicy = false;
+ mainMonitorPolicy = 0;
if ((res = sqlite3_step(m_stmt)) == SQLITE_ROW) {
mainMonitorPolicy = sqlite3_column_int(m_stmt, 0);
+
+ sqlite3_finalize(m_stmt);
m_dbMutex.unlock();
}
else {
+ sqlite3_finalize(m_stmt);
m_dbMutex.unlock();
res = PgAddMainMonitorPolicy(userId);
TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "PgAddMainMonitorPolicy failed : %d", res);
static const std::string QUERY_DELETE = std::string("DELETE FROM MainMonitorPolicy WHERE USER_ID=?");
+ ///////////////////////////////////////////////////
+ // prepare privacy monitor policy for global apps
+ ///////////////////////////////////////////////////
+ res = prepareGlobalPackagePolicy(userId);
+ TryCatchResLogReturn(res == PRIV_GUARD_ERROR_SUCCESS, m_dbMutex.unlock();, PRIV_GUARD_ERROR_INTERNAL_ERROR, "PgPrepareGlobalPackagePolicy: %d", res);
+
m_dbMutex.lock();
// initialize
res = sqlite3_step(m_stmt);
TryCatchResLogReturn(res == SQLITE_DONE, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_step : %d", res);
+ sqlite3_finalize(m_stmt);
+
m_dbMutex.unlock();
return PRIV_GUARD_ERROR_SUCCESS;
}
PrivacyGuardDb::PrivacyGuardDb(void)
+ : m_bInitialized(false)
{
// open DB
m_bDBOpen = false;
if (m_bInitialized == true) {
m_dbMutex.lock();
- g_list_free(m_privacy_list);
- cynara_monitor_configuration_destroy(p_conf);
+ g_list_free_full(m_privacy_list, g_free);
+ m_privacy_list = NULL;
+ g_list_free_full(m_prepared_user_id_list, g_free);
+ m_prepared_user_id_list = NULL;
m_bInitialized = false;
m_dbMutex.unlock();
}
#include "Utils.h"
void
+PrivacyInfoService::PgAddPrivacyAccessLog(SocketConnection* pConnector)
+{
+ int userId = 0;
+ std::string packageId;
+ std::string privacyId;
+ time_t accessTime = 0;
+
+ pConnector->read(&userId, &packageId, &privacyId, &accessTime);
+
+ int result = PrivacyGuardDb::getInstance()->PgAddPrivacyAccessLog(userId, packageId, privacyId, accessTime);
+
+ pConnector->write(result);
+}
+
+void
PrivacyInfoService::PgAddMonitorPolicy(SocketConnection* pConnector)
{
int userId = 0;
pConnector->write(result);
}
-void
+/*void
PrivacyInfoService::PgDeleteAllLogsAndMonitorPolicy(SocketConnection* pConnector)
{
int result = PrivacyGuardDb::getInstance()->PgDeleteAllLogsAndMonitorPolicy();
pConnector->write(result);
+}*/
+
+void
+PrivacyInfoService::PgDeleteAllLogs(SocketConnection* pConnector)
+{
+ int result = PrivacyGuardDb::getInstance()->PgDeleteAllLogs();
+
+ pConnector->write(result);
}
void
pConnector->write(result);
}
-void
+/*void
PrivacyInfoService::PgDeleteMonitorPolicyByPackageId(SocketConnection* pConnector)
{
std::string packageId;
int result = PrivacyGuardDb::getInstance()->PgDeleteMonitorPolicyByPackageId(packageId);
pConnector->write(result);
-}
+}*/
void
PrivacyInfoService::PgForeachTotalPrivacyCountOfPackage(SocketConnection* pConnector)
}
void
-PrivacyInfoService::PgForeachPrivacyPackageId(SocketConnection* pConnector)
+PrivacyInfoService::PgForeachPackageIdUsingPrivacy(SocketConnection* pConnector)
{
int userId = 0;
std::list < std::string > packageList;
pConnector->read(&userId);
- int result = PrivacyGuardDb::getInstance()->PgForeachPrivacyPackageId(userId, packageList);
+ int result = PrivacyGuardDb::getInstance()->PgForeachPackageIdUsingPrivacy(userId, packageList);
pConnector->write(result);
pConnector->write(packageList);
PrivacyInfoService::PgUpdateMainMonitorPolicy(SocketConnection* pConnector)
{
int userId = 0;
- bool mainMonitorPolicy = false;
+ int mainMonitorPolicy = 0;
pConnector->read(&userId, &mainMonitorPolicy);
PrivacyInfoService::PgGetMainMonitorPolicy(SocketConnection* pConnector)
{
int userId = 0;
- bool mainMonitorPolicy = false;
+ int mainMonitorPolicy = 0;
pConnector->read(&userId);
pConnector->write(result);
pConnector->write(mainMonitorPolicy);
}
-
-void
-PrivacyInfoService::PgDeleteMainMonitorPolicyByUserId(SocketConnection* pConnector)
-{
- int userId = 0;
-
- pConnector->read(&userId);
-
- int result = PrivacyGuardDb::getInstance()->PgDeleteMainMonitorPolicyByUserId(userId);
-
- pConnector->write(result);
-}
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(PACKAGE_NAME tc-privacy-guard)
+PROJECT(${PACKAGE_NAME})
+
+SET(TC1_NAME tc-privacy-guard)
+
+SET(TC1_SRCS ${TC1_NAME}.c)
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/client/inc)
+
+SET(requires glib-2.0 dlog)
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${PACKAGE_NAME} REQUIRED ${requires})
+FOREACH(flag ${${PACKAGE_NAME}_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+# Compiler flags
+SET(EXTRA_CXXFLAGS "${EXTRA_CFLAGS} -fPIC -Wall -Werror")
+SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC -Wall -fvisibility=hidden -D_WITH_SYSTEMD_")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${PACKAGE_NAME_CFLAGS}")
+
+ADD_EXECUTABLE(${TC1_NAME} ${TC1_SRCS})
+
+TARGET_LINK_LIBRARIES(${TC1_NAME} "privacy-guard-client")
+
+INSTALL(TARGETS ${TC1_NAME} DESTINATION /usr/bin)
--- /dev/null
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <glib.h>
+#include <privacy_guard_client.h>
+#include <privacy_guard_client_internal.h>
+
+#define BRIGHTNESS 0
+#define RED 31
+#define GREEN 32
+#define YELLOW 33
+#define BG_BLACK 40
+
+#define USER_ID_OWNER 5001
+#define INVALID_USER_ID -1
+
+#define LEN_FUNCTION_NAME 128
+#define LEN_PRIVACY_ID 128
+#define LEN_PACKAGE_ID 128
+#define LEN_PARAM 128
+
+#define PRIVACY_ACCOUNT "http://tizen.org/privacy/account"
+#define PRIVACY_BOOKMARK "http://tizen.org/privacy/bookmark"
+#define PRIVACY_CALENDAR "http://tizen.org/privacy/calendar"
+#define PRIVACY_CALL "http://tizen.org/privacy/call"
+#define PRIVACY_USERHISTORY "http://tizen.org/privacy/userhistory"
+#define PRIVACY_CAMERA "http://tizen.org/privacy/camera"
+#define PRIVACY_CONTACTS "http://tizen.org/privacy/contacts"
+#define PRIVACY_SENSOR "http://tizen.org/privacy/sensor"
+#define PRIVACY_LOCATION "http://tizen.org/privacy/location"
+#define PRIVACY_MESSAGE "http://tizen.org/privacy/message"
+#define PRIVACY_MICROPHONE "http://tizen.org/privacy/microphone"
+
+
+typedef struct {
+ char function_name[LEN_FUNCTION_NAME];
+ char privacy_id[LEN_PRIVACY_ID];
+ char package_id[LEN_PACKAGE_ID];
+} TEST_DATA;
+
+static int fail_cnt = 0;
+static int success_cnt = 0;
+
+static GList *all_package_list = NULL;
+
+static GList *package_list_using_location = NULL;
+static GList *package_list_using_account = NULL;
+static GList *package_list_using_bookmark = NULL;
+static GList *package_list_using_calendar = NULL;
+static GList *package_list_using_call = NULL;
+static GList *package_list_using_userhistory = NULL;
+static GList *package_list_using_camera = NULL;
+static GList *package_list_using_contacts = NULL;
+static GList *package_list_using_message = NULL;
+static GList *package_list_using_microphone = NULL;
+static GList *package_list_using_sensor = NULL;
+
+// temp utility
+/*static void display_all_packages(void)
+{
+ int i;
+
+ for (i = 0; i < (int)g_list_length(all_package_list); i++) {
+ char *package_id = (char*)g_list_nth_data(all_package_list, i);
+ printf("######################### found package: [%d][%s]\n", i, package_id);
+ }
+}*/
+
+///////////////////////////////////////////////////////////////////////////////
+// test utilities
+///////////////////////////////////////////////////////////////////////////////
+static void __change_color_to_red(void)
+{
+ printf("%c[%d;%dm", 0x1B, BRIGHTNESS, RED);
+}
+
+static void __change_color_to_green(void)
+{
+ printf("%c[%d;%dm", 0x1B, BRIGHTNESS, GREEN);
+}
+
+static void __change_color_to_yellow(void)
+{
+ printf("%c[%d;%dm", 0x1B, BRIGHTNESS, YELLOW);
+}
+
+static void __change_color_to_origin(void)
+{
+ printf("%c[%dm", 0x1B, 0);
+}
+
+static void __start_test(const char *function_name)
+{
+ __change_color_to_yellow();
+ printf("================================================================================\n");
+ printf("\t%s\n", function_name);
+ printf("================================================================================\n");
+ __change_color_to_origin();
+}
+
+static void __finish_test(void)
+{
+ __change_color_to_yellow();
+ printf("\n\n");
+ __change_color_to_origin();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test verfication utility
+///////////////////////////////////////////////////////////////////////////////
+static const char* __get_result_string(int ret)
+{
+ if (ret == PRIV_GUARD_ERROR_SUCCESS) {
+ return "PRIV_GUARD_ERROR_SUCCESS";
+ } else if (ret == PRIV_GUARD_ERROR_NOT_INITIALIZED) {
+ return "PRIV_GUARD_ERROR_NOT_INITIALIZED";
+ } else if (ret == PRIV_GUARD_ERROR_INVALID_PARAMETER) {
+ return "PRIV_GUARD_ERROR_INVALID_PARAMETER";
+ } else if (ret == PRIV_GUARD_ERROR_OUT_OF_MEMORY) {
+ return "PRIV_GUARD_ERROR_OUT_OF_MEMORY";
+ } else if (ret == PRIV_GUARD_ERROR_IO_ERROR) {
+ return "PRIV_GUARD_ERROR_IO_ERROR";
+ } else if (ret == PRIV_GUARD_ERROR_NO_DATA) {
+ return "PRIV_GUARD_ERROR_NO_DATA";
+ } else if (ret == PRIV_GUARD_ERROR_DB_ERROR) {
+ return "PRIV_GUARD_ERROR_DB_ERROR";
+ } else if (ret == PRIV_GUARD_ERROR_IPC_ERROR) {
+ return "PRIV_GUARD_ERROR_IPC_ERROR";
+ } else if (ret == PRIV_GUARD_ERROR_INVALID_STATE) {
+ return "PRIV_GUARD_ERROR_INVALID_STATE";
+ } else if (ret == PRIV_GUARD_ERROR_SYSTEM_ERROR) {
+ return "PRIV_GUARD_ERROR_SYSTEM_ERROR";
+ } else if (ret == PRIV_GUARD_ERROR_USER_NOT_CONSENTED) {
+ return "PRIV_GUARD_ERROR_USER_NOT_CONSENTED";
+ } else if (ret == PRIV_GUARD_ERROR_INTERNAL_ERROR) {
+ return "PRIV_GUARD_ERROR_INTERNAL_ERROR";
+ } else if (ret == PRIV_GUARD_ERROR_NOT_PERMITTED) {
+ return "PRIV_GUARD_ERROR_NOT_PERMITTED";
+ } else {
+ return "PRIV_GUARD_ERROR_UNKNOWN";
+ }
+
+ return "FAIL";
+}
+
+static const char *__get_bool_string(const bool result)
+{
+ if (result == true) {
+ return "TRUE";
+ }
+
+ return "FALSE";
+}
+
+static void __check_result_error_code(int expected, int actual, int line)
+{
+ printf("expected result = %s, actual result = %s\n", __get_result_string(expected), __get_result_string(actual));
+
+ if(expected != actual) {
+ printf("not matched [line %d]\n", line);
+ __change_color_to_red();
+ printf("test fail\n");
+ fail_cnt++;
+ } else {
+ printf("matched [line %d]\n", line);
+ __change_color_to_green();
+ printf("test success\n");
+ success_cnt++;
+ }
+ __change_color_to_origin();
+}
+
+static void __check_result_int(int expected, int actual, int line)
+{
+ printf("expected result = %d, actual result = %d\n", expected, actual);
+
+ if(expected != actual) {
+ printf("not matched [line %d]\n", line);
+ __change_color_to_red();
+ printf("test fail\n");
+ fail_cnt++;
+ } else {
+ printf("matched [line %d]\n", line);
+ __change_color_to_green();
+ printf("test success\n");
+ success_cnt++;
+ }
+ __change_color_to_origin();
+}
+
+static void __check_result_int_over_zero(int actual, int line)
+{
+ printf("expected result > 0, actual result = %d\n", actual);
+
+ if (actual <= 0) {
+ printf("not matched [line %d]\n", line);
+ __change_color_to_red();
+ printf("test fail\n");
+ fail_cnt++;
+ } else {
+ printf("matched [line %d]\n", line);
+ __change_color_to_green();
+ printf("test success\n");
+ success_cnt++;
+ }
+ __change_color_to_origin();
+}
+
+static void __check_result_bool(bool expected, bool actual, int line)
+{
+ printf("expected result = %s, actual result = %s\n", __get_bool_string(expected), __get_bool_string(actual));
+
+ if(expected != actual) {
+ printf("not matched [line %d]\n", line);
+ __change_color_to_red();
+ printf("test fail\n");
+ fail_cnt++;
+ } else {
+ printf("matched [line %d]\n", line);
+ __change_color_to_green();
+ printf("test success\n");
+ success_cnt++;
+ }
+ __change_color_to_origin();
+}
+
+static void __check_pointer_not_null(const void *ptr, int line)
+{
+ printf("expected result = \"NOT_NULL_POINTER\", actual result = %p\n", ptr);
+
+ if(!ptr) {
+ printf("null string [line %d]\n", line);
+ __change_color_to_red();
+ printf("test fail\n");
+ fail_cnt++;
+ } else {
+ printf("not null string [line %d]\n", line);
+ __change_color_to_green();
+ printf("test success\n");
+ success_cnt++;
+ }
+ __change_color_to_origin();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// callbacks
+///////////////////////////////////////////////////////////////////////////////
+
+// callback for privacy_guard_client_monitor_policy_cb
+static bool __monitor_policy_cb(const char *privacy_id, const int monitor_policy, void *user_data)
+{
+ __change_color_to_yellow();
+ printf("%s is called.\n", __FUNCTION__);
+ __change_color_to_origin();
+
+ if (!user_data) {
+ printf("user_data is null.\n");
+ return false;
+ }
+
+ TEST_DATA *data = user_data;
+ int on = 1, off = 0;
+
+ if (strncmp(data->function_name, "__test_privacy_guard_client_update_monitor_policy_02", strlen(data->function_name)) == 0) {
+ if (strncmp(privacy_id, data->privacy_id, strlen(data->privacy_id)) == 0) {
+ __check_result_int(off, monitor_policy, __LINE__);
+ }
+ } else if (strncmp(data->function_name, "__test_privacy_guard_client_foreach_monitor_policy_by_package_id_02", strlen(data->function_name)) == 0) {
+ if (strncmp(privacy_id, data->privacy_id, strlen(data->privacy_id)) == 0) {
+ __check_result_int(on, monitor_policy, __LINE__);
+ }
+ }
+
+ return true;
+}
+
+// callback for privacy_guard_client_package_id_cb
+static bool __package_id_cb(const char *package_id, void *user_data)
+{
+ __change_color_to_yellow();
+ printf("%s is called.\n", __FUNCTION__);
+ __change_color_to_origin();
+
+ char *data = (char*)user_data;
+ if (strncmp(data, "__db_util_get_all_package_list_using_privacy", strlen(data)) == 0) {
+ all_package_list = g_list_append(all_package_list, strdup(package_id));
+ } else if (strncmp(data, "__test_privacy_guard_client_foreach_privacy_package_id", strlen(data)) == 0) {
+ bool is_privacy_package = false;
+ int res = privacy_guard_client_check_privacy_package(USER_ID_OWNER, package_id, &is_privacy_package);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ __check_result_bool(true, is_privacy_package, __LINE__);
+ }
+
+ return true;
+}
+
+// callback for privacy_guard_client_package_info_cb
+static bool __package_info_cb(const char *package_id, const int count, const time_t time, const int monitor_policy, void *user_data)
+{
+ __change_color_to_yellow();
+ printf("%s is called.\n", __FUNCTION__);
+ __change_color_to_origin();
+
+ if (!user_data) {
+ printf("user_data is null.\n");
+ return false;
+ }
+
+ char *privacy_id = (char*)user_data;
+ GList *node;
+
+ if (strncmp(privacy_id, PRIVACY_ACCOUNT, strlen(privacy_id)) == 0) {
+ node = g_list_find_custom(package_list_using_account, package_id, (GCompareFunc)strcmp);
+ __check_pointer_not_null(node, __LINE__);
+ } else if (strncmp(privacy_id, PRIVACY_BOOKMARK, strlen(privacy_id)) == 0) {
+ node = g_list_find_custom(package_list_using_bookmark, package_id, (GCompareFunc)strcmp);
+ __check_pointer_not_null(node, __LINE__);
+ } else if (strncmp(privacy_id, PRIVACY_CALENDAR, strlen(privacy_id)) == 0) {
+ node = g_list_find_custom(package_list_using_calendar, package_id, (GCompareFunc)strcmp);
+ __check_pointer_not_null(node, __LINE__);
+ } else if (strncmp(privacy_id, PRIVACY_CALL, strlen(privacy_id)) == 0) {
+ node = g_list_find_custom(package_list_using_call, package_id, (GCompareFunc)strcmp);
+ __check_pointer_not_null(node, __LINE__);
+ } else if (strncmp(privacy_id, PRIVACY_USERHISTORY, strlen(privacy_id)) == 0) {
+ node = g_list_find_custom(package_list_using_userhistory, package_id, (GCompareFunc)strcmp);
+ __check_pointer_not_null(node, __LINE__);
+ } else if (strncmp(privacy_id, PRIVACY_CAMERA, strlen(privacy_id)) == 0) {
+ node = g_list_find_custom(package_list_using_camera, package_id, (GCompareFunc)strcmp);
+ __check_pointer_not_null(node, __LINE__);
+ } else if (strncmp(privacy_id, PRIVACY_CONTACTS, strlen(privacy_id)) == 0) {
+ node = g_list_find_custom(package_list_using_contacts, package_id, (GCompareFunc)strcmp);
+ __check_pointer_not_null(node, __LINE__);
+ } else if (strncmp(privacy_id, PRIVACY_SENSOR, strlen(privacy_id)) == 0) {
+ node = g_list_find_custom(package_list_using_sensor, package_id, (GCompareFunc)strcmp);
+ __check_pointer_not_null(node, __LINE__);
+ } else if (strncmp(privacy_id, PRIVACY_LOCATION, strlen(privacy_id)) == 0) {
+ node = g_list_find_custom(package_list_using_location, package_id, (GCompareFunc)strcmp);
+ __check_pointer_not_null(node, __LINE__);
+ } else if (strncmp(privacy_id, PRIVACY_MESSAGE, strlen(privacy_id)) == 0) {
+ node = g_list_find_custom(package_list_using_message, package_id, (GCompareFunc)strcmp);
+ __check_pointer_not_null(node, __LINE__);
+ } else if (strncmp(privacy_id, PRIVACY_MICROPHONE, strlen(privacy_id)) == 0) {
+ node = g_list_find_custom(package_list_using_microphone, package_id, (GCompareFunc)strcmp);
+ __check_pointer_not_null(node, __LINE__);
+ }
+
+ return true;
+}
+
+// callback for privacy_guard_client_privacy_count_cb
+static bool __privacy_count_cb(const char *privacy_id, const int count, void *user_data)
+{
+ __change_color_to_yellow();
+ printf("%s is called.\n", __FUNCTION__);
+ __change_color_to_origin();
+
+ if (!user_data) {
+ printf("user_data is null.\n");
+ return false;
+ }
+
+ char *data = (char*)user_data;
+
+ if (strncmp(data, "__test_privacy_guard_client_foreach_total_privacy_count_of_privacy_02", strlen(data)) == 0) {
+ __check_result_int_over_zero(count, __LINE__);
+ }
+
+ return true;
+}
+
+// callback for privacy_guard_client_privacy_count_of_package_cb
+static bool __privacy_count_of_package_cb(const char *package_id, const int count, void *user_data)
+{
+ __change_color_to_yellow();
+ printf("%s is called.\n", __FUNCTION__);
+ __change_color_to_origin();
+
+ if (!user_data) {
+ printf("user_data is null.\n");
+ return false;
+ }
+
+ char *data = (char*)user_data;
+
+ if (strncmp(data, "__test_privacy_guard_client_foreach_total_privacy_count_of_package_02", strlen(data)) == 0) {
+ __check_result_int_over_zero(count, __LINE__);
+ } else if (strncmp(data, "__test_privacy_guard_client_foreach_privacy_count_by_privacy_id_02", strlen(data)) == 0) {
+ __check_result_int(1, count, __LINE__);
+ } else if (strncmp(data, "__test_privacy_guard_client_foreach_privacy_count_by_package_id_02", strlen(data)) == 0) {
+ __check_result_int(1, count, __LINE__);
+ } else if (strncmp(data, PRIVACY_ACCOUNT, strlen(data)) == 0) {
+ package_list_using_account = g_list_append(package_list_using_account, strdup(package_id));
+ } else if (strncmp(data, PRIVACY_BOOKMARK, strlen(data)) == 0) {
+ package_list_using_bookmark = g_list_append(package_list_using_bookmark, strdup(package_id));
+ } else if (strncmp(data, PRIVACY_CALENDAR, strlen(data)) == 0) {
+ package_list_using_calendar = g_list_append(package_list_using_calendar, strdup(package_id));
+ } else if (strncmp(data, PRIVACY_CALL, strlen(data)) == 0) {
+ package_list_using_call = g_list_append(package_list_using_call, strdup(package_id));
+ } else if (strncmp(data, PRIVACY_USERHISTORY, strlen(data)) == 0) {
+ package_list_using_userhistory = g_list_append(package_list_using_userhistory, strdup(package_id));
+ } else if (strncmp(data, PRIVACY_CAMERA, strlen(data)) == 0) {
+ package_list_using_camera = g_list_append(package_list_using_camera, strdup(package_id));
+ } else if (strncmp(data, PRIVACY_CONTACTS, strlen(data)) == 0) {
+ package_list_using_contacts = g_list_append(package_list_using_contacts, strdup(package_id));
+ } else if (strncmp(data, PRIVACY_SENSOR, strlen(data)) == 0) {
+ package_list_using_sensor = g_list_append(package_list_using_sensor, strdup(package_id));
+ } else if (strncmp(data, PRIVACY_LOCATION, strlen(data)) == 0) {
+ package_list_using_location = g_list_append(package_list_using_location, strdup(package_id));
+ } else if (strncmp(data, PRIVACY_MESSAGE, strlen(data)) == 0) {
+ package_list_using_message = g_list_append(package_list_using_message, strdup(package_id));
+ } else if (strncmp(data, PRIVACY_MICROPHONE, strlen(data)) == 0) {
+ package_list_using_microphone = g_list_append(package_list_using_microphone, strdup(package_id));
+ }
+
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test preparation utility
+///////////////////////////////////////////////////////////////////////////////
+static int __db_util_delete_all_logs(void)
+{
+ int res = privacy_guard_client_delete_all_logs();
+ if (res != PRIV_GUARD_ERROR_SUCCESS) {
+ printf("failed to operate privacy_guard_client_delete_all_logs() [%d]\n", res);
+ }
+
+ return res;
+}
+
+static int __db_util_get_all_package_list_using_privacy(void)
+{
+ int res = privacy_guard_client_foreach_package_id_using_privacy(USER_ID_OWNER, __package_id_cb, (char*)__FUNCTION__);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) {
+ printf("failed to operate privacy_guard_client_add_privacy_access_log() [%d]\n", res);
+ }
+
+ //display_all_packages();
+
+ return res;
+}
+
+static int __db_util_get_package_list_using_privacy(const char *privacy_id)
+{
+ int res;
+ time_t start_date, end_date;
+
+ end_date = time(NULL);
+ start_date = end_date - (24 * 60 * 60) * 7; // almost 7 days
+
+ res = privacy_guard_client_foreach_privacy_count_by_privacy_id(USER_ID_OWNER, start_date, end_date, privacy_id, __privacy_count_of_package_cb, (char*)privacy_id);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) {
+ printf("Failed to operate privacy_guard_client_foreach_privacy_count_by_privacy_id() [%d]\n", res);
+ }
+
+ return res;
+}
+
+static int __db_util_add_test_logs(void)
+{
+ int i;
+ time_t access_time;
+ int res = -1;
+
+ access_time = time(NULL);
+
+ for (i = 0; i < (int)g_list_length(all_package_list); i++) {
+ char *package_id = (char*)g_list_nth_data(all_package_list, i);
+ if (package_id) {
+ //printf("## [%d] package_id[%s]\n", i, package_id);
+ // account
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_ACCOUNT, 1);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_update_monitor_policy() [%d]\n", res);
+ res = privacy_guard_client_add_privacy_access_log(USER_ID_OWNER, package_id, PRIVACY_ACCOUNT, access_time - i * 100);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_add_privacy_access_log() [%d]\n", res);
+ // bookmark
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_BOOKMARK, 1);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_update_monitor_policy() [%d]\n", res);
+ res = privacy_guard_client_add_privacy_access_log(USER_ID_OWNER, package_id, PRIVACY_BOOKMARK, access_time - i * 100);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_add_privacy_access_log() [%d]\n", res);
+ // calendar
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_CALENDAR, 1);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_update_monitor_policy() [%d]\n", res);
+ res = privacy_guard_client_add_privacy_access_log(USER_ID_OWNER, package_id, PRIVACY_CALENDAR, access_time - i * 100);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_add_privacy_access_log() [%d]\n", res);
+ // call
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_CALL, 1);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_update_monitor_policy() [%d]\n", res);
+ res = privacy_guard_client_add_privacy_access_log(USER_ID_OWNER, package_id, PRIVACY_CALL, access_time - i * 100);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_add_privacy_access_log() [%d]\n", res);
+ // userhistory
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_USERHISTORY, 1);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_update_monitor_policy() [%d]\n", res);
+ res = privacy_guard_client_add_privacy_access_log(USER_ID_OWNER, package_id, PRIVACY_USERHISTORY, access_time - i * 100);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_add_privacy_access_log() [%d]\n", res);
+ // camera
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_CAMERA, 1);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_update_monitor_policy() [%d]\n", res);
+ res = privacy_guard_client_add_privacy_access_log(USER_ID_OWNER, package_id, PRIVACY_CAMERA, access_time - i * 100);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_add_privacy_access_log() [%d]\n", res);
+ // contacts
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_CONTACTS, 1);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_update_monitor_policy() [%d]\n", res);
+ res = privacy_guard_client_add_privacy_access_log(USER_ID_OWNER, package_id, PRIVACY_CONTACTS, access_time - i * 100);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_add_privacy_access_log() [%d]\n", res);
+ // sensor
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_SENSOR, 1);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_update_monitor_policy() [%d]\n", res);
+ res = privacy_guard_client_add_privacy_access_log(USER_ID_OWNER, package_id, PRIVACY_SENSOR, access_time - i * 100);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_add_privacy_access_log() [%d]\n", res);
+ // location
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_LOCATION, 1);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_update_monitor_policy() [%d]\n", res);
+ res = privacy_guard_client_add_privacy_access_log(USER_ID_OWNER, package_id, PRIVACY_LOCATION, access_time - i * 100);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_add_privacy_access_log() [%d]\n", res);
+ // message
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_MESSAGE, 1);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_update_monitor_policy() [%d]\n", res);
+ res = privacy_guard_client_add_privacy_access_log(USER_ID_OWNER, package_id, PRIVACY_MESSAGE, access_time - i * 100);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_add_privacy_access_log() [%d]\n", res);
+ // microphone
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_MICROPHONE, 1);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_update_monitor_policy() [%d]\n", res);
+ res = privacy_guard_client_add_privacy_access_log(USER_ID_OWNER, package_id, PRIVACY_MICROPHONE, access_time - i * 100);
+ if (res != PRIV_GUARD_ERROR_SUCCESS) printf("Failed to operate privacy_guard_client_add_privacy_access_log() [%d]\n", res);
+ }
+ }
+
+ return res;
+}
+
+static void __test_preparation(void)
+{
+ fail_cnt = 0;
+ success_cnt = 0;
+
+ all_package_list = NULL;
+ package_list_using_location = NULL;
+ package_list_using_account = NULL;
+ package_list_using_bookmark = NULL;
+ package_list_using_calendar = NULL;
+ package_list_using_call = NULL;
+ package_list_using_userhistory = NULL;
+ package_list_using_camera = NULL;
+ package_list_using_contacts = NULL;
+ package_list_using_message = NULL;
+ package_list_using_microphone = NULL;
+ package_list_using_sensor = NULL;
+
+ __db_util_get_all_package_list_using_privacy();
+
+ __db_util_add_test_logs();
+
+ __db_util_get_package_list_using_privacy(PRIVACY_ACCOUNT);
+ __db_util_get_package_list_using_privacy(PRIVACY_LOCATION);
+ __db_util_get_package_list_using_privacy(PRIVACY_BOOKMARK);
+ __db_util_get_package_list_using_privacy(PRIVACY_CALENDAR);
+ __db_util_get_package_list_using_privacy(PRIVACY_CALL);
+ __db_util_get_package_list_using_privacy(PRIVACY_USERHISTORY);
+ __db_util_get_package_list_using_privacy(PRIVACY_CAMERA);
+ __db_util_get_package_list_using_privacy(PRIVACY_CONTACTS);
+ __db_util_get_package_list_using_privacy(PRIVACY_SENSOR);
+ __db_util_get_package_list_using_privacy(PRIVACY_MESSAGE);
+ __db_util_get_package_list_using_privacy(PRIVACY_MICROPHONE);
+}
+
+static void __test_termination(void)
+{
+ fail_cnt = 0;
+ success_cnt = 0;
+
+ g_list_free(all_package_list);
+ g_list_free(package_list_using_location);
+ g_list_free(package_list_using_account);
+ g_list_free(package_list_using_bookmark);
+ g_list_free(package_list_using_calendar);
+ g_list_free(package_list_using_call);
+ g_list_free(package_list_using_userhistory);
+ g_list_free(package_list_using_camera);
+ g_list_free(package_list_using_contacts);
+ g_list_free(package_list_using_message);
+ g_list_free(package_list_using_microphone);
+ g_list_free(package_list_using_sensor);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// main testcases
+///////////////////////////////////////////////////////////////////////////////
+
+static void __test_privacy_guard_client_foreach_total_privacy_count_of_package_01(void)
+{
+ __start_test(__FUNCTION__);
+
+ time_t start_date, end_date;
+
+ end_date = time(NULL);
+ start_date = end_date - (24 * 60 * 60) * 7; // almost 7 days
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - delete all logs
+ //////////////////////////////////////////////////////////////////////////
+ int res = __db_util_delete_all_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // positive case
+ //////////////////////////////////////////////////////////////////////////
+ res = privacy_guard_client_foreach_total_privacy_count_of_package(USER_ID_OWNER, start_date, end_date, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // negative cases
+ //////////////////////////////////////////////////////////////////////////
+ // invalid user id
+ res = privacy_guard_client_foreach_total_privacy_count_of_package(INVALID_USER_ID, start_date, end_date, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ // invalid start date
+ res = privacy_guard_client_foreach_total_privacy_count_of_package(USER_ID_OWNER, -1, end_date, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ // invalid end date
+ res = privacy_guard_client_foreach_total_privacy_count_of_package(USER_ID_OWNER, start_date, -1, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ __finish_test();
+}
+
+static void __test_privacy_guard_client_foreach_total_privacy_count_of_package_02(void)
+{
+ __start_test(__FUNCTION__);
+
+ time_t start_date, end_date;
+
+ end_date = time(NULL);
+ start_date = end_date - (24 * 60 * 60) * 7; // almost 7 days
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - delete all logs
+ //////////////////////////////////////////////////////////////////////////
+ int res = __db_util_delete_all_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - add logs to each package
+ //////////////////////////////////////////////////////////////////////////
+ res = __db_util_add_test_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // positive case
+ //////////////////////////////////////////////////////////////////////////
+ res = privacy_guard_client_foreach_total_privacy_count_of_package(USER_ID_OWNER, start_date, end_date, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ __finish_test();
+}
+
+static void __test_privacy_guard_client_foreach_total_privacy_count_of_privacy_01(void)
+{
+ __start_test(__FUNCTION__);
+
+ time_t start_date, end_date;
+
+ end_date = time(NULL);
+ start_date = end_date - (24 * 60 * 60) * 7; // almost 7 days
+
+ //////////////////////////////////////////////////////////////////////////
+ // positive case
+ //////////////////////////////////////////////////////////////////////////
+ int res = privacy_guard_client_foreach_total_privacy_count_of_privacy(USER_ID_OWNER, start_date, end_date, __privacy_count_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // negative cases
+ //////////////////////////////////////////////////////////////////////////
+ // invalid user id
+ res = privacy_guard_client_foreach_total_privacy_count_of_privacy(INVALID_USER_ID, start_date, end_date, __privacy_count_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ // invalid start date
+ res = privacy_guard_client_foreach_total_privacy_count_of_privacy(USER_ID_OWNER, -1, end_date, __privacy_count_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ // invalid end date
+ res = privacy_guard_client_foreach_total_privacy_count_of_privacy(USER_ID_OWNER, start_date, -1, __privacy_count_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ __finish_test();
+}
+
+static void __test_privacy_guard_client_foreach_total_privacy_count_of_privacy_02(void)
+{
+ __start_test(__FUNCTION__);
+
+ time_t start_date, end_date;
+
+ end_date = time(NULL);
+ start_date = end_date - (24 * 60 * 60) * 7; // almost 7 days
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - delete all logs
+ //////////////////////////////////////////////////////////////////////////
+ int res = __db_util_delete_all_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - add logs to each package
+ //////////////////////////////////////////////////////////////////////////
+ res = __db_util_add_test_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // positive case
+ //////////////////////////////////////////////////////////////////////////
+ res = privacy_guard_client_foreach_total_privacy_count_of_privacy(USER_ID_OWNER, start_date, end_date, __privacy_count_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ __finish_test();
+}
+
+static void __test_privacy_guard_client_foreach_privacy_count_by_privacy_id_01(void)
+{
+ __start_test(__FUNCTION__);
+
+ time_t start_date, end_date;
+ char privacy_id[LEN_PRIVACY_ID] = "http://tizen.org/privacy/location";
+
+ end_date = time(NULL);
+ start_date = end_date - (24 * 60 * 60) * 7; // almost 7 days
+
+ //////////////////////////////////////////////////////////////////////////
+ // positive case
+ //////////////////////////////////////////////////////////////////////////
+ int res = privacy_guard_client_foreach_privacy_count_by_privacy_id(USER_ID_OWNER, start_date, end_date, privacy_id, __privacy_count_of_package_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // negative cases
+ //////////////////////////////////////////////////////////////////////////
+ // invalid user id
+ res = privacy_guard_client_foreach_privacy_count_by_privacy_id(INVALID_USER_ID, start_date, end_date, privacy_id, __privacy_count_of_package_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ // invalid start date
+ res = privacy_guard_client_foreach_privacy_count_by_privacy_id(USER_ID_OWNER, -1, end_date, privacy_id, __privacy_count_of_package_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ // invalid end date
+ res = privacy_guard_client_foreach_privacy_count_by_privacy_id(USER_ID_OWNER, start_date, -1, privacy_id, __privacy_count_of_package_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ // invalid privacy id
+ res = privacy_guard_client_foreach_privacy_count_by_privacy_id(USER_ID_OWNER, start_date, -1, NULL, __privacy_count_of_package_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ __finish_test();
+}
+
+static void __test_privacy_guard_client_foreach_privacy_count_by_privacy_id_02(void)
+{
+ __start_test(__FUNCTION__);
+
+ time_t start_date, end_date;
+
+ end_date = time(NULL);
+ start_date = end_date - (24 * 60 * 60) * 7; // almost 7 days
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - delete all logs
+ //////////////////////////////////////////////////////////////////////////
+ int res = __db_util_delete_all_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - add logs to each package
+ //////////////////////////////////////////////////////////////////////////
+ res = __db_util_add_test_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // positive case
+ //////////////////////////////////////////////////////////////////////////
+ res = privacy_guard_client_foreach_privacy_count_by_privacy_id(USER_ID_OWNER, start_date, end_date, PRIVACY_ACCOUNT, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ res = privacy_guard_client_foreach_privacy_count_by_privacy_id(USER_ID_OWNER, start_date, end_date, PRIVACY_BOOKMARK, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ res = privacy_guard_client_foreach_privacy_count_by_privacy_id(USER_ID_OWNER, start_date, end_date, PRIVACY_CALENDAR, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ res = privacy_guard_client_foreach_privacy_count_by_privacy_id(USER_ID_OWNER, start_date, end_date, PRIVACY_CALL, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ res = privacy_guard_client_foreach_privacy_count_by_privacy_id(USER_ID_OWNER, start_date, end_date, PRIVACY_USERHISTORY, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ res = privacy_guard_client_foreach_privacy_count_by_privacy_id(USER_ID_OWNER, start_date, end_date, PRIVACY_CAMERA, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ res = privacy_guard_client_foreach_privacy_count_by_privacy_id(USER_ID_OWNER, start_date, end_date, PRIVACY_CONTACTS, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ res = privacy_guard_client_foreach_privacy_count_by_privacy_id(USER_ID_OWNER, start_date, end_date, PRIVACY_SENSOR, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ res = privacy_guard_client_foreach_privacy_count_by_privacy_id(USER_ID_OWNER, start_date, end_date, PRIVACY_LOCATION, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ res = privacy_guard_client_foreach_privacy_count_by_privacy_id(USER_ID_OWNER, start_date, end_date, PRIVACY_MESSAGE, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ res = privacy_guard_client_foreach_privacy_count_by_privacy_id(USER_ID_OWNER, start_date, end_date, PRIVACY_MICROPHONE, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ __finish_test();
+}
+
+static void __test_privacy_guard_client_foreach_privacy_count_by_package_id_01(void)
+{
+ __start_test(__FUNCTION__);
+
+ time_t start_date, end_date;
+ char *package_id;
+
+ package_id = (char*)g_list_first(all_package_list)->data;
+
+ end_date = time(NULL);
+ start_date = end_date - (24 * 60 * 60) * 7; // almost 7 days
+
+ //////////////////////////////////////////////////////////////////////////
+ // positive case
+ //////////////////////////////////////////////////////////////////////////
+ int res = privacy_guard_client_foreach_privacy_count_by_package_id(USER_ID_OWNER, start_date, end_date, package_id, __privacy_count_of_package_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // negative cases
+ //////////////////////////////////////////////////////////////////////////
+ // invalid user id
+ res = privacy_guard_client_foreach_privacy_count_by_package_id(INVALID_USER_ID, start_date, end_date, package_id, __privacy_count_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ // invalid start date
+ res = privacy_guard_client_foreach_privacy_count_by_package_id(USER_ID_OWNER, -1, end_date, package_id, __privacy_count_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ // invalid end date
+ res = privacy_guard_client_foreach_privacy_count_by_package_id(USER_ID_OWNER, start_date, -1, package_id, __privacy_count_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ // invalid privacy id
+ res = privacy_guard_client_foreach_privacy_count_by_package_id(USER_ID_OWNER, start_date, end_date, NULL, __privacy_count_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ __finish_test();
+}
+
+static void __test_privacy_guard_client_foreach_privacy_count_by_package_id_02(void)
+{
+ __start_test(__FUNCTION__);
+
+ time_t start_date, end_date;
+ int i;
+
+ end_date = time(NULL);
+ start_date = end_date - (24 * 60 * 60) * 7; // almost 7 days
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - delete all logs
+ //////////////////////////////////////////////////////////////////////////
+ int res = __db_util_delete_all_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - add logs to each package
+ //////////////////////////////////////////////////////////////////////////
+ res = __db_util_add_test_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // positive case
+ //////////////////////////////////////////////////////////////////////////
+ for (i = 0; i < (int)g_list_length(all_package_list); i++) {
+ char *package_id = (char*)g_list_nth_data(all_package_list, i);
+ if (package_id) {
+ res = privacy_guard_client_foreach_privacy_count_by_package_id(USER_ID_OWNER, start_date, end_date, package_id, __privacy_count_of_package_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ __finish_test();
+}
+
+static void __test_privacy_guard_client_update_monitor_policy_01(void)
+{
+ __start_test(__FUNCTION__);
+
+ int on = 1, off = 0;
+ char privacy_id[LEN_PRIVACY_ID] = "http://tizen.org/privacy/location";
+ char *package_id;
+
+ package_id = (char*)g_list_first(all_package_list)->data;
+
+ //////////////////////////////////////////////////////////////////////////
+ // positive case
+ //////////////////////////////////////////////////////////////////////////
+ int res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, privacy_id, on);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // negative cases
+ //////////////////////////////////////////////////////////////////////////
+ // invalid user id
+ res = privacy_guard_client_update_monitor_policy(INVALID_USER_ID, package_id, privacy_id, on);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ // invalid package_id
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, NULL, privacy_id, on);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ // invalid privacy id
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, NULL, off);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ __finish_test();
+}
+
+static void __test_privacy_guard_client_update_monitor_policy_02(void)
+{
+ __start_test(__FUNCTION__);
+
+ int off = 0;
+ int i;
+ TEST_DATA data;
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - delete all logs
+ //////////////////////////////////////////////////////////////////////////
+ int res = __db_util_delete_all_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - add logs to each package
+ //////////////////////////////////////////////////////////////////////////
+ res = __db_util_add_test_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // positive case
+ //////////////////////////////////////////////////////////////////////////
+ // LOCATION
+ for (i = 0; i < (int)g_list_length(package_list_using_location); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_location, i);
+ if (package_id) {
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_LOCATION, off);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_LOCATION, strlen(PRIVACY_LOCATION));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // ACCOUNT
+ for (i = 0; i < (int)g_list_length(package_list_using_account); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_account, i);
+ if (package_id) {
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_ACCOUNT, off);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_ACCOUNT, strlen(PRIVACY_ACCOUNT));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // BOOKMARK
+ for (i = 0; i < (int)g_list_length(package_list_using_bookmark); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_bookmark, i);
+ if (package_id) {
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_BOOKMARK, off);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_BOOKMARK, strlen(PRIVACY_BOOKMARK));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // CALENDAR
+ for (i = 0; i < (int)g_list_length(package_list_using_calendar); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_calendar, i);
+ if (package_id) {
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_CALENDAR, off);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_CALENDAR, strlen(PRIVACY_CALENDAR));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // CALL
+ for (i = 0; i < (int)g_list_length(package_list_using_call); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_call, i);
+ if (package_id) {
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_CALL, off);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_CALL, strlen(PRIVACY_CALL));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // USERHISTORY
+ for (i = 0; i < (int)g_list_length(package_list_using_userhistory); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_userhistory, i);
+ if (package_id) {
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_USERHISTORY, off);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_USERHISTORY, strlen(PRIVACY_USERHISTORY));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // CAMERA
+ for (i = 0; i < (int)g_list_length(package_list_using_camera); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_camera, i);
+ if (package_id) {
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_CAMERA, off);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_CAMERA, strlen(PRIVACY_CAMERA));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // CONTACTS
+ for (i = 0; i < (int)g_list_length(package_list_using_contacts); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_contacts, i);
+ if (package_id) {
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_CONTACTS, off);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_CONTACTS, strlen(PRIVACY_CONTACTS));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // MESSAGE
+ for (i = 0; i < (int)g_list_length(package_list_using_message); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_message, i);
+ if (package_id) {
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_MESSAGE, off);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_MESSAGE, strlen(PRIVACY_MESSAGE));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // MICROPHONE
+ for (i = 0; i < (int)g_list_length(package_list_using_microphone); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_microphone, i);
+ if (package_id) {
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_MICROPHONE, off);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_MICROPHONE, strlen(PRIVACY_MICROPHONE));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // SENSOR
+ for (i = 0; i < (int)g_list_length(package_list_using_sensor); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_sensor, i);
+ if (package_id) {
+ res = privacy_guard_client_update_monitor_policy(USER_ID_OWNER, package_id, PRIVACY_SENSOR, off);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_SENSOR, strlen(PRIVACY_SENSOR));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ __finish_test();
+}
+
+static void __test_privacy_guard_client_foreach_monitor_policy_by_package_id_01(void)
+{
+ __start_test(__FUNCTION__);
+
+ char *package_id;
+
+ package_id = (char*)g_list_first(all_package_list)->data;
+
+ //////////////////////////////////////////////////////////////////////////
+ // positive case
+ //////////////////////////////////////////////////////////////////////////
+ int res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // negative cases
+ //////////////////////////////////////////////////////////////////////////
+ // invalid user id
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(INVALID_USER_ID, package_id, __monitor_policy_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ // invalid package id
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, NULL, __monitor_policy_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ __finish_test();
+}
+
+static void __test_privacy_guard_client_foreach_monitor_policy_by_package_id_02(void)
+{
+ __start_test(__FUNCTION__);
+
+ int i;
+ TEST_DATA data;
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - delete all logs
+ //////////////////////////////////////////////////////////////////////////
+ int res = __db_util_delete_all_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - add logs to each package
+ //////////////////////////////////////////////////////////////////////////
+ res = __db_util_add_test_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // positive case
+ //////////////////////////////////////////////////////////////////////////
+ // LOCATION
+ for (i = 0; i < (int)g_list_length(package_list_using_location); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_location, i);
+ if (package_id) {
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_LOCATION, strlen(PRIVACY_LOCATION));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // ACCOUNT
+ for (i = 0; i < (int)g_list_length(package_list_using_account); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_account, i);
+ if (package_id) {
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_ACCOUNT, strlen(PRIVACY_ACCOUNT));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // BOOKMARK
+ for (i = 0; i < (int)g_list_length(package_list_using_bookmark); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_bookmark, i);
+ if (package_id) {
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_BOOKMARK, strlen(PRIVACY_BOOKMARK));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // CALENDAR
+ for (i = 0; i < (int)g_list_length(package_list_using_calendar); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_calendar, i);
+ if (package_id) {
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_CALENDAR, strlen(PRIVACY_CALENDAR));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // CALL
+ for (i = 0; i < (int)g_list_length(package_list_using_call); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_call, i);
+ if (package_id) {
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_CALL, strlen(PRIVACY_CALL));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // USERHISTORY
+ for (i = 0; i < (int)g_list_length(package_list_using_userhistory); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_userhistory, i);
+ if (package_id) {
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_USERHISTORY, strlen(PRIVACY_USERHISTORY));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // CAMERA
+ for (i = 0; i < (int)g_list_length(package_list_using_camera); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_camera, i);
+ if (package_id) {
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_CAMERA, strlen(PRIVACY_CAMERA));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // CONTACTS
+ for (i = 0; i < (int)g_list_length(package_list_using_contacts); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_contacts, i);
+ if (package_id) {
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_CONTACTS, strlen(PRIVACY_CONTACTS));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // MESSAGE
+ for (i = 0; i < (int)g_list_length(package_list_using_message); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_message, i);
+ if (package_id) {
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_MESSAGE, strlen(PRIVACY_MESSAGE));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // MICROPHONE
+ for (i = 0; i < (int)g_list_length(package_list_using_microphone); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_microphone, i);
+ if (package_id) {
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_MICROPHONE, strlen(PRIVACY_MICROPHONE));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ // SENSOR
+ for (i = 0; i < (int)g_list_length(package_list_using_sensor); i++) {
+ char *package_id = (char*)g_list_nth_data(package_list_using_sensor, i);
+ if (package_id) {
+ memset(&data, 0x0, sizeof(TEST_DATA));
+ strncpy(data.function_name, __FUNCTION__, strlen(__FUNCTION__));
+ strncpy(data.privacy_id, PRIVACY_SENSOR, strlen(PRIVACY_SENSOR));
+ strncpy(data.package_id, package_id, strlen(package_id));
+ res = privacy_guard_client_foreach_monitor_policy_by_package_id(USER_ID_OWNER, package_id, __monitor_policy_cb, &data);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ }
+ }
+
+ __finish_test();
+
+}
+
+static void __test_privacy_guard_client_check_privacy_package_01(void)
+{
+ __start_test(__FUNCTION__);
+
+ bool is_privacy_package = false;
+ char *package_id;
+
+ package_id = (char*)g_list_first(all_package_list)->data;
+
+ //////////////////////////////////////////////////////////////////////////
+ // positive case
+ //////////////////////////////////////////////////////////////////////////
+ int res = privacy_guard_client_check_privacy_package(USER_ID_OWNER, package_id, &is_privacy_package);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ __check_result_bool(true, is_privacy_package, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // negative cases
+ //////////////////////////////////////////////////////////////////////////
+ // invalid user id
+ res = privacy_guard_client_check_privacy_package(INVALID_USER_ID, package_id, &is_privacy_package);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ // invalid package id
+ res = privacy_guard_client_check_privacy_package(USER_ID_OWNER, NULL, &is_privacy_package);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ __finish_test();
+}
+
+static void __test_privacy_guard_client_check_privacy_package_02(void)
+{
+ __start_test(__FUNCTION__);
+
+ int i;
+ bool is_privacy_package = false;
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - delete all logs
+ //////////////////////////////////////////////////////////////////////////
+ int res = __db_util_delete_all_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - add logs to each package
+ //////////////////////////////////////////////////////////////////////////
+ res = __db_util_add_test_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // positive case
+ //////////////////////////////////////////////////////////////////////////
+ // LOCATION
+ for (i = 0; i < (int)g_list_length(all_package_list); i++) {
+ char *package_id = (char*)g_list_nth_data(all_package_list, i);
+ if (package_id) {
+ res = privacy_guard_client_check_privacy_package(USER_ID_OWNER, package_id, &is_privacy_package);
+ __check_result_bool(true, is_privacy_package, __LINE__);
+ }
+ }
+ __finish_test();
+}
+
+static void __test_privacy_guard_client_foreach_privacy_package_id(void)
+{
+ __start_test(__FUNCTION__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // positive case
+ //////////////////////////////////////////////////////////////////////////
+ int res = privacy_guard_client_foreach_package_id_using_privacy(USER_ID_OWNER, __package_id_cb, (char*)__FUNCTION__);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // negative cases
+ //////////////////////////////////////////////////////////////////////////
+ // invalid user id
+ res = privacy_guard_client_foreach_package_id_using_privacy(INVALID_USER_ID, __package_id_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ __finish_test();
+}
+
+static void __test_privacy_guard_client_foreach_package_info_by_privacy_id(void)
+{
+ __start_test(__FUNCTION__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - delete all logs
+ //////////////////////////////////////////////////////////////////////////
+ int res = __db_util_delete_all_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // preparation - add logs to each package
+ //////////////////////////////////////////////////////////////////////////
+ res = __db_util_add_test_logs();
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+ //////////////////////////////////////////////////////////////////////////
+ // positive case
+ //////////////////////////////////////////////////////////////////////////
+ res = privacy_guard_client_foreach_package_info_by_privacy_id(USER_ID_OWNER, PRIVACY_ACCOUNT, __package_info_cb, (char*)PRIVACY_ACCOUNT);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ res = privacy_guard_client_foreach_package_info_by_privacy_id(USER_ID_OWNER, PRIVACY_BOOKMARK, __package_info_cb, (char*)PRIVACY_BOOKMARK);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ res = privacy_guard_client_foreach_package_info_by_privacy_id(USER_ID_OWNER, PRIVACY_CALENDAR, __package_info_cb, (char*)PRIVACY_CALENDAR);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ res = privacy_guard_client_foreach_package_info_by_privacy_id(USER_ID_OWNER, PRIVACY_CALL, __package_info_cb, (char*)PRIVACY_CALL);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ res = privacy_guard_client_foreach_package_info_by_privacy_id(USER_ID_OWNER, PRIVACY_USERHISTORY, __package_info_cb, (char*)PRIVACY_USERHISTORY);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ res = privacy_guard_client_foreach_package_info_by_privacy_id(USER_ID_OWNER, PRIVACY_CAMERA, __package_info_cb, (char*)PRIVACY_CAMERA);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ res = privacy_guard_client_foreach_package_info_by_privacy_id(USER_ID_OWNER, PRIVACY_CONTACTS, __package_info_cb, (char*)PRIVACY_CONTACTS);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ res = privacy_guard_client_foreach_package_info_by_privacy_id(USER_ID_OWNER, PRIVACY_SENSOR, __package_info_cb, (char*)PRIVACY_SENSOR);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ res = privacy_guard_client_foreach_package_info_by_privacy_id(USER_ID_OWNER, PRIVACY_LOCATION, __package_info_cb, (char*)PRIVACY_LOCATION);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ res = privacy_guard_client_foreach_package_info_by_privacy_id(USER_ID_OWNER, PRIVACY_MESSAGE, __package_info_cb, (char*)PRIVACY_MESSAGE);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+ res = privacy_guard_client_foreach_package_info_by_privacy_id(USER_ID_OWNER, PRIVACY_MICROPHONE, __package_info_cb, (char*)PRIVACY_MICROPHONE);
+ __check_result_error_code(PRIV_GUARD_ERROR_SUCCESS, res, __LINE__);
+
+
+ //////////////////////////////////////////////////////////////////////////
+ // negative cases
+ //////////////////////////////////////////////////////////////////////////
+ // invalid user id
+ res = privacy_guard_client_foreach_package_info_by_privacy_id(INVALID_USER_ID, PRIVACY_LOCATION, __package_info_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ // invalid privacy id
+ res = privacy_guard_client_foreach_package_info_by_privacy_id(USER_ID_OWNER, NULL, __package_info_cb, NULL);
+ __check_result_error_code(PRIV_GUARD_ERROR_INVALID_PARAMETER, res, __LINE__);
+
+ __finish_test();
+}
+
+int main()
+{
+ __change_color_to_green();
+ printf("Test Start\n");
+ __change_color_to_origin();
+
+ __test_preparation();
+
+ /////////////////////////////////////////////////////////////////////////
+ // test cases ///////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////////////
+ __test_privacy_guard_client_foreach_total_privacy_count_of_package_01();
+ __test_privacy_guard_client_foreach_total_privacy_count_of_package_02();
+ __test_privacy_guard_client_foreach_total_privacy_count_of_privacy_01();
+ __test_privacy_guard_client_foreach_total_privacy_count_of_privacy_02();
+ __test_privacy_guard_client_foreach_privacy_count_by_privacy_id_01();
+ __test_privacy_guard_client_foreach_privacy_count_by_privacy_id_02();
+ __test_privacy_guard_client_foreach_privacy_count_by_package_id_01();
+ __test_privacy_guard_client_foreach_privacy_count_by_package_id_02();
+ __test_privacy_guard_client_update_monitor_policy_01();
+ __test_privacy_guard_client_update_monitor_policy_02();
+ __test_privacy_guard_client_foreach_monitor_policy_by_package_id_01();
+ __test_privacy_guard_client_foreach_monitor_policy_by_package_id_02();
+ __test_privacy_guard_client_check_privacy_package_01();
+ __test_privacy_guard_client_check_privacy_package_02();
+ __test_privacy_guard_client_foreach_privacy_package_id();
+ __test_privacy_guard_client_foreach_package_info_by_privacy_id();
+ //////////////////////////////////////////////////////////////////////////
+
+ __change_color_to_green();
+ printf("Test Complete\n");
+ printf("success : %d, ", success_cnt);
+ __change_color_to_red();
+ printf("fail : %d\n", fail_cnt);
+ __change_color_to_origin();
+
+ __test_termination();
+
+ return 0;
+}
+