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