, __minRequestedAccuracy(LOC_ACCURACY_INVALID)
, __timerInterval(0)
, __timerTicks(0)
+ , __awakeReqCount(0)
, __pLocRequestInfoList(null)
, __pSyncLocRequestInfoList(null)
, __pAlarmRequestInfoList(null)
return E_SUCCESS;
}
+void
+_LocationManager::KeepLocationUpdateAwake(bool enable)
+{
+ SysLog(NID_LOC, "Location update awake requested (%d).", enable);
+ const int ARRAY_LIST_CAPACITY = 1;
+
+ std::unique_ptr< ArrayList, AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
+ SysTryReturnVoidResult(NID_LOC, pArgList, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ std::unique_ptr< Boolean > pEnable(new (std::nothrow) Boolean(enable));
+ SysTryReturnVoidResult(NID_LOC, pEnable, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ result r = pArgList->Construct(ARRAY_LIST_CAPACITY);
+ SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Array Construct failed. Propogating.", GetErrorMessage(r));
+ r = pArgList->Add(*pEnable);
+ SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Arraylist addition of an object failed. Propogating.", GetErrorMessage(r));
+ pEnable.release();
+
+ r = SendUserEvent(REQ_ID_HANDLE_LOC_AWAKE_REQ, pArgList.get());
+ SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to send the user event. Propagating.", GetErrorMessage(r));
+ pArgList.release();
+}
+
Location
_LocationManager::GetLastKnownLocation(void)
{
__pLocRequestInfoList->Add(*pNewLocRequestInfo.get());
pNewLocRequestInfo.release();
- if (__minRequestedAccuracy == LOC_ACCURACY_INVALID)
- {
- result r = _PowerManagerImpl::PowerControl(1, 1);
- SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to keep the CPU in awake state.", GetErrorMessage(r));
- }
const int FIRST_REQUEST = 1;
int count = __pLocRequestInfoList->GetCount();
SysLog(NID_LOC, "Total count of request info is (%d).", count);
SysLog(NID_LOC, "Total count of request info is (%d).", __pLocRequestInfoList->GetCount());
if (__pLocRequestInfoList->GetCount() == LIST_COUNT_ZERO)
{
- _PowerManagerImpl::PowerControl(1, 0);
-
Reset();
location_manager_stop(__locMgrStatus.gpsHandler.handle);
location_manager_stop(__locMgrStatus.wpsHandler.handle);
}
void
+_LocationManager::HandleSettingsChange(void)
+{
+ const String GPS_STRING(L"http://tizen.org/setting/location.gps");
+ const String WPS_STRING(L"http://tizen.org/setting/location.wps");
+
+ bool gpsEnabled = false;
+ bool wpsEnabled = false;
+ result gps = _SettingInfoImpl::GetValue(GPS_STRING, gpsEnabled);
+ SysTryReturnVoidResult(NID_LOC, gps == E_SUCCESS, gps, "[%s] Failed to get the setting value for GPS.", GetErrorMessage(gps));
+ result wps = _SettingInfoImpl::GetValue(WPS_STRING, wpsEnabled);
+ SysTryReturnVoidResult(NID_LOC, wps == E_SUCCESS, wps, "[%s] Failed to get the setting value for WPS.", GetErrorMessage(wps));
+
+ SysLog(NID_LOC, "The previous GPS setting value is (%d) and WPS setting value is (%d).", __gpsEnabled, __wpsEnabled);
+ SysLog(NID_LOC, "The changed GPS setting value is (%d) and WPS setting value is (%d).", gpsEnabled, wpsEnabled);
+
+ SysLog(NID_LOC, "The Location manager state is (%d).", __locMgrStatus.locMgrState);
+
+ switch (__locMgrStatus.locMgrState)
+ {
+ case LOC_MGR_STATE_PASSIVE_IDLE:
+ {
+ if (gpsEnabled && !wpsEnabled)
+ {
+ SysLog(NID_LOC, "GPS setting enabled during the LOC_MGR_STATE_PASSIVE_IDLE.");
+ int res = location_manager_start(__locMgrStatus.gpsHandler.handle);
+ SysTryLog(NID_LOC, res == 0, "Failed to start the GPS location updates in Passive Idle mode.");
+ if (res == 0)
+ {
+ const int LOC_CHECK_TIMER_VALUE = 1;
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_GPS_ONLY;
+ __locMgrStatus.locMgrSubState = LM_SS_NO_FIX;
+ __pLocCheckTimer->Start(LOC_CHECK_TIMER_VALUE * 1000);
+ }
+ }
+ else if (!gpsEnabled && wpsEnabled)
+ {
+ SysLog(NID_LOC, "WPS setting enabled during the LOC_MGR_STATE_PASSIVE_IDLE.");
+ int res = location_manager_start(__locMgrStatus.wpsHandler.handle);
+ SysTryLog(NID_LOC, res == 0, "Failed to start the WPS location updates in Passive Idle mode.");
+ if (res == 0)
+ {
+ const int LOC_CHECK_TIMER_VALUE = 1;
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_WPS_ONLY;
+ __locMgrStatus.locMgrSubState = LM_SS_NO_FIX;
+ __pLocCheckTimer->Start(LOC_CHECK_TIMER_VALUE * 1000);
+ }
+ }
+ }
+ break;
+
+ case LOC_MGR_STATE_BOTH_GPS_WPS:
+ {
+ if (!gpsEnabled)
+ {
+ SysLog(NID_LOC, "GPS setting turned off during LOC_MGR_STATE_BOTH_GPS_WPS.");
+ location_manager_stop(__locMgrStatus.gpsHandler.handle);
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_WPS_ONLY;
+ }
+
+ if (!wpsEnabled)
+ {
+ SysLog(NID_LOC, "WPS setting turned off during LOC_MGR_STATE_BOTH_GPS_WPS.");
+ location_manager_stop(__locMgrStatus.wpsHandler.handle);
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_GPS_ONLY;
+ }
+ }
+ break;
+
+ case LOC_MGR_STATE_GPS_ONLY:
+ {
+ if (!gpsEnabled)
+ {
+ int res = -1;
+ if (wpsEnabled)
+ {
+ SysLog(NID_LOC, "The WPS setting is enabled. So starting WPS now.");
+ res = location_manager_start(__locMgrStatus.wpsHandler.handle);
+ SysTryLog(NID_LOC, res == 0, "Failed to start the location updates for WPS. Return value is (%d).", res);
+ if (res == 0)
+ {
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_WPS_ONLY;
+ }
+ }
+ if (!wpsEnabled || res != 0)
+ {
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_PASSIVE_IDLE;
+ StopSubStateTimer();
+ __pLocCheckTimer->Cancel();
+ }
+
+ SysLog(NID_LOC, "GPS setting turned off during LOC_MGR_STATE_GPS_ONLY.");
+ location_manager_stop(__locMgrStatus.gpsHandler.handle);
+ }
+ }
+ break;
+
+ case LOC_MGR_STATE_WPS_ONLY:
+ {
+ if (!wpsEnabled)
+ {
+ int res = -1;
+ if (gpsEnabled)
+ {
+ SysLog(NID_LOC, "The GPS setting is enabled. So starting GPS now.");
+ res = location_manager_start(__locMgrStatus.gpsHandler.handle);
+ SysTryLog(NID_LOC, res == 0, "Failed to start the location updates for GPS. Return value is (%d).", res);
+ if (res == 0)
+ {
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_GPS_ONLY;
+ }
+ }
+ if (!gpsEnabled || res != 0)
+ {
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_PASSIVE_IDLE;
+ StopSubStateTimer();
+ __pLocCheckTimer->Cancel();
+ }
+
+ SysLog(NID_LOC, "WPS setting turned off during LOC_MGR_STATE_WPS_ONLY.");
+ location_manager_stop(__locMgrStatus.wpsHandler.handle);
+ }
+ }
+ break;
+
+ case LOC_MGR_STATE_IDLE:
+ // follow through
+ default:
+ SysLog(NID_LOC, "GPS setting changed when there is no active location request. (%d),", __locMgrStatus.locMgrState);
+ break;
+ }
+
+ __gpsEnabled = gpsEnabled;
+ __wpsEnabled = wpsEnabled;
+}
+
+void
_LocationManager::HandleBothGpsWpsState(void)
{
bool isGpsAccMet = false;
location_manager_destroy(__locMgrStatus.wpsHandler.handle);
}
SettingInfo::RemoveSettingEventListener(*this);
+ _PowerManagerImpl::PowerControl(1, 0);
}
void
}
break;
+ case REQ_ID_HANDLE_SETTINGS_CHANGE:
+ {
+ SysLog(NID_LOC, "REQ_ID_HANDLE_SETTINGS_CHANGE");
+ HandleSettingsChange();
+ }
+ break;
+
+ case REQ_ID_HANDLE_LOC_AWAKE_REQ:
+ {
+ SysLog(NID_LOC, "REQ_ID_HANDLE_LOC_AWAKE_REQ");
+ SysTryReturnVoidResult(NID_LOC, pArgs, E_INVALID_ARG, "[E_INVALID_ARG] Null argument encountered. Ignored.");
+ Boolean* pEnable = null;
+ result r = E_SUCCESS;
+ bool enable = false;
+ SysTryCatch(NID_LOC, pArgs->GetCount() == ARRAY_LIST_CAPACITY, pArgs->RemoveAll(true), E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+ pEnable = static_cast< Boolean* >(pArgs->GetAt(0));
+ SysTryCatch(NID_LOC, pEnable, , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+
+ enable = pEnable->ToBool();
+
+ if (enable == true)
+ {
+ __awakeReqCount++;
+ }
+ else
+ {
+ __awakeReqCount--;
+ }
+
+ SysLog(NID_LOC, "The number of current awake request count is (%d).", __awakeReqCount);
+
+ if (__awakeReqCount == 1)
+ {
+ r = _PowerManagerImpl::PowerControl(1, 1);
+ SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to lock the CPU in awake state.", GetErrorMessage(r));
+ }
+ else if (__awakeReqCount == 0)
+ {
+ r = _PowerManagerImpl::PowerControl(1, 0);
+ SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to unlock the CPU in awake state.", GetErrorMessage(r));
+ }
+ }
+ break;
+
}
if (pArgs)
return;
}
- bool gpsEnabled = false;
- bool wpsEnabled = false;
- result gps = _SettingInfoImpl::GetValue(GPS_STRING, gpsEnabled);
- SysTryReturnVoidResult(NID_LOC, gps == E_SUCCESS, gps, "[%s] Failed to get the setting value for GPS.", GetErrorMessage(gps));
- result wps = _SettingInfoImpl::GetValue(WPS_STRING, wpsEnabled);
- SysTryReturnVoidResult(NID_LOC, wps == E_SUCCESS, wps, "[%s] Failed to get the setting value for WPS.", GetErrorMessage(wps));
-
- SysLog(NID_LOC, "The current GPS setting value is (%d) and WPS setting value is (%d).", __gpsEnabled, __wpsEnabled);
- SysLog(NID_LOC, "The changed GPS setting value is (%d) and WPS setting value is (%d).", gpsEnabled, wpsEnabled);
-
- switch (__locMgrStatus.locMgrState)
- {
- case LOC_MGR_STATE_PASSIVE_IDLE:
- {
- if (gpsEnabled && !wpsEnabled)
- {
- SysLog(NID_LOC, "GPS setting enabled during the LOC_MGR_STATE_PASSIVE_IDLE.");
- int res = location_manager_start(__locMgrStatus.gpsHandler.handle);
- SysTryLog(NID_LOC, res == 0, "Failed to start the GPS location updates in Passive Idle mode.");
- if (res == 0)
- {
- const int LOC_CHECK_TIMER_VALUE = 1;
- __locMgrStatus.locMgrState = LOC_MGR_STATE_GPS_ONLY;
- __locMgrStatus.locMgrSubState = LM_SS_NO_FIX;
- __pLocCheckTimer->Start(LOC_CHECK_TIMER_VALUE * 1000);
- }
- }
- else if (!gpsEnabled && wpsEnabled)
- {
- SysLog(NID_LOC, "WPS setting enabled during the LOC_MGR_STATE_PASSIVE_IDLE.");
- int res = location_manager_start(__locMgrStatus.wpsHandler.handle);
- SysTryLog(NID_LOC, res == 0, "Failed to start the WPS location updates in Passive Idle mode.");
- if (res == 0)
- {
- const int LOC_CHECK_TIMER_VALUE = 1;
- __locMgrStatus.locMgrState = LOC_MGR_STATE_WPS_ONLY;
- __locMgrStatus.locMgrSubState = LM_SS_NO_FIX;
- __pLocCheckTimer->Start(LOC_CHECK_TIMER_VALUE * 1000);
- }
- }
- }
- break;
-
- case LOC_MGR_STATE_BOTH_GPS_WPS:
- {
- if (!gpsEnabled)
- {
- SysLog(NID_LOC, "GPS setting turned off during LOC_MGR_STATE_BOTH_GPS_WPS.");
- location_manager_stop(__locMgrStatus.gpsHandler.handle);
- __locMgrStatus.locMgrState = LOC_MGR_STATE_WPS_ONLY;
- }
-
- if (!wpsEnabled)
- {
- SysLog(NID_LOC, "WPS setting turned off during LOC_MGR_STATE_BOTH_GPS_WPS.");
- location_manager_stop(__locMgrStatus.wpsHandler.handle);
- __locMgrStatus.locMgrState = LOC_MGR_STATE_GPS_ONLY;
- }
- }
- break;
-
- case LOC_MGR_STATE_GPS_ONLY:
- {
- if (!gpsEnabled)
- {
- int res = -1;
- if (wpsEnabled)
- {
- SysLog(NID_LOC, "The WPS setting is enabled. So starting WPS now.");
- res = location_manager_start(__locMgrStatus.wpsHandler.handle);
- SysTryLog(NID_LOC, res == 0, "Failed to start the location updates for WPS. Return value is (%d).", res);
- if (res == 0)
- {
- __locMgrStatus.locMgrState = LOC_MGR_STATE_WPS_ONLY;
- }
- }
- if (!wpsEnabled || res != 0)
- {
- __locMgrStatus.locMgrState = LOC_MGR_STATE_PASSIVE_IDLE;
- StopSubStateTimer();
- __pLocCheckTimer->Cancel();
- }
-
- SysLog(NID_LOC, "GPS setting turned off during LOC_MGR_STATE_GPS_ONLY.");
- location_manager_stop(__locMgrStatus.gpsHandler.handle);
- }
- }
- break;
-
- case LOC_MGR_STATE_WPS_ONLY:
- {
- if (!wpsEnabled)
- {
- int res = -1;
- if (gpsEnabled)
- {
- SysLog(NID_LOC, "The GPS setting is enabled. So starting GPS now.");
- res = location_manager_start(__locMgrStatus.gpsHandler.handle);
- SysTryLog(NID_LOC, res == 0, "Failed to start the location updates for GPS. Return value is (%d).", res);
- if (res == 0)
- {
- __locMgrStatus.locMgrState = LOC_MGR_STATE_GPS_ONLY;
- }
- }
- if (!gpsEnabled || res != 0)
- {
- __locMgrStatus.locMgrState = LOC_MGR_STATE_PASSIVE_IDLE;
- StopSubStateTimer();
- __pLocCheckTimer->Cancel();
- }
-
- SysLog(NID_LOC, "WPS setting turned off during LOC_MGR_STATE_WPS_ONLY.");
- location_manager_stop(__locMgrStatus.wpsHandler.handle);
- }
- }
- break;
-
- case LOC_MGR_STATE_IDLE:
- // follow through
- default:
- SysLog(NID_LOC, "GPS setting changed when there is no active location request. (%d),", __locMgrStatus.locMgrState);
- break;
- }
-
- __gpsEnabled = gpsEnabled;
- __wpsEnabled = wpsEnabled;
+ SendUserEvent(REQ_ID_HANDLE_SETTINGS_CHANGE, null);
}
bool
}
__locationUpdater.awakeEnabled = enable;
+ __pLocationManager->KeepLocationUpdateAwake(enable);
+
UiApp* appInstance = UiApp::GetInstance();
if (appInstance == null) // This is service APP. So should be handled now.
{
__regionMonitor.speed = location.GetSpeed() * 0.2777778;
double currentHorAcc = pLocation->GetHorizontalAccuracy();
- double previousHorAcc = __regionMonitor.pLocation->GetHorizontalAccuracy();
-
+ double previousHorAcc = __regionMonitor.pLocation->GetHorizontalAccuracy();
if (Double::IsNaN(previousHorAcc) || (!Double::IsNaN(currentHorAcc) && currentHorAcc <= previousHorAcc) || timeDifference > DEFAULT_THRESHOLD_LOC_VALIDITY_TIME_OUT) // Copy the location only if it is new and accuracy is better than before.
{
_LocationProviderImpl::OnAlarmExpiredEventReceived(void)
{
SysLog(NID_LOC, "Region Monitor Alarm expired event received.");
- result r = ActivateRegionMonitoring(true);
- SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to start the region monitoring. Propogating.", GetErrorMessage(r));
+ if (__regionMonitor.status != LOC_SVC_STATUS_IDLE)
+ {
+ result r = ActivateRegionMonitoring(true);
+ SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to start the region monitoring. Propogating.", GetErrorMessage(r));
+ }
}
void
_LocationImpl::GetInstance(*__regionMonitor.pLocation)->SetValidity(false);
_LocationImpl::GetInstance(*__regionMonitor.pLocation)->SetTimestamp(currentTime);
+ __pLocationManager->KeepLocationUpdateAwake(true);
+ __regionMonitor.tempPaused = false;
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.");
result r = __pLocationManager->RequestStopAlarm(__regionMonitor.reqId);
SysTryLog(NID_LOC, r == E_SUCCESS, "[%s] Failed to stop the alarm. Ignored.", GetErrorMessage(r));
+ if (!__regionMonitor.tempPaused)
+ {
+ __pLocationManager->KeepLocationUpdateAwake(false);
+ __regionMonitor.tempPaused = true;
+ }
r = __regionMonitor.pTimer->Cancel();
SysTryLog(NID_LOC, r == E_SUCCESS, "[%s] Failed to stop the timer. Ignored.", GetErrorMessage(r));
}
}
+ __pLocationManager->KeepLocationUpdateAwake(false);
+ __regionMonitor.tempPaused = true;
result r = __pLocationManager->StopLocationUpdates(__regionMonitor.reqId);
SysTryLog(NID_LOC, r == E_SUCCESS, "Failed to stop the location updates.");