diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2017-07-31 17:31:08 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-07-31 17:31:08 +0000 |
commit | 80b07fc4de0fb38f16b78d8ee2e60a817ae90fdb (patch) | |
tree | bc0492cb8c963e45d7768a2d322bcb8fdfa6a53c | |
parent | fe5db8fbedcc5d2a8fcc6e3996e37853090e609d (diff) | |
parent | 8c5f3c170c15131ba4986dabc5009089d565cd5e (diff) | |
download | gps-80b07fc4de0fb38f16b78d8ee2e60a817ae90fdb.tar.gz |
Merge "Prevent gps stuck on if multiple starts are called" into oc-dr1-dev
-rw-r--r-- | msm8998/location/LocationAPIClientBase.cpp | 34 | ||||
-rw-r--r-- | msm8998/location/LocationAPIClientBase.h | 1 |
2 files changed, 21 insertions, 14 deletions
diff --git a/msm8998/location/LocationAPIClientBase.cpp b/msm8998/location/LocationAPIClientBase.cpp index 89dc538..606a7b7 100644 --- a/msm8998/location/LocationAPIClientBase.cpp +++ b/msm8998/location/LocationAPIClientBase.cpp @@ -43,7 +43,8 @@ LocationAPIClientBase::LocationAPIClientBase() : mLocationAPI(nullptr), mLocationControlAPI(nullptr), mBatchSize(-1), - mEnabled(false) + mEnabled(false), + mTracking(false) { // use recursive mutex, in case callback come from the same thread @@ -137,20 +138,24 @@ uint32_t LocationAPIClientBase::locAPIStartTracking(LocationOptions& options) uint32_t retVal = LOCATION_ERROR_GENERAL_FAILURE; pthread_mutex_lock(&mMutex); if (mLocationAPI) { - RequestQueue* requests = mRequestQueues[REQUEST_TRACKING]; - if (requests) { - delete requests; - mRequestQueues[REQUEST_TRACKING] = nullptr; + if (mTracking) { + LOC_LOGW("%s:%d] Existing tracking session present", __FUNCTION__, __LINE__); + } else { + RequestQueue* requests = mRequestQueues[REQUEST_TRACKING]; + if (requests) { + delete requests; + mRequestQueues[REQUEST_TRACKING] = nullptr; + } + uint32_t session = mLocationAPI->startTracking(options); + LOC_LOGI("%s:%d] start new session: %d", __FUNCTION__, __LINE__, session); + // onResponseCb might be called from other thread immediately after + // startTracking returns, so we are not going to unlock mutex + // until StartTrackingRequest is pushed into mRequestQueues[REQUEST_TRACKING] + requests = new RequestQueue(session); + requests->push(new StartTrackingRequest(*this)); + mRequestQueues[REQUEST_TRACKING] = requests; + mTracking = true; } - uint32_t session = mLocationAPI->startTracking(options); - LOC_LOGI("%s:%d] start new session: %d", __FUNCTION__, __LINE__, session); - // onResponseCb might be called from other thread immediately after - // startTracking returns, so we are not going to unlock mutex - // until StartTrackingRequest is pushed into mRequestQueues[REQUEST_TRACKING] - requests = new RequestQueue(session); - requests->push(new StartTrackingRequest(*this)); - mRequestQueues[REQUEST_TRACKING] = requests; - retVal = LOCATION_ERROR_SUCCESS; } pthread_mutex_unlock(&mMutex); @@ -169,6 +174,7 @@ void LocationAPIClientBase::locAPIStopTracking() if (session > 0) { requests->push(new StopTrackingRequest(*this)); mLocationAPI->stopTracking(session); + mTracking = false; } } } diff --git a/msm8998/location/LocationAPIClientBase.h b/msm8998/location/LocationAPIClientBase.h index 0805d7c..3a1d994 100644 --- a/msm8998/location/LocationAPIClientBase.h +++ b/msm8998/location/LocationAPIClientBase.h @@ -463,6 +463,7 @@ private: std::map<uint32_t, SessionEntity> mSessionMap; int32_t mBatchSize; bool mEnabled; + bool mTracking; GnssConfig mConfig; }; |