Add Bluetooth Mode Change API 67/68967/21
authorSeok Hong <seok85.hong@samsung.com>
Mon, 16 May 2016 06:09:11 +0000 (15:09 +0900)
committerSeok Hong <seok85.hong@samsung.com>
Mon, 23 May 2016 01:29:43 +0000 (10:29 +0900)
Change-Id: Ide7e9c6ff49ad0a9d98c4b92f213586601338e9b
Signed-off-by: Seok Hong <seok85.hong@samsung.com>
Policies
libs/bluetooth.cpp
libs/dpm/restriction.cpp
libs/dpm/restriction.h
packaging/device-policy-manager.spec
policy/bluetooth.hxx
server/CMakeLists.txt
server/bluetooth.cpp
tools/dpm-cli-toolkit/dpm-cli-toolkit.c
tools/dpm-cli-toolkit/dpm-cli-toolkit.h
tools/dpm-cli-toolkit/restriction.c

index 644ec4e..ceeb4c8 100644 (file)
--- 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                |
index 44aff64..d1d5091 100644 (file)
@@ -28,6 +28,26 @@ BluetoothPolicy::~BluetoothPolicy()
 {
 }
 
+// for restriction CPIs
+int BluetoothPolicy::setModeChangeState(const bool enable)
+{
+    try {
+        return context->methodCall<int>("BluetoothPolicy::setModeChangeState", enable);
+    } catch (runtime::Exception& e) {
+        return -1;
+    }
+}
+
+bool BluetoothPolicy::getModeChangeState()
+{
+    try {
+        return context->methodCall<bool>("BluetoothPolicy::getModeChangeState");
+    } catch (runtime::Exception& e) {
+        return -1;
+    }
+}
+
+// for bluetooth CAPIs
 int BluetoothPolicy::addDeviceToBlacklist(const std::string& mac)
 {
     try {
index a5cabaf..1cb6320 100644 (file)
@@ -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<BluetoothPolicy>(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<BluetoothPolicy>(handle);
+    int ret = bluetooth.getModeChangeState();
+    if (ret < 0) {
+        return -1;
+    }
+    *enable = ret;
+
+    return DPM_ERROR_NONE;
+}
index 363dcc3..19f90c7 100644 (file)
@@ -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
  */
 
index 90c3f54..a755e18 100644 (file)
@@ -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)
index b3c31a7..02d738c 100644 (file)
@@ -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);
index dc36c6a..fa0bc1f 100644 (file)
@@ -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
index c7e499e..47dbcfd 100644 (file)
@@ -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;
index 74afad9..9132048 100644 (file)
@@ -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;
index a493176..9ef28e8 100644 (file)
@@ -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);
index 18bb686..7d1433e 100644 (file)
@@ -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;
+}