Merge "sync with latest 3.0" into tizen
[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-passive.h"
38 #include "location-position.h"
39 #include "module-internal.h"
40 #include "location-common-util.h"
41 #include "location-privacy.h"
42
43 #define LOCATION_PRIVILEGE                      "http://tizen.org/privilege/location"
44 #define LOCATION_ENABLE_PRIVILEGE       "http://tizen.org/privilege/location.enable"
45
46 typedef struct _LocationSetting {
47         LocationSettingCb callback;
48         void *user_data;
49 } LocationSetting;
50
51 enum {
52         _METHOD_HYBRID = 0,
53         _METHOD_GPS_1,
54         _METHOD_GPS_2,
55         _METHOD_WPS_1,
56         _METHOD_WPS_2,
57         _METHOD_MAX
58 };
59
60 static LocationSetting g_location_setting;
61 static bool is_method_created[_METHOD_MAX] = {false};
62
63 static char *__convert_setting_key(LocationMethod method)
64 {
65         char *key = NULL;
66         switch (method) {
67         case LOCATION_METHOD_HYBRID:
68                 key = g_strdup(VCONFKEY_LOCATION_USE_MY_LOCATION);
69                 break;
70         case LOCATION_METHOD_GPS:
71                 key = g_strdup(VCONFKEY_LOCATION_ENABLED);
72                 break;
73         case LOCATION_METHOD_WPS:
74                 key = g_strdup(VCONFKEY_LOCATION_NETWORK_ENABLED);
75                 break;
76         case INTERNAL_METHOD_MOCK:
77                 key = g_strdup(VCONFKEY_LOCATION_MOCK_ENABLED);
78                 break;
79         default:
80                 break;
81         }
82
83         return key;
84 }
85
86 static LocationMethod __convert_method_from_key(const char *key)
87 {
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;
95
96         return _method;
97 }
98
99 static void __location_setting_cb(keynode_t *key, gpointer data)
100 {
101         if (key == NULL || data == NULL)
102                 return;
103
104         LocationSetting *_setting = (LocationSetting *)data;
105         LocationMethod _method = LOCATION_METHOD_NONE;
106
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);
110         }
111 }
112
113 EXPORT_API
114 int location_init(void)
115 {
116 #if !GLIB_CHECK_VERSION(2, 35, 0)
117         g_type_init();
118 #endif
119
120 #if !GLIB_CHECK_VERSION(2, 31, 0)
121         if (!g_thread_supported()) g_thread_init(NULL);
122 #endif
123         if (FALSE == module_init())
124                 return LOCATION_ERROR_NOT_AVAILABLE;
125
126         return LOCATION_ERROR_NONE;
127 }
128
129 EXPORT_API LocationObject *
130 location_new(LocationMethod method, gboolean is_internal_for_hybrid)
131 {
132         LocationObject *self = NULL;
133         LOCATION_LOGD("method : %d, is_internal_for_hybrid[%d]", method, is_internal_for_hybrid);
134
135         switch (method) {
136         case LOCATION_METHOD_HYBRID:
137                 if (is_method_created[_METHOD_HYBRID]) {
138                         LOCATION_LOGE("Hybrid handle already exist.");
139                 } else {
140                         self = g_object_new(LOCATION_TYPE_HYBRID, NULL);
141                         is_method_created[_METHOD_HYBRID] = true;
142                 }
143                 break;
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.");
148                         } else {
149                                 is_method_created[_METHOD_GPS_2] = true;
150                                 self = g_object_new(LOCATION_TYPE_GPS, NULL);
151                         }
152                 } else {
153                         if (is_method_created[_METHOD_GPS_1]) {
154                                 LOCATION_LOGE("GPS handle already exist.");
155                         } else {
156                                 is_method_created[_METHOD_GPS_1] = true;
157                                 self = g_object_new(LOCATION_TYPE_GPS, NULL);
158                         }
159                 }
160                 break;
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.");
165                         } else {
166                                 is_method_created[_METHOD_WPS_2] = true;
167                                 self = g_object_new(LOCATION_TYPE_WPS, NULL);
168                         }
169                 } else {
170                         if (is_method_created[_METHOD_WPS_1]) {
171                                 LOCATION_LOGE("WPS handle already exist.");
172                         } else {
173                                 is_method_created[_METHOD_WPS_1] = true;
174                                 self = g_object_new(LOCATION_TYPE_WPS, NULL);
175                         }
176                 }
177                 break;
178         case LOCATION_METHOD_PASSIVE:
179                 self = g_object_new(LOCATION_TYPE_PASSIVE, NULL);
180                 break;
181         default:
182                 break;
183         }
184
185         LOC_COND_LOG(!self, _E, "Fail to create location object. [method=%d]", method);
186         return self;
187 }
188
189 EXPORT_API int
190 location_free(LocationObject *obj, gboolean is_internal_for_hybrid)
191 {
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;
198                 else
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;
203                 else
204                         is_method_created[_METHOD_WPS_1] = false;
205         }
206         g_object_unref(obj);
207         return LOCATION_ERROR_NONE;
208 }
209
210 EXPORT_API int
211 location_request_single_location(LocationObject *obj, int timeout)
212 {
213         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
214
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));
219         }
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));
222
223         return ret;
224 }
225
226 EXPORT_API int
227 location_cancel_single_location(LocationObject *obj)
228 {
229         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
230
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));
235         }
236
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);
240
241         return ret;
242 }
243
244 EXPORT_API int
245 location_start(LocationObject *obj)
246 {
247         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
248
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));
253         }
254
255         ret = location_ielement_start(LOCATION_IELEMENT(obj));
256         LOC_IF_FAIL(ret, _E, "Fail to start [%s]", err_msg(ret));
257
258         return ret;
259 }
260
261 EXPORT_API int
262 location_stop(LocationObject *obj)
263 {
264         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
265
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));
269
270         return ret;
271 }
272
273 EXPORT_API int
274 location_start_batch(LocationObject *obj)
275 {
276         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
277         int ret = LOCATION_ERROR_NONE;
278
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));
282         }
283
284         ret = location_ielement_start_batch(LOCATION_IELEMENT(obj));
285         LOC_IF_FAIL(ret, _E, "Fail to start_batch [%s]", err_msg(ret));
286
287         return ret;
288 }
289
290 EXPORT_API int
291 location_stop_batch(LocationObject *obj)
292 {
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));
297
298         return ret;
299 }
300
301 EXPORT_API gboolean
302 location_is_supported_method(LocationMethod method)
303 {
304         gboolean is_supported = FALSE;
305
306         switch (method) {
307         case LOCATION_METHOD_HYBRID:
308                 if (module_is_supported("gps") || module_is_supported("wps"))
309                         is_supported = TRUE;
310                 break;
311         case LOCATION_METHOD_GPS:
312                 is_supported = module_is_supported("gps");
313                 break;
314         case LOCATION_METHOD_WPS:
315                 is_supported = module_is_supported("wps");
316                 break;
317         case LOCATION_METHOD_PASSIVE:
318                 is_supported = module_is_supported("passive");
319                 break;
320         default:
321                         break;
322         }
323
324         return is_supported;
325 }
326
327 EXPORT_API int
328 location_is_enabled_method(LocationMethod method, int *is_enabled)
329 {
330         g_return_val_if_fail(is_enabled, LOCATION_ERROR_PARAMETER);
331         int vconf_val = 0;
332         int vconf_ret = VCONF_ERROR;
333
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));
336
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);
340                 g_free(_key);
341                 return LOCATION_ERROR_NOT_AVAILABLE;
342         } else {
343                 LOCATION_SECLOG("[%s]:[%d]", _key, vconf_val);
344         }
345
346         *is_enabled = vconf_val;
347         g_free(_key);
348
349         return LOCATION_ERROR_NONE;
350 }
351
352 EXPORT_API int
353 location_enable_method(const LocationMethod method, const int enable)
354 {
355         int ret = 0;
356         char *_key = NULL;
357
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));
361         }
362
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;
366         }
367
368         /* for itself */
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));
371
372         ret = vconf_set_int(_key, enable);
373         if (ret != VCONF_OK) {
374                 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
375                 g_free(_key);
376                 return LOCATION_ERROR_NOT_ALLOWED;
377         }
378         g_free(_key);
379
380         /* for hybrid */
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));
383
384         if (enable) {
385                 ret = vconf_set_int(_key, enable);
386                 if (ret != VCONF_OK) {
387                         LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
388                         g_free(_key);
389                         return LOCATION_ERROR_NOT_ALLOWED;
390                 }
391         } else {
392                 int i = 0;
393                 int enabled_state = 0;
394
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);
398                         g_free(_key);
399                 }
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);
405                                 g_free(_key);
406                                 return LOCATION_ERROR_NOT_ALLOWED;
407                         } else {
408                                 LOCATION_SECLOG("[%s]:[%d]", _key, ret);
409                         }
410                         g_free(_key);
411                 }
412         }
413
414         return ret;
415 }
416
417 EXPORT_API int
418 location_add_setting_notify(LocationMethod method, LocationSettingCb callback, void *user_data)
419 {
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));
423
424         g_location_setting.callback = callback;
425         g_location_setting.user_data = user_data;
426
427         ret = location_setting_add_notify(_key, __location_setting_cb, &g_location_setting);
428         g_free(_key);
429
430         return ret;
431 }
432
433 EXPORT_API int
434 location_ignore_setting_notify(LocationMethod method, LocationSettingCb callback)
435 {
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));
439
440         g_location_setting.callback = NULL;
441         g_location_setting.user_data = NULL;
442
443         ret = location_setting_ignore_notify(_key, __location_setting_cb);
444         g_free(_key);
445
446         return ret;
447 }
448
449
450 EXPORT_API int
451 location_get_position(LocationObject *obj, LocationPosition **position, LocationAccuracy **accuracy)
452 {
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);
456
457         int ret = LOCATION_ERROR_NONE;
458
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));
462         }
463
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));
466
467         return ret;
468 }
469
470 EXPORT_API int
471 location_get_position_ext(LocationObject *obj, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
472 {
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);
477
478         int ret = LOCATION_ERROR_NONE;
479
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));
483         }
484
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));
487
488         return ret;
489 }
490
491 EXPORT_API int
492 location_get_last_position(LocationObject *obj, LocationPosition **position, LocationAccuracy **accuracy)
493 {
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);
497
498         int ret = LOCATION_ERROR_NONE;
499
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));
503         }
504
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));
507
508         return ret;
509 }
510
511 EXPORT_API int
512 location_get_last_position_ext(LocationObject *obj, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
513 {
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);
518
519         int ret = LOCATION_ERROR_NONE;
520
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));
524         }
525
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));
528
529         return ret;
530 }
531
532 EXPORT_API int
533 location_get_nmea(LocationObject *obj, char **nmea)
534 {
535         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
536         g_return_val_if_fail(nmea, LOCATION_ERROR_PARAMETER);
537
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));
541
542         return ret;
543 }
544
545
546 EXPORT_API int
547 location_get_satellite(LocationObject *obj, LocationSatellite **satellite)
548 {
549         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
550         g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
551
552         int ret = LOCATION_ERROR_NONE;
553
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));
557         }
558
559         ret = location_ielement_get_satellite(LOCATION_IELEMENT(obj), satellite);
560         LOC_IF_FAIL(ret, _E, "Fail to get_satellite [%s]", err_msg(ret));
561
562         return ret;
563 }
564
565 EXPORT_API int
566 location_get_batch(LocationObject *obj, LocationBatch **batch)
567 {
568         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
569         g_return_val_if_fail(batch, LOCATION_ERROR_PARAMETER);
570
571         int ret = LOCATION_ERROR_NONE;
572
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));
576         }
577
578         ret = location_ielement_get_batch(LOCATION_IELEMENT(obj), batch);
579         LOC_IF_FAIL(ret, _E, "Fail to get_batch [%s]", err_msg(ret));
580
581         return ret;
582 }
583
584 EXPORT_API int
585 location_get_last_satellite(LocationObject *obj, LocationSatellite **satellite)
586 {
587         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
588         g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
589
590         int ret = LOCATION_ERROR_NONE;
591
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));
595         }
596
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));
599
600         return ret;
601 }
602
603 EXPORT_API int
604 location_get_velocity(LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy)
605 {
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);
609
610         int ret = LOCATION_ERROR_NONE;
611
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));
615         }
616
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));
619
620         return ret;
621 }
622
623 EXPORT_API int
624 location_get_last_velocity(LocationObject *obj, LocationVelocity **velocity, LocationAccuracy **accuracy)
625 {
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);
629
630         int ret = LOCATION_ERROR_NONE;
631
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));
635         }
636
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));
639
640         return ret;
641 }
642
643 EXPORT_API int
644 location_get_accessibility_state(LocationAccessState *state)
645 {
646         if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
647                 int ret = location_check_cynara(LOCATION_PRIVILEGE);
648
649                 if (ret == LOCATION_ERROR_NONE) {
650                         *state = LOCATION_ACCESS_ALLOWED;
651                 } else {
652                         *state = LOCATION_ACCESS_DENIED;
653                         LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
654                 }
655         } else {
656                 *state = LOCATION_ACCESS_ALLOWED;
657         }
658
659         return LOCATION_ERROR_NONE;
660 }
661
662 EXPORT_API int
663 location_set_accessibility_state(LocationAccessState state)
664 {
665         int auth = LOCATION_APP_NOT_FOUND;
666         int ret = LOCATION_ERROR_NONE;
667
668         switch (state) {
669         case LOCATION_ACCESS_DENIED:
670                 auth = LOCATION_APP_OFF;
671                 break;
672         case LOCATION_ACCESS_ALLOWED:
673                 auth = LOCATION_APP_ON;
674                 break;
675         case LOCATION_ACCESS_NONE:
676         default:
677                 return LOCATION_ERROR_PARAMETER;
678         }
679
680         ret = location_application_set_authority(auth);
681         LOCATION_LOGD("set_accessibility_state [%d], Error[%d]", auth, ret);
682         return ret;
683 }
684
685 EXPORT_API int
686 location_send_command(const char *cmd)
687 {
688         g_return_val_if_fail(cmd, LOCATION_ERROR_PARAMETER);
689         return LOCATION_ERROR_NOT_AVAILABLE;
690 }
691
692 EXPORT_API int
693 location_set_option(LocationObject *obj, const char *option)
694 {
695         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
696         int ret = LOCATION_ERROR_NONE;
697
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));
701         }
702
703         ret = location_ielement_set_option(LOCATION_IELEMENT(obj), option);
704         LOC_IF_FAIL(ret, _E, "Fail to get_velocity [%s]", err_msg(ret));
705         return ret;
706 }
707
708
709 /*
710  * Tizen 3.0
711  */
712 EXPORT_API int
713 location_enable_mock(const int enable)
714 {
715         int ret = LOCATION_ERROR_NONE;
716
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));
720         }
721
722 #if 0 /* Tizen platform didn't turn developer option on */
723         gboolean developer_option = FALSE;
724
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);
727 #endif
728
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;
733         }
734
735         return ret;
736 }
737
738 EXPORT_API int
739 location_set_mock_location(LocationObject *obj, const LocationPosition *position, const LocationVelocity *velocity, const LocationAccuracy *accuracy)
740 {
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);
745
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));
749
750         return ret;
751 }
752
753 EXPORT_API int
754 location_clear_mock_location(LocationObject *obj)
755 {
756         g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
757
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));
761
762         return ret;
763 }
764
765 EXPORT_API int
766 location_enable_restriction(const int enable)
767 {
768         int ret = LOCATION_ERROR_NONE;
769         int restriction = 0;
770
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));
774         }
775         if (enable) {
776                 int value = 0;
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));
779
780                 if (restriction == RESTRICT_OFF) {
781
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));
786                         }
787
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));
792                         }
793
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));
798                         }
799
800                         if (value == 0)
801                                 value = RESTRICT_NONE;
802
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));
805                 }
806
807         } else {
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));
810
811                 if (restriction > RESTRICT_OFF) {
812
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));
816                         }
817
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));
821                         }
822
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));
826                         }
827
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));
830                 }
831         }
832
833         return LOCATION_ERROR_NONE;
834 }