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
|
#define LOG_TAG "Gnss"
#include "Gnss.h"
#include <android/hardware/gnss/1.0/types.h>
#include <log/log.h>
#include "Constants.h"
#include "GnssDebug.h"
#include "GnssMeasurement.h"
#include "Utils.h"
namespace android {
namespace hardware {
namespace gnss {
namespace V1_1 {
namespace implementation {
using ::android::hardware::gnss::common::Utils;
using GnssSvFlags = IGnssCallback::GnssSvFlags;
using namespace ::android::hardware::gnss::common;
const uint32_t MIN_INTERVAL_MILLIS = 100;
sp<::android::hardware::gnss::V1_1::IGnssCallback> Gnss::sGnssCallback = nullptr;
Gnss::Gnss() : mMinIntervalMs(1000), mGnssConfiguration{new GnssConfiguration()} {}
Gnss::~Gnss() {
stop();
}
// Methods from ::android::hardware::gnss::V1_0::IGnss follow.
Return<bool> Gnss::setCallback(const sp<::android::hardware::gnss::V1_0::IGnssCallback>&) {
// Mock handles only new callback (see setCallback1_1) coming from Android P+
return false;
}
Return<bool> Gnss::start() {
if (mIsActive) {
ALOGW("Gnss has started. Restarting...");
stop();
}
mIsActive = true;
mThread = std::thread([this]() {
while (mIsActive == true) {
auto svStatus = this->getMockSvStatus();
this->reportSvStatus(svStatus);
auto location = Utils::getMockLocationV1_0();
this->reportLocation(location);
std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs));
}
});
return true;
}
Return<bool> Gnss::stop() {
mIsActive = false;
if (mThread.joinable()) {
mThread.join();
}
return true;
}
Return<void> Gnss::cleanup() {
// TODO implement
return Void();
}
Return<bool> Gnss::injectTime(int64_t, int64_t, int32_t) {
// TODO implement
return bool{};
}
Return<bool> Gnss::injectLocation(double, double, float) {
// TODO implement
return bool{};
}
Return<void> Gnss::deleteAidingData(::android::hardware::gnss::V1_0::IGnss::GnssAidingData) {
return Void();
}
Return<bool> Gnss::setPositionMode(::android::hardware::gnss::V1_0::IGnss::GnssPositionMode,
::android::hardware::gnss::V1_0::IGnss::GnssPositionRecurrence,
uint32_t, uint32_t, uint32_t) {
// TODO implement
return bool{};
}
Return<sp<::android::hardware::gnss::V1_0::IAGnssRil>> Gnss::getExtensionAGnssRil() {
// TODO implement
return ::android::sp<::android::hardware::gnss::V1_0::IAGnssRil>{};
}
Return<sp<::android::hardware::gnss::V1_0::IGnssGeofencing>> Gnss::getExtensionGnssGeofencing() {
// TODO implement
return ::android::sp<::android::hardware::gnss::V1_0::IGnssGeofencing>{};
}
Return<sp<::android::hardware::gnss::V1_0::IAGnss>> Gnss::getExtensionAGnss() {
// TODO implement
return ::android::sp<::android::hardware::gnss::V1_0::IAGnss>{};
}
Return<sp<::android::hardware::gnss::V1_0::IGnssNi>> Gnss::getExtensionGnssNi() {
// TODO implement
return ::android::sp<::android::hardware::gnss::V1_0::IGnssNi>{};
}
Return<sp<::android::hardware::gnss::V1_0::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement() {
// TODO implement
return new GnssMeasurement();
}
Return<sp<::android::hardware::gnss::V1_0::IGnssNavigationMessage>>
Gnss::getExtensionGnssNavigationMessage() {
// TODO implement
return ::android::sp<::android::hardware::gnss::V1_0::IGnssNavigationMessage>{};
}
Return<sp<::android::hardware::gnss::V1_0::IGnssXtra>> Gnss::getExtensionXtra() {
// TODO implement
return ::android::sp<::android::hardware::gnss::V1_0::IGnssXtra>{};
}
Return<sp<::android::hardware::gnss::V1_0::IGnssConfiguration>>
Gnss::getExtensionGnssConfiguration() {
// TODO implement
return new GnssConfiguration();
}
Return<sp<::android::hardware::gnss::V1_0::IGnssDebug>> Gnss::getExtensionGnssDebug() {
return new GnssDebug();
}
Return<sp<::android::hardware::gnss::V1_0::IGnssBatching>> Gnss::getExtensionGnssBatching() {
// TODO implement
return ::android::sp<::android::hardware::gnss::V1_0::IGnssBatching>{};
}
// Methods from ::android::hardware::gnss::V1_1::IGnss follow.
Return<bool> Gnss::setCallback_1_1(
const sp<::android::hardware::gnss::V1_1::IGnssCallback>& callback) {
if (callback == nullptr) {
ALOGE("%s: Null callback ignored", __func__);
return false;
}
sGnssCallback = callback;
uint32_t capabilities = 0x0;
auto ret = sGnssCallback->gnssSetCapabilitesCb(capabilities);
if (!ret.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
IGnssCallback::GnssSystemInfo gnssInfo = {.yearOfHw = 2018};
ret = sGnssCallback->gnssSetSystemInfoCb(gnssInfo);
if (!ret.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
auto gnssName = "Google Mock GNSS Implementation v1.1";
ret = sGnssCallback->gnssNameCb(gnssName);
if (!ret.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
return true;
}
Return<bool> Gnss::setPositionMode_1_1(
::android::hardware::gnss::V1_0::IGnss::GnssPositionMode,
::android::hardware::gnss::V1_0::IGnss::GnssPositionRecurrence, uint32_t minIntervalMs,
uint32_t, uint32_t, bool) {
mMinIntervalMs = (minIntervalMs < MIN_INTERVAL_MILLIS) ? MIN_INTERVAL_MILLIS : minIntervalMs;
return true;
}
Return<sp<::android::hardware::gnss::V1_1::IGnssConfiguration>>
Gnss::getExtensionGnssConfiguration_1_1() {
return mGnssConfiguration;
}
Return<sp<::android::hardware::gnss::V1_1::IGnssMeasurement>>
Gnss::getExtensionGnssMeasurement_1_1() {
// TODO implement
return new GnssMeasurement();
}
Return<bool> Gnss::injectBestLocation(const GnssLocation&) {
return true;
}
Return<GnssSvStatus> Gnss::getMockSvStatus() const {
std::unique_lock<std::recursive_mutex> lock(mGnssConfiguration->getMutex());
GnssSvInfo mockGnssSvInfoList[] = {
Utils::getMockSvInfoV1_0(3, GnssConstellationType::GPS, 32.5, 59.1, 166.5,
kGpsL1FreqHz),
Utils::getMockSvInfoV1_0(5, GnssConstellationType::GPS, 27.0, 29.0, 56.5, kGpsL1FreqHz),
Utils::getMockSvInfoV1_0(17, GnssConstellationType::GPS, 30.5, 71.0, 77.0,
kGpsL5FreqHz),
Utils::getMockSvInfoV1_0(26, GnssConstellationType::GPS, 24.1, 28.0, 253.0,
kGpsL5FreqHz),
Utils::getMockSvInfoV1_0(5, GnssConstellationType::GLONASS, 20.5, 11.5, 116.0,
kGloG1FreqHz),
Utils::getMockSvInfoV1_0(17, GnssConstellationType::GLONASS, 21.5, 28.5, 186.0,
kGloG1FreqHz),
Utils::getMockSvInfoV1_0(18, GnssConstellationType::GLONASS, 28.3, 38.8, 69.0,
kGloG1FreqHz),
Utils::getMockSvInfoV1_0(10, GnssConstellationType::GLONASS, 25.0, 66.0, 247.0,
kGloG1FreqHz)};
GnssSvStatus svStatus = {.numSvs = sizeof(mockGnssSvInfoList) / sizeof(GnssSvInfo)};
for (uint32_t i = 0; i < svStatus.numSvs; i++) {
if (mGnssConfiguration->isBlacklisted(mockGnssSvInfoList[i])) {
/**
* Note well, this is a simple, mock emulation of not using a satellite by changing the
* used bit. Simply blanking the used bit, as is done here, is *not* an acceptable
* actual device implementation - actual devices *must not* use the satellite in the
* position calculation, as specified in IGnssConfiguration.hal.
*/
mockGnssSvInfoList[i].svFlag &=
~static_cast<uint8_t>(IGnssCallback::GnssSvFlags::USED_IN_FIX);
}
svStatus.gnssSvList[i] = mockGnssSvInfoList[i];
}
return svStatus;
}
Return<void> Gnss::reportLocation(const GnssLocation& location) const {
std::unique_lock<std::mutex> lock(mMutex);
if (sGnssCallback == nullptr) {
ALOGE("%s: sGnssCallback is null.", __func__);
return Void();
}
sGnssCallback->gnssLocationCb(location);
return Void();
}
Return<void> Gnss::reportSvStatus(const GnssSvStatus& svStatus) const {
std::unique_lock<std::mutex> lock(mMutex);
if (sGnssCallback == nullptr) {
ALOGE("%s: sGnssCallback is null.", __func__);
return Void();
}
sGnssCallback->gnssSvStatusCb(svStatus);
return Void();
}
} // namespace implementation
} // namespace V1_1
} // namespace gnss
} // namespace hardware
} // namespace android
|