1 #ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSS_H 2 #define ANDROID_HARDWARE_GNSS_V1_1_GNSS_H 3 4 #include <android/hardware/gnss/1.1/IGnss.h> 5 #include <hidl/MQDescriptor.h> 6 #include <hidl/Status.h> 7 #include <atomic> 8 #include <mutex> 9 #include <thread> 10 #include "GnssConfiguration.h" 11 12 namespace android { 13 namespace hardware { 14 namespace gnss { 15 namespace V1_1 { 16 namespace implementation { 17 18 using ::android::hardware::hidl_array; 19 using ::android::hardware::hidl_memory; 20 using ::android::hardware::hidl_string; 21 using ::android::hardware::hidl_vec; 22 using ::android::hardware::Return; 23 using ::android::hardware::Void; 24 using ::android::sp; 25 26 using GnssConstellationType = V1_0::GnssConstellationType; 27 using GnssLocation = V1_0::GnssLocation; 28 using GnssSvInfo = V1_0::IGnssCallback::GnssSvInfo; 29 using GnssSvStatus = V1_0::IGnssCallback::GnssSvStatus; 30 31 /** 32 * Unlike the gnss/1.0/default implementation, which is a shim layer to the legacy gps.h, this 33 * default implementation serves as a mock implementation for emulators 34 */ 35 struct Gnss : public IGnss { 36 Gnss(); 37 ~Gnss(); 38 // Methods from ::android::hardware::gnss::V1_0::IGnss follow. 39 Return<bool> setCallback( 40 const sp<::android::hardware::gnss::V1_0::IGnssCallback>& callback) override; 41 Return<bool> start() override; 42 Return<bool> stop() override; 43 Return<void> cleanup() override; 44 Return<bool> injectTime(int64_t timeMs, int64_t timeReferenceMs, 45 int32_t uncertaintyMs) override; 46 Return<bool> injectLocation(double latitudeDegrees, double longitudeDegrees, 47 float accuracyMeters) override; 48 Return<void> deleteAidingData( 49 ::android::hardware::gnss::V1_0::IGnss::GnssAidingData aidingDataFlags) override; 50 Return<bool> setPositionMode( 51 ::android::hardware::gnss::V1_0::IGnss::GnssPositionMode mode, 52 ::android::hardware::gnss::V1_0::IGnss::GnssPositionRecurrence recurrence, 53 uint32_t minIntervalMs, uint32_t preferredAccuracyMeters, 54 uint32_t preferredTimeMs) override; 55 Return<sp<::android::hardware::gnss::V1_0::IAGnssRil>> getExtensionAGnssRil() override; 56 Return<sp<::android::hardware::gnss::V1_0::IGnssGeofencing>> getExtensionGnssGeofencing() 57 override; 58 Return<sp<::android::hardware::gnss::V1_0::IAGnss>> getExtensionAGnss() override; 59 Return<sp<::android::hardware::gnss::V1_0::IGnssNi>> getExtensionGnssNi() override; 60 Return<sp<::android::hardware::gnss::V1_0::IGnssMeasurement>> getExtensionGnssMeasurement() 61 override; 62 Return<sp<::android::hardware::gnss::V1_0::IGnssNavigationMessage>> 63 getExtensionGnssNavigationMessage() override; 64 Return<sp<::android::hardware::gnss::V1_0::IGnssXtra>> getExtensionXtra() override; 65 Return<sp<::android::hardware::gnss::V1_0::IGnssConfiguration>> getExtensionGnssConfiguration() 66 override; 67 Return<sp<::android::hardware::gnss::V1_0::IGnssDebug>> getExtensionGnssDebug() override; 68 Return<sp<::android::hardware::gnss::V1_0::IGnssBatching>> getExtensionGnssBatching() override; 69 70 // Methods from ::android::hardware::gnss::V1_1::IGnss follow. 71 Return<bool> setCallback_1_1( 72 const sp<::android::hardware::gnss::V1_1::IGnssCallback>& callback) override; 73 Return<bool> setPositionMode_1_1( 74 ::android::hardware::gnss::V1_0::IGnss::GnssPositionMode mode, 75 ::android::hardware::gnss::V1_0::IGnss::GnssPositionRecurrence recurrence, 76 uint32_t minIntervalMs, uint32_t preferredAccuracyMeters, uint32_t preferredTimeMs, 77 bool lowPowerMode) override; 78 Return<sp<::android::hardware::gnss::V1_1::IGnssConfiguration>> 79 getExtensionGnssConfiguration_1_1() override; 80 Return<sp<::android::hardware::gnss::V1_1::IGnssMeasurement>> getExtensionGnssMeasurement_1_1() 81 override; 82 Return<bool> injectBestLocation( 83 const ::android::hardware::gnss::V1_0::GnssLocation& location) override; 84 85 // Methods from ::android::hidl::base::V1_0::IBase follow. 86 private: 87 Return<GnssLocation> getMockLocation() const; 88 Return<GnssSvStatus> getMockSvStatus() const; 89 Return<GnssSvInfo> getSvInfo(int16_t svid, GnssConstellationType type, float cN0DbHz, 90 float elevationDegress, float azimuthDegress) const; 91 Return<void> reportLocation(const GnssLocation&) const; 92 Return<void> reportSvStatus(const GnssSvStatus&) const; 93 94 static sp<IGnssCallback> sGnssCallback; 95 std::atomic<long> mMinIntervalMs; 96 sp<GnssConfiguration> mGnssConfiguration; 97 std::atomic<bool> mIsActive; 98 std::thread mThread; 99 mutable std::mutex mMutex; 100 }; 101 102 } // namespace implementation 103 } // namespace V1_1 104 } // namespace gnss 105 } // namespace hardware 106 } // namespace android 107 108 #endif // ANDROID_HARDWARE_GNSS_V1_1_GNSS_H 109