ADD_SUBDIRECTORY(client)\r
#ADD_SUBDIRECTORY(test)\r
ADD_SUBDIRECTORY(capi)\r
+ADD_SUBDIRECTORY(pkgmgr_plugin)\r
${common_src_dir}/SocketStream.cpp
${common_src_dir}/PrivacyIdInfo.cpp
${client_src_dir}/SocketClient.cpp
- ${client_src_dir}/PrivacyManager.cpp
+ ${client_src_dir}/PrivacyManagerClient.cpp
${client_src_dir}/PrivacyChecker.cpp
${client_src_dir}/privacy_checker_client.cpp
${client_src_dir}/privacy_info_client.cpp
${client_src_dir}/privacy_manager_client.cpp
)
SET(PRIVACY_MANAGER_CLIENT_HEADERS
- ${client_include_dir}/PrivacyManager.h
- ${client_include_dir}/PrivacyChecker.h
+ ${client_include_dir}/PrivacyManagerClient.h
${client_include_dir}/PrivacyChecker.h
${client_include_dir}/privacy_info_client.h
${client_include_dir}/privacy_manager_client.h
class EXTERN_API PrivacyChecker\r
{\r
private:\r
- static const std::string DB_PATH;\r
static std::map < std::string, bool > m_privacyCache;\r
+ static std::map < std::string, std::map < std::string, bool > > m_privacyInfoCache;\r
static std::string m_pkgId;\r
static bool m_isInitialized;\r
static std::mutex m_cacheMutex;\r
private:\r
static int initializeDbus(void);\r
static int finalizeDbus(void);\r
- static int getUniqueIdFromPackageId(const std::string pkgId, int& uniqueId);\r
- static int updateCache(void);\r
- static int updateCache(const std::string privacyId);\r
+ static int updateCache(const std::string pkgId, std::string privacyId, std::map < std::string, bool >& pkgCacheMap);\r
+ static int updateCache(const std::string privacyId, std::map < std::string, bool >& pkgCacheMap);\r
+ static int updateCache(std::map < std::string, bool >& pkgCacheMap);\r
static void printCache(void);\r
static void* runSignalListenerThread(void* pData);\r
static int getCurrentPkgId(std::string& pkgId);\r
+ static int check(const std::string privacyId, std::map < std::string, bool >& privacyMap);\r
\r
public:\r
+ // for Checking in App Process\r
static int initialize(const std::string pkgId);\r
+ static int check(const std::string pkgId, const std::string privacyId);\r
+ static int checkWithPrivilege(const std::string pkgId, const std::string privilegeId);\r
+ static int checkWithDeviceCap(const std::string pkgId, const std::string deviceCap);\r
+ \r
+ // for Checking in Server Process\r
+ static int initialize(void); \r
static int check(const std::string privacyId);\r
+ static int checkWithPrivilege(const std::string privilegeId);\r
+ static int checkWithDeviceCap(const std::string deviceCap);\r
+ \r
+ // common \r
static int finalize(void);\r
static DBusHandlerResult handleNotification(DBusConnection* connection, DBusMessage* message, void* user_data);\r
};\r
\r
class SocketClient;\r
\r
-class EXTERN_API PrivacyManager\r
+class EXTERN_API PrivacyManagerClient\r
{\r
private:\r
- static PrivacyManager* m_pInstance;\r
+ static PrivacyManagerClient* m_pInstance;\r
static const std::string INTERFACE_NAME;\r
\r
std::unique_ptr< SocketClient > m_pSocketClient;\r
\r
static std::mutex m_singletonMutex;\r
\r
- PrivacyManager();\r
- ~PrivacyManager();\r
+ PrivacyManagerClient();\r
+ ~PrivacyManagerClient();\r
\r
public:\r
- static PrivacyManager* getInstance(void);\r
+ static PrivacyManagerClient* getInstance(void);\r
\r
int addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& list);\r
\r
* limitations under the License. \r
*/\r
\r
-#ifndef _PRIVACY_INFO_CLIENT_H\r
-#define _PRIVACY_INFO_CLIENT_H\r
+#ifndef _PRIVACY_CHECKER_CLIENT_H\r
+#define _PRIVACY_CHECKER_CLIENT_H\r
\r
#include <privacy_manager_client_types.h>\r
\r
\r
EXTERN_API int privacy_checker_initialize(const char *package_id);\r
EXTERN_API int privacy_checker_check_privacy(const char *privacy_id);\r
-EXTERN_API int privacy_checker_check_privacy_by_privilege(const char *privilege_id);\r
-EXTERN_API int privacy_checker_check_privacy_by_device_cap(const char *device_cap);\r
+EXTERN_API int privacy_checker_check_by_privilege(const char *privilege_id);\r
+EXTERN_API int privacy_checker_check_by_device_cap(const char *device_cap);\r
+EXTERN_API int privacy_checker_finalize(void);\r
+\r
+EXTERN_API int privacy_checker_check_package_by_privilege(const char* package_id, const char *privilege_id);\r
+EXTERN_API int privacy_checker_check_package_by_device_cap(const char* package_id, const char *device_cap);\r
+\r
EXTERN_API int privacy_checker_finalize(void);\r
\r
#ifdef __cplusplus\r
#endif\r
\r
\r
-#endif //_PRIVACY_INFO_CLIENT_H\r
+#endif //_PRIVACY_CHECKER_CLIENT_H\r
EXTERN_API int privacy_manager_client_foreach_get_privacy_info(const char *package_id, privacy_manager_client_privacy_info_cb callback, void* user_data);\r
EXTERN_API int privacy_manager_client_set_package_privacy(const char *package_id, const char *privacy_id, bool enable);\r
\r
+EXTERN_API int privacy_manager_client_check_user_consented(const char *package_id, bool consented);\r
\r
#ifdef __cplusplus\r
}\r
*/\r
\r
#include <PrivacyChecker.h>\r
-#include <PrivacyManager.h>\r
+#include <PrivacyIdInfo.h>\r
+#include <PrivacyManagerClient.h>\r
#include <SocketClient.h>\r
#include <algorithm> \r
#include <memory>\r
#include <unistd.h>\r
\r
bool PrivacyChecker::m_isInitialized = false;\r
-const std::string PrivacyChecker::DB_PATH("/opt/dbspace/.privacy.db");\r
std::map < std::string, bool >PrivacyChecker::m_privacyCache;\r
+std::map < std::string, std::map < std::string, bool > > PrivacyChecker::m_privacyInfoCache;\r
std::mutex PrivacyChecker::m_cacheMutex;\r
std::string PrivacyChecker::m_pkgId;\r
DBusConnection* PrivacyChecker::m_pDBusConnection;\r
const int MAX_LOCAL_BUF_SIZE = 128;\r
\r
int\r
-PrivacyChecker::getUniqueIdFromPackageId(const std::string pkgId, int& uniqueId)\r
+PrivacyChecker::initialize(const std::string pkgId)\r
{\r
LOGI("enter");\r
- std::string PkgIdQuery = std::string("SELECT UNIQUE_ID from PackageInfo where PKG_ID=?");\r
\r
- int res;\r
- openDb(DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY);\r
- prepareDb(pDbH, PkgIdQuery.c_str(), pStmt);\r
+ if (m_isInitialized)\r
+ return PRIV_MGR_ERROR_SUCCESS;\r
\r
- res = sqlite3_bind_text(pStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
- TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_IO_ERROR, , "sqlite3_bind_text : %d", res);\r
+ m_pkgId = pkgId;\r
\r
- res = sqlite3_step(pStmt.get());\r
- TryReturn( res == SQLITE_ROW, PRIV_MGR_ERROR_IO_ERROR, , "sqlite3_step : %d", res);\r
+ std::lock_guard < std::mutex > guard(m_cacheMutex);\r
+\r
+ int res = updateCache(m_privacyCache);\r
+ TryReturn(res == 0, res, m_pkgId.clear(), "Failed to update cache : %d", res);\r
\r
- uniqueId = sqlite3_column_int(pStmt.get(), 0);\r
- LOGI("%s : %d", pkgId.c_str(), uniqueId);\r
+ res = initialize();\r
+ TryReturn(res == 0, res, m_pkgId.clear(), "Failed to initialize() : %d", res);\r
\r
- LOGI("leave");\r
return PRIV_MGR_ERROR_SUCCESS;\r
}\r
\r
int\r
-PrivacyChecker::initialize(const std::string pkgId)\r
+PrivacyChecker::initialize(void)\r
{\r
LOGI("enter");\r
\r
res = pthread_create(&signalThread, NULL, &runSignalListenerThread, NULL);\r
TryReturn(res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, errno = res;, "Failed to create listener thread :%s", strerror(res));\r
\r
- m_pkgId = pkgId;\r
- res = updateCache();\r
- TryReturn(res == 0, res, m_pkgId.clear(), "Failed to update cache : %d", res);\r
-\r
m_isInitialized = true;\r
\r
LOGI("leave");\r
char* pPkgId;\r
char* pPrivacyId;\r
\r
+ LOGI("enter");\r
+\r
if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_NAME.c_str()))\r
{\r
r = dbus_message_get_args(message, &error,\r
DBUS_TYPE_INVALID);\r
TryReturn(r, DBUS_HANDLER_RESULT_NOT_YET_HANDLED, , "Fail to get data : %s", error.message);\r
\r
+ std::lock_guard < std::mutex > guard(m_cacheMutex);\r
+\r
if (std::string(pPkgId) == m_pkgId)\r
{\r
LOGI("Current app pkg privacy information updated");\r
- updateCache(pPrivacyId);\r
+ updateCache(pPrivacyId, m_privacyCache);\r
printCache();\r
}\r
+\r
+ std::map < std::string, std::map < std::string, bool > > :: iterator iter = m_privacyInfoCache.find(std::string(pPkgId));\r
+ if (iter != m_privacyInfoCache.end())\r
+ {\r
+ LOGI("Current pkg privacy is in cache");\r
+ updateCache(std::string(pPkgId), pPrivacyId, iter->second);\r
+ }\r
+ \r
}\r
else\r
{\r
}\r
\r
int\r
-PrivacyChecker::check(const std::string privacyId)\r
+PrivacyChecker::check(const std::string privacyId, std::map < std::string, bool >& privacyMap)\r
{\r
LOGI("enter");\r
\r
- std::lock_guard < std::mutex > guard(m_cacheMutex);\r
+ TryReturn(m_isInitialized, PRIV_MGR_ERROR_NOT_INITIALIZED, , "Not initialized");\r
\r
- TryReturn(m_isInitialized, -1, , "Not initialized");\r
-\r
- std::map < std::string, bool >::const_iterator iter = m_privacyCache.find(privacyId);\r
- if (iter == m_privacyCache.end() )\r
+ std::map < std::string, bool >::const_iterator iter = privacyMap.find(privacyId);\r
+ if (iter == privacyMap.end() )\r
{\r
LOGD("NO matcheded");\r
- return -1;\r
+ return PRIV_MGR_ERROR_USER_NOT_CONSENTED;\r
}\r
else if (!iter->second)\r
{\r
LOGD("NOT allowed");\r
- return -1;\r
+ return PRIV_MGR_ERROR_USER_NOT_CONSENTED;\r
}\r
LOGD("OK");\r
\r
}\r
\r
int\r
-PrivacyChecker::finalize(void)\r
+PrivacyChecker::check(const std::string privacyId)\r
{\r
- std::lock_guard <std::mutex> guard (m_cacheMutex);\r
- m_privacyCache.clear();\r
- \r
- if (m_pLoop != NULL)\r
+ LOGI("enter");\r
+\r
+ if (!m_isInitialized)\r
+ return PRIV_MGR_ERROR_NOT_INITIALIZED;\r
+\r
+ std::lock_guard < std::mutex > guard(m_cacheMutex);\r
+\r
+ int res = check(privacyId, m_privacyCache);\r
+\r
+ LOGI("leave");\r
+\r
+ return res;\r
+}\r
+\r
+int\r
+PrivacyChecker::check(const std::string pkgId, const std::string privacyId)\r
+{\r
+ LOGI("enter");\r
+\r
+ if (!m_isInitialized)\r
+ initialize();\r
+ std::lock_guard < std::mutex > guard(m_cacheMutex);\r
+ int res;\r
+\r
+ std::map < std::string, std::map < std::string, bool > >::iterator iter = m_privacyInfoCache.find(pkgId);\r
+ if (iter == m_privacyInfoCache.end() )\r
{\r
- g_main_loop_quit(m_pLoop);\r
- m_pLoop = NULL;\r
+ std::map < std::string, bool > pkgCacheMap;\r
+ res = updateCache(pkgCacheMap);\r
+ TryReturn( res == PRIV_MGR_ERROR_SUCCESS, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
+\r
+ m_privacyInfoCache.insert( std::map < std::string, std::map < std::string, bool > >::value_type(std::string(pkgId), pkgCacheMap));\r
+ iter = m_privacyInfoCache.find(pkgId);\r
}\r
+ if (iter->second.size() == 0)\r
+ return PRIV_MGR_ERROR_USER_NOT_CONSENTED;\r
\r
- m_isInitialized = false;\r
+ res = check(privacyId, iter->second);\r
\r
- return PRIV_MGR_ERROR_SUCCESS;\r
+ LOGI("leave");\r
+\r
+ return res;\r
}\r
\r
int\r
-PrivacyChecker::updateCache(void)\r
+PrivacyChecker::checkWithPrivilege(const std::string pkgId, const std::string privilege)\r
{\r
LOGI("enter");\r
- static const std::string PrivacyQuery = "SELECT PRIVACY_ID, IS_ENABLED from Privacy where ID=?";\r
- \r
- std::lock_guard < std::mutex > guard(m_cacheMutex);\r
\r
- int res;\r
- int id;\r
- res = getUniqueIdFromPackageId(m_pkgId, id);\r
- TryReturn( res == 0, -1, , "getUniqueIdFromPackageId : %d", res);\r
- LOGD("id : %d" ,id);\r
- \r
- openDb(DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY);\r
- prepareDb(pDbH, PrivacyQuery.c_str(), pPrivacyStmt);\r
- res = sqlite3_bind_int(pPrivacyStmt.get(), 1, id);\r
- TryReturn( res == 0, -1, , "sqlite3_bind_int : %d", res);\r
+ std::string privacyId;\r
+ int res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId);\r
+ if (res == PRIV_MGR_ERROR_NO_DATA)\r
+ return PRIV_MGR_ERROR_USER_NOT_CONSENTED;\r
+ TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res);\r
\r
+ LOGI("leave");\r
\r
- while ( sqlite3_step(pPrivacyStmt.get()) == SQLITE_ROW )\r
- {\r
- LOGI("start");\r
- const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pPrivacyStmt.get(), 0));\r
- bool privacyEnabled = sqlite3_column_int(pPrivacyStmt.get(), 1) > 0 ? true : false;\r
+ return check(pkgId, privacyId);\r
+}\r
+\r
+int\r
+PrivacyChecker::checkWithPrivilege(const std::string privilege)\r
+{\r
+ LOGI("enter");\r
\r
- m_privacyCache.insert(std::map < std::string, bool >::value_type(std::string(privacyId), privacyEnabled));\r
+ std::string privacyId;\r
+ int res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId);\r
+ if (res == PRIV_MGR_ERROR_NO_DATA)\r
+ return PRIV_MGR_ERROR_USER_NOT_CONSENTED;\r
+ TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res);\r
+\r
+ LOGI("leave");\r
+\r
+ return check(privacyId);\r
+}\r
+\r
+int\r
+PrivacyChecker::checkWithDeviceCap(const std::string pkgId, const std::string deviceCap)\r
+{\r
+ LOGI("enter");\r
+\r
+ std::string privacyId;\r
+ int res = PrivacyIdInfo::getPrivacyIdFromDeviceCap(deviceCap, privacyId);\r
+ if (res == PRIV_MGR_ERROR_NO_DATA)\r
+ return PRIV_MGR_ERROR_USER_NOT_CONSENTED;\r
+ TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res);\r
\r
- LOGD("Privacy found : %s %d", privacyId, privacyEnabled);\r
- }\r
LOGI("leave");\r
+\r
+ return check(pkgId ,privacyId);\r
+}\r
+\r
+int\r
+PrivacyChecker::checkWithDeviceCap(const std::string deviceCap)\r
+{\r
+ LOGI("enter");\r
+\r
+ std::string privacyId;\r
+ int res = PrivacyIdInfo::getPrivacyIdFromDeviceCap(deviceCap, privacyId);\r
+ if (res == PRIV_MGR_ERROR_NO_DATA)\r
+ return PRIV_MGR_ERROR_USER_NOT_CONSENTED;\r
+ TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res);\r
+\r
+ LOGI("leave");\r
+\r
+ return check(privacyId);\r
+}\r
+\r
+int\r
+PrivacyChecker::finalize(void)\r
+{\r
+ std::lock_guard <std::mutex> guard (m_cacheMutex);\r
+ m_privacyCache.clear();\r
+ m_privacyInfoCache.clear();\r
+ \r
+ if (m_pLoop != NULL)\r
+ {\r
+ g_main_loop_quit(m_pLoop);\r
+ m_pLoop = NULL;\r
+ }\r
+\r
+ m_isInitialized = false;\r
+\r
return PRIV_MGR_ERROR_SUCCESS;\r
}\r
+\r
void\r
PrivacyChecker::printCache(void)\r
{\r
LOGD(" %s : %d", iter->first.c_str(), iter->second);\r
}\r
}\r
+\r
int\r
-PrivacyChecker::updateCache(const std::string privacyId)\r
+PrivacyChecker::updateCache(const std::string privacyId, std::map < std::string, bool >& pkgCacheMap)\r
{\r
- LOGI("enter");\r
- static const std::string PrivacyQuery = "SELECT IS_ENABLED from Privacy where ID=? and PRIVACY_ID=?";\r
-\r
- int res;\r
- int id;\r
- res = getUniqueIdFromPackageId(m_pkgId, id);\r
- TryReturn( res == 0, -1, , "getUniqueIdFromPackageId : %d", res);\r
+ return updateCache(m_pkgId, privacyId, pkgCacheMap);\r
+}\r
\r
- LOGD("id : %d" ,id);\r
+int\r
+PrivacyChecker::updateCache(const std::string pkgId, std::string privacyId, std::map < std::string, bool >& pkgCacheMap)\r
+{\r
+ LOGI("enter");\r
+ static const std::string PrivacyQuery = "SELECT IS_ENABLED from PrivacyInfo where PKG_ID=? and PRIVACY_ID=?";\r
\r
- openDb(DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY);\r
+ openDb(PRIVACY_DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY);\r
prepareDb(pDbH, PrivacyQuery.c_str(), pPrivacyStmt);\r
- res = sqlite3_bind_int(pPrivacyStmt.get(), 1, id);\r
- TryReturn( res == 0, -1, , "sqlite3_bind_int : %d", res);\r
+ int res = sqlite3_bind_text(pPrivacyStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
+ TryReturn( res == 0, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
\r
res = sqlite3_bind_text(pPrivacyStmt.get(), 2, privacyId.c_str(), -1, SQLITE_TRANSIENT);\r
- TryReturn( res == 0, -1, , "sqlite3_bind_text : %d", res);\r
+ TryReturn( res == 0, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
\r
+ LOGI(" %s -- %s", pkgId.c_str(), privacyId.c_str());\r
while ( sqlite3_step(pPrivacyStmt.get()) == SQLITE_ROW )\r
{\r
bool privacyEnabled = sqlite3_column_int(pPrivacyStmt.get(), 0) > 0 ? true : false;\r
\r
- std::lock_guard < std::mutex > guard(m_cacheMutex);\r
- m_privacyCache.erase(privacyId);\r
- m_privacyCache.insert(std::map < std::string, bool >::value_type(privacyId, privacyEnabled));\r
+ LOGI("Set result : %s : %d", privacyId.c_str(), privacyEnabled );\r
+ pkgCacheMap.erase(privacyId);\r
+ pkgCacheMap.insert(std::map < std::string, bool >::value_type(privacyId, privacyEnabled));\r
}\r
\r
LOGI("leave");\r
\r
return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+\r
+int\r
+PrivacyChecker::updateCache(std::map < std::string, bool >& pkgCacheMap)\r
+{\r
+ LOGI("enter");\r
+ static const std::string PrivacyQuery = "SELECT PRIVACY_ID, IS_ENABLED from PrivacyInfo where PKG_ID=?";\r
+\r
+ pkgCacheMap.clear();\r
+ \r
+ openDb(PRIVACY_DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY);\r
+ prepareDb(pDbH, PrivacyQuery.c_str(), pPrivacyStmt);\r
+ int res = sqlite3_bind_text(pPrivacyStmt.get(), 1, m_pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
+ TryReturn( res == 0, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
+\r
+ while ( sqlite3_step(pPrivacyStmt.get()) == SQLITE_ROW )\r
+ {\r
+ LOGI("start");\r
+ const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pPrivacyStmt.get(), 0));\r
+ bool privacyEnabled = sqlite3_column_int(pPrivacyStmt.get(), 1) > 0 ? true : false;\r
+\r
+ pkgCacheMap.insert(std::map < std::string, bool >::value_type(std::string(privacyId), privacyEnabled));\r
+\r
+ LOGD("Privacy found : %s %d", privacyId, privacyEnabled);\r
+ }\r
+ LOGI("leave");\r
+ return PRIV_MGR_ERROR_SUCCESS;\r
}
\ No newline at end of file
+++ /dev/null
-/*\r
- * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-#include <PrivacyManager.h>\r
-#include <SocketClient.h>\r
-#include <PrivacyIdInfo.h>\r
-#include <algorithm> \r
-#include <memory>\r
-#include <Utils.h>\r
-\r
-std::mutex PrivacyManager::m_singletonMutex;\r
-PrivacyManager* PrivacyManager::m_pInstance = NULL;\r
-const std::string PrivacyManager::INTERFACE_NAME("PrivacyInfoService");\r
-\r
-PrivacyManager::PrivacyManager(void)\r
-{\r
- std::unique_ptr<SocketClient> pSocketClient(new SocketClient(INTERFACE_NAME));\r
- m_pSocketClient = std::move(pSocketClient);\r
-}\r
-\r
-PrivacyManager*\r
-PrivacyManager::getInstance(void)\r
-{\r
- std::lock_guard<std::mutex> guard(m_singletonMutex);\r
- if (m_pInstance == NULL)\r
- m_pInstance = new PrivacyManager();\r
- return m_pInstance;\r
-}\r
-\r
-int\r
-PrivacyManager::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& pList)\r
-{\r
- int result;\r
-\r
- std::list < std::string > privacyList;\r
-\r
- result = PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(pList, privacyList);\r
- if (result != PRIV_MGR_ERROR_SUCCESS )\r
- return result;\r
-\r
- if (privacyList.size() == 0)\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-\r
- m_pSocketClient->connect();\r
- m_pSocketClient->call("addPrivacyInfo", pkgId, privacyList, &result);\r
- m_pSocketClient->disconnect();\r
-\r
- return result;\r
-}\r
-\r
-int\r
-PrivacyManager::removeAppPackagePrivacyInfo(const std::string pkgId)\r
-{\r
- int result;\r
- m_pSocketClient->connect();\r
- m_pSocketClient->call("removePrivacyInfo", pkgId, pkgId, &result);\r
- m_pSocketClient->disconnect();\r
-\r
- return result;\r
-}\r
-\r
-int\r
-PrivacyManager::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled)\r
-{\r
- int result;\r
- m_pSocketClient->connect();\r
- m_pSocketClient->call("setPrivacySetting", pkgId, privacyId, isEnabled, &result);\r
- m_pSocketClient->disconnect();\r
-\r
- return result;\r
-}\r
- \r
-int\r
-PrivacyManager::getPrivacyAppPackages(std::list < std::string >& pList)\r
-{\r
- int result, size;\r
- std::string temp1;\r
- SocketClient* p = new SocketClient(INTERFACE_NAME);\r
- p->connect();\r
- p->call("getPrivacyAppPackages", &result, &size, &pList);\r
- p->disconnect();\r
-\r
- return result;\r
-}\r
-\r
-int\r
-PrivacyManager::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & list)\r
-{\r
-\r
- std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));\r
-\r
- int result;\r
- pSocketClient->connect();\r
- pSocketClient->call("getAppPackagePrivacyInfo", pkgId, &result, &list);\r
-\r
- pSocketClient->disconnect();\r
-\r
- for (std::list < std::pair <std::string, bool > >::const_iterator iter = list.begin(); iter != list.end(); ++iter){\r
- LOGD(" %s : %d", iter->first.c_str(), iter->second);\r
- }\r
-\r
- return result;\r
-}\r
-\r
-int\r
-PrivacyManager::isUserPrompted(const std::string pkgId, bool& isPrompted)\r
-{\r
- LOGI("enter");\r
-\r
- std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));\r
-\r
- int result;\r
- pSocketClient->connect();\r
- pSocketClient->call("isUserPrompted", pkgId, &result, &isPrompted);\r
- pSocketClient->disconnect();\r
-\r
- LOGI("leave");\r
-\r
- return result;\r
-}\r
-\r
-int\r
-PrivacyManager::setUserPrompted(const std::string pkgId, bool prompted)\r
-{\r
- LOGI("enter");\r
-\r
- std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));\r
-\r
- int result;\r
- pSocketClient->connect();\r
- pSocketClient->call("setUserPrompted", pkgId, prompted, &result);\r
- pSocketClient->disconnect();\r
- LOGI("leave");\r
-\r
- return result;\r
-}
\ No newline at end of file
--- /dev/null
+/*\r
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+#include <PrivacyManagerClient.h>\r
+#include <SocketClient.h>\r
+#include <PrivacyIdInfo.h>\r
+#include <algorithm> \r
+#include <memory>\r
+#include <Utils.h>\r
+\r
+std::mutex PrivacyManagerClient::m_singletonMutex;\r
+PrivacyManagerClient* PrivacyManagerClient::m_pInstance = NULL;\r
+const std::string PrivacyManagerClient::INTERFACE_NAME("PrivacyInfoService");\r
+\r
+PrivacyManagerClient::PrivacyManagerClient(void)\r
+{\r
+ std::unique_ptr<SocketClient> pSocketClient(new SocketClient(INTERFACE_NAME));\r
+ m_pSocketClient = std::move(pSocketClient);\r
+}\r
+\r
+PrivacyManagerClient*\r
+PrivacyManagerClient::getInstance(void)\r
+{\r
+ std::lock_guard<std::mutex> guard(m_singletonMutex);\r
+ if (m_pInstance == NULL)\r
+ m_pInstance = new PrivacyManagerClient();\r
+ return m_pInstance;\r
+}\r
+\r
+int\r
+PrivacyManagerClient::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& pList)\r
+{\r
+\r
+ std::list < std::string > privacyList;\r
+\r
+ int res = PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(pList, privacyList);\r
+ if (res != PRIV_MGR_ERROR_SUCCESS )\r
+ return res;\r
+\r
+ if (privacyList.size() == 0)\r
+ return PRIV_MGR_ERROR_SUCCESS;\r
+\r
+#ifdef __READ_DB_IPC__\r
+ m_pSocketClient->connect();\r
+ m_pSocketClient->call("addPrivacyInfo", pkgId, privacyList, &result);\r
+ m_pSocketClient->disconnect();\r
+\r
+ return result;\r
+#else\r
+ LOGI("enter");\r
+\r
+ static const std::string pkgInfoQuery("INSERT INTO PackageInfo(PKG_ID, IS_SET) VALUES(?, ?)");\r
+ static const std::string privacyQuery("INSERT INTO PrivacyInfo(PKG_ID, PRIVACY_ID, IS_ENABLED) VALUES(?, ?, ?)");\r
+ \r
+ openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+ prepareDb(pDbHandler, pkgInfoQuery.c_str(), pPkgInfoStmt);\r
+\r
+ res = sqlite3_bind_text(pPkgInfoStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
+ TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
+ \r
+ res = sqlite3_bind_int(pPkgInfoStmt.get(), 2, 0);\r
+ TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);\r
+\r
+ res = sqlite3_step(pPkgInfoStmt.get());\r
+ TryReturn( res == SQLITE_DONE || res == SQLITE_CONSTRAINT, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res);\r
+ \r
+ prepareDb(pDbHandler, privacyQuery.c_str(), pPrivacyStmt);\r
+ for ( std::list <std::string>::const_iterator iter = privacyList.begin(); iter != privacyList.end(); ++iter)\r
+ {\r
+ LOGD(" install privacy: %s", iter->c_str());\r
+ \r
+ res = sqlite3_bind_text(pPrivacyStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
+ TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);\r
+\r
+ res = sqlite3_bind_text(pPrivacyStmt.get(), 2, iter->c_str(), -1, SQLITE_TRANSIENT);\r
+ TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
+ \r
+ // Before setting app and popup is ready, default value is true\r
+ res = sqlite3_bind_int(pPrivacyStmt.get(), 3, 1);\r
+ TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);\r
+\r
+ res = sqlite3_step(pPrivacyStmt.get());\r
+ TryReturn( res == SQLITE_DONE || res == SQLITE_CONSTRAINT, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res);\r
+\r
+ sqlite3_reset(pPrivacyStmt.get());\r
+ }\r
+\r
+ return 0;\r
+#endif\r
+}\r
+\r
+int\r
+PrivacyManagerClient::removeAppPackagePrivacyInfo(const std::string pkgId)\r
+{\r
+ int result;\r
+ m_pSocketClient->connect();\r
+ m_pSocketClient->call("removePrivacyInfo", pkgId, &result);\r
+ m_pSocketClient->disconnect();\r
+\r
+ return result;\r
+}\r
+\r
+int\r
+PrivacyManagerClient::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled)\r
+{\r
+ int result;\r
+ m_pSocketClient->connect();\r
+ m_pSocketClient->call("setPrivacySetting", pkgId, privacyId, isEnabled, &result);\r
+ m_pSocketClient->disconnect();\r
+\r
+ return result;\r
+}\r
+ \r
+int\r
+PrivacyManagerClient::getPrivacyAppPackages(std::list < std::string >& pList)\r
+{\r
+ int result, size;\r
+ std::string temp1;\r
+ SocketClient* p = new SocketClient(INTERFACE_NAME);\r
+ p->connect();\r
+ p->call("getPrivacyAppPackages", &result, &size, &pList);\r
+ p->disconnect();\r
+\r
+ return result;\r
+}\r
+\r
+int\r
+PrivacyManagerClient::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & list)\r
+{\r
+\r
+ std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));\r
+\r
+ int result;\r
+ pSocketClient->connect();\r
+ pSocketClient->call("getAppPackagePrivacyInfo", pkgId, &result, &list);\r
+\r
+ pSocketClient->disconnect();\r
+\r
+ for (std::list < std::pair <std::string, bool > >::const_iterator iter = list.begin(); iter != list.end(); ++iter){\r
+ LOGD(" %s : %d", iter->first.c_str(), iter->second);\r
+ }\r
+\r
+ return result;\r
+}\r
+\r
+int\r
+PrivacyManagerClient::isUserPrompted(const std::string pkgId, bool& isPrompted)\r
+{\r
+ LOGI("enter");\r
+\r
+ std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));\r
+\r
+ int result;\r
+ pSocketClient->connect();\r
+ pSocketClient->call("isUserPrompted", pkgId, &result, &isPrompted);\r
+ pSocketClient->disconnect();\r
+\r
+ LOGI("leave");\r
+\r
+ return result;\r
+}\r
+\r
+int\r
+PrivacyManagerClient::setUserPrompted(const std::string pkgId, bool prompted)\r
+{\r
+ LOGI("enter");\r
+\r
+ std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));\r
+\r
+ int result;\r
+ pSocketClient->connect();\r
+ pSocketClient->call("setUserPrompted", pkgId, prompted, &result);\r
+ pSocketClient->disconnect();\r
+ LOGI("leave");\r
+\r
+ return result;\r
+}
\ No newline at end of file
#include <string.h>\r
#include <string>\r
#include <memory>\r
-#include <PrivacyManager.h>\r
+#include <PrivacyManagerClient.h>\r
#include <privacy_manager_client.h>\r
#include <privacy_manager_client_types.h>\r
#include "privacy_manager_client_internal_types.h"\r
{\r
return PrivacyChecker::check(std::string(privacy_id));\r
}\r
-int privacy_checker_check_privacy_by_privilege(const char *privilege_id)\r
-{\r
- int res;\r
- std::string privacyId;\r
-\r
- res = PrivacyIdInfo::getPrivacyIdFromPrivilege(std::string(privilege_id), privacyId);\r
- if (res != PRIV_MGR_ERROR_SUCCESS)\r
- return res;\r
-\r
- return PrivacyChecker::check(privacyId);\r
\r
+int privacy_checker_check_by_privilege(const char *privilege_id)\r
+{\r
+ return PrivacyChecker::checkWithPrivilege(privilege_id);\r
}\r
\r
-int privacy_checker_check_privacy_by_device_cap(const char *device_cap)\r
+int privacy_checker_check_by_device_cap(const char *device_cap)\r
{\r
- int res;\r
- std::string privacyId;\r
-\r
- res = PrivacyIdInfo::getPrivacyIdFromDeviceCap(std::string(device_cap), privacyId);\r
- if (res != PRIV_MGR_ERROR_SUCCESS)\r
- return res;\r
-\r
- return PrivacyChecker::check(privacyId);\r
-\r
+ return PrivacyChecker::checkWithPrivilege(device_cap);\r
}\r
\r
int privacy_checker_finalize(void)\r
{\r
return PrivacyChecker::finalize();\r
}\r
+\r
+int privacy_checker_check_package_by_privilege(const char* package_id, const char *privilege_id)\r
+{\r
+ return PrivacyChecker::checkWithPrivilege(package_id,privilege_id);\r
+}\r
+\r
+int privacy_checker_check_package_by_device_cap(const char* package_id, const char *device_cap)\r
+{\r
+ return PrivacyChecker::checkWithDeviceCap(package_id, device_cap);\r
+}
\ No newline at end of file
#include <string.h>\r
#include <string>\r
#include <memory>\r
-#include <PrivacyManager.h>\r
+#include <PrivacyManagerClient.h>\r
#include <privacy_manager_client.h>\r
#include <privacy_manager_client_types.h>\r
#include "privacy_manager_client_internal_types.h"\r
#include <string.h>\r
#include <string>\r
#include <memory>\r
-#include <PrivacyManager.h>\r
+#include <dlog.h>\r
+#include <PrivacyManagerClient.h>\r
#include <privacy_manager_client.h>\r
#include "privacy_manager_client_internal_types.h"\r
\r
\r
int privacy_manager_client_install_privacy(const char *package_id, const char** privacy_list)\r
{\r
- int retval;\r
- PrivacyManager* pInst = PrivacyManager::getInstance();\r
+ LOGI("enter");\r
+\r
+ PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();\r
std::list < std::string > privacyList;\r
\r
- while (*privacy_list != NULL)\r
- privacyList.push_back(std::string(*privacy_list ++));\r
+ while (*privacy_list[0] != '\0')\r
+ privacyList.push_back(std::string(*privacy_list++));\r
+\r
+ int retval = pInst->addAppPackagePrivacyInfo(std::string(package_id), privacyList);\r
\r
- retval = pInst->addAppPackagePrivacyInfo(std::string(package_id), privacyList);\r
+ LOGI("leave");\r
\r
return retval;\r
}\r
{\r
if (package_id == NULL)\r
return PRIV_MGR_ERROR_INVALID_PARAMETER;\r
- return PrivacyManager::getInstance()->removeAppPackagePrivacyInfo(std::string(package_id));\r
+ return PrivacyManagerClient::getInstance()->removeAppPackagePrivacyInfo(std::string(package_id));\r
}\r
\r
int privacy_manager_client_foreach_privacy_packages(privacy_manager_client_privacy_packages_cb callback, void *user_data)\r
{\r
int retval;\r
- PrivacyManager* pInst = PrivacyManager::getInstance();\r
+ PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();\r
\r
std::list < std::string > list;\r
retval = pInst->getPrivacyAppPackages(list);\r
{\r
int retval;\r
bool res;\r
- PrivacyManager* pInst = PrivacyManager::getInstance();\r
+ PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();\r
\r
std::list < std::pair <std::string, bool > > list;\r
\r
- retval = pInst->getAppPackagePrivacyInfo(package_id, list);\r
+ retval = pInst->getAppPackagePrivacyInfo(std::string(package_id), list);\r
if (retval != PRIV_MGR_ERROR_SUCCESS)\r
return retval;\r
if (list.size() == 0)\r
}\r
int privacy_manager_client_set_package_privacy(const char *package_id, const char *privacy_id, bool enable)\r
{\r
- PrivacyManager* pInst = PrivacyManager::getInstance();\r
+ PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();\r
\r
return pInst->setPrivacySetting(package_id, privacy_id, enable);\r
}\r
+\r
+int privacy_manager_client_check_user_consented(const char *package_id, bool consented)\r
+{\r
+ PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();\r
+\r
+ return pInst->isUserPrompted(std::string(package_id), consented);\r
+}
\ No newline at end of file
static bool m_isInitialized;\r
\r
public:\r
- static void initialize(void);\r
+ static int initialize(void);\r
static int getPrivacyIdFromPrivilege(const std::string privilege, std::string& privacyId);\r
static int getPrivacyIdFromDeviceCap(const std::string deviceCap, std::string& privacyId);\r
\r
#include <string>\r
#include <privacy_manager_client_types.h>\r
\r
+static const std::string PRIVACY_DB_PATH("/opt/dbspace/.privacy.db");\r
+static const std::string PRIVACY_INFO_DB_PATH("/opt/dbspace/.privacylist.db");\r
static const std::string SERVER_ADDRESS ("/tmp/privacy_manager_server");\r
static const std::string DBUS_PATH("/privacy_manager/dbus_notification");\r
static const std::string DBUS_SIGNAL_INTERFACE("org.tizen.privacy_manager.signal");\r
#include <algorithm>\r
#include <dlog.h>\r
#include <sqlite3.h>\r
-\r
+#include <memory>\r
+#include <string>\r
\r
#define TryCatchLogReturn(condition, expr, r, logFormat) if (!(condition)) { \\r
LOGE(logFormat); \\r
}\\r
setStmtToUniquePtr(pStmt, pStmt##Temp);\r
\r
+class Utils\r
+{\r
+public:\r
+ static std::string toHash (std::string src);\r
+};\r
#endif //_UTILS_H_\r
PRIV_MGR_ERROR_IPC_ERROR = -16,\r
PRIV_MGR_ERROR_INVALID_STATE = -17,\r
PRIV_MGR_ERROR_SYSTEM_ERROR = -18,\r
+ PRIV_MGR_ERROR_USER_NOT_CONSENTED = -19,\r
\r
PRIV_MGR_ERROR_UNKNOWN = -(0x99),\r
};\r
\r
#include <PrivacyIdInfo.h>\r
#include <privacy_manager_client_types.h>\r
+#include <PrivacyManagerTypes.h>\r
#include <dlog.h>\r
#include <set>\r
+#include <Utils.h>\r
\r
\r
std::map <std::string, std::string> PrivacyIdInfo::m_privilegeToPrivacyMap;\r
char DeviceCap[128];\r
char privacy[128];\r
};\r
-\r
+/*\r
static struct PrivacyPrivilegePair DeviceCapToPrivacyTable[] =\r
{\r
- {"bluetooth.admin", "bluetooth"},\r
- {"bluetooth.gap", "bluetooth"},\r
- {"bluetooth.spp", "bluetooth"},\r
- {"bluetoothmanager", "bluetooth"},\r
+ {"bluetooth.admin", "http://tizen.org/privacy/bluetooth"},\r
+ {"bluetooth.gap", "http://tizen.org/privacy/bluetooth"},\r
+ {"bluetooth.spp", "http://tizen.org/privacy/bluetooth"},\r
+ {"bluetoothmanager", "http://tizen.org/privacy/bluetooth"},\r
\r
- {"calendar.read", "calender"},\r
- {"calendar.write", "calender"},\r
+ {"calendar.read", "http://tizen.org/privacy/calender"},\r
+ {"calendar.write", "http://tizen.org/privacy/calender"},\r
\r
- {"contact.read", "contact"},\r
- {"contact.write", "contact"},\r
+ {"contact.read", "http://tizen.org/privacy/contact"},\r
+ {"contact.write", "http://tizen.org/privacy/contact"},\r
\r
- {"messaging.read", "messaging"},\r
- {"messaging.write", "messaging"},\r
- {"messaging.send", "messaging"},\r
+ {"messaging.read", "http://tizen.org/privacy/messaging"},\r
+ {"messaging.write", "http://tizen.org/privacy/messaging"},\r
+ {"messaging.send", "http://tizen.org/privacy/messaging"},\r
\r
- {"nfc.admin", "nfc"},\r
- {"nfcmanager.cardemulation", "nfc"},\r
- {"nfc.common", "nfc"},\r
- {"nfc.p2p", "nfc"},\r
- {"nfc.tag", "nfc"},\r
+ {"nfc.admin", "http://tizen.org/privacy/nfc"},\r
+ {"nfcmanager.cardemulation", "http://tizen.org/privacy/nfc"},\r
+ {"nfc.common", "http://tizen.org/privacy/nfc"},\r
+ {"nfc.p2p", "http://tizen.org/privacy/nfc"},\r
+ {"nfc.tag", "http://tizen.org/privacy/nfc"},\r
\r
- {"XMLHttpRequest", "internet"},\r
- {"externalNetworkAccess", "internet"},\r
+ {"XMLHttpRequest", "http://tizen.org/privacy/internet"},\r
+ {"externalNetworkAccess", "http://tizen.org/privacy/internet"},\r
\r
{"\0", "\0"}\r
};\r
\r
static struct PrivacyPrivilegePair PrivilegeToPrivacyTable[] =\r
{\r
- {"http://tizen.org/privilege/bluetooth.admin", "bluetooth"},\r
- {"http://tizen.org/privilege/bluetooth.gap", "bluetooth"},\r
- {"http://tizen.org/privilege/bluetooth.health", "bluetooth"},\r
- {"http://tizen.org/privilege/bluetooth.opp", "bluetooth"},\r
- {"http://tizen.org/privilege/bluetooth.spp", "bluetooth"},\r
- {"http://tizen.org/privilege/bluetoothmanager", "bluetooth"},\r
+ {"http://tizen.org/privilege/bluetooth.admin", "http://tizen.org/privacy/bluetooth"},\r
+ {"http://tizen.org/privilege/bluetooth.gap", "http://tizen.org/privacy/bluetooth"},\r
+ {"http://tizen.org/privilege/bluetooth.health", "http://tizen.org/privacy/bluetooth"},\r
+ {"http://tizen.org/privilege/bluetooth.opp", "http://tizen.org/privacy/bluetooth"},\r
+ {"http://tizen.org/privilege/bluetooth.spp", "http://tizen.org/privacy/bluetooth"},\r
+ {"http://tizen.org/privilege/bluetoothmanager", "http://tizen.org/privacy/bluetooth"},\r
\r
- {"http://tizen.org/privilege/calendar.read", "calender"},\r
- {"http://tizen.org/privilege/calendar.write", "calender"},\r
+ {"http://tizen.org/privilege/calendar.read", "http://tizen.org/privacy/calender"},\r
+ {"http://tizen.org/privilege/calendar.write", "http://tizen.org/privacy/calender"},\r
\r
- {"http://tizen.org/privilege/contact.read", "contact"},\r
- {"http://tizen.org/privilege/contact.write", "contact"},\r
+ {"http://tizen.org/privilege/contact.read", "http://tizen.org/privacy/contact"},\r
+ {"http://tizen.org/privilege/contact.write", "http://tizen.org/privacy/contact"},\r
\r
- {"http://tizen.org/privilege/contextmanager.privacy", "context"},\r
- {"http://tizen.org/privilege/contextmanager.upload", "context"},\r
+ {"http://tizen.org/privilege/contextmanager.privacy", "http://tizen.org/privacy/context"},\r
+ {"http://tizen.org/privilege/contextmanager.upload", "http://tizen.org/privacy/context"},\r
\r
- {"http://tizen.org/privilege/location", "location"},\r
+ {"http://tizen.org/privilege/location", "http://tizen.org/privacy/location"},\r
\r
- {"http://tizen.org/privilege/messaging.read", "messaging"},\r
- {"http://tizen.org/privilege/messaging.write", "messaging"},\r
+ {"http://tizen.org/privilege/messaging.read", "http://tizen.org/privacy/messaging"},\r
+ {"http://tizen.org/privilege/messaging.write", "http://tizen.org/privacy/messaging"},\r
\r
- {"http://tizen.org/privilege/nfc.admin", "nfc"},\r
- {"http://tizen.org/privilege/nfcmanager.cardemulation", "nfc"},\r
- {"http://tizen.org/privilege/nfc.common", "nfc"},\r
- {"http://tizen.org/privilege/nfc.p2p", "nfc"},\r
- {"http://tizen.org/privilege/nfc.tag", "nfc"},\r
+ {"http://tizen.org/privilege/nfc.admin", "http://tizen.org/privacy/nfc"},\r
+ {"http://tizen.org/privilege/nfcmanager.cardemulation", "http://tizen.org/privacy/nfc"},\r
+ {"http://tizen.org/privilege/nfc.common", "http://tizen.org/privacy/nfc"},\r
+ {"http://tizen.org/privilege/nfc.p2p", "http://tizen.org/privacy/nfc"},\r
+ {"http://tizen.org/privilege/nfc.tag", "http://tizen.org/privacy/nfc"},\r
\r
- {"http://tizen.org/privilege/http", "internet"},\r
- {"http://tizen.org/privilege/socket", "internet"},\r
- {"http://tizen.org/privilege/web.service", "internet"},\r
+ {"http://tizen.org/privilege/http", "http://tizen.org/privacy/internet"},\r
+ {"http://tizen.org/privilege/socket", "http://tizen.org/privacy/internet"},\r
+ {"http://tizen.org/privilege/web.service", "http://tizen.org/privacy/internet"},\r
\r
{"\0", "\0"}\r
};\r
+*/\r
\r
-\r
-void\r
+int\r
PrivacyIdInfo::initialize(void)\r
{\r
- int i = 0;\r
- while (PrivilegeToPrivacyTable[i].privilege[0] != '\0') \r
- {\r
- m_privilegeToPrivacyMap.insert(std::map < std::string, std::string >::value_type(std::string(PrivilegeToPrivacyTable[i].privilege), std::string(PrivilegeToPrivacyTable[i].privacy)));\r
- ++i;\r
- }\r
-\r
- i = 0;\r
- while (DeviceCapToPrivacyTable[i].privilege[0] != '\0') \r
- {\r
- m_deviceCapToPrivacyMap.insert(std::map < std::string, std::string >::value_type(std::string(DeviceCapToPrivacyTable[i].privilege), std::string(DeviceCapToPrivacyTable[i].privacy)));\r
- ++i;\r
- }\r
- m_isInitialized = true;\r
+ static const std::string sqlPrivilege("SELECT PRIVILEGE_ID, PRIVACY_ID from PrivilegeToPrivacyTable");\r
+ static const std::string sqlDeviceCap("SELECT DEVICE_CAP, PRIVACY_ID from DeviceCapToPrivacyTable");\r
+\r
+ LOGI("enter");\r
+ \r
+ openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY);\r
+ prepareDb(pDbHandler, sqlPrivilege.c_str(), pStmtPrivilege);\r
+\r
+ int res;\r
+ while ( (res = sqlite3_step(pStmtPrivilege.get())) == SQLITE_ROW )\r
+ {\r
+ const char* privilegeId = reinterpret_cast < const char* > (sqlite3_column_text(pStmtPrivilege.get(), 0));\r
+ const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pStmtPrivilege.get(), 1));\r
+ m_privilegeToPrivacyMap.insert(std::map < std::string, std::string >::value_type(std::string(privilegeId), std::string(privacyId)));\r
+ LOGD(" %s : %s", privilegeId, privacyId);\r
+ }\r
+\r
+ prepareDb(pDbHandler, sqlDeviceCap.c_str(), pStmtDeviceCap);\r
+ while ( (res = sqlite3_step(pStmtDeviceCap.get())) == SQLITE_ROW )\r
+ {\r
+ const char* DeviceCap = reinterpret_cast < const char* > (sqlite3_column_text(pStmtDeviceCap.get(), 0));\r
+ const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pStmtDeviceCap.get(), 1));\r
+ m_deviceCapToPrivacyMap.insert(std::map < std::string, std::string >::value_type(std::string(DeviceCap), std::string(privacyId)));\r
+ }\r
+ m_isInitialized = true;\r
+\r
+ return PRIV_MGR_ERROR_SUCCESS;\r
}\r
\r
int\r
/*\r
- * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
*\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
* limitations under the License.\r
*/\r
\r
+#include <Utils.h>\r
\r
-#include <TestService.h>\r
-\r
-void\r
-TestService::test(SocketConnection* pConnector)\r
+std::string Utils::toHash(std::string src)\r
{\r
- std::string res1, res2;\r
- pConnector->read(&res1, &res2);\r
- LOGD("TEST received: %s %s", res1.c_str(),res2.c_str());\r
-\r
- pConnector->write(std::string("-test OK-"));\r
- pConnector->write(std::string("-byebye-"));\r
-}\r
+ return src;\r
+}
\ No newline at end of file
+++ /dev/null
-<manifest>
- <define>
- <domain name="policy-manager" />
- <provide>
- <label name="policy-manager::daemon" />
- <label name="policy-manager::db" />
- </provide>
- </define>
- <request>
- <domain name="_" />
- </request>
-</manifest>
<manifest>
<define>
- <domain name="policy-manager" />
+ <domain name="privacy-manager" />
<provide>
- <label name="policy-manager::daemon" />
- <label name="policy-manager::db" />
+ <label name="privacy-manager::daemon" />
+ <label name="privacy-manager::db" />
</provide>
</define>
<request>
- <domain name="_" />
+ <domain name="privacy-manager-server" />
</request>
+ <assign>
+ <filesystem path="/usr/bin/privacy-manager-server" label="privacy-manager::daemon" exec_label="privacy-manager::daemon"/>
+ <filesystem path="/usr/share/license/privacy-manager-server" label="_"/>
+ <filesystem path="/etc/rc.d/init.d/privacy-manager-server.sh" label="_" exec_label="none"/>
+ <filesystem path="/etc/rc.d/rc3.d/S10privacy-manager-server.sh" label="_" exec_label="none"/>
+ <filesystem path="/etc/rc.d/rc5.d/S10privacy-manager-server.sh" label="_" exec_label="none"/>
+ <filesystem path="/usr/lib/systemd/system/privacy-manager-server.service" label="_" exec_label="none" />
+ <filesystem path="/usr/lib/systemd/system/multi-user.target.wants/privacy-manager-server.service" label="_" exec_label="none" />
+ </assign>
</manifest>
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
-provides: privacy-manager-server
-
%description
Privacy Management
Group: Development/Libraries
Requires: privacy-manager-server = %{version}-%{release}
-provides: libprivacy-manager-client.so.1
-
%description -n privacy-manager-client
privacy-manager client
%package -n privacy-manager-client-devel
Summary: privacy-manager client devel
Group: Development/Libraries
+BuildRequires: pkgconfig(libxml-2.0)
Requires: privacy-manager-client = %{version}-%{release}
%description -n privacy-manager-client-devel
BuildRequires: pkgconfig(glib-2.0)
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
+Requires: privacy-manager-client = %{version}-%{release}
%description -n capi-security-privacy-manager
The Privacy Manager API provides functions to get/set information about privacy information of installed packages.
%package -n capi-security-privacy-manager-devel
Summary: Privacy Manager API (Development)
Group: TO_BE/FILLED_IN
-Requires: %{name} = %{version}-%{release}
+Requires: privacy-manager-client = %{version}-%{release}
%description -n capi-security-privacy-manager-devel
The Privacy Manager API provides functions to get/set information about privacy information of installed packages.(DEV)
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}/usr/share/license
-cp LICENSE.APLv2 %{buildroot}/usr/share/license/%{name}
+cp LICENSE.APLv2 %{buildroot}/usr/share/license/privacy-manager-server
mkdir -p %{buildroot}/usr/share/license
cp LICENSE.APLv2 %{buildroot}/usr/share/license/privacy-manager-client
mkdir -p %{buildroot}/usr/bin
cp res/usr/bin/* %{buildroot}/usr/bin/
+mkdir -p %{buildroot}/opt/dbspace
+cp res/opt/dbspace/.privacylist.db /%{buildroot}/opt/dbspace/
#mkdir -p %{buildroot}/etc/rc.d/init.d
#cp res/etc/rc.d/init.d/* %{buildroot}/etc/rc.d/init.d/
%make_install -n privacy-manager-client
install -D %{SOURCE2} %{buildroot}%{_datadir}/privacy-manager-client.manifest
-%make_install -n privacy-manager-server
+%make_install -n privacy-manager
install -D %{SOURCE1} %{buildroot}%{_datadir}/privacy-manager-server.manifest
%make_install -n capi-security-privacy-manager
#mkdir -p %{buildroot}/etc/rc.d/rc3.d
#mkdir -p %{buildroot}/etc/rc.d/rc5.d
-#ln -sf /etc/rc.d/init.d/wrt-security-daemon.sh %{buildroot}/etc/rc.d/rc3.d/S10privacy-manager-server.sh
-#ln -sf /etc/rc.d/init.d/wrt-security-daemon.sh %{buildroot}/etc/rc.d/rc5.d/S10privacy-manager-server.sh
+#ln -sf res/etc/rc.d/init.d/privacy-manager-server.sh %{buildroot}/etc/rc.d/rc3.d/S10privacy-manager-server.sh
+#ln -sf res/etc/rc.d/init.d/privacy-manager-server.sh %{buildroot}/etc/rc.d/rc5.d/S10privacy-manager-server.sh
mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants
install -m 0644 %{SOURCE3} %{buildroot}%{_libdir}/systemd/system/privacy-manager-server.service
%clean
rm -rf %{buildroot}
-%post
+%post -n privacy-manager-server
/sbin/ldconfig
+echo "Check privacy DB"
if [ ! -f /opt/dbspace/.privacy.db ]
then
+ echo "Create privacy DB"
/usr/bin/privacy_manager_create_clean_db.sh
fi
%files -n privacy-manager-server
%defattr(-,root,root,-)
-%manifest %{_datadir}/%{name}.manifest
+%manifest %{_datadir}/privacy-manager-server.manifest
%{_bindir}/*
%{_libdir}/systemd/*
-#%{_libdir}/etc/rc.d/init.d/privacy-manager-server.sh
+#/etc/rc.d/init.d/privacy-manager-server.sh
#%attr(755,root,root) /etc/rc.d/init.d/privacy-manager-server.sh
#/etc/rc.d/rc3.d/S10privacy-manager-server.sh
#/etc/rc.d/rc5.d/S10privacy-manager-server.sh
%files -n privacy-manager-client
%defattr(-,root,root,-)
%manifest %{_datadir}/privacy-manager-client.manifest
-%{_libdir}/*.so*
+%{_libdir}/libprivacy-manager-client.so*
/usr/share/license/privacy-manager-client
+/usr/etc/package-manager/parserlib/libprivileges.so
+/opt/dbspace/.privacylist.db
%files -n privacy-manager-client-devel
%defattr(-,root,root,-)
%{_includedir}/privacymgr/*.h
%{_libdir}/libcapi-security-privacy-manager.so
%{_libdir}/pkgconfig/capi-security-privacy-manager.pc
-
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+SET (this_target privileges)
+
+SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/cmake_build_tmp/output)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(bin_pkgs REQUIRED dlog libxml-2.0)
+
+INCLUDE_DIRECTORIES(
+ /usr/include
+ /usr/include/glib-2.0
+ /usr/lib/glib-2.0/include
+ /usr/include/libxml2
+ /usr/include/package_manager
+ /usr/include/dlog
+ "${CMAKE_SOURCE_DIR}/client/inc/"
+ "${CMAKE_SOURCE_DIR}/common/inc/"
+ )
+
+SET (${this_target}_SOURCE_FILES
+ privileges.cpp
+ )
+
+ADD_DEFINITIONS("-DDLOG_ERROR_ENABLED")
+ADD_DEFINITIONS("-DLOG_TAG=\"PRIVILEGE_PLUGIN\"")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall" )
+
+SET(CMAKE_C_FLAGS_PROFILING " -g -pg")
+SET(CMAKE_CXX_FLAGS_PROFILING " -std=c++0x -g -pg")
+SET(CMAKE_C_FLAGS_DEBUG " -g")
+SET(CMAKE_CXX_FLAGS_DEBUG " -std=c++0x -g")
+SET(CMAKE_C_FLAGS_RELEASE " -g")
+SET(CMAKE_CXX_FLAGS_RELEASE " -std=c++0x -g")
+SET(CMAKE_C_FLAGS_CCOV " -g --coverage")
+SET(CMAKE_CXX_FLAGS_CCOV " -std=c++0x -g --coverage")
+
+## Create Library
+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)
+
+TARGET_LINK_LIBRARIES(${this_target} "-lxml2" )
+TARGET_LINK_LIBRARIES(${this_target} "-lglib-2.0" )
+TARGET_LINK_LIBRARIES(${this_target} "-ldlog" )
+TARGET_LINK_LIBRARIES(${this_target} "-lprivacy-manager-client" "-L../client" )
+
+ADD_CUSTOM_COMMAND(TARGET ${this_target}
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX} ${LIBRARY_OUTPUT_PATH}/debug/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}
+ COMMAND ${CMAKE_STRIP} --strip-unneeded ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}
+ COMMENT "strip ${this_target}"
+ )
+
+INSTALL(TARGETS ${this_target} DESTINATION "../etc/package-manager/parserlib")
+
--- /dev/null
+//\r
+// Open Service Platform\r
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#include <errno.h>\r
+#include <libxml/parser.h>\r
+#include <libxml/tree.h>\r
+#include <privacy_manager_client.h>\r
+#include <dlog.h>\r
+#include <list>\r
+#include <string>\r
+\r
+static const xmlChar _NODE_PRIVILEGES[] = "privileges";\r
+static const xmlChar _NODE_PRIVILEGE[] = "privilege";\r
+\r
+\r
+void destroy_char_list(char** ppList, int size)\r
+{\r
+ int i;\r
+ for (i = 0; i < size; ++i)\r
+ {\r
+ if (ppList[i])\r
+ free(ppList[i]);\r
+ }\r
+ free(ppList);\r
+}\r
+\r
+extern "C"\r
+__attribute__ ((visibility("default")))\r
+int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)\r
+{\r
+ int ret;\r
+ LOGI("enter");\r
+\r
+ // Node: <privileges>\r
+ xmlNodePtr curPtr = xmlFirstElementChild(xmlDocGetRootElement(docPtr));\r
+ LOGD("Node: %s", curPtr->name);\r
+\r
+ curPtr = curPtr->xmlChildrenNode;\r
+ if (curPtr == NULL)\r
+ {\r
+ LOGD("No privileges");\r
+ return 0;\r
+ }\r
+\r
+ std::list <std::string> privilegeList;\r
+ while (curPtr != NULL)\r
+ {\r
+ LOGD("Node: %s", curPtr->name);\r
+\r
+ if (xmlStrcmp(curPtr->name, _NODE_PRIVILEGE) == 0)\r
+ {\r
+ xmlChar* pPrivilege = xmlNodeListGetString(docPtr, curPtr->xmlChildrenNode, 1);\r
+ LOGD(" value= %s", reinterpret_cast<char*>(pPrivilege));\r
+ if (pPrivilege == NULL)\r
+ {\r
+ LOGE("Failed to get value");\r
+ return -EINVAL;\r
+ }\r
+ privilegeList.push_back(std::string( reinterpret_cast<char*> (pPrivilege)));\r
+ }\r
+ curPtr = curPtr->next;\r
+ }\r
+\r
+ char** ppPrivilegeList = (char**) calloc(1, privilegeList.size() + 1);\r
+ std::list <std::string>::iterator iter = privilegeList.begin();\r
+ for (int i = 0; i < privilegeList.size(); ++i)\r
+ {\r
+ ppPrivilegeList[i] = (char*)calloc (1, strlen(iter->c_str() + 1));\r
+ if (ppPrivilegeList[i] == NULL)\r
+ {\r
+ destroy_char_list(ppPrivilegeList, privilegeList.size() + 1);\r
+ return -ENOMEM;\r
+ }\r
+ memcpy(ppPrivilegeList[i], iter->c_str(), strlen(iter->c_str()));\r
+ ++iter;\r
+ }\r
+ for (int i = 0; i < privilegeList.size(); ++i)\r
+ LOGD(" values : %s", ppPrivilegeList[i]);\r
+\r
+ ppPrivilegeList[privilegeList.size()] = (char*)calloc (1, sizeof(char) + 1 );\r
+ memcpy(ppPrivilegeList[privilegeList.size()], "\0", 1);\r
+\r
+ ret = privacy_manager_client_install_privacy(packageId, (const char**) ppPrivilegeList);\r
+ destroy_char_list(ppPrivilegeList, privilegeList.size() + 1);\r
+ if (ret != PRIV_MGR_ERROR_SUCCESS)\r
+ {\r
+ LOGD("Failed to install privacy : %d", ret);\r
+ return -EINVAL;\r
+ }\r
+\r
+ LOGI("leave");\r
+}\r
+\r
+extern "C"\r
+__attribute__ ((visibility("default")))\r
+int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char* packageId)\r
+{\r
+ LOGI("enter");\r
+\r
+ privacy_manager_client_uninstall_privacy(packageId);\r
+\r
+ return 0;\r
+ LOGI("leave"); \r
+}
\ No newline at end of file
+++ /dev/null
-prefix=@PREFIX@
-exec_prefix=@EXEC_PREFIX@
-libdir=@LIBDIR@
-includedir=@INCLUDEDIR@
-
-Name: privacy-manager-server
-Description: Privacy Manager Server
-Version: @VERSION@
-Requires:
PRAGMA foreign_keys = ON; BEGIN TRANSACTION;
CREATE TABLE PackageInfo(
- UNIQUE_ID INTEGER PRIMARY KEY AUTOINCREMENT,
- PKG_ID TEXT not null,
+ PKG_ID TEXT not null PRIMARY KEY UNIQUE,
IS_SET BOOL not null,
CHECK(1) );
-CREATE TABLE Privacy(
- ID INTEGER not null,
+CREATE TABLE PrivacyInfo(
+ PKG_ID TEXT not null ,
PRIVACY_ID TEXT not null,
IS_ENABLED INTEGER not null,
- FOREIGN KEY(ID) REFERENCES PackageInfo(UNQUE_ID),
+ FOREIGN KEY(PKG_ID) REFERENCES PackageInfo(PKG_ID),
+ CONSTRAINT PKG_PRIVACY UNIQUE (PKG_ID, PRIVACY_ID)
CHECK(1) );
-CREATE VIEW PrivacyView as SELECT
- PackageInfo.UNIQUE_ID,
- PackageInfo.PKG_ID,
- Privacy.PRIVACY_ID,
- Privacy.IS_ENABLED
- FROM PackageInfo, Privacy
- WHERE PackageInfo.UNIQUE_ID = Privacy.ID;
COMMIT;
BEGIN TRANSACTION;
CREATE TABLE DB_VERSION_0_1 (version INT); COMMIT;
${server_src_dir}/SocketService.cpp
${server_src_dir}/PrivacyManagerDaemon.cpp
${server_src_dir}/service/PrivacyInfoService.cpp
- ${server_src_dir}/service/TestService.cpp
${server_src_dir}/PrivacyManagerServer.cpp
${server_src_dir}/NotificationServer.cpp
)
SET(PRIVACY_MANAGER_SERVER_HEADERS
- ${server_include_dir}/SocketService.h
- ${server_include_dir}/PrivacyManagerDaemon.h
- ${common_include_dir}/SocketConnection.h
- ${common_include_dir}/SocketConnection.h
+ # ${server_include_dir}/SocketService.h
+ # ${server_include_dir}/PrivacyManagerDaemon.h
+ # ${common_include_dir}/SocketConnection.h
+ # ${common_include_dir}/SocketConnection.h
)
SET(PRIVACY_MANAGER_SERVER_LDFLAGS " -module -avoid-version ")
SET(PRIVACY_MANAGER_SERVER_CFLAGS " ${CFLAGS} -fPIC ")
INSTALL(TARGETS privacy-manager-server DESTINATION ../bin COMPONENT RuntimeLibraries)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/privacy-manager-server.pc DESTINATION ../lib/pkgconfig)
-INSTALL(FILES ${PRIVACY_MANAGER_SERVER_HEADERS} DESTINATION ../include/privacy_manager/server)
\ No newline at end of file
+INSTALL(FILES ${PRIVACY_MANAGER_SERVER_HEADERS} DESTINATION ../include/privacy_manager/server)
* limitations under the License.\r
*/\r
\r
-#ifndef _PRIVACY_DB_H_\r
-#define _PRIVACY_DB_H_\r
+#ifndef _PRIVACY_MANAGER_SERVER_H_\r
+#define _PRIVACY_MANAGER_SERVER_H_\r
\r
#include <string>\r
#include <memory>\r
#include <list>\r
#include <mutex>\r
-#include <sqlite3.h>\r
#include <NotificationServer.h>\r
\r
class NotificationServer;\r
-struct sqlite3;\r
-class a;\r
class PrivacyManagerServer\r
{\r
private:\r
static std::mutex m_singletonMutex;\r
- static const std::string DB_PATH;\r
static PrivacyManagerServer* m_pInstance;\r
- sqlite3* m_pDBHandler;\r
NotificationServer m_notificationServer;\r
\r
- const static std::string CREATE_PACKAGE_INFO_TABLE;\r
- const static std::string CREATE_PRIVACY_TABLE;\r
-\r
private:\r
void createDB(void);\r
- int isPackageIdAreadyExisted(const std::string pkgId, bool& isExisted);\r
\r
public:\r
\r
\r
static PrivacyManagerServer* getInstance(void);\r
\r
- sqlite3* getDBHandler(void);\r
-\r
- int getUniqueIdFromPackageId(const std::string pkgId, int& id);\r
-\r
int getPrivacyAppPackages(std::list <std::string>& list);\r
\r
- int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > > *pList);\r
+ int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > > & list);\r
\r
int setPrivacySetting(const std::string pkgId, const std::string privacyId, bool enabled);\r
\r
};\r
\r
\r
-#endif // _PRIVACY_DB_H_
\ No newline at end of file
+#endif // _PRIVACY_MANAGER_SERVER_H_
\ No newline at end of file
+++ /dev/null
-/*\r
- * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-#ifndef _TEST_SERVICE_H_\r
-#define _TEST_SERVICE_H_\r
-\r
-#include <SocketConnection.h>\r
-#include <SocketService.h>\r
-\r
-class TestService {\r
-private:\r
- inline static std::string getInterfaceName(void)\r
- {\r
- return "TestService";\r
- }\r
-\r
-public:\r
- static void registerCallbacks(SocketService* pSocketService)\r
- {\r
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("test"), test);\r
- }\r
-\r
- static void test(SocketConnection* pConnector);\r
-\r
-};\r
-#endif // _TEST_SERVICE_H_
\ No newline at end of file
#include <string>\r
#include <PrivacyManagerDaemon.h>\r
#include <PrivacyInfoService.h>\r
-#include <TestService.h>\r
#include <PrivacyManagerServer.h>\r
\r
PrivacyManagerDaemon* PrivacyManagerDaemon::pInstance = NULL;\r
pSocketService->initialize();\r
\r
PrivacyInfoService::registerCallbacks(pSocketService);\r
- TestService::registerCallbacks(pSocketService);\r
\r
return 0;\r
}\r
#include <dlog.h>\r
#include <Utils.h>\r
#include <PrivacyManagerTypes.h>\r
+#include <sqlite3.h>\r
\r
std::mutex PrivacyManagerServer::m_singletonMutex;\r
-const std::string PrivacyManagerServer::DB_PATH("/opt/dbspace/.privacy.db");\r
PrivacyManagerServer* PrivacyManagerServer::m_pInstance = NULL;\r
\r
void\r
}\r
\r
int\r
-PrivacyManagerServer::isPackageIdAreadyExisted(const std::string pkgId, bool& isExisted)\r
-{\r
- LOGI("enter");\r
-\r
- isExisted = false;\r
-\r
- static const std::string query = std::string("SELECT UNIQUE_ID from PackageInfo where PKG_ID=?");\r
-\r
- int res;\r
-\r
- openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
- prepareDb(pDbHandler, query.c_str(), pStmt);\r
-\r
- res = sqlite3_bind_text(pStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
- TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_prepare_v2 : %d", res);\r
-\r
- res = sqlite3_step(pStmt.get());\r
- if (res == SQLITE_DONE)\r
- {\r
- isExisted = true;\r
- return 0;\r
- }\r
-\r
- LOGI("leave");\r
-\r
- return 0;\r
-}\r
-\r
-int\r
-PrivacyManagerServer::getUniqueIdFromPackageId(const std::string pkgId, int& uniqueId)\r
-{\r
- LOGI("enter");\r
-\r
- static const std::string query = std::string("SELECT UNIQUE_ID from PackageInfo where PKG_ID=?");\r
-\r
- int res;\r
-\r
- openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
- prepareDb(pDbHandler, query.c_str(), pStmt);\r
-\r
- res = sqlite3_bind_text(pStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
- TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_prepare_v2 : %d", res);\r
-\r
- res = sqlite3_step(pStmt.get());\r
- TryReturn( res == SQLITE_ROW, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res);\r
-\r
-\r
- int cnt = sqlite3_data_count(pStmt.get());\r
- TryReturn(cnt != 0, PRIV_MGR_ERROR_NO_DATA, , "Failed to find data");\r
-\r
- uniqueId = sqlite3_column_int(pStmt.get(), 0);\r
-\r
- LOGI("%s : %d", pkgId.c_str(), uniqueId);\r
-\r
- LOGI("leave");\r
-\r
- return 0;\r
-}\r
-int\r
PrivacyManagerServer::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool enabled)\r
{\r
LOGI("enter");\r
\r
- static const std::string query = std::string("UPDATE Privacy set IS_ENABLED =? where ID=? and PRIVACY_ID=?");\r
-\r
- int uniqueId;\r
- int res = getUniqueIdFromPackageId(pkgId, uniqueId);\r
- TryReturn(res == 0, PRIV_MGR_ERROR_NO_DATA, , "getUniqueIdFromPackageId : %d", res);\r
+ static const std::string query = std::string("UPDATE PrivacyInfo set IS_ENABLED =? where PKG_ID=? and PRIVACY_ID=?");\r
\r
- openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+ openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
prepareDb(pDbHandler, query.c_str(), pStmt);\r
\r
- res = sqlite3_bind_int(pStmt.get(), 1, enabled);\r
+ int res = sqlite3_bind_int(pStmt.get(), 1, enabled);\r
TryReturn(res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);\r
\r
- res = sqlite3_bind_int(pStmt.get(), 2, uniqueId);\r
+ res = sqlite3_bind_text(pStmt.get(), 2, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
TryReturn(res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);\r
\r
res = sqlite3_bind_text(pStmt.get(), 3, privacyId.c_str(), -1, SQLITE_TRANSIENT);\r
{\r
LOGI("enter");\r
\r
- std::string query = "SELECT pkg_id from PackageInfo";\r
+ std::string query = "SELECT PKG_ID from PackageInfo";\r
\r
- openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+ openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
prepareDb(pDbHandler, query.c_str(), pStmt);\r
\r
while ( sqlite3_step(pStmt.get()) == SQLITE_ROW )\r
}\r
\r
int\r
-PrivacyManagerServer::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > >* pPrivacyInfoList)\r
+PrivacyManagerServer::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > >& privacyInfoList)\r
{\r
LOGI("enter");\r
\r
- static const std::string query = "SELECT PRIVACY_ID, IS_ENABLED from Privacy where ID=?";\r
-\r
- int uniqueId;\r
- int res = getUniqueIdFromPackageId(pkgId, uniqueId);\r
- TryReturn( res == 0, -1, , "getUniqueIdFromPackageId : %d", res);\r
+ static const std::string query = "SELECT PRIVACY_ID, IS_ENABLED from PrivacyInfo where PKG_ID=?";\r
\r
- openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+ openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
prepareDb(pDbHandler, query.c_str(), pStmt);\r
\r
- res = sqlite3_bind_int(pStmt.get(), 1, uniqueId);\r
+ int res = sqlite3_bind_text(pStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);\r
\r
- std::unique_ptr < std::list < std::pair < std:: string, bool > > > pList ( new std::list < std::pair < std:: string, bool > >);\r
-\r
LOGI("start");\r
- while ((res= sqlite3_step(pStmt.get())) == SQLITE_ROW )\r
+\r
+ while ( (res= sqlite3_step(pStmt.get())) == SQLITE_ROW )\r
{\r
const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0));\r
bool privacyEnabled = sqlite3_column_int(pStmt.get(), 1) > 0 ? true : false;\r
\r
- pList->push_back( std::pair <std::string, bool> (std::string(privacyId), privacyEnabled) );\r
+ privacyInfoList.push_back( std::pair <std::string, bool> (std::string(privacyId), privacyEnabled) );\r
\r
LOGD("Privacy found : %s %d", privacyId, privacyEnabled);\r
}\r
- *pPrivacyInfoList = *pList.release();\r
\r
LOGI("leave");\r
\r
LOGI("enter");\r
\r
static const std::string pkgInfoQuery("INSERT INTO PackageInfo(PKG_ID, IS_SET) VALUES(?, ?)");\r
- static const std::string privacyQuery("INSERT INTO Privacy(ID, PRIVACY_ID, IS_ENABLED) VALUES(?, ?, ?)");\r
-\r
- int res;\r
- int uniqueId;\r
- bool check;\r
- res = isPackageIdAreadyExisted(pkgId, check);\r
- TryReturn(check, PRIV_MGR_ERROR_INVALID_STATE, ,"The pkg ID %s is alreay added : %d", pkgId.c_str(), res);\r
+ static const std::string privacyQuery("INSERT INTO PrivacyInfo(PKG_ID, PRIVACY_ID, IS_ENABLED) VALUES(?, ?, ?)");\r
\r
- openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+ openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
prepareDb(pDbHandler, pkgInfoQuery.c_str(), pPkgInfoStmt);\r
\r
- res = sqlite3_bind_text(pPkgInfoStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
+ int res = sqlite3_bind_text(pPkgInfoStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
\r
res = sqlite3_bind_int(pPkgInfoStmt.get(), 2, 0);\r
\r
res = sqlite3_step(pPkgInfoStmt.get());\r
TryReturn( res == SQLITE_DONE, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res);\r
-\r
- \r
- res = getUniqueIdFromPackageId(pkgId, uniqueId);\r
- TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getUniqueIdFromPackageId : %d", res);\r
\r
for ( std::list <std::string>::const_iterator iter = privilegeList.begin(); iter != privilegeList.end(); ++iter)\r
{\r
+ LOGD(" install privacy: %s", iter->c_str());\r
prepareDb(pDbHandler, privacyQuery.c_str(), pPrivacyStmt);\r
\r
- res = sqlite3_bind_int(pPrivacyStmt.get(), 1, uniqueId);\r
+ res = sqlite3_bind_text(pPrivacyStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);\r
\r
res = sqlite3_bind_text(pPrivacyStmt.get(), 2, iter->c_str(), -1, SQLITE_TRANSIENT);\r
TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);\r
\r
res = sqlite3_step(pPrivacyStmt.get());\r
- TryReturn( res == SQLITE_DONE, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res);\r
+ TryReturn( res == SQLITE_DONE || res == SQLITE_CONSTRAINT, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res);\r
+\r
+ sqlite3_reset(pPrivacyStmt.get());\r
}\r
\r
return 0;\r
LOGI("enter");\r
\r
static const std::string pkgInfoQuery("DELETE FROM PackageInfo WHERE PKG_ID=?");\r
- static const std::string privacyQuery("DELETE FROM Privacy WHERE ID=?");\r
+ static const std::string privacyQuery("DELETE FROM PrivacyInfo WHERE PKG_ID=?");\r
\r
int res;\r
- int uniqueId;\r
- res = getUniqueIdFromPackageId(pkgId, uniqueId);\r
- TryReturn( res == 0, res, , "getUniqueIdFromPackageId : %d", res);\r
\r
- openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+ openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
prepareDb(pDbHandler, pkgInfoQuery.c_str(), pPkgInfoStmt);\r
\r
res = sqlite3_bind_text(pPkgInfoStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
\r
prepareDb(pDbHandler, privacyQuery.c_str(), pPrivacyStmt);\r
\r
- res = sqlite3_bind_int(pPrivacyStmt.get(), 1, uniqueId);\r
- TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res); \r
+ res = sqlite3_bind_text(pPrivacyStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
+ TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); \r
\r
res = sqlite3_step(pPrivacyStmt.get());\r
TryReturn( res == SQLITE_DONE, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res);\r
\r
static const std::string query = "SELECT IS_SET from PackageInfo where PKG_ID=?";\r
\r
- int uniqueId;\r
- int res = getUniqueIdFromPackageId(pkgId, uniqueId);\r
- TryReturn( res == 0, res, , "getUniqueIdFromPackageId : %d", res);\r
+ isPrompted = true;\r
\r
- openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+ openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
prepareDb(pDbHandler, query.c_str(), pStmt);\r
\r
- res = sqlite3_bind_text(pStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
+ int res = sqlite3_bind_text(pStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
\r
std::unique_ptr < std::list < std::pair < std:: string, bool > > > pList ( new std::list < std::pair < std:: string, bool > >);\r
}\r
else\r
{\r
- LOGE("Fail to get data : %d", res);\r
+ LOGE("The package[%s] doesnt access privacy", pkgId.c_str());\r
return PRIV_MGR_ERROR_DB_ERROR;\r
}\r
\r
- LOGI("leave");\r
-\r
return 0;\r
}\r
\r
\r
int res;\r
\r
- openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+ openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
prepareDb(pDbHandler, query.c_str(), pStmt);\r
\r
res = sqlite3_bind_int(pStmt.get(), 1, prompted? 1 : 0);\r
}\r
LOGI("leave");\r
return m_pInstance;\r
-}\r
-\r
-sqlite3*\r
-PrivacyManagerServer::getDBHandler(void)\r
-{\r
- return m_pDBHandler;\r
-}\r
+}
\ No newline at end of file
\r
std::list < std::pair < std::string, bool > > infoList;\r
\r
- int res = pPrivacyManagerServer->getAppPackagePrivacyInfo(pkgId, &infoList);\r
+ int res = pPrivacyManagerServer->getAppPackagePrivacyInfo(pkgId, infoList);\r
\r
pConnector->write( res );\r
pConnector->write( infoList );\r