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