Add location policy test 48/67648/1
authorseolhee, kim <s414.kim@samsung.com>
Thu, 28 Apr 2016 00:50:00 +0000 (09:50 +0900)
committerseolhee, kim <s414.kim@samsung.com>
Thu, 28 Apr 2016 00:50:00 +0000 (09:50 +0900)
Change-Id: Ie1cd08b5f1db4bf84c6cd550fc0138ca12bc2562
Signed-off-by: seolhee, kim <s414.kim@samsung.com>
data/test.xml
src/restriction.c

index 2bfff0c..9b55f16 100644 (file)
@@ -59,7 +59,7 @@
        </policy-group>
 
        <policy-group id="RESTRICTION">
-           <policy id="SET_CAMERA_STATE" desc="Set Camera State" status="ON">
+               <policy id="SET_CAMERA_STATE" desc="Set Camera State" status="ON">
                </policy>
                <policy id="GET_CAMERA_STATE" desc="Get Camera State" status="ON">
                </policy>
                </policy>
                <policy id="GET_MICROPHONE_STATE" desc="Get Microphone State" status="ON">
                </policy>
-               <policy id="ON_CLIPBOARD_RESTRICTION" desc="ENABLE CLIPBOARD_RESTRICTION" status="ON">
+               <policy id="SET_LOCATION_STATE" desc="Set Location State" status="ON">
                </policy>
-               <policy id="OFF_CLIPBOARD_RESTRICTION" desc="DISABLE CLIPBOARD_RESTRICTION" status="ON">
-               </policy>
-               <policy id="ON_CLIPBOARD_SHARE_RESTRICTION" desc="ENABLE CLIPBOARD_SHARE_RESTRICTION" status="ON">
-               </policy>
-               <policy id="OFF_CLIPBOARD_SHARE_RESTRICTION" desc="DISABLE CLIPBOARD_SHARE_RESTRICTION" status="ON">
-               </policy>
-               <policy id="ON_SETTINGS_CHANGES_RESTRICTION" desc="ENABLE SETTINGS_CHANGES_RESTRICTION" status="ON">
-               </policy>
-               <policy id="OFF_SETTINGS_CHANGES_RESTRICTION" desc="DISABLE SETTINGS_CHANGES_RRESTRICTION" status="ON">
-               </policy>
-               <policy id="ON_USB_DEBUGGING_RESTRICTION" desc="ENABLE USB_DEBUGGING_RESTRICTION" status="ON">
-               </policy>
-               <policy id="OFF_USB_DEBUGGING_RESTRICTION" desc="DISABLE USB_DEBUGGING_RESTRICTION" status="ON">
-               </policy>
-               <policy id="ON_USB_MASS_STORAGE_RESTRICTION" desc="ENABLE USB_MASS_STORAGE_RESTRICTION" status="ON">
-               </policy>
-               <policy id="OFF_USB_MASS_STORAGE_RESTRICTION" desc="DISABLE USB_MASS_STORAGE_RESTRICTION" status="ON">
-               </policy>
-               <policy id="ON_FACTORY_RESET_RESTRICTION" desc="ENABLE FACTORY_RESET_RESTRICTION" status="ON">
-               </policy>
-               <policy id="OFF_FACTORY_RESET_RESTRICTION" desc="DISABLE FACTORY_RESET_RESTRICTION" status="ON">
+               <policy id="GET_LOCATION_STATE" desc="Get Location State" status="ON">
                </policy>
        </policy-group>
 
index 966e81c..fa04667 100644 (file)
@@ -3,12 +3,12 @@
 
 /* dpm integration test */
 // ON_SET_CHANGES_RESTRICTION
-int set_camera_state_handler(struct dpm_toolkit_entityself)
+int set_camera_state_handler(struct dpm_toolkit_entity *self)
 {
-    dlog_print(DLOG_DEBUG, LOG_TAG, "set_camera_state_handler");
+       dlog_print(DLOG_DEBUG, LOG_TAG, "set_camera_state_handler");
        dpm_context_h handle;
-    dpm_restriction_policy_h camera_policy_handle;
-       dpm_toolkit_entity_tselected_policy = self;
+       dpm_restriction_policy_h camera_policy_handle;
+       dpm_toolkit_entity_t *selected_policy = self;
        char radio_text[][MAX_RADIO_TEXT_LEN] = {"ENABLE", "DISABLE"};
        int radio_num = sizeof(radio_text) / sizeof(radio_text[0]);
        int enable = 1;
@@ -17,49 +17,49 @@ int set_camera_state_handler(struct dpm_toolkit_entity* self)
 
        dlog_print(DLOG_DEBUG, LOG_TAG, "radio index: %d", selected_policy->radio_index);
 
-       switch(selected_policy->radio_index) {
-               case 0:
-                       enable = 1;
-                       break;
-               case 1:
-                       enable = 0;
-                       break;
-               default:
-                       enable = 1;
-                       break;
-    }
+       switch (selected_policy->radio_index) {
+       case 0:
+               enable = 1;
+               break;
+       case 1:
+               enable = 0;
+               break;
+       default:
+               enable = 1;
+               break;
+       }
 
-    dlog_print(DLOG_DEBUG, LOG_TAG, "Camera State: %d", enable);                       
+       dlog_print(DLOG_DEBUG, LOG_TAG, "Camera State: %d", enable);
 
        handle = dpm_context_create();
        if (handle == NULL) {
                dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device policy context handle");
                return POLICY_RESULT_FAIL;
        }
-       
-    camera_policy_handle = dpm_context_acquire_restriction_policy(handle);
+
+       camera_policy_handle = dpm_context_acquire_restriction_policy(handle);
        if (camera_policy_handle == NULL) {
                dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create camera policy handle");
                return POLICY_RESULT_FAIL;
        }
-       
+
        if (dpm_restriction_set_camera_state(camera_policy_handle, enable) == 0) {
                dpm_context_release_restriction_policy(handle, camera_policy_handle);
                dpm_context_destroy(handle);
                return POLICY_RESULT_SUCCESS;
        }
 
-    dpm_context_release_restriction_policy(handle, camera_policy_handle);
+       dpm_context_release_restriction_policy(handle, camera_policy_handle);
        dpm_context_destroy(handle);
        return POLICY_RESULT_FAIL;
 }
 
-int get_camera_state_handler(struct dpm_toolkit_entityself)
+int get_camera_state_handler(struct dpm_toolkit_entity *self)
 {
        dlog_print(DLOG_DEBUG, LOG_TAG, "get_camera_state_handler");
-    dpm_context_h handle;
+       dpm_context_h handle;
        dpm_restriction_policy_h camera_policy_handle;
-       dpm_toolkit_entity_tselected_policy = self;
+       dpm_toolkit_entity_t *selected_policy = self;
        int state = 1;
        char state_text[2][MAX_RADIO_TEXT_LEN] = {"DISABLE", "ENABLE"};
 
@@ -68,8 +68,8 @@ int get_camera_state_handler(struct dpm_toolkit_entity* self)
                dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device policy context handle");
                return POLICY_RESULT_FAIL;
        }
-       
-    camera_policy_handle = dpm_context_acquire_restriction_policy(handle);
+
+       camera_policy_handle = dpm_context_acquire_restriction_policy(handle);
        if (camera_policy_handle == NULL) {
                dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create camera policy handle");
                return POLICY_RESULT_FAIL;
@@ -82,36 +82,36 @@ int get_camera_state_handler(struct dpm_toolkit_entity* self)
                return POLICY_RESULT_NONE;
        }
 
-    dpm_context_release_restriction_policy(handle, camera_policy_handle);
+       dpm_context_release_restriction_policy(handle, camera_policy_handle);
        dpm_context_destroy(handle);
        return POLICY_RESULT_FAIL;
 }
 
-int set_microphone_state_handler(struct dpm_toolkit_entityself)
+int set_microphone_state_handler(struct dpm_toolkit_entity *self)
 {
        dlog_print(DLOG_DEBUG, LOG_TAG, "set_microphone_state_handler");
        dpm_context_h handle;
-    dpm_restriction_policy_h mic_policy_handle;
-       dpm_toolkit_entity_tselected_policy = self;
+       dpm_restriction_policy_h mic_policy_handle;
+       dpm_toolkit_entity_t *selected_policy = self;
        char radio_text[][MAX_RADIO_TEXT_LEN] = {"ENABLE", "DISABLE"};
        int radio_num = sizeof(radio_text) / sizeof(radio_text[0]);
        int enable = 1;
 
        handler_display_radio_popup((char *)xmlGetProp(selected_policy->model, (xmlChar *) "desc"), selected_policy, radio_text, radio_num);
 
-    dlog_print(DLOG_DEBUG, LOG_TAG, "radio index: %d", selected_policy->radio_index);
-       
-       switch(selected_policy->radio_index) {
-               case 0:
-                       enable = 1;
-                       break;
-               case 1:
-                       enable = 0;
-                       break;
-               default:
-                       enable = 1;
-                       break;
-    }
+       dlog_print(DLOG_DEBUG, LOG_TAG, "radio index: %d", selected_policy->radio_index);
+
+       switch (selected_policy->radio_index) {
+       case 0:
+               enable = 1;
+               break;
+       case 1:
+               enable = 0;
+               break;
+       default:
+               enable = 1;
+               break;
+       }
 
        dlog_print(DLOG_DEBUG, LOG_TAG, "Microphone State: %d", enable);
 
@@ -120,30 +120,30 @@ int set_microphone_state_handler(struct dpm_toolkit_entity* self)
                dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device policy context handle");
                return POLICY_RESULT_FAIL;
        }
-       
-    mic_policy_handle = dpm_context_acquire_restriction_policy(handle);
+
+       mic_policy_handle = dpm_context_acquire_restriction_policy(handle);
        if (mic_policy_handle == NULL) {
                dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create microphone policy handle");
                return POLICY_RESULT_FAIL;
        }
-       
+
        if (dpm_restriction_set_microphone_state(mic_policy_handle, enable) == 0) {
                dpm_context_release_restriction_policy(handle, mic_policy_handle);
                dpm_context_destroy(handle);
                return POLICY_RESULT_SUCCESS;
        }
 
-    dpm_context_release_restriction_policy(handle, mic_policy_handle);
+       dpm_context_release_restriction_policy(handle, mic_policy_handle);
        dpm_context_destroy(handle);
        return POLICY_RESULT_FAIL;
 }
 
-int get_microphone_state_handler(struct dpm_toolkit_entityself)
+int get_microphone_state_handler(struct dpm_toolkit_entity *self)
 {
        dlog_print(DLOG_DEBUG, LOG_TAG, "get_microphone_state_handler");
-    dpm_context_h handle;
+       dpm_context_h handle;
        dpm_restriction_policy_h mic_policy_handle;
-       dpm_toolkit_entity_tselected_policy = self;
+       dpm_toolkit_entity_t *selected_policy = self;
        int state = 1;
        char state_text[2][MAX_RADIO_TEXT_LEN] = {"DISABLE", "ENABLE"};
 
@@ -152,8 +152,8 @@ int get_microphone_state_handler(struct dpm_toolkit_entity* self)
                dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create device policy context handle");
                return POLICY_RESULT_FAIL;
        }
-       
-    mic_policy_handle = dpm_context_acquire_restriction_policy(handle);
+
+       mic_policy_handle = dpm_context_acquire_restriction_policy(handle);
        if (mic_policy_handle == NULL) {
                dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create microphone policy handle");
                return POLICY_RESULT_FAIL;
@@ -166,11 +166,96 @@ int get_microphone_state_handler(struct dpm_toolkit_entity* self)
                return POLICY_RESULT_NONE;
        }
 
-    dpm_context_release_restriction_policy(handle, mic_policy_handle);
+       dpm_context_release_restriction_policy(handle, mic_policy_handle);
        dpm_context_destroy(handle);
        return POLICY_RESULT_FAIL;
 }
 
+int set_location_state_handler(struct dpm_toolkit_entity *self)
+{
+       dpm_context_h ctx = NULL;
+       dpm_restriction_policy_h handle = NULL;
+       dpm_toolkit_entity_t *selected_policy = self;
+       int enable = -1;
+       char radio_text_quality[][MAX_RADIO_TEXT_LEN] = {"ALLOW", "DISALLOW"};
+       int radio_num = sizeof(radio_text_quality) / sizeof(radio_text_quality[0]);
+
+       handler_display_radio_popup((char *)xmlGetProp(selected_policy->model, (xmlChar *)"desc"),
+                                                               selected_policy, radio_text_quality, radio_num);
+
+       ctx = dpm_context_create();
+       if (ctx == NULL) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create dpm context");
+               return POLICY_RESULT_FAIL;
+       }
+
+       handle = dpm_context_acquire_restriction_policy(ctx);
+       if (handle == NULL) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create client handle");
+               dpm_context_destroy(ctx);
+               return POLICY_RESULT_FAIL;
+       }
+
+       switch (selected_policy->radio_index) {
+       case 0:
+               enable = 0;
+               break;
+       case 1:
+               enable = 1;
+               break;
+       default:
+               break;
+       }
+
+       if (dpm_restriction_set_location_state(handle, enable) != 0) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set location state");
+               dpm_context_release_restriction_policy(ctx, handle);
+               dpm_context_destroy(ctx);
+               return POLICY_RESULT_FAIL;
+       }
+
+       dpm_context_release_restriction_policy(ctx, handle);
+       dpm_context_destroy(ctx);
+       return POLICY_RESULT_SUCCESS;
+}
+
+int get_location_state_handler(struct dpm_toolkit_entity *self)
+{
+       dpm_context_h ctx = NULL;
+       dpm_restriction_policy_h handle = NULL;
+       dpm_toolkit_entity_t *selected_policy = self;
+       int location_status = -1;
+       char input[PATH_MAX] = "\0";
+
+       ctx = dpm_context_create();
+       if (ctx == NULL) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create dpm context");
+               return POLICY_RESULT_FAIL;
+       }
+
+       handle = dpm_context_acquire_restriction_policy(ctx);
+       if (handle == NULL) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create client handle");
+               dpm_context_destroy(ctx);
+               return POLICY_RESULT_FAIL;
+       }
+
+       dpm_restriction_get_location_state(handle, &location_status);
+       if (location_status < 0) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get location status");
+               dpm_context_release_restriction_policy(ctx, handle);
+               dpm_context_destroy(ctx);
+               return POLICY_RESULT_FAIL;
+       }
+
+       dpm_context_release_restriction_policy(ctx, handle);
+       dpm_context_destroy(ctx);
+
+       snprintf(input, PATH_MAX, "Location Allow status : %d", location_status);
+       display_result_popup((char *)xmlGetProp(selected_policy->model, (xmlChar *)"desc"), input);
+       return POLICY_RESULT_SUCCESS;
+}
+
 dpm_toolkit_entity_t dpm_toolkit_restriction_policy[] = {
        {
         .id = "SET_CAMERA_STATE",
@@ -187,6 +272,14 @@ dpm_toolkit_entity_t dpm_toolkit_restriction_policy[] = {
        {
         .id = "GET_MICROPHONE_STATE",
         .handler = get_microphone_state_handler
+       },
+       {
+        .id = "SET_LOCATION_STATE",
+        .handler = set_location_state_handler
+       },
+       {
+        .id = "GET_LOCATION_STATE",
+        .handler = get_location_state_handler
        }
 };
 
@@ -208,4 +301,3 @@ void __CONSTRUCTOR__ dpm_toolkit_restriction_policy_constructor()
                dlog_print(DLOG_ERROR, LOG_TAG, "add restriction group fail");
 
 }
-