From 381d8e7afc48df5b7e2485feca460a763bd894af Mon Sep 17 00:00:00 2001 From: "kj7.sung" Date: Thu, 28 Apr 2016 14:51:24 +0900 Subject: [PATCH] Location setting restriction to support DPM Change-Id: I5c3d9aa8139a5c93ea18d1bb7a082f7c9ed1e56c Signed-off-by: kj7.sung --- location/include/location-types.h | 11 ++++++ location/manager/location-gps.c | 2 +- location/manager/location.c | 76 +++++++++++++++++++++++++++++++++++++++ location/manager/location.h | 2 ++ packaging/liblbs-location.changes | 7 ++++ packaging/liblbs-location.spec | 2 +- 6 files changed, 98 insertions(+), 2 deletions(-) diff --git a/location/include/location-types.h b/location/include/location-types.h index 9e15897..95ed229 100644 --- a/location/include/location-types.h +++ b/location/include/location-types.h @@ -91,6 +91,17 @@ typedef enum { } LocationAccessState; /** + * @brief This represents the setting type. + */ +typedef enum { + RESTRICT_OFF = 0, + RESTRICT_NONE = 0x01, + RESTRICT_GPS = RESTRICT_NONE << 0x01, + RESTRICT_WPS = RESTRICT_NONE << 0x02, + RESTRICT_HYBRID = RESTRICT_NONE << 0x03, +} LocationRestrictType; + +/** * @brief Location object redefined by GObject. */ typedef GObject LocationObject; diff --git a/location/manager/location-gps.c b/location/manager/location-gps.c index 286d7b5..3e78d03 100755 --- a/location/manager/location-gps.c +++ b/location/manager/location-gps.c @@ -593,7 +593,7 @@ static int location_gps_stop_batch(LocationGps *self) if (__get_started(self) == TRUE) { __set_started(self, FALSE); ret = priv->mod->ops.stop_batch(priv->mod->handler); - LOC_IF_FAIL_LOG(ret, _E, "Failed to stop_batch [%s]", err_mgs(ret)); + LOC_IF_FAIL_LOG(ret, _E, "Failed to stop_batch [%s]", err_msg(ret)); } else { return LOCATION_ERROR_NONE; } diff --git a/location/manager/location.c b/location/manager/location.c index b5ee57c..f36721e 100755 --- a/location/manager/location.c +++ b/location/manager/location.c @@ -286,6 +286,11 @@ location_enable_method(const LocationMethod method, const int enable) LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret)); #endif + if (location_setting_get_int(VCONFKEY_LOCATION_RESTRICT) > RESTRICT_OFF) { + LOCATION_SECLOG("Location setting is denied by DPM"); + return LOCATION_ERROR_NOT_ALLOWED; + } + /* for itself */ _key = __convert_setting_key(method); LOC_COND_RET(!_key, LOCATION_ERROR_NOT_SUPPORTED, _E, "Invalid method = %d [%s]", method, err_msg(LOCATION_ERROR_NOT_SUPPORTED)); @@ -760,3 +765,74 @@ location_clear_mock_location(LocationObject *obj) return ret; } + +EXPORT_API int +location_enable_restriction(const int enable) +{ + int ret = LOCATION_ERROR_NONE; + int restriction = 0; + +#ifndef TIZEN_PROFILE_TV + ret = location_check_cynara(LOCATION_ENABLE_PRIVILEGE); + LOC_IF_FAIL(ret, _E, "Privilege not allowed [%s]", err_msg(ret)); +#endif + 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; +} diff --git a/location/manager/location.h b/location/manager/location.h index ebb1527..84d3ee7 100755 --- a/location/manager/location.h +++ b/location/manager/location.h @@ -877,6 +877,8 @@ int location_set_mock_method_enabled(const LocationMethod method, const int enab int location_set_mock_location(LocationObject *obj, const LocationPosition *position, const LocationVelocity *velocity, const LocationAccuracy *accuracy); int location_clear_mock_location(LocationObject *obj); +int location_enable_restriction(const int enable); + /** * @} @} */ diff --git a/packaging/liblbs-location.changes b/packaging/liblbs-location.changes index ba3b2ed..978b2fc 100644 --- a/packaging/liblbs-location.changes +++ b/packaging/liblbs-location.changes @@ -1,3 +1,10 @@ +[Version] libslp-location_1.3.0 +[Date] 12 May 2016 +[Changes] Add location restriction to support DPM +[Developer] Kyoungjun Sung + +================================================================================ + [Version] libslp-location_1.2.1 [Date] 9 May 2016 [Changes] Change tag style for error log diff --git a/packaging/liblbs-location.spec b/packaging/liblbs-location.spec index a17aee4..d0432a0 100755 --- a/packaging/liblbs-location.spec +++ b/packaging/liblbs-location.spec @@ -1,6 +1,6 @@ Name: liblbs-location Summary: Location Based Service Library -Version: 1.2.1 +Version: 1.3.0 Release: 1 Group: Location/Libraries License: Apache-2.0 -- 2.7.4