Loading gnss/1.1/default/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -5,6 +5,7 @@ cc_binary { vendor: true, vendor: true, srcs: [ srcs: [ "Gnss.cpp", "Gnss.cpp", "GnssDebug.cpp", "GnssConfiguration.cpp", "GnssConfiguration.cpp", "GnssMeasurement.cpp", "GnssMeasurement.cpp", "service.cpp", "service.cpp", Loading gnss/1.1/default/Gnss.cpp +77 −24 Original line number Original line Diff line number Diff line #define LOG_TAG "Gnss" #define LOG_TAG "Gnss" #include <android/hardware/gnss/1.0/types.h> #include <log/log.h> #include <log/log.h> #include "Gnss.h" #include "Gnss.h" #include "GnssConfiguration.h" #include "GnssConstants.h" #include "GnssDebug.h" #include "GnssMeasurement.h" #include "GnssMeasurement.h" namespace android { namespace android { Loading @@ -12,10 +14,12 @@ namespace gnss { namespace V1_1 { namespace V1_1 { namespace implementation { namespace implementation { using GnssSvFlags = IGnssCallback::GnssSvFlags; const uint32_t MIN_INTERVAL_MILLIS = 100; const uint32_t MIN_INTERVAL_MILLIS = 100; sp<::android::hardware::gnss::V1_1::IGnssCallback> Gnss::sGnssCallback = nullptr; sp<::android::hardware::gnss::V1_1::IGnssCallback> Gnss::sGnssCallback = nullptr; Gnss::Gnss() : mMinIntervalMs(1000) {} Gnss::Gnss() : mMinIntervalMs(1000), mGnssConfiguration{new GnssConfiguration()} {} Gnss::~Gnss() { Gnss::~Gnss() { stop(); stop(); Loading @@ -36,7 +40,10 @@ Return<bool> Gnss::start() { mIsActive = true; mIsActive = true; mThread = std::thread([this]() { mThread = std::thread([this]() { while (mIsActive == true) { while (mIsActive == true) { V1_0::GnssLocation location = this->getMockLocation(); auto svStatus = this->getMockSvStatus(); this->reportSvStatus(svStatus); auto location = this->getMockLocation(); this->reportLocation(location); this->reportLocation(location); std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs)); std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs)); Loading Loading @@ -70,7 +77,6 @@ Return<bool> Gnss::injectLocation(double, double, float) { } } Return<void> Gnss::deleteAidingData(::android::hardware::gnss::V1_0::IGnss::GnssAidingData) { Return<void> Gnss::deleteAidingData(::android::hardware::gnss::V1_0::IGnss::GnssAidingData) { // TODO implement return Void(); return Void(); } } Loading Loading @@ -124,8 +130,7 @@ Gnss::getExtensionGnssConfiguration() { } } Return<sp<::android::hardware::gnss::V1_0::IGnssDebug>> Gnss::getExtensionGnssDebug() { Return<sp<::android::hardware::gnss::V1_0::IGnssDebug>> Gnss::getExtensionGnssDebug() { // TODO implement return new GnssDebug(); return ::android::sp<::android::hardware::gnss::V1_0::IGnssDebug>{}; } } Return<sp<::android::hardware::gnss::V1_0::IGnssBatching>> Gnss::getExtensionGnssBatching() { Return<sp<::android::hardware::gnss::V1_0::IGnssBatching>> Gnss::getExtensionGnssBatching() { Loading Loading @@ -175,8 +180,7 @@ Return<bool> Gnss::setPositionMode_1_1( Return<sp<::android::hardware::gnss::V1_1::IGnssConfiguration>> Return<sp<::android::hardware::gnss::V1_1::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_1_1() { Gnss::getExtensionGnssConfiguration_1_1() { // TODO implement return mGnssConfiguration; return new GnssConfiguration(); } } Return<sp<::android::hardware::gnss::V1_1::IGnssMeasurement>> Return<sp<::android::hardware::gnss::V1_1::IGnssMeasurement>> Loading @@ -185,27 +189,66 @@ Gnss::getExtensionGnssMeasurement_1_1() { return new GnssMeasurement(); return new GnssMeasurement(); } } Return<bool> Gnss::injectBestLocation(const ::android::hardware::gnss::V1_0::GnssLocation&) { Return<bool> Gnss::injectBestLocation(const GnssLocation&) { // TODO implement return true; return bool{}; } } Return<V1_0::GnssLocation> Gnss::getMockLocation() { Return<GnssLocation> Gnss::getMockLocation() const { V1_0::GnssLocation location = {.gnssLocationFlags = 0xFF, GnssLocation location = {.gnssLocationFlags = 0xFF, .latitudeDegrees = 37.4219999, .latitudeDegrees = kMockLatitudeDegrees, .longitudeDegrees = -122.0840575, .longitudeDegrees = kMockLongitudeDegrees, .altitudeMeters = 1.60062531, .altitudeMeters = kMockAltitudeMeters, .speedMetersPerSec = 0, .speedMetersPerSec = kMockSpeedMetersPerSec, .bearingDegrees = 0, .bearingDegrees = kMockBearingDegrees, .horizontalAccuracyMeters = 5, .horizontalAccuracyMeters = kMockHorizontalAccuracyMeters, .verticalAccuracyMeters = 5, .verticalAccuracyMeters = kMockVerticalAccuracyMeters, .speedAccuracyMetersPerSecond = 1, .speedAccuracyMetersPerSecond = kMockSpeedAccuracyMetersPerSecond, .bearingAccuracyDegrees = 90, .bearingAccuracyDegrees = kMockBearingAccuracyDegrees, .timestamp = 1519930775453L}; .timestamp = kMockTimestamp}; return location; return location; } } Return<void> Gnss::reportLocation(const V1_0::GnssLocation& location) { Return<GnssSvInfo> Gnss::getSvInfo(int16_t svid, GnssConstellationType type, float cN0DbHz, float elevationDegrees, float azimuthDegrees) const { GnssSvInfo svInfo = {.svid = svid, .constellation = type, .cN0Dbhz = cN0DbHz, .elevationDegrees = elevationDegrees, .azimuthDegrees = azimuthDegrees, .svFlag = GnssSvFlags::USED_IN_FIX | GnssSvFlags::HAS_EPHEMERIS_DATA | GnssSvFlags::HAS_ALMANAC_DATA}; return svInfo; } Return<GnssSvStatus> Gnss::getMockSvStatus() const { std::unique_lock<std::recursive_mutex> lock(mGnssConfiguration->getMutex()); GnssSvInfo mockGnssSvInfoList[] = { getSvInfo(3, GnssConstellationType::GPS, 32.5, 59.1, 166.5), getSvInfo(5, GnssConstellationType::GPS, 27.0, 29.0, 56.5), getSvInfo(17, GnssConstellationType::GPS, 30.5, 71.0, 77.0), getSvInfo(26, GnssConstellationType::GPS, 24.1, 28.0, 253.0), getSvInfo(30, GnssConstellationType::GPS, 20.5, 11.5, 116.0), getSvInfo(10, GnssConstellationType::GLONASS, 25.0, 66.0, 247.0)}; GnssSvStatus svStatus = {.numSvs = sizeof(mockGnssSvInfoList) / sizeof(GnssSvInfo)}; for (uint32_t i = 0; i < svStatus.numSvs; i++) { if (mGnssConfiguration->isBlacklisted(mockGnssSvInfoList[i])) { /** * Note well, this is a simple, mock emulation of not using a satellite by changing the * used bit. Simply blanking the used bit, as is done here, is *not* an acceptable * actual device implementation - actual devices *must not* use the satellite in the * position calculation, as specified in IGnssConfiguration.hal. */ mockGnssSvInfoList[i].svFlag &= ~static_cast<uint8_t>(IGnssCallback::GnssSvFlags::USED_IN_FIX); } svStatus.gnssSvList[i] = mockGnssSvInfoList[i]; } return svStatus; } Return<void> Gnss::reportLocation(const GnssLocation& location) const { std::unique_lock<std::mutex> lock(mMutex); std::unique_lock<std::mutex> lock(mMutex); if (sGnssCallback == nullptr) { if (sGnssCallback == nullptr) { ALOGE("%s: sGnssCallback is null.", __func__); ALOGE("%s: sGnssCallback is null.", __func__); Loading @@ -215,6 +258,16 @@ Return<void> Gnss::reportLocation(const V1_0::GnssLocation& location) { return Void(); return Void(); } } Return<void> Gnss::reportSvStatus(const GnssSvStatus& svStatus) const { std::unique_lock<std::mutex> lock(mMutex); if (sGnssCallback == nullptr) { ALOGE("%s: sGnssCallback is null.", __func__); return Void(); } sGnssCallback->gnssSvStatusCb(svStatus); return Void(); } } // namespace implementation } // namespace implementation } // namespace V1_1 } // namespace V1_1 } // namespace gnss } // namespace gnss Loading gnss/1.1/default/Gnss.h +16 −5 Original line number Original line Diff line number Diff line Loading @@ -7,6 +7,7 @@ #include <atomic> #include <atomic> #include <mutex> #include <mutex> #include <thread> #include <thread> #include "GnssConfiguration.h" namespace android { namespace android { namespace hardware { namespace hardware { Loading @@ -22,6 +23,11 @@ using ::android::hardware::Return; using ::android::hardware::Void; using ::android::hardware::Void; using ::android::sp; using ::android::sp; using GnssConstellationType = V1_0::GnssConstellationType; using GnssLocation = V1_0::GnssLocation; using GnssSvInfo = V1_0::IGnssCallback::GnssSvInfo; using GnssSvStatus = V1_0::IGnssCallback::GnssSvStatus; /** /** * Unlike the gnss/1.0/default implementation, which is a shim layer to the legacy gps.h, this * Unlike the gnss/1.0/default implementation, which is a shim layer to the legacy gps.h, this * default implementation serves as a mock implementation for emulators * default implementation serves as a mock implementation for emulators Loading Loading @@ -78,14 +84,19 @@ struct Gnss : public IGnss { // Methods from ::android::hidl::base::V1_0::IBase follow. // Methods from ::android::hidl::base::V1_0::IBase follow. private: private: Return<V1_0::GnssLocation> getMockLocation(); Return<GnssLocation> getMockLocation() const; Return<void> reportLocation(const V1_0::GnssLocation& location); Return<GnssSvStatus> getMockSvStatus() const; Return<GnssSvInfo> getSvInfo(int16_t svid, GnssConstellationType type, float cN0DbHz, float elevationDegress, float azimuthDegress) const; Return<void> reportLocation(const GnssLocation&) const; Return<void> reportSvStatus(const GnssSvStatus&) const; static sp<::android::hardware::gnss::V1_1::IGnssCallback> sGnssCallback; static sp<IGnssCallback> sGnssCallback; std::atomic<long> mMinIntervalMs; sp<GnssConfiguration> mGnssConfiguration; std::atomic<bool> mIsActive; std::atomic<bool> mIsActive; std::thread mThread; std::thread mThread; std::mutex mMutex; mutable std::mutex mMutex; std::atomic<long> mMinIntervalMs; }; }; } // namespace implementation } // namespace implementation Loading gnss/1.1/default/GnssConfiguration.cpp +30 −4 Original line number Original line Diff line number Diff line #define LOG_TAG "GnssConfiguration" #include "GnssConfiguration.h" #include "GnssConfiguration.h" #include <log/log.h> namespace android { namespace android { namespace hardware { namespace hardware { Loading Loading @@ -43,10 +46,33 @@ Return<bool> GnssConfiguration::setEmergencySuplPdn(bool) { } } // Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow. // Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow. Return<bool> GnssConfiguration::setBlacklist( Return<bool> GnssConfiguration::setBlacklist(const hidl_vec<BlacklistedSource>& sourceList) { const hidl_vec<::android::hardware::gnss::V1_1::IGnssConfiguration::BlacklistedSource>&) { std::unique_lock<std::recursive_mutex> lock(mMutex); // TODO implement mBlacklistedConstellationSet.clear(); return bool{}; 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::isBlacklisted(const GnssSvInfo& gnssSvInfo) const { std::unique_lock<std::recursive_mutex> lock(mMutex); if (mBlacklistedConstellationSet.find(gnssSvInfo.constellation) != mBlacklistedConstellationSet.end()) { return true; } BlacklistedSource source = {.constellation = gnssSvInfo.constellation, .svid = gnssSvInfo.svid}; return (mBlacklistedSourceSet.find(source) != mBlacklistedSourceSet.end()); } std::recursive_mutex& GnssConfiguration::getMutex() const { return mMutex; } } // Methods from ::android::hidl::base::V1_0::IBase follow. // Methods from ::android::hidl::base::V1_0::IBase follow. Loading gnss/1.1/default/GnssConfiguration.h +31 −4 Original line number Original line Diff line number Diff line #ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H #ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H #define ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H #define ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H #include <android/hardware/gnss/1.1/IGnssCallback.h> #include <android/hardware/gnss/1.1/IGnssConfiguration.h> #include <android/hardware/gnss/1.1/IGnssConfiguration.h> #include <hidl/MQDescriptor.h> #include <hidl/MQDescriptor.h> #include <hidl/Status.h> #include <hidl/Status.h> #include <mutex> #include <unordered_set> namespace android { namespace android { namespace hardware { namespace hardware { Loading @@ -19,6 +22,26 @@ using ::android::hardware::Return; using ::android::hardware::Void; using ::android::hardware::Void; using ::android::sp; using ::android::sp; using BlacklistedSource = ::android::hardware::gnss::V1_1::IGnssConfiguration::BlacklistedSource; using GnssConstellationType = V1_0::GnssConstellationType; using GnssSvInfo = V1_0::IGnssCallback::GnssSvInfo; struct BlacklistedSourceHash { inline int operator()(const BlacklistedSource& source) const { return int(source.constellation) * 1000 + int(source.svid); } }; struct BlacklistedSourceEqual { inline bool operator()(const BlacklistedSource& s1, const BlacklistedSource& s2) const { return (s1.constellation == s2.constellation) && (s1.svid == s2.svid); } }; using BlacklistedSourceSet = std::unordered_set<BlacklistedSource, BlacklistedSourceHash, BlacklistedSourceEqual>; using BlacklistedConstellationSet = std::unordered_set<GnssConstellationType>; struct GnssConfiguration : public IGnssConfiguration { struct GnssConfiguration : public IGnssConfiguration { // Methods from ::android::hardware::gnss::V1_0::IGnssConfiguration follow. // Methods from ::android::hardware::gnss::V1_0::IGnssConfiguration follow. Return<bool> setSuplEs(bool enabled) override; Return<bool> setSuplEs(bool enabled) override; Loading @@ -30,11 +53,15 @@ struct GnssConfiguration : public IGnssConfiguration { Return<bool> setEmergencySuplPdn(bool enable) override; Return<bool> setEmergencySuplPdn(bool enable) override; // Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow. // Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow. Return<bool> setBlacklist( Return<bool> setBlacklist(const hidl_vec<BlacklistedSource>& blacklist) override; const hidl_vec<::android::hardware::gnss::V1_1::IGnssConfiguration::BlacklistedSource>& blacklist) override; Return<bool> isBlacklisted(const GnssSvInfo& gnssSvInfo) const; std::recursive_mutex& getMutex() const; // Methods from ::android::hidl::base::V1_0::IBase follow. private: BlacklistedSourceSet mBlacklistedSourceSet; BlacklistedConstellationSet mBlacklistedConstellationSet; mutable std::recursive_mutex mMutex; }; }; } // namespace implementation } // namespace implementation Loading Loading
gnss/1.1/default/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -5,6 +5,7 @@ cc_binary { vendor: true, vendor: true, srcs: [ srcs: [ "Gnss.cpp", "Gnss.cpp", "GnssDebug.cpp", "GnssConfiguration.cpp", "GnssConfiguration.cpp", "GnssMeasurement.cpp", "GnssMeasurement.cpp", "service.cpp", "service.cpp", Loading
gnss/1.1/default/Gnss.cpp +77 −24 Original line number Original line Diff line number Diff line #define LOG_TAG "Gnss" #define LOG_TAG "Gnss" #include <android/hardware/gnss/1.0/types.h> #include <log/log.h> #include <log/log.h> #include "Gnss.h" #include "Gnss.h" #include "GnssConfiguration.h" #include "GnssConstants.h" #include "GnssDebug.h" #include "GnssMeasurement.h" #include "GnssMeasurement.h" namespace android { namespace android { Loading @@ -12,10 +14,12 @@ namespace gnss { namespace V1_1 { namespace V1_1 { namespace implementation { namespace implementation { using GnssSvFlags = IGnssCallback::GnssSvFlags; const uint32_t MIN_INTERVAL_MILLIS = 100; const uint32_t MIN_INTERVAL_MILLIS = 100; sp<::android::hardware::gnss::V1_1::IGnssCallback> Gnss::sGnssCallback = nullptr; sp<::android::hardware::gnss::V1_1::IGnssCallback> Gnss::sGnssCallback = nullptr; Gnss::Gnss() : mMinIntervalMs(1000) {} Gnss::Gnss() : mMinIntervalMs(1000), mGnssConfiguration{new GnssConfiguration()} {} Gnss::~Gnss() { Gnss::~Gnss() { stop(); stop(); Loading @@ -36,7 +40,10 @@ Return<bool> Gnss::start() { mIsActive = true; mIsActive = true; mThread = std::thread([this]() { mThread = std::thread([this]() { while (mIsActive == true) { while (mIsActive == true) { V1_0::GnssLocation location = this->getMockLocation(); auto svStatus = this->getMockSvStatus(); this->reportSvStatus(svStatus); auto location = this->getMockLocation(); this->reportLocation(location); this->reportLocation(location); std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs)); std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs)); Loading Loading @@ -70,7 +77,6 @@ Return<bool> Gnss::injectLocation(double, double, float) { } } Return<void> Gnss::deleteAidingData(::android::hardware::gnss::V1_0::IGnss::GnssAidingData) { Return<void> Gnss::deleteAidingData(::android::hardware::gnss::V1_0::IGnss::GnssAidingData) { // TODO implement return Void(); return Void(); } } Loading Loading @@ -124,8 +130,7 @@ Gnss::getExtensionGnssConfiguration() { } } Return<sp<::android::hardware::gnss::V1_0::IGnssDebug>> Gnss::getExtensionGnssDebug() { Return<sp<::android::hardware::gnss::V1_0::IGnssDebug>> Gnss::getExtensionGnssDebug() { // TODO implement return new GnssDebug(); return ::android::sp<::android::hardware::gnss::V1_0::IGnssDebug>{}; } } Return<sp<::android::hardware::gnss::V1_0::IGnssBatching>> Gnss::getExtensionGnssBatching() { Return<sp<::android::hardware::gnss::V1_0::IGnssBatching>> Gnss::getExtensionGnssBatching() { Loading Loading @@ -175,8 +180,7 @@ Return<bool> Gnss::setPositionMode_1_1( Return<sp<::android::hardware::gnss::V1_1::IGnssConfiguration>> Return<sp<::android::hardware::gnss::V1_1::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_1_1() { Gnss::getExtensionGnssConfiguration_1_1() { // TODO implement return mGnssConfiguration; return new GnssConfiguration(); } } Return<sp<::android::hardware::gnss::V1_1::IGnssMeasurement>> Return<sp<::android::hardware::gnss::V1_1::IGnssMeasurement>> Loading @@ -185,27 +189,66 @@ Gnss::getExtensionGnssMeasurement_1_1() { return new GnssMeasurement(); return new GnssMeasurement(); } } Return<bool> Gnss::injectBestLocation(const ::android::hardware::gnss::V1_0::GnssLocation&) { Return<bool> Gnss::injectBestLocation(const GnssLocation&) { // TODO implement return true; return bool{}; } } Return<V1_0::GnssLocation> Gnss::getMockLocation() { Return<GnssLocation> Gnss::getMockLocation() const { V1_0::GnssLocation location = {.gnssLocationFlags = 0xFF, GnssLocation location = {.gnssLocationFlags = 0xFF, .latitudeDegrees = 37.4219999, .latitudeDegrees = kMockLatitudeDegrees, .longitudeDegrees = -122.0840575, .longitudeDegrees = kMockLongitudeDegrees, .altitudeMeters = 1.60062531, .altitudeMeters = kMockAltitudeMeters, .speedMetersPerSec = 0, .speedMetersPerSec = kMockSpeedMetersPerSec, .bearingDegrees = 0, .bearingDegrees = kMockBearingDegrees, .horizontalAccuracyMeters = 5, .horizontalAccuracyMeters = kMockHorizontalAccuracyMeters, .verticalAccuracyMeters = 5, .verticalAccuracyMeters = kMockVerticalAccuracyMeters, .speedAccuracyMetersPerSecond = 1, .speedAccuracyMetersPerSecond = kMockSpeedAccuracyMetersPerSecond, .bearingAccuracyDegrees = 90, .bearingAccuracyDegrees = kMockBearingAccuracyDegrees, .timestamp = 1519930775453L}; .timestamp = kMockTimestamp}; return location; return location; } } Return<void> Gnss::reportLocation(const V1_0::GnssLocation& location) { Return<GnssSvInfo> Gnss::getSvInfo(int16_t svid, GnssConstellationType type, float cN0DbHz, float elevationDegrees, float azimuthDegrees) const { GnssSvInfo svInfo = {.svid = svid, .constellation = type, .cN0Dbhz = cN0DbHz, .elevationDegrees = elevationDegrees, .azimuthDegrees = azimuthDegrees, .svFlag = GnssSvFlags::USED_IN_FIX | GnssSvFlags::HAS_EPHEMERIS_DATA | GnssSvFlags::HAS_ALMANAC_DATA}; return svInfo; } Return<GnssSvStatus> Gnss::getMockSvStatus() const { std::unique_lock<std::recursive_mutex> lock(mGnssConfiguration->getMutex()); GnssSvInfo mockGnssSvInfoList[] = { getSvInfo(3, GnssConstellationType::GPS, 32.5, 59.1, 166.5), getSvInfo(5, GnssConstellationType::GPS, 27.0, 29.0, 56.5), getSvInfo(17, GnssConstellationType::GPS, 30.5, 71.0, 77.0), getSvInfo(26, GnssConstellationType::GPS, 24.1, 28.0, 253.0), getSvInfo(30, GnssConstellationType::GPS, 20.5, 11.5, 116.0), getSvInfo(10, GnssConstellationType::GLONASS, 25.0, 66.0, 247.0)}; GnssSvStatus svStatus = {.numSvs = sizeof(mockGnssSvInfoList) / sizeof(GnssSvInfo)}; for (uint32_t i = 0; i < svStatus.numSvs; i++) { if (mGnssConfiguration->isBlacklisted(mockGnssSvInfoList[i])) { /** * Note well, this is a simple, mock emulation of not using a satellite by changing the * used bit. Simply blanking the used bit, as is done here, is *not* an acceptable * actual device implementation - actual devices *must not* use the satellite in the * position calculation, as specified in IGnssConfiguration.hal. */ mockGnssSvInfoList[i].svFlag &= ~static_cast<uint8_t>(IGnssCallback::GnssSvFlags::USED_IN_FIX); } svStatus.gnssSvList[i] = mockGnssSvInfoList[i]; } return svStatus; } Return<void> Gnss::reportLocation(const GnssLocation& location) const { std::unique_lock<std::mutex> lock(mMutex); std::unique_lock<std::mutex> lock(mMutex); if (sGnssCallback == nullptr) { if (sGnssCallback == nullptr) { ALOGE("%s: sGnssCallback is null.", __func__); ALOGE("%s: sGnssCallback is null.", __func__); Loading @@ -215,6 +258,16 @@ Return<void> Gnss::reportLocation(const V1_0::GnssLocation& location) { return Void(); return Void(); } } Return<void> Gnss::reportSvStatus(const GnssSvStatus& svStatus) const { std::unique_lock<std::mutex> lock(mMutex); if (sGnssCallback == nullptr) { ALOGE("%s: sGnssCallback is null.", __func__); return Void(); } sGnssCallback->gnssSvStatusCb(svStatus); return Void(); } } // namespace implementation } // namespace implementation } // namespace V1_1 } // namespace V1_1 } // namespace gnss } // namespace gnss Loading
gnss/1.1/default/Gnss.h +16 −5 Original line number Original line Diff line number Diff line Loading @@ -7,6 +7,7 @@ #include <atomic> #include <atomic> #include <mutex> #include <mutex> #include <thread> #include <thread> #include "GnssConfiguration.h" namespace android { namespace android { namespace hardware { namespace hardware { Loading @@ -22,6 +23,11 @@ using ::android::hardware::Return; using ::android::hardware::Void; using ::android::hardware::Void; using ::android::sp; using ::android::sp; using GnssConstellationType = V1_0::GnssConstellationType; using GnssLocation = V1_0::GnssLocation; using GnssSvInfo = V1_0::IGnssCallback::GnssSvInfo; using GnssSvStatus = V1_0::IGnssCallback::GnssSvStatus; /** /** * Unlike the gnss/1.0/default implementation, which is a shim layer to the legacy gps.h, this * Unlike the gnss/1.0/default implementation, which is a shim layer to the legacy gps.h, this * default implementation serves as a mock implementation for emulators * default implementation serves as a mock implementation for emulators Loading Loading @@ -78,14 +84,19 @@ struct Gnss : public IGnss { // Methods from ::android::hidl::base::V1_0::IBase follow. // Methods from ::android::hidl::base::V1_0::IBase follow. private: private: Return<V1_0::GnssLocation> getMockLocation(); Return<GnssLocation> getMockLocation() const; Return<void> reportLocation(const V1_0::GnssLocation& location); Return<GnssSvStatus> getMockSvStatus() const; Return<GnssSvInfo> getSvInfo(int16_t svid, GnssConstellationType type, float cN0DbHz, float elevationDegress, float azimuthDegress) const; Return<void> reportLocation(const GnssLocation&) const; Return<void> reportSvStatus(const GnssSvStatus&) const; static sp<::android::hardware::gnss::V1_1::IGnssCallback> sGnssCallback; static sp<IGnssCallback> sGnssCallback; std::atomic<long> mMinIntervalMs; sp<GnssConfiguration> mGnssConfiguration; std::atomic<bool> mIsActive; std::atomic<bool> mIsActive; std::thread mThread; std::thread mThread; std::mutex mMutex; mutable std::mutex mMutex; std::atomic<long> mMinIntervalMs; }; }; } // namespace implementation } // namespace implementation Loading
gnss/1.1/default/GnssConfiguration.cpp +30 −4 Original line number Original line Diff line number Diff line #define LOG_TAG "GnssConfiguration" #include "GnssConfiguration.h" #include "GnssConfiguration.h" #include <log/log.h> namespace android { namespace android { namespace hardware { namespace hardware { Loading Loading @@ -43,10 +46,33 @@ Return<bool> GnssConfiguration::setEmergencySuplPdn(bool) { } } // Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow. // Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow. Return<bool> GnssConfiguration::setBlacklist( Return<bool> GnssConfiguration::setBlacklist(const hidl_vec<BlacklistedSource>& sourceList) { const hidl_vec<::android::hardware::gnss::V1_1::IGnssConfiguration::BlacklistedSource>&) { std::unique_lock<std::recursive_mutex> lock(mMutex); // TODO implement mBlacklistedConstellationSet.clear(); return bool{}; 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::isBlacklisted(const GnssSvInfo& gnssSvInfo) const { std::unique_lock<std::recursive_mutex> lock(mMutex); if (mBlacklistedConstellationSet.find(gnssSvInfo.constellation) != mBlacklistedConstellationSet.end()) { return true; } BlacklistedSource source = {.constellation = gnssSvInfo.constellation, .svid = gnssSvInfo.svid}; return (mBlacklistedSourceSet.find(source) != mBlacklistedSourceSet.end()); } std::recursive_mutex& GnssConfiguration::getMutex() const { return mMutex; } } // Methods from ::android::hidl::base::V1_0::IBase follow. // Methods from ::android::hidl::base::V1_0::IBase follow. Loading
gnss/1.1/default/GnssConfiguration.h +31 −4 Original line number Original line Diff line number Diff line #ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H #ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H #define ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H #define ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H #include <android/hardware/gnss/1.1/IGnssCallback.h> #include <android/hardware/gnss/1.1/IGnssConfiguration.h> #include <android/hardware/gnss/1.1/IGnssConfiguration.h> #include <hidl/MQDescriptor.h> #include <hidl/MQDescriptor.h> #include <hidl/Status.h> #include <hidl/Status.h> #include <mutex> #include <unordered_set> namespace android { namespace android { namespace hardware { namespace hardware { Loading @@ -19,6 +22,26 @@ using ::android::hardware::Return; using ::android::hardware::Void; using ::android::hardware::Void; using ::android::sp; using ::android::sp; using BlacklistedSource = ::android::hardware::gnss::V1_1::IGnssConfiguration::BlacklistedSource; using GnssConstellationType = V1_0::GnssConstellationType; using GnssSvInfo = V1_0::IGnssCallback::GnssSvInfo; struct BlacklistedSourceHash { inline int operator()(const BlacklistedSource& source) const { return int(source.constellation) * 1000 + int(source.svid); } }; struct BlacklistedSourceEqual { inline bool operator()(const BlacklistedSource& s1, const BlacklistedSource& s2) const { return (s1.constellation == s2.constellation) && (s1.svid == s2.svid); } }; using BlacklistedSourceSet = std::unordered_set<BlacklistedSource, BlacklistedSourceHash, BlacklistedSourceEqual>; using BlacklistedConstellationSet = std::unordered_set<GnssConstellationType>; struct GnssConfiguration : public IGnssConfiguration { struct GnssConfiguration : public IGnssConfiguration { // Methods from ::android::hardware::gnss::V1_0::IGnssConfiguration follow. // Methods from ::android::hardware::gnss::V1_0::IGnssConfiguration follow. Return<bool> setSuplEs(bool enabled) override; Return<bool> setSuplEs(bool enabled) override; Loading @@ -30,11 +53,15 @@ struct GnssConfiguration : public IGnssConfiguration { Return<bool> setEmergencySuplPdn(bool enable) override; Return<bool> setEmergencySuplPdn(bool enable) override; // Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow. // Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow. Return<bool> setBlacklist( Return<bool> setBlacklist(const hidl_vec<BlacklistedSource>& blacklist) override; const hidl_vec<::android::hardware::gnss::V1_1::IGnssConfiguration::BlacklistedSource>& blacklist) override; Return<bool> isBlacklisted(const GnssSvInfo& gnssSvInfo) const; std::recursive_mutex& getMutex() const; // Methods from ::android::hidl::base::V1_0::IBase follow. private: BlacklistedSourceSet mBlacklistedSourceSet; BlacklistedConstellationSet mBlacklistedConstellationSet; mutable std::recursive_mutex mMutex; }; }; } // namespace implementation } // namespace implementation Loading