App media policy 23/144223/4 accepted/tizen/4.0/unified/20170921.074239 accepted/tizen/unified/20170921.072513 submit/tizen/20170921.053121 submit/tizen_4.0/20170921.052723
authorJaemin Ryu <jm77.ryu@samsung.com>
Wed, 16 Aug 2017 02:39:31 +0000 (11:39 +0900)
committerJaemin Ryu <jm77.ryu@samsung.com>
Thu, 14 Sep 2017 00:58:37 +0000 (00:58 +0000)
Change-Id: Iaf09e564e93154f185e3d27124fe83945f5bcf39
Signed-off-by: Jaemin Ryu <jm77.ryu@samsung.com>
CMakeLists.txt [new file with mode: 0755]
api/CMakeLists.txt [new file with mode: 0755]
api/dpm-media.pc.in [new file with mode: 0644]
api/media.cpp [new file with mode: 0644]
api/media.h [new file with mode: 0644]
dpm-media.manifest [new file with mode: 0644]
packaging/dpm-media.spec [new file with mode: 0755]
plugin/CMakeLists.txt [new file with mode: 0755]
plugin/media.cpp [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..d5afff7
--- /dev/null
@@ -0,0 +1,85 @@
+#
+# Copyright (c) 2017 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.
+#
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
+
+PROJECT(dpm-media)
+
+IF(NOT DEFINED VERSION)
+       SET(VERSION "0.0.1")
+ENDIF(NOT DEFINED VERSION)
+
+INCLUDE(FindPkgConfig)
+
+IF(NOT CMAKE_BUILD_TYPE)
+       SET(CMAKE_BUILD_TYPE "DEBUG")
+ENDIF(NOT CMAKE_BUILD_TYPE)
+
+SET(DPM_API     ${PROJECT_SOURCE_DIR}/api)
+SET(DPM_PLUGIN  ${PROJECT_SOURCE_DIR}/plugin)
+
+IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
+       SET(CXX_STD "c++0x")
+else()
+       SET(CXX_STD "c++11")
+endif()
+
+SET(COMPILE_BASE_FLAGS         "-g -fPIC -Werror -Wall -Wl,--as-needed -Wl,--no-whole-archive")
+SET(CMAKE_C_FLAGS_PROFILING    "${COMPILE_BASE_FLAGS} -O0 -pg")
+SET(CMAKE_CXX_FLAGS_PROFILING  "${COMPILE_BASE_FLAGS} -O0 -pg -std=${CXX_STD} -fno-rtti")
+SET(CMAKE_C_FLAGS_DEBUG                "${COMPILE_BASE_FLAGS} -O0 -ggdb")
+SET(CMAKE_CXX_FLAGS_DEBUG      "${COMPILE_BASE_FLAGS} -O0 -ggdb -std=${CXX_STD} -fno-rtti")
+SET(CMAKE_C_FLAGS_RELEASE      "${COMPILE_BASE_FLAGS} -O2 -DNDEBUG")
+SET(CMAKE_CXX_FLAGS_RELEASE    "${COMPILE_BASE_FLAGS} -O2 -DNDEBUG -std=${CXX_STD} -fno-rtti")
+SET(CMAKE_C_FLAGS_CCOV         "${COMPILE_BASE_FLAGS} -O0 --coverage")
+SET(CMAKE_CXX_FLAGS_CCOV       "${COMPILE_BASE_FLAGS} -O0 --coverage -std=${CXX_STD} -fno-rtti")
+
+IF(NOT DEFINED LIB_INSTALL_DIR)
+       SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}")
+ENDIF(NOT DEFINED LIB_INSTALL_DIR)
+
+IF(NOT DEFINED INCLUDE_INSTALL_DIR)
+       SET(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
+ENDIF(NOT DEFINED INCLUDE_INSTALL_DIR)
+
+IF(NOT DEFINED CONF_INSTALL_DIR)
+       SET(CONF_INSTALL_DIR "${SYSCONF_INSTALL_DIR}/dpm")
+ENDIF(NOT DEFINED CONF_INSTALL_DIR)
+
+IF(NOT DEFINED DATA_INSTALL_DIR)
+       SET(DATA_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/dpm")
+ENDIF(NOT DEFINED DATA_INSTALL_DIR)
+
+IF(NOT DEFINED DB_INSTALL_DIR)
+       SET(DB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/dbspace")
+ENDIF(NOT DEFINED DB_INSTALL_DIR)
+
+IF(NOT DEFINED RUN_INSTALL_DIR)
+       SET(RUN_INSTALL_DIR "/var/run")
+ENDIF(NOT DEFINED RUN_INSTALL_DIR)
+
+IF(NOT DEFINED PAMD_INSTALL_DIR)
+       SET(PAMD_INSTALL_DIR "${SYSCONF_INSTALL_DIR}/pam.d")
+ENDIF(NOT DEFINED PAMD_INSTALL_DIR)
+
+IF(NOT DEFINED SYSTEMD_UNIT_INSTALL_DIR)
+       SET(SYSTEMD_UNIT_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib/systemd/system")
+ENDIF(NOT DEFINED SYSTEMD_UNIT_INSTALL_DIR)
+
+ADD_DEFINITIONS(-DUG_WAYLAND)
+
+ADD_SUBDIRECTORY(${DPM_PLUGIN})
+ADD_SUBDIRECTORY(${DPM_API})
diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..f911043
--- /dev/null
@@ -0,0 +1,48 @@
+#
+# Copyright (c) 2015 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.
+#
+SET(TARGET ${PROJECT_NAME})
+SET(PC_FILE "${TARGET}.pc")
+
+SET(LIB_VERSION "${VERSION}")
+SET(LIB_SOVERSION "0")
+
+SET(API_SOURCES "media.cpp")
+SET(API_HEADERS "media.h")
+
+SET(DEPENDENCY      klay
+                                       dpm-pil
+                    capi-base-common
+                    capi-system-info
+)
+
+PKG_CHECK_MODULES(API_DEPS REQUIRED ${DEPENDENCY})
+
+SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack")
+
+ADD_LIBRARY(${TARGET} SHARED ${API_SOURCES})
+
+SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS "-fvisibility=default")
+SET_TARGET_PROPERTIES(${TARGET} PROPERTIES SOVERSION ${LIB_SOVERSION})
+SET_TARGET_PROPERTIES(${TARGET} PROPERTIES VERSION   ${LIB_VERSION})
+
+INCLUDE_DIRECTORIES(SYSTEM ${API_DEPS_INCLUDE_DIRS})
+TARGET_LINK_LIBRARIES(${TARGET} ${API_DEPS_LIBRARIES} pthread)
+
+CONFIGURE_FILE(${PC_FILE}.in ${CMAKE_BINARY_DIR}/${PC_FILE} @ONLY)
+
+INSTALL(FILES ${CMAKE_BINARY_DIR}/${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+INSTALL(TARGETS ${TARGET} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+INSTALL(FILES ${API_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/dpm)
diff --git a/api/dpm-media.pc.in b/api/dpm-media.pc.in
new file mode 100644 (file)
index 0000000..ea61380
--- /dev/null
@@ -0,0 +1,13 @@
+# Package Information for pkg-config
+
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=@CMAKE_INSTALL_PREFIX@
+libdir=@LIB_INSTALL_DIR@
+includedir=@INCLUDE_INSTALL_DIR@
+
+Name: Media policy module
+Description: Media policy module for device policy manager
+Version: @VERSION@
+Libs: -L${libdir} -ldpm-media
+Cflags: -I${includedir}/dpm
+
diff --git a/api/media.cpp b/api/media.cpp
new file mode 100644 (file)
index 0000000..80f5bad
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ *  Copyright (c) 2016 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 <tizen.h>
+#include <tizen_type.h>
+
+#include <dpm/pil/policy-client.h>
+
+#include "media.h"
+
+EXPORT_API int dpm_media_set_camera_state(void* handle, int allow)
+{
+       RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+
+       DevicePolicyClient &client = GetDevicePolicyClient(handle);
+       try {
+               Status<int> status { -1 };
+               status = client.methodCall<int>("Media::setCameraState", allow);
+               return status.get();
+       } catch (...) {
+               return -1;
+       }
+}
+
+EXPORT_API int dpm_media_get_camera_state(void *handle, int *is_allowed)
+{
+       RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER);
+
+       DevicePolicyClient &client = GetDevicePolicyClient(handle);
+       try {
+               Status<bool> status { true };
+               status = client.methodCall<bool>("Media::getCameraState");
+               *is_allowed = status.get();
+       } catch (...) {
+               return -1;
+       }
+
+       return 0;
+}
+
+EXPORT_API int dpm_media_set_microphone_state(void* handle, int allow)
+{
+       RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+
+       DevicePolicyClient &client = GetDevicePolicyClient(handle);
+       try {
+               Status<int> status { -1 };
+               status = client.methodCall<int>("Media::setMicrophoneState", allow);
+               return status.get();
+       } catch (...) {
+               return -1;
+       }
+}
+
+EXPORT_API int dpm_media_get_microphone_state(void *handle, int *is_allowed)
+{
+       RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER);
+
+       DevicePolicyClient &client = GetDevicePolicyClient(handle);
+       try {
+               Status<bool> status { true };
+               status = client.methodCall<bool>("Media::getMicrophoneState");
+               *is_allowed = status.get();
+       } catch (...) {
+               return -1;
+       }
+
+       return 0;
+}
+
+EXPORT_API int dpm_media_set_clipboard_state(void* handle, int allow)
+{
+       RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+
+       DevicePolicyClient &client = GetDevicePolicyClient(handle);
+       try {
+               Status<int> status { -1 };
+               status = client.methodCall<int>("Media::setClipboardState", allow);
+               return status.get();
+       } catch (...) {
+               return -1;
+       }
+}
+
+EXPORT_API int dpm_media_get_clipboard_state(void *handle, int *is_allowed)
+{
+       RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER);
+
+       DevicePolicyClient &client = GetDevicePolicyClient(handle);
+       try {
+               Status<bool> status { true };
+               status = client.methodCall<bool>("Media::getClipboardState");
+               *is_allowed = status.get();
+       } catch (...) {
+               return -1;
+       }
+
+       return 0;
+}
diff --git a/api/media.h b/api/media.h
new file mode 100644 (file)
index 0000000..01bfb7c
--- /dev/null
@@ -0,0 +1,162 @@
+/*
+ *  Copyright (c) 2016 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 __CAPI_MEDIA_H__
+#define __CAPI_MEDIA_H__
+
+typedef void * device_policy_manager_h;
+
+/**
+ * @file media.h
+ * @brief This file provides APIs to control media functionality.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup  CAPI_DPM_MEDIA_POLICY_MODULE
+ * @{
+ */
+
+/**
+ * @partner
+ * @brief       Allows or disallows the use of camera.
+ * @details     An administrator can use this API to set whether the use of camera
+ *              is allowed or not.
+ * @since_tizen 3.0
+ * @privlevel   partner
+ * @privilege   %http://tizen.org/privilege/dpm.camera
+ * @param[in]   handle Device policy manager handle
+ * @param[in]   allow If true, allow the use of camera, if false, disallow the use of camera
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_TIMED_OUT Time out
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #DPM_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         The handle must be created by dpm_manager_create().
+ * @see         dpm_manager_create()
+ * @see         dpm_media_get_camera_state()
+ */
+int dpm_media_set_camera_state(device_policy_manager_h handle, int allow);
+
+/**
+ * @brief       Check whether the use of camera is allowed or not.
+ * @details     An administrator can use this API to check whether the use of camera
+ *              is allowed or not.
+ * @since_tizen 3.0
+ * @param[in]   handle Device policy manager handle
+ * @param[out]  is_allowed true if the use of camera is allowed, false otherwise.
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #DPM_ERROR_TIMED_OUT Time out
+ * @pre         The handle must be created by dpm_manager_create().
+ * @see         dpm_manager_create()
+ * @see         dpm_media_set_camera_state()
+ */
+int dpm_media_get_camera_state(device_policy_manager_h handle, int *is_allowed);
+
+/**
+ * @partner
+ * @brief       Allows or disallows the use of microphone.
+ * @details     An administrator can use this API to set whether the use of microphone
+ *              is allowed or not.
+ * @since_tizen 3.0
+ * @privlevel   partner
+ * @privilege   %http://tizen.org/privilege/dpm.microphone
+ * @param[in]   handle Device policy manager handle
+ * @param[in]   allow If true, allow the use of microphone,
+ *              if false, disallow the use of microphone
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_TIMED_OUT Time out
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #DPM_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         The handle must be created by dpm_manager_create().
+ * @see         dpm_manager_create()
+ * @see         dpm_media_get_microphone_state()
+ */
+int dpm_media_set_microphone_state(device_policy_manager_h handle, int allow);
+
+/**
+ * @brief       Checks whether the use of microphone is allowed or not.
+ * @details     An administrator can use this API to check whether the use of microphone
+ *              is allowed of not.
+ * @since_tizen 3.0
+ * @param[in]   handle Device policy manager handle
+ * @param[out]  is_allowed true if the use of microphone is allowed, false otherwise.
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #DPM_ERROR_TIMED_OUT Time out
+ * @pre         The handle must be created by dpm_manager_create().
+ * @see         dpm_manager_create()
+ * @see         dpm_media_set_microphone_state()
+ */
+int dpm_media_get_microphone_state(device_policy_manager_h handle, int *is_allowed);
+
+/**
+ * @partner
+ * @brief       Allows or disallows user to access the clipboard.
+ * @details     An administrator can use this API to set whether the clipboard access.
+ *              is allowed or not
+ * @since_tizen 3.0
+ * @privlevel   partner
+ * @privilege   %http://tizen.org/privilege/dpm.clipboard
+ * @param[in]   handle Device policy manager handle
+ * @param[in]   allow If true, allow the clipboard access, if false, disallow the clipboard access.
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_TIMED_OUT Time out
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #DPM_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         The handle must be created by dpm_manager_create().
+ * @see         dpm_manager_create()
+ * @see         dpm_media_get_clipboard_state()
+ */
+int dpm_media_set_clipboard_state(device_policy_manager_h handle, int allow);
+
+/**
+ * @brief       Checks whether the clipboard access is allowed or not.
+ * @details     An administrator can use this API to check whether the clipboard access
+ *              is allowed or not.
+ * @since_tizen 3.0
+ * @param[in]   handle Device policy manager handle
+ * @param[out]  is_allowed true if the access is allowed, false otherwise.
+ * @return      #DPM_ERROR_NONE on success, otherwise a negative value
+ * @retval      #DPM_ERROR_NONE Successful
+ * @retval      #DPM_ERROR_TIMED_OUT Time out
+ * @retval      #DPM_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre         The handle must be created by dpm_manager_create().
+ * @see         dpm_manager_create()
+ * @see         dpm_media_set_clipboard_state()
+ */
+int dpm_media_get_clipboard_state(device_policy_manager_h handle, int *is_allowed);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __CAPI_MEDIA_POLICY_H__ */
diff --git a/dpm-media.manifest b/dpm-media.manifest
new file mode 100644 (file)
index 0000000..a76fdba
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
diff --git a/packaging/dpm-media.spec b/packaging/dpm-media.spec
new file mode 100755 (executable)
index 0000000..6d99fff
--- /dev/null
@@ -0,0 +1,76 @@
+Name:    dpm-media
+Version: 1.0.1
+Release: 0
+License: Apache-2.0
+Source0: %{name}-%{version}.tar.gz
+Summary: Tizen Device Policy Manager Media Policy Module
+Group:   Security/Other
+BuildRequires: gcc
+BuildRequires: cmake
+BuildRequires: gettext-tools
+BuildRequires: pkgconfig(klay)
+BuildRequires: pkgconfig(dpm-pil)
+BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(capi-base-common)
+
+%description
+The dpm-media package provides media  policy module for device policy manager
+
+%files
+%manifest dpm-media.manifest
+%defattr(644,root,root,755)
+%attr(755,root,root) /opt/data/dpm/plugins/media
+%attr(755,root,root) %{_libdir}/libdpm-media.so.%{version}
+%{_libdir}/libdpm-media.so.0
+
+%prep
+%setup -q
+
+%build
+%{!?build_type:%define build_type "RELEASE"}
+
+%if %{build_type} == "DEBUG" || %{build_type} == "PROFILING" || %{build_type} == "CCOV"
+       CFLAGS="$CFLAGS -Wp,-U_FORTIFY_SOURCE"
+       CXXFLAGS="$CXXFLAGS -Wp,-U_FORTIFY_SOURCE"
+%endif
+
+%cmake . -DVERSION=%{version} \
+         -DCMAKE_BUILD_TYPE=%{build_type} \
+         -DSCRIPT_INSTALL_DIR=%{_scriptdir} \
+         -DSYSTEMD_UNIT_INSTALL_DIR=%{_unitdir} \
+         -DDATA_INSTALL_DIR=%{TZ_SYS_DATA}/dpm \
+         -DDB_INSTALL_DIR=%{TZ_SYS_DB} \
+         -DRUN_INSTALL_DIR=%{TZ_SYS_RUN} \
+         -DAPP_INSTALL_PREFIX="%{TZ_SYS_RO_APP}" \
+         -DAPP_SHARE_PACKAGES_DIR="%{TZ_SYS_RO_PACKAGES}" \
+
+make %{?jobs:-j%jobs}
+
+%install
+%make_install
+
+%clean
+rm -rf %{buildroot}
+
+%post
+
+%preun
+
+%postun
+
+## Devel Package ##############################################################
+%package -n libdpm-media-devel
+Summary: Libraries and header files for device policy client development
+Group: Development/Libraries
+Requires: device-policy-manager = %{version}-%{release}
+
+%description -n libdpm-media-devel
+The libdpm-media-devel package includes the libraries and header files necessary for
+developing the DPM client program.
+
+%files -n libdpm-media-devel
+%manifest dpm-media.manifest
+%defattr(644,root,root,755)
+%{_libdir}/libdpm-media.so
+%{_libdir}/pkgconfig/dpm-media.pc
+%{_includedir}/dpm
diff --git a/plugin/CMakeLists.txt b/plugin/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..9cca5cf
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# Copyright (c) 2015 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.
+#
+SET(TARGET "dpm-plugin-media")
+
+SET(PLUGIN_SOURCES "media.cpp")
+
+SET(DEPENDENCY      klay
+                                       dpm-pil
+)
+
+PKG_CHECK_MODULES(PLUGIN_DEPS REQUIRED ${DEPENDENCY})
+
+SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack")
+
+ADD_LIBRARY(${TARGET} SHARED ${PLUGIN_SOURCES})
+SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS "-fvisibility=default")
+INCLUDE_DIRECTORIES(SYSTEM ${PLUGIN_DEPS_INCLUDE_DIRS})
+TARGET_LINK_LIBRARIES(${TARGET} ${PLUGIN_DEPS_LIBRARIES})
+
+INSTALL(FILES libdpm-plugin-media.so RENAME media DESTINATION /opt/data/dpm/plugins)
diff --git a/plugin/media.cpp b/plugin/media.cpp
new file mode 100644 (file)
index 0000000..faee080
--- /dev/null
@@ -0,0 +1,194 @@
+/*
+ *  Copyright (c) 2016 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 <iostream>
+
+#include <klay/dbus/connection.h>
+#include <klay/dbus/variant.h>
+
+#include <dpm/pil/policy-context.h>
+#include <dpm/pil/policy-model.h>
+#include <dpm/pil/policy-storage.h>
+#include <dpm/pil/policy-event.h>
+
+class CameraState : public GlobalPolicy<DataSetInt> {
+public:
+       CameraState() : GlobalPolicy("camera")
+       {
+               PolicyEventNotifier::create("camera");
+       }
+
+       bool apply(const DataType& value) {
+               int enable = value;
+               PolicyEventNotifier::emit("camera", enable ? "allowed" : "disallowed");
+               return false;
+       }
+};
+
+class ClipboardState : public GlobalPolicy<DataSetInt> {
+public:
+       ClipboardState() : GlobalPolicy("clipboard")
+       {
+               PolicyEventNotifier::create("clipboard");
+       }
+
+       bool apply(const DataType& value) {
+               int enable = value;
+               PolicyEventNotifier::emit("clipboard", enable ? "allowed" : "disallowed");
+               return false;
+       }
+};
+
+#define PULSEAUDIO_LOGIN_INTERFACE          \
+       "org.pulseaudio.Server",                \
+       "/org/pulseaudio/StreamManager",        \
+       "org.pulseaudio.StreamManager"
+
+class MicrophoneState : public GlobalPolicy<DataSetInt> {
+public:
+       MicrophoneState() : GlobalPolicy("microphone")
+       {
+               PolicyEventNotifier::create("microphone");
+       }
+
+       bool apply(const DataType& value) {
+               int enable = value;
+               char *result = NULL;
+               try {
+                       dbus::Connection &systemDBus = dbus::Connection::getSystem();
+                       systemDBus.methodcall(PULSEAUDIO_LOGIN_INTERFACE,
+                                                                 "UpdateRestriction",
+                                                                 -1,
+                                                                 "(s)",
+                                                                 "(su)",
+                                                                 "block_recording_media",
+                                                                 !enable).get("(s)", &result);
+               } catch (runtime::Exception& e) {
+                       ERROR("Failed to enforce microphone policy");
+                       return false;
+               }
+
+               if (strcmp(result, "STREAM_MANAGER_RETURN_OK") != 0) {
+                       return false;
+               }
+
+               PolicyEventNotifier::emit("microphone", enable ? "allowed" : "disallowed");
+               return true;
+       }
+};
+
+class Media : public AbstractPolicyProvider {
+public:
+       Media();
+       virtual ~Media();
+
+       int setCameraState(bool enable);
+       bool getCameraState();
+
+       int setMicrophoneState(bool enable);
+       bool getMicrophoneState();
+
+       int setClipboardState(bool enable);
+       bool getClipboardState();
+
+public:
+       CameraState camera;
+       MicrophoneState microphone;
+       ClipboardState clipboard;
+};
+
+Media::Media()
+{
+}
+
+Media::~Media()
+{
+}
+
+int Media::setCameraState(bool enable)
+{
+       try {
+               camera.set(enable);
+       } catch (runtime::Exception& e) {
+               std::cerr << e.what() << std::endl;
+               return -1;
+       }
+
+       return 0;
+}
+
+bool Media::getCameraState()
+{
+       return camera.get();
+}
+
+int Media::setMicrophoneState(bool enable)
+{
+       try {
+               microphone.set(enable);
+       } catch (runtime::Exception& e) {
+               std::cerr << e.what() << std::endl;
+               return -1;
+       }
+
+       return 0;
+}
+
+
+bool Media::getMicrophoneState()
+{
+       return microphone.get();
+}
+
+int Media::setClipboardState(bool enable)
+{
+       try {
+               clipboard.set(enable);
+       } catch (runtime::Exception& e) {
+               std::cerr << e.what() << std::endl;
+               return -1;
+       }
+
+       return 0;
+}
+
+bool Media::getClipboardState()
+{
+       return clipboard.get();
+}
+
+extern "C" {
+
+#define PRIVILEGE_CAMERA "http://tizen.org/privilege/dpm.camera"
+#define PRIVILEGE_MICROPHONE "http://tizen.org/privilege/dpm.microphone"
+#define PRIVILEGE_CLIPBOARD "http://tizen.org/privilege/dpm.clipboard"
+
+AbstractPolicyProvider *PolicyFactory(PolicyControlContext& context)
+{
+       Media *policy = new Media();
+
+       context.expose(policy, PRIVILEGE_CAMERA,     (int)(Media::setCameraState)(bool));
+    context.expose(policy, PRIVILEGE_MICROPHONE, (int)(Media::setMicrophoneState)(bool));
+    context.expose(policy, PRIVILEGE_CLIPBOARD,  (int)(Media::setClipboardState)(bool));
+
+       context.expose(policy, "", (bool)(Media::getCameraState)());
+    context.expose(policy, "", (bool)(Media::getMicrophoneState)());
+    context.expose(policy, "", (bool)(Media::getClipboardState)());
+
+       return policy;
+}
+
+}