[ACR-716] Mock location
[platform/core/location/lbs-location.git] / location / manager / location.c
1 /*
2  * libslp-location
3  *
4  * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
7  *                      Genie Kim <daejins.kim@samsung.com>
8  *
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
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <glib.h>
27 #include <stdio.h>
28 #include <vconf.h>
29
30 #include "location.h"
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-position.h"
38 #include "module-internal.h"
39 #include "location-common-util.h"
40 #ifndef TIZEN_PROFILE_TV
41 #include "location-privacy.h"
42 #endif
43
44 #define LOCATION_PRIVILEGE      "http://tizen.org/privilege/location"
45 #define LOCATION_ENABLE_PRIVILEGE       "http://tizen.org/privilege/location.enable"
46
47 typedef struct _LocationSetting {
48         LocationSettingCb callback;
49         void *user_data;
50 } LocationSetting;
51
52 static LocationSetting g_location_setting;
53
54 static char *__convert_setting_key(LocationMethod method)
55 {
56         char *key = NULL;
57         switch (method) {
58         case LOCATION_METHOD_HYBRID:
59                 key = g_strdup(VCONFKEY_LOCATION_USE_MY_LOCATION);
60                 break;
61         case LOCATION_METHOD_GPS:
62                 key = g_strdup(VCONFKEY_LOCATION_ENABLED);
63                 break;
64         case LOCATION_METHOD_WPS:
65                 key = g_strdup(VCONFKEY_LOCATION_NETWORK_ENABLED);
66                 break;
67         case INTERNAL_METHOD_MOCK:
68                 key = g_strdup(VCONFKEY_LOCATION_MOCK_ENABLED);
69                 break;
70         default:
71                 break;
72         }
73
74         return key;
75 }
76
77 static LocationMethod __convert_method_from_key(const char *key)
78 {
79         LocationMethod _method = LOCATION_METHOD_NONE;
80         if (g_strcmp0(key, VCONFKEY_LOCATION_USE_MY_LOCATION) == 0)
81                 _method = LOCATION_METHOD_HYBRID;
82         else if (g_strcmp0(key, VCONFKEY_LOCATION_ENABLED) == 0)
83                 _method = LOCATION_METHOD_GPS;
84         else if (g_strcmp0(key, VCONFKEY_LOCATION_NETWORK_ENABLED) == 0)
85                 _method = LOCATION_METHOD_WPS;
86
87         return _method;
88 }
89
90 static void __location_setting_cb(keynode_t *key, gpointer data)
91 {
92         if (key == NULL || data == NULL)
93                 return;
94
95         LocationSetting *_setting = (LocationSetting *)data;
96         LocationMethod _method = LOCATION_METHOD_NONE;
97
98         if (_setting->callback) {
99                 _method = __convert_method_from_key(vconf_keynode_get_name(key));
100                 _setting->callback(_method, location_setting_get_key_val(key), _setting->user_data);
101         }
102 }
103
104 EXPORT_API
105 int location_init(void)
106 {
107 #if !GLIB_CHECK_VERSION(2, 35, 0)
108         g_type_init();
109 #endif
110
111 #if !GLIB_CHECK_VERSION(2, 31, 0)
112         if (!g_thread_supported()) g_thread_init(NULL);
113 #endif
114         if (FALSE == module_init())
115                 return LOCATION_ERROR_NOT_AVAILABLE;
116
117         return LOCATION_ERROR_NONE;
118 }
119
120 EXPORT_API LocationObject *
121 location_new(LocationMethod method)
122 {
123         LocationObject *self = NULL;
124         LOCATION_LOGD("method: %d", method);
125
126         switch (method) {
127         case LOCATION_METHOD_HYBRID:
128                 self = g_object_new(LOCATION_TYPE_HYBRID, NULL);
129                 break;
130         case LOCATION_METHOD_GPS:
131                 self = g_object_new(LOCATION_TYPE_GPS, NULL);
132                 break;
133         case LOCATION_METHOD_WPS:
134                 self = g_object_new(LOCATION_TYPE_WPS, NULL);
135                 break;
136         default:
137                 break;
138         }
139
140         LOC_COND_LOG(!self, _E, "Fail to create location object. [method=%d]", method);
141         return self;
142 }
143
144 EXPORT_API int
145 location_free(LocationObject *obj)
146 {
147         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
148         g_object_unref(obj);
149         return LOCATION_ERROR_NONE;
150 }
151
152 EXPORT_API int
153 location_request_single_location(LocationObject *obj, int timeout)
154 {
155         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
156
157         int ret = LOCATION_ERROR_NONE;
158         ret = location_ielement_request_single_location(LOCATION_IELEMENT(obj), timeout);
159         LOC_IF_FAIL(ret, _E, "Fail to request single location [%s]", err_msg(ret));
160
161         return ret;
162 }
163
164 EXPORT_API int
165 location_start(LocationObject *obj)
166 {
167         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
168
169         int ret = LOCATION_ERROR_NONE;
170 #ifndef TIZEN_PROFILE_TV
171         ret = location_check_cynara(LOCATION_PRIVILEGE);
172         LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
173 #endif
174
175         ret = location_ielement_start(LOCATION_IELEMENT(obj));
176         LOC_IF_FAIL(ret, _E, "Fail to start [%s]", err_msg(ret));
177
178         return ret;
179 }
180
181 EXPORT_API int
182 location_stop(LocationObject *obj)
183 {
184         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
185
186         int ret = LOCATION_ERROR_NONE;
187         ret = location_ielement_stop(LOCATION_IELEMENT(obj));
188         LOC_IF_FAIL(ret, _E, "Fail to stop [%s]", err_msg(ret));
189
190         return ret;
191 }
192
193 EXPORT_API int
194 location_start_batch(LocationObject *obj)
195 {
196         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
197         int ret = LOCATION_ERROR_NONE;
198
199 #ifndef TIZEN_PROFILE_TV
200         ret = location_check_cynara(LOCATION_PRIVILEGE);
201         LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
202 #endif
203
204         ret = location_ielement_start_batch(LOCATION_IELEMENT(obj));
205         LOC_IF_FAIL(ret, _E, "Fail to start_batch [%s]", err_msg(ret));
206
207         return ret;
208 }
209
210 EXPORT_API int
211 location_stop_batch(LocationObject *obj)
212 {
213         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
214         int ret = LOCATION_ERROR_NONE;
215         ret = location_ielement_stop_batch(LOCATION_IELEMENT(obj));
216         LOC_IF_FAIL(ret, _E, "Fail to stop_batch [%d]", err_msg(ret));
217
218         return ret;
219 }
220
221 EXPORT_API gboolean
222 location_is_supported_method(LocationMethod method)
223 {
224         gboolean is_supported = FALSE;
225
226         switch (method) {
227         case LOCATION_METHOD_HYBRID:
228                 if (module_is_supported("gps") || module_is_supported("wps"))
229                         is_supported = TRUE;
230                 break;
231         case LOCATION_METHOD_GPS:
232                 is_supported = module_is_supported("gps");
233                 break;
234         case LOCATION_METHOD_WPS:
235                 is_supported = module_is_supported("wps");
236                 break;
237         default:
238                         break;
239         }
240
241         return is_supported;
242 }
243
244 EXPORT_API int
245 location_is_enabled_method(LocationMethod method, int *is_enabled)
246 {
247         g_return_val_if_fail(is_enabled, LOCATION_ERROR_PARAMETER);
248         int vconf_val = 0;
249         int vconf_ret = VCONF_ERROR;
250
251         char *_key = __convert_setting_key(method);
252         LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
253
254         vconf_ret = vconf_get_int(_key, &vconf_val);
255         if (vconf_ret != VCONF_OK) {
256                 LOCATION_SECLOG("vconf_get failed [%s], error [%d]", _key, vconf_ret);
257                 g_free(_key);
258                 return LOCATION_ERROR_NOT_AVAILABLE;
259         } else {
260                 LOCATION_SECLOG("[%s]:[%d]", _key, vconf_val);
261         }
262
263         *is_enabled = vconf_val;
264         g_free(_key);
265
266         return LOCATION_ERROR_NONE;
267 }
268
269 EXPORT_API int
270 location_enable_method(const LocationMethod method, const int enable)
271 {
272         int ret = 0;
273         char *_key = NULL;
274
275 #ifndef TIZEN_PROFILE_TV
276         ret = location_check_cynara(LOCATION_ENABLE_PRIVILEGE);
277         LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
278 #endif
279
280         if (location_setting_get_int(VCONFKEY_LOCATION_RESTRICT) > RESTRICT_OFF) {
281                 LOCATION_SECLOG("Location setting is denied by DPM");
282                 return LOCATION_ERROR_NOT_ALLOWED;
283         }
284
285         /* for itself */
286         _key = __convert_setting_key(method);
287         LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
288
289         ret = vconf_set_int(_key, enable);
290         if (ret != VCONF_OK) {
291                 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
292                 g_free(_key);
293                 return LOCATION_ERROR_NOT_ALLOWED;
294         }
295         g_free(_key);
296
297         /* for hybrid */
298         _key = __convert_setting_key(LOCATION_METHOD_HYBRID);
299         LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", LOCATION_METHOD_HYBRID, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
300
301         if (enable) {
302                 ret = vconf_set_int(_key, enable);
303                 if (ret != VCONF_OK) {
304                         LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
305                         g_free(_key);
306                         return LOCATION_ERROR_NOT_ALLOWED;
307                 }
308         } else {
309                 int i = 0;
310                 int enabled_state = 0;
311
312                 for (i = LOCATION_METHOD_GPS; i < LOCATION_METHOD_MAX; i++) {
313                         _key = __convert_setting_key(i);
314                         enabled_state |= location_setting_get_int(_key);
315                         g_free(_key);
316                 }
317                 if (!enabled_state) {
318                         _key = __convert_setting_key(LOCATION_METHOD_HYBRID);
319                         ret = vconf_set_int(_key, enable);
320                         if (ret != VCONF_OK) {
321                                 LOCATION_SECLOG("vconf_set_int failed [%s], error [%d]", _key, ret);
322                                 g_free(_key);
323                                 return LOCATION_ERROR_NOT_ALLOWED;
324                         } else {
325                                 LOCATION_SECLOG("[%s]:[%d]", _key, ret);
326                         }
327                         g_free(_key);
328                 }
329         }
330
331         return ret;
332 }
333
334 EXPORT_API int
335 location_add_setting_notify(LocationMethod method, LocationSettingCb callback, void *user_data)
336 {
337         int ret = LOCATION_ERROR_NONE;
338         char *_key = __convert_setting_key(method);
339         LOC_COND_RET(!_key, LOCATION_ERROR_PARAMETER, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_PARAMETER));
340
341         g_location_setting.callback = callback;
342         g_location_setting.user_data = user_data;
343
344         ret = location_setting_add_notify(_key, __location_setting_cb, &g_location_setting);
345         g_free(_key);
346
347         return ret;
348 }
349
350 EXPORT_API int
351 location_ignore_setting_notify(LocationMethod method, LocationSettingCb callback)
352 {
353         int ret = LOCATION_ERROR_NONE;
354         char *_key = __convert_setting_key(method);
355         LOC_COND_RET(!_key, LOCATION_ERROR_PARAMETER, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_PARAMETER));
356
357         g_location_setting.callback = NULL;
358         g_location_setting.user_data = NULL;
359
360         ret = location_setting_ignore_notify(_key, __location_setting_cb);
361         g_free(_key);
362
363         return ret;
364 }
365
366
367 EXPORT_API int
368 location_get_position(LocationObject *obj, LocationPosition **position, LocationAccuracy **accuracy)
369 {
370         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
371         g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
372         g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
373
374         int ret = LOCATION_ERROR_NONE;
375
376 #ifndef TIZEN_PROFILE_TV
377         ret = location_check_cynara(LOCATION_PRIVILEGE);
378         LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
379 #endif
380
381         ret = location_ielement_get_position(LOCATION_IELEMENT(obj), position, accuracy);
382         LOC_COND_RET(ret != LOCATION_ERROR_NONE, ret, _E, "Fail to get_position [%s]", err_msg(ret));
383
384         return ret;
385 }
386
387 EXPORT_API int
388 location_get_position_ext(LocationObject *obj, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
389 {
390         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
391         g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
392         g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
393         g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
394
395         int ret = LOCATION_ERROR_NONE;
396
397 #ifndef TIZEN_PROFILE_TV
398         ret = location_check_cynara(LOCATION_PRIVILEGE);
399         LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
400 #endif
401
402         ret = location_ielement_get_position_ext(LOCATION_IELEMENT(obj), position, velocity, accuracy);
403         LOC_IF_FAIL(ret, _E, "Fail to get_position_ext [%s]", err_msg(ret));
404
405         return ret;
406 }
407
408 EXPORT_API int
409 location_get_last_position(LocationObject *obj, LocationPosition **position, LocationAccuracy **accuracy)
410 {
411         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
412         g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
413         g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
414
415         int ret = LOCATION_ERROR_NONE;
416
417 #ifndef TIZEN_PROFILE_TV
418         ret = location_check_cynara(LOCATION_PRIVILEGE);
419         LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
420 #endif
421
422         ret = location_ielement_get_last_position(LOCATION_IELEMENT(obj), position, accuracy);
423         LOC_IF_FAIL(ret, _E, "Fail to get_last_position [%s]", err_msg(ret));
424
425         return ret;
426 }
427
428 EXPORT_API int
429 location_get_last_position_ext(LocationObject *obj, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
430 {
431         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
432         g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
433         g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
434         g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
435
436         int ret = LOCATION_ERROR_NONE;
437
438 #ifndef TIZEN_PROFILE_TV
439         ret = location_check_cynara(LOCATION_PRIVILEGE);
440         LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
441 #endif
442
443         ret = location_ielement_get_last_position_ext(LOCATION_IELEMENT(obj), position, velocity, accuracy);
444         LOC_IF_FAIL(ret, _E, "Fail to get_last_position_ext [%s]", err_msg(ret));
445
446         return ret;
447 }
448
449 EXPORT_API int
450 location_get_nmea(LocationObject *obj, char **nmea)
451 {
452         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
453         g_return_val_if_fail(nmea, LOCATION_ERROR_PARAMETER);
454
455         int ret = LOCATION_ERROR_NONE;
456         ret = location_ielement_get_nmea(LOCATION_IELEMENT(obj), nmea);
457         LOC_IF_FAIL(ret, _E, "Fail to get_nmea [%s]", err_msg(ret));
458
459         return ret;
460 }
461
462
463 EXPORT_API int
464 location_get_satellite(LocationObject *obj, LocationSatellite **satellite)
465 {
466         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
467         g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
468
469         int ret = LOCATION_ERROR_NONE;
470
471 #ifndef TIZEN_PROFILE_TV
472         ret = location_check_cynara(LOCATION_PRIVILEGE);
473         LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
474 #endif
475
476         ret = location_ielement_get_satellite(LOCATION_IELEMENT(obj), satellite);
477         LOC_IF_FAIL(ret, _E, "Fail to get_satellite [%s]", err_msg(ret));
478
479         return ret;
480 }
481
482 EXPORT_API int
483 location_get_batch(LocationObject *obj, LocationBatch **batch)
484 {
485         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
486         g_return_val_if_fail(batch, LOCATION_ERROR_PARAMETER);
487
488         int ret = LOCATION_ERROR_NONE;
489
490 #ifndef TIZEN_PROFILE_TV
491         ret = location_check_cynara(LOCATION_PRIVILEGE);
492         LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
493 #endif
494
495         ret = location_ielement_get_batch(LOCATION_IELEMENT(obj), batch);
496         LOC_IF_FAIL(ret, _E, "Fail to get_batch [%s]", err_msg(ret));
497
498         return ret;
499 }
500
501 EXPORT_API int
502 location_get_last_satellite(LocationObject *obj, LocationSatellite **satellite)
503 {
504         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
505         g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
506
507         int ret = LOCATION_ERROR_NONE;
508
509 #ifndef TIZEN_PROFILE_TV
510         ret = location_check_cynara(LOCATION_PRIVILEGE);
511         LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
512 #endif
513
514         ret = location_ielement_get_last_satellite(LOCATION_IELEMENT(obj), satellite);
515         LOC_IF_FAIL(ret, _E, "Fail to get_last_satellite [%s]", err_msg(ret));
516
517         return ret;
518 }
519
520 EXPORT_API int
521 location_get_velocity(LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy)
522 {
523         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
524         g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
525         g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
526
527         int ret = LOCATION_ERROR_NONE;
528
529 #ifndef TIZEN_PROFILE_TV
530         ret = location_check_cynara(LOCATION_PRIVILEGE);
531         LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
532 #endif
533
534         ret = location_ielement_get_velocity(LOCATION_IELEMENT(obj), velocity, accuracy);
535         LOC_IF_FAIL(ret, _E, "Fail to get_velocity [%s]", err_msg(ret));
536
537         return ret;
538 }
539
540 EXPORT_API int
541 location_get_last_velocity(LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy)
542 {
543         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
544         g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
545         g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
546
547         int ret = LOCATION_ERROR_NONE;
548
549 #ifndef TIZEN_PROFILE_TV
550         ret = location_check_cynara(LOCATION_PRIVILEGE);
551         LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
552 #endif
553
554         ret = location_ielement_get_last_velocity(LOCATION_IELEMENT(obj), velocity, accuracy);
555         LOC_IF_FAIL(ret, _E, "Fail to get_last_velocity [%s]", err_msg(ret));
556
557         return ret;
558 }
559
560 EXPORT_API int
561 location_get_accessibility_state(LocationAccessState *state)
562 {
563         int ret = LOCATION_ERROR_NONE;
564
565 #ifndef TIZEN_PROFILE_TV
566         ret = location_check_cynara(LOCATION_PRIVILEGE);
567 #endif
568
569         if (ret == LOCATION_ERROR_NONE) {
570                 *state = LOCATION_ACCESS_ALLOWED;
571         } else {
572                 *state = LOCATION_ACCESS_DENIED;
573                 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
574         }
575
576         return LOCATION_ERROR_NONE;
577 }
578
579 EXPORT_API int
580 location_set_accessibility_state(LocationAccessState state)
581 {
582         int auth = LOCATION_APP_NOT_FOUND;
583         int ret = LOCATION_ERROR_NONE;
584
585         switch (state) {
586         case LOCATION_ACCESS_DENIED:
587                 auth = LOCATION_APP_OFF;
588                 break;
589         case LOCATION_ACCESS_ALLOWED:
590                 auth = LOCATION_APP_ON;
591                 break;
592         case LOCATION_ACCESS_NONE:
593         default:
594                 return LOCATION_ERROR_PARAMETER;
595         }
596
597         ret = location_application_set_authority(auth);
598         LOCATION_LOGD("set_accessibility_state [%d], Error[%d]", auth, ret);
599         return ret;
600 }
601
602 EXPORT_API int
603 location_send_command(const char *cmd)
604 {
605         g_return_val_if_fail(cmd, LOCATION_ERROR_PARAMETER);
606         return LOCATION_ERROR_NOT_AVAILABLE;
607 }
608
609 EXPORT_API int
610 location_set_option(LocationObject *obj, const char *option)
611 {
612         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
613         int ret = LOCATION_ERROR_NONE;
614
615 #ifndef TIZEN_PROFILE_TV
616         ret = location_check_cynara(LOCATION_PRIVILEGE);
617         LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
618 #endif
619
620         ret = location_ielement_set_option(LOCATION_IELEMENT(obj), option);
621         LOC_IF_FAIL(ret, _E, "Fail to get_velocity [%s]", err_msg(ret));
622         return ret;
623 }
624
625
626 /*
627  * Tizen 3.0
628  */
629 EXPORT_API int
630 location_enable_mock(const int enable)
631 {
632         int ret = LOCATION_ERROR_NONE;
633
634 #ifndef TIZEN_PROFILE_TV
635         ret = location_check_cynara(LOCATION_PRIVILEGE);
636         LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
637 #endif
638
639 #if 0 /* Tizen platform didn't turn developer option on */
640         gboolean developer_option = FALSE;
641
642         ret = vconf_get_bool(VCONFKEY_SETAPPL_DEVELOPER_OPTION_STATE, &developer_option);
643         LOC_COND_RET(!developer_option, LOCATION_ERROR_NOT_ALLOWED, _E, "Cannot enable mock location because developer option is not turned on", ret);
644 #endif
645
646         ret = vconf_set_int(VCONFKEY_LOCATION_MOCK_ENABLED, enable);
647         if (ret != VCONF_OK) {
648                 LOCATION_SECLOG("vconf_set_int failed [MOCK_ENABLED], ret=[%d]", ret);
649                 return LOCATION_ERROR_NOT_ALLOWED;
650         }
651
652         return ret;
653 }
654
655 EXPORT_API int
656 location_set_mock_location(LocationObject *obj, const LocationPosition *position, const LocationVelocity *velocity, const LocationAccuracy *accuracy)
657 {
658         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
659         g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
660         g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
661         g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
662
663         int ret = LOCATION_ERROR_NONE;
664         ret = location_ielement_set_mock_location(LOCATION_IELEMENT(obj), position, velocity, accuracy);
665         LOC_IF_FAIL(ret, _E, "Fail to set_mock_location [%s]", err_msg(ret));
666
667         return ret;
668 }
669
670 EXPORT_API int
671 location_clear_mock_location(LocationObject *obj)
672 {
673         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
674
675         int ret = LOCATION_ERROR_NONE;
676         ret = location_ielement_clear_mock_location(LOCATION_IELEMENT(obj));
677         LOC_IF_FAIL(ret, _E, "Fail to clear_mock_location [%s]", err_msg(ret));
678
679         return ret;
680 }
681
682 EXPORT_API int
683 location_enable_restriction(const int enable)
684 {
685         int ret = LOCATION_ERROR_NONE;
686         int restriction = 0;
687
688 #ifndef TIZEN_PROFILE_TV
689         ret = location_check_cynara(LOCATION_ENABLE_PRIVILEGE);
690         LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
691 #endif
692         if (enable) {
693                 int value = 0;
694                 ret = vconf_get_int(VCONFKEY_LOCATION_RESTRICT, &restriction);
695                 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to get restriction status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
696
697                 if (restriction == RESTRICT_OFF) {
698
699                         if (location_setting_get_int(VCONFKEY_LOCATION_ENABLED)) {
700                                 value |= RESTRICT_GPS;
701                                 ret = vconf_set_int(VCONFKEY_LOCATION_ENABLED, 0);
702                                 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
703                         }
704
705                         if (location_setting_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED)) {
706                                 value |= RESTRICT_WPS;
707                                 ret = vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 0);
708                                 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
709                         }
710
711                         if (location_setting_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION)) {
712                                 value |= RESTRICT_HYBRID;
713                                 ret = vconf_set_int(VCONFKEY_LOCATION_USE_MY_LOCATION, 0);
714                                 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
715                         }
716
717                         if (value == 0)
718                                 value = RESTRICT_NONE;
719
720                         ret = vconf_set_int(VCONFKEY_LOCATION_RESTRICT, value);
721                         LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set value. %d [%s]", value, err_msg(LOCATION_ERROR_NOT_ALLOWED));
722                 }
723
724         } else {
725                 ret = vconf_get_int(VCONFKEY_LOCATION_RESTRICT, &restriction);
726                 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to get restriction status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
727
728                 if (restriction > RESTRICT_OFF) {
729
730                         if (restriction & RESTRICT_GPS) {
731                                 ret = vconf_set_int(VCONFKEY_LOCATION_ENABLED, 1);
732                                 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
733                         }
734
735                         if (restriction & RESTRICT_WPS) {
736                                 ret = vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 1);
737                                 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
738                         }
739
740                         if (restriction & RESTRICT_HYBRID) {
741                                 ret = vconf_set_int(VCONFKEY_LOCATION_USE_MY_LOCATION, 1);
742                                 LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
743                         }
744
745                         ret = vconf_set_int(VCONFKEY_LOCATION_RESTRICT, RESTRICT_OFF);
746                         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));
747                 }
748         }
749
750         return LOCATION_ERROR_NONE;
751 }