GnssBatching API, port from Fused Location

New HAL APIs for Gnss location batches,
still to be connected (default implementation)
similarly to this aspect of fused_location.h,
initially as a single client system API.

Bug: 31974439
Test: Ensured it builds and runs GPS & FLP (in Test app & maps)
Change-Id: I27d3fd2cffad25039b006e60c4496a440dc86c13
diff --git a/gnss/1.0/default/Android.mk b/gnss/1.0/default/Android.mk
index 6289491..a6f73f2 100644
--- a/gnss/1.0/default/Android.mk
+++ b/gnss/1.0/default/Android.mk
@@ -8,6 +8,7 @@
     AGnss.cpp \
     AGnssRil.cpp \
     Gnss.cpp \
+    GnssBatching.cpp \
     GnssDebug.cpp \
     GnssGeofencing.cpp \
     GnssMeasurement.cpp \
diff --git a/gnss/1.0/default/Gnss.cpp b/gnss/1.0/default/Gnss.cpp
index 5e6e65d..28a1950 100644
--- a/gnss/1.0/default/Gnss.cpp
+++ b/gnss/1.0/default/Gnss.cpp
@@ -534,6 +534,23 @@
     return mGnssDebug;
 }
 
+Return<sp<IGnssBatching>> Gnss::getExtensionGnssBatching()  {
+    if (mGnssIface == nullptr) {
+        ALOGE("%s: Gnss interface is unavailable", __func__);
+    } else {
+        // TODO(b/34133439): actually get an flpLocationIface
+        const FlpLocationInterface* flpLocationIface = nullptr;
+
+        if (flpLocationIface == nullptr) {
+            ALOGE("%s: GnssBatching interface is not implemented by HAL", __func__);
+        } else {
+            mGnssBatching = new GnssBatching(flpLocationIface);
+        }
+    }
+
+    return mGnssBatching;
+}
+
 IGnss* HIDL_FETCH_IGnss(const char* hal) {
     hw_module_t* module;
     IGnss* iface = nullptr;
diff --git a/gnss/1.0/default/Gnss.h b/gnss/1.0/default/Gnss.h
index e12ac12..36947c1 100644
--- a/gnss/1.0/default/Gnss.h
+++ b/gnss/1.0/default/Gnss.h
@@ -19,6 +19,7 @@
 
 #include <AGnss.h>
 #include <AGnssRil.h>
+#include <GnssBatching.h>
 #include <GnssConfiguration.h>
 #include <GnssDebug.h>
 #include <GnssGeofencing.h>
@@ -29,6 +30,7 @@
 
 #include <ThreadCreationWrapper.h>
 #include <android/hardware/gnss/1.0/IGnss.h>
+#include <hardware/fused_location.h>
 #include <hardware/gps.h>
 #include <hidl/Status.h>
 
@@ -51,6 +53,7 @@
  * IGnssCallback interface to be passed into the conventional implementation of the GNSS HAL.
  */
 struct Gnss : public IGnss {
+    // TODO: Add flp_device_t, either in ctor, or later attach?
     Gnss(gps_device_t* gnss_device);
     ~Gnss();
 
@@ -83,6 +86,7 @@
     Return<sp<IGnssXtra>> getExtensionXtra() override;
     Return<sp<IGnssConfiguration>> getExtensionGnssConfiguration() override;
     Return<sp<IGnssDebug>> getExtensionGnssDebug() override;
+    Return<sp<IGnssBatching>> getExtensionGnssBatching() override;
 
     /*
      * Callback methods to be passed into the conventional GNSS HAL by the default
@@ -119,6 +123,7 @@
     sp<GnssNavigationMessage> mGnssNavigationMessage = nullptr;
     sp<GnssDebug> mGnssDebug = nullptr;
     sp<GnssConfiguration> mGnssConfig = nullptr;
+    sp<GnssBatching> mGnssBatching = nullptr;
     const GpsInterface* mGnssIface = nullptr;
     static sp<IGnssCallback> sGnssCbIface;
     static std::vector<std::unique_ptr<ThreadFuncArgs>> sThreadFuncArgsList;
diff --git a/gnss/1.0/default/GnssBatching.cpp b/gnss/1.0/default/GnssBatching.cpp
new file mode 100644
index 0000000..404b5da
--- /dev/null
+++ b/gnss/1.0/default/GnssBatching.cpp
@@ -0,0 +1,48 @@
+#include "GnssBatching.h"
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+GnssBatching::GnssBatching(const FlpLocationInterface* flpLocationIface) :
+    mFlpLocationIface(flpLocationIface) {}
+
+
+// Methods from ::android::hardware::gnss::V1_0::IGnssBatching follow.
+Return<bool> GnssBatching::init(const sp<IGnssBatchingCallback>& callback) {
+    // TODO(b/34133439) implement
+    return false;
+}
+
+Return<uint16_t> GnssBatching::getBatchSize() {
+    // TODO(b/34133439) implement
+    return 0;
+}
+
+Return<bool> GnssBatching::start(const IGnssBatching::Options& options) {
+    // TODO(b/34133439) implement
+    return false;
+}
+
+Return<void> GnssBatching::flush() {
+    // TODO(b/34133439) implement
+    return Void();
+}
+
+Return<bool> GnssBatching::stop() {
+    // TODO(b/34133439) implement
+    return false;
+}
+
+Return<void> GnssBatching::cleanup() {
+    // TODO(b/34133439) implement
+    return Void();
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
diff --git a/gnss/1.0/default/GnssBatching.h b/gnss/1.0/default/GnssBatching.h
new file mode 100644
index 0000000..ac3aa99
--- /dev/null
+++ b/gnss/1.0/default/GnssBatching.h
@@ -0,0 +1,50 @@
+#ifndef ANDROID_HARDWARE_GNSS_V1_0_GNSSBATCHING_H
+#define ANDROID_HARDWARE_GNSS_V1_0_GNSSBATCHING_H
+
+#include <android/hardware/gnss/1.0/IGnssBatching.h>
+#include <hardware/fused_location.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+
+
+namespace android {
+namespace hardware {
+namespace gnss {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::gnss::V1_0::IGnssBatching;
+using ::android::hardware::gnss::V1_0::IGnssBatchingCallback;
+using ::android::hidl::base::V1_0::IBase;
+using ::android::hardware::hidl_array;
+using ::android::hardware::hidl_memory;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+
+struct GnssBatching : public IGnssBatching {
+    GnssBatching(const FlpLocationInterface* flpLocationIface);
+
+    // Methods from ::android::hardware::gnss::V1_0::IGnssBatching follow.
+    Return<bool> init(const sp<IGnssBatchingCallback>& callback) override;
+    Return<uint16_t> getBatchSize() override;
+    Return<bool> start(const IGnssBatching::Options& options ) override;
+    Return<void> flush() override;
+    Return<bool> stop() override;
+    Return<void> cleanup() override;
+
+ private:
+    const FlpLocationInterface* mFlpLocationIface = nullptr;
+};
+
+extern "C" IGnssBatching* HIDL_FETCH_IGnssBatching(const char* name);
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace gnss
+}  // namespace hardware
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_GNSS_V1_0_GNSSBATCHING_H