4 * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
7 * Genie Kim <daejins.kim@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
32 #include "location-log.h"
33 #include "location-setting.h"
34 #include "location-ielement.h"
35 #include "location-hybrid.h"
36 #include "location-gps.h"
37 #include "location-wps.h"
38 #include "location-mock.h"
39 #include "location-position.h"
40 #include "module-internal.h"
41 #include "location-common-util.h"
42 #ifndef TIZEN_PROFILE_TV
43 #include "location-privacy.h"
46 #define LOCATION_PRIVILEGE "http://tizen.org/privilege/location"
47 #define LOCATION_ENABLE_PRIVILEGE "http://tizen.org/privilege/location.enable"
49 typedef struct _LocationSetting {
50 LocationSettingCb callback;
54 static LocationSetting g_location_setting;
56 static char *__convert_setting_key(LocationMethod method)
60 case LOCATION_METHOD_HYBRID:
61 key = g_strdup(VCONFKEY_LOCATION_USE_MY_LOCATION);
63 case LOCATION_METHOD_GPS:
64 key = g_strdup(VCONFKEY_LOCATION_ENABLED);
66 case LOCATION_METHOD_WPS:
67 key = g_strdup(VCONFKEY_LOCATION_NETWORK_ENABLED);
69 case LOCATION_METHOD_MOCK:
70 key = g_strdup(VCONFKEY_LOCATION_MOCK_ENABLED);
79 static LocationMethod __convert_method_from_key(const char *key)
81 LocationMethod _method = LOCATION_METHOD_NONE;
82 if (g_strcmp0(key, VCONFKEY_LOCATION_USE_MY_LOCATION) == 0) {
83 _method = LOCATION_METHOD_HYBRID;
84 } else if (g_strcmp0(key, VCONFKEY_LOCATION_ENABLED) == 0) {
85 _method = LOCATION_METHOD_GPS;
86 } else if (g_strcmp0(key, VCONFKEY_LOCATION_NETWORK_ENABLED) == 0) {
87 _method = LOCATION_METHOD_WPS;
88 } else if (g_strcmp0(key, VCONFKEY_LOCATION_MOCK_ENABLED) == 0) {
89 _method = LOCATION_METHOD_MOCK;
95 static void __location_setting_cb(keynode_t *key, gpointer data)
97 if (key == NULL || data == NULL) {
100 LocationSetting *_setting = (LocationSetting *)data;
101 LocationMethod _method = LOCATION_METHOD_NONE;
103 if (_setting->callback) {
104 _method = __convert_method_from_key(vconf_keynode_get_name(key));
105 _setting->callback(_method, location_setting_get_key_val(key), _setting->user_data);
110 int location_init(void)
112 #if !GLIB_CHECK_VERSION(2, 35, 0)
116 #if !GLIB_CHECK_VERSION(2, 31, 0)
117 if (!g_thread_supported()) g_thread_init(NULL);
119 if (FALSE == module_init())
120 return LOCATION_ERROR_NOT_AVAILABLE;
122 #ifndef TIZEN_PROFILE_TV
123 location_privacy_initialize();
126 return LOCATION_ERROR_NONE;
129 EXPORT_API LocationObject *
130 location_new(LocationMethod method)
132 LocationObject *self = NULL;
133 LOCATION_LOGD("method: %d", method);
136 case LOCATION_METHOD_HYBRID:
137 self = g_object_new(LOCATION_TYPE_HYBRID, NULL);
139 case LOCATION_METHOD_GPS:
140 self = g_object_new(LOCATION_TYPE_GPS, NULL);
142 case LOCATION_METHOD_WPS:
143 self = g_object_new(LOCATION_TYPE_WPS, NULL);
145 case LOCATION_METHOD_MOCK:
146 self = g_object_new(LOCATION_TYPE_MOCK, NULL);
151 if (!self) LOCATION_LOGE("Fail to create location object. Method [%d]", method);
156 location_free(LocationObject *obj)
158 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
160 #ifndef TIZEN_PROFILE_TV
161 location_privacy_finalize();
164 return LOCATION_ERROR_NONE;
168 location_request_single_location(LocationObject *obj, int timeout)
170 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
172 int ret = LOCATION_ERROR_NONE;
174 #ifndef TIZEN_PROFILE_TV
175 ret = location_get_privacy(LOCATION_PRIVILEGE);
176 if (ret != LOCATION_ERROR_NONE) {
177 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
178 return LOCATION_ERROR_NOT_ALLOWED;
182 ret = location_ielement_request_single_location(LOCATION_IELEMENT(obj), timeout);
183 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to request single location. Error [%d]", ret);
189 location_start(LocationObject *obj)
191 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
193 int ret = LOCATION_ERROR_NONE;
195 #ifndef TIZEN_PROFILE_TV
196 ret = location_get_privacy(LOCATION_PRIVILEGE);
197 if (ret != LOCATION_ERROR_NONE) {
198 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
199 return LOCATION_ERROR_NOT_ALLOWED;
203 ret = location_ielement_start(LOCATION_IELEMENT(obj));
204 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to start. Error [%d]", ret);
210 location_stop(LocationObject *obj)
212 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
213 int ret = LOCATION_ERROR_NONE;
215 #ifndef TIZEN_PROFILE_TV
216 ret = location_get_privacy(LOCATION_PRIVILEGE);
217 if (ret != LOCATION_ERROR_NONE) {
218 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
219 return LOCATION_ERROR_NOT_ALLOWED;
223 ret = location_ielement_stop(LOCATION_IELEMENT(obj));
224 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to stop. Error [%d]", ret);
230 location_start_batch(LocationObject *obj)
232 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
233 int ret = LOCATION_ERROR_NONE;
235 #ifndef TIZEN_PROFILE_TV
236 ret = location_get_privacy(LOCATION_PRIVILEGE);
237 if (ret != LOCATION_ERROR_NONE) {
238 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
239 return LOCATION_ERROR_NOT_ALLOWED;
243 ret = location_ielement_start_batch(LOCATION_IELEMENT(obj));
244 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to Batch start. Error [%d]", ret);
250 location_stop_batch(LocationObject *obj)
252 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
253 int ret = LOCATION_ERROR_NONE;
255 #ifndef TIZEN_PROFILE_TV
256 ret = location_get_privacy(LOCATION_PRIVILEGE);
257 if (ret != LOCATION_ERROR_NONE) {
258 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
259 return LOCATION_ERROR_NOT_ALLOWED;
263 ret = location_ielement_stop_batch(LOCATION_IELEMENT(obj));
264 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to Batch stop. Error [%d]", ret);
270 location_is_supported_method(LocationMethod method)
272 gboolean is_supported = FALSE;
275 case LOCATION_METHOD_HYBRID:
276 if (module_is_supported("gps") || module_is_supported("wps") || module_is_supported("mock"))
279 case LOCATION_METHOD_GPS:
280 is_supported = module_is_supported("gps");
282 case LOCATION_METHOD_WPS:
283 is_supported = module_is_supported("wps");
285 case LOCATION_METHOD_MOCK:
286 is_supported = module_is_supported("mock");
296 location_is_enabled_method(LocationMethod method, int *is_enabled)
298 g_return_val_if_fail(is_enabled, LOCATION_ERROR_PARAMETER);
300 int vconf_ret = VCONF_ERROR;
302 char *_key = __convert_setting_key(method);
304 LOCATION_LOGE("Invalid method[%d]", method);
305 return LOCATION_ERROR_NOT_SUPPORTED;
308 vconf_ret = vconf_get_int(_key, &vconf_val);
309 if (vconf_ret != VCONF_OK) {
310 LOCATION_SECLOG("failed [%s], error [%d]", _key, vconf_ret);
312 return LOCATION_ERROR_NOT_AVAILABLE;
314 LOCATION_SECLOG("[%s]:[%d]", _key, vconf_val);
317 *is_enabled = vconf_val;
320 return LOCATION_ERROR_NONE;
324 location_enable_method(const LocationMethod method, const int enable)
329 #ifndef TIZEN_PROFILE_TV
330 ret = location_check_privilege(LOCATION_ENABLE_PRIVILEGE);
331 if (ret != LOCATION_ERROR_NONE) {
332 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
333 return LOCATION_ERROR_NOT_ALLOWED;
338 _key = __convert_setting_key(method);
340 LOCATION_LOGE("Invalid method[%d]", method);
341 return LOCATION_ERROR_NOT_SUPPORTED;
343 ret = vconf_set_int(_key, enable);
344 if (ret != VCONF_OK) {
345 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
347 return LOCATION_ERROR_NOT_ALLOWED;
352 _key = __convert_setting_key(LOCATION_METHOD_HYBRID);
354 LOCATION_LOGE("Invalid method[%d]", LOCATION_METHOD_HYBRID);
355 return LOCATION_ERROR_NOT_SUPPORTED;
359 ret = vconf_set_int(_key, enable);
360 if (ret != VCONF_OK) {
361 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
363 return LOCATION_ERROR_NOT_ALLOWED;
367 int enabled_state = 0;
369 for (i = LOCATION_METHOD_GPS; i < LOCATION_METHOD_MAX; i++) {
370 _key = __convert_setting_key(i);
371 enabled_state |= location_setting_get_int(_key);
374 if (!enabled_state) {
375 _key = __convert_setting_key(LOCATION_METHOD_HYBRID);
376 ret = vconf_set_int(_key, enable);
377 if (ret != VCONF_OK) {
378 LOCATION_SECLOG("vconf_set_int failed [%s], error [%d]", _key, ret);
380 return LOCATION_ERROR_NOT_ALLOWED;
382 LOCATION_SECLOG("[%s]:[%d]", _key, ret);
392 location_add_setting_notify(LocationMethod method, LocationSettingCb callback, void *user_data)
394 int ret = LOCATION_ERROR_NONE;
395 char *_key = __convert_setting_key(method);
397 LOCATION_LOGE("Invalid method[%d]", method);
398 return LOCATION_ERROR_PARAMETER;
401 g_location_setting.callback = callback;
402 g_location_setting.user_data = user_data;
404 ret = location_setting_add_notify(_key, __location_setting_cb, &g_location_setting);
411 location_ignore_setting_notify(LocationMethod method, LocationSettingCb callback)
413 int ret = LOCATION_ERROR_NONE;
414 char *_key = __convert_setting_key(method);
416 LOCATION_LOGE("Invalid method[%d]", method);
417 return LOCATION_ERROR_PARAMETER;
420 g_location_setting.callback = NULL;
421 g_location_setting.user_data = NULL;
423 ret = location_setting_ignore_notify(_key, __location_setting_cb);
431 location_get_position(LocationObject *obj,
432 LocationPosition **position,
433 LocationAccuracy **accuracy)
435 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
436 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
437 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
439 int ret = LOCATION_ERROR_NONE;
441 #ifndef TIZEN_PROFILE_TV
442 ret = location_get_privacy(LOCATION_PRIVILEGE);
443 if (ret != LOCATION_ERROR_NONE) {
444 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
445 return LOCATION_ERROR_NOT_ALLOWED;
449 ret = location_ielement_get_position(LOCATION_IELEMENT(obj), position, accuracy);
450 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_position. Error [%d]", ret);
456 location_get_position_ext(LocationObject *obj,
457 LocationPosition **position,
458 LocationVelocity **velocity,
459 LocationAccuracy **accuracy)
461 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
462 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
463 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
464 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
466 int ret = LOCATION_ERROR_NONE;
468 #ifndef TIZEN_PROFILE_TV
469 ret = location_get_privacy(LOCATION_PRIVILEGE);
470 if (ret != LOCATION_ERROR_NONE) {
471 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
472 return LOCATION_ERROR_NOT_ALLOWED;
476 ret = location_ielement_get_position_ext(LOCATION_IELEMENT(obj), position, velocity, accuracy);
477 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_position_ext. Error [%d]", ret);
483 location_get_last_position(LocationObject *obj,
484 LocationPosition **position,
485 LocationAccuracy **accuracy)
487 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
488 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
489 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
491 int ret = LOCATION_ERROR_NONE;
493 #ifndef TIZEN_PROFILE_TV
494 ret = location_get_privacy(LOCATION_PRIVILEGE);
495 if (ret != LOCATION_ERROR_NONE) {
496 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
497 return LOCATION_ERROR_NOT_ALLOWED;
501 ret = location_ielement_get_last_position(LOCATION_IELEMENT(obj), position, accuracy);
502 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_last_position. Error [%d]", ret);
508 location_get_last_position_ext(LocationObject *obj,
509 LocationPosition **position,
510 LocationVelocity **velocity,
511 LocationAccuracy **accuracy)
513 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
514 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
515 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
516 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
518 int ret = LOCATION_ERROR_NONE;
520 #ifndef TIZEN_PROFILE_TV
521 ret = location_get_privacy(LOCATION_PRIVILEGE);
522 if (ret != LOCATION_ERROR_NONE) {
523 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
524 return LOCATION_ERROR_NOT_ALLOWED;
528 ret = location_ielement_get_last_position_ext(LOCATION_IELEMENT(obj), position, velocity, accuracy);
529 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_last_position_ext. Error [%d]", ret);
535 location_get_nmea(LocationObject *obj, char **nmea)
537 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
538 g_return_val_if_fail(nmea, LOCATION_ERROR_PARAMETER);
540 int ret = LOCATION_ERROR_NONE;
542 #ifndef TIZEN_PROFILE_TV
543 ret = location_get_privacy(LOCATION_PRIVILEGE);
544 if (ret != LOCATION_ERROR_NONE) {
545 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
546 return LOCATION_ERROR_NOT_ALLOWED;
550 ret = location_ielement_get_nmea(LOCATION_IELEMENT(obj), nmea);
551 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_nmea. Error [%d]", ret);
558 location_get_satellite(LocationObject *obj, LocationSatellite **satellite)
560 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
561 g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
563 int ret = LOCATION_ERROR_NONE;
565 #ifndef TIZEN_PROFILE_TV
566 ret = location_get_privacy(LOCATION_PRIVILEGE);
567 if (ret != LOCATION_ERROR_NONE) {
568 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
569 return LOCATION_ERROR_NOT_ALLOWED;
573 ret = location_ielement_get_satellite(LOCATION_IELEMENT(obj), satellite);
574 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_satellite. Error [%d]", ret);
580 location_get_batch(LocationObject *obj, LocationBatch **batch)
582 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
583 g_return_val_if_fail(batch, LOCATION_ERROR_PARAMETER);
585 int ret = LOCATION_ERROR_NONE;
587 #ifndef TIZEN_PROFILE_TV
588 ret = location_get_privacy(LOCATION_PRIVILEGE);
589 if (ret != LOCATION_ERROR_NONE) {
590 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
591 return LOCATION_ERROR_NOT_ALLOWED;
595 ret = location_ielement_get_batch(LOCATION_IELEMENT(obj), batch);
596 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_batch. Error [%d]", ret);
602 location_get_last_satellite(LocationObject *obj, LocationSatellite **satellite)
604 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
605 g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
607 int ret = LOCATION_ERROR_NONE;
609 #ifndef TIZEN_PROFILE_TV
610 ret = location_get_privacy(LOCATION_PRIVILEGE);
611 if (ret != LOCATION_ERROR_NONE) {
612 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
613 return LOCATION_ERROR_NOT_ALLOWED;
617 ret = location_ielement_get_last_satellite(LOCATION_IELEMENT(obj), satellite);
618 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_last_satellite. Error [%d]", ret);
624 location_get_velocity(LocationObject *obj,
625 LocationVelocity **velocity,
626 LocationAccuracy **accuracy)
628 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
629 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
630 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
632 int ret = LOCATION_ERROR_NONE;
634 #ifndef TIZEN_PROFILE_TV
635 ret = location_get_privacy(LOCATION_PRIVILEGE);
636 if (ret != LOCATION_ERROR_NONE) {
637 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
638 return LOCATION_ERROR_NOT_ALLOWED;
642 ret = location_ielement_get_velocity(LOCATION_IELEMENT(obj), velocity, accuracy);
643 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_velocity. Error [%d]", ret);
649 location_get_last_velocity(LocationObject *obj,
650 LocationVelocity **velocity,
651 LocationAccuracy **accuracy)
653 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
654 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
655 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
657 int ret = LOCATION_ERROR_NONE;
659 #ifndef TIZEN_PROFILE_TV
660 ret = location_get_privacy(LOCATION_PRIVILEGE);
661 if (ret != LOCATION_ERROR_NONE) {
662 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
663 return LOCATION_ERROR_NOT_ALLOWED;
667 ret = location_ielement_get_last_velocity(LOCATION_IELEMENT(obj), velocity, accuracy);
668 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_last_velocity. Error [%d]", ret);
674 location_get_accessibility_state(LocationAccessState *state)
676 int auth = location_application_get_authority();
678 case LOCATION_APP_OFF:
679 *state = LOCATION_ACCESS_DENIED;
681 case LOCATION_APP_ON:
682 *state = LOCATION_ACCESS_ALLOWED;
684 case LOCATION_APP_NOT_FOUND:
685 *state = LOCATION_ACCESS_NONE;
688 return LOCATION_ERROR_UNKNOWN;
691 LOCATION_LOGD("get_accessibility_state [%d]", auth);
692 return LOCATION_ERROR_NONE;
696 location_set_accessibility_state(LocationAccessState state)
698 int auth = LOCATION_APP_NOT_FOUND;
699 int ret = LOCATION_ERROR_NONE;
702 case LOCATION_ACCESS_DENIED:
703 auth = LOCATION_APP_OFF;
705 case LOCATION_ACCESS_ALLOWED:
706 auth = LOCATION_APP_ON;
708 case LOCATION_ACCESS_NONE:
710 return LOCATION_ERROR_PARAMETER;
713 ret = location_application_set_authority(auth);
714 LOCATION_LOGD("set_accessibility_state [%d], Error[%d]", auth, ret);
719 location_send_command(const char *cmd)
721 g_return_val_if_fail(cmd, LOCATION_ERROR_PARAMETER);
722 return LOCATION_ERROR_NOT_AVAILABLE;
726 location_set_option(LocationObject *obj, const char *option)
728 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
729 int ret = LOCATION_ERROR_NONE;
731 #ifndef TIZEN_PROFILE_TV
732 ret = location_get_privacy(LOCATION_PRIVILEGE);
733 if (ret != LOCATION_ERROR_NONE) {
734 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
735 return LOCATION_ERROR_NOT_ALLOWED;
739 ret = location_ielement_set_option(LOCATION_IELEMENT(obj), option);
740 if (ret != LOCATION_ERROR_NONE)
741 LOCATION_LOGE("Fail to get_velocity. Error [%d]", ret);
751 location_get_service_state(LocationObject *obj, int *state)
753 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
754 g_return_val_if_fail(state, LOCATION_ERROR_PARAMETER);
756 int ret = LOCATION_ERROR_NONE;
758 #ifndef TIZEN_PROFILE_TV
759 ret = location_get_privacy(LOCATION_PRIVILEGE);
760 if (ret != LOCATION_ERROR_NONE) {
761 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
762 return LOCATION_ERROR_NOT_ALLOWED;
766 ret = location_ielement_get_status(LOCATION_IELEMENT(obj), state);
767 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_position. Error [%d]", ret);
774 location_enable_mock(const LocationMethod method, const int enable)
779 if (method != LOCATION_METHOD_MOCK) {
780 return LOCATION_ERROR_PARAMETER;
783 #ifndef TIZEN_PROFILE_TV
784 ret = location_check_privilege(LOCATION_PRIVILEGE);
785 if (ret != LOCATION_ERROR_NONE) {
786 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
787 return LOCATION_ERROR_NOT_ALLOWED;
791 #if 0 /* Tizen platform didn't turn developer option on */
792 gboolean developer_option = FALSE;
794 ret = vconf_get_bool(VCONFKEY_SETAPPL_DEVELOPER_OPTION_STATE, &developer_option);
795 if (!developer_option) {
796 LOCATION_LOGE("Cannot enable mock location because developer option is not turned on", ret);
797 return LOCATION_ERROR_NOT_ALLOWED;
801 _key = __convert_setting_key(method);
803 LOCATION_LOGE("Invalid method[%d]", method);
804 return LOCATION_ERROR_NOT_SUPPORTED;
806 ret = vconf_set_int(_key, enable);
807 if (ret != VCONF_OK) {
808 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
810 return LOCATION_ERROR_NOT_ALLOWED;
819 static char *__convert_mock_setting_key(LocationMethod method)
823 case LOCATION_METHOD_MOCK_GPS:
824 key = g_strdup(VCONFKEY_LOCATION_MOCK_GPS_ENABLED);
826 case LOCATION_METHOD_MOCK_WPS:
827 key = g_strdup(VCONFKEY_LOCATION_MOCK_NETWORK_ENABLED);
836 location_set_mock_method_enabled(const LocationMethod method, const int enable)
842 _key = __convert_setting_key(method);
844 LOCATION_LOGE("Invalid method[%d]", method);
845 return LOCATION_ERROR_NOT_SUPPORTED;
848 ret = vconf_get_int(_key, &vconf_val);
849 if (ret != VCONF_OK) {
850 LOCATION_SECLOG("failed [%s], error [%d]", _key, ret);
852 return LOCATION_ERROR_NOT_ALLOWED;
856 _key = __convert_mock_setting_key(method);
858 LOCATION_LOGE("Invalid method[%d]", method);
859 return LOCATION_ERROR_NOT_SUPPORTED;
861 ret = vconf_set_int(_key, enable);
862 if (ret != VCONF_OK) {
863 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
865 return LOCATION_ERROR_NOT_ALLOWED;
876 location_set_mock_location(LocationObject *obj, const LocationPosition *position, const LocationVelocity *velocity, const LocationAccuracy *accuracy)
878 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
879 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
880 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
881 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
883 int ret = LOCATION_ERROR_NONE;
885 #ifndef TIZEN_PROFILE_TV
886 ret = location_get_privacy(LOCATION_PRIVILEGE);
887 if (ret != LOCATION_ERROR_NONE) {
888 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
889 return LOCATION_ERROR_NOT_ALLOWED;
893 ret = location_ielement_set_mock_location(LOCATION_IELEMENT(obj), position, velocity, accuracy);
894 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to location_ielement_set_mock_location. Error [%d]", ret);
900 location_clear_mock_location(LocationObject *obj)
902 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
904 int ret = LOCATION_ERROR_NONE;
906 #ifndef TIZEN_PROFILE_TV
907 ret = location_get_privacy(LOCATION_PRIVILEGE);
908 if (ret != LOCATION_ERROR_NONE) {
909 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
910 return LOCATION_ERROR_NOT_ALLOWED;
914 ret = location_ielement_clear_mock_location(LOCATION_IELEMENT(obj));
915 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to location_ielement_set_mock_location. Error [%d]", ret);