From 44f98c871429221382cf8720513393da313d5f52 Mon Sep 17 00:00:00 2001 From: Seok Hong Date: Mon, 23 May 2016 11:20:14 +0900 Subject: [PATCH] Add Bluetooth Pairing restriction API Change-Id: I6a5a39333f93f781af54a908bcd9e14634f38f47 Signed-off-by: Seok Hong --- Policies | 1 + libs/bluetooth.cpp | 18 ++++++++++++++++++ libs/dpm/restriction.cpp | 25 +++++++++++++++++++++++++ libs/dpm/restriction.h | 38 ++++++++++++++++++++++++++++++++++++++ policy/bluetooth.hxx | 2 ++ server/bluetooth.cpp | 29 +++++++++++++++++++++++++++++ server/data/PolicyManifest.xml | 2 +- 7 files changed, 114 insertions(+), 1 deletion(-) diff --git a/Policies b/Policies index a1b4cc7..b5b3503 100644 --- a/Policies +++ b/Policies @@ -14,6 +14,7 @@ their operations in some circumstance. | bluetooth | allowed / disallowed | dpm_restriction_get_bluetooth_mode_change_state | | bluetooth-tethering | allowed / disallowed | dpm_restriction_get_bluetooth_tethering_state | | bluetooth-desktop-connectivity | allowed / disallowed | dpm_restriction_get_bluetooth_desktop_connectivity_state | +| bluetooth-pairing | allowed / disallowed | dpm_restriction_get_bluetooth_pairing_state | | bluetooth-device-restriction | allowed / disallowed | dpm_bluetooth_is_device_restricted | | bluetooth-uuid-restriction | allowed / disallowed | dpm_bluetooth_is_uuid_restricted | | usb | allowed / disallowed | dpm_restriction_get_usb_state | diff --git a/libs/bluetooth.cpp b/libs/bluetooth.cpp index f7a8c5e..72efe06 100644 --- a/libs/bluetooth.cpp +++ b/libs/bluetooth.cpp @@ -83,6 +83,24 @@ bool BluetoothPolicy::getTetheringState() } } +int BluetoothPolicy::setPairingState(const bool enable) +{ + try { + return context->methodCall("BluetoothPolicy::setPairingState", enable); + } catch (runtime::Exception &e) { + return -1; + } +} + +bool BluetoothPolicy::getPairingState() +{ + try { + return context->methodCall("BluetoothPolicy::getPairingState"); + } catch (runtime::Exception &e) { + return -1; + } +} + // for bluetooth CAPIs int BluetoothPolicy::addDeviceToBlacklist(const std::string& mac) diff --git a/libs/dpm/restriction.cpp b/libs/dpm/restriction.cpp index db3a4ab..ae3390a 100644 --- a/libs/dpm/restriction.cpp +++ b/libs/dpm/restriction.cpp @@ -350,3 +350,28 @@ int dpm_restriction_get_bluetooth_desktop_connectivity_state(dpm_restriction_pol return DPM_ERROR_NONE; } + +int dpm_restriction_set_bluetooth_pairing_state(dpm_restriction_policy_h handle, int enable) +{ + RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); + + DevicePolicyContext &client = GetDevicePolicyContext(handle); + BluetoothPolicy bluetooth = client.createPolicyInterface(); + return bluetooth.setPairingState(enable); +} + +int dpm_restriction_get_bluetooth_pairing_state(dpm_restriction_policy_h handle, int *enable) +{ + RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(enable, DPM_ERROR_INVALID_PARAMETER); + + DevicePolicyContext &client = GetDevicePolicyContext(handle); + BluetoothPolicy bluetooth = client.createPolicyInterface(); + int ret = bluetooth.getPairingState(); + if (ret < 0) { + return -1; + } + *enable = ret; + + return DPM_ERROR_NONE; +} diff --git a/libs/dpm/restriction.h b/libs/dpm/restriction.h index 2f95baa..fc130dc 100644 --- a/libs/dpm/restriction.h +++ b/libs/dpm/restriction.h @@ -575,6 +575,44 @@ DPM_API int dpm_restriction_set_bluetooth_desktop_connectivity_state(dpm_restric DPM_API int dpm_restriction_get_bluetooth_desktop_connectivity_state(dpm_restriction_policy_h handle, int *enable); /** + * @brief Checks whether the the Bluetooth pairing is restricted. + * @details An administrator can use this API to check whether the Bluetooth pairing is restricted. + * If the Bluetooth pairing is restricted, the UI is grayed out so user can not change its state. + * @since_tizen 3.0 + * @param[in] handle The restriction policy handle + * @param[out] enable TRUE if modification is allowed, + * FALSE if modification is denied + * @return #DPM_ERROR_NONE on success, otherwise a negative value + * @retval #DPM_ERROR_NONE Successful + * @retval #DPM_ERROR_TIMEOUT Time out + * @retval #DPM_ERROR_INVALID_PARAMETER Invalid parameter + * @pre handle must be created by dpm_context_acquire_restriction_policy() + * @see dpm_context_acquire_restriction_policy() + * @see dpm_context_release_restriction_policy() + * @see dpm_restriction_get_bluetooth_pairing_state() + */ +DPM_API int dpm_restriction_set_bluetooth_pairing_state(dpm_restriction_policy_h handle, int enable); + +/** + * @brief Checks whether the the Bluetooth pairing is restricted. + * @details An administrator can use this API to check whether the Bluetooth pairing is restricted. + * If the Bluetooth pairing is restricted, the UI is grayed out so user can not change its state. + * @since_tizen 3.0 + * @param[in] handle The restriction policy handle + * @param[out] enable TRUE if modification is allowed, + * FALSE if modification is denied + * @return #DPM_ERROR_NONE on success, otherwise a negative value + * @retval #DPM_ERROR_NONE Successful + * @retval #DPM_ERROR_TIMEOUT Time out + * @retval #DPM_ERROR_INVALID_PARAMETER Invalid parameter + * @pre handle must be created by dpm_context_acquire_restriction_policy() + * @see dpm_context_acquire_restriction_policy() + * @see dpm_context_release_restriction_policy() + * @see dpm_restriction_set_bluetooth_pairing_state() + */ +DPM_API int dpm_restriction_get_bluetooth_pairing_state(dpm_restriction_policy_h handle, int *enable); + +/** * @} // end of DPM_RESTRICTION_POLICY */ diff --git a/policy/bluetooth.hxx b/policy/bluetooth.hxx index 62fc7f7..ad61845 100644 --- a/policy/bluetooth.hxx +++ b/policy/bluetooth.hxx @@ -39,6 +39,8 @@ public: bool getDesktopConnectivityState(); int setTetheringState(bool enable); bool getTetheringState(); + int setPairingState(const bool enable); + bool getPairingState(); // for bluetooth CAPIs int addDeviceToBlacklist(const std::string& mac); diff --git a/server/bluetooth.cpp b/server/bluetooth.cpp index f4b852d..c80046e 100644 --- a/server/bluetooth.cpp +++ b/server/bluetooth.cpp @@ -63,6 +63,11 @@ void bluetoothAdapterStateChangedCb(int result, bt_adapter_state_e state, void * if (ret != BLUETOOTH_DPM_RESULT_SUCCESS) { // TODO(seok85.hong): we can notify to admin client with this notification. } + ret = policy.setPairingState(IsPolicyAllowed(context, "bluetooth-pairing")); + if (ret != BLUETOOTH_DPM_RESULT_SUCCESS) { + // TODO(seok85.hong): we can notify to admin client with this notification. + } + ret = policy.setDeviceRestriction(IsPolicyEnabled(context, "bluetooth-device-restriction")); if (ret != BLUETOOTH_DPM_RESULT_SUCCESS) { // TODO(seok85.hong): we can notify to admin client with this notification. @@ -89,6 +94,9 @@ BluetoothPolicy::BluetoothPolicy(PolicyControlContext& ctxt) : ctxt.registerNonparametricMethod(this, (bool)(BluetoothPolicy::getDesktopConnectivityState)); ctxt.registerParametricMethod(this, (int)(BluetoothPolicy::setTetheringState)(bool)); ctxt.registerNonparametricMethod(this, (bool)(BluetoothPolicy::getTetheringState)); + ctxt.registerParametricMethod(this, (int)(BluetoothPolicy::setPairingState)(bool)); + ctxt.registerNonparametricMethod(this, (bool)(BluetoothPolicy::getPairingState)); + // for bluetooth CPIs ctxt.registerParametricMethod(this, (int)(BluetoothPolicy::addDeviceToBlacklist)(std::string)); ctxt.registerParametricMethod(this, (int)(BluetoothPolicy::removeDeviceFromBlacklist)(std::string)); @@ -102,6 +110,7 @@ BluetoothPolicy::BluetoothPolicy(PolicyControlContext& ctxt) : ctxt.createNotification("bluetooth"); ctxt.createNotification("bluetooth-tethering"); ctxt.createNotification("bluetooth-desktop-connectivity"); + ctxt.createNotification("bluetooth-pairing"); ctxt.createNotification("bluetooth-uuid-restriction"); ctxt.createNotification("bluetooth-device-restriction"); @@ -164,6 +173,26 @@ bool BluetoothPolicy::getDesktopConnectivityState() return IsPolicyAllowed(context, "bluetooth-desktop-connectivity"); } +int BluetoothPolicy::setPairingState(const bool enable) +{ + int ret = BLUETOOTH_DPM_RESULT_SUCCESS; + ret = bluetooth_dpm_set_pairing_state(enable == true ? BLUETOOTH_DPM_ALLOWED : BLUETOOTH_DPM_RESTRICTED); + if (ret == BLUETOOTH_DPM_RESULT_ACCESS_DENIED || + ret == BLUETOOTH_DPM_RESULT_FAIL) { + return -1; + } + + SetPolicyAllowed(context, "bluetooth-pairing", enable); + + return 0; +} + +bool BluetoothPolicy::getPairingState() +{ + return IsPolicyAllowed(context, "bluetooth-pairing"); +} + + int BluetoothPolicy::addDeviceToBlacklist(const std::string& mac) { int ret = BLUETOOTH_DPM_RESULT_SUCCESS; diff --git a/server/data/PolicyManifest.xml b/server/data/PolicyManifest.xml index 04825a0..41c80ad 100644 --- a/server/data/PolicyManifest.xml +++ b/server/data/PolicyManifest.xml @@ -34,7 +34,7 @@ disabled - allowed + allowed allowed allowed allowed -- 2.7.4