Only allow one extension obj of each type to be created

HAL did not expect multiple calls of GetExtensionsGnssX,
but if it happens, it causes a static callback function
in AGnss to get set to null when the first instance of
the obj gets deleted even if a second instance of AGnss
is created. This causes SUPL to fail because the static
callback function in AGnss is null and stops HAL from
being able to request SUPL into the Android Framework.

CRs-fixed: 2614283
Change-Id: I764bdc25e134056c3f761e411fde5209e93ea546
diff --git a/android/2.0/Gnss.cpp b/android/2.0/Gnss.cpp
index 2276c14..b33495f 100644
--- a/android/2.0/Gnss.cpp
+++ b/android/2.0/Gnss.cpp
@@ -385,31 +385,41 @@
 
 Return<sp<V1_0::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration()  {
     ENTRY_LOG_CALLFLOW();
-    mGnssConfig = new GnssConfiguration(this);
+    if (mGnssConfig == nullptr) {
+        mGnssConfig = new GnssConfiguration(this);
+    }
     return mGnssConfig;
 }
 
 Return<sp<V1_0::IGnssGeofencing>> Gnss::getExtensionGnssGeofencing()  {
     ENTRY_LOG_CALLFLOW();
-    mGnssGeofencingIface = new GnssGeofencing();
+    if (mGnssGeofencingIface == nullptr) {
+        mGnssGeofencingIface = new GnssGeofencing();
+    }
     return mGnssGeofencingIface;
 }
 
 Return<sp<V1_0::IGnssBatching>> Gnss::getExtensionGnssBatching()  {
     ENTRY_LOG_CALLFLOW();
-    mGnssBatching = new GnssBatching();
+    if (mGnssBatching == nullptr) {
+        mGnssBatching = new GnssBatching();
+    }
     return mGnssBatching;
 }
 
 Return<sp<V1_0::IGnssDebug>> Gnss::getExtensionGnssDebug() {
     ENTRY_LOG_CALLFLOW();
-    mGnssDebug = new GnssDebug(this);
+    if (mGnssDebug == nullptr) {
+        mGnssDebug = new GnssDebug(this);
+    }
     return mGnssDebug;
 }
 
 Return<sp<V1_0::IAGnssRil>> Gnss::getExtensionAGnssRil() {
     ENTRY_LOG_CALLFLOW();
-    mGnssRil = new AGnssRil(this);
+    if (mGnssRil == nullptr) {
+        mGnssRil = new AGnssRil(this);
+    }
     return mGnssRil;
 }
 
@@ -596,17 +606,23 @@
 
 Return<sp<V2_0::IAGnss>> Gnss::getExtensionAGnss_2_0() {
     ENTRY_LOG_CALLFLOW();
-    mAGnssIface_2_0 = new AGnss(this);
+    if (mAGnssIface_2_0 == nullptr) {
+        mAGnssIface_2_0 = new AGnss(this);
+    }
     return mAGnssIface_2_0;
 }
 Return<sp<V2_0::IAGnssRil>> Gnss::getExtensionAGnssRil_2_0() {
-    mGnssRil = new AGnssRil(this);
+    if (mGnssRil == nullptr) {
+        mGnssRil = new AGnssRil(this);
+    }
     return mGnssRil;
 }
 
 Return<sp<V2_0::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_2_0() {
     ENTRY_LOG_CALLFLOW();
-    mGnssConfig = new GnssConfiguration(this);
+    if (mGnssConfig == nullptr) {
+        mGnssConfig = new GnssConfiguration(this);
+    }
     return mGnssConfig;
 }
 Return<sp<V2_0::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_2_0() {
@@ -646,13 +662,17 @@
 
 Return<sp<V2_0::IGnssDebug>> Gnss::getExtensionGnssDebug_2_0() {
     ENTRY_LOG_CALLFLOW();
-    mGnssDebug = new GnssDebug(this);
+    if (mGnssDebug == nullptr) {
+        mGnssDebug = new GnssDebug(this);
+    }
     return mGnssDebug;
 }
 
 Return<sp<V2_0::IGnssBatching>> Gnss::getExtensionGnssBatching_2_0() {
     ENTRY_LOG_CALLFLOW();
-    mGnssBatching = new GnssBatching();
+    if (mGnssBatching == nullptr) {
+        mGnssBatching = new GnssBatching();
+    }
     return mGnssBatching;
 }