Add GNSS HAL v3.0 (hardware/interfaces)
Bug: 158518085
Test: atest VtsHalGnssV3_0TargetTest
atest VtsHalGnssV2_1TargetTest
atest VtsHalGnssV2_0TargetTest
atest VtsHalGnssV1_1TargetTest
atest VtsHalGnssV1_0TargetTest
Change-Id: Id4ac1e31207da7cfff3f1885c84748785bec19ba
diff --git a/gnss/2.1/default/Android.bp b/gnss/2.1/default/Android.bp
index c4dc8fd..7739f90 100644
--- a/gnss/2.1/default/Android.bp
+++ b/gnss/2.1/default/Android.bp
@@ -21,12 +21,6 @@
vendor: true,
vintf_fragments: ["android.hardware.gnss@2.1-service.xml"],
srcs: [
- "Gnss.cpp",
- "GnssAntennaInfo.cpp",
- "GnssDebug.cpp",
- "GnssMeasurement.cpp",
- "GnssMeasurementCorrections.cpp",
- "GnssConfiguration.cpp",
"service.cpp",
],
shared_libs: [
diff --git a/gnss/2.1/default/Gnss.cpp b/gnss/2.1/default/Gnss.cpp
deleted file mode 100644
index 16f2bf3..0000000
--- a/gnss/2.1/default/Gnss.cpp
+++ /dev/null
@@ -1,494 +0,0 @@
-/*
- * Copyright (C) 2019 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 "Gnss"
-
-#include "Gnss.h"
-#include <log/log.h>
-#include <sys/epoll.h>
-#include <string>
-#include "GnssAntennaInfo.h"
-#include "GnssDebug.h"
-#include "GnssMeasurement.h"
-#include "GnssMeasurementCorrections.h"
-#include "Utils.h"
-
-using ::android::hardware::gnss::common::Utils;
-using ::android::hardware::gnss::measurement_corrections::V1_1::implementation::
- GnssMeasurementCorrections;
-
-namespace android {
-namespace hardware {
-namespace gnss {
-namespace V2_1 {
-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()},
- mHardwareModeOn(false),
- mGnssFd(-1) {}
-
-Gnss::~Gnss() {
- stop();
-}
-
-std::unique_ptr<V2_0::GnssLocation> Gnss::getLocationFromHW() {
- char inputBuffer[INPUT_BUFFER_SIZE];
- mHardwareModeOn = false;
- if (mGnssFd == -1) {
- mGnssFd = open(GNSS_PATH, O_RDWR | O_NONBLOCK);
- }
- if (mGnssFd == -1) {
- return nullptr;
- }
- // Send control message to device
- int bytes_write = write(mGnssFd, CMD_GET_LOCATION, strlen(CMD_GET_LOCATION));
- if (bytes_write <= 0) {
- return nullptr;
- }
-
- struct epoll_event ev, events[1];
- ev.data.fd = mGnssFd;
- ev.events = EPOLLIN;
- int epoll_fd = epoll_create1(0);
- epoll_ctl(epoll_fd, EPOLL_CTL_ADD, mGnssFd, &ev);
- int bytes_read = -1;
- std::string inputStr = "";
- int epoll_ret = epoll_wait(epoll_fd, events, 1, mMinIntervalMs);
- // Indicates it is a hardwareMode, don't need to wait outside.
- mHardwareModeOn = true;
- if (epoll_ret == -1) {
- return nullptr;
- }
- while (true) {
- bytes_read = read(mGnssFd, &inputBuffer, INPUT_BUFFER_SIZE);
- if (bytes_read <= 0) {
- break;
- }
- inputStr += std::string(inputBuffer, bytes_read);
- }
- return NmeaFixInfo::getLocationFromInputStr(inputStr);
-}
-
-Return<bool> Gnss::start() {
- if (mIsActive) {
- ALOGW("Gnss has started. Restarting...");
- stop();
- }
-
- mIsActive = true;
- mThread = std::thread([this]() {
- while (mIsActive == true) {
- auto svStatus = filterBlacklistedSatellitesV2_1(Utils::getMockSvInfoListV2_1());
- this->reportSvStatus(svStatus);
-
- auto currentLocation = getLocationFromHW();
- if (currentLocation != nullptr) {
- this->reportLocation(*currentLocation);
- } else {
- 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);
- }
-
- // Only need do the sleep in the static location mode, which mocks the "wait
- // for" hardware behavior.
- if (!mHardwareModeOn) {
- std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs));
- }
- }
- }
- });
- return true;
-}
-
-hidl_vec<GnssSvInfo> Gnss::filterBlacklistedSatellitesV2_1(hidl_vec<GnssSvInfo> gnssSvInfoList) {
- for (uint32_t i = 0; i < gnssSvInfoList.size(); i++) {
- if (mGnssConfiguration->isBlacklistedV2_1(gnssSvInfoList[i])) {
- gnssSvInfoList[i].v2_0.v1_0.svFlag &=
- ~static_cast<uint8_t>(V1_0::IGnssCallback::GnssSvFlags::USED_IN_FIX);
- }
- }
- return gnssSvInfoList;
-}
-
-Return<bool> Gnss::stop() {
- ALOGD("stop");
- mIsActive = false;
- if (mThread.joinable()) {
- mThread.join();
- }
- if (mGnssFd != -1) {
- close(mGnssFd);
- mGnssFd = -1;
- }
- return true;
-}
-
-// Methods from V1_0::IGnss follow.
-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() {
- sGnssCallback_2_1 = nullptr;
- sGnssCallback_2_0 = nullptr;
- return Void();
-}
-
-Return<bool> Gnss::injectTime(int64_t, int64_t, int32_t) {
- return true;
-}
-
-Return<bool> Gnss::injectLocation(double, double, float) {
- return true;
-}
-
-Return<void> Gnss::deleteAidingData(V1_0::IGnss::GnssAidingData) {
- // TODO implement
- return Void();
-}
-
-Return<bool> Gnss::setPositionMode(V1_0::IGnss::GnssPositionMode,
- V1_0::IGnss::GnssPositionRecurrence, uint32_t minIntervalMs,
- uint32_t, uint32_t) {
- mMinIntervalMs = minIntervalMs;
- return true;
-}
-
-Return<sp<V1_0::IAGnssRil>> Gnss::getExtensionAGnssRil() {
- // TODO implement
- return ::android::sp<V1_0::IAGnssRil>{};
-}
-
-Return<sp<V1_0::IGnssGeofencing>> Gnss::getExtensionGnssGeofencing() {
- // TODO implement
- return ::android::sp<V1_0::IGnssGeofencing>{};
-}
-
-Return<sp<V1_0::IAGnss>> Gnss::getExtensionAGnss() {
- // TODO implement
- return ::android::sp<V1_0::IAGnss>{};
-}
-
-Return<sp<V1_0::IGnssNi>> Gnss::getExtensionGnssNi() {
- // TODO implement
- return ::android::sp<V1_0::IGnssNi>{};
-}
-
-Return<sp<V1_0::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement() {
- ALOGD("Gnss::getExtensionGnssMeasurement");
- return new GnssMeasurement();
-}
-
-Return<sp<V1_0::IGnssNavigationMessage>> Gnss::getExtensionGnssNavigationMessage() {
- // TODO implement
- return ::android::sp<V1_0::IGnssNavigationMessage>{};
-}
-
-Return<sp<V1_0::IGnssXtra>> Gnss::getExtensionXtra() {
- // TODO implement
- return ::android::sp<V1_0::IGnssXtra>{};
-}
-
-Return<sp<V1_0::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration() {
- // TODO implement
- return ::android::sp<V1_0::IGnssConfiguration>{};
-}
-
-Return<sp<V1_0::IGnssDebug>> Gnss::getExtensionGnssDebug() {
- return new V1_1::implementation::GnssDebug();
-}
-
-Return<sp<V1_0::IGnssBatching>> Gnss::getExtensionGnssBatching() {
- // TODO implement
- return ::android::sp<V1_0::IGnssBatching>{};
-}
-
-// Methods from V1_1::IGnss follow.
-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,
- V1_0::IGnss::GnssPositionRecurrence, uint32_t minIntervalMs,
- uint32_t, uint32_t, bool) {
- mMinIntervalMs = minIntervalMs;
- return true;
-}
-
-Return<sp<V1_1::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_1_1() {
- // TODO implement
- return ::android::sp<V1_1::IGnssConfiguration>{};
-}
-
-Return<sp<V1_1::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_1_1() {
- // TODO implement
- return ::android::sp<V1_1::IGnssMeasurement>{};
-}
-
-Return<bool> Gnss::injectBestLocation(const V1_0::GnssLocation&) {
- return true;
-}
-
-// Methods from V2_0::IGnss follow.
-Return<bool> Gnss::setCallback_2_0(const sp<V2_0::IGnssCallback>& callback) {
- ALOGD("Gnss::setCallback_2_0");
- if (callback == nullptr) {
- ALOGE("%s: Null callback ignored", __func__);
- return false;
- }
-
- sGnssCallback_2_0 = callback;
-
- using Capabilities = V2_0::IGnssCallback::Capabilities;
- const auto capabilities = Capabilities::MEASUREMENTS | Capabilities::MEASUREMENT_CORRECTIONS |
- Capabilities::LOW_POWER_MODE | Capabilities::SATELLITE_BLACKLIST;
- auto ret = sGnssCallback_2_0->gnssSetCapabilitiesCb_2_0(capabilities);
- if (!ret.isOk()) {
- ALOGE("%s: Unable to invoke callback", __func__);
- }
-
- V1_1::IGnssCallback::GnssSystemInfo gnssInfo = {.yearOfHw = 2019};
-
- ret = sGnssCallback_2_0->gnssSetSystemInfoCb(gnssInfo);
- if (!ret.isOk()) {
- ALOGE("%s: Unable to invoke callback", __func__);
- }
-
- auto gnssName = "Google Mock GNSS Implementation v2.1";
- ret = sGnssCallback_2_0->gnssNameCb(gnssName);
- if (!ret.isOk()) {
- ALOGE("%s: Unable to invoke callback", __func__);
- }
-
- return true;
-}
-
-Return<sp<V2_0::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_2_0() {
- ALOGD("Gnss::getExtensionGnssConfiguration_2_0");
- return mGnssConfiguration;
-}
-
-Return<sp<V2_0::IGnssDebug>> Gnss::getExtensionGnssDebug_2_0() {
- // TODO implement
- return ::android::sp<V2_0::IGnssDebug>{};
-}
-
-Return<sp<V2_0::IAGnss>> Gnss::getExtensionAGnss_2_0() {
- // TODO implement
- return ::android::sp<V2_0::IAGnss>{};
-}
-
-Return<sp<V2_0::IAGnssRil>> Gnss::getExtensionAGnssRil_2_0() {
- // TODO implement
- return ::android::sp<V2_0::IAGnssRil>{};
-}
-
-Return<sp<V2_0::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_2_0() {
- ALOGD("Gnss::getExtensionGnssMeasurement_2_0");
- return new GnssMeasurement();
-}
-
-Return<sp<measurement_corrections::V1_0::IMeasurementCorrections>>
-Gnss::getExtensionMeasurementCorrections() {
- ALOGD("Gnss::getExtensionMeasurementCorrections()");
- return new GnssMeasurementCorrections();
-}
-
-Return<sp<visibility_control::V1_0::IGnssVisibilityControl>> Gnss::getExtensionVisibilityControl() {
- // TODO implement
- return ::android::sp<visibility_control::V1_0::IGnssVisibilityControl>{};
-}
-
-Return<sp<V2_0::IGnssBatching>> Gnss::getExtensionGnssBatching_2_0() {
- // TODO implement
- return ::android::sp<V2_0::IGnssBatching>{};
-}
-
-Return<bool> Gnss::injectBestLocation_2_0(const V2_0::GnssLocation&) {
- // TODO(b/124012850): Implement function.
- return bool{};
-}
-
-// Methods from V2_1::IGnss follow.
-Return<bool> Gnss::setCallback_2_1(const sp<V2_1::IGnssCallback>& callback) {
- ALOGD("Gnss::setCallback_2_1");
- if (callback == nullptr) {
- ALOGE("%s: Null callback ignored", __func__);
- return false;
- }
-
- sGnssCallback_2_1 = callback;
-
- using Capabilities = V2_1::IGnssCallback::Capabilities;
- const auto capabilities = Capabilities::MEASUREMENTS | Capabilities::MEASUREMENT_CORRECTIONS |
- Capabilities::LOW_POWER_MODE | Capabilities::SATELLITE_BLACKLIST |
- Capabilities::ANTENNA_INFO;
- auto ret = sGnssCallback_2_1->gnssSetCapabilitiesCb_2_1(capabilities);
- if (!ret.isOk()) {
- ALOGE("%s: Unable to invoke callback", __func__);
- }
-
- V1_1::IGnssCallback::GnssSystemInfo gnssInfo = {.yearOfHw = 2020};
-
- ret = sGnssCallback_2_1->gnssSetSystemInfoCb(gnssInfo);
- if (!ret.isOk()) {
- ALOGE("%s: Unable to invoke callback", __func__);
- }
-
- auto gnssName = "Android Mock GNSS Implementation v2.1";
- ret = sGnssCallback_2_1->gnssNameCb(gnssName);
- if (!ret.isOk()) {
- ALOGE("%s: Unable to invoke callback", __func__);
- }
-
- return true;
-}
-
-Return<sp<V2_1::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_2_1() {
- ALOGD("Gnss::getExtensionGnssMeasurement_2_1");
- return new GnssMeasurement();
-}
-
-Return<sp<V2_1::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_2_1() {
- ALOGD("Gnss::getExtensionGnssConfiguration_2_1");
- return mGnssConfiguration;
-}
-
-Return<sp<measurement_corrections::V1_1::IMeasurementCorrections>>
-Gnss::getExtensionMeasurementCorrections_1_1() {
- ALOGD("Gnss::getExtensionMeasurementCorrections_1_1()");
- return new GnssMeasurementCorrections();
-}
-
-Return<sp<V2_1::IGnssAntennaInfo>> Gnss::getExtensionGnssAntennaInfo() {
- ALOGD("Gnss::getExtensionGnssAntennaInfo");
- return new GnssAntennaInfo();
-}
-
-void Gnss::reportSvStatus(const hidl_vec<GnssSvInfo>& svInfoList) const {
- std::unique_lock<std::mutex> lock(mMutex);
- // TODO(skz): update this to call 2_0 callback if non-null
- if (sGnssCallback_2_1 == nullptr) {
- ALOGE("%s: sGnssCallback v2.1 is null.", __func__);
- return;
- }
- auto ret = sGnssCallback_2_1->gnssSvStatusCb_2_1(svInfoList);
- if (!ret.isOk()) {
- ALOGE("%s: Unable to invoke callback", __func__);
- }
-}
-
-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) {
- auto ret = sGnssCallback_2_1->gnssLocationCb_2_0(location);
- if (!ret.isOk()) {
- ALOGE("%s: Unable to invoke callback v2.1", __func__);
- }
- return;
- }
- if (sGnssCallback_2_0 == nullptr) {
- ALOGE("%s: No non-null callback", __func__);
- return;
- }
- auto ret = sGnssCallback_2_0->gnssLocationCb_2_0(location);
- if (!ret.isOk()) {
- ALOGE("%s: Unable to invoke callback v2.0", __func__);
- }
-}
-
-} // namespace implementation
-} // namespace V2_1
-} // namespace gnss
-} // namespace hardware
-} // namespace android
diff --git a/gnss/2.1/default/Gnss.h b/gnss/2.1/default/Gnss.h
deleted file mode 100644
index 9af0d46..0000000
--- a/gnss/2.1/default/Gnss.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (C) 2019 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.
- */
-
-#pragma once
-
-#include <android/hardware/gnss/2.1/IGnss.h>
-#include <hidl/MQDescriptor.h>
-#include <hidl/Status.h>
-#include <atomic>
-#include <mutex>
-#include <thread>
-#include "GnssAntennaInfo.h"
-#include "GnssConfiguration.h"
-#include "NmeaFixInfo.h"
-
-namespace android {
-namespace hardware {
-namespace gnss {
-namespace V2_1 {
-
-using GnssSvInfo = IGnssCallback::GnssSvInfo;
-using ::android::hardware::gnss::common::NmeaFixInfo;
-
-namespace implementation {
-
-constexpr int INPUT_BUFFER_SIZE = 128;
-constexpr char CMD_GET_LOCATION[] = "CMD_GET_LOCATION";
-constexpr char GNSS_PATH[] = "/dev/gnss0";
-
-struct Gnss : public IGnss {
- Gnss();
- ~Gnss();
- // Methods from V1_0::IGnss follow.
- Return<bool> setCallback(const sp<V1_0::IGnssCallback>& callback) override;
- Return<bool> start() override;
- Return<bool> stop() override;
- Return<void> cleanup() override;
- Return<bool> injectTime(int64_t timeMs, int64_t timeReferenceMs,
- int32_t uncertaintyMs) override;
- Return<bool> injectLocation(double latitudeDegrees, double longitudeDegrees,
- float accuracyMeters) override;
- Return<void> deleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags) override;
- Return<bool> setPositionMode(V1_0::IGnss::GnssPositionMode mode,
- V1_0::IGnss::GnssPositionRecurrence recurrence,
- uint32_t minIntervalMs, uint32_t preferredAccuracyMeters,
- uint32_t preferredTimeMs) override;
- Return<sp<V1_0::IAGnssRil>> getExtensionAGnssRil() override;
- Return<sp<V1_0::IGnssGeofencing>> getExtensionGnssGeofencing() override;
- Return<sp<V1_0::IAGnss>> getExtensionAGnss() override;
- Return<sp<V1_0::IGnssNi>> getExtensionGnssNi() override;
- Return<sp<V1_0::IGnssMeasurement>> getExtensionGnssMeasurement() override;
- Return<sp<V1_0::IGnssNavigationMessage>> getExtensionGnssNavigationMessage() override;
- Return<sp<V1_0::IGnssXtra>> getExtensionXtra() override;
- Return<sp<V1_0::IGnssConfiguration>> getExtensionGnssConfiguration() override;
- Return<sp<V1_0::IGnssDebug>> getExtensionGnssDebug() override;
- Return<sp<V1_0::IGnssBatching>> getExtensionGnssBatching() override;
-
- // Methods from V1_1::IGnss follow.
- Return<bool> setCallback_1_1(const sp<V1_1::IGnssCallback>& callback) override;
- Return<bool> setPositionMode_1_1(V1_0::IGnss::GnssPositionMode mode,
- V1_0::IGnss::GnssPositionRecurrence recurrence,
- uint32_t minIntervalMs, uint32_t preferredAccuracyMeters,
- uint32_t preferredTimeMs, bool lowPowerMode) override;
- Return<sp<V1_1::IGnssConfiguration>> getExtensionGnssConfiguration_1_1() override;
- Return<sp<V1_1::IGnssMeasurement>> getExtensionGnssMeasurement_1_1() override;
- Return<bool> injectBestLocation(const V1_0::GnssLocation& location) override;
-
- // Methods from V2_0::IGnss follow.
- Return<bool> setCallback_2_0(const sp<V2_0::IGnssCallback>& callback) override;
- Return<sp<V2_0::IGnssConfiguration>> getExtensionGnssConfiguration_2_0() override;
- Return<sp<V2_0::IGnssDebug>> getExtensionGnssDebug_2_0() override;
- Return<sp<V2_0::IAGnss>> getExtensionAGnss_2_0() override;
- Return<sp<V2_0::IAGnssRil>> getExtensionAGnssRil_2_0() override;
- Return<sp<V2_0::IGnssMeasurement>> getExtensionGnssMeasurement_2_0() override;
- Return<sp<measurement_corrections::V1_0::IMeasurementCorrections>>
- getExtensionMeasurementCorrections() override;
- Return<sp<visibility_control::V1_0::IGnssVisibilityControl>> getExtensionVisibilityControl()
- override;
- Return<sp<V2_0::IGnssBatching>> getExtensionGnssBatching_2_0() override;
- Return<bool> injectBestLocation_2_0(const V2_0::GnssLocation& location) override;
-
- // Methods from V2_1::IGnss follow.
- Return<bool> setCallback_2_1(const sp<V2_1::IGnssCallback>& callback) override;
- Return<sp<V2_1::IGnssMeasurement>> getExtensionGnssMeasurement_2_1() override;
- Return<sp<V2_1::IGnssConfiguration>> getExtensionGnssConfiguration_2_1() override;
- Return<sp<measurement_corrections::V1_1::IMeasurementCorrections>>
- getExtensionMeasurementCorrections_1_1() override;
- Return<sp<V2_1::IGnssAntennaInfo>> getExtensionGnssAntennaInfo() override;
-
- private:
- std::unique_ptr<V2_0::GnssLocation> getLocationFromHW();
- 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;
- std::atomic<bool> mHardwareModeOn;
- std::atomic<int> mGnssFd;
- std::thread mThread;
-
- mutable std::mutex mMutex;
- hidl_vec<GnssSvInfo> filterBlacklistedSatellitesV2_1(hidl_vec<GnssSvInfo> gnssSvInfoList);
-};
-
-} // namespace implementation
-} // namespace V2_1
-} // namespace gnss
-} // namespace hardware
-} // namespace android
diff --git a/gnss/2.1/default/GnssAntennaInfo.cpp b/gnss/2.1/default/GnssAntennaInfo.cpp
deleted file mode 100644
index ed183a9..0000000
--- a/gnss/2.1/default/GnssAntennaInfo.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (C) 2020 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 "GnssAntennaInfo"
-
-#include "GnssAntennaInfo.h"
-#include "Utils.h"
-
-#include <log/log.h>
-
-using ::android::hardware::gnss::common::Utils;
-
-namespace android {
-namespace hardware {
-namespace gnss {
-namespace V2_1 {
-namespace implementation {
-
-sp<IGnssAntennaInfoCallback> GnssAntennaInfo::sCallback = nullptr;
-
-GnssAntennaInfo::GnssAntennaInfo() : mMinIntervalMillis(1000) {}
-
-GnssAntennaInfo::~GnssAntennaInfo() {
- stop();
-}
-
-// Methods from ::android::hardware::gnss::V2_1::IGnssAntennaInfo follow.
-Return<GnssAntennaInfo::GnssAntennaInfoStatus> GnssAntennaInfo::setCallback(
- const sp<IGnssAntennaInfoCallback>& callback) {
- ALOGD("setCallback");
- std::unique_lock<std::mutex> lock(mMutex);
- sCallback = callback;
-
- if (mIsActive) {
- ALOGW("GnssAntennaInfo callback already set. Resetting the callback...");
- stop();
- }
- start();
-
- return GnssAntennaInfoStatus::SUCCESS;
-}
-
-Return<void> GnssAntennaInfo::close() {
- ALOGD("close");
- stop();
- std::unique_lock<std::mutex> lock(mMutex);
- sCallback = nullptr;
- return Void();
-}
-
-// Private methods
-void GnssAntennaInfo::start() {
- ALOGD("start");
- mIsActive = true;
- mThread = std::thread([this]() {
- while (mIsActive == true) {
- if (sCallback != nullptr) {
- auto antennaInfos = Utils::getMockAntennaInfos();
- this->reportAntennaInfo(antennaInfos);
- }
-
- /** For mock implementation this is good. On real device, we should only report
- antennaInfo at start and when there is a configuration change. **/
- std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMillis));
- }
- });
-}
-
-void GnssAntennaInfo::stop() {
- ALOGD("stop");
- mIsActive = false;
- if (mThread.joinable()) {
- mThread.join();
- }
-}
-
-void GnssAntennaInfo::reportAntennaInfo(
- const hidl_vec<IGnssAntennaInfoCallback::GnssAntennaInfo>& antennaInfo) const {
- std::unique_lock<std::mutex> lock(mMutex);
-
- if (sCallback == nullptr) {
- ALOGE("%s: No non-null callback", __func__);
- return;
- }
-
- auto ret = sCallback->gnssAntennaInfoCb(antennaInfo);
- if (!ret.isOk()) {
- ALOGE("%s: Unable to invoke callback", __func__);
- }
-}
-
-} // namespace implementation
-} // namespace V2_1
-} // namespace gnss
-} // namespace hardware
-} // namespace android
\ No newline at end of file
diff --git a/gnss/2.1/default/GnssAntennaInfo.h b/gnss/2.1/default/GnssAntennaInfo.h
deleted file mode 100644
index f2ce9a8..0000000
--- a/gnss/2.1/default/GnssAntennaInfo.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2020 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_V2_1_GNSSANTENNAINFO_H
-#define ANDROID_HARDWARE_GNSS_V2_1_GNSSANTENNAINFO_H
-
-#include <android/hardware/gnss/2.1/IGnssAntennaInfo.h>
-
-#include <mutex>
-#include <thread>
-
-namespace android {
-namespace hardware {
-namespace gnss {
-namespace V2_1 {
-namespace implementation {
-
-using ::android::sp;
-using ::android::hardware::Return;
-using ::android::hardware::Void;
-
-struct GnssAntennaInfo : public IGnssAntennaInfo {
- GnssAntennaInfo();
- ~GnssAntennaInfo();
-
- // Methods from ::android::hardware::gnss::V2_1::IGnssAntennaInfo follow.
- Return<GnssAntennaInfoStatus> setCallback(
- const sp<IGnssAntennaInfoCallback>& callback) override;
- Return<void> close() override;
-
- private:
- void start();
- void stop();
- void reportAntennaInfo(
- const hidl_vec<IGnssAntennaInfoCallback::GnssAntennaInfo>& antennaInfo) const;
-
- // Guarded by mMutex
- static sp<IGnssAntennaInfoCallback> sCallback;
-
- std::atomic<long> mMinIntervalMillis;
- std::atomic<bool> mIsActive;
- std::thread mThread;
-
- // Synchronization lock for sCallback
- mutable std::mutex mMutex;
-};
-
-} // namespace implementation
-} // namespace V2_1
-} // namespace gnss
-} // namespace hardware
-} // namespace android
-
-#endif // ANDROID_HARDWARE_GNSS_V2_1_GNSSCONFIGURATION_H
\ No newline at end of file
diff --git a/gnss/2.1/default/GnssConfiguration.cpp b/gnss/2.1/default/GnssConfiguration.cpp
deleted file mode 100644
index cd8f07f..0000000
--- a/gnss/2.1/default/GnssConfiguration.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) 2019 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 "GnssConfiguration"
-
-#include "GnssConfiguration.h"
-#include <log/log.h>
-
-namespace android {
-namespace hardware {
-namespace gnss {
-namespace V2_1 {
-namespace implementation {
-
-// Methods from ::android::hardware::gnss::V1_0::IGnssConfiguration follow.
-Return<bool> GnssConfiguration::setSuplEs(bool enable) {
- ALOGD("setSuplEs enable: %d", enable);
- // Method deprecated in 2.0 and not expected to be called by the framework.
- return false;
-}
-
-Return<bool> GnssConfiguration::setSuplVersion(uint32_t) {
- return true;
-}
-
-Return<bool> GnssConfiguration::setSuplMode(hidl_bitfield<SuplMode>) {
- return true;
-}
-
-Return<bool> GnssConfiguration::setGpsLock(hidl_bitfield<GpsLock> gpsLock) {
- ALOGD("setGpsLock gpsLock: %hhu", static_cast<GpsLock>(gpsLock));
- // Method deprecated in 2.0 and not expected to be called by the framework.
- return false;
-}
-
-Return<bool> GnssConfiguration::setLppProfile(hidl_bitfield<LppProfile>) {
- return true;
-}
-
-Return<bool> GnssConfiguration::setGlonassPositioningProtocol(hidl_bitfield<GlonassPosProtocol>) {
- return true;
-}
-
-Return<bool> GnssConfiguration::setEmergencySuplPdn(bool) {
- return true;
-}
-
-// Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow.
-Return<bool> GnssConfiguration::setBlacklist(
- const hidl_vec<V1_1::IGnssConfiguration::BlacklistedSource>&) {
- // TODO (b/122463906): Reuse 1.1 implementation.
- return bool{};
-}
-
-// Methods from ::android::hardware::gnss::V2_0::IGnssConfiguration follow.
-Return<bool> GnssConfiguration::setEsExtensionSec(uint32_t emergencyExtensionSeconds) {
- ALOGD("setEsExtensionSec emergencyExtensionSeconds: %d", emergencyExtensionSeconds);
- return true;
-}
-
-// Methods from ::android::hardware::gnss::V2_1::IGnssConfiguration follow.
-Return<bool> GnssConfiguration::setBlacklist_2_1(
- const hidl_vec<V2_1::IGnssConfiguration::BlacklistedSource>& sourceList) {
- std::unique_lock<std::recursive_mutex> lock(mMutex);
- mBlacklistedConstellationSet.clear();
- mBlacklistedSourceSet.clear();
- for (auto source : sourceList) {
- if (source.svid == 0) {
- // Wildcard blacklist, i.e., blacklist entire constellation.
- mBlacklistedConstellationSet.insert(source.constellation);
- } else {
- mBlacklistedSourceSet.insert(source);
- }
- }
- return true;
-}
-
-Return<bool> GnssConfiguration::isBlacklistedV2_1(const GnssSvInfoV2_1& gnssSvInfo) const {
- std::unique_lock<std::recursive_mutex> lock(mMutex);
- if (mBlacklistedConstellationSet.find(gnssSvInfo.v2_0.constellation) !=
- mBlacklistedConstellationSet.end()) {
- return true;
- }
- BlacklistedSourceV2_1 source = {.constellation = gnssSvInfo.v2_0.constellation,
- .svid = gnssSvInfo.v2_0.v1_0.svid};
- return (mBlacklistedSourceSet.find(source) != mBlacklistedSourceSet.end());
-}
-
-} // namespace implementation
-} // namespace V2_1
-} // namespace gnss
-} // namespace hardware
-} // namespace android
\ No newline at end of file
diff --git a/gnss/2.1/default/GnssConfiguration.h b/gnss/2.1/default/GnssConfiguration.h
deleted file mode 100644
index 662d61d..0000000
--- a/gnss/2.1/default/GnssConfiguration.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (C) 2019 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_V2_1_GNSSCONFIGURATION_H
-#define ANDROID_HARDWARE_GNSS_V2_1_GNSSCONFIGURATION_H
-
-#include <android/hardware/gnss/2.1/IGnssCallback.h>
-#include <android/hardware/gnss/2.1/IGnssConfiguration.h>
-#include <hidl/MQDescriptor.h>
-#include <hidl/Status.h>
-#include <mutex>
-#include <unordered_set>
-
-namespace android {
-namespace hardware {
-namespace gnss {
-namespace V2_1 {
-namespace implementation {
-
-using ::android::sp;
-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 BlacklistedSourceV2_1 =
- ::android::hardware::gnss::V2_1::IGnssConfiguration::BlacklistedSource;
-using GnssConstellationTypeV2_0 = V2_0::GnssConstellationType;
-using GnssSvInfoV2_1 = V2_1::IGnssCallback::GnssSvInfo;
-
-struct BlacklistedSourceHashV2_1 {
- inline int operator()(const BlacklistedSourceV2_1& source) const {
- return int(source.constellation) * 1000 + int(source.svid);
- }
-};
-
-struct BlacklistedSourceEqualV2_1 {
- inline bool operator()(const BlacklistedSourceV2_1& s1, const BlacklistedSourceV2_1& s2) const {
- return (s1.constellation == s2.constellation) && (s1.svid == s2.svid);
- }
-};
-
-using BlacklistedSourceSetV2_1 =
- std::unordered_set<BlacklistedSourceV2_1, BlacklistedSourceHashV2_1,
- BlacklistedSourceEqualV2_1>;
-using BlacklistedConstellationSetV2_1 = std::unordered_set<GnssConstellationTypeV2_0>;
-
-struct GnssConfiguration : public IGnssConfiguration {
- // Methods from ::android::hardware::gnss::V1_0::IGnssConfiguration follow.
- Return<bool> setSuplEs(bool enabled) override;
- Return<bool> setSuplVersion(uint32_t version) override;
- Return<bool> setSuplMode(hidl_bitfield<SuplMode> mode) override;
- Return<bool> setGpsLock(hidl_bitfield<GpsLock> lock) override;
- Return<bool> setLppProfile(hidl_bitfield<LppProfile> lppProfile) override;
- Return<bool> setGlonassPositioningProtocol(hidl_bitfield<GlonassPosProtocol> protocol) override;
- Return<bool> setEmergencySuplPdn(bool enable) override;
-
- // Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow.
- Return<bool> setBlacklist(
- const hidl_vec<V1_1::IGnssConfiguration::BlacklistedSource>& blacklist) override;
-
- std::recursive_mutex& getMutex() const;
-
- // Methods from ::android::hardware::gnss::V2_0::IGnssConfiguration follow.
- Return<bool> setEsExtensionSec(uint32_t emergencyExtensionSeconds) override;
-
- // Methods from ::android::hardware::gnss::V2_1::IGnssConfiguration follow.
- Return<bool> setBlacklist_2_1(
- const hidl_vec<V2_1::IGnssConfiguration::BlacklistedSource>& blacklist) override;
-
- Return<bool> isBlacklistedV2_1(const GnssSvInfoV2_1& gnssSvInfo) const;
-
- private:
- mutable std::recursive_mutex mMutex;
-
- BlacklistedSourceSetV2_1 mBlacklistedSourceSet;
- BlacklistedConstellationSetV2_1 mBlacklistedConstellationSet;
-};
-
-} // namespace implementation
-} // namespace V2_1
-} // namespace gnss
-} // namespace hardware
-} // namespace android
-
-#endif // ANDROID_HARDWARE_GNSS_V2_1_GNSSCONFIGURATION_H
\ No newline at end of file
diff --git a/gnss/2.1/default/GnssDebug.cpp b/gnss/2.1/default/GnssDebug.cpp
deleted file mode 100644
index a9f7ded..0000000
--- a/gnss/2.1/default/GnssDebug.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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
diff --git a/gnss/2.1/default/GnssDebug.h b/gnss/2.1/default/GnssDebug.h
deleted file mode 100644
index 969d337..0000000
--- a/gnss/2.1/default/GnssDebug.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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_
diff --git a/gnss/2.1/default/GnssMeasurement.cpp b/gnss/2.1/default/GnssMeasurement.cpp
deleted file mode 100644
index 63bbc0a..0000000
--- a/gnss/2.1/default/GnssMeasurement.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright (C) 2019 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 "GnssMeasurement"
-
-#include "GnssMeasurement.h"
-#include <log/log.h>
-#include "Utils.h"
-
-namespace android {
-namespace hardware {
-namespace gnss {
-
-using common::Utils;
-
-namespace V2_1 {
-namespace implementation {
-
-sp<V2_1::IGnssMeasurementCallback> GnssMeasurement::sCallback_2_1 = nullptr;
-sp<V2_0::IGnssMeasurementCallback> GnssMeasurement::sCallback_2_0 = nullptr;
-
-GnssMeasurement::GnssMeasurement() : mMinIntervalMillis(1000) {}
-
-GnssMeasurement::~GnssMeasurement() {
- stop();
-}
-
-// Methods from V1_0::IGnssMeasurement follow.
-Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> GnssMeasurement::setCallback(
- const sp<V1_0::IGnssMeasurementCallback>&) {
- // TODO implement
- return V1_0::IGnssMeasurement::GnssMeasurementStatus{};
-}
-
-Return<void> GnssMeasurement::close() {
- ALOGD("close");
- stop();
- std::unique_lock<std::mutex> lock(mMutex);
- sCallback_2_1 = nullptr;
- sCallback_2_0 = nullptr;
- return Void();
-}
-
-// Methods from V1_1::IGnssMeasurement follow.
-Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> GnssMeasurement::setCallback_1_1(
- const sp<V1_1::IGnssMeasurementCallback>&, bool) {
- // TODO implement
- return V1_0::IGnssMeasurement::GnssMeasurementStatus{};
-}
-
-// Methods from V2_0::IGnssMeasurement follow.
-Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> GnssMeasurement::setCallback_2_0(
- const sp<V2_0::IGnssMeasurementCallback>& callback, bool) {
- ALOGD("setCallback_2_0");
- std::unique_lock<std::mutex> lock(mMutex);
- sCallback_2_0 = callback;
-
- if (mIsActive) {
- ALOGW("GnssMeasurement callback already set. Resetting the callback...");
- stop();
- }
- start();
-
- return V1_0::IGnssMeasurement::GnssMeasurementStatus::SUCCESS;
-}
-
-// Methods from V2_1::IGnssMeasurement follow.
-Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> GnssMeasurement::setCallback_2_1(
- const sp<V2_1::IGnssMeasurementCallback>& callback, bool) {
- ALOGD("setCallback_2_1");
- std::unique_lock<std::mutex> lock(mMutex);
- sCallback_2_1 = callback;
-
- if (mIsActive) {
- ALOGW("GnssMeasurement callback already set. Resetting the callback...");
- stop();
- }
- start();
-
- return V1_0::IGnssMeasurement::GnssMeasurementStatus::SUCCESS;
-}
-
-void GnssMeasurement::start() {
- ALOGD("start");
- mIsActive = true;
- mThread = std::thread([this]() {
- while (mIsActive == true) {
- if (sCallback_2_1 != nullptr) {
- auto measurement = Utils::getMockMeasurementV2_1();
- this->reportMeasurement(measurement);
- } else {
- auto measurement = Utils::getMockMeasurementV2_0();
- this->reportMeasurement(measurement);
- }
-
- std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMillis));
- }
- });
-}
-
-void GnssMeasurement::stop() {
- ALOGD("stop");
- mIsActive = false;
- if (mThread.joinable()) {
- mThread.join();
- }
-}
-
-void GnssMeasurement::reportMeasurement(const GnssDataV2_0& data) {
- ALOGD("reportMeasurement()");
- std::unique_lock<std::mutex> lock(mMutex);
- if (sCallback_2_0 == nullptr) {
- ALOGE("%s: GnssMeasurement::sCallback_2_0 is null.", __func__);
- return;
- }
- auto ret = sCallback_2_0->gnssMeasurementCb_2_0(data);
- if (!ret.isOk()) {
- ALOGE("%s: Unable to invoke callback", __func__);
- }
-}
-
-void GnssMeasurement::reportMeasurement(const GnssDataV2_1& data) {
- ALOGD("reportMeasurement()");
- std::unique_lock<std::mutex> lock(mMutex);
- if (sCallback_2_1 == nullptr) {
- ALOGE("%s: GnssMeasurement::sCallback_2_1 is null.", __func__);
- return;
- }
- auto ret = sCallback_2_1->gnssMeasurementCb_2_1(data);
- if (!ret.isOk()) {
- ALOGE("%s: Unable to invoke callback", __func__);
- }
-}
-
-} // namespace implementation
-} // namespace V2_1
-} // namespace gnss
-} // namespace hardware
-} // namespace android
diff --git a/gnss/2.1/default/GnssMeasurement.h b/gnss/2.1/default/GnssMeasurement.h
deleted file mode 100644
index d446419..0000000
--- a/gnss/2.1/default/GnssMeasurement.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2019 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.
- */
-
-#pragma once
-
-#include <android/hardware/gnss/2.1/IGnssMeasurement.h>
-#include <hidl/MQDescriptor.h>
-#include <hidl/Status.h>
-#include <atomic>
-#include <mutex>
-#include <thread>
-
-namespace android {
-namespace hardware {
-namespace gnss {
-namespace V2_1 {
-namespace implementation {
-
-using GnssDataV2_1 = V2_1::IGnssMeasurementCallback::GnssData;
-using GnssDataV2_0 = V2_0::IGnssMeasurementCallback::GnssData;
-
-using ::android::sp;
-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;
-
-struct GnssMeasurement : public IGnssMeasurement {
- GnssMeasurement();
- ~GnssMeasurement();
- // Methods from V1_0::IGnssMeasurement follow.
- Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> setCallback(
- const sp<V1_0::IGnssMeasurementCallback>& callback) override;
- Return<void> close() override;
-
- // Methods from V1_1::IGnssMeasurement follow.
- Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> setCallback_1_1(
- const sp<V1_1::IGnssMeasurementCallback>& callback, bool enableFullTracking) override;
-
- // Methods from V2_0::IGnssMeasurement follow.
- Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> setCallback_2_0(
- const sp<V2_0::IGnssMeasurementCallback>& callback, bool enableFullTracking) override;
-
- // Methods from V2_1::IGnssMeasurement follow.
- Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> setCallback_2_1(
- const sp<V2_1::IGnssMeasurementCallback>& callback, bool enableFullTracking) override;
-
- private:
- void start();
- void stop();
- void reportMeasurement(const GnssDataV2_0&);
- void reportMeasurement(const GnssDataV2_1&);
-
- // Guarded by mMutex
- static sp<V2_1::IGnssMeasurementCallback> sCallback_2_1;
-
- // Guarded by mMutex
- static sp<V2_0::IGnssMeasurementCallback> sCallback_2_0;
-
- std::atomic<long> mMinIntervalMillis;
- std::atomic<bool> mIsActive;
- std::thread mThread;
-
- // Synchronization lock for sCallback_2_1 and sCallback_2_0
- mutable std::mutex mMutex;
-};
-
-} // namespace implementation
-} // namespace V2_1
-} // namespace gnss
-} // namespace hardware
-} // namespace android
diff --git a/gnss/2.1/default/GnssMeasurementCorrections.cpp b/gnss/2.1/default/GnssMeasurementCorrections.cpp
deleted file mode 100644
index accf62b..0000000
--- a/gnss/2.1/default/GnssMeasurementCorrections.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (C) 2019 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 "GnssMeasurementCorrections"
-
-#include "GnssMeasurementCorrections.h"
-#include <log/log.h>
-
-namespace android {
-namespace hardware {
-namespace gnss {
-namespace measurement_corrections {
-namespace V1_1 {
-namespace implementation {
-
-// Methods from V1_0::IMeasurementCorrections follow.
-Return<bool> GnssMeasurementCorrections::setCorrections(
- const V1_0::MeasurementCorrections& corrections) {
- ALOGD("setCorrections");
- ALOGD("corrections = lat: %f, lng: %f, alt: %f, hUnc: %f, vUnc: %f, toa: %llu, "
- "satCorrections.size: %d",
- corrections.latitudeDegrees, corrections.longitudeDegrees, corrections.altitudeMeters,
- corrections.horizontalPositionUncertaintyMeters,
- corrections.verticalPositionUncertaintyMeters,
- static_cast<unsigned long long>(corrections.toaGpsNanosecondsOfWeek),
- static_cast<int>(corrections.satCorrections.size()));
- for (auto singleSatCorrection : corrections.satCorrections) {
- ALOGD("singleSatCorrection = flags: %d, constellation: %d, svid: %d, cfHz: %f, probLos: %f,"
- " epl: %f, eplUnc: %f",
- static_cast<int>(singleSatCorrection.singleSatCorrectionFlags),
- static_cast<int>(singleSatCorrection.constellation),
- static_cast<int>(singleSatCorrection.svid), singleSatCorrection.carrierFrequencyHz,
- singleSatCorrection.probSatIsLos, singleSatCorrection.excessPathLengthMeters,
- singleSatCorrection.excessPathLengthUncertaintyMeters);
- ALOGD("reflecting plane = lat: %f, lng: %f, alt: %f, azm: %f",
- singleSatCorrection.reflectingPlane.latitudeDegrees,
- singleSatCorrection.reflectingPlane.longitudeDegrees,
- singleSatCorrection.reflectingPlane.altitudeMeters,
- singleSatCorrection.reflectingPlane.azimuthDegrees);
- }
-
- return true;
-}
-
-Return<bool> GnssMeasurementCorrections::setCallback(
- const sp<V1_0::IMeasurementCorrectionsCallback>& callback) {
- using Capabilities = V1_0::IMeasurementCorrectionsCallback::Capabilities;
- auto ret =
- callback->setCapabilitiesCb(Capabilities::LOS_SATS | Capabilities::EXCESS_PATH_LENGTH |
- Capabilities::REFLECTING_PLANE);
- if (!ret.isOk()) {
- ALOGE("%s: Unable to invoke callback", __func__);
- return false;
- }
- return true;
-}
-
-// Methods from V1_1::IMeasurementCorrections follow.
-Return<bool> GnssMeasurementCorrections::setCorrections_1_1(
- const V1_1::MeasurementCorrections& corrections) {
- ALOGD("setCorrections_1_1");
- ALOGD("corrections = lat: %f, lng: %f, alt: %f, hUnc: %f, vUnc: %f, toa: %llu,"
- "satCorrections.size: %d, hasEnvironmentBearing: %d, environmentBearingDeg: %f,"
- "environmentBearingUncDeg: %f",
- corrections.v1_0.latitudeDegrees, corrections.v1_0.longitudeDegrees,
- corrections.v1_0.altitudeMeters, corrections.v1_0.horizontalPositionUncertaintyMeters,
- corrections.v1_0.verticalPositionUncertaintyMeters,
- static_cast<unsigned long long>(corrections.v1_0.toaGpsNanosecondsOfWeek),
- static_cast<int>(corrections.v1_0.satCorrections.size()),
- corrections.hasEnvironmentBearing, corrections.environmentBearingDegrees,
- corrections.environmentBearingUncertaintyDegrees);
- for (auto singleSatCorrection : corrections.satCorrections) {
- ALOGD("singleSatCorrection = flags: %d, constellation: %d, svid: %d, cfHz: %f, probLos: %f,"
- " epl: %f, eplUnc: %f",
- static_cast<int>(singleSatCorrection.v1_0.singleSatCorrectionFlags),
- static_cast<int>(singleSatCorrection.constellation),
- static_cast<int>(singleSatCorrection.v1_0.svid),
- singleSatCorrection.v1_0.carrierFrequencyHz, singleSatCorrection.v1_0.probSatIsLos,
- singleSatCorrection.v1_0.excessPathLengthMeters,
- singleSatCorrection.v1_0.excessPathLengthUncertaintyMeters);
- ALOGD("reflecting plane = lat: %f, lng: %f, alt: %f, azm: %f",
- singleSatCorrection.v1_0.reflectingPlane.latitudeDegrees,
- singleSatCorrection.v1_0.reflectingPlane.longitudeDegrees,
- singleSatCorrection.v1_0.reflectingPlane.altitudeMeters,
- singleSatCorrection.v1_0.reflectingPlane.azimuthDegrees);
- }
-
- return true;
-}
-
-} // namespace implementation
-} // namespace V1_1
-} // namespace measurement_corrections
-} // namespace gnss
-} // namespace hardware
-} // namespace android
diff --git a/gnss/2.1/default/GnssMeasurementCorrections.h b/gnss/2.1/default/GnssMeasurementCorrections.h
deleted file mode 100644
index 036e855..0000000
--- a/gnss/2.1/default/GnssMeasurementCorrections.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2019 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.
- */
-
-#pragma once
-
-#include <android/hardware/gnss/measurement_corrections/1.1/IMeasurementCorrections.h>
-#include <hidl/MQDescriptor.h>
-#include <hidl/Status.h>
-
-namespace android {
-namespace hardware {
-namespace gnss {
-namespace measurement_corrections {
-namespace V1_1 {
-namespace implementation {
-
-using ::android::sp;
-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;
-
-struct GnssMeasurementCorrections : public IMeasurementCorrections {
- // Methods from V1_0::IMeasurementCorrections follow.
- Return<bool> setCorrections(const V1_0::MeasurementCorrections& corrections) override;
- Return<bool> setCallback(const sp<V1_0::IMeasurementCorrectionsCallback>& callback) override;
-
- // Methods from V1_1::IMeasurementCorrections follow.
- Return<bool> setCorrections_1_1(const V1_1::MeasurementCorrections& corrections) override;
-};
-
-} // namespace implementation
-} // namespace V1_1
-} // namespace measurement_corrections
-} // namespace gnss
-} // namespace hardware
-} // namespace android
diff --git a/gnss/2.1/default/service.cpp b/gnss/2.1/default/service.cpp
index 5e004d5..4f282cf 100644
--- a/gnss/2.1/default/service.cpp
+++ b/gnss/2.1/default/service.cpp
@@ -18,17 +18,17 @@
#include <hidl/HidlSupport.h>
#include <hidl/HidlTransportSupport.h>
-#include "Gnss.h"
+#include "v2_1/GnssTemplate.h"
using ::android::OK;
using ::android::sp;
using ::android::hardware::configureRpcThreadpool;
using ::android::hardware::joinRpcThreadpool;
+using ::android::hardware::gnss::common::implementation::GnssTemplate;
using ::android::hardware::gnss::V2_1::IGnss;
-using ::android::hardware::gnss::V2_1::implementation::Gnss;
int main(int /* argc */, char* /* argv */[]) {
- sp<IGnss> gnss = new Gnss();
+ sp<IGnss> gnss = new GnssTemplate<IGnss>();
configureRpcThreadpool(1, true /* will join */);
if (gnss->registerAsService() != OK) {
ALOGE("Could not register gnss 2.1 service.");