blob: 33a8fc3f236d8f97d653bc7e89c1ceb7d98bef36 [file] [log] [blame]
Michael Bestas3a0209e2023-05-04 01:15:47 +03001/*
2 * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
3 * Not a Contribution
4 */
5/*
6 * Copyright (C) 2016 The Android Open Source Project
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21#define LOG_TAG "LocSvc_AGnssInterface"
22
23#include <log_util.h>
24#include "Gnss.h"
25#include "AGnss.h"
26
27namespace android {
28namespace hardware {
29namespace gnss {
30namespace V2_1 {
31namespace implementation {
32
33static AGnss* spAGnss = nullptr;
34
35AGnss::AGnss(Gnss* gnss) : mGnss(gnss), mType(LOC_AGPS_TYPE_INVALID) {
36 spAGnss = this;
37}
38
39AGnss::~AGnss() {
40 spAGnss = nullptr;
41}
42
43void AGnss::agnssStatusIpV4Cb(AGnssExtStatusIpV4 status) {
44 if (nullptr != spAGnss) {
45 spAGnss->statusCb(status.type, status.status);
46 }
47}
48
49void AGnss::statusCb(AGpsExtType type, LocAGpsStatusValue status) {
50
51 V2_0::IAGnssCallback::AGnssType aType;
52 IAGnssCallback::AGnssStatusValue aStatus;
53
Michael Bestas3a0209e2023-05-04 01:15:47 +030054 switch (type) {
55 case LOC_AGPS_TYPE_SUPL:
56 aType = IAGnssCallback::AGnssType::SUPL;
57 break;
58 case LOC_AGPS_TYPE_SUPL_ES:
59 aType = IAGnssCallback::AGnssType::SUPL_EIMS;
60 break;
61 default:
62 LOC_LOGE("invalid type: %d", type);
63 return;
64 }
65
66 switch (status) {
67 case LOC_GPS_REQUEST_AGPS_DATA_CONN:
68 aStatus = IAGnssCallback::AGnssStatusValue::REQUEST_AGNSS_DATA_CONN;
69 break;
70 case LOC_GPS_RELEASE_AGPS_DATA_CONN:
71 aStatus = IAGnssCallback::AGnssStatusValue::RELEASE_AGNSS_DATA_CONN;
72 break;
73 case LOC_GPS_AGPS_DATA_CONNECTED:
74 aStatus = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONNECTED;
75 break;
76 case LOC_GPS_AGPS_DATA_CONN_DONE:
77 aStatus = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONN_DONE;
78 break;
79 case LOC_GPS_AGPS_DATA_CONN_FAILED:
80 aStatus = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONN_FAILED;
81 break;
82 default:
83 LOC_LOGE("invalid status: %d", status);
84 return;
85 }
86
Michael Bestas222c86c2024-07-18 12:36:55 -040087 mMutex.lock();
88 // cache the AGps Type
89 mType = type;
90 auto aGnssCbIface = mAGnssCbIface;
91 mMutex.unlock();
92 if (aGnssCbIface != nullptr) {
93 auto r = aGnssCbIface->agnssStatusCb(aType, aStatus);
Michael Bestas3a0209e2023-05-04 01:15:47 +030094 if (!r.isOk()) {
95 LOC_LOGw("Error invoking AGNSS status cb %s", r.description().c_str());
96 }
97 }
98 else {
99 LOC_LOGw("setCallback has not been called yet");
100 }
101}
102
103Return<void> AGnss::setCallback(const sp<V2_0::IAGnssCallback>& callback) {
104
105 if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
106 LOC_LOGE("Null GNSS interface");
107 return Void();
108 }
109
110 // Save the interface
Michael Bestas222c86c2024-07-18 12:36:55 -0400111 mMutex.lock();
Michael Bestas3a0209e2023-05-04 01:15:47 +0300112 mAGnssCbIface = callback;
Michael Bestas222c86c2024-07-18 12:36:55 -0400113 mMutex.unlock();
Michael Bestas3a0209e2023-05-04 01:15:47 +0300114
115 AgpsCbInfo cbInfo = {};
116 cbInfo.statusV4Cb = (void*)agnssStatusIpV4Cb;
117 cbInfo.atlType = AGPS_ATL_TYPE_SUPL | AGPS_ATL_TYPE_SUPL_ES;
118
119 mGnss->getGnssInterface()->agpsInit(cbInfo);
120 return Void();
121}
122
123Return<bool> AGnss::dataConnClosed() {
124
125 if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
126 LOC_LOGE("Null GNSS interface");
127 return false;
128 }
129
130 mGnss->getGnssInterface()->agpsDataConnClosed(LOC_AGPS_TYPE_SUPL);
131 return true;
132}
133
134Return<bool> AGnss::dataConnFailed() {
135
136 if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
137 LOC_LOGE("Null GNSS interface");
138 return false;
139 }
140
141 mGnss->getGnssInterface()->agpsDataConnFailed(LOC_AGPS_TYPE_SUPL);
142 return true;
143}
144
145Return<bool> AGnss::dataConnOpen(uint64_t /*networkHandle*/, const hidl_string& apn,
146 V2_0::IAGnss::ApnIpType apnIpType) {
147
148 if (mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
149 LOC_LOGE("Null GNSS interface");
150 return false;
151 }
152
153 std::string apnString(apn.c_str());
154 // During Emergency SUPL, an apn name of "sos" means that no
155 // apn was found, like in the simless case, so apn is cleared
156 if (LOC_AGPS_TYPE_SUPL_ES == mType && "sos" == apnString) {
157 LOC_LOGD("dataConnOpen APN name = [sos] cleared");
158 apnString.clear();
159 }
160
161 LOC_LOGD("dataConnOpen APN name = [%s]", apnString.c_str());
162
163 AGpsBearerType bearerType;
164 switch (apnIpType) {
165 case IAGnss::ApnIpType::IPV4:
166 bearerType = AGPS_APN_BEARER_IPV4;
167 break;
168 case IAGnss::ApnIpType::IPV6:
169 bearerType = AGPS_APN_BEARER_IPV6;
170 break;
171 case IAGnss::ApnIpType::IPV4V6:
172 bearerType = AGPS_APN_BEARER_IPV4V6;
173 break;
174 default:
175 bearerType = AGPS_APN_BEARER_IPV4;
176 break;
177 }
178
179 mGnss->getGnssInterface()->agpsDataConnOpen(
180 LOC_AGPS_TYPE_SUPL, apnString.c_str(), apnString.size(), (int)bearerType);
181 return true;
182}
183
184Return<bool> AGnss::setServer(V2_0::IAGnssCallback::AGnssType type,
185 const hidl_string& hostname,
186 int32_t port) {
187 if (mGnss == nullptr) {
188 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
189 return false;
190 }
191
192 GnssConfig config;
193 memset(&config, 0, sizeof(GnssConfig));
194 config.size = sizeof(GnssConfig);
195 config.flags = GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT;
196 config.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer);
197 if (type == IAGnssCallback::AGnssType::SUPL) {
198 config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL;
199 } else if (type == IAGnssCallback::AGnssType::C2K) {
200 config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_C2K;
201 } else if (type == IAGnssCallback::AGnssType::SUPL_EIMS) {
202 config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL_EIMS;
203 } else if (type == IAGnssCallback::AGnssType::SUPL_IMS) {
204 config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL_IMS;
205 } else {
206 LOC_LOGE("%s]: invalid AGnssType: %d", __FUNCTION__, static_cast<uint8_t>(type));
207 return false;
208 }
209 config.assistanceServer.hostName = strdup(hostname.c_str());
210 config.assistanceServer.port = port;
211 return mGnss->updateConfiguration(config);
212}
213
214} // namespace implementation
215} // namespace V2_1
216} // namespace gnss
217} // namespace hardware
218} // namespace android