From: Seok Hong Date: Mon, 16 May 2016 06:09:11 +0000 (+0900) Subject: Add Bluetooth Mode Change API X-Git-Tag: accepted/tizen/common/20160524.150236~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b5b52ba8cd37fb1d0534f8db98f932b1b7bac8c9;p=platform%2Fcore%2Fsecurity%2Fdevice-policy-manager.git Add Bluetooth Mode Change API Change-Id: Ide7e9c6ff49ad0a9d98c4b92f213586601338e9b Signed-off-by: Seok Hong --- diff --git a/Policies b/Policies index 644ec4e..ceeb4c8 100644 --- a/Policies +++ b/Policies @@ -11,7 +11,7 @@ their operations in some circumstance. | wifi-hotspot | allowed / disallowed | dpm_restriction_get_wifi_hotspot | | wifi-profile-change | allowed / disallowed | dpm_wifi_is_profile_change_restricted | | wifi-ssid-restriction | allowed / disallowed | dpm_wifi_is_network_access_restricted | -| bluetooth | allowed / disallowed | dpm_restriction_get_bluetooth_state | +| bluetooth | allowed / disallowed | dpm_restriction_get_bluetooth_mode_change_state | | bluetooth-tethering | allowed / disallowed | dpm_restriction_get_bluetooth_tethering_state | | bluetooth-device-restriction | allowed / disallowed | dpm_bluetooth_is_device_restricted | | bluetooth-uuid-restriction | allowed / disallowed | dpm_bluetooth_is_uuid_restricted | diff --git a/libs/bluetooth.cpp b/libs/bluetooth.cpp index 44aff64..d1d5091 100644 --- a/libs/bluetooth.cpp +++ b/libs/bluetooth.cpp @@ -28,6 +28,26 @@ BluetoothPolicy::~BluetoothPolicy() { } +// for restriction CPIs +int BluetoothPolicy::setModeChangeState(const bool enable) +{ + try { + return context->methodCall("BluetoothPolicy::setModeChangeState", enable); + } catch (runtime::Exception& e) { + return -1; + } +} + +bool BluetoothPolicy::getModeChangeState() +{ + try { + return context->methodCall("BluetoothPolicy::getModeChangeState"); + } catch (runtime::Exception& e) { + return -1; + } +} + +// for bluetooth CAPIs int BluetoothPolicy::addDeviceToBlacklist(const std::string& mac) { try { diff --git a/libs/dpm/restriction.cpp b/libs/dpm/restriction.cpp index a5cabaf..1cb6320 100644 --- a/libs/dpm/restriction.cpp +++ b/libs/dpm/restriction.cpp @@ -16,6 +16,7 @@ #include "restriction.h" #include "restriction.hxx" +#include "bluetooth.hxx" #include "debug.h" #include "policy-client.h" @@ -281,3 +282,26 @@ int dpm_restriction_get_bluetooth_tethering_state(dpm_restriction_policy_h handl *state = ret; return DPM_ERROR_NONE; } + +int dpm_restriction_set_bluetooth_mode_change_state(dpm_restriction_policy_h handle, int enable) +{ + RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); + + BluetoothPolicy& bluetooth = GetPolicyInterface(handle); + return bluetooth.setModeChangeState(enable); +} + +int dpm_restriction_get_bluetooth_mode_change_state(dpm_restriction_policy_h handle, int *enable) +{ + RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(enable, DPM_ERROR_INVALID_PARAMETER); + + BluetoothPolicy& bluetooth = GetPolicyInterface(handle); + int ret = bluetooth.getModeChangeState(); + if (ret < 0) { + return -1; + } + *enable = ret; + + return DPM_ERROR_NONE; +} diff --git a/libs/dpm/restriction.h b/libs/dpm/restriction.h index 363dcc3..19f90c7 100644 --- a/libs/dpm/restriction.h +++ b/libs/dpm/restriction.h @@ -495,6 +495,46 @@ DPM_API int dpm_restriction_set_usb_tethering_state(dpm_restriction_policy_h han DPM_API int dpm_restriction_get_usb_tethering_state(dpm_restriction_policy_h handle, int *enable); /** + * @brief Allows or disallows the user to change Bluetooth settings + * @details An administrator can use this API to restrict changing Bluetooth settings. + * When restricted, the UI is grayed out so the user cannot modify the settings. + * @since_tizen 3.0 + * @param[in] handle The restriction policy handle + * @param[in] enable TRUE to restrict wifi hostspot setting, else FALSE + * @return #DPM_ERROR_NONE on success, otherwise a negative value + * @retval #DPM_ERROR_NONE Successful + * @retval #DPM_ERROR_TIMEOUT Time out + * @retval #DPM_ERROR_NOT_SUPPORTED Not supported + * @retval #DPM_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DPM_ERROR_PERMISSION_DENIED The application does not have + * the privilege to call this API + * @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_mode_change_state() + */ +DPM_API int dpm_restriction_set_bluetooth_mode_change_state(dpm_restriction_policy_h handle, int enable); + +/** + * @brief Checks whether the the Bluetooth is restricted. + * @details An administrator can use this API to check whether the Bluetooth is restricted. + * If the Bluetooth 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_mode_change_state() + */ +DPM_API int dpm_restriction_get_bluetooth_mode_change_state(dpm_restriction_policy_h handle, int *enable); + +/** * @} // end of DPM_RESTRICTION_POLICY */ diff --git a/packaging/device-policy-manager.spec b/packaging/device-policy-manager.spec index 90c3f54..a755e18 100644 --- a/packaging/device-policy-manager.spec +++ b/packaging/device-policy-manager.spec @@ -22,6 +22,7 @@ BuildRequires: pkgconfig(deviced) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(vconf-internal-keys) BuildRequires: pkgconfig(bluetooth-api) +BuildRequires: pkgconfig(capi-network-bluetooth) BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(auth-fw-admin) diff --git a/policy/bluetooth.hxx b/policy/bluetooth.hxx index b3c31a7..02d738c 100644 --- a/policy/bluetooth.hxx +++ b/policy/bluetooth.hxx @@ -32,6 +32,11 @@ public: BluetoothPolicy(PolicyControlContext& ctxt); ~BluetoothPolicy(); + // for restriction CPIs + int setModeChangeState(const bool enable); + bool getModeChangeState(); + + // for bluetooth CAPIs int addDeviceToBlacklist(const std::string& mac); int removeDeviceFromBlacklist(const std::string& mac); int setDeviceRestriction(const bool enable); diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index dc36c6a..fa0bc1f 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -54,6 +54,7 @@ PKG_CHECK_MODULES(SERVER_DEPS deviced libtzplatform-config bluetooth-api + capi-network-bluetooth auth-fw-admin capi-network-wifi capi-system-info diff --git a/server/bluetooth.cpp b/server/bluetooth.cpp index c7e499e..47dbcfd 100644 --- a/server/bluetooth.cpp +++ b/server/bluetooth.cpp @@ -54,6 +54,10 @@ void bluetoothAdapterStateChangedCb(int result, bt_adapter_state_e state, void * // TODO(seok85.hong): "re-enforce-policy" : we can notify to admin client with this notification, // when we should be re-enforced again for the policy that we were failed to set into Bluetooth int ret = BLUETOOTH_DPM_RESULT_SUCCESS; + ret = policy.setModeChangeState(IsPolicyEnabled(context, "bluetooth")); + 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. @@ -72,6 +76,10 @@ namespace DevicePolicyManager { BluetoothPolicy::BluetoothPolicy(PolicyControlContext& ctxt) : context(ctxt) { + // for restriction CPIs + ctxt.registerParametricMethod(this, (int)(BluetoothPolicy::setModeChangeState)(bool)); + ctxt.registerNonparametricMethod(this, (bool)(BluetoothPolicy::getModeChangeState)); + // for bluetooth CPIs ctxt.registerParametricMethod(this, (int)(BluetoothPolicy::addDeviceToBlacklist)(std::string)); ctxt.registerParametricMethod(this, (int)(BluetoothPolicy::removeDeviceFromBlacklist)(std::string)); ctxt.registerParametricMethod(this, (int)(BluetoothPolicy::setDeviceRestriction)(bool)); @@ -102,6 +110,25 @@ BluetoothPolicy::~BluetoothPolicy() bt_deinitialize(); } +int BluetoothPolicy::setModeChangeState(const bool enable) +{ + int ret = BLUETOOTH_DPM_RESULT_SUCCESS; + ret = bluetooth_dpm_set_allow_mode(enable == true ? BLUETOOTH_DPM_BT_ALLOWED : BLUETOOTH_DPM_BT_RESTRICTED); + if (ret == BLUETOOTH_DPM_RESULT_ACCESS_DENIED || + ret == BLUETOOTH_DPM_RESULT_FAIL) { + return -1; + } + + SetPolicyEnabled(context, "bluetooth", enable); + + return 0; +} + +bool BluetoothPolicy::getModeChangeState() +{ + return IsPolicyEnabled(context, "bluetooth"); +} + int BluetoothPolicy::addDeviceToBlacklist(const std::string& mac) { int ret = BLUETOOTH_DPM_RESULT_SUCCESS; diff --git a/tools/dpm-cli-toolkit/dpm-cli-toolkit.c b/tools/dpm-cli-toolkit/dpm-cli-toolkit.c index 74afad9..9132048 100644 --- a/tools/dpm-cli-toolkit/dpm-cli-toolkit.c +++ b/tools/dpm-cli-toolkit/dpm-cli-toolkit.c @@ -68,6 +68,8 @@ void print_menu(int num) printf("6. Remove uuid from blacklist\n"); printf("7. Set uuid restriction\n"); printf("8. Check uuid restriction\n"); + printf("9. Set mode change state\n"); + printf("10. Check mode change state\n"); break; default: break; @@ -446,6 +448,27 @@ void bluetooth_policy_handler(void) printf("UUID Restriction: Allowed\n"); } break; + case 9: + printf("enable(1) or disable(0)> "); + if (scanf("%d", &enable) < 0) { + input_status = -1; + goto out; + } + if ((enable != 0) && (enable != 1)) { + input_status = -1; + goto out; + } + ret = set_mode_change_state_handler(enable); + break; + case 10: + ret = is_mode_change_state_handler(&enable); + if (ret == 0) { + if (enable == 0) + printf("Mode change state: Disallowed\n"); + else + printf("Mode change state: Allowed\n"); + } + break; default: printf("Wrong command!\n"); break; diff --git a/tools/dpm-cli-toolkit/dpm-cli-toolkit.h b/tools/dpm-cli-toolkit/dpm-cli-toolkit.h index a493176..9ef28e8 100644 --- a/tools/dpm-cli-toolkit/dpm-cli-toolkit.h +++ b/tools/dpm-cli-toolkit/dpm-cli-toolkit.h @@ -72,6 +72,8 @@ int add_uuid_to_blacklist_handler(const char *uuid); int remove_uuid_from_blacklist_handler(const char *uuid); int set_uuid_restriction_handler(const int enable); int is_uuid_restricted_handler(int *enable); +int set_mode_change_state_handler(const int enable); +int is_mode_change_state_handler(int *enable); int set_camera_state_handler(int state); int get_camera_state_handler(int *state); diff --git a/tools/dpm-cli-toolkit/restriction.c b/tools/dpm-cli-toolkit/restriction.c index 18bb686..7d1433e 100644 --- a/tools/dpm-cli-toolkit/restriction.c +++ b/tools/dpm-cli-toolkit/restriction.c @@ -617,3 +617,58 @@ out: else return 0; } + +int set_mode_change_state_handler(const int enable) +{ + dpm_context_h context; + context = dpm_context_create(); + if (context == NULL) { + printf("Failed to create client context\n"); + return -1; + } + + dpm_restriction_policy_h policy = dpm_context_acquire_restriction_policy(context); + if (policy == NULL) { + printf("Failed to get restriction policy interface\n"); + dpm_context_destroy(context); + return -1; + } + + if (dpm_restriction_set_bluetooth_mode_change_state(policy, enable) < 0) { + printf("Failed to set mode change state\n"); + dpm_context_release_restriction_policy(context, policy); + dpm_context_destroy(context); + return -1; + } + + return 0; +} + +int is_mode_change_state_handler(int *enable) +{ + dpm_context_h context; + context = dpm_context_create(); + if (context == NULL) { + printf("Failed to create client context\n"); + return -1; + } + + dpm_restriction_policy_h policy = dpm_context_acquire_restriction_policy(context); + if (policy == NULL) { + printf("Failed to get restriction policy interface\n"); + dpm_context_destroy(context); + return -1; + } + + if (dpm_restriction_get_bluetooth_mode_change_state(policy, enable) != DPM_ERROR_NONE) { + printf("Failed to check mode change state\n"); + dpm_context_release_restriction_policy(context, policy); + dpm_context_destroy(context); + return -1; + } + + dpm_context_release_restriction_policy(context, policy); + dpm_context_destroy(context); + + return 0; +}