summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnas Nashif <anas.nashif@intel.com>2013-09-24 03:56:45 -0400
committerAnas Nashif <anas.nashif@intel.com>2013-09-24 03:56:45 -0400
commit6f5460ebbb30f00d8f9194fabafa00fd19ef38cf (patch)
tree432964ed876221d47b55153f7632bb56dbc75b60
parent7de6c330687bd2e0499a4a8ba3a3faf998282a2b (diff)
parent9c248fd7ef5df2ef8b6ec8b9e4f8806399ada489 (diff)
downloadlocations-6f5460ebbb30f00d8f9194fabafa00fd19ef38cf.tar.gz
locations-6f5460ebbb30f00d8f9194fabafa00fd19ef38cf.tar.bz2
locations-6f5460ebbb30f00d8f9194fabafa00fd19ef38cf.zip
Merge branch 'tizen_2.2' into tizen
Change-Id: Icb3670c283456a980442d9b0054b0a9629267e77
-rwxr-xr-xCMakeLists.txt3
-rw-r--r--packaging/osp-locations.changes3
-rw-r--r--[-rwxr-xr-x]packaging/osp-locations.spec24
-rw-r--r--src/FLocCoordinates.cpp8
-rw-r--r--src/FLoc_AlarmRequestInfo.h85
-rw-r--r--src/FLoc_Config.h1
-rw-r--r--src/FLoc_ILocProviderEventListener.h7
-rw-r--r--src/FLoc_ILocationManagerListener.h6
-rw-r--r--src/FLoc_LocProviderEventArg.h1
-rw-r--r--src/FLoc_LocationManager.cpp1538
-rw-r--r--src/FLoc_LocationManager.h226
-rw-r--r--src/FLoc_LocationProviderImpl.cpp171
-rw-r--r--src/FLoc_LocationProviderImpl.h44
-rw-r--r--src/FLoc_MathUtils.cpp2
-rw-r--r--src/FLoc_MathUtils.h2
-rw-r--r--src/FLoc_SyncLocationRequestInfo.h38
-rw-r--r--src/FLoc_WaitLoopListener.h68
17 files changed, 1631 insertions, 596 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 881c9cd..088db30 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,12 +6,12 @@ SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/cmake_build_tmp/output)
INCLUDE_DIRECTORIES (
${ROOTSTRAP_ROOT}/usr/include/location
+ ${ROOTSTRAP_ROOT}/usr/include
inc
src
/usr/include/osp
/usr/include/osp/app
/usr/include/osp/base
- /usr/include/osp/io
/usr/include/osp/system
/usr/include/osp/security
)
@@ -48,6 +48,7 @@ TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp -losp-appfw")
TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp -losp-uifw")
TARGET_LINK_LIBRARIES(${this_target} "-lcapi-location-manager")
TARGET_LINK_LIBRARIES(${this_target} "-lpthread")
+TARGET_LINK_LIBRARIES(${this_target} "-lalarm")
SET_TARGET_PROPERTIES(${this_target}
PROPERTIES
diff --git a/packaging/osp-locations.changes b/packaging/osp-locations.changes
new file mode 100644
index 0000000..d21a7c3
--- /dev/null
+++ b/packaging/osp-locations.changes
@@ -0,0 +1,3 @@
+version: 1.2.2.1
+Author: Nandan S R (nandan.sr@samsung.com)
+Change: 1) In region Monitoring, use the core accuracy value, instead of LocationAccuracy enum. 2) During WPS positioning, when accuracy is not met by WPS and GPS is not available, the timer value changed to 10 sec if the requested accuracy is FINEST or TEN_METERS.
diff --git a/packaging/osp-locations.spec b/packaging/osp-locations.spec
index 6667810..f6200d8 100755..100644
--- a/packaging/osp-locations.spec
+++ b/packaging/osp-locations.spec
@@ -1,11 +1,12 @@
Name: osp-locations
-Summary: osp locations library
-Version: 1.2.1.0
+Summary: The Locations library of OSP
+Version: 1.2.2.1
Release: 2
Group: System/Libraries
-License: TO_BE/FILLED_IN
+License: Apache License, Version 2
Source0: %{name}-%{version}.tar.gz
BuildRequires: cmake
+BuildRequires: pkgconfig(alarm-service)
BuildRequires: pkgconfig(capi-location-manager)
BuildRequires: pkgconfig(osp-appfw)
BuildRequires: pkgconfig(osp-uifw)
@@ -16,24 +17,26 @@ BuildRequires: osp-uifw-internal-devel
Requires: osp-appfw
Requires: osp-uifw
+Provides: libosp-locations.so.1
+
%description
-osp locations library
+The Locations library of OSP
%package devel
-Summary: osp locations library (Development)
+Summary: The Locations library of OSP (Development)
Group: TO_BE/FILLED_IN
Requires: %{name} = %{version}-%{release}
%description devel
-osp locations library (DEV)
+The Locations library of OSP (DEV)
%package internal-devel
-Summary: osp locations library (Internal)
+Summary: The Locations library of OSP (Internal Development)
Group: TO_BE/FILLED_IN
Requires: %{name} = %{version}-%{release}
%description internal-devel
-osp locations library (Internal-DEV)
+The Locations library of OSP (Internal-DEV)
%prep
%setup -q
@@ -41,9 +44,9 @@ osp locations library (Internal-DEV)
%build
MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
%ifarch %{ix86}
-CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_SECURE_LOG -D_OSP_X86_ -D_OSP_EMUL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
+CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_SECURE_LOG -D_OSP_X86_ -D_OSP_EMUL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DOBS=1 -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DARCH=x86
%else
-CXXFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -funwind-tables -D_OSP_DEBUG_ -D_SECURE_LOG -D_OSP_ARMEL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
+CXXFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -funwind-tables -D_OSP_DEBUG_ -D_SECURE_LOG -D_OSP_ARMEL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DOBS=1 -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DARCH=arm
%endif
# Call make instruction with smp support
@@ -61,6 +64,7 @@ cp %{_builddir}/%{name}-%{version}/LICENSE.APLv2 %{buildroot}/usr/share/license
%postun -p /sbin/ldconfig
%files
+%manifest osp-location.manifest
/usr/share/license/%{name}
%{_libdir}/osp/*.so*
diff --git a/src/FLocCoordinates.cpp b/src/FLocCoordinates.cpp
index 5ec1284..80ae61e 100644
--- a/src/FLocCoordinates.cpp
+++ b/src/FLocCoordinates.cpp
@@ -129,10 +129,10 @@ result
Coordinates::Set(double latitude, double longitude, double altitude)
{
SysSecureTryReturn(NID_LOC, (MIN_LATITUDE <= latitude) && (latitude <= MAX_LATITUDE),
- E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The latitude(%lf) must be in the range [-90.0, 90.0].", latitude);
+ E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The latitude(%lf) must be in the range [-90.0, 90.0].", latitude);
SysSecureTryReturn(NID_LOC, (MIN_LONGITUDE <= longitude) && (longitude <= MAX_LONGITUDE),
- E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The longitude(%lf) must be in the range [-180.0, 180.0].", longitude);
+ E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The longitude(%lf) must be in the range [-180.0, 180.0].", longitude);
__latitude = latitude;
__longitude = longitude;
@@ -144,7 +144,7 @@ result
Coordinates::SetLatitude(double latitude)
{
SysSecureTryReturn(NID_LOC, (MIN_LATITUDE <= latitude) && (latitude <= MAX_LATITUDE),
- E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The latitude(%lf) must be in the range [-90.0, 90.0].", latitude);
+ E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The latitude(%lf) must be in the range [-90.0, 90.0].", latitude);
__latitude = latitude;
return E_SUCCESS;
}
@@ -153,7 +153,7 @@ result
Coordinates::SetLongitude(double longitude)
{
SysSecureTryReturn(NID_LOC, (MIN_LONGITUDE <= longitude) && (longitude <= MAX_LONGITUDE),
- E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The longitude(%lf) must be in the range [-180.0, 180.0].", longitude);
+ E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The longitude(%lf) must be in the range [-180.0, 180.0].", longitude);
__longitude = longitude;
return E_SUCCESS;
}
diff --git a/src/FLoc_AlarmRequestInfo.h b/src/FLoc_AlarmRequestInfo.h
new file mode 100644
index 0000000..3fe184d
--- /dev/null
+++ b/src/FLoc_AlarmRequestInfo.h
@@ -0,0 +1,85 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file FLoc_AlarmRequestInfo.h
+ * @brief This is the header file for the %_AlarmRequestInfo class.
+ *
+ * This header file contains the declarations of the %_AlarmRequestInfo class member variables.
+ */
+
+#ifndef _FLOC_INTERNAL_ALARM_REQUEST_INFO_H_
+#define _FLOC_INTERNAL_ALARM_REQUEST_INFO_H_
+
+#include <FBaseObject.h>
+#include <FLocTypes.h>
+
+namespace Tizen { namespace Locations
+{
+
+class _ILocationManagerListener;
+
+class _AlarmRequestInfo
+ : public Tizen::Base::Object
+{
+public:
+ _AlarmRequestInfo(int interval, _ILocationManagerListener* pListener, RequestId reqId)
+ : Tizen::Base::Object()
+ , __interval(interval)
+ , __alarmId(-1)
+ , __reqId(reqId)
+ , __pListener(pListener)
+ {
+ }
+
+ ~_AlarmRequestInfo(void)
+ {
+ }
+
+ _AlarmRequestInfo(const _AlarmRequestInfo& rhs)
+ : Tizen::Base::Object()
+ , __interval(rhs.__interval)
+ , __alarmId(rhs.__alarmId)
+ , __reqId(rhs.__reqId)
+ , __pListener(rhs.__pListener)
+ {
+ }
+
+ int GetInterval(void) const {return __interval;}
+
+ RequestId GetRequestId(void) const {return __reqId;}
+
+ void SetAlarmId(int alarmId) {__alarmId = alarmId;}
+
+ _ILocationManagerListener* GetListener(void) const {return __pListener;}
+
+ int GetAlarmId(void) const {return __alarmId;}
+
+private:
+ _AlarmRequestInfo(void);
+
+ _AlarmRequestInfo& operator =(const _AlarmRequestInfo& rhs);
+
+private:
+ int __interval;
+ int __alarmId;
+ RequestId __reqId;
+ _ILocationManagerListener* __pListener;
+
+};
+}}
+#endif //_FLOC_INTERNAL_ALARM_REQUEST_INFO_H_
diff --git a/src/FLoc_Config.h b/src/FLoc_Config.h
index 46c2b7e..00a5adb 100644
--- a/src/FLoc_Config.h
+++ b/src/FLoc_Config.h
@@ -35,6 +35,7 @@ const int DEFAULT_AVG_SPEED = 20; //Take average car speed as 72 km/hr = 20 m/s
const int DEFAULT_REGION_MONITORING_CYCLE_INTERVAL = 5;
const int DEFAULT_DISTANCE_CHECKING_INTERVAL = 10;
const int DEFAULT_THRESHOLD_LOC_VALIDITY_TIME_OUT = 3;
+const int MAX_TIMER_VALUE_DURING_WPS_POSITIONING = 640;
}} // Tizen::Locations
#endif //_FLOC_INTERNAL_CONFIG_H_
diff --git a/src/FLoc_ILocProviderEventListener.h b/src/FLoc_ILocProviderEventListener.h
index 3c0934f..e153b1f 100644
--- a/src/FLoc_ILocProviderEventListener.h
+++ b/src/FLoc_ILocProviderEventListener.h
@@ -77,6 +77,13 @@ public:
*/
virtual void OnRegionMonitoringStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus) = 0;
+ /**
+ * Called when the alarm expiry event is fired from the location provider impl class to break the context. @n
+ *
+ * @since 2.1.1
+ */
+ virtual void OnAlarmExpiredEventReceived(void) = 0;
+
}; //_ILocProviderEventListener
}} // Tizen::Locations
diff --git a/src/FLoc_ILocationManagerListener.h b/src/FLoc_ILocationManagerListener.h
index 93cf389..bf5f2d7 100644
--- a/src/FLoc_ILocationManagerListener.h
+++ b/src/FLoc_ILocationManagerListener.h
@@ -59,6 +59,12 @@ public:
*/
virtual void OnLocationUpdated(RequestId reqId, const Tizen::Locations::Location& location) = 0;
+ /**
+ * Called when the alarm requested by the location provider has expired. @n
+ *
+ * @since 2.1.1
+ */
+ virtual void OnAlarmExpired(void) = 0;
}; //_ILocationManagerListener
}} // Tizen::Locations
diff --git a/src/FLoc_LocProviderEventArg.h b/src/FLoc_LocProviderEventArg.h
index 4468117..42ccc2e 100644
--- a/src/FLoc_LocProviderEventArg.h
+++ b/src/FLoc_LocProviderEventArg.h
@@ -39,6 +39,7 @@ enum _LocProviderEventType
_LOC_PRV_EVENT_SEND_LOC,
_LOC_PRV_EVENT_SEND_LOC_SVC_CB,
_LOC_PRV_EVENT_SEND_MONITOR_SVC_CB,
+ _LOC_PRV_EVENT_SEND_ALARM_EXPIRY,
};
class _LocProviderEventArg
diff --git a/src/FLoc_LocationManager.cpp b/src/FLoc_LocationManager.cpp
index 634c950..2a23afd 100644
--- a/src/FLoc_LocationManager.cpp
+++ b/src/FLoc_LocationManager.cpp
@@ -25,6 +25,7 @@
#include <cassert>
#include <iostream>
#include <pthread.h>
+#include <stdlib.h>
#include <unique_ptr.h>
#include <FBaseColArrayList.h>
#include <FBaseInteger.h>
@@ -32,11 +33,13 @@
#include <FBaseRtMutex.h>
#include <FBaseRtTimer.h>
#include <FBaseRtMonitor.h>
-#include <FBaseRtWaitingLoop.h>
#include <FBaseSysLog.h>
+#include <FBaseUtilMath.h>
#include <FLocCoordinates.h>
-#include <FSysSystemTime.h>
+#include <FSysSettingInfo.h>
#include <FSys_PowerManagerImpl.h>
+#include <FSys_SettingInfoImpl.h>
+#include "FLoc_AlarmRequestInfo.h"
#include "FLoc_Config.h"
#include "FLoc_LocationImpl.h"
#include "FLoc_LocationManager.h"
@@ -44,12 +47,12 @@
#include "FLoc_LocationRequestInfo.h"
#include "FLoc_SyncLocationRequestInfo.h"
+using namespace std;
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
{
@@ -58,14 +61,16 @@ _LocationManager* _LocationManager::__pUniqueInstance = null;
_LocationManager::_LocationManager(void)
: Tizen::Base::Runtime::EventDrivenThread()
- , __locMethodRequested(LOC_METHOD_REQUESTED_NONE)
- , __locationMgrState(LOC_MGR_STATE_IDLE)
+ , __gpsEnabled(false)
+ , __wpsEnabled(false)
, __minRequestedAccuracy(LOC_ACCURACY_INVALID)
, __timerInterval(0)
, __timerTicks(0)
, __pLocRequestInfoList(null)
, __pSyncLocRequestInfoList(null)
- , __pLocUpdateTimer(null)
+ , __pAlarmRequestInfoList(null)
+ , __pLocCallbackTimer(null)
+ , __pLocCheckTimer(null)
, __pInitMonitor(null)
{
}
@@ -81,9 +86,8 @@ _LocationManager::StartLocationUpdates(LocationAccuracy accuracy, int interval,
static RequestId nextLocRequestId = 1;
const int ARRAY_LIST_CAPACITY = 1;
- std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
+ std::unique_ptr< ArrayList, AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
SysTryReturn(NID_LOC, pArgList, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
std::unique_ptr< _LocationRequestInfo > pLocRequestInfo(new (std::nothrow) _LocationRequestInfo(accuracy, interval, pListener, nextLocRequestId));
SysTryReturn(NID_LOC, pLocRequestInfo, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
@@ -91,18 +95,16 @@ _LocationManager::StartLocationUpdates(LocationAccuracy accuracy, int interval,
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Array Construct failed. Propogating.", GetErrorMessage(r));
r = pArgList->Add(*pLocRequestInfo);
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Arraylist addition of an object failed. Propogating", GetErrorMessage(r));
-
pLocRequestInfo.release();
r = SendUserEvent(REQ_ID_START_LOC_UPDATES, pArgList.get());
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to send the user event. Propagating.", GetErrorMessage(r));
+ pArgList.release();
reqId = nextLocRequestId;
nextLocRequestId++;
-
- pArgList.release();
-
SysLog(NID_LOC, "Request ID (%ld) is assigned for the location request with accuracy (%d) and interval (%d).", reqId, accuracy, interval);
+
return E_SUCCESS;
}
@@ -112,9 +114,8 @@ _LocationManager::StopLocationUpdates(RequestId reqId)
SysLog(NID_LOC, "Location update stop requested for request ID (%d).", reqId);
const int ARRAY_LIST_CAPACITY = 1;
- std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
+ std::unique_ptr< ArrayList, AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
SysTryReturn(NID_LOC, pArgList, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
std::unique_ptr< Integer > pReqId(new (std::nothrow) Integer(static_cast< int >(reqId)));
SysTryReturn(NID_LOC, pReqId, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
@@ -122,13 +123,12 @@ _LocationManager::StopLocationUpdates(RequestId reqId)
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Array Construct failed. Propogating.", GetErrorMessage(r));
r = pArgList->Add(*pReqId);
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Arraylist addition of an object failed. Propogating.", GetErrorMessage(r));
-
pReqId.release();
r = SendUserEvent(REQ_ID_STOP_LOC_UPDATES, pArgList.get());
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to send the user event. Propagating.", GetErrorMessage(r));
-
pArgList.release();
+
return E_SUCCESS;
}
@@ -138,7 +138,7 @@ _LocationManager::ChangeUpdateInterval(RequestId reqId, int interval)
SysLog(NID_LOC, "Interval update requested for request ID (%d).", reqId);
const int ARRAY_LIST_CAPACITY = 2;
- std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
+ std::unique_ptr< ArrayList, AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
SysTryReturn(NID_LOC, pArgList, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
result r = pArgList->Construct(ARRAY_LIST_CAPACITY);
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Array Construct failed. Propogating.", GetErrorMessage(r));
@@ -148,7 +148,6 @@ _LocationManager::ChangeUpdateInterval(RequestId reqId, int interval)
r = pArgList->Add(*pReqId);
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Arraylist addition of an object failed. Propogating.", GetErrorMessage(r));
-
pReqId.release();
std::unique_ptr< Integer > pInterval(new (std::nothrow) Integer(interval));
@@ -156,13 +155,12 @@ _LocationManager::ChangeUpdateInterval(RequestId reqId, int interval)
r = pArgList->Add(*pInterval);
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Arraylist addition of an object failed. Propogating.", GetErrorMessage(r));
-
pInterval.release();
r = SendUserEvent(REQ_ID_UPDATE_INTERVAL, pArgList.get());
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to send the user event. Propagating.", GetErrorMessage(r));
-
pArgList.release();
+
return E_SUCCESS;
}
@@ -172,11 +170,14 @@ _LocationManager::RegisterLocationMonitor(_LocationMonitor* pLocationMonitor)
RequestId reqId;
const int ARRAY_LIST_CAPACITY = 1;
+ Location location = GetLastKnownLocation();
+ DateTime lastLocTime = location.GetTimestamp();
+
result r = StartLocationUpdates(pLocationMonitor->GetAccuracy(), 1, null, reqId);
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Error to request location updates.", GetErrorMessage(r));
- std::unique_ptr< _SyncLocationRequestInfo > pSyncLocationRequestInfo(new (std::nothrow) _SyncLocationRequestInfo(pLocationMonitor, reqId));
- std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
+ std::unique_ptr< _SyncLocationRequestInfo > pSyncLocationRequestInfo(new (std::nothrow) _SyncLocationRequestInfo(pLocationMonitor, reqId, lastLocTime));
+ std::unique_ptr< ArrayList, AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
SysTryCatch(NID_LOC, pSyncLocationRequestInfo != null && pArgList != null, , E_OUT_OF_MEMORY,
"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
@@ -189,8 +190,8 @@ _LocationManager::RegisterLocationMonitor(_LocationMonitor* pLocationMonitor)
r = SendUserEvent(REQ_ID_SYNC_LOC_RETRIEVAL, pArgList.get());
SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to send the user event. Propagating.", GetErrorMessage(r));
-
pArgList.release();
+
return E_SUCCESS;
CATCH:
@@ -198,6 +199,54 @@ CATCH:
return r;
}
+result
+_LocationManager::RequestStartAlarm(int interval, _ILocationManagerListener* pListener, RequestId reqId)
+{
+ const int ARRAY_LIST_CAPACITY = 1;
+
+ std::unique_ptr< ArrayList, AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_LOC, pArgList, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ std::unique_ptr< _AlarmRequestInfo > pAlarmRequestInfo(new (std::nothrow) _AlarmRequestInfo(interval, pListener, reqId));
+ SysTryReturn(NID_LOC, pAlarmRequestInfo, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ result r = pArgList->Construct(ARRAY_LIST_CAPACITY);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Array Construct failed. Propogating.", GetErrorMessage(r));
+ r = pArgList->Add(*pAlarmRequestInfo.get());
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Arraylist addition of an object failed. Propogating", GetErrorMessage(r));
+ pAlarmRequestInfo.release();
+
+ r = SendUserEvent(REQ_ID_START_ALARM, pArgList.get());
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to send the user event. Propagating.", GetErrorMessage(r));
+ pArgList.release();
+ SysLog(NID_LOC, "Successfully requested for alarm addition.");
+
+ return E_SUCCESS;
+}
+
+result
+_LocationManager::RequestStopAlarm(RequestId reqId)
+{
+ SysLog(NID_LOC, "Alarm stop requested for request ID (%d).", reqId);
+ const int ARRAY_LIST_CAPACITY = 1;
+
+ std::unique_ptr< ArrayList, AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_LOC, pArgList, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ std::unique_ptr< Integer > pReqId(new (std::nothrow) Integer(static_cast< int >(reqId)));
+ SysTryReturn(NID_LOC, pReqId, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ result r = pArgList->Construct(ARRAY_LIST_CAPACITY);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Array Construct failed. Propogating.", GetErrorMessage(r));
+ r = pArgList->Add(*pReqId);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Arraylist addition of an object failed. Propogating.", GetErrorMessage(r));
+ pReqId.release();
+
+ r = SendUserEvent(REQ_ID_STOP_ALARM, pArgList.get());
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to send the user event. Propagating.", GetErrorMessage(r));
+ pArgList.release();
+
+ return E_SUCCESS;
+}
+
Location
_LocationManager::GetLastKnownLocation(void)
{
@@ -206,7 +255,7 @@ _LocationManager::GetLastKnownLocation(void)
result r = synchronizer.Construct();
SysTryReturn(NID_LOC, r == E_SUCCESS, location, r, "[%s] Propogating.", GetErrorMessage(r));
- std::unique_ptr< Tizen::Base::Collection::ArrayList > pArgList(new (std::nothrow) ArrayList());
+ std::unique_ptr< ArrayList > pArgList(new (std::nothrow) ArrayList());
SysTryReturn(NID_LOC, pArgList, location, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
r = pArgList->Construct();
SysTryReturn(NID_LOC, r == E_SUCCESS, location, r, "[%s] Propogating.", GetErrorMessage(r));
@@ -227,8 +276,8 @@ _LocationManager::GetLastKnownLocation(void)
r = synchronizer.Wait();
SysTryCatch(NID_LOC, r == E_SUCCESS, synchronizer.Exit(), r, "[%s] Propogating", GetErrorMessage(r));
synchronizer.Exit();
- SysLog(NID_LOC, "Last location(validity: %x, method: %ls) retrieved.",
- location.IsValid(), location.GetExtraInfo(L"location_method").GetPointer());
+ SysLog(NID_LOC, "Last location(validity: %x, method: %ls) retrieved.",
+ location.IsValid(), location.GetExtraInfo(L"location_method").GetPointer());
return location;
@@ -240,7 +289,11 @@ CATCH:
LocationAccuracy
_LocationManager::GetAccuracyLevel(double horAcc) const
{
- if (horAcc <= 5.0)
+ if (Double::IsNaN(horAcc))
+ {
+ return LOC_ACCURACY_INVALID;
+ }
+ else if (horAcc <= 5.0)
{
return LOC_ACCURACY_FINEST;
}
@@ -297,9 +350,15 @@ _LocationManager::AddToLocRequestInfoList(const _LocationRequestInfo* pLocReques
result r = _PowerManagerImpl::PowerControl(1, 1);
SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to keep the CPU in awake state.", GetErrorMessage(r));
}
- SysLog(NID_LOC, "Total count of request info is (%d).", __pLocRequestInfoList->GetCount());
- RestartLocationUpdates();
- RestartUpdateTimer();
+ const int FIRST_REQUEST = 1;
+ int count = __pLocRequestInfoList->GetCount();
+ SysLog(NID_LOC, "Total count of request info is (%d).", count);
+ if (count == FIRST_REQUEST)
+ {
+ InitiateLocationRequest();
+ }
+ UpdateMinimunAccuracy();
+ RestartCallbackTimer();
}
void
@@ -322,51 +381,25 @@ _LocationManager::RemoveFromLocRequestInfoList(RequestId reqId)
{
_PowerManagerImpl::PowerControl(1, 0);
- __pLocUpdateTimer->Cancel();
- location_manager_stop(__gpsHandler.handle);
- location_manager_stop(__wpsHandler.handle);
-
Reset();
+ location_manager_stop(__locMgrStatus.gpsHandler.handle);
+ location_manager_stop(__locMgrStatus.wpsHandler.handle);
}
else
{
- RestartLocationUpdates();
- RestartUpdateTimer();
+ UpdateMinimunAccuracy();
+ RestartCallbackTimer();
}
}
void
_LocationManager::AddToSyncLocationRequestInfoList(_SyncLocationRequestInfo& syncLocRequestInfo)
{
- static bool hasRetrievalStarted = false;
+ result r = syncLocRequestInfo.StartTimer(*this);
+ SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to start the sync timer.", GetErrorMessage(r));
- result r = __pSyncLocRequestInfoList->Add(syncLocRequestInfo);
+ r = __pSyncLocRequestInfoList->Add(syncLocRequestInfo);
SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to add the sync request into the list.", GetErrorMessage(r));
-
- if (hasRetrievalStarted == true)
- {
- SysLog(NID_LOC, "The retrieval under process.");
- return;
- }
- while (__pSyncLocRequestInfoList->GetCount() != 0)
- {
- hasRetrievalStarted = true;
- const int WAIT_TIME = 1000;
- WaitingLoop::GetInstance()->Wait(WAIT_TIME);
-
- int count = __pSyncLocRequestInfoList->GetCount();
- for (int i = 0; i < count; i++)
- {
- _SyncLocationRequestInfo* pSyncLocRequestInfo = static_cast< _SyncLocationRequestInfo* >(__pSyncLocRequestInfoList->GetAt(i));
- if (pSyncLocRequestInfo != null)
- {
- SysLog(NID_LOC, "Handle the sync location request with request ID (%ld)", pSyncLocRequestInfo->GetRequestId());
-
- HandleSyncRetrievalTimerExpiry(*pSyncLocRequestInfo);
- }
- }
- }
- hasRetrievalStarted = false;
return;
CATCH:
@@ -383,77 +416,119 @@ _LocationManager::RemoveSyncLocRetrievalRequest(_SyncLocationRequestInfo& syncLo
}
void
-_LocationManager::RestartLocationUpdates(void)
+_LocationManager::AddToAlarmRequestInfoList(_AlarmRequestInfo& alarmRequestInfo)
{
- int count = __pLocRequestInfoList->GetCount();
- int result = 0;
- bool isAccuracyChanged = false;
+ alarm_id_t alarmId;
+
+ int res = alarmmgr_add_alarm_withcb(ALARM_TYPE_DEFAULT, alarmRequestInfo.GetInterval(), 0, AlarmExpiryCallback, this, &alarmId);
+ SysTryReturnVoidResult(NID_LOC, res == ALARMMGR_RESULT_SUCCESS, E_SYSTEM, "Failed to add the alarm for next cycle.");
+ alarmRequestInfo.SetAlarmId(alarmId);
+ SysLog(NID_LOC, "The alarm ID (%d) is set to the alarm request.", alarmId);
+
+ std::unique_ptr< _AlarmRequestInfo > pNewAlarmRequestInfo(new (std::nothrow) _AlarmRequestInfo(alarmRequestInfo));
+ SysTryReturnVoidResult(NID_LOC, pNewAlarmRequestInfo, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ result r = __pAlarmRequestInfoList->Add(*pNewAlarmRequestInfo.get());
+ SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] Failed to add the alarm request into list.");
+ pNewAlarmRequestInfo.release();
+
+ return;
+}
+
+void
+_LocationManager::RemoveFromAlarmRequestInfoList(RequestId reqId)
+{
+ int count = __pAlarmRequestInfoList->GetCount();
+ SysLog(NID_LOC, "Total count of Alarm Request pending is (%d).", count);
+ for (int i = 0; i < count; i++)
+ {
+ const _AlarmRequestInfo* pAlarmRequestInfo = static_cast< const _AlarmRequestInfo* >(__pAlarmRequestInfoList->GetAt(i));
+ if (reqId == pAlarmRequestInfo->GetRequestId())
+ {
+ int res = alarmmgr_remove_alarm(pAlarmRequestInfo->GetAlarmId());
+ SysTryLog(NID_LOC, res == ALARMMGR_RESULT_SUCCESS, "Failed to remove the Alarm.");
+ SysLog(NID_LOC, "The alarm with request Id (%d) and Alarm Id (%d) will be removed.", reqId, pAlarmRequestInfo->GetAlarmId());
+ __pAlarmRequestInfoList->RemoveAt(i);
+ break;
+ }
+ }
+ return;
+}
+void
+_LocationManager::UpdateMinimunAccuracy(void)
+{
+ int count = __pLocRequestInfoList->GetCount();
for (int i = 0; i < count; i++)
{
const _LocationRequestInfo* pLocRequestInfo = static_cast< const _LocationRequestInfo* >(__pLocRequestInfoList->GetAt(i));
if (__minRequestedAccuracy > pLocRequestInfo->GetAccuracy() || __minRequestedAccuracy == LOC_ACCURACY_INVALID)
{
__minRequestedAccuracy = pLocRequestInfo->GetAccuracy();
- isAccuracyChanged = true;
}
}
- if (!isAccuracyChanged)
+}
+
+void
+_LocationManager::InitiateLocationRequest(void)
+{
+ if (__locMgrStatus.locMgrState != LOC_MGR_STATE_IDLE)
{
+ SysLog(NID_LOC, "Location manager already running.");
return;
}
- SysLog(NID_LOC, "Location updates are restarted and new minimum requested Accuracy is (%d).", __minRequestedAccuracy);
- switch (__locMethodRequested)
- {
- case LOC_METHOD_REQUESTED_NONE:
- {
- SysLog(NID_LOC, "None of the methods running. Start all");
+ SysLog(NID_LOC, "None of the methods running. Start all");
+ bool gpsEnabled = false;
+ bool wpsEnabled = false;
+ int resultGps = -1;
+ int resultWps = -1;
+ const int LOC_CHECK_TIMER_VALUE = 1000;
- result = location_manager_start(__gpsHandler.handle);
- SysTryLog(NID_LOC, result == 0, "Failed to start the location updates for GPS.");
+ result gps = _SettingInfoImpl::GetValue(L"http://tizen.org/setting/location.gps", gpsEnabled);
+ result wps = _SettingInfoImpl::GetValue(L"http://tizen.org/setting/location.wps", wpsEnabled);
+ __gpsEnabled = gpsEnabled;
+ __wpsEnabled = wpsEnabled;
- result = location_manager_start(__wpsHandler.handle);
- SysTryLog(NID_LOC, result == 0, "Failed to start the location updates for WPS.");
+ if (gps == E_SUCCESS && __gpsEnabled)
+ {
+ resultGps = location_manager_start(__locMgrStatus.gpsHandler.handle);
+ SysTryLog(NID_LOC, resultGps == 0, "Failed to start the core GPS location provider with result (%d).", resultGps);
}
- break;
-
- case LOC_METHOD_REQUESTED_GPS:
+ if (wps == E_SUCCESS && __wpsEnabled)
{
- SysLog(NID_LOC, "GPS Running. Start WPS.");
-
- result = location_manager_start(__wpsHandler.handle);
- SysTryLog(NID_LOC, result == 0, "Failed to start the location updates for WPS.");
+ resultWps = location_manager_start(__locMgrStatus.wpsHandler.handle);
+ SysTryLog(NID_LOC, resultWps == 0, "Failed to start the core WPS location provider with result (%d).", resultWps);
}
- break;
- case LOC_METHOD_REQUESTED_WPS:
+ if (resultGps == 0 && resultWps == 0)
{
- SysLog(NID_LOC, "WPS Running. Start GPS.");
-
- result = location_manager_start(__gpsHandler.handle);
- SysTryLog(NID_LOC, result == 0, "Failed to start the location updates for GPS.");
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_BOTH_GPS_WPS;
}
- break;
-
- case LOC_METHOD_REQUESTED_ALL:
+ else if (resultGps == 0 && resultWps != 0)
{
- SysLog(NID_LOC, "All the providers are already started.");
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_GPS_ONLY;
}
- break;
+ else if (resultGps != 0 && resultWps == 0)
+ {
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_WPS_ONLY;
}
-
- __locationMgrState = LOC_MGR_STATE_FAST_SENSING;
- __locMethodRequested = LOC_METHOD_REQUESTED_ALL;
+ else
+ {
+ SysLog(NID_LOC, "Failed to start both the location providers.");
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_PASSIVE_IDLE;
+ return;
+ }
+ __locMgrStatus.locMgrSubState = LM_SS_NO_FIX;
+ __pLocCheckTimer->Start(LOC_CHECK_TIMER_VALUE);
}
void
-_LocationManager::RestartUpdateTimer(void)
+_LocationManager::RestartCallbackTimer(void)
{
int gcd = 1;
int count = __pLocRequestInfoList->GetCount();
- __pLocUpdateTimer->Cancel();
+ __pLocCallbackTimer->Cancel();
if (count > 0)
{
@@ -477,12 +552,9 @@ _LocationManager::RestartUpdateTimer(void)
__timerInterval = gcd;
__timerTicks = 0;
- SysLog(NID_LOC, "Updated Timer interval is (%d).", __timerInterval);
- result r = __pLocUpdateTimer->Start(__timerInterval * 1000);
- if (IsFailed(r))
- {
- SysLog(NID_LOC, "Failed to start the Location update timer.");
- }
+ result r = __pLocCallbackTimer->Start(__timerInterval * 1000);
+ SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to start the location callback timer.", GetErrorMessage(r));
+ SysLog(NID_LOC, "The callback timer interval successfully updated to (%d).", __timerInterval);
}
void
@@ -491,20 +563,21 @@ _LocationManager::HandleSyncRetrievalTimerExpiry(_SyncLocationRequestInfo& syncL
LocationAccuracy accuracy = LOC_ACCURACY_INVALID;
DateTime timestamp = DateTime::GetMinValue();
- Location location = GetRecentLocationAvailable();
+ const Location* pBestLoc = FindBestLocation();
+ SysTryReturnVoidResult(NID_LOC, pBestLoc != null, E_INVALID_DATA, "[E_INVALID_DATA] Location not available.");
SysLog(NID_LOC, "Location(timestamp: %ls, validity: %x, accuracy: %f) is retrieved.",
- location.GetTimestamp().ToString().GetPointer(), location.IsValid(), location.GetHorizontalAccuracy());
- if (location.IsValid())
+ pBestLoc->GetTimestamp().ToString().GetPointer(), pBestLoc->IsValid(), pBestLoc->GetHorizontalAccuracy());
+ if (pBestLoc->IsValid())
{
- accuracy = GetAccuracyLevel(location.GetHorizontalAccuracy());
- timestamp = location.GetTimestamp();
+ accuracy = GetAccuracyLevel(pBestLoc->GetHorizontalAccuracy());
+ timestamp = pBestLoc->GetTimestamp();
}
bool inTime = syncLocRequestInfo.IsInTime(timestamp);
bool accurate = syncLocRequestInfo.IsAccuracySatisfying(accuracy);
if (inTime && accurate)
{
- unique_ptr< Location > pLocation(new (std::nothrow) Location(location));
+ unique_ptr< Location > pLocation(new (std::nothrow) Location(*pBestLoc));
SysTryCatchLabel(NID_LOC, pLocation != null, , NOTIFY, E_OUT_OF_MEMORY,
"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
syncLocRequestInfo.GetLocationMonitor()->SetLocation(pLocation.get());
@@ -516,7 +589,7 @@ _LocationManager::HandleSyncRetrievalTimerExpiry(_SyncLocationRequestInfo& syncL
{
if (inTime)
{
- unique_ptr< Location > pLocation(new (std::nothrow) Location(location));
+ unique_ptr< Location > pLocation(new (std::nothrow) Location(*pBestLoc));
SysTryCatchLabel(NID_LOC, pLocation != null, , NOTIFY, E_OUT_OF_MEMORY,
"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
syncLocRequestInfo.GetLocationMonitor()->SetLocation(pLocation.get());
@@ -532,7 +605,7 @@ _LocationManager::HandleSyncRetrievalTimerExpiry(_SyncLocationRequestInfo& syncL
}
SysLog(NID_LOC, "Wait for next location(Tick: %d).", syncLocRequestInfo.GetTickCount());
- syncLocRequestInfo.IncrementTickCount();
+ syncLocRequestInfo.StartTimer(*this);
return;
NOTIFY:
@@ -540,123 +613,11 @@ NOTIFY:
RemoveSyncLocRetrievalRequest(syncLocRequestInfo);
}
-result
-_LocationManager::SetLocationInformation(double latitude, double longitude, double altitude, time_t timestamp, location_method_e locMethod, Location* pLocation)
-{
- SysSecureLog(NID_LOC, "Location Information is: Latitude (%lf), Longitude (%lf), Altitude (%lf), TimeStamp (%ld), Location method (%d)", latitude, longitude, altitude, timestamp, locMethod);
-
- int res = -1;
- LocationAccuracy requiredAcc;
- int rangeValue = 0;
-
- //Accuracy details.
- location_accuracy_level_e accLevel = LOCATIONS_ACCURACY_NONE;
- double horAcc = Tizen::Locations::NaN;
- double verAcc = Tizen::Locations::NaN;
-
- //Velocity details.
- double climb = Tizen::Locations::NaN;
- double direction = Tizen::Locations::NaN;
- double speed = Tizen::Locations::NaN;
- time_t time_stamp = 0;
-
- RequestId requestId;
- Location locationData = _LocationImpl::GetLocationInstance();
- _LocationImpl* pLocDataImpl = _LocationImpl::GetInstance(locationData);
-
- switch (locMethod)
- {
- case LOCATIONS_METHOD_GPS:
- {
- res = location_manager_get_accuracy(__gpsHandler.handle, &accLevel, &horAcc, &verAcc);
- SysLog(NID_LOC, "Get Accuracy: Result (%d), Horizontal Acc (%lf), Vertical Acc (%lf)", res, horAcc, verAcc);
- SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM, "Invalid accuracy values from Native Location Provider.");
-
- res = location_manager_get_velocity(__gpsHandler.handle, &climb, &direction, &speed, &time_stamp);
- SysLog(NID_LOC, "Get Velocity: Result (%d), Climb (%lf), Direction (%lf), Speed (%lf), Time stamp (%ld)", res, climb, direction, speed, time_stamp);
- SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM, "Invalid accuracy values from Native Location Provider.");
-
- pLocDataImpl->SetExtraInfo(L"location_method", L"gps");
- requestId = REQ_ID_SUSTAIN_GPS;
- }
- break;
-
- case LOCATIONS_METHOD_WPS:
- {
- res = location_manager_get_accuracy(__wpsHandler.handle, &accLevel, &horAcc, &verAcc);
- SysLog(NID_LOC, "Get Accuracy: Result (%d), Horizontal Acc (%lf), Vertical Acc (%lf)", res, horAcc, verAcc);
- SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM, "Invalid accuracy values from Native Location Provider.");
-
- res = location_manager_get_velocity(__wpsHandler.handle, &climb, &direction, &speed, &time_stamp);
- SysTryLog(NID_LOC, res == 0, "Get Velocity: Result (%d), Climb (%lf), Direction (%lf), Speed (%lf), Time stamp (%ld)", res, climb, direction, speed, time_stamp);
-
- pLocDataImpl->SetExtraInfo(L"location_method", L"network");
- requestId = REQ_ID_SUSTAIN_WPS;
- }
- break;
-
- default:
- SysTryReturn(NID_LOC, false, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The location method is not valid");
- }
-
- Coordinates coordinates;
- coordinates.Set(latitude, longitude, altitude);
- pLocDataImpl->SetCoordinates(coordinates);
- pLocDataImpl->SetHorizontalAccuracy(horAcc);
- pLocDataImpl->SetVerticalAccuracy(verAcc);
- pLocDataImpl->SetTimestamp((long long) timestamp * 1000);
- pLocDataImpl->SetCourse(direction);
- pLocDataImpl->SetSpeed(speed);
- pLocDataImpl->SetValidity(true);
- *pLocation = locationData;
-
- requiredAcc = __minRequestedAccuracy;
- switch (requiredAcc)
- {
- case LOC_ACCURACY_FINEST:
- rangeValue = ACCURACY_FINEST;
- break;
-
- case LOC_ACCURACY_TEN_METERS:
- rangeValue = ACCURACY_TEN_MTRS;
- break;
-
- case LOC_ACCURACY_HUNDRED_METERS:
- rangeValue = ACCURACY_HUNDRED_MTRS;
- break;
-
- case LOC_ACCURACY_ONE_KILOMETER:
- rangeValue = ACCURACY_ONE_KILOMETER;
- break;
-
- case LOC_ACCURACY_ANY:
- rangeValue = ACCURACY_ANY;
- break;
-
- case LOC_ACCURACY_INVALID:
- // follow through
- default:
- SysAssertf(false, "The Accuracy value is not defined.");
- }
-
- if (__locationMgrState == LOC_MGR_STATE_FAST_SENSING && horAcc <= rangeValue)
- {
- SysLog(NID_LOC, "State is LOC_MGR_STATE_FAST_SENSING and accuracy is within range. RequestId is (%d)", requestId);
- __locationMgrState = LOC_MGR_STATE_FAST_SENSING_SETTLED;
- SendUserEvent(requestId, null);
- }
- else if (__locationMgrState == LOC_MGR_STATE_FAST_SENSING_SETTLED && horAcc > rangeValue)
- {
- SysLog(NID_LOC, "State is LOC_MGR_STATE_FAST_SENSING_SETTLED and accuracy is out of range. Restart location updates.");
- SendUserEvent(REQ_ID_RESTART_LOC_UPDATES, null);
- }
- return E_SUCCESS;
-}
-
void
_LocationManager::SendLocationCallbacks(void)
{
const Location* pBestLocation = FindBestLocation();
+ SysTryReturnVoidResult(NID_LOC, pBestLocation != null, E_INVALID_DATA, "[E_INVALID_DATA] Location not available.");
SysLog(NID_LOC, "Send location(validity: %x) through the callback.", pBestLocation->IsValid());
unique_ptr< Location > pLocation(new (std::nothrow) Location(*pBestLocation));
@@ -676,8 +637,11 @@ _LocationManager::SendLocationCallbacks(void)
void
_LocationManager::Reset(void)
{
- __locMethodRequested = LOC_METHOD_REQUESTED_NONE;
- __locationMgrState = LOC_MGR_STATE_IDLE;
+ StopSubStateTimer();
+ __pLocCallbackTimer->Cancel();
+ __pLocCheckTimer->Cancel();
+ __locMgrStatus.locMgrSubState = LM_SS_IDLE;
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_IDLE;
__minRequestedAccuracy = LOC_ACCURACY_INVALID;
__timerInterval = 0;
__timerTicks = 0;
@@ -708,14 +672,14 @@ _LocationManager::GetLastKnownLocation(location_method_e nativeLocMethod)
{
case LOCATIONS_METHOD_GPS:
{
- nativeHandle = __gpsHandler.handle;
+ nativeHandle = __locMgrStatus.gpsHandler.handle;
locationMethod = L"gps";
}
break;
case LOCATIONS_METHOD_WPS:
{
- nativeHandle = __wpsHandler.handle;
+ nativeHandle = __locMgrStatus.wpsHandler.handle;
locationMethod = L"network";
}
break;
@@ -738,7 +702,7 @@ _LocationManager::GetLastKnownLocation(location_method_e nativeLocMethod)
int res = location_manager_get_last_position(nativeHandle, &altitude, &latitude, &longitude, &timestampPosition);
SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to fetch last position from nativeHandle(%x).", nativeHandle);
SysSecureLog(NID_LOC, "Last position(latitude: %lf, longitude: %lf, altitude: %lf, timestamp: %ld",
- latitude, longitude, altitude, timestampPosition);
+ latitude, longitude, altitude, timestampPosition);
Coordinates coord;
coord.Set(latitude, longitude, altitude);
@@ -751,6 +715,8 @@ _LocationManager::GetLastKnownLocation(location_method_e nativeLocMethod)
if (res == 0)
{
SysLog(NID_LOC, "Last accuracy(horAcc: %lf, vAcc: %lf, level: %x)", horAcc, verAcc, level);
+ horAcc = ConvertToNativeFormat(horAcc);
+ verAcc = ConvertToNativeFormat(verAcc);
pLocationImpl->SetHorizontalAccuracy(horAcc);
pLocationImpl->SetVerticalAccuracy(verAcc);
}
@@ -762,8 +728,9 @@ _LocationManager::GetLastKnownLocation(location_method_e nativeLocMethod)
res = location_manager_get_last_velocity(nativeHandle, &climb, &direction, &speed, &timestampVelocity);
if (res == 0)
{
- SysLog(NID_LOC, "Last velocity(climb: %lf, direction: %lf, speed: %lf, timestamp: %ld)",
- climb, direction, speed, timestampVelocity);
+ SysLog(NID_LOC, "Last velocity(climb: %lf, direction: %lf, speed: %lf, timestamp: %ld)", climb, direction, speed, timestampVelocity);
+ direction = ConvertToNativeFormat(direction);
+ speed = ConvertToNativeFormat(speed);
pLocationImpl->SetCourse(direction);
pLocationImpl->SetSpeed(speed);
}
@@ -777,17 +744,17 @@ _LocationManager::GetLastKnownLocation(location_method_e nativeLocMethod)
res = gps_status_get_last_satellite(nativeHandle, &satUsedCount, &satViewCount, &timestampSatellite);
if (res == 0)
{
- long timeDiff = abs(timestampPosition - timestampSatellite);
+ long timeDiff = Math::Abs(timestampPosition - timestampSatellite);
res = gps_status_foreach_last_satellites_in_view(nativeHandle, SatelliteInfoUpdated, &satInfo);
SysLog(NID_LOC, "Last satellite(foreachResult: %d, inUse: %d, inView: %d, timestamp: %ld, timeDiff: %ld)",
- res, satUsedCount, satViewCount, timestampSatellite, timeDiff);
+ res, satUsedCount, satViewCount, timestampSatellite, timeDiff);
satInfo.Trim();
SysLog(NID_LOC, "Last satellite(info: %ls)", satInfo.GetPointer());
pLocationImpl->SetExtraInfo(L"satellite", satInfo);
}
}
- pLocationImpl->SetTimestamp(((long long)timestampPosition) * 1000); // in milliseconds
+ pLocationImpl->SetTimestamp(((long long) timestampPosition) * 1000); // in milliseconds
pLocationImpl->SetValidity(true);
pLocationImpl->SetExtraInfo(L"location_method", locationMethod);
}
@@ -828,8 +795,8 @@ _LocationManager::GetRecentLocationAvailable(void)
}
}
-void
-_LocationManager::UpdateLocRequestInfoList(RequestId reqId, int interval)
+void
+_LocationManager::UpdateLocRequestInterval(RequestId reqId, int interval)
{
int count = __pLocRequestInfoList->GetCount();
@@ -839,7 +806,7 @@ _LocationManager::UpdateLocRequestInfoList(RequestId reqId, int interval)
if (reqId == pLocRequestInfo->GetRequestId())
{
pLocRequestInfo->SetInterval(interval);
- RestartUpdateTimer();
+ RestartCallbackTimer();
break;
}
}
@@ -848,89 +815,94 @@ _LocationManager::UpdateLocRequestInfoList(RequestId reqId, int interval)
const Location*
_LocationManager::FindBestLocation(void)
{
- switch (__locMethodRequested)
+ switch (__locMgrStatus.locMgrState)
{
- case LOC_METHOD_REQUESTED_GPS:
+ case LOC_MGR_STATE_GPS_ONLY:
{
SysLog(NID_LOC, "GPS location provider running.");
- return __gpsHandler.pLocation.get();
+ return __locMgrStatus.gpsHandler.pLocation.get();
}
break;
- case LOC_METHOD_REQUESTED_WPS:
+ case LOC_MGR_STATE_WPS_ONLY:
{
SysLog(NID_LOC, "WPS location provider running.");
- return __wpsHandler.pLocation.get();
+ return __locMgrStatus.wpsHandler.pLocation.get();
}
break;
- case LOC_METHOD_REQUESTED_ALL:
+ case LOC_MGR_STATE_PASSIVE_IDLE: //Give back the available location in case of Passive location because the location provider takes care of the location and send Denied.
+ // follow through
+ case LOC_MGR_STATE_BOTH_GPS_WPS:
{
SysLog(NID_LOC, "All the methods are running. Get the best location among all the providers.");
long long gpsTimestamp = 0;
long long wpsTimestamp = 0;
- if (__gpsHandler.pLocation->IsValid())
+ if (__locMgrStatus.gpsHandler.pLocation->IsValid())
{
- gpsTimestamp = _LocationImpl::GetInstance(*__gpsHandler.pLocation)->GetTimestampInMs();
+ gpsTimestamp = _LocationImpl::GetInstance(*__locMgrStatus.gpsHandler.pLocation)->GetTimestampInMs();
}
- if (__wpsHandler.pLocation->IsValid())
+ if (__locMgrStatus.wpsHandler.pLocation->IsValid())
{
- wpsTimestamp = _LocationImpl::GetInstance(*__wpsHandler.pLocation)->GetTimestampInMs();
+ wpsTimestamp = _LocationImpl::GetInstance(*__locMgrStatus.wpsHandler.pLocation)->GetTimestampInMs();
}
SysLog(NID_LOC, "Compare timestamp(gps: %lld, wps: %lld) of different locations.", gpsTimestamp, wpsTimestamp);
if (gpsTimestamp > wpsTimestamp)
{
SysLog(NID_LOC, "GPS time stamp is greater than WPS.");
- return __gpsHandler.pLocation.get();
+ return __locMgrStatus.gpsHandler.pLocation.get();
}
else if (wpsTimestamp > gpsTimestamp)
{
SysLog(NID_LOC, "WPS time stamp is greater than GPS.");
- return __wpsHandler.pLocation.get();
+ return __locMgrStatus.wpsHandler.pLocation.get();
}
else if (gpsTimestamp == wpsTimestamp)
{
- if (__gpsHandler.pLocation->GetHorizontalAccuracy() <= __wpsHandler.pLocation->GetHorizontalAccuracy())
+ double gpsAccuracy = __locMgrStatus.gpsHandler.pLocation->GetHorizontalAccuracy();
+ double wpsAccuracy = __locMgrStatus.wpsHandler.pLocation->GetHorizontalAccuracy();
+ if ((gpsAccuracy <= wpsAccuracy) || Double::IsNaN(wpsAccuracy))
{
SysLog(NID_LOC, "GPS time stamp is equal to WPS and GPS accuracy is better than WPS.");
- return __gpsHandler.pLocation.get();
+ return __locMgrStatus.gpsHandler.pLocation.get();
}
else
{
- SysLog(NID_LOC, "WPS time stamp is equal to GPS but WPS accuracy is better than GPS.");
- return __wpsHandler.pLocation.get();
+ SysLog(NID_LOC, "WPS time stamp is equal to GPS and WPS accuracy is better than GPS.");
+ return __locMgrStatus.wpsHandler.pLocation.get();
}
}
}
break;
- case LOC_METHOD_REQUESTED_NONE:
+ case LOC_MGR_STATE_IDLE:
// follow through
default:
SysLog(NID_LOC, "Location updates not running.");
return null;
}
- SysLog(NID_LOC, "Returning null as none of the conditions are satsfied.");
+ SysLog(NID_LOC, "Returning null as none of the conditions are satisfied.");
return null;
}
result
_LocationManager::GetLocation(location_method_e nativeLocMethod)
{
- const int MAX_VALID_TIME_DIFFERENCE = 2000;
- double altitude = 0.0;
- double latitude = 0.0;
- double longitude = 0.0;
- time_t timestamp;
+ location_accuracy_level_e accuracy_level;
int res = -1;
- int satellitesInViewCount = 0;
- int satellitesInUseCount = 0;
- time_t timestampSatellite = 0;
- String satInfo = L"";
+ time_t timestamp = 0;
long long timeDiff = 0;
+ double altitude = NaN;
+ double latitude = NaN;
+ double longitude = NaN;
+ double climb = NaN;
+ double direction = NaN;
+ double speed = NaN;
+ double horizontal_acc = NaN;
+ double vertical_acc = NaN;
location_manager_h nativeHandle = null;
Location* pLocation = null;
@@ -938,15 +910,15 @@ _LocationManager::GetLocation(location_method_e nativeLocMethod)
{
case LOCATIONS_METHOD_GPS:
{
- nativeHandle = __gpsHandler.handle;
- pLocation = __gpsHandler.pLocation.get();
+ nativeHandle = __locMgrStatus.gpsHandler.handle;
+ pLocation = __locMgrStatus.gpsHandler.pLocation.get();
}
break;
case LOCATIONS_METHOD_WPS:
{
- nativeHandle = __wpsHandler.handle;
- pLocation = __wpsHandler.pLocation.get();
+ nativeHandle = __locMgrStatus.wpsHandler.handle;
+ pLocation = __locMgrStatus.wpsHandler.pLocation.get();
}
break;
@@ -954,38 +926,702 @@ _LocationManager::GetLocation(location_method_e nativeLocMethod)
break;
}
- res = location_manager_get_position(nativeHandle, &altitude, &latitude, &longitude, &timestamp);
- SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM, "Failed to obtain the natvie location information for the method (%x)", nativeLocMethod);
+ res = location_manager_get_location(nativeHandle, &altitude, &latitude, &longitude, &climb, &direction, &speed, &accuracy_level, &horizontal_acc, &vertical_acc, &timestamp);
+ SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM, "Failed to obtain the natvie location information for the method (%x)", nativeLocMethod);
+ SysSecureLog(NID_LOC, "Location details: Lat(%lf), Long(%lf), Alt(%lf), Climb (%lf), Direction (%lf), Speed (%lf), Accuracy Level(%d), HAcc (%lf), VAcc (%lf), timestamp (%ld).",
+ latitude, longitude, altitude, climb, direction, speed, accuracy_level, horizontal_acc, vertical_acc, timestamp);
if (res == 0)
{
- result r = SetLocationInformation(latitude, longitude, altitude, timestamp, nativeLocMethod, pLocation);
- if (r != E_SUCCESS)
- {
- SysLog(NID_LOC, "Failed to set the location information");
- }
+ Location locationData = _LocationImpl::GetLocationInstance();
+ _LocationImpl* pLocDataImpl = _LocationImpl::GetInstance(locationData);
+
+ horizontal_acc = ConvertToNativeFormat(horizontal_acc);
+ vertical_acc = ConvertToNativeFormat(vertical_acc);
+ Coordinates coordinates;
+ coordinates.Set(latitude, longitude, altitude);
+ pLocDataImpl->SetCoordinates(coordinates);
+ pLocDataImpl->SetHorizontalAccuracy(horizontal_acc);
+ pLocDataImpl->SetVerticalAccuracy(vertical_acc);
+ pLocDataImpl->SetTimestamp((long long) timestamp * 1000);
+ pLocDataImpl->SetCourse(direction);
+ pLocDataImpl->SetSpeed(speed);
+ pLocDataImpl->SetValidity(true);
if (nativeLocMethod == LOCATIONS_METHOD_GPS)
{
- res = gps_status_get_satellite(__gpsHandler.handle, &satellitesInUseCount, &satellitesInViewCount, &timestampSatellite);
+ const int MAX_VALID_TIME_DIFFERENCE = 2000;
+ int satellitesInViewCount = 0;
+ int satellitesInUseCount = 0;
+ time_t timestampSatellite = 0;
+ String satInfo = L"";
- timeDiff = abs(timestamp - timestampSatellite);
+ __locMgrStatus.gpsFailCount = 0;
+ pLocDataImpl->SetExtraInfo(L"location_method", L"gps");
+ res = gps_status_get_satellite(nativeHandle, &satellitesInUseCount, &satellitesInViewCount, &timestampSatellite);
+
+ timeDiff = Math::Abs(timestamp - timestampSatellite);
timeDiff = timeDiff * 1000;
SysLog(NID_LOC, "Result (%d), Satellites in Use (%d), Satellites in View (%d), Time stamp (%ld), Time Difference (Loc and Sat) (%ld)",
res, satellitesInUseCount, satellitesInViewCount, timestampSatellite, timeDiff);
if (res == 0 && timeDiff <= MAX_VALID_TIME_DIFFERENCE)
{
- res = gps_status_foreach_satellites_in_view(__gpsHandler.handle, SatelliteInfoUpdated, &satInfo);
+ res = gps_status_foreach_satellites_in_view(__locMgrStatus.gpsHandler.handle, SatelliteInfoUpdated, &satInfo);
}
satInfo.Trim();
SysLog(NID_LOC, "Result of get satellite is (%d) and satelliteInfo string representation is (%ls)", res, satInfo.GetPointer());
- _LocationImpl::GetInstance(*__gpsHandler.pLocation.get())->SetExtraInfo(L"satellite", satInfo);
+ pLocDataImpl->SetExtraInfo(L"satellite", satInfo);
+ }
+ else if (nativeLocMethod == LOCATIONS_METHOD_WPS)
+ {
+ pLocDataImpl->SetExtraInfo(L"location_method", L"network");
}
+ *pLocation = locationData;
}
return E_SUCCESS;
}
+void
+_LocationManager::HandleBothGpsWpsState(void)
+{
+ bool isGpsAccMet = false;
+ bool isWpsAccMet = false;
+ bool isGpsTimeUpdated = false;
+ bool isWpsTimeUpdated = false;
+
+ IsGpsLocationUpdated(isGpsTimeUpdated, isGpsAccMet);
+ IsWpsLocationUpdated(isWpsTimeUpdated, isWpsAccMet);
+
+ if (isWpsAccMet)
+ {
+ StopSubStateTimer();
+ SysLog(NID_LOC, "WPS accuracy is met during LOC_MGR_STATE_BOTH_GPS_WPS state.");
+ location_manager_stop(__locMgrStatus.gpsHandler.handle);
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_WPS_ONLY;
+ __locMgrStatus.locMgrSubState = LM_SS_SETTLED;
+ }
+ else if (isGpsAccMet)
+ {
+ SysLog(NID_LOC, "GPS accuracy is met during LOC_MGR_STATE_BOTH_GPS_WPS state. Wait for 10 more seconds to give WPS a chance.");
+
+ if (__locMgrStatus.locMgrSubState != LM_SS_BOTH_SETTLED_WAITING)
+ {
+ const int SUB_STATE_TIMER_VALUE = 10;
+ result r = RestartSubStateTimer(SUB_STATE_TIMER_VALUE);
+ if (!IsFailed(r))
+ {
+ SysLog(NID_LOC, "Started a timer for 10 seconds to give WPS a chance in the state LOC_MGR_STATE_BOTH_GPS_WPS.");
+ __locMgrStatus.locMgrSubState = LM_SS_BOTH_SETTLED_WAITING;
+ }
+ }
+ }
+ else if (isWpsTimeUpdated || isGpsTimeUpdated)
+ {
+ SysLog(NID_LOC, "GPS accuracy and WPS accuracy not met during LOC_MGR_STATE_BOTH_GPS_WPS state. Wait for 20 seconds.");
+
+ if (__locMgrStatus.locMgrSubState != LM_SS_BOTH_SENSING)
+ {
+ const int SUB_STATE_TIMER_VALUE = 20;
+ result r = RestartSubStateTimer(SUB_STATE_TIMER_VALUE);
+ if (!IsFailed(r))
+ {
+ SysLog(NID_LOC, "Started a timer for 20 seconds as the accuracy is not met in state LOC_MGR_STATE_BOTH_GPS_WPS.");
+ __locMgrStatus.locMgrSubState = LM_SS_BOTH_SENSING;
+ }
+ }
+ }
+ else
+ {
+ SysLog(NID_LOC, "Position not obtained by either GPS or WPS.");
+ StopSubStateTimer();
+ __locMgrStatus.locMgrSubState = LM_SS_NO_FIX;
+ }
+}
+
+void
+_LocationManager::HandleGpsOnlyState(void)
+{
+ bool isGpsAccMet = false;
+ bool isTimeUpdated = false;
+ double minAccRequested = ConvertLocationAccuracyToDouble(__minRequestedAccuracy);
+
+ IsGpsLocationUpdated(isTimeUpdated, isGpsAccMet);
+
+ if (!__wpsEnabled && isGpsAccMet)
+ {
+ StopSubStateTimer();
+ __locMgrStatus.locMgrSubState = LM_SS_SETTLED;
+ return;
+ }
+
+ if (__wpsEnabled)
+ {
+ SysLog(NID_LOC, "WPS setting is enabled.");
+ if (isGpsAccMet) //Location available with requested accuracy.
+ {
+ if (minAccRequested > ConvertLocationAccuracyToDouble(LOC_ACCURACY_TEN_METERS))
+ {
+ if (__locMgrStatus.locMgrSubState != LM_SS_GPS_ONLY_SETTLED)
+ {
+ const int SUB_STATE_TIMER_VALUE = 120;
+ result r = RestartSubStateTimer(SUB_STATE_TIMER_VALUE);
+ if (!IsFailed(r))
+ {
+ SysLog(NID_LOC, "Started the sub state timer of 120 seconds in LOC_MGR_STATE_GPS_ONLY state.");
+ __locMgrStatus.locMgrSubState = LM_SS_GPS_ONLY_SETTLED;
+ }
+ }
+ }
+ else
+ {
+ __locMgrStatus.locMgrSubState = LM_SS_SETTLED;
+ }
+ }
+ else if (isTimeUpdated) //GPS Location available with less accuracy.
+ {
+ if (__locMgrStatus.locMgrSubState != LM_SS_GPS_ONLY_SENSING)
+ {
+ const int SUB_STATE_TIMER_VALUE = 40;
+ result r = RestartSubStateTimer(SUB_STATE_TIMER_VALUE);
+ if (!IsFailed(r))
+ {
+ SysLog(NID_LOC, "Started the sub state timer of 40 seconds in LOC_MGR_STATE_GPS_ONLY state.");
+ __locMgrStatus.locMgrSubState = LM_SS_GPS_ONLY_SENSING;
+ }
+ }
+ }
+ else //Location not available
+ {
+ if (__locMgrStatus.locMgrSubState != LM_SS_GPS_ONLY_NO_FIX)
+ {
+ const int SUB_STATE_TIMER_VALUE = 10;
+ result r = RestartSubStateTimer(SUB_STATE_TIMER_VALUE);
+ if (!IsFailed(r))
+ {
+ SysLog(NID_LOC, "Started the sub state timer of 10 seconds in LOC_MGR_STATE_GPS_ONLY state.");
+ __locMgrStatus.locMgrSubState = LM_SS_GPS_ONLY_NO_FIX;
+ }
+ }
+ }
+ }
+ else
+ {
+ StopSubStateTimer();
+
+ if (isTimeUpdated)
+ {
+ SysLog(NID_LOC, "GPS position available with less accuracy in LOC_MGR_STATE_GPS_ONLY state.");
+ __locMgrStatus.locMgrSubState = LM_SS_SENSING;
+ }
+ else
+ {
+ SysLog(NID_LOC, "GPS position not available in LOC_MGR_STATE_GPS_ONLY state.");
+ __locMgrStatus.locMgrSubState = LM_SS_NO_FIX;
+ }
+ }
+}
+
+void
+_LocationManager::HandleWpsOnlyState(void)
+{
+ bool isWpsAccMet = false;
+ bool isTimeUpdated = false;
+ double wpsAccuracy = __locMgrStatus.wpsHandler.pLocation->GetHorizontalAccuracy();
+
+ IsWpsLocationUpdated(isTimeUpdated, isWpsAccMet);
+
+ if (isWpsAccMet)
+ {
+ StopSubStateTimer();
+ __locMgrStatus.locMgrSubState = LM_SS_SETTLED;
+ return;
+ }
+
+ if (__gpsEnabled)
+ {
+ SysLog(NID_LOC, "GPS is enabled.");
+ if (isTimeUpdated) // WPS location available with less accuracy
+ {
+ SysLog(NID_LOC, "WPS position available with less accuracy in LOC_MGR_STATE_WPS_ONLY state.");
+ if (__locMgrStatus.gpsFailCount == 0)
+ {
+ if (__minRequestedAccuracy > LOC_ACCURACY_TEN_METERS)
+ {
+ if (__locMgrStatus.locMgrSubState != LM_SS_WPS_ONLY_LESS_ACC_SENSING)
+ {
+ double currAccDiff = wpsAccuracy - ConvertLocationAccuracyToDouble(__minRequestedAccuracy);
+ int subStateTimerValue = 0;
+
+ if (currAccDiff < 100)
+ {
+ subStateTimerValue = 15;
+ }
+ else
+ {
+ subStateTimerValue = 10;
+ }
+ result r = RestartSubStateTimer(subStateTimerValue * 1000);
+ if (!IsFailed(r))
+ {
+ SysLog(NID_LOC, "Started the sub state timer for (%d) seconds in LOC_MGR_STATE_WPS_ONLY as WPS accuracy not met.", subStateTimerValue);
+ __locMgrStatus.locMgrSubState = LM_SS_WPS_ONLY_LESS_ACC_SENSING;
+ }
+ }
+ }
+ else if (__minRequestedAccuracy == LOC_ACCURACY_FINEST || __minRequestedAccuracy == LOC_ACCURACY_TEN_METERS)
+ {
+ if (__locMgrStatus.locMgrSubState != LM_SS_WPS_ONLY_FINE_ACC_SENSING)
+ {
+ const int SUB_STATE_TIMER_VALUE = 5;
+ result r = RestartSubStateTimer(SUB_STATE_TIMER_VALUE);
+ if (!IsFailed(r))
+ {
+ SysLog(NID_LOC, "Started the sub state timer for 5 seconds in LOC_MGR_STATE_WPS_ONLY as WPS accuracy not met.");
+ __locMgrStatus.locMgrSubState = LM_SS_WPS_ONLY_FINE_ACC_SENSING;
+ }
+ }
+ }
+ }
+ else
+ {
+ if (__locMgrStatus.locMgrSubState != LM_SS_WPS_ONLY_SENSING)
+ {
+ SysLog(NID_LOC, "The number of GPS failures is (%d)", __locMgrStatus.gpsFailCount);
+ const int SUB_STATE_TIMER_VALUE = 10;
+ double timerVal = SUB_STATE_TIMER_VALUE;
+ if (__minRequestedAccuracy > LOC_ACCURACY_TEN_METERS)
+ {
+ timerVal = Math::Pow(2, (__locMgrStatus.gpsFailCount - 1)) * 10;
+ if (timerVal > MAX_TIMER_VALUE_DURING_WPS_POSITIONING)
+ {
+ timerVal = MAX_TIMER_VALUE_DURING_WPS_POSITIONING;
+ }
+ }
+ result r = RestartSubStateTimer((int)timerVal);
+ if (!IsFailed(r))
+ {
+ SysLog(NID_LOC, "Started the sub state timer for (%d) seconds in LOC_MGR_STATE_WPS_ONLY mode when last GPS session has failed.", timerVal);
+ __locMgrStatus.locMgrSubState = LM_SS_WPS_ONLY_SENSING;
+ }
+ }
+ }
+ }
+ else
+ {
+ if (__locMgrStatus.locMgrSubState != LM_SS_WPS_ONLY_NO_FIX)
+ {
+ const int SUB_STATE_TIMER_VALUE = 10;
+ SysLog(NID_LOC, "WPS position not available in LOC_MGR_STATE_WPS_ONLY state.");
+ result r = RestartSubStateTimer(SUB_STATE_TIMER_VALUE);
+ if (!IsFailed(r))
+ {
+ SysLog(NID_LOC, "Started the sub state timer for 10 seconds in LOC_MGR_STATE_WPS_ONLY state when GPS is enabled and WPS no fix.");
+ __locMgrStatus.locMgrSubState = LM_SS_WPS_ONLY_NO_FIX;
+ }
+ }
+ }
+ }
+ else
+ {
+ StopSubStateTimer();
+ if (isTimeUpdated)
+ {
+ SysLog(NID_LOC, "WPS position available with less accuracy in LOC_MGR_STATE_WPS_ONLY state.");
+ __locMgrStatus.locMgrSubState = LM_SS_SENSING;
+ }
+ else
+ {
+ SysLog(NID_LOC, "WPS position not available in LOC_MGR_STATE_WPS_ONLY state.");
+ __locMgrStatus.locMgrSubState = LM_SS_NO_FIX;
+ }
+ }
+}
+
+void
+_LocationManager::IsGpsLocationUpdated(bool& isTimeUpdated, bool& isAccMet)
+{
+ double minAccRequested = ConvertLocationAccuracyToDouble(__minRequestedAccuracy);
+
+ if (__locMgrStatus.gpsHandler.pLocation->GetTimestamp() > __locMgrStatus.gpsHandler.oldTimeStamp)
+ {
+ double gpsAccuracy = __locMgrStatus.gpsHandler.pLocation->GetHorizontalAccuracy();
+ isTimeUpdated = true;
+ if (!Double::IsNaN(gpsAccuracy) && gpsAccuracy <= minAccRequested)
+ {
+ isAccMet = true;
+ }
+ __locMgrStatus.gpsHandler.oldTimeStamp = __locMgrStatus.gpsHandler.pLocation->GetTimestamp();
+ }
+}
+
+void
+_LocationManager::IsWpsLocationUpdated(bool& isTimeUpdated, bool& isAccMet)
+{
+ double minAccRequested = ConvertLocationAccuracyToDouble(__minRequestedAccuracy);
+
+ if (__locMgrStatus.wpsHandler.pLocation->GetTimestamp() > __locMgrStatus.wpsHandler.oldTimeStamp)
+ {
+ double wpsAccuracy = __locMgrStatus.wpsHandler.pLocation->GetHorizontalAccuracy();
+ isTimeUpdated = true;
+ if (!Double::IsNaN(wpsAccuracy) && wpsAccuracy <= minAccRequested)
+ {
+ isAccMet = true;
+ }
+ __locMgrStatus.wpsHandler.oldTimeStamp = __locMgrStatus.wpsHandler.pLocation->GetTimestamp();
+ }
+}
+
+double
+_LocationManager::ConvertLocationAccuracyToDouble(LocationAccuracy locAcc)
+{
+ SysAssertf((locAcc > LOC_ACCURACY_INVALID && locAcc <= LOC_ACCURACY_ANY), "The accuracy value is not valid.");
+
+ static int accArray[] = {NaN, ACCURACY_FINEST, ACCURACY_TEN_MTRS, ACCURACY_HUNDRED_MTRS, ACCURACY_ONE_KILOMETER, ACCURACY_ANY};
+
+ return accArray[locAcc];
+}
+
+result
+_LocationManager::RestartSubStateTimer(int timeout)
+{
+ result r = E_SUCCESS;
+
+ StopSubStateTimer();
+ r = __locMgrStatus.pLocMgrSubStateTimer->Start(timeout * 1000);
+ SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to start the sub state timer with timer value (%d) seconds.", GetErrorMessage(r), timeout);
+ __locMgrStatus.isSubStateTimerStarted = true;
+ // Make a note of the GPS time stamp when sub state timer started. This is used to identify GPS fail case.
+ __locMgrStatus.gpsTimeAtSubstateTimerStart = __locMgrStatus.gpsHandler.pLocation->GetTimestamp();
+ return E_SUCCESS;
+}
+
+void
+_LocationManager::StopSubStateTimer(void)
+{
+ if (__locMgrStatus.isSubStateTimerStarted)
+ {
+ result r = __locMgrStatus.pLocMgrSubStateTimer->Cancel();
+ SysTryLog(NID_LOC, r == E_SUCCESS, "[%s] Failed to stop the sub state timer.", GetErrorMessage(r));
+ __locMgrStatus.isSubStateTimerStarted = false;
+ }
+}
+
+void
+_LocationManager::HandleSubStateTimerExpiry(void)
+{
+ SysLog(NID_LOC, "The substate timer expired for the State (%d) with sub state (%d).", __locMgrStatus.locMgrState, __locMgrStatus.locMgrSubState);
+
+ switch (__locMgrStatus.locMgrState)
+ {
+ case LOC_MGR_STATE_BOTH_GPS_WPS:
+ {
+ switch (__locMgrStatus.locMgrSubState)
+ {
+ case LM_SS_BOTH_SENSING:
+ // follow through
+ case LM_SS_BOTH_SETTLED_WAITING:
+ {
+ enum nextState
+ {
+ SWITCH_STATE_NONE,
+ SWITCH_STATE_WPS_ONLY,
+ SWITCH_STATE_GPS_ONLY
+ };
+
+ nextState nxtState = SWITCH_STATE_NONE;
+ double gpsAccuracy = __locMgrStatus.gpsHandler.pLocation->GetHorizontalAccuracy();
+ double wpsAccuracy = __locMgrStatus.wpsHandler.pLocation->GetHorizontalAccuracy();
+
+ long long wpsTimestamp = __locMgrStatus.wpsHandler.pLocation->GetTimestamp().GetTicks();
+ long long gpsTimestamp = __locMgrStatus.gpsHandler.pLocation->GetTimestamp().GetTicks();
+
+ long long timeDiff = Math::Abs(wpsTimestamp - gpsTimestamp);
+ SysLog(NID_LOC, "Accuracy values are, GPS (%lf) and WPS (%lf). Time difference is (%lld).", gpsAccuracy, wpsAccuracy, timeDiff);
+
+ if (timeDiff <= 1)
+ {
+ SysLog(NID_LOC, "Both GPS and WPS position available.");
+ if (!Double::IsNaN(wpsAccuracy) && wpsAccuracy <= gpsAccuracy)
+ {
+ SysLog(NID_LOC, "WPS accuracy is better than or equal to GPS.");
+ nxtState = SWITCH_STATE_WPS_ONLY;
+ }
+ else
+ {
+ SysLog(NID_LOC, "GPS accuracy is better than WPS.");
+ nxtState = SWITCH_STATE_GPS_ONLY;
+ }
+ }
+ else
+ {
+ SysLog(NID_LOC, "WPS and GPS timestamp is not similar.");
+ if (wpsTimestamp > gpsTimestamp)
+ {
+ SysLog(NID_LOC, "WPS timestamp is better than GPS.");
+ nxtState = SWITCH_STATE_WPS_ONLY;
+ }
+ else
+ {
+ SysLog(NID_LOC, "GPS timestamp is better than WPS.");
+ nxtState = SWITCH_STATE_GPS_ONLY;
+ }
+ }
+
+ switch(nxtState)
+ {
+ case SWITCH_STATE_WPS_ONLY:
+ {
+ location_manager_stop(__locMgrStatus.gpsHandler.handle);
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_WPS_ONLY;
+ __locMgrStatus.locMgrSubState = LM_SS_NO_FIX;
+ }
+ break;
+
+ case SWITCH_STATE_GPS_ONLY:
+ {
+ location_manager_stop(__locMgrStatus.wpsHandler.handle);
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_GPS_ONLY;
+ __locMgrStatus.locMgrSubState = LM_SS_NO_FIX;
+ }
+ break;
+
+ case SWITCH_STATE_NONE:
+ // follow through
+ default:
+ SysAssertf(false, "This state cannot happen.");
+ break;
+ }
+
+ if (__locMgrStatus.locMgrSubState == LM_SS_BOTH_SENSING)
+ {
+ long long diff = gpsTimestamp - __locMgrStatus.gpsTimeAtSubstateTimerStart.GetTicks();
+ if (diff < 0) // Considered to be GPS fail.
+ {
+ __locMgrStatus.gpsFailCount++;
+ }
+ }
+ }
+ break;
+
+ case LM_SS_IDLE:
+ // follow through
+ case LM_SS_SETTLED:
+ // follow through
+ case LM_SS_SENSING:
+ // follow through
+ case LM_SS_NO_FIX:
+ // follow through
+ case LM_SS_GPS_ONLY_SETTLED:
+ // follow through
+ case LM_SS_GPS_ONLY_SENSING:
+ // follow through
+ case LM_SS_GPS_ONLY_NO_FIX:
+ // follow through
+ case LM_SS_WPS_ONLY_LESS_ACC_SENSING:
+ // follow through
+ case LM_SS_WPS_ONLY_FINE_ACC_SENSING:
+ // follow through
+ case LM_SS_WPS_ONLY_SENSING:
+ // follow through
+ case LM_SS_WPS_ONLY_NO_FIX:
+ // follow through
+ default:
+ SysLog(NID_LOC, "The sub state timer expired in wrong location manager sub state.");
+ break;
+ }
+ }
+ break;
+
+ case LOC_MGR_STATE_GPS_ONLY:
+ {
+ switch (__locMgrStatus.locMgrSubState)
+ {
+ case LM_SS_GPS_ONLY_SETTLED:
+ // follow through
+ case LM_SS_GPS_ONLY_SENSING:
+ // follow through
+ case LM_SS_GPS_ONLY_NO_FIX:
+ {
+ if (__wpsEnabled)
+ {
+ SysLog(NID_LOC, "WPS setting is enabled. Start WPS now.");
+ int res = location_manager_start(__locMgrStatus.wpsHandler.handle);
+ SysTryLog(NID_LOC, res == 0, "Failed to start the core WPS location manager. So continue with GPS only.");
+ if (res == 0)
+ {
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_BOTH_GPS_WPS;
+ }
+ }
+ __locMgrStatus.locMgrSubState = LM_SS_NO_FIX;
+ }
+ break;
+
+ case LM_SS_IDLE:
+ // follow through
+ case LM_SS_SETTLED:
+ // follow through
+ case LM_SS_SENSING:
+ // follow through
+ case LM_SS_NO_FIX:
+ // follow through
+ case LM_SS_BOTH_SENSING:
+ // follow through
+ case LM_SS_BOTH_SETTLED_WAITING:
+ // follow through
+ case LM_SS_WPS_ONLY_LESS_ACC_SENSING:
+ // follow through
+ case LM_SS_WPS_ONLY_FINE_ACC_SENSING:
+ // follow through
+ case LM_SS_WPS_ONLY_SENSING:
+ // follow through
+ case LM_SS_WPS_ONLY_NO_FIX:
+ // follow through
+ default:
+ SysLog(NID_LOC, "The sub state timer expired in wrong location manager sub state.");
+ break;
+ }
+ }
+ break;
+
+ case LOC_MGR_STATE_WPS_ONLY:
+ {
+ switch (__locMgrStatus.locMgrSubState)
+ {
+ case LM_SS_WPS_ONLY_LESS_ACC_SENSING:
+ // follow through
+ case LM_SS_WPS_ONLY_FINE_ACC_SENSING:
+ // follow through
+ case LM_SS_WPS_ONLY_SENSING:
+ // follow through
+ case LM_SS_WPS_ONLY_NO_FIX:
+ {
+ if (__gpsEnabled)
+ {
+ SysLog(NID_LOC, "GPS setting is enabled and WPS could not fix the location with requested accuracy. Start GPS now.");
+ int res = location_manager_start(__locMgrStatus.gpsHandler.handle);
+ SysTryLog(NID_LOC, res == 0, "Failed to start the core GPS location provider. So continue with WPS only.");
+ if (res == 0)
+ {
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_BOTH_GPS_WPS;
+ }
+ }
+ __locMgrStatus.locMgrSubState = LM_SS_NO_FIX;
+ }
+ break;
+
+ case LM_SS_IDLE:
+ // follow through
+ case LM_SS_SETTLED:
+ // follow through
+ case LM_SS_SENSING:
+ // follow through
+ case LM_SS_NO_FIX:
+ // follow through
+ case LM_SS_BOTH_SENSING:
+ // follow through
+ case LM_SS_BOTH_SETTLED_WAITING:
+ // follow through
+ case LM_SS_GPS_ONLY_SETTLED:
+ // follow through
+ case LM_SS_GPS_ONLY_SENSING:
+ // follow through
+ case LM_SS_GPS_ONLY_NO_FIX:
+ // follow through
+ default:
+ SysLog(NID_LOC, "The sub state timer expired in wrong location manager sub state.");
+ break;
+ }
+ }
+ break;
+
+ case LOC_MGR_STATE_IDLE:
+ // follow through
+ case LOC_MGR_STATE_PASSIVE_IDLE:
+ // follow through
+ default:
+ SysLog(NID_LOC, "The sub state timer expired in wrong location manager state.");
+ break;
+ }
+
+ __locMgrStatus.isSubStateTimerStarted = false;
+}
+
+void
+_LocationManager::HandleLocationCheckTimerExpiry(void)
+{
+ SysLog(NID_LOC, "Location check timer expired.");
+ const int LOC_CHECK_TIMER_VALUE = 1000;
+
+ switch (__locMgrStatus.locMgrState)
+ {
+ case LOC_MGR_STATE_BOTH_GPS_WPS:
+ {
+ if (__locMgrStatus.wpsHandler.serviceState == LOCATIONS_SERVICE_ENABLED)
+ {
+ result gpsRes = GetLocation(LOCATIONS_METHOD_WPS);
+ SysTryLog(NID_LOC, gpsRes == E_SUCCESS, "[E_SYSTEM] Failed to obtain the WPS location information.");
+ }
+ else
+ {
+ SysLog(NID_LOC, "WPS Location not available at the Native side.");
+ }
+
+ if (__locMgrStatus.gpsHandler.serviceState == LOCATIONS_SERVICE_ENABLED)
+ {
+ result wpsRes = GetLocation(LOCATIONS_METHOD_GPS);
+ SysTryLog(NID_LOC, wpsRes == E_SUCCESS, "[E_SYSTEM] Failed to obtain the GPS location information.");
+ }
+ else
+ {
+ SysLog(NID_LOC, "GPS Location not available at the Native side.");
+ }
+ HandleBothGpsWpsState();
+ }
+ break;
+
+ case LOC_MGR_STATE_GPS_ONLY:
+ {
+ if (__locMgrStatus.gpsHandler.serviceState == LOCATIONS_SERVICE_ENABLED)
+ {
+ result res = GetLocation(LOCATIONS_METHOD_GPS);
+ SysTryLog(NID_LOC, res == E_SUCCESS, "[E_SYSTEM] Failed to obtain the GPS location information.");
+ }
+ else
+ {
+ SysLog(NID_LOC, "GPS Location not available at the Native side.");
+ }
+ HandleGpsOnlyState();
+ }
+ break;
+
+ case LOC_MGR_STATE_WPS_ONLY:
+ {
+ if (__locMgrStatus.wpsHandler.serviceState == LOCATIONS_SERVICE_ENABLED)
+ {
+ result res = GetLocation(LOCATIONS_METHOD_WPS);
+ SysTryLog(NID_LOC, res == E_SUCCESS, "[E_SYSTEM] Failed to obtain the WPS location information.");
+ }
+ else
+ {
+ SysLog(NID_LOC, "WPS Location not available at the Native side.");
+ }
+ HandleWpsOnlyState();
+ }
+ break;
+
+ case LOC_MGR_STATE_IDLE:
+ //follow through
+ case LOC_MGR_STATE_PASSIVE_IDLE:
+ //follow through
+ default:
+ SysLog(NID_LOC, "The timer expiry called in wrong location manager state.");
+ return;
+ }
+
+ __pLocCheckTimer->Start(LOC_CHECK_TIMER_VALUE);
+}
+
bool
_LocationManager::OnStart(void)
{
@@ -993,40 +1629,57 @@ _LocationManager::OnStart(void)
int res = -1;
- std::unique_ptr< Tizen::Base::Collection::ArrayList, AllElementsDeleter > pLocInfoRequestList(new (std::nothrow) ArrayList());
+ std::unique_ptr< ArrayList, AllElementsDeleter > pLocInfoRequestList(new (std::nothrow) ArrayList(SingleObjectDeleter));
SysTryReturn(NID_LOC, pLocInfoRequestList != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
result r = pLocInfoRequestList->Construct();
SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the Location Request list.");
- std::unique_ptr< Tizen::Base::Collection::ArrayList, AllElementsDeleter > pSyncLocInfoRequestList(new (std::nothrow) ArrayList());
+ std::unique_ptr< ArrayList, AllElementsDeleter > pSyncLocInfoRequestList(new (std::nothrow) ArrayList(SingleObjectDeleter));
SysTryReturn(NID_LOC, pSyncLocInfoRequestList != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
r = pSyncLocInfoRequestList->Construct();
SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the Sync Location Request list.");
+ std::unique_ptr< ArrayList, AllElementsDeleter > pAlarmInfoRequestList(new (std::nothrow) ArrayList(SingleObjectDeleter));
+ SysTryReturn(NID_LOC, pAlarmInfoRequestList != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ r = pAlarmInfoRequestList->Construct();
+ SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the Sync Location Request list.");
+
unique_ptr< Tizen::Locations::Location > pGpsLocation(_LocationImpl::GetLocationInstanceN());
SysTryReturn(NID_LOC, pGpsLocation != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
unique_ptr< Tizen::Locations::Location > pWpsLocation(_LocationImpl::GetLocationInstanceN());
SysTryReturn(NID_LOC, pWpsLocation != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
- std::unique_ptr< Tizen::Base::Runtime::Timer > pLocUpdateTimer(new (std::nothrow) Timer());
+ std::unique_ptr< Timer > pLocUpdateTimer(new (std::nothrow) Timer());
r = pLocUpdateTimer->Construct(*this);
- SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the location timer.");
-
- res = location_manager_create(LOCATIONS_METHOD_GPS, &__gpsHandler.handle);
- SysTryReturn(NID_LOC, res == 0, false, E_SYSTEM, "[E_SYSTEM] Failed to create Native GPS Location provider.");
- res = location_manager_set_service_state_changed_cb(__gpsHandler.handle, GpsServiceUpdateCallback, this);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the location update timer.");
+ std::unique_ptr< Timer > pLocCheckTimer(new (std::nothrow) Timer());
+ r = pLocCheckTimer->Construct(*this);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the location chek timer.");
+ std::unique_ptr< Timer > pLocMgrSubstateTimer(new (std::nothrow) Timer());
+ r = pLocMgrSubstateTimer->Construct(*this);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the location manager sub state timer.");
+
+ r = SettingInfo::AddSettingEventListener(*this);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to set the setting event listener.");
+
+ res = location_manager_create(LOCATIONS_METHOD_GPS, &__locMgrStatus.gpsHandler.handle);
+ SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to create Native GPS Location provider.");
+ res = location_manager_set_service_state_changed_cb(__locMgrStatus.gpsHandler.handle, GpsServiceUpdateCallback, this);
SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to register service callback for Native GPS Location provider.");
- res = location_manager_create(LOCATIONS_METHOD_WPS, &__wpsHandler.handle);
+ res = location_manager_create(LOCATIONS_METHOD_WPS, &__locMgrStatus.wpsHandler.handle);
SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to create Native WPS Location provider.");
- res = location_manager_set_service_state_changed_cb(__wpsHandler.handle, WpsServiceUpdateCallback, this);
+ res = location_manager_set_service_state_changed_cb(__locMgrStatus.wpsHandler.handle, WpsServiceUpdateCallback, this);
SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to register service callback for Native WPS Location provider.");
__pLocRequestInfoList = std::move(pLocInfoRequestList);
__pSyncLocRequestInfoList = std::move(pSyncLocInfoRequestList);
- __pLocUpdateTimer = std::move(pLocUpdateTimer);
- __gpsHandler.pLocation= std::move(pGpsLocation);
- __wpsHandler.pLocation= std::move(pWpsLocation);
+ __pAlarmRequestInfoList = std::move(pAlarmInfoRequestList);
+ __pLocCallbackTimer = std::move(pLocUpdateTimer);
+ __pLocCheckTimer = std::move(pLocCheckTimer);
+ __locMgrStatus.pLocMgrSubStateTimer = std::move(pLocMgrSubstateTimer);
+ __locMgrStatus.gpsHandler.pLocation = std::move(pGpsLocation);
+ __locMgrStatus.wpsHandler.pLocation = std::move(pWpsLocation);
r = __pInitMonitor->Enter();
SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to Enter Monitor. Propagating.", GetErrorMessage(r));
@@ -1039,15 +1692,17 @@ _LocationManager::OnStart(void)
return true;
CATCH:
- if (__gpsHandler.handle)
+ if (__locMgrStatus.gpsHandler.handle)
{
- location_manager_destroy(__gpsHandler.handle);
+ location_manager_destroy(__locMgrStatus.gpsHandler.handle);
}
- if (__wpsHandler.handle)
+ if (__locMgrStatus.wpsHandler.handle)
{
- location_manager_destroy(__wpsHandler.handle);
+ location_manager_destroy(__locMgrStatus.wpsHandler.handle);
}
+ SettingInfo::RemoveSettingEventListener(*this);
+
return false;
}
@@ -1057,14 +1712,15 @@ _LocationManager::OnStop(void)
delete __pInitMonitor;
__pInitMonitor = null;
- if (__gpsHandler.handle)
+ if (__locMgrStatus.gpsHandler.handle)
{
- location_manager_destroy(__gpsHandler.handle);
+ location_manager_destroy(__locMgrStatus.gpsHandler.handle);
}
- if (__wpsHandler.handle)
+ if (__locMgrStatus.wpsHandler.handle)
{
- location_manager_destroy(__wpsHandler.handle);
+ location_manager_destroy(__locMgrStatus.wpsHandler.handle);
}
+ SettingInfo::RemoveSettingEventListener(*this);
}
void
@@ -1100,29 +1756,6 @@ _LocationManager::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
}
break;
- case REQ_ID_RESTART_LOC_UPDATES:
- {
- SysLog(NID_LOC, "REQ_ID_RESTART_LOC_UPDATES.");
- RestartLocationUpdates();
- }
- break;
-
- case REQ_ID_SUSTAIN_GPS:
- {
- SysLog(NID_LOC, "REQ_ID_SUSTAIN_GPS.");
- location_manager_stop(__wpsHandler.handle);
- __locMethodRequested = LOC_METHOD_REQUESTED_GPS;
- }
- break;
-
- case REQ_ID_SUSTAIN_WPS:
- {
- SysLog(NID_LOC, "REQ_ID_SUSTAIN_WPS.");
- location_manager_stop(__gpsHandler.handle);
- __locMethodRequested = LOC_METHOD_REQUESTED_WPS;
- }
- break;
-
case REQ_ID_SYNC_LOC_RETRIEVAL:
{
SysLog(NID_LOC, "REQ_ID_SYNC_LOC_RETRIEVAL.");
@@ -1176,7 +1809,33 @@ _LocationManager::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
pInterval = static_cast< Integer* >(pArgs->GetAt(1));
SysTryCatch(NID_LOC, pInterval, , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
- UpdateLocRequestInfoList(static_cast< long >(pReqId->ToInt()), pInterval->ToInt());
+ UpdateLocRequestInterval(static_cast< long >(pReqId->ToInt()), pInterval->ToInt());
+ }
+ break;
+
+ case REQ_ID_START_ALARM:
+ {
+ SysLog(NID_LOC, "REQ_ID_START_ALARM");
+ SysTryReturnVoidResult(NID_LOC, pArgs, E_INVALID_ARG, "[E_INVALID_ARG] Null argument encountered. Ignored.");
+ _AlarmRequestInfo* pAlarmRequestInfo = null;
+ SysTryCatch(NID_LOC, pArgs->GetCount() == ARRAY_LIST_CAPACITY, pArgs->RemoveAll(true), E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+ pAlarmRequestInfo = static_cast< _AlarmRequestInfo* >(pArgs->GetAt(0));
+ SysTryCatch(NID_LOC, pAlarmRequestInfo, , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+
+ AddToAlarmRequestInfoList(*pAlarmRequestInfo);
+ }
+ break;
+
+ case REQ_ID_STOP_ALARM:
+ {
+ SysLog(NID_LOC, "REQ_ID_STOP_ALARM");
+ SysTryReturnVoidResult(NID_LOC, pArgs, E_INVALID_ARG, "[E_INVALID_ARG] Null argument encountered. Ignored.");
+ Integer* pReqId = null;
+ SysTryCatch(NID_LOC, pArgs->GetCount() == ARRAY_LIST_CAPACITY, pArgs->RemoveAll(true), E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+ pReqId = static_cast< Integer* >(pArgs->GetAt(0));
+ SysTryCatch(NID_LOC, pReqId, , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+
+ RemoveFromAlarmRequestInfoList(static_cast< long >(pReqId->ToInt()));
}
break;
@@ -1198,72 +1857,180 @@ CATCH:
void
_LocationManager::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
{
- if (__pLocUpdateTimer->Equals(timer))
+ if (__pLocCheckTimer->Equals(timer))
+ {
+ HandleLocationCheckTimerExpiry();
+ }
+ else if (__pLocCallbackTimer->Equals(timer))
{
__timerTicks++;
SysLog(NID_LOC, "LocationManager update timer expired. Timer Tick value is (%d).", __timerTicks);
- result r = E_SUCCESS;
- switch (__locMethodRequested)
- {
- case LOC_METHOD_REQUESTED_GPS:
+ __pLocCallbackTimer->Start(__timerInterval * 1000);
+ SendLocationCallbacks();
+ }
+ else if (__locMgrStatus.pLocMgrSubStateTimer.get()->Equals(timer))
+ {
+ SysLog(NID_LOC, "Substate timer expired.");
+ HandleSubStateTimerExpiry();
+ }
+ else
+ {
+ int count = __pSyncLocRequestInfoList->GetCount();
+ for (int i = 0; i < count; i++)
{
- r = GetLocation(LOCATIONS_METHOD_GPS);
- SysTryLog(NID_LOC, r == E_SUCCESS, "[E_SYSTEM] Failed to obtain the GPS location information");
- if (IsFailed(r))
+ _SyncLocationRequestInfo* pSyncLocRequestInfo = static_cast< _SyncLocationRequestInfo* >(__pSyncLocRequestInfoList->GetAt(i));
+ if (pSyncLocRequestInfo != null && pSyncLocRequestInfo->Equals(timer))
{
- SendUserEvent(REQ_ID_RESTART_LOC_UPDATES, null);
+ SysLog(NID_LOC, "Timer expired for the sync location request with request ID (%ld)", pSyncLocRequestInfo->GetRequestId());
+
+ HandleSyncRetrievalTimerExpiry(*pSyncLocRequestInfo);
+ break;
}
}
- break;
+ }
+ return;
+}
- case LOC_METHOD_REQUESTED_WPS:
+void
+_LocationManager::OnSettingChanged(Tizen::Base::String& key)
+{
+ const String GPS_STRING(L"http://tizen.org/setting/location.gps");
+ const String WPS_STRING(L"http://tizen.org/setting/location.wps");
+
+ SysLog(NID_LOC, "The setting value is changed for (%ls) setting.", key.GetPointer());
+
+ if (!((key.Equals(GPS_STRING, false)) || (key.Equals(WPS_STRING, false))))
+ {
+ 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)
{
- r = GetLocation(LOCATIONS_METHOD_WPS);
- SysTryLog(NID_LOC, r == E_SUCCESS, "[E_SYSTEM] Failed to obtain the WPS location information");
- if (IsFailed(r))
+ 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)
{
- SendUserEvent(REQ_ID_RESTART_LOC_UPDATES, null);
+ 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);
}
}
- break;
+ 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_METHOD_REQUESTED_ALL:
+ case LOC_MGR_STATE_GPS_ONLY:
+ {
+ if (!gpsEnabled)
{
- if (__wpsHandler.serviceState == LOCATIONS_SERVICE_ENABLED)
+ int res = -1;
+ if (wpsEnabled)
{
- r = GetLocation(LOCATIONS_METHOD_WPS);
- SysTryLog(NID_LOC, r == E_SUCCESS, "[E_SYSTEM] Failed to obtain the WPS location information");
+ 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;
+ }
}
- else
+ if (!wpsEnabled || res != 0)
{
- SysLog(NID_LOC, "WPS Location not available at the Native side.");
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_PASSIVE_IDLE;
+ StopSubStateTimer();
+ __pLocCheckTimer->Cancel();
}
- if (__gpsHandler.serviceState == LOCATIONS_SERVICE_ENABLED)
+ 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)
{
- r = GetLocation(LOCATIONS_METHOD_GPS);
- SysTryLog(NID_LOC, r == E_SUCCESS, "[E_SYSTEM] Failed to obtain the GPS location information");
+ 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;
+ }
}
- else
+ if (!gpsEnabled || res != 0)
{
- SysLog(NID_LOC, "GPS Location not available at the Native side.");
+ __locMgrStatus.locMgrState = LOC_MGR_STATE_PASSIVE_IDLE;
+ StopSubStateTimer();
+ __pLocCheckTimer->Cancel();
}
- }
- break;
- case LOC_METHOD_REQUESTED_NONE:
- // follow through
- default:
- SysLog(NID_LOC, "Timer expired when no location update is called.");
- return;
+ SysLog(NID_LOC, "WPS setting turned off during LOC_MGR_STATE_WPS_ONLY.");
+ location_manager_stop(__locMgrStatus.wpsHandler.handle);
}
+ }
+ break;
- __pLocUpdateTimer->Start(__timerInterval * 1000);
- SendLocationCallbacks();
+ 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;
}
- return;
+ __gpsEnabled = gpsEnabled;
+ __wpsEnabled = wpsEnabled;
}
bool
@@ -1304,7 +2071,7 @@ _LocationManager::GpsServiceUpdateCallback(location_service_state_e state, void*
}
_LocationManager* pThis = static_cast< _LocationManager* >(user_data);
- pThis->__gpsHandler.serviceState = state;
+ pThis->__locMgrStatus.gpsHandler.serviceState = state;
}
void
@@ -1318,7 +2085,36 @@ _LocationManager::WpsServiceUpdateCallback(location_service_state_e state, void*
}
_LocationManager* pThis = static_cast< _LocationManager* >(user_data);
- pThis->__wpsHandler.serviceState = state;
+ pThis->__locMgrStatus.wpsHandler.serviceState = state;
+}
+
+int
+_LocationManager::AlarmExpiryCallback(alarm_id_t alarm_id, void* user_param)
+{
+ SysLog(NID_LOC, "The Alarm expired successfully for the alarm ID (%d).", alarm_id);
+ if (user_param == null)
+ {
+ SysLog(NID_LOC, "The user parameter is null. So cannot handle the callback.");
+ return -1;
+ }
+ _LocationManager* pThis = static_cast< _LocationManager* >(user_param);
+ int count = pThis->__pAlarmRequestInfoList->GetCount();
+
+ for (int i = 0; i < count; i++)
+ {
+ _AlarmRequestInfo* pAlarmRequestInfo = static_cast< _AlarmRequestInfo* >(pThis->__pAlarmRequestInfoList->GetAt(i));
+ if (pAlarmRequestInfo)
+ {
+ if (alarm_id == pAlarmRequestInfo->GetAlarmId())
+ {
+ pAlarmRequestInfo->GetListener()->OnAlarmExpired();
+ pThis->__pAlarmRequestInfoList->RemoveAt(i);
+ break;
+ }
+ }
+ }
+
+ return 0;
}
void
@@ -1334,8 +2130,8 @@ _LocationManager::InitLocationManager(void)
r = pLocMgr->Start();
SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to start the Location Manager. Propagating.", GetErrorMessage(r));
- r = pLocMgr->WaitThreadStart();
- SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to WaitThreadStart. Propagating.", GetErrorMessage(r));
+ r = pLocMgr->WaitUntilThreadStart();
+ SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to WaitUntilThreadStart. Propagating.", GetErrorMessage(r));
__pUniqueInstance = pLocMgr.release();
std::atexit(DestroyLocationManager);
@@ -1348,7 +2144,7 @@ _LocationManager::DestroyLocationManager(void)
}
result
-_LocationManager::WaitThreadStart()
+_LocationManager::WaitUntilThreadStart()
{
result r = __pInitMonitor->Enter();
SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to Enter Monitor. Propagating.", GetErrorMessage(r));
diff --git a/src/FLoc_LocationManager.h b/src/FLoc_LocationManager.h
index 5723199..04de9d6 100644
--- a/src/FLoc_LocationManager.h
+++ b/src/FLoc_LocationManager.h
@@ -26,17 +26,19 @@
#define _FLOC_INTERNAL_LOCATION_MANAGER_H_
#include <unique_ptr.h>
+#include <alarm.h>
#include <location/locations.h>
#include <FBaseColAllElementsDeleter.h>
+#include <FBaseDateTime.h>
#include <FBaseRtEventDrivenThread.h>
#include <FLocLocation.h>
+#include <FSysISettingEventListener.h>
#include "FLoc_ILocationManagerListener.h"
#include "FLoc_Types.h"
-#include "FLoc_WaitLoopListener.h"
namespace Tizen { namespace Locations
{
-
+class _AlarmRequestInfo;
class _LocationMonitor;
class _LocationRequestInfo;
class _SyncLocationRequestInfo;
@@ -44,6 +46,7 @@ class _SyncLocationRequestInfo;
class _LocationManager
: public Tizen::Base::Runtime::EventDrivenThread
, public Tizen::Base::Runtime::ITimerEventListener
+ , public Tizen::System::ISettingEventListener
{
public:
// This method adds the location request into the list of requests and requests for location updates from core location provider.
@@ -70,23 +73,29 @@ public:
//
result RegisterLocationMonitor(_LocationMonitor* pLocationMonitor);
- // This method returns the stored location.
+ // This method adds the alarm request into the list of requests and requests for alarm from the core alarm manager.
//
// @since 2.0
//
- Location GetLastKnownLocation(void);
+ result RequestStartAlarm(int interval, _ILocationManagerListener* pListener, RequestId reqId);
- // This method converts the horizontal accuracy in meters to the LocationAccuracy enum type.
+ // This method removes the alarm request from the list of requests and requests the removal of alarm from the core alarm manager.
//
// @since 2.0
//
- LocationAccuracy GetAccuracyLevel(double horAcc) const;
+ result RequestStopAlarm(RequestId reqId);
+
+ // This method returns the stored location.
+ //
+ // @since 2.0
+ //
+ Location GetLastKnownLocation(void);
- // This method returns the wait loop listener of this class.
+ // This method converts the horizontal accuracy in meters to the LocationAccuracy enum type.
//
// @since 2.0
//
- _WaitLoopListener* GetWaitLoopListener(void){return &__waitLoopListener;}
+ LocationAccuracy GetAccuracyLevel(double horAcc) const;
// This method returns the single instance of the location maanger.
//
@@ -143,29 +152,41 @@ private:
//
void RemoveSyncLocRetrievalRequest(_SyncLocationRequestInfo& syncLocRequestInfo);
- // The method restarts both GPS and WPS native location providers.
+ // The method adds the _AlarmRequestInfo instance corresponding to a reqId from the array list.
//
// @since 2.0
//
- void RestartLocationUpdates(void);
+ void AddToAlarmRequestInfoList(_AlarmRequestInfo& alarmRequestInfo);
- // The method restarts the update timer after calculating the GCD of the timeout values requested by each location provider.
+ // The method removes the _AlarmRequestInfo instance from the list.
//
// @since 2.0
//
- void RestartUpdateTimer(void);
+ void RemoveFromAlarmRequestInfoList(RequestId reqId);
- // The method is called everytime the sync retrieval timer is expired.
+ // The method updates the minimum accuracy required.
//
- // @since 2.0
+ // @since 2.2
//
- void HandleSyncRetrievalTimerExpiry(_SyncLocationRequestInfo& syncLocRequestInfo);
+ void UpdateMinimunAccuracy(void);
- // The method is called everytime the Async update timer is expired to set the location information.
+ // The method starts the core location provider when the location is requested during Location manager idle state.
+ //
+ // @since 2.2
+ //
+ void InitiateLocationRequest(void);
+
+ // The method restarts the callback timer after calculating the GCD of the timeout values requested by each location provider.
+ //
+ // @since 2.2
+ //
+ void RestartCallbackTimer(void);
+
+ // The method is called everytime the sync retrieval timer is expired.
//
// @since 2.0
//
- result SetLocationInformation(double latitude, double longitude, double altitude, time_t timestamp, location_method_e locMethod, Location* pLocation);
+ void HandleSyncRetrievalTimerExpiry(_SyncLocationRequestInfo& syncLocRequestInfo);
// The method is called to send back the callbacks in case of async location updates.
//
@@ -183,13 +204,12 @@ private:
//
// @since 2.0
//
- result WaitThreadStart();
+ result WaitUntilThreadStart();
// The method calls the construct method of the event driven thread.
//
// @since 2.0
//
-
result Construct(void);
// This method is gets the last known location from Native side for the given method.
@@ -208,7 +228,7 @@ private:
//
// @since 2.0
//
- void UpdateLocRequestInfoList(RequestId reqId, int interval);
+ void UpdateLocRequestInterval(RequestId reqId, int interval);
// This method gets the better location among the three location providers.
//
@@ -222,6 +242,75 @@ private:
//
result GetLocation(location_method_e nativeLocMethod);
+ // This method handles the location information obtained from core location provider/s when the location manager state is LOC_MGR_STATE_BOTH_GPS_WPS.
+ //
+ // @since 2.2
+ //
+ void HandleBothGpsWpsState(void);
+
+ // This method handles the location information obtained from core GPS location provider when the location manager state is LOC_MGR_STATE_GPS_ONLY.
+ //
+ // @since 2.2
+ //
+ void HandleGpsOnlyState(void);
+
+ // This method handles the location information obtained from core WPS location provider when the location manager state is LOC_MGR_STATE_WPS_ONLY.
+ //
+ // @since 2.2
+ //
+ void HandleWpsOnlyState(void);
+
+ // This method checks the validity of location updated by GPS core provider is valid or not.
+ //
+ // @since 2.2
+ //
+ void IsGpsLocationUpdated(bool& isTimeUpdated, bool& isAccMet);
+
+ // This method checks the validity of location updated by WPS core provider is valid or not.
+ //
+ // @since 2.2
+ //
+ void IsWpsLocationUpdated(bool& isTimeUpdated, bool& isAccMet);
+
+ // This method converts the LocationAccuracy enum variable to corresponding double value.
+ //
+ // @since 2.2
+ //
+ double ConvertLocationAccuracyToDouble(LocationAccuracy locAcc);
+
+ // This method stops if timer is running and starts the sub state timer for the given interval.
+ //
+ // @since 2.2
+ //
+ result RestartSubStateTimer(int timeout);
+
+ // This method stops the sub state timer if it is running.
+ //
+ // @since 2.2
+ //
+ void StopSubStateTimer(void);
+
+ // This method handles the expiry of the sub state.
+ //
+ // @since 2.2
+ //
+ void HandleSubStateTimerExpiry(void);
+
+ // This method handles the expiry of the location check timer.
+ //
+ // @since 2.2
+ //
+ void HandleLocationCheckTimerExpiry(void);
+
+ // This method Covert error code for native error.
+ //
+ // @since 2.1
+ //
+ inline double ConvertToNativeFormat(double value)
+ {
+ return value < 0.0 ? Tizen::Locations::NaN : value;
+ }
+
// @see @ref Tizen::Base::Runtime::EventDrivenThread::OnStart()
//
// @since 2.0
@@ -246,6 +335,12 @@ private:
//
virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
+ // @see @ref Tizen::System::ISettingEventListener::OnSettingChanged()
+ //
+ // @since 2.1
+ //
+ virtual void OnSettingChanged(Tizen::Base::String& key);
+
// This callback is recieved from native location manager for satellite information.
//
// @since 2.0
@@ -264,6 +359,12 @@ private:
//
static void WpsServiceUpdateCallback(location_service_state_e state, void* user_data);
+ // This method is called by the core alarm manager when the requested alarm is expired.
+ //
+ // @since 2.0
+ //
+ static int AlarmExpiryCallback(alarm_id_t alarm_id, void* user_param);
+
// This method initializes the single instance of the location manager.
//
// @since 2.0
@@ -279,29 +380,37 @@ private:
private:
const static RequestId REQ_ID_START_LOC_UPDATES = 1;
const static RequestId REQ_ID_STOP_LOC_UPDATES = 2;
- const static RequestId REQ_ID_RESTART_LOC_UPDATES = 3;
- const static RequestId REQ_ID_SUSTAIN_GPS = 4;
- const static RequestId REQ_ID_SUSTAIN_WPS = 5;
- const static RequestId REQ_ID_SYNC_LOC_RETRIEVAL = 6;
- const static RequestId REQ_ID_GET_LAST_LOCATION = 7;
- const static RequestId REQ_ID_UPDATE_INTERVAL = 8;
-
- enum _LocationMethodRequested
- {
- LOC_METHOD_REQUESTED_NONE,
- LOC_METHOD_REQUESTED_GPS,
- LOC_METHOD_REQUESTED_WPS,
- LOC_METHOD_REQUESTED_ALL,
- }
- __locMethodRequested;
+ const static RequestId REQ_ID_SYNC_LOC_RETRIEVAL = 3;
+ const static RequestId REQ_ID_GET_LAST_LOCATION = 4;
+ const static RequestId REQ_ID_UPDATE_INTERVAL = 5;
+ const static RequestId REQ_ID_START_ALARM = 6;
+ const static RequestId REQ_ID_STOP_ALARM = 7;
enum _LocationManagerState
{
LOC_MGR_STATE_IDLE,
- LOC_MGR_STATE_FAST_SENSING,
- LOC_MGR_STATE_FAST_SENSING_SETTLED
- }
- __locationMgrState;
+ LOC_MGR_STATE_PASSIVE_IDLE,
+ LOC_MGR_STATE_BOTH_GPS_WPS,
+ LOC_MGR_STATE_GPS_ONLY,
+ LOC_MGR_STATE_WPS_ONLY
+ };
+
+ enum _LocationManagerSubState
+ {
+ LM_SS_IDLE,
+ LM_SS_SETTLED,
+ LM_SS_SENSING,
+ LM_SS_NO_FIX,
+ LM_SS_BOTH_SENSING,
+ LM_SS_BOTH_SETTLED_WAITING,
+ LM_SS_GPS_ONLY_SETTLED,
+ LM_SS_GPS_ONLY_SENSING,
+ LM_SS_GPS_ONLY_NO_FIX,
+ LM_SS_WPS_ONLY_LESS_ACC_SENSING,
+ LM_SS_WPS_ONLY_FINE_ACC_SENSING,
+ LM_SS_WPS_ONLY_SENSING,
+ LM_SS_WPS_ONLY_NO_FIX
+ };
class _LocationManagerHandle
{
@@ -311,6 +420,7 @@ private:
, handle(null)
, pLocation(null)
{
+ oldTimeStamp.SetValue(1970, 1, 1);
}
~_LocationManagerHandle(void)
@@ -320,20 +430,48 @@ private:
public:
location_service_state_e serviceState;
location_manager_h handle;
+ Tizen::Base::DateTime oldTimeStamp;
std::unique_ptr< Tizen::Locations::Location > pLocation;
};
+ class _LocationManagerStatus
+ {
+ public:
+ _LocationManagerStatus(void)
+ : isSubStateTimerStarted(false)
+ , locMgrState(LOC_MGR_STATE_IDLE)
+ , locMgrSubState(LM_SS_IDLE)
+ , gpsFailCount(0)
+ {
+ }
+ ~_LocationManagerStatus(void)
+ {
+ }
+
+ public:
+ bool isSubStateTimerStarted;
+ _LocationManagerState locMgrState;
+ _LocationManagerSubState locMgrSubState;
+ int gpsFailCount;
+ Tizen::Base::DateTime gpsTimeAtSubstateTimerStart;
+ std::unique_ptr< Tizen::Base::Runtime::Timer > pLocMgrSubStateTimer;
+ _LocationManagerHandle gpsHandler;
+ _LocationManagerHandle wpsHandler;
+ };
+
+ bool __gpsEnabled;
+ bool __wpsEnabled;
+ _LocationManagerStatus __locMgrStatus;
LocationAccuracy __minRequestedAccuracy;
int __timerInterval;
int __timerTicks;
- _LocationManagerHandle __gpsHandler;
- _LocationManagerHandle __wpsHandler;
std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > __pLocRequestInfoList;
std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > __pSyncLocRequestInfoList;
- std::unique_ptr< Tizen::Base::Runtime::Timer > __pLocUpdateTimer;
- static _LocationManager* __pUniqueInstance;
- _WaitLoopListener __waitLoopListener;
+ std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > __pAlarmRequestInfoList;
+ std::unique_ptr< Tizen::Base::Runtime::Timer > __pLocCallbackTimer;
+ std::unique_ptr< Tizen::Base::Runtime::Timer > __pLocCheckTimer;
Tizen::Base::Runtime::Monitor* __pInitMonitor;
+ static _LocationManager* __pUniqueInstance;
friend class std::default_delete< _LocationManager >;
}; // class _LocationManager
diff --git a/src/FLoc_LocationProviderImpl.cpp b/src/FLoc_LocationProviderImpl.cpp
index 2d25b79..57700ee 100644
--- a/src/FLoc_LocationProviderImpl.cpp
+++ b/src/FLoc_LocationProviderImpl.cpp
@@ -39,7 +39,7 @@
#include <FLocTypes.h>
#include <FSysPowerManager.h>
#include <FSysSystemTime.h>
-#include <FSys_AlarmImpl.h>
+#include <FSec_AccessController.h>
#include <FSys_SettingInfoImpl.h>
#include "FLoc_LocationImpl.h"
#include "FLoc_LocationManager.h"
@@ -54,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
@@ -69,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();
@@ -89,22 +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());
+ 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));
- std::unique_ptr< Tizen::System::Alarm> pAlarm (new (std::nothrow) Alarm());
- SysTryReturn(NID_LOC, pAlarm != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
- r = pAlarm->Construct(*this);
- SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to construct the alarm. Propagating.", GetErrorMessage(r));
-
- UiApp* pAppInstance = Tizen::App::UiApp::GetInstance();
+ UiApp* pAppInstance = UiApp::GetInstance();
if (pAppInstance != null)
{
_AppManagerImpl* pAppManager = _AppManagerImpl::GetInstance();
@@ -116,7 +112,7 @@ _LocationProviderImpl::Construct(const LocationCriteria& criteria, ILocationProv
std::unique_ptr< Tizen::Locations::Location > pLastLocation(_LocationImpl::GetLocationInstanceN());
SysTryReturn(NID_LOC, pLastLocation != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
- std::unique_ptr<Tizen::Locations::Location> pLastRegionLocation (_LocationImpl::GetLocationInstanceN());
+ std::unique_ptr< Tizen::Locations::Location > pLastRegionLocation(_LocationImpl::GetLocationInstanceN());
SysTryReturn(NID_LOC, pLastRegionLocation != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
_Event::Initialize();
@@ -124,10 +120,9 @@ _LocationProviderImpl::Construct(const LocationCriteria& criteria, ILocationProv
__regionMonitor.pRegionList = std::move(pRegionList);
__regionMonitor.pTimer = std::move(pTimer);
- __regionMonitor.pAlarm = std::move(pAlarm);
__regionMonitor.pLocation = std::move(pLastRegionLocation);
__locationUpdater.pLocation = std::move(pLastLocation);
-
+
__criteria = criteria;
__pLocationListener = &listener;
__pLocationManager = pLocationManager;
@@ -187,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);
@@ -266,7 +261,7 @@ _LocationProviderImpl::RemoveMonitoringRegion(RegionId regionId)
_RegionInfo* pRegionInfo = static_cast< _RegionInfo* >(__regionMonitor.pRegionList->GetAt(i));
if (regionId == pRegionInfo->GetRegionId())
{
- __regionMonitor.pRegionList->RemoveAt(i, true);
+ __regionMonitor.pRegionList->RemoveAt(i);
isIdValid = true;
break;
}
@@ -413,12 +408,29 @@ _LocationProviderImpl::OnLocationUpdated(RequestId reqId, const Tizen::Locations
}
void
+_LocationProviderImpl::OnAlarmExpired(void)
+{
+ SysLog(NID_LOC, "The call back of the Alarm expiry is called from location manager.");
+
+ std::unique_ptr< _LocProviderEventArg > pLocProviderEventArg(new (std::nothrow) _LocProviderEventArg());
+ SysTryReturnVoidResult(NID_LOC, pLocProviderEventArg, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ pLocProviderEventArg->SetEventType(_LOC_PRV_EVENT_SEND_ALARM_EXPIRY);
+
+ result r = _Event::FireAsync(*pLocProviderEventArg);
+ SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to fire the event.", GetErrorMessage(r));
+ pLocProviderEventArg.release();
+
+ return;
+}
+
+void
_LocationProviderImpl::OnLocationEventReceivedN(RequestId reqId, Tizen::Locations::Location& 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;
Location* pLocation = &location;
@@ -443,6 +455,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.");
@@ -452,35 +469,39 @@ _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);
-
+
__regionMonitor.speed = location.GetSpeed() * 0.2777778;
- if ( currentAccuracy <= lastLocAccuracy || timeDifference > DEFAULT_THRESHOLD_LOC_VALIDITY_TIME_OUT) // Copy the location only if it is new and accuracy is better than before.
+ double currentHorAcc = 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.
{
*__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);
}
}
@@ -500,10 +521,18 @@ _LocationProviderImpl::OnRegionMonitoringStatusChanged(Tizen::Locations::Locatio
}
void
+_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));
+}
+
+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());
@@ -534,19 +563,10 @@ _LocationProviderImpl::OnActiveAppChanged(const Tizen::App::AppId& appId)
}
void
-_LocationProviderImpl::OnAlarmExpired(Alarm& alarm)
-{
- SysLog(NID_LOC, "Region Monitor Alarm expired.");
- result r = ActivateRegionMonitoring(true);
- SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to start the region monitoring. Propogating.", GetErrorMessage(r));
-}
-
-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
@@ -565,9 +585,9 @@ _LocationProviderImpl::StartLocationUpdates(LocationUpdateType updateType, int i
__locationUpdater.distanceThreshold = distance;
}
- if (!__locationUpdater.awakeEnabled)
+ if (!__locationUpdater.awakeEnabled)
{
- UiApp* pAppInstance = Tizen::App::UiApp::GetInstance();
+ UiApp* pAppInstance = UiApp::GetInstance();
if (pAppInstance == null)
{
startUpdate = false;
@@ -599,11 +619,11 @@ _LocationProviderImpl::StartLocationUpdates(LocationUpdateType updateType, int i
r = __pLocationManager->StartLocationUpdates(__criteria.GetAccuracy(), __locationUpdater.updateInterval, this, __locationUpdater.reqId);
SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to start the Native location updates. Propagating.", GetErrorMessage(r));
__locationUpdater.status = LOC_SVC_STATUS_NOT_FIXED;
- }
+ }
}
else
{
- __locationUpdater.status = LOC_SVC_STATUS_PAUSED;
+ __locationUpdater.status = LOC_SVC_STATUS_PAUSED;
}
__locationUpdater.type = updateType;
@@ -672,27 +692,31 @@ _LocationProviderImpl::FireImpl(Tizen::Base::Runtime::IEventListener& listener,
case _LOC_PRV_EVENT_SEND_MONITOR_SVC_CB:
pLocProviderEventListener->OnRegionMonitoringStatusChanged(pEventArg->GetLocServiceStatus());
break;
+
+ case _LOC_PRV_EVENT_SEND_ALARM_EXPIRY:
+ pLocProviderEventListener->OnAlarmExpiredEventReceived();
+ break;
}
}
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
@@ -732,17 +756,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
{
@@ -756,12 +780,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
@@ -815,12 +843,17 @@ _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());
+ region.GetCoordinate().GetLongitude(), region.GetRadius());
SysSecureLog(NID_LOC, "[RegionID %d] Location Information is (Latitude: %lf, Longitude: %lf, Horizontal accuracy:%lf", region.GetRegionId(), location.GetCoordinates().GetLatitude(),
- location.GetCoordinates().GetLongitude(), location.GetHorizontalAccuracy());
+ location.GetCoordinates().GetLongitude(), location.GetHorizontalAccuracy());
_RegionState regionState = REGION_STATE_UNKNOWN;
double distanceBtwCenters = region.GetCoordinate().GetDistanceTo(location.GetCoordinates());
@@ -923,6 +956,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;
}
@@ -944,25 +981,25 @@ _LocationProviderImpl::ActivateRegionMonitoring(bool startUpdate)
}
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));
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the timer. Propogating.", GetErrorMessage(r));
if (startUpdate)
{
_LocationImpl::GetInstance(*__regionMonitor.pLocation)->SetValidity(false);
- _LocationImpl::GetInstance(*__regionMonitor.pLocation)->SetTimestamp(currentTime);
+ _LocationImpl::GetInstance(*__regionMonitor.pLocation)->SetTimestamp(currentTime);
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;
}
void
_LocationProviderImpl::StopRegionMonitoring(void)
{
- result r = _AlarmImpl::GetInstance(__regionMonitor.pAlarm.get())->Cancel();
+ result r = __pLocationManager->RequestStopAlarm(__regionMonitor.reqId);
SysTryLog(NID_LOC, r == E_SUCCESS, "[%s] Failed to stop the alarm. Ignored.", GetErrorMessage(r));
r = __regionMonitor.pTimer->Cancel();
@@ -992,7 +1029,7 @@ _LocationProviderImpl::SetNextRegionMonitoringTime(void)
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 / speed) - bufferTime; //Calculate the alarm time based on the shortest distance between current location and nearest region boundary.
+ 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)
{
@@ -1008,11 +1045,9 @@ _LocationProviderImpl::SetNextRegionMonitoringTime(void)
result r = __pLocationManager->StopLocationUpdates(__regionMonitor.reqId);
SysTryLog(NID_LOC, r == E_SUCCESS, "Failed to stop the location updates.");
-
- alarmDateTime.AddSeconds(alarmTime);
- r = _AlarmImpl::GetInstance(__regionMonitor.pAlarm.get())->Set(alarmDateTime, 0, null);
- SysTryLog(NID_LOC, r == E_SUCCESS, "Failed to set the alarm for next cycle.");
-
+
+ r = __pLocationManager->RequestStartAlarm(alarmTime, this, __regionMonitor.reqId);
+
SysLog(NID_LOC, "Next alarm expires after %ld seconds.", alarmTime);
}
}}
diff --git a/src/FLoc_LocationProviderImpl.h b/src/FLoc_LocationProviderImpl.h
index e00f64c..5cdd1e8 100644
--- a/src/FLoc_LocationProviderImpl.h
+++ b/src/FLoc_LocationProviderImpl.h
@@ -32,8 +32,6 @@
#include <FBaseRtITimerEventListener.h>
#include <FBaseRtTimer.h>
#include <FLocLocationCriteria.h>
-#include <FSysAlarm.h>
-#include <FSysIAlarmEventListener.h>
#include <FBaseRt_Event.h>
#include <FLoc_Config.h>
#include "FLoc_ILocationManagerListener.h"
@@ -61,7 +59,6 @@ class _LocationProviderImpl
, public Tizen::Locations::_ILocProviderEventListener
, public Tizen::App::IActiveAppEventListener
, public Tizen::Base::Runtime::ITimerEventListener
- , public Tizen::System::IAlarmEventListener
{
public:
/**
@@ -162,6 +159,11 @@ private:
virtual void OnLocationUpdated(RequestId reqId, const Tizen::Locations::Location& location);
/**
+ * @see @ref Tizen::Locations::_ILocationManagerListener::OnAlarmExpired()
+ */
+ virtual void OnAlarmExpired(void);
+
+ /**
* @see @ref Tizen::Locations::_ILocProviderEventListener::OnLocationEventReceivedN()
*/
virtual void OnLocationEventReceivedN(RequestId reqId, Tizen::Locations::Location& location);
@@ -177,14 +179,14 @@ private:
virtual void OnRegionMonitoringStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus);
/**
- * @see @ref Tizen::App::IActiveAppEventListener::OnActiveAppChanged()
+ * @see @ref Tizen::Locations::_ILocProviderEventListener::OnAlarmExpiredEventReceived()
*/
- virtual void OnActiveAppChanged(const Tizen::App::AppId& appId);
+ virtual void OnAlarmExpiredEventReceived(void);
/**
- * @see @ref Tizen::System::IAlarmEventListener::OnAlarmExpired()
+ * @see @ref Tizen::App::IActiveAppEventListener::OnActiveAppChanged()
*/
- virtual void OnAlarmExpired(Tizen::System::Alarm& alarm);
+ virtual void OnActiveAppChanged(const Tizen::App::AppId& appId);
/**
* @see @ref Tizen::Base::Runtime::ITimerEventListener::OnTimerExpired()
@@ -219,13 +221,13 @@ private:
//
// @since 2.0
//
- void HandleLocationUpdate(Tizen::Locations::Location& location, bool isLocationValid);
+ void HandleLocationUpdate(Tizen::Locations::Location& location, bool isLocationValid, bool isPrivilegeDenied);
// This method handles the region monitoring.
//
// @since 2.0
//
- void HandleRegionMonitoring(Tizen::Locations::Location& location, bool isLocationValid);
+ void HandleRegionMonitoring(Tizen::Locations::Location& location, bool isLocationValid, bool isPrivilegeDenied, bool isAccuracyMet);
// This method sends the callbacks to the applications regarding the Region events.
// @since 2.0
@@ -275,7 +277,7 @@ private:
, awakeEnabled(false)
, updateInterval(0)
, status(LOC_SVC_STATUS_IDLE)
- , type(_LOCATION_UPDATE_TYPE_NONE)
+ , type(_LOCATION_UPDATE_TYPE_NONE)
, reqId(-1)
, distanceThreshold(0.0)
, pLocation(null)
@@ -285,7 +287,7 @@ private:
~_LocationUpdater(void)
{
}
-
+
public:
bool firstLocationUpdate;
bool awakeEnabled;
@@ -294,18 +296,18 @@ private:
LocationUpdateType type;
RequestId reqId;
double distanceThreshold;
- std::unique_ptr<Tizen::Locations::Location> pLocation;
- }__locationUpdater;
-
+ std::unique_ptr< Tizen::Locations::Location > pLocation;
+ }
+ __locationUpdater;
+
class _RegionMonitor
{
public:
_RegionMonitor(void)
: reqId(-1)
, status(LOC_SVC_STATUS_IDLE)
- , speed (DEFAULT_AVG_SPEED)
+ , speed(DEFAULT_AVG_SPEED)
, pTimer(null)
- , pAlarm(null)
, pLocation(null)
, pRegionList(null)
{
@@ -314,16 +316,16 @@ private:
~_RegionMonitor(void)
{
}
-
+
public:
RequestId reqId;
LocationServiceStatus status;
double speed;
- std::unique_ptr<Tizen::Base::Runtime::Timer> pTimer;
- std::unique_ptr<Tizen::System::Alarm> pAlarm;
- std::unique_ptr<Tizen::Locations::Location> pLocation;
+ std::unique_ptr< Tizen::Base::Runtime::Timer > pTimer;
+ std::unique_ptr< Tizen::Locations::Location > pLocation;
std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > pRegionList;
- }__regionMonitor;
+ }
+ __regionMonitor;
LocationAccuracy __lastLocationAccuracy;
LocationCriteria __criteria;
diff --git a/src/FLoc_MathUtils.cpp b/src/FLoc_MathUtils.cpp
index f7f1c54..f050a6a 100644
--- a/src/FLoc_MathUtils.cpp
+++ b/src/FLoc_MathUtils.cpp
@@ -77,7 +77,7 @@ _MathUtils::GetShortestDistance(const Location& location, const Tizen::Base::Col
for (int i = 0; i < count; i++)
{
- const _RegionInfo* pRegionInfo = static_cast<const _RegionInfo*> (regionList.GetAt(i));
+ const _RegionInfo* pRegionInfo = static_cast< const _RegionInfo* >(regionList.GetAt(i));
if (pRegionInfo)
{
Coordinates regionCoordinate = pRegionInfo->GetCoordinate();
diff --git a/src/FLoc_MathUtils.h b/src/FLoc_MathUtils.h
index 7459b2d..018026b 100644
--- a/src/FLoc_MathUtils.h
+++ b/src/FLoc_MathUtils.h
@@ -29,7 +29,7 @@
namespace Tizen { namespace Base { namespace Collection
{
- class IList;
+class IList;
}}}
namespace Tizen { namespace Locations
diff --git a/src/FLoc_SyncLocationRequestInfo.h b/src/FLoc_SyncLocationRequestInfo.h
index f286707..d5b99c6 100644
--- a/src/FLoc_SyncLocationRequestInfo.h
+++ b/src/FLoc_SyncLocationRequestInfo.h
@@ -31,7 +31,6 @@
#include <FBaseRtTimer.h>
#include <FBaseRtITimerEventListener.h>
#include <FLocTypes.h>
-#include <FSysSystemTime.h>
namespace Tizen { namespace Locations
{
@@ -42,28 +41,52 @@ class _SyncLocationRequestInfo
: public Tizen::Base::Object
{
public:
- _SyncLocationRequestInfo(_LocationMonitor* pLocMonitor, RequestId reqId)
+ _SyncLocationRequestInfo(_LocationMonitor* pLocMonitor, RequestId reqId, const Tizen::Base::DateTime& requestTime)
: Tizen::Base::Object()
+ , __oldLocTime(requestTime)
, __pLocMonitor(pLocMonitor)
+ , __pTimer(null)
, __reqId(reqId)
, __tickCount(0)
{
- Tizen::System::SystemTime::GetCurrentTime(__requestTime);
}
~_SyncLocationRequestInfo(void) {}
_LocationMonitor* GetLocationMonitor(void) const {return __pLocMonitor;}
+ result StartTimer(Tizen::Base::Runtime::ITimerEventListener& listener)
+ {
+ result r = E_SUCCESS;
+
+ if (__pTimer == null)
+ {
+ std::unique_ptr< Tizen::Base::Runtime::Timer > pTimer(new (std::nothrow) Tizen::Base::Runtime::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(listener);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to construct the timer.", GetErrorMessage(r));
+
+ __pTimer = std::move(pTimer);
+ }
+
+ const int DEFAULT_TIME_OUT = 1000;
+ r = __pTimer->Start(DEFAULT_TIME_OUT);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the timer.", GetErrorMessage(r));
+ __tickCount++;
+ return E_SUCCESS;
+ }
+
+ bool Equals(const Tizen::Base::Runtime::Timer& timer) {return __pTimer->Equals(timer);}
+
RequestId GetRequestId(void) const {return __reqId;}
int GetTickCount(void) const {return __tickCount;}
- void IncrementTickCount(void) { __tickCount++;}
-
bool IsInTime(const Tizen::Base::DateTime& timestamp)
{
- return (timestamp > __requestTime) ? true : false;
+ SysSecureLog(NID_LOC, "Previous location time is (%ls) and the current location time is (%ls)", __oldLocTime.ToString().GetPointer(), timestamp.ToString().GetPointer());
+ return (timestamp > __oldLocTime) ? true : false;
}
bool IsAccuracySatisfying(LocationAccuracy accuracy)
@@ -84,8 +107,9 @@ private:
_SyncLocationRequestInfo& operator =(const _SyncLocationRequestInfo& rhs);
private:
- Tizen::Base::DateTime __requestTime;
+ Tizen::Base::DateTime __oldLocTime;
_LocationMonitor* __pLocMonitor;
+ std::unique_ptr< Tizen::Base::Runtime::Timer > __pTimer;
RequestId __reqId;
int __tickCount;
}; //_SyncLocationRequestInfo
diff --git a/src/FLoc_WaitLoopListener.h b/src/FLoc_WaitLoopListener.h
deleted file mode 100644
index be41387..0000000
--- a/src/FLoc_WaitLoopListener.h
+++ /dev/null
@@ -1,68 +0,0 @@
-//
-// Open Service Platform
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file FLoc_WaitLoopListener.h
- * @brief This is the header file for the %_WaitLoopListener class.
- *
- * This header file contains the declarations of the %_WaitLoopListener class methods.
- */
-
-#ifndef _FLOC_INTERNAL_WAITLOOP_LISTENER_H_
-#define _FLOC_INTERNAL_WAITLOOP_LISTENER_H_
-
-#include <FBaseRtIWaitingLoopCondition.h>
-
-namespace Tizen { namespace Locations
-{
-
-class _WaitLoopListener
- : public Tizen::Base::Object
- , public Tizen::Base::Runtime::IWaitingLoopCondition
-{
-public:
- _WaitLoopListener(void)
- : Tizen::Base::Object()
- , __isThreadInitialized(false)
- {
- }
-
- ~_WaitLoopListener(void)
- {
- }
-
- void SetValue(bool isInit)
- {
- __isThreadInitialized = isInit;
- }
-
- bool GetValue(void)
- {
- return __isThreadInitialized;
- }
-
-private:
- virtual bool IsMet(void)
- {
- return (__isThreadInitialized == true) ? true : false;
- }
-
-private:
- bool __isThreadInitialized;
-} ;// class _WaitLoopListener
-}} // Tizen::Locations
-#endif // _FLOC_INTERNAL_WAITLOOP_LISTENER_H_ \ No newline at end of file