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"
46 typedef struct _LocationSetting {
47 LocationSettingCb callback;
60 static LocationSetting g_location_setting;
61 static bool is_method_created[_METHOD_MAX] = {false};
63 static char *__convert_setting_key(LocationMethod method)
67 case LOCATION_METHOD_HYBRID:
68 key = g_strdup(VCONFKEY_LOCATION_USE_MY_LOCATION);
70 case LOCATION_METHOD_GPS:
71 key = g_strdup(VCONFKEY_LOCATION_ENABLED);
73 case LOCATION_METHOD_WPS:
74 key = g_strdup(VCONFKEY_LOCATION_NETWORK_ENABLED);
76 case INTERNAL_METHOD_MOCK:
77 key = g_strdup(VCONFKEY_LOCATION_MOCK_ENABLED);
86 static LocationMethod __convert_method_from_key(const char *key)
88 LocationMethod _method = LOCATION_METHOD_NONE;
89 if (g_strcmp0(key, VCONFKEY_LOCATION_USE_MY_LOCATION) == 0)
90 _method = LOCATION_METHOD_HYBRID;
91 else if (g_strcmp0(key, VCONFKEY_LOCATION_ENABLED) == 0)
92 _method = LOCATION_METHOD_GPS;
93 else if (g_strcmp0(key, VCONFKEY_LOCATION_NETWORK_ENABLED) == 0)
94 _method = LOCATION_METHOD_WPS;
99 static void __location_setting_cb(keynode_t *key, gpointer data)
101 if (key == NULL || data == NULL)
104 LocationSetting *_setting = (LocationSetting *)data;
105 LocationMethod _method = LOCATION_METHOD_NONE;
107 if (_setting->callback) {
108 _method = __convert_method_from_key(vconf_keynode_get_name(key));
109 _setting->callback(_method, location_setting_get_key_val(key), _setting->user_data);
114 int location_init(void)
116 #if !GLIB_CHECK_VERSION(2, 35, 0)
120 #if !GLIB_CHECK_VERSION(2, 31, 0)
121 if (!g_thread_supported()) g_thread_init(NULL);
123 if (FALSE == module_init())
124 return LOCATION_ERROR_NOT_AVAILABLE;
126 return LOCATION_ERROR_NONE;
129 EXPORT_API LocationObject *
130 location_new(LocationMethod method, gboolean is_internal_for_hybrid)
132 LocationObject *self = NULL;
133 LOCATION_LOGD("method : %d, is_internal_for_hybrid[%d]", method, is_internal_for_hybrid);
136 case LOCATION_METHOD_HYBRID:
137 if (is_method_created[_METHOD_HYBRID]) {
138 LOCATION_LOGE("Hybrid handle already exist.");
140 self = g_object_new(LOCATION_TYPE_HYBRID, NULL);
141 is_method_created[_METHOD_HYBRID] = true;
144 case LOCATION_METHOD_GPS:
145 if (is_internal_for_hybrid) {
146 if (is_method_created[_METHOD_GPS_2]) {
147 LOCATION_LOGD("Hybrid(GPS) handle already exist.");
149 is_method_created[_METHOD_GPS_2] = true;
150 self = g_object_new(LOCATION_TYPE_GPS, NULL);
153 if (is_method_created[_METHOD_GPS_1]) {
154 LOCATION_LOGE("GPS handle already exist.");
156 is_method_created[_METHOD_GPS_1] = true;
157 self = g_object_new(LOCATION_TYPE_GPS, NULL);
161 case LOCATION_METHOD_WPS:
162 if (is_internal_for_hybrid) {
163 if (is_method_created[_METHOD_WPS_2]) {
164 LOCATION_LOGD("Hybrid(WPS) handle already exist.");
166 is_method_created[_METHOD_WPS_2] = true;
167 self = g_object_new(LOCATION_TYPE_WPS, NULL);
170 if (is_method_created[_METHOD_WPS_1]) {
171 LOCATION_LOGE("WPS handle already exist.");
173 is_method_created[_METHOD_WPS_1] = true;
174 self = g_object_new(LOCATION_TYPE_WPS, NULL);
178 case LOCATION_METHOD_PASSIVE:
179 self = g_object_new(LOCATION_TYPE_PASSIVE, NULL);
185 LOC_COND_LOG(!self, _E, "Fail to create location object. [method=%d]", method);
190 location_free(LocationObject *obj, gboolean is_internal_for_hybrid)
192 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
193 if (G_OBJECT_TYPE(obj) == LOCATION_TYPE_HYBRID) {
194 is_method_created[_METHOD_HYBRID] = false;
195 } else if (G_OBJECT_TYPE(obj) == LOCATION_TYPE_GPS) {
196 if (is_internal_for_hybrid)
197 is_method_created[_METHOD_GPS_2] = false;
199 is_method_created[_METHOD_GPS_1] = false;
200 } else if (G_OBJECT_TYPE(obj) == LOCATION_TYPE_WPS) {
201 if (is_internal_for_hybrid)
202 is_method_created[_METHOD_WPS_2] = false;
204 is_method_created[_METHOD_WPS_1] = false;
207 return LOCATION_ERROR_NONE;
211 location_request_single_location(LocationObject *obj, int timeout)
213 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
215 int ret = LOCATION_ERROR_NONE;
216 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
217 ret = location_check_cynara(LOCATION_PRIVILEGE);
218 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
220 ret = location_ielement_request_single_location(LOCATION_IELEMENT(obj), timeout);
221 LOC_IF_FAIL(ret, _E, "Fail to request single location [%s]", err_msg(ret));
227 location_cancel_single_location(LocationObject *obj)
229 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
231 int ret = LOCATION_ERROR_NONE;
232 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
233 ret = location_check_cynara(LOCATION_PRIVILEGE);
234 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
237 ret = location_ielement_cancel_single_location(LOCATION_IELEMENT(obj));
238 if (ret != LOCATION_ERROR_NONE)
239 LOCATION_LOGE("Fail to cancel single location. Error [%d]", ret);
245 location_start(LocationObject *obj)
247 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
249 int ret = LOCATION_ERROR_NONE;
250 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
251 ret = location_check_cynara(LOCATION_PRIVILEGE);
252 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
255 ret = location_ielement_start(LOCATION_IELEMENT(obj));
256 LOC_IF_FAIL(ret, _E, "Fail to start [%s]", err_msg(ret));
262 location_stop(LocationObject *obj)
264 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
266 int ret = LOCATION_ERROR_NONE;
267 ret = location_ielement_stop(LOCATION_IELEMENT(obj));
268 LOC_IF_FAIL(ret, _E, "Fail to stop [%s]", err_msg(ret));
274 location_start_batch(LocationObject *obj)
276 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
277 int ret = LOCATION_ERROR_NONE;
279 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
280 ret = location_check_cynara(LOCATION_PRIVILEGE);
281 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
284 ret = location_ielement_start_batch(LOCATION_IELEMENT(obj));
285 LOC_IF_FAIL(ret, _E, "Fail to start_batch [%s]", err_msg(ret));
291 location_stop_batch(LocationObject *obj)
293 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
294 int ret = LOCATION_ERROR_NONE;
295 ret = location_ielement_stop_batch(LOCATION_IELEMENT(obj));
296 LOC_IF_FAIL(ret, _E, "Fail to stop_batch [%d]", err_msg(ret));
302 location_is_supported_method(LocationMethod method)
304 gboolean is_supported = FALSE;
307 case LOCATION_METHOD_HYBRID:
308 if (module_is_supported("gps") || module_is_supported("wps"))
311 case LOCATION_METHOD_GPS:
312 is_supported = module_is_supported("gps");
314 case LOCATION_METHOD_WPS:
315 is_supported = module_is_supported("wps");
317 case LOCATION_METHOD_PASSIVE:
318 is_supported = module_is_supported("passive");
328 location_is_enabled_method(LocationMethod method, int *is_enabled)
330 g_return_val_if_fail(is_enabled, LOCATION_ERROR_PARAMETER);
332 int vconf_ret = VCONF_ERROR;
334 char *_key = __convert_setting_key(method);
335 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
337 vconf_ret = vconf_get_int(_key, &vconf_val);
338 if (vconf_ret != VCONF_OK) {
339 LOCATION_SECLOG("vconf_get failed [%s], error [%d]", _key, vconf_ret);
341 return LOCATION_ERROR_NOT_AVAILABLE;
343 LOCATION_SECLOG("[%s]:[%d]", _key, vconf_val);
346 *is_enabled = vconf_val;
349 return LOCATION_ERROR_NONE;
353 location_enable_method(const LocationMethod method, const int enable)
358 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
359 ret = location_check_cynara(LOCATION_ENABLE_PRIVILEGE);
360 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
363 if (location_setting_get_int(VCONFKEY_LOCATION_RESTRICT) > RESTRICT_OFF) {
364 LOCATION_SECLOG("Location setting is denied by DPM");
365 return LOCATION_ERROR_NOT_ALLOWED;
369 _key = __convert_setting_key(method);
370 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
372 ret = vconf_set_int(_key, enable);
373 if (ret != VCONF_OK) {
374 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
376 return LOCATION_ERROR_NOT_ALLOWED;
381 _key = __convert_setting_key(LOCATION_METHOD_HYBRID);
382 LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", LOCATION_METHOD_HYBRID, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
385 ret = vconf_set_int(_key, enable);
386 if (ret != VCONF_OK) {
387 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
389 return LOCATION_ERROR_NOT_ALLOWED;
393 int enabled_state = 0;
395 for (i = LOCATION_METHOD_GPS; i < LOCATION_METHOD_MAX; i++) {
396 _key = __convert_setting_key(i);
397 enabled_state |= location_setting_get_int(_key);
400 if (!enabled_state) {
401 _key = __convert_setting_key(LOCATION_METHOD_HYBRID);
402 ret = vconf_set_int(_key, enable);
403 if (ret != VCONF_OK) {
404 LOCATION_SECLOG("vconf_set_int failed [%s], error [%d]", _key, ret);
406 return LOCATION_ERROR_NOT_ALLOWED;
408 LOCATION_SECLOG("[%s]:[%d]", _key, ret);
418 location_add_setting_notify(LocationMethod method, LocationSettingCb callback, void *user_data)
420 int ret = LOCATION_ERROR_NONE;
421 char *_key = __convert_setting_key(method);
422 LOC_COND_RET(!_key, LOCATION_ERROR_PARAMETER, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_PARAMETER));
424 g_location_setting.callback = callback;
425 g_location_setting.user_data = user_data;
427 ret = location_setting_add_notify(_key, __location_setting_cb, &g_location_setting);
434 location_ignore_setting_notify(LocationMethod method, LocationSettingCb callback)
436 int ret = LOCATION_ERROR_NONE;
437 char *_key = __convert_setting_key(method);
438 LOC_COND_RET(!_key, LOCATION_ERROR_PARAMETER, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_PARAMETER));
440 g_location_setting.callback = NULL;
441 g_location_setting.user_data = NULL;
443 ret = location_setting_ignore_notify(_key, __location_setting_cb);
451 location_get_position(LocationObject *obj, LocationPosition **position, LocationAccuracy **accuracy)
453 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
454 g_return_val_if_fail(position, 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(LOCATION_IELEMENT(obj), position, accuracy);
465 LOC_COND_RET(ret != LOCATION_ERROR_NONE, ret, _E, "Fail to get_position [%s]", err_msg(ret));
471 location_get_position_ext(LocationObject *obj, LocationPosition **position, LocationVelocity **velocity, 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(velocity, LOCATION_ERROR_PARAMETER);
476 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
478 int ret = LOCATION_ERROR_NONE;
480 if (_get_tizen_profile() != 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_position_ext(LOCATION_IELEMENT(obj), position, velocity, accuracy);
486 LOC_IF_FAIL(ret, _E, "Fail to get_position_ext [%s]", err_msg(ret));
492 location_get_last_position(LocationObject *obj, LocationPosition **position, LocationAccuracy **accuracy)
494 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
495 g_return_val_if_fail(position, 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(LOCATION_IELEMENT(obj), position, accuracy);
506 LOC_IF_FAIL(ret, _E, "Fail to get_last_position [%s]", err_msg(ret));
512 location_get_last_position_ext(LocationObject *obj, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
514 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
515 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
516 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
517 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
519 int ret = LOCATION_ERROR_NONE;
521 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
522 ret = location_check_cynara(LOCATION_PRIVILEGE);
523 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
526 ret = location_ielement_get_last_position_ext(LOCATION_IELEMENT(obj), position, velocity, accuracy);
527 LOC_IF_FAIL(ret, _E, "Fail to get_last_position_ext [%s]", err_msg(ret));
533 location_get_nmea(LocationObject *obj, char **nmea)
535 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
536 g_return_val_if_fail(nmea, LOCATION_ERROR_PARAMETER);
538 int ret = LOCATION_ERROR_NONE;
539 ret = location_ielement_get_nmea(LOCATION_IELEMENT(obj), nmea);
540 LOC_IF_FAIL(ret, _E, "Fail to get_nmea [%s]", err_msg(ret));
547 location_get_satellite(LocationObject *obj, LocationSatellite **satellite)
549 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
550 g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
552 int ret = LOCATION_ERROR_NONE;
554 if (_get_tizen_profile() != 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_satellite(LOCATION_IELEMENT(obj), satellite);
560 LOC_IF_FAIL(ret, _E, "Fail to get_satellite [%s]", err_msg(ret));
566 location_get_batch(LocationObject *obj, LocationBatch **batch)
568 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
569 g_return_val_if_fail(batch, 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_batch(LOCATION_IELEMENT(obj), batch);
579 LOC_IF_FAIL(ret, _E, "Fail to get_batch [%s]", err_msg(ret));
585 location_get_last_satellite(LocationObject *obj, LocationSatellite **satellite)
587 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
588 g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
590 int ret = LOCATION_ERROR_NONE;
592 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
593 ret = location_check_cynara(LOCATION_PRIVILEGE);
594 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
597 ret = location_ielement_get_last_satellite(LOCATION_IELEMENT(obj), satellite);
598 LOC_IF_FAIL(ret, _E, "Fail to get_last_satellite [%s]", err_msg(ret));
604 location_get_velocity(LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy)
606 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
607 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
608 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
610 int ret = LOCATION_ERROR_NONE;
612 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
613 ret = location_check_cynara(LOCATION_PRIVILEGE);
614 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
617 ret = location_ielement_get_velocity(LOCATION_IELEMENT(obj), velocity, accuracy);
618 LOC_IF_FAIL(ret, _E, "Fail to get_velocity [%s]", err_msg(ret));
624 location_get_last_velocity(LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy)
626 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
627 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
628 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
630 int ret = LOCATION_ERROR_NONE;
632 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
633 ret = location_check_cynara(LOCATION_PRIVILEGE);
634 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
637 ret = location_ielement_get_last_velocity(LOCATION_IELEMENT(obj), velocity, accuracy);
638 LOC_IF_FAIL(ret, _E, "Fail to get_last_velocity [%s]", err_msg(ret));
644 location_get_accessibility_state(LocationAccessState *state)
646 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
647 int ret = location_check_cynara(LOCATION_PRIVILEGE);
649 if (ret == LOCATION_ERROR_NONE) {
650 *state = LOCATION_ACCESS_ALLOWED;
652 *state = LOCATION_ACCESS_DENIED;
653 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
656 *state = LOCATION_ACCESS_ALLOWED;
659 return LOCATION_ERROR_NONE;
663 location_set_accessibility_state(LocationAccessState state)
665 int auth = LOCATION_APP_NOT_FOUND;
666 int ret = LOCATION_ERROR_NONE;
669 case LOCATION_ACCESS_DENIED:
670 auth = LOCATION_APP_OFF;
672 case LOCATION_ACCESS_ALLOWED:
673 auth = LOCATION_APP_ON;
675 case LOCATION_ACCESS_NONE:
677 return LOCATION_ERROR_PARAMETER;
680 ret = location_application_set_authority(auth);
681 LOCATION_LOGD("set_accessibility_state [%d], Error[%d]", auth, ret);
686 location_send_command(const char *cmd)
688 g_return_val_if_fail(cmd, LOCATION_ERROR_PARAMETER);
689 return LOCATION_ERROR_NOT_AVAILABLE;
693 location_set_option(LocationObject *obj, const char *option)
695 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
696 int ret = LOCATION_ERROR_NONE;
698 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
699 ret = location_check_cynara(LOCATION_PRIVILEGE);
700 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
703 ret = location_ielement_set_option(LOCATION_IELEMENT(obj), option);
704 LOC_IF_FAIL(ret, _E, "Fail to get_velocity [%s]", err_msg(ret));
713 location_enable_mock(const int enable)
715 int ret = LOCATION_ERROR_NONE;
717 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
718 ret = location_check_cynara(LOCATION_PRIVILEGE);
719 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
722 #if 0 /* Tizen platform didn't turn developer option on */
723 gboolean developer_option = FALSE;
725 ret = vconf_get_bool(VCONFKEY_SETAPPL_DEVELOPER_OPTION_STATE, &developer_option);
726 LOC_COND_RET(!developer_option, LOCATION_ERROR_NOT_ALLOWED, _E, "Cannot enable mock location because developer option is not turned on", ret);
729 ret = vconf_set_int(VCONFKEY_LOCATION_MOCK_ENABLED, enable);
730 if (ret != VCONF_OK) {
731 LOCATION_SECLOG("vconf_set_int failed [MOCK_ENABLED], ret=[%d]", ret);
732 return LOCATION_ERROR_NOT_ALLOWED;
739 location_set_mock_location(LocationObject *obj, const LocationPosition *position, const LocationVelocity *velocity, const LocationAccuracy *accuracy)
741 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
742 g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
743 g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
744 g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
746 int ret = LOCATION_ERROR_NONE;
747 ret = location_ielement_set_mock_location(LOCATION_IELEMENT(obj), position, velocity, accuracy);
748 LOC_IF_FAIL(ret, _E, "Fail to set_mock_location [%s]", err_msg(ret));
754 location_clear_mock_location(LocationObject *obj)
756 g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
758 int ret = LOCATION_ERROR_NONE;
759 ret = location_ielement_clear_mock_location(LOCATION_IELEMENT(obj));
760 LOC_IF_FAIL(ret, _E, "Fail to clear_mock_location [%s]", err_msg(ret));
766 location_enable_restriction(const int enable)
768 int ret = LOCATION_ERROR_NONE;
771 if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
772 ret = location_check_cynara(LOCATION_ENABLE_PRIVILEGE);
773 LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
777 ret = vconf_get_int(VCONFKEY_LOCATION_RESTRICT, &restriction);
778 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to get restriction status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
780 if (restriction == RESTRICT_OFF) {
782 if (location_setting_get_int(VCONFKEY_LOCATION_ENABLED)) {
783 value |= RESTRICT_GPS;
784 ret = vconf_set_int(VCONFKEY_LOCATION_ENABLED, 0);
785 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
788 if (location_setting_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED)) {
789 value |= RESTRICT_WPS;
790 ret = vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 0);
791 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
794 if (location_setting_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION)) {
795 value |= RESTRICT_HYBRID;
796 ret = vconf_set_int(VCONFKEY_LOCATION_USE_MY_LOCATION, 0);
797 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
801 value = RESTRICT_NONE;
803 ret = vconf_set_int(VCONFKEY_LOCATION_RESTRICT, value);
804 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set value. %d [%s]", value, err_msg(LOCATION_ERROR_NOT_ALLOWED));
808 ret = vconf_get_int(VCONFKEY_LOCATION_RESTRICT, &restriction);
809 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to get restriction status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
811 if (restriction > RESTRICT_OFF) {
813 if (restriction & RESTRICT_GPS) {
814 ret = vconf_set_int(VCONFKEY_LOCATION_ENABLED, 1);
815 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
818 if (restriction & RESTRICT_WPS) {
819 ret = vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 1);
820 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
823 if (restriction & RESTRICT_HYBRID) {
824 ret = vconf_set_int(VCONFKEY_LOCATION_USE_MY_LOCATION, 1);
825 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
828 ret = vconf_set_int(VCONFKEY_LOCATION_RESTRICT, RESTRICT_OFF);
829 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));
833 return LOCATION_ERROR_NONE;