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