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