diff options
Diffstat (limited to 'src/FLoc_LocationProviderImpl.cpp')
-rw-r--r-- | src/FLoc_LocationProviderImpl.cpp | 98 |
1 files changed, 67 insertions, 31 deletions
diff --git a/src/FLoc_LocationProviderImpl.cpp b/src/FLoc_LocationProviderImpl.cpp index f88e03b..2d25b79 100644 --- a/src/FLoc_LocationProviderImpl.cpp +++ b/src/FLoc_LocationProviderImpl.cpp @@ -41,7 +41,6 @@ #include <FSysSystemTime.h> #include <FSys_AlarmImpl.h> #include <FSys_SettingInfoImpl.h> -#include "FLoc_Config.h" #include "FLoc_LocationImpl.h" #include "FLoc_LocationManager.h" #include "FLoc_LocationMonitor.h" @@ -49,13 +48,13 @@ #include "FLoc_MathUtils.h" #include "FLoc_Types.h" +using namespace std; using namespace Tizen::App; using namespace Tizen::Base; using namespace Tizen::Base::Collection; using namespace Tizen::Base::Runtime; using namespace Tizen::Base::Utility; using namespace Tizen::System; -using namespace std; namespace Tizen { namespace Locations { @@ -243,7 +242,7 @@ _LocationProviderImpl::AddMonitoringRegion(const Coordinates& regionCenter, doub return E_SUCCESS; } - r = ActivateRegionMonitoring(); + r = ActivateRegionMonitoring(true); SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to start the region monitoring. Propogating.", GetErrorMessage(r)); __regionMonitor.status = LOC_SVC_STATUS_NOT_FIXED; @@ -419,6 +418,7 @@ _LocationProviderImpl::OnLocationEventReceivedN(RequestId reqId, Tizen::Location SysLog(NID_LOC, "Location Event received."); bool isNew = false; LocationAccuracy currentAccuracy = LOC_ACCURACY_INVALID; + LocationAccuracy lastLocAccuracy = __lastLocationAccuracy; long long lastLocationTime = 0; Location* pLocation = &location; @@ -456,24 +456,31 @@ _LocationProviderImpl::OnLocationEventReceivedN(RequestId reqId, Tizen::Location } else if (reqId == __regionMonitor.reqId) { - if (isNew) // Copy the location only if it is new. + if (isNew) { - *__regionMonitor.pLocation = location; - } + bool gpsEnabled = false; + _SettingInfoImpl::GetValue(L"http://tizen.org/setting/location.gps", gpsEnabled); + SysLog(NID_LOC, "The GPS settings value is %d", gpsEnabled); + + __regionMonitor.speed = location.GetSpeed() * 0.2777778; - if (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."); + if ( currentAccuracy <= lastLocAccuracy || timeDifference > DEFAULT_THRESHOLD_LOC_VALIDITY_TIME_OUT) // Copy the location only if it is new and accuracy is better than before. + { + *__regionMonitor.pLocation = location; + } - r = __pLocationManager->StopLocationUpdates(__regionMonitor.reqId); - SysTryLog(NID_LOC, r == E_SUCCESS, "Failed to stop the location updates."); - HandleRegionMonitoring(location, isNew); - } - else - { - SysLog(NID_LOC, "Location criteria (accuracy: %ld) is not met for handling region monitoring.", currentAccuracy); + if ((currentAccuracy != LOC_ACCURACY_INVALID && currentAccuracy <= __criteria.GetAccuracy()) || !gpsEnabled) + { + 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); + } + else + { + SysLog(NID_LOC, "Location criteria (accuracy: %ld) is not met for handling region monitoring.", currentAccuracy); + } } } @@ -530,7 +537,7 @@ void _LocationProviderImpl::OnAlarmExpired(Alarm& alarm) { SysLog(NID_LOC, "Region Monitor Alarm expired."); - result r = ActivateRegionMonitoring(); + result r = ActivateRegionMonitoring(true); SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to start the region monitoring. Propogating.", GetErrorMessage(r)); } @@ -920,23 +927,35 @@ _LocationProviderImpl::GetUserPrivilege(void) } result -_LocationProviderImpl::ActivateRegionMonitoring(void) +_LocationProviderImpl::ActivateRegionMonitoring(bool startUpdate) { long long currentTime; SystemTime::GetTicks(currentTime); + int DEFAULT_WAITING_TIME = DEFAULT_WAITING_TIME_FOR_FIXING_GPS_LOCATION; - SysLog(NID_LOC, "Current system time is %lld", currentTime); + SysLog(NID_LOC, "Current system time is %lld and location update request is %d", currentTime, startUpdate); - _LocationImpl::GetInstance(*__regionMonitor.pLocation)->SetValidity(false); - _LocationImpl::GetInstance(*__regionMonitor.pLocation)->SetTimestamp(currentTime); + bool gpsEnabled = false; + result gps = _SettingInfoImpl::GetValue(L"http://tizen.org/setting/location.gps", gpsEnabled); + if (gps == E_SUCCESS && !gpsEnabled) + { + SysLog(NID_LOC, "The GPS setting is OFF. So wait for only 10 seconds."); + DEFAULT_WAITING_TIME = DEFAULT_WAITING_TIME_FOR_FIXING_WPS_LOCATION; + } - result r = __regionMonitor.pTimer->Start(DEFAULT_WAITING_TIME_FOR_FIXING_LOCATION * 1000); - SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the timer. Propogating.", GetErrorMessage(r)); + result r = __regionMonitor.pTimer->Start(DEFAULT_WAITING_TIME * 1000); + SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the timer. Propogating.", GetErrorMessage(r)); - r = __pLocationManager->StartLocationUpdates(__criteria.GetAccuracy(), MIN_LOCATION_UPDATE_INTERVAL, this, __regionMonitor.reqId); - SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the location updates. Propogating.", GetErrorMessage(r)); + if (startUpdate) + { + _LocationImpl::GetInstance(*__regionMonitor.pLocation)->SetValidity(false); + _LocationImpl::GetInstance(*__regionMonitor.pLocation)->SetTimestamp(currentTime); - SysLog(NID_LOC, "Timer & Location updates are started."); + r = __pLocationManager->StartLocationUpdates(__criteria.GetAccuracy(), MIN_LOCATION_UPDATE_INTERVAL, this, __regionMonitor.reqId); + SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the location updates. Propogating.", GetErrorMessage(r)); + SysLog(NID_LOC, "Location updates started."); + } + return E_SUCCESS; } @@ -962,19 +981,36 @@ _LocationProviderImpl::SetNextRegionMonitoringTime(void) SysLog(NID_LOC, "Current System Time is %ls", alarmDateTime.ToString().GetPointer()); + double speed = DEFAULT_AVG_SPEED; + if (__regionMonitor.speed > DEFAULT_AVG_SPEED) + { + SysLog(NID_LOC, "The speed of the user is greater than the default speed. So updating the value."); + speed = __regionMonitor.speed; + } if (__regionMonitor.pLocation->IsValid()) { const int bufferTime = 5; //Buffer of 5 seconds for determining the alarmTime; double minDistance = _MathUtils::GetShortestDistance(*__regionMonitor.pLocation, *__regionMonitor.pRegionList); - long long newAlarmTime = ((int) minDistance / DEFAULT_AVG_SPEED) - bufferTime; //Calculate the alarm time based on the shortest distance between current location and nearest region boundary. - if (newAlarmTime > alarmTime) + long long newAlarmTime = ((int) minDistance / speed) - bufferTime; //Calculate the alarm time based on the shortest distance between current location and nearest region boundary. + + if (newAlarmTime < DEFAULT_REGION_MONITORING_CYCLE_INTERVAL) + { + SysLog(NID_LOC, "The alarm time is less than 5 seconds. So do not stop the location updates."); + ActivateRegionMonitoring(false); + return; + } + else { alarmTime = newAlarmTime; } } + + result r = __pLocationManager->StopLocationUpdates(__regionMonitor.reqId); + SysTryLog(NID_LOC, r == E_SUCCESS, "Failed to stop the location updates."); + alarmDateTime.AddSeconds(alarmTime); - result r = _AlarmImpl::GetInstance(__regionMonitor.pAlarm.get())->Set(alarmDateTime, 0, null); + r = _AlarmImpl::GetInstance(__regionMonitor.pAlarm.get())->Set(alarmDateTime, 0, null); SysTryLog(NID_LOC, r == E_SUCCESS, "Failed to set the alarm for next cycle."); SysLog(NID_LOC, "Next alarm expires after %ld seconds.", alarmTime); |