summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2017-06-13 07:27:10 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2017-06-13 07:27:10 +0000
commitdecf9059939f48caa600c4747de3806cee6f58dd (patch)
treef766a43bbd9d91b311ff22065ae0e8150e62051a
parent239133816ba83f45879230edba9251681157e02b (diff)
parent79a065efe9ac18253c55fbcfc2fa8341a38ec539 (diff)
downloadgps-decf9059939f48caa600c4747de3806cee6f58dd.tar.gz
release-request-2ec08f61-b94c-464b-8a22-2d354ef71488-for-git_oc-dr1-release-4094616 snap-temp-L42100000073564610
Change-Id: Idfbb1303475eadd3e2f60705c1eb367d43a048dd
-rw-r--r--msm8998/location/LocationAPIClientBase.cpp95
-rw-r--r--msm8998/location/LocationAPIClientBase.h3
2 files changed, 51 insertions, 47 deletions
diff --git a/msm8998/location/LocationAPIClientBase.cpp b/msm8998/location/LocationAPIClientBase.cpp
index 5d058f6..89dc538 100644
--- a/msm8998/location/LocationAPIClientBase.cpp
+++ b/msm8998/location/LocationAPIClientBase.cpp
@@ -34,6 +34,7 @@
#include "LocationAPIClientBase.h"
#define FLP_CONF_FILE "/vendor/etc/flp.conf"
+#define GEOFENCE_SESSION_ID -1
LocationAPIClientBase::LocationAPIClientBase() :
mTrackingCallback(nullptr),
@@ -41,7 +42,8 @@ LocationAPIClientBase::LocationAPIClientBase() :
mGeofenceBreachCallback(nullptr),
mLocationAPI(nullptr),
mLocationControlAPI(nullptr),
- mBatchSize(-1)
+ mBatchSize(-1),
+ mEnabled(false)
{
// use recursive mutex, in case callback come from the same thread
@@ -138,7 +140,7 @@ uint32_t LocationAPIClientBase::locAPIStartTracking(LocationOptions& options)
RequestQueue* requests = mRequestQueues[REQUEST_TRACKING];
if (requests) {
delete requests;
- requests = nullptr;
+ mRequestQueues[REQUEST_TRACKING] = nullptr;
}
uint32_t session = mLocationAPI->startTracking(options);
LOC_LOGI("%s:%d] start new session: %d", __FUNCTION__, __LINE__, session);
@@ -225,7 +227,7 @@ uint32_t LocationAPIClientBase::locAPIStartSession(uint32_t id, uint32_t session
RequestQueue* requests = mRequestQueues[REQUEST_TRACKING];
if (requests) {
delete requests;
- requests = nullptr;
+ mRequestQueues[REQUEST_TRACKING] = nullptr;
}
trackingSession = mLocationAPI->startTracking(options);
LOC_LOGI("%s:%d] start new session: %d", __FUNCTION__, __LINE__, trackingSession);
@@ -236,7 +238,7 @@ uint32_t LocationAPIClientBase::locAPIStartSession(uint32_t id, uint32_t session
RequestQueue* requests = mRequestQueues[REQUEST_BATCHING];
if (requests) {
delete requests;
- requests = nullptr;
+ mRequestQueues[REQUEST_BATCHING] = nullptr;
}
batchingSession = mLocationAPI->startBatching(options);
LOC_LOGI("%s:%d] start new session: %d", __FUNCTION__, __LINE__, batchingSession);
@@ -337,7 +339,7 @@ uint32_t LocationAPIClientBase::locAPIUpdateSessionOptions(uint32_t id, uint32_t
RequestQueue* requests = mRequestQueues[REQUEST_TRACKING];
if (requests) {
delete requests;
- requests = nullptr;
+ mRequestQueues[REQUEST_TRACKING] = nullptr;
}
trackingSession = mLocationAPI->startTracking(options);
LOC_LOGI("%s:%d] start new session: %d",
@@ -363,7 +365,7 @@ uint32_t LocationAPIClientBase::locAPIUpdateSessionOptions(uint32_t id, uint32_t
RequestQueue* requests = mRequestQueues[REQUEST_BATCHING];
if (requests) {
delete requests;
- requests = nullptr;
+ mRequestQueues[REQUEST_BATCHING] = nullptr;
}
batchingSession = mLocationAPI->startBatching(options);
LOC_LOGI("%s:%d] start new session: %d",
@@ -421,15 +423,16 @@ uint32_t LocationAPIClientBase::locAPIAddGeofences(
pthread_mutex_lock(&mMutex);
if (mLocationAPI) {
RequestQueue* requests = mRequestQueues[REQUEST_GEOFENCE];
- if (requests) {
- delete requests;
+ if (!requests) {
+ // Create a new RequestQueue for Geofenceing if we've not had one.
+ // The RequestQueue will be released when LocationAPIClientBase is released.
+ requests = new RequestQueue(GEOFENCE_SESSION_ID);
+ mRequestQueues[REQUEST_GEOFENCE] = requests;
}
uint32_t* sessions = mLocationAPI->addGeofences(count, options, data);
if (sessions) {
LOC_LOGI("%s:%d] start new sessions: %p", __FUNCTION__, __LINE__, sessions);
- requests = new RequestQueue(-1);
requests->push(new AddGeofencesRequest(*this));
- mRequestQueues[REQUEST_GEOFENCE] = requests;
for (size_t i = 0; i < count; i++) {
mGeofenceBiDict.set(ids[i], sessions[i], options[i].breachTypeMask);
@@ -587,7 +590,7 @@ void LocationAPIClientBase::locAPIGnssNiResponse(uint32_t id, GnssNiResponse res
RequestQueue* requests = mRequestQueues[REQUEST_NIRESPONSE];
if (requests) {
delete requests;
- requests = nullptr;
+ mRequestQueues[REQUEST_NIRESPONSE] = nullptr;
}
uint32_t session = id;
mLocationAPI->gnssNiResponse(id, response);
@@ -607,7 +610,7 @@ uint32_t LocationAPIClientBase::locAPIGnssDeleteAidingData(GnssAidingData& data)
RequestQueue* requests = mRequestQueues[REQUEST_DELETEAIDINGDATA];
if (requests) {
delete requests;
- requests = nullptr;
+ mRequestQueues[REQUEST_DELETEAIDINGDATA] = nullptr;
}
uint32_t session = mLocationControlAPI->gnssDeleteAidingData(data);
LOC_LOGI("%s:%d] start new session: %d", __FUNCTION__, __LINE__, session);
@@ -626,19 +629,24 @@ uint32_t LocationAPIClientBase::locAPIEnable(LocationTechnologyType techType)
{
uint32_t retVal = LOCATION_ERROR_GENERAL_FAILURE;
pthread_mutex_lock(&mMutex);
- if (mLocationControlAPI) {
+ if (mEnabled) {
+ // just return success if already enabled
+ retVal = LOCATION_ERROR_SUCCESS;
+ } else if (mLocationControlAPI) {
RequestQueue* requests = mRequestQueues[REQUEST_CONTROL];
if (requests) {
delete requests;
- requests = nullptr;
+ mRequestQueues[REQUEST_CONTROL] = nullptr;
}
uint32_t session = mLocationControlAPI->enable(techType);
LOC_LOGI("%s:%d] start new session: %d", __FUNCTION__, __LINE__, session);
requests = new RequestQueue(session);
- requests->push(new EnableRequest(*this));
mRequestQueues[REQUEST_CONTROL] = requests;
-
- retVal = LOCATION_ERROR_SUCCESS;
+ if (requests) {
+ requests->push(new EnableRequest(*this));
+ retVal = LOCATION_ERROR_SUCCESS;
+ mEnabled = true;
+ }
}
pthread_mutex_unlock(&mMutex);
@@ -648,7 +656,7 @@ uint32_t LocationAPIClientBase::locAPIEnable(LocationTechnologyType techType)
void LocationAPIClientBase::locAPIDisable()
{
pthread_mutex_lock(&mMutex);
- if (mLocationControlAPI) {
+ if (mEnabled && mLocationControlAPI) {
uint32_t session = 0;
RequestQueue* requests = mRequestQueues[REQUEST_CONTROL];
if (requests) {
@@ -656,6 +664,7 @@ void LocationAPIClientBase::locAPIDisable()
if (session > 0) {
requests->push(new DisableRequest(*this));
mLocationControlAPI->disable(session);
+ mEnabled = false;
}
}
}
@@ -666,7 +675,8 @@ uint32_t LocationAPIClientBase::locAPIGnssUpdateConfig(GnssConfig config)
{
uint32_t retVal = LOCATION_ERROR_GENERAL_FAILURE;
if (memcmp(&mConfig, &config, sizeof(GnssConfig)) == 0) {
- LOC_LOGE("%s:%d] GnssConfig is identical to previous call", __FUNCTION__, __LINE__);
+ LOC_LOGV("%s:%d] GnssConfig is identical to previous call", __FUNCTION__, __LINE__);
+ retVal = LOCATION_ERROR_SUCCESS;
return retVal;
}
@@ -676,17 +686,17 @@ uint32_t LocationAPIClientBase::locAPIGnssUpdateConfig(GnssConfig config)
memcpy(&mConfig, &config, sizeof(GnssConfig));
uint32_t session = 0;
- RequestQueue* requests = mRequestQueues[REQUEST_CONTROL];
+ RequestQueue* requests = mRequestQueues[REQUEST_CONFIG];
+ uint32_t* idArray = mLocationControlAPI->gnssUpdateConfig(config);
+ LOC_LOGV("%s:%d] gnssUpdateConfig return array: %p", __FUNCTION__, __LINE__, idArray);
+ if (!requests && idArray != nullptr) {
+ requests = new RequestQueue(idArray[0]);
+ mRequestQueues[REQUEST_CONFIG] = requests;
+ }
if (requests) {
- session = requests->getSession();
- if (session > 0) {
- requests->push(new GnssUpdateConfigRequest(*this));
- uint32_t* idArray = mLocationControlAPI->gnssUpdateConfig(config);
- LOC_LOGV("%s:%d] gnssUpdateConfig return array: %p", __FUNCTION__, __LINE__, idArray);
- }
+ requests->push(new GnssUpdateConfigRequest(*this));
+ retVal = LOCATION_ERROR_SUCCESS;
}
-
- retVal = LOCATION_ERROR_SUCCESS;
}
pthread_mutex_unlock(&mMutex);
return retVal;
@@ -751,10 +761,11 @@ void LocationAPIClientBase::onCollectiveResponseCb(
}
}
LocationAPIRequest* request = nullptr;
- if (count > 0 && ids)
- request = getRequestBySession(ids[0]);
- if (!request)
- request = getGeofencesRequest();
+ pthread_mutex_lock(&mMutex);
+ if (mRequestQueues[REQUEST_GEOFENCE] != nullptr) {
+ request = mRequestQueues[REQUEST_GEOFENCE]->pop();
+ }
+ pthread_mutex_unlock(&mMutex);
if (request) {
request->onCollectiveResponse(count, errors, ids);
delete request;
@@ -786,8 +797,11 @@ void LocationAPIClientBase::onCtrlCollectiveResponseCb(
}
}
LocationAPIRequest* request = nullptr;
- if (count > 0 && ids)
- request = getRequestBySession(ids[0]);
+ pthread_mutex_lock(&mMutex);
+ if (mRequestQueues[REQUEST_CONFIG] != nullptr) {
+ request = mRequestQueues[REQUEST_CONFIG]->pop();
+ }
+ pthread_mutex_unlock(&mMutex);
if (request) {
request->onCollectiveResponse(count, errors, ids);
delete request;
@@ -801,6 +815,7 @@ LocationAPIClientBase::getRequestBySession(uint32_t session)
LocationAPIRequest* request = nullptr;
for (int i = 0; i < REQUEST_MAX; i++) {
if (i != REQUEST_GEOFENCE &&
+ i != REQUEST_CONFIG &&
mRequestQueues[i] &&
mRequestQueues[i]->getSession() == session) {
request = mRequestQueues[i]->pop();
@@ -810,15 +825,3 @@ LocationAPIClientBase::getRequestBySession(uint32_t session)
pthread_mutex_unlock(&mMutex);
return request;
}
-
-LocationAPIClientBase::LocationAPIRequest*
-LocationAPIClientBase::getGeofencesRequest()
-{
- pthread_mutex_lock(&mMutex);
- LocationAPIRequest* request = nullptr;
- if (mRequestQueues[REQUEST_GEOFENCE]) {
- request = mRequestQueues[REQUEST_GEOFENCE]->pop();
- }
- pthread_mutex_unlock(&mMutex);
- return request;
-}
diff --git a/msm8998/location/LocationAPIClientBase.h b/msm8998/location/LocationAPIClientBase.h
index 832dca8..0805d7c 100644
--- a/msm8998/location/LocationAPIClientBase.h
+++ b/msm8998/location/LocationAPIClientBase.h
@@ -50,6 +50,7 @@ enum REQUEST_TYPE {
REQUEST_NIRESPONSE,
REQUEST_DELETEAIDINGDATA,
REQUEST_CONTROL,
+ REQUEST_CONFIG,
REQUEST_MAX,
};
@@ -446,7 +447,6 @@ private:
};
LocationAPIRequest* getRequestBySession(uint32_t session);
- LocationAPIRequest* getGeofencesRequest();
private:
pthread_mutex_t mMutex;
@@ -462,6 +462,7 @@ private:
RequestQueue* mRequestQueues[REQUEST_MAX];
std::map<uint32_t, SessionEntity> mSessionMap;
int32_t mBatchSize;
+ bool mEnabled;
GnssConfig mConfig;
};