blob: 2771f27b796dd44e6dde30f8ff8a5b0802947428 [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
35Gnss::Gnss() : mMinIntervalMs(1000) {}
36
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) {
51 auto svStatus = Utils::getMockSvInfoListV2_1();
52 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
63Return<bool> Gnss::stop() {
64 ALOGD("stop");
65 mIsActive = false;
66 if (mThread.joinable()) {
67 mThread.join();
68 }
69 return true;
70}
71
72// Methods from V1_0::IGnss follow.
73Return<bool> Gnss::setCallback(const sp<V1_0::IGnssCallback>&) {
74 // TODO implement
75 return bool{};
76}
77
78Return<void> Gnss::cleanup() {
79 // TODO implement
80 return Void();
81}
82
83Return<bool> Gnss::injectTime(int64_t, int64_t, int32_t) {
84 // TODO implement
85 return bool{};
86}
87
88Return<bool> Gnss::injectLocation(double, double, float) {
89 // TODO implement
90 return bool{};
91}
92
93Return<void> Gnss::deleteAidingData(V1_0::IGnss::GnssAidingData) {
94 // TODO implement
95 return Void();
96}
97
98Return<bool> Gnss::setPositionMode(V1_0::IGnss::GnssPositionMode,
99 V1_0::IGnss::GnssPositionRecurrence, uint32_t, uint32_t,
100 uint32_t) {
101 // TODO implement
102 return bool{};
103}
104
105Return<sp<V1_0::IAGnssRil>> Gnss::getExtensionAGnssRil() {
106 // TODO implement
107 return ::android::sp<V1_0::IAGnssRil>{};
108}
109
110Return<sp<V1_0::IGnssGeofencing>> Gnss::getExtensionGnssGeofencing() {
111 // TODO implement
112 return ::android::sp<V1_0::IGnssGeofencing>{};
113}
114
115Return<sp<V1_0::IAGnss>> Gnss::getExtensionAGnss() {
116 // TODO implement
117 return ::android::sp<V1_0::IAGnss>{};
118}
119
120Return<sp<V1_0::IGnssNi>> Gnss::getExtensionGnssNi() {
121 // TODO implement
122 return ::android::sp<V1_0::IGnssNi>{};
123}
124
125Return<sp<V1_0::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement() {
126 // TODO implement
127 return ::android::sp<V1_0::IGnssMeasurement>{};
128}
129
130Return<sp<V1_0::IGnssNavigationMessage>> Gnss::getExtensionGnssNavigationMessage() {
131 // TODO implement
132 return ::android::sp<V1_0::IGnssNavigationMessage>{};
133}
134
135Return<sp<V1_0::IGnssXtra>> Gnss::getExtensionXtra() {
136 // TODO implement
137 return ::android::sp<V1_0::IGnssXtra>{};
138}
139
140Return<sp<V1_0::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration() {
141 // TODO implement
142 return ::android::sp<V1_0::IGnssConfiguration>{};
143}
144
145Return<sp<V1_0::IGnssDebug>> Gnss::getExtensionGnssDebug() {
146 // TODO implement
147 return ::android::sp<V1_0::IGnssDebug>{};
148}
149
150Return<sp<V1_0::IGnssBatching>> Gnss::getExtensionGnssBatching() {
151 // TODO implement
152 return ::android::sp<V1_0::IGnssBatching>{};
153}
154
155// Methods from V1_1::IGnss follow.
156Return<bool> Gnss::setCallback_1_1(const sp<V1_1::IGnssCallback>&) {
157 // TODO implement
158 return bool{};
159}
160
161Return<bool> Gnss::setPositionMode_1_1(V1_0::IGnss::GnssPositionMode,
162 V1_0::IGnss::GnssPositionRecurrence, uint32_t, uint32_t,
163 uint32_t, bool) {
164 return true;
165}
166
167Return<sp<V1_1::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_1_1() {
168 // TODO implement
169 return ::android::sp<V1_1::IGnssConfiguration>{};
170}
171
172Return<sp<V1_1::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_1_1() {
173 // TODO implement
174 return ::android::sp<V1_1::IGnssMeasurement>{};
175}
176
177Return<bool> Gnss::injectBestLocation(const V1_0::GnssLocation&) {
178 // TODO implement
179 return bool{};
180}
181
182// Methods from V2_0::IGnss follow.
183Return<bool> Gnss::setCallback_2_0(const sp<V2_0::IGnssCallback>&) {
184 // TODO implement
185 return bool{};
186}
187
188Return<sp<V2_0::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_2_0() {
189 // TODO implement
190 return ::android::sp<V2_0::IGnssConfiguration>{};
191}
192
193Return<sp<V2_0::IGnssDebug>> Gnss::getExtensionGnssDebug_2_0() {
194 // TODO implement
195 return ::android::sp<V2_0::IGnssDebug>{};
196}
197
198Return<sp<V2_0::IAGnss>> Gnss::getExtensionAGnss_2_0() {
199 // TODO implement
200 return ::android::sp<V2_0::IAGnss>{};
201}
202
203Return<sp<V2_0::IAGnssRil>> Gnss::getExtensionAGnssRil_2_0() {
204 // TODO implement
205 return ::android::sp<V2_0::IAGnssRil>{};
206}
207
208Return<sp<V2_0::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_2_0() {
209 // TODO implement
210 return ::android::sp<V2_0::IGnssMeasurement>{};
211}
212
213Return<sp<measurement_corrections::V1_0::IMeasurementCorrections>>
214Gnss::getExtensionMeasurementCorrections() {
215 // TODO implement
216 return ::android::sp<measurement_corrections::V1_0::IMeasurementCorrections>{};
217}
218
219Return<sp<visibility_control::V1_0::IGnssVisibilityControl>> Gnss::getExtensionVisibilityControl() {
220 // TODO implement
221 return ::android::sp<visibility_control::V1_0::IGnssVisibilityControl>{};
222}
223
224Return<sp<V2_0::IGnssBatching>> Gnss::getExtensionGnssBatching_2_0() {
225 // TODO implement
226 return ::android::sp<V2_0::IGnssBatching>{};
227}
228
229Return<bool> Gnss::injectBestLocation_2_0(const V2_0::GnssLocation&) {
230 // TODO implement
231 return bool{};
232}
233
234// Methods from V2_1::IGnss follow.
235Return<bool> Gnss::setCallback_2_1(const sp<V2_1::IGnssCallback>& callback) {
236 ALOGD("Gnss::setCallback_2_1");
237 if (callback == nullptr) {
238 ALOGE("%s: Null callback ignored", __func__);
239 return false;
240 }
241
242 sGnssCallback_2_1 = callback;
243
244 using Capabilities = V2_0::IGnssCallback::Capabilities;
245 const auto capabilities = Capabilities::MEASUREMENTS | Capabilities::MEASUREMENT_CORRECTIONS |
246 Capabilities::LOW_POWER_MODE | Capabilities::SATELLITE_BLACKLIST;
247 auto ret = sGnssCallback_2_1->gnssSetCapabilitiesCb_2_0(capabilities);
248 if (!ret.isOk()) {
249 ALOGE("%s: Unable to invoke callback", __func__);
250 }
251
252 V1_1::IGnssCallback::GnssSystemInfo gnssInfo = {.yearOfHw = 2020};
253
254 ret = sGnssCallback_2_1->gnssSetSystemInfoCb(gnssInfo);
255 if (!ret.isOk()) {
256 ALOGE("%s: Unable to invoke callback", __func__);
257 }
258
259 auto gnssName = "Android Mock GNSS Implementation v2.1";
260 ret = sGnssCallback_2_1->gnssNameCb(gnssName);
261 if (!ret.isOk()) {
262 ALOGE("%s: Unable to invoke callback", __func__);
263 }
264
265 return true;
266}
267
268Return<sp<V2_1::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_2_1() {
269 ALOGD("Gnss::getExtensionGnssMeasurement_2_1");
270 return new GnssMeasurement();
271}
272
273void Gnss::reportSvStatus(const hidl_vec<GnssSvInfo>& svInfoList) const {
274 std::unique_lock<std::mutex> lock(mMutex);
275 if (sGnssCallback_2_1 == nullptr) {
276 ALOGE("%s: sGnssCallback v2.1 is null.", __func__);
277 return;
278 }
279 auto ret = sGnssCallback_2_1->gnssSvStatusCb_2_1(svInfoList);
280 if (!ret.isOk()) {
281 ALOGE("%s: Unable to invoke callback", __func__);
282 }
283}
284
285void Gnss::reportLocation(const V2_0::GnssLocation& location) const {
286 std::unique_lock<std::mutex> lock(mMutex);
287 if (sGnssCallback_2_1 == nullptr) {
288 ALOGE("%s: sGnssCallback v2.1 is null.", __func__);
289 return;
290 }
291 auto ret = sGnssCallback_2_1->gnssLocationCb_2_0(location);
292 if (!ret.isOk()) {
293 ALOGE("%s: Unable to invoke callback", __func__);
294 }
295}
296
297} // namespace implementation
298} // namespace V2_1
299} // namespace gnss
300} // namespace hardware
301} // namespace android