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

Commit 216311fd authored by Sasha Kuznetsov's avatar Sasha Kuznetsov
Browse files

Complete 2.1 gnss default implementation to pass all VTS tests

Test: atest VtsHalGnssV2_1TargetTest && atest VtsHalGnssV2_0TargetTest && atest VtsHalGnssV1_1TargetTest && atest VtsHalGnssV1_0TargetTest
Bug: 146216289
Change-Id: Idfd80f70b67359dcbf1dc033b9b4218aff0c869c
parent 9392b58d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ cc_binary {
    vintf_fragments: ["android.hardware.gnss@2.1-service.xml"],
    srcs: [
        "Gnss.cpp",
        "GnssDebug.cpp",
        "GnssMeasurement.cpp",
        "GnssMeasurementCorrections.cpp",
        "GnssConfiguration.cpp",
+90 −22
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#define LOG_TAG "Gnss"

#include "Gnss.h"
#include "GnssDebug.h"
#include "GnssMeasurement.h"
#include "GnssMeasurementCorrections.h"
#include "Utils.h"
@@ -35,6 +36,8 @@ namespace implementation {

sp<V2_1::IGnssCallback> Gnss::sGnssCallback_2_1 = nullptr;
sp<V2_0::IGnssCallback> Gnss::sGnssCallback_2_0 = nullptr;
sp<V1_1::IGnssCallback> Gnss::sGnssCallback_1_1 = nullptr;
sp<V1_0::IGnssCallback> Gnss::sGnssCallback_1_0 = nullptr;

Gnss::Gnss() : mMinIntervalMs(1000), mGnssConfiguration{new GnssConfiguration()} {}

@@ -55,8 +58,13 @@ Return<bool> Gnss::start() {
            auto svStatus = filterBlacklistedSatellitesV2_1(Utils::getMockSvInfoListV2_1());
            this->reportSvStatus(svStatus);

            if (sGnssCallback_2_1 != nullptr || sGnssCallback_2_0 != nullptr) {
                const auto location = Utils::getMockLocationV2_0();
                this->reportLocation(location);
            } else {
                const auto location = Utils::getMockLocationV1_0();
                this->reportLocation(location);
            }

            std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs));
        }
@@ -84,9 +92,29 @@ Return<bool> Gnss::stop() {
}

// Methods from V1_0::IGnss follow.
Return<bool> Gnss::setCallback(const sp<V1_0::IGnssCallback>&) {
    // TODO implement
    return bool{};
Return<bool> Gnss::setCallback(const sp<V1_0::IGnssCallback>& callback) {
    if (callback == nullptr) {
        ALOGE("%s: Null callback ignored", __func__);
        return false;
    }

    sGnssCallback_1_0 = callback;

    uint32_t capabilities = 0x0 | V1_0::IGnssCallback::Capabilities::MEASUREMENTS |
                            V1_0::IGnssCallback::Capabilities::SCHEDULING;
    auto ret = sGnssCallback_1_0->gnssSetCapabilitesCb(capabilities);
    if (!ret.isOk()) {
        ALOGE("%s: Unable to invoke callback", __func__);
    }

    IGnssCallback::GnssSystemInfo gnssInfo = {.yearOfHw = 2018};

    ret = sGnssCallback_1_0->gnssSetSystemInfoCb(gnssInfo);
    if (!ret.isOk()) {
        ALOGE("%s: Unable to invoke callback", __func__);
    }

    return true;
}

Return<void> Gnss::cleanup() {
@@ -96,13 +124,11 @@ Return<void> Gnss::cleanup() {
}

Return<bool> Gnss::injectTime(int64_t, int64_t, int32_t) {
    // TODO implement
    return bool{};
    return true;
}

Return<bool> Gnss::injectLocation(double, double, float) {
    // TODO implement
    return bool{};
    return true;
}

Return<void> Gnss::deleteAidingData(V1_0::IGnss::GnssAidingData) {
@@ -111,10 +137,10 @@ Return<void> Gnss::deleteAidingData(V1_0::IGnss::GnssAidingData) {
}

Return<bool> Gnss::setPositionMode(V1_0::IGnss::GnssPositionMode,
                                   V1_0::IGnss::GnssPositionRecurrence, uint32_t, uint32_t,
                                   uint32_t) {
    // TODO implement
    return bool{};
                                   V1_0::IGnss::GnssPositionRecurrence, uint32_t minIntervalMs,
                                   uint32_t, uint32_t) {
    mMinIntervalMs = minIntervalMs;
    return true;
}

Return<sp<V1_0::IAGnssRil>> Gnss::getExtensionAGnssRil() {
@@ -138,8 +164,8 @@ Return<sp<V1_0::IGnssNi>> Gnss::getExtensionGnssNi() {
}

Return<sp<V1_0::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement() {
    // TODO implement
    return ::android::sp<V1_0::IGnssMeasurement>{};
    ALOGD("Gnss::getExtensionGnssMeasurement");
    return new GnssMeasurement();
}

Return<sp<V1_0::IGnssNavigationMessage>> Gnss::getExtensionGnssNavigationMessage() {
@@ -158,8 +184,7 @@ Return<sp<V1_0::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration() {
}

Return<sp<V1_0::IGnssDebug>> Gnss::getExtensionGnssDebug() {
    // TODO implement
    return ::android::sp<V1_0::IGnssDebug>{};
    return new V1_1::implementation::GnssDebug();
}

Return<sp<V1_0::IGnssBatching>> Gnss::getExtensionGnssBatching() {
@@ -168,9 +193,34 @@ Return<sp<V1_0::IGnssBatching>> Gnss::getExtensionGnssBatching() {
}

// Methods from V1_1::IGnss follow.
Return<bool> Gnss::setCallback_1_1(const sp<V1_1::IGnssCallback>&) {
    // TODO implement
    return bool{};
Return<bool> Gnss::setCallback_1_1(const sp<V1_1::IGnssCallback>& callback) {
    if (callback == nullptr) {
        ALOGE("%s: Null callback ignored", __func__);
        return false;
    }

    sGnssCallback_1_1 = callback;

    uint32_t capabilities = 0x0;
    auto ret = sGnssCallback_1_1->gnssSetCapabilitesCb(capabilities);
    if (!ret.isOk()) {
        ALOGE("%s: Unable to invoke callback", __func__);
    }

    IGnssCallback::GnssSystemInfo gnssInfo = {.yearOfHw = 2018};

    ret = sGnssCallback_1_1->gnssSetSystemInfoCb(gnssInfo);
    if (!ret.isOk()) {
        ALOGE("%s: Unable to invoke callback", __func__);
    }

    auto gnssName = "Google Mock GNSS Implementation v2.1";
    ret = sGnssCallback_1_1->gnssNameCb(gnssName);
    if (!ret.isOk()) {
        ALOGE("%s: Unable to invoke callback", __func__);
    }

    return true;
}

Return<bool> Gnss::setPositionMode_1_1(V1_0::IGnss::GnssPositionMode,
@@ -191,8 +241,7 @@ Return<sp<V1_1::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_1_1() {
}

Return<bool> Gnss::injectBestLocation(const V1_0::GnssLocation&) {
    // TODO implement
    return bool{};
    return true;
}

// Methods from V2_0::IGnss follow.
@@ -332,6 +381,25 @@ void Gnss::reportSvStatus(const hidl_vec<GnssSvInfo>& svInfoList) const {
    }
}

void Gnss::reportLocation(const V1_0::GnssLocation& location) const {
    std::unique_lock<std::mutex> lock(mMutex);
    if (sGnssCallback_1_1 != nullptr) {
        auto ret = sGnssCallback_1_1->gnssLocationCb(location);
        if (!ret.isOk()) {
            ALOGE("%s: Unable to invoke callback v1.1", __func__);
        }
        return;
    }
    if (sGnssCallback_1_0 == nullptr) {
        ALOGE("%s: No non-null callback", __func__);
        return;
    }
    auto ret = sGnssCallback_1_0->gnssLocationCb(location);
    if (!ret.isOk()) {
        ALOGE("%s: Unable to invoke callback v1.0", __func__);
    }
}

void Gnss::reportLocation(const V2_0::GnssLocation& location) const {
    std::unique_lock<std::mutex> lock(mMutex);
    if (sGnssCallback_2_1 != nullptr) {
+3 −0
Original line number Diff line number Diff line
@@ -92,10 +92,13 @@ struct Gnss : public IGnss {

  private:
    void reportLocation(const V2_0::GnssLocation&) const;
    void reportLocation(const V1_0::GnssLocation&) const;
    void reportSvStatus(const hidl_vec<GnssSvInfo>&) const;

    static sp<V2_1::IGnssCallback> sGnssCallback_2_1;
    static sp<V2_0::IGnssCallback> sGnssCallback_2_0;
    static sp<V1_1::IGnssCallback> sGnssCallback_1_1;
    static sp<V1_0::IGnssCallback> sGnssCallback_1_0;
    std::atomic<long> mMinIntervalMs;
    sp<GnssConfiguration> mGnssConfiguration;
    std::atomic<bool> mIsActive;
+62 −0
Original line number Diff line number Diff line
/*
 * 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.
 */

#define LOG_TAG "GnssDebug"

#include <log/log.h>

#include "Constants.h"
#include "GnssDebug.h"

using namespace ::android::hardware::gnss::common;

namespace android {
namespace hardware {
namespace gnss {
namespace V1_1 {
namespace implementation {

// Methods from ::android::hardware::gnss::V1_0::IGnssDebug follow.
Return<void> GnssDebug::getDebugData(V1_0::IGnssDebug::getDebugData_cb _hidl_cb) {
    PositionDebug positionDebug = {
            .valid = true,
            .latitudeDegrees = kMockLatitudeDegrees,
            .longitudeDegrees = kMockLongitudeDegrees,
            .altitudeMeters = kMockAltitudeMeters,
            .speedMetersPerSec = kMockSpeedMetersPerSec,
            .bearingDegrees = kMockBearingDegrees,
            .horizontalAccuracyMeters = kMockHorizontalAccuracyMeters,
            .verticalAccuracyMeters = kMockVerticalAccuracyMeters,
            .speedAccuracyMetersPerSecond = kMockSpeedAccuracyMetersPerSecond,
            .bearingAccuracyDegrees = kMockBearingAccuracyDegrees,
            .ageSeconds = 0.99};

    TimeDebug timeDebug = {.timeEstimate = kMockTimestamp,
                           .timeUncertaintyNs = 1000,
                           .frequencyUncertaintyNsPerSec = 5.0e4};

    DebugData data = {.position = positionDebug, .time = timeDebug};

    _hidl_cb(data);

    return Void();
}

}  // namespace implementation
}  // namespace V1_1
}  // namespace gnss
}  // namespace hardware
}  // namespace android
+51 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.
 */

#ifndef android_hardware_gnss_V1_1_GnssDebug_H_
#define android_hardware_gnss_V1_1_GnssDebug_H_

#include <android/hardware/gnss/1.0/IGnssDebug.h>
#include <hidl/Status.h>

namespace android {
namespace hardware {
namespace gnss {
namespace V1_1 {
namespace implementation {

using ::android::sp;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using V1_0::IGnssDebug;

/* Interface for GNSS Debug support. */
struct GnssDebug : public IGnssDebug {
    /*
     * Methods from ::android::hardware::gnss::V1_0::IGnssDebug follow.
     * These declarations were generated from IGnssDebug.hal.
     */
    Return<void> getDebugData(V1_0::IGnssDebug::getDebugData_cb _hidl_cb) override;
};

}  // namespace implementation
}  // namespace V1_1
}  // namespace gnss
}  // namespace hardware
}  // namespace android

#endif  // android_hardware_gnss_V1_1_GnssDebug_H_