blob: bd5e6e852c7249d493d9f94b62467ad1f35f396f [file] [log] [blame]
Yu-Han Yangc06b5362019-10-25 14:14:35 -07001/*
2 * Copyright (C) 2019 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 <android/hardware/gnss/2.1/IGnss.h>
20#include <hidl/MQDescriptor.h>
21#include <hidl/Status.h>
22#include <atomic>
23#include <mutex>
24#include <thread>
Sasha Kuznetsov768de572020-02-11 06:00:10 +000025#include "GnssAntennaInfo.h"
Sasha Kuznetsov845f6d52019-12-04 12:17:50 -080026#include "GnssConfiguration.h"
Yu-Han Yangc06b5362019-10-25 14:14:35 -070027
28namespace android {
29namespace hardware {
30namespace gnss {
31namespace V2_1 {
32
33using GnssSvInfo = IGnssCallback::GnssSvInfo;
34
35namespace implementation {
36
37struct Gnss : public IGnss {
38 Gnss();
39 ~Gnss();
40 // Methods from V1_0::IGnss follow.
41 Return<bool> setCallback(const sp<V1_0::IGnssCallback>& callback) override;
42 Return<bool> start() override;
43 Return<bool> stop() override;
44 Return<void> cleanup() override;
45 Return<bool> injectTime(int64_t timeMs, int64_t timeReferenceMs,
46 int32_t uncertaintyMs) override;
47 Return<bool> injectLocation(double latitudeDegrees, double longitudeDegrees,
48 float accuracyMeters) override;
49 Return<void> deleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags) override;
50 Return<bool> setPositionMode(V1_0::IGnss::GnssPositionMode mode,
51 V1_0::IGnss::GnssPositionRecurrence recurrence,
52 uint32_t minIntervalMs, uint32_t preferredAccuracyMeters,
53 uint32_t preferredTimeMs) override;
54 Return<sp<V1_0::IAGnssRil>> getExtensionAGnssRil() override;
55 Return<sp<V1_0::IGnssGeofencing>> getExtensionGnssGeofencing() override;
56 Return<sp<V1_0::IAGnss>> getExtensionAGnss() override;
57 Return<sp<V1_0::IGnssNi>> getExtensionGnssNi() override;
58 Return<sp<V1_0::IGnssMeasurement>> getExtensionGnssMeasurement() override;
59 Return<sp<V1_0::IGnssNavigationMessage>> getExtensionGnssNavigationMessage() override;
60 Return<sp<V1_0::IGnssXtra>> getExtensionXtra() override;
61 Return<sp<V1_0::IGnssConfiguration>> getExtensionGnssConfiguration() override;
62 Return<sp<V1_0::IGnssDebug>> getExtensionGnssDebug() override;
63 Return<sp<V1_0::IGnssBatching>> getExtensionGnssBatching() override;
64
65 // Methods from V1_1::IGnss follow.
66 Return<bool> setCallback_1_1(const sp<V1_1::IGnssCallback>& callback) override;
67 Return<bool> setPositionMode_1_1(V1_0::IGnss::GnssPositionMode mode,
68 V1_0::IGnss::GnssPositionRecurrence recurrence,
69 uint32_t minIntervalMs, uint32_t preferredAccuracyMeters,
70 uint32_t preferredTimeMs, bool lowPowerMode) override;
71 Return<sp<V1_1::IGnssConfiguration>> getExtensionGnssConfiguration_1_1() override;
72 Return<sp<V1_1::IGnssMeasurement>> getExtensionGnssMeasurement_1_1() override;
73 Return<bool> injectBestLocation(const V1_0::GnssLocation& location) override;
74
75 // Methods from V2_0::IGnss follow.
76 Return<bool> setCallback_2_0(const sp<V2_0::IGnssCallback>& callback) override;
77 Return<sp<V2_0::IGnssConfiguration>> getExtensionGnssConfiguration_2_0() override;
78 Return<sp<V2_0::IGnssDebug>> getExtensionGnssDebug_2_0() override;
79 Return<sp<V2_0::IAGnss>> getExtensionAGnss_2_0() override;
80 Return<sp<V2_0::IAGnssRil>> getExtensionAGnssRil_2_0() override;
81 Return<sp<V2_0::IGnssMeasurement>> getExtensionGnssMeasurement_2_0() override;
82 Return<sp<measurement_corrections::V1_0::IMeasurementCorrections>>
83 getExtensionMeasurementCorrections() override;
84 Return<sp<visibility_control::V1_0::IGnssVisibilityControl>> getExtensionVisibilityControl()
85 override;
86 Return<sp<V2_0::IGnssBatching>> getExtensionGnssBatching_2_0() override;
87 Return<bool> injectBestLocation_2_0(const V2_0::GnssLocation& location) override;
88
89 // Methods from V2_1::IGnss follow.
90 Return<bool> setCallback_2_1(const sp<V2_1::IGnssCallback>& callback) override;
91 Return<sp<V2_1::IGnssMeasurement>> getExtensionGnssMeasurement_2_1() override;
Sasha Kuznetsov845f6d52019-12-04 12:17:50 -080092 Return<sp<V2_1::IGnssConfiguration>> getExtensionGnssConfiguration_2_1() override;
Sasha Kuznetsov31eea852020-01-03 13:06:38 -080093 Return<sp<measurement_corrections::V1_1::IMeasurementCorrections>>
94 getExtensionMeasurementCorrections_1_1() override;
Sasha Kuznetsov768de572020-02-11 06:00:10 +000095 Return<sp<V2_1::IGnssAntennaInfo>> getExtensionGnssAntennaInfo() override;
Yu-Han Yangc06b5362019-10-25 14:14:35 -070096
97 private:
98 void reportLocation(const V2_0::GnssLocation&) const;
Sasha Kuznetsov216311f2020-01-02 17:23:42 -080099 void reportLocation(const V1_0::GnssLocation&) const;
Yu-Han Yangc06b5362019-10-25 14:14:35 -0700100 void reportSvStatus(const hidl_vec<GnssSvInfo>&) const;
101
102 static sp<V2_1::IGnssCallback> sGnssCallback_2_1;
Sasha Kuznetsovc1c257b2019-12-13 13:08:16 -0800103 static sp<V2_0::IGnssCallback> sGnssCallback_2_0;
Sasha Kuznetsov216311f2020-01-02 17:23:42 -0800104 static sp<V1_1::IGnssCallback> sGnssCallback_1_1;
105 static sp<V1_0::IGnssCallback> sGnssCallback_1_0;
Yu-Han Yangc06b5362019-10-25 14:14:35 -0700106 std::atomic<long> mMinIntervalMs;
Sasha Kuznetsov845f6d52019-12-04 12:17:50 -0800107 sp<GnssConfiguration> mGnssConfiguration;
Yu-Han Yangc06b5362019-10-25 14:14:35 -0700108 std::atomic<bool> mIsActive;
109 std::thread mThread;
110 mutable std::mutex mMutex;
Sasha Kuznetsov845f6d52019-12-04 12:17:50 -0800111 hidl_vec<GnssSvInfo> filterBlacklistedSatellitesV2_1(hidl_vec<GnssSvInfo> gnssSvInfoList);
Yu-Han Yangc06b5362019-10-25 14:14:35 -0700112};
113
114} // namespace implementation
115} // namespace V2_1
116} // namespace gnss
117} // namespace hardware
118} // namespace android