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