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 #include <android/hardware/gnss/2.0/IGnss.h> 19 #include <mutex> 20 #include <memory> 21 #include "data_sink.h" 22 #include "gnss_hw_conn.h" 23 24 namespace goldfish { 25 namespace ahg = ::android::hardware::gnss; 26 namespace ahg20 = ahg::V2_0; 27 namespace ahg11 = ahg::V1_1; 28 namespace ahg10 = ahg::V1_0; 29 namespace ahgmc10 = ahg::measurement_corrections::V1_0; 30 namespace ahgvc10 = ahg::visibility_control::V1_0; 31 32 using ::android::sp; 33 using ::android::hardware::Return; 34 35 struct Gnss20 : public ahg20::IGnss { 36 // Methods from V2_0::IGnss follow. 37 Return<sp<ahg20::IGnssConfiguration>> getExtensionGnssConfiguration_2_0() override; 38 Return<sp<ahg20::IGnssDebug>> getExtensionGnssDebug_2_0() override; 39 Return<sp<ahg20::IAGnss>> getExtensionAGnss_2_0() override; 40 Return<sp<ahg20::IAGnssRil>> getExtensionAGnssRil_2_0() override; 41 Return<sp<ahg20::IGnssMeasurement>> getExtensionGnssMeasurement_2_0() override; 42 Return<bool> setCallback_2_0(const sp<ahg20::IGnssCallback>& callback) override; 43 Return<sp<ahgmc10::IMeasurementCorrections>> 44 getExtensionMeasurementCorrections() override; 45 Return<sp<ahgvc10::IGnssVisibilityControl>> getExtensionVisibilityControl() override; 46 Return<sp<ahg20::IGnssBatching>> getExtensionGnssBatching_2_0() override; 47 Return<bool> injectBestLocation_2_0(const ahg20::GnssLocation& location) override; 48 49 // Methods from V1_1::IGnss follow. 50 Return<bool> setCallback_1_1(const sp<ahg11::IGnssCallback>& callback) override; 51 Return<bool> setPositionMode_1_1(ahg10::IGnss::GnssPositionMode mode, 52 ahg10::IGnss::GnssPositionRecurrence recurrence, 53 uint32_t minIntervalMs, uint32_t preferredAccuracyMeters, 54 uint32_t preferredTimeMs, bool lowPowerMode) override; 55 Return<sp<ahg11::IGnssConfiguration>> getExtensionGnssConfiguration_1_1() override; 56 Return<sp<ahg11::IGnssMeasurement>> getExtensionGnssMeasurement_1_1() override; 57 Return<bool> injectBestLocation(const ahg10::GnssLocation& location) override; 58 59 // Methods from V1_0::IGnss follow. 60 Return<bool> setCallback(const sp<ahg10::IGnssCallback>& callback) override; 61 Return<bool> start() override; 62 Return<bool> stop() override; 63 Return<void> cleanup() override; 64 Return<bool> injectTime(int64_t timeMs, int64_t timeReferenceMs, 65 int32_t uncertaintyMs) override; 66 Return<bool> injectLocation(double latitudeDegrees, double longitudeDegrees, 67 float accuracyMeters) override; 68 Return<void> deleteAidingData(ahg10::IGnss::GnssAidingData aidingDataFlags) override; 69 Return<bool> setPositionMode(ahg10::IGnss::GnssPositionMode mode, 70 ahg10::IGnss::GnssPositionRecurrence recurrence, 71 uint32_t minIntervalMs, uint32_t preferredAccuracyMeters, 72 uint32_t preferredTimeMs) override; 73 Return<sp<ahg10::IAGnssRil>> getExtensionAGnssRil() override; 74 Return<sp<ahg10::IGnssGeofencing>> getExtensionGnssGeofencing() override; 75 Return<sp<ahg10::IAGnss>> getExtensionAGnss() override; 76 Return<sp<ahg10::IGnssNi>> getExtensionGnssNi() override; 77 Return<sp<ahg10::IGnssMeasurement>> getExtensionGnssMeasurement() override; 78 Return<sp<ahg10::IGnssNavigationMessage>> getExtensionGnssNavigationMessage() override; 79 Return<sp<ahg10::IGnssXtra>> getExtensionXtra() override; 80 Return<sp<ahg10::IGnssConfiguration>> getExtensionGnssConfiguration() override; 81 Return<sp<ahg10::IGnssDebug>> getExtensionGnssDebug() override; 82 Return<sp<ahg10::IGnssBatching>> getExtensionGnssBatching() override; 83 84 private: 85 bool open(); 86 void cleanupImpl(); 87 bool injectBestLocationImpl(const ahg10::GnssLocation&, 88 const ahg20::ElapsedRealtime); 89 90 91 DataSink m_dataSink; // all updates go here 92 93 std::unique_ptr<GnssHwConn> m_gnssHwConn; 94 mutable std::mutex m_gnssHwConnMtx; 95 }; 96 97 } // namespace goldfish 98