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;
94 static void __location_setting_cb(keynode_t *key, gpointer data)
96 if (key == NULL || data == NULL)
99 LocationSetting *_setting = (LocationSetting *)data;
100 LocationMethod _method = LOCATION_METHOD_NONE;
102 if (_setting->callback) {
103 _method = __convert_method_from_key(vconf_keynode_get_name(key));
104 _setting->callback(_method, location_setting_get_key_val(key), _setting->user_data);
109 int location_init(void)
111 #if !GLIB_CHECK_VERSION(2, 35, 0)
115 #if !GLIB_CHECK_VERSION(2, 31, 0)
116 if (!g_thread_supported()) g_thread_init(NULL);
118 if (FALSE == module_init())
119 return LOCATION_ERROR_NOT_AVAILABLE;
121 return LOCATION_ERROR_NONE;
124 EXPORT_API LocationObject *
125 location_new(LocationMethod method)
127 LocationObject *self = NULL;
128 LOCATION_LOGD("method: %d", method);
131 case LOCATION_METHOD_HYBRID:
132 self = g_object_new(LOCATION_TYPE_HYBRID, NULL);
134 case LOCATION_METHOD_GPS:
135 self = g_object_new(LOCATION_TYPE_GPS, NULL);
137 case LOCATION_METHOD_WPS:
138 self = g_object_new(LOCATION_TYPE_WPS, NULL);
140 case LOCATION_METHOD_MOCK:
141 self = g_object_new(LOCATION_TYPE_MOCK, NULL);
146 LOC_COND_LOG(!self, _E, "Fail to create location object. [method=%d]", method);
151 location_free(LocationObject *obj)
153 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
155 return LOCATION_ERROR_NONE;
159 location_request_single_location(LocationObject *obj, int timeout)
161 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
163 int ret = LOCATION_ERROR_NONE;
164 ret = location_ielement_request_single_location(LOCATION_IELEMENT(obj), timeout);
165 LOC_IF_FAIL(ret, _E, "Fail to request single location [%s]", err_msg(ret));
171 location_start(LocationObject *obj)
173 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
175 int ret = LOCATION_ERROR_NONE;
176 #ifndef TIZEN_PROFILE_TV
177 ret = location_check_cynara(LOCATION_PRIVILEGE);
178 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
181 ret = location_ielement_start(LOCATION_IELEMENT(obj));
182 LOC_IF_FAIL(ret, _E, "Fail to start [%s]", err_msg(ret));
188 location_stop(LocationObject *obj)
190 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
192 int ret = LOCATION_ERROR_NONE;
193 ret = location_ielement_stop(LOCATION_IELEMENT(obj));
194 LOC_IF_FAIL(ret, _E, "Fail to stop [%s]", err_msg(ret));
200 location_start_batch(LocationObject *obj)
202 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
203 int ret = LOCATION_ERROR_NONE;
205 #ifndef TIZEN_PROFILE_TV
206 ret = location_check_cynara(LOCATION_PRIVILEGE);
207 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
210 ret = location_ielement_start_batch(LOCATION_IELEMENT(obj));
211 LOC_IF_FAIL(ret, _E, "Fail to start_batch [%s]", err_msg(ret));
217 location_stop_batch(LocationObject *obj)
219 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
220 int ret = LOCATION_ERROR_NONE;
221 ret = location_ielement_stop_batch(LOCATION_IELEMENT(obj));
222 LOC_IF_FAIL(ret, _E, "Fail to stop_batch [%d]", err_msg(ret));
228 location_is_supported_method(LocationMethod method)
230 gboolean is_supported = FALSE;
233 case LOCATION_METHOD_HYBRID:
234 if (module_is_supported("gps") || module_is_supported("wps") || module_is_supported("mock"))
237 case LOCATION_METHOD_GPS:
238 is_supported = module_is_supported("gps");
240 case LOCATION_METHOD_WPS:
241 is_supported = module_is_supported("wps");
243 case LOCATION_METHOD_MOCK:
244 is_supported = module_is_supported("mock");
254 location_is_enabled_method(LocationMethod method, int *is_enabled)
256 g_return_val_if_fail(is_enabled, LOCATION_ERROR_PARAMETER);
258 int vconf_ret = VCONF_ERROR;
260 char *_key = __convert_setting_key(method);
261 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
263 vconf_ret = vconf_get_int(_key, &vconf_val);
264 if (vconf_ret != VCONF_OK) {
265 LOCATION_SECLOG("vconf_get failed [%s], error [%d]", _key, vconf_ret);
267 return LOCATION_ERROR_NOT_AVAILABLE;
269 LOCATION_SECLOG("[%s]:[%d]", _key, vconf_val);
272 *is_enabled = vconf_val;
275 return LOCATION_ERROR_NONE;
279 location_enable_method(const LocationMethod method, const int enable)
284 #ifndef TIZEN_PROFILE_TV
285 ret = location_check_cynara(LOCATION_ENABLE_PRIVILEGE);
286 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
289 if (location_setting_get_int(VCONFKEY_LOCATION_RESTRICT) > RESTRICT_OFF) {
290 LOCATION_SECLOG("Location setting is denied by DPM");
291 return LOCATION_ERROR_NOT_ALLOWED;
295 _key = __convert_setting_key(method);
296 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
298 ret = vconf_set_int(_key, enable);
299 if (ret != VCONF_OK) {
300 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
302 return LOCATION_ERROR_NOT_ALLOWED;
307 _key = __convert_setting_key(LOCATION_METHOD_HYBRID);
308 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", LOCATION_METHOD_HYBRID, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
311 ret = vconf_set_int(_key, enable);
312 if (ret != VCONF_OK) {
313 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
315 return LOCATION_ERROR_NOT_ALLOWED;
319 int enabled_state = 0;
321 for (i = LOCATION_METHOD_GPS; i < LOCATION_METHOD_MAX; i++) {
322 _key = __convert_setting_key(i);
323 enabled_state |= location_setting_get_int(_key);
326 if (!enabled_state) {
327 _key = __convert_setting_key(LOCATION_METHOD_HYBRID);
328 ret = vconf_set_int(_key, enable);
329 if (ret != VCONF_OK) {
330 LOCATION_SECLOG("vconf_set_int failed [%s], error [%d]", _key, ret);
332 return LOCATION_ERROR_NOT_ALLOWED;
334 LOCATION_SECLOG("[%s]:[%d]", _key, ret);
344 location_add_setting_notify(LocationMethod method, LocationSettingCb callback, void *user_data)
346 int ret = LOCATION_ERROR_NONE;
347 char *_key = __convert_setting_key(method);
348 LOC_COND_RET(!_key, LOCATION_ERROR_PARAMETER, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_PARAMETER));
350 g_location_setting.callback = callback;
351 g_location_setting.user_data = user_data;
353 ret = location_setting_add_notify(_key, __location_setting_cb, &g_location_setting);
360 location_ignore_setting_notify(LocationMethod method, LocationSettingCb callback)
362 int ret = LOCATION_ERROR_NONE;
363 char *_key = __convert_setting_key(method);
364 LOC_COND_RET(!_key, LOCATION_ERROR_PARAMETER, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_PARAMETER));
366 g_location_setting.callback = NULL;
367 g_location_setting.user_data = NULL;
369 ret = location_setting_ignore_notify(_key, __location_setting_cb);
377 location_get_position(LocationObject *obj, LocationPosition **position, LocationAccuracy **accuracy)
379 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
380 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
381 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
383 int ret = LOCATION_ERROR_NONE;
385 #ifndef TIZEN_PROFILE_TV
386 ret = location_check_cynara(LOCATION_PRIVILEGE);
387 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
390 ret = location_ielement_get_position(LOCATION_IELEMENT(obj), position, accuracy);
391 LOC_COND_RET(ret != LOCATION_ERROR_NONE, ret, _E, "Fail to get_position [%s]", err_msg(ret));
397 location_get_position_ext(LocationObject *obj, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
399 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
400 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
401 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
402 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
404 int ret = LOCATION_ERROR_NONE;
406 #ifndef TIZEN_PROFILE_TV
407 ret = location_check_cynara(LOCATION_PRIVILEGE);
408 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
411 ret = location_ielement_get_position_ext(LOCATION_IELEMENT(obj), position, velocity, accuracy);
412 LOC_IF_FAIL(ret, _E, "Fail to get_position_ext [%s]", err_msg(ret));
418 location_get_last_position(LocationObject *obj, LocationPosition **position, LocationAccuracy **accuracy)
420 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
421 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
422 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
424 int ret = LOCATION_ERROR_NONE;
426 #ifndef TIZEN_PROFILE_TV
427 ret = location_check_cynara(LOCATION_PRIVILEGE);
428 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
431 ret = location_ielement_get_last_position(LOCATION_IELEMENT(obj), position, accuracy);
432 LOC_IF_FAIL(ret, _E, "Fail to get_last_position [%s]", err_msg(ret));
438 location_get_last_position_ext(LocationObject *obj, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
440 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
441 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
442 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
443 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
445 int ret = LOCATION_ERROR_NONE;
447 #ifndef TIZEN_PROFILE_TV
448 ret = location_check_cynara(LOCATION_PRIVILEGE);
449 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
452 ret = location_ielement_get_last_position_ext(LOCATION_IELEMENT(obj), position, velocity, accuracy);
453 LOC_IF_FAIL(ret, _E, "Fail to get_last_position_ext [%s]", err_msg(ret));
459 location_get_nmea(LocationObject *obj, char **nmea)
461 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
462 g_return_val_if_fail(nmea, LOCATION_ERROR_PARAMETER);
464 int ret = LOCATION_ERROR_NONE;
465 ret = location_ielement_get_nmea(LOCATION_IELEMENT(obj), nmea);
466 LOC_IF_FAIL(ret, _E, "Fail to get_nmea [%s]", err_msg(ret));
473 location_get_satellite(LocationObject *obj, LocationSatellite **satellite)
475 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
476 g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
478 int ret = LOCATION_ERROR_NONE;
480 #ifndef TIZEN_PROFILE_TV
481 ret = location_check_cynara(LOCATION_PRIVILEGE);
482 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
485 ret = location_ielement_get_satellite(LOCATION_IELEMENT(obj), satellite);
486 LOC_IF_FAIL(ret, _E, "Fail to get_satellite [%s]", err_msg(ret));
492 location_get_batch(LocationObject *obj, LocationBatch **batch)
494 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
495 g_return_val_if_fail(batch, LOCATION_ERROR_PARAMETER);
497 int ret = LOCATION_ERROR_NONE;
499 #ifndef TIZEN_PROFILE_TV
500 ret = location_check_cynara(LOCATION_PRIVILEGE);
501 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
504 ret = location_ielement_get_batch(LOCATION_IELEMENT(obj), batch);
505 LOC_IF_FAIL(ret, _E, "Fail to get_batch [%s]", err_msg(ret));
511 location_get_last_satellite(LocationObject *obj, LocationSatellite **satellite)
513 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
514 g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
516 int ret = LOCATION_ERROR_NONE;
518 #ifndef TIZEN_PROFILE_TV
519 ret = location_check_cynara(LOCATION_PRIVILEGE);
520 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
523 ret = location_ielement_get_last_satellite(LOCATION_IELEMENT(obj), satellite);
524 LOC_IF_FAIL(ret, _E, "Fail to get_last_satellite [%s]", err_msg(ret));
530 location_get_velocity(LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy)
532 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
533 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
534 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
536 int ret = LOCATION_ERROR_NONE;
538 #ifndef TIZEN_PROFILE_TV
539 ret = location_check_cynara(LOCATION_PRIVILEGE);
540 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
543 ret = location_ielement_get_velocity(LOCATION_IELEMENT(obj), velocity, accuracy);
544 LOC_IF_FAIL(ret, _E, "Fail to get_velocity [%s]", err_msg(ret));
550 location_get_last_velocity(LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy)
552 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
553 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
554 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
556 int ret = LOCATION_ERROR_NONE;
558 #ifndef TIZEN_PROFILE_TV
559 ret = location_check_cynara(LOCATION_PRIVILEGE);
560 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
563 ret = location_ielement_get_last_velocity(LOCATION_IELEMENT(obj), velocity, accuracy);
564 LOC_IF_FAIL(ret, _E, "Fail to get_last_velocity [%s]", err_msg(ret));
570 location_get_accessibility_state(LocationAccessState *state)
572 int auth = location_application_get_authority();
574 case LOCATION_APP_OFF:
575 *state = LOCATION_ACCESS_DENIED;
577 case LOCATION_APP_ON:
578 *state = LOCATION_ACCESS_ALLOWED;
580 case LOCATION_APP_NOT_FOUND:
581 *state = LOCATION_ACCESS_NONE;
584 return LOCATION_ERROR_UNKNOWN;
587 LOCATION_LOGD("get_accessibility_state [%d]", auth);
588 return LOCATION_ERROR_NONE;
592 location_set_accessibility_state(LocationAccessState state)
594 int auth = LOCATION_APP_NOT_FOUND;
595 int ret = LOCATION_ERROR_NONE;
598 case LOCATION_ACCESS_DENIED:
599 auth = LOCATION_APP_OFF;
601 case LOCATION_ACCESS_ALLOWED:
602 auth = LOCATION_APP_ON;
604 case LOCATION_ACCESS_NONE:
606 return LOCATION_ERROR_PARAMETER;
609 ret = location_application_set_authority(auth);
610 LOCATION_LOGD("set_accessibility_state [%d], Error[%d]", auth, ret);
615 location_send_command(const char *cmd)
617 g_return_val_if_fail(cmd, LOCATION_ERROR_PARAMETER);
618 return LOCATION_ERROR_NOT_AVAILABLE;
622 location_set_option(LocationObject *obj, const char *option)
624 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
625 int ret = LOCATION_ERROR_NONE;
627 #ifndef TIZEN_PROFILE_TV
628 ret = location_check_cynara(LOCATION_PRIVILEGE);
629 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
632 ret = location_ielement_set_option(LOCATION_IELEMENT(obj), option);
633 LOC_IF_FAIL(ret, _E, "Fail to get_velocity [%s]", err_msg(ret));
643 location_get_service_state(LocationObject *obj, int *state)
645 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
646 g_return_val_if_fail(state, LOCATION_ERROR_PARAMETER);
648 int ret = LOCATION_ERROR_NONE;
649 ret = location_ielement_get_status(LOCATION_IELEMENT(obj), state);
650 LOC_IF_FAIL(ret, _E, "Fail to get_position [%s]", err_msg(ret));
657 location_enable_mock(const LocationMethod method, const int enable)
662 LOC_COND_RET(method != LOCATION_METHOD_MOCK, LOCATION_ERROR_PARAMETER, _E, "Method is not mock [%s]", err_msg(LOCATION_ERROR_PARAMETER));
664 #ifndef TIZEN_PROFILE_TV
665 ret = location_check_cynara(LOCATION_PRIVILEGE);
666 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
669 #if 0 /* Tizen platform didn't turn developer option on */
670 gboolean developer_option = FALSE;
672 ret = vconf_get_bool(VCONFKEY_SETAPPL_DEVELOPER_OPTION_STATE, &developer_option);
673 LOC_COND_RET(!developer_option, LOCATION_ERROR_NOT_ALLOWED, _E, "Cannot enable mock location because developer option is not turned on", ret);
676 _key = __convert_setting_key(method);
677 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
679 ret = vconf_set_int(_key, enable);
680 if (ret != VCONF_OK) {
681 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
683 return LOCATION_ERROR_NOT_ALLOWED;
692 static char *__convert_mock_setting_key(LocationMethod method)
696 case LOCATION_METHOD_MOCK_GPS:
697 key = g_strdup(VCONFKEY_LOCATION_MOCK_GPS_ENABLED);
699 case LOCATION_METHOD_MOCK_WPS:
700 key = g_strdup(VCONFKEY_LOCATION_MOCK_NETWORK_ENABLED);
709 location_set_mock_method_enabled(const LocationMethod method, const int enable)
715 _key = __convert_setting_key(method);
716 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
718 ret = vconf_get_int(_key, &vconf_val);
719 if (ret != VCONF_OK) {
720 LOCATION_SECLOG("failed [%s], error [%d]", _key, ret);
722 return LOCATION_ERROR_NOT_ALLOWED;
726 _key = __convert_mock_setting_key(method);
727 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method[%d]", method);
728 ret = vconf_set_int(_key, enable);
729 if (ret != VCONF_OK) {
730 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
732 return LOCATION_ERROR_NOT_ALLOWED;
743 location_set_mock_location(LocationObject *obj, const LocationPosition *position, const LocationVelocity *velocity, const LocationAccuracy *accuracy)
745 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
746 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
747 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
748 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
750 int ret = LOCATION_ERROR_NONE;
751 ret = location_ielement_set_mock_location(LOCATION_IELEMENT(obj), position, velocity, accuracy);
752 LOC_IF_FAIL(ret, _E, "Fail to set_mock_location [%s]", err_msg(ret));
758 location_clear_mock_location(LocationObject *obj)
760 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
762 int ret = LOCATION_ERROR_NONE;
763 ret = location_ielement_clear_mock_location(LOCATION_IELEMENT(obj));
764 LOC_IF_FAIL(ret, _E, "Fail to clear_mock_location [%s]", err_msg(ret));
770 location_enable_restriction(const int enable)
772 int ret = LOCATION_ERROR_NONE;
775 #ifndef TIZEN_PROFILE_TV
776 ret = location_check_cynara(LOCATION_ENABLE_PRIVILEGE);
777 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
781 ret = vconf_get_int(VCONFKEY_LOCATION_RESTRICT, &restriction);
782 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to get restriction status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
784 if (restriction == RESTRICT_OFF) {
786 if (location_setting_get_int(VCONFKEY_LOCATION_ENABLED)) {
787 value |= RESTRICT_GPS;
788 ret = vconf_set_int(VCONFKEY_LOCATION_ENABLED, 0);
789 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
792 if (location_setting_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED)) {
793 value |= RESTRICT_WPS;
794 ret = vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 0);
795 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
798 if (location_setting_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION)) {
799 value |= RESTRICT_HYBRID;
800 ret = vconf_set_int(VCONFKEY_LOCATION_USE_MY_LOCATION, 0);
801 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
805 value = RESTRICT_NONE;
807 ret = vconf_set_int(VCONFKEY_LOCATION_RESTRICT, value);
808 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set value. %d [%s]", value, err_msg(LOCATION_ERROR_NOT_ALLOWED));
812 ret = vconf_get_int(VCONFKEY_LOCATION_RESTRICT, &restriction);
813 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to get restriction status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
815 if (restriction > RESTRICT_OFF) {
817 if (restriction & RESTRICT_GPS) {
818 ret = vconf_set_int(VCONFKEY_LOCATION_ENABLED, 1);
819 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
822 if (restriction & RESTRICT_WPS) {
823 ret = vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 1);
824 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
827 if (restriction & RESTRICT_HYBRID) {
828 ret = vconf_set_int(VCONFKEY_LOCATION_USE_MY_LOCATION, 1);
829 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
832 ret = vconf_set_int(VCONFKEY_LOCATION_RESTRICT, RESTRICT_OFF);
833 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));
837 return LOCATION_ERROR_NONE;