blob: 28a19501c905d24afc096b4d625a14ae5762f7ac [file] [log] [blame]
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -07001/*
2 * Copyright (C) 2016 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#define LOG_TAG "GnssHAL_GnssInterface"
18
19#include "Gnss.h"
20#include <GnssUtils.h>
21
22namespace android {
23namespace hardware {
24namespace gnss {
25namespace V1_0 {
26namespace implementation {
27
28std::vector<std::unique_ptr<ThreadFuncArgs>> Gnss::sThreadFuncArgsList;
29sp<IGnssCallback> Gnss::sGnssCbIface = nullptr;
30bool Gnss::sInterfaceExists = false;
31
32GpsCallbacks Gnss::sGnssCb = {
33 .size = sizeof(GpsCallbacks),
34 .location_cb = locationCb,
35 .status_cb = statusCb,
36 .sv_status_cb = gpsSvStatusCb,
37 .nmea_cb = nmeaCb,
38 .set_capabilities_cb = setCapabilitiesCb,
39 .acquire_wakelock_cb = acquireWakelockCb,
40 .release_wakelock_cb = releaseWakelockCb,
41 .create_thread_cb = createThreadCb,
42 .request_utc_time_cb = requestUtcTimeCb,
43 .set_system_info_cb = setSystemInfoCb,
44 .gnss_sv_status_cb = gnssSvStatusCb,
45};
46
47Gnss::Gnss(gps_device_t* gnssDevice) {
48 /* Error out if an instance of the interface already exists. */
49 LOG_ALWAYS_FATAL_IF(sInterfaceExists);
50 sInterfaceExists = true;
51
52 if (gnssDevice == nullptr) {
53 ALOGE("%s: Invalid device_t handle", __func__);
54 return;
55 }
56
57 mGnssIface = gnssDevice->get_gps_interface(gnssDevice);
58}
59
60Gnss::~Gnss() {
61 sThreadFuncArgsList.clear();
62}
63
64void Gnss::locationCb(GpsLocation* location) {
65 if (sGnssCbIface == nullptr) {
66 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
67 return;
68 }
69
70 if (location == nullptr) {
71 ALOGE("%s: Invalid location from GNSS HAL", __func__);
72 return;
73 }
74
75 android::hardware::gnss::V1_0::GnssLocation gnssLocation = convertToGnssLocation(location);
76 sGnssCbIface->gnssLocationCb(gnssLocation);
77}
78
79void Gnss::statusCb(GpsStatus* gnssStatus) {
80 if (sGnssCbIface == nullptr) {
81 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
82 return;
83 }
84
85 if (gnssStatus == nullptr) {
86 ALOGE("%s: Invalid GpsStatus from GNSS HAL", __func__);
87 return;
88 }
89
90 IGnssCallback::GnssStatusValue status =
91 static_cast<IGnssCallback::GnssStatusValue>(gnssStatus->status);
92
93 sGnssCbIface->gnssStatusCb(status);
94}
95
96void Gnss::gnssSvStatusCb(GnssSvStatus* status) {
97 if (sGnssCbIface == nullptr) {
98 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
99 return;
100 }
101
102 if (status == nullptr) {
103 ALOGE("Invalid status from GNSS HAL %s", __func__);
104 return;
105 }
106
107 IGnssCallback::GnssSvStatus svStatus;
108 svStatus.numSvs = status->num_svs;
109
110 if (svStatus.numSvs > static_cast<uint32_t>(GnssMax::SVS_COUNT)) {
111 ALOGW("Too many satellites %zd. Clamps to %d.", svStatus.numSvs, GnssMax::SVS_COUNT);
112 svStatus.numSvs = static_cast<uint32_t>(GnssMax::SVS_COUNT);
113 }
114
115 for (size_t i = 0; i < svStatus.numSvs; i++) {
116 auto svInfo = status->gnss_sv_list[i];
117 IGnssCallback::GnssSvInfo gnssSvInfo = {
118 .svid = svInfo.svid,
119 .constellation = static_cast<android::hardware::gnss::V1_0::GnssConstellationType>(
120 svInfo.constellation),
121 .cN0Dbhz = svInfo.c_n0_dbhz,
122 .elevationDegrees = svInfo.elevation,
123 .azimuthDegrees = svInfo.azimuth,
Yifan Hong35e2aac2016-12-05 12:35:05 -0800124 .svFlag = svInfo.flags
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700125 };
126 svStatus.gnssSvList[i] = gnssSvInfo;
127 }
128
129 sGnssCbIface->gnssSvStatusCb(svStatus);
130}
131
132/*
133 * This enum is used by gpsSvStatusCb() method below to convert GpsSvStatus
134 * to GnssSvStatus for backward compatibility. It is only used by the default
135 * implementation and is not part of the GNSS interface.
136 */
137enum SvidValues : uint16_t {
138 GLONASS_SVID_OFFSET = 64,
139 GLONASS_SVID_COUNT = 24,
140 BEIDOU_SVID_OFFSET = 200,
141 BEIDOU_SVID_COUNT = 35,
142 SBAS_SVID_MIN = 33,
143 SBAS_SVID_MAX = 64,
144 SBAS_SVID_ADD = 87,
145 QZSS_SVID_MIN = 193,
146 QZSS_SVID_MAX = 200
147};
148
149/*
150 * The following code that converts GpsSvStatus to GnssSvStatus is moved here from
151 * GnssLocationProvider. GnssLocationProvider does not require it anymore since GpsSvStatus is
152 * being deprecated and is no longer part of the GNSS interface.
153 */
154void Gnss::gpsSvStatusCb(GpsSvStatus* svInfo) {
155 if (sGnssCbIface == nullptr) {
156 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
157 return;
158 }
159
160 if (svInfo == nullptr) {
161 ALOGE("Invalid status from GNSS HAL %s", __func__);
162 return;
163 }
164
165 IGnssCallback::GnssSvStatus svStatus;
166 svStatus.numSvs = svInfo->num_svs;
167 /*
168 * Clamp the list size since GnssSvStatus can support a maximum of
169 * GnssMax::SVS_COUNT entries.
170 */
171 if (svStatus.numSvs > static_cast<uint32_t>(GnssMax::SVS_COUNT)) {
172 ALOGW("Too many satellites %zd. Clamps to %d.", svStatus.numSvs, GnssMax::SVS_COUNT);
173 svStatus.numSvs = static_cast<uint32_t>(GnssMax::SVS_COUNT);
174 }
175
176 uint32_t ephemerisMask = svInfo->ephemeris_mask;
177 uint32_t almanacMask = svInfo->almanac_mask;
178 uint32_t usedInFixMask = svInfo->used_in_fix_mask;
179 /*
180 * Conversion from GpsSvInfo to IGnssCallback::GnssSvInfo happens below.
181 */
182 for (size_t i = 0; i < svStatus.numSvs; i++) {
183 IGnssCallback::GnssSvInfo& info = svStatus.gnssSvList[i];
184 info.svid = svInfo->sv_list[i].prn;
185 if (info.svid >= 1 && info.svid <= 32) {
186 info.constellation = GnssConstellationType::GPS;
187 } else if (info.svid > GLONASS_SVID_OFFSET &&
188 info.svid <= GLONASS_SVID_OFFSET + GLONASS_SVID_COUNT) {
189 info.constellation = GnssConstellationType::GLONASS;
190 info.svid -= GLONASS_SVID_OFFSET;
191 } else if (info.svid > BEIDOU_SVID_OFFSET &&
192 info.svid <= BEIDOU_SVID_OFFSET + BEIDOU_SVID_COUNT) {
193 info.constellation = GnssConstellationType::BEIDOU;
194 info.svid -= BEIDOU_SVID_OFFSET;
195 } else if (info.svid >= SBAS_SVID_MIN && info.svid <= SBAS_SVID_MAX) {
196 info.constellation = GnssConstellationType::SBAS;
197 info.svid += SBAS_SVID_ADD;
198 } else if (info.svid >= QZSS_SVID_MIN && info.svid <= QZSS_SVID_MAX) {
199 info.constellation = GnssConstellationType::QZSS;
200 } else {
201 ALOGD("Unknown constellation type with Svid = %d.", info.svid);
202 info.constellation = GnssConstellationType::UNKNOWN;
203 }
204
205 info.cN0Dbhz = svInfo->sv_list[i].snr;
206 info.elevationDegrees = svInfo->sv_list[i].elevation;
207 info.azimuthDegrees = svInfo->sv_list[i].azimuth;
Yifan Hong35e2aac2016-12-05 12:35:05 -0800208 // TODO: b/31702236
209 info.svFlag = static_cast<uint8_t>(IGnssCallback::GnssSvFlags::NONE);
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700210
211 /*
212 * Only GPS info is valid for these fields, as these masks are just 32
213 * bits, by GPS prn.
214 */
215 if (info.constellation == GnssConstellationType::GPS) {
216 int32_t svidMask = (1 << (info.svid - 1));
217 if ((ephemerisMask & svidMask) != 0) {
218 info.svFlag |= IGnssCallback::GnssSvFlags::HAS_EPHEMERIS_DATA;
219 }
220 if ((almanacMask & svidMask) != 0) {
221 info.svFlag |= IGnssCallback::GnssSvFlags::HAS_ALMANAC_DATA;
222 }
223 if ((usedInFixMask & svidMask) != 0) {
224 info.svFlag |= IGnssCallback::GnssSvFlags::USED_IN_FIX;
225 }
226 }
227 }
228
229 sGnssCbIface->gnssSvStatusCb(svStatus);
230}
231
232void Gnss::nmeaCb(GpsUtcTime timestamp, const char* nmea, int length) {
233 if (sGnssCbIface == nullptr) {
234 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
235 return;
236 }
237
238 android::hardware::hidl_string nmeaString;
239 nmeaString.setToExternal(nmea, length);
240 sGnssCbIface->gnssNmeaCb(timestamp, nmeaString);
241}
242
243void Gnss::setCapabilitiesCb(uint32_t capabilities) {
244 if (sGnssCbIface == nullptr) {
245 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
246 return;
247 }
248
249 sGnssCbIface->gnssSetCapabilitesCb(capabilities);
250}
251
252void Gnss::acquireWakelockCb() {
253 if (sGnssCbIface == nullptr) {
254 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
255 return;
256 }
257
258 sGnssCbIface->gnssAcquireWakelockCb();
259}
260
261void Gnss::releaseWakelockCb() {
262 if (sGnssCbIface == nullptr) {
263 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
264 return;
265 }
266
267 sGnssCbIface->gnssReleaseWakelockCb();
268}
269
270void Gnss::requestUtcTimeCb() {
271 if (sGnssCbIface == nullptr) {
272 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
273 return;
274 }
275
276 sGnssCbIface->gnssRequestTimeCb();
277}
278
279pthread_t Gnss::createThreadCb(const char* name, void (*start)(void*), void* arg) {
280 return createPthread(name, start, arg, &sThreadFuncArgsList);
281}
282
283void Gnss::setSystemInfoCb(const LegacyGnssSystemInfo* info) {
284 if (sGnssCbIface == nullptr) {
285 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
286 return;
287 }
288
289 if (info == nullptr) {
290 ALOGE("Invalid GnssSystemInfo from GNSS HAL %s", __func__);
291 return;
292 }
293
294 IGnssCallback::GnssSystemInfo gnssInfo = {
295 .yearOfHw = info->year_of_hw
296 };
297
298 sGnssCbIface->gnssSetSystemInfoCb(gnssInfo);
299}
300
301
302// Methods from ::android::hardware::gnss::V1_0::IGnss follow.
303Return<bool> Gnss::setCallback(const sp<IGnssCallback>& callback) {
304 if (mGnssIface == nullptr) {
305 ALOGE("%s: Gnss interface is unavailable", __func__);
306 return false;
307 }
308
309 sGnssCbIface = callback;
310
311 return (mGnssIface->init(&sGnssCb) == 0);
312}
313
314Return<bool> Gnss::start() {
315 if (mGnssIface == nullptr) {
316 ALOGE("%s: Gnss interface is unavailable", __func__);
317 return false;
318 }
319
320 return (mGnssIface->start() == 0);
321}
322
323Return<bool> Gnss::stop() {
324 if (mGnssIface == nullptr) {
325 ALOGE("%s: Gnss interface is unavailable", __func__);
326 return false;
327 }
328
329 return (mGnssIface->stop() == 0);
330}
331
332Return<void> Gnss::cleanup() {
333 if (mGnssIface == nullptr) {
334 ALOGE("%s: Gnss interface is unavailable", __func__);
335 } else {
336 mGnssIface->cleanup();
337 }
338 return Void();
339}
340
341Return<bool> Gnss::injectLocation(double latitudeDegrees,
342 double longitudeDegrees,
343 float accuracyMeters) {
344 if (mGnssIface == nullptr) {
345 ALOGE("%s: Gnss interface is unavailable", __func__);
346 return false;
347 }
348
349 return (mGnssIface->inject_location(latitudeDegrees, longitudeDegrees, accuracyMeters) == 0);
350}
351
352Return<bool> Gnss::injectTime(int64_t timeMs, int64_t timeReferenceMs,
353 int32_t uncertaintyMs) {
354 if (mGnssIface == nullptr) {
355 ALOGE("%s: Gnss interface is unavailable", __func__);
356 return false;
357 }
358
359 return (mGnssIface->inject_time(timeMs, timeReferenceMs, uncertaintyMs) == 0);
360}
361
362Return<void> Gnss::deleteAidingData(IGnss::GnssAidingData aidingDataFlags) {
363 if (mGnssIface == nullptr) {
364 ALOGE("%s: Gnss interface is unavailable", __func__);
365 } else {
366 mGnssIface->delete_aiding_data(static_cast<GpsAidingData>(aidingDataFlags));
367 }
368 return Void();
369}
370
371Return<bool> Gnss::setPositionMode(IGnss::GnssPositionMode mode,
372 IGnss::GnssPositionRecurrence recurrence,
373 uint32_t minIntervalMs,
374 uint32_t preferredAccuracyMeters,
375 uint32_t preferredTimeMs) {
376 if (mGnssIface == nullptr) {
377 ALOGE("%s: Gnss interface is unavailable", __func__);
378 return false;
379 }
380
381 return (mGnssIface->set_position_mode(static_cast<GpsPositionMode>(mode),
382 static_cast<GpsPositionRecurrence>(recurrence),
383 minIntervalMs,
384 preferredAccuracyMeters,
385 preferredTimeMs) == 0);
386}
387
Martijn Coenen527924a2017-01-04 12:59:48 +0100388Return<sp<IAGnssRil>> Gnss::getExtensionAGnssRil() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700389 if (mGnssIface == nullptr) {
390 ALOGE("%s: Gnss interface is unavailable", __func__);
391 } else {
392 const AGpsRilInterface* agpsRilIface = static_cast<const AGpsRilInterface*>(
393 mGnssIface->get_extension(AGPS_RIL_INTERFACE));
394 if (agpsRilIface == nullptr) {
395 ALOGE("%s GnssRil interface not implemented by GNSS HAL", __func__);
396 } else {
397 mGnssRil = new AGnssRil(agpsRilIface);
398 }
399 }
Martijn Coenen527924a2017-01-04 12:59:48 +0100400 return mGnssRil;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700401}
402
Martijn Coenen527924a2017-01-04 12:59:48 +0100403Return<sp<IGnssConfiguration>> Gnss::getExtensionGnssConfiguration() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700404 if (mGnssIface == nullptr) {
405 ALOGE("%s: Gnss interface is unavailable", __func__);
406 } else {
407 const GnssConfigurationInterface* gnssConfigIface =
408 static_cast<const GnssConfigurationInterface*>(
409 mGnssIface->get_extension(GNSS_CONFIGURATION_INTERFACE));
410
411 if (gnssConfigIface == nullptr) {
412 ALOGE("%s GnssConfiguration interface not implemented by GNSS HAL", __func__);
413 } else {
414 mGnssConfig = new GnssConfiguration(gnssConfigIface);
415 }
416 }
Martijn Coenen527924a2017-01-04 12:59:48 +0100417 return mGnssConfig;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700418}
Martijn Coenen527924a2017-01-04 12:59:48 +0100419Return<sp<IGnssGeofencing>> Gnss::getExtensionGnssGeofencing() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700420 if (mGnssIface == nullptr) {
421 ALOGE("%s: Gnss interface is unavailable", __func__);
422 } else {
423 const GpsGeofencingInterface* gpsGeofencingIface =
424 static_cast<const GpsGeofencingInterface*>(
425 mGnssIface->get_extension(GPS_GEOFENCING_INTERFACE));
426
427 if (gpsGeofencingIface == nullptr) {
428 ALOGE("%s GnssGeofencing interface not implemented by GNSS HAL", __func__);
429 } else {
430 mGnssGeofencingIface = new GnssGeofencing(gpsGeofencingIface);
431 }
432 }
433
Martijn Coenen527924a2017-01-04 12:59:48 +0100434 return mGnssGeofencingIface;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700435}
436
Martijn Coenen527924a2017-01-04 12:59:48 +0100437Return<sp<IAGnss>> Gnss::getExtensionAGnss() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700438 if (mGnssIface == nullptr) {
439 ALOGE("%s: Gnss interface is unavailable", __func__);
440 } else {
441 const AGpsInterface* agpsIface = static_cast<const AGpsInterface*>(
442 mGnssIface->get_extension(AGPS_INTERFACE));
443 if (agpsIface == nullptr) {
444 ALOGE("%s AGnss interface not implemented by GNSS HAL", __func__);
445 } else {
446 mAGnssIface = new AGnss(agpsIface);
447 }
448 }
Martijn Coenen527924a2017-01-04 12:59:48 +0100449 return mAGnssIface;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700450}
451
Martijn Coenen527924a2017-01-04 12:59:48 +0100452Return<sp<IGnssNi>> Gnss::getExtensionGnssNi() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700453 if (mGnssIface == nullptr) {
454 ALOGE("%s: Gnss interface is unavailable", __func__);
455 } else {
456 const GpsNiInterface* gpsNiIface = static_cast<const GpsNiInterface*>(
457 mGnssIface->get_extension(GPS_NI_INTERFACE));
458 if (gpsNiIface == nullptr) {
459 ALOGE("%s GnssNi interface not implemented by GNSS HAL", __func__);
460 } else {
461 mGnssNi = new GnssNi(gpsNiIface);
462 }
463 }
Martijn Coenen527924a2017-01-04 12:59:48 +0100464 return mGnssNi;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700465}
466
Martijn Coenen527924a2017-01-04 12:59:48 +0100467Return<sp<IGnssMeasurement>> Gnss::getExtensionGnssMeasurement() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700468 if (mGnssIface == nullptr) {
469 ALOGE("%s: Gnss interface is unavailable", __func__);
470 } else {
471 const GpsMeasurementInterface* gpsMeasurementIface =
472 static_cast<const GpsMeasurementInterface*>(
473 mGnssIface->get_extension(GPS_MEASUREMENT_INTERFACE));
474
475 if (gpsMeasurementIface == nullptr) {
476 ALOGE("%s GnssMeasurement interface not implemented by GNSS HAL", __func__);
477 } else {
478 mGnssMeasurement = new GnssMeasurement(gpsMeasurementIface);
479 }
480 }
Martijn Coenen527924a2017-01-04 12:59:48 +0100481 return mGnssMeasurement;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700482}
483
Martijn Coenen527924a2017-01-04 12:59:48 +0100484Return<sp<IGnssNavigationMessage>> Gnss::getExtensionGnssNavigationMessage() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700485 if (mGnssIface == nullptr) {
486 ALOGE("%s: Gnss interface is unavailable", __func__);
487 } else {
488 const GpsNavigationMessageInterface* gpsNavigationMessageIface =
489 static_cast<const GpsNavigationMessageInterface*>(
490 mGnssIface->get_extension(GPS_NAVIGATION_MESSAGE_INTERFACE));
491
492 if (gpsNavigationMessageIface == nullptr) {
493 ALOGE("%s GnssNavigationMessage interface not implemented by GNSS HAL",
494 __func__);
495 } else {
496 mGnssNavigationMessage = new GnssNavigationMessage(gpsNavigationMessageIface);
497 }
498 }
499
Martijn Coenen527924a2017-01-04 12:59:48 +0100500 return mGnssNavigationMessage;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700501}
502
Martijn Coenen527924a2017-01-04 12:59:48 +0100503Return<sp<IGnssXtra>> Gnss::getExtensionXtra() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700504 if (mGnssIface == nullptr) {
505 ALOGE("%s: Gnss interface is unavailable", __func__);
506 } else {
507 const GpsXtraInterface* gpsXtraIface = static_cast<const GpsXtraInterface*>(
508 mGnssIface->get_extension(GPS_XTRA_INTERFACE));
509
510 if (gpsXtraIface == nullptr) {
511 ALOGE("%s GnssXtra interface not implemented by HAL", __func__);
512 } else {
513 mGnssXtraIface = new GnssXtra(gpsXtraIface);
514 }
515 }
516
Martijn Coenen527924a2017-01-04 12:59:48 +0100517 return mGnssXtraIface;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700518}
519
Martijn Coenen527924a2017-01-04 12:59:48 +0100520Return<sp<IGnssDebug>> Gnss::getExtensionGnssDebug() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700521 if (mGnssIface == nullptr) {
522 ALOGE("%s: Gnss interface is unavailable", __func__);
523 } else {
524 const GpsDebugInterface* gpsDebugIface = static_cast<const GpsDebugInterface*>(
525 mGnssIface->get_extension(GPS_DEBUG_INTERFACE));
526
527 if (gpsDebugIface == nullptr) {
528 ALOGE("%s: GnssDebug interface is not implemented by HAL", __func__);
529 } else {
530 mGnssDebug = new GnssDebug(gpsDebugIface);
531 }
532 }
533
Martijn Coenen527924a2017-01-04 12:59:48 +0100534 return mGnssDebug;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700535}
536
Wyatt Rileyad03ab22016-12-14 14:54:29 -0800537Return<sp<IGnssBatching>> Gnss::getExtensionGnssBatching() {
538 if (mGnssIface == nullptr) {
539 ALOGE("%s: Gnss interface is unavailable", __func__);
540 } else {
541 // TODO(b/34133439): actually get an flpLocationIface
542 const FlpLocationInterface* flpLocationIface = nullptr;
543
544 if (flpLocationIface == nullptr) {
545 ALOGE("%s: GnssBatching interface is not implemented by HAL", __func__);
546 } else {
547 mGnssBatching = new GnssBatching(flpLocationIface);
548 }
549 }
550
551 return mGnssBatching;
552}
553
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700554IGnss* HIDL_FETCH_IGnss(const char* hal) {
555 hw_module_t* module;
556 IGnss* iface = nullptr;
557 int err = hw_get_module(GPS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
558
559 if (err == 0) {
560 hw_device_t* device;
561 err = module->methods->open(module, GPS_HARDWARE_MODULE_ID, &device);
562 if (err == 0) {
563 iface = new Gnss(reinterpret_cast<gps_device_t*>(device));
564 } else {
565 ALOGE("gnssDevice open %s failed: %d", hal, err);
566 }
567 } else {
568 ALOGE("gnss hw_get_module %s failed: %d", hal, err);
569 }
570 return iface;
571}
572
573} // namespace implementation
574} // namespace V1_0
575} // namespace gnss
576} // namespace hardware
577} // namespace android