--- /dev/null
+#
+# 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-bluetooth)
+
+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})
--- /dev/null
+#
+# 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 "bluetooth.cpp")
+SET(API_HEADERS "bluetooth.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)
--- /dev/null
+/*
+ * 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 "bluetooth.h"
+
+EXPORT_API int dpm_bluetooth_set_mode_change_state(device_policy_manager_h handle, bool allow)
+{
+ RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+
+ try {
+ DevicePolicyClient& client = GetDevicePolicyClient(handle);
+
+ Status<int> status { -1 };
+ status = client.methodCall<int>("Bluetooth::setModeChangeState", allow);
+ return status.get();
+ } catch (...) {
+ return -1;
+ }
+}
+
+EXPORT_API int dpm_bluetooth_get_mode_change_state(device_policy_manager_h handle, bool *is_allowed)
+{
+ RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+ RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER);
+
+ try {
+ DevicePolicyClient& client = GetDevicePolicyClient(handle);
+
+ Status<bool> status { true };
+ status = client.methodCall<bool>("Bluetooth::getModeChangeState");
+ *is_allowed = status.get();
+ } catch (...) {
+ return -1;
+ }
+
+ return DPM_ERROR_NONE;
+}
+
+EXPORT_API int dpm_bluetooth_set_desktop_connectivity_state(device_policy_manager_h handle, bool allow)
+{
+ RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+
+ try {
+ DevicePolicyClient& client = GetDevicePolicyClient(handle);
+
+ Status<int> status { -1 };
+ status = client.methodCall<bool>("Bluetooth::setDesktopConnectivityState", allow);
+ return status.get();
+ } catch (...) {
+ return -1;
+ }
+}
+
+EXPORT_API int dpm_bluetooth_get_desktop_connectivity_state(device_policy_manager_h handle, bool *is_allowed)
+{
+ RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+ RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER);
+
+ try {
+ DevicePolicyClient& client = GetDevicePolicyClient(handle);
+
+ Status<bool> status { true };
+ status = client.methodCall<bool>("Bluetooth::getDesktopConnectivityState");
+ *is_allowed = status.get();
+ } catch (...) {
+ return -1;
+ }
+
+ return DPM_ERROR_NONE;
+}
+
+EXPORT_API int dpm_bluetooth_set_tethering_state(device_policy_manager_h handle, bool allow)
+{
+ RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+
+ try {
+ DevicePolicyClient& client = GetDevicePolicyClient(handle);
+
+ Status<int> status { -1 };
+ status = client.methodCall<int>("Bluetooth::setTetheringState", allow);
+ return status.get();
+ } catch (...) {
+ return -1;
+ }
+}
+
+EXPORT_API int dpm_bluetooth_get_tethering_state(device_policy_manager_h handle, bool *is_allowed)
+{
+ RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+ RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER);
+
+ try {
+ DevicePolicyClient& client = GetDevicePolicyClient(handle);
+
+ Status<bool> status { true };
+ status = client.methodCall<bool>("Bluetooth::getTetheringState");
+ *is_allowed = status.get();
+ } catch (...) {
+ return -1;
+ }
+
+ return DPM_ERROR_NONE;
+}
+
+EXPORT_API int dpm_bluetooth_set_pairing_state(device_policy_manager_h handle, bool allow)
+{
+ RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+
+ try {
+ DevicePolicyClient& client = GetDevicePolicyClient(handle);
+
+ Status<int> status { -1 };
+ status = client.methodCall<int>("Bluetooth::setPairingState", allow);
+ return status.get();
+ } catch (...) {
+ return -1;
+ }
+}
+
+EXPORT_API int dpm_bluetooth_get_pairing_state(device_policy_manager_h handle, bool *is_allowed)
+{
+ RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+ RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER);
+
+ try {
+ DevicePolicyClient& client = GetDevicePolicyClient(handle);
+
+ Status<bool> status { true };
+ status = client.methodCall<bool>("Bluetooth::getPairingState");
+ *is_allowed = status.get();
+ } catch (...) {
+ return -1;
+ }
+
+ return DPM_ERROR_NONE;
+}
--- /dev/null
+/*
+ * 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_DPM_BLUETOOTH_POLICY_H__
+#define __CAPI_DPM_BLUETOOTH_POLICY_H__
+
+#include <stdbool.h>
+
+typedef void * device_policy_manager_h;
+
+/**
+ * @file bluetooth.h
+ * @brief This file provides APIs to control bluetooth functionality.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup CAPI_DPM_BLUETOOTH_POLICY_MODULE
+ * @{
+ */
+
+/**
+ * @partner
+ * @brief Allows or disallows user to change the bluetooth tethering state.
+ * @details An administrator can use this API to allow of disallow user
+ * to chanage the bluetooth tethering state.
+ * When disallowed, the UI is grayed out so user cannot change the state.
+ * @since_tizen 3.0
+ * @privlevel partner
+ * @privilege %http://tizen.org/privilege/dpm.bluetooth
+ * @param[in] handle Device policy manager handle
+ * @param[in] allow If true, allow user to change the bluetooth tethering state,
+ * if false, disallow user to change the bluetooth tethering state.
+ * @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_bluetooth_get_tethering_state()
+ */
+int dpm_bluetooth_set_tethering_state(device_policy_manager_h handle, bool allow);
+
+/**
+ * @brief Checks whether the bluetooth tethering state change is allowed.
+ * @details An administrator can use this API to check whether user is allowed
+ * to change bluetooth tethering state.
+ * is allowed or not.
+ * If the bluetooth tethering state change is disallowed, the UI is grayed out
+ * so user can not change its state.
+ * @since_tizen 3.0
+ * @param[in] handle Device policy manager handle
+ * @param[out] is_allowed true if the change 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_bluetooth_set_tethering_state()
+ */
+int dpm_bluetooth_get_tethering_state(device_policy_manager_h handle, bool *is_allowed);
+
+/**
+ * @partner
+ * @brief Allows or disallows user to change the bluetooth state.
+ * @details An administrator can use this API to allow or disallow user
+ * to change the bluetooth state.
+ * When disallowed, the UI is grayed out so user cannot change the state.
+ * @since_tizen 3.0
+ * @privlevel partner
+ * @privilege %http://tizen.org/privilege/dpm.bluetooth
+ * @param[in] handle Device policy manager handle
+ * @param[in] allow If true, allow user to change bluetooth state,
+ * if false, disallow user to change bluetooth state.
+ * @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_bluetooth_get_mode_change_state()
+ */
+int dpm_bluetooth_set_mode_change_state(device_policy_manager_h handle, bool allow);
+
+/**
+ * @brief Checks whether the the bluetooth state change is allowed of not.
+ * @details An administrator can use this API to check whether the bluetooth state change
+ * is allowed or not.
+ * If the bluetooth state change is disallowed, the UI is grayed out
+ * so user can not change its state.
+ * @since_tizen 3.0
+ * @param[in] handle Device policy manager handle
+ * @param[out] is_allowed true if the change 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_bluetooth_set_mode_change_state()
+ */
+int dpm_bluetooth_get_mode_change_state(device_policy_manager_h handle, bool *is_allowed);
+
+/**
+ * @partner
+ * @brief Allows or disallows the bluetooth desktop connectivity.
+ * @details An administrator can use this API to allow or disallow the bluetooth
+ * desktop connectivity.
+ * If the bluetooth desktop connectivity is disallowed, the UI is grayed out
+ * so user can not
+ * change its state.
+ * @since_tizen 3.0
+ * @privlevel partner
+ * @privilege %http://tizen.org/privilege/dpm.bluetooth
+ * @param[in] handle Device policy manager handle
+ * @param[out] allow If true, allow the bluetooth desktop connectivity,
+ * if false, disallow the bluetooth desktop connectivitiy
+ * @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_bluetooth_get_desktop_connectivity_state()
+ */
+int dpm_bluetooth_set_desktop_connectivity_state(device_policy_manager_h handle, bool allow);
+
+/**
+ * @brief Checks whether the the Bluetooth desktop connectivity is allowed or not.
+ * @details An administrator can use this API to check whether the Bluetooth desktop
+ * connectivity is allowed or not.
+ * If the Bluetooth desktop connectivity is disallowed, the UI is grayed out
+ * so user can not change its state.
+ * @since_tizen 3.0
+ * @param[in] handle Device policy manager handle
+ * @param[out] is_allowed true if the connectivity 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_bluetooth_set_desktop_connectivity_state()
+ */
+int dpm_bluetooth_get_desktop_connectivity_state(device_policy_manager_h handle, bool *is_allowed);
+
+/**
+ * @partner
+ * @brief Allows or disallows user to change the bluetooth pairing.
+ * @details An administrator can use this API to allow or disallow the bluetooth pairing.
+ * If the bluetooth pairing is disallowed, the UI is grayed out
+ * so user can not change its state.
+ * @since_tizen 3.0
+ * @privlevel partner
+ * @privilege %http://tizen.org/privilege/dpm.bluetooth
+ * @param[in] handle Device policy manager handle
+ * @param[out] allow If true, allow the bluetooth pairing, if false, disallow the bluetooth pairing.
+ * @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_bluetooth_get_pairing_state()
+ */
+int dpm_bluetooth_set_pairing_state(device_policy_manager_h handle, bool allow);
+
+/**
+ * @brief Checks whether the the bluetooth pairing is allowed or not.
+ * @details An administrator can use this API to check whether the bluetooth
+ * pairing is allowed or not.
+ * If the bluetooth pairing is disallowed, the UI is grayed out
+ * so user can not change its state.
+ * @since_tizen 3.0
+ * @param[in] handle Device policy manager handle
+ * @param[out] is_allowed true if the pairing 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_bluetooth_set_pairing_state()
+ */
+int dpm_bluetooth_get_pairing_state(device_policy_manager_h handle, bool *is_allowed);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __CAPI_DPM_BLUETOOTH_POLICY_H__ */
--- /dev/null
+# Package Information for pkg-config
+
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=@CMAKE_INSTALL_PREFIX@
+libdir=@LIB_INSTALL_DIR@
+includedir=@INCLUDE_INSTALL_DIR@
+
+Name: Bluetooth policy module
+Description: Bluetooth policy module for device policy manager
+Version: @VERSION@
+Libs: -L${libdir} -ldpm-bluetooth
+Cflags: -I${includedir}/dpm
+
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_" />
+ </request>
+</manifest>
--- /dev/null
+Name: dpm-bluetooth
+Version: 1.0.1
+Release: 0
+License: Apache-2.0
+Source0: %{name}-%{version}.tar.gz
+Summary: Tizen Device Policy Manager BLuetooth Policy Module
+Group: Security/Other
+BuildRequires: gcc
+BuildRequires: cmake
+BuildRequires: gettext-tools
+BuildRequires: pkgconfig(klay)
+BuildRequires: pkgconfig(dpm-pil)
+BuildRequires: pkgconfig(bluetooth-api)
+BuildRequires: pkgconfig(capi-network-bluetooth)
+BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(capi-base-common)
+
+
+%description
+The dpm-bluetooth package provides bluetooth policy module for device policy manager
+
+%files
+%manifest dpm-bluetooth.manifest
+%defattr(644,root,root,755)
+%attr(755,root,root) /opt/data/dpm/plugins/bluetooth
+%attr(755,root,root) %{_libdir}/libdpm-bluetooth.so.%{version}
+%{_libdir}/libdpm-bluetooth.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-bluetooth-devel
+Summary: Libraries and header files for device policy client development
+Group: Development/Libraries
+Requires: device-policy-manager = %{version}-%{release}
+
+%description -n libdpm-bluetooth-devel
+The libdpm-bluetooth-devel package includes the libraries and header files necessary for
+developing the DPM client program.
+
+%files -n libdpm-bluetooth-devel
+%manifest dpm-bluetooth.manifest
+%defattr(644,root,root,755)
+%{_libdir}/libdpm-bluetooth.so
+%{_libdir}/pkgconfig/dpm-bluetooth.pc
+%{_includedir}/dpm
--- /dev/null
+#
+# 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-bluetooth")
+
+SET(PLUGIN_SOURCES "bluetooth.cpp")
+
+SET(DEPENDENCY klay
+ dpm-pil
+ bluetooth-api
+ capi-network-bluetooth
+)
+
+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-bluetooth.so RENAME bluetooth DESTINATION /opt/data/dpm/plugins)
--- /dev/null
+/*
+ * 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 <bluetooth.h>
+#include <bluetooth-api.h>
+#include <bluetooth_internal.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>
+
+#define BT_FAILED(ret) \
+ (((int)(ret) == BLUETOOTH_DPM_RESULT_ACCESS_DENIED) || \
+ ((int)(ret) == BLUETOOTH_DPM_RESULT_FAIL))
+
+#define POLICY_IS_ALLOWED(enable) \
+ ((int)(enable) ? BLUETOOTH_DPM_ALLOWED : \
+ BLUETOOTH_DPM_RESTRICTED)
+
+#define STATE_CHANGE_IS_ALLOWED(enable) \
+ ((int)(enable) ? BLUETOOTH_DPM_BT_ALLOWED : \
+ BLUETOOTH_DPM_BT_RESTRICTED)
+
+namespace {
+
+inline int canonicalize(int value)
+{
+ return -value;
+}
+
+} // namespace
+
+class ModeChange : public GlobalPolicy<DataSetInt> {
+public:
+ ModeChange() : GlobalPolicy("bluetooth")
+ {
+ PolicyEventNotifier::create("bluetooth");
+ }
+
+ bool apply(const DataType& value)
+ {
+ int ret = bluetooth_dpm_set_allow_mode(STATE_CHANGE_IS_ALLOWED(value));
+ if (!BT_FAILED(ret)) {
+ int enable = value;
+ PolicyEventNotifier::emit("bluetooth", enable ? "allowed" : "disallowed");
+ return true;
+ }
+ return false;
+ }
+};
+
+class DesktopConnectivity : public GlobalPolicy<DataSetInt> {
+public:
+ DesktopConnectivity() : GlobalPolicy("bluetooth-desktop-connectivity")
+ {
+ PolicyEventNotifier::create("bluetooth-desktop-connectivity");
+ }
+
+ bool apply(const DataType & value)
+ {
+ int ret = bluetooth_dpm_set_desktop_connectivity_state(POLICY_IS_ALLOWED(value));
+ if (!BT_FAILED(ret)) {
+ int enable = value;
+ PolicyEventNotifier::emit("bluetooth-desktop-connectivity",
+ enable ? "allowed" : "disallowed");
+ return true;
+ }
+ return false;
+ }
+};
+
+class Pairing: public GlobalPolicy<DataSetInt> {
+public:
+ Pairing() : GlobalPolicy("bluetooth-pairing")
+ {
+ PolicyEventNotifier::create("bluetooth-pairing");
+ }
+
+ bool apply(const DataType& value)
+ {
+ int ret = bluetooth_dpm_set_pairing_state(POLICY_IS_ALLOWED(value));
+ if (!BT_FAILED(ret)) {
+ int enable = value;
+ PolicyEventNotifier::emit("bluetooth-pairing",
+ enable ? "allowed" : "disallowed");
+ return true;
+ }
+ return false;
+ }
+};
+
+class Tethering: public GlobalPolicy<DataSetInt> {
+public:
+ Tethering() : GlobalPolicy("bluetooth-tethering")
+ {
+ PolicyEventNotifier::create("bluetooth-tethering");
+ }
+
+ bool apply(const DataType& value)
+ {
+ int enable = value;
+ PolicyEventNotifier::emit("bluetooth-tethering",
+ enable ? "allowed" : "disallowed");
+ return true;
+ }
+};
+
+class Bluetooth : public AbstractPolicyProvider {
+public:
+ Bluetooth();
+ ~Bluetooth();
+
+ int setModeChangeState(bool enable);
+ bool getModeChangeState();
+ int setDesktopConnectivityState(bool enable);
+ bool getDesktopConnectivityState();
+ int setTetheringState(bool enable);
+ bool getTetheringState();
+ int setPairingState(bool enable);
+ bool getPairingState();
+
+private:
+ static void onStateChanged(int result, bt_adapter_state_e state, void *user_data);
+
+private:
+ ModeChange modeChange;
+ DesktopConnectivity connectivity;
+ Pairing pairing;
+ Tethering tethering;
+};
+
+Bluetooth::Bluetooth()
+{
+ if (::bt_initialize() != BT_ERROR_NONE) {
+ ERROR("Bluetooth framework was not initilaized");
+ return;
+ }
+
+ if (::bt_adapter_set_state_changed_cb(onStateChanged, this) != BT_ERROR_NONE) {
+ ERROR("Failed to register Bluetooth callback");
+ return;
+ }
+}
+
+Bluetooth::~Bluetooth()
+{
+ ::bt_deinitialize();
+}
+
+void Bluetooth::onStateChanged(int result, bt_adapter_state_e state, void *user_data)
+{
+ Bluetooth *pimpl = reinterpret_cast<Bluetooth *>(user_data);
+ if (pimpl != nullptr && state == BT_ADAPTER_ENABLED) {
+// pimpl->modeChange.apply();
+// pimpl->desktopConnectivity.apply();
+// pimpl->pairing.apply();
+// pimpl->deviceRestriction.enforce();
+// pimpl->uuidRestriction.enforce();
+ }
+}
+
+int Bluetooth::setModeChangeState(bool enable)
+{
+ try {
+ modeChange.set(enable);
+ } catch (runtime::Exception& e) {
+ ERROR(e.what());
+ return -1;
+ }
+
+ return 0;
+}
+
+bool Bluetooth::getModeChangeState()
+{
+ return modeChange.get();
+}
+
+int Bluetooth::setDesktopConnectivityState(bool enable)
+{
+ try {
+ connectivity.set(enable);
+ } catch (runtime::Exception& e) {
+ ERROR(e.what());
+ return -1;
+ }
+
+ return 0;
+}
+
+bool Bluetooth::getDesktopConnectivityState()
+{
+ return connectivity.get();
+}
+
+int Bluetooth::setPairingState(bool enable)
+{
+ try {
+ pairing.set(enable);
+ } catch (runtime::Exception& e) {
+ ERROR(e.what());
+ return -1;
+ }
+
+ return 0;
+}
+
+bool Bluetooth::getPairingState()
+{
+ return pairing.get();
+}
+
+int Bluetooth::setTetheringState(bool enable)
+{
+ try {
+ tethering.set(enable);
+ } catch (runtime::Exception& e) {
+ ERROR(e.what());
+ return -1;
+ }
+
+ return 0;
+}
+
+bool Bluetooth::getTetheringState()
+{
+ return tethering.get();
+}
+
+
+extern "C" {
+
+#define PRIVILEGE "http://tizen.org/privilege/dpm.bluetooth"
+
+AbstractPolicyProvider *PolicyFactory(PolicyControlContext& context)
+{
+ Bluetooth *policy = new Bluetooth();
+
+ context.expose(policy, PRIVILEGE, (int)(Bluetooth::setModeChangeState)(bool));
+ context.expose(policy, PRIVILEGE, (int)(Bluetooth::setDesktopConnectivityState)(bool));
+ context.expose(policy, PRIVILEGE, (int)(Bluetooth::setTetheringState)(bool));
+ context.expose(policy, PRIVILEGE, (int)(Bluetooth::setPairingState)(bool));
+
+ context.expose(policy, "", (bool)(Bluetooth::getModeChangeState)());
+ context.expose(policy, "", (bool)(Bluetooth::getDesktopConnectivityState)());
+ context.expose(policy, "", (bool)(Bluetooth::getTetheringState)());
+ context.expose(policy, "", (bool)(Bluetooth::getPairingState)());
+
+ return policy;
+}
+
+} // extern "C"