blob: df2fe20ef4f7938b11abf06f99ecce4672e7b84d [file] [log] [blame]
Michael Bestas3a0209e2023-05-04 01:15:47 +03001/*
2 * Copyright (c) 2017-2019, 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_0 {
31namespace implementation {
32
33static AGnss* spAGnss = nullptr;
34
35AGnss::AGnss(Gnss* gnss) : mGnss(gnss) {
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
54 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 auto aGnssCbIface = mAGnssCbIface;
89 mMutex.unlock();
90 if (aGnssCbIface != nullptr) {
91 auto r = aGnssCbIface->agnssStatusCb(aType, aStatus);
Michael Bestas3a0209e2023-05-04 01:15:47 +030092 if (!r.isOk()) {
93 LOC_LOGw("Error invoking AGNSS status cb %s", r.description().c_str());
94 }
95 }
96 else {
97 LOC_LOGw("setCallback has not been called yet");
98 }
99}
100
101Return<void> AGnss::setCallback(const sp<V2_0::IAGnssCallback>& callback) {
102
103 if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
104 LOC_LOGE("Null GNSS interface");
105 return Void();
106 }
107
108 // Save the interface
Michael Bestas222c86c2024-07-18 12:36:55 -0400109 mMutex.lock();
Michael Bestas3a0209e2023-05-04 01:15:47 +0300110 mAGnssCbIface = callback;
Michael Bestas222c86c2024-07-18 12:36:55 -0400111 mMutex.unlock();
Michael Bestas3a0209e2023-05-04 01:15:47 +0300112
113 AgpsCbInfo cbInfo = {};
114 cbInfo.statusV4Cb = (void*)agnssStatusIpV4Cb;
115 cbInfo.atlType = AGPS_ATL_TYPE_SUPL | AGPS_ATL_TYPE_SUPL_ES;
116
117 mGnss->getGnssInterface()->agpsInit(cbInfo);
118 return Void();
119}
120
121Return<bool> AGnss::dataConnClosed() {
122
123 if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
124 LOC_LOGE("Null GNSS interface");
125 return false;
126 }
127
128 mGnss->getGnssInterface()->agpsDataConnClosed(LOC_AGPS_TYPE_SUPL);
129 return true;
130}
131
132Return<bool> AGnss::dataConnFailed() {
133
134 if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
135 LOC_LOGE("Null GNSS interface");
136 return false;
137 }
138
139 mGnss->getGnssInterface()->agpsDataConnFailed(LOC_AGPS_TYPE_SUPL);
140 return true;
141}
142
143Return<bool> AGnss::dataConnOpen(uint64_t /*networkHandle*/, const hidl_string& apn,
144 V2_0::IAGnss::ApnIpType apnIpType) {
145
146 if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
147 LOC_LOGE("Null GNSS interface");
148 return false;
149 }
150
151 /* Validate */
152 if(apn.empty()){
153 LOC_LOGE("Invalid APN");
154 return false;
155 }
156
157 LOC_LOGD("dataConnOpen APN name = [%s]", apn.c_str());
158
159 AGpsBearerType bearerType;
160 switch (apnIpType) {
161 case IAGnss::ApnIpType::IPV4:
162 bearerType = AGPS_APN_BEARER_IPV4;
163 break;
164 case IAGnss::ApnIpType::IPV6:
165 bearerType = AGPS_APN_BEARER_IPV6;
166 break;
167 case IAGnss::ApnIpType::IPV4V6:
168 bearerType = AGPS_APN_BEARER_IPV4V6;
169 break;
170 default:
171 bearerType = AGPS_APN_BEARER_IPV4;
172 break;
173 }
174
175 mGnss->getGnssInterface()->agpsDataConnOpen(
176 LOC_AGPS_TYPE_SUPL, apn.c_str(), apn.size(), (int)bearerType);
177 return true;
178}
179
180Return<bool> AGnss::setServer(V2_0::IAGnssCallback::AGnssType type,
181 const hidl_string& hostname,
182 int32_t port) {
183 if (mGnss == nullptr) {
184 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
185 return false;
186 }
187
188 GnssConfig config;
189 memset(&config, 0, sizeof(GnssConfig));
190 config.size = sizeof(GnssConfig);
191 config.flags = GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT;
192 config.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer);
193 if (type == IAGnssCallback::AGnssType::SUPL) {
194 config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL;
195 } else if (type == IAGnssCallback::AGnssType::C2K) {
196 config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_C2K;
197 } else if (type == IAGnssCallback::AGnssType::SUPL_EIMS) {
198 config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL_EIMS;
199 } else if (type == IAGnssCallback::AGnssType::SUPL_IMS) {
200 config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL_IMS;
201 } else {
202 LOC_LOGE("%s]: invalid AGnssType: %d", __FUNCTION__, static_cast<uint8_t>(type));
203 return false;
204 }
205 config.assistanceServer.hostName = strdup(hostname.c_str());
206 config.assistanceServer.port = port;
207 return mGnss->updateConfiguration(config);
208}
209
210} // namespace implementation
211} // namespace V2_0
212} // namespace gnss
213} // namespace hardware
214} // namespace android