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