4 * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
28 #include "location-log.h"
29 #include "location-setting.h"
30 #include "location-ielement.h"
31 #include "location-hybrid.h"
32 #include "location-gps.h"
33 #include "location-wps.h"
34 #include "location-passive.h"
35 #include "location-position.h"
36 #include "module-internal.h"
37 #include "location-common-util.h"
38 #include "location-privacy.h"
40 #define LOCATION_PRIVILEGE "http://tizen.org/privilege/location"
41 #define LOCATION_ENABLE_PRIVILEGE "http://tizen.org/privilege/location.enable"
43 typedef struct _LocationSetting {
44 LocationSettingCb callback;
48 static LocationSetting g_location_setting;
50 static char *__convert_setting_key(LocationMethod method)
54 case LOCATION_METHOD_HYBRID:
55 key = g_strdup(VCONFKEY_LOCATION_USE_MY_LOCATION);
57 case LOCATION_METHOD_GPS:
58 key = g_strdup(VCONFKEY_LOCATION_ENABLED);
60 case LOCATION_METHOD_WPS:
61 key = g_strdup(VCONFKEY_LOCATION_NETWORK_ENABLED);
63 case INTERNAL_METHOD_MOCK:
64 key = g_strdup(VCONFKEY_LOCATION_MOCK_ENABLED);
73 static LocationMethod __convert_method_from_key(const char *key)
75 LocationMethod _method = LOCATION_METHOD_NONE;
76 if (g_strcmp0(key, VCONFKEY_LOCATION_USE_MY_LOCATION) == 0)
77 _method = LOCATION_METHOD_HYBRID;
78 else if (g_strcmp0(key, VCONFKEY_LOCATION_ENABLED) == 0)
79 _method = LOCATION_METHOD_GPS;
80 else if (g_strcmp0(key, VCONFKEY_LOCATION_NETWORK_ENABLED) == 0)
81 _method = LOCATION_METHOD_WPS;
86 static void __location_setting_cb(keynode_t *key, gpointer data)
88 if (key == NULL || data == NULL)
91 LocationSetting *_setting = (LocationSetting *)data;
92 LocationMethod _method = LOCATION_METHOD_NONE;
94 if (_setting->callback) {
95 _method = __convert_method_from_key(vconf_keynode_get_name(key));
96 _setting->callback(_method, location_setting_get_key_val(key), _setting->user_data);
101 int location_init(void)
103 #if !GLIB_CHECK_VERSION(2, 35, 0)
107 #if !GLIB_CHECK_VERSION(2, 31, 0)
108 if (!g_thread_supported()) g_thread_init(NULL);
110 if (FALSE == module_init())
111 return LOCATION_ERROR_NOT_AVAILABLE;
113 return LOCATION_ERROR_NONE;
116 EXPORT_API LocationObject *
117 location_new(LocationMethod method, gboolean multi_handle)
119 LocationObject *self = NULL;
120 LOCATION_LOGD("method : %d, multi_handle[%d]", method, multi_handle);
123 case LOCATION_METHOD_HYBRID:
124 self = g_object_new(LOCATION_TYPE_HYBRID, NULL);
126 case LOCATION_METHOD_GPS:
127 self = g_object_new(LOCATION_TYPE_GPS, NULL);
129 case LOCATION_METHOD_WPS:
130 self = g_object_new(LOCATION_TYPE_WPS, NULL);
132 case LOCATION_METHOD_PASSIVE:
133 self = g_object_new(LOCATION_TYPE_PASSIVE, NULL);
139 LOC_COND_LOG(!self, _E, "Fail to create location object. [method=%d]", method);
144 location_free(LocationObject *obj, gboolean multi_handle)
146 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
148 return LOCATION_ERROR_NONE;
152 location_request_single_location(LocationObject *obj, int timeout)
154 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
156 int ret = LOCATION_ERROR_NONE;
157 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
158 ret = location_check_cynara(LOCATION_PRIVILEGE);
159 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
161 ret = location_ielement_request_single_location(LOCATION_IELEMENT(obj), timeout);
162 LOC_IF_FAIL(ret, _E, "Fail to request single location [%s]", err_msg(ret));
168 location_cancel_single_location(LocationObject *obj)
170 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
172 int ret = LOCATION_ERROR_NONE;
173 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
174 ret = location_check_cynara(LOCATION_PRIVILEGE);
175 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
178 ret = location_ielement_cancel_single_location(LOCATION_IELEMENT(obj));
179 if (ret != LOCATION_ERROR_NONE)
180 LOCATION_LOGE("Fail to cancel single location. Error [%d]", ret);
186 location_start(LocationObject *obj)
188 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
190 int ret = LOCATION_ERROR_NONE;
191 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
192 ret = location_check_cynara(LOCATION_PRIVILEGE);
193 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
196 ret = location_ielement_start(LOCATION_IELEMENT(obj));
197 LOC_IF_FAIL(ret, _E, "Fail to start [%s]", err_msg(ret));
203 location_stop(LocationObject *obj)
205 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
207 int ret = LOCATION_ERROR_NONE;
208 ret = location_ielement_stop(LOCATION_IELEMENT(obj));
209 LOC_IF_FAIL(ret, _E, "Fail to stop [%s]", err_msg(ret));
215 location_start_batch(LocationObject *obj)
217 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
218 int ret = LOCATION_ERROR_NONE;
220 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
221 ret = location_check_cynara(LOCATION_PRIVILEGE);
222 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
225 ret = location_ielement_start_batch(LOCATION_IELEMENT(obj));
226 LOC_IF_FAIL(ret, _E, "Fail to start_batch [%s]", err_msg(ret));
232 location_stop_batch(LocationObject *obj)
234 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
235 int ret = LOCATION_ERROR_NONE;
236 ret = location_ielement_stop_batch(LOCATION_IELEMENT(obj));
237 LOC_IF_FAIL(ret, _E, "Fail to stop_batch [%s]", err_msg(ret));
243 location_is_supported_method(LocationMethod method)
245 gboolean is_supported = FALSE;
248 case LOCATION_METHOD_HYBRID:
249 if (module_is_supported("gps") || module_is_supported("wps"))
252 case LOCATION_METHOD_GPS:
253 is_supported = module_is_supported("gps");
255 case LOCATION_METHOD_WPS:
256 is_supported = module_is_supported("wps");
258 case LOCATION_METHOD_PASSIVE:
259 is_supported = module_is_supported("passive");
269 location_is_enabled_method(LocationMethod method, int *is_enabled)
271 g_return_val_if_fail(is_enabled, LOCATION_ERROR_PARAMETER);
273 int vconf_ret = VCONF_ERROR;
275 char *_key = __convert_setting_key(method);
276 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
278 vconf_ret = vconf_get_int(_key, &vconf_val);
279 if (vconf_ret != VCONF_OK) {
280 LOCATION_SECLOG("vconf_get failed [%s], error [%d]", _key, vconf_ret);
282 return LOCATION_ERROR_NOT_AVAILABLE;
284 LOCATION_SECLOG("[%s]:[%d]", _key, vconf_val);
287 *is_enabled = vconf_val;
290 return LOCATION_ERROR_NONE;
294 location_enable_method(const LocationMethod method, const int enable)
299 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
300 ret = location_check_cynara(LOCATION_ENABLE_PRIVILEGE);
301 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
304 if (location_setting_get_int(VCONFKEY_LOCATION_RESTRICT) > RESTRICT_OFF) {
305 LOCATION_SECLOG("Location setting is denied by DPM");
306 return LOCATION_ERROR_NOT_ALLOWED;
310 _key = __convert_setting_key(method);
311 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
313 ret = vconf_set_int(_key, enable);
314 if (ret != VCONF_OK) {
315 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
317 return LOCATION_ERROR_NOT_ALLOWED;
322 _key = __convert_setting_key(LOCATION_METHOD_HYBRID);
323 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", LOCATION_METHOD_HYBRID, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
326 ret = vconf_set_int(_key, enable);
327 if (ret != VCONF_OK) {
328 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
330 return LOCATION_ERROR_NOT_ALLOWED;
334 int enabled_state = 0;
336 for (i = LOCATION_METHOD_GPS; i < LOCATION_METHOD_MAX; i++) {
337 _key = __convert_setting_key(i);
338 enabled_state |= location_setting_get_int(_key);
341 if (!enabled_state) {
342 _key = __convert_setting_key(LOCATION_METHOD_HYBRID);
343 ret = vconf_set_int(_key, enable);
344 if (ret != VCONF_OK) {
345 LOCATION_SECLOG("vconf_set_int failed [%s], error [%d]", _key, ret);
347 return LOCATION_ERROR_NOT_ALLOWED;
349 LOCATION_SECLOG("[%s]:[%d]", _key, ret);
359 location_add_setting_notify(LocationMethod method, LocationSettingCb callback, void *user_data)
361 int ret = LOCATION_ERROR_NONE;
362 char *_key = __convert_setting_key(method);
363 LOC_COND_RET(!_key, LOCATION_ERROR_PARAMETER, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_PARAMETER));
365 g_location_setting.callback = callback;
366 g_location_setting.user_data = user_data;
368 ret = location_setting_add_notify(_key, __location_setting_cb, &g_location_setting);
375 location_ignore_setting_notify(LocationMethod method, LocationSettingCb callback)
377 int ret = LOCATION_ERROR_NONE;
378 char *_key = __convert_setting_key(method);
379 LOC_COND_RET(!_key, LOCATION_ERROR_PARAMETER, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_PARAMETER));
381 g_location_setting.callback = NULL;
382 g_location_setting.user_data = NULL;
384 ret = location_setting_ignore_notify(_key, __location_setting_cb);
392 location_get_position(LocationObject *obj, LocationPosition **position, LocationAccuracy **accuracy)
394 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
395 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
396 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
398 int ret = LOCATION_ERROR_NONE;
400 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
401 ret = location_check_cynara(LOCATION_PRIVILEGE);
402 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
405 ret = location_ielement_get_position(LOCATION_IELEMENT(obj), position, accuracy);
406 LOC_COND_RET(ret != LOCATION_ERROR_NONE, ret, _E, "Fail to get_position [%s]", err_msg(ret));
412 location_get_position_ext(LocationObject *obj, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
414 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
415 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
416 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
417 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
419 int ret = LOCATION_ERROR_NONE;
421 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
422 ret = location_check_cynara(LOCATION_PRIVILEGE);
423 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
426 ret = location_ielement_get_position_ext(LOCATION_IELEMENT(obj), position, velocity, accuracy);
427 LOC_IF_FAIL(ret, _E, "Fail to get_position_ext [%s]", err_msg(ret));
433 location_get_last_position(LocationObject *obj, LocationPosition **position, 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 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
442 ret = location_check_cynara(LOCATION_PRIVILEGE);
443 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
446 ret = location_ielement_get_last_position(LOCATION_IELEMENT(obj), position, accuracy);
447 LOC_IF_FAIL(ret, _E, "Fail to get_last_position [%s]", err_msg(ret));
453 location_get_last_position_ext(LocationObject *obj, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
455 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
456 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
457 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
458 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
460 int ret = LOCATION_ERROR_NONE;
462 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
463 ret = location_check_cynara(LOCATION_PRIVILEGE);
464 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
467 ret = location_ielement_get_last_position_ext(LOCATION_IELEMENT(obj), position, velocity, accuracy);
468 LOC_IF_FAIL(ret, _E, "Fail to get_last_position_ext [%s]", err_msg(ret));
474 location_get_nmea(LocationObject *obj, char **nmea)
476 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
477 g_return_val_if_fail(nmea, LOCATION_ERROR_PARAMETER);
479 int ret = LOCATION_ERROR_NONE;
480 ret = location_ielement_get_nmea(LOCATION_IELEMENT(obj), nmea);
481 LOC_IF_FAIL(ret, _E, "Fail to get_nmea [%s]", err_msg(ret));
488 location_get_satellite(LocationObject *obj, LocationSatellite **satellite)
490 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
491 g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
493 int ret = LOCATION_ERROR_NONE;
495 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
496 ret = location_check_cynara(LOCATION_PRIVILEGE);
497 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
500 ret = location_ielement_get_satellite(LOCATION_IELEMENT(obj), satellite);
501 LOC_IF_FAIL(ret, _E, "Fail to get_satellite [%s]", err_msg(ret));
507 location_get_batch(LocationObject *obj, LocationBatch **batch)
509 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
510 g_return_val_if_fail(batch, LOCATION_ERROR_PARAMETER);
512 int ret = LOCATION_ERROR_NONE;
514 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
515 ret = location_check_cynara(LOCATION_PRIVILEGE);
516 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
519 ret = location_ielement_get_batch(LOCATION_IELEMENT(obj), batch);
520 LOC_IF_FAIL(ret, _E, "Fail to get_batch [%s]", err_msg(ret));
526 location_get_last_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_last_satellite(LOCATION_IELEMENT(obj), satellite);
539 LOC_IF_FAIL(ret, _E, "Fail to get_last_satellite [%s]", err_msg(ret));
545 location_get_velocity(LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy)
547 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
548 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
549 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
551 int ret = LOCATION_ERROR_NONE;
553 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
554 ret = location_check_cynara(LOCATION_PRIVILEGE);
555 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
558 ret = location_ielement_get_velocity(LOCATION_IELEMENT(obj), velocity, accuracy);
559 LOC_IF_FAIL(ret, _E, "Fail to get_velocity [%s]", err_msg(ret));
565 location_get_last_velocity(LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy)
567 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
568 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
569 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
571 int ret = LOCATION_ERROR_NONE;
573 if (_get_tizen_profile() != 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_velocity(LOCATION_IELEMENT(obj), velocity, accuracy);
579 LOC_IF_FAIL(ret, _E, "Fail to get_last_velocity [%s]", err_msg(ret));
585 location_get_accessibility_state(LocationAccessState *state)
587 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
588 int ret = location_check_cynara(LOCATION_PRIVILEGE);
590 if (ret == LOCATION_ERROR_NONE) {
591 *state = LOCATION_ACCESS_ALLOWED;
593 *state = LOCATION_ACCESS_DENIED;
594 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
597 *state = LOCATION_ACCESS_ALLOWED;
600 return LOCATION_ERROR_NONE;
604 location_set_accessibility_state(LocationAccessState state)
606 int auth = LOCATION_APP_NOT_FOUND;
607 int ret = LOCATION_ERROR_NONE;
610 case LOCATION_ACCESS_DENIED:
611 auth = LOCATION_APP_OFF;
613 case LOCATION_ACCESS_ALLOWED:
614 auth = LOCATION_APP_ON;
616 case LOCATION_ACCESS_NONE:
618 return LOCATION_ERROR_PARAMETER;
621 ret = location_application_set_authority(auth);
622 LOCATION_LOGD("set_accessibility_state [%d], Error[%d]", auth, ret);
627 location_send_command(const char *cmd)
629 g_return_val_if_fail(cmd, LOCATION_ERROR_PARAMETER);
630 return LOCATION_ERROR_NOT_AVAILABLE;
634 location_set_option(LocationObject *obj, const char *option)
636 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
637 int ret = LOCATION_ERROR_NONE;
639 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
640 ret = location_check_cynara(LOCATION_PRIVILEGE);
641 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
644 ret = location_ielement_set_option(LOCATION_IELEMENT(obj), option);
645 LOC_IF_FAIL(ret, _E, "Fail to get_velocity [%s]", err_msg(ret));
654 location_enable_mock(const int enable)
656 int ret = LOCATION_ERROR_NONE;
658 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
659 ret = location_check_cynara(LOCATION_PRIVILEGE);
660 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
663 #if 0 /* Tizen platform didn't turn developer option on */
664 gboolean developer_option = FALSE;
666 ret = vconf_get_bool(VCONFKEY_SETAPPL_DEVELOPER_OPTION_STATE, &developer_option);
667 LOC_COND_RET(!developer_option, LOCATION_ERROR_NOT_ALLOWED, _E, "Cannot enable mock location because developer option is not turned on", ret);
670 ret = vconf_set_int(VCONFKEY_LOCATION_MOCK_ENABLED, enable);
671 if (ret != VCONF_OK) {
672 LOCATION_SECLOG("vconf_set_int failed [MOCK_ENABLED], ret=[%d]", ret);
673 return LOCATION_ERROR_NOT_ALLOWED;
680 location_set_mock_location(LocationObject *obj, const LocationPosition *position, const LocationVelocity *velocity, const LocationAccuracy *accuracy)
682 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
683 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
684 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
685 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
687 int ret = LOCATION_ERROR_NONE;
688 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
689 ret = location_check_cynara(LOCATION_PRIVILEGE);
690 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
693 ret = location_ielement_set_mock_location(LOCATION_IELEMENT(obj), position, velocity, accuracy);
694 LOC_IF_FAIL(ret, _E, "Fail to set_mock_location [%s]", err_msg(ret));
700 location_clear_mock_location(LocationObject *obj)
702 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
704 int ret = LOCATION_ERROR_NONE;
705 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
706 ret = location_check_cynara(LOCATION_PRIVILEGE);
707 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
710 ret = location_ielement_clear_mock_location(LOCATION_IELEMENT(obj));
711 LOC_IF_FAIL(ret, _E, "Fail to clear_mock_location [%s]", err_msg(ret));
717 location_enable_restriction(const int enable)
719 int ret = LOCATION_ERROR_NONE;
722 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
723 ret = location_check_cynara(LOCATION_ENABLE_PRIVILEGE);
724 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
728 ret = vconf_get_int(VCONFKEY_LOCATION_RESTRICT, &restriction);
729 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to get restriction status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
731 if (restriction == RESTRICT_OFF) {
733 if (location_setting_get_int(VCONFKEY_LOCATION_ENABLED)) {
734 value |= RESTRICT_GPS;
735 ret = vconf_set_int(VCONFKEY_LOCATION_ENABLED, 0);
736 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
739 if (location_setting_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED)) {
740 value |= RESTRICT_WPS;
741 ret = vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 0);
742 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
745 if (location_setting_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION)) {
746 value |= RESTRICT_HYBRID;
747 ret = vconf_set_int(VCONFKEY_LOCATION_USE_MY_LOCATION, 0);
748 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
752 value = RESTRICT_NONE;
754 ret = vconf_set_int(VCONFKEY_LOCATION_RESTRICT, value);
755 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set value. %d [%s]", value, err_msg(LOCATION_ERROR_NOT_ALLOWED));
759 ret = vconf_get_int(VCONFKEY_LOCATION_RESTRICT, &restriction);
760 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to get restriction status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
762 if (restriction > RESTRICT_OFF) {
764 if (restriction & RESTRICT_GPS) {
765 ret = vconf_set_int(VCONFKEY_LOCATION_ENABLED, 1);
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 (restriction & RESTRICT_WPS) {
770 ret = vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 1);
771 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
774 if (restriction & RESTRICT_HYBRID) {
775 ret = vconf_set_int(VCONFKEY_LOCATION_USE_MY_LOCATION, 1);
776 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
779 ret = vconf_set_int(VCONFKEY_LOCATION_RESTRICT, RESTRICT_OFF);
780 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));
784 return LOCATION_ERROR_NONE;