diff options
Diffstat (limited to 'src/FLoc_LocationProviderImpl.cpp')
-rw-r--r-- | src/FLoc_LocationProviderImpl.cpp | 82 |
1 files changed, 51 insertions, 31 deletions
diff --git a/src/FLoc_LocationProviderImpl.cpp b/src/FLoc_LocationProviderImpl.cpp index dcb75da..f37894a 100644 --- a/src/FLoc_LocationProviderImpl.cpp +++ b/src/FLoc_LocationProviderImpl.cpp @@ -39,6 +39,7 @@ #include <FLocTypes.h> #include <FSysPowerManager.h> #include <FSysSystemTime.h> +#include <FSec_AccessController.h> #include <FSys_SettingInfoImpl.h> #include "FLoc_LocationImpl.h" #include "FLoc_LocationManager.h" @@ -53,6 +54,7 @@ using namespace Tizen::Base; using namespace Tizen::Base::Collection; using namespace Tizen::Base::Runtime; using namespace Tizen::Base::Utility; +using namespace Tizen::Security; using namespace Tizen::System; namespace Tizen { namespace Locations @@ -68,7 +70,7 @@ _LocationProviderImpl::_LocationProviderImpl(void) _LocationProviderImpl::~_LocationProviderImpl(void) { - UiApp* pAppInstance = Tizen::App::UiApp::GetInstance(); + UiApp* pAppInstance = UiApp::GetInstance(); if (pAppInstance) { _AppManagerImpl* pAppManager = _AppManagerImpl::GetInstance(); @@ -88,17 +90,17 @@ _LocationProviderImpl::Construct(const LocationCriteria& criteria, ILocationProv _LocationManager* pLocationManager = _LocationManager::GetInstance(); SysTryReturn(NID_LOC, pLocationManager != null, GetLastResult(), GetLastResult(), "[%s] Failed to get the location manager instance.", GetErrorMessage(GetLastResult())); - std::unique_ptr< Tizen::Base::Collection::ArrayList, AllElementsDeleter > pRegionList(new (std::nothrow) ArrayList(SingleObjectDeleter)); + std::unique_ptr< ArrayList, AllElementsDeleter > pRegionList(new (std::nothrow) ArrayList(SingleObjectDeleter)); SysTryReturn(NID_LOC, pRegionList != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); result r = pRegionList->Construct(); SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to construct the list. Propagating.", GetErrorMessage(r)); - std::unique_ptr< Tizen::Base::Runtime::Timer > pTimer(new (std::nothrow) Timer()); + std::unique_ptr< Timer > pTimer(new (std::nothrow) Timer()); SysTryReturn(NID_LOC, pTimer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pTimer->Construct(*this); SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to construct the timer. Propagating.", GetErrorMessage(r)); - UiApp* pAppInstance = Tizen::App::UiApp::GetInstance(); + UiApp* pAppInstance = UiApp::GetInstance(); if (pAppInstance != null) { _AppManagerImpl* pAppManager = _AppManagerImpl::GetInstance(); @@ -180,7 +182,7 @@ _LocationProviderImpl::KeepLocationUpdateAwake(bool enable) } __locationUpdater.awakeEnabled = enable; - UiApp* appInstance = Tizen::App::UiApp::GetInstance(); + UiApp* appInstance = UiApp::GetInstance(); if (appInstance == null) // This is service APP. So should be handled now. { SysLog(NID_LOC, "Handling the request awake mode(%d) for the service application.", enable); @@ -427,6 +429,7 @@ _LocationProviderImpl::OnLocationEventReceivedN(RequestId reqId, Tizen::Location { SysLog(NID_LOC, "Location Event received."); bool isNew = false; + bool isPrivilegeDenied = false; LocationAccuracy currentAccuracy = LOC_ACCURACY_INVALID; LocationAccuracy lastLocAccuracy = __lastLocationAccuracy; long long lastLocationTime = 0; @@ -453,6 +456,11 @@ _LocationProviderImpl::OnLocationEventReceivedN(RequestId reqId, Tizen::Location currentAccuracy = __pLocationManager->GetAccuracyLevel(pLocation->GetHorizontalAccuracy()); } + if (!GetUserPrivilege()) + { + isPrivilegeDenied = true; + } + if (currentAccuracy != __lastLocationAccuracy) { SysLog(NID_LOC, "Notify the accuracy change."); @@ -462,13 +470,14 @@ _LocationProviderImpl::OnLocationEventReceivedN(RequestId reqId, Tizen::Location if (reqId == __locationUpdater.reqId) { - HandleLocationUpdate(location, isNew); + HandleLocationUpdate(location, isNew, isPrivilegeDenied); } else if (reqId == __regionMonitor.reqId) { if (isNew) { bool gpsEnabled = false; + bool isAccuracyMet = false; _SettingInfoImpl::GetValue(L"http://tizen.org/setting/location.gps", gpsEnabled); SysLog(NID_LOC, "The GPS settings value is %d", gpsEnabled); @@ -479,18 +488,17 @@ _LocationProviderImpl::OnLocationEventReceivedN(RequestId reqId, Tizen::Location *__regionMonitor.pLocation = location; } - if ((currentAccuracy != LOC_ACCURACY_INVALID && currentAccuracy <= __criteria.GetAccuracy()) || !gpsEnabled) + if (!gpsEnabled || (currentAccuracy != LOC_ACCURACY_INVALID && currentAccuracy <= __criteria.GetAccuracy())) { SysLog(NID_LOC, "Location criteria (accuracy: %ld) is met for handling region monitoring.", currentAccuracy); - result r = __regionMonitor.pTimer->Cancel(); - SysTryLog(NID_LOC, r == E_SUCCESS, "Failed to cancel the timer."); - - HandleRegionMonitoring(location, isNew); + isAccuracyMet = true; } else { SysLog(NID_LOC, "Location criteria (accuracy: %ld) is not met for handling region monitoring.", currentAccuracy); } + + HandleRegionMonitoring(location, isNew, isPrivilegeDenied, isAccuracyMet); } } @@ -521,7 +529,7 @@ void _LocationProviderImpl::OnActiveAppChanged(const Tizen::App::AppId& appId) { Tizen::App::App* pApp = Tizen::App::App::GetInstance(); - Tizen::App::AppId currentAppId = pApp->GetAppId(); + AppId currentAppId = pApp->GetAppId(); SysLog(NID_LOC, "Active App ID is (%ls) and the current app Id is (%ls)", appId.GetPointer(), currentAppId.GetPointer()); @@ -555,8 +563,7 @@ void _LocationProviderImpl::OnTimerExpired(Timer& timer) { SysLog(NID_LOC, "Region Monitor timer expired due to unavailability of location information."); - __pLocationManager->StopLocationUpdates(__regionMonitor.reqId); - HandleRegionMonitoring(*__regionMonitor.pLocation, __regionMonitor.pLocation->IsValid()); + HandleRegionMonitoring(*__regionMonitor.pLocation, __regionMonitor.pLocation->IsValid(), !GetUserPrivilege(), true); } result @@ -577,7 +584,7 @@ _LocationProviderImpl::StartLocationUpdates(LocationUpdateType updateType, int i if (!__locationUpdater.awakeEnabled) { - UiApp* pAppInstance = Tizen::App::UiApp::GetInstance(); + UiApp* pAppInstance = UiApp::GetInstance(); if (pAppInstance == null) { startUpdate = false; @@ -690,23 +697,23 @@ _LocationProviderImpl::FireImpl(Tizen::Base::Runtime::IEventListener& listener, } void -_LocationProviderImpl::HandleLocationUpdate(Tizen::Locations::Location& location, bool isNew) +_LocationProviderImpl::HandleLocationUpdate(Tizen::Locations::Location& location, bool isNew, bool isPrivilegeDenied) { LocationServiceStatus newLocationUpdateStatus = __locationUpdater.status; - if (isNew) + if (isPrivilegeDenied) { + SysLog(NID_LOC, "User consent not available."); if (__locationUpdater.type != _LOCATION_UPDATE_TYPE_NONE && __locationUpdater.status != LOC_SVC_STATUS_PAUSED) { - newLocationUpdateStatus = LOC_SVC_STATUS_RUNNING; + newLocationUpdateStatus = LOC_SVC_STATUS_DENIED; } } - else if (!GetUserPrivilege()) + else if (isNew) { - SysLog(NID_LOC, "User consent not available."); if (__locationUpdater.type != _LOCATION_UPDATE_TYPE_NONE && __locationUpdater.status != LOC_SVC_STATUS_PAUSED) { - newLocationUpdateStatus = LOC_SVC_STATUS_DENIED; + newLocationUpdateStatus = LOC_SVC_STATUS_RUNNING; } } else @@ -746,17 +753,17 @@ _LocationProviderImpl::HandleLocationUpdate(Tizen::Locations::Location& location } void -_LocationProviderImpl::HandleRegionMonitoring(Tizen::Locations::Location& location, bool isNew) +_LocationProviderImpl::HandleRegionMonitoring(Tizen::Locations::Location& location, bool isNew, bool isPrivilegeDenied, bool isAccuracyMet) { LocationServiceStatus newRegionMonitorStatus = __regionMonitor.status; - if (isNew) + if (isPrivilegeDenied) { - newRegionMonitorStatus = LOC_SVC_STATUS_RUNNING; + newRegionMonitorStatus = LOC_SVC_STATUS_DENIED; } - else if (!GetUserPrivilege()) + else if (isNew) { - newRegionMonitorStatus = LOC_SVC_STATUS_DENIED; + newRegionMonitorStatus = LOC_SVC_STATUS_RUNNING; } else { @@ -770,12 +777,16 @@ _LocationProviderImpl::HandleRegionMonitoring(Tizen::Locations::Location& locati __pLocationListener->OnRegionMonitoringStatusChanged(__regionMonitor.status); } - if (newRegionMonitorStatus == LOC_SVC_STATUS_RUNNING) + if (isAccuracyMet) { - NotifyRegionCrossedStatus(location); + result r = __regionMonitor.pTimer->Cancel(); + SysTryLog(NID_LOC, r == E_SUCCESS, "Failed to cancel the timer."); + if (newRegionMonitorStatus == LOC_SVC_STATUS_RUNNING) + { + NotifyRegionCrossedStatus(location); + } + SetNextRegionMonitoringTime(); } - - SetNextRegionMonitoringTime(); } void @@ -829,7 +840,12 @@ _LocationProviderImpl::NotifyRegionCrossedStatus(const Tizen::Locations::Locatio _RegionState _LocationProviderImpl::GetRegionCurrentState(const _RegionInfo& region, const Location& location) { - TryReturn(location.GetHorizontalAccuracy() >= 0.0, REGION_STATE_UNKNOWN, "Location received with invalid accuracy"); + double horAcc = location.GetHorizontalAccuracy(); + if (Double::IsNaN(horAcc)) + { + horAcc = 0.0; + } + TryReturn(horAcc >= 0.0, REGION_STATE_UNKNOWN, "Location received with invalid accuracy"); SysSecureLog(NID_LOC, "[RegionID %d] Region Information is (Center latitude: %lf, Center longitude: %lf, Region radius:%lf", region.GetRegionId(), region.GetCoordinate().GetLatitude(), region.GetCoordinate().GetLongitude(), region.GetRadius()); @@ -937,6 +953,10 @@ _LocationProviderImpl::GetUserPrivilege(void) { return false; } + + result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION); + SysTryReturn(NID_LOC, r == E_SUCCESS, false, r, "[%s] The user does not allow the application to use location information.", GetErrorMessage(r)); + return true; } |