diff options
author | hb.min <hb.min@samsung.com> | 2013-09-11 17:19:22 +0900 |
---|---|---|
committer | hb.min <hb.min@samsung.com> | 2013-09-12 13:38:02 +0900 |
commit | a4cda1e4677c62970d74b9767a4ed05eb1b0d135 (patch) | |
tree | a462d82cd935c6e0f59b21471b55aa849ded4fa4 | |
parent | 93957a4e7f12fc6fda720c765e4c86cd57751cd4 (diff) | |
download | privacy-manager-a4cda1e4677c62970d74b9767a4ed05eb1b0d135.tar.gz privacy-manager-a4cda1e4677c62970d74b9767a4ed05eb1b0d135.tar.bz2 privacy-manager-a4cda1e4677c62970d74b9767a4ed05eb1b0d135.zip |
Add feature filtering logic for privacy item
Change-Id: I7c81a87ab4928fc1a03e16235596577d56cf41dd
Signed-off-by: hb.min <hb.min@samsung.com>
-rw-r--r-- | client/CMakeLists.txt | 2 | ||||
-rw-r--r-- | common/inc/PrivacyIdInfo.h | 12 | ||||
-rw-r--r-- | common/inc/Utils.h | 24 | ||||
-rw-r--r-- | common/src/PrivacyIdInfo.cpp | 118 | ||||
-rwxr-xr-x | packaging/privacy-manager.spec | 3 | ||||
-rw-r--r-- | res/opt/dbspace/.privacylist.db | bin | 11264 -> 11264 bytes | |||
-rw-r--r-- | server/CMakeLists.txt | 2 |
7 files changed, 128 insertions, 33 deletions
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 9937442..58c2242 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -8,7 +8,7 @@ SET(LIBDIR "\${prefix}/lib") SET(INCLUDEDIR "\${prefix}/include") INCLUDE(FindPkgConfig) -pkg_check_modules(privacy-manager-client REQUIRED dlog sqlite3 dbus-1 dbus-glib-1 db-util pkgmgr-info) +pkg_check_modules(privacy-manager-client REQUIRED dlog sqlite3 dbus-1 dbus-glib-1 db-util pkgmgr-info capi-system-info) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/common/inc/PrivacyIdInfo.h b/common/inc/PrivacyIdInfo.h index fbe3d53..a3ba526 100644 --- a/common/inc/PrivacyIdInfo.h +++ b/common/inc/PrivacyIdInfo.h @@ -24,18 +24,20 @@ class PrivacyIdInfo { private: - static std::map <std::string, std::string> m_privilegeToPrivacyMap; + static std::map< std::string, std::string > m_privilegeToPrivacyMap; static bool m_isInitialized; public: static int initialize(void); static int getPrivacyIdFromPrivilege(const std::string privilege, std::string& privacyId); - static int getPrivilegeListFromPrivacyId(const std::string privacyId, std::list < std::string> & privilegeList); - static int getPrivacyIdListFromPrivilegeList(const std::list < std::string> privilegeList, std::list < std::string> & privacyIdList); - static int getAllPrivacyId(std::list < std::string >& privacyIdList); + static int getPrivilegeListFromPrivacyId(const std::string privacyId, std::list< std::string > & privilegeList); + static int getPrivacyIdListFromPrivilegeList(const std::list< std::string > privilegeList, std::list< std::string >& privacyIdList); + static int getAllPrivacyId(std::list< std::string >& privacyIdList); static int getPrivaycDisplayName(const std::string privacyId, std::string& displayName); static int getPrivaycDescription(const std::string privacyId, std::string& description); + + static int isFeatureEnabled(const char* feature, bool& enabled); }; -#endif //_PRIVACY_ID_INFO_H_
\ No newline at end of file +#endif //_PRIVACY_ID_INFO_H_ diff --git a/common/inc/Utils.h b/common/inc/Utils.h index 1e7c94e..53bd238 100644 --- a/common/inc/Utils.h +++ b/common/inc/Utils.h @@ -24,6 +24,7 @@ #include <sqlite3.h> #include <memory> #include <string> +#include <unistd.h> #include <db-util.h> #define TryCatchLogReturn(condition, expr, r, logFormat) if (!(condition)) { \ @@ -56,14 +57,29 @@ auto DbDeleter = [&](sqlite3* pPtr) { /*sqlite3_close(pPtr);*/ db_util_close(pPt {\ /*int res = sqlite3_open_v2(dbpath, &pHandler##Temp, mode , NULL);*/\ int res = db_util_open_with_options(dbpath, &pHandler##Temp, mode, NULL);\ - TryCatchResLogReturn( res == SQLITE_OK, , PRIV_MGR_ERROR_DB_ERROR, "db_util_open_with_options : %d", res);\ + TryCatchResLogReturn(res == SQLITE_OK, , PRIV_MGR_ERROR_DB_ERROR, "db_util_open_with_options : %d", res);\ }\ setDbToUniquePtr(pHandler, pHandler##Temp);\ - + +static const int MAX_DATABASE_RETRY_COUNT = 5; +static const int SLEEP_TIME = 50000; #define prepareDb(pHandler, sql, pStmt) sqlite3_stmt* pStmt##Temp;\ {\ - int res = sqlite3_prepare_v2(pHandler.get(), sql, -1, & pStmt##Temp, NULL);\ - TryCatchResLogReturn( res == SQLITE_OK, , PRIV_MGR_ERROR_DB_ERROR, "sqlite3_prepare_v2 : %d", res);\ + int res = SQLITE_OK;\ + for (int dbRetryCount = 0; dbRetryCount < MAX_DATABASE_RETRY_COUNT; dbRetryCount++)\ + {\ + res = sqlite3_prepare_v2(pHandler.get(), sql, -1, & pStmt##Temp, NULL);\ + if (res != SQLITE_BUSY)\ + {\ + break;\ + }\ + else\ + {\ + LOGE("[DbRetryCount][%d]: Database is busy!", dbRetryCount); \ + usleep(SLEEP_TIME);\ + }\ + }\ + TryCatchResLogReturn(res == SQLITE_OK, , PRIV_MGR_ERROR_DB_ERROR, "sqlite3_prepare_v2 : %d", res);\ }\ setStmtToUniquePtr(pStmt, pStmt##Temp); diff --git a/common/src/PrivacyIdInfo.cpp b/common/src/PrivacyIdInfo.cpp index 0662443..5102c53 100644 --- a/common/src/PrivacyIdInfo.cpp +++ b/common/src/PrivacyIdInfo.cpp @@ -21,24 +21,48 @@ #include <set> #include <Utils.h> #include <libintl.h> +#include <system_info.h> -std::map <std::string, std::string> PrivacyIdInfo::m_privilegeToPrivacyMap; +std::map< std::string, std::string > PrivacyIdInfo::m_privilegeToPrivacyMap; bool PrivacyIdInfo:: m_isInitialized; int PrivacyIdInfo::initialize(void) { static const std::string sqlPrivilege("SELECT PRIVILEGE_ID, PRIVACY_ID from PrivilegeToPrivacyTable"); + static const std::string sqlPrivacyInfo("SELECT FEATURE FROM PrivacyInfo where PRIVACY_ID=?"); openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY); prepareDb(pDbHandler, sqlPrivilege.c_str(), pStmtPrivilege); int res; - while ( (res = sqlite3_step(pStmtPrivilege.get())) == SQLITE_ROW ) + while ((res = sqlite3_step(pStmtPrivilege.get())) == SQLITE_ROW) { const char* privilegeId = reinterpret_cast < const char* > (sqlite3_column_text(pStmtPrivilege.get(), 0)); const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pStmtPrivilege.get(), 1)); - m_privilegeToPrivacyMap.insert(std::map < std::string, std::string >::value_type(std::string(privilegeId), std::string(privacyId))); + + prepareDb(pDbHandler, sqlPrivacyInfo.c_str(), pStmtPrivacyInfo); + res = sqlite3_bind_text(pStmtPrivacyInfo.get(), 1, privacyId, -1, SQLITE_TRANSIENT); + TryReturn(res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); + res = sqlite3_step(pStmtPrivacyInfo.get()); + LOGD("privacy id : %s", privacyId); + TryReturn(res == SQLITE_DONE || res == SQLITE_ROW, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res); + + const char* feature = reinterpret_cast < const char* > (sqlite3_column_text(pStmtPrivacyInfo.get(), 0)); + if (feature != NULL) + { + bool isSupported = false; + + res = isFeatureEnabled(feature, isSupported); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "isFeatureEnabled : %d", res); + + if (!isSupported) + { + continue; + } + } + + m_privilegeToPrivacyMap.insert(std::map< std::string, std::string >::value_type(std::string(privilegeId), std::string(privacyId))); } m_isInitialized = true; @@ -50,23 +74,30 @@ int PrivacyIdInfo::getPrivacyIdFromPrivilege(const std::string privilege, std::string& privacyId) { if (!m_isInitialized) + { initialize(); - std::map < std::string, std::string >::iterator iter = m_privilegeToPrivacyMap.find(privilege); + } + + std::map< std::string, std::string >::iterator iter = m_privilegeToPrivacyMap.find(privilege); if (iter == m_privilegeToPrivacyMap.end()) + { return PRIV_MGR_ERROR_NO_DATA; + } privacyId = iter->second; return PRIV_MGR_ERROR_SUCCESS; } int -PrivacyIdInfo::getPrivilegeListFromPrivacyId(const std::string privacyId, std::list < std::string> & privilegeList) +PrivacyIdInfo::getPrivilegeListFromPrivacyId(const std::string privacyId, std::list< std::string >& privilegeList) { if (!m_isInitialized) + { initialize(); + } privilegeList.clear(); - for (std::map < std::string, std::string >::iterator iter = m_privilegeToPrivacyMap.begin(); iter != m_privilegeToPrivacyMap.end(); ++iter) + for (std::map< std::string, std::string >::iterator iter = m_privilegeToPrivacyMap.begin(); iter != m_privilegeToPrivacyMap.end(); ++iter) { if (privacyId.compare((iter->second)) == 0) { @@ -84,24 +115,28 @@ PrivacyIdInfo::getPrivilegeListFromPrivacyId(const std::string privacyId, std::l } int -PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(const std::list < std::string> privilegeList, std::list < std::string> & privacyIdList) +PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(const std::list< std::string > privilegeList, std::list< std::string >& privacyIdList) { if (!m_isInitialized) + { initialize(); + } privacyIdList.clear(); - std::set <std::string> privacyIdSet; + std::set< std::string > privacyIdSet; - for (std::list < std::string > ::const_iterator iter = privilegeList.begin(); iter != privilegeList.end(); ++iter) + for (std::list< std::string >::const_iterator iter = privilegeList.begin(); iter != privilegeList.end(); ++iter) { std::string privacyId; int res = getPrivacyIdFromPrivilege(*iter, privacyId); if (res == PRIV_MGR_ERROR_SUCCESS) + { privacyIdSet.insert(privacyId); + } } - - for (std::set < std::string >::iterator iter = privacyIdSet.begin(); iter != privacyIdSet.end(); ++iter) + + for (std::set< std::string >::iterator iter = privacyIdSet.begin(); iter != privacyIdSet.end(); ++iter) { privacyIdList.push_back(*iter); } @@ -110,20 +145,36 @@ PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(const std::list < std::string> } int -PrivacyIdInfo::getAllPrivacyId(std::list < std::string >& privacyIdList) +PrivacyIdInfo::getAllPrivacyId(std::list< std::string >& privacyIdList) { - static const std::string sql("SELECT PRIVACY_ID from PrivacyInfo"); + static const std::string sql("SELECT PRIVACY_ID, FEATURE from PrivacyInfo"); if (!m_isInitialized) + { initialize(); - + } + openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY); prepareDb(pDbHandler, sql.c_str(), pStmt); int res; - while ( (res = sqlite3_step(pStmt.get())) == SQLITE_ROW ) + while ((res = sqlite3_step(pStmt.get())) == SQLITE_ROW) { - const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0)); + const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0)); + const char* feature = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 1)); + LOGD("privacy: %s, feature: %s", privacyId, feature); + + if (feature != NULL) + { + bool isSupported = false; + res = isFeatureEnabled(feature, isSupported); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "isFeatureEnabled : %d", res); + if (!isSupported) + { + continue; + } + } + privacyIdList.push_back(std::string(privacyId)); SECURE_LOGD(" privacy Id : %s", privacyId); } @@ -135,7 +186,9 @@ int PrivacyIdInfo::getPrivaycDisplayName(const std::string privacyId, std::string& displayName) { if (!m_isInitialized) + { initialize(); + } std::string sql = std::string("SELECT STR_MODULE_ID, STR_NAME_ID from PrivacyInfo where PRIVACY_ID=?"); @@ -143,17 +196,21 @@ PrivacyIdInfo::getPrivaycDisplayName(const std::string privacyId, std::string& d prepareDb(pDbHandler, sql.c_str(), pStmt); int res = sqlite3_bind_text(pStmt.get(), 1, privacyId.c_str(), -1, SQLITE_TRANSIENT); - TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); + TryReturn(res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); - if ( sqlite3_step(pStmt.get()) == SQLITE_ROW ) + if (sqlite3_step(pStmt.get()) == SQLITE_ROW) { const char* pModuleId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0)); const char* pNameId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 1)); if (pNameId == NULL) + { displayName = privacyId; + } else + { displayName = std::string(dgettext(pModuleId, pNameId)); + } } else { @@ -168,7 +225,9 @@ int PrivacyIdInfo::getPrivaycDescription(const std::string privacyId, std::string& displayName) { if (!m_isInitialized) + { initialize(); + } std::string sql = std::string("SELECT STR_MODULE_ID, STR_NAME_ID from PrivacyInfo where PRIVACY_ID=?"); @@ -176,12 +235,12 @@ PrivacyIdInfo::getPrivaycDescription(const std::string privacyId, std::string& d prepareDb(pDbHandler, sql.c_str(), pStmt); int res = sqlite3_bind_text(pStmt.get(), 1, privacyId.c_str(), -1, SQLITE_TRANSIENT); - TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); + TryReturn(res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); - if ( sqlite3_step(pStmt.get()) == SQLITE_ROW ) + if (sqlite3_step(pStmt.get()) == SQLITE_ROW) { const char* pModuleId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0)); - const char* pNameId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0)); + const char* pNameId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 1)); displayName = std::string(dgettext(pModuleId, pNameId)); } @@ -193,3 +252,20 @@ PrivacyIdInfo::getPrivaycDescription(const std::string privacyId, std::string& d return PRIV_MGR_ERROR_SUCCESS; } + +int +PrivacyIdInfo::isFeatureEnabled(const char* feature, bool& enabled) +{ + int res = PRIV_MGR_ERROR_SUCCESS; + + if (feature == NULL) + { + enabled = true; + return res; + } + + res = system_info_get_platform_bool(feature, &enabled); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, PRIV_MGR_ERROR_SYSTEM_ERROR, , "system_info_get_platform_bool : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; +} diff --git a/packaging/privacy-manager.spec b/packaging/privacy-manager.spec index 4c78fee..e3036e4 100755 --- a/packaging/privacy-manager.spec +++ b/packaging/privacy-manager.spec @@ -1,6 +1,6 @@ Name: privacy-manager-server Summary: Privacy Management -Version: 0.0.4 +Version: 0.0.5 Release: 0 Group: System/Libraries License: SAMSUNG @@ -15,6 +15,7 @@ BuildRequires: pkgconfig(dbus-1) BuildRequires: pkgconfig(dbus-glib-1) BuildRequires: pkgconfig(db-util) BuildRequires: pkgconfig(pkgmgr-info) +BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(libprivilege-control) BuildRequires: pkgconfig(security-server) BuildRequires: gettext-tools diff --git a/res/opt/dbspace/.privacylist.db b/res/opt/dbspace/.privacylist.db Binary files differindex b8ba047..7b9b282 100644 --- a/res/opt/dbspace/.privacylist.db +++ b/res/opt/dbspace/.privacylist.db diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index fa8a791..a7334e5 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -8,7 +8,7 @@ SET(LIBDIR "\${prefix}/lib") SET(INCLUDEDIR "\${prefix}/include") INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED dlog sqlite3 dbus-1 dbus-glib-1 db-util pkgmgr-info security-server) +pkg_check_modules(pkgs REQUIRED dlog sqlite3 dbus-1 dbus-glib-1 db-util pkgmgr-info capi-system-info security-server) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") |