blob: 8fad5d633ba1228b899f7a99398605d5d5167b7f [file] [log] [blame]
Michael Bestas3a0209e2023-05-04 01:15:47 +03001/*
2 * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
3 * Not a Contribution
4 */
5/*
6 * Copyright (C) 2016 The Android Open Source Project
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21#define LOG_TAG "LocSvc_GnssInterface"
22#define LOG_NDEBUG 0
23
24#include <fstream>
25#include <log_util.h>
26#include <dlfcn.h>
27#include <cutils/properties.h>
28#include "Gnss.h"
29#include "LocationUtil.h"
30#include "battery_listener.h"
31#include "loc_misc_utils.h"
32
33typedef const GnssInterface* (getLocationInterface)();
34
35#define IMAGES_INFO_FILE "/sys/devices/soc0/images"
36#define DELIMITER ";"
37
38namespace android {
39namespace hardware {
40namespace gnss {
41namespace V2_0 {
42namespace implementation {
43
44using ::android::hardware::gnss::visibility_control::V1_0::implementation::GnssVisibilityControl;
45static sp<Gnss> sGnss;
46static std::string getVersionString() {
47 static std::string version;
48 if (!version.empty())
49 return version;
50
51 char value[PROPERTY_VALUE_MAX] = {0};
52 property_get("ro.hardware", value, "unknown");
53 version.append(value).append(DELIMITER);
54
55 std::ifstream in(IMAGES_INFO_FILE);
56 std::string s;
57 while(getline(in, s)) {
58 std::size_t found = s.find("CRM:");
59 if (std::string::npos == found) {
60 continue;
61 }
62
63 // skip over space characters after "CRM:"
64 const char* substr = s.c_str();
65 found += 4;
66 while (0 != substr[found] && isspace(substr[found])) {
67 found++;
68 }
69 if (s.find("11:") != found) {
70 continue;
71 }
72 s.erase(0, found + 3);
73
74 found = s.find_first_of("\r\n");
75 if (std::string::npos != found) {
76 s.erase(s.begin() + found, s.end());
77 }
78 version.append(s).append(DELIMITER);
79 }
80 return version;
81}
82
83void Gnss::GnssDeathRecipient::serviceDied(uint64_t cookie, const wp<IBase>& who) {
84 LOC_LOGE("%s] service died. cookie: %llu, who: %p",
85 __FUNCTION__, static_cast<unsigned long long>(cookie), &who);
86 if (mGnss != nullptr) {
87 mGnss->getGnssInterface()->resetNetworkInfo();
88 mGnss->cleanup();
89 }
90}
91
92void location_on_battery_status_changed(bool charging) {
93 LOC_LOGd("battery status changed to %s charging", charging ? "" : "not");
94 if (sGnss != nullptr) {
95 sGnss->getGnssInterface()->updateBatteryStatus(charging);
96 }
97}
98Gnss::Gnss() {
99 ENTRY_LOG_CALLFLOW();
100 sGnss = this;
101 // initilize gnss interface at first in case needing notify battery status
102 sGnss->getGnssInterface()->initialize();
103 // register health client to listen on battery change
104 loc_extn_battery_properties_listener_init(location_on_battery_status_changed);
105 // clear pending GnssConfig
106 memset(&mPendingConfig, 0, sizeof(GnssConfig));
107 mGnssDeathRecipient = new GnssDeathRecipient(this);
108}
109
110Gnss::~Gnss() {
111 ENTRY_LOG_CALLFLOW();
112 if (mApi != nullptr) {
113 mApi->destroy();
114 mApi = nullptr;
115 }
116 sGnss = nullptr;
117}
118
119GnssAPIClient* Gnss::getApi() {
120 if (mApi != nullptr) {
121 return mApi;
122 }
123
124 if (mGnssCbIface_2_0 != nullptr) {
125 mApi = new GnssAPIClient(mGnssCbIface_2_0);
126 } else if (mGnssCbIface_1_1 != nullptr) {
127 mApi = new GnssAPIClient(mGnssCbIface_1_1, mGnssNiCbIface);
128 } else if (mGnssCbIface != nullptr) {
129 mApi = new GnssAPIClient(mGnssCbIface, mGnssNiCbIface);
130 } else {
131 LOC_LOGW("%s] GnssAPIClient is not ready", __FUNCTION__);
132 return mApi;
133 }
134
135 if (mPendingConfig.size == sizeof(GnssConfig)) {
136 // we have pending GnssConfig
137 mApi->gnssConfigurationUpdate(mPendingConfig);
138 // clear size to invalid mPendingConfig
139 mPendingConfig.size = 0;
140 if (mPendingConfig.assistanceServer.hostName != nullptr) {
141 free((void*)mPendingConfig.assistanceServer.hostName);
142 }
143 }
144
145 return mApi;
146}
147
148const GnssInterface* Gnss::getGnssInterface() {
149 static bool getGnssInterfaceFailed = false;
150
151 if (nullptr == mGnssInterface && !getGnssInterfaceFailed) {
152 void * libHandle = nullptr;
153 getLocationInterface* getter = (getLocationInterface*)
154 dlGetSymFromLib(libHandle, "libgnss.so", "getGnssInterface");
155
156 if (nullptr == getter) {
157 getGnssInterfaceFailed = true;
158 } else {
159 mGnssInterface = (GnssInterface*)(*getter)();
160 }
161 }
162 return mGnssInterface;
163}
164
165Return<bool> Gnss::setCallback(const sp<V1_0::IGnssCallback>& callback) {
166 ENTRY_LOG_CALLFLOW();
167
168 // In case where previous call to setCallback_1_1 or setCallback_2_0, then
169 // we need to cleanup these interfaces/callbacks here since we no longer
170 // do so in cleanup() function to keep callbacks around after cleanup()
171 if (mApi != nullptr) {
172 mApi->gnssUpdateCallbacks_2_0(nullptr);
173 }
174 if (mGnssCbIface_1_1 != nullptr) {
175 mGnssCbIface_1_1->unlinkToDeath(mGnssDeathRecipient);
176 mGnssCbIface_1_1 = nullptr;
177 }
178 if (mGnssCbIface_2_0 != nullptr) {
179 mGnssCbIface_2_0->unlinkToDeath(mGnssDeathRecipient);
180 mGnssCbIface_2_0 = nullptr;
181 }
182
183
184 if (mGnssCbIface != nullptr) {
185 mGnssCbIface->unlinkToDeath(mGnssDeathRecipient);
186 }
187 mGnssCbIface = callback;
188 if (mGnssCbIface != nullptr) {
189 mGnssCbIface->linkToDeath(mGnssDeathRecipient, 0 /*cookie*/);
190 }
191
192 GnssAPIClient* api = getApi();
193 if (api != nullptr) {
194 api->gnssUpdateCallbacks(mGnssCbIface, mGnssNiCbIface);
195 api->gnssEnable(LOCATION_TECHNOLOGY_TYPE_GNSS);
196 api->requestCapabilities();
197 }
198 return true;
199}
200
201Return<bool> Gnss::setGnssNiCb(const sp<IGnssNiCallback>& callback) {
202 ENTRY_LOG_CALLFLOW();
203 mGnssNiCbIface = callback;
204 GnssAPIClient* api = getApi();
205 if (api != nullptr) {
206 api->gnssUpdateCallbacks(mGnssCbIface, mGnssNiCbIface);
207 }
208 return true;
209}
210
211Return<bool> Gnss::updateConfiguration(GnssConfig& gnssConfig) {
212 ENTRY_LOG_CALLFLOW();
213 GnssAPIClient* api = getApi();
214 if (api) {
215 api->gnssConfigurationUpdate(gnssConfig);
216 } else if (gnssConfig.flags != 0) {
217 // api is not ready yet, update mPendingConfig with gnssConfig
218 mPendingConfig.size = sizeof(GnssConfig);
219
220 if (gnssConfig.flags & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) {
221 mPendingConfig.flags |= GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT;
222 mPendingConfig.gpsLock = gnssConfig.gpsLock;
223 }
224 if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) {
225 mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT;
226 mPendingConfig.suplVersion = gnssConfig.suplVersion;
227 }
228 if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) {
229 mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT;
230 mPendingConfig.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer);
231 mPendingConfig.assistanceServer.type = gnssConfig.assistanceServer.type;
232 if (mPendingConfig.assistanceServer.hostName != nullptr) {
233 free((void*)mPendingConfig.assistanceServer.hostName);
234 mPendingConfig.assistanceServer.hostName =
235 strdup(gnssConfig.assistanceServer.hostName);
236 }
237 mPendingConfig.assistanceServer.port = gnssConfig.assistanceServer.port;
238 }
239 if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) {
240 mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT;
241 mPendingConfig.lppProfileMask = gnssConfig.lppProfileMask;
242 }
243 if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) {
244 mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT;
245 mPendingConfig.lppeControlPlaneMask = gnssConfig.lppeControlPlaneMask;
246 }
247 if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) {
248 mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT;
249 mPendingConfig.lppeUserPlaneMask = gnssConfig.lppeUserPlaneMask;
250 }
251 if (gnssConfig.flags & GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) {
252 mPendingConfig.flags |= GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT;
253 mPendingConfig.aGlonassPositionProtocolMask = gnssConfig.aGlonassPositionProtocolMask;
254 }
255 if (gnssConfig.flags & GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT) {
256 mPendingConfig.flags |= GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT;
257 mPendingConfig.emergencyPdnForEmergencySupl = gnssConfig.emergencyPdnForEmergencySupl;
258 }
259 if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT) {
260 mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT;
261 mPendingConfig.suplEmergencyServices = gnssConfig.suplEmergencyServices;
262 }
263 if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_MODE_BIT) {
264 mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_MODE_BIT;
265 mPendingConfig.suplModeMask = gnssConfig.suplModeMask;
266 }
267 if (gnssConfig.flags & GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT) {
268 mPendingConfig.flags |= GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT;
269 mPendingConfig.blacklistedSvIds = gnssConfig.blacklistedSvIds;
270 }
271 if (gnssConfig.flags & GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT) {
272 mPendingConfig.flags |= GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT;
273 mPendingConfig.emergencyExtensionSeconds = gnssConfig.emergencyExtensionSeconds;
274 }
275 }
276 return true;
277}
278
279Return<bool> Gnss::start() {
280 ENTRY_LOG_CALLFLOW();
281 bool retVal = false;
282 GnssAPIClient* api = getApi();
283 if (api) {
284 retVal = api->gnssStart();
285 }
286 return retVal;
287}
288
289Return<bool> Gnss::stop() {
290 ENTRY_LOG_CALLFLOW();
291 bool retVal = false;
292 GnssAPIClient* api = getApi();
293 if (api) {
294 retVal = api->gnssStop();
295 }
296 return retVal;
297}
298
299Return<void> Gnss::cleanup() {
300 ENTRY_LOG_CALLFLOW();
301
302 if (mApi != nullptr) {
303 mApi->gnssStop();
304 mApi->gnssDisable();
305 }
306
307 return Void();
308}
309
310Return<bool> Gnss::injectLocation(double latitudeDegrees,
311 double longitudeDegrees,
312 float accuracyMeters) {
313 ENTRY_LOG_CALLFLOW();
314 const GnssInterface* gnssInterface = getGnssInterface();
315 if (nullptr != gnssInterface) {
316 gnssInterface->injectLocation(latitudeDegrees, longitudeDegrees, accuracyMeters);
317 return true;
318 } else {
319 return false;
320 }
321}
322
323Return<bool> Gnss::injectTime(int64_t timeMs, int64_t timeReferenceMs,
324 int32_t uncertaintyMs) {
325 return true;
326}
327
328Return<void> Gnss::deleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags) {
329 ENTRY_LOG_CALLFLOW();
330 GnssAPIClient* api = getApi();
331 if (api) {
332 api->gnssDeleteAidingData(aidingDataFlags);
333 }
334 return Void();
335}
336
337Return<bool> Gnss::setPositionMode(V1_0::IGnss::GnssPositionMode mode,
338 V1_0::IGnss::GnssPositionRecurrence recurrence,
339 uint32_t minIntervalMs,
340 uint32_t preferredAccuracyMeters,
341 uint32_t preferredTimeMs) {
342 ENTRY_LOG_CALLFLOW();
343 bool retVal = false;
344 GnssAPIClient* api = getApi();
345 if (api) {
346 retVal = api->gnssSetPositionMode(mode, recurrence, minIntervalMs,
347 preferredAccuracyMeters, preferredTimeMs);
348 }
349 return retVal;
350}
351
352Return<sp<V1_0::IAGnss>> Gnss::getExtensionAGnss() {
353 ENTRY_LOG_CALLFLOW();
354 // deprecated function. Must return nullptr to pass VTS
355 return nullptr;
356}
357
358Return<sp<V1_0::IGnssNi>> Gnss::getExtensionGnssNi() {
359 ENTRY_LOG_CALLFLOW();
360 // deprecated function. Must return nullptr to pass VTS
361 return nullptr;
362}
363
364Return<sp<V1_0::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement() {
365 ENTRY_LOG_CALLFLOW();
366 if (mGnssMeasurement == nullptr)
367 mGnssMeasurement = new GnssMeasurement();
368 return mGnssMeasurement;
369}
370
371Return<sp<V1_0::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration() {
372 ENTRY_LOG_CALLFLOW();
373 if (mGnssConfig == nullptr) {
374 mGnssConfig = new GnssConfiguration(this);
375 }
376 return mGnssConfig;
377}
378
379Return<sp<V1_0::IGnssGeofencing>> Gnss::getExtensionGnssGeofencing() {
380 ENTRY_LOG_CALLFLOW();
381 if (mGnssGeofencingIface == nullptr) {
382 mGnssGeofencingIface = new GnssGeofencing();
383 }
384 return mGnssGeofencingIface;
385}
386
387Return<sp<V1_0::IGnssBatching>> Gnss::getExtensionGnssBatching() {
388 ENTRY_LOG_CALLFLOW();
389 if (mGnssBatching == nullptr) {
390 mGnssBatching = new GnssBatching();
391 }
392 return mGnssBatching;
393}
394
395Return<sp<V1_0::IGnssDebug>> Gnss::getExtensionGnssDebug() {
396 ENTRY_LOG_CALLFLOW();
397 if (mGnssDebug == nullptr) {
398 mGnssDebug = new GnssDebug(this);
399 }
400 return mGnssDebug;
401}
402
403Return<sp<V1_0::IAGnssRil>> Gnss::getExtensionAGnssRil() {
404 ENTRY_LOG_CALLFLOW();
405 if (mGnssRil == nullptr) {
406 mGnssRil = new AGnssRil(this);
407 }
408 return mGnssRil;
409}
410
411// Methods from ::android::hardware::gnss::V1_1::IGnss follow.
412Return<bool> Gnss::setCallback_1_1(const sp<V1_1::IGnssCallback>& callback) {
413 ENTRY_LOG_CALLFLOW();
414 auto r = callback->gnssNameCb(getVersionString());
415 if (!r.isOk()) {
416 LOC_LOGE("%s] Error from gnssNameCb description=%s",
417 __func__, r.description().c_str());
418 }
419
420 // In case where previous call to setCallback or setCallback_2_1, then
421 // we need to cleanup these interfaces/callbacks here since we no longer
422 // do so in cleanup() function to keep callbacks around after cleanup()
423 if (mApi != nullptr) {
424 mApi->gnssUpdateCallbacks_2_0(nullptr);
425 }
426 if (mGnssCbIface != nullptr) {
427 mGnssCbIface->unlinkToDeath(mGnssDeathRecipient);
428 mGnssCbIface = nullptr;
429 }
430 if (mGnssCbIface_2_0 != nullptr) {
431 mGnssCbIface_2_0->unlinkToDeath(mGnssDeathRecipient);
432 mGnssCbIface_2_0 = nullptr;
433 }
434
435
436 if (mGnssCbIface_1_1 != nullptr) {
437 mGnssCbIface_1_1->unlinkToDeath(mGnssDeathRecipient);
438 }
439 mGnssCbIface_1_1 = callback;
440 if (mGnssCbIface_1_1 != nullptr) {
441 mGnssCbIface_1_1->linkToDeath(mGnssDeathRecipient, 0 /*cookie*/);
442 }
443
444 const GnssInterface* gnssInterface = getGnssInterface();
445 if (nullptr != gnssInterface) {
446 OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) {
447 odcpiRequestCb(odcpiRequest);
448 };
Michael Bestas9f1f76e2024-05-28 23:23:20 +0300449 gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW,
450 (EMERGENCY_ODCPI | NON_EMERGENCY_ODCPI));
Michael Bestas3a0209e2023-05-04 01:15:47 +0300451 }
452
453 GnssAPIClient* api = getApi();
454 if (api != nullptr) {
455 api->gnssUpdateCallbacks(mGnssCbIface_1_1, mGnssNiCbIface);
456 api->gnssEnable(LOCATION_TECHNOLOGY_TYPE_GNSS);
457 api->requestCapabilities();
458 }
459
460 return true;
461}
462
463Return<bool> Gnss::setPositionMode_1_1(V1_0::IGnss::GnssPositionMode mode,
464 V1_0::IGnss::GnssPositionRecurrence recurrence,
465 uint32_t minIntervalMs,
466 uint32_t preferredAccuracyMeters,
467 uint32_t preferredTimeMs,
468 bool lowPowerMode) {
469 ENTRY_LOG_CALLFLOW();
470 bool retVal = false;
471 GnssAPIClient* api = getApi();
472 if (api) {
473 GnssPowerMode powerMode = lowPowerMode?
474 GNSS_POWER_MODE_M4 : GNSS_POWER_MODE_M2;
475 retVal = api->gnssSetPositionMode(mode, recurrence, minIntervalMs,
476 preferredAccuracyMeters, preferredTimeMs, powerMode, minIntervalMs);
477 }
478 return retVal;
479}
480
481Return<sp<V1_1::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_1_1() {
482 ENTRY_LOG_CALLFLOW();
483#ifdef GNSS_HIDL_LEGACY_MEASURMENTS
484 return nullptr;
485#else
486 if (mGnssMeasurement == nullptr)
487 mGnssMeasurement = new GnssMeasurement();
488 return mGnssMeasurement;
489#endif
490}
491
492Return<sp<V1_1::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_1_1() {
493 ENTRY_LOG_CALLFLOW();
494 if (mGnssConfig == nullptr)
495 mGnssConfig = new GnssConfiguration(this);
496 return mGnssConfig;
497}
498
499Return<bool> Gnss::injectBestLocation(const GnssLocation& gnssLocation) {
500 ENTRY_LOG_CALLFLOW();
501 const GnssInterface* gnssInterface = getGnssInterface();
502 if (nullptr != gnssInterface) {
503 Location location = {};
504 convertGnssLocation(gnssLocation, location);
505 gnssInterface->odcpiInject(location);
506 }
507 return true;
508}
509
510void Gnss::odcpiRequestCb(const OdcpiRequestInfo& request) {
511 ENTRY_LOG_CALLFLOW();
512
513 if (ODCPI_REQUEST_TYPE_STOP == request.type) {
514 return;
515 }
516 if (mGnssCbIface_2_0 != nullptr) {
517 // For emergency mode, request DBH (Device based hybrid) location
518 // Mark Independent from GNSS flag to false.
519 if (ODCPI_REQUEST_TYPE_START == request.type) {
520 LOC_LOGd("gnssRequestLocationCb_2_0 isUserEmergency = %d", request.isEmergencyMode);
521 auto r = mGnssCbIface_2_0->gnssRequestLocationCb_2_0(!request.isEmergencyMode,
522 request.isEmergencyMode);
523 if (!r.isOk()) {
524 LOC_LOGe("Error invoking gnssRequestLocationCb_2_0 %s", r.description().c_str());
525 }
526 } else {
527 LOC_LOGv("Unsupported ODCPI request type: %d", request.type);
528 }
529 } else if (mGnssCbIface_1_1 != nullptr) {
530 // For emergency mode, request DBH (Device based hybrid) location
531 // Mark Independent from GNSS flag to false.
532 if (ODCPI_REQUEST_TYPE_START == request.type) {
533 auto r = mGnssCbIface_1_1->gnssRequestLocationCb(!request.isEmergencyMode);
534 if (!r.isOk()) {
535 LOC_LOGe("Error invoking gnssRequestLocationCb %s", r.description().c_str());
536 }
537 } else {
538 LOC_LOGv("Unsupported ODCPI request type: %d", request.type);
539 }
540 } else {
541 LOC_LOGe("ODCPI request not supported.");
542 }
543}
544
545// Methods from ::android::hardware::gnss::V2_0::IGnss follow.
546Return<bool> Gnss::setCallback_2_0(const sp<V2_0::IGnssCallback>& callback) {
547 ENTRY_LOG_CALLFLOW();
548 auto r = callback->gnssNameCb(getVersionString());
549 if (!r.isOk()) {
550 LOC_LOGE("%s] Error from gnssNameCb description=%s",
551 __func__, r.description().c_str());
552 }
553
554 // In case where previous call to setCallback or setCallback_1_1, then
555 // we need to cleanup these interfaces/callbacks here since we no longer
556 // do so in cleanup() function to keep callbacks around after cleanup()
557 if (mApi != nullptr) {
558 mApi->gnssUpdateCallbacks(nullptr, nullptr);
559 }
560 mGnssNiCbIface = nullptr;
561 if (mGnssCbIface != nullptr) {
562 mGnssCbIface->unlinkToDeath(mGnssDeathRecipient);
563 mGnssCbIface = nullptr;
564 }
565 if (mGnssCbIface_1_1 != nullptr) {
566 mGnssCbIface_1_1->unlinkToDeath(mGnssDeathRecipient);
567 mGnssCbIface_1_1 = nullptr;
568 }
569
570 if (mGnssCbIface_2_0 != nullptr) {
571 mGnssCbIface_2_0->unlinkToDeath(mGnssDeathRecipient);
572 }
573 mGnssCbIface_2_0 = callback;
574 if (mGnssCbIface_2_0 != nullptr) {
575 mGnssCbIface_2_0->linkToDeath(mGnssDeathRecipient, 0 /*cookie*/);
576 }
577
578 const GnssInterface* gnssInterface = getGnssInterface();
579 if (nullptr != gnssInterface) {
580 OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) {
581 odcpiRequestCb(odcpiRequest);
582 };
Michael Bestas9f1f76e2024-05-28 23:23:20 +0300583 gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW,
584 (EMERGENCY_ODCPI | NON_EMERGENCY_ODCPI));
Michael Bestas3a0209e2023-05-04 01:15:47 +0300585 }
586
587 GnssAPIClient* api = getApi();
588 if (api != nullptr) {
589 api->gnssUpdateCallbacks_2_0(mGnssCbIface_2_0);
590 api->gnssEnable(LOCATION_TECHNOLOGY_TYPE_GNSS);
591 api->requestCapabilities();
592 }
593
594 return true;
595}
596
597Return<sp<V2_0::IAGnss>> Gnss::getExtensionAGnss_2_0() {
598 ENTRY_LOG_CALLFLOW();
599 if (mAGnssIface_2_0 == nullptr) {
600 mAGnssIface_2_0 = new AGnss(this);
601 }
602 return mAGnssIface_2_0;
603}
604Return<sp<V2_0::IAGnssRil>> Gnss::getExtensionAGnssRil_2_0() {
605 if (mGnssRil == nullptr) {
606 mGnssRil = new AGnssRil(this);
607 }
608 return mGnssRil;
609}
610
611Return<sp<V2_0::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_2_0() {
612 ENTRY_LOG_CALLFLOW();
613 if (mGnssConfig == nullptr) {
614 mGnssConfig = new GnssConfiguration(this);
615 }
616 return mGnssConfig;
617}
618Return<sp<V2_0::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_2_0() {
619 ENTRY_LOG_CALLFLOW();
620#ifdef GNSS_HIDL_LEGACY_MEASURMENTS
621 return nullptr;
622#else
623 if (mGnssMeasurement == nullptr)
624 mGnssMeasurement = new GnssMeasurement();
625 return mGnssMeasurement;
626#endif
627}
628Return<sp<::android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrections>>
629 Gnss::getExtensionMeasurementCorrections() {
630 // We do not support, so return nullptr to pass VTS
631 return nullptr;
632}
633Return<sp<::android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControl>>
634 Gnss::getExtensionVisibilityControl() {
635 ENTRY_LOG_CALLFLOW();
636 if (mVisibCtrl == nullptr) {
637 mVisibCtrl = new GnssVisibilityControl(this);
638 }
639 return mVisibCtrl;
640}
641
642Return<bool> Gnss::injectBestLocation_2_0(const V2_0::GnssLocation& gnssLocation) {
643 ENTRY_LOG_CALLFLOW();
644 const GnssInterface* gnssInterface = getGnssInterface();
645 if (nullptr != gnssInterface) {
646 Location location = {};
647 convertGnssLocation(gnssLocation, location);
648 gnssInterface->odcpiInject(location);
649 }
650 return true;
651}
652
653Return<sp<V2_0::IGnssDebug>> Gnss::getExtensionGnssDebug_2_0() {
654 ENTRY_LOG_CALLFLOW();
655 if (mGnssDebug == nullptr) {
656 mGnssDebug = new GnssDebug(this);
657 }
658 return mGnssDebug;
659}
660
661Return<sp<V2_0::IGnssBatching>> Gnss::getExtensionGnssBatching_2_0() {
662 return nullptr;
663}
664
665V1_0::IGnss* HIDL_FETCH_IGnss(const char* hal) {
666 ENTRY_LOG_CALLFLOW();
667 V1_0::IGnss* iface = nullptr;
668 iface = new Gnss();
669 if (iface == nullptr) {
670 LOC_LOGE("%s]: failed to get %s", __FUNCTION__, hal);
671 }
672 return iface;
673}
674
675} // namespace implementation
676} // namespace V2_0
677} // namespace gnss
678} // namespace hardware
679} // namespace android