locAPIRemoveGeofences roolback to async result notification
locAPIRemoveGeofences is rolled back to async result notification, using the RemoveGeofencesRequest, but using a new temporal bidict of sessions & ids, to avoid a previous race condition using the wrong id when removing and adding a geofence. Change-Id: Icd85373b82e620ea4059431f0c3d13c95f99ca3c CRs-fixed: 2132679
This commit is contained in:
parent
57640c9f33
commit
63c4d2f67b
2 changed files with 24 additions and 12 deletions
18
location/LocationAPIClientBase.cpp
Normal file → Executable file
18
location/LocationAPIClientBase.cpp
Normal file → Executable file
|
@ -614,26 +614,24 @@ void LocationAPIClientBase::locAPIRemoveGeofences(size_t count, uint32_t* ids)
|
|||
}
|
||||
|
||||
if (mRequestQueues[REQUEST_GEOFENCE].getSession() == GEOFENCE_SESSION_ID) {
|
||||
BiDict<GeofenceBreachTypeMask>* removedGeofenceBiDict =
|
||||
new BiDict<GeofenceBreachTypeMask>();
|
||||
size_t j = 0;
|
||||
uint32_t id_cb;
|
||||
LocationError err;
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
sessions[j] = mGeofenceBiDict.getSession(ids[i]);
|
||||
id_cb = ids[i];
|
||||
if (sessions[j] > 0) {
|
||||
GeofenceBreachTypeMask type = mGeofenceBiDict.getExtBySession(sessions[j]);
|
||||
mGeofenceBiDict.rmBySession(sessions[j]);
|
||||
err = LOCATION_ERROR_SUCCESS;
|
||||
onRemoveGeofencesCb(1, &err, &id_cb);
|
||||
removedGeofenceBiDict->set(ids[i], sessions[j], type);
|
||||
j++;
|
||||
} else {
|
||||
err = LOCATION_ERROR_ID_UNKNOWN;
|
||||
onRemoveGeofencesCb(1, &err, &id_cb);
|
||||
}
|
||||
}
|
||||
|
||||
if (j > 0) {
|
||||
mRequestQueues[REQUEST_GEOFENCE].push(new RemoveGeofencesRequest(*this));
|
||||
mRequestQueues[REQUEST_GEOFENCE].push(new RemoveGeofencesRequest(*this,
|
||||
removedGeofenceBiDict));
|
||||
mLocationAPI->removeGeofences(j, sessions);
|
||||
} else {
|
||||
delete(removedGeofenceBiDict);
|
||||
}
|
||||
} else {
|
||||
LOC_LOGE("%s:%d] invalid session: %d.", __FUNCTION__, __LINE__,
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <map>
|
||||
|
||||
#include "LocationAPI.h"
|
||||
#include "platform_lib_log_util.h"
|
||||
|
||||
enum SESSION_MODE {
|
||||
SESSION_MODE_NONE = 0,
|
||||
|
@ -469,11 +470,24 @@ private:
|
|||
|
||||
class RemoveGeofencesRequest : public LocationAPIRequest {
|
||||
public:
|
||||
RemoveGeofencesRequest(LocationAPIClientBase& API) : mAPI(API) {}
|
||||
RemoveGeofencesRequest(LocationAPIClientBase& API,
|
||||
BiDict<GeofenceBreachTypeMask>* removedGeofenceBiDict) :
|
||||
mAPI(API), mRemovedGeofenceBiDict(removedGeofenceBiDict) {}
|
||||
inline void onCollectiveResponse(size_t count, LocationError* errors, uint32_t* sessions) {
|
||||
// No need to handle collectiveResponse, cbs already notified
|
||||
if (nullptr != mRemovedGeofenceBiDict) {
|
||||
uint32_t *ids = (uint32_t*)malloc(sizeof(uint32_t) * count);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
ids[i] = mRemovedGeofenceBiDict->getId(sessions[i]);
|
||||
}
|
||||
mAPI.onRemoveGeofencesCb(count, errors, ids);
|
||||
free(ids);
|
||||
delete(mRemovedGeofenceBiDict);
|
||||
} else {
|
||||
LOC_LOGE("%s:%d] Unable to access removed geofences data.", __FUNCTION__, __LINE__);
|
||||
}
|
||||
}
|
||||
LocationAPIClientBase& mAPI;
|
||||
BiDict<GeofenceBreachTypeMask>* mRemovedGeofenceBiDict;
|
||||
};
|
||||
|
||||
class ModifyGeofencesRequest : public LocationAPIRequest {
|
||||
|
|
Loading…
Reference in a new issue