[automerger skipped] Merge Android R (rvc-dev-plus-aosp-without-vendor@6692709) am: eda7fc5438 -s ours am: c7da72b771 -s ours am: 492e1e2532 -s ours

am skip reason: Change-Id I6a07c809d90b8e567a3e5027b2eb4c499eeedb1b with SHA-1 89d54d71a0 is in history

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

Change-Id: I9e0cf1b6c4e5c24b82b186b47477ae732b50dddf
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;
 };