Add Bluetooth Pairing restriction test 01/70901/6
authorSeok Hong <seok85.hong@samsung.com>
Mon, 23 May 2016 07:36:35 +0000 (16:36 +0900)
committerSeok Hong <seok85.hong@samsung.com>
Thu, 2 Jun 2016 05:31:21 +0000 (14:31 +0900)
Change-Id: I46390e0494797235d5f4bc8b12515c3eada8dbcb
Signed-off-by: Seok Hong <seok85.hong@samsung.com>
data/dpm-toolkit.xml
src/restriction.c

index b82e326..66bc72e 100755 (executable)
@@ -65,6 +65,8 @@
                <policy id="GET_BLUETOOTH_MODE_CHANGE_STATE" desc="Get Bluetooth Mode Change State" status="ON"/>
                <policy id="SET_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE" desc="Set Bluetooth Desktop Connectivity State" status="ON"/>
                <policy id="GET_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE" desc="Get Bluetooth Desktop Connectivity State" status="ON"/>
+               <policy id="SET_BLUETOOTH_PAIRING_STATE" desc="Set Bluetooth Pairing State" status="ON"/>
+               <policy id="GET_BLUETOOTH_PAIRING_STATE" desc="Get Bluetooth Pairing State" status="ON"/>
        </policy-group>
 
        <policy-group id="ZONE" desc="Zone Policy">
index 38a8abe..596cb71 100644 (file)
@@ -1060,6 +1060,87 @@ int get_bluetooth_desktop_connectivity_state_handler(struct xtk_policy *self)
        return POLICY_RESULT_FAIL;
 }
 
+int set_bluetooth_pairing_state_handler(struct xtk_policy *self)
+{
+       int state;
+       int allow;
+       dpm_context_h context = NULL;
+       dpm_restriction_policy_h policy = NULL;
+
+       if (xtk_open_radio_popup(self, STATE_CHANGE_OPTIONS, &allow) == XTK_EVENT_CANCEL) {
+               return POLICY_RESULT_FAIL;
+       }
+
+       context = dpm_context_create();
+       if (context == NULL) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device policy context handle");
+               return POLICY_RESULT_FAIL;
+       }
+
+       policy = dpm_context_acquire_restriction_policy(context);
+       if (policy == NULL) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create usb tethering policy handle");
+               dpm_context_destroy(context);
+               return POLICY_RESULT_FAIL;
+       }
+
+       if (dpm_restriction_set_bluetooth_pairing_state(policy, allow) != 0) {
+               dpm_context_release_restriction_policy(context, policy);
+               dpm_context_destroy(context);
+               return POLICY_RESULT_FAIL;
+       }
+
+       if (dpm_restriction_get_bluetooth_pairing_state(policy, &state) != 0) {
+               dpm_context_release_restriction_policy(context, policy);
+               dpm_context_destroy(context);
+               return POLICY_RESULT_FAIL;
+       }
+
+       if (state == allow) {
+               dpm_context_release_restriction_policy(context, policy);
+               dpm_context_destroy(context);
+               xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
+               return POLICY_RESULT_NONE;
+       }
+
+       dpm_context_release_restriction_policy(context, policy);
+       dpm_context_destroy(context);
+
+       return POLICY_RESULT_FAIL;
+}
+
+int get_bluetooth_pairing_state_handler(struct xtk_policy *self)
+{
+       int state;
+       dpm_context_h context = NULL;
+       dpm_restriction_policy_h policy = NULL;
+
+       context = dpm_context_create();
+       if (context == NULL) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device policy context handle");
+               return POLICY_RESULT_FAIL;
+       }
+
+       policy = dpm_context_acquire_restriction_policy(context);
+       if (policy == NULL) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create usb tethering policy handle");
+               dpm_context_destroy(context);
+               return POLICY_RESULT_FAIL;
+       }
+
+       if (dpm_restriction_get_bluetooth_pairing_state(policy, &state) == 0) {
+               dpm_context_release_restriction_policy(context, policy);
+               dpm_context_destroy(context);
+               xtk_open_message_popup(self, STATE_CHANGE_MESSAGE(state));
+               return POLICY_RESULT_NONE;
+       }
+
+       dpm_context_release_restriction_policy(context, policy);
+       dpm_context_destroy(context);
+
+       return POLICY_RESULT_FAIL;
+}
+
 xtk_policy_t xtk_restriction_policy[] = {
        {
                .id = "SET_CAMERA_STATE",
@@ -1164,6 +1245,14 @@ xtk_policy_t xtk_restriction_policy[] = {
        {
                .id = "GET_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE",
                .handler = get_bluetooth_desktop_connectivity_state_handler
+       },
+       {
+               .id = "SET_BLUETOOTH_PAIRING_STATE",
+               .handler = set_bluetooth_pairing_state_handler
+       },
+       {
+               .id = "GET_BLUETOOTH_PAIRING_STATE",
+               .handler = get_bluetooth_pairing_state_handler
        }
 };