1 /* 2 * Copyright (C) 2018 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 #ifndef ANDROID_HARDWARE_GNSS_V2_0_GNSS_H 18 #define ANDROID_HARDWARE_GNSS_V2_0_GNSS_H 19 20 #include <android/hardware/gnss/2.0/IGnss.h> 21 #include <hidl/MQDescriptor.h> 22 #include <hidl/Status.h> 23 #include <atomic> 24 #include <mutex> 25 #include <thread> 26 27 namespace android { 28 namespace hardware { 29 namespace gnss { 30 namespace V2_0 { 31 namespace implementation { 32 33 using ::android::sp; 34 using ::android::hardware::hidl_array; 35 using ::android::hardware::hidl_memory; 36 using ::android::hardware::hidl_string; 37 using ::android::hardware::hidl_vec; 38 using ::android::hardware::Return; 39 using ::android::hardware::Void; 40 41 using GnssConstellationType = V1_0::GnssConstellationType; 42 using GnssLocation = V1_0::GnssLocation; 43 using GnssSvInfo = V1_0::IGnssCallback::GnssSvInfo; 44 using GnssSvStatus = V1_0::IGnssCallback::GnssSvStatus; 45 46 struct Gnss : public IGnss { 47 Gnss(); 48 ~Gnss(); 49 // Methods from V1_0::IGnss follow. 50 Return<bool> setCallback(const sp<V1_0::IGnssCallback>& callback) override; 51 Return<bool> start() override; 52 Return<bool> stop() override; 53 Return<void> cleanup() override; 54 Return<bool> injectTime(int64_t timeMs, int64_t timeReferenceMs, 55 int32_t uncertaintyMs) override; 56 Return<bool> injectLocation(double latitudeDegrees, double longitudeDegrees, 57 float accuracyMeters) override; 58 Return<void> deleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags) override; 59 Return<bool> setPositionMode(V1_0::IGnss::GnssPositionMode mode, 60 V1_0::IGnss::GnssPositionRecurrence recurrence, 61 uint32_t minIntervalMs, uint32_t preferredAccuracyMeters, 62 uint32_t preferredTimeMs) override; 63 Return<sp<V1_0::IAGnssRil>> getExtensionAGnssRil() override; 64 Return<sp<V1_0::IGnssGeofencing>> getExtensionGnssGeofencing() override; 65 Return<sp<V1_0::IAGnss>> getExtensionAGnss() override; 66 Return<sp<V1_0::IGnssNi>> getExtensionGnssNi() override; 67 Return<sp<V1_0::IGnssMeasurement>> getExtensionGnssMeasurement() override; 68 Return<sp<V1_0::IGnssNavigationMessage>> getExtensionGnssNavigationMessage() override; 69 Return<sp<V1_0::IGnssXtra>> getExtensionXtra() override; 70 Return<sp<V1_0::IGnssConfiguration>> getExtensionGnssConfiguration() override; 71 Return<sp<V1_0::IGnssDebug>> getExtensionGnssDebug() override; 72 Return<sp<V1_0::IGnssBatching>> getExtensionGnssBatching() override; 73 74 // Methods from V1_1::IGnss follow. 75 Return<bool> setCallback_1_1(const sp<V1_1::IGnssCallback>& callback) override; 76 Return<bool> setPositionMode_1_1(V1_0::IGnss::GnssPositionMode mode, 77 V1_0::IGnss::GnssPositionRecurrence recurrence, 78 uint32_t minIntervalMs, uint32_t preferredAccuracyMeters, 79 uint32_t preferredTimeMs, bool lowPowerMode) override; 80 Return<sp<V1_1::IGnssConfiguration>> getExtensionGnssConfiguration_1_1() override; 81 Return<sp<V1_1::IGnssMeasurement>> getExtensionGnssMeasurement_1_1() override; 82 Return<bool> injectBestLocation(const GnssLocation& location) override; 83 84 // Methods from V2_0::IGnss follow. 85 Return<sp<V2_0::IGnssConfiguration>> getExtensionGnssConfiguration_2_0() override; 86 Return<sp<V2_0::IGnssDebug>> getExtensionGnssDebug_2_0() override; 87 Return<sp<V2_0::IAGnss>> getExtensionAGnss_2_0() override; 88 Return<sp<V2_0::IAGnssRil>> getExtensionAGnssRil_2_0() override; 89 Return<sp<V2_0::IGnssMeasurement>> getExtensionGnssMeasurement_2_0() override; 90 Return<bool> setCallback_2_0(const sp<V2_0::IGnssCallback>& callback) override; 91 Return<sp<measurement_corrections::V1_0::IMeasurementCorrections>> 92 getExtensionMeasurementCorrections() override; 93 Return<sp<visibility_control::V1_0::IGnssVisibilityControl>> getExtensionVisibilityControl() 94 override; 95 Return<sp<V2_0::IGnssBatching>> getExtensionGnssBatching_2_0() override; 96 Return<bool> injectBestLocation_2_0(const V2_0::GnssLocation& location) override; 97 98 private: 99 Return<void> reportLocation(const V2_0::GnssLocation&) const; 100 static sp<V2_0::IGnssCallback> sGnssCallback_2_0; 101 static sp<V1_1::IGnssCallback> sGnssCallback_1_1; 102 std::atomic<long> mMinIntervalMs; 103 std::atomic<bool> mIsActive; 104 std::thread mThread; 105 mutable std::mutex mMutex; 106 }; 107 108 } // namespace implementation 109 } // namespace V2_0 110 } // namespace gnss 111 } // namespace hardware 112 } // namespace android 113 114 #endif // ANDROID_HARDWARE_GNSS_V2_0_GNSS_H 115