[TSAM-7930] 1. Add incorrect method errors for setting_changed_cb
[platform/core/api/location-manager.git] / src / locations.c
index 3b094bf..9313bcf 100755 (executable)
@@ -21,7 +21,7 @@
 #include "locations.h"
 #include "location_internal.h"
 
-static location_setting_changed_s g_location_setting[LOCATIONS_METHOD_MOCK + 1];
+static location_setting_changed_s g_location_setting[LOCATIONS_METHOD_PASSIVE + 1];
 
 static location_method_e __convert_location_method_e(LocationMethod method)
 {
@@ -56,8 +56,8 @@ static LocationMethod __convert_LocationMethod(location_method_e method)
        case LOCATIONS_METHOD_WPS:
                _method = LOCATION_METHOD_WPS;
                break;
-       case LOCATIONS_METHOD_MOCK:
-               _method = LOCATION_METHOD_MOCK;
+       case LOCATIONS_METHOD_PASSIVE:
+               _method = LOCATION_METHOD_PASSIVE;
                break;
        case LOCATIONS_METHOD_NONE:
        default:
@@ -77,24 +77,24 @@ static void __cb_service_updated(GObject *self, guint type, gpointer data, gpoin
                LOCATIONS_LOGD("Current satellite information: timestamp : %d, number of active : %d, number of inview : %d",
                                                sat->timestamp, sat->num_of_sat_used, sat->num_of_sat_inview);
                ((gps_status_satellite_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE])(sat->num_of_sat_used, sat->num_of_sat_inview,
-                               sat->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_SATELLITE]);
+                                                                                       sat->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_SATELLITE]);
        } else if (type == DISTANCE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE]) {
                LocationPosition *pos = (LocationPosition *) data;
                LocationVelocity *vel = (LocationVelocity *) velocity;  /* current velocity */
                ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE])(0, pos->latitude, pos->longitude, pos->altitude,
-                                                                                                                                                               vel->speed, vel->direction, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_DISTANCE]);
+                                                               vel->speed, vel->direction, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_DISTANCE]);
        } else {
 
                if (handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION] && (type & POSITION_UPDATED) != 0) {
                        LocationPosition *pos = (LocationPosition *) data;
-                       ((location_position_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION])(pos->latitude, pos->longitude, pos->altitude, pos->timestamp,
-                                       handle->user_data[_LOCATIONS_EVENT_TYPE_POSITION]);
+                       ((location_position_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION])(pos->latitude, pos->longitude, pos->altitude,
+                                                                                       pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_POSITION]);
                }
 
                if (handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY] && (type & VELOCITY_UPDATED) != 0) {
                        LocationVelocity *vel = (LocationVelocity *) velocity;
-                       ((location_velocity_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY])(vel->speed, vel->direction, vel->climb, vel->timestamp,
-                                       handle->user_data[_LOCATIONS_EVENT_TYPE_VELOCITY]);
+                       ((location_velocity_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY])(vel->speed, vel->direction, vel->climb,
+                                                                                       vel->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_VELOCITY]);
                }
 
                if (handle->user_cb[_LOCATIONS_EVENT_TYPE_POS_VEL] && (type & LOCATION_CHANGED) != 0) {
@@ -102,7 +102,7 @@ static void __cb_service_updated(GObject *self, guint type, gpointer data, gpoin
                        LocationVelocity *vel = (LocationVelocity *) velocity;
                        LocationAccuracy *acc = (LocationAccuracy *) accuracy;
                        ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POS_VEL])(pos->latitude, pos->longitude, pos->altitude,
-                                                                                                                                                                       vel->speed, vel->direction, acc->horizontal_accuracy, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_POS_VEL]);
+                                                                       vel->speed, vel->direction, acc->horizontal_accuracy, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_POS_VEL]);
                }
        }
 }
@@ -122,6 +122,15 @@ static void __cb_location_updated(GObject *self, int error, gpointer position, g
        }
 }
 
+static void __cb_batch_updated(GObject *self, guint num_of_location, gpointer userdata)
+{
+       LOCATIONS_LOGD("Batch callback function has been invoked.");
+       location_manager_s *handle = (location_manager_s *) userdata;
+
+       if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH])
+               ((location_batch_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH])(num_of_location, handle->user_data[_LOCATIONS_EVENT_TYPE_BATCH]);
+}
+
 static void __cb_service_enabled(GObject *self, guint status, gpointer userdata)
 {
        LOCATIONS_LOGD("Invoked. status = %d", status);
@@ -405,7 +414,7 @@ EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool
 {
        LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
 
-       if (LOCATIONS_METHOD_HYBRID > method || LOCATIONS_METHOD_MOCK < method) {
+       if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_WPS) {
                LOCATIONS_LOGE("Not supported method [%d]", method);
                return LOCATIONS_ERROR_INCORRECT_METHOD;
        }
@@ -420,6 +429,7 @@ EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool
                        return LOCATIONS_ERROR_INCORRECT_METHOD;
                return __convert_error_code(ret);
        }
+
        if (is_enabled_val == -1)
                return TIZEN_ERROR_PERMISSION_DENIED;
 
@@ -431,7 +441,7 @@ EXPORT_API int location_manager_enable_method(const location_method_e method, co
 {
        LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
 
-       if (LOCATIONS_METHOD_HYBRID > method || LOCATIONS_METHOD_MOCK < method) {
+       if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_WPS) {
                LOCATIONS_LOGE("Not supported method [%d]", method);
                return LOCATIONS_ERROR_INCORRECT_METHOD;
        }
@@ -450,9 +460,6 @@ EXPORT_API int location_manager_enable_method(const location_method_e method, co
                }
                return LOCATIONS_ERROR_NONE;
 
-       } else if (LOCATIONS_METHOD_MOCK == method) {
-               ret = location_enable_mock(LOCATION_METHOD_MOCK, enable);
-               return __convert_error_code(ret);
        } else  {
                if ((LOCATIONS_METHOD_GPS == method) && (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
                        LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
@@ -486,8 +493,8 @@ EXPORT_API int location_manager_create(location_method_e method, location_manage
                        LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
                        return LOCATIONS_ERROR_NOT_SUPPORTED;
                }
-       } else if (method == LOCATIONS_METHOD_MOCK) {
-               if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
+       } else if (method == LOCATIONS_METHOD_PASSIVE) {
+               if (__is_location_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
                        LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
                        return LOCATIONS_ERROR_NOT_SUPPORTED;
                }
@@ -552,7 +559,6 @@ EXPORT_API int location_manager_destroy(location_manager_h manager)
        LOCATIONS_NULL_ARG_CHECK(manager);
        location_manager_s *handle = (location_manager_s *) manager;
 
-
        if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) {
                g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
                handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0;
@@ -593,7 +599,7 @@ EXPORT_API int location_manager_start(location_manager_h manager)
        if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED])
                handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
 
-       if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_MOCK >= handle->method) {
+       if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_PASSIVE) {
                if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN])
                        handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
 
@@ -637,8 +643,13 @@ EXPORT_API int location_manager_request_single_location(location_manager_h manag
                return ret;
 
        ret = location_request_single_location(handle->object, timeout);
-       if (ret != LOCATION_ERROR_NONE)
+       if (ret != LOCATION_ERROR_NONE) {
+               if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
+                       LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD : method - %d", handle->method);
+                       return LOCATIONS_ERROR_INCORRECT_METHOD;
+               }
                return __convert_error_code(ret);
+       }
 
        return LOCATIONS_ERROR_NONE;
 }
@@ -656,7 +667,7 @@ EXPORT_API int location_manager_stop(location_manager_h manager)
                handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
        }
 
-       if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_MOCK >= handle->method) {
+       if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_PASSIVE) {
                if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) {
                        g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
                        handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0;
@@ -752,8 +763,8 @@ EXPORT_API int location_manager_get_method(location_manager_h manager, location_
        case LOCATION_METHOD_WPS:
                *method = LOCATIONS_METHOD_WPS;
                break;
-       case LOCATION_METHOD_MOCK:
-               *method = LOCATIONS_METHOD_MOCK;
+       case LOCATION_METHOD_PASSIVE:
+               *method = LOCATIONS_METHOD_PASSIVE;
                break;
        default: {
                LOCATIONS_LOGE("[LOCATIONS_ERROR_INVALID_PARAMETER] method : %d ", method);
@@ -775,10 +786,9 @@ EXPORT_API int location_manager_get_position(location_manager_h manager, double
        LOCATIONS_NULL_ARG_CHECK(timestamp);
 
        location_manager_s *handle = (location_manager_s *) manager;
-       int ret;
        LocationPosition *pos = NULL;
        LocationAccuracy *acc = NULL;
-       ret = location_get_position(handle->object, &pos, &acc);
+       int ret = location_get_position(handle->object, &pos, &acc);
        if (ret != LOCATION_ERROR_NONE)
                return __convert_error_code(ret);
 
@@ -812,11 +822,10 @@ EXPORT_API int location_manager_get_location(location_manager_h manager, double
        LOCATIONS_NULL_ARG_CHECK(timestamp);
 
        location_manager_s *handle = (location_manager_s *) manager;
-       int ret;
        LocationPosition *pos = NULL;
        LocationVelocity *vel = NULL;
        LocationAccuracy *acc = NULL;
-       ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
+       int ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
        if (ret != LOCATION_ERROR_NONE)
                return __convert_error_code(ret);
 
@@ -852,10 +861,10 @@ EXPORT_API int location_manager_get_velocity(location_manager_h manager, double
        LOCATIONS_NULL_ARG_CHECK(timestamp);
 
        location_manager_s *handle = (location_manager_s *) manager;
-       int ret;
        LocationVelocity *vel = NULL;
        LocationAccuracy *acc = NULL;
-       ret = location_get_velocity(handle->object, &vel, &acc);
+
+       int ret = location_get_velocity(handle->object, &vel, &acc);
        if (ret != LOCATION_ERROR_NONE)
                return __convert_error_code(ret);
 
@@ -1030,6 +1039,7 @@ EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, lo
 
 EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e *state)
 {
+       dlog_print(DLOG_WARN, LOG_TAG, "DEPRECATION WARNING: location_manager_get_accessibility_state() is deprecated and will be removed from next release.");
        LOCATIONS_LOGD("location_manager_get_accessibility_state");
        LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
        LOCATIONS_NULL_ARG_CHECK(state);
@@ -1174,8 +1184,12 @@ EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method,
        LocationMethod _method = __convert_LocationMethod(method);
        int ret = LOCATION_ERROR_NONE;
 
-       if (_method == LOCATION_METHOD_NONE)
+       if (_method == LOCATION_METHOD_NONE) {
                return __convert_error_code(LOCATION_ERROR_PARAMETER);
+       } else if (_method == LOCATION_METHOD_PASSIVE) {
+               LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
+               return LOCATIONS_ERROR_INCORRECT_METHOD;
+       }
 
        g_location_setting[_method].callback = callback;
        g_location_setting[_method].user_data = user_data;
@@ -1194,8 +1208,12 @@ EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e metho
        LocationMethod _method = __convert_LocationMethod(method);
        int ret = LOCATION_ERROR_NONE;
 
-       if (_method == LOCATION_METHOD_NONE)
+       if (_method == LOCATION_METHOD_NONE) {
                return __convert_error_code(LOCATION_ERROR_PARAMETER);
+       } else if (_method == LOCATION_METHOD_PASSIVE) {
+               LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
+               return LOCATIONS_ERROR_INCORRECT_METHOD;
+       }
 
        ret = location_ignore_setting_notify(_method, __setting_changed_cb);
        if (ret != LOCATION_ERROR_NONE) {
@@ -1433,13 +1451,138 @@ EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h man
 /**
  * Tizen 3.0
  */
+EXPORT_API int location_manager_set_location_batch_cb(location_manager_h manager, location_batch_cb callback, int batch_interval, int batch_period, void *user_data)
+{
+       LOCATIONS_LOGD("location_manager_set_location_batch_cb");
+       LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
+
+       LOCATIONS_CHECK_CONDITION(batch_interval >= 1 && batch_interval <= 255, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
+       LOCATIONS_CHECK_CONDITION(batch_period >= 1 && batch_period <= 60000, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
+       LOCATIONS_CHECK_CONDITION(batch_interval <= batch_period, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
+       LOCATIONS_NULL_ARG_CHECK(manager);
+       LOCATIONS_NULL_ARG_CHECK(callback);
+       location_manager_s *handle = (location_manager_s *) manager;
+       g_object_set(handle->object, "batch-period", batch_period, NULL);
+       g_object_set(handle->object, "batch-interval", batch_interval, NULL);
+       return __set_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager, callback, user_data);
+}
+
+EXPORT_API int location_manager_unset_location_batch_cb(location_manager_h manager)
+{
+       LOCATIONS_LOGD("location_manager_unset_location_batch_cb");
+       LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
+       return __unset_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager);
+}
+
+EXPORT_API int location_manager_start_batch(location_manager_h manager)
+{
+       LOCATIONS_LOGD("location_manager_start_batch");
+       LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
+       LOCATIONS_NULL_ARG_CHECK(manager);
+       location_manager_s *handle = (location_manager_s *) manager;
+
+       if (LOCATIONS_METHOD_GPS == handle->method) {
+               if (!handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED])
+                       handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = g_signal_connect(handle->object, "batch-updated", G_CALLBACK(__cb_batch_updated), handle);
+       } else {
+               LOCATIONS_LOGE("method is not GPS [LOCATIONS_ERROR_INCORRECT_METHOD]");
+               return LOCATIONS_ERROR_INCORRECT_METHOD;
+       }
+
+       if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH] != NULL)
+               LOCATIONS_LOGD("batch status set : Start");
+
+       int ret = location_start_batch(handle->object);
+       if (ret != LOCATION_ERROR_NONE)
+               return __convert_error_code(ret);
+
+       return LOCATIONS_ERROR_NONE;
+}
+
+EXPORT_API int location_manager_stop_batch(location_manager_h manager)
+{
+       LOCATIONS_LOGD("location_manager_stop_batch");
+       LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
+       LOCATIONS_NULL_ARG_CHECK(manager);
+       location_manager_s *handle = (location_manager_s *) manager;
+
+       if (LOCATIONS_METHOD_GPS == handle->method) {
+               if (handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]) {
+                       g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]);
+                       handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = 0;
+               }
+       }
+
+       int ret = location_stop_batch(handle->object);
+       if (ret != LOCATION_ERROR_NONE)
+               return __convert_error_code(ret);
+
+       return LOCATIONS_ERROR_NONE;
+}
+
+EXPORT_API int location_manager_foreach_location_batch(location_manager_h manager, location_batch_get_location_cb callback, void *user_data)
+{
+       LOCATIONS_LOGD("location_manager_foreach_location_batch");
+       LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
+       LOCATIONS_NULL_ARG_CHECK(manager);
+       LOCATIONS_NULL_ARG_CHECK(callback);
+       location_manager_s *handle = (location_manager_s *) manager;
+       LocationBatch *batch = NULL;
+
+       int ret = location_get_batch(handle->object, &batch);
+       if (ret != LOCATION_ERROR_NONE || batch == NULL) {
+               if (ret == LOCATION_ERROR_NOT_ALLOWED) {
+                       LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
+                       return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
+               }
+
+               LOCATIONS_LOGE("Batch is NULL [LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE]");
+               return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
+       }
+
+       int i;
+       for (i = 0; i < batch->num_of_location; i++) {
+               gdouble latitude;
+               gdouble longitude;
+               gdouble altitude;
+               gdouble speed;
+               gdouble direction;
+               gdouble h_accuracy;
+               gdouble v_accuracy;
+               guint timestamp;
+
+               location_get_batch_details(batch, i, &latitude, &longitude, &altitude, &speed, &direction, &h_accuracy, &v_accuracy, &timestamp);
+               if (callback(latitude, longitude, altitude, speed, direction, h_accuracy, v_accuracy, timestamp, user_data) != TRUE)
+                       break;
+       }
+       location_batch_free(batch);
+       batch = NULL;
+       return LOCATIONS_ERROR_NONE;
+}
+
+EXPORT_API int location_manager_is_enabled_mock_location(bool *enabled)
+{
+       LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
+       LOCATIONS_NULL_ARG_CHECK(enabled);
+       int is_enabled_val = -1;
+       int ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &is_enabled_val);
+       if (ret != LOCATION_ERROR_NONE)
+               return __convert_error_code(ret);
+
+       if (is_enabled_val == -1)
+               return TIZEN_ERROR_PERMISSION_DENIED;
+
+       *enabled = (is_enabled_val == 0) ? FALSE : TRUE;
+       return LOCATIONS_ERROR_NONE;
+}
+
 EXPORT_API int location_manager_enable_mock_location(const bool enable)
 {
        LOCATIONS_LOGD("enable: %d", enable);
        LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
        int ret = LOCATION_ERROR_NONE;
 
-       ret = location_enable_mock(LOCATION_METHOD_MOCK, enable);
+       ret = location_enable_mock(enable);
        return __convert_error_code(ret);
 }
 
@@ -1460,7 +1603,7 @@ EXPORT_API int location_manager_set_mock_location(location_manager_h manager, co
        LocationVelocity *vel = NULL;
        LocationAccuracy *acc = NULL;
 
-       ret = location_is_enabled_method(LOCATION_METHOD_MOCK, &enabled);
+       ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &enabled);
        LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
        if (ret == LOCATIONS_ERROR_NONE) {
                if (enabled == 0)
@@ -1476,19 +1619,26 @@ EXPORT_API int location_manager_set_mock_location(location_manager_h manager, co
        }
        vel = location_velocity_new(0, speed, direction, 0);
        if (!vel) {
-               LOCATIONS_LOGE("Failed to create volocity");
+               LOCATIONS_LOGE("Failed to create velocity");
+               location_position_free(pos);
                return LOCATIONS_ERROR_OUT_OF_MEMORY;
        }
 
        acc = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, accuracy, -1);
-       if (!vel) {
+       if (!acc) {
                LOCATIONS_LOGE("Failed to create accuracy");
+               location_position_free(pos);
+               location_velocity_free(vel);
                return LOCATIONS_ERROR_OUT_OF_MEMORY;
        }
 
        ret = location_set_mock_location(handle->object, pos, vel, acc);
-       return __convert_error_code(ret);
 
+       location_position_free(pos);
+       location_velocity_free(vel);
+       location_accuracy_free(acc);
+
+       return __convert_error_code(ret);
 }
 
 EXPORT_API int location_manager_clear_mock_location(location_manager_h manager)
@@ -1497,10 +1647,10 @@ EXPORT_API int location_manager_clear_mock_location(location_manager_h manager)
        LOCATIONS_NULL_ARG_CHECK(manager);
 
        location_manager_s *handle = (location_manager_s *) manager;
-       int ret = LOCATION_ERROR_NONE;
        int enabled;
 
-       ret = location_is_enabled_method(LOCATION_METHOD_MOCK, &enabled);
+       int ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &enabled);
+       LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
        if (ret == LOCATIONS_ERROR_NONE) {
                if (enabled == 0)
                        return __convert_error_code(LOCATION_ERROR_SETTING_OFF);