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.
31 #include "location-log.h"
32 #include "location-setting.h"
33 #include "location-ielement.h"
34 #include "location-hybrid.h"
35 #include "location-gps.h"
36 #include "location-wps.h"
37 #include "location-passive.h"
38 #include "location-position.h"
39 #include "module-internal.h"
40 #include "location-common-util.h"
41 #ifndef TIZEN_PROFILE_TV
42 #include "location-privacy.h"
45 #define LOCATION_PRIVILEGE "http://tizen.org/privilege/location"
46 #define LOCATION_ENABLE_PRIVILEGE "http://tizen.org/privilege/location.enable"
49 typedef struct _LocationSetting {
50 LocationSettingCb callback;
63 static LocationSetting g_location_setting;
64 static bool is_method_created[_METHOD_MAX] = {false};
66 static char *__convert_setting_key(LocationMethod method)
70 case LOCATION_METHOD_HYBRID:
71 key = g_strdup(VCONFKEY_LOCATION_USE_MY_LOCATION);
73 case LOCATION_METHOD_GPS:
74 key = g_strdup(VCONFKEY_LOCATION_ENABLED);
76 case LOCATION_METHOD_WPS:
77 key = g_strdup(VCONFKEY_LOCATION_NETWORK_ENABLED);
79 case INTERNAL_METHOD_MOCK:
80 key = g_strdup(VCONFKEY_LOCATION_MOCK_ENABLED);
89 static LocationMethod __convert_method_from_key(const char *key)
91 LocationMethod _method = LOCATION_METHOD_NONE;
92 if (g_strcmp0(key, VCONFKEY_LOCATION_USE_MY_LOCATION) == 0)
93 _method = LOCATION_METHOD_HYBRID;
94 else if (g_strcmp0(key, VCONFKEY_LOCATION_ENABLED) == 0)
95 _method = LOCATION_METHOD_GPS;
96 else if (g_strcmp0(key, VCONFKEY_LOCATION_NETWORK_ENABLED) == 0)
97 _method = LOCATION_METHOD_WPS;
102 static void __location_setting_cb(keynode_t *key, gpointer data)
104 if (key == NULL || data == NULL)
107 LocationSetting *_setting = (LocationSetting *)data;
108 LocationMethod _method = LOCATION_METHOD_NONE;
110 if (_setting->callback) {
111 _method = __convert_method_from_key(vconf_keynode_get_name(key));
112 _setting->callback(_method, location_setting_get_key_val(key), _setting->user_data);
117 int location_init(void)
119 #if !GLIB_CHECK_VERSION(2, 35, 0)
123 #if !GLIB_CHECK_VERSION(2, 31, 0)
124 if (!g_thread_supported()) g_thread_init(NULL);
126 if (FALSE == module_init())
127 return LOCATION_ERROR_NOT_AVAILABLE;
129 return LOCATION_ERROR_NONE;
132 EXPORT_API LocationObject *
133 location_new(LocationMethod method, gboolean is_internal_for_hybrid)
135 LocationObject *self = NULL;
136 LOCATION_LOGD("method : %d, is_internal_for_hybrid[%d]", method, is_internal_for_hybrid);
139 case LOCATION_METHOD_HYBRID:
140 if (is_method_created[_METHOD_HYBRID]) {
141 LOCATION_LOGE("Hybrid handle already exist.");
143 self = g_object_new(LOCATION_TYPE_HYBRID, NULL);
144 is_method_created[_METHOD_HYBRID] = true;
147 case LOCATION_METHOD_GPS:
148 if (is_internal_for_hybrid) {
149 if (is_method_created[_METHOD_GPS_2]) {
150 LOCATION_LOGD("Hybrid(GPS) handle already exist.");
152 is_method_created[_METHOD_GPS_2] = true;
153 self = g_object_new(LOCATION_TYPE_GPS, NULL);
156 if (is_method_created[_METHOD_GPS_1]) {
157 LOCATION_LOGE("GPS handle already exist.");
159 is_method_created[_METHOD_GPS_1] = true;
160 self = g_object_new(LOCATION_TYPE_GPS, NULL);
164 case LOCATION_METHOD_WPS:
165 if (is_internal_for_hybrid) {
166 if (is_method_created[_METHOD_WPS_2]) {
167 LOCATION_LOGD("Hybrid(WPS) handle already exist.");
169 is_method_created[_METHOD_WPS_2] = true;
170 self = g_object_new(LOCATION_TYPE_WPS, NULL);
173 if (is_method_created[_METHOD_WPS_1]) {
174 LOCATION_LOGE("WPS handle already exist.");
176 is_method_created[_METHOD_WPS_1] = true;
177 self = g_object_new(LOCATION_TYPE_WPS, NULL);
181 case LOCATION_METHOD_PASSIVE:
182 self = g_object_new(LOCATION_TYPE_PASSIVE, NULL);
188 LOC_COND_LOG(!self, _E, "Fail to create location object. [method=%d]", method);
193 location_free(LocationObject *obj, gboolean is_internal_for_hybrid)
195 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
196 if (G_OBJECT_TYPE(obj) == LOCATION_TYPE_HYBRID) {
197 is_method_created[_METHOD_HYBRID] = false;
198 } else if (G_OBJECT_TYPE(obj) == LOCATION_TYPE_GPS) {
199 if (is_internal_for_hybrid)
200 is_method_created[_METHOD_GPS_2] = false;
202 is_method_created[_METHOD_GPS_1] = false;
203 } else if (G_OBJECT_TYPE(obj) == LOCATION_TYPE_WPS) {
204 if (is_internal_for_hybrid)
205 is_method_created[_METHOD_WPS_2] = false;
207 is_method_created[_METHOD_WPS_1] = false;
210 return LOCATION_ERROR_NONE;
214 location_request_single_location(LocationObject *obj, int timeout)
216 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
218 int ret = LOCATION_ERROR_NONE;
219 ret = location_ielement_request_single_location(LOCATION_IELEMENT(obj), timeout);
220 LOC_IF_FAIL(ret, _E, "Fail to request single location [%s]", err_msg(ret));
226 location_start(LocationObject *obj)
228 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
230 int ret = LOCATION_ERROR_NONE;
231 #ifndef TIZEN_PROFILE_TV
232 ret = location_check_cynara(LOCATION_PRIVILEGE);
233 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
236 ret = location_ielement_start(LOCATION_IELEMENT(obj));
237 LOC_IF_FAIL(ret, _E, "Fail to start [%s]", err_msg(ret));
243 location_stop(LocationObject *obj)
245 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
247 int ret = LOCATION_ERROR_NONE;
248 ret = location_ielement_stop(LOCATION_IELEMENT(obj));
249 LOC_IF_FAIL(ret, _E, "Fail to stop [%s]", err_msg(ret));
255 location_start_batch(LocationObject *obj)
257 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
258 int ret = LOCATION_ERROR_NONE;
260 #ifndef TIZEN_PROFILE_TV
261 ret = location_check_cynara(LOCATION_PRIVILEGE);
262 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
265 ret = location_ielement_start_batch(LOCATION_IELEMENT(obj));
266 LOC_IF_FAIL(ret, _E, "Fail to start_batch [%s]", err_msg(ret));
272 location_stop_batch(LocationObject *obj)
274 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
275 int ret = LOCATION_ERROR_NONE;
276 ret = location_ielement_stop_batch(LOCATION_IELEMENT(obj));
277 LOC_IF_FAIL(ret, _E, "Fail to stop_batch [%d]", err_msg(ret));
283 location_is_supported_method(LocationMethod method)
285 gboolean is_supported = FALSE;
288 case LOCATION_METHOD_HYBRID:
289 if (module_is_supported("gps") || module_is_supported("wps"))
292 case LOCATION_METHOD_GPS:
293 is_supported = module_is_supported("gps");
295 case LOCATION_METHOD_WPS:
296 is_supported = module_is_supported("wps");
298 case LOCATION_METHOD_PASSIVE:
299 is_supported = module_is_supported("passive");
309 location_is_enabled_method(LocationMethod method, int *is_enabled)
311 g_return_val_if_fail(is_enabled, LOCATION_ERROR_PARAMETER);
313 int vconf_ret = VCONF_ERROR;
315 char *_key = __convert_setting_key(method);
316 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
318 vconf_ret = vconf_get_int(_key, &vconf_val);
319 if (vconf_ret != VCONF_OK) {
320 LOCATION_SECLOG("vconf_get failed [%s], error [%d]", _key, vconf_ret);
322 return LOCATION_ERROR_NOT_AVAILABLE;
324 LOCATION_SECLOG("[%s]:[%d]", _key, vconf_val);
327 *is_enabled = vconf_val;
330 return LOCATION_ERROR_NONE;
334 location_enable_method(const LocationMethod method, const int enable)
339 #ifndef TIZEN_PROFILE_TV
340 ret = location_check_cynara(LOCATION_ENABLE_PRIVILEGE);
341 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
344 if (location_setting_get_int(VCONFKEY_LOCATION_RESTRICT) > RESTRICT_OFF) {
345 LOCATION_SECLOG("Location setting is denied by DPM");
346 return LOCATION_ERROR_NOT_ALLOWED;
350 _key = __convert_setting_key(method);
351 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
353 ret = vconf_set_int(_key, enable);
354 if (ret != VCONF_OK) {
355 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
357 return LOCATION_ERROR_NOT_ALLOWED;
362 _key = __convert_setting_key(LOCATION_METHOD_HYBRID);
363 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", LOCATION_METHOD_HYBRID, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
366 ret = vconf_set_int(_key, enable);
367 if (ret != VCONF_OK) {
368 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
370 return LOCATION_ERROR_NOT_ALLOWED;
374 int enabled_state = 0;
376 for (i = LOCATION_METHOD_GPS; i < LOCATION_METHOD_MAX; i++) {
377 _key = __convert_setting_key(i);
378 enabled_state |= location_setting_get_int(_key);
381 if (!enabled_state) {
382 _key = __convert_setting_key(LOCATION_METHOD_HYBRID);
383 ret = vconf_set_int(_key, enable);
384 if (ret != VCONF_OK) {
385 LOCATION_SECLOG("vconf_set_int failed [%s], error [%d]", _key, ret);
387 return LOCATION_ERROR_NOT_ALLOWED;
389 LOCATION_SECLOG("[%s]:[%d]", _key, ret);
399 location_add_setting_notify(LocationMethod method, LocationSettingCb callback, void *user_data)
401 int ret = LOCATION_ERROR_NONE;
402 char *_key = __convert_setting_key(method);
403 LOC_COND_RET(!_key, LOCATION_ERROR_PARAMETER, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_PARAMETER));
405 g_location_setting.callback = callback;
406 g_location_setting.user_data = user_data;
408 ret = location_setting_add_notify(_key, __location_setting_cb, &g_location_setting);
415 location_ignore_setting_notify(LocationMethod method, LocationSettingCb callback)
417 int ret = LOCATION_ERROR_NONE;
418 char *_key = __convert_setting_key(method);
419 LOC_COND_RET(!_key, LOCATION_ERROR_PARAMETER, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_PARAMETER));
421 g_location_setting.callback = NULL;
422 g_location_setting.user_data = NULL;
424 ret = location_setting_ignore_notify(_key, __location_setting_cb);
432 location_get_position(LocationObject *obj, LocationPosition **position, LocationAccuracy **accuracy)
434 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
435 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
436 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
438 int ret = LOCATION_ERROR_NONE;
440 #ifndef TIZEN_PROFILE_TV
441 ret = location_check_cynara(LOCATION_PRIVILEGE);
442 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
445 ret = location_ielement_get_position(LOCATION_IELEMENT(obj), position, accuracy);
446 LOC_COND_RET(ret != LOCATION_ERROR_NONE, ret, _E, "Fail to get_position [%s]", err_msg(ret));
452 location_get_position_ext(LocationObject *obj, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
454 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
455 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
456 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
457 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
459 int ret = LOCATION_ERROR_NONE;
461 #ifndef TIZEN_PROFILE_TV
462 ret = location_check_cynara(LOCATION_PRIVILEGE);
463 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
466 ret = location_ielement_get_position_ext(LOCATION_IELEMENT(obj), position, velocity, accuracy);
467 LOC_IF_FAIL(ret, _E, "Fail to get_position_ext [%s]", err_msg(ret));
473 location_get_last_position(LocationObject *obj, LocationPosition **position, LocationAccuracy **accuracy)
475 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
476 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
477 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
479 int ret = LOCATION_ERROR_NONE;
481 #ifndef TIZEN_PROFILE_TV
482 ret = location_check_cynara(LOCATION_PRIVILEGE);
483 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
486 ret = location_ielement_get_last_position(LOCATION_IELEMENT(obj), position, accuracy);
487 LOC_IF_FAIL(ret, _E, "Fail to get_last_position [%s]", err_msg(ret));
493 location_get_last_position_ext(LocationObject *obj, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
495 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
496 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
497 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
498 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
500 int ret = LOCATION_ERROR_NONE;
502 #ifndef TIZEN_PROFILE_TV
503 ret = location_check_cynara(LOCATION_PRIVILEGE);
504 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
507 ret = location_ielement_get_last_position_ext(LOCATION_IELEMENT(obj), position, velocity, accuracy);
508 LOC_IF_FAIL(ret, _E, "Fail to get_last_position_ext [%s]", err_msg(ret));
514 location_get_nmea(LocationObject *obj, char **nmea)
516 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
517 g_return_val_if_fail(nmea, LOCATION_ERROR_PARAMETER);
519 int ret = LOCATION_ERROR_NONE;
520 ret = location_ielement_get_nmea(LOCATION_IELEMENT(obj), nmea);
521 LOC_IF_FAIL(ret, _E, "Fail to get_nmea [%s]", err_msg(ret));
528 location_get_satellite(LocationObject *obj, LocationSatellite **satellite)
530 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
531 g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
533 int ret = LOCATION_ERROR_NONE;
535 #ifndef TIZEN_PROFILE_TV
536 ret = location_check_cynara(LOCATION_PRIVILEGE);
537 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
540 ret = location_ielement_get_satellite(LOCATION_IELEMENT(obj), satellite);
541 LOC_IF_FAIL(ret, _E, "Fail to get_satellite [%s]", err_msg(ret));
547 location_get_batch(LocationObject *obj, LocationBatch **batch)
549 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
550 g_return_val_if_fail(batch, LOCATION_ERROR_PARAMETER);
552 int ret = LOCATION_ERROR_NONE;
554 #ifndef TIZEN_PROFILE_TV
555 ret = location_check_cynara(LOCATION_PRIVILEGE);
556 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
559 ret = location_ielement_get_batch(LOCATION_IELEMENT(obj), batch);
560 LOC_IF_FAIL(ret, _E, "Fail to get_batch [%s]", err_msg(ret));
566 location_get_last_satellite(LocationObject *obj, LocationSatellite **satellite)
568 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
569 g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
571 int ret = LOCATION_ERROR_NONE;
573 #ifndef TIZEN_PROFILE_TV
574 ret = location_check_cynara(LOCATION_PRIVILEGE);
575 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
578 ret = location_ielement_get_last_satellite(LOCATION_IELEMENT(obj), satellite);
579 LOC_IF_FAIL(ret, _E, "Fail to get_last_satellite [%s]", err_msg(ret));
585 location_get_velocity(LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy)
587 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
588 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
589 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
591 int ret = LOCATION_ERROR_NONE;
593 #ifndef TIZEN_PROFILE_TV
594 ret = location_check_cynara(LOCATION_PRIVILEGE);
595 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
598 ret = location_ielement_get_velocity(LOCATION_IELEMENT(obj), velocity, accuracy);
599 LOC_IF_FAIL(ret, _E, "Fail to get_velocity [%s]", err_msg(ret));
605 location_get_last_velocity(LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy)
607 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
608 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
609 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
611 int ret = LOCATION_ERROR_NONE;
613 #ifndef TIZEN_PROFILE_TV
614 ret = location_check_cynara(LOCATION_PRIVILEGE);
615 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
618 ret = location_ielement_get_last_velocity(LOCATION_IELEMENT(obj), velocity, accuracy);
619 LOC_IF_FAIL(ret, _E, "Fail to get_last_velocity [%s]", err_msg(ret));
625 location_get_accessibility_state(LocationAccessState *state)
627 #ifndef TIZEN_PROFILE_TV
628 int ret = location_check_cynara(LOCATION_PRIVILEGE);
630 if (ret == LOCATION_ERROR_NONE) {
631 *state = LOCATION_ACCESS_ALLOWED;
633 *state = LOCATION_ACCESS_DENIED;
634 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
637 *state = LOCATION_ACCESS_ALLOWED;
640 return LOCATION_ERROR_NONE;
644 location_set_accessibility_state(LocationAccessState state)
646 int auth = LOCATION_APP_NOT_FOUND;
647 int ret = LOCATION_ERROR_NONE;
650 case LOCATION_ACCESS_DENIED:
651 auth = LOCATION_APP_OFF;
653 case LOCATION_ACCESS_ALLOWED:
654 auth = LOCATION_APP_ON;
656 case LOCATION_ACCESS_NONE:
658 return LOCATION_ERROR_PARAMETER;
661 ret = location_application_set_authority(auth);
662 LOCATION_LOGD("set_accessibility_state [%d], Error[%d]", auth, ret);
667 location_send_command(const char *cmd)
669 g_return_val_if_fail(cmd, LOCATION_ERROR_PARAMETER);
670 return LOCATION_ERROR_NOT_AVAILABLE;
674 location_set_option(LocationObject *obj, const char *option)
676 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
677 int ret = LOCATION_ERROR_NONE;
679 #ifndef TIZEN_PROFILE_TV
680 ret = location_check_cynara(LOCATION_PRIVILEGE);
681 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
684 ret = location_ielement_set_option(LOCATION_IELEMENT(obj), option);
685 LOC_IF_FAIL(ret, _E, "Fail to get_velocity [%s]", err_msg(ret));
694 location_enable_mock(const int enable)
696 int ret = LOCATION_ERROR_NONE;
698 #ifndef TIZEN_PROFILE_TV
699 ret = location_check_cynara(LOCATION_PRIVILEGE);
700 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
703 #if 0 /* Tizen platform didn't turn developer option on */
704 gboolean developer_option = FALSE;
706 ret = vconf_get_bool(VCONFKEY_SETAPPL_DEVELOPER_OPTION_STATE, &developer_option);
707 LOC_COND_RET(!developer_option, LOCATION_ERROR_NOT_ALLOWED, _E, "Cannot enable mock location because developer option is not turned on", ret);
710 ret = vconf_set_int(VCONFKEY_LOCATION_MOCK_ENABLED, enable);
711 if (ret != VCONF_OK) {
712 LOCATION_SECLOG("vconf_set_int failed [MOCK_ENABLED], ret=[%d]", ret);
713 return LOCATION_ERROR_NOT_ALLOWED;
720 location_set_mock_location(LocationObject *obj, const LocationPosition *position, const LocationVelocity *velocity, const LocationAccuracy *accuracy)
722 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
723 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
724 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
725 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
727 int ret = LOCATION_ERROR_NONE;
728 ret = location_ielement_set_mock_location(LOCATION_IELEMENT(obj), position, velocity, accuracy);
729 LOC_IF_FAIL(ret, _E, "Fail to set_mock_location [%s]", err_msg(ret));
735 location_clear_mock_location(LocationObject *obj)
737 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
739 int ret = LOCATION_ERROR_NONE;
740 ret = location_ielement_clear_mock_location(LOCATION_IELEMENT(obj));
741 LOC_IF_FAIL(ret, _E, "Fail to clear_mock_location [%s]", err_msg(ret));
747 location_enable_restriction(const int enable)
749 int ret = LOCATION_ERROR_NONE;
752 #ifndef TIZEN_PROFILE_TV
753 ret = location_check_cynara(LOCATION_ENABLE_PRIVILEGE);
754 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
758 ret = vconf_get_int(VCONFKEY_LOCATION_RESTRICT, &restriction);
759 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to get restriction status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
761 if (restriction == RESTRICT_OFF) {
763 if (location_setting_get_int(VCONFKEY_LOCATION_ENABLED)) {
764 value |= RESTRICT_GPS;
765 ret = vconf_set_int(VCONFKEY_LOCATION_ENABLED, 0);
766 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
769 if (location_setting_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED)) {
770 value |= RESTRICT_WPS;
771 ret = vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 0);
772 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
775 if (location_setting_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION)) {
776 value |= RESTRICT_HYBRID;
777 ret = vconf_set_int(VCONFKEY_LOCATION_USE_MY_LOCATION, 0);
778 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
782 value = RESTRICT_NONE;
784 ret = vconf_set_int(VCONFKEY_LOCATION_RESTRICT, value);
785 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set value. %d [%s]", value, err_msg(LOCATION_ERROR_NOT_ALLOWED));
789 ret = vconf_get_int(VCONFKEY_LOCATION_RESTRICT, &restriction);
790 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to get restriction status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
792 if (restriction > RESTRICT_OFF) {
794 if (restriction & RESTRICT_GPS) {
795 ret = vconf_set_int(VCONFKEY_LOCATION_ENABLED, 1);
796 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
799 if (restriction & RESTRICT_WPS) {
800 ret = vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 1);
801 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
804 if (restriction & RESTRICT_HYBRID) {
805 ret = vconf_set_int(VCONFKEY_LOCATION_USE_MY_LOCATION, 1);
806 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
809 ret = vconf_set_int(VCONFKEY_LOCATION_RESTRICT, RESTRICT_OFF);
810 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set value. %d [%s]", RESTRICT_OFF, err_msg(LOCATION_ERROR_NOT_ALLOWED));
814 return LOCATION_ERROR_NONE;