Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a42956fb authored by Shinru Han's avatar Shinru Han
Browse files

Add minDistance parameter to GnssBatching (hardware/interface)

Test: atest VtsHalGnssTargetTest
Bug: b/206670536
Change-Id: I982dd64d0cfe0f42c411e4df27d9fdd160c74d2e
parent 5fe87812
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -36,9 +36,15 @@ package android.hardware.gnss;
interface IGnssBatching {
  void init(in android.hardware.gnss.IGnssBatchingCallback callback);
  int getBatchSize();
  void start(in long periodNanos, in int flags);
  void start(in android.hardware.gnss.IGnssBatching.Options options);
  void flush();
  void stop();
  void cleanup();
  const int WAKEUP_ON_FIFO_FULL = 1;
  @VintfStability
  parcelable Options {
    long periodNanos;
    float minDistanceMeters;
    int flags;
  }
}
+21 −3
Original line number Diff line number Diff line
@@ -46,6 +46,25 @@ interface IGnssBatching {
     */
    const int WAKEUP_ON_FIFO_FULL = 0x01;

    /** Options specifying the batching request. */
    @VintfStability
    parcelable Options {
        /** Time interval between samples in the location batch, in nanoseconds. */
        long periodNanos;

        /**
         * The minimum distance in meters that the batching engine should
         * accumulate before trying another GPS fix when in a challenging GPS environment.
         *
         * This is an optional field. If it is set as 0, the chipset can operate in an automatic
         * mode.
         */
        float minDistanceMeters;

        /** A bit field of Flags (WAKEUP_ON_FIFO_FULL) indicating the batching behavior. */
        int flags;
    }

    /**
     * Open the interface and provides the callback routines to the implementation of this
     * interface.
@@ -83,10 +102,9 @@ interface IGnssBatching {
     * for using flushBatchedLocation to explicitly ask for the location as needed, to avoid it
     * being dropped.
     *
     * @param periodNanos  Time interval between samples in the location batch, in nanoseconds
     * @param flags  A bitfield of flags (WAKEUP_ON_FIFO_FULL) indicating the batching behavior
     * @param options  Options specifying the batching request.
     */
    void start(in long periodNanos, in int flags);
    void start(in Options options);

    /**
     * Retrieve all batched locations currently stored.
+6 −4
Original line number Diff line number Diff line
@@ -52,17 +52,19 @@ ndk::ScopedAStatus GnssBatching::getBatchSize(int* size) {
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus GnssBatching::start(int64_t periodNanos, int flags) {
    ALOGD("start: periodNanos=%" PRId64 ", flags=%d", periodNanos, flags);
ndk::ScopedAStatus GnssBatching::start(const Options& options) {
    ALOGD("start: periodNanos=%" PRId64 ", minDistanceMeters=%f, flags=%d", options.periodNanos,
          options.minDistanceMeters, options.flags);
    if (mIsActive) {
        ALOGW("Gnss has started. Restarting...");
        stop();
    }

    mWakeUpOnFifoFull = (flags & IGnssBatching::WAKEUP_ON_FIFO_FULL) ? true : false;
    // mMinIntervalMs is not smaller than 1 sec
    periodNanos = (periodNanos < 1e9) ? 1e9 : periodNanos;
    long periodNanos = (options.periodNanos < 1e9) ? 1e9 : options.periodNanos;
    mMinIntervalMs = periodNanos / 1e6;
    mWakeUpOnFifoFull = (options.flags & IGnssBatching::WAKEUP_ON_FIFO_FULL) ? true : false;
    mMinDistanceMeters = options.minDistanceMeters;

    mIsActive = true;
    mThread = std::thread([this]() {
+2 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ struct GnssBatching : public BnGnssBatching {
    ~GnssBatching();
    ndk::ScopedAStatus init(const std::shared_ptr<IGnssBatchingCallback>& callback) override;
    ndk::ScopedAStatus getBatchSize(int* size) override;
    ndk::ScopedAStatus start(int64_t periodNanos, int flags) override;
    ndk::ScopedAStatus start(const Options& options) override;
    ndk::ScopedAStatus flush() override;
    ndk::ScopedAStatus stop() override;
    ndk::ScopedAStatus cleanup() override;
@@ -42,6 +42,7 @@ struct GnssBatching : public BnGnssBatching {
    std::thread mThread;
    std::atomic<bool> mIsActive;
    std::atomic<long> mMinIntervalMs;
    std::atomic<float> mMinDistanceMeters;
    std::atomic<bool> mWakeUpOnFifoFull;

    // Synchronization lock for sCallback
+4 −0
Original line number Diff line number Diff line
@@ -813,6 +813,10 @@ TEST_P(GnssHalTest, BlocklistConstellationLocationOn) {
 * TestAllExtensions.
 */
TEST_P(GnssHalTest, TestAllExtensions) {
    if (aidl_gnss_hal_->getInterfaceVersion() == 1) {
        return;
    }

    sp<IGnssBatching> iGnssBatching;
    auto status = aidl_gnss_hal_->getExtensionGnssBatching(&iGnssBatching);
    if (status.isOk() && iGnssBatching != nullptr) {