Report Locations to AFW only when active tracking

We want to avoid reporting locations to AFW while
measurements is active but tracking is not active.

Bug: 157440593
Test: No location report during measurement only request.


Change-Id: Icbb581199e6f5eba3cfe81cb6ab39337bb7ea51a
Merged-In: Icbb581199e6f5eba3cfe81cb6ab39337bb7ea51a
CRs-fixed: 2441384
(cherry picked from commit a0ca9c02a5ea830c95a376628988d285935a448f)
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;
 };