From 216311fd97d42332537a0ec076a8a0b6387a4d24 Mon Sep 17 00:00:00 2001 From: Sasha Kuznetsov Date: Thu, 2 Jan 2020 17:23:42 -0800 Subject: [PATCH] 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 --- gnss/2.1/default/Android.bp | 1 + gnss/2.1/default/Gnss.cpp | 112 ++++++++++++++++++++++++++------- gnss/2.1/default/Gnss.h | 3 + gnss/2.1/default/GnssDebug.cpp | 62 ++++++++++++++++++ gnss/2.1/default/GnssDebug.h | 51 +++++++++++++++ 5 files changed, 207 insertions(+), 22 deletions(-) create mode 100644 gnss/2.1/default/GnssDebug.cpp create mode 100644 gnss/2.1/default/GnssDebug.h diff --git a/gnss/2.1/default/Android.bp b/gnss/2.1/default/Android.bp index 7ef999081e..834847e91e 100644 --- a/gnss/2.1/default/Android.bp +++ b/gnss/2.1/default/Android.bp @@ -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", diff --git a/gnss/2.1/default/Gnss.cpp b/gnss/2.1/default/Gnss.cpp index 6b61a827d0..7db86897f9 100644 --- a/gnss/2.1/default/Gnss.cpp +++ b/gnss/2.1/default/Gnss.cpp @@ -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 Gnss::sGnssCallback_2_1 = nullptr; sp Gnss::sGnssCallback_2_0 = nullptr; +sp Gnss::sGnssCallback_1_1 = nullptr; +sp Gnss::sGnssCallback_1_0 = nullptr; Gnss::Gnss() : mMinIntervalMs(1000), mGnssConfiguration{new GnssConfiguration()} {} @@ -55,8 +58,13 @@ Return Gnss::start() { auto svStatus = filterBlacklistedSatellitesV2_1(Utils::getMockSvInfoListV2_1()); this->reportSvStatus(svStatus); - const auto location = Utils::getMockLocationV2_0(); - this->reportLocation(location); + 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 Gnss::stop() { } // Methods from V1_0::IGnss follow. -Return Gnss::setCallback(const sp&) { - // TODO implement - return bool{}; +Return Gnss::setCallback(const sp& 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 Gnss::cleanup() { @@ -96,13 +124,11 @@ Return Gnss::cleanup() { } Return Gnss::injectTime(int64_t, int64_t, int32_t) { - // TODO implement - return bool{}; + return true; } Return Gnss::injectLocation(double, double, float) { - // TODO implement - return bool{}; + return true; } Return Gnss::deleteAidingData(V1_0::IGnss::GnssAidingData) { @@ -111,10 +137,10 @@ Return Gnss::deleteAidingData(V1_0::IGnss::GnssAidingData) { } Return 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> Gnss::getExtensionAGnssRil() { @@ -138,8 +164,8 @@ Return> Gnss::getExtensionGnssNi() { } Return> Gnss::getExtensionGnssMeasurement() { - // TODO implement - return ::android::sp{}; + ALOGD("Gnss::getExtensionGnssMeasurement"); + return new GnssMeasurement(); } Return> Gnss::getExtensionGnssNavigationMessage() { @@ -158,8 +184,7 @@ Return> Gnss::getExtensionGnssConfiguration() { } Return> Gnss::getExtensionGnssDebug() { - // TODO implement - return ::android::sp{}; + return new V1_1::implementation::GnssDebug(); } Return> Gnss::getExtensionGnssBatching() { @@ -168,9 +193,34 @@ Return> Gnss::getExtensionGnssBatching() { } // Methods from V1_1::IGnss follow. -Return Gnss::setCallback_1_1(const sp&) { - // TODO implement - return bool{}; +Return Gnss::setCallback_1_1(const sp& 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 Gnss::setPositionMode_1_1(V1_0::IGnss::GnssPositionMode, @@ -191,8 +241,7 @@ Return> Gnss::getExtensionGnssMeasurement_1_1() { } Return 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& svInfoList) const { } } +void Gnss::reportLocation(const V1_0::GnssLocation& location) const { + std::unique_lock 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 lock(mMutex); if (sGnssCallback_2_1 != nullptr) { diff --git a/gnss/2.1/default/Gnss.h b/gnss/2.1/default/Gnss.h index 7917bbd6a2..7a2a2c953a 100644 --- a/gnss/2.1/default/Gnss.h +++ b/gnss/2.1/default/Gnss.h @@ -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&) const; static sp sGnssCallback_2_1; static sp sGnssCallback_2_0; + static sp sGnssCallback_1_1; + static sp sGnssCallback_1_0; std::atomic mMinIntervalMs; sp mGnssConfiguration; std::atomic mIsActive; diff --git a/gnss/2.1/default/GnssDebug.cpp b/gnss/2.1/default/GnssDebug.cpp new file mode 100644 index 0000000000..a9f7ded2a7 --- /dev/null +++ b/gnss/2.1/default/GnssDebug.cpp @@ -0,0 +1,62 @@ +/* + * 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 + +#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 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 diff --git a/gnss/2.1/default/GnssDebug.h b/gnss/2.1/default/GnssDebug.h new file mode 100644 index 0000000000..969d337524 --- /dev/null +++ b/gnss/2.1/default/GnssDebug.h @@ -0,0 +1,51 @@ +/* + * 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 +#include + +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 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_