[automerger skipped] Merge QQ3A.200605.002 into master am: 7cc48ad849 -s ours am: ef10dd79e8 -s ours am: 89d54d71a0 -s ours am: 5568245489 -s ours am: 8a208db46b -s ours

am skip reason: Change-Id If818e3387646f6fffeef422bafe580543b4d8c57 with SHA-1 a4cc21bf27 is in history

Original change: https://android-review.googlesource.com/c/platform/hardware/qcom/sdm845/gps/+/1323621

Change-Id: Ib3c5e7b43eb3792f397b9269a66888e20e6858a1
diff --git a/sdm845/android/location_api/GnssAPIClient.cpp b/sdm845/android/location_api/GnssAPIClient.cpp
index 61b8b38..b799981 100644
--- a/sdm845/android/location_api/GnssAPIClient.cpp
+++ b/sdm845/android/location_api/GnssAPIClient.cpp
@@ -57,7 +57,8 @@
     mGnssNiCbIface(nullptr),
     mControlClient(new LocationAPIControlClient()),
     mLocationCapabilitiesMask(0),
-    mLocationCapabilitiesCached(false)
+    mLocationCapabilitiesCached(false),
+    mTracking(false)
 {
     LOC_LOGD("%s]: (%p %p)", __FUNCTION__, &gpsCb, &niCb);
 
@@ -141,6 +142,11 @@
 bool GnssAPIClient::gnssStart()
 {
     LOC_LOGD("%s]: ()", __FUNCTION__);
+
+    mMutex.lock();
+    mTracking = true;
+    mMutex.unlock();
+
     bool retVal = true;
     locAPIStartTracking(mTrackingOptions);
     return retVal;
@@ -149,6 +155,11 @@
 bool GnssAPIClient::gnssStop()
 {
     LOC_LOGD("%s]: ()", __FUNCTION__);
+
+    mMutex.lock();
+    mTracking = false;
+    mMutex.unlock();
+
     bool retVal = true;
     locAPIStopTracking();
     return retVal;
@@ -349,11 +360,17 @@
 
 void GnssAPIClient::onTrackingCb(Location location)
 {
-    LOC_LOGD("%s]: (flags: %02x)", __FUNCTION__, location.flags);
     mMutex.lock();
     auto gnssCbIface(mGnssCbIface);
+    bool isTracking = mTracking;
     mMutex.unlock();
 
+    LOC_LOGD("%s]: (flags: %02x isTracking: %d)", __FUNCTION__, location.flags, isTracking);
+
+    if (!isTracking) {
+        return;
+    }
+
     if (gnssCbIface != nullptr) {
         GnssLocation gnssLocation;
         convertGnssLocation(location, gnssLocation);
diff --git a/sdm845/android/location_api/GnssAPIClient.h b/sdm845/android/location_api/GnssAPIClient.h
index 82f8fbf..39e919e 100644
--- a/sdm845/android/location_api/GnssAPIClient.h
+++ b/sdm845/android/location_api/GnssAPIClient.h
@@ -98,6 +98,7 @@
     LocationAPIControlClient* mControlClient;
     LocationCapabilitiesMask mLocationCapabilitiesMask;
     bool mLocationCapabilitiesCached;
+    bool mTracking;
     TrackingOptions mTrackingOptions;
 };