-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)\r
-\r
-MESSAGE("build privacy-manager")\r
-\r
-SET(CMAKE_VERBOSE_MAKEFILE OFF)\r
-\r
-IF("${USE_AUTOSTART}" STREQUAL "1")\r
- ADD_DEFINITIONS("-DUSE_AUTOSTART")\r
-ENDIF()\r
-\r
-ADD_DEFINITIONS("-DCLIENT_IPC_THREAD")\r
-ADD_DEFINITIONS("-DUSE_IPC_EPOLL")\r
-\r
-STRING(REGEX MATCH "([^.]*)" API_VERSION "${VERSION}")\r
-ADD_DEFINITIONS("-DAPI_VERSION=\"$(API_VERSION)\"")\r
-\r
-ADD_SUBDIRECTORY(server)\r
-ADD_SUBDIRECTORY(client)\r
-#ADD_SUBDIRECTORY(test)\r
-ADD_SUBDIRECTORY(capi)\r
-ADD_SUBDIRECTORY(pkgmgr_plugin)\r
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+MESSAGE("build privacy-manager")
+
+SET(CMAKE_VERBOSE_MAKEFILE OFF)
+
+IF("${USE_AUTOSTART}" STREQUAL "1")
+ ADD_DEFINITIONS("-DUSE_AUTOSTART")
+ENDIF()
+
+ADD_DEFINITIONS("-DCLIENT_IPC_THREAD")
+ADD_DEFINITIONS("-DUSE_IPC_EPOLL")
+
+STRING(REGEX MATCH "([^.]*)" API_VERSION "${VERSION}")
+ADD_DEFINITIONS("-DAPI_VERSION=\"$(API_VERSION)\"")
+
+ADD_SUBDIRECTORY(server)
+ADD_SUBDIRECTORY(client)
+#ADD_SUBDIRECTORY(test)
+ADD_SUBDIRECTORY(capi)
+ADD_SUBDIRECTORY(pkgmgr_plugin)
*/
EXPORT_API int privacy_info_is_enabled(privacy_info_h privacy_info, bool *enabled);
-/**\r
- * @brief Creates and returns a copy of the given privacy info handle.\r
- *\r
- * @remarks A newly created service should be destroyed by calling privacy_info_destroy() if it is no longer needed.\r
- *\r
- * @param [out] clone If successful, a newly created privacy info handle will be returned.\r
- * @param [in] privacy_info The privacy info handle\r
- * @return 0 on success, otherwise a negative error value.\r
- * @retval #PRIVACY_MANAGER_ERROR_NONE Successful\r
- * @retval #PRIVACY_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter\r
- * @retval #PRIVACY_MANAGER_ERROR_OUT_OF_MEMORY Out of memory\r
- * @see privacy_info_destroy()\r
- */\r
-EXPORT_API int privacy_info_clone(privacy_info_h *clone, privacy_info_h privacy_info);\r
+/**
+ * @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
}
-/*\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
-#include <string.h>\r
-#include <stdlib.h>\r
-#include <privacy_manager.h>\r
-#include <privacy_info.h>\r
-#include <privacy_manager_client_types.h>\r
-#include <privacy_info_client.h>\r
-#include <privacy_manager_client.h>\r
-#include <privacy_manager_types_private.h>\r
-#include <dlog.h>\r
-\r
-\r
-static int _privacy_manager_convert_error(int error)\r
-{\r
- int ret = PRIV_MGR_ERROR_SUCCESS;\r
-\r
- LOGD("before error : %d", error);\r
-\r
- switch (error) \r
- {\r
- case PRIV_MGR_ERROR_SUCCESS:\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <privacy_manager.h>
+#include <privacy_info.h>
+#include <privacy_manager_client_types.h>
+#include <privacy_info_client.h>
+#include <privacy_manager_client.h>
+#include <privacy_manager_types_private.h>
+#include <dlog.h>
+
+
+static int _privacy_manager_convert_error(int error)
+{
+ 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:
case PRIV_MGR_ERROR_DB_ERROR:
ret = PRIVACY_MANAGER_ERROR_DB_FAILED;
break;
- case PRIV_MGR_ERROR_IPC_ERROR:\r
- ret = PRIVACY_MANAGER_ERROR_IPC_FAILED;\r
- break;\r
- }\r
- LOGD("after error : %d", ret);\r
- return ret;\r
-}\r
-\r
-typedef struct _foreach_privacy_package_context_\r
-{\r
- privacy_manager_privacy_packages_cb callback;\r
- void *user_data;\r
-} foreach_privacy_package_context_s;\r
-\r
-typedef struct _foreach_privacy_info_context_\r
-{\r
- privacy_manager_privacy_info_cb callback;\r
- void *user_data;\r
-} foreach_privacy_info_context_s;\r
-\r
-typedef struct _foreach_all_privacy_context_\r
-{\r
- privacy_manager_all_privacy_info_cb callback;\r
- void *user_data;\r
-} foreach_all_privacy_context_s;\r
-\r
-typedef struct _foreach_package_by_privacy_context_\r
-{\r
- privacy_manager_packages_by_privacy_cb callback;\r
- void *user_data;\r
-} foreach_package_by_privacy_context_s;\r
-\r
-//static int _create_privacy_info(const char* package_id, bool enabled, privacy_info_h *privacy_info)\r
-//{\r
-// privacy_info_h temp = (privacy_info_h) calloc(1, sizeof(privacy_info_h));\r
-// if (temp == NULL)\r
-// return PRIV_MGR_ERROR_OUT_OF_MEMORY;\r
-//\r
-// int size = strlen(package_id);\r
-// temp->privacy_info_client->privacy_id = (char*) calloc(1, size + 1);\r
-// if (temp->privacy_info_client->privacy_id == NULL)\r
-// {\r
-// free(temp);\r
-// return PRIV_MGR_ERROR_OUT_OF_MEMORY;\r
-// }\r
-// memcpy(temp->privacy_info_client->privacy_id, package_id, size + 1);\r
-//\r
-// temp->privacy_info_client->is_enabled = enabled;\r
-//\r
-// *privacy_info = temp;\r
-//\r
-// return PRIV_MGR_ERROR_SUCCESS;\r
-//}\r
-\r
-bool __privacy_manager_client_privacy_packages_cb(const char *package_id, void* user_data)\r
-{\r
- foreach_privacy_package_context_s* context = (foreach_privacy_package_context_s*) user_data;\r
- return context->callback(package_id, context->user_data);\r
-}\r
-\r
-bool __privacy_manager_client_privacy_info_cb (privacy_info_client_s* privacy_info_client, void* user_data)\r
-{\r
- foreach_privacy_info_context_s* context = (foreach_privacy_info_context_s*) user_data;\r
-\r
- struct privacy_info_s* privacy_info = NULL;\r
-\r
- bool ret = false;\r
-\r
- privacy_info = (struct privacy_info_s*) calloc(1, sizeof(struct privacy_info_s));\r
-\r
- privacy_info->privacy_info_client = privacy_info_client;\r
-\r
- ret = context->callback(privacy_info, context->user_data);\r
-\r
- free(privacy_info);\r
-\r
- return ret;\r
-}\r
-\r
-bool __privacy_manager_client_all_privacy_info_cb(privacy_info_client_s* privacy_info_client, void* user_data)\r
-{\r
- foreach_all_privacy_context_s* context = (foreach_all_privacy_context_s*) user_data;\r
-\r
- struct privacy_info_s* privacy_info = NULL;\r
-\r
- bool ret = false;\r
-\r
- privacy_info = (struct privacy_info_s*) calloc(1, sizeof(struct privacy_info_s));\r
-\r
- privacy_info->privacy_info_client = privacy_info_client;\r
-\r
- ret = context->callback(privacy_info, context->user_data);\r
-\r
- free(privacy_info);\r
-\r
- return ret;\r
-}\r
-\r
-bool __privacy_manager_client_packages_by_privacy_cb(const char *package_id, bool is_enabled, void* user_data)\r
-{\r
- foreach_package_by_privacy_context_s* context = (foreach_package_by_privacy_context_s*) user_data;\r
-\r
- bool ret = false;\r
-\r
- ret = context->callback(package_id, is_enabled, context->user_data);\r
-\r
- return ret;\r
-}\r
-\r
-int privacy_manager_foreach_privacy_packages(privacy_manager_privacy_packages_cb callback, void *user_data)\r
-{\r
- int retval;\r
-\r
- foreach_privacy_package_context_s* context = NULL;\r
-\r
- context = (foreach_privacy_package_context_s*) calloc(1, sizeof(foreach_privacy_package_context_s));\r
- if (context == NULL)\r
- return PRIV_MGR_ERROR_OUT_OF_MEMORY;\r
-\r
- context->callback = callback;\r
- context->user_data = user_data;\r
-\r
- retval = privacy_manager_client_foreach_privacy_packages(__privacy_manager_client_privacy_packages_cb, context);\r
- free(context);\r
-\r
- return _privacy_manager_convert_error(retval);\r
-}\r
-\r
-int privacy_manager_foreach_privacy_info(const char *package_id, privacy_manager_privacy_info_cb callback, void* user_data)\r
-{\r
- int retval;\r
-\r
- foreach_privacy_info_context_s* context = NULL;\r
- \r
- context = (foreach_privacy_info_context_s*) calloc(1, sizeof(foreach_privacy_info_context_s));\r
- if (context == NULL)\r
- return PRIV_MGR_ERROR_OUT_OF_MEMORY;\r
-\r
- context->callback = callback;\r
- context->user_data = user_data;\r
-\r
- retval = privacy_manager_client_foreach_get_privacy_info(package_id, __privacy_manager_client_privacy_info_cb, context);\r
-\r
- return _privacy_manager_convert_error(retval);\r
-}\r
-\r
-int privacy_manager_set_package_privacy(const char *package_id, const char *privacy_id, bool enable)\r
-{\r
- int retval = privacy_manager_client_set_package_privacy(package_id, privacy_id, enable);\r
-\r
- return _privacy_manager_convert_error(retval);\r
-}\r
-\r
-int privacy_manager_foreach_all_privacy(privacy_manager_all_privacy_info_cb callback, void* user_data)\r
-{\r
- int retval;\r
-\r
- foreach_all_privacy_context_s* context = NULL;\r
- \r
- context = (foreach_all_privacy_context_s*) calloc(1, sizeof(foreach_all_privacy_context_s));\r
- if (context == NULL)\r
- return PRIV_MGR_ERROR_OUT_OF_MEMORY;\r
-\r
- context->callback = callback;\r
- context->user_data = user_data;\r
-\r
- retval = privacy_manager_client_foreach_all_privacy(__privacy_manager_client_all_privacy_info_cb, context);\r
-\r
- return _privacy_manager_convert_error(retval);\r
-}\r
-\r
-int privacy_manager_foreach_package_list_by_privacy(const char *privacy_id, privacy_manager_client_packages_by_privacy_cb callback, void* user_data)\r
-{\r
- int retval;\r
-\r
- foreach_package_by_privacy_context_s* context = NULL;\r
- \r
- context = (foreach_package_by_privacy_context_s*) calloc(1, sizeof(foreach_package_by_privacy_context_s));\r
- if (context == NULL)\r
- return PRIV_MGR_ERROR_OUT_OF_MEMORY;\r
-\r
- context->callback = callback;\r
- context->user_data = user_data;\r
-\r
- retval = privacy_manager_client_foreach_package_list_by_privacy(privacy_id, __privacy_manager_client_packages_by_privacy_cb, context);\r
-\r
- return _privacy_manager_convert_error(retval);\r
+ 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_
+{
+ privacy_manager_privacy_packages_cb callback;
+ void *user_data;
+} foreach_privacy_package_context_s;
+
+typedef struct _foreach_privacy_info_context_
+{
+ privacy_manager_privacy_info_cb callback;
+ 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));
+// if (temp == NULL)
+// return PRIV_MGR_ERROR_OUT_OF_MEMORY;
+//
+// int size = strlen(package_id);
+// temp->privacy_info_client->privacy_id = (char*) calloc(1, size + 1);
+// if (temp->privacy_info_client->privacy_id == NULL)
+// {
+// free(temp);
+// return PRIV_MGR_ERROR_OUT_OF_MEMORY;
+// }
+// memcpy(temp->privacy_info_client->privacy_id, package_id, size + 1);
+//
+// temp->privacy_info_client->is_enabled = enabled;
+//
+// *privacy_info = temp;
+//
+// return PRIV_MGR_ERROR_SUCCESS;
+//}
+
+bool __privacy_manager_client_privacy_packages_cb(const char *package_id, void* user_data)
+{
+ foreach_privacy_package_context_s* context = (foreach_privacy_package_context_s*) user_data;
+ return context->callback(package_id, context->user_data);
+}
+
+bool __privacy_manager_client_privacy_info_cb (privacy_info_client_s* privacy_info_client, void* user_data)
+{
+ foreach_privacy_info_context_s* context = (foreach_privacy_info_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_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;
+
+ foreach_privacy_package_context_s* context = NULL;
+
+ context = (foreach_privacy_package_context_s*) calloc(1, sizeof(foreach_privacy_package_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_privacy_packages(__privacy_manager_client_privacy_packages_cb, context);
+ free(context);
+
+ return _privacy_manager_convert_error(retval);
+}
+
+int privacy_manager_foreach_privacy_info(const char *package_id, privacy_manager_privacy_info_cb callback, void* user_data)
+{
+ int retval;
+
+ foreach_privacy_info_context_s* context = NULL;
+
+ context = (foreach_privacy_info_context_s*) calloc(1, sizeof(foreach_privacy_info_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_get_privacy_info(package_id, __privacy_manager_client_privacy_info_cb, context);
+
+ 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
-/*\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
-#ifndef _PRIVACY_CHECKER_H_\r
-#define _PRIVACY_CHECKER_H_\r
-\r
-#include <string>\r
-#include <mutex>\r
-#include <list>\r
-#include <vector>\r
-#include <memory>\r
-#include <map>\r
-#include <PrivacyManagerTypes.h>\r
-#include <dbus/dbus.h>\r
-#include <glib.h>\r
-\r
-struct sqlite3;\r
-\r
-class EXTERN_API PrivacyChecker\r
-{\r
-private:\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
- static DBusConnection* m_pDBusConnection;\r
- static GMainLoop* m_pLoop;\r
- static GMainContext* m_pHandlerGMainContext;\r
- static pthread_t m_signalThread;\r
-\r
-private:\r
- static int initializeDbus(void);\r
- static int finalizeDbus(void);\r
- static int updateCache(const std::string pkgId, std::string privacyId, std::map < std::string, bool >& pkgCacheMap);\r
- static int updateCache(const std::string pkgId, 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
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _PRIVACY_CHECKER_H_
+#define _PRIVACY_CHECKER_H_
+
+#include <string>
+#include <mutex>
+#include <list>
+#include <vector>
+#include <memory>
+#include <map>
+#include <PrivacyManagerTypes.h>
+#include <dbus/dbus.h>
+#include <glib.h>
+
+struct sqlite3;
+
+class EXTERN_API PrivacyChecker
+{
+private:
+ static std::map < std::string, bool > m_privacyCache;
+ static std::map < std::string, std::map < std::string, bool > > m_privacyInfoCache;
+ static std::string m_pkgId;
+ static bool m_isInitialized;
+ static std::mutex m_cacheMutex;
+ static DBusConnection* m_pDBusConnection;
+ static GMainLoop* m_pLoop;
+ static GMainContext* m_pHandlerGMainContext;
+ static pthread_t m_signalThread;
+
+private:
+ static int initializeDbus(void);
+ static int finalizeDbus(void);
+ static int updateCache(const std::string pkgId, std::string privacyId, std::map < std::string, bool >& pkgCacheMap);
+ static int updateCache(const std::string pkgId, std::map < std::string, bool >& pkgCacheMap);
+ static void printCache(void);
+ static void* runSignalListenerThread(void* pData);
+ static int getCurrentPkgId(std::string& pkgId);
+ static int check(const std::string privacyId, std::map < std::string, bool >& privacyMap);
+
+public:
+ // for Checking in App Process
+ static int initialize(const std::string pkgId);
+ static int check(const std::string pkgId, const std::string privacyId);
+ static int checkWithPrivilege(const std::string pkgId, const std::string privilegeId);
+ static int checkWithDeviceCap(const std::string pkgId, const std::string deviceCap);
+
+ // for Checking in Server Process
+ static int initialize(void);
+ static int check(const std::string privacyId);
+ static int checkWithPrivilege(const std::string privilegeId);
+ static int checkWithDeviceCap(const std::string deviceCap);
+
+ // common
+ static int finalize(void);
+ static DBusHandlerResult handleNotification(DBusConnection* connection, DBusMessage* message, void* user_data);
+};
+
#endif // _PRIVACY_CHECKER_H_
\ No newline at end of file
-/*\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
-#ifndef _PRIVACY_MANAGER_H_\r
-#define _PRIVACY_MANAGER_H_\r
-\r
-#include <string>\r
-#include <mutex>\r
-#include <list>\r
-#include <vector>\r
-#include <memory>\r
-#include <PrivacyManagerTypes.h>\r
-\r
-class SocketClient;\r
-\r
-class EXTERN_API PrivacyManagerClient\r
-{\r
-private:\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
- PrivacyManagerClient();\r
- ~PrivacyManagerClient();\r
-\r
-public:\r
- static PrivacyManagerClient* getInstance(void);\r
-\r
- int addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& list, bool privacyPopupRequired, bool isServerOperation = true);\r
-\r
- int removeAppPackagePrivacyInfo(const std::string pkgId, bool isServerOperation = true);\r
-\r
- int setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled);\r
- \r
- int getPrivacyAppPackages(std::list < std::string >& list) const;\r
-\r
- int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & list) const;\r
-\r
- int isUserPrompted(const std::string pkgId, bool& isPrompted) const;\r
-\r
- int setUserPrompted(const std::string pkgId, bool prompted);\r
-\r
- int getAppPackagesbyPrivacyId(const std::string privacyId, std::list < std::pair < std::string, bool > >& list) const;\r
-\r
- int getPrivaycDisplayName(const std::string privacyId, std::string& displayName) const;\r
-\r
- int getPrivaycDescription(const std::string privacyId, std::string& description) const;\r
-};\r
-\r
-#endif // _PRIVACY_MANAGER_H_\r
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _PRIVACY_MANAGER_H_
+#define _PRIVACY_MANAGER_H_
+
+#include <string>
+#include <mutex>
+#include <list>
+#include <vector>
+#include <memory>
+#include <PrivacyManagerTypes.h>
+
+class SocketClient;
+
+class EXTERN_API PrivacyManagerClient
+{
+private:
+ static PrivacyManagerClient* m_pInstance;
+ static const std::string INTERFACE_NAME;
+
+ std::unique_ptr< SocketClient > m_pSocketClient;
+
+ static std::mutex m_singletonMutex;
+
+ PrivacyManagerClient();
+ ~PrivacyManagerClient();
+
+public:
+ static PrivacyManagerClient* getInstance(void);
+
+ int addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& list, bool privacyPopupRequired, bool isServerOperation = true);
+
+ int removeAppPackagePrivacyInfo(const std::string pkgId, bool isServerOperation = true);
+
+ int setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled);
+
+ int getPrivacyAppPackages(std::list < std::string >& list) const;
+
+ int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & list) const;
+
+ int isUserPrompted(const std::string pkgId, bool& isPrompted) const;
+
+ int setUserPrompted(const std::string pkgId, bool prompted);
+
+ int getAppPackagesbyPrivacyId(const std::string privacyId, std::list < std::pair < std::string, bool > >& list) const;
+
+ int getPrivaycDisplayName(const std::string privacyId, std::string& displayName) const;
+
+ int getPrivaycDescription(const std::string privacyId, std::string& description) const;
+};
+
+#endif // _PRIVACY_MANAGER_H_
\ No newline at end of file
-/*\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
-#ifndef SECURITYSOCKETCLIENT_H_\r
-#define SECURITYSOCKETCLIENT_H_\r
-\r
-#include <memory>\r
-#include <string>\r
-#include <dlog.h>\r
-#include "SocketConnection.h"\r
-\r
-/* IMPORTANT:\r
- * Methods connect(), call() and disconnected() should be called one by one.\r
- * Between connect() and disconnect() you can use call() only once.\r
- * It is because of timeout on call, e.g. to avoid waiting for corrupted data.\r
- */\r
-\r
-/* USAGE:\r
- * Class should be used according to this scheme:\r
- * SocketClient client("Interface Name");\r
- * (...)\r
- * client.connect();\r
- * client.call("Method name", in_arg1, in_arg2, ..., in_argN,\r
- * out_arg1, out_arg2, ..., out_argM);\r
- * client.disconnect();\r
- * (...)\r
- *\r
- * input parameters of the call are passed with reference,\r
- * output ones are passed as pointers - parameters MUST be passed this way.\r
- *\r
- * Currently client supports serialization and deserialization of simple types\r
- * (int, char, float, unsigned), strings (std::string and char*) and\r
- * some STL containers (std::vector, std::list, std::map, std::pair).\r
- * Structures and classes are not (yet) supported.\r
- */\r
-\r
-#include <string>\r
-#include <PrivacyManagerTypes.h>\r
-\r
-class EXTERN_API SocketClient \r
-{\r
-public:\r
-\r
- SocketClient(const std::string &interfaceName);\r
- int connect();\r
- int disconnect();\r
-\r
- int call(std::string methodName)\r
- {\r
- int res = make_call(m_interfaceName);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);\r
-\r
- res = make_call(methodName);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- template<typename ...Args>\r
- int call(std::string methodName, const Args&... args)\r
- {\r
- int res = make_call(m_interfaceName);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);\r
- res = make_call(methodName);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);\r
- res = make_call(args...);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- template<typename T>\r
- int read(T* outvalue)\r
- {\r
- return m_socketConnector->read(outvalue);\r
- }\r
-private:\r
- template<typename T, typename ...Args>\r
- int make_call(const T& invalue, const Args&... args)\r
- {\r
- int res = make_call(invalue);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);\r
- res = make_call(args...);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- template<typename T>\r
- int make_call(const T& invalue)\r
- {\r
- return m_socketConnector->write(invalue);\r
- }\r
-\r
- template<typename T, typename ...Args>\r
- int make_call(const T* invalue, const Args&... args)\r
- {\r
- int res = make_call(invalue);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);\r
- res = make_call(args...);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- template<typename T>\r
- int make_call(const T* invalue)\r
- {\r
- return m_socketConnector->write(invalue);\r
- }\r
-\r
- template<typename T, typename ...Args>\r
- int make_call(T * outvalue, const Args&... args)\r
- {\r
- int res = make_call(outvalue);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);\r
- res = make_call(args...);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- template<typename T>\r
- int make_call(T* outvalue)\r
- {\r
- return m_socketConnector->read(outvalue);\r
- }\r
-\r
-\r
-private:\r
- std::string m_serverAddress;\r
- std::string m_interfaceName;\r
- std::unique_ptr<SocketConnection> m_socketConnector;\r
- int m_socketFd;\r
-};\r
-\r
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SECURITYSOCKETCLIENT_H_
+#define SECURITYSOCKETCLIENT_H_
+
+#include <memory>
+#include <string>
+#include <dlog.h>
+#include "SocketConnection.h"
+
+/* IMPORTANT:
+ * Methods connect(), call() and disconnected() should be called one by one.
+ * Between connect() and disconnect() you can use call() only once.
+ * It is because of timeout on call, e.g. to avoid waiting for corrupted data.
+ */
+
+/* USAGE:
+ * Class should be used according to this scheme:
+ * SocketClient client("Interface Name");
+ * (...)
+ * client.connect();
+ * client.call("Method name", in_arg1, in_arg2, ..., in_argN,
+ * out_arg1, out_arg2, ..., out_argM);
+ * client.disconnect();
+ * (...)
+ *
+ * input parameters of the call are passed with reference,
+ * output ones are passed as pointers - parameters MUST be passed this way.
+ *
+ * Currently client supports serialization and deserialization of simple types
+ * (int, char, float, unsigned), strings (std::string and char*) and
+ * some STL containers (std::vector, std::list, std::map, std::pair).
+ * Structures and classes are not (yet) supported.
+ */
+
+#include <string>
+#include <PrivacyManagerTypes.h>
+
+class EXTERN_API SocketClient
+{
+public:
+
+ SocketClient(const std::string &interfaceName);
+ int connect();
+ int disconnect();
+
+ int call(std::string methodName)
+ {
+ int res = make_call(m_interfaceName);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);
+
+ res = make_call(methodName);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ template<typename ...Args>
+ int call(std::string methodName, const Args&... args)
+ {
+ int res = make_call(m_interfaceName);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);
+ res = make_call(methodName);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);
+ res = make_call(args...);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ template<typename T>
+ int read(T* outvalue)
+ {
+ return m_socketConnector->read(outvalue);
+ }
+private:
+ template<typename T, typename ...Args>
+ int make_call(const T& invalue, const Args&... args)
+ {
+ int res = make_call(invalue);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);
+ res = make_call(args...);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ template<typename T>
+ int make_call(const T& invalue)
+ {
+ return m_socketConnector->write(invalue);
+ }
+
+ template<typename T, typename ...Args>
+ int make_call(const T* invalue, const Args&... args)
+ {
+ int res = make_call(invalue);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);
+ res = make_call(args...);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ template<typename T>
+ int make_call(const T* invalue)
+ {
+ return m_socketConnector->write(invalue);
+ }
+
+ template<typename T, typename ...Args>
+ int make_call(T * outvalue, const Args&... args)
+ {
+ int res = make_call(outvalue);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);
+ res = make_call(args...);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ template<typename T>
+ int make_call(T* outvalue)
+ {
+ return m_socketConnector->read(outvalue);
+ }
+
+
+private:
+ std::string m_serverAddress;
+ std::string m_interfaceName;
+ std::unique_ptr<SocketConnection> m_socketConnector;
+ int m_socketFd;
+};
+
#endif /* SECURITYSOCKETCLIENT_H_ */
\ No newline at end of file
-/*\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 _PRIVACY_CHECKER_CLIENT_H\r
-#define _PRIVACY_CHECKER_CLIENT_H\r
-\r
-#include <privacy_manager_client_types.h>\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\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_by_privilege(const char *privilege_id);\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
-\r
-EXTERN_API int privacy_checker_finalize(void);\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-\r
-#endif //_PRIVACY_CHECKER_CLIENT_H\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _PRIVACY_CHECKER_CLIENT_H
+#define _PRIVACY_CHECKER_CLIENT_H
+
+#include <privacy_manager_client_types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+EXTERN_API int privacy_checker_initialize(const char *package_id);
+EXTERN_API int privacy_checker_check_privacy(const char *privacy_id);
+EXTERN_API int privacy_checker_check_by_privilege(const char *privilege_id);
+EXTERN_API int privacy_checker_finalize(void);
+
+EXTERN_API int privacy_checker_check_package_by_privilege(const char* package_id, const char *privilege_id);
+
+EXTERN_API int privacy_checker_finalize(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif //_PRIVACY_CHECKER_CLIENT_H
-/*\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 _PRIVACY_INFO_CLIENT_H\r
-#define _PRIVACY_INFO_CLIENT_H\r
-\r
-#include <privacy_manager_client_types.h>\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-typedef struct _privacy_info_client_s {\r
- char *privacy_id;\r
- bool is_enabled;\r
-} privacy_info_client_s;\r
-\r
-EXTERN_API int create_privacy_info_client_s(const char* package_id, bool enabled, privacy_info_client_s **privacy_info);\r
-EXTERN_API int privacy_info_client_s_destroy(privacy_info_client_s* privacy_info);\r
-EXTERN_API int privacy_info_client_get_privacy_id(privacy_info_client_s* privacy_info, char **privacy_id);\r
-EXTERN_API int privacy_info_client_get_privacy_display_name(privacy_info_client_s* privacy_info, char **name);\r
-EXTERN_API int privacy_info_client_get_privacy_description(privacy_info_client_s* privacy_info, char **description);\r
-EXTERN_API int privacy_info_client_is_enabled(privacy_info_client_s* privacy_info, bool *enabled);\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-\r
-#endif //_PRIVACY_INFO_CLIENT_H\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _PRIVACY_INFO_CLIENT_H
+#define _PRIVACY_INFO_CLIENT_H
+
+#include <privacy_manager_client_types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct _privacy_info_client_s {
+ char *privacy_id;
+ bool is_enabled;
+} privacy_info_client_s;
+
+EXTERN_API int create_privacy_info_client_s(const char* package_id, bool enabled, privacy_info_client_s **privacy_info);
+EXTERN_API int privacy_info_client_s_destroy(privacy_info_client_s* privacy_info);
+EXTERN_API int privacy_info_client_get_privacy_id(privacy_info_client_s* privacy_info, char **privacy_id);
+EXTERN_API int privacy_info_client_get_privacy_display_name(privacy_info_client_s* privacy_info, char **name);
+EXTERN_API int privacy_info_client_get_privacy_description(privacy_info_client_s* privacy_info, char **description);
+EXTERN_API int privacy_info_client_is_enabled(privacy_info_client_s* privacy_info, bool *enabled);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif //_PRIVACY_INFO_CLIENT_H
-/*\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 _PRIVACY_MANAGER_CLIENT_H\r
-#define _PRIVACY_MANAGER_CLIENT_H\r
-\r
-#include <privacy_info_client.h>\r
-#include <privacy_manager_client_types.h>\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-typedef bool (*privacy_manager_client_privacy_packages_cb) (const char *package_id, void* user_data);\r
-typedef bool (*privacy_manager_client_privacy_info_cb) (privacy_info_client_s* privacy_info, void* user_data);\r
-typedef bool (*privacy_manager_client_all_privacy_info_cb) (privacy_info_client_s* privacy_info, void* user_data);\r
-typedef bool (*privacy_manager_client_packages_by_privacy_cb) (const char *package_id, bool is_enabled, void* user_data);\r
-\r
-EXTERN_API int privacy_manager_client_install_privacy(const char *package_id, const char** privacy_list, bool privacy_popup_required);\r
-EXTERN_API int privacy_manager_client_uninstall_privacy(const char *package_id);\r
-EXTERN_API int privacy_manager_client_uninstall_privacy_by_server(const char *package_id);\r
-EXTERN_API int privacy_manager_client_foreach_privacy_packages(privacy_manager_client_privacy_packages_cb callback, void *user_data);\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
-EXTERN_API int privacy_manager_client_set_user_consented(const char *package_id, bool consented);\r
-\r
-EXTERN_API int privacy_manager_client_foreach_all_privacy(privacy_manager_client_all_privacy_info_cb callback, void* user_data);\r
-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);\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-\r
-#endif //__TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_H\r
-\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _PRIVACY_MANAGER_CLIENT_H
+#define _PRIVACY_MANAGER_CLIENT_H
+
+#include <privacy_info_client.h>
+#include <privacy_manager_client_types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+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, bool privacy_popup_required);
+EXTERN_API int privacy_manager_client_uninstall_privacy(const char *package_id);
+EXTERN_API int privacy_manager_client_uninstall_privacy_by_server(const char *package_id);
+EXTERN_API int privacy_manager_client_foreach_privacy_packages(privacy_manager_client_privacy_packages_cb callback, void *user_data);
+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_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
+}
+#endif
+
+
+#endif //__TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_H
+
-/*\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 <PrivacyChecker.h>\r
-#include <PrivacyIdInfo.h>\r
-#include <PrivacyManagerClient.h>\r
-#include <SocketClient.h>\r
-#include <algorithm> \r
-#include <memory>\r
-#include <Utils.h>\r
-#include <dlog.h>\r
-#include <sqlite3.h>\r
-#include <dbus/dbus-glib-lowlevel.h>\r
-#include <sys/types.h>\r
-#include <unistd.h>\r
-\r
-bool PrivacyChecker::m_isInitialized = false;\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
-GMainLoop* PrivacyChecker::m_pLoop = NULL;\r
-GMainContext* PrivacyChecker::m_pHandlerGMainContext = NULL;\r
-const int MAX_LOCAL_BUF_SIZE = 128;\r
-pthread_t PrivacyChecker::m_signalThread;\r
-\r
-int\r
-PrivacyChecker::initialize(const std::string pkgId)\r
-{\r
- LOGI("enter");\r
-\r
- if (m_isInitialized) {\r
- LOGD("Already Initalized");\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- m_pkgId = pkgId;\r
-\r
- std::lock_guard < std::mutex > guard(m_cacheMutex);\r
-\r
- int res = updateCache(m_pkgId, m_privacyCache);\r
- TryReturn(res == 0, res, m_pkgId.clear(), "Failed to update cache : %d", res);\r
-\r
- res = initialize();\r
- TryReturn(res == 0, res, m_pkgId.clear(), "Failed to initialize() : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int\r
-PrivacyChecker::initialize(void)\r
-{\r
- LOGI("enter");\r
-\r
- TryReturn(!m_isInitialized, PRIV_MGR_ERROR_SUCCESS, , "Already Initalized");\r
-\r
- m_pHandlerGMainContext = g_main_context_new();\r
- TryReturn(m_pHandlerGMainContext != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, m_pkgId.clear(), "cannot create m_pHandlerGMainContext");\r
-\r
- m_pLoop = g_main_loop_new(m_pHandlerGMainContext, FALSE);\r
- TryReturn(m_pLoop != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, m_pkgId.clear(), "cannot create m_pLoop");\r
-\r
- int res = pthread_create(&m_signalThread, NULL, &runSignalListenerThread, NULL);\r
- TryReturn(res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, errno = res;, "Failed to create listener thread :%s", strerror(res));\r
- LOGD("created thread");\r
-\r
- m_isInitialized = true;\r
-\r
- LOGI("leave");\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-void*\r
-PrivacyChecker::runSignalListenerThread(void* pData)\r
-{\r
- pthread_detach(pthread_self());\r
- LOGI("Running g main loop for signal");\r
-\r
- initializeDbus();\r
-\r
- g_main_loop_run(m_pLoop);\r
-\r
- finalizeDbus();\r
-\r
- pthread_exit(NULL);\r
-\r
- return (void*) 0;\r
-}\r
-\r
-int\r
-PrivacyChecker::initializeDbus(void)\r
-{\r
- LOGI("enter");\r
- DBusError error;\r
- dbus_error_init(&error);\r
-\r
- m_pDBusConnection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);\r
- TryReturn(m_pDBusConnection != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_get_private [%s] : %d", PRIV_MGR_ERROR_SYSTEM_ERROR);\r
-\r
- dbus_connection_setup_with_g_main(m_pDBusConnection, m_pHandlerGMainContext);\r
- std::unique_ptr < char[] > pRule(new char[MAX_LOCAL_BUF_SIZE]);\r
-\r
- snprintf(pRule.get(), MAX_LOCAL_BUF_SIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str());\r
- dbus_bus_add_match(m_pDBusConnection, pRule.get(), &error);\r
- TryReturn(!dbus_error_is_set(&error), PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_add_match[%s] : %d", error.message, PRIV_MGR_ERROR_SYSTEM_ERROR);\r
-\r
- dbus_bool_t r = dbus_connection_add_filter(m_pDBusConnection, handleNotification, NULL, NULL);\r
- TryReturn(r, PRIV_MGR_ERROR_SYSTEM_ERROR, , "dbus_connection_add_filter: %d", PRIV_MGR_ERROR_SYSTEM_ERROR);\r
-\r
- LOGI("leave");\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int\r
-PrivacyChecker::finalizeDbus(void)\r
-{\r
- dbus_connection_remove_filter(m_pDBusConnection, handleNotification, NULL);\r
- dbus_connection_close(m_pDBusConnection);\r
- m_pDBusConnection = NULL;\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-\r
-DBusHandlerResult\r
-PrivacyChecker::handleNotification(DBusConnection* connection, DBusMessage* message, void* user_data)\r
-{\r
- DBusError error;\r
- dbus_bool_t r;\r
- dbus_error_init(&error);\r
-\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_SETTING_CHANGED.c_str()))\r
- {\r
- r = dbus_message_get_args(message, &error,\r
- DBUS_TYPE_STRING, &pPkgId,\r
- DBUS_TYPE_STRING, &pPrivacyId,\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(m_pkgId, 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 if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_PKG_REMOVED.c_str()))\r
- {\r
- r = dbus_message_get_args(message, &error,\r
- DBUS_TYPE_STRING, &pPkgId,\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
- 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("cache for pkg : %d is in cache", pPkgId);\r
- m_privacyInfoCache.erase(iter);\r
- }\r
- }\r
-// else\r
-// {\r
-// return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;\r
-// }\r
- \r
-\r
- // This event is not only for specific handler. All handlers of daemons should be check it and handle it.\r
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;\r
-}\r
-\r
-int\r
-PrivacyChecker::check(const std::string privacyId, std::map < std::string, bool >& privacyMap)\r
-{\r
- LOGI("enter");\r
-\r
- TryReturn(m_isInitialized, PRIV_MGR_ERROR_NOT_INITIALIZED, , "Not initialized");\r
-\r
- std::map < std::string, bool >::iterator iter;\r
-\r
- iter = privacyMap.find(privacyId);\r
- if (iter == privacyMap.end() )\r
- {\r
- LOGD("NO matcheded");\r
- return PRIV_MGR_ERROR_USER_NOT_CONSENTED;\r
- }\r
- else if (!iter->second)\r
- {\r
- LOGD("NOT allowed");\r
- return PRIV_MGR_ERROR_USER_NOT_CONSENTED;\r
- }\r
-\r
- LOGD("OK");\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int\r
-PrivacyChecker::check(const std::string privacyId)\r
-{\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 %s: %s", pkgId.c_str(), privacyId.c_str());\r
-\r
- if (!m_isInitialized)\r
- initialize();\r
-\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
- std::map < std::string, bool > pkgCacheMap;\r
- res = updateCache(pkgId, pkgCacheMap);\r
- TryReturn( res == PRIV_MGR_ERROR_SUCCESS, PRIV_MGR_ERROR_DB_ERROR, , "updateCache : %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
-\r
- if (iter->second.size() == 0)\r
- {\r
- LOGD("No privacy contained");\r
- return PRIV_MGR_ERROR_USER_NOT_CONSENTED;\r
- }\r
-\r
- res = check(privacyId, iter->second);\r
-\r
- LOGI("leave");\r
-\r
- return res;\r
-}\r
-\r
-int\r
-PrivacyChecker::checkWithPrivilege(const std::string pkgId, const std::string privilege)\r
-{\r
- LOGI("enter");\r
-\r
- std::string privacyId;\r
- int res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId);\r
- if (res == PRIV_MGR_ERROR_NO_DATA) {\r
- LOGD("%s is not privacy privilege", privilege.c_str());\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res);\r
-\r
- LOGI("leave");\r
-\r
- return check(pkgId, privacyId);\r
-}\r
-\r
-int\r
-PrivacyChecker::checkWithPrivilege(const std::string privilege)\r
-{\r
- LOGI("enter");\r
-\r
- std::string privacyId;\r
- int res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId);\r
- if (res == PRIV_MGR_ERROR_NO_DATA) {\r
- LOGD("%s is not privacy privilege", privilege.c_str());\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\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
- if (m_pHandlerGMainContext != NULL) \r
- {\r
- g_main_context_unref(m_pHandlerGMainContext);\r
- m_pHandlerGMainContext = NULL;\r
- }\r
-\r
- m_isInitialized = false;\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-void\r
-PrivacyChecker::printCache(void)\r
-{\r
- std::map < std::string, bool >::const_iterator iter = m_privacyCache.begin();\r
- for (; iter != m_privacyCache.end(); ++iter)\r
- {\r
- LOGD(" %s : %d", iter->first.c_str(), iter->second);\r
- }\r
-}\r
-\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(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, 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, 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
- SECURE_LOGD("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
-int\r
-PrivacyChecker::updateCache(std::string pkgId, 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, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
- TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
-\r
- while ( (res = 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
- SECURE_LOGD("Privacy found : %s %d", privacyId, privacyEnabled);\r
- }\r
- LOGI("leave : %d", res);\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}
\ No newline at end of file
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <PrivacyChecker.h>
+#include <PrivacyIdInfo.h>
+#include <PrivacyManagerClient.h>
+#include <SocketClient.h>
+#include <algorithm>
+#include <memory>
+#include <Utils.h>
+#include <dlog.h>
+#include <sqlite3.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+bool PrivacyChecker::m_isInitialized = false;
+std::map < std::string, bool >PrivacyChecker::m_privacyCache;
+std::map < std::string, std::map < std::string, bool > > PrivacyChecker::m_privacyInfoCache;
+std::mutex PrivacyChecker::m_cacheMutex;
+std::string PrivacyChecker::m_pkgId;
+DBusConnection* PrivacyChecker::m_pDBusConnection;
+GMainLoop* PrivacyChecker::m_pLoop = NULL;
+GMainContext* PrivacyChecker::m_pHandlerGMainContext = NULL;
+const int MAX_LOCAL_BUF_SIZE = 128;
+pthread_t PrivacyChecker::m_signalThread;
+
+int
+PrivacyChecker::initialize(const std::string pkgId)
+{
+ if (m_isInitialized) {
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ m_pkgId = pkgId;
+
+ std::lock_guard < std::mutex > guard(m_cacheMutex);
+
+ int res = updateCache(m_pkgId, m_privacyCache);
+ TryReturn(res == 0, res, m_pkgId.clear(), "Failed to update cache : %d", res);
+
+ res = initialize();
+ TryReturn(res == 0, res, m_pkgId.clear(), "Failed to initialize() : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int
+PrivacyChecker::initialize(void)
+{
+ TryReturn(!m_isInitialized, PRIV_MGR_ERROR_SUCCESS, , "Already Initalized");
+
+ m_pHandlerGMainContext = g_main_context_new();
+ TryReturn(m_pHandlerGMainContext != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, m_pkgId.clear(), "cannot create m_pHandlerGMainContext");
+
+ m_pLoop = g_main_loop_new(m_pHandlerGMainContext, FALSE);
+ TryReturn(m_pLoop != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, m_pkgId.clear(), "cannot create m_pLoop");
+
+ int res = pthread_create(&m_signalThread, NULL, &runSignalListenerThread, NULL);
+ TryReturn(res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, errno = res;, "Failed to create listener thread :%s", strerror(res));
+
+ m_isInitialized = true;
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+void*
+PrivacyChecker::runSignalListenerThread(void* pData)
+{
+ pthread_detach(pthread_self());
+ LOGI("Running g main loop for signal");
+
+ initializeDbus();
+
+ g_main_loop_run(m_pLoop);
+
+ finalizeDbus();
+
+ pthread_exit(NULL);
+
+ return (void*) 0;
+}
+
+int
+PrivacyChecker::initializeDbus(void)
+{
+ DBusError error;
+ dbus_error_init(&error);
+
+ m_pDBusConnection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
+ TryReturn(m_pDBusConnection != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_get_private [%s] : %d", PRIV_MGR_ERROR_SYSTEM_ERROR);
+
+ dbus_connection_setup_with_g_main(m_pDBusConnection, m_pHandlerGMainContext);
+ std::unique_ptr < char[] > pRule(new char[MAX_LOCAL_BUF_SIZE]);
+
+ snprintf(pRule.get(), MAX_LOCAL_BUF_SIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str());
+ dbus_bus_add_match(m_pDBusConnection, pRule.get(), &error);
+ TryReturn(!dbus_error_is_set(&error), PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_add_match[%s] : %d", error.message, PRIV_MGR_ERROR_SYSTEM_ERROR);
+
+ dbus_bool_t r = dbus_connection_add_filter(m_pDBusConnection, handleNotification, NULL, NULL);
+ TryReturn(r, PRIV_MGR_ERROR_SYSTEM_ERROR, , "dbus_connection_add_filter: %d", PRIV_MGR_ERROR_SYSTEM_ERROR);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int
+PrivacyChecker::finalizeDbus(void)
+{
+ dbus_connection_remove_filter(m_pDBusConnection, handleNotification, NULL);
+ dbus_connection_close(m_pDBusConnection);
+ m_pDBusConnection = NULL;
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+
+DBusHandlerResult
+PrivacyChecker::handleNotification(DBusConnection* connection, DBusMessage* message, void* user_data)
+{
+ DBusError error;
+ dbus_bool_t r;
+ dbus_error_init(&error);
+
+ char* pPkgId;
+ char* pPrivacyId;
+
+ if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_SETTING_CHANGED.c_str()))
+ {
+ r = dbus_message_get_args(message, &error,
+ DBUS_TYPE_STRING, &pPkgId,
+ DBUS_TYPE_STRING, &pPrivacyId,
+ DBUS_TYPE_INVALID);
+ TryReturn(r, DBUS_HANDLER_RESULT_NOT_YET_HANDLED, , "Fail to get data : %s", error.message);
+
+ std::lock_guard < std::mutex > guard(m_cacheMutex);
+
+ if (std::string(pPkgId) == m_pkgId)
+ {
+ LOGI("Current app pkg privacy information updated");
+ updateCache(m_pkgId, pPrivacyId, m_privacyCache);
+ //printCache();
+ }
+
+ std::map < std::string, std::map < std::string, bool > > :: iterator iter = m_privacyInfoCache.find(std::string(pPkgId));
+ if (iter != m_privacyInfoCache.end())
+ {
+ LOGI("Current pkg privacy is in cache");
+ updateCache(std::string(pPkgId), pPrivacyId, iter->second);
+ }
+
+ }
+ else if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_PKG_REMOVED.c_str()))
+ {
+ r = dbus_message_get_args(message, &error,
+ DBUS_TYPE_STRING, &pPkgId,
+ DBUS_TYPE_INVALID);
+ TryReturn(r, DBUS_HANDLER_RESULT_NOT_YET_HANDLED, , "Fail to get data : %s", error.message);
+
+ std::lock_guard < std::mutex > guard(m_cacheMutex);
+
+ std::map < std::string, std::map < std::string, bool > > :: iterator iter = m_privacyInfoCache.find(std::string(pPkgId));
+ if (iter != m_privacyInfoCache.end())
+ {
+ m_privacyInfoCache.erase(iter);
+ }
+ }
+// else
+// {
+// return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+// }
+
+
+ // This event is not only for specific handler. All handlers of daemons should be check it and handle it.
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+int
+PrivacyChecker::check(const std::string privacyId, std::map < std::string, bool >& privacyMap)
+{
+ TryReturn(m_isInitialized, PRIV_MGR_ERROR_NOT_INITIALIZED, , "Not initialized");
+
+ std::map < std::string, bool >::iterator iter;
+
+ iter = privacyMap.find(privacyId);
+ if (iter == privacyMap.end() )
+ {
+ LOGD("The application cannot access the privacy inforamtion.");
+ return PRIV_MGR_ERROR_USER_NOT_CONSENTED;
+ }
+ else if (!iter->second)
+ {
+ LOGD("User does not consented to access the privacy information");
+ return PRIV_MGR_ERROR_USER_NOT_CONSENTED;
+ }
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int
+PrivacyChecker::check(const std::string privacyId)
+{
+ if (!m_isInitialized)
+ return PRIV_MGR_ERROR_NOT_INITIALIZED;
+
+ std::lock_guard < std::mutex > guard(m_cacheMutex);
+
+ int res = check(privacyId, m_privacyCache);
+
+ return res;
+}
+
+int
+PrivacyChecker::check(const std::string pkgId, const std::string privacyId)
+{
+ if (!m_isInitialized)
+ initialize();
+
+ std::lock_guard < std::mutex > guard(m_cacheMutex);
+ int res;
+
+ std::map < std::string, std::map < std::string, bool > >::iterator iter = m_privacyInfoCache.find(pkgId);
+ if (iter == m_privacyInfoCache.end() )
+ {
+ std::map < std::string, bool > pkgCacheMap;
+ res = updateCache(pkgId, pkgCacheMap);
+ TryReturn( res == PRIV_MGR_ERROR_SUCCESS, PRIV_MGR_ERROR_DB_ERROR, , "Failed to update cache : %d", res);
+
+ m_privacyInfoCache.insert( std::map < std::string, std::map < std::string, bool > >::value_type(std::string(pkgId), pkgCacheMap));
+ iter = m_privacyInfoCache.find(pkgId);
+ }
+
+ if (iter->second.size() == 0)
+ {
+ return PRIV_MGR_ERROR_USER_NOT_CONSENTED;
+ }
+
+ res = check(privacyId, iter->second);
+
+ return res;
+}
+
+int
+PrivacyChecker::checkWithPrivilege(const std::string pkgId, const std::string privilege)
+{
+ std::string privacyId;
+ int res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId);
+ if (res == PRIV_MGR_ERROR_NO_DATA) {
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res);
+
+ return check(pkgId, privacyId);
+}
+
+int
+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_SUCCESS;
+ }
+
+ TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res);
+
+ return check(privacyId);
+}
+
+int
+PrivacyChecker::finalize(void)
+{
+ std::lock_guard <std::mutex> guard (m_cacheMutex);
+ m_privacyCache.clear();
+ m_privacyInfoCache.clear();
+
+ if (m_pLoop != NULL)
+ {
+ g_main_loop_quit(m_pLoop);
+ m_pLoop = NULL;
+ }
+
+ if (m_pHandlerGMainContext != NULL)
+ {
+ g_main_context_unref(m_pHandlerGMainContext);
+ m_pHandlerGMainContext = NULL;
+ }
+
+ m_isInitialized = false;
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+void
+PrivacyChecker::printCache(void)
+{
+ std::map < std::string, bool >::const_iterator iter = m_privacyCache.begin();
+ for (; iter != m_privacyCache.end(); ++iter)
+ {
+ LOGD(" %s : %d", iter->first.c_str(), iter->second);
+ }
+}
+
+int
+PrivacyChecker::updateCache(const std::string pkgId, std::string privacyId, std::map < std::string, bool >& pkgCacheMap)
+{
+ static const std::string PrivacyQuery = "SELECT IS_ENABLED from PrivacyInfo where PKG_ID=? and PRIVACY_ID=?";
+
+ openDb(PRIVACY_DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY);
+ prepareDb(pDbH, PrivacyQuery.c_str(), pPrivacyStmt);
+ int res = sqlite3_bind_text(pPrivacyStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);
+ TryReturn( res == 0, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);
+
+ res = sqlite3_bind_text(pPrivacyStmt.get(), 2, privacyId.c_str(), -1, SQLITE_TRANSIENT);
+ TryReturn( res == 0, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);
+
+ while ( sqlite3_step(pPrivacyStmt.get()) == SQLITE_ROW )
+ {
+ bool privacyEnabled = sqlite3_column_int(pPrivacyStmt.get(), 0) > 0 ? true : false;
+
+ SECURE_LOGD("Set result : %s : %d", privacyId.c_str(), privacyEnabled );
+ pkgCacheMap.erase(privacyId);
+ pkgCacheMap.insert(std::map < std::string, bool >::value_type(privacyId, privacyEnabled));
+ }
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int
+PrivacyChecker::updateCache(std::string pkgId, std::map < std::string, bool >& pkgCacheMap)
+{
+ static const std::string PrivacyQuery = "SELECT PRIVACY_ID, IS_ENABLED from PrivacyInfo where PKG_ID=?";
+
+ pkgCacheMap.clear();
+
+ openDb(PRIVACY_DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY);
+ prepareDb(pDbH, PrivacyQuery.c_str(), pPrivacyStmt);
+ int res = sqlite3_bind_text(pPrivacyStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);
+ TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);
+
+ while ( (res = sqlite3_step(pPrivacyStmt.get())) == SQLITE_ROW )
+ {
+ const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pPrivacyStmt.get(), 0));
+ bool privacyEnabled = sqlite3_column_int(pPrivacyStmt.get(), 1) > 0 ? true : false;
+
+ pkgCacheMap.insert(std::map < std::string, bool >::value_type(std::string(privacyId), privacyEnabled));
+
+ SECURE_LOGD("Privacy found : %s %d", privacyId, privacyEnabled);
+ }
+ return PRIV_MGR_ERROR_SUCCESS;
+}
-/*\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 <PrivacyDb.h>\r
-#include <SocketClient.h>\r
-#include <PrivacyIdInfo.h>\r
-#include <algorithm> \r
-#include <memory>\r
-#include <Utils.h>\r
-\r
-#undef __READ_DB_IPC__\r
-\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 >& list, bool privacyPopupRequired, bool isServerOperation)\r
-{\r
-\r
- std::list < std::string > privacyList;\r
-\r
- int res = PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(list, 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
- if (isServerOperation == true)\r
- {\r
- int result = PRIV_MGR_ERROR_SUCCESS;\r
- res = m_pSocketClient->connect();\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);\r
- res = m_pSocketClient->call("addPrivacyInfo", pkgId, privacyList, privacyPopupRequired, &result);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);\r
- res = m_pSocketClient->disconnect();\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res);\r
-\r
- return result;\r
- }\r
- else\r
- {\r
- return PrivacyDb::getInstance()->addAppPackagePrivacyInfo(pkgId, privacyList, privacyPopupRequired);\r
- }\r
-}\r
-\r
-int\r
-PrivacyManagerClient::removeAppPackagePrivacyInfo(const std::string pkgId, bool isServerOperation)\r
-{\r
- if (isServerOperation == true)\r
- {\r
- int result = PRIV_MGR_ERROR_SUCCESS;\r
- int res = m_pSocketClient->connect();\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);\r
- result = m_pSocketClient->call("removePrivacyInfo", pkgId, &result);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);\r
- result = m_pSocketClient->disconnect();\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res);\r
-\r
- return result;\r
- }\r
- else\r
- return PrivacyDb::getInstance()->removeAppPackagePrivacyInfo(pkgId);\r
-}\r
-\r
-int\r
-PrivacyManagerClient::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled)\r
-{\r
- int result = PRIV_MGR_ERROR_SUCCESS;\r
- int res = m_pSocketClient->connect();\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);\r
- res = m_pSocketClient->call("setPrivacySetting", pkgId, privacyId, isEnabled, &result);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);\r
- res = m_pSocketClient->disconnect();\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);\r
-\r
- return result;\r
-}\r
- \r
-int\r
-PrivacyManagerClient::getPrivacyAppPackages(std::list < std::string >& list) const\r
-{\r
-#ifdef __READ_DB_IPC__\r
-\r
- std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));\r
-\r
- int result = PRIV_MGR_ERROR_SUCCESS\r
- int size = 0;\r
-\r
- int res = pSocketClient->connect();\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);\r
- res = pSocketClient->call("getPrivacyAppPackages", &result, &size, &list);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);\r
- res = pSocketClient->disconnect();\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);\r
-\r
- return result;\r
-#endif\r
-\r
- return PrivacyDb::getInstance()->getPrivacyAppPackages(list);\r
-}\r
-\r
-int\r
-PrivacyManagerClient::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & list) const\r
-{\r
-#ifdef __READ_DB_IPC__\r
- std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));\r
-\r
- int result = PRIV_MGR_ERROR_SUCCESS;\r
- int res = pSocketClient->connect();\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);\r
- pSocketClient->call("getAppPackagePrivacyInfo", pkgId, &result, &list);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);\r
- pSocketClient->disconnect();\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res);\r
-\r
- return result;\r
-#endif \r
-\r
- return PrivacyDb::getInstance()->getAppPackagePrivacyInfo(pkgId, list);\r
-}\r
-\r
-int\r
-PrivacyManagerClient::isUserPrompted(const std::string pkgId, bool& isPrompted) const\r
-{\r
-#ifdef __READ_DB_IPC__\r
- LOGI("enter");\r
-\r
- std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));\r
-\r
- int result = PRIV_MGR_ERROR_SUCCESS;\r
- int res = pSocketClient->connect();\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);\r
- res = pSocketClient->call("isUserPrompted", pkgId, &result, &isPrompted);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);\r
- res = pSocketClient->disconnect();\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res);\r
-\r
- LOGI("leave");\r
-\r
- return result;\r
-#endif\r
- return PrivacyDb::getInstance()->isUserPrompted(pkgId, isPrompted);\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 = PRIV_MGR_ERROR_SUCCESS;\r
- int res = pSocketClient->connect();\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);\r
- res = pSocketClient->call("setUserPrompted", pkgId, prompted, &result);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);\r
- res = pSocketClient->disconnect();\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res);\r
-\r
- LOGI("leave");\r
-\r
- return result;\r
-}\r
-\r
-int\r
-PrivacyManagerClient::getAppPackagesbyPrivacyId(const std::string privacyId, std::list < std::pair < std::string, bool > >& list) const\r
-{\r
- return PrivacyDb::getInstance()->getAppPackagesbyPrivacyId(privacyId, list);\r
-}\r
-\r
-int\r
-PrivacyManagerClient::getPrivaycDisplayName(const std::string privacyId, std::string& displayName) const\r
-{\r
- return PrivacyIdInfo::getPrivaycDisplayName(privacyId, displayName);\r
-}\r
-\r
-int\r
-PrivacyManagerClient::getPrivaycDescription(const std::string privacyId, std::string& description) const\r
-{\r
- return PrivacyIdInfo::getPrivaycDescription(privacyId, description);\r
-}\r
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <PrivacyManagerClient.h>
+#include <PrivacyDb.h>
+#include <SocketClient.h>
+#include <PrivacyIdInfo.h>
+#include <algorithm>
+#include <memory>
+#include <Utils.h>
+
+#undef __READ_DB_IPC__
+
+
+std::mutex PrivacyManagerClient::m_singletonMutex;
+PrivacyManagerClient* PrivacyManagerClient::m_pInstance = NULL;
+const std::string PrivacyManagerClient::INTERFACE_NAME("PrivacyInfoService");
+
+PrivacyManagerClient::PrivacyManagerClient(void)
+{
+ std::unique_ptr<SocketClient> pSocketClient(new SocketClient(INTERFACE_NAME));
+ m_pSocketClient = std::move(pSocketClient);
+}
+
+PrivacyManagerClient*
+PrivacyManagerClient::getInstance(void)
+{
+ std::lock_guard<std::mutex> guard(m_singletonMutex);
+ if (m_pInstance == NULL)
+ m_pInstance = new PrivacyManagerClient();
+ return m_pInstance;
+}
+
+int
+PrivacyManagerClient::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& list, bool privacyPopupRequired, bool isServerOperation)
+{
+
+ std::list < std::string > privacyList;
+
+ int res = PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(list, privacyList);
+ if (res != PRIV_MGR_ERROR_SUCCESS )
+ return res;
+
+ if (privacyList.size() == 0)
+ return PRIV_MGR_ERROR_SUCCESS;
+
+ if (isServerOperation == true)
+ {
+ int result = PRIV_MGR_ERROR_SUCCESS;
+ res = m_pSocketClient->connect();
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
+ res = m_pSocketClient->call("addPrivacyInfo", pkgId, privacyList, privacyPopupRequired, &result);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
+ res = m_pSocketClient->disconnect();
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res);
+
+ return result;
+ }
+ else
+ {
+ return PrivacyDb::getInstance()->addAppPackagePrivacyInfo(pkgId, privacyList, privacyPopupRequired);
+ }
+}
+
+int
+PrivacyManagerClient::removeAppPackagePrivacyInfo(const std::string pkgId, bool isServerOperation)
+{
+ if (isServerOperation == true)
+ {
+ int result = PRIV_MGR_ERROR_SUCCESS;
+ int res = m_pSocketClient->connect();
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
+ result = m_pSocketClient->call("removePrivacyInfo", pkgId, &result);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
+ result = m_pSocketClient->disconnect();
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res);
+
+ return result;
+ }
+ else
+ return PrivacyDb::getInstance()->removeAppPackagePrivacyInfo(pkgId);
+}
+
+int
+PrivacyManagerClient::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled)
+{
+ int result = PRIV_MGR_ERROR_SUCCESS;
+ int res = m_pSocketClient->connect();
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
+ res = m_pSocketClient->call("setPrivacySetting", pkgId, privacyId, isEnabled, &result);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
+ res = m_pSocketClient->disconnect();
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
+
+ return result;
+}
+
+int
+PrivacyManagerClient::getPrivacyAppPackages(std::list < std::string >& list) const
+{
+#ifdef __READ_DB_IPC__
+
+ std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));
+
+ int result = PRIV_MGR_ERROR_SUCCESS
+ int size = 0;
+
+ int res = pSocketClient->connect();
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
+ res = pSocketClient->call("getPrivacyAppPackages", &result, &size, &list);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
+ res = pSocketClient->disconnect();
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
+
+ return result;
+#endif
+
+ return PrivacyDb::getInstance()->getPrivacyAppPackages(list);
+}
+
+int
+PrivacyManagerClient::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & list) const
+{
+#ifdef __READ_DB_IPC__
+ std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));
+
+ int result = PRIV_MGR_ERROR_SUCCESS;
+ int res = pSocketClient->connect();
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
+ pSocketClient->call("getAppPackagePrivacyInfo", pkgId, &result, &list);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
+ pSocketClient->disconnect();
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res);
+
+ return result;
+#endif
+
+ return PrivacyDb::getInstance()->getAppPackagePrivacyInfo(pkgId, list);
+}
+
+int
+PrivacyManagerClient::isUserPrompted(const std::string pkgId, bool& isPrompted) const
+{
+#ifdef __READ_DB_IPC__
+ std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));
+
+ int result = PRIV_MGR_ERROR_SUCCESS;
+ int res = pSocketClient->connect();
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
+ res = pSocketClient->call("isUserPrompted", pkgId, &result, &isPrompted);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
+ res = pSocketClient->disconnect();
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res);
+
+ return result;
+#endif
+ return PrivacyDb::getInstance()->isUserPrompted(pkgId, isPrompted);
+}
+
+int
+PrivacyManagerClient::setUserPrompted(const std::string pkgId, bool prompted)
+{
+ std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));
+
+ int result = PRIV_MGR_ERROR_SUCCESS;
+ int res = pSocketClient->connect();
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
+ res = pSocketClient->call("setUserPrompted", pkgId, prompted, &result);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
+ res = pSocketClient->disconnect();
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res);
+
+ return result;
+}
+
+int
+PrivacyManagerClient::getAppPackagesbyPrivacyId(const std::string privacyId, std::list < std::pair < std::string, bool > >& list) const
+{
+ return PrivacyDb::getInstance()->getAppPackagesbyPrivacyId(privacyId, list);
+}
+
+int
+PrivacyManagerClient::getPrivaycDisplayName(const std::string privacyId, std::string& displayName) const
+{
+ return PrivacyIdInfo::getPrivaycDisplayName(privacyId, displayName);
+}
+
+int
+PrivacyManagerClient::getPrivaycDescription(const std::string privacyId, std::string& description) const
+{
+ return PrivacyIdInfo::getPrivaycDescription(privacyId, description);
+}
-/*\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 <sys/socket.h>\r
-#include <string.h>\r
-#include <fcntl.h>\r
-#include <sys/types.h>\r
-#include <sys/un.h>\r
-#include <errno.h>\r
-#include <unistd.h>\r
-#include <PrivacyManagerTypes.h>\r
-#include "SocketClient.h"\r
-#include <Utils.h>\r
-\r
-#define throwWithErrnoMessage(specificInfo) do {\\r
- LOGE("%s : %s", specificInfo, strerror(errno)); \\r
- return -1; \\r
- } while(0)\r
-\r
-SocketClient::SocketClient(const std::string& interfaceName) \r
-{\r
- m_interfaceName = interfaceName;\r
- m_serverAddress = SERVER_ADDRESS;\r
- LOGI("Client created");\r
-}\r
-\r
-int SocketClient::connect()\r
-{\r
- struct sockaddr_un remote;\r
- m_socketFd = socket(AF_UNIX, SOCK_STREAM,0);\r
- TryReturn( m_socketFd != -1, PRIV_MGR_ERROR_IPC_ERROR, , "socket : %s", strerror(errno));\r
-\r
- int res;\r
- //socket needs to be nonblocking, because read can block after select\r
- int flags;\r
- if ( (flags = fcntl(m_socketFd, F_GETFL, 0)) == -1 )\r
- flags = 0;\r
- res = fcntl(m_socketFd, F_SETFL, flags | O_NONBLOCK);\r
- TryReturn( m_socketFd != -1, PRIV_MGR_ERROR_IPC_ERROR, , "fcntl : %s", strerror(errno));\r
-\r
- bzero(&remote, sizeof(remote));\r
- remote.sun_family = AF_UNIX;\r
- strcpy(remote.sun_path, m_serverAddress.c_str());\r
- res = ::connect(m_socketFd, (struct sockaddr *)&remote, SUN_LEN(&remote));\r
- TryReturn( res != -1, PRIV_MGR_ERROR_IPC_ERROR, , "connect : %s", strerror(errno));\r
-\r
- m_socketConnector.reset(new SocketConnection(m_socketFd));\r
- \r
- LOGI("Client connected");\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int SocketClient::disconnect()\r
-{\r
- //Socket should be already closed by server side, \r
- //even though we should close it in case of any errors\r
- close(m_socketFd);\r
- LOGI("Client disconnected");\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sys/socket.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/un.h>
+#include <errno.h>
+#include <unistd.h>
+#include <PrivacyManagerTypes.h>
+#include "SocketClient.h"
+#include <Utils.h>
+
+#define throwWithErrnoMessage(specificInfo) do {\
+ LOGE("%s : %s", specificInfo, strerror(errno)); \
+ return -1; \
+ } while(0)
+
+SocketClient::SocketClient(const std::string& interfaceName)
+{
+ m_interfaceName = interfaceName;
+ m_serverAddress = SERVER_ADDRESS;
+ LOGI("Client created");
+}
+
+int SocketClient::connect()
+{
+ struct sockaddr_un remote;
+ m_socketFd = socket(AF_UNIX, SOCK_STREAM,0);
+ TryReturn( m_socketFd != -1, PRIV_MGR_ERROR_IPC_ERROR, , "socket : %s", strerror(errno));
+
+ int res;
+ //socket needs to be nonblocking, because read can block after select
+ int flags;
+ if ( (flags = fcntl(m_socketFd, F_GETFL, 0)) == -1 )
+ flags = 0;
+ res = fcntl(m_socketFd, F_SETFL, flags | O_NONBLOCK);
+ TryReturn( m_socketFd != -1, PRIV_MGR_ERROR_IPC_ERROR, , "fcntl : %s", strerror(errno));
+
+ bzero(&remote, sizeof(remote));
+ remote.sun_family = AF_UNIX;
+ strcpy(remote.sun_path, m_serverAddress.c_str());
+ res = ::connect(m_socketFd, (struct sockaddr *)&remote, SUN_LEN(&remote));
+ TryReturn( res != -1, PRIV_MGR_ERROR_IPC_ERROR, , "connect : %s", strerror(errno));
+
+ m_socketConnector.reset(new SocketConnection(m_socketFd));
+
+ LOGI("Client connected");
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int SocketClient::disconnect()
+{
+ //Socket should be already closed by server side,
+ //even though we should close it in case of any errors
+ close(m_socketFd);
+ LOGI("Client disconnected");
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
-/*\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
-#include <string.h>\r
-#include <string>\r
-#include <memory>\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 <PrivacyChecker.h>\r
-#include <privacy_checker_client.h>\r
-#include <privacy_info_client.h>\r
-#include <PrivacyIdInfo.h>\r
-\r
-int privacy_checker_initialize(const char *package_id)\r
-{\r
- return PrivacyChecker::initialize(std::string(package_id));\r
-}\r
-\r
-int privacy_checker_check_privacy(const char *privacy_id)\r
-{\r
- return PrivacyChecker::check(std::string(privacy_id));\r
-}\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_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
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+#include <string>
+#include <memory>
+#include <PrivacyManagerClient.h>
+#include <privacy_manager_client.h>
+#include <privacy_manager_client_types.h>
+#include "privacy_manager_client_internal_types.h"
+#include <PrivacyChecker.h>
+#include <privacy_checker_client.h>
+#include <privacy_info_client.h>
+#include <PrivacyIdInfo.h>
+
+int privacy_checker_initialize(const char *package_id)
+{
+ return PrivacyChecker::initialize(std::string(package_id));
+}
+
+int privacy_checker_check_privacy(const char *privacy_id)
+{
+ return PrivacyChecker::check(std::string(privacy_id));
+}
+
+int privacy_checker_check_by_privilege(const char *privilege_id)
+{
+ return PrivacyChecker::checkWithPrivilege(privilege_id);
+}
+
+int privacy_checker_finalize(void)
+{
+ return PrivacyChecker::finalize();
+}
+
+int privacy_checker_check_package_by_privilege(const char* package_id, const char *privilege_id)
+{
+ return PrivacyChecker::checkWithPrivilege(package_id,privilege_id);
}
\ No newline at end of file
-/*\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
-#include <string.h>\r
-#include <string>\r
-#include <memory>\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
-int privacy_info_client_s_destroy(privacy_info_client_s* privacy_info)\r
-{\r
- if (privacy_info != NULL)\r
- {\r
- if (privacy_info->privacy_id)\r
- free(privacy_info->privacy_id);\r
- free (privacy_info);\r
- }\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int privacy_info_client_get_privacy_id(privacy_info_client_s* privacy_info, char **privacy_id)\r
-{\r
- int size = strlen(privacy_info->privacy_id);\r
- *privacy_id = (char*) calloc(1, size + 1);\r
-\r
- memcpy (*privacy_id, privacy_info->privacy_id, size);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int privacy_info_client_get_privacy_display_name(privacy_info_client_s* privacy_info, char **name)\r
-{\r
- std::string displayName;\r
- int res = PrivacyManagerClient::getInstance()->getPrivaycDisplayName(std::string(privacy_info->privacy_id), displayName);\r
- if (res != PRIV_MGR_ERROR_SUCCESS)\r
- return res;\r
-\r
- int size = strlen(displayName.c_str());\r
- *name = (char*) calloc(1, size + 1);\r
- memcpy (*name, displayName.c_str(), size);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int privacy_info_client_get_privacy_description(privacy_info_client_s* privacy_info, char **description)\r
-{\r
- std::string desc;\r
- int res = PrivacyManagerClient::getInstance()->getPrivaycDisplayName(std::string(privacy_info->privacy_id), desc);\r
- if (res != PRIV_MGR_ERROR_SUCCESS)\r
- return res;\r
-\r
- int size = strlen(desc.c_str());\r
- *description = (char*) calloc(1, size + 1);\r
- memcpy (*description, desc.c_str(), size);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int privacy_info_client_is_enabled(privacy_info_client_s* privacy_info, bool *enabled)\r
-{\r
- *enabled = privacy_info->is_enabled;\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+#include <string>
+#include <memory>
+#include <PrivacyManagerClient.h>
+#include <privacy_manager_client.h>
+#include <privacy_manager_client_types.h>
+#include "privacy_manager_client_internal_types.h"
+
+int privacy_info_client_s_destroy(privacy_info_client_s* privacy_info)
+{
+ if (privacy_info != NULL)
+ {
+ if (privacy_info->privacy_id)
+ free(privacy_info->privacy_id);
+ free (privacy_info);
+ }
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int privacy_info_client_get_privacy_id(privacy_info_client_s* privacy_info, char **privacy_id)
+{
+ int size = strlen(privacy_info->privacy_id);
+ *privacy_id = (char*) calloc(1, size + 1);
+
+ memcpy (*privacy_id, privacy_info->privacy_id, size);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int privacy_info_client_get_privacy_display_name(privacy_info_client_s* privacy_info, char **name)
+{
+ std::string displayName;
+ int res = PrivacyManagerClient::getInstance()->getPrivaycDisplayName(std::string(privacy_info->privacy_id), displayName);
+ if (res != PRIV_MGR_ERROR_SUCCESS)
+ return res;
+
+ int size = strlen(displayName.c_str());
+ *name = (char*) calloc(1, size + 1);
+ memcpy (*name, displayName.c_str(), size);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int privacy_info_client_get_privacy_description(privacy_info_client_s* privacy_info, char **description)
+{
+ std::string desc;
+ int res = PrivacyManagerClient::getInstance()->getPrivaycDisplayName(std::string(privacy_info->privacy_id), desc);
+ if (res != PRIV_MGR_ERROR_SUCCESS)
+ return res;
+
+ int size = strlen(desc.c_str());
+ *description = (char*) calloc(1, size + 1);
+ memcpy (*description, desc.c_str(), size);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int privacy_info_client_is_enabled(privacy_info_client_s* privacy_info, bool *enabled)
+{
+ *enabled = privacy_info->is_enabled;
+ return PRIV_MGR_ERROR_SUCCESS;
+}
-/*\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
-#include <string.h>\r
-#include <string>\r
-#include <memory>\r
-#include <dlog.h>\r
-#include <PrivacyManagerClient.h>\r
-#include <PrivacyIdInfo.h>\r
-#include <privacy_manager_client.h>\r
-#include "privacy_manager_client_internal_types.h"\r
-\r
-int create_privacy_info_client_s(const char* privacy_id, bool enabled, privacy_info_client_s **privacy_info)\r
-{\r
- privacy_info_client_s* temp = (privacy_info_client_s*) calloc(1, sizeof(privacy_info_client_s));\r
- if (temp == NULL)\r
- return PRIV_MGR_ERROR_OUT_OF_MEMORY;\r
-\r
- int size = strlen(privacy_id);\r
- temp->privacy_id = (char*) calloc(1, size + 1);\r
- if (temp->privacy_id == NULL)\r
- {\r
- free(temp);\r
- return PRIV_MGR_ERROR_OUT_OF_MEMORY;\r
- }\r
- memcpy(temp->privacy_id, privacy_id, size + 1);\r
- \r
- temp->is_enabled = enabled;\r
-\r
- *privacy_info = temp;\r
- \r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int privacy_manager_client_install_privacy(const char *package_id, const char** privacy_list, bool privacy_popup_required)\r
-{\r
- PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();\r
- std::list < std::string > privacyList;\r
-\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, privacy_popup_required, false);\r
-\r
- return retval;\r
-}\r
-\r
-int privacy_manager_client_uninstall_privacy(const char *package_id)\r
-{\r
- if (package_id == NULL)\r
- return PRIV_MGR_ERROR_INVALID_PARAMETER;\r
- return PrivacyManagerClient::getInstance()->removeAppPackagePrivacyInfo(std::string(package_id), false);\r
-}\r
-\r
-int privacy_manager_client_uninstall_privacy_by_server(const char *package_id)\r
-{\r
- if (package_id == NULL)\r
- return PRIV_MGR_ERROR_INVALID_PARAMETER;\r
- return PrivacyManagerClient::getInstance()->removeAppPackagePrivacyInfo(std::string(package_id), true);\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
- PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();\r
-\r
- std::list < std::string > list;\r
- retval = pInst->getPrivacyAppPackages(list);\r
- if (retval != PRIV_MGR_ERROR_SUCCESS)\r
- return retval;\r
- if (list.size() == 0)\r
- return PRIV_MGR_ERROR_NO_DATA;\r
-\r
- for (std::list < std::string >::iterator iter = list.begin(); iter != list.end(); ++iter)\r
- {\r
- if ( ! callback(iter->c_str(), user_data) )\r
- break;\r
- }\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-int privacy_manager_client_foreach_get_privacy_info(const char *package_id, privacy_manager_client_privacy_info_cb callback, void* user_data)\r
-{\r
- int retval;\r
- bool res;\r
- PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();\r
-\r
- std::list < std::pair <std::string, bool > > list;\r
-\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
- return PRIV_MGR_ERROR_NO_DATA;\r
-\r
- for (std::list < std::pair <std::string, bool > >::iterator iter = list.begin(); iter != list.end(); ++iter)\r
- {\r
- privacy_info_client_s *privacy_info_client_s = NULL;\r
- retval = create_privacy_info_client_s(iter->first.c_str(), iter->second, &privacy_info_client_s);\r
- res = callback(privacy_info_client_s, user_data);\r
- privacy_info_client_s_destroy(privacy_info_client_s);\r
- if (!res)\r
- break;\r
- }\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-\r
-}\r
-int privacy_manager_client_set_package_privacy(const char *package_id, const char *privacy_id, bool enable)\r
-{\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
-}\r
-\r
-int privacy_manager_client_set_user_consented(const char *package_id, bool consented)\r
-{\r
- PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();\r
-\r
- return pInst->setUserPrompted(std::string(package_id), consented);\r
-}\r
-\r
-int privacy_manager_client_foreach_all_privacy(privacy_manager_client_all_privacy_info_cb callback, void* user_data)\r
-{\r
- int retval;\r
- bool res;\r
-\r
- std::list < std::string > privacyList;\r
- retval = PrivacyIdInfo::getAllPrivacyId(privacyList);\r
- if (retval != PRIV_MGR_ERROR_SUCCESS)\r
- return retval;\r
- if (privacyList.size() == 0)\r
- return PRIV_MGR_ERROR_NO_DATA;\r
-\r
- for (std::list < std::string >::iterator iter = privacyList.begin(); iter != privacyList.end(); ++iter)\r
- {\r
- privacy_info_client_s *privacy_info_client_s = NULL;\r
- retval = create_privacy_info_client_s(iter->c_str(), false, &privacy_info_client_s);\r
- res = callback(privacy_info_client_s, user_data);\r
- privacy_info_client_s_destroy(privacy_info_client_s);\r
- if (!res)\r
- break;\r
- }\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int privacy_manager_client_foreach_package_list_by_privacy(const char *privacy_id, privacy_manager_client_packages_by_privacy_cb callback, void* user_data)\r
-{\r
- int retval;\r
- bool res;\r
- PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();\r
-\r
- std::list < std::pair < std::string, bool > > packageList;\r
- retval = pInst->getAppPackagesbyPrivacyId(std::string(privacy_id), packageList);\r
-\r
- if (retval != PRIV_MGR_ERROR_SUCCESS)\r
- return retval;\r
- if (packageList.size() == 0)\r
- return PRIV_MGR_ERROR_NO_DATA;\r
-\r
- for (std::list < std::pair < std::string, bool > >::iterator iter = packageList.begin(); iter != packageList.end(); ++iter)\r
- {\r
- res = callback(iter->first.c_str(), iter->second, user_data);\r
- if (!res)\r
- break;\r
- }\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+#include <string>
+#include <memory>
+#include <dlog.h>
+#include <PrivacyManagerClient.h>
+#include <PrivacyIdInfo.h>
+#include <privacy_manager_client.h>
+#include "privacy_manager_client_internal_types.h"
+
+int create_privacy_info_client_s(const char* privacy_id, bool enabled, privacy_info_client_s **privacy_info)
+{
+ privacy_info_client_s* temp = (privacy_info_client_s*) calloc(1, sizeof(privacy_info_client_s));
+ if (temp == NULL)
+ return PRIV_MGR_ERROR_OUT_OF_MEMORY;
+
+ int size = strlen(privacy_id);
+ temp->privacy_id = (char*) calloc(1, size + 1);
+ if (temp->privacy_id == NULL)
+ {
+ free(temp);
+ return PRIV_MGR_ERROR_OUT_OF_MEMORY;
+ }
+ memcpy(temp->privacy_id, privacy_id, size + 1);
+
+ temp->is_enabled = enabled;
+
+ *privacy_info = temp;
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int privacy_manager_client_install_privacy(const char *package_id, const char** privacy_list, bool privacy_popup_required)
+{
+ PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();
+ std::list < std::string > privacyList;
+
+ while (*privacy_list[0] != '\0')
+ privacyList.push_back(std::string(*privacy_list++));
+
+ int retval = pInst->addAppPackagePrivacyInfo(std::string(package_id), privacyList, privacy_popup_required, false);
+
+ return retval;
+}
+
+int privacy_manager_client_uninstall_privacy(const char *package_id)
+{
+ if (package_id == NULL)
+ return PRIV_MGR_ERROR_INVALID_PARAMETER;
+ return PrivacyManagerClient::getInstance()->removeAppPackagePrivacyInfo(std::string(package_id), false);
+}
+
+int privacy_manager_client_uninstall_privacy_by_server(const char *package_id)
+{
+ if (package_id == NULL)
+ return PRIV_MGR_ERROR_INVALID_PARAMETER;
+ return PrivacyManagerClient::getInstance()->removeAppPackagePrivacyInfo(std::string(package_id), true);
+}
+
+int privacy_manager_client_foreach_privacy_packages(privacy_manager_client_privacy_packages_cb callback, void *user_data)
+{
+ int retval;
+ PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();
+
+ std::list < std::string > list;
+ retval = pInst->getPrivacyAppPackages(list);
+ if (retval != PRIV_MGR_ERROR_SUCCESS)
+ return retval;
+ if (list.size() == 0)
+ return PRIV_MGR_ERROR_NO_DATA;
+
+ for (std::list < std::string >::iterator iter = list.begin(); iter != list.end(); ++iter)
+ {
+ if ( ! callback(iter->c_str(), user_data) )
+ break;
+ }
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+int privacy_manager_client_foreach_get_privacy_info(const char *package_id, privacy_manager_client_privacy_info_cb callback, void* user_data)
+{
+ int retval;
+ bool res;
+ PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();
+
+ std::list < std::pair <std::string, bool > > list;
+
+ retval = pInst->getAppPackagePrivacyInfo(std::string(package_id), list);
+ if (retval != PRIV_MGR_ERROR_SUCCESS)
+ return retval;
+ if (list.size() == 0)
+ return PRIV_MGR_ERROR_NO_DATA;
+
+ for (std::list < std::pair <std::string, bool > >::iterator iter = list.begin(); iter != list.end(); ++iter)
+ {
+ privacy_info_client_s *privacy_info_client_s = NULL;
+ retval = create_privacy_info_client_s(iter->first.c_str(), iter->second, &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_set_package_privacy(const char *package_id, const char *privacy_id, bool enable)
+{
+ PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();
+
+ return pInst->setPrivacySetting(package_id, privacy_id, enable);
+}
+
+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);
+}
+
+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);
+
+ 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
-/*\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 __TIZEN_PRIVACYMGR_PRIVACY_INFO_CLIENT_INTERNAL_TYPES_H\r
-#define __TIZEN_PRIVACYMGR_PRIVACY_INFO_CLIENT_INTERNAL_TYPES_H\r
-\r
-#include <tizen.h>\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_PRIVACYMGR_PRIVACY_INFO_CLIENT_INTERNAL_TYPES_H
+#define __TIZEN_PRIVACYMGR_PRIVACY_INFO_CLIENT_INTERNAL_TYPES_H
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
#endif //__TIZEN_PRIVACYMGR_PRIVACY_INFO_CLIENT_INTERNAL_TYPES_H
\ No newline at end of file
-/*\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
-#ifndef _IPRIVACY_MANAGER_H_\r
-#define _IPRIVACY_MANAGER_H_\r
-\r
-#include <string>\r
-#include <mutex>\r
-#include <list>\r
-#include <vector>\r
-#include <memory>\r
-#include <PrivacyManagerTypes.h>\r
-\r
-class SocketClient;\r
-\r
-class EXTERN_API IPrivacyManager\r
-{\r
-public:\r
- int addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& pList, bool privacyPopupRequired);\r
-\r
- int removeAppPackagePrivacyInfo(const std::string pkgId);\r
-\r
- int setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled);\r
- \r
- int getPrivacyAppPackages(std::list < std::string >& pList);\r
-\r
- int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & pList);\r
-};\r
-\r
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _IPRIVACY_MANAGER_H_
+#define _IPRIVACY_MANAGER_H_
+
+#include <string>
+#include <mutex>
+#include <list>
+#include <vector>
+#include <memory>
+#include <PrivacyManagerTypes.h>
+
+class SocketClient;
+
+class EXTERN_API IPrivacyManager
+{
+public:
+ int addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& pList, bool privacyPopupRequired);
+
+ int removeAppPackagePrivacyInfo(const std::string pkgId);
+
+ int setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled);
+
+ int getPrivacyAppPackages(std::list < std::string >& pList);
+
+ int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & pList);
+};
+
#endif // _IPRIVACY_MANAGER_H_
\ No newline at end of file
-/*\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 _PRIVACY_ID_INFO_H_\r
-#define _PRIVACY_ID_INFO_H_\r
-\r
-#include <string>\r
-#include <map>\r
-#include <list>\r
-\r
-class PrivacyIdInfo\r
-{\r
-private:\r
- static std::map <std::string, std::string> m_privilegeToPrivacyMap;\r
- static bool m_isInitialized;\r
-\r
-public:\r
- static int initialize(void);\r
- static int getPrivacyIdFromPrivilege(const std::string privilege, std::string& privacyId);\r
- static int getPrivacyIdListFromPrivilegeList(const std::list < std::string> privilegeList, std::list < std::string> & privacyIdList);\r
- static int getAllPrivacyId(std::list < std::string >& privacyIdList);\r
-\r
- static int getPrivaycDisplayName(const std::string privacyId, std::string& displayName);\r
- static int getPrivaycDescription(const std::string privacyId, std::string& description);\r
-};\r
-\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _PRIVACY_ID_INFO_H_
+#define _PRIVACY_ID_INFO_H_
+
+#include <string>
+#include <map>
+#include <list>
+
+class PrivacyIdInfo
+{
+private:
+ static std::map <std::string, std::string> m_privilegeToPrivacyMap;
+ static bool m_isInitialized;
+
+public:
+ static int initialize(void);
+ static int getPrivacyIdFromPrivilege(const std::string privilege, std::string& privacyId);
+ static int getPrivacyIdListFromPrivilegeList(const std::list < std::string> privilegeList, std::list < std::string> & privacyIdList);
+ static int getAllPrivacyId(std::list < std::string >& privacyIdList);
+
+ static int getPrivaycDisplayName(const std::string privacyId, std::string& displayName);
+ static int getPrivaycDescription(const std::string privacyId, std::string& description);
+};
+
#endif //_PRIVACY_ID_INFO_H_
\ No newline at end of file
-/*\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 _PRIVACY_MANAGER_TYPES_H_\r
-#define _PRIVACY_MANAGER_TYPES_H_\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
-static const std::string DBUS_SIGNAL_SETTING_CHANGED("privacy_setting_changed");\r
-static const std::string DBUS_SIGNAL_PKG_REMOVED("privacy_pkg_removed");\r
-\r
-#endif\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _PRIVACY_MANAGER_TYPES_H_
+#define _PRIVACY_MANAGER_TYPES_H_
+
+#include <string>
+#include <privacy_manager_client_types.h>
+
+static const std::string PRIVACY_DB_PATH("/opt/dbspace/.privacy.db");
+static const std::string PRIVACY_INFO_DB_PATH("/opt/dbspace/.privacylist.db");
+static const std::string SERVER_ADDRESS ("/tmp/privacy_manager_server");
+static const std::string DBUS_PATH("/privacy_manager/dbus_notification");
+static const std::string DBUS_SIGNAL_INTERFACE("org.tizen.privacy_manager.signal");
+static const std::string DBUS_SIGNAL_SETTING_CHANGED("privacy_setting_changed");
+static const std::string DBUS_SIGNAL_PKG_REMOVED("privacy_pkg_removed");
+
+#endif
-/*\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 _SOCKET_CONNECTION_H_\r
-#define _SOCKET_CONNECTION_H_\r
-\r
-#include <dlog.h>\r
-#include <new>\r
-#include <list>\r
-#include <utility>\r
-#include <SocketStream.h>\r
-#include <PrivacyManagerTypes.h>\r
-#include <iostream>\r
-#include <Utils.h>\r
-/*\r
- * This class implements interface for generic read and write from given socket.\r
- * It does not maintain socket descriptor, so any connecting and disconnecting should be\r
- */\r
-\r
-/*\r
- * Throws SocketConnectionException when read/write will not succeed or if any bad allocation\r
- * exception occurs during read.\r
- */\r
-\r
-class EXTERN_API SocketConnection\r
-{\r
-\r
-public:\r
-\r
- explicit SocketConnection(int socket_fd) : m_socketStream(socket_fd){\r
- LOGI("Created");\r
- }\r
-\r
- template<typename T, typename ...Args>\r
- int read(T* out, const Args&... args )\r
- {\r
- int res = read(out);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);\r
- res = read(args...);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- template<typename T>\r
- int read(T* out)\r
- {\r
- int length = 0;\r
- int res = m_socketStream.readStream(sizeof(length), &length);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "readStream : %d", res);\r
- char* pBuf = new (std::nothrow) char[length + 1];\r
- TryReturn(pBuf != NULL, PRIV_MGR_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_MGR_ERROR_OUT_OF_MEMORY);\r
-\r
- res = m_socketStream.readStream(length, pBuf);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res);\r
-\r
- pBuf[length] = 0;\r
-\r
- out = T(pBuf);\r
-\r
- delete[] pBuf;\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
- \r
- int read(bool* pB)\r
- { \r
- int length = 0;\r
- int res = m_socketStream.readStream(sizeof(length), &length);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "readStream : %d", res);\r
-\r
- char* pBuf = new (std::nothrow) char[length + 1];\r
- TryReturn(pBuf != NULL, PRIV_MGR_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_MGR_ERROR_OUT_OF_MEMORY);\r
-\r
- res = m_socketStream.readStream(length, pBuf);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res);\r
-\r
- pBuf[length] = 0;\r
-\r
- *pB = * reinterpret_cast <bool* > (pBuf);\r
-\r
- delete[] pBuf;\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- int read(bool& b)\r
- {\r
- return read(&b);\r
- }\r
- \r
- int read(int& i)\r
- {\r
- return read(&i);\r
- }\r
-\r
- int read(int* pI)\r
- {\r
- int length = 0;\r
- int res = m_socketStream.readStream(sizeof(length), &length);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "readStream : %d", res);\r
-\r
- char* pBuf = new (std::nothrow) char[length + 1];\r
- TryReturn(pBuf != NULL, PRIV_MGR_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_MGR_ERROR_OUT_OF_MEMORY);\r
-\r
- res = m_socketStream.readStream(length, pBuf);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res);\r
-\r
- pBuf[length] = 0;\r
-\r
- *pI = * reinterpret_cast <int* > (pBuf);\r
-\r
- delete[] pBuf;\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- int read(std::string* pStr)\r
- {\r
- int length = 0;\r
- int res = m_socketStream.readStream(sizeof(length), &length);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "readStream : %d", res);\r
-\r
- char* pBuf = new (std::nothrow) char[length + 1];\r
- TryReturn(pBuf != NULL, PRIV_MGR_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_MGR_ERROR_OUT_OF_MEMORY);\r
-\r
- m_socketStream.readStream(length, pBuf);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res);\r
-\r
- pBuf[length] = 0;\r
-\r
- *pStr = std::string(pBuf);\r
- delete[] pBuf;\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
- \r
- int read(std::string& str)\r
- {\r
- return read(&str);\r
- }\r
-\r
- template < typename T >\r
- int read (std::list<T>& list) \r
- {\r
- int length;\r
- int res = read(length);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);\r
-\r
- for (int i = 0; i < length; ++i) \r
- {\r
- T obj;\r
- res = read (obj);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);\r
- list.push_back(obj);\r
- }\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- template < typename T >\r
- int read (std::list<T>* pList) \r
- {\r
- return read(*pList);\r
- }\r
-\r
- template < typename K, typename P >\r
- void read (std::pair<K, P>& pair) \r
- {\r
- int res = read( pair.first);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);\r
- res = read( pair.second);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- template < typename K, typename P >\r
- int read (std::pair<K, P>* pPair) \r
- {\r
- return read( *pPair);\r
- }\r
-\r
- template<typename T, typename ...Args>\r
- int write(const T& in, const Args&... args)\r
- {\r
- int res = write(in);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);\r
- res = write(args...);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- int write(const std::string& in)\r
- {\r
- int length = in.size();\r
- int res = m_socketStream.writeStream(sizeof(length), &length);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);\r
- res = m_socketStream.writeStream(length, in.c_str());\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
- \r
- int write(const unsigned int& in)\r
- {\r
- int length = sizeof(in);\r
- int res = m_socketStream.writeStream(sizeof(length), &length);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);\r
- res = m_socketStream.writeStream(length, &in);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- int write(const int& in)\r
- {\r
- int length = sizeof(in);\r
- int res = m_socketStream.writeStream(sizeof(length), &length);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);\r
- res = m_socketStream.writeStream(length, &in);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- int write(const bool& in)\r
- {\r
- int length = sizeof(in);\r
- int res = m_socketStream.writeStream(sizeof(length), &length);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);\r
- res = m_socketStream.writeStream(length, &in);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- int write(const char*& in)\r
- {\r
- int length = strlen(in);\r
- int res = m_socketStream.writeStream(sizeof(length), &length);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);\r
- res = m_socketStream.writeStream(length, in);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- template<typename T, typename ...Args>\r
- int write(const T* in, const Args&... args)\r
- {\r
- int res = write(in);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);\r
- res = write(args...);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- template<typename K, typename T>\r
- int write(const std::pair<K, T> p)\r
- {\r
- int res = write(p.first);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);\r
- res = write(p.second);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- template<typename K, typename T>\r
- int write(const std::pair<K, T&> p)\r
- {\r
- int res = write(p.first);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);\r
- res = write(p.second);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- template<typename K, typename T>\r
- int write(const std::pair<K, T&>* pPair) \r
- {\r
- return write(*pPair);\r
- }\r
-\r
- template<typename T>\r
- int write(const std::list <T> list) \r
- {\r
- int length = list.size();\r
- int res = write(length);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);\r
- for (typename std::list <T>::const_iterator iter = list.begin(); iter != list.end(); iter++) {\r
- res = write(*iter);\r
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);\r
- }\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- template<typename T>\r
- int write(const std::list <T>* pList) \r
- {\r
- return write(*pList);\r
- }\r
-\r
-\r
-private:\r
- SocketStream m_socketStream;\r
-};\r
-\r
-#endif // _SOCKET_CONNECTION_H_\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _SOCKET_CONNECTION_H_
+#define _SOCKET_CONNECTION_H_
+
+#include <dlog.h>
+#include <new>
+#include <list>
+#include <utility>
+#include <SocketStream.h>
+#include <PrivacyManagerTypes.h>
+#include <iostream>
+#include <Utils.h>
+/*
+ * This class implements interface for generic read and write from given socket.
+ * It does not maintain socket descriptor, so any connecting and disconnecting should be
+ */
+
+/*
+ * Throws SocketConnectionException when read/write will not succeed or if any bad allocation
+ * exception occurs during read.
+ */
+
+class EXTERN_API SocketConnection
+{
+
+public:
+
+ explicit SocketConnection(int socket_fd) : m_socketStream(socket_fd){
+ LOGI("Created");
+ }
+
+ template<typename T, typename ...Args>
+ int read(T* out, const Args&... args )
+ {
+ int res = read(out);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);
+ res = read(args...);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ template<typename T>
+ int read(T* out)
+ {
+ int length = 0;
+ int res = m_socketStream.readStream(sizeof(length), &length);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "readStream : %d", res);
+ char* pBuf = new (std::nothrow) char[length + 1];
+ TryReturn(pBuf != NULL, PRIV_MGR_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_MGR_ERROR_OUT_OF_MEMORY);
+
+ res = m_socketStream.readStream(length, pBuf);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res);
+
+ pBuf[length] = 0;
+
+ out = T(pBuf);
+
+ delete[] pBuf;
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ int read(bool* pB)
+ {
+ int length = 0;
+ int res = m_socketStream.readStream(sizeof(length), &length);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "readStream : %d", res);
+
+ char* pBuf = new (std::nothrow) char[length + 1];
+ TryReturn(pBuf != NULL, PRIV_MGR_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_MGR_ERROR_OUT_OF_MEMORY);
+
+ res = m_socketStream.readStream(length, pBuf);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res);
+
+ pBuf[length] = 0;
+
+ *pB = * reinterpret_cast <bool* > (pBuf);
+
+ delete[] pBuf;
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ int read(bool& b)
+ {
+ return read(&b);
+ }
+
+ int read(int& i)
+ {
+ return read(&i);
+ }
+
+ int read(int* pI)
+ {
+ int length = 0;
+ int res = m_socketStream.readStream(sizeof(length), &length);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "readStream : %d", res);
+
+ char* pBuf = new (std::nothrow) char[length + 1];
+ TryReturn(pBuf != NULL, PRIV_MGR_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_MGR_ERROR_OUT_OF_MEMORY);
+
+ res = m_socketStream.readStream(length, pBuf);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res);
+
+ pBuf[length] = 0;
+
+ *pI = * reinterpret_cast <int* > (pBuf);
+
+ delete[] pBuf;
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ int read(std::string* pStr)
+ {
+ int length = 0;
+ int res = m_socketStream.readStream(sizeof(length), &length);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "readStream : %d", res);
+
+ char* pBuf = new (std::nothrow) char[length + 1];
+ TryReturn(pBuf != NULL, PRIV_MGR_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_MGR_ERROR_OUT_OF_MEMORY);
+
+ m_socketStream.readStream(length, pBuf);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res);
+
+ pBuf[length] = 0;
+
+ *pStr = std::string(pBuf);
+ delete[] pBuf;
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ int read(std::string& str)
+ {
+ return read(&str);
+ }
+
+ template < typename T >
+ int read (std::list<T>& list)
+ {
+ int length;
+ int res = read(length);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);
+
+ for (int i = 0; i < length; ++i)
+ {
+ T obj;
+ res = read (obj);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);
+ list.push_back(obj);
+ }
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ template < typename T >
+ int read (std::list<T>* pList)
+ {
+ return read(*pList);
+ }
+
+ template < typename K, typename P >
+ void read (std::pair<K, P>& pair)
+ {
+ int res = read( pair.first);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);
+ res = read( pair.second);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ template < typename K, typename P >
+ int read (std::pair<K, P>* pPair)
+ {
+ return read( *pPair);
+ }
+
+ template<typename T, typename ...Args>
+ int write(const T& in, const Args&... args)
+ {
+ int res = write(in);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
+ res = write(args...);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ int write(const std::string& in)
+ {
+ int length = in.size();
+ int res = m_socketStream.writeStream(sizeof(length), &length);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
+ res = m_socketStream.writeStream(length, in.c_str());
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ int write(const unsigned int& in)
+ {
+ int length = sizeof(in);
+ int res = m_socketStream.writeStream(sizeof(length), &length);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
+ res = m_socketStream.writeStream(length, &in);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ int write(const int& in)
+ {
+ int length = sizeof(in);
+ int res = m_socketStream.writeStream(sizeof(length), &length);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
+ res = m_socketStream.writeStream(length, &in);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ int write(const bool& in)
+ {
+ int length = sizeof(in);
+ int res = m_socketStream.writeStream(sizeof(length), &length);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
+ res = m_socketStream.writeStream(length, &in);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ int write(const char*& in)
+ {
+ int length = strlen(in);
+ int res = m_socketStream.writeStream(sizeof(length), &length);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
+ res = m_socketStream.writeStream(length, in);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ template<typename T, typename ...Args>
+ int write(const T* in, const Args&... args)
+ {
+ int res = write(in);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
+ res = write(args...);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ template<typename K, typename T>
+ int write(const std::pair<K, T> p)
+ {
+ int res = write(p.first);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
+ res = write(p.second);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ template<typename K, typename T>
+ int write(const std::pair<K, T&> p)
+ {
+ int res = write(p.first);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
+ res = write(p.second);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ template<typename K, typename T>
+ int write(const std::pair<K, T&>* pPair)
+ {
+ return write(*pPair);
+ }
+
+ template<typename T>
+ int write(const std::list <T> list)
+ {
+ int length = list.size();
+ int res = write(length);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
+ for (typename std::list <T>::const_iterator iter = list.begin(); iter != list.end(); iter++) {
+ res = write(*iter);
+ TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
+ }
+
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+
+ template<typename T>
+ int write(const std::list <T>* pList)
+ {
+ return write(*pList);
+ }
+
+
+private:
+ SocketStream m_socketStream;
+};
+
+#endif // _SOCKET_CONNECTION_H_
-/*\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 _SOCKET_STREAM_H_\r
-#define _SOCKET_STREAM_H_\r
-\r
-#include <string>\r
-#include <PrivacyManagerTypes.h>\r
-\r
-class EXTERN_API SocketStream\r
-{\r
-public:\r
- explicit SocketStream(int socket_fd) \r
- : m_socketFd(socket_fd)\r
- , m_bytesRead(0)\r
- ,m_bytesWrote(0)\r
- {\r
- LOGI("Created");\r
- }\r
-\r
- int readStream(size_t num, void * bytes);\r
- int writeStream(size_t num, const void * bytes);\r
-private:\r
- int throwWithErrnoMessage(std::string specificInfo);\r
- int m_socketFd;\r
- int m_bytesRead;\r
- int m_bytesWrote;\r
-};\r
-\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _SOCKET_STREAM_H_
+#define _SOCKET_STREAM_H_
+
+#include <string>
+#include <PrivacyManagerTypes.h>
+
+class EXTERN_API SocketStream
+{
+public:
+ explicit SocketStream(int socket_fd)
+ : m_socketFd(socket_fd)
+ , m_bytesRead(0)
+ ,m_bytesWrote(0)
+ {
+ LOGI("Created");
+ }
+
+ int readStream(size_t num, void * bytes);
+ int writeStream(size_t num, const void * bytes);
+private:
+ int throwWithErrnoMessage(std::string specificInfo);
+ int m_socketFd;
+ int m_bytesRead;
+ int m_bytesWrote;
+};
+
#endif //_SOCKET_STREAM_H_
\ No newline at end of file
-/*\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 __TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_TYPES_H\r
-#define __TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_TYPES_H\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-#ifndef EXTERN_API\r
-#define EXTERN_API __attribute__((visibility("default")))\r
-#endif\r
-\r
-enum {\r
- PRIV_MGR_ERROR_SUCCESS = 0,\r
-\r
- PRIV_MGR_ERROR_NOT_INITIALIZED = -10,\r
- PRIV_MGR_ERROR_INVALID_PARAMETER = -11,\r
- PRIV_MGR_ERROR_OUT_OF_MEMORY = -12,\r
- PRIV_MGR_ERROR_IO_ERROR = -13,\r
- PRIV_MGR_ERROR_NO_DATA = -14,\r
- PRIV_MGR_ERROR_DB_ERROR = -15,\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
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif //__TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_TYPES_H\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_TYPES_H
+#define __TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_TYPES_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef EXTERN_API
+#define EXTERN_API __attribute__((visibility("default")))
+#endif
+
+enum {
+ PRIV_MGR_ERROR_SUCCESS = 0,
+
+ PRIV_MGR_ERROR_NOT_INITIALIZED = -10,
+ PRIV_MGR_ERROR_INVALID_PARAMETER = -11,
+ PRIV_MGR_ERROR_OUT_OF_MEMORY = -12,
+ PRIV_MGR_ERROR_IO_ERROR = -13,
+ PRIV_MGR_ERROR_NO_DATA = -14,
+ PRIV_MGR_ERROR_DB_ERROR = -15,
+ PRIV_MGR_ERROR_IPC_ERROR = -16,
+ PRIV_MGR_ERROR_INVALID_STATE = -17,
+ PRIV_MGR_ERROR_SYSTEM_ERROR = -18,
+ PRIV_MGR_ERROR_USER_NOT_CONSENTED = -19,
+
+ PRIV_MGR_ERROR_UNKNOWN = -(0x99),
+};
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_TYPES_H
if ( (it = m_filteredPkgList.find(pkgId)) != m_filteredPkgList.end())
return true;
- return false;
+ return false;
#else
return false;
#endif
int
PrivacyDb::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool enabled)
{
- LOGI("enter");
-
static const std::string query = std::string("UPDATE PrivacyInfo set IS_ENABLED =? where PKG_ID=? and PRIVACY_ID=?");
openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);
res = sqlite3_step(pStmt.get());
TryReturn( res == SQLITE_DONE, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res);
- LOGI("leave");
-
return 0;
}
int
PrivacyDb::getPrivacyAppPackages(std::list <std::string>& list) const
{
- LOGI("enter");
-
std::string query = "SELECT PKG_ID from PackageInfo";
openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY);
list.push_back(std::string(pValue));
}
- LOGI("leave");
-
return 0;
}
int
PrivacyDb::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > >& privacyInfoList) const
{
- LOGI("enter");
-
static const std::string query = "SELECT PRIVACY_ID, IS_ENABLED from PrivacyInfo where PKG_ID=?";
openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY);
SECURE_LOGD("Privacy found : %s %d", privacyId, privacyEnabled);
}
- LOGI("leave");
-
return 0;
}
int
PrivacyDb::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string > privilegeList, bool privacyPopupRequired)
{
- LOGI("enter");
-
static const std::string pkgInfoQuery("INSERT INTO PackageInfo(PKG_ID, IS_SET) VALUES(?, ?)");
static const std::string privacyQuery("INSERT INTO PrivacyInfo(PKG_ID, PRIVACY_ID, IS_ENABLED) VALUES(?, ?, ?)");
for ( std::list <std::string>::const_iterator iter = privilegeList.begin(); iter != privilegeList.end(); ++iter)
{
- SECURE_LOGD(" install privacy: %s", iter->c_str());
+ SECURE_LOGD("install privacy: %s", iter->c_str());
prepareDb(pDbHandler, privacyQuery.c_str(), pPrivacyStmt);
res = sqlite3_bind_text(pPrivacyStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);
int
PrivacyDb::removeAppPackagePrivacyInfo(const std::string pkgId)
{
- LOGI("enter");
-
static const std::string pkgInfoQuery("DELETE FROM PackageInfo WHERE PKG_ID=?");
static const std::string privacyQuery("DELETE FROM PrivacyInfo WHERE PKG_ID=?");
int
PrivacyDb::isUserPrompted(const std::string pkgId, bool& isPrompted) const
{
- LOGI("enter");
-
static const std::string query = "SELECT IS_SET from PackageInfo where PKG_ID=?";
isPrompted = true;
int
PrivacyDb::setUserPrompted(const std::string pkgId, bool prompted)
{
- LOGI("enter");
-
std::string query = std::string("UPDATE PackageInfo set IS_SET =? where PKG_ID=?");
int res;
res = sqlite3_step(pStmt.get());
TryReturn( res == SQLITE_DONE, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res);
- LOGI("leave");
-
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);
list.push_back( std::pair <std::string, bool >(pkgId, isEnabled) );
}
- LOGI("leave");
-
return PRIV_MGR_ERROR_SUCCESS;
}
PrivacyDb*
PrivacyDb::getInstance(void)
{
- LOGI("enter");
std::lock_guard < std::mutex > guard(m_singletonMutex);
if (m_pInstance == NULL)
m_pInstance = new PrivacyDb();
}
- LOGI("leave");
-
return m_pInstance;
}
-/*\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
-#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
-#include <libintl.h>\r
-\r
-std::map <std::string, std::string> PrivacyIdInfo::m_privilegeToPrivacyMap;\r
-bool PrivacyIdInfo:: m_isInitialized;\r
-\r
-int\r
-PrivacyIdInfo::initialize(void)\r
-{\r
- static const std::string sqlPrivilege("SELECT PRIVILEGE_ID, PRIVACY_ID from PrivilegeToPrivacyTable");\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
- }\r
-\r
- m_isInitialized = true;\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int\r
-PrivacyIdInfo::getPrivacyIdFromPrivilege(const std::string privilege, std::string& privacyId)\r
-{\r
- if (!m_isInitialized)\r
- initialize();\r
- std::map < std::string, std::string >::iterator iter = m_privilegeToPrivacyMap.find(privilege);\r
- if (iter == m_privilegeToPrivacyMap.end())\r
- return PRIV_MGR_ERROR_NO_DATA;\r
- privacyId = iter->second;\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int\r
-PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(const std::list < std::string> privilegeList, std::list < std::string> & privacyIdList)\r
-{\r
- if (!m_isInitialized)\r
- initialize();\r
-\r
- privacyIdList.clear();\r
-\r
- std::set <std::string> privacyIdSet;\r
-\r
- for (std::list < std::string > ::const_iterator iter = privilegeList.begin(); iter != privilegeList.end(); ++iter)\r
- {\r
- std::string privacyId;\r
- int res = getPrivacyIdFromPrivilege(*iter, privacyId);\r
- if (res == PRIV_MGR_ERROR_SUCCESS)\r
- privacyIdSet.insert(privacyId);\r
- }\r
- \r
- for (std::set < std::string >::iterator iter = privacyIdSet.begin(); iter != privacyIdSet.end(); ++iter)\r
- {\r
- privacyIdList.push_back(*iter);\r
- }\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int\r
-PrivacyIdInfo::getAllPrivacyId(std::list < std::string >& privacyIdList)\r
-{\r
- static const std::string sql("SELECT PRIVACY_ID from PrivacyInfo");\r
-\r
- if (!m_isInitialized)\r
- initialize(); \r
- \r
- openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY);\r
- prepareDb(pDbHandler, sql.c_str(), pStmt);\r
-\r
- int res;\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
- privacyIdList.push_back(std::string(privacyId));\r
- SECURE_LOGD(" privacy Id : %s", privacyId);\r
- }\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int\r
-PrivacyIdInfo::getPrivaycDisplayName(const std::string privacyId, std::string& displayName)\r
-{\r
- LOGI("enter");\r
-\r
- if (!m_isInitialized)\r
- initialize();\r
- //bindtextdomain("privacy-manager", "/usr/share/locale");\r
- //setlocale(LC_ALL, "");\r
-\r
- std::string sql = std::string("SELECT STR_MODULE_ID, STR_NAME_ID from PrivacyInfo where PRIVACY_ID=?");\r
-\r
- openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY);\r
- prepareDb(pDbHandler, sql.c_str(), pStmt);\r
-\r
- int res = sqlite3_bind_text(pStmt.get(), 1, privacyId.c_str(), -1, SQLITE_TRANSIENT);\r
- TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
-\r
- if ( sqlite3_step(pStmt.get()) == SQLITE_ROW )\r
- {\r
- const char* pModuleId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0));\r
- const char* pNameId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 1));\r
-\r
- LOGD("result : [%s] [%s]", pModuleId, pNameId);\r
-\r
- if (pNameId == NULL)\r
- displayName = privacyId;\r
- else\r
- displayName = std::string(dgettext(pModuleId, pNameId));\r
- }\r
- else\r
- {\r
- LOGI("Cannot find privacy string %s ", privacyId.c_str());\r
-\r
- // Todo : return no_data.\r
- displayName = privacyId;\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- }\r
-\r
- LOGI("leave %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int\r
-PrivacyIdInfo::getPrivaycDescription(const std::string privacyId, std::string& displayName)\r
-{\r
- LOGI("enter");\r
-\r
- if (!m_isInitialized)\r
- initialize();\r
-\r
- std::string sql = std::string("SELECT STR_MODULE_ID, STR_NAME_ID from PrivacyInfo where PRIVACY_ID=?");\r
-\r
- openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY);\r
- prepareDb(pDbHandler, sql.c_str(), pStmt);\r
-\r
- int res = sqlite3_bind_text(pStmt.get(), 1, privacyId.c_str(), -1, SQLITE_TRANSIENT);\r
- TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
-\r
- if ( sqlite3_step(pStmt.get()) == SQLITE_ROW )\r
- {\r
- const char* pModuleId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0));\r
- const char* pNameId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0));\r
-\r
- LOGD("result : %s %s", pModuleId, pNameId);\r
-\r
- displayName = std::string(dgettext(pModuleId, pNameId));\r
- }\r
- else\r
- {\r
- LOGI("Cannot find privacy string %s ", privacyId.c_str());\r
- return PRIV_MGR_ERROR_NO_DATA;\r
- }\r
-\r
- LOGI("leave %d", res);\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <PrivacyIdInfo.h>
+#include <privacy_manager_client_types.h>
+#include <PrivacyManagerTypes.h>
+#include <dlog.h>
+#include <set>
+#include <Utils.h>
+#include <libintl.h>
+
+std::map <std::string, std::string> PrivacyIdInfo::m_privilegeToPrivacyMap;
+bool PrivacyIdInfo:: m_isInitialized;
+
+int
+PrivacyIdInfo::initialize(void)
+{
+ static const std::string sqlPrivilege("SELECT PRIVILEGE_ID, PRIVACY_ID from PrivilegeToPrivacyTable");
+
+ openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY);
+ prepareDb(pDbHandler, sqlPrivilege.c_str(), pStmtPrivilege);
+
+ int res;
+ while ( (res = sqlite3_step(pStmtPrivilege.get())) == SQLITE_ROW )
+ {
+ const char* privilegeId = reinterpret_cast < const char* > (sqlite3_column_text(pStmtPrivilege.get(), 0));
+ const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pStmtPrivilege.get(), 1));
+ m_privilegeToPrivacyMap.insert(std::map < std::string, std::string >::value_type(std::string(privilegeId), std::string(privacyId)));
+ }
+
+ m_isInitialized = true;
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int
+PrivacyIdInfo::getPrivacyIdFromPrivilege(const std::string privilege, std::string& privacyId)
+{
+ if (!m_isInitialized)
+ initialize();
+ std::map < std::string, std::string >::iterator iter = m_privilegeToPrivacyMap.find(privilege);
+ if (iter == m_privilegeToPrivacyMap.end())
+ return PRIV_MGR_ERROR_NO_DATA;
+ privacyId = iter->second;
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int
+PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(const std::list < std::string> privilegeList, std::list < std::string> & privacyIdList)
+{
+ if (!m_isInitialized)
+ initialize();
+
+ privacyIdList.clear();
+
+ std::set <std::string> privacyIdSet;
+
+ for (std::list < std::string > ::const_iterator iter = privilegeList.begin(); iter != privilegeList.end(); ++iter)
+ {
+ std::string privacyId;
+ int res = getPrivacyIdFromPrivilege(*iter, privacyId);
+ if (res == PRIV_MGR_ERROR_SUCCESS)
+ privacyIdSet.insert(privacyId);
+ }
+
+ for (std::set < std::string >::iterator iter = privacyIdSet.begin(); iter != privacyIdSet.end(); ++iter)
+ {
+ privacyIdList.push_back(*iter);
+ }
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int
+PrivacyIdInfo::getAllPrivacyId(std::list < std::string >& privacyIdList)
+{
+ static const std::string sql("SELECT PRIVACY_ID from PrivacyInfo");
+
+ if (!m_isInitialized)
+ initialize();
+
+ openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY);
+ prepareDb(pDbHandler, sql.c_str(), pStmt);
+
+ int res;
+ while ( (res = sqlite3_step(pStmt.get())) == SQLITE_ROW )
+ {
+ const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0));
+ privacyIdList.push_back(std::string(privacyId));
+ SECURE_LOGD(" privacy Id : %s", privacyId);
+ }
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int
+PrivacyIdInfo::getPrivaycDisplayName(const std::string privacyId, std::string& displayName)
+{
+ if (!m_isInitialized)
+ initialize();
+
+ std::string sql = std::string("SELECT STR_MODULE_ID, STR_NAME_ID from PrivacyInfo where PRIVACY_ID=?");
+
+ openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY);
+ prepareDb(pDbHandler, sql.c_str(), pStmt);
+
+ int res = sqlite3_bind_text(pStmt.get(), 1, privacyId.c_str(), -1, SQLITE_TRANSIENT);
+ TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);
+
+ if ( sqlite3_step(pStmt.get()) == SQLITE_ROW )
+ {
+ const char* pModuleId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0));
+ const char* pNameId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 1));
+
+ if (pNameId == NULL)
+ displayName = privacyId;
+ else
+ displayName = std::string(dgettext(pModuleId, pNameId));
+ }
+ else
+ {
+ LOGI("Cannot find privacy string %s ", privacyId.c_str());
+ return PRIV_MGR_ERROR_NO_DATA;
+ }
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int
+PrivacyIdInfo::getPrivaycDescription(const std::string privacyId, std::string& displayName)
+{
+ if (!m_isInitialized)
+ initialize();
+
+ std::string sql = std::string("SELECT STR_MODULE_ID, STR_NAME_ID from PrivacyInfo where PRIVACY_ID=?");
+
+ openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY);
+ prepareDb(pDbHandler, sql.c_str(), pStmt);
+
+ int res = sqlite3_bind_text(pStmt.get(), 1, privacyId.c_str(), -1, SQLITE_TRANSIENT);
+ TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);
+
+ if ( sqlite3_step(pStmt.get()) == SQLITE_ROW )
+ {
+ const char* pModuleId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0));
+ const char* pNameId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0));
+
+ displayName = std::string(dgettext(pModuleId, pNameId));
+ }
+ else
+ {
+ LOGI("Cannot find privacy string %s ", privacyId.c_str());
+ return PRIV_MGR_ERROR_NO_DATA;
+ }
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
-/*\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
-#include "SocketConnection.h"\r
-\r
-//\r
-// Note:\r
-//\r
-// The file here is left blank to enable precompilation\r
-// of templates in corresponding header file.\r
-// Do not remove this file.\r
-//\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "SocketConnection.h"
+
+//
+// Note:
+//
+// The file here is left blank to enable precompilation
+// of templates in corresponding header file.
+// Do not remove this file.
+//
-/*\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
-\r
-#include <sys/socket.h>\r
-#include <sys/select.h>\r
-#include <errno.h>\r
-#include <cstring>\r
-#include <unistd.h>\r
-#include <dlog.h>\r
-#include <Utils.h>\r
-#include "SocketStream.h"\r
-\r
-#define READ_TIEMOUT_SEC 1\r
-#define READ_TIMEUOT_NSEC 0\r
-#define WRITE_TIMEOUT_SEC 0\r
-#define WRITE_TIMEOUT_NSEC 100000000\r
-#define MAX_BUFFER 10240\r
-\r
-int\r
-SocketStream::throwWithErrnoMessage(std::string function_name)\r
-{\r
- LOGE("%s : %s", function_name.c_str(), strerror(errno));\r
- return errno;\r
-}\r
-\r
-int\r
-SocketStream::readStream(size_t num, void* pBytes)\r
-{\r
- TryReturn(pBytes != NULL, -1, , "Null pointer to buffer");\r
-\r
- m_bytesRead += num;\r
- \r
- TryReturn(m_bytesRead <= MAX_BUFFER, -1, , "Too big buffer requested!");\r
-\r
- char partBuffer[MAX_BUFFER];\r
- std::string wholeBuffer;\r
-\r
- fd_set rset, allset;\r
- int maxFd;\r
- ssize_t bytesRead = 0;\r
- ssize_t bytesToRead = (ssize_t) num;\r
-\r
- timespec timeout;\r
-\r
- maxFd = m_socketFd;\r
- ++maxFd;\r
-\r
- FD_ZERO(&allset);\r
- FD_SET(m_socketFd, &allset);\r
-\r
- int ret = -1;\r
-\r
- while(bytesToRead != 0)\r
- {\r
- timeout.tv_sec = READ_TIEMOUT_SEC;\r
- timeout.tv_nsec = READ_TIMEUOT_NSEC;\r
- rset = allset;\r
-\r
- if ( (ret = pselect(maxFd, &rset, NULL, NULL, &timeout, NULL)) == -1 )\r
- {\r
- if (errno == EINTR)\r
- continue;\r
- LOGD("pselect : %s", strerror(errno));\r
- return -1;\r
- } \r
- //This means pselect got timedout\r
- //This is not a proper behavior in reading data from UDS\r
- //And could mean we got corrupted connection\r
- TryReturn(ret != 0, -1, , "Couldn't read whole data");\r
-\r
- if ( FD_ISSET(m_socketFd, &rset) )\r
- {\r
- bytesRead = read(m_socketFd, partBuffer, num);\r
- if ( bytesRead <= 0 )\r
- {\r
- if(errno == ECONNRESET || errno == ENOTCONN || errno == ETIMEDOUT)\r
- {\r
- LOGI("Connection closed : %s", strerror(errno));\r
- return -1;\r
- }\r
- else if (errno != EAGAIN && errno != EWOULDBLOCK){\r
- LOGI("read()");\r
- return -1;\r
- }\r
- }\r
-\r
- wholeBuffer.append(partBuffer, bytesRead);\r
- bytesToRead -= bytesRead;\r
- bytesRead = 0;\r
- continue;\r
- }\r
-\r
- }\r
- memcpy(pBytes, wholeBuffer.c_str(), num);\r
- \r
- return 0;\r
-}\r
-\r
-int\r
-SocketStream::writeStream(size_t num, const void* pBytes)\r
-{\r
- TryReturn(pBytes != NULL, -1, , "Null pointer to buffer");\r
- \r
- m_bytesWrote += num;\r
- \r
- TryReturn(m_bytesRead <= MAX_BUFFER, -1, , "Too big buffer requested!");\r
-\r
- fd_set wset, allset;\r
- int maxFd;\r
-\r
- timespec timeout;\r
-\r
- maxFd = m_socketFd;\r
- ++maxFd;\r
-\r
- FD_ZERO(&allset);\r
- FD_SET(m_socketFd, &allset);\r
-\r
- int res;\r
- int writeRes;\r
- int bytesToWrite = num;\r
- unsigned int currentOffset = 0;\r
-\r
- while(currentOffset != num)\r
- {\r
- timeout.tv_sec = WRITE_TIMEOUT_SEC;\r
- timeout.tv_nsec = WRITE_TIMEOUT_NSEC;\r
- wset = allset;\r
-\r
- if ( (res = pselect(maxFd, NULL, &wset, NULL, &timeout, NULL)) == -1 )\r
- {\r
- if(errno == EINTR)\r
- continue;\r
- LOGD("pselect : %s", strerror(errno));\r
- return -1;\r
- }\r
-\r
- if(FD_ISSET(m_socketFd, &wset))\r
- {\r
- if ( (writeRes = write(m_socketFd, reinterpret_cast<const char *>(pBytes) + currentOffset, bytesToWrite)) == -1)\r
- {\r
- if(errno == ECONNRESET || errno == EPIPE)\r
- {\r
- LOGI("Connection closed : %s", strerror(errno));\r
- return -1;\r
-\r
- }\r
- else if(errno != EAGAIN && errno != EWOULDBLOCK)\r
- {\r
- LOGE("write()");\r
- return -1;\r
- }\r
- }\r
- currentOffset += writeRes;\r
- bytesToWrite -= writeRes;\r
- }\r
- }\r
- return 0;\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <sys/socket.h>
+#include <sys/select.h>
+#include <errno.h>
+#include <cstring>
+#include <unistd.h>
+#include <dlog.h>
+#include <Utils.h>
+#include "SocketStream.h"
+
+#define READ_TIEMOUT_SEC 1
+#define READ_TIMEUOT_NSEC 0
+#define WRITE_TIMEOUT_SEC 0
+#define WRITE_TIMEOUT_NSEC 100000000
+#define MAX_BUFFER 10240
+
+int
+SocketStream::throwWithErrnoMessage(std::string function_name)
+{
+ LOGE("%s : %s", function_name.c_str(), strerror(errno));
+ return errno;
+}
+
+int
+SocketStream::readStream(size_t num, void* pBytes)
+{
+ TryReturn(pBytes != NULL, -1, , "Null pointer to buffer");
+
+ m_bytesRead += num;
+
+ TryReturn(m_bytesRead <= MAX_BUFFER, -1, , "Too big buffer requested!");
+
+ char partBuffer[MAX_BUFFER];
+ std::string wholeBuffer;
+
+ fd_set rset, allset;
+ int maxFd;
+ ssize_t bytesRead = 0;
+ ssize_t bytesToRead = (ssize_t) num;
+
+ timespec timeout;
+
+ maxFd = m_socketFd;
+ ++maxFd;
+
+ FD_ZERO(&allset);
+ FD_SET(m_socketFd, &allset);
+
+ int ret = -1;
+
+ while(bytesToRead != 0)
+ {
+ timeout.tv_sec = READ_TIEMOUT_SEC;
+ timeout.tv_nsec = READ_TIMEUOT_NSEC;
+ rset = allset;
+
+ if ( (ret = pselect(maxFd, &rset, NULL, NULL, &timeout, NULL)) == -1 )
+ {
+ if (errno == EINTR)
+ continue;
+ LOGD("pselect : %s", strerror(errno));
+ return -1;
+ }
+ //This means pselect got timedout
+ //This is not a proper behavior in reading data from UDS
+ //And could mean we got corrupted connection
+ TryReturn(ret != 0, -1, , "Couldn't read whole data");
+
+ if ( FD_ISSET(m_socketFd, &rset) )
+ {
+ bytesRead = read(m_socketFd, partBuffer, num);
+ if ( bytesRead <= 0 )
+ {
+ if(errno == ECONNRESET || errno == ENOTCONN || errno == ETIMEDOUT)
+ {
+ LOGI("Connection closed : %s", strerror(errno));
+ return -1;
+ }
+ else if (errno != EAGAIN && errno != EWOULDBLOCK){
+ LOGI("read()");
+ return -1;
+ }
+ }
+
+ wholeBuffer.append(partBuffer, bytesRead);
+ bytesToRead -= bytesRead;
+ bytesRead = 0;
+ continue;
+ }
+
+ }
+ memcpy(pBytes, wholeBuffer.c_str(), num);
+
+ return 0;
+}
+
+int
+SocketStream::writeStream(size_t num, const void* pBytes)
+{
+ TryReturn(pBytes != NULL, -1, , "Null pointer to buffer");
+
+ m_bytesWrote += num;
+
+ TryReturn(m_bytesRead <= MAX_BUFFER, -1, , "Too big buffer requested!");
+
+ fd_set wset, allset;
+ int maxFd;
+
+ timespec timeout;
+
+ maxFd = m_socketFd;
+ ++maxFd;
+
+ FD_ZERO(&allset);
+ FD_SET(m_socketFd, &allset);
+
+ int res;
+ int writeRes;
+ int bytesToWrite = num;
+ unsigned int currentOffset = 0;
+
+ while(currentOffset != num)
+ {
+ timeout.tv_sec = WRITE_TIMEOUT_SEC;
+ timeout.tv_nsec = WRITE_TIMEOUT_NSEC;
+ wset = allset;
+
+ if ( (res = pselect(maxFd, NULL, &wset, NULL, &timeout, NULL)) == -1 )
+ {
+ if(errno == EINTR)
+ continue;
+ LOGD("pselect : %s", strerror(errno));
+ return -1;
+ }
+
+ if(FD_ISSET(m_socketFd, &wset))
+ {
+ if ( (writeRes = write(m_socketFd, reinterpret_cast<const char *>(pBytes) + currentOffset, bytesToWrite)) == -1)
+ {
+ if(errno == ECONNRESET || errno == EPIPE)
+ {
+ LOGI("Connection closed : %s", strerror(errno));
+ return -1;
+
+ }
+ else if(errno != EAGAIN && errno != EWOULDBLOCK)
+ {
+ LOGE("write()");
+ return -1;
+ }
+ }
+ currentOffset += writeRes;
+ bytesToWrite -= writeRes;
+ }
+ }
+ return 0;
}
\ No newline at end of file
-/*\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
-#include <Utils.h>\r
-\r
-std::string Utils::toHash(std::string src)\r
-{\r
- return src;\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <Utils.h>
+
+std::string Utils::toHash(std::string src)
+{
+ return src;
}
\ No newline at end of file
{
int ret;
bool privacyPopupRequired = true;
- LOGI("enter");
// Node: <privileges>
xmlNodePtr curPtr = xmlFirstElementChild(xmlDocGetRootElement(docPtr));
- LOGD("Node: %s", curPtr->name);
curPtr = curPtr->xmlChildrenNode;
if (curPtr == NULL)
std::list <std::string> privilegeList;
while (curPtr != NULL)
{
- LOGD("Node: %s", curPtr->name);
-
if (xmlStrcmp(curPtr->name, _NODE_PRIVILEGE) == 0)
{
xmlChar* pPrivilege = xmlNodeListGetString(docPtr, curPtr->xmlChildrenNode, 1);
- SECURE_LOGD(" value= %s", reinterpret_cast<char*>(pPrivilege));\r
+
if (pPrivilege == NULL)
{
LOGE("Failed to get value");
return -EINVAL;
}
- LOGI("leave");
-
return 0;
}
__attribute__ ((visibility("default")))
int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char* packageId)
{
- LOGI("enter");
-
int res = privacy_manager_client_uninstall_privacy_by_server(packageId);
if (res != PRIV_MGR_ERROR_SUCCESS)
{
}
}
- LOGI("leave");
return 0;
}
int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr docPtr, const char* packageId)
{
int res = 0;
+
+ LOGD("Update privacy Info");
res = PKGMGR_PARSER_PLUGIN_UNINSTALL(docPtr, packageId);
if (res != 0)
LOGD("Failed to install privacy Info: %d", res);
}
return res;
-}
\ No newline at end of file
+}
-/*\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 _NOTIFICATION_SERVER_H_\r
-#define _NOTIFICATION_SERVER_H_\r
-\r
-#include <string>\r
-#include <memory>\r
-#include <list>\r
-#include <sqlite3.h>\r
-#include <mutex>\r
-#include <dbus/dbus.h>\r
-\r
-class NotificationServer\r
-{\r
-private:\r
- bool m_initialized;\r
- DBusConnection* m_pDBusConnection;\r
-public:\r
-\r
- NotificationServer(void);\r
- ~NotificationServer(void);\r
- int initialize(void);\r
- int notifySettingChanged(const std::string pkgId, const std::string privacyId);\r
- int notifyPkgRemoved(const std::string pkgId);\r
-};\r
-\r
-\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _NOTIFICATION_SERVER_H_
+#define _NOTIFICATION_SERVER_H_
+
+#include <string>
+#include <memory>
+#include <list>
+#include <sqlite3.h>
+#include <mutex>
+#include <dbus/dbus.h>
+
+class NotificationServer
+{
+private:
+ bool m_initialized;
+ DBusConnection* m_pDBusConnection;
+public:
+
+ NotificationServer(void);
+ ~NotificationServer(void);
+ int initialize(void);
+ int notifySettingChanged(const std::string pkgId, const std::string privacyId);
+ int notifyPkgRemoved(const std::string pkgId);
+};
+
+
#endif // _NOTIFICATION_SERVER_H_
\ No newline at end of file
-/*\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 _PRIVACY_INFO_SERVICE_H_\r
-#define _PRIVACY_INFO_SERVICE_H_\r
-\r
-#include <SocketConnection.h>\r
-#include <SocketService.h>\r
-\r
-class PrivacyInfoService {\r
-private:\r
- inline static std::string getInterfaceName(void)\r
- {\r
- return "PrivacyInfoService";\r
- }\r
-\r
-public:\r
- static void registerCallbacks(SocketService* pSocketService)\r
- {\r
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("addPrivacyInfo"), addPrivacyInfo);\r
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("removePrivacyInfo"), removePrivacyInfo);\r
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("setPrivacySetting"), setPrivacySetting);\r
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("getPrivacyAppPackages"), getPrivacyAppPackages);\r
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("getAppPackagePrivacyInfo"), getAppPackagePrivacyInfo);\r
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("isUserPrompted"), isUserPrompted);\r
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("setUserPrompted"), setUserPrompted);\r
- }\r
-\r
- static void addPrivacyInfo(SocketConnection* pConnector);\r
-\r
- static void removePrivacyInfo(SocketConnection* pConnector);\r
-\r
- static void setPrivacySetting(SocketConnection* pConnector);\r
- \r
- // input message format\r
- // interface_name(str) | method_name(str)\r
- // output message format\r
- // result (int) | list size (int) | serialized package list (using delimeter)\r
- static void getPrivacyAppPackages(SocketConnection* pConnector);\r
-\r
- static void getAppPackagePrivacyInfo(SocketConnection* pConnector);\r
-\r
- static void isUserPrompted(SocketConnection* pConnector);\r
- \r
- static void setUserPrompted(SocketConnection* pConnector);\r
-\r
-};\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _PRIVACY_INFO_SERVICE_H_
+#define _PRIVACY_INFO_SERVICE_H_
+
+#include <SocketConnection.h>
+#include <SocketService.h>
+
+class PrivacyInfoService {
+private:
+ inline static std::string getInterfaceName(void)
+ {
+ return "PrivacyInfoService";
+ }
+
+public:
+ static void registerCallbacks(SocketService* pSocketService)
+ {
+ pSocketService->registerServiceCallback(getInterfaceName(), std::string("addPrivacyInfo"), addPrivacyInfo);
+ pSocketService->registerServiceCallback(getInterfaceName(), std::string("removePrivacyInfo"), removePrivacyInfo);
+ pSocketService->registerServiceCallback(getInterfaceName(), std::string("setPrivacySetting"), setPrivacySetting);
+ pSocketService->registerServiceCallback(getInterfaceName(), std::string("getPrivacyAppPackages"), getPrivacyAppPackages);
+ pSocketService->registerServiceCallback(getInterfaceName(), std::string("getAppPackagePrivacyInfo"), getAppPackagePrivacyInfo);
+ pSocketService->registerServiceCallback(getInterfaceName(), std::string("isUserPrompted"), isUserPrompted);
+ pSocketService->registerServiceCallback(getInterfaceName(), std::string("setUserPrompted"), setUserPrompted);
+ }
+
+ static void addPrivacyInfo(SocketConnection* pConnector);
+
+ static void removePrivacyInfo(SocketConnection* pConnector);
+
+ static void setPrivacySetting(SocketConnection* pConnector);
+
+ // input message format
+ // interface_name(str) | method_name(str)
+ // output message format
+ // result (int) | list size (int) | serialized package list (using delimeter)
+ static void getPrivacyAppPackages(SocketConnection* pConnector);
+
+ static void getAppPackagePrivacyInfo(SocketConnection* pConnector);
+
+ static void isUserPrompted(SocketConnection* pConnector);
+
+ static void setUserPrompted(SocketConnection* pConnector);
+
+};
#endif // _PRIVACY_INFO_SERVICE_H_
\ No newline at end of file
-/*\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 _PRIVACY_MANAGER_DAEMON_H_\r
-#define _PRIVACY_MANAGER_DAEMON_H_\r
-\r
-#include <privacy_manager_client_types.h>\r
-\r
-class SocketService;\r
-\r
-class EXTERN_API PrivacyManagerDaemon\r
-{\r
-private:\r
- static PrivacyManagerDaemon* pInstance;\r
- SocketService* pSocketService;\r
-\r
-private:\r
- PrivacyManagerDaemon(void);\r
- ~PrivacyManagerDaemon(void);\r
-\r
-\r
-public:\r
- static PrivacyManagerDaemon* getInstance(void);\r
- int initialize(void);\r
- int start(void);\r
- int stop(void);\r
- int shutdown(void);\r
-};\r
-\r
-#endif // _PRIVACY_MANAGER_DAEMON_H_
\ No newline at end of file
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _PRIVACY_MANAGER_DAEMON_H_
+#define _PRIVACY_MANAGER_DAEMON_H_
+
+#include <privacy_manager_client_types.h>
+
+class SocketService;
+
+class EXTERN_API PrivacyManagerDaemon
+{
+private:
+ static PrivacyManagerDaemon* pInstance;
+ SocketService* pSocketService;
+
+private:
+ PrivacyManagerDaemon(void);
+ ~PrivacyManagerDaemon(void);
+
+
+public:
+ static PrivacyManagerDaemon* getInstance(void);
+ int initialize(void);
+ int start(void);
+ int stop(void);
+ int shutdown(void);
+};
+
+#endif // _PRIVACY_MANAGER_DAEMON_H_
-/*\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 _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 <NotificationServer.h>\r
-\r
-class NotificationServer;\r
-\r
-class PrivacyManagerServer\r
-{\r
-private:\r
- static std::mutex m_singletonMutex;\r
- static PrivacyManagerServer* m_pInstance;\r
- NotificationServer m_notificationServer;\r
-\r
-private:\r
- void createDB(void);\r
-\r
-public:\r
-\r
- explicit PrivacyManagerServer(void);\r
-\r
- static PrivacyManagerServer* getInstance(void);\r
-\r
- int getPrivacyAppPackages(std::list <std::string>& list);\r
-\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
- int addAppPackagePrivacyInfo(const std::string pkgcId, const std::list < std::string > privilegeList, bool privacyPopupRequired);\r
-\r
- int removeAppPackagePrivacyInfo(const std::string pkgId);\r
-\r
- int isUserPrompted(const std::string pkgId, bool& isPrompted);\r
-\r
- int setUserPrompted(const std::string pkgId, bool prompted);\r
-\r
-};\r
-\r
-\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _PRIVACY_MANAGER_SERVER_H_
+#define _PRIVACY_MANAGER_SERVER_H_
+
+#include <string>
+#include <memory>
+#include <list>
+#include <mutex>
+#include <NotificationServer.h>
+
+class NotificationServer;
+
+class PrivacyManagerServer
+{
+private:
+ static std::mutex m_singletonMutex;
+ static PrivacyManagerServer* m_pInstance;
+ NotificationServer m_notificationServer;
+
+private:
+ void createDB(void);
+
+public:
+
+ explicit PrivacyManagerServer(void);
+
+ static PrivacyManagerServer* getInstance(void);
+
+ int getPrivacyAppPackages(std::list <std::string>& list);
+
+ int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > > & list);
+
+ int setPrivacySetting(const std::string pkgId, const std::string privacyId, bool enabled);
+
+ int addAppPackagePrivacyInfo(const std::string pkgcId, const std::list < std::string > privilegeList, bool privacyPopupRequired);
+
+ int removeAppPackagePrivacyInfo(const std::string pkgId);
+
+ int isUserPrompted(const std::string pkgId, bool& isPrompted);
+
+ int setUserPrompted(const std::string pkgId, bool prompted);
+
+};
+
+
#endif // _PRIVACY_MANAGER_SERVER_H_
\ No newline at end of file
-/*\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 _SOCKET_SERVICE_H_\r
-#define _SOCKET_SERVICE_H_\r
-\r
-#include <string>\r
-#include <mutex>\r
-#include <list>\r
-#include <map>\r
-#include <memory>\r
-#include <pthread.h>\r
-#include <SocketConnection.h>\r
-\r
-typedef void(*socketServiceCallback)(SocketConnection* pConnector);\r
-\r
-class SocketService\r
-{\r
- struct ConnectionInfo{\r
- ConnectionInfo(int fd, void* pData) : connFd(fd), pData(pData) {}\r
- int connFd;\r
- void* pData;\r
- };\r
- class ServiceCallback\r
- {\r
- public:\r
- ServiceCallback(socketServiceCallback callback)\r
- : serviceCallback(callback)\r
- {}\r
- socketServiceCallback serviceCallback;\r
- };\r
- \r
-private:\r
- static const int MAX_LISTEN;\r
- static const int TIMEOUT_SEC;\r
- static const int TIMEOUT_NSEC;\r
- int m_listenFd;\r
- int m_signalToClose;\r
- pthread_t m_mainThread;\r
-\r
- typedef std::shared_ptr<ServiceCallback> ServiceCallbackPtr;\r
- //Map for callback methods, key is a method name and value is a callback to method\r
- typedef std::map<std::string, ServiceCallbackPtr> ServiceMethodCallbackMap;\r
- //Map for interface methods, key is an interface name and value is a map of available methods with callbacks\r
- std::map <std::string, ServiceMethodCallbackMap > m_callbackMap;\r
-\r
- std::list < int > m_clientSocketList;\r
- std::mutex m_clientSocketListMutex;\r
-\r
-private:\r
- static void* serverThread(void* );\r
- static void* connectionThread(void* pData);\r
- int connectionService(int fd);\r
- int mainloop(void);\r
- void closeConnections(void);\r
-\r
- void addClientSocket(int clientSocket);\r
- void removeClientSocket(int clientSocket);\r
- bool popClientSocket(int* pClientSocket);\r
-\r
-public:\r
- SocketService(void);\r
- ~SocketService(void);\r
- int initialize(void);\r
- int registerServiceCallback(const std::string &interfaceName, const std::string &methodName, socketServiceCallback callbackMethod);\r
- int start(void);\r
- int stop(void);\r
- int shutdown(void);\r
-};\r
-\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _SOCKET_SERVICE_H_
+#define _SOCKET_SERVICE_H_
+
+#include <string>
+#include <mutex>
+#include <list>
+#include <map>
+#include <memory>
+#include <pthread.h>
+#include <SocketConnection.h>
+
+typedef void(*socketServiceCallback)(SocketConnection* pConnector);
+
+class SocketService
+{
+ struct ConnectionInfo{
+ ConnectionInfo(int fd, void* pData) : connFd(fd), pData(pData) {}
+ int connFd;
+ void* pData;
+ };
+ class ServiceCallback
+ {
+ public:
+ ServiceCallback(socketServiceCallback callback)
+ : serviceCallback(callback)
+ {}
+ socketServiceCallback serviceCallback;
+ };
+
+private:
+ static const int MAX_LISTEN;
+ static const int TIMEOUT_SEC;
+ static const int TIMEOUT_NSEC;
+ int m_listenFd;
+ int m_signalToClose;
+ pthread_t m_mainThread;
+
+ typedef std::shared_ptr<ServiceCallback> ServiceCallbackPtr;
+ //Map for callback methods, key is a method name and value is a callback to method
+ typedef std::map<std::string, ServiceCallbackPtr> ServiceMethodCallbackMap;
+ //Map for interface methods, key is an interface name and value is a map of available methods with callbacks
+ std::map <std::string, ServiceMethodCallbackMap > m_callbackMap;
+
+ std::list < int > m_clientSocketList;
+ std::mutex m_clientSocketListMutex;
+
+private:
+ static void* serverThread(void* );
+ static void* connectionThread(void* pData);
+ int connectionService(int fd);
+ int mainloop(void);
+ void closeConnections(void);
+
+ void addClientSocket(int clientSocket);
+ void removeClientSocket(int clientSocket);
+ bool popClientSocket(int* pClientSocket);
+
+public:
+ SocketService(void);
+ ~SocketService(void);
+ int initialize(void);
+ int registerServiceCallback(const std::string &interfaceName, const std::string &methodName, socketServiceCallback callbackMethod);
+ int start(void);
+ int stop(void);
+ int shutdown(void);
+};
+
#endif //_SOCKET_SERVICE_H_
\ No newline at end of file
-/*\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 __PRIVACY_MANAGER_DAEMON_H__\r
-#define __PRIVACY_MANAGER_DAEMON_H__\r
-\r
-#include <privacy_manager_client_types.h>\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-int EXTERN_API privacy_manager_daemon_initialize(void);\r
-int EXTERN_API privacy_manager_daemon_start(void);\r
-int EXTERN_API privacy_manager_daemon_stop(void);\r
-int EXTERN_API privacy_manager_daemon_shutdown(void);\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-\r
-#endif //__PRIVACY_MANAGER_DAEMON_H__\r
-\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PRIVACY_MANAGER_DAEMON_H__
+#define __PRIVACY_MANAGER_DAEMON_H__
+
+#include <privacy_manager_client_types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int EXTERN_API privacy_manager_daemon_initialize(void);
+int EXTERN_API privacy_manager_daemon_start(void);
+int EXTERN_API privacy_manager_daemon_stop(void);
+int EXTERN_API privacy_manager_daemon_shutdown(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif //__PRIVACY_MANAGER_DAEMON_H__
+
-/*\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
-\r
-#include <NotificationServer.h>\r
-#include <dbus/dbus.h>\r
-#include <dbus/dbus-glib-lowlevel.h>\r
-#include <PrivacyManagerTypes.h>\r
-#include <Utils.h>\r
-\r
-auto DBusConnectionDeleter = [&](DBusConnection* pPtr) { dbus_connection_close(pPtr); pPtr = NULL;};\r
-const int MAX_LOCAL_BUF_SIZE = 128;\r
-\r
-NotificationServer::NotificationServer(void)\r
- : m_initialized(false)\r
- , m_pDBusConnection(NULL)\r
-{\r
-\r
-}\r
-\r
-NotificationServer::~NotificationServer(void)\r
-{\r
- if (m_pDBusConnection)\r
- {\r
- dbus_connection_close(m_pDBusConnection);\r
- m_pDBusConnection = NULL;\r
- }\r
-}\r
-\r
-int\r
-NotificationServer::initialize(void)\r
-{\r
- if (m_initialized)\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- \r
- DBusError error;\r
- dbus_error_init(&error);\r
-\r
- m_pDBusConnection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);\r
- TryReturn(m_pDBusConnection != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_get_private : %s", error.message);\r
-\r
- dbus_connection_setup_with_g_main(m_pDBusConnection, NULL);\r
- std::unique_ptr < char[] > pRule(new char[MAX_LOCAL_BUF_SIZE]);\r
-\r
- snprintf(pRule.get(), MAX_LOCAL_BUF_SIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str());\r
-\r
- dbus_bus_add_match(m_pDBusConnection, pRule.get(), &error);\r
- TryReturn(!dbus_error_is_set(&error), PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_add_match : %s", error.message);\r
-\r
- m_initialized = true;\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int\r
-NotificationServer::notifySettingChanged(const std::string pkgId, const std::string privacyId)\r
-{\r
- LOGI("enter");\r
-\r
- if (!m_initialized)\r
- return PRIV_MGR_ERROR_INVALID_STATE;\r
-\r
- char* pPkgId = const_cast <char*> (pkgId.c_str());\r
- char* pPrivacyId = const_cast <char*> (privacyId.c_str());\r
-\r
- DBusMessage* pMessage = dbus_message_new_signal(DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_SETTING_CHANGED.c_str());\r
- TryReturn(pMessage != NULL, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_new_signal");\r
-\r
- dbus_bool_t r;\r
- r = dbus_message_append_args(pMessage,\r
- DBUS_TYPE_STRING, &pPkgId,\r
- DBUS_TYPE_STRING, &pPrivacyId,\r
- DBUS_TYPE_INVALID);\r
- TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_append_args");\r
-\r
- r = dbus_connection_send(m_pDBusConnection, pMessage, NULL);\r
- TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, dbus_message_unref(pMessage);, "dbus_connection_send");\r
-\r
- dbus_connection_flush(m_pDBusConnection);\r
- dbus_message_unref(pMessage);\r
-\r
- LOGI("leave");\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int\r
-NotificationServer::notifyPkgRemoved(const std::string pkgId)\r
-{\r
- LOGI("enter");\r
-\r
- if (!m_initialized)\r
- return PRIV_MGR_ERROR_INVALID_STATE;\r
-\r
- char* pPkgId = const_cast <char*> (pkgId.c_str());\r
-\r
- DBusMessage* pMessage = dbus_message_new_signal(DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_PKG_REMOVED.c_str());\r
- TryReturn(pMessage != NULL, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_new_signal");\r
-\r
- dbus_bool_t r;\r
- r = dbus_message_append_args(pMessage,\r
- DBUS_TYPE_STRING, &pPkgId,\r
- DBUS_TYPE_INVALID);\r
- TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_append_args");\r
-\r
- r = dbus_connection_send(m_pDBusConnection, pMessage, NULL);\r
- TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, dbus_message_unref(pMessage);, "dbus_connection_send");\r
-\r
- dbus_connection_flush(m_pDBusConnection);\r
- dbus_message_unref(pMessage);\r
-\r
- LOGI("leave");\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}
\ No newline at end of file
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <NotificationServer.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <PrivacyManagerTypes.h>
+#include <Utils.h>
+
+auto DBusConnectionDeleter = [&](DBusConnection* pPtr) { dbus_connection_close(pPtr); pPtr = NULL;};
+const int MAX_LOCAL_BUF_SIZE = 128;
+
+NotificationServer::NotificationServer(void)
+ : m_initialized(false)
+ , m_pDBusConnection(NULL)
+{
+
+}
+
+NotificationServer::~NotificationServer(void)
+{
+ if (m_pDBusConnection)
+ {
+ dbus_connection_close(m_pDBusConnection);
+ m_pDBusConnection = NULL;
+ }
+}
+
+int
+NotificationServer::initialize(void)
+{
+ if (m_initialized)
+ return PRIV_MGR_ERROR_SUCCESS;
+
+ DBusError error;
+ dbus_error_init(&error);
+
+ m_pDBusConnection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
+ TryReturn(m_pDBusConnection != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_get_private : %s", error.message);
+
+ dbus_connection_setup_with_g_main(m_pDBusConnection, NULL);
+ std::unique_ptr < char[] > pRule(new char[MAX_LOCAL_BUF_SIZE]);
+
+ snprintf(pRule.get(), MAX_LOCAL_BUF_SIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str());
+
+ dbus_bus_add_match(m_pDBusConnection, pRule.get(), &error);
+ TryReturn(!dbus_error_is_set(&error), PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_add_match : %s", error.message);
+
+ m_initialized = true;
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int
+NotificationServer::notifySettingChanged(const std::string pkgId, const std::string privacyId)
+{
+ if (!m_initialized)
+ return PRIV_MGR_ERROR_INVALID_STATE;
+
+ char* pPkgId = const_cast <char*> (pkgId.c_str());
+ char* pPrivacyId = const_cast <char*> (privacyId.c_str());
+
+ DBusMessage* pMessage = dbus_message_new_signal(DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_SETTING_CHANGED.c_str());
+ TryReturn(pMessage != NULL, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_new_signal");
+
+ dbus_bool_t r;
+ r = dbus_message_append_args(pMessage,
+ DBUS_TYPE_STRING, &pPkgId,
+ DBUS_TYPE_STRING, &pPrivacyId,
+ DBUS_TYPE_INVALID);
+ TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_append_args");
+
+ r = dbus_connection_send(m_pDBusConnection, pMessage, NULL);
+ TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, dbus_message_unref(pMessage);, "dbus_connection_send");
+
+ dbus_connection_flush(m_pDBusConnection);
+ dbus_message_unref(pMessage);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int
+NotificationServer::notifyPkgRemoved(const std::string pkgId)
+{
+ if (!m_initialized)
+ return PRIV_MGR_ERROR_INVALID_STATE;
+
+ char* pPkgId = const_cast <char*> (pkgId.c_str());
+
+ DBusMessage* pMessage = dbus_message_new_signal(DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_PKG_REMOVED.c_str());
+ TryReturn(pMessage != NULL, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_new_signal");
+
+ dbus_bool_t r;
+ r = dbus_message_append_args(pMessage,
+ DBUS_TYPE_STRING, &pPkgId,
+ DBUS_TYPE_INVALID);
+ TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_append_args");
+
+ r = dbus_connection_send(m_pDBusConnection, pMessage, NULL);
+ TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, dbus_message_unref(pMessage);, "dbus_connection_send");
+
+ dbus_connection_flush(m_pDBusConnection);
+ dbus_message_unref(pMessage);
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
-/*\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
-#include <string>\r
-#include <PrivacyManagerDaemon.h>\r
-#include <PrivacyInfoService.h>\r
-#include <PrivacyManagerServer.h>\r
-#include <SocketService.h>\r
-\r
-PrivacyManagerDaemon* PrivacyManagerDaemon::pInstance = NULL;\r
-\r
-PrivacyManagerDaemon::PrivacyManagerDaemon(void)\r
- : pSocketService(NULL)\r
-{\r
-\r
-}\r
-\r
-PrivacyManagerDaemon::~PrivacyManagerDaemon(void)\r
-{\r
-\r
-}\r
-\r
-PrivacyManagerDaemon*\r
-PrivacyManagerDaemon::getInstance(void)\r
-{\r
- if (pInstance == NULL)\r
- pInstance = new PrivacyManagerDaemon();\r
- PrivacyManagerServer::getInstance();\r
- return pInstance;\r
-}\r
-\r
-int\r
-PrivacyManagerDaemon::initialize(void)\r
-{\r
- if (pSocketService == NULL)\r
- pSocketService = new SocketService();\r
-\r
- pSocketService->initialize();\r
-\r
- PrivacyInfoService::registerCallbacks(pSocketService);\r
-\r
- return 0;\r
-}\r
-\r
-int\r
-PrivacyManagerDaemon::start(void)\r
-{\r
- if (pSocketService == NULL)\r
- return -1;\r
- return pSocketService->start();\r
-\r
- return 0;\r
-}\r
-\r
-int\r
-PrivacyManagerDaemon::stop(void)\r
-{\r
- pSocketService->stop();\r
- return 0;\r
-}\r
-\r
-int\r
-PrivacyManagerDaemon::shutdown(void)\r
-{\r
- pSocketService->shutdown();\r
- return 0;\r
-}\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string>
+#include <PrivacyManagerDaemon.h>
+#include <PrivacyInfoService.h>
+#include <PrivacyManagerServer.h>
+#include <SocketService.h>
+
+PrivacyManagerDaemon* PrivacyManagerDaemon::pInstance = NULL;
+
+PrivacyManagerDaemon::PrivacyManagerDaemon(void)
+ : pSocketService(NULL)
+{
+
+}
+
+PrivacyManagerDaemon::~PrivacyManagerDaemon(void)
+{
+
+}
+
+PrivacyManagerDaemon*
+PrivacyManagerDaemon::getInstance(void)
+{
+ if (pInstance == NULL)
+ pInstance = new PrivacyManagerDaemon();
+ PrivacyManagerServer::getInstance();
+ return pInstance;
+}
+
+int
+PrivacyManagerDaemon::initialize(void)
+{
+ if (pSocketService == NULL)
+ pSocketService = new SocketService();
+
+ pSocketService->initialize();
+
+ PrivacyInfoService::registerCallbacks(pSocketService);
+
+ return 0;
+}
+
+int
+PrivacyManagerDaemon::start(void)
+{
+ if (pSocketService == NULL)
+ return -1;
+ return pSocketService->start();
+
+ return 0;
+}
+
+int
+PrivacyManagerDaemon::stop(void)
+{
+ pSocketService->stop();
+ return 0;
+}
+
+int
+PrivacyManagerDaemon::shutdown(void)
+{
+ pSocketService->shutdown();
+ return 0;
+}
-/*\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
-#include <sstream>\r
-#include <dlog.h>\r
-#include <Utils.h>\r
-#include <PrivacyManagerServer.h>\r
-#include <PrivacyManagerTypes.h>\r
-#include <PrivacyDb.h>\r
-\r
-std::mutex PrivacyManagerServer::m_singletonMutex;\r
-PrivacyManagerServer* PrivacyManagerServer::m_pInstance = NULL;\r
-\r
-void\r
-PrivacyManagerServer::createDB(void)\r
-{\r
-\r
-}\r
-\r
-int\r
-PrivacyManagerServer::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool enabled)\r
-{\r
- int res = PrivacyDb::getInstance()->setPrivacySetting(pkgId, privacyId, enabled);\r
- TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "privacyDb::setPrivacySetting : %d", res);\r
-\r
- res = m_notificationServer.notifySettingChanged(pkgId, privacyId);\r
- TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "NotificationServer::notifySettingChanged : %d", res);\r
-\r
- return res;\r
-}\r
-\r
-int\r
-PrivacyManagerServer::getPrivacyAppPackages(std::list <std::string>& list)\r
-{\r
- return PrivacyDb::getInstance()->getPrivacyAppPackages(list);\r
-}\r
-\r
-int\r
-PrivacyManagerServer::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > >& privacyInfoList)\r
-{\r
- return PrivacyDb::getInstance()->getAppPackagePrivacyInfo(pkgId, privacyInfoList);\r
-}\r
-\r
-\r
-int\r
-PrivacyManagerServer::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string > privilegeList, bool privacyPopupRequired)\r
-{\r
- return PrivacyDb::getInstance()->addAppPackagePrivacyInfo(pkgId, privilegeList, privacyPopupRequired);\r
-}\r
-\r
-int\r
-PrivacyManagerServer::removeAppPackagePrivacyInfo(const std::string pkgId)\r
-{\r
- int res = PrivacyDb::getInstance()->removeAppPackagePrivacyInfo(pkgId);\r
- TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "privacyDb::removeAppPackagePrivacyInfo : %d", res);\r
-\r
- res = m_notificationServer.notifyPkgRemoved(pkgId);\r
- TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "NotificationServer::notifyPkgRemoved : %d", res);\r
-\r
- return res;\r
-}\r
-\r
-int\r
-PrivacyManagerServer::isUserPrompted(const std::string pkgId, bool& isPrompted)\r
-{\r
- return PrivacyDb::getInstance()->isUserPrompted(pkgId, isPrompted);\r
-}\r
-\r
-int\r
-PrivacyManagerServer::setUserPrompted(const std::string pkgId, bool prompted)\r
-{\r
- return PrivacyDb::getInstance()->setUserPrompted(pkgId, prompted);\r
-}\r
-\r
-PrivacyManagerServer::PrivacyManagerServer(void)\r
-{\r
-\r
-}\r
-\r
-PrivacyManagerServer*\r
-PrivacyManagerServer::getInstance(void)\r
-{\r
- LOGI("enter");\r
- std::lock_guard < std::mutex > guard(m_singletonMutex);\r
-\r
- if (m_pInstance == NULL)\r
- { \r
- m_pInstance = new PrivacyManagerServer();\r
- \r
- m_pInstance->m_notificationServer.initialize();\r
- }\r
- LOGI("leave");\r
- return m_pInstance;\r
-}
\ No newline at end of file
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sstream>
+#include <dlog.h>
+#include <Utils.h>
+#include <PrivacyManagerServer.h>
+#include <PrivacyManagerTypes.h>
+#include <PrivacyDb.h>
+
+std::mutex PrivacyManagerServer::m_singletonMutex;
+PrivacyManagerServer* PrivacyManagerServer::m_pInstance = NULL;
+
+void
+PrivacyManagerServer::createDB(void)
+{
+
+}
+
+int
+PrivacyManagerServer::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool enabled)
+{
+ int res = PrivacyDb::getInstance()->setPrivacySetting(pkgId, privacyId, enabled);
+ TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "privacyDb::setPrivacySetting : %d", res);
+
+ res = m_notificationServer.notifySettingChanged(pkgId, privacyId);
+ TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "NotificationServer::notifySettingChanged : %d", res);
+
+ return res;
+}
+
+int
+PrivacyManagerServer::getPrivacyAppPackages(std::list <std::string>& list)
+{
+ return PrivacyDb::getInstance()->getPrivacyAppPackages(list);
+}
+
+int
+PrivacyManagerServer::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > >& privacyInfoList)
+{
+ return PrivacyDb::getInstance()->getAppPackagePrivacyInfo(pkgId, privacyInfoList);
+}
+
+
+int
+PrivacyManagerServer::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string > privilegeList, bool privacyPopupRequired)
+{
+ return PrivacyDb::getInstance()->addAppPackagePrivacyInfo(pkgId, privilegeList, privacyPopupRequired);
+}
+
+int
+PrivacyManagerServer::removeAppPackagePrivacyInfo(const std::string pkgId)
+{
+ int res = PrivacyDb::getInstance()->removeAppPackagePrivacyInfo(pkgId);
+ TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "privacyDb::removeAppPackagePrivacyInfo : %d", res);
+
+ res = m_notificationServer.notifyPkgRemoved(pkgId);
+ TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "NotificationServer::notifyPkgRemoved : %d", res);
+
+ return res;
+}
+
+int
+PrivacyManagerServer::isUserPrompted(const std::string pkgId, bool& isPrompted)
+{
+ return PrivacyDb::getInstance()->isUserPrompted(pkgId, isPrompted);
+}
+
+int
+PrivacyManagerServer::setUserPrompted(const std::string pkgId, bool prompted)
+{
+ return PrivacyDb::getInstance()->setUserPrompted(pkgId, prompted);
+}
+
+PrivacyManagerServer::PrivacyManagerServer(void)
+{
+
+}
+
+PrivacyManagerServer*
+PrivacyManagerServer::getInstance(void)
+{
+ std::lock_guard < std::mutex > guard(m_singletonMutex);
+
+ if (m_pInstance == NULL)
+ {
+ m_pInstance = new PrivacyManagerServer();
+
+ m_pInstance->m_notificationServer.initialize();
+ }
+
+ return m_pInstance;
+}
-/*\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
-#include <errno.h>\r
-#include <sys/types.h>\r
-#include <sys/socket.h>\r
-#include <sys/un.h>\r
-#include <sys/signalfd.h>\r
-#include <sys/select.h>\r
-#include <sys/stat.h>\r
-#include <signal.h>\r
-#include <unistd.h>\r
-#include <fcntl.h>\r
-#include <memory>\r
-#include <dlog.h>\r
-#include <PrivacyManagerTypes.h>\r
-#include <Utils.h>\r
-#include "SocketService.h"\r
-#include "SocketConnection.h"\r
-\r
-const int SocketService::MAX_LISTEN = 5;\r
-\r
-SocketService::SocketService(void)\r
- : m_listenFd(-1)\r
- , m_signalToClose(-1)\r
- , m_mainThread(-1)\r
-{\r
-\r
-}\r
-\r
-SocketService::~SocketService(void)\r
-{\r
-\r
-}\r
-\r
-int\r
-SocketService::initialize(void)\r
-{\r
- LOGI("SocketService initializing");\r
-\r
- m_listenFd = socket(AF_UNIX, SOCK_STREAM, 0);\r
- TryReturn( m_listenFd != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "socket : %s", strerror(errno));\r
-\r
- int flags = -1;\r
- int res;\r
- if ( (flags = fcntl(m_listenFd, F_GETFL, 0)) == -1)\r
- flags = 0;\r
- res = fcntl(m_listenFd, F_SETFL, flags | O_NONBLOCK);\r
- TryReturn( res != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "fcntl : %s", strerror(errno));\r
-\r
- sockaddr_un server_address;\r
- bzero(&server_address, sizeof(server_address));\r
- server_address.sun_family = AF_UNIX;\r
- strcpy(server_address.sun_path, SERVER_ADDRESS.c_str());\r
- unlink(server_address.sun_path);\r
-\r
- mode_t socket_umask, original_umask;\r
- socket_umask = 0;\r
- original_umask = umask(socket_umask);\r
-\r
- res = bind(m_listenFd, (struct sockaddr*)&server_address, SUN_LEN(&server_address));\r
- TryReturn( res != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "bind : %s", strerror(errno));\r
-\r
- umask(original_umask);\r
-\r
- LOGI("SocketService initialized");\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int\r
-SocketService::start(void)\r
-{\r
- LOGI("SocketService starting");\r
-\r
- sigset_t sigset;\r
- sigemptyset(&sigset);\r
-// if ( sigaddset(&sigset, m_signalToClose) == -1 ) \r
-// {\r
-// LOGE("Failed to sigaddset : %s", strerror(errno));\r
-// return -1;\r
-// }\r
-\r
- int res = 0;\r
- res = pthread_sigmask(SIG_BLOCK, &sigset, NULL);\r
- TryReturn( res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, , "pthread_sigmask : %s", strerror(errno));\r
-\r
- pthread_t mainThread;\r
- res = pthread_create(&mainThread, NULL, &serverThread, this);\r
- TryReturn( res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, errno = res, "pthread_create : %s", strerror(res));\r
-\r
- m_mainThread = mainThread;\r
-\r
- LOGI("SocketService started");\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-void*\r
-SocketService::serverThread(void* pData)\r
-{\r
- pthread_detach(pthread_self());\r
- SocketService &t = *static_cast< SocketService* > (pData);\r
- LOGI("Running main thread");\r
- int ret = t.mainloop();\r
- if (ret < 0)\r
- {\r
- return (void*) 1;\r
- }\r
- return (void*) 0;\r
-}\r
-\r
-int\r
-SocketService::mainloop(void)\r
-{\r
- if( listen(m_listenFd, MAX_LISTEN) == -1 ){\r
- LOGE("listen : %s", strerror(errno));\r
- return PRIV_MGR_ERROR_IPC_ERROR;\r
- }\r
-\r
- //Settings to catch closing signal in select\r
- int signal_fd;\r
- sigset_t sigset;\r
- int res;\r
- res = sigemptyset(&sigset);\r
- TryReturn( res != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "sigemptyset : %s", strerror(errno));\r
-\r
-// if( sigaddset(&sigset, m_signalToClose) == -1) {\r
-// LOGE("sigaddset : %s", strerror(errno));\r
-// return -1;\r
-// }\r
- signal_fd = signalfd(-1, &sigset, 0);\r
- TryReturn( signal_fd >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, , "signalfd : %s", strerror(errno));\r
-\r
- //Setting descriptors for pselect\r
- fd_set allset, rset;\r
- int maxfd;\r
- FD_ZERO(&allset);\r
- FD_SET(m_listenFd, &allset);\r
- FD_SET(signal_fd, &allset);\r
- maxfd = (m_listenFd > signal_fd) ? (m_listenFd) : (signal_fd);\r
- ++maxfd;\r
- //this will block SIGPIPE for this thread and every thread created in it\r
- //reason : from here on we don't won't to receive SIGPIPE on writing to closed socket\r
- //instead of signal we want to receive error from write - hence blocking SIGPIPE\r
- sigset_t set;\r
- sigemptyset(&set);\r
- sigaddset(&set, SIGPIPE);\r
- pthread_sigmask(SIG_BLOCK, &set, NULL);\r
-\r
- while(1)\r
- {\r
- rset = allset;\r
- if(pselect(maxfd, &rset, NULL, NULL, NULL, NULL) == -1)\r
- {\r
- closeConnections();\r
- LOGE("pselect()");\r
- return PRIV_MGR_ERROR_SYSTEM_ERROR;\r
- }\r
-\r
- if(FD_ISSET(signal_fd, &rset))\r
- {\r
- LOGI("Got signal to close");\r
- signalfd_siginfo siginfo;\r
- ssize_t res;\r
- res = read(signal_fd, &siginfo, sizeof(siginfo));\r
- TryReturn( res > 0, PRIV_MGR_ERROR_IPC_ERROR, closeConnections();, "read : %s", strerror(errno));\r
- TryReturn( (size_t)res == sizeof(siginfo), PRIV_MGR_ERROR_IPC_ERROR, closeConnections();, "couldn't read whole siginfo");\r
-\r
- if((int)siginfo.ssi_signo == m_signalToClose)\r
- {\r
- LOGI("Server thread got signal to close");\r
- closeConnections();\r
- return PRIV_MGR_ERROR_SUCCESS;\r
- } \r
- else \r
- {\r
- LOGI("Got not handled signal");\r
- }\r
- }\r
- if(FD_ISSET(m_listenFd, &rset))\r
- {\r
- int clientFd;\r
- clientFd = accept(m_listenFd, NULL, NULL);\r
- TryReturn( clientFd != -1, PRIV_MGR_ERROR_IPC_ERROR, closeConnections();, "accept : %s", strerror(errno));\r
-\r
- LOGI("Got incoming connection");\r
- ConnectionInfo * connection = new ConnectionInfo(clientFd, (void *)this);\r
- int res;\r
- pthread_t client_thread;\r
- if((res = pthread_create(&client_thread, NULL, &connectionThread, connection)) < 0)\r
- {\r
- delete connection;\r
- errno = res;\r
- closeConnections();\r
- LOGE("pthread_create()");\r
- return PRIV_MGR_ERROR_SYSTEM_ERROR;\r
- }\r
- addClientSocket(clientFd);\r
- }\r
- } \r
-}\r
-\r
-void*\r
-SocketService::connectionThread(void* pData)\r
-{\r
- pthread_detach(pthread_self());\r
- std::unique_ptr<ConnectionInfo> connectionInfo (static_cast<ConnectionInfo *>(pData));\r
- SocketService &t = *static_cast<SocketService *>(connectionInfo->pData);\r
- LOGI("Starting connection thread");\r
- int ret = t.connectionService(connectionInfo->connFd);\r
- if (ret < 0)\r
- {\r
- LOGE("Connection thread error");\r
- t.removeClientSocket(connectionInfo->connFd);\r
- close(connectionInfo->connFd);\r
- return (void*)1;\r
- }\r
- LOGI("Client serviced");\r
- return (void*)0;\r
-}\r
-\r
-int\r
-SocketService::connectionService(int fd)\r
-{\r
-\r
- SocketConnection connector = SocketConnection(fd);\r
- std::string interfaceName, methodName;\r
-\r
- int res = connector.read(&interfaceName, &methodName);\r
- if (res != PRIV_MGR_ERROR_SUCCESS)\r
- {\r
- LOGE("read : %d", res);\r
- return res;\r
- }\r
-\r
- LOGD("Got interface : %s", interfaceName.c_str());\r
- LOGD("Got method : %s", methodName.c_str());\r
-\r
- if( m_callbackMap.find(interfaceName) == m_callbackMap.end())\r
- {\r
- LOGE("Unknown interface : %s", interfaceName.c_str());\r
- return PRIV_MGR_ERROR_NO_DATA;\r
- }\r
-\r
- if(m_callbackMap[interfaceName].find(methodName) == m_callbackMap[interfaceName].end())\r
- {\r
- LOGE("Unknown method : %s", methodName.c_str());\r
- return PRIV_MGR_ERROR_NO_DATA;\r
- }\r
-\r
-// if(m_callbackMap[interfaceName][methodName]->securityCallback != NULL){\r
-// if(!m_callbackMap[interfaceName][methodName]->securityCallback(fd)){\r
-// LOGE("Security check returned false");\r
-// return -1;\r
-// }\r
-// }\r
-\r
- LOGI("Calling service");\r
- m_callbackMap[interfaceName][methodName]->serviceCallback(&connector);\r
- \r
- LOGI("Removing client");\r
- removeClientSocket(fd);\r
- close(fd);\r
-\r
- LOGI("Call served");\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int\r
-SocketService::stop(void)\r
-{\r
- LOGI("Stopping");\r
- if(close(m_listenFd) == -1)\r
- if(errno != ENOTCONN)\r
- {\r
- LOGE("close() : %s", strerror(errno));\r
- return PRIV_MGR_ERROR_IPC_ERROR;\r
- }\r
-\r
- int returned_value;\r
- if((returned_value = pthread_kill(m_mainThread, m_signalToClose)) < 0)\r
- {\r
- errno = returned_value;\r
- LOGE("pthread_kill() : %s", strerror(errno));\r
- return PRIV_MGR_ERROR_IPC_ERROR;\r
- }\r
- pthread_join(m_mainThread, NULL);\r
-\r
- LOGI("Stopped");\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int\r
-SocketService::shutdown(void)\r
-{\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-int\r
-SocketService::registerServiceCallback(const std::string &interfaceName, const std::string &methodName, socketServiceCallback callbackMethod)\r
-{\r
- if(NULL == callbackMethod)\r
- {\r
- LOGE("Null callback");\r
- return PRIV_MGR_ERROR_INVALID_PARAMETER;\r
- }\r
- if(interfaceName.empty() || methodName.empty())\r
- {\r
- LOGE("Interface and method name cannot be empty");\r
- return PRIV_MGR_ERROR_INVALID_PARAMETER;\r
- }\r
-\r
- auto serviceCallbackPtr = std::make_shared<ServiceCallback>(ServiceCallback(callbackMethod));\r
- m_callbackMap[interfaceName][methodName] = serviceCallbackPtr;\r
-\r
- return PRIV_MGR_ERROR_SUCCESS;\r
-}\r
-\r
-void\r
-SocketService::addClientSocket(int clientSocket)\r
-{\r
- std::lock_guard<std::mutex> guard(m_clientSocketListMutex);\r
- m_clientSocketList.push_back(clientSocket);\r
-}\r
-\r
-void\r
-SocketService::removeClientSocket(int clientSocket)\r
-{\r
- std::lock_guard<std::mutex> guard(m_clientSocketListMutex);\r
- m_clientSocketList.remove(clientSocket);\r
-}\r
-\r
-bool\r
-SocketService::popClientSocket(int * pClientSocket)\r
-{\r
- std::lock_guard<std::mutex> guard(m_clientSocketListMutex);\r
- if(m_clientSocketList.empty())\r
- return false;\r
- *pClientSocket = m_clientSocketList.front();\r
- m_clientSocketList.pop_front();\r
- return true;\r
-}\r
-\r
-\r
-void\r
-SocketService::closeConnections(void)\r
-{\r
- int clientSocket;\r
- LOGI("Closing client sockets");\r
- while(popClientSocket(&clientSocket))\r
- {\r
- if(close(clientSocket) == -1)\r
- {\r
- LOGE("close() : %s", strerror(errno));\r
- }\r
- }\r
-\r
- LOGI("Connections closed");\r
-}\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/signalfd.h>
+#include <sys/select.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <memory>
+#include <dlog.h>
+#include <PrivacyManagerTypes.h>
+#include <Utils.h>
+#include "SocketService.h"
+#include "SocketConnection.h"
+
+const int SocketService::MAX_LISTEN = 5;
+
+SocketService::SocketService(void)
+ : m_listenFd(-1)
+ , m_signalToClose(-1)
+ , m_mainThread(-1)
+{
+
+}
+
+SocketService::~SocketService(void)
+{
+
+}
+
+int
+SocketService::initialize(void)
+{
+ LOGI("SocketService initializing");
+
+ m_listenFd = socket(AF_UNIX, SOCK_STREAM, 0);
+ TryReturn( m_listenFd != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "socket : %s", strerror(errno));
+
+ int flags = -1;
+ int res;
+ if ( (flags = fcntl(m_listenFd, F_GETFL, 0)) == -1)
+ flags = 0;
+ res = fcntl(m_listenFd, F_SETFL, flags | O_NONBLOCK);
+ TryReturn( res != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "fcntl : %s", strerror(errno));
+
+ sockaddr_un server_address;
+ bzero(&server_address, sizeof(server_address));
+ server_address.sun_family = AF_UNIX;
+ strcpy(server_address.sun_path, SERVER_ADDRESS.c_str());
+ unlink(server_address.sun_path);
+
+ mode_t socket_umask, original_umask;
+ socket_umask = 0;
+ original_umask = umask(socket_umask);
+
+ res = bind(m_listenFd, (struct sockaddr*)&server_address, SUN_LEN(&server_address));
+ TryReturn( res != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "bind : %s", strerror(errno));
+
+ umask(original_umask);
+
+ LOGI("SocketService initialized");
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int
+SocketService::start(void)
+{
+ LOGI("SocketService starting");
+
+ sigset_t sigset;
+ sigemptyset(&sigset);
+// if ( sigaddset(&sigset, m_signalToClose) == -1 )
+// {
+// LOGE("Failed to sigaddset : %s", strerror(errno));
+// return -1;
+// }
+
+ int res = 0;
+ res = pthread_sigmask(SIG_BLOCK, &sigset, NULL);
+ TryReturn( res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, , "pthread_sigmask : %s", strerror(errno));
+
+ pthread_t mainThread;
+ res = pthread_create(&mainThread, NULL, &serverThread, this);
+ TryReturn( res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, errno = res, "pthread_create : %s", strerror(res));
+
+ m_mainThread = mainThread;
+
+ LOGI("SocketService started");
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+void*
+SocketService::serverThread(void* pData)
+{
+ pthread_detach(pthread_self());
+ SocketService &t = *static_cast< SocketService* > (pData);
+ LOGI("Running main thread");
+ int ret = t.mainloop();
+ if (ret < 0)
+ {
+ return (void*) 1;
+ }
+ return (void*) 0;
+}
+
+int
+SocketService::mainloop(void)
+{
+ if( listen(m_listenFd, MAX_LISTEN) == -1 ){
+ LOGE("listen : %s", strerror(errno));
+ return PRIV_MGR_ERROR_IPC_ERROR;
+ }
+
+ //Settings to catch closing signal in select
+ int signal_fd;
+ sigset_t sigset;
+ int res;
+ res = sigemptyset(&sigset);
+ TryReturn( res != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "sigemptyset : %s", strerror(errno));
+
+// if( sigaddset(&sigset, m_signalToClose) == -1) {
+// LOGE("sigaddset : %s", strerror(errno));
+// return -1;
+// }
+ signal_fd = signalfd(-1, &sigset, 0);
+ TryReturn( signal_fd >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, , "signalfd : %s", strerror(errno));
+
+ //Setting descriptors for pselect
+ fd_set allset, rset;
+ int maxfd;
+ FD_ZERO(&allset);
+ FD_SET(m_listenFd, &allset);
+ FD_SET(signal_fd, &allset);
+ maxfd = (m_listenFd > signal_fd) ? (m_listenFd) : (signal_fd);
+ ++maxfd;
+ //this will block SIGPIPE for this thread and every thread created in it
+ //reason : from here on we don't won't to receive SIGPIPE on writing to closed socket
+ //instead of signal we want to receive error from write - hence blocking SIGPIPE
+ sigset_t set;
+ sigemptyset(&set);
+ sigaddset(&set, SIGPIPE);
+ pthread_sigmask(SIG_BLOCK, &set, NULL);
+
+ while(1)
+ {
+ rset = allset;
+ if(pselect(maxfd, &rset, NULL, NULL, NULL, NULL) == -1)
+ {
+ closeConnections();
+ LOGE("pselect()");
+ return PRIV_MGR_ERROR_SYSTEM_ERROR;
+ }
+
+ if(FD_ISSET(signal_fd, &rset))
+ {
+ LOGI("Got signal to close");
+ signalfd_siginfo siginfo;
+ ssize_t res;
+ res = read(signal_fd, &siginfo, sizeof(siginfo));
+ TryReturn( res > 0, PRIV_MGR_ERROR_IPC_ERROR, closeConnections();, "read : %s", strerror(errno));
+ TryReturn( (size_t)res == sizeof(siginfo), PRIV_MGR_ERROR_IPC_ERROR, closeConnections();, "couldn't read whole siginfo");
+
+ if((int)siginfo.ssi_signo == m_signalToClose)
+ {
+ LOGI("Server thread got signal to close");
+ closeConnections();
+ return PRIV_MGR_ERROR_SUCCESS;
+ }
+ else
+ {
+ LOGI("Got not handled signal");
+ }
+ }
+ if(FD_ISSET(m_listenFd, &rset))
+ {
+ int clientFd;
+ clientFd = accept(m_listenFd, NULL, NULL);
+ TryReturn( clientFd != -1, PRIV_MGR_ERROR_IPC_ERROR, closeConnections();, "accept : %s", strerror(errno));
+
+ LOGI("Got incoming connection");
+ ConnectionInfo * connection = new ConnectionInfo(clientFd, (void *)this);
+ int res;
+ pthread_t client_thread;
+ if((res = pthread_create(&client_thread, NULL, &connectionThread, connection)) < 0)
+ {
+ delete connection;
+ errno = res;
+ closeConnections();
+ LOGE("pthread_create()");
+ return PRIV_MGR_ERROR_SYSTEM_ERROR;
+ }
+ addClientSocket(clientFd);
+ }
+ }
+}
+
+void*
+SocketService::connectionThread(void* pData)
+{
+ pthread_detach(pthread_self());
+ std::unique_ptr<ConnectionInfo> connectionInfo (static_cast<ConnectionInfo *>(pData));
+ SocketService &t = *static_cast<SocketService *>(connectionInfo->pData);
+ LOGI("Starting connection thread");
+ int ret = t.connectionService(connectionInfo->connFd);
+ if (ret < 0)
+ {
+ LOGE("Connection thread error");
+ t.removeClientSocket(connectionInfo->connFd);
+ close(connectionInfo->connFd);
+ return (void*)1;
+ }
+ LOGI("Client serviced");
+ return (void*)0;
+}
+
+int
+SocketService::connectionService(int fd)
+{
+
+ SocketConnection connector = SocketConnection(fd);
+ std::string interfaceName, methodName;
+
+ int res = connector.read(&interfaceName, &methodName);
+ if (res != PRIV_MGR_ERROR_SUCCESS)
+ {
+ LOGE("read : %d", res);
+ return res;
+ }
+
+ LOGD("Got interface : %s", interfaceName.c_str());
+ LOGD("Got method : %s", methodName.c_str());
+
+ if( m_callbackMap.find(interfaceName) == m_callbackMap.end())
+ {
+ LOGE("Unknown interface : %s", interfaceName.c_str());
+ return PRIV_MGR_ERROR_NO_DATA;
+ }
+
+ if(m_callbackMap[interfaceName].find(methodName) == m_callbackMap[interfaceName].end())
+ {
+ LOGE("Unknown method : %s", methodName.c_str());
+ return PRIV_MGR_ERROR_NO_DATA;
+ }
+
+// if(m_callbackMap[interfaceName][methodName]->securityCallback != NULL){
+// if(!m_callbackMap[interfaceName][methodName]->securityCallback(fd)){
+// LOGE("Security check returned false");
+// return -1;
+// }
+// }
+
+ LOGI("Calling service");
+ m_callbackMap[interfaceName][methodName]->serviceCallback(&connector);
+
+ LOGI("Removing client");
+ removeClientSocket(fd);
+ close(fd);
+
+ LOGI("Call served");
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int
+SocketService::stop(void)
+{
+ LOGI("Stopping");
+ if(close(m_listenFd) == -1)
+ if(errno != ENOTCONN)
+ {
+ LOGE("close() : %s", strerror(errno));
+ return PRIV_MGR_ERROR_IPC_ERROR;
+ }
+
+ int returned_value;
+ if((returned_value = pthread_kill(m_mainThread, m_signalToClose)) < 0)
+ {
+ errno = returned_value;
+ LOGE("pthread_kill() : %s", strerror(errno));
+ return PRIV_MGR_ERROR_IPC_ERROR;
+ }
+ pthread_join(m_mainThread, NULL);
+
+ LOGI("Stopped");
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int
+SocketService::shutdown(void)
+{
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+int
+SocketService::registerServiceCallback(const std::string &interfaceName, const std::string &methodName, socketServiceCallback callbackMethod)
+{
+ if(NULL == callbackMethod)
+ {
+ LOGE("Null callback");
+ return PRIV_MGR_ERROR_INVALID_PARAMETER;
+ }
+ if(interfaceName.empty() || methodName.empty())
+ {
+ LOGE("Interface and method name cannot be empty");
+ return PRIV_MGR_ERROR_INVALID_PARAMETER;
+ }
+
+ auto serviceCallbackPtr = std::make_shared<ServiceCallback>(ServiceCallback(callbackMethod));
+ m_callbackMap[interfaceName][methodName] = serviceCallbackPtr;
+
+ return PRIV_MGR_ERROR_SUCCESS;
+}
+
+void
+SocketService::addClientSocket(int clientSocket)
+{
+ std::lock_guard<std::mutex> guard(m_clientSocketListMutex);
+ m_clientSocketList.push_back(clientSocket);
+}
+
+void
+SocketService::removeClientSocket(int clientSocket)
+{
+ std::lock_guard<std::mutex> guard(m_clientSocketListMutex);
+ m_clientSocketList.remove(clientSocket);
+}
+
+bool
+SocketService::popClientSocket(int * pClientSocket)
+{
+ std::lock_guard<std::mutex> guard(m_clientSocketListMutex);
+ if(m_clientSocketList.empty())
+ return false;
+ *pClientSocket = m_clientSocketList.front();
+ m_clientSocketList.pop_front();
+ return true;
+}
+
+
+void
+SocketService::closeConnections(void)
+{
+ int clientSocket;
+ LOGI("Closing client sockets");
+ while(popClientSocket(&clientSocket))
+ {
+ if(close(clientSocket) == -1)
+ {
+ LOGE("close() : %s", strerror(errno));
+ }
+ }
+
+ LOGI("Connections closed");
+}
-/*\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
-#include <PrivacyManagerDaemon.h>\r
-#include <glib.h>\r
-\r
-int\r
-main(int argc, char* argv[])\r
-{\r
- PrivacyManagerDaemon* pDaemon = PrivacyManagerDaemon::getInstance();\r
-\r
- pDaemon->inialize();\r
- pDaemon->start();\r
-\r
- GMainLoop* pLoop;\r
- pLoop = g_main_new(TRUE);\r
-\r
- g_main_loop_run(pLoop);\r
-\r
- pDaemon->stop();\r
- pDaemon->shutdown();\r
-\r
- return 0;\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <PrivacyManagerDaemon.h>
+#include <glib.h>
+
+int
+main(int argc, char* argv[])
+{
+ PrivacyManagerDaemon* pDaemon = PrivacyManagerDaemon::getInstance();
+
+ pDaemon->inialize();
+ pDaemon->start();
+
+ GMainLoop* pLoop;
+ pLoop = g_main_new(TRUE);
+
+ g_main_loop_run(pLoop);
+
+ pDaemon->stop();
+ pDaemon->shutdown();
+
+ return 0;
}
\ No newline at end of file
-/*\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
-#include <privacy_manager_daemon.h>\r
-#include <PrivacyManagerDaemon.h>\r
-\r
-int privacy_manager_daemon_initialize(void)\r
-{\r
- PrivacyManagerDaemon* pPrivacyDaemon = PrivacyManagerDaemon::getInstance();\r
-\r
- return pPrivacyDaemon->initialize();\r
-}\r
-\r
-int privacy_manager_daemon_start(void)\r
-{\r
- PrivacyManagerDaemon* pInstance = PrivacyManagerDaemon::getInstance();\r
-\r
- return pInstance->start();\r
-}\r
-\r
-int privacy_manager_daemon_stop(void)\r
-{\r
- PrivacyManagerDaemon* pInstance = PrivacyManagerDaemon::getInstance();\r
-\r
- return pInstance->stop();\r
-}\r
-\r
-int privacy_manager_daemon_shutdown(void)\r
-{\r
- PrivacyManagerDaemon* pInstance = PrivacyManagerDaemon::getInstance();\r
-\r
- return pInstance->shutdown();\r
-}\r
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <privacy_manager_daemon.h>
+#include <PrivacyManagerDaemon.h>
+
+int privacy_manager_daemon_initialize(void)
+{
+ PrivacyManagerDaemon* pPrivacyDaemon = PrivacyManagerDaemon::getInstance();
+
+ return pPrivacyDaemon->initialize();
+}
+
+int privacy_manager_daemon_start(void)
+{
+ PrivacyManagerDaemon* pInstance = PrivacyManagerDaemon::getInstance();
+
+ return pInstance->start();
+}
+
+int privacy_manager_daemon_stop(void)
+{
+ PrivacyManagerDaemon* pInstance = PrivacyManagerDaemon::getInstance();
+
+ return pInstance->stop();
+}
+
+int privacy_manager_daemon_shutdown(void)
+{
+ PrivacyManagerDaemon* pInstance = PrivacyManagerDaemon::getInstance();
+
+ return pInstance->shutdown();
+}
-/*\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 <PrivacyInfoService.h>\r
-#include <PrivacyManagerServer.h>\r
-#include <dlog.h>\r
-#include <Utils.h>\r
-\r
-void\r
-PrivacyInfoService::addPrivacyInfo(SocketConnection* pConnector)\r
-{\r
- LOGI("enter");\r
-\r
- std::string pkgId;\r
- std::list < std::string > list;\r
- bool privacyPopupRequired = true;\r
- pConnector->read(&pkgId, &list, &privacyPopupRequired);\r
-\r
- PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();\r
- int result = pPrivacyManagerServer->addAppPackagePrivacyInfo(pkgId, list, privacyPopupRequired);\r
-\r
- pConnector->write(result);\r
-}\r
-\r
-void\r
-PrivacyInfoService::removePrivacyInfo(SocketConnection* pConnector)\r
-{\r
- LOGI("enter");\r
-\r
- std::string pkgId;\r
- pConnector->read(&pkgId);\r
-\r
- PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();\r
- int res = pPrivacyManagerServer->removeAppPackagePrivacyInfo(pkgId);\r
-\r
- pConnector->write(res);\r
-}\r
-\r
-void\r
-PrivacyInfoService::setPrivacySetting(SocketConnection* pConnector)\r
-{\r
- LOGI("enter");\r
-\r
- std::string pkgId;\r
- std::string privacyId;\r
- bool enabled = false;\r
- pConnector->read(&pkgId, &privacyId, &enabled);\r
-\r
- PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();\r
- int result = pPrivacyManagerServer->setPrivacySetting(pkgId, privacyId, enabled);\r
-\r
- pConnector->write(result);\r
-}\r
-\r
-void\r
-PrivacyInfoService::getPrivacyAppPackages(SocketConnection* pConnector)\r
-{\r
- LOGI("enter");\r
- PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();\r
- std::list <std::string> list;\r
- int result = pPrivacyManagerServer->getPrivacyAppPackages(list);\r
-\r
- pConnector->write( (unsigned int) result);\r
- pConnector->write( (unsigned int) list.size());\r
- pConnector->write(list);\r
-}\r
-\r
-void\r
-PrivacyInfoService::getAppPackagePrivacyInfo(SocketConnection* pConnector)\r
-{\r
- LOGI("enter");\r
-\r
- std::string pkgId;\r
-\r
- pConnector->read(&pkgId);\r
- PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();\r
-\r
- \r
- std::list < std::pair < std::string, bool > > infoList;\r
- \r
- int res = pPrivacyManagerServer->getAppPackagePrivacyInfo(pkgId, infoList);\r
-\r
- pConnector->write( res );\r
- pConnector->write( infoList );\r
-}\r
-\r
-void\r
-PrivacyInfoService::isUserPrompted(SocketConnection* pConnector)\r
-{\r
- LOGI("enter");\r
-\r
- std::string pkgId;\r
-\r
- pConnector->read(&pkgId);\r
- PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();\r
-\r
- bool isPrompted;\r
- int res = pPrivacyManagerServer->isUserPrompted(pkgId, isPrompted);\r
-\r
- pConnector->write( res );\r
- pConnector->write( isPrompted );\r
-\r
- LOGI("leave");\r
-}\r
-\r
-void\r
-PrivacyInfoService::setUserPrompted(SocketConnection* pConnector)\r
-{\r
- LOGI("enter");\r
-\r
- std::string pkgId;\r
- bool prompted = false;\r
-\r
- pConnector->read(&pkgId, &prompted);\r
- PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();\r
-\r
- int res = pPrivacyManagerServer->setUserPrompted(pkgId, prompted);\r
- LOGI("write");\r
- pConnector->write( res );\r
-\r
- LOGI("leave");\r
-}
\ No newline at end of file
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <PrivacyInfoService.h>
+#include <PrivacyManagerServer.h>
+#include <dlog.h>
+#include <Utils.h>
+
+void
+PrivacyInfoService::addPrivacyInfo(SocketConnection* pConnector)
+{
+ std::string pkgId;
+ std::list < std::string > list;
+ bool privacyPopupRequired = true;
+ pConnector->read(&pkgId, &list, &privacyPopupRequired);
+
+ PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();
+ int result = pPrivacyManagerServer->addAppPackagePrivacyInfo(pkgId, list, privacyPopupRequired);
+
+ pConnector->write(result);
+}
+
+void
+PrivacyInfoService::removePrivacyInfo(SocketConnection* pConnector)
+{
+ std::string pkgId;
+ pConnector->read(&pkgId);
+
+ PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();
+ int res = pPrivacyManagerServer->removeAppPackagePrivacyInfo(pkgId);
+
+ pConnector->write(res);
+}
+
+void
+PrivacyInfoService::setPrivacySetting(SocketConnection* pConnector)
+{
+ std::string pkgId;
+ std::string privacyId;
+ bool enabled = false;
+ pConnector->read(&pkgId, &privacyId, &enabled);
+
+ PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();
+ int result = pPrivacyManagerServer->setPrivacySetting(pkgId, privacyId, enabled);
+
+ pConnector->write(result);
+}
+
+void
+PrivacyInfoService::getPrivacyAppPackages(SocketConnection* pConnector)
+{
+ PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();
+ std::list <std::string> list;
+ int result = pPrivacyManagerServer->getPrivacyAppPackages(list);
+
+ pConnector->write( (unsigned int) result);
+ pConnector->write( (unsigned int) list.size());
+ pConnector->write(list);
+}
+
+void
+PrivacyInfoService::getAppPackagePrivacyInfo(SocketConnection* pConnector)
+{
+ std::string pkgId;
+
+ pConnector->read(&pkgId);
+ PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();
+
+
+ std::list < std::pair < std::string, bool > > infoList;
+
+ int res = pPrivacyManagerServer->getAppPackagePrivacyInfo(pkgId, infoList);
+
+ pConnector->write( res );
+ pConnector->write( infoList );
+}
+
+void
+PrivacyInfoService::isUserPrompted(SocketConnection* pConnector)
+{
+ std::string pkgId;
+
+ pConnector->read(&pkgId);
+ PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();
+
+ bool isPrompted;
+ int res = pPrivacyManagerServer->isUserPrompted(pkgId, isPrompted);
+
+ pConnector->write( res );
+ pConnector->write( isPrompted );
+
+}
+
+void
+PrivacyInfoService::setUserPrompted(SocketConnection* pConnector)
+{
+ std::string pkgId;
+ bool prompted = false;
+
+ pConnector->read(&pkgId, &prompted);
+ PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();
+
+ int res = pPrivacyManagerServer->setUserPrompted(pkgId, prompted);
+ LOGI("write");
+ pConnector->write( res );
+
+}