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 #include <log/log.h>
18
19 #include "gnss.h"
20 #include "gnss_configuration.h"
21 #include "gnss_measurement.h"
22 #include "agnss.h"
23
24 namespace {
25 constexpr char kGnssDeviceName[] = "Android Studio Emulator GPS";
26 };
27
28 namespace goldfish {
29
getExtensionGnssConfiguration_2_0()30 Return<sp<ahg20::IGnssConfiguration>> Gnss20::getExtensionGnssConfiguration_2_0() {
31 return new GnssConfiguration20();
32 }
33
getExtensionGnssDebug_2_0()34 Return<sp<ahg20::IGnssDebug>> Gnss20::getExtensionGnssDebug_2_0() {
35 return nullptr;
36 }
37
getExtensionAGnss_2_0()38 Return<sp<ahg20::IAGnss>> Gnss20::getExtensionAGnss_2_0() {
39 return new AGnss20();
40 }
41
getExtensionAGnssRil_2_0()42 Return<sp<ahg20::IAGnssRil>> Gnss20::getExtensionAGnssRil_2_0() {
43 return nullptr;
44 }
45
getExtensionGnssMeasurement_2_0()46 Return<sp<ahg20::IGnssMeasurement>> Gnss20::getExtensionGnssMeasurement_2_0() {
47 return new GnssMeasurement20();
48 }
49
setCallback_2_0(const sp<ahg20::IGnssCallback> & callback)50 Return<bool> Gnss20::setCallback_2_0(const sp<ahg20::IGnssCallback>& callback) {
51 if (callback == nullptr) {
52 return false;
53 } else if (open()) {
54 using Caps = ahg20::IGnssCallback::Capabilities;
55 callback->gnssSetCapabilitiesCb_2_0(Caps::MEASUREMENTS | 0);
56 callback->gnssNameCb(kGnssDeviceName);
57 callback->gnssSetSystemInfoCb({.yearOfHw = 2020});
58
59 m_dataSink.setCallback20(callback);
60 return true;
61 } else {
62 return false;
63 }
64 }
65
getExtensionMeasurementCorrections()66 Return<sp<ahgmc10::IMeasurementCorrections>> Gnss20::getExtensionMeasurementCorrections() {
67 return nullptr;
68 }
69
getExtensionVisibilityControl()70 Return<sp<ahgvc10::IGnssVisibilityControl>> Gnss20::getExtensionVisibilityControl() {
71 return nullptr;
72 }
73
getExtensionGnssBatching_2_0()74 Return<sp<ahg20::IGnssBatching>> Gnss20::getExtensionGnssBatching_2_0() {
75 return nullptr;
76 }
77
injectBestLocation_2_0(const ahg20::GnssLocation & location)78 Return<bool> Gnss20::injectBestLocation_2_0(const ahg20::GnssLocation& location) {
79 (void)location;
80 return true;
81 }
82
setPositionMode_1_1(ahg10::IGnss::GnssPositionMode mode,ahg10::IGnss::GnssPositionRecurrence recurrence,uint32_t minIntervalMs,uint32_t preferredAccuracyMeters,uint32_t preferredTimeMs,bool lowPowerMode)83 Return<bool> Gnss20::setPositionMode_1_1(ahg10::IGnss::GnssPositionMode mode,
84 ahg10::IGnss::GnssPositionRecurrence recurrence,
85 uint32_t minIntervalMs, uint32_t preferredAccuracyMeters,
86 uint32_t preferredTimeMs, bool lowPowerMode) {
87 (void)mode;
88 (void)recurrence;
89 (void)minIntervalMs;
90 (void)preferredAccuracyMeters;
91 (void)preferredTimeMs;
92 (void)lowPowerMode;
93 return true;
94 }
95
start()96 Return<bool> Gnss20::start() {
97 std::unique_lock<std::mutex> lock(m_gnssHwConnMtx);
98 if (m_gnssHwConn) {
99 return m_gnssHwConn->start();
100 } else {
101 return false;
102 }
103 }
104
stop()105 Return<bool> Gnss20::stop() {
106 std::unique_lock<std::mutex> lock(m_gnssHwConnMtx);
107 if (m_gnssHwConn) {
108 return m_gnssHwConn->stop();
109 } else {
110 return false;
111 }
112 }
113
cleanup()114 Return<void> Gnss20::cleanup() {
115 {
116 std::unique_lock<std::mutex> lock(m_gnssHwConnMtx);
117 m_gnssHwConn.reset();
118 }
119
120 m_dataSink.cleanup();
121
122 return {};
123 }
124
injectTime(int64_t timeMs,int64_t timeReferenceMs,int32_t uncertaintyMs)125 Return<bool> Gnss20::injectTime(int64_t timeMs, int64_t timeReferenceMs,
126 int32_t uncertaintyMs) {
127 (void)timeMs;
128 (void)timeReferenceMs;
129 (void)uncertaintyMs;
130 return true;
131 }
132
injectLocation(double latitudeDegrees,double longitudeDegrees,float accuracyMeters)133 Return<bool> Gnss20::injectLocation(double latitudeDegrees, double longitudeDegrees,
134 float accuracyMeters) {
135 (void)latitudeDegrees;
136 (void)longitudeDegrees;
137 (void)accuracyMeters;
138 return false;
139 }
140
deleteAidingData(ahg10::IGnss::GnssAidingData aidingDataFlags)141 Return<void> Gnss20::deleteAidingData(ahg10::IGnss::GnssAidingData aidingDataFlags) {
142 (void)aidingDataFlags;
143 return {};
144 }
145
getExtensionGnssGeofencing()146 Return<sp<ahg10::IGnssGeofencing>> Gnss20::getExtensionGnssGeofencing() {
147 return nullptr;
148 }
149
getExtensionGnssNavigationMessage()150 Return<sp<ahg10::IGnssNavigationMessage>> Gnss20::getExtensionGnssNavigationMessage() {
151 return nullptr;
152 }
153
getExtensionXtra()154 Return<sp<ahg10::IGnssXtra>> Gnss20::getExtensionXtra() {
155 return nullptr;
156 }
157
158 ////////////////////////////////////////////////////////////////////////////////
open()159 bool Gnss20::open() {
160 std::unique_lock<std::mutex> lock(m_gnssHwConnMtx);
161 if (m_gnssHwConn) {
162 return true;
163 } else {
164 auto conn = std::make_unique<GnssHwConn>(&m_dataSink);
165 if (conn->ok()) {
166 m_gnssHwConn = std::move(conn);
167 return true;
168 } else {
169 return false;
170 }
171 }
172 }
173
174 //// deprecated and old versions ///////////////////////////////////////////////
setCallback_1_1(const sp<ahg11::IGnssCallback> &)175 Return<bool> Gnss20::setCallback_1_1(const sp<ahg11::IGnssCallback>&) {
176 return false;
177 }
178
getExtensionGnssMeasurement_1_1()179 Return<sp<ahg11::IGnssMeasurement>> Gnss20::getExtensionGnssMeasurement_1_1() {
180 return nullptr;
181 }
182
getExtensionGnssConfiguration_1_1()183 Return<sp<ahg11::IGnssConfiguration>> Gnss20::getExtensionGnssConfiguration_1_1() {
184 return nullptr;
185 }
186
setCallback(const sp<ahg10::IGnssCallback> &)187 Return<bool> Gnss20::setCallback(const sp<ahg10::IGnssCallback>&) {
188 return false;
189 }
190
getExtensionGnssMeasurement()191 Return<sp<ahg10::IGnssMeasurement>> Gnss20::getExtensionGnssMeasurement() {
192 return nullptr;
193 }
194
getExtensionAGnss()195 Return<sp<ahg10::IAGnss>> Gnss20::getExtensionAGnss() {
196 return nullptr;
197 }
198
getExtensionGnssNi()199 Return<sp<ahg10::IGnssNi>> Gnss20::getExtensionGnssNi() {
200 return nullptr;
201 }
202
getExtensionGnssDebug()203 Return<sp<ahg10::IGnssDebug>> Gnss20::getExtensionGnssDebug() {
204 return nullptr;
205 }
206
getExtensionGnssBatching()207 Return<sp<ahg10::IGnssBatching>> Gnss20::getExtensionGnssBatching() {
208 return nullptr;
209 }
210
injectBestLocation(const ahg10::GnssLocation &)211 Return<bool> Gnss20::injectBestLocation(const ahg10::GnssLocation&) {
212 return false;
213 }
214
setPositionMode(ahg10::IGnss::GnssPositionMode,ahg10::IGnss::GnssPositionRecurrence,uint32_t,uint32_t,uint32_t)215 Return<bool> Gnss20::setPositionMode(ahg10::IGnss::GnssPositionMode,
216 ahg10::IGnss::GnssPositionRecurrence,
217 uint32_t, uint32_t, uint32_t) {
218 return false;
219 }
220
getExtensionGnssConfiguration()221 Return<sp<ahg10::IGnssConfiguration>> Gnss20::getExtensionGnssConfiguration() {
222 return nullptr;
223 }
224
getExtensionAGnssRil()225 Return<sp<ahg10::IAGnssRil>> Gnss20::getExtensionAGnssRil() {
226 return nullptr;
227 }
228
229 } // namespace goldfish
230