-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gnss.cpp
806 lines (703 loc) · 26.9 KB
/
Gnss.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "GnssAidl"
#include "Gnss.h"
#include <inttypes.h>
#include <log/log.h>
#include <utils/Timers.h>
#include "AGnss.h"
#include "AGnssRil.h"
#include "DeviceFileReader.h"
#include "FixLocationParser.h"
#include "GnssAntennaInfo.h"
#include "GnssBatching.h"
#include "GnssConfiguration.h"
#include "GnssDebug.h"
#include "GnssGeofence.h"
#include "GnssNavigationMessageInterface.h"
#include "GnssPsds.h"
#include "GnssVisibilityControl.h"
#include "MeasurementCorrectionsInterface.h"
#include "Utils.h"
#include <hardware/gps.h>
namespace aidl::android::hardware::gnss {
using ::android::hardware::gnss::common::Utils;
using ndk::ScopedAStatus;
using GnssSvInfo = IGnssCallback::GnssSvInfo;
std::vector<std::unique_ptr<ThreadFuncArgs>> Gnss::sThreadFuncArgsList;
std::shared_ptr<IGnssCallback> Gnss::sGnssCallback = nullptr;
const GpsInterface* mGnssIface = nullptr;
GpsCallbacks Gnss::sGnssCb = {
.size = sizeof(GpsCallbacks),
.location_cb = locationCb,
.status_cb = statusCb,
.sv_status_cb = gpsSvStatusCb,
.nmea_cb = nmeaCb,
.set_capabilities_cb = setCapabilitiesCb,
.acquire_wakelock_cb = acquireWakelockCb,
.release_wakelock_cb = releaseWakelockCb,
.create_thread_cb = createThreadCb,
.request_utc_time_cb = requestUtcTimeCb,
.set_system_info_cb = setSystemInfoCb,
.gnss_sv_status_cb = gnssSvStatusCb,
};
bool Gnss::sWakelockHeldGnss = false;
bool Gnss::sWakelockHeldFused = false;
uint32_t Gnss::sCapabilitiesCached = 0;
uint16_t Gnss::sYearOfHwCached = 0;
GnssLocation convertToGnssLocation(GpsLocation* location) {
GnssLocation gnssLocation ;
if (location != nullptr) {
// Bit operation AND with 1f below is needed to clear vertical accuracy,
// speed accuracy and bearing accuracy flags as some vendors are found
// to be setting these bits in pre-Android-O devices
gnssLocation.gnssLocationFlags = static_cast<uint16_t>(location->flags & 0x1f);
gnssLocation.latitudeDegrees = location->latitude;
gnssLocation.longitudeDegrees = location->longitude;
gnssLocation.altitudeMeters = location->altitude;
gnssLocation.speedMetersPerSec = location->speed;
gnssLocation.bearingDegrees = location->bearing;
gnssLocation.horizontalAccuracyMeters = location->accuracy;
// Older chipsets do not provide the following 3 fields, hence the flags
// HAS_VERTICAL_ACCURACY, HAS_SPEED_ACCURACY and HAS_BEARING_ACCURACY are
// not set and the field are set to zeros.
gnssLocation.verticalAccuracyMeters = 0;
gnssLocation.speedAccuracyMetersPerSecond = 0;
gnssLocation.bearingAccuracyDegrees = 0;
gnssLocation.timestampMillis = location->timestamp;
}
return gnssLocation;
}
Gnss::Gnss() : mMinIntervalMs(1000), mFirstFixReceived(false) {
ALOGD("make Gnss");
hw_module_t* module;
int err = hw_get_module(GPS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
if (err == 0) {
hw_device_t* device;
gps_device_t* gnssDevice;
err = module->methods->open(module, GPS_HARDWARE_MODULE_ID, &device);
if (err == 0) {
ALOGD("gnss hw_get_module ok");
gnssDevice =(gps_device_t *)device;
mGnssIface = gnssDevice->get_gps_interface(gnssDevice);
} else {
ALOGE("gnssDevice open %s failed: %d", GPS_HARDWARE_MODULE_ID, err);
}
} else {
ALOGE("gnss hw_get_module %s failed: %d", GPS_HARDWARE_MODULE_ID, err);
}
}
void Gnss::locationCb(GpsLocation* location) {
if (sGnssCallback == nullptr) {
ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
return;
}
if (location == nullptr) {
ALOGE("%s: Invalid location from GNSS HAL", __func__);
return;
}
GnssLocation gnssLocation = convertToGnssLocation(location);
if (sGnssCallback == nullptr) {
ALOGE("%s: GnssCallback is null.", __func__);
return;
}
auto status = sGnssCallback->gnssLocationCb(gnssLocation);
if (!status.isOk()) {
ALOGE("%s: Unable to invoke gnssLocationCb", __func__);
}
}
void Gnss::statusCb(GpsStatus* gnssStatus) {
if (sGnssCallback == nullptr) {
ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
return;
}
if (gnssStatus == nullptr) {
ALOGE("%s: Invalid GpsStatus from GNSS HAL", __func__);
return;
}
IGnssCallback::GnssStatusValue status = static_cast<IGnssCallback::GnssStatusValue>(gnssStatus->status);
if (sGnssCallback == nullptr) {
ALOGE("%s: sGnssCallback is null.", __func__);
return;
}
auto status1 = sGnssCallback->gnssStatusCb(status);
if (!status1.isOk()) {
ALOGE("%s: Unable to invoke gnssStatusCb", __func__);
}
}
void Gnss::gnssSvStatusCb(GnssSvStatus* status) {
if (sGnssCallback == nullptr) {
ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
return;
}
if (status == nullptr) {
ALOGE("Invalid status from GNSS HAL %s", __func__);
return;
}
int numSvs = status->num_svs;
std::vector<GnssSvInfo> gnssSvInfoList;
if (numSvs > 64) {
ALOGW("Too many satellites %u. Clamps to 64.", numSvs);
numSvs = 64;
}
for (int i = 0; i < numSvs; i++) {
auto svInfo = status->gnss_sv_list[i];
GnssSvInfo gnssSvInfo = {
.svid = svInfo.svid,
.constellation = static_cast<
GnssConstellationType>(
svInfo.constellation),
.cN0Dbhz = svInfo.c_n0_dbhz,
.elevationDegrees = svInfo.elevation,
.azimuthDegrees = svInfo.azimuth,
// Older chipsets do not provide carrier frequency, hence
// HAS_CARRIER_FREQUENCY flag and the carrierFrequencyHz fields
// are not set. So we are resetting both fields here.
//.svFlag = static_cast<uint8_t>(
// svInfo.flags &= ~(static_cast<uint8_t>(
// V1_0::IGnssCallback::GnssSvFlags::HAS_CARRIER_FREQUENCY))),
.svFlag = svInfo.flags,
.carrierFrequencyHz = 1575420000};
gnssSvInfoList.push_back(gnssSvInfo);
}
if (sGnssCallback == nullptr) {
ALOGE("%s: sGnssCallback is null.", __func__);
return;
}
auto res = sGnssCallback->gnssSvStatusCb(gnssSvInfoList);
if (!res.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
}
/*
* This enum is used by gpsSvStatusCb() method below to convert GpsSvStatus
* to GnssSvStatus for backward compatibility. It is only used by the default
* implementation and is not part of the GNSS interface.
*/
enum SvidValues : uint16_t {
GLONASS_SVID_OFFSET = 64,
GLONASS_SVID_COUNT = 24,
BEIDOU_SVID_OFFSET = 200,
BEIDOU_SVID_COUNT = 35,
SBAS_SVID_MIN = 33,
SBAS_SVID_MAX = 64,
SBAS_SVID_ADD = 87,
QZSS_SVID_MIN = 193,
QZSS_SVID_MAX = 200
};
/*
* The following code that converts GpsSvStatus to GnssSvStatus is moved here from
* GnssLocationProvider. GnssLocationProvider does not require it anymore since GpsSvStatus is
* being deprecated and is no longer part of the GNSS interface.
*/
void Gnss::gpsSvStatusCb(GpsSvStatus* svInfo) {
if (sGnssCallback == nullptr) {
ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
return;
}
if (svInfo == nullptr) {
ALOGE("Invalid status from GNSS HAL %s", __func__);
return;
}
int numSvs = svInfo->num_svs;
std::vector<GnssSvInfo> gnssSvInfoList;
/*
* Clamp the list size since GnssSvStatus can support a maximum of
* GnssMax::SVS_COUNT entries.
*/
if (numSvs > 64) {
ALOGW("Too many satellites %u. Clamps to 64.", numSvs);
numSvs = 64;
}
uint32_t ephemerisMask = svInfo->ephemeris_mask;
uint32_t almanacMask = svInfo->almanac_mask;
uint32_t usedInFixMask = svInfo->used_in_fix_mask;
/*
* Conversion from GpsSvInfo to IGnssCallback::GnssSvInfo happens below.
*/
for (int i = 0; i < numSvs; i++) {
GnssSvInfo info;
info.svid = svInfo->sv_list[i].prn;
if (info.svid >= 1 && info.svid <= 32) {
info.constellation = GnssConstellationType::GPS;
} else if (info.svid > GLONASS_SVID_OFFSET &&
info.svid <= GLONASS_SVID_OFFSET + GLONASS_SVID_COUNT) {
info.constellation = GnssConstellationType::GLONASS;
info.svid -= GLONASS_SVID_OFFSET;
} else if (info.svid > BEIDOU_SVID_OFFSET &&
info.svid <= BEIDOU_SVID_OFFSET + BEIDOU_SVID_COUNT) {
info.constellation = GnssConstellationType::BEIDOU;
info.svid -= BEIDOU_SVID_OFFSET;
} else if (info.svid >= SBAS_SVID_MIN && info.svid <= SBAS_SVID_MAX) {
info.constellation = GnssConstellationType::SBAS;
info.svid += SBAS_SVID_ADD;
} else if (info.svid >= QZSS_SVID_MIN && info.svid <= QZSS_SVID_MAX) {
info.constellation = GnssConstellationType::QZSS;
} else {
ALOGD("Unknown constellation type with Svid = %d.", info.svid);
info.constellation = GnssConstellationType::UNKNOWN;
}
info.cN0Dbhz = svInfo->sv_list[i].snr;
info.elevationDegrees = svInfo->sv_list[i].elevation;
info.azimuthDegrees = svInfo->sv_list[i].azimuth;
// TODO: b/31702236
info.svFlag = static_cast<uint8_t>(IGnssCallback::GnssSvFlags::NONE);
/*
* Only GPS info is valid for these fields, as these masks are just 32
* bits, by GPS prn.
*/
if (info.constellation == GnssConstellationType::GPS) {
int32_t svidMask = (1 << (info.svid - 1));
if ((ephemerisMask & svidMask) != 0) {
info.svFlag |= (int)IGnssCallback::GnssSvFlags::HAS_EPHEMERIS_DATA;
}
if ((almanacMask & svidMask) != 0) {
info.svFlag |= (int)IGnssCallback::GnssSvFlags::HAS_ALMANAC_DATA;
}
if ((usedInFixMask & svidMask) != 0) {
info.svFlag |= (int)IGnssCallback::GnssSvFlags::USED_IN_FIX;
}
}
gnssSvInfoList.push_back(info);
}
if (sGnssCallback == nullptr) {
ALOGE("%s: sGnssCallback is null.", __func__);
return;
}
auto status = sGnssCallback->gnssSvStatusCb(gnssSvInfoList);
if (!status.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
}
void Gnss::nmeaCb(GpsUtcTime timestamp, const char* nmea, int length) {
if (sGnssCallback == nullptr) {
ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
return;
}
char nmeaString[300]={0};
memcpy(nmeaString,nmea,length);
if(sGnssCallback != nullptr) {
auto ret = sGnssCallback->gnssNmeaCb(timestamp, nmeaString);
if (!ret.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
}
}
void Gnss::setCapabilitiesCb(uint32_t capabilities) {
if (sGnssCallback == nullptr) {
ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
return;
}
if(sGnssCallback != nullptr) {
auto ret = sGnssCallback->gnssSetCapabilitiesCb(capabilities);
if (!ret.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
}
// Save for reconnection when some legacy hal's don't resend this info
sCapabilitiesCached = capabilities;
}
void Gnss::acquireWakelockCb() {
acquireWakelockGnss();
}
void Gnss::releaseWakelockCb() {
releaseWakelockGnss();
}
void Gnss::acquireWakelockGnss() {
sWakelockHeldGnss = true;
updateWakelock();
}
void Gnss::releaseWakelockGnss() {
sWakelockHeldGnss = false;
updateWakelock();
}
void Gnss::acquireWakelockFused() {
sWakelockHeldFused = true;
updateWakelock();
}
void Gnss::releaseWakelockFused() {
sWakelockHeldFused = false;
updateWakelock();
}
void Gnss::updateWakelock() {
// Track the state of the last request - in case the wake lock in the layer above is reference
// counted.
static bool sWakelockHeld = false;
if (sGnssCallback == nullptr) {
ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
return;
}
if (sWakelockHeldGnss || sWakelockHeldFused) {
if (!sWakelockHeld) {
ALOGI("%s: GNSS HAL Wakelock acquired due to gps: %d, fused: %d", __func__,
sWakelockHeldGnss, sWakelockHeldFused);
sWakelockHeld = true;
if(sGnssCallback != nullptr) {
auto ret = sGnssCallback->gnssAcquireWakelockCb();
if (!ret.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
}
}
} else {
if (sWakelockHeld) {
ALOGI("%s: GNSS HAL Wakelock released", __func__);
} else {
// To avoid burning power, always release, even if logic got here with sWakelock false
// which it shouldn't, unless underlying *.h implementation makes duplicate requests.
ALOGW("%s: GNSS HAL Wakelock released, duplicate request", __func__);
}
sWakelockHeld = false;
if(sGnssCallback != nullptr) {
auto ret = sGnssCallback->gnssReleaseWakelockCb();
if (!ret.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
}
}
}
void Gnss::requestUtcTimeCb() {
if (sGnssCallback == nullptr ) {
ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
return;
}
if(sGnssCallback != nullptr) {
auto ret = sGnssCallback->gnssRequestTimeCb();
if (!ret.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
}
}
pthread_t Gnss::createThreadCb(const char* name, void (*start)(void*), void* arg) {
return createPthread(name, start, arg, &sThreadFuncArgsList);
}
void Gnss::setSystemInfoCb(const LegacyGnssSystemInfo* info) {
if (sGnssCallback == nullptr ) {
ALOGE("%s: GNSS Callback Interface configured incorrectly", __func__);
return;
}
if (info == nullptr) {
ALOGE("Invalid GnssSystemInfo from GNSS HAL %s", __func__);
return;
}
IGnssCallback::GnssSystemInfo gnssInfo = {
.yearOfHw = info->year_of_hw
};
if(sGnssCallback != nullptr) {
auto ret = sGnssCallback->gnssSetSystemInfoCb(gnssInfo);
if (!ret.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
}
// Save for reconnection when some legacy hal's don't resend this info
sYearOfHwCached = info->year_of_hw;
}
ScopedAStatus Gnss::setCallback(const std::shared_ptr<IGnssCallback>& callback) {
ALOGD("setCallback");
if (mGnssIface == nullptr) {
ALOGE("%s: Gnss interface is unavailable", __func__);
return ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
if (callback == nullptr) {
ALOGE("%s: Null callback ignored", __func__);
return ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
sGnssCallback = callback;
int capabilities =
(int)(IGnssCallback::CAPABILITY_MEASUREMENTS | IGnssCallback::CAPABILITY_SCHEDULING |
IGnssCallback::CAPABILITY_SATELLITE_BLOCKLIST |
IGnssCallback::CAPABILITY_SATELLITE_PVT |
IGnssCallback::CAPABILITY_CORRELATION_VECTOR |
IGnssCallback::CAPABILITY_ANTENNA_INFO |
IGnssCallback::CAPABILITY_ACCUMULATED_DELTA_RANGE);
auto status = sGnssCallback->gnssSetCapabilitiesCb(capabilities);
if (!status.isOk()) {
ALOGE("%s: Unable to invoke callback.gnssSetCapabilitiesCb", __func__);
}
IGnssCallback::GnssSystemInfo systemInfo = {
.yearOfHw = 2022,
.name = "Google, Cuttlefish, AIDL v3",
};
status = sGnssCallback->gnssSetSystemInfoCb(systemInfo);
if (!status.isOk()) {
ALOGE("%s: Unable to invoke callback.gnssSetSystemInfoCb", __func__);
}
GnssSignalType signalType1 = {
.constellation = GnssConstellationType::GPS,
.carrierFrequencyHz = 1.57542e+09,
.codeType = GnssSignalType::CODE_TYPE_C,
};
GnssSignalType signalType2 = {
.constellation = GnssConstellationType::GLONASS,
.carrierFrequencyHz = 1.5980625e+09,
.codeType = GnssSignalType::CODE_TYPE_C,
};
status = sGnssCallback->gnssSetSignalTypeCapabilitiesCb(
std::vector<GnssSignalType>({signalType1, signalType2}));
if (!status.isOk()) {
ALOGE("%s: Unable to invoke callback.gnssSetSignalTypeCapabilitiesCb", __func__);
}
if (sCapabilitiesCached != 0) {
setCapabilitiesCb(sCapabilitiesCached);
}
if (sYearOfHwCached != 0) {
LegacyGnssSystemInfo info;
info.year_of_hw = sYearOfHwCached;
setSystemInfoCb(&info);
}
if(mGnssIface->init(&sGnssCb)){
ALOGE("%s: Unable to init gps module", __func__);
}
return ScopedAStatus::ok();
}
std::unique_ptr<GnssLocation> Gnss::getLocationFromHW() {
if (!::android::hardware::gnss::common::ReplayUtils::hasFixedLocationDeviceFile()) {
return nullptr;
}
std::string inputStr =
::android::hardware::gnss::common::DeviceFileReader::Instance().getLocationData();
return ::android::hardware::gnss::common::FixLocationParser::getLocationFromInputStr(inputStr);
}
ScopedAStatus Gnss::start() {
ALOGD("start()");
if (mIsActive) {
ALOGW("Gnss has started. Restarting...");
stop();
}
mIsActive = true;
mThreadBlocker.reset();
// notify measurement engine to update measurement interval
//mGnssMeasurementInterface->setLocationEnabled(true);
this->reportGnssStatusValue(IGnssCallback::GnssStatusValue::SESSION_BEGIN);
if (mGnssIface == nullptr) {
ALOGE("%s: Gnss interface is unavailable", __func__);
return ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
mGnssIface->start() ;
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::stop() {
ALOGD("stop");
mIsActive = false;
mGnssMeasurementInterface->setLocationEnabled(false);
this->reportGnssStatusValue(IGnssCallback::GnssStatusValue::SESSION_END);
if (mGnssIface == nullptr) {
ALOGE("%s: Gnss interface is unavailable", __func__);
return ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
mGnssIface->stop();
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::close() {
ALOGD("close");
sGnssCallback = nullptr;
return ScopedAStatus::ok();
}
void Gnss::reportLocation(const GnssLocation& location) const {
std::unique_lock<std::mutex> lock(mMutex);
if (sGnssCallback == nullptr) {
ALOGE("%s: GnssCallback is null.", __func__);
return;
}
auto status = sGnssCallback->gnssLocationCb(location);
if (!status.isOk()) {
ALOGE("%s: Unable to invoke gnssLocationCb", __func__);
}
return;
}
void Gnss::reportSvStatus() const {
if (mIsSvStatusActive) {
auto svStatus = filterBlocklistedSatellites(Utils::getMockSvInfoList());
reportSvStatus(svStatus);
}
}
void Gnss::reportSvStatus(const std::vector<GnssSvInfo>& svInfoList) const {
std::unique_lock<std::mutex> lock(mMutex);
if (sGnssCallback == nullptr) {
ALOGE("%s: sGnssCallback is null.", __func__);
return;
}
auto status = sGnssCallback->gnssSvStatusCb(svInfoList);
if (!status.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
}
std::vector<GnssSvInfo> Gnss::filterBlocklistedSatellites(
std::vector<GnssSvInfo> gnssSvInfoList) const {
for (uint32_t i = 0; i < gnssSvInfoList.size(); i++) {
if (mGnssConfiguration->isBlocklisted(gnssSvInfoList[i])) {
gnssSvInfoList[i].svFlag &= ~(uint32_t)IGnssCallback::GnssSvFlags::USED_IN_FIX;
}
}
return gnssSvInfoList;
}
void Gnss::reportGnssStatusValue(const IGnssCallback::GnssStatusValue gnssStatusValue) const {
std::unique_lock<std::mutex> lock(mMutex);
if (sGnssCallback == nullptr) {
ALOGE("%s: sGnssCallback is null.", __func__);
return;
}
auto status = sGnssCallback->gnssStatusCb(gnssStatusValue);
if (!status.isOk()) {
ALOGE("%s: Unable to invoke gnssStatusCb", __func__);
}
}
void Gnss::reportNmea() const {
if (mIsNmeaActive) {
std::unique_lock<std::mutex> lock(mMutex);
if (sGnssCallback == nullptr) {
ALOGE("%s: sGnssCallback is null.", __func__);
return;
}
nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
auto status = sGnssCallback->gnssNmeaCb(now, "$TEST,0,1,2,3,4,5");
if (!status.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
}
}
ScopedAStatus Gnss::startSvStatus() {
ALOGD("startSvStatus");
mIsSvStatusActive = true;
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::stopSvStatus() {
ALOGD("stopSvStatus");
mIsSvStatusActive = false;
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::startNmea() {
ALOGD("startNmea");
mIsNmeaActive = true;
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::stopNmea() {
ALOGD("stopNmea");
mIsNmeaActive = false;
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::getExtensionAGnss(std::shared_ptr<IAGnss>* iAGnss) {
ALOGD("Gnss::getExtensionAGnss");
*iAGnss = SharedRefBase::make<AGnss>();
return ndk::ScopedAStatus::ok();
}
ScopedAStatus Gnss::injectTime(int64_t timeMs, int64_t timeReferenceMs, int uncertaintyMs) {
ALOGD("injectTime. timeMs:%" PRId64 ", timeReferenceMs:%" PRId64 ", uncertaintyMs:%d", timeMs,
timeReferenceMs, uncertaintyMs);
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::getExtensionAGnssRil(std::shared_ptr<IAGnssRil>* iAGnssRil) {
ALOGD("Gnss::getExtensionAGnssRil");
*iAGnssRil = SharedRefBase::make<AGnssRil>();
return ndk::ScopedAStatus::ok();
}
ScopedAStatus Gnss::injectLocation(const GnssLocation& location) {
ALOGD("injectLocation. lat:%lf, lng:%lf, acc:%f", location.latitudeDegrees,
location.longitudeDegrees, location.horizontalAccuracyMeters);
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::injectBestLocation(const GnssLocation& location) {
ALOGD("injectBestLocation. lat:%lf, lng:%lf, acc:%f", location.latitudeDegrees,
location.longitudeDegrees, location.horizontalAccuracyMeters);
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::deleteAidingData(GnssAidingData aidingDataFlags) {
ALOGD("deleteAidingData. flags:%d", (int)aidingDataFlags);
mFirstFixReceived = false;
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::setPositionMode(const PositionModeOptions& options) {
ALOGD("setPositionMode. minIntervalMs:%d, lowPowerMode:%d", options.minIntervalMs,
(int)options.lowPowerMode);
mMinIntervalMs = std::max(1000, options.minIntervalMs);
mGnssMeasurementInterface->setLocationInterval(mMinIntervalMs);
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::getExtensionPsds(std::shared_ptr<IGnssPsds>* iGnssPsds) {
ALOGD("getExtensionPsds");
*iGnssPsds = SharedRefBase::make<GnssPsds>();
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::getExtensionGnssConfiguration(
std::shared_ptr<IGnssConfiguration>* iGnssConfiguration) {
ALOGD("getExtensionGnssConfiguration");
if (mGnssConfiguration == nullptr) {
mGnssConfiguration = SharedRefBase::make<GnssConfiguration>();
}
*iGnssConfiguration = mGnssConfiguration;
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::getExtensionGnssPowerIndication(
std::shared_ptr<IGnssPowerIndication>* iGnssPowerIndication) {
ALOGD("getExtensionGnssPowerIndication");
if (mGnssPowerIndication == nullptr) {
mGnssPowerIndication = SharedRefBase::make<GnssPowerIndication>();
}
*iGnssPowerIndication = mGnssPowerIndication;
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::getExtensionGnssMeasurement(
std::shared_ptr<IGnssMeasurementInterface>* iGnssMeasurement) {
ALOGD("getExtensionGnssMeasurement");
if (mGnssMeasurementInterface == nullptr) {
mGnssMeasurementInterface = SharedRefBase::make<GnssMeasurementInterface>();
mGnssMeasurementInterface->setGnssInterface(static_cast<std::shared_ptr<Gnss>>(this));
}
*iGnssMeasurement = mGnssMeasurementInterface;
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::getExtensionGnssBatching(std::shared_ptr<IGnssBatching>* iGnssBatching) {
ALOGD("getExtensionGnssBatching");
*iGnssBatching = SharedRefBase::make<GnssBatching>();
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::getExtensionGnssGeofence(std::shared_ptr<IGnssGeofence>* iGnssGeofence) {
ALOGD("getExtensionGnssGeofence");
*iGnssGeofence = SharedRefBase::make<GnssGeofence>();
return ScopedAStatus::ok();
}
ScopedAStatus Gnss::getExtensionGnssNavigationMessage(
std::shared_ptr<IGnssNavigationMessageInterface>* iGnssNavigationMessage) {
ALOGD("getExtensionGnssNavigationMessage");
*iGnssNavigationMessage = SharedRefBase::make<GnssNavigationMessageInterface>();
return ScopedAStatus::ok();
}
ndk::ScopedAStatus Gnss::getExtensionGnssDebug(std::shared_ptr<IGnssDebug>* iGnssDebug) {
ALOGD("Gnss::getExtensionGnssDebug");
*iGnssDebug = SharedRefBase::make<GnssDebug>();
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus Gnss::getExtensionGnssVisibilityControl(
std::shared_ptr<visibility_control::IGnssVisibilityControl>* iGnssVisibilityControl) {
ALOGD("Gnss::getExtensionGnssVisibilityControl");
*iGnssVisibilityControl = SharedRefBase::make<visibility_control::GnssVisibilityControl>();
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus Gnss::getExtensionGnssAntennaInfo(
std::shared_ptr<IGnssAntennaInfo>* iGnssAntennaInfo) {
ALOGD("Gnss::getExtensionGnssAntennaInfo");
*iGnssAntennaInfo = SharedRefBase::make<GnssAntennaInfo>();
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus Gnss::getExtensionMeasurementCorrections(
std::shared_ptr<measurement_corrections::IMeasurementCorrectionsInterface>*
iMeasurementCorrections) {
ALOGD("Gnss::getExtensionMeasurementCorrections");
*iMeasurementCorrections =
SharedRefBase::make<measurement_corrections::MeasurementCorrectionsInterface>();
return ndk::ScopedAStatus::ok();
}
} // namespace aidl::android::hardware::gnss