From: Young-Ae Kang Date: Thu, 15 Oct 2015 06:31:03 +0000 (+0900) Subject: [ACR-476] Added mock location APIs X-Git-Tag: accepted/tizen/mobile/20160122.034841^0 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fapi%2Flocation-manager.git;a=commitdiff_plain;h=2f1343b65fb8ced5fabd1c1e77fc4d1c6cde3d9f [ACR-476] Added mock location APIs Change-Id: I1f4a8932722631acf1ed49f767ccceb6c8e428db --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 1da16b7..d8b258b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) SET(fw_name "capi-location-manager") -PROJECT(${fw_name}) +PROJECT(${fw_name} C) SET(CMAKE_INSTALL_PREFIX /usr) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) diff --git a/include/location_internal.h b/include/location_internal.h old mode 100644 new mode 100755 index 1dd6a7d..cd78239 --- a/include/location_internal.h +++ b/include/location_internal.h @@ -85,6 +85,7 @@ typedef enum { _LOCATION_SIGNAL_LOCATION_UPDATED, _LOCATION_SIGNAL_BATCH_UPDATED, _LOCATION_SIGNAL_ERROR_EMITTED, + _LOCATION_SIGNAL_STATUS_CHANGED, _LOCATION_SIGNAL_NUM } _location_signal_e; diff --git a/include/locations.h b/include/locations.h old mode 100644 new mode 100755 index 746306f..b60ebba --- a/include/locations.h +++ b/include/locations.h @@ -44,8 +44,9 @@ typedef enum { LOCATIONS_ERROR_INCORRECT_METHOD = TIZEN_ERROR_LOCATION_MANAGER | 0x01, /**< Location manager contains incorrect method for a given call */ LOCATIONS_ERROR_NETWORK_FAILED = TIZEN_ERROR_LOCATION_MANAGER | 0x02, /**< Network unavailable */ LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE = TIZEN_ERROR_LOCATION_MANAGER | 0x03, /**< Location service is not available */ - LOCATIONS_ERROR_GPS_SETTING_OFF = TIZEN_ERROR_LOCATION_MANAGER | 0x04, /**< GPS/WPS setting is not enabled */ + LOCATIONS_ERROR_GPS_SETTING_OFF = TIZEN_ERROR_LOCATION_MANAGER | 0x04, /**< Setting for GPS, WPS, or MOCK is turned off */ LOCATIONS_ERROR_SECURITY_RESTRICTED = TIZEN_ERROR_LOCATION_MANAGER | 0x05, /**< Restricted by security system policy */ + LOCATIONS_ERROR_SETTING_OFF = LOCATIONS_ERROR_GPS_SETTING_OFF, /**< Setting for GPS, WPS, or MOCK is turned off (Since 3.0) */ } location_error_e; @@ -58,6 +59,7 @@ 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; /** @@ -255,7 +257,7 @@ int location_manager_is_enabled_method(location_method_e method, bool *enable); /** * @platform - * @brief Enable the given location method. + * @brief Enables the given location method. * @since_tizen 2.3.1 * @privlevel platform * @privilege %http://tizen.org/privilege/location.enable @@ -864,6 +866,73 @@ int location_manager_set_location_changed_cb(location_manager_h manager, locatio int location_manager_unset_location_changed_cb(location_manager_h manager); /** + * @brief Enables mock location. + * @remarks You can enable the mock location when developer mode is enabled. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/location + * @param[in] enable The value to set + * @return 0 on success, otherwise a negative error value + * @retval #LOCATIONS_ERROR_NONE Successful + * @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_set_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] 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] accuracy The horizontal accuracy (meters) + * @return 0 on success, otherwise a negative error value + * @retval #LOCATIONS_ERROR_NONE Successful + * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument + * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available + * @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_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 + * @param[in] manager The location manager handle + * @return 0 on success, otherwise a negative error value + * @retval #LOCATIONS_ERROR_NONE Successful + * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument + * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available + * @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_set_mock_location() + */ +int location_manager_clear_mock_location(location_manager_h manager); + +/** * @} */ diff --git a/packaging/capi-location-manager.spec b/packaging/capi-location-manager.spec old mode 100755 new mode 100644 index 7842f31..bf6e4a0 --- a/packaging/capi-location-manager.spec +++ b/packaging/capi-location-manager.spec @@ -1,6 +1,6 @@ Name: capi-location-manager Summary: A Location Manager library in Tizen Native API -Version: 0.6.3 +Version: 0.7.0 Release: 1 Group: Location/API License: Apache-2.0 diff --git a/src/location_bounds.c b/src/location_bounds.c old mode 100755 new mode 100644 diff --git a/src/location_internal.c b/src/location_internal.c index 5f4d378..5c123ad 100644 --- a/src/location_internal.c +++ b/src/location_internal.c @@ -47,8 +47,8 @@ int __convert_error_code(int code) msg = "LOCATIONS_ERROR_NETWORK_FAILED"; break; case LOCATION_ERROR_SETTING_OFF: - ret = LOCATIONS_ERROR_GPS_SETTING_OFF; - msg = "LOCATIONS_ERROR_GPS_SETTING_OFF"; + ret = LOCATIONS_ERROR_SETTING_OFF; + msg = "LOCATIONS_ERROR_SETTING_OFF"; break; case LOCATION_ERROR_SECURITY_DENIED: ret = LOCATIONS_ERROR_SECURITY_RESTRICTED; diff --git a/src/locations.c b/src/locations.c index 9cbdff0..46e5b13 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_WPS + 1]; +static location_setting_changed_s g_location_setting[LOCATIONS_METHOD_MOCK + 1]; static location_method_e __convert_location_method_e(LocationMethod method) { @@ -56,6 +56,9 @@ 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; @@ -121,23 +124,44 @@ static void __cb_location_updated(GObject *self, int error, gpointer position, g static void __cb_service_enabled(GObject *self, guint status, gpointer userdata) { - LOCATIONS_LOGD("Callback function has been invoked. "); + LOCATIONS_LOGD("Invoked. status = %d", status); location_manager_s *handle = (location_manager_s *) userdata; if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) { ((location_service_state_changed_cb) - handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]); + handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]); } } static void __cb_service_disabled(GObject *self, guint status, gpointer userdata) { - LOCATIONS_LOGD("Callback function has been invoked. "); + LOCATIONS_LOGD("Invoked. status = %d", status); location_manager_s *handle = (location_manager_s *) userdata; - if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) + if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) { ((location_service_state_changed_cb) - handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]); + handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED,handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]); + } } +#if 0 +static void __cb_service_status_changed(GObject *self, guint status, gpointer userdata) +{ + LOCATIONS_LOGD("Invoked. status = %u", status); + location_manager_s *handle = (location_manager_s *) userdata; + + if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) { + if (status == LOCATION_STATUS_2D_FIX || status == LOCATION_STATUS_3D_FIX) + ((location_service_state_changed_cb) + handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]); + else if (status == LOCATION_STATUS_NO_FIX) + ((location_service_state_changed_cb) + handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]); + else if (status == LOCATION_STATUS_MOCK_FAIL) + ((location_service_state_changed_cb) + handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ERROR, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]); + } +} +#endif + static int __compare_position(gconstpointer a, gconstpointer b) { if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE) { @@ -384,7 +408,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_WPS < method) { + if (LOCATIONS_METHOD_HYBRID > method || LOCATIONS_METHOD_MOCK < method) { LOCATIONS_LOGE("Not supported method [%d]", method); return LOCATIONS_ERROR_INCORRECT_METHOD; } @@ -411,7 +435,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_WPS < method) { + if (LOCATIONS_METHOD_HYBRID > method || LOCATIONS_METHOD_MOCK < method) { LOCATIONS_LOGE("Not supported method [%d]", method); return LOCATIONS_ERROR_INCORRECT_METHOD; } @@ -430,7 +454,10 @@ EXPORT_API int location_manager_enable_method(const location_method_e method, co } return LOCATIONS_ERROR_NONE; - } else { + } 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); return LOCATIONS_ERROR_NOT_SUPPORTED; @@ -447,7 +474,6 @@ EXPORT_API int location_manager_enable_method(const location_method_e method, co } } - EXPORT_API int location_manager_create(location_method_e method, location_manager_h *manager) { LOCATIONS_LOGD("location_manager_create (method : %d)", method); @@ -471,6 +497,7 @@ EXPORT_API int location_manager_create(location_method_e method, location_manage LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED); return LOCATIONS_ERROR_NOT_SUPPORTED; } + if (!location_is_supported_method(_method)) { LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED); return LOCATIONS_ERROR_NOT_SUPPORTED; @@ -508,6 +535,11 @@ EXPORT_API int location_manager_create(location_method_e method, location_manage if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle); +#if 0 + if (!handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED]) + handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED] = g_signal_connect(handle->object, "status-changed", G_CALLBACK(__cb_service_status_changed), handle); +#endif + *manager = (location_manager_h) handle; return LOCATIONS_ERROR_NONE; } @@ -519,6 +551,7 @@ 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; @@ -529,6 +562,18 @@ EXPORT_API int location_manager_destroy(location_manager_h manager) handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0; } +#if 0 + if (handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED]) { + g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED]); + handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED] = 0; + } +#endif + + if (handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]) { + g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]); + handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED] = 0; + } + int ret = location_free(handle->object); if (ret != LOCATIONS_ERROR_NONE) { return __convert_error_code(ret); @@ -547,7 +592,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_WPS >= handle->method) { + if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_MOCK >= handle->method) { 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); @@ -611,7 +656,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_WPS >= handle->method) { + if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_MOCK >= handle->method) { 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; @@ -707,13 +752,15 @@ 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(0x%08x) : Out of range (location_method_e) - method : %d ", LOCATIONS_ERROR_INVALID_PARAMETER, method); return LOCATIONS_ERROR_INVALID_PARAMETER; } } - /**method = handle->method; */ return LOCATIONS_ERROR_NONE; } @@ -1360,8 +1407,9 @@ EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h man LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(callback); location_manager_s *handle = (location_manager_s *) manager; - int ret; + int ret = LOCATION_ERROR_NONE; LocationSatellite *last_sat = NULL; + ret = location_get_last_satellite(handle->object, &last_sat); if (ret != LOCATION_ERROR_NONE || last_sat == NULL) { if (ret == LOCATION_ERROR_NOT_SUPPORTED) { @@ -1388,3 +1436,173 @@ EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h man location_satellite_free(last_sat); return LOCATIONS_ERROR_NONE; } + + +/** + * Tizen 3.0 + */ +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); + return __convert_error_code(ret); +} + +EXPORT_API 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) +{ + LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported()); + LOCATIONS_NULL_ARG_CHECK(manager); + + LOCATIONS_CHECK_CONDITION(latitude >= -90 && latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); + LOCATIONS_CHECK_CONDITION(longitude >= -180 && longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); + LOCATIONS_CHECK_CONDITION(direction >= 0 && direction <= 360, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); + + location_manager_s *handle = (location_manager_s *) manager; + int ret = LOCATION_ERROR_NONE; + int enabled; + LocationPosition *pos = NULL; + LocationVelocity *vel = NULL; + LocationAccuracy *acc = NULL; + + ret = location_is_enabled_method(LOCATION_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); + } + + } else { + return __convert_error_code(ret); + } + + pos = location_position_new(0, latitude, longitude, 0, LOCATION_STATUS_3D_FIX); + if (!pos) { + LOCATIONS_LOGE("Failed to create position"); + return LOCATIONS_ERROR_OUT_OF_MEMORY; + } + vel = location_velocity_new(0, speed, direction, 0); + if (!vel) { + LOCATIONS_LOGE("Failed to create volocity"); + return LOCATIONS_ERROR_OUT_OF_MEMORY; + } + + acc = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, accuracy, -1); + if (!vel) { + LOCATIONS_LOGE("Failed to create accuracy"); + return LOCATIONS_ERROR_OUT_OF_MEMORY; + } + + ret = location_set_mock_location(handle->object, pos, vel, acc); + return __convert_error_code(ret); + +} + +EXPORT_API int location_manager_clear_mock_location(location_manager_h manager) +{ + LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported()); + location_manager_s *handle = (location_manager_s *) manager; + int ret = LOCATION_ERROR_NONE; + int enabled; + + ret = location_is_enabled_method(LOCATION_METHOD_MOCK, &enabled); + if (ret == LOCATIONS_ERROR_NONE) { + if (enabled == 0) { + return __convert_error_code(LOCATIONS_ERROR_SETTING_OFF); + } + } else { + return __convert_error_code(ret); + } + + ret = location_clear_mock_location(handle->object); + return __convert_error_code(ret); +} + + +#if 0 +/** + * @brief Gets the state of location service. + * @since_tizen 3.0 + * @param[in] manager The location manager handle + * @param[out] state The current state of location service + * @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_create() + * @see location_manager_set_setting_changed_cb() + * @see location_manager_unset_setting_changed_cb() + */ +int location_manager_get_service_state(location_manager_h manager, location_service_state_e *state); + +EXPORT_API int location_manager_get_service_state(location_manager_h manager, location_service_state_e *state) +{ + LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported()); + LOCATIONS_NULL_ARG_CHECK(manager); + LOCATIONS_NULL_ARG_CHECK(state); + + location_manager_s *handle = (location_manager_s *) manager; + + int service_state = -1; + + int ret = location_get_service_state(handle->object, &service_state); + if (ret != LOCATION_ERROR_NONE) { + if (ret == LOCATION_ERROR_NOT_SUPPORTED) + return LOCATIONS_ERROR_INCORRECT_METHOD; + return __convert_error_code(ret); + } + + switch (service_state) { + case -1: + ret = LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; + *state = LOCATIONS_SERVICE_DISABLED; + break; + case 0: + *state = LOCATIONS_SERVICE_DISABLED; + break; + case 1: + *state = LOCATIONS_SERVICE_ENABLED; + break; + default: + *state = LOCATIONS_SERVICE_ERROR; + break; + + } + + return ret; +} + +EXPORT_API int location_add_test_provider(const LocationMethod method, const int enable) +{ + int ret = 0; + char *_key = NULL; + +#ifndef TIZEN_PROFILE_TV + ret = location_check_privilege(LOCATION_ENABLE_PRIVILEGE); + if (ret != LOCATION_ERROR_NONE) { + LOCATION_LOGE("Cannot use location service for privacy[%d]", ret); + return LOCATION_ERROR_NOT_ALLOWED; + } +#endif + + if (method == LOCATION_METHOD_MOCK) { + _key = __convert_setting_key(method); + if (!_key) { + LOCATION_LOGE("Invalid method[%d]", method); + return LOCATION_ERROR_NOT_SUPPORTED; + } + ret = vconf_set_int(_key, enable); + if (ret != VCONF_OK) { + LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret); + g_free(_key); + return LOCATION_ERROR_NOT_ALLOWED; + } + + g_free(_key); + } + return ret; +} +#endif diff --git a/test/capi-location-manager-test.manifest b/test/capi-location-manager-test.manifest index a76fdba..97e8c31 100755 --- a/test/capi-location-manager-test.manifest +++ b/test/capi-location-manager-test.manifest @@ -1,5 +1,5 @@ - + diff --git a/test/location_test.c b/test/location_test.c index 25dcc3b..01ba706 100755 --- a/test/location_test.c +++ b/test/location_test.c @@ -21,6 +21,8 @@ #include #include #include +#include + static location_manager_h manager; static GMainLoop *g_mainloop = NULL; @@ -274,7 +276,7 @@ static void _state_change_cb(location_service_state_e state, void *user_data) if (ret != LOCATIONS_ERROR_NONE) { fprintf(stderr, " Fail: location_manager_get_position ---> %d \n", ret); } else { - fprintf(stderr, "[%ld] alt: %g, lat %g, long %g\n", timestamp, altitude, latitude, longitude); + fprintf(stderr, "[%ld] lat: %f, lng: %f, alt: %f\n", timestamp, latitude, longitude, altitude); } location_accuracy_level_e level; @@ -284,7 +286,7 @@ static void _state_change_cb(location_service_state_e state, void *user_data) if (ret != LOCATIONS_ERROR_NONE) { fprintf(stderr, " Fail: location_manager_get_accuracy ---> %d \n", ret); } else { - fprintf(stderr, "Level: %d, horizontal: %g, vertical %g\n", level, horizontal, vertical); + fprintf(stderr, "Level: %d, horizontal: %f, vertical %f\n", level, horizontal, vertical); } #if 0 char *nmea; @@ -303,7 +305,7 @@ static void _state_change_cb(location_service_state_e state, void *user_data) void _position_updated_cb(double latitude, double longitude, double altitude, time_t timestamp, void *user_data) { fprintf(stderr, "-------------------------- position updated --------------------------\n"); - fprintf(stderr, "[%ld] lat[%f] lon[%f] alt[%f]\n", timestamp, latitude, longitude, altitude); + fprintf(stderr, "[%ld] lat: %f, lng: %f, alt: %f\n", timestamp, latitude, longitude, altitude); location_manager_h lm = (location_manager_h) user_data; location_accuracy_level_e level; @@ -313,12 +315,12 @@ void _position_updated_cb(double latitude, double longitude, double altitude, ti if (ret != LOCATIONS_ERROR_NONE) { fprintf(stderr, " Fail: location_manager_get_accuracy ---> %d \n", ret); } else { - fprintf(stderr, "Level: %d, horizontal: %g, vertical %g\n", level, horizontal, vertical); + fprintf(stderr, "Level: %d, horizontal: %f, vertical %f\n", level, horizontal, vertical); } repeat_count++; - if (repeat_count > 2) { + if (repeat_count > 9) { test_timer = g_timeout_add_seconds(1, wait_test, NULL); } } @@ -345,7 +347,7 @@ void _location_changed_cb(double latitude, double longitude, double altitude, do repeat_count++; - if (repeat_count > 2) { + if (repeat_count > 5) { test_timer = g_timeout_add_seconds(1, wait_test, NULL); } } @@ -390,7 +392,11 @@ static void print_location_status() fprintf(stderr, "gps: %d, ", is_enabled); location_manager_is_enabled_method(LOCATIONS_METHOD_WPS, &is_enabled); - fprintf(stderr, "wps: %d\n", 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) @@ -407,6 +413,44 @@ static int enable_method(location_method_e method, bool enable) return ret; } +static int test_clear_mock_location(gpointer user_data) +{ + location_manager_h manager = (location_manager_h) user_data; + int ret = 0; + + ret = location_manager_clear_mock_location(manager); + fprintf(stderr, "\n==== location_manager_clear_mock_location: %d ====\n\n", ret); + + /* + int state = 0; + ret = location_manager_get_service_state(manager, &state); + fprintf(stderr, "the current state: %d, ret = %d\n", state, ret); + */ + + return FALSE; +} + + +static int test_set_mock_location(gpointer user_data) +{ + location_manager_h manager = (location_manager_h) user_data; + int ret = 0; + + /* + int state = 0; + ret = location_manager_get_service_state(manager, &state); + fprintf(stderr, "the current state: %d, ret = %d\n", state, ret); + */ + + ret = location_manager_set_mock_location(manager, 20, 20, 0, 40, 50, 100); + fprintf(stderr, "\n==== location_manager_set_location: %d ====\n\n", ret); + if (ret != LOCATIONS_ERROR_NONE) { + g_timeout_add_seconds(3, test_clear_mock_location, manager); + } + + return FALSE; +} + static void print_menu() { fprintf(stderr, "============= LOCATION TEST =============\n"); @@ -422,10 +466,12 @@ static void print_menu() fprintf(stderr, "[22] Distance based location update: LOCATIONS_METHOD_GPS\n"); fprintf(stderr, "[23] Distance based location update: LOCATIONS_METHOD_WPS\n\n"); fprintf(stderr, "[31] Location batch update: LOCATIONS_METHOD_GPS\n\n"); - fprintf(stderr, "[41] Turn on/off method: LOCATIONS_METHOD_HYBRID\n"); - fprintf(stderr, "[42] Turn on/off method: LOCATIONS_METHOD_GPS\n"); - fprintf(stderr, "[43] Turn on/off method: LOCATIONS_METHOD_WPS\n\n"); - fprintf(stderr, "[51] Boundary Test\n\n"); + fprintf(stderr, "[41] Turn on/off mock test: LOCATIONS_METHOD_MOCK\n"); + fprintf(stderr, "[42] Set & Clear location: LOCATIONS_METHOD_HYBRID\n\n"); + fprintf(stderr, "[51] Turn on/off method: LOCATIONS_METHOD_HYBRID\n"); + fprintf(stderr, "[52] Turn on/off method: LOCATIONS_METHOD_GPS\n"); + fprintf(stderr, "[53] Turn on/off method: LOCATIONS_METHOD_WPS\n\n"); + fprintf(stderr, "[61] Boundary Test\n\n"); fprintf(stderr, "[0] Exit!!!\n\n"); fprintf(stderr, "Select menu: "); @@ -529,7 +575,6 @@ static int location_test() fprintf(stderr, " Input batch period ==> "); ret = scanf("%d", &period); - ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager); fprintf(stderr, "location_manager_create (method : %d)\n", LOCATIONS_METHOD_GPS); @@ -540,21 +585,70 @@ static int location_test() fprintf(stderr, "start_batch: %d\n", ret); break; } - case 41: - case 42: - case 43: { - int method = menu - 41; + case 41: { + basic = 1; + int onoff = 1; + + fprintf(stderr, "\n Mock Location (ON: 1 or OFF: 0) Input ==> "); + ret = scanf("%d", &onoff); + + 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_set_mock_location(manager, 10, 20, 0, 40, 50, 100); + fprintf(stderr, "location_manager_set_mock_location: %d\n", ret); + if (ret == LOCATIONS_ERROR_SETTING_OFF) { + fprintf(stderr, "Setting for Mock Location is turned OFF!!!\n"); + break; + } + + ret = location_manager_start(manager); + fprintf(stderr, "start: %d\n", ret); + + g_timeout_add_seconds(3, test_clear_mock_location, manager); + + g_timeout_add_seconds(10, wait_test, NULL); + + break; + } + case 42: { + basic = 1; + + ret = location_manager_create(LOCATIONS_METHOD_HYBRID, &manager); + fprintf(stderr, "location_manager_create (method: %d): %d\n", LOCATIONS_METHOD_HYBRID, ret); + + ret = location_manager_start(manager); + fprintf(stderr, "start: %d\n", ret); + + /* + int state = 0; + ret = location_manager_get_service_state(manager, &state); + fprintf(stderr, "the current state: %d, ret = %d\n", state, ret); + */ + + g_timeout_add_seconds(5, test_set_mock_location, manager); + + break; + } + case 51: + case 52: + case 53: { + int method = menu - 51; int onoff = 1; fprintf(stderr, "\n Input ON: 1 or OFF: 0 ==> "); ret = scanf("%d", &onoff); - ret = enable_method(method, onoff); - fprintf(stderr, "Enabling method: [%d], ret=%d\n", method, ret); + if (onoff == 0 || onoff == 1) { + ret = enable_method(method, onoff); + fprintf(stderr, "Enabling method: [%d], ret=%d\n", method, ret); + } break; } - - case 51: { + case 61: { location_bounds_h hPolyLocationBound = NULL; bool bIsContained = false; int nPolySize = 3; @@ -595,7 +689,7 @@ static int location_test() return 0; } - if (menu < 40) { + if (menu > 0 && menu < 50) { ret = location_manager_set_service_state_changed_cb(manager, _state_change_cb, (void *)manager); fprintf(stderr, "set_service_state_changed_cb: %d\n", ret);