summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryingjiew <yingjiewang@codeaurora.org>2021-11-11 10:27:32 +0800
committeryingjiew <yingjiewang@codeaurora.org>2021-12-01 15:26:20 +0800
commit910eaec42f840aaeddca3caca431905e9361b64f (patch)
treec44990b095571b27218eb9ded574417134324112
parent648683feefe63134f222a68fd4f560114568961f (diff)
Mutex member mGnssCbIface that shared cross thread
To avoid race condtion, add mutex protection when access to shared member. Change-Id: Ib7b34f9adba07162936c64b92dd771e367499e99 CRs-Fixed: 3073005
-rw-r--r--android/aidl-impl/location_api/GnssAPIClient.cpp33
1 files changed, 17 insertions, 16 deletions
diff --git a/android/aidl-impl/location_api/GnssAPIClient.cpp b/android/aidl-impl/location_api/GnssAPIClient.cpp
index 1caa0ad..b9d9b10 100644
--- a/android/aidl-impl/location_api/GnssAPIClient.cpp
+++ b/android/aidl-impl/location_api/GnssAPIClient.cpp
@@ -79,7 +79,7 @@ void GnssAPIClient::gnssUpdateCallbacks(const shared_ptr<IGnssCallback>& gpsCb)
mGnssCbIface = gpsCb;
mMutex.unlock();
- if (mGnssCbIface != nullptr) {
+ if (gpsCb != nullptr) {
setCallbacks();
}
}
@@ -148,23 +148,24 @@ void GnssAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask)
LOC_LOGD("%s]: (%02x)", __FUNCTION__, capabilitiesMask);
mLocationCapabilitiesMask = capabilitiesMask;
mLocationCapabilitiesCached = true;
+ mMutex.lock();
+ auto gnssCbIface(mGnssCbIface);
+ mMutex.unlock();
- if (mGnssCbIface != nullptr) {
- uint32_t capabilities = 0;
- if (capabilitiesMask & LOCATION_CAPABILITIES_CONSTELLATION_ENABLEMENT_BIT) {
- capabilities |= IGnssCallback::CAPABILITY_SATELLITE_BLOCKLIST;
- }
- // CORRELATION_VECTOR not supported.
- capabilities |= IGnssCallback::CAPABILITY_SATELLITE_PVT;
- if (capabilitiesMask & LOCATION_CAPABILITIES_MEASUREMENTS_CORRECTION_BIT) {
- capabilities |= IGnssCallback::CAPABILITY_MEASUREMENT_CORRECTIONS_FOR_DRIVING;
- }
+ uint32_t capabilities = 0;
+ if (capabilitiesMask & LOCATION_CAPABILITIES_CONSTELLATION_ENABLEMENT_BIT) {
+ capabilities |= IGnssCallback::CAPABILITY_SATELLITE_BLOCKLIST;
+ }
+ // CORRELATION_VECTOR not supported.
+ capabilities |= IGnssCallback::CAPABILITY_SATELLITE_PVT;
+ if (capabilitiesMask & LOCATION_CAPABILITIES_MEASUREMENTS_CORRECTION_BIT) {
+ capabilities |= IGnssCallback::CAPABILITY_MEASUREMENT_CORRECTIONS_FOR_DRIVING;
+ }
- if (mGnssCbIface != nullptr) {
- auto r = mGnssCbIface->gnssSetCapabilitiesCb(capabilities);
- if (!r.isOk()) {
- LOC_LOGe("Error from AIDL gnssSetCapabilitiesCb");
- }
+ if (gnssCbIface != nullptr) {
+ auto r = gnssCbIface->gnssSetCapabilitiesCb(capabilities);
+ if (!r.isOk()) {
+ LOC_LOGe("Error from AIDL gnssSetCapabilitiesCb");
}
}
}