Gnss.h 4.6 KB

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