1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <aidl/android/hardware/gnss/BnAGnss.h> 20 #include <aidl/android/hardware/gnss/BnAGnssRil.h> 21 #include <aidl/android/hardware/gnss/BnGnss.h> 22 #include <aidl/android/hardware/gnss/BnGnssAntennaInfo.h> 23 #include <aidl/android/hardware/gnss/BnGnssBatching.h> 24 #include <aidl/android/hardware/gnss/BnGnssConfiguration.h> 25 #include <aidl/android/hardware/gnss/BnGnssDebug.h> 26 #include <aidl/android/hardware/gnss/BnGnssMeasurementInterface.h> 27 #include <aidl/android/hardware/gnss/BnGnssPowerIndication.h> 28 #include <aidl/android/hardware/gnss/BnGnssPsds.h> 29 #include <aidl/android/hardware/gnss/gnss_assistance/BnGnssAssistanceInterface.h> 30 #include <aidl/android/hardware/gnss/measurement_corrections/BnMeasurementCorrectionsInterface.h> 31 #include <aidl/android/hardware/gnss/visibility_control/BnGnssVisibilityControl.h> 32 #include <atomic> 33 #include <mutex> 34 #include <thread> 35 #include "GnssConfiguration.h" 36 #include "GnssMeasurementInterface.h" 37 #include "GnssPowerIndication.h" 38 #include "Utils.h" 39 40 namespace aidl::android::hardware::gnss { 41 42 class Gnss : public BnGnss { 43 public: 44 Gnss(); ~Gnss()45 ~Gnss() { stop(); }; 46 ndk::ScopedAStatus setCallback(const std::shared_ptr<IGnssCallback>& callback) override; 47 ndk::ScopedAStatus start() override; 48 ndk::ScopedAStatus stop() override; 49 ndk::ScopedAStatus close() override; 50 51 ndk::ScopedAStatus injectTime(int64_t timeMs, int64_t timeReferenceMs, 52 int uncertaintyMs) override; 53 ndk::ScopedAStatus injectLocation(const GnssLocation& location) override; 54 ndk::ScopedAStatus injectBestLocation(const GnssLocation& location) override; 55 ndk::ScopedAStatus deleteAidingData(GnssAidingData aidingDataFlags) override; 56 ndk::ScopedAStatus setPositionMode(const PositionModeOptions& options) override; 57 ndk::ScopedAStatus startSvStatus() override; 58 ndk::ScopedAStatus stopSvStatus() override; 59 ndk::ScopedAStatus startNmea() override; 60 ndk::ScopedAStatus stopNmea() override; 61 62 ndk::ScopedAStatus getExtensionPsds(std::shared_ptr<IGnssPsds>* iGnssPsds) override; 63 ndk::ScopedAStatus getExtensionGnssConfiguration( 64 std::shared_ptr<IGnssConfiguration>* iGnssConfiguration) override; 65 ndk::ScopedAStatus getExtensionGnssPowerIndication( 66 std::shared_ptr<IGnssPowerIndication>* iGnssPowerIndication) override; 67 ndk::ScopedAStatus getExtensionGnssMeasurement( 68 std::shared_ptr<IGnssMeasurementInterface>* iGnssMeasurement) override; 69 ndk::ScopedAStatus getExtensionGnssBatching( 70 std::shared_ptr<IGnssBatching>* iGnssBatching) override; 71 ndk::ScopedAStatus getExtensionGnssGeofence( 72 std::shared_ptr<IGnssGeofence>* iGnssGeofence) override; 73 ndk::ScopedAStatus getExtensionGnssNavigationMessage( 74 std::shared_ptr<IGnssNavigationMessageInterface>* iGnssNavigationMessage) override; 75 ndk::ScopedAStatus getExtensionAGnss(std::shared_ptr<IAGnss>* iAGnss) override; 76 ndk::ScopedAStatus getExtensionAGnssRil(std::shared_ptr<IAGnssRil>* iAGnssRil) override; 77 ndk::ScopedAStatus getExtensionGnssDebug(std::shared_ptr<IGnssDebug>* iGnssDebug) override; 78 ndk::ScopedAStatus getExtensionGnssVisibilityControl( 79 std::shared_ptr<android::hardware::gnss::visibility_control::IGnssVisibilityControl>* 80 iGnssVisibilityControl) override; 81 ndk::ScopedAStatus getExtensionGnssAntennaInfo( 82 std::shared_ptr<IGnssAntennaInfo>* iGnssAntennaInfo) override; 83 ndk::ScopedAStatus getExtensionMeasurementCorrections( 84 std::shared_ptr<android::hardware::gnss::measurement_corrections:: 85 IMeasurementCorrectionsInterface>* iMeasurementCorrections) 86 override; 87 ndk::ScopedAStatus getExtensionGnssAssistanceInterface( 88 std::shared_ptr<android::hardware::gnss::gnss_assistance::IGnssAssistanceInterface>* 89 iGnssAssistanceInterface) override; 90 91 void reportSvStatus() const; 92 void setGnssMeasurementEnabled(const bool enabled); 93 void setGnssMeasurementInterval(const long intervalMs); 94 std::shared_ptr<GnssLocation> getLastLocation() const; 95 std::shared_ptr<GnssConfiguration> mGnssConfiguration; 96 std::shared_ptr<GnssPowerIndication> mGnssPowerIndication; 97 std::shared_ptr<GnssMeasurementInterface> mGnssMeasurementInterface; 98 99 private: 100 void reportLocation(const GnssLocation&); 101 void reportSvStatus(const std::vector<IGnssCallback::GnssSvInfo>& svInfoList) const; 102 void reportGnssStatusValue(const IGnssCallback::GnssStatusValue gnssStatusValue) const; 103 void reportNmea() const; 104 std::vector<IGnssCallback::GnssSvInfo> filterBlocklistedSatellites( 105 std::vector<IGnssCallback::GnssSvInfo> gnssSvInfoList) const; 106 std::unique_ptr<GnssLocation> getLocationFromHW(); 107 108 static std::shared_ptr<IGnssCallback> sGnssCallback; 109 110 std::atomic<long> mMinIntervalMs; 111 std::atomic<long> mGnssMeasurementIntervalMs; 112 std::atomic<bool> mIsActive; 113 std::atomic<bool> mIsSvStatusActive; 114 std::atomic<bool> mIsNmeaActive; 115 std::atomic<bool> mFirstFixReceived; 116 std::atomic<bool> mGnssMeasurementEnabled; 117 std::shared_ptr<GnssLocation> mLastLocation; 118 std::thread mThread; 119 ::android::hardware::gnss::common::ThreadBlocker mThreadBlocker; 120 121 mutable std::mutex mMutex; 122 }; 123 124 } // namespace aidl::android::hardware::gnss 125