blob: 384fd49cf626c17a68ba0ac759c4a6c71f02be87 [file] [log] [blame]
Yu-Han Yangc06b5362019-10-25 14:14:35 -07001/*
2 * Copyright (C) 2019 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 "Gnss"
18
19#include "Gnss.h"
20#include "GnssMeasurement.h"
21#include "Utils.h"
22
23#include <log/log.h>
24
25using ::android::hardware::gnss::common::Utils;
26
27namespace android {
28namespace hardware {
29namespace gnss {
30namespace V2_1 {
31namespace implementation {
32
33sp<V2_1::IGnssCallback> Gnss::sGnssCallback_2_1 = nullptr;
34
Sasha Kuznetsov845f6d52019-12-04 12:17:50 -080035Gnss::Gnss() : mMinIntervalMs(1000), mGnssConfiguration{new GnssConfiguration()} {}
Yu-Han Yangc06b5362019-10-25 14:14:35 -070036
37Gnss::~Gnss() {
38 stop();
39}
40
41Return<bool> Gnss::start() {
42 ALOGD("start");
43 if (mIsActive) {
44 ALOGW("Gnss has started. Restarting...");
45 stop();
46 }
47
48 mIsActive = true;
49 mThread = std::thread([this]() {
50 while (mIsActive == true) {
Sasha Kuznetsov845f6d52019-12-04 12:17:50 -080051 auto svStatus = filterBlacklistedSatellitesV2_1(Utils::getMockSvInfoListV2_1());
Yu-Han Yangc06b5362019-10-25 14:14:35 -070052 this->reportSvStatus(svStatus);
53
54 const auto location = Utils::getMockLocationV2_0();
55 this->reportLocation(location);
56
57 std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs));
58 }
59 });
60 return true;
61}
62
Sasha Kuznetsov845f6d52019-12-04 12:17:50 -080063hidl_vec<GnssSvInfo> Gnss::filterBlacklistedSatellitesV2_1(hidl_vec<GnssSvInfo> gnssSvInfoList) {
64 for (uint32_t i = 0; i < gnssSvInfoList.size(); i++) {
65 if (mGnssConfiguration->isBlacklistedV2_1(gnssSvInfoList[i])) {
66 gnssSvInfoList[i].v2_0.v1_0.svFlag &=
67 ~static_cast<uint8_t>(V1_0::IGnssCallback::GnssSvFlags::USED_IN_FIX);
68 }
69 }
70 return gnssSvInfoList;
71}
72
Yu-Han Yangc06b5362019-10-25 14:14:35 -070073Return<bool> Gnss::stop() {
74 ALOGD("stop");
75 mIsActive = false;
76 if (mThread.joinable()) {
77 mThread.join();
78 }
79 return true;
80}
81
82// Methods from V1_0::IGnss follow.
83Return<bool> Gnss::setCallback(const sp<V1_0::IGnssCallback>&) {
84 // TODO implement
85 return bool{};
86}
87
88Return<void> Gnss::cleanup() {
89 // TODO implement
90 return Void();
91}
92
93Return<bool> Gnss::injectTime(int64_t, int64_t, int32_t) {
94 // TODO implement
95 return bool{};
96}
97
98Return<bool> Gnss::injectLocation(double, double, float) {
99 // TODO implement
100 return bool{};
101}
102
103Return<void> Gnss::deleteAidingData(V1_0::IGnss::GnssAidingData) {
104 // TODO implement
105 return Void();
106}
107
108Return<bool> Gnss::setPositionMode(V1_0::IGnss::GnssPositionMode,
109 V1_0::IGnss::GnssPositionRecurrence, uint32_t, uint32_t,
110 uint32_t) {
111 // TODO implement
112 return bool{};
113}
114
115Return<sp<V1_0::IAGnssRil>> Gnss::getExtensionAGnssRil() {
116 // TODO implement
117 return ::android::sp<V1_0::IAGnssRil>{};
118}
119
120Return<sp<V1_0::IGnssGeofencing>> Gnss::getExtensionGnssGeofencing() {
121 // TODO implement
122 return ::android::sp<V1_0::IGnssGeofencing>{};
123}
124
125Return<sp<V1_0::IAGnss>> Gnss::getExtensionAGnss() {
126 // TODO implement
127 return ::android::sp<V1_0::IAGnss>{};
128}
129
130Return<sp<V1_0::IGnssNi>> Gnss::getExtensionGnssNi() {
131 // TODO implement
132 return ::android::sp<V1_0::IGnssNi>{};
133}
134
135Return<sp<V1_0::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement() {
136 // TODO implement
137 return ::android::sp<V1_0::IGnssMeasurement>{};
138}
139
140Return<sp<V1_0::IGnssNavigationMessage>> Gnss::getExtensionGnssNavigationMessage() {
141 // TODO implement
142 return ::android::sp<V1_0::IGnssNavigationMessage>{};
143}
144
145Return<sp<V1_0::IGnssXtra>> Gnss::getExtensionXtra() {
146 // TODO implement
147 return ::android::sp<V1_0::IGnssXtra>{};
148}
149
150Return<sp<V1_0::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration() {
151 // TODO implement
152 return ::android::sp<V1_0::IGnssConfiguration>{};
153}
154
155Return<sp<V1_0::IGnssDebug>> Gnss::getExtensionGnssDebug() {
156 // TODO implement
157 return ::android::sp<V1_0::IGnssDebug>{};
158}
159
160Return<sp<V1_0::IGnssBatching>> Gnss::getExtensionGnssBatching() {
161 // TODO implement
162 return ::android::sp<V1_0::IGnssBatching>{};
163}
164
165// Methods from V1_1::IGnss follow.
166Return<bool> Gnss::setCallback_1_1(const sp<V1_1::IGnssCallback>&) {
167 // TODO implement
168 return bool{};
169}
170
171Return<bool> Gnss::setPositionMode_1_1(V1_0::IGnss::GnssPositionMode,
172 V1_0::IGnss::GnssPositionRecurrence, uint32_t, uint32_t,
173 uint32_t, bool) {
174 return true;
175}
176
177Return<sp<V1_1::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_1_1() {
178 // TODO implement
179 return ::android::sp<V1_1::IGnssConfiguration>{};
180}
181
182Return<sp<V1_1::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_1_1() {
183 // TODO implement
184 return ::android::sp<V1_1::IGnssMeasurement>{};
185}
186
187Return<bool> Gnss::injectBestLocation(const V1_0::GnssLocation&) {
188 // TODO implement
189 return bool{};
190}
191
192// Methods from V2_0::IGnss follow.
193Return<bool> Gnss::setCallback_2_0(const sp<V2_0::IGnssCallback>&) {
194 // TODO implement
195 return bool{};
196}
197
198Return<sp<V2_0::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_2_0() {
199 // TODO implement
200 return ::android::sp<V2_0::IGnssConfiguration>{};
201}
202
203Return<sp<V2_0::IGnssDebug>> Gnss::getExtensionGnssDebug_2_0() {
204 // TODO implement
205 return ::android::sp<V2_0::IGnssDebug>{};
206}
207
208Return<sp<V2_0::IAGnss>> Gnss::getExtensionAGnss_2_0() {
209 // TODO implement
210 return ::android::sp<V2_0::IAGnss>{};
211}
212
213Return<sp<V2_0::IAGnssRil>> Gnss::getExtensionAGnssRil_2_0() {
214 // TODO implement
215 return ::android::sp<V2_0::IAGnssRil>{};
216}
217
218Return<sp<V2_0::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_2_0() {
219 // TODO implement
220 return ::android::sp<V2_0::IGnssMeasurement>{};
221}
222
223Return<sp<measurement_corrections::V1_0::IMeasurementCorrections>>
224Gnss::getExtensionMeasurementCorrections() {
225 // TODO implement
226 return ::android::sp<measurement_corrections::V1_0::IMeasurementCorrections>{};
227}
228
229Return<sp<visibility_control::V1_0::IGnssVisibilityControl>> Gnss::getExtensionVisibilityControl() {
230 // TODO implement
231 return ::android::sp<visibility_control::V1_0::IGnssVisibilityControl>{};
232}
233
234Return<sp<V2_0::IGnssBatching>> Gnss::getExtensionGnssBatching_2_0() {
235 // TODO implement
236 return ::android::sp<V2_0::IGnssBatching>{};
237}
238
239Return<bool> Gnss::injectBestLocation_2_0(const V2_0::GnssLocation&) {
240 // TODO implement
241 return bool{};
242}
243
244// Methods from V2_1::IGnss follow.
245Return<bool> Gnss::setCallback_2_1(const sp<V2_1::IGnssCallback>& callback) {
246 ALOGD("Gnss::setCallback_2_1");
247 if (callback == nullptr) {
248 ALOGE("%s: Null callback ignored", __func__);
249 return false;
250 }
251
252 sGnssCallback_2_1 = callback;
253
254 using Capabilities = V2_0::IGnssCallback::Capabilities;
255 const auto capabilities = Capabilities::MEASUREMENTS | Capabilities::MEASUREMENT_CORRECTIONS |
256 Capabilities::LOW_POWER_MODE | Capabilities::SATELLITE_BLACKLIST;
257 auto ret = sGnssCallback_2_1->gnssSetCapabilitiesCb_2_0(capabilities);
258 if (!ret.isOk()) {
259 ALOGE("%s: Unable to invoke callback", __func__);
260 }
261
262 V1_1::IGnssCallback::GnssSystemInfo gnssInfo = {.yearOfHw = 2020};
263
264 ret = sGnssCallback_2_1->gnssSetSystemInfoCb(gnssInfo);
265 if (!ret.isOk()) {
266 ALOGE("%s: Unable to invoke callback", __func__);
267 }
268
269 auto gnssName = "Android Mock GNSS Implementation v2.1";
270 ret = sGnssCallback_2_1->gnssNameCb(gnssName);
271 if (!ret.isOk()) {
272 ALOGE("%s: Unable to invoke callback", __func__);
273 }
274
275 return true;
276}
277
278Return<sp<V2_1::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_2_1() {
279 ALOGD("Gnss::getExtensionGnssMeasurement_2_1");
280 return new GnssMeasurement();
281}
282
Sasha Kuznetsov845f6d52019-12-04 12:17:50 -0800283Return<sp<V2_1::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_2_1() {
284 return mGnssConfiguration;
285}
286
Yu-Han Yangc06b5362019-10-25 14:14:35 -0700287void Gnss::reportSvStatus(const hidl_vec<GnssSvInfo>& svInfoList) const {
288 std::unique_lock<std::mutex> lock(mMutex);
289 if (sGnssCallback_2_1 == nullptr) {
290 ALOGE("%s: sGnssCallback v2.1 is null.", __func__);
291 return;
292 }
293 auto ret = sGnssCallback_2_1->gnssSvStatusCb_2_1(svInfoList);
294 if (!ret.isOk()) {
295 ALOGE("%s: Unable to invoke callback", __func__);
296 }
297}
298
299void Gnss::reportLocation(const V2_0::GnssLocation& location) const {
300 std::unique_lock<std::mutex> lock(mMutex);
301 if (sGnssCallback_2_1 == nullptr) {
302 ALOGE("%s: sGnssCallback v2.1 is null.", __func__);
303 return;
304 }
305 auto ret = sGnssCallback_2_1->gnssLocationCb_2_0(location);
306 if (!ret.isOk()) {
307 ALOGE("%s: Unable to invoke callback", __func__);
308 }
309}
310
311} // namespace implementation
312} // namespace V2_1
313} // namespace gnss
314} // namespace hardware
315} // namespace android