Yu-Han Yang | c06b536 | 2019-10-25 14:14:35 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 25 | using ::android::hardware::gnss::common::Utils; |
| 26 | |
| 27 | namespace android { |
| 28 | namespace hardware { |
| 29 | namespace gnss { |
| 30 | namespace V2_1 { |
| 31 | namespace implementation { |
| 32 | |
| 33 | sp<V2_1::IGnssCallback> Gnss::sGnssCallback_2_1 = nullptr; |
| 34 | |
Sasha Kuznetsov | 845f6d5 | 2019-12-04 12:17:50 -0800 | [diff] [blame^] | 35 | Gnss::Gnss() : mMinIntervalMs(1000), mGnssConfiguration{new GnssConfiguration()} {} |
Yu-Han Yang | c06b536 | 2019-10-25 14:14:35 -0700 | [diff] [blame] | 36 | |
| 37 | Gnss::~Gnss() { |
| 38 | stop(); |
| 39 | } |
| 40 | |
| 41 | Return<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 Kuznetsov | 845f6d5 | 2019-12-04 12:17:50 -0800 | [diff] [blame^] | 51 | auto svStatus = filterBlacklistedSatellitesV2_1(Utils::getMockSvInfoListV2_1()); |
Yu-Han Yang | c06b536 | 2019-10-25 14:14:35 -0700 | [diff] [blame] | 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 | |
Sasha Kuznetsov | 845f6d5 | 2019-12-04 12:17:50 -0800 | [diff] [blame^] | 63 | hidl_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 Yang | c06b536 | 2019-10-25 14:14:35 -0700 | [diff] [blame] | 73 | Return<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. |
| 83 | Return<bool> Gnss::setCallback(const sp<V1_0::IGnssCallback>&) { |
| 84 | // TODO implement |
| 85 | return bool{}; |
| 86 | } |
| 87 | |
| 88 | Return<void> Gnss::cleanup() { |
| 89 | // TODO implement |
| 90 | return Void(); |
| 91 | } |
| 92 | |
| 93 | Return<bool> Gnss::injectTime(int64_t, int64_t, int32_t) { |
| 94 | // TODO implement |
| 95 | return bool{}; |
| 96 | } |
| 97 | |
| 98 | Return<bool> Gnss::injectLocation(double, double, float) { |
| 99 | // TODO implement |
| 100 | return bool{}; |
| 101 | } |
| 102 | |
| 103 | Return<void> Gnss::deleteAidingData(V1_0::IGnss::GnssAidingData) { |
| 104 | // TODO implement |
| 105 | return Void(); |
| 106 | } |
| 107 | |
| 108 | Return<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 | |
| 115 | Return<sp<V1_0::IAGnssRil>> Gnss::getExtensionAGnssRil() { |
| 116 | // TODO implement |
| 117 | return ::android::sp<V1_0::IAGnssRil>{}; |
| 118 | } |
| 119 | |
| 120 | Return<sp<V1_0::IGnssGeofencing>> Gnss::getExtensionGnssGeofencing() { |
| 121 | // TODO implement |
| 122 | return ::android::sp<V1_0::IGnssGeofencing>{}; |
| 123 | } |
| 124 | |
| 125 | Return<sp<V1_0::IAGnss>> Gnss::getExtensionAGnss() { |
| 126 | // TODO implement |
| 127 | return ::android::sp<V1_0::IAGnss>{}; |
| 128 | } |
| 129 | |
| 130 | Return<sp<V1_0::IGnssNi>> Gnss::getExtensionGnssNi() { |
| 131 | // TODO implement |
| 132 | return ::android::sp<V1_0::IGnssNi>{}; |
| 133 | } |
| 134 | |
| 135 | Return<sp<V1_0::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement() { |
| 136 | // TODO implement |
| 137 | return ::android::sp<V1_0::IGnssMeasurement>{}; |
| 138 | } |
| 139 | |
| 140 | Return<sp<V1_0::IGnssNavigationMessage>> Gnss::getExtensionGnssNavigationMessage() { |
| 141 | // TODO implement |
| 142 | return ::android::sp<V1_0::IGnssNavigationMessage>{}; |
| 143 | } |
| 144 | |
| 145 | Return<sp<V1_0::IGnssXtra>> Gnss::getExtensionXtra() { |
| 146 | // TODO implement |
| 147 | return ::android::sp<V1_0::IGnssXtra>{}; |
| 148 | } |
| 149 | |
| 150 | Return<sp<V1_0::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration() { |
| 151 | // TODO implement |
| 152 | return ::android::sp<V1_0::IGnssConfiguration>{}; |
| 153 | } |
| 154 | |
| 155 | Return<sp<V1_0::IGnssDebug>> Gnss::getExtensionGnssDebug() { |
| 156 | // TODO implement |
| 157 | return ::android::sp<V1_0::IGnssDebug>{}; |
| 158 | } |
| 159 | |
| 160 | Return<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. |
| 166 | Return<bool> Gnss::setCallback_1_1(const sp<V1_1::IGnssCallback>&) { |
| 167 | // TODO implement |
| 168 | return bool{}; |
| 169 | } |
| 170 | |
| 171 | Return<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 | |
| 177 | Return<sp<V1_1::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_1_1() { |
| 178 | // TODO implement |
| 179 | return ::android::sp<V1_1::IGnssConfiguration>{}; |
| 180 | } |
| 181 | |
| 182 | Return<sp<V1_1::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_1_1() { |
| 183 | // TODO implement |
| 184 | return ::android::sp<V1_1::IGnssMeasurement>{}; |
| 185 | } |
| 186 | |
| 187 | Return<bool> Gnss::injectBestLocation(const V1_0::GnssLocation&) { |
| 188 | // TODO implement |
| 189 | return bool{}; |
| 190 | } |
| 191 | |
| 192 | // Methods from V2_0::IGnss follow. |
| 193 | Return<bool> Gnss::setCallback_2_0(const sp<V2_0::IGnssCallback>&) { |
| 194 | // TODO implement |
| 195 | return bool{}; |
| 196 | } |
| 197 | |
| 198 | Return<sp<V2_0::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_2_0() { |
| 199 | // TODO implement |
| 200 | return ::android::sp<V2_0::IGnssConfiguration>{}; |
| 201 | } |
| 202 | |
| 203 | Return<sp<V2_0::IGnssDebug>> Gnss::getExtensionGnssDebug_2_0() { |
| 204 | // TODO implement |
| 205 | return ::android::sp<V2_0::IGnssDebug>{}; |
| 206 | } |
| 207 | |
| 208 | Return<sp<V2_0::IAGnss>> Gnss::getExtensionAGnss_2_0() { |
| 209 | // TODO implement |
| 210 | return ::android::sp<V2_0::IAGnss>{}; |
| 211 | } |
| 212 | |
| 213 | Return<sp<V2_0::IAGnssRil>> Gnss::getExtensionAGnssRil_2_0() { |
| 214 | // TODO implement |
| 215 | return ::android::sp<V2_0::IAGnssRil>{}; |
| 216 | } |
| 217 | |
| 218 | Return<sp<V2_0::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_2_0() { |
| 219 | // TODO implement |
| 220 | return ::android::sp<V2_0::IGnssMeasurement>{}; |
| 221 | } |
| 222 | |
| 223 | Return<sp<measurement_corrections::V1_0::IMeasurementCorrections>> |
| 224 | Gnss::getExtensionMeasurementCorrections() { |
| 225 | // TODO implement |
| 226 | return ::android::sp<measurement_corrections::V1_0::IMeasurementCorrections>{}; |
| 227 | } |
| 228 | |
| 229 | Return<sp<visibility_control::V1_0::IGnssVisibilityControl>> Gnss::getExtensionVisibilityControl() { |
| 230 | // TODO implement |
| 231 | return ::android::sp<visibility_control::V1_0::IGnssVisibilityControl>{}; |
| 232 | } |
| 233 | |
| 234 | Return<sp<V2_0::IGnssBatching>> Gnss::getExtensionGnssBatching_2_0() { |
| 235 | // TODO implement |
| 236 | return ::android::sp<V2_0::IGnssBatching>{}; |
| 237 | } |
| 238 | |
| 239 | Return<bool> Gnss::injectBestLocation_2_0(const V2_0::GnssLocation&) { |
| 240 | // TODO implement |
| 241 | return bool{}; |
| 242 | } |
| 243 | |
| 244 | // Methods from V2_1::IGnss follow. |
| 245 | Return<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 | |
| 278 | Return<sp<V2_1::IGnssMeasurement>> Gnss::getExtensionGnssMeasurement_2_1() { |
| 279 | ALOGD("Gnss::getExtensionGnssMeasurement_2_1"); |
| 280 | return new GnssMeasurement(); |
| 281 | } |
| 282 | |
Sasha Kuznetsov | 845f6d5 | 2019-12-04 12:17:50 -0800 | [diff] [blame^] | 283 | Return<sp<V2_1::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_2_1() { |
| 284 | return mGnssConfiguration; |
| 285 | } |
| 286 | |
Yu-Han Yang | c06b536 | 2019-10-25 14:14:35 -0700 | [diff] [blame] | 287 | void 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 | |
| 299 | void 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 |