From 81269ebd20208bc887aaa68daf2534999480aca2 Mon Sep 17 00:00:00 2001 From: Hyunwoo Kim Date: Tue, 2 Apr 2013 00:35:39 +0900 Subject: [PATCH] Add new CAPIs Change-Id: Id4f35d927d2b7a91d6d6eeb04193010dfc507389 Signed-off-by: Hyunwoo Kim --- capi/include/privacy_info.h | 14 +++++ capi/include/privacy_manager.h | 51 ++++++++++++++++ capi/src/privacy_info.c | 59 +++++++++++++++++- capi/src/privacy_manager.c | 111 +++++++++++++++++++++++++++++++++- client/inc/PrivacyManagerClient.h | 2 + client/inc/privacy_manager_client.h | 8 ++- client/src/PrivacyChecker.cpp | 8 +-- client/src/PrivacyManagerClient.cpp | 6 ++ client/src/privacy_manager_client.cpp | 64 +++++++++++++++++++- common/inc/PrivacyDb.h | 7 ++- common/inc/PrivacyIdInfo.h | 2 +- common/src/PrivacyDb.cpp | 38 +++++++++++- common/src/PrivacyIdInfo.cpp | 21 +++++++ packaging/privacy-manager.spec | 6 +- pkgmgr_plugin/privileges.cpp | 2 + server/src/SocketService.cpp | 9 +-- 16 files changed, 382 insertions(+), 26 deletions(-) diff --git a/capi/include/privacy_info.h b/capi/include/privacy_info.h index f3cee7e..4d9ee85 100644 --- a/capi/include/privacy_info.h +++ b/capi/include/privacy_info.h @@ -86,6 +86,20 @@ EXPORT_API int privacy_info_get_privacy_description(privacy_info_h privacy_info, */ EXPORT_API int privacy_info_is_enabled(privacy_info_h privacy_info, bool *enabled); +/** + * @brief Creates and returns a copy of the given privacy info handle. + * + * @remarks A newly created service should be destroyed by calling privacy_info_destroy() if it is no longer needed. + * + * @param [out] clone If successful, a newly created privacy info handle will be returned. + * @param [in] privacy_info The privacy info handle + * @return 0 on success, otherwise a negative error value. + * @retval #PRIVACY_MANAGER_ERROR_NONE Successful + * @retval #PRIVACY_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PRIVACY_MANAGER_ERROR_OUT_OF_MEMORY Out of memory + * @see privacy_info_destroy() + */ +EXPORT_API int privacy_info_clone(privacy_info_h *clone, privacy_info_h privacy_info); #ifdef __cplusplus } diff --git a/capi/include/privacy_manager.h b/capi/include/privacy_manager.h index 9900d3b..e1433e1 100644 --- a/capi/include/privacy_manager.h +++ b/capi/include/privacy_manager.h @@ -69,6 +69,29 @@ typedef bool (*privacy_manager_privacy_packages_cb) (const char *package_id, voi typedef bool (*privacy_manager_privacy_info_cb) (privacy_info_h privacy_info, void* user_data); /** + * @brief Called to get all privacy info once. + * @remarks @a privacy_info will be automatically destroyed when the callback function returns. (Do not release @a privacy_info.) + * @param[in] privacy_info_h privacy info + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop. + * @pre privacy_manager_foreach_all_privacy() will invoke this callback. + * @see privacy_manager_foreach_all_privacy() + */ +typedef bool (*privacy_manager_all_privacy_info_cb) (privacy_info_h privacy_info, void* user_data); + +/** + * @brief Called to get a package id and privacy enabled info once for each privacy ID. + * @remarks @a package_id will be automatically destroyed when the callback function returns. (Do not release @a package_id.) + * @param[in] package_id The package id which uses the specific privacy information. + * @param[in] is_enabled A Boolean value indicating whether the privacy setting of the package is enabled + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop. + * @pre privacy_manager_foreach_package_list_by_privacy() will invoke this callback. + * @see privacy_manager_foreach_package_list_by_privacy() + */ +typedef bool (*privacy_manager_packages_by_privacy_cb) (const char *package_id, bool is_enabled, void* user_data); + +/** * @brief Retrieves privacy package list. * @param [in] callback The callback function to invoke * @param [in] user_data The user data to be passed to the callback function @@ -112,6 +135,34 @@ EXPORT_API int privacy_manager_foreach_privacy_info(const char *package_id, priv */ EXPORT_API int privacy_manager_set_package_privacy(const char *package_id, const char *privacy_id, bool enable); +/** + * @brief Retrieves all privacy list. + * @param [in] callback The callback function to invoke + * @param [in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #PRIVACY_MANAGER_ERROR_NONE Successful + * @retval #PRIVACY_MANAGER_ERROR_IPC_FAILED IPC failed + * @retval #PRIVACY_MANAGER_ERROR_DB_FAILED DB operation failed + * @post This function invokes privacy_manager_all_privacy_info_cb() repeatedly for each application context. + * @see privacy_manager_all_privacy_info_cb() + */ +EXPORT_API int privacy_manager_foreach_all_privacy(privacy_manager_all_privacy_info_cb callback, void* user_data); + +/** + * @brief Retrieves package list by the privacy id. + * @param [in] callback The callback function to invoke + * @param [in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #PRIVACY_MANAGER_ERROR_NONE Successful + * @retval #PRIVACY_MANAGER_ERROR_NO_DATA no package founded. + * @retval #PRIVACY_MANAGER_ERROR_IPC_FAILED IPC failed + * @retval #PRIVACY_MANAGER_ERROR_DB_FAILED DB operation failed + * @post This function invokes privacy_manager_all_privacy_info_cb() repeatedly for each application context. + * @see privacy_manager_all_privacy_info_cb() + */ +EXPORT_API int privacy_manager_foreach_package_list_by_privacy(const char *privacy_id, privacy_manager_packages_by_privacy_cb callback, void* user_data); + + #ifdef __cplusplus } diff --git a/capi/src/privacy_info.c b/capi/src/privacy_info.c index a41284f..3f88e21 100644 --- a/capi/src/privacy_info.c +++ b/capi/src/privacy_info.c @@ -24,8 +24,33 @@ static int _privacy_info_convert_error(int error) { + int ret = PRIV_MGR_ERROR_SUCCESS; - return PRIVACY_MANAGER_ERROR_NONE; + switch (error) + { + case PRIV_MGR_ERROR_SUCCESS: + ret = PRIVACY_MANAGER_ERROR_NONE; + break; + case PRIV_MGR_ERROR_INVALID_PARAMETER: + ret = PRIVACY_MANAGER_ERROR_INVALID_PARAMETER; + break; + case PRIV_MGR_ERROR_OUT_OF_MEMORY: + ret = PRIVACY_MANAGER_ERROR_OUT_OF_MEMORY; + break; + case PRIV_MGR_ERROR_IO_ERROR: + ret = PRIVACY_MANAGER_ERROR_IO_ERROR; + break; + case PRIV_MGR_ERROR_NO_DATA: + ret = PRIVACY_MANAGER_ERROR_NO_DATA; + break; + case PRIV_MGR_ERROR_DB_ERROR: + ret = PRIVACY_MANAGER_ERROR_DB_FAILED; + break; + case PRIV_MGR_ERROR_IPC_ERROR: + ret = PRIVACY_MANAGER_ERROR_IPC_FAILED; + break; + } + return ret; } int privacy_info_destroy(privacy_info_h privacy_info) @@ -73,3 +98,35 @@ int privacy_info_is_enabled(struct privacy_info_s* privacy_info, bool *enable) return _privacy_info_convert_error(retval); } + +int privacy_info_create(const char *privacy_id, privacy_info_h *privacy_info) +{ + int retval; + privacy_info_client_s* privacy_info_client = NULL; + + retval = create_privacy_info_client_s(privacy_id, false, &privacy_info_client); + if (retval != PRIV_MGR_ERROR_SUCCESS) + return _privacy_info_convert_error(retval); + + privacy_info_h privacy_info_temp = NULL; + privacy_info_temp = (struct privacy_info_s*) calloc(1, sizeof(struct privacy_info_s)); + if (privacy_info_temp == NULL) + return PRIVACY_MANAGER_ERROR_OUT_OF_MEMORY; + + privacy_info_temp->privacy_info_client = privacy_info_client; + + *privacy_info = privacy_info_temp; + + return PRIVACY_MANAGER_ERROR_NONE; +} + +int privacy_info_clone(privacy_info_h *clone, privacy_info_h privacy_info) +{ + int retval; + if (clone == NULL || privacy_info == NULL) + return PRIVACY_MANAGER_ERROR_INVALID_PARAMETER; + + retval = privacy_info_create(privacy_info->privacy_info_client->privacy_id, clone); + + return retval; +} \ No newline at end of file diff --git a/capi/src/privacy_manager.c b/capi/src/privacy_manager.c index a78bf9d..dadd1ae 100644 --- a/capi/src/privacy_manager.c +++ b/capi/src/privacy_manager.c @@ -22,11 +22,41 @@ #include #include #include +#include static int _privacy_manager_convert_error(int error) { - return PRIVACY_MANAGER_ERROR_NONE; + int ret = PRIV_MGR_ERROR_SUCCESS; + + LOGD("before error : %d", error); + + switch (error) + { + case PRIV_MGR_ERROR_SUCCESS: + ret = PRIVACY_MANAGER_ERROR_NONE; + break; + case PRIV_MGR_ERROR_INVALID_PARAMETER: + ret = PRIVACY_MANAGER_ERROR_INVALID_PARAMETER; + break; + case PRIV_MGR_ERROR_OUT_OF_MEMORY: + ret = PRIVACY_MANAGER_ERROR_OUT_OF_MEMORY; + break; + case PRIV_MGR_ERROR_IO_ERROR: + ret = PRIVACY_MANAGER_ERROR_IO_ERROR; + break; + case PRIV_MGR_ERROR_NO_DATA: + ret = PRIVACY_MANAGER_ERROR_NO_DATA; + break; + case PRIV_MGR_ERROR_DB_ERROR: + ret = PRIVACY_MANAGER_ERROR_DB_FAILED; + break; + case PRIV_MGR_ERROR_IPC_ERROR: + ret = PRIVACY_MANAGER_ERROR_IPC_FAILED; + break; + } + LOGD("after error : %d", ret); + return ret; } typedef struct _foreach_privacy_package_context_ @@ -41,6 +71,18 @@ typedef struct _foreach_privacy_info_context_ void *user_data; } foreach_privacy_info_context_s; +typedef struct _foreach_all_privacy_context_ +{ + privacy_manager_all_privacy_info_cb callback; + void *user_data; +} foreach_all_privacy_context_s; + +typedef struct _foreach_package_by_privacy_context_ +{ + privacy_manager_packages_by_privacy_cb callback; + void *user_data; +} foreach_package_by_privacy_context_s; + //static int _create_privacy_info(const char* package_id, bool enabled, privacy_info_h *privacy_info) //{ // privacy_info_h temp = (privacy_info_h) calloc(1, sizeof(privacy_info_h)); @@ -88,6 +130,36 @@ bool __privacy_manager_client_privacy_info_cb (privacy_info_client_s* privacy_in return ret; } +bool __privacy_manager_client_all_privacy_info_cb(privacy_info_client_s* privacy_info_client, void* user_data) +{ + foreach_all_privacy_context_s* context = (foreach_all_privacy_context_s*) user_data; + + struct privacy_info_s* privacy_info = NULL; + + bool ret = false; + + privacy_info = (struct privacy_info_s*) calloc(1, sizeof(struct privacy_info_s)); + + privacy_info->privacy_info_client = privacy_info_client; + + ret = context->callback(privacy_info, context->user_data); + + free(privacy_info); + + return ret; +} + +bool __privacy_manager_client_packages_by_privacy_cb(const char *package_id, bool is_enabled, void* user_data) +{ + foreach_package_by_privacy_context_s* context = (foreach_package_by_privacy_context_s*) user_data; + + bool ret = false; + + ret = context->callback(package_id, is_enabled, context->user_data); + + return ret; +} + int privacy_manager_foreach_privacy_packages(privacy_manager_privacy_packages_cb callback, void *user_data) { int retval; @@ -124,9 +196,46 @@ int privacy_manager_foreach_privacy_info(const char *package_id, privacy_manager return _privacy_manager_convert_error(retval); } + int privacy_manager_set_package_privacy(const char *package_id, const char *privacy_id, bool enable) { int retval = privacy_manager_client_set_package_privacy(package_id, privacy_id, enable); return _privacy_manager_convert_error(retval); } + +int privacy_manager_foreach_all_privacy(privacy_manager_all_privacy_info_cb callback, void* user_data) +{ + int retval; + + foreach_all_privacy_context_s* context = NULL; + + context = (foreach_all_privacy_context_s*) calloc(1, sizeof(foreach_all_privacy_context_s)); + if (context == NULL) + return PRIV_MGR_ERROR_OUT_OF_MEMORY; + + context->callback = callback; + context->user_data = user_data; + + retval = privacy_manager_client_foreach_all_privacy(__privacy_manager_client_all_privacy_info_cb, context); + + return _privacy_manager_convert_error(retval); +} + +int privacy_manager_foreach_package_list_by_privacy(const char *privacy_id, privacy_manager_client_packages_by_privacy_cb callback, void* user_data) +{ + int retval; + + foreach_package_by_privacy_context_s* context = NULL; + + context = (foreach_package_by_privacy_context_s*) calloc(1, sizeof(foreach_package_by_privacy_context_s)); + if (context == NULL) + return PRIV_MGR_ERROR_OUT_OF_MEMORY; + + context->callback = callback; + context->user_data = user_data; + + retval = privacy_manager_client_foreach_package_list_by_privacy(privacy_id, __privacy_manager_client_packages_by_privacy_cb, context); + + return _privacy_manager_convert_error(retval); +} \ No newline at end of file diff --git a/client/inc/PrivacyManagerClient.h b/client/inc/PrivacyManagerClient.h index e5ae684..ab5cb38 100644 --- a/client/inc/PrivacyManagerClient.h +++ b/client/inc/PrivacyManagerClient.h @@ -55,6 +55,8 @@ public: int isUserPrompted(const std::string pkgId, bool& isPrompted); int setUserPrompted(const std::string pkgId, bool prompted); + + int getAppPackagesbyPrivacyId(std::string privacyId, std::list < std::pair < std::string, bool > >& list); }; #endif // _PRIVACY_MANAGER_H_ \ No newline at end of file diff --git a/client/inc/privacy_manager_client.h b/client/inc/privacy_manager_client.h index 4d407a6..43741af 100644 --- a/client/inc/privacy_manager_client.h +++ b/client/inc/privacy_manager_client.h @@ -26,6 +26,8 @@ extern "C" { typedef bool (*privacy_manager_client_privacy_packages_cb) (const char *package_id, void* user_data); typedef bool (*privacy_manager_client_privacy_info_cb) (privacy_info_client_s* privacy_info, void* user_data); +typedef bool (*privacy_manager_client_all_privacy_info_cb) (privacy_info_client_s* privacy_info, void* user_data); +typedef bool (*privacy_manager_client_packages_by_privacy_cb) (const char *package_id, bool is_enabled, void* user_data); EXTERN_API int privacy_manager_client_install_privacy(const char *package_id, const char** privacy_list); EXTERN_API int privacy_manager_client_uninstall_privacy(const char *package_id); @@ -33,7 +35,11 @@ EXTERN_API int privacy_manager_client_foreach_privacy_packages(privacy_manager_c EXTERN_API int privacy_manager_client_foreach_get_privacy_info(const char *package_id, privacy_manager_client_privacy_info_cb callback, void* user_data); EXTERN_API int privacy_manager_client_set_package_privacy(const char *package_id, const char *privacy_id, bool enable); -EXTERN_API int privacy_manager_client_check_user_consented(const char *package_id, bool consented); +EXTERN_API int privacy_manager_client_check_user_consented(const char *package_id, bool *consented); +EXTERN_API int privacy_manager_client_set_user_consented(const char *package_id, bool consented); + +EXTERN_API int privacy_manager_client_foreach_all_privacy(privacy_manager_client_all_privacy_info_cb callback, void* user_data); +EXTERN_API int privacy_manager_client_foreach_package_list_by_privacy(const char *privacy_id, privacy_manager_client_packages_by_privacy_cb callback, void* user_data); #ifdef __cplusplus } diff --git a/client/src/PrivacyChecker.cpp b/client/src/PrivacyChecker.cpp index b2d9b08..8eadd0c 100644 --- a/client/src/PrivacyChecker.cpp +++ b/client/src/PrivacyChecker.cpp @@ -274,7 +274,7 @@ PrivacyChecker::checkWithPrivilege(const std::string pkgId, const std::string pr int res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId); if (res == PRIV_MGR_ERROR_NO_DATA) { LOGD("NOT privacy privilege"); - return PRIV_MGR_ERROR_USER_NOT_CONSENTED; + return PRIV_MGR_ERROR_SUCCESS; } TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res); @@ -292,7 +292,7 @@ PrivacyChecker::checkWithPrivilege(const std::string privilege) std::string privacyId; int res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId); if (res == PRIV_MGR_ERROR_NO_DATA) - return PRIV_MGR_ERROR_USER_NOT_CONSENTED; + return PRIV_MGR_ERROR_SUCCESS; TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res); LOGI("leave"); @@ -308,7 +308,7 @@ PrivacyChecker::checkWithDeviceCap(const std::string pkgId, const std::string de std::string privacyId; int res = PrivacyIdInfo::getPrivacyIdFromDeviceCap(deviceCap, privacyId); if (res == PRIV_MGR_ERROR_NO_DATA) - return PRIV_MGR_ERROR_USER_NOT_CONSENTED; + return PRIV_MGR_ERROR_SUCCESS; TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res); LOGI("leave"); @@ -324,7 +324,7 @@ PrivacyChecker::checkWithDeviceCap(const std::string deviceCap) std::string privacyId; int res = PrivacyIdInfo::getPrivacyIdFromDeviceCap(deviceCap, privacyId); if (res == PRIV_MGR_ERROR_NO_DATA) - return PRIV_MGR_ERROR_USER_NOT_CONSENTED; + return PRIV_MGR_ERROR_SUCCESS; TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res); LOGI("leave"); diff --git a/client/src/PrivacyManagerClient.cpp b/client/src/PrivacyManagerClient.cpp index 6979767..d2633c2 100644 --- a/client/src/PrivacyManagerClient.cpp +++ b/client/src/PrivacyManagerClient.cpp @@ -166,4 +166,10 @@ PrivacyManagerClient::setUserPrompted(const std::string pkgId, bool prompted) LOGI("leave"); return result; +} + +int +PrivacyManagerClient::getAppPackagesbyPrivacyId(std::string privacyId, std::list < std::pair < std::string, bool > >& list) +{ + return PrivacyDb::getInstance()->getAppPackagesbyPrivacyId(privacyId, list); } \ No newline at end of file diff --git a/client/src/privacy_manager_client.cpp b/client/src/privacy_manager_client.cpp index c09043c..3c3c252 100644 --- a/client/src/privacy_manager_client.cpp +++ b/client/src/privacy_manager_client.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "privacy_manager_client_internal_types.h" @@ -121,9 +122,68 @@ int privacy_manager_client_set_package_privacy(const char *package_id, const cha return pInst->setPrivacySetting(package_id, privacy_id, enable); } -int privacy_manager_client_check_user_consented(const char *package_id, bool consented) +int privacy_manager_client_check_user_consented(const char *package_id, bool *consented) { PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance(); - return pInst->isUserPrompted(std::string(package_id), consented); + return pInst->isUserPrompted(std::string(package_id), *consented); +} + +int privacy_manager_client_set_user_consented(const char *package_id, bool consented) +{ + PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance(); + + return pInst->setUserPrompted(std::string(package_id), consented); +} + +int privacy_manager_client_foreach_all_privacy(privacy_manager_client_all_privacy_info_cb callback, void* user_data) +{ + int retval; + bool res; + + std::list < std::string > privacyList; + retval = PrivacyIdInfo::getAllPrivacyId(privacyList); + if (retval != PRIV_MGR_ERROR_SUCCESS) + return retval; + if (privacyList.size() == 0) + return PRIV_MGR_ERROR_NO_DATA; + + for (std::list < std::string >::iterator iter = privacyList.begin(); iter != privacyList.end(); ++iter) + { + privacy_info_client_s *privacy_info_client_s = NULL; + retval = create_privacy_info_client_s(iter->c_str(), false, &privacy_info_client_s); + res = callback(privacy_info_client_s, user_data); + privacy_info_client_s_destroy(privacy_info_client_s); + if (!res) + break; + } + + return PRIV_MGR_ERROR_SUCCESS; +} + +int privacy_manager_client_foreach_package_list_by_privacy(const char *privacy_id, privacy_manager_client_packages_by_privacy_cb callback, void* user_data) +{ + int retval; + bool res; + PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance(); + + std::list < std::pair < std::string, bool > > packageList; + retval = pInst->getAppPackagesbyPrivacyId(std::string(privacy_id), packageList); + for (std::list < std::pair < std::string, bool > >::iterator iter = packageList.begin(); iter != packageList.end(); ++iter) + { + LOGD("result : %s %d", iter->first.c_str(), iter->second); + } + if (retval != PRIV_MGR_ERROR_SUCCESS) + return retval; + if (packageList.size() == 0) + return PRIV_MGR_ERROR_NO_DATA; + + for (std::list < std::pair < std::string, bool > >::iterator iter = packageList.begin(); iter != packageList.end(); ++iter) + { + res = callback(iter->first.c_str(), iter->second, user_data); + if (!res) + break; + } + + return PRIV_MGR_ERROR_SUCCESS; } \ No newline at end of file diff --git a/common/inc/PrivacyDb.h b/common/inc/PrivacyDb.h index 4ba9d80..d74b958 100644 --- a/common/inc/PrivacyDb.h +++ b/common/inc/PrivacyDb.h @@ -38,9 +38,9 @@ private: public: static PrivacyDb* getInstance(void); - int getPrivacyAppPackages(std::list & list); + int getPrivacyAppPackages(std::list & list) const; - int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > > & list); + int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > > & list) const; int setPrivacySetting(const std::string pkgId, const std::string privacyId, bool enabled); @@ -48,10 +48,11 @@ public: int removeAppPackagePrivacyInfo(const std::string pkgId); - int isUserPrompted(const std::string pkgId, bool& isPrompted); + int isUserPrompted(const std::string pkgId, bool& isPrompted) const; int setUserPrompted(const std::string pkgId, bool prompted); + int getAppPackagesbyPrivacyId(std::string privacyId, std::list < std::pair < std::string, bool > >& list) const; }; diff --git a/common/inc/PrivacyIdInfo.h b/common/inc/PrivacyIdInfo.h index 3756369..0c58248 100644 --- a/common/inc/PrivacyIdInfo.h +++ b/common/inc/PrivacyIdInfo.h @@ -32,8 +32,8 @@ public: static int initialize(void); static int getPrivacyIdFromPrivilege(const std::string privilege, std::string& privacyId); static int getPrivacyIdFromDeviceCap(const std::string deviceCap, 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); }; #endif //_PRIVACY_ID_INFO_H_ \ No newline at end of file diff --git a/common/src/PrivacyDb.cpp b/common/src/PrivacyDb.cpp index 0335b82..efab9e9 100644 --- a/common/src/PrivacyDb.cpp +++ b/common/src/PrivacyDb.cpp @@ -58,7 +58,7 @@ PrivacyDb::setPrivacySetting(const std::string pkgId, const std::string privacyI } int -PrivacyDb::getPrivacyAppPackages(std::list & list) +PrivacyDb::getPrivacyAppPackages(std::list & list) const { LOGI("enter"); @@ -81,7 +81,7 @@ PrivacyDb::getPrivacyAppPackages(std::list & list) } int -PrivacyDb::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > >& privacyInfoList) +PrivacyDb::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > >& privacyInfoList) const { LOGI("enter"); @@ -186,7 +186,7 @@ PrivacyDb::removeAppPackagePrivacyInfo(const std::string pkgId) } int -PrivacyDb::isUserPrompted(const std::string pkgId, bool& isPrompted) +PrivacyDb::isUserPrompted(const std::string pkgId, bool& isPrompted) const { LOGI("enter"); @@ -239,6 +239,38 @@ PrivacyDb::setUserPrompted(const std::string pkgId, bool prompted) return 0; } +int +PrivacyDb::getAppPackagesbyPrivacyId(std::string privacyId, std::list < std::pair < std::string, bool > >& list) const +{ + LOGI("enter"); + + std::string sql = std::string("SELECT PKG_ID, IS_ENABLED from PrivacyInfo where PRIVACY_ID=?"); + + openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); + prepareDb(pDbHandler, sql.c_str(), pStmt); + + LOGD("privacy id : %s", privacyId.c_str()); + 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); + + while ( sqlite3_step(pStmt.get()) == SQLITE_ROW ) + { + + const char* pPkgId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0)); + bool isEnabled = sqlite3_column_int(pStmt.get(), 1) > 0 ? true : false; + LOGD("result : %s %d", pPkgId, isEnabled); + list.push_back( std::pair (std::string(pPkgId), isEnabled) ); + } + + + + + LOGI("leave %d", res); + + return PRIV_MGR_ERROR_SUCCESS; +} + + PrivacyDb::PrivacyDb(void) { diff --git a/common/src/PrivacyIdInfo.cpp b/common/src/PrivacyIdInfo.cpp index 080420b..048f527 100644 --- a/common/src/PrivacyIdInfo.cpp +++ b/common/src/PrivacyIdInfo.cpp @@ -183,4 +183,25 @@ PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(const std::list < std::string> } return PRIV_MGR_ERROR_SUCCESS; +} + +int +PrivacyIdInfo::getAllPrivacyId(std::list < std::string >& privacyIdList) +{ + static const std::string sql("SELECT PRIVACY_ID from PrivacyInfo"); + + LOGI("enter"); + + 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 ) + { + const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0)); + privacyIdList.push_back(std::string(privacyId)); + LOGD(" privacy Id : %s", privacyId); + } + + return PRIV_MGR_ERROR_SUCCESS; } \ No newline at end of file diff --git a/packaging/privacy-manager.spec b/packaging/privacy-manager.spec index 33cb60e..391d213 100644 --- a/packaging/privacy-manager.spec +++ b/packaging/privacy-manager.spec @@ -1,7 +1,7 @@ Name: privacy-manager-server Summary: Privacy Management Version: 0.0.2 -Release: 2 +Release: 3 Group: System/Libraries License: SAMSUNG Source0: %{name}-%{version}.tar.gz @@ -112,8 +112,8 @@ install -D %{SOURCE4} %{buildroot}%{_datadir}/capi-security-privacy-manager.mani #mkdir -p %{buildroot}/etc/rc.d/rc3.d #mkdir -p %{buildroot}/etc/rc.d/rc5.d -#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 +#ln -sf /etc/rc.d/init.d/privacy-manager-server.sh %{buildroot}/etc/rc.d/rc3.d/S10privacy-manager-server.sh +#ln -sf /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 diff --git a/pkgmgr_plugin/privileges.cpp b/pkgmgr_plugin/privileges.cpp index 83248d9..e52cffb 100644 --- a/pkgmgr_plugin/privileges.cpp +++ b/pkgmgr_plugin/privileges.cpp @@ -103,6 +103,8 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId) } LOGI("leave"); + + return 0; } extern "C" diff --git a/server/src/SocketService.cpp b/server/src/SocketService.cpp index 612c3e2..8695ca0 100644 --- a/server/src/SocketService.cpp +++ b/server/src/SocketService.cpp @@ -32,8 +32,6 @@ #include "SocketConnection.h" const int SocketService::MAX_LISTEN = 5; -const int SocketService::TIMEOUT_SEC = 0; -const int SocketService::TIMEOUT_NSEC = 100000000; SocketService::SocketService(void) : m_listenFd(-1) @@ -153,7 +151,6 @@ SocketService::mainloop(void) FD_ZERO(&allset); FD_SET(m_listenFd, &allset); FD_SET(signal_fd, &allset); - timespec timeout; maxfd = (m_listenFd > signal_fd) ? (m_listenFd) : (signal_fd); ++maxfd; //this will block SIGPIPE for this thread and every thread created in it @@ -166,10 +163,8 @@ SocketService::mainloop(void) while(1) { - timeout.tv_sec = TIMEOUT_SEC; - timeout.tv_nsec = TIMEOUT_NSEC; rset = allset; - if(pselect(maxfd, &rset, NULL, NULL, &timeout, NULL) == -1) + if(pselect(maxfd, &rset, NULL, NULL, NULL, NULL) == -1) { closeConnections(); LOGE("pselect()"); @@ -371,4 +366,4 @@ SocketService::closeConnections(void) } LOGI("Connections closed"); -} \ No newline at end of file +} -- 2.7.4