removed wrong contacts, added authors
[platform/core/location/lbs-location.git] / location / manager / location.c
index eff9ca5..b0ea74a 100755 (executable)
@@ -3,9 +3,6 @@
  *
  * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
- *                     Genie Kim <daejins.kim@samsung.com>
- *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -25,7 +22,6 @@
 
 #include <glib.h>
 #include <stdio.h>
-#include <pthread.h>
 #include <vconf.h>
 
 #include "location.h"
 #include "location-hybrid.h"
 #include "location-gps.h"
 #include "location-wps.h"
-#include "location-mock.h"
+#include "location-passive.h"
 #include "location-position.h"
 #include "module-internal.h"
 #include "location-common-util.h"
-#ifndef TIZEN_PROFILE_TV
 #include "location-privacy.h"
-#endif
 
-#define LOCATION_PRIVILEGE     "http://tizen.org/privilege/location"
+#define LOCATION_PRIVILEGE                     "http://tizen.org/privilege/location"
 #define LOCATION_ENABLE_PRIVILEGE      "http://tizen.org/privilege/location.enable"
 
 typedef struct _LocationSetting {
@@ -66,7 +60,7 @@ static char *__convert_setting_key(LocationMethod method)
        case LOCATION_METHOD_WPS:
                key = g_strdup(VCONFKEY_LOCATION_NETWORK_ENABLED);
                break;
-       case LOCATION_METHOD_MOCK:
+       case INTERNAL_METHOD_MOCK:
                key = g_strdup(VCONFKEY_LOCATION_MOCK_ENABLED);
                break;
        default:
@@ -79,24 +73,21 @@ static char *__convert_setting_key(LocationMethod method)
 static LocationMethod __convert_method_from_key(const char *key)
 {
        LocationMethod _method = LOCATION_METHOD_NONE;
-       if (g_strcmp0(key, VCONFKEY_LOCATION_USE_MY_LOCATION) == 0) {
+       if (g_strcmp0(key, VCONFKEY_LOCATION_USE_MY_LOCATION) == 0)
                _method = LOCATION_METHOD_HYBRID;
-       } else if (g_strcmp0(key, VCONFKEY_LOCATION_ENABLED) == 0) {
+       else if (g_strcmp0(key, VCONFKEY_LOCATION_ENABLED) == 0)
                _method = LOCATION_METHOD_GPS;
-       } else if (g_strcmp0(key, VCONFKEY_LOCATION_NETWORK_ENABLED) == 0) {
+       else if (g_strcmp0(key, VCONFKEY_LOCATION_NETWORK_ENABLED) == 0)
                _method = LOCATION_METHOD_WPS;
-       } else if (g_strcmp0(key, VCONFKEY_LOCATION_MOCK_ENABLED) == 0) {
-               _method = LOCATION_METHOD_MOCK;
-       }
 
        return _method;
 }
 
 static void __location_setting_cb(keynode_t *key, gpointer data)
 {
-       if (key == NULL || data == NULL) {
+       if (key == NULL || data == NULL)
                return;
-       }
+
        LocationSetting *_setting = (LocationSetting *)data;
        LocationMethod _method = LOCATION_METHOD_NONE;
 
@@ -123,10 +114,10 @@ int location_init(void)
 }
 
 EXPORT_API LocationObject *
-location_new(LocationMethod method)
+location_new(LocationMethod method, gboolean multi_handle)
 {
        LocationObject *self = NULL;
-       LOCATION_LOGD("method: %d", method);
+       LOCATION_LOGD("method : %d, multi_handle[%d]", method, multi_handle);
 
        switch (method) {
        case LOCATION_METHOD_HYBRID:
@@ -138,18 +129,19 @@ location_new(LocationMethod method)
        case LOCATION_METHOD_WPS:
                self = g_object_new(LOCATION_TYPE_WPS, NULL);
                break;
-       case LOCATION_METHOD_MOCK:
-               self = g_object_new(LOCATION_TYPE_MOCK, NULL);
+       case LOCATION_METHOD_PASSIVE:
+               self = g_object_new(LOCATION_TYPE_PASSIVE, NULL);
+               break;
        default:
                break;
        }
 
-       if (!self) LOCATION_LOGE("Fail to create location object. Method [%d]", method);
+       LOC_COND_LOG(!self, _E, "Fail to create location object. [method=%d]", method);
        return self;
 }
 
 EXPORT_API int
-location_free(LocationObject *obj)
+location_free(LocationObject *obj, gboolean multi_handle)
 {
        g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
        g_object_unref(obj);
@@ -162,8 +154,30 @@ location_request_single_location(LocationObject *obj, int timeout)
        g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
 
        int ret = LOCATION_ERROR_NONE;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
+       }
        ret = location_ielement_request_single_location(LOCATION_IELEMENT(obj), timeout);
-       if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to request single location. Error [%d]", ret);
+       LOC_IF_FAIL(ret, _E, "Fail to request single location [%s]", err_msg(ret));
+
+       return ret;
+}
+
+EXPORT_API int
+location_cancel_single_location(LocationObject *obj)
+{
+       g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
+
+       int ret = LOCATION_ERROR_NONE;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
+       }
+
+       ret = location_ielement_cancel_single_location(LOCATION_IELEMENT(obj));
+       if (ret != LOCATION_ERROR_NONE)
+               LOCATION_LOGE("Fail to cancel single location. Error [%d]", ret);
 
        return ret;
 }
@@ -174,16 +188,13 @@ location_start(LocationObject *obj)
        g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
 
        int ret = LOCATION_ERROR_NONE;
-#ifndef TIZEN_PROFILE_TV
-       ret = location_check_cynara(LOCATION_PRIVILEGE);
-       if (ret != LOCATION_ERROR_NONE) {
-               LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
-               return LOCATION_ERROR_NOT_ALLOWED;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
        }
-#endif
 
        ret = location_ielement_start(LOCATION_IELEMENT(obj));
-       if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to start. Error [%d]", ret);
+       LOC_IF_FAIL(ret, _E, "Fail to start [%s]", err_msg(ret));
 
        return ret;
 }
@@ -192,10 +203,10 @@ EXPORT_API int
 location_stop(LocationObject *obj)
 {
        g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
-       int ret = LOCATION_ERROR_NONE;
 
+       int ret = LOCATION_ERROR_NONE;
        ret = location_ielement_stop(LOCATION_IELEMENT(obj));
-       if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to stop. Error [%d]", ret);
+       LOC_IF_FAIL(ret, _E, "Fail to stop [%s]", err_msg(ret));
 
        return ret;
 }
@@ -206,16 +217,13 @@ location_start_batch(LocationObject *obj)
        g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
        int ret = LOCATION_ERROR_NONE;
 
-#ifndef TIZEN_PROFILE_TV
-       ret = location_check_cynara(LOCATION_PRIVILEGE);
-       if (ret != LOCATION_ERROR_NONE) {
-               LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
-               return LOCATION_ERROR_NOT_ALLOWED;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
        }
-#endif
 
        ret = location_ielement_start_batch(LOCATION_IELEMENT(obj));
-       if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to Batch start. Error [%d]", ret);
+       LOC_IF_FAIL(ret, _E, "Fail to start_batch [%s]", err_msg(ret));
 
        return ret;
 }
@@ -226,7 +234,7 @@ location_stop_batch(LocationObject *obj)
        g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
        int ret = LOCATION_ERROR_NONE;
        ret = location_ielement_stop_batch(LOCATION_IELEMENT(obj));
-       if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to Batch stop. Error [%d]", ret);
+       LOC_IF_FAIL(ret, _E, "Fail to stop_batch [%s]", err_msg(ret));
 
        return ret;
 }
@@ -238,18 +246,18 @@ location_is_supported_method(LocationMethod method)
 
        switch (method) {
        case LOCATION_METHOD_HYBRID:
-                       if (module_is_supported("gps") || module_is_supported("wps") || module_is_supported("mock"))
-                               is_supported = TRUE;
-                       break;
+               if (module_is_supported("gps") || module_is_supported("wps"))
+                       is_supported = TRUE;
+               break;
        case LOCATION_METHOD_GPS:
-                       is_supported = module_is_supported("gps");
-                       break;
+               is_supported = module_is_supported("gps");
+               break;
        case LOCATION_METHOD_WPS:
-                       is_supported = module_is_supported("wps");
-                       break;
-       case LOCATION_METHOD_MOCK:
-                       is_supported = module_is_supported("mock");
-                       break;
+               is_supported = module_is_supported("wps");
+               break;
+       case LOCATION_METHOD_PASSIVE:
+               is_supported = module_is_supported("passive");
+               break;
        default:
                        break;
        }
@@ -265,14 +273,11 @@ location_is_enabled_method(LocationMethod method, int *is_enabled)
        int vconf_ret = VCONF_ERROR;
 
        char *_key = __convert_setting_key(method);
-       if (!_key) {
-               LOCATION_LOGE("Invalid method[%d]", method);
-               return LOCATION_ERROR_NOT_SUPPORTED;
-       }
+       LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
 
        vconf_ret = vconf_get_int(_key, &vconf_val);
        if (vconf_ret != VCONF_OK) {
-               LOCATION_SECLOG("failed [%s], error [%d]", _key, vconf_ret);
+               LOCATION_SECLOG("vconf_get failed [%s], error [%d]", _key, vconf_ret);
                g_free(_key);
                return LOCATION_ERROR_NOT_AVAILABLE;
        } else {
@@ -291,20 +296,20 @@ location_enable_method(const LocationMethod method, const int enable)
        int ret = 0;
        char *_key = NULL;
 
-#ifndef TIZEN_PROFILE_TV
-       ret = location_check_cynara(LOCATION_ENABLE_PRIVILEGE);
-       if (ret != LOCATION_ERROR_NONE) {
-               LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_ENABLE_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
+       }
+
+       if (location_setting_get_int(VCONFKEY_LOCATION_RESTRICT) > RESTRICT_OFF) {
+               LOCATION_SECLOG("Location setting is denied by DPM");
                return LOCATION_ERROR_NOT_ALLOWED;
        }
-#endif
 
        /* for itself */
        _key = __convert_setting_key(method);
-       if (!_key) {
-               LOCATION_LOGE("Invalid method[%d]", method);
-               return LOCATION_ERROR_NOT_SUPPORTED;
-       }
+       LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
+
        ret = vconf_set_int(_key, enable);
        if (ret != VCONF_OK) {
                LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
@@ -315,10 +320,7 @@ location_enable_method(const LocationMethod method, const int enable)
 
        /* for hybrid */
        _key = __convert_setting_key(LOCATION_METHOD_HYBRID);
-       if (!_key) {
-               LOCATION_LOGE("Invalid method[%d]", LOCATION_METHOD_HYBRID);
-               return LOCATION_ERROR_NOT_SUPPORTED;
-       }
+       LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", LOCATION_METHOD_HYBRID, err_msg(LOCATION_ERROR_NOT_SUPPORTED));
 
        if (enable) {
                ret = vconf_set_int(_key, enable);
@@ -358,10 +360,7 @@ location_add_setting_notify(LocationMethod method, LocationSettingCb callback, v
 {
        int ret = LOCATION_ERROR_NONE;
        char *_key = __convert_setting_key(method);
-       if (!_key) {
-               LOCATION_LOGE("Invalid method[%d]", method);
-               return LOCATION_ERROR_PARAMETER;
-       }
+       LOC_COND_RET(!_key, LOCATION_ERROR_PARAMETER, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_PARAMETER));
 
        g_location_setting.callback = callback;
        g_location_setting.user_data = user_data;
@@ -377,10 +376,7 @@ location_ignore_setting_notify(LocationMethod method, LocationSettingCb callback
 {
        int ret = LOCATION_ERROR_NONE;
        char *_key = __convert_setting_key(method);
-       if (!_key) {
-               LOCATION_LOGE("Invalid method[%d]", method);
-               return LOCATION_ERROR_PARAMETER;
-       }
+       LOC_COND_RET(!_key, LOCATION_ERROR_PARAMETER, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_PARAMETER));
 
        g_location_setting.callback = NULL;
        g_location_setting.user_data = NULL;
@@ -401,16 +397,13 @@ location_get_position(LocationObject *obj, LocationPosition **position, Location
 
        int ret = LOCATION_ERROR_NONE;
 
-#ifndef TIZEN_PROFILE_TV
-       ret = location_check_cynara(LOCATION_PRIVILEGE);
-       if (ret != LOCATION_ERROR_NONE) {
-               LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
-               return LOCATION_ERROR_NOT_ALLOWED;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
        }
-#endif
 
        ret = location_ielement_get_position(LOCATION_IELEMENT(obj), position, accuracy);
-       if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_position. Error [%d]", ret);
+       LOC_COND_RET(ret != LOCATION_ERROR_NONE, ret, _E, "Fail to get_position [%s]", err_msg(ret));
 
        return ret;
 }
@@ -425,16 +418,13 @@ location_get_position_ext(LocationObject *obj, LocationPosition **position, Loca
 
        int ret = LOCATION_ERROR_NONE;
 
-#ifndef TIZEN_PROFILE_TV
-       ret = location_check_cynara(LOCATION_PRIVILEGE);
-       if (ret != LOCATION_ERROR_NONE) {
-               LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
-               return LOCATION_ERROR_NOT_ALLOWED;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
        }
-#endif
 
        ret = location_ielement_get_position_ext(LOCATION_IELEMENT(obj), position, velocity, accuracy);
-       if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_position_ext. Error [%d]", ret);
+       LOC_IF_FAIL(ret, _E, "Fail to get_position_ext [%s]", err_msg(ret));
 
        return ret;
 }
@@ -448,16 +438,13 @@ location_get_last_position(LocationObject *obj, LocationPosition **position, Loc
 
        int ret = LOCATION_ERROR_NONE;
 
-#ifndef TIZEN_PROFILE_TV
-       ret = location_check_cynara(LOCATION_PRIVILEGE);
-       if (ret != LOCATION_ERROR_NONE) {
-               LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
-               return LOCATION_ERROR_NOT_ALLOWED;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
        }
-#endif
 
        ret = location_ielement_get_last_position(LOCATION_IELEMENT(obj), position, accuracy);
-       if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_last_position. Error [%d]", ret);
+       LOC_IF_FAIL(ret, _E, "Fail to get_last_position [%s]", err_msg(ret));
 
        return ret;
 }
@@ -472,16 +459,13 @@ location_get_last_position_ext(LocationObject *obj, LocationPosition **position,
 
        int ret = LOCATION_ERROR_NONE;
 
-#ifndef TIZEN_PROFILE_TV
-       ret = location_check_cynara(LOCATION_PRIVILEGE);
-       if (ret != LOCATION_ERROR_NONE) {
-               LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
-               return LOCATION_ERROR_NOT_ALLOWED;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
        }
-#endif
 
        ret = location_ielement_get_last_position_ext(LOCATION_IELEMENT(obj), position, velocity, accuracy);
-       if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_last_position_ext. Error [%d]", ret);
+       LOC_IF_FAIL(ret, _E, "Fail to get_last_position_ext [%s]", err_msg(ret));
 
        return ret;
 }
@@ -494,9 +478,7 @@ location_get_nmea(LocationObject *obj, char **nmea)
 
        int ret = LOCATION_ERROR_NONE;
        ret = location_ielement_get_nmea(LOCATION_IELEMENT(obj), nmea);
-       if (ret != LOCATION_ERROR_NONE) {
-               LOCATION_LOGE("Fail to get_nmea. Error [%d]", ret);
-       }
+       LOC_IF_FAIL(ret, _E, "Fail to get_nmea [%s]", err_msg(ret));
 
        return ret;
 }
@@ -510,18 +492,13 @@ location_get_satellite(LocationObject *obj, LocationSatellite **satellite)
 
        int ret = LOCATION_ERROR_NONE;
 
-#ifndef TIZEN_PROFILE_TV
-       ret = location_check_cynara(LOCATION_PRIVILEGE);
-       if (ret != LOCATION_ERROR_NONE) {
-               LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
-               return LOCATION_ERROR_NOT_ALLOWED;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
        }
-#endif
 
        ret = location_ielement_get_satellite(LOCATION_IELEMENT(obj), satellite);
-       if (ret != LOCATION_ERROR_NONE) {
-               LOCATION_LOGE("Fail to get_satellite. Error [%d]", ret);
-       }
+       LOC_IF_FAIL(ret, _E, "Fail to get_satellite [%s]", err_msg(ret));
 
        return ret;
 }
@@ -534,16 +511,13 @@ location_get_batch(LocationObject *obj, LocationBatch **batch)
 
        int ret = LOCATION_ERROR_NONE;
 
-#ifndef TIZEN_PROFILE_TV
-       ret = location_check_cynara(LOCATION_PRIVILEGE);
-       if (ret != LOCATION_ERROR_NONE) {
-               LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
-               return LOCATION_ERROR_NOT_ALLOWED;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
        }
-#endif
 
        ret = location_ielement_get_batch(LOCATION_IELEMENT(obj), batch);
-       if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_batch. Error [%d]", ret);
+       LOC_IF_FAIL(ret, _E, "Fail to get_batch [%s]", err_msg(ret));
 
        return ret;
 }
@@ -556,16 +530,13 @@ location_get_last_satellite(LocationObject *obj, LocationSatellite **satellite)
 
        int ret = LOCATION_ERROR_NONE;
 
-#ifndef TIZEN_PROFILE_TV
-       ret = location_check_cynara(LOCATION_PRIVILEGE);
-       if (ret != LOCATION_ERROR_NONE) {
-               LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
-               return LOCATION_ERROR_NOT_ALLOWED;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
        }
-#endif
 
        ret = location_ielement_get_last_satellite(LOCATION_IELEMENT(obj), satellite);
-       if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_last_satellite. Error [%d]", ret);
+       LOC_IF_FAIL(ret, _E, "Fail to get_last_satellite [%s]", err_msg(ret));
 
        return ret;
 }
@@ -579,16 +550,13 @@ location_get_velocity(LocationObject *obj, LocationVelocity **velocity, Location
 
        int ret = LOCATION_ERROR_NONE;
 
-#ifndef TIZEN_PROFILE_TV
-       ret = location_check_cynara(LOCATION_PRIVILEGE);
-       if (ret != LOCATION_ERROR_NONE) {
-               LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
-               return LOCATION_ERROR_NOT_ALLOWED;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
        }
-#endif
 
        ret = location_ielement_get_velocity(LOCATION_IELEMENT(obj), velocity, accuracy);
-       if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_velocity. Error [%d]", ret);
+       LOC_IF_FAIL(ret, _E, "Fail to get_velocity [%s]", err_msg(ret));
 
        return ret;
 }
@@ -602,16 +570,13 @@ location_get_last_velocity(LocationObject *obj, LocationVelocity **velocity, Loc
 
        int ret = LOCATION_ERROR_NONE;
 
-#ifndef TIZEN_PROFILE_TV
-       ret = location_check_cynara(LOCATION_PRIVILEGE);
-       if (ret != LOCATION_ERROR_NONE) {
-               LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
-               return LOCATION_ERROR_NOT_ALLOWED;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
        }
-#endif
 
        ret = location_ielement_get_last_velocity(LOCATION_IELEMENT(obj), velocity, accuracy);
-       if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_last_velocity. Error [%d]", ret);
+       LOC_IF_FAIL(ret, _E, "Fail to get_last_velocity [%s]", err_msg(ret));
 
        return ret;
 }
@@ -619,22 +584,19 @@ location_get_last_velocity(LocationObject *obj, LocationVelocity **velocity, Loc
 EXPORT_API int
 location_get_accessibility_state(LocationAccessState *state)
 {
-       int auth = location_application_get_authority();
-       switch (auth) {
-       case LOCATION_APP_OFF:
-               *state = LOCATION_ACCESS_DENIED;
-               break;
-       case LOCATION_APP_ON:
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               int ret = location_check_cynara(LOCATION_PRIVILEGE);
+
+               if (ret == LOCATION_ERROR_NONE) {
+                       *state = LOCATION_ACCESS_ALLOWED;
+               } else {
+                       *state = LOCATION_ACCESS_DENIED;
+                       LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
+               }
+       } else {
                *state = LOCATION_ACCESS_ALLOWED;
-               break;
-       case LOCATION_APP_NOT_FOUND:
-               *state = LOCATION_ACCESS_NONE;
-               break;
-       default:
-               return LOCATION_ERROR_UNKNOWN;
        }
 
-       LOCATION_LOGD("get_accessibility_state [%d]", auth);
        return LOCATION_ERROR_NONE;
 }
 
@@ -674,17 +636,13 @@ location_set_option(LocationObject *obj, const char *option)
        g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
        int ret = LOCATION_ERROR_NONE;
 
-#ifndef TIZEN_PROFILE_TV
-       ret = location_check_cynara(LOCATION_PRIVILEGE);
-       if (ret != LOCATION_ERROR_NONE) {
-               LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
-               return LOCATION_ERROR_NOT_ALLOWED;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
        }
-#endif
 
        ret = location_ielement_set_option(LOCATION_IELEMENT(obj), option);
-       if (ret != LOCATION_ERROR_NONE)
-               LOCATION_LOGE("Fail to get_velocity. Error [%d]", ret);
+       LOC_IF_FAIL(ret, _E, "Fail to get_velocity [%s]", err_msg(ret));
        return ret;
 }
 
@@ -692,122 +650,31 @@ location_set_option(LocationObject *obj, const char *option)
 /*
  * Tizen 3.0
  */
-
 EXPORT_API int
-location_get_service_state(LocationObject *obj, int *state)
+location_enable_mock(const int enable)
 {
-       g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
-       g_return_val_if_fail(state, LOCATION_ERROR_PARAMETER);
-
        int ret = LOCATION_ERROR_NONE;
-       ret = location_ielement_get_status(LOCATION_IELEMENT(obj), state);
-       if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to get_position. Error [%d]", ret);
-
-       return ret;
-}
-
 
-EXPORT_API int
-location_enable_mock(const LocationMethod method, const int enable)
-{
-       int ret = 0;
-       char *_key = NULL;
-
-       if (method != LOCATION_METHOD_MOCK) {
-               return LOCATION_ERROR_PARAMETER;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
        }
 
-#ifndef TIZEN_PROFILE_TV
-       ret = location_check_cynara(LOCATION_PRIVILEGE);
-       if (ret != LOCATION_ERROR_NONE) {
-               LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
-               return LOCATION_ERROR_NOT_ALLOWED;
-       }
-#endif
-
 #if 0 /* Tizen platform didn't turn developer option on */
        gboolean developer_option = FALSE;
 
        ret = vconf_get_bool(VCONFKEY_SETAPPL_DEVELOPER_OPTION_STATE, &developer_option);
-       if (!developer_option) {
-               LOCATION_LOGE("Cannot enable mock location because developer option is not turned on", ret);
-               return LOCATION_ERROR_NOT_ALLOWED;
-       }
+       LOC_COND_RET(!developer_option, LOCATION_ERROR_NOT_ALLOWED, _E, "Cannot enable mock location because developer option is not turned on", ret);
 #endif
 
-       _key = __convert_setting_key(method);
-       if (!_key) {
-               LOCATION_LOGE("Invalid method[%d]", method);
-               return LOCATION_ERROR_NOT_SUPPORTED;
-       }
-       ret = vconf_set_int(_key, enable);
-       if (ret != VCONF_OK) {
-               LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
-               g_free(_key);
-               return LOCATION_ERROR_NOT_ALLOWED;
-       }
-
-       g_free(_key);
-
-       return ret;
-}
-
-#if 0
-static char *__convert_mock_setting_key(LocationMethod method)
-{
-       char *key = NULL;
-       switch (method) {
-       case LOCATION_METHOD_MOCK_GPS:
-                       key = g_strdup(VCONFKEY_LOCATION_MOCK_GPS_ENABLED);
-                       break;
-       case LOCATION_METHOD_MOCK_WPS:
-                       key = g_strdup(VCONFKEY_LOCATION_MOCK_NETWORK_ENABLED);
-                       break;
-       default:
-                       break;
-       }
-       return key;
-}
-
-EXPORT_API int
-location_set_mock_method_enabled(const LocationMethod method, const int enable)
-{
-       int ret = 0;
-       char *_key = NULL;
-       int vconf_val = 0;
-
-       _key = __convert_setting_key(method);
-       if (!_key) {
-               LOCATION_LOGE("Invalid method[%d]", method);
-               return LOCATION_ERROR_NOT_SUPPORTED;
-       }
-
-       ret = vconf_get_int(_key, &vconf_val);
+       ret = vconf_set_int(VCONFKEY_LOCATION_MOCK_ENABLED, enable);
        if (ret != VCONF_OK) {
-               LOCATION_SECLOG("failed [%s], error [%d]", _key, ret);
-               g_free(_key);
+               LOCATION_SECLOG("vconf_set_int failed [MOCK_ENABLED], ret=[%d]", ret);
                return LOCATION_ERROR_NOT_ALLOWED;
        }
 
-       if (vconf_val) {
-               _key = __convert_mock_setting_key(method);
-               if (!_key) {
-                       LOCATION_LOGE("Invalid method[%d]", method);
-                       return LOCATION_ERROR_NOT_SUPPORTED;
-               }
-               ret = vconf_set_int(_key, enable);
-               if (ret != VCONF_OK) {
-                       LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
-                       g_free(_key);
-                       return LOCATION_ERROR_NOT_ALLOWED;
-               }
-               g_free(_key);
-       }
-
        return ret;
 }
-#endif
-
 
 EXPORT_API int
 location_set_mock_location(LocationObject *obj, const LocationPosition *position, const LocationVelocity *velocity, const LocationAccuracy *accuracy)
@@ -818,8 +685,13 @@ location_set_mock_location(LocationObject *obj, const LocationPosition *position
        g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
 
        int ret = LOCATION_ERROR_NONE;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
+       }
+
        ret = location_ielement_set_mock_location(LOCATION_IELEMENT(obj), position, velocity, accuracy);
-       if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to location_ielement_set_mock_location. Error [%d]", ret);
+       LOC_IF_FAIL(ret, _E, "Fail to set_mock_location [%s]", err_msg(ret));
 
        return ret;
 }
@@ -830,8 +702,84 @@ location_clear_mock_location(LocationObject *obj)
        g_return_val_if_fail(obj, LOCATION_ERROR_PARAMETER);
 
        int ret = LOCATION_ERROR_NONE;
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
+       }
+
        ret = location_ielement_clear_mock_location(LOCATION_IELEMENT(obj));
-       if (ret != LOCATION_ERROR_NONE) LOCATION_LOGE("Fail to location_ielement_set_mock_location. Error [%d]", ret);
+       LOC_IF_FAIL(ret, _E, "Fail to clear_mock_location [%s]", err_msg(ret));
 
        return ret;
-}
\ No newline at end of file
+}
+
+EXPORT_API int
+location_enable_restriction(const int enable)
+{
+       int ret = LOCATION_ERROR_NONE;
+       int restriction = 0;
+
+       if (_get_tizen_profile() != TIZEN_PROFILE_TV) {
+               ret = location_check_cynara(LOCATION_ENABLE_PRIVILEGE);
+               LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret));
+       }
+       if (enable) {
+               int value = 0;
+               ret = vconf_get_int(VCONFKEY_LOCATION_RESTRICT, &restriction);
+               LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to get restriction status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
+
+               if (restriction == RESTRICT_OFF) {
+
+                       if (location_setting_get_int(VCONFKEY_LOCATION_ENABLED)) {
+                               value |= RESTRICT_GPS;
+                               ret = vconf_set_int(VCONFKEY_LOCATION_ENABLED, 0);
+                               LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
+                       }
+
+                       if (location_setting_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED)) {
+                               value |= RESTRICT_WPS;
+                               ret = vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 0);
+                               LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
+                       }
+
+                       if (location_setting_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION)) {
+                               value |= RESTRICT_HYBRID;
+                               ret = vconf_set_int(VCONFKEY_LOCATION_USE_MY_LOCATION, 0);
+                               LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
+                       }
+
+                       if (value == 0)
+                               value = RESTRICT_NONE;
+
+                       ret = vconf_set_int(VCONFKEY_LOCATION_RESTRICT, value);
+                       LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set value. %d [%s]", value, err_msg(LOCATION_ERROR_NOT_ALLOWED));
+               }
+
+       } else {
+               ret = vconf_get_int(VCONFKEY_LOCATION_RESTRICT, &restriction);
+               LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to get restriction status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
+
+               if (restriction > RESTRICT_OFF) {
+
+                       if (restriction & RESTRICT_GPS) {
+                               ret = vconf_set_int(VCONFKEY_LOCATION_ENABLED, 1);
+                               LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
+                       }
+
+                       if (restriction & RESTRICT_WPS) {
+                               ret = vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 1);
+                               LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
+                       }
+
+                       if (restriction & RESTRICT_HYBRID) {
+                               ret = vconf_set_int(VCONFKEY_LOCATION_USE_MY_LOCATION, 1);
+                               LOC_COND_RET(ret != VCONF_OK, LOCATION_ERROR_NOT_ALLOWED, _E, "Fail to set status [%s]", err_msg(LOCATION_ERROR_NOT_ALLOWED));
+                       }
+
+                       ret = vconf_set_int(VCONFKEY_LOCATION_RESTRICT, RESTRICT_OFF);
+                       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));
+               }
+       }
+
+       return LOCATION_ERROR_NONE;
+}