Add bluetooth-tethering policy in Restriction Policy 31/69431/2
authorSeok Hong <seok85.hong@samsung.com>
Fri, 13 May 2016 07:23:01 +0000 (16:23 +0900)
committerSeok Hong <seok85.hong@samsung.com>
Fri, 13 May 2016 07:45:16 +0000 (16:45 +0900)
- Add set/getBluetoothTetheringState() APIs in Restriction Policy
  This API just set or get state from PolicyStorage with "bluetooth-tethering"

- Add bluetooth-tethering policy test in dpm_cli_toolkit

Change-Id: Ia4122b37b358dfbcd63cd8401931ae7f55edf912
Signed-off-by: Seok Hong <seok85.hong@samsung.com>
libs/dpm/restriction.cpp
libs/dpm/restriction.h
libs/restriction.cpp
policy/restriction.hxx
server/restriction.cpp
tools/dpm-cli-toolkit/dpm-cli-toolkit.c
tools/dpm-cli-toolkit/dpm-cli-toolkit.h
tools/dpm-cli-toolkit/main.c
tools/dpm-cli-toolkit/restriction.c

index f5518cf..578ff7c 100644 (file)
@@ -237,3 +237,25 @@ int dpm_restriction_get_wifi_hotspot_state(dpm_restriction_policy_h handle, int
     *state = ret;
     return DPM_ERROR_NONE;
 }
+
+int dpm_restriction_set_bluetooth_tethering_state(dpm_restriction_policy_h handle, int enable)
+{
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+
+    RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    return restriction.setBluetoothTetheringState(enable);
+}
+
+int dpm_restriction_get_bluetooth_tethering_state(dpm_restriction_policy_h handle, int *state)
+{
+    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(state, DPM_ERROR_INVALID_PARAMETER);
+
+    RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    int ret = restriction.getBluetoothTetheringState();
+    if (ret < 0) {
+        return -1;
+    }
+    *state = ret;
+    return DPM_ERROR_NONE;
+}
index 666774a..706f6af 100644 (file)
@@ -411,6 +411,48 @@ DPM_API int dpm_restriction_set_wifi_hotspot_state(dpm_restriction_policy_h hand
 DPM_API int dpm_restriction_get_wifi_hotspot_state(dpm_restriction_policy_h handle, int *enable);
 
 /**
+ * @brief       Allows or disallows the user to change Bluetooth tethering settings
+ * @details     An administrator can use this API to restrict changing Bluetooth tethering 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_tethering_state()
+ */
+DPM_API int dpm_restriction_set_bluetooth_tethering_state(dpm_restriction_policy_h handle, int enable);
+
+/**
+ * @brief       Checks whether the the Bluetooth tethering is restricted.
+ * @details     An administrator can use this API to check whether the Bluetooth tethering
+ *              is restricted.
+ *              If the Bluetooth tethering 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_tethering_state()
+ */
+DPM_API int dpm_restriction_get_bluetooth_tethering_state(dpm_restriction_policy_h handle, int *enable);
+
+/**
  * @} // end of DPM_RESTRICTION_POLICY
  */
 
index 838457d..06fd26f 100644 (file)
@@ -192,4 +192,22 @@ bool RestrictionPolicy::getWifiHotspotState()
     }
 }
 
+int RestrictionPolicy::setBluetoothTetheringState(bool enable)
+{
+    try {
+        return context->methodCall<int>("RestrictionPolicy::setBluetoothTetheringState", enable);
+    } catch (runtime::Exception& e) {
+        return -1;
+    }
+}
+
+bool RestrictionPolicy::getBluetoothTetheringState()
+{
+    try {
+        return context->methodCall<bool>("RestrictionPolicy::getBluetoothTetheringState");
+    } catch (runtime::Exception &e) {
+        return -1;
+    }
+}
+
 } //namespace DevicePolicyManager
index 48e118c..5dd6afa 100644 (file)
@@ -56,6 +56,9 @@ public:
        int setWifiHotspotState(bool enable);
        bool getWifiHotspotState();
 
+       int setBluetoothTetheringState(bool enable);
+       bool getBluetoothTetheringState();
+
 private:
        PolicyControlContext& context;
 };
index 099acb7..dbdc816 100644 (file)
@@ -43,6 +43,8 @@ RestrictionPolicy::RestrictionPolicy(PolicyControlContext& ctxt) :
        context.registerNonparametricMethod(this, (bool)(RestrictionPolicy::getWifiState));
        context.registerParametricMethod(this, (int)(RestrictionPolicy::setWifiHotspotState)(bool));
        context.registerNonparametricMethod(this, (bool)(RestrictionPolicy::getWifiHotspotState));
+       context.registerParametricMethod(this, (int)(RestrictionPolicy::setBluetoothTetheringState)(bool));
+       context.registerNonparametricMethod(this, (bool)(RestrictionPolicy::getBluetoothTetheringState));
 
        context.createNotification("camera");
        context.createNotification("clipboard");
@@ -53,6 +55,7 @@ RestrictionPolicy::RestrictionPolicy(PolicyControlContext& ctxt) :
        context.createNotification("usb-debugging");
        context.createNotification("wifi");
        context.createNotification("wifi-hotspot");
+       context.createNotification("bluetooth-tethering");
 }
 
 RestrictionPolicy::~RestrictionPolicy()
@@ -159,6 +162,17 @@ bool RestrictionPolicy::getWifiHotspotState()
        return IsPolicyAllowed(context, "wifi-hotspot");
 }
 
+int RestrictionPolicy::setBluetoothTetheringState(bool enable)
+{
+       SetPolicyAllowed(context, "bluetooth-tethering", enable);
+       return 0;
+}
+
+bool RestrictionPolicy::getBluetoothTetheringState()
+{
+       return IsPolicyAllowed(context, "bluetooth-tethering");
+}
+
 RestrictionPolicy restrictionPolicy(Server::instance());
 
 } // namespace DevicePolicyManager
index 3f22667..4347d49 100644 (file)
@@ -568,3 +568,21 @@ void usb_debugging_policy_handler(int command, int state)
     else
         printf("usb_debugging state: %s\n", state_text[p_state]);
 }
+
+void bluetooth_tethering_policy_handler(int command, int state)
+{
+    int ret = 1;
+    int p_state = 1;
+    char state_text[2][10] = {"DISALLOW", "ALLOW"};
+
+    if (command == 'v') {
+        p_state = state;
+        ret = set_bluetooth_tethering_state_handler(p_state);
+    } else
+        ret = get_bluetooth_tethering_state_handler(&p_state);
+
+    if (ret < 0)
+        printf("bluetooth-tethering policy operation is failed.\n");
+    else
+        printf("bluetooth-tethering state: %s\n", state_text[p_state]);
+}
index 28aba6b..7f45c3e 100644 (file)
@@ -39,6 +39,7 @@ void location_policy_handler(int command, int state);
 void clipboard_policy_handler(int command, int state);
 void settings_policy_handler(int command, int state);
 void usb_debugging_policy_handler(int command, int state);
+void bluetooth_tethering_policy_handler(int command, int state);
 
 int set_password_quality_handler(int password_quality);
 int set_password_min_length_handler(int min_length);
@@ -83,5 +84,7 @@ int set_settings_changes_restriction_handler(int state);
 int get_settings_changes_restriction_handler(int *state);
 int set_usb_debugging_state_handler(int state);
 int get_usb_debugging_state_handler(int *state);
+int set_bluetooth_tethering_state_handler(int state);
+int get_bluetooth_tethering_state_handler(int *state);
 
 #endif /* !__DPM_CLI_TOOLKIT_H__ */
index 554b150..45a3b76 100644 (file)
@@ -134,6 +134,8 @@ void restriction_policy_command_handler(char *policy, int command, int state)
         settings_policy_handler(command, state);
     else if (strcmp(policy, "usb_debugging") == 0)
         usb_debugging_policy_handler(command, state);
+    else if (strcmp(policy, "bluetooth-tethering") == 0)
+        bluetooth_tethering_policy_handler(command, state);
     else {
         printf("Wrong policy name! Please refer to the policy names bleow.\n");
         print_rule();
index fa7821b..e0b91ea 100644 (file)
@@ -441,3 +441,91 @@ out:
     else
         return 0;
 }
+
+int set_bluetooth_tethering_state_handler(int state)
+{
+    dpm_context_h context = NULL;
+    dpm_restriction_policy_h policy = NULL;
+    int ret = 0;
+    int get_value = 0;
+
+    context = dpm_context_create();
+    if (context == NULL) {
+        printf("Failed in dpm_context_create()\n");
+        return -1;
+    }
+
+    policy = dpm_context_acquire_restriction_policy(context);
+    if (policy == NULL) {
+        printf("Failed in dpm_context_acquire_restriction_policy()\n");
+        dpm_context_destroy(context);
+        return -1;
+    }
+
+    if (dpm_restriction_set_bluetooth_tethering_state(policy, state) != 0) {
+        printf("Failed in dpm_restriction_set_bluetooth_tethering_state()\n");
+        ret = -1;
+        goto out;
+    }
+
+    if (dpm_restriction_get_bluetooth_tethering_state(policy, &get_value) < 0) {
+        printf("Failed in dpm_restriction_get_bluetooth_tethering_state()\n");
+        ret = -1;
+        goto out;
+    }
+
+    if (state != get_value) {
+        printf("Failed to set value of restriction\n");
+        ret = -1;
+        goto out;
+    }
+
+out:
+    dpm_context_release_restriction_policy(context, policy);
+    dpm_context_destroy(context);
+
+    if (ret == -1)
+        return ret;
+    else
+        return 0;
+}
+
+int get_bluetooth_tethering_state_handler(int *state)
+{
+    dpm_context_h context = NULL;
+    dpm_restriction_policy_h policy = NULL;
+    int ret = 0;
+
+    context = dpm_context_create();
+    if (context == NULL) {
+        printf("Failed in dpm_context_create()\n");
+        return -1;
+    }
+
+    policy = dpm_context_acquire_restriction_policy(context);
+    if (policy == NULL) {
+        printf("Failed in dpm_context_acquire_restriction_policy()\n");
+        dpm_context_destroy(context);
+        return -1;
+    }
+
+    if (dpm_restriction_get_bluetooth_tethering_state(policy, state) < 0) {
+        printf("Failed in dpm_restriction_get_bluetooth_tethering_state()\n");
+        ret = -1;
+        goto out;
+    }
+
+    if (*state == 1 || *state == 0)
+        ret = 0;
+    else
+        ret = -1;
+
+out:
+    dpm_context_release_restriction_policy(context, policy);
+    dpm_context_destroy(context);
+
+    if (ret == -1)
+        return ret;
+    else
+        return 0;
+}