blob: c47206a7a4f29b01e7a61f51f503dc18d7b8f4f6 [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 Kuznetsov845f6d52019-12-04 12:17:50 -080025#include "GnssConfiguration.h"
Yu-Han Yangc06b5362019-10-25 14:14:35 -070026
27namespace android {
28namespace hardware {
29namespace gnss {
30namespace V2_1 {
31
32using GnssSvInfo = IGnssCallback::GnssSvInfo;
33
34namespace implementation {
35
36struct Gnss : public IGnss {
37 Gnss();
38 ~Gnss();
39 // Methods from V1_0::IGnss follow.
40 Return<bool> setCallback(const sp<V1_0::IGnssCallback>& callback) override;
41 Return<bool> start() override;
42 Return<bool> stop() override;
43 Return<void> cleanup() override;
44 Return<bool> injectTime(int64_t timeMs, int64_t timeReferenceMs,
45 int32_t uncertaintyMs) override;
46 Return<bool> injectLocation(double latitudeDegrees, double longitudeDegrees,
47 float accuracyMeters) override;
48 Return<void> deleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags) override;
49 Return<bool> setPositionMode(V1_0::IGnss::GnssPositionMode mode,
50 V1_0::IGnss::GnssPositionRecurrence recurrence,
51 uint32_t minIntervalMs, uint32_t preferredAccuracyMeters,
52 uint32_t preferredTimeMs) override;
53 Return<sp<V1_0::IAGnssRil>> getExtensionAGnssRil() override;
54 Return<sp<V1_0::IGnssGeofencing>> getExtensionGnssGeofencing() override;
55 Return<sp<V1_0::IAGnss>> getExtensionAGnss() override;
56 Return<sp<V1_0::IGnssNi>> getExtensionGnssNi() override;
57 Return<sp<V1_0::IGnssMeasurement>> getExtensionGnssMeasurement() override;
58 Return<sp<V1_0::IGnssNavigationMessage>> getExtensionGnssNavigationMessage() override;
59 Return<sp<V1_0::IGnssXtra>> getExtensionXtra() override;
60 Return<sp<V1_0::IGnssConfiguration>> getExtensionGnssConfiguration() override;
61 Return<sp<V1_0::IGnssDebug>> getExtensionGnssDebug() override;
62 Return<sp<V1_0::IGnssBatching>> getExtensionGnssBatching() override;
63
64 // Methods from V1_1::IGnss follow.
65 Return<bool> setCallback_1_1(const sp<V1_1::IGnssCallback>& callback) override;
66 Return<bool> setPositionMode_1_1(V1_0::IGnss::GnssPositionMode mode,
67 V1_0::IGnss::GnssPositionRecurrence recurrence,
68 uint32_t minIntervalMs, uint32_t preferredAccuracyMeters,
69 uint32_t preferredTimeMs, bool lowPowerMode) override;
70 Return<sp<V1_1::IGnssConfiguration>> getExtensionGnssConfiguration_1_1() override;
71 Return<sp<V1_1::IGnssMeasurement>> getExtensionGnssMeasurement_1_1() override;
72 Return<bool> injectBestLocation(const V1_0::GnssLocation& location) override;
73
74 // Methods from V2_0::IGnss follow.
75 Return<bool> setCallback_2_0(const sp<V2_0::IGnssCallback>& callback) override;
76 Return<sp<V2_0::IGnssConfiguration>> getExtensionGnssConfiguration_2_0() override;
77 Return<sp<V2_0::IGnssDebug>> getExtensionGnssDebug_2_0() override;
78 Return<sp<V2_0::IAGnss>> getExtensionAGnss_2_0() override;
79 Return<sp<V2_0::IAGnssRil>> getExtensionAGnssRil_2_0() override;
80 Return<sp<V2_0::IGnssMeasurement>> getExtensionGnssMeasurement_2_0() override;
81 Return<sp<measurement_corrections::V1_0::IMeasurementCorrections>>
82 getExtensionMeasurementCorrections() override;
83 Return<sp<visibility_control::V1_0::IGnssVisibilityControl>> getExtensionVisibilityControl()
84 override;
85 Return<sp<V2_0::IGnssBatching>> getExtensionGnssBatching_2_0() override;
86 Return<bool> injectBestLocation_2_0(const V2_0::GnssLocation& location) override;
87
88 // Methods from V2_1::IGnss follow.
89 Return<bool> setCallback_2_1(const sp<V2_1::IGnssCallback>& callback) override;
90 Return<sp<V2_1::IGnssMeasurement>> getExtensionGnssMeasurement_2_1() override;
Sasha Kuznetsov845f6d52019-12-04 12:17:50 -080091 Return<sp<V2_1::IGnssConfiguration>> getExtensionGnssConfiguration_2_1() override;
Sasha Kuznetsov31eea852020-01-03 13:06:38 -080092 Return<sp<measurement_corrections::V1_1::IMeasurementCorrections>>
93 getExtensionMeasurementCorrections_1_1() override;
Yu-Han Yangc06b5362019-10-25 14:14:35 -070094
95 private:
96 void reportLocation(const V2_0::GnssLocation&) const;
Sasha Kuznetsov216311f2020-01-02 17:23:42 -080097 void reportLocation(const V1_0::GnssLocation&) const;
Yu-Han Yangc06b5362019-10-25 14:14:35 -070098 void reportSvStatus(const hidl_vec<GnssSvInfo>&) const;
99
100 static sp<V2_1::IGnssCallback> sGnssCallback_2_1;
Sasha Kuznetsovc1c257b2019-12-13 13:08:16 -0800101 static sp<V2_0::IGnssCallback> sGnssCallback_2_0;
Sasha Kuznetsov216311f2020-01-02 17:23:42 -0800102 static sp<V1_1::IGnssCallback> sGnssCallback_1_1;
103 static sp<V1_0::IGnssCallback> sGnssCallback_1_0;
Yu-Han Yangc06b5362019-10-25 14:14:35 -0700104 std::atomic<long> mMinIntervalMs;
Sasha Kuznetsov845f6d52019-12-04 12:17:50 -0800105 sp<GnssConfiguration> mGnssConfiguration;
Yu-Han Yangc06b5362019-10-25 14:14:35 -0700106 std::atomic<bool> mIsActive;
107 std::thread mThread;
108 mutable std::mutex mMutex;
Sasha Kuznetsov845f6d52019-12-04 12:17:50 -0800109 hidl_vec<GnssSvInfo> filterBlacklistedSatellitesV2_1(hidl_vec<GnssSvInfo> gnssSvInfoList);
Yu-Han Yangc06b5362019-10-25 14:14:35 -0700110};
111
112} // namespace implementation
113} // namespace V2_1
114} // namespace gnss
115} // namespace hardware
116} // namespace android