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/Android.bp b/gnss/1.0/Android.bp
index a69d30b..10ab932 100644
--- a/gnss/1.0/Android.bp
+++ b/gnss/1.0/Android.bp
@@ -11,6 +11,8 @@
"IAGnssRil.hal",
"IAGnssRilCallback.hal",
"IGnss.hal",
+ "IGnssBatching.hal",
+ "IGnssBatchingCallback.hal",
"IGnssCallback.hal",
"IGnssConfiguration.hal",
"IGnssDebug.hal",
@@ -32,6 +34,8 @@
"android/hardware/gnss/1.0/AGnssRilAll.cpp",
"android/hardware/gnss/1.0/AGnssRilCallbackAll.cpp",
"android/hardware/gnss/1.0/GnssAll.cpp",
+ "android/hardware/gnss/1.0/GnssBatchingAll.cpp",
+ "android/hardware/gnss/1.0/GnssBatchingCallbackAll.cpp",
"android/hardware/gnss/1.0/GnssCallbackAll.cpp",
"android/hardware/gnss/1.0/GnssConfigurationAll.cpp",
"android/hardware/gnss/1.0/GnssDebugAll.cpp",
@@ -59,6 +63,8 @@
"IAGnssRil.hal",
"IAGnssRilCallback.hal",
"IGnss.hal",
+ "IGnssBatching.hal",
+ "IGnssBatchingCallback.hal",
"IGnssCallback.hal",
"IGnssConfiguration.hal",
"IGnssDebug.hal",
@@ -100,6 +106,16 @@
"android/hardware/gnss/1.0/BnGnss.h",
"android/hardware/gnss/1.0/BpGnss.h",
"android/hardware/gnss/1.0/BsGnss.h",
+ "android/hardware/gnss/1.0/IGnssBatching.h",
+ "android/hardware/gnss/1.0/IHwGnssBatching.h",
+ "android/hardware/gnss/1.0/BnGnssBatching.h",
+ "android/hardware/gnss/1.0/BpGnssBatching.h",
+ "android/hardware/gnss/1.0/BsGnssBatching.h",
+ "android/hardware/gnss/1.0/IGnssBatchingCallback.h",
+ "android/hardware/gnss/1.0/IHwGnssBatchingCallback.h",
+ "android/hardware/gnss/1.0/BnGnssBatchingCallback.h",
+ "android/hardware/gnss/1.0/BpGnssBatchingCallback.h",
+ "android/hardware/gnss/1.0/BsGnssBatchingCallback.h",
"android/hardware/gnss/1.0/IGnssCallback.h",
"android/hardware/gnss/1.0/IHwGnssCallback.h",
"android/hardware/gnss/1.0/BnGnssCallback.h",
diff --git a/gnss/1.0/Android.mk b/gnss/1.0/Android.mk
index d2c7fcf..d72280f 100644
--- a/gnss/1.0/Android.mk
+++ b/gnss/1.0/Android.mk
@@ -164,6 +164,8 @@
$(GEN): $(LOCAL_PATH)/IAGnss.hal
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/IAGnssRil.hal
$(GEN): $(LOCAL_PATH)/IAGnssRil.hal
+$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/IGnssBatching.hal
+$(GEN): $(LOCAL_PATH)/IGnssBatching.hal
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/IGnssCallback.hal
$(GEN): $(LOCAL_PATH)/IGnssCallback.hal
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/IGnssConfiguration.hal
@@ -195,6 +197,48 @@
LOCAL_GENERATED_SOURCES += $(GEN)
#
+# Build IGnssBatching.hal
+#
+GEN := $(intermediates)/android/hardware/gnss/V1_0/IGnssBatching.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IGnssBatching.hal
+$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/IGnssBatchingCallback.hal
+$(GEN): $(LOCAL_PATH)/IGnssBatchingCallback.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+ $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+ -Ljava \
+ -randroid.hardware:hardware/interfaces \
+ -randroid.hidl:system/libhidl/transport \
+ android.hardware.gnss@1.0::IGnssBatching
+
+$(GEN): $(LOCAL_PATH)/IGnssBatching.hal
+ $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build IGnssBatchingCallback.hal
+#
+GEN := $(intermediates)/android/hardware/gnss/V1_0/IGnssBatchingCallback.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IGnssBatchingCallback.hal
+$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal
+$(GEN): $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+ $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+ -Ljava \
+ -randroid.hardware:hardware/interfaces \
+ -randroid.hidl:system/libhidl/transport \
+ android.hardware.gnss@1.0::IGnssBatchingCallback
+
+$(GEN): $(LOCAL_PATH)/IGnssBatchingCallback.hal
+ $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
# Build IGnssCallback.hal
#
GEN := $(intermediates)/android/hardware/gnss/V1_0/IGnssCallback.java
@@ -623,6 +667,8 @@
$(GEN): $(LOCAL_PATH)/IAGnss.hal
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/IAGnssRil.hal
$(GEN): $(LOCAL_PATH)/IAGnssRil.hal
+$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/IGnssBatching.hal
+$(GEN): $(LOCAL_PATH)/IGnssBatching.hal
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/IGnssCallback.hal
$(GEN): $(LOCAL_PATH)/IGnssCallback.hal
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/IGnssConfiguration.hal
@@ -654,6 +700,48 @@
LOCAL_GENERATED_SOURCES += $(GEN)
#
+# Build IGnssBatching.hal
+#
+GEN := $(intermediates)/android/hardware/gnss/V1_0/IGnssBatching.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IGnssBatching.hal
+$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/IGnssBatchingCallback.hal
+$(GEN): $(LOCAL_PATH)/IGnssBatchingCallback.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+ $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+ -Ljava \
+ -randroid.hardware:hardware/interfaces \
+ -randroid.hidl:system/libhidl/transport \
+ android.hardware.gnss@1.0::IGnssBatching
+
+$(GEN): $(LOCAL_PATH)/IGnssBatching.hal
+ $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
+# Build IGnssBatchingCallback.hal
+#
+GEN := $(intermediates)/android/hardware/gnss/V1_0/IGnssBatchingCallback.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IGnssBatchingCallback.hal
+$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal
+$(GEN): $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+ $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+ -Ljava \
+ -randroid.hardware:hardware/interfaces \
+ -randroid.hidl:system/libhidl/transport \
+ android.hardware.gnss@1.0::IGnssBatchingCallback
+
+$(GEN): $(LOCAL_PATH)/IGnssBatchingCallback.hal
+ $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
# Build IGnssCallback.hal
#
GEN := $(intermediates)/android/hardware/gnss/V1_0/IGnssCallback.java
diff --git a/gnss/1.0/IGnss.hal b/gnss/1.0/IGnss.hal
index cc19ef8..24a5371 100644
--- a/gnss/1.0/IGnss.hal
+++ b/gnss/1.0/IGnss.hal
@@ -18,6 +18,7 @@
import IAGnss;
import IAGnssRil;
+import IGnssBatching;
import IGnssCallback;
import IGnssConfiguration;
import IGnssDebug;
@@ -81,14 +82,19 @@
setCallback(IGnssCallback callback) generates (bool success);
/*
- * Starts navigating.
+ * Starts a location output stream using the IGnssCallback
+ * gnssLocationCb(), following the settings from the most recent call to
+ * setPositionMode().
+ *
+ * This output must operate independently of any GNSS location batching
+ * operations, see the IGnssBatching.hal for details.
*
* @return success Returns true on success.
*/
start() generates (bool success);
/*
- * Stops navigating.
+ * Stops the location output stream.
*
* @return success Returns true on success.
*/
@@ -218,4 +224,11 @@
* @return debugIface Handle to the IGnssDebug interface.
*/
getExtensionGnssDebug() generates (IGnssDebug debugIface);
+
+ /*
+ * This method returns the IGnssBatching interface.
+ *
+ * @return batchingIface Handle to the IGnssBatching interface.
+ */
+ getExtensionGnssBatching() generates (IGnssBatching batchingIface);
};
diff --git a/gnss/1.0/IGnssBatching.hal b/gnss/1.0/IGnssBatching.hal
new file mode 100644
index 0000000..4f0695d
--- /dev/null
+++ b/gnss/1.0/IGnssBatching.hal
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hardware.gnss@1.0;
+
+import IGnssBatchingCallback;
+
+/*
+ * Extended interface for GNSS Batching support.
+ *
+ * If this interface is supported, this batching request must be able to run in
+ * parallel with, or without, non-batched location requested by the
+ * IGnss start() & stop() - i.e. both requests must be handled independently,
+ * and not interfere with each other.
+ *
+ * For example, if a 1Hz continuous output is underway on the IGnssCallback,
+ * due to an IGnss start() operation,
+ * and then a IGnssBatching start() is called for a location every 10
+ * seconds, the newly added batching request must not disrupt the 1Hz
+ * continuous location output on the IGnssCallback.
+ *
+ * As with GNSS Location outputs, source of location must be GNSS satellite
+ * measurements, optionally using interial and baro sensors to improve
+ * relative motion filtering. No additional absolute positioning information,
+ * such as WiFi derived location, may be mixed with the GNSS information.
+ */
+
+interface IGnssBatching {
+ /*
+ * Enum which holds the bit masks for batching control.
+ */
+ enum Flag : uint8_t {
+ /*
+ * If this flag is set, the hardware implementation
+ * must wake up the application processor when the FIFO is full, and
+ * call IGnssBatchingCallback to return the locations.
+ *
+ * If the flag is not set, the hardware implementation must drop
+ * the oldest data when the FIFO is full.
+ */
+ WAKEUP_ON_FIFO_FULL = 0x01
+ };
+
+ struct Options {
+ /*
+ * Time interval between samples in the location batch, in nano
+ * seconds.
+ */
+ int64_t periodNanos;
+
+ /*
+ * Flags controlling how batching should behave.
+ */
+ bitfield<Flag> flags;
+ };
+
+ /*
+ * Opens the interface and provides the callback routines
+ * to the implementation of this interface.
+ *
+ * @param callback Callback interface for IGnssBatching.
+ *
+ * @return success Returns true on success.
+ */
+ init(IGnssBatchingCallback callback) generates (bool success);
+
+ /*
+ * Return the batch size (in number of GnssLocation objects)
+ * available in this hardware implementation.
+ *
+ * If the available size is variable, for example, based on other operations
+ * consuming memory, this is the minimum size guaranteed to be available
+ * for batching operations.
+ *
+ * This may, for example, be used by the upper layer, to decide on the
+ * batching interval and whether the AP should be woken up or not.
+ *
+ * @return batchSize number of location objects supported per batch
+ */
+ getBatchSize() generates (uint16_t batchSize);
+
+ /*
+ * Start batching locations. This API is primarily used when the AP is
+ * asleep and the device can batch locations in the hardware.
+ *
+ * IGnssBatchingCallback is used to return the locations.
+ *
+ * When the buffer is full and WAKEUP_ON_FIFO_FULL is used,
+ * IGnssBatchingCallback must be called to return the locations.
+ *
+ * When the buffer is full and WAKEUP_ON_FIFO_FULL is not set,
+ * the oldest location object is dropped. In this case the AP must not be
+ * woken up. The AP would then generally be responsible for using
+ * flushBatchedLocation to explicitly ask for the location as needed,
+ * to avoid it being dropped.
+ *
+ * @param options See struct Options definition.
+ *
+ * @return success Returns true on success.
+ */
+ start(Options options) generates (bool success);
+
+ /**
+ * Retrieve all batched locations currently stored.
+ *
+ * IGnssBatchingCallback is used to return the location.
+ *
+ * IGnssBatchingCallback must be called in response, even if there are
+ * no locations to flush (in which case the Location vector must be empty).
+ *
+ * Subsequent calls to flushBatchedLocation
+ * must not return any of the locations returned in this call.
+ */
+ flush();
+
+ /**
+ * Stop batching.
+ *
+ * @return success Returns true on success.
+ */
+ stop() generates (bool success);
+
+ /**
+ * Closes the interface. If any batch operations are in progress,
+ * they should be stopped.
+ *
+ * init() may be called again, after this, if the interface is to be restored
+ */
+ cleanup();
+
+};
diff --git a/gnss/1.0/IGnssBatchingCallback.hal b/gnss/1.0/IGnssBatchingCallback.hal
new file mode 100644
index 0000000..a8f4b88
--- /dev/null
+++ b/gnss/1.0/IGnssBatchingCallback.hal
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hardware.gnss@1.0;
+
+/* The callback interface to report measurements from the HAL. */
+interface IGnssBatchingCallback {
+ /*
+ * Called when a batch of locations is output, by various means, including
+ * a flush request, as well as the buffer becoming full (if appropriate option
+ * is set.)
+ *
+ * All locations returned by this callback must be cleared from the hardware
+ * buffer, such the sequential calls of this callback do not return any
+ * redundant locations. (Same lat/lon, at a new time, is acceptable.)
+ *
+ * @param locations GNSS Location information from HAL.
+ */
+ gnssLocationBatchCb(vec<GnssLocation> locations);
+};
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