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 #include "location-privacy.h"
43 #define LOCATION_PRIVILEGE "http://tizen.org/privilege/location"
44 #define LOCATION_ENABLE_PRIVILEGE "http://tizen.org/privilege/location.enable"
47 typedef struct _LocationSetting {
48 LocationSettingCb callback;
61 static LocationSetting g_location_setting;
62 static bool is_method_created[_METHOD_MAX] = {false};
64 static char *__convert_setting_key(LocationMethod method)
68 case LOCATION_METHOD_HYBRID:
69 key = g_strdup(VCONFKEY_LOCATION_USE_MY_LOCATION);
71 case LOCATION_METHOD_GPS:
72 key = g_strdup(VCONFKEY_LOCATION_ENABLED);
74 case LOCATION_METHOD_WPS:
75 key = g_strdup(VCONFKEY_LOCATION_NETWORK_ENABLED);
77 case INTERNAL_METHOD_MOCK:
78 key = g_strdup(VCONFKEY_LOCATION_MOCK_ENABLED);
87 static LocationMethod __convert_method_from_key(const char *key)
89 LocationMethod _method = LOCATION_METHOD_NONE;
90 if (g_strcmp0(key, VCONFKEY_LOCATION_USE_MY_LOCATION) == 0)
91 _method = LOCATION_METHOD_HYBRID;
92 else if (g_strcmp0(key, VCONFKEY_LOCATION_ENABLED) == 0)
93 _method = LOCATION_METHOD_GPS;
94 else if (g_strcmp0(key, VCONFKEY_LOCATION_NETWORK_ENABLED) == 0)
95 _method = LOCATION_METHOD_WPS;
100 static void __location_setting_cb(keynode_t *key, gpointer data)
102 if (key == NULL || data == NULL)
105 LocationSetting *_setting = (LocationSetting *)data;
106 LocationMethod _method = LOCATION_METHOD_NONE;
108 if (_setting->callback) {
109 _method = __convert_method_from_key(vconf_keynode_get_name(key));
110 _setting->callback(_method, location_setting_get_key_val(key), _setting->user_data);
115 int location_init(void)
117 #if !GLIB_CHECK_VERSION(2, 35, 0)
121 #if !GLIB_CHECK_VERSION(2, 31, 0)
122 if (!g_thread_supported()) g_thread_init(NULL);
124 if (FALSE == module_init())
125 return LOCATION_ERROR_NOT_AVAILABLE;
127 return LOCATION_ERROR_NONE;
130 EXPORT_API LocationObject *
131 location_new(LocationMethod method, gboolean is_internal_for_hybrid)
133 LocationObject *self = NULL;
134 LOCATION_LOGD("method : %d, is_internal_for_hybrid[%d]", method, is_internal_for_hybrid);
137 case LOCATION_METHOD_HYBRID:
138 if (is_method_created[_METHOD_HYBRID]) {
139 LOCATION_LOGE("Hybrid handle already exist.");
141 self = g_object_new(LOCATION_TYPE_HYBRID, NULL);
142 is_method_created[_METHOD_HYBRID] = true;
145 case LOCATION_METHOD_GPS:
146 if (is_internal_for_hybrid) {
147 if (is_method_created[_METHOD_GPS_2]) {
148 LOCATION_LOGD("Hybrid(GPS) handle already exist.");
150 is_method_created[_METHOD_GPS_2] = true;
151 self = g_object_new(LOCATION_TYPE_GPS, NULL);
154 if (is_method_created[_METHOD_GPS_1]) {
155 LOCATION_LOGE("GPS handle already exist.");
157 is_method_created[_METHOD_GPS_1] = true;
158 self = g_object_new(LOCATION_TYPE_GPS, NULL);
162 case LOCATION_METHOD_WPS:
163 if (is_internal_for_hybrid) {
164 if (is_method_created[_METHOD_WPS_2]) {
165 LOCATION_LOGD("Hybrid(WPS) handle already exist.");
167 is_method_created[_METHOD_WPS_2] = true;
168 self = g_object_new(LOCATION_TYPE_WPS, NULL);
171 if (is_method_created[_METHOD_WPS_1]) {
172 LOCATION_LOGE("WPS handle already exist.");
174 is_method_created[_METHOD_WPS_1] = true;
175 self = g_object_new(LOCATION_TYPE_WPS, NULL);
179 case LOCATION_METHOD_PASSIVE:
180 self = g_object_new(LOCATION_TYPE_PASSIVE, NULL);
186 LOC_COND_LOG(!self, _E, "Fail to create location object. [method=%d]", method);
191 location_free(LocationObject *obj, gboolean is_internal_for_hybrid)
193 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
194 if (G_OBJECT_TYPE(obj) == LOCATION_TYPE_HYBRID) {
195 is_method_created[_METHOD_HYBRID] = false;
196 } else if (G_OBJECT_TYPE(obj) == LOCATION_TYPE_GPS) {
197 if (is_internal_for_hybrid)
198 is_method_created[_METHOD_GPS_2] = false;
200 is_method_created[_METHOD_GPS_1] = false;
201 } else if (G_OBJECT_TYPE(obj) == LOCATION_TYPE_WPS) {
202 if (is_internal_for_hybrid)
203 is_method_created[_METHOD_WPS_2] = false;
205 is_method_created[_METHOD_WPS_1] = false;
208 return LOCATION_ERROR_NONE;
212 location_request_single_location(LocationObject *obj, int timeout)
214 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
216 int ret = LOCATION_ERROR_NONE;
217 ret = location_ielement_request_single_location(LOCATION_IELEMENT(obj), timeout);
218 LOC_IF_FAIL(ret, _E, "Fail to request single location [%s]", err_msg(ret));
224 location_start(LocationObject *obj)
226 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
228 int ret = LOCATION_ERROR_NONE;
229 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
230 ret = location_check_cynara(LOCATION_PRIVILEGE);
231 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
234 ret = location_ielement_start(LOCATION_IELEMENT(obj));
235 LOC_IF_FAIL(ret, _E, "Fail to start [%s]", err_msg(ret));
241 location_stop(LocationObject *obj)
243 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
245 int ret = LOCATION_ERROR_NONE;
246 ret = location_ielement_stop(LOCATION_IELEMENT(obj));
247 LOC_IF_FAIL(ret, _E, "Fail to stop [%s]", err_msg(ret));
253 location_start_batch(LocationObject *obj)
255 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
256 int ret = LOCATION_ERROR_NONE;
258 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
259 ret = location_check_cynara(LOCATION_PRIVILEGE);
260 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
263 ret = location_ielement_start_batch(LOCATION_IELEMENT(obj));
264 LOC_IF_FAIL(ret, _E, "Fail to start_batch [%s]", err_msg(ret));
270 location_stop_batch(LocationObject *obj)
272 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
273 int ret = LOCATION_ERROR_NONE;
274 ret = location_ielement_stop_batch(LOCATION_IELEMENT(obj));
275 LOC_IF_FAIL(ret, _E, "Fail to stop_batch [%d]", err_msg(ret));
281 location_is_supported_method(LocationMethod method)
283 gboolean is_supported = FALSE;
286 case LOCATION_METHOD_HYBRID:
287 if (module_is_supported("gps") || module_is_supported("wps"))
290 case LOCATION_METHOD_GPS:
291 is_supported = module_is_supported("gps");
293 case LOCATION_METHOD_WPS:
294 is_supported = module_is_supported("wps");
296 case LOCATION_METHOD_PASSIVE:
297 is_supported = module_is_supported("passive");
307 location_is_enabled_method(LocationMethod method, int *is_enabled)
309 g_return_val_if_fail(is_enabled, LOCATION_ERROR_PARAMETER);
311 int vconf_ret = VCONF_ERROR;
313 char *_key = __convert_setting_key(method);
314 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
316 vconf_ret = vconf_get_int(_key, &vconf_val);
317 if (vconf_ret != VCONF_OK) {
318 LOCATION_SECLOG("vconf_get failed [%s], error [%d]", _key, vconf_ret);
320 return LOCATION_ERROR_NOT_AVAILABLE;
322 LOCATION_SECLOG("[%s]:[%d]", _key, vconf_val);
325 *is_enabled = vconf_val;
328 return LOCATION_ERROR_NONE;
332 location_enable_method(const LocationMethod method, const int enable)
337 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
338 ret = location_check_cynara(LOCATION_ENABLE_PRIVILEGE);
339 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
342 if (location_setting_get_int(VCONFKEY_LOCATION_RESTRICT) > RESTRICT_OFF) {
343 LOCATION_SECLOG("Location setting is denied by DPM");
344 return LOCATION_ERROR_NOT_ALLOWED;
348 _key = __convert_setting_key(method);
349 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
351 ret = vconf_set_int(_key, enable);
352 if (ret != VCONF_OK) {
353 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
355 return LOCATION_ERROR_NOT_ALLOWED;
360 _key = __convert_setting_key(LOCATION_METHOD_HYBRID);
361 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", LOCATION_METHOD_HYBRID, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
364 ret = vconf_set_int(_key, enable);
365 if (ret != VCONF_OK) {
366 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
368 return LOCATION_ERROR_NOT_ALLOWED;
372 int enabled_state = 0;
374 for (i = LOCATION_METHOD_GPS; i < LOCATION_METHOD_MAX; i++) {
375 _key = __convert_setting_key(i);
376 enabled_state |= location_setting_get_int(_key);
379 if (!enabled_state) {
380 _key = __convert_setting_key(LOCATION_METHOD_HYBRID);
381 ret = vconf_set_int(_key, enable);
382 if (ret != VCONF_OK) {
383 LOCATION_SECLOG("vconf_set_int failed [%s], error [%d]", _key, ret);
385 return LOCATION_ERROR_NOT_ALLOWED;
387 LOCATION_SECLOG("[%s]:[%d]", _key, ret);
397 location_add_setting_notify(LocationMethod method, LocationSettingCb callback, void *user_data)
399 int ret = LOCATION_ERROR_NONE;
400 char *_key = __convert_setting_key(method);
401 LOC_COND_RET(!_key, LOCATION_ERROR_PARAMETER, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_PARAMETER));
403 g_location_setting.callback = callback;
404 g_location_setting.user_data = user_data;
406 ret = location_setting_add_notify(_key, __location_setting_cb, &g_location_setting);
413 location_ignore_setting_notify(LocationMethod method, LocationSettingCb callback)
415 int ret = LOCATION_ERROR_NONE;
416 char *_key = __convert_setting_key(method);
417 LOC_COND_RET(!_key, LOCATION_ERROR_PARAMETER, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_PARAMETER));
419 g_location_setting.callback = NULL;
420 g_location_setting.user_data = NULL;
422 ret = location_setting_ignore_notify(_key, __location_setting_cb);
430 location_get_position(LocationObject *obj, LocationPosition **position, LocationAccuracy **accuracy)
432 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
433 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
434 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
436 int ret = LOCATION_ERROR_NONE;
438 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
439 ret = location_check_cynara(LOCATION_PRIVILEGE);
440 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
443 ret = location_ielement_get_position(LOCATION_IELEMENT(obj), position, accuracy);
444 LOC_COND_RET(ret != LOCATION_ERROR_NONE, ret, _E, "Fail to get_position [%s]", err_msg(ret));
450 location_get_position_ext(LocationObject *obj, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
452 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
453 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
454 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
455 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
457 int ret = LOCATION_ERROR_NONE;
459 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
460 ret = location_check_cynara(LOCATION_PRIVILEGE);
461 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
464 ret = location_ielement_get_position_ext(LOCATION_IELEMENT(obj), position, velocity, accuracy);
465 LOC_IF_FAIL(ret, _E, "Fail to get_position_ext [%s]", err_msg(ret));
471 location_get_last_position(LocationObject *obj, LocationPosition **position, LocationAccuracy **accuracy)
473 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
474 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
475 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
477 int ret = LOCATION_ERROR_NONE;
479 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
480 ret = location_check_cynara(LOCATION_PRIVILEGE);
481 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
484 ret = location_ielement_get_last_position(LOCATION_IELEMENT(obj), position, accuracy);
485 LOC_IF_FAIL(ret, _E, "Fail to get_last_position [%s]", err_msg(ret));
491 location_get_last_position_ext(LocationObject *obj, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
493 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
494 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
495 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
496 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
498 int ret = LOCATION_ERROR_NONE;
500 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
501 ret = location_check_cynara(LOCATION_PRIVILEGE);
502 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
505 ret = location_ielement_get_last_position_ext(LOCATION_IELEMENT(obj), position, velocity, accuracy);
506 LOC_IF_FAIL(ret, _E, "Fail to get_last_position_ext [%s]", err_msg(ret));
512 location_get_nmea(LocationObject *obj, char **nmea)
514 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
515 g_return_val_if_fail(nmea, LOCATION_ERROR_PARAMETER);
517 int ret = LOCATION_ERROR_NONE;
518 ret = location_ielement_get_nmea(LOCATION_IELEMENT(obj), nmea);
519 LOC_IF_FAIL(ret, _E, "Fail to get_nmea [%s]", err_msg(ret));
526 location_get_satellite(LocationObject *obj, LocationSatellite **satellite)
528 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
529 g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
531 int ret = LOCATION_ERROR_NONE;
533 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
534 ret = location_check_cynara(LOCATION_PRIVILEGE);
535 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
538 ret = location_ielement_get_satellite(LOCATION_IELEMENT(obj), satellite);
539 LOC_IF_FAIL(ret, _E, "Fail to get_satellite [%s]", err_msg(ret));
545 location_get_batch(LocationObject *obj, LocationBatch **batch)
547 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
548 g_return_val_if_fail(batch, LOCATION_ERROR_PARAMETER);
550 int ret = LOCATION_ERROR_NONE;
552 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
553 ret = location_check_cynara(LOCATION_PRIVILEGE);
554 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
557 ret = location_ielement_get_batch(LOCATION_IELEMENT(obj), batch);
558 LOC_IF_FAIL(ret, _E, "Fail to get_batch [%s]", err_msg(ret));
564 location_get_last_satellite(LocationObject *obj, LocationSatellite **satellite)
566 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
567 g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
569 int ret = LOCATION_ERROR_NONE;
571 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
572 ret = location_check_cynara(LOCATION_PRIVILEGE);
573 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
576 ret = location_ielement_get_last_satellite(LOCATION_IELEMENT(obj), satellite);
577 LOC_IF_FAIL(ret, _E, "Fail to get_last_satellite [%s]", err_msg(ret));
583 location_get_velocity(LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy)
585 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
586 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
587 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
589 int ret = LOCATION_ERROR_NONE;
591 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
592 ret = location_check_cynara(LOCATION_PRIVILEGE);
593 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
596 ret = location_ielement_get_velocity(LOCATION_IELEMENT(obj), velocity, accuracy);
597 LOC_IF_FAIL(ret, _E, "Fail to get_velocity [%s]", err_msg(ret));
603 location_get_last_velocity(LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy)
605 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
606 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
607 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
609 int ret = LOCATION_ERROR_NONE;
611 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
612 ret = location_check_cynara(LOCATION_PRIVILEGE);
613 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
616 ret = location_ielement_get_last_velocity(LOCATION_IELEMENT(obj), velocity, accuracy);
617 LOC_IF_FAIL(ret, _E, "Fail to get_last_velocity [%s]", err_msg(ret));
623 location_get_accessibility_state(LocationAccessState *state)
625 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
626 int ret = location_check_cynara(LOCATION_PRIVILEGE);
628 if (ret == LOCATION_ERROR_NONE) {
629 *state = LOCATION_ACCESS_ALLOWED;
631 *state = LOCATION_ACCESS_DENIED;
632 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
635 *state = LOCATION_ACCESS_ALLOWED;
638 return LOCATION_ERROR_NONE;
642 location_set_accessibility_state(LocationAccessState state)
644 int auth = LOCATION_APP_NOT_FOUND;
645 int ret = LOCATION_ERROR_NONE;
648 case LOCATION_ACCESS_DENIED:
649 auth = LOCATION_APP_OFF;
651 case LOCATION_ACCESS_ALLOWED:
652 auth = LOCATION_APP_ON;
654 case LOCATION_ACCESS_NONE:
656 return LOCATION_ERROR_PARAMETER;
659 ret = location_application_set_authority(auth);
660 LOCATION_LOGD("set_accessibility_state [%d], Error[%d]", auth, ret);
665 location_send_command(const char *cmd)
667 g_return_val_if_fail(cmd, LOCATION_ERROR_PARAMETER);
668 return LOCATION_ERROR_NOT_AVAILABLE;
672 location_set_option(LocationObject *obj, const char *option)
674 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
675 int ret = LOCATION_ERROR_NONE;
677 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
678 ret = location_check_cynara(LOCATION_PRIVILEGE);
679 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
682 ret = location_ielement_set_option(LOCATION_IELEMENT(obj), option);
683 LOC_IF_FAIL(ret, _E, "Fail to get_velocity [%s]", err_msg(ret));
692 location_enable_mock(const int enable)
694 int ret = LOCATION_ERROR_NONE;
696 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
697 ret = location_check_cynara(LOCATION_PRIVILEGE);
698 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
701 #if 0 /* Tizen platform didn't turn developer option on */
702 gboolean developer_option = FALSE;
704 ret = vconf_get_bool(VCONFKEY_SETAPPL_DEVELOPER_OPTION_STATE, &developer_option);
705 LOC_COND_RET(!developer_option, LOCATION_ERROR_NOT_ALLOWED, _E, "Cannot enable mock location because developer option is not turned on", ret);
708 ret = vconf_set_int(VCONFKEY_LOCATION_MOCK_ENABLED, enable);
709 if (ret != VCONF_OK) {
710 LOCATION_SECLOG("vconf_set_int failed [MOCK_ENABLED], ret=[%d]", ret);
711 return LOCATION_ERROR_NOT_ALLOWED;
718 location_set_mock_location(LocationObject *obj, const LocationPosition *position, const LocationVelocity *velocity, const LocationAccuracy *accuracy)
720 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
721 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
722 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
723 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
725 int ret = LOCATION_ERROR_NONE;
726 ret = location_ielement_set_mock_location(LOCATION_IELEMENT(obj), position, velocity, accuracy);
727 LOC_IF_FAIL(ret, _E, "Fail to set_mock_location [%s]", err_msg(ret));
733 location_clear_mock_location(LocationObject *obj)
735 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
737 int ret = LOCATION_ERROR_NONE;
738 ret = location_ielement_clear_mock_location(LOCATION_IELEMENT(obj));
739 LOC_IF_FAIL(ret, _E, "Fail to clear_mock_location [%s]", err_msg(ret));
745 location_enable_restriction(const int enable)
747 int ret = LOCATION_ERROR_NONE;
750 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
751 ret = location_check_cynara(LOCATION_ENABLE_PRIVILEGE);
752 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
756 ret = vconf_get_int(VCONFKEY_LOCATION_RESTRICT, &restriction);
757 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to get restriction status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
759 if (restriction == RESTRICT_OFF) {
761 if (location_setting_get_int(VCONFKEY_LOCATION_ENABLED)) {
762 value |= RESTRICT_GPS;
763 ret = vconf_set_int(VCONFKEY_LOCATION_ENABLED, 0);
764 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
767 if (location_setting_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED)) {
768 value |= RESTRICT_WPS;
769 ret = vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 0);
770 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
773 if (location_setting_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION)) {
774 value |= RESTRICT_HYBRID;
775 ret = vconf_set_int(VCONFKEY_LOCATION_USE_MY_LOCATION, 0);
776 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
780 value = RESTRICT_NONE;
782 ret = vconf_set_int(VCONFKEY_LOCATION_RESTRICT, value);
783 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set value. %d [%s]", value, err_msg(LOCATION_ERROR_NOT_ALLOWED));
787 ret = vconf_get_int(VCONFKEY_LOCATION_RESTRICT, &restriction);
788 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to get restriction status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
790 if (restriction > RESTRICT_OFF) {
792 if (restriction & RESTRICT_GPS) {
793 ret = vconf_set_int(VCONFKEY_LOCATION_ENABLED, 1);
794 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
797 if (restriction & RESTRICT_WPS) {
798 ret = vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 1);
799 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
802 if (restriction & RESTRICT_HYBRID) {
803 ret = vconf_set_int(VCONFKEY_LOCATION_USE_MY_LOCATION, 1);
804 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
807 ret = vconf_set_int(VCONFKEY_LOCATION_RESTRICT, RESTRICT_OFF);
808 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));
812 return LOCATION_ERROR_NONE;