• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2017, 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 #include <gps_extended_c.h>
27 
28 namespace android {
29 namespace hardware {
30 namespace gnss {
31 namespace V1_0 {
32 namespace implementation {
33 
34 sp<IAGnssCallback> AGnss::sAGnssCbIface = nullptr;
35 
AGnss(Gnss * gnss)36 AGnss::AGnss(Gnss* gnss) : mGnss(gnss) {
37 }
38 
agnssStatusIpV4Cb(IAGnssCallback::AGnssStatusIpV4 status)39 void AGnss::agnssStatusIpV4Cb(IAGnssCallback::AGnssStatusIpV4 status){
40 
41     auto r = sAGnssCbIface->agnssStatusIpV4Cb(status);
42     if (!r.isOk()) {
43         LOC_LOGE("Error invoking AGNSS status cb %s", r.description().c_str());
44     }
45 }
46 
setCallback(const sp<IAGnssCallback> & callback)47 Return<void> AGnss::setCallback(const sp<IAGnssCallback>& callback) {
48 
49     if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
50         LOC_LOGE("Null GNSS interface");
51         return Void();
52     }
53 
54     // Save the interface
55     sAGnssCbIface = callback;
56 
57     mGnss->getGnssInterface()->agpsInit((void*)agnssStatusIpV4Cb);
58     return Void();
59 }
60 
dataConnClosed()61 Return<bool> AGnss::dataConnClosed() {
62 
63     if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
64         LOC_LOGE("Null GNSS interface");
65         return false;
66     }
67 
68     mGnss->getGnssInterface()->agpsDataConnClosed(LOC_AGPS_TYPE_SUPL);
69     return true;
70 }
71 
dataConnFailed()72 Return<bool> AGnss::dataConnFailed() {
73 
74     if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
75         LOC_LOGE("Null GNSS interface");
76         return false;
77     }
78 
79     mGnss->getGnssInterface()->agpsDataConnFailed(LOC_AGPS_TYPE_SUPL);
80     return true;
81 }
82 
dataConnOpen(const hidl_string & apn,IAGnss::ApnIpType apnIpType)83 Return<bool> AGnss::dataConnOpen(const hidl_string& apn,
84         IAGnss::ApnIpType apnIpType) {
85 
86     if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
87         LOC_LOGE("Null GNSS interface");
88         return false;
89     }
90 
91     /* Validate */
92     if(apn.empty()){
93         LOC_LOGE("Invalid APN");
94         return false;
95     }
96 
97     LOC_LOGD("dataConnOpen APN name = [%s]", apn.c_str());
98 
99     mGnss->getGnssInterface()->agpsDataConnOpen(
100             LOC_AGPS_TYPE_SUPL, apn.c_str(), apn.size(), (int)apnIpType);
101     return true;
102 }
103 
setServer(IAGnssCallback::AGnssType type,const hidl_string & hostname,int32_t port)104 Return<bool> AGnss::setServer(IAGnssCallback::AGnssType type,
105                               const hidl_string& hostname,
106                               int32_t port) {
107     if (mGnss == nullptr) {
108         LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
109         return false;
110     }
111 
112     GnssConfig config;
113     memset(&config, 0, sizeof(GnssConfig));
114     config.size = sizeof(GnssConfig);
115     config.flags = GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT;
116     config.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer);
117     if (type == IAGnssCallback::AGnssType::TYPE_SUPL) {
118         config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL;
119     } else if (type == IAGnssCallback::AGnssType::TYPE_C2K) {
120         config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_C2K;
121     } else {
122         LOC_LOGE("%s]: invalid AGnssType: %d", __FUNCTION__, static_cast<int>(type));
123         return false;
124     }
125     config.assistanceServer.hostName = strdup(hostname.c_str());
126     config.assistanceServer.port = port;
127     return mGnss->updateConfiguration(config);
128 }
129 
130 }  // namespace implementation
131 }  // namespace V1_0
132 }  // namespace gnss
133 }  // namespace hardware
134 }  // namespace android
135