Prevent gps stuck on if multiple starts are called
If framework happens to call start of session multiple times without calling stop first, it can cause a session to get stuck on without any way to stop it CRs-fixed: 2083756 Change-Id: Ic871d870ca67c9465438f8494e381bfbcb85a830
This commit is contained in:
parent
7cc7da646c
commit
c1da12aa2e
2 changed files with 16 additions and 9 deletions
|
@ -223,7 +223,8 @@ LocationAPIClientBase::LocationAPIClientBase() :
|
||||||
mGeofenceBreachCallback(nullptr),
|
mGeofenceBreachCallback(nullptr),
|
||||||
mBatchingStatusCallback(nullptr),
|
mBatchingStatusCallback(nullptr),
|
||||||
mLocationAPI(nullptr),
|
mLocationAPI(nullptr),
|
||||||
mBatchSize(-1)
|
mBatchSize(-1),
|
||||||
|
mTracking(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
// use recursive mutex, in case callback come from the same thread
|
// use recursive mutex, in case callback come from the same thread
|
||||||
|
@ -303,14 +304,18 @@ uint32_t LocationAPIClientBase::locAPIStartTracking(LocationOptions& options)
|
||||||
uint32_t retVal = LOCATION_ERROR_GENERAL_FAILURE;
|
uint32_t retVal = LOCATION_ERROR_GENERAL_FAILURE;
|
||||||
pthread_mutex_lock(&mMutex);
|
pthread_mutex_lock(&mMutex);
|
||||||
if (mLocationAPI) {
|
if (mLocationAPI) {
|
||||||
uint32_t session = mLocationAPI->startTracking(options);
|
if (mTracking) {
|
||||||
LOC_LOGI("%s:%d] start new session: %d", __FUNCTION__, __LINE__, session);
|
LOC_LOGW("%s:%d] Existing tracking session present", __FUNCTION__, __LINE__);
|
||||||
// onResponseCb might be called from other thread immediately after
|
} else {
|
||||||
// startTracking returns, so we are not going to unlock mutex
|
uint32_t session = mLocationAPI->startTracking(options);
|
||||||
// until StartTrackingRequest is pushed into mRequestQueues[REQUEST_TRACKING]
|
LOC_LOGI("%s:%d] start new session: %d", __FUNCTION__, __LINE__, session);
|
||||||
mRequestQueues[REQUEST_TRACKING].reset(session);
|
// onResponseCb might be called from other thread immediately after
|
||||||
mRequestQueues[REQUEST_TRACKING].push(new StartTrackingRequest(*this));
|
// startTracking returns, so we are not going to unlock mutex
|
||||||
|
// until StartTrackingRequest is pushed into mRequestQueues[REQUEST_TRACKING]
|
||||||
|
mRequestQueues[REQUEST_TRACKING].reset(session);
|
||||||
|
mRequestQueues[REQUEST_TRACKING].push(new StartTrackingRequest(*this));
|
||||||
|
mTracking = true;
|
||||||
|
}
|
||||||
|
|
||||||
retVal = LOCATION_ERROR_SUCCESS;
|
retVal = LOCATION_ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -328,6 +333,7 @@ void LocationAPIClientBase::locAPIStopTracking()
|
||||||
if (session > 0) {
|
if (session > 0) {
|
||||||
mRequestQueues[REQUEST_TRACKING].push(new StopTrackingRequest(*this));
|
mRequestQueues[REQUEST_TRACKING].push(new StopTrackingRequest(*this));
|
||||||
mLocationAPI->stopTracking(session);
|
mLocationAPI->stopTracking(session);
|
||||||
|
mTracking = false;
|
||||||
} else {
|
} else {
|
||||||
LOC_LOGE("%s:%d] invalid session: %d.", __FUNCTION__, __LINE__, session);
|
LOC_LOGE("%s:%d] invalid session: %d.", __FUNCTION__, __LINE__, session);
|
||||||
}
|
}
|
||||||
|
|
|
@ -539,6 +539,7 @@ private:
|
||||||
BiDict<GeofenceBreachTypeMask> mGeofenceBiDict;
|
BiDict<GeofenceBreachTypeMask> mGeofenceBiDict;
|
||||||
BiDict<SessionEntity> mSessionBiDict;
|
BiDict<SessionEntity> mSessionBiDict;
|
||||||
int32_t mBatchSize;
|
int32_t mBatchSize;
|
||||||
|
bool mTracking;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* LOCATION_API_CLINET_BASE_H */
|
#endif /* LOCATION_API_CLINET_BASE_H */
|
||||||
|
|
Loading…
Reference in a new issue