#include "FLoc_LocationImpl.h"
#include "FLoc_LocationProviderImpl.h"
-
using namespace Tizen::Security;
namespace Tizen { namespace Locations
SysAssertf(__pImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
__pImpl = new (std::nothrow) _LocationProviderImpl();
- SysTryReturnResult(NID_LOC, __pImpl, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ SysTryReturnResult(NID_LOC, __pImpl, E_OUT_OF_MEMORY, "Memory allocation failed.");
result r = __pImpl->Construct(criteria, listener);
SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to construct location Provider.", GetErrorMessage(r));
{
result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION);
r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
- SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "[%s] The application is not permitted to call this method.",GetErrorMessage(r));
+ SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "The application is not permitted to call this method.");
r = _AccessController::CheckUserPrivilege(_PRV_POWER);
SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
{
result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION);
r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
- SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "[%s] The application is not permitted to call this method.",GetErrorMessage(r));
+ SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "The application is not permitted to call this method.");
r = _AccessController::CheckUserPrivilege(_PRV_POWER);
SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
#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"
#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
{
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;
SysLog(NID_LOC, "Location Event received.");
bool isNew = false;
LocationAccuracy currentAccuracy = LOC_ACCURACY_INVALID;
+ LocationAccuracy lastLocAccuracy = __lastLocationAccuracy;
long long lastLocationTime = 0;
Location* pLocation = &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);
+ }
}
}
_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));
}
}
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;
}
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);