Merge "Fix issue of incorrect set of used_in_fix flag"
diff --git a/android/Gnss.cpp b/android/Gnss.cpp
index 1412883..1d5a04e 100644
--- a/android/Gnss.cpp
+++ b/android/Gnss.cpp
@@ -121,6 +121,7 @@
     if (api != nullptr) {
         api->gnssUpdateCallbacks(mGnssCbIface, mGnssNiCbIface);
         api->locAPIEnable(LOCATION_TECHNOLOGY_TYPE_GNSS);
+        api->requestCapabilities();
     }
     return true;
 }
diff --git a/android/location_api/GnssAPIClient.cpp b/android/location_api/GnssAPIClient.cpp
index b4f0406..4cb3f7d 100644
--- a/android/location_api/GnssAPIClient.cpp
+++ b/android/location_api/GnssAPIClient.cpp
@@ -49,7 +49,8 @@
     LocationAPIClientBase(),
     mGnssCbIface(nullptr),
     mGnssNiCbIface(nullptr),
-    mLocationCapabilitiesMask(0)
+    mLocationCapabilitiesMask(0),
+    mLocationCapabilitiesCached(false)
 {
     LOC_LOGD("%s]: (%p %p)", __FUNCTION__, &gpsCb, &niCb);
 
@@ -218,11 +219,20 @@
     locAPIGnssUpdateConfig(gnssConfig);
 }
 
+void GnssAPIClient::requestCapabilities() {
+    // only send capablities if it's already cached, otherwise the first time LocationAPI
+    // is initialized, capabilities will be sent by LocationAPI
+    if (mLocationCapabilitiesCached) {
+        onCapabilitiesCb(mLocationCapabilitiesMask);
+    }
+}
+
 // callbacks
 void GnssAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask)
 {
     LOC_LOGD("%s]: (%02x)", __FUNCTION__, capabilitiesMask);
     mLocationCapabilitiesMask = capabilitiesMask;
+    mLocationCapabilitiesCached = true;
     if (mGnssCbIface != nullptr) {
         uint32_t data = 0;
         if ((capabilitiesMask & LOCATION_CAPABILITIES_TIME_BASED_TRACKING_BIT) ||
diff --git a/android/location_api/GnssAPIClient.h b/android/location_api/GnssAPIClient.h
index 1809c09..d447157 100644
--- a/android/location_api/GnssAPIClient.h
+++ b/android/location_api/GnssAPIClient.h
@@ -74,6 +74,7 @@
     inline LocationCapabilitiesMask gnssGetCapabilities() const {
         return mLocationCapabilitiesMask;
     }
+    void requestCapabilities();
 
     // callbacks we are interested in
     void onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) final;
@@ -90,6 +91,7 @@
     sp<IGnssNiCallback> mGnssNiCbIface;
 
     LocationCapabilitiesMask mLocationCapabilitiesMask;
+    bool mLocationCapabilitiesCached;
 
     LocationOptions mLocationOptions;
 };
diff --git a/core/ContextBase.cpp b/core/ContextBase.cpp
index a9858e2..565f70c 100644
--- a/core/ContextBase.cpp
+++ b/core/ContextBase.cpp
@@ -145,10 +145,8 @@
    /* inject supl config to modem with config values from config.xml or gps.conf, default 1 */
    mGps_conf.AGPS_CONFIG_INJECT = 1;
 
-   const char* GPS_CONF_FILE = "/etc/gps.conf";
-   const char* SAP_CONF_FILE = "/etc/sap.conf";
-   UTIL_READ_CONF(GPS_CONF_FILE, mGps_conf_table);
-   UTIL_READ_CONF(SAP_CONF_FILE, mSap_conf_table);
+   UTIL_READ_CONF(LOC_PATH_GPS_CONF, mGps_conf_table);
+   UTIL_READ_CONF(LOC_PATH_SAP_CONF, mSap_conf_table);
 }
 
 uint32_t ContextBase::getCarrierCapabilities() {
diff --git a/core/loc_gps.h b/core/loc_gps.h
index cdb1af6..2e495b8 100644
--- a/core/loc_gps.h
+++ b/core/loc_gps.h
@@ -2187,7 +2187,7 @@
      * Deliver GNSS configuration contents to HAL.
      * Parameters:
      *     config_data - a pointer to a char array which holds what usually is expected from
-                         file(/etc/gps.conf), i.e., a sequence of UTF8 strings separated by '\n'.
+                         file(/vendor/etc/gps.conf), i.e., a sequence of UTF8 strings separated by '\n'.
      *     length - total number of UTF8 characters in configuraiton data.
      *
      * IMPORTANT:
diff --git a/etc/Android.mk b/etc/Android.mk
index 025d3f7..d9eb0e1 100644
--- a/etc/Android.mk
+++ b/etc/Android.mk
@@ -5,7 +5,7 @@
 LOCAL_MODULE := gps.conf
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := ETC
-LOCAL_MODULE_PATH  := $(TARGET_OUT_ETC)/
+LOCAL_MODULE_PATH  := $(TARGET_OUT_VENDOR)/etc/
 LOCAL_SRC_FILES := gps.conf
 
 include $(BUILD_PREBUILT)
diff --git a/utils/MsgTask.cpp b/utils/MsgTask.cpp
index 2163511..a0dc57f 100644
--- a/utils/MsgTask.cpp
+++ b/utils/MsgTask.cpp
@@ -62,9 +62,9 @@
 }
 
 void MsgTask::destroy() {
+    LocThread* thread = mThread;
     msg_q_unblock((void*)mQ);
-    if (mThread) {
-        LocThread* thread = mThread;
+    if (thread) {
         mThread = NULL;
         delete thread;
     } else {
diff --git a/utils/loc_target.cpp b/utils/loc_target.cpp
index 1016861..53a8985 100644
--- a/utils/loc_target.cpp
+++ b/utils/loc_target.cpp
@@ -198,7 +198,7 @@
     static const char hw_platform_dep[]  =
         "/sys/devices/system/soc/soc0/hw_platform";
     static const char id_dep[]           = "/sys/devices/system/soc/soc0/id";
-    static const char mdm[]              = "/dev/mdm"; // No such file or directory
+    static const char mdm[]              = "/target"; // mdm target we are using
 
     char rd_hw_platform[LINE_LEN];
     char rd_id[LINE_LEN];
diff --git a/utils/platform_lib_abstractions/loc_pla/include/platform_lib_gettid.h b/utils/platform_lib_abstractions/loc_pla/include/platform_lib_gettid.h
index 9956937..340c3c5 100644
--- a/utils/platform_lib_abstractions/loc_pla/include/platform_lib_gettid.h
+++ b/utils/platform_lib_abstractions/loc_pla/include/platform_lib_gettid.h
@@ -34,6 +34,10 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
+#ifdef USE_GLIB
+const char* getprogname();
+#endif /* USE_GLIB */
+
 pid_t platform_lib_abstraction_gettid();
 #ifdef __cplusplus
 }
diff --git a/utils/platform_lib_abstractions/loc_pla/include/platform_lib_macros.h b/utils/platform_lib_abstractions/loc_pla/include/platform_lib_macros.h
index c712122..d0795eb 100644
--- a/utils/platform_lib_abstractions/loc_pla/include/platform_lib_macros.h
+++ b/utils/platform_lib_abstractions/loc_pla/include/platform_lib_macros.h
@@ -66,6 +66,18 @@
 
 #endif /* USE_GLIB */
 
+
+// Below are the location conf file paths
+extern const char LOC_PATH_GPS_CONF[];
+extern const char LOC_PATH_IZAT_CONF[];
+extern const char LOC_PATH_FLP_CONF[];
+extern const char LOC_PATH_LOWI_CONF[];
+extern const char LOC_PATH_SAP_CONF[];
+extern const char LOC_PATH_APDR_CONF[];
+extern const char LOC_PATH_XTWIFI_CONF[];
+extern const char LOC_PATH_QUIPC_CONF[];
+
+
 #ifdef __cplusplus
 }
 #endif /*__cplusplus */
diff --git a/utils/platform_lib_abstractions/loc_pla/src/platform_lib_gettid.cpp b/utils/platform_lib_abstractions/loc_pla/src/platform_lib_gettid.cpp
index 8686327..1b7aa32 100644
--- a/utils/platform_lib_abstractions/loc_pla/src/platform_lib_gettid.cpp
+++ b/utils/platform_lib_abstractions/loc_pla/src/platform_lib_gettid.cpp
@@ -30,6 +30,12 @@
 
 #ifdef USE_GLIB
 #include <loc_stub_gettid.h>
+
+#include <errno.h>
+const char* getprogname() {
+    return program_invocation_short_name;
+}
+
 #else
 #include <unistd.h>
 #endif /* USE_GLIB */
diff --git a/utils/platform_lib_abstractions/loc_pla/src/platform_lib_log_util.cpp b/utils/platform_lib_abstractions/loc_pla/src/platform_lib_log_util.cpp
index ef23201..3cb51a3 100644
--- a/utils/platform_lib_abstractions/loc_pla/src/platform_lib_log_util.cpp
+++ b/utils/platform_lib_abstractions/loc_pla/src/platform_lib_log_util.cpp
@@ -26,6 +26,7 @@
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include "platform_lib_log_util.h"
+#include "platform_lib_macros.h"
 
 char * get_timestamp(char *str, unsigned long buf_size)
 {
@@ -40,3 +41,38 @@
   return str;
 }
 
+// Below are the location conf file paths
+#ifdef __ANDROID__
+
+#define LOC_PATH_GPS_CONF_STR      "/vendor/etc/gps.conf"
+#define LOC_PATH_IZAT_CONF_STR     "/vendor/etc/izat.conf"
+#define LOC_PATH_FLP_CONF_STR      "/vendor/etc/flp.conf"
+#define LOC_PATH_LOWI_CONF_STR     "/vendor/etc/lowi.conf"
+#define LOC_PATH_SAP_CONF_STR      "/vendor/etc/sap.conf"
+#define LOC_PATH_APDR_CONF_STR     "/vendor/etc/apdr.conf"
+#define LOC_PATH_XTWIFI_CONF_STR   "/vendor/etc/xtwifi.conf"
+#define LOC_PATH_QUIPC_CONF_STR    "/vendor/etc/quipc.conf"
+
+#else
+
+#define LOC_PATH_GPS_CONF_STR      "/etc/gps.conf"
+#define LOC_PATH_IZAT_CONF_STR     "/etc/izat.conf"
+#define LOC_PATH_FLP_CONF_STR      "/etc/flp.conf"
+#define LOC_PATH_LOWI_CONF_STR     "/etc/lowi.conf"
+#define LOC_PATH_SAP_CONF_STR      "/etc/sap.conf"
+#define LOC_PATH_APDR_CONF_STR     "/etc/apdr.conf"
+#define LOC_PATH_XTWIFI_CONF_STR   "/etc/xtwifi.conf"
+#define LOC_PATH_QUIPC_CONF_STR    "/etc/quipc.conf"
+
+#endif // __ANDROID__
+
+// Reference below arrays wherever needed to avoid duplicating
+// same conf path string over and again in location code.
+const char LOC_PATH_GPS_CONF[]    = LOC_PATH_GPS_CONF_STR;
+const char LOC_PATH_IZAT_CONF[]   = LOC_PATH_IZAT_CONF_STR;
+const char LOC_PATH_FLP_CONF[]    = LOC_PATH_FLP_CONF_STR;
+const char LOC_PATH_LOWI_CONF[]   = LOC_PATH_LOWI_CONF_STR;
+const char LOC_PATH_SAP_CONF[]    = LOC_PATH_SAP_CONF_STR;
+const char LOC_PATH_APDR_CONF[]   = LOC_PATH_APDR_CONF_STR;
+const char LOC_PATH_XTWIFI_CONF[] = LOC_PATH_XTWIFI_CONF_STR;
+const char LOC_PATH_QUIPC_CONF[]  = LOC_PATH_QUIPC_CONF_STR;