summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhb.min <hb.min@samsung.com>2013-10-01 23:35:19 +0900
committerhb.min <hb.min@samsung.com>2013-10-01 23:35:19 +0900
commit77c9a55ff3b2874b44747dac1cf95ac4a3245585 (patch)
tree4ee929d1b3cea4aa167be4e98adeb755b079361e
parent06258caa75592e076fa3c6549b0344dc253d6644 (diff)
downloadprivacy-manager-77c9a55ff3b2874b44747dac1cf95ac4a3245585.tar.gz
privacy-manager-77c9a55ff3b2874b44747dac1cf95ac4a3245585.tar.bz2
privacy-manager-77c9a55ff3b2874b44747dac1cf95ac4a3245585.zip
Sync with tizen_2.2submit/tizen/20131002.061927
I added two features on Tizen 2.2 branch. This merges these features to Tizen 3.0 branch. Details of these features are below. Feature #1 [Requirement] The privacy-popup should be controlled by build configuration, instead of "testautomation" privilege. [Solution] Add controlling module of privacy-popup by build configuration and set default setting to disable. Feature #2 [Requirement] Unsupported features should not be displayed in “Setting > Privacy” menu. [Solution] Add feature filtering module for Privacy item. Change-Id: If2d025a50fcb67fe83a9ddba3c44607cff7b6105
-rw-r--r--client/CMakeLists.txt6
-rw-r--r--client/src/privacy_manager_client.cpp8
-rw-r--r--common/inc/PrivacyIdInfo.h11
-rw-r--r--common/inc/Utils.h24
-rw-r--r--common/src/PrivacyIdInfo.cpp140
-rw-r--r--pkgmgr_plugin/CMakeLists.txt7
-rw-r--r--pkgmgr_plugin/privileges.cpp13
-rw-r--r--res/opt/dbspace/.privacylist.dbbin11264 -> 11264 bytes
-rw-r--r--server/CMakeLists.txt2
9 files changed, 173 insertions, 38 deletions
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt
index 26c8cf8..6930aeb 100644
--- a/client/CMakeLists.txt
+++ b/client/CMakeLists.txt
@@ -41,6 +41,12 @@ 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-manager-client (executable)
diff --git a/client/src/privacy_manager_client.cpp b/client/src/privacy_manager_client.cpp
index 74a9ff1..fc01694 100644
--- a/client/src/privacy_manager_client.cpp
+++ b/client/src/privacy_manager_client.cpp
@@ -127,9 +127,15 @@ int privacy_manager_client_set_package_privacy(const char *package_id, const cha
int privacy_manager_client_check_user_consented(const char *package_id, bool *consented)
{
+
+#ifdef __PRIVACY_POPUP
PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();
return pInst->isUserPrompted(std::string(package_id), *consented);
+#else
+ *consented = true;
+ return PRIV_MGR_ERROR_SUCCESS;
+#endif
}
int privacy_manager_client_set_user_consented(const char *package_id, bool consented)
@@ -186,4 +192,4 @@ int privacy_manager_client_foreach_package_list_by_privacy(const char *privacy_i
}
return PRIV_MGR_ERROR_SUCCESS;
-} \ No newline at end of file
+}
diff --git a/common/inc/PrivacyIdInfo.h b/common/inc/PrivacyIdInfo.h
index dfd0d3b..a3ba526 100644
--- a/common/inc/PrivacyIdInfo.h
+++ b/common/inc/PrivacyIdInfo.h
@@ -24,17 +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 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 5663a76..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,34 +74,69 @@ 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;
+ }
+ privacyId = iter->second;
return PRIV_MGR_ERROR_SUCCESS;
}
int
-PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(const std::list < std::string> privilegeList, std::list < std::string> & privacyIdList)
+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)
+ {
+ if (privacyId.compare((iter->second)) == 0)
+ {
+ privilegeList.push_back(iter->first);
+ }
+ }
+
+ if (privilegeList.size() == 0)
+ {
+ LOGE("PrivilegeList of %s privacy is empty!", privacyId.c_str());
+ return PRIV_MGR_ERROR_NO_DATA;
+ }
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int
+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);
}
@@ -86,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);
}
@@ -111,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=?");
@@ -119,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
{
@@ -144,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=?");
@@ -152,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));
}
@@ -169,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/pkgmgr_plugin/CMakeLists.txt b/pkgmgr_plugin/CMakeLists.txt
index 40162b8..b8a0488 100644
--- a/pkgmgr_plugin/CMakeLists.txt
+++ b/pkgmgr_plugin/CMakeLists.txt
@@ -43,6 +43,13 @@ ADD_LIBRARY (${this_target} SHARED ${${this_target}_SOURCE_FILES} )
ADD_DEPENDENCIES(${this_target} privacy-manager-client)
## SET LINKER FLAGS
SET(CMAKE_SHARED_LINKER_FLAGS -Wl,--no-undefined)
+## 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)
+
TARGET_LINK_LIBRARIES(${this_target} ${pkg_LDFLAGS} ${pkg_LIBRARIES})
TARGET_LINK_LIBRARIES(${this_target} "-lprivacy-manager-client" "-L../client" )
diff --git a/pkgmgr_plugin/privileges.cpp b/pkgmgr_plugin/privileges.cpp
index 831bf42..1e6d61d 100644
--- a/pkgmgr_plugin/privileges.cpp
+++ b/pkgmgr_plugin/privileges.cpp
@@ -25,7 +25,6 @@
static const xmlChar _NODE_PRIVILEGES[] = "privileges";
static const xmlChar _NODE_PRIVILEGE[] = "privilege";
-static const char TEST_AUTOMATION_PRIVILEGE[] = "http://tizen.org/privilege/testautomation";
void destroy_char_list(char** ppList, int size)
{
@@ -43,7 +42,6 @@ __attribute__ ((visibility("default")))
int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
{
int ret;
- bool privacyPopupRequired = true;
// Node: <privileges>
xmlNodePtr curPtr = xmlFirstElementChild(xmlDocGetRootElement(docPtr));
@@ -67,11 +65,6 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
LOGE("Failed to get value");
return -EINVAL;
}
- if (strncmp(reinterpret_cast<char*>(pPrivilege), TEST_AUTOMATION_PRIVILEGE, strlen(TEST_AUTOMATION_PRIVILEGE) ) == 0 )
- {
- SECURE_LOGD("No privacy popup");
- privacyPopupRequired = false;
- }
else
{
privilegeList.push_back(std::string( reinterpret_cast<char*> (pPrivilege)));
@@ -97,7 +90,11 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
ppPrivilegeList[privilegeList.size()] = (char*)calloc (2, sizeof(char));
memcpy(ppPrivilegeList[privilegeList.size()], "\0", 1);
- ret = privacy_manager_client_install_privacy(packageId, (const char**) ppPrivilegeList, privacyPopupRequired);
+#ifdef __PRIVACY_POPUP
+ ret = privacy_manager_client_install_privacy(packageId, (const char**) ppPrivilegeList, true);
+#else
+ ret = privacy_manager_client_install_privacy(packageId, (const char**) ppPrivilegeList, false);
+#endif
destroy_char_list(ppPrivilegeList, privilegeList.size() + 1);
if (ret != PRIV_MGR_ERROR_SUCCESS)
{
diff --git a/res/opt/dbspace/.privacylist.db b/res/opt/dbspace/.privacylist.db
index e441411..7b9b282 100644
--- a/res/opt/dbspace/.privacylist.db
+++ b/res/opt/dbspace/.privacylist.db
Binary files differ
diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt
index e8e9676..f62ae61 100644
--- a/server/CMakeLists.txt
+++ b/server/CMakeLists.txt
@@ -7,7 +7,7 @@ SET(EXEC_PREFIX "\${prefix}")
SET(INCLUDEDIR "\${prefix}/include")
INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED dlog sqlite3 dbus-1 dbus-glib-1 db-util pkgmgr-info)
+pkg_check_modules(pkgs 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}")