blob: 19e22c25d52a038f6fec567382ab4d14a0a0afed [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,
gomoc3d92782017-01-11 14:04:21 -0800124 .svFlag = svInfo.flags,
125 // Older chipsets do not provide carrier frequency, hence HAS_CARRIER_FREQUENCY flag
126 // is not set and the carrierFrequencyHz field is set to zero
127 .carrierFrequencyHz = 0
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700128 };
129 svStatus.gnssSvList[i] = gnssSvInfo;
130 }
131
132 sGnssCbIface->gnssSvStatusCb(svStatus);
133}
134
135/*
136 * This enum is used by gpsSvStatusCb() method below to convert GpsSvStatus
137 * to GnssSvStatus for backward compatibility. It is only used by the default
138 * implementation and is not part of the GNSS interface.
139 */
140enum SvidValues : uint16_t {
141 GLONASS_SVID_OFFSET = 64,
142 GLONASS_SVID_COUNT = 24,
143 BEIDOU_SVID_OFFSET = 200,
144 BEIDOU_SVID_COUNT = 35,
145 SBAS_SVID_MIN = 33,
146 SBAS_SVID_MAX = 64,
147 SBAS_SVID_ADD = 87,
148 QZSS_SVID_MIN = 193,
149 QZSS_SVID_MAX = 200
150};
151
152/*
153 * The following code that converts GpsSvStatus to GnssSvStatus is moved here from
154 * GnssLocationProvider. GnssLocationProvider does not require it anymore since GpsSvStatus is
155 * being deprecated and is no longer part of the GNSS interface.
156 */
157void Gnss::gpsSvStatusCb(GpsSvStatus* svInfo) {
158 if (sGnssCbIface == nullptr) {
159 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
160 return;
161 }
162
163 if (svInfo == nullptr) {
164 ALOGE("Invalid status from GNSS HAL %s", __func__);
165 return;
166 }
167
168 IGnssCallback::GnssSvStatus svStatus;
169 svStatus.numSvs = svInfo->num_svs;
170 /*
171 * Clamp the list size since GnssSvStatus can support a maximum of
172 * GnssMax::SVS_COUNT entries.
173 */
174 if (svStatus.numSvs > static_cast<uint32_t>(GnssMax::SVS_COUNT)) {
175 ALOGW("Too many satellites %zd. Clamps to %d.", svStatus.numSvs, GnssMax::SVS_COUNT);
176 svStatus.numSvs = static_cast<uint32_t>(GnssMax::SVS_COUNT);
177 }
178
179 uint32_t ephemerisMask = svInfo->ephemeris_mask;
180 uint32_t almanacMask = svInfo->almanac_mask;
181 uint32_t usedInFixMask = svInfo->used_in_fix_mask;
182 /*
183 * Conversion from GpsSvInfo to IGnssCallback::GnssSvInfo happens below.
184 */
185 for (size_t i = 0; i < svStatus.numSvs; i++) {
186 IGnssCallback::GnssSvInfo& info = svStatus.gnssSvList[i];
187 info.svid = svInfo->sv_list[i].prn;
188 if (info.svid >= 1 && info.svid <= 32) {
189 info.constellation = GnssConstellationType::GPS;
190 } else if (info.svid > GLONASS_SVID_OFFSET &&
191 info.svid <= GLONASS_SVID_OFFSET + GLONASS_SVID_COUNT) {
192 info.constellation = GnssConstellationType::GLONASS;
193 info.svid -= GLONASS_SVID_OFFSET;
194 } else if (info.svid > BEIDOU_SVID_OFFSET &&
195 info.svid <= BEIDOU_SVID_OFFSET + BEIDOU_SVID_COUNT) {
196 info.constellation = GnssConstellationType::BEIDOU;
197 info.svid -= BEIDOU_SVID_OFFSET;
198 } else if (info.svid >= SBAS_SVID_MIN && info.svid <= SBAS_SVID_MAX) {
199 info.constellation = GnssConstellationType::SBAS;
200 info.svid += SBAS_SVID_ADD;
201 } else if (info.svid >= QZSS_SVID_MIN && info.svid <= QZSS_SVID_MAX) {
202 info.constellation = GnssConstellationType::QZSS;
203 } else {
204 ALOGD("Unknown constellation type with Svid = %d.", info.svid);
205 info.constellation = GnssConstellationType::UNKNOWN;
206 }
207
208 info.cN0Dbhz = svInfo->sv_list[i].snr;
209 info.elevationDegrees = svInfo->sv_list[i].elevation;
210 info.azimuthDegrees = svInfo->sv_list[i].azimuth;
Yifan Hong35e2aac2016-12-05 12:35:05 -0800211 // TODO: b/31702236
212 info.svFlag = static_cast<uint8_t>(IGnssCallback::GnssSvFlags::NONE);
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700213
214 /*
215 * Only GPS info is valid for these fields, as these masks are just 32
216 * bits, by GPS prn.
217 */
218 if (info.constellation == GnssConstellationType::GPS) {
219 int32_t svidMask = (1 << (info.svid - 1));
220 if ((ephemerisMask & svidMask) != 0) {
221 info.svFlag |= IGnssCallback::GnssSvFlags::HAS_EPHEMERIS_DATA;
222 }
223 if ((almanacMask & svidMask) != 0) {
224 info.svFlag |= IGnssCallback::GnssSvFlags::HAS_ALMANAC_DATA;
225 }
226 if ((usedInFixMask & svidMask) != 0) {
227 info.svFlag |= IGnssCallback::GnssSvFlags::USED_IN_FIX;
228 }
229 }
230 }
231
232 sGnssCbIface->gnssSvStatusCb(svStatus);
233}
234
235void Gnss::nmeaCb(GpsUtcTime timestamp, const char* nmea, int length) {
236 if (sGnssCbIface == nullptr) {
237 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
238 return;
239 }
240
241 android::hardware::hidl_string nmeaString;
242 nmeaString.setToExternal(nmea, length);
243 sGnssCbIface->gnssNmeaCb(timestamp, nmeaString);
244}
245
246void Gnss::setCapabilitiesCb(uint32_t capabilities) {
247 if (sGnssCbIface == nullptr) {
248 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
249 return;
250 }
251
252 sGnssCbIface->gnssSetCapabilitesCb(capabilities);
253}
254
255void Gnss::acquireWakelockCb() {
256 if (sGnssCbIface == nullptr) {
257 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
258 return;
259 }
260
261 sGnssCbIface->gnssAcquireWakelockCb();
262}
263
264void Gnss::releaseWakelockCb() {
265 if (sGnssCbIface == nullptr) {
266 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
267 return;
268 }
269
270 sGnssCbIface->gnssReleaseWakelockCb();
271}
272
273void Gnss::requestUtcTimeCb() {
274 if (sGnssCbIface == nullptr) {
275 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
276 return;
277 }
278
279 sGnssCbIface->gnssRequestTimeCb();
280}
281
282pthread_t Gnss::createThreadCb(const char* name, void (*start)(void*), void* arg) {
283 return createPthread(name, start, arg, &sThreadFuncArgsList);
284}
285
286void Gnss::setSystemInfoCb(const LegacyGnssSystemInfo* info) {
287 if (sGnssCbIface == nullptr) {
288 ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
289 return;
290 }
291
292 if (info == nullptr) {
293 ALOGE("Invalid GnssSystemInfo from GNSS HAL %s", __func__);
294 return;
295 }
296
297 IGnssCallback::GnssSystemInfo gnssInfo = {
298 .yearOfHw = info->year_of_hw
299 };
300
301 sGnssCbIface->gnssSetSystemInfoCb(gnssInfo);
302}
303
304
305// Methods from ::android::hardware::gnss::V1_0::IGnss follow.
306Return<bool> Gnss::setCallback(const sp<IGnssCallback>& callback) {
307 if (mGnssIface == nullptr) {
308 ALOGE("%s: Gnss interface is unavailable", __func__);
309 return false;
310 }
311
312 sGnssCbIface = callback;
313
314 return (mGnssIface->init(&sGnssCb) == 0);
315}
316
317Return<bool> Gnss::start() {
318 if (mGnssIface == nullptr) {
319 ALOGE("%s: Gnss interface is unavailable", __func__);
320 return false;
321 }
322
323 return (mGnssIface->start() == 0);
324}
325
326Return<bool> Gnss::stop() {
327 if (mGnssIface == nullptr) {
328 ALOGE("%s: Gnss interface is unavailable", __func__);
329 return false;
330 }
331
332 return (mGnssIface->stop() == 0);
333}
334
335Return<void> Gnss::cleanup() {
336 if (mGnssIface == nullptr) {
337 ALOGE("%s: Gnss interface is unavailable", __func__);
338 } else {
339 mGnssIface->cleanup();
340 }
341 return Void();
342}
343
344Return<bool> Gnss::injectLocation(double latitudeDegrees,
345 double longitudeDegrees,
346 float accuracyMeters) {
347 if (mGnssIface == nullptr) {
348 ALOGE("%s: Gnss interface is unavailable", __func__);
349 return false;
350 }
351
352 return (mGnssIface->inject_location(latitudeDegrees, longitudeDegrees, accuracyMeters) == 0);
353}
354
355Return<bool> Gnss::injectTime(int64_t timeMs, int64_t timeReferenceMs,
356 int32_t uncertaintyMs) {
357 if (mGnssIface == nullptr) {
358 ALOGE("%s: Gnss interface is unavailable", __func__);
359 return false;
360 }
361
362 return (mGnssIface->inject_time(timeMs, timeReferenceMs, uncertaintyMs) == 0);
363}
364
365Return<void> Gnss::deleteAidingData(IGnss::GnssAidingData aidingDataFlags) {
366 if (mGnssIface == nullptr) {
367 ALOGE("%s: Gnss interface is unavailable", __func__);
368 } else {
369 mGnssIface->delete_aiding_data(static_cast<GpsAidingData>(aidingDataFlags));
370 }
371 return Void();
372}
373
374Return<bool> Gnss::setPositionMode(IGnss::GnssPositionMode mode,
375 IGnss::GnssPositionRecurrence recurrence,
376 uint32_t minIntervalMs,
377 uint32_t preferredAccuracyMeters,
378 uint32_t preferredTimeMs) {
379 if (mGnssIface == nullptr) {
380 ALOGE("%s: Gnss interface is unavailable", __func__);
381 return false;
382 }
383
384 return (mGnssIface->set_position_mode(static_cast<GpsPositionMode>(mode),
385 static_cast<GpsPositionRecurrence>(recurrence),
386 minIntervalMs,
387 preferredAccuracyMeters,
388 preferredTimeMs) == 0);
389}
390
Martijn Coenen527924a2017-01-04 12:59:48 +0100391Return<sp<IAGnssRil>> Gnss::getExtensionAGnssRil() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700392 if (mGnssIface == nullptr) {
393 ALOGE("%s: Gnss interface is unavailable", __func__);
394 } else {
395 const AGpsRilInterface* agpsRilIface = static_cast<const AGpsRilInterface*>(
396 mGnssIface->get_extension(AGPS_RIL_INTERFACE));
397 if (agpsRilIface == nullptr) {
398 ALOGE("%s GnssRil interface not implemented by GNSS HAL", __func__);
399 } else {
400 mGnssRil = new AGnssRil(agpsRilIface);
401 }
402 }
Martijn Coenen527924a2017-01-04 12:59:48 +0100403 return mGnssRil;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700404}
405
Martijn Coenen527924a2017-01-04 12:59:48 +0100406Return<sp<IGnssConfiguration>> Gnss::getExtensionGnssConfiguration() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700407 if (mGnssIface == nullptr) {
408 ALOGE("%s: Gnss interface is unavailable", __func__);
409 } else {
410 const GnssConfigurationInterface* gnssConfigIface =
411 static_cast<const GnssConfigurationInterface*>(
412 mGnssIface->get_extension(GNSS_CONFIGURATION_INTERFACE));
413
414 if (gnssConfigIface == nullptr) {
415 ALOGE("%s GnssConfiguration interface not implemented by GNSS HAL", __func__);
416 } else {
417 mGnssConfig = new GnssConfiguration(gnssConfigIface);
418 }
419 }
Martijn Coenen527924a2017-01-04 12:59:48 +0100420 return mGnssConfig;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700421}
Martijn Coenen527924a2017-01-04 12:59:48 +0100422Return<sp<IGnssGeofencing>> Gnss::getExtensionGnssGeofencing() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700423 if (mGnssIface == nullptr) {
424 ALOGE("%s: Gnss interface is unavailable", __func__);
425 } else {
426 const GpsGeofencingInterface* gpsGeofencingIface =
427 static_cast<const GpsGeofencingInterface*>(
428 mGnssIface->get_extension(GPS_GEOFENCING_INTERFACE));
429
430 if (gpsGeofencingIface == nullptr) {
431 ALOGE("%s GnssGeofencing interface not implemented by GNSS HAL", __func__);
432 } else {
433 mGnssGeofencingIface = new GnssGeofencing(gpsGeofencingIface);
434 }
435 }
436
Martijn Coenen527924a2017-01-04 12:59:48 +0100437 return mGnssGeofencingIface;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700438}
439
Martijn Coenen527924a2017-01-04 12:59:48 +0100440Return<sp<IAGnss>> Gnss::getExtensionAGnss() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700441 if (mGnssIface == nullptr) {
442 ALOGE("%s: Gnss interface is unavailable", __func__);
443 } else {
444 const AGpsInterface* agpsIface = static_cast<const AGpsInterface*>(
445 mGnssIface->get_extension(AGPS_INTERFACE));
446 if (agpsIface == nullptr) {
447 ALOGE("%s AGnss interface not implemented by GNSS HAL", __func__);
448 } else {
449 mAGnssIface = new AGnss(agpsIface);
450 }
451 }
Martijn Coenen527924a2017-01-04 12:59:48 +0100452 return mAGnssIface;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700453}
454
Martijn Coenen527924a2017-01-04 12:59:48 +0100455Return<sp<IGnssNi>> Gnss::getExtensionGnssNi() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700456 if (mGnssIface == nullptr) {
457 ALOGE("%s: Gnss interface is unavailable", __func__);
458 } else {
459 const GpsNiInterface* gpsNiIface = static_cast<const GpsNiInterface*>(
460 mGnssIface->get_extension(GPS_NI_INTERFACE));
461 if (gpsNiIface == nullptr) {
462 ALOGE("%s GnssNi interface not implemented by GNSS HAL", __func__);
463 } else {
464 mGnssNi = new GnssNi(gpsNiIface);
465 }
466 }
Martijn Coenen527924a2017-01-04 12:59:48 +0100467 return mGnssNi;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700468}
469
Martijn Coenen527924a2017-01-04 12:59:48 +0100470Return<sp<IGnssMeasurement>> Gnss::getExtensionGnssMeasurement() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700471 if (mGnssIface == nullptr) {
472 ALOGE("%s: Gnss interface is unavailable", __func__);
473 } else {
474 const GpsMeasurementInterface* gpsMeasurementIface =
475 static_cast<const GpsMeasurementInterface*>(
476 mGnssIface->get_extension(GPS_MEASUREMENT_INTERFACE));
477
478 if (gpsMeasurementIface == nullptr) {
479 ALOGE("%s GnssMeasurement interface not implemented by GNSS HAL", __func__);
480 } else {
481 mGnssMeasurement = new GnssMeasurement(gpsMeasurementIface);
482 }
483 }
Martijn Coenen527924a2017-01-04 12:59:48 +0100484 return mGnssMeasurement;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700485}
486
Martijn Coenen527924a2017-01-04 12:59:48 +0100487Return<sp<IGnssNavigationMessage>> Gnss::getExtensionGnssNavigationMessage() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700488 if (mGnssIface == nullptr) {
489 ALOGE("%s: Gnss interface is unavailable", __func__);
490 } else {
491 const GpsNavigationMessageInterface* gpsNavigationMessageIface =
492 static_cast<const GpsNavigationMessageInterface*>(
493 mGnssIface->get_extension(GPS_NAVIGATION_MESSAGE_INTERFACE));
494
495 if (gpsNavigationMessageIface == nullptr) {
496 ALOGE("%s GnssNavigationMessage interface not implemented by GNSS HAL",
497 __func__);
498 } else {
499 mGnssNavigationMessage = new GnssNavigationMessage(gpsNavigationMessageIface);
500 }
501 }
502
Martijn Coenen527924a2017-01-04 12:59:48 +0100503 return mGnssNavigationMessage;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700504}
505
Martijn Coenen527924a2017-01-04 12:59:48 +0100506Return<sp<IGnssXtra>> Gnss::getExtensionXtra() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700507 if (mGnssIface == nullptr) {
508 ALOGE("%s: Gnss interface is unavailable", __func__);
509 } else {
510 const GpsXtraInterface* gpsXtraIface = static_cast<const GpsXtraInterface*>(
511 mGnssIface->get_extension(GPS_XTRA_INTERFACE));
512
513 if (gpsXtraIface == nullptr) {
514 ALOGE("%s GnssXtra interface not implemented by HAL", __func__);
515 } else {
516 mGnssXtraIface = new GnssXtra(gpsXtraIface);
517 }
518 }
519
Martijn Coenen527924a2017-01-04 12:59:48 +0100520 return mGnssXtraIface;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700521}
522
Martijn Coenen527924a2017-01-04 12:59:48 +0100523Return<sp<IGnssDebug>> Gnss::getExtensionGnssDebug() {
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700524 if (mGnssIface == nullptr) {
525 ALOGE("%s: Gnss interface is unavailable", __func__);
526 } else {
527 const GpsDebugInterface* gpsDebugIface = static_cast<const GpsDebugInterface*>(
528 mGnssIface->get_extension(GPS_DEBUG_INTERFACE));
529
530 if (gpsDebugIface == nullptr) {
531 ALOGE("%s: GnssDebug interface is not implemented by HAL", __func__);
532 } else {
533 mGnssDebug = new GnssDebug(gpsDebugIface);
534 }
535 }
536
Martijn Coenen527924a2017-01-04 12:59:48 +0100537 return mGnssDebug;
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700538}
539
Wyatt Rileyad03ab22016-12-14 14:54:29 -0800540Return<sp<IGnssBatching>> Gnss::getExtensionGnssBatching() {
541 if (mGnssIface == nullptr) {
542 ALOGE("%s: Gnss interface is unavailable", __func__);
543 } else {
544 // TODO(b/34133439): actually get an flpLocationIface
545 const FlpLocationInterface* flpLocationIface = nullptr;
546
547 if (flpLocationIface == nullptr) {
548 ALOGE("%s: GnssBatching interface is not implemented by HAL", __func__);
549 } else {
550 mGnssBatching = new GnssBatching(flpLocationIface);
551 }
552 }
553
554 return mGnssBatching;
555}
556
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -0700557IGnss* HIDL_FETCH_IGnss(const char* hal) {
558 hw_module_t* module;
559 IGnss* iface = nullptr;
560 int err = hw_get_module(GPS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
561
562 if (err == 0) {
563 hw_device_t* device;
564 err = module->methods->open(module, GPS_HARDWARE_MODULE_ID, &device);
565 if (err == 0) {
566 iface = new Gnss(reinterpret_cast<gps_device_t*>(device));
567 } else {
568 ALOGE("gnssDevice open %s failed: %d", hal, err);
569 }
570 } else {
571 ALOGE("gnss hw_get_module %s failed: %d", hal, err);
572 }
573 return iface;
574}
575
576} // namespace implementation
577} // namespace V1_0
578} // namespace gnss
579} // namespace hardware
580} // namespace android