summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkj7.sung <kj7.sung@samsung.com>2016-07-27 17:01:11 +0900
committerchanywa <cbible.kim@samsung.com>2016-08-17 08:42:45 +0900
commitd75be0e9449f0e3ae949869f21e43724c884ff79 (patch)
treede81b5199c15d55c74c8f1b79a2b71264719acf3
parentb1faccbcd5285bdba0492e1c91b140984c95721f (diff)
downloadlocation-manager-d75be0e9449f0e3ae949869f21e43724c884ff79.tar.gz
location-manager-d75be0e9449f0e3ae949869f21e43724c884ff79.tar.bz2
location-manager-d75be0e9449f0e3ae949869f21e43724c884ff79.zip
Signed-off-by: kj7.sung <kj7.sung@samsung.com> Change-Id: I5f61fc80cc2c3b422747fc94074684fbdf0e2115
-rwxr-xr-xinclude/locations.h42
-rwxr-xr-xsrc/locations.c63
-rwxr-xr-xtest/location_test.c8
3 files changed, 61 insertions, 52 deletions
diff --git a/include/locations.h b/include/locations.h
index a440454..6f1eba6 100755
--- a/include/locations.h
+++ b/include/locations.h
@@ -59,7 +59,6 @@ typedef enum {
LOCATIONS_METHOD_HYBRID, /**< This method selects the best method available at the moment */
LOCATIONS_METHOD_GPS, /**< This method uses Global Positioning System */
LOCATIONS_METHOD_WPS, /**< This method uses WiFi Positioning System */
- LOCATIONS_METHOD_MOCK, /**< This method uses mock location for testing (Since 3.0)*/
} location_method_e;
/**
@@ -905,6 +904,7 @@ int location_manager_unset_location_changed_cb(location_manager_h manager);
* @param[in] callback The callback function to register
* @param[in] batch_interval The batch sampling interval [1 ~ 255] (seconds)
* @param[in] batch_period The batch period [1 ~ 60000] (seconds)
+ * @param[in] user_data The user data to be passed to the callback function
* @return @c 0 on success, otherwise a negative error value
* @retval #LOCATIONS_ERROR_NONE Successful
* @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
@@ -980,7 +980,7 @@ int location_manager_stop_batch(location_manager_h manager);
* @privilege %http://tizen.org/privilege/location
* @param[in] manager The location manager handle
* @param[in] callback The iteration callback function
- * @param[in] user_data The user data passed from the callback registration function
+ * @param[in] user_data The user data to be passed to the callback function
* @return @c 0 on success, otherwise a negative error value
* @retval #LOCATIONS_ERROR_NONE Successful
* @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
@@ -995,8 +995,24 @@ int location_manager_stop_batch(location_manager_h manager);
int location_manager_foreach_location_batch(location_manager_h manager, location_batch_get_location_cb callback, void *user_data);
/**
+ * @brief Checks whether the mock location is enabled.
+ * @since_tizen 3.0
+ * @param[out] enabled Indicates whether the mock location is enabled
+ * @return 0 on success, otherwise a negative error value
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #LOCATIONS_ERROR_NOT_SUPPORTED Not supported
+ * @see location_manager_enable_mock_location()
+ * @see location_manager_set_mock_location()
+ * @see location_manager_clear_mock_location()
+ */
+int location_manager_is_enabled_mock_location(bool *enabled);
+
+/**
* @brief Enables mock location.
- * @remarks You can enable the mock location when developer mode is enabled.
+ * @details The mock location is a testing function to make location API and callback deliver a mock location
+ * set by location_manager_set_mock_location() instead of real positioning data even in the other applications.
+ * @remarks The mock location can only be enabled if developer mode is enabled.
* @since_tizen 3.0
* @privlevel public
* @privilege %http://tizen.org/privilege/location
@@ -1006,25 +1022,24 @@ int location_manager_foreach_location_batch(location_manager_h manager, location
* @retval #LOCATIONS_ERROR_SETTING_OFF MOCK location is not enabled
* @retval #LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED Permission denied
* @retval #LOCATIONS_ERROR_NOT_SUPPORTED Not supported
- * @see location_manager_is_enabled_method()
- * @see location_manager_create()
+ * @see location_manager_is_enabled_mock_location()
* @see location_manager_set_mock_location()
+ * @see location_manager_clear_mock_location()
*/
int location_manager_enable_mock_location(const bool enable);
/**
* @brief Sets a mock location for the given location method.
* @details The location sets the given altitude, latitude, longitude, climb, direction, speed, level, horizontal and vertical accuracy.
- *
* @since_tizen 3.0
* @privlevel public
* @privilege %http://tizen.org/privilege/location
* @param[in] manager The location manager handle
* @param[in] latitude The current latitude [-90.0 ~ 90.0] (degrees)
- * @param[in] longitude The current longitude [-180.0 ~ 180.0] (degrees)
+ * @param[in] longitude The current longitude [-180.0 ~ 180.0] (degrees)
* @param[in] altitude The current altitude (meters)
- * @param[in] speed The speed (km/h)
- * @param[in] direction The direction, degrees from the north [0.0 ~ 360.0]
+ * @param[in] speed The speed (km/h)
+ * @param[in] direction The direction, degrees from the north [0.0 ~ 360.0]
* @param[in] accuracy The horizontal accuracy (meters)
* @return 0 on success, otherwise a negative error value
* @retval #LOCATIONS_ERROR_NONE Successful
@@ -1033,16 +1048,15 @@ int location_manager_enable_mock_location(const bool enable);
* @retval #LOCATIONS_ERROR_SETTING_OFF MOCK location is not enabled
* @retval #LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED The application does not have the privilege to call this method
* @retval #LOCATIONS_ERROR_NOT_SUPPORTED Not supported
- * @see location_manager_is_enabled_method()
- * @see location_manager_enable_mock_location()
* @see location_manager_create()
+ * @see location_manager_is_enabled_mock_location()
+ * @see location_manager_enable_mock_location()
* @see location_manager_clear_mock_location()
*/
int location_manager_set_mock_location(location_manager_h manager, const double latitude, const double longitude, const double altitude, const double speed, const double direction, const double accuracy);
/**
* @brief Clears a mock location.
- *
* @since_tizen 3.0
* @privlevel public
* @privilege %http://tizen.org/privilege/location
@@ -1054,9 +1068,9 @@ int location_manager_set_mock_location(location_manager_h manager, const double
* @retval #LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED The application does not have the privilege to call this method
* @retval #LOCATIONS_ERROR_SETTING_OFF MOCK location is not enabled
* @retval #LOCATIONS_ERROR_NOT_SUPPORTED Not supported
- * @see location_manager_is_enabled_method()
- * @see location_manager_enable_mock_location()
* @see location_manager_create()
+ * @see location_manager_is_enabled_mock_location()
+ * @see location_manager_enable_mock_location()
* @see location_manager_set_mock_location()
*/
int location_manager_clear_mock_location(location_manager_h manager);
diff --git a/src/locations.c b/src/locations.c
index 0cc3859..ff1b7be 100755
--- a/src/locations.c
+++ b/src/locations.c
@@ -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_WPS + 1];
static location_method_e __convert_location_method_e(LocationMethod method)
{
@@ -56,9 +56,6 @@ 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;
- break;
case LOCATIONS_METHOD_NONE:
default:
_method = LOCATION_METHOD_NONE;
@@ -414,7 +411,7 @@ EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool
{
LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
- if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_MOCK) {
+ if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_WPS) {
LOCATIONS_LOGE("Not supported method [%d]", method);
return LOCATIONS_ERROR_INCORRECT_METHOD;
}
@@ -429,6 +426,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;
@@ -440,7 +438,7 @@ EXPORT_API int location_manager_enable_method(const location_method_e method, co
{
LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
- if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_MOCK) {
+ if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_WPS) {
LOCATIONS_LOGE("Not supported method [%d]", method);
return LOCATIONS_ERROR_INCORRECT_METHOD;
}
@@ -459,9 +457,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);
@@ -495,11 +490,6 @@ 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) {
- LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
- return LOCATIONS_ERROR_NOT_SUPPORTED;
- }
}
LocationMethod _method = __convert_LocationMethod(method);
@@ -561,7 +551,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;
@@ -602,7 +591,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 (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_MOCK) {
+ if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_WPS) {
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);
@@ -665,7 +654,7 @@ EXPORT_API int location_manager_stop(location_manager_h manager)
handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
}
- if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_MOCK) {
+ if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_WPS) {
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;
@@ -761,9 +750,6 @@ 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;
- break;
default: {
LOCATIONS_LOGE("[LOCATIONS_ERROR_INVALID_PARAMETER] method : %d ", method);
return LOCATIONS_ERROR_INVALID_PARAMETER;
@@ -784,10 +770,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);
@@ -821,11 +806,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);
@@ -861,10 +845,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);
@@ -1551,13 +1535,29 @@ EXPORT_API int location_manager_foreach_location_batch(location_manager_h manage
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);
}
@@ -1578,7 +1578,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)
@@ -1594,7 +1594,7 @@ 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;
}
@@ -1614,7 +1614,6 @@ EXPORT_API int location_manager_set_mock_location(location_manager_h manager, co
location_accuracy_free(acc);
return __convert_error_code(ret);
-
}
EXPORT_API int location_manager_clear_mock_location(location_manager_h manager)
@@ -1623,10 +1622,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);
diff --git a/test/location_test.c b/test/location_test.c
index e86eca2..2a901ff 100755
--- a/test/location_test.c
+++ b/test/location_test.c
@@ -386,10 +386,6 @@ static void print_location_status()
location_manager_is_enabled_method(LOCATIONS_METHOD_WPS, &is_enabled);
fprintf(stderr, "wps: %d, ", is_enabled);
-
- /* location_manager_is_test_location_enabled(&is_enabled); */
- location_manager_is_enabled_method(LOCATIONS_METHOD_MOCK, &is_enabled);
- fprintf(stderr, "mock: %d\n", is_enabled);
}
static int enable_method(location_method_e method, bool enable)
@@ -592,8 +588,8 @@ static int location_test()
ret = location_manager_enable_mock_location(onoff);
fprintf(stderr, "Enabling mock test: ret=%d\n", ret);
- ret = location_manager_create(LOCATIONS_METHOD_MOCK, &manager);
- fprintf(stderr, "location_manager_create (method: %d): %d\n", LOCATIONS_METHOD_MOCK, ret);
+ ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager);
+ fprintf(stderr, "location_manager_create (method: %d - mock): %d\n", LOCATIONS_METHOD_GPS, ret);
ret = location_manager_set_mock_location(manager, 10, 20, 0, 40, 50, 100);
fprintf(stderr, "location_manager_set_mock_location: %d\n", ret);