• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 before <log/log.h> to overwrite the default value.
18 #define LOG_TAG "AGnssJni"
19 
20 #include "AGnss.h"
21 
22 #include "Utils.h"
23 
24 using android::hardware::gnss::IAGnss;
25 using IAGnss_V1_0 = android::hardware::gnss::V1_0::IAGnss;
26 using IAGnss_V2_0 = android::hardware::gnss::V2_0::IAGnss;
27 using IAGnssCallback_V1_0 = android::hardware::gnss::V1_0::IAGnssCallback;
28 using IAGnssCallback_V2_0 = android::hardware::gnss::V2_0::IAGnssCallback;
29 using AGnssType = android::hardware::gnss::IAGnssCallback::AGnssType;
30 
31 namespace android::gnss {
32 
33 // Implementation of AGnss (AIDL HAL)
34 
AGnss(const sp<IAGnss> & iAGnss)35 AGnss::AGnss(const sp<IAGnss>& iAGnss) : mIAGnss(iAGnss) {
36     assert(mIAGnss != nullptr);
37 }
38 
setCallback(const std::unique_ptr<AGnssCallback> & callback)39 jboolean AGnss::setCallback(const std::unique_ptr<AGnssCallback>& callback) {
40     auto status = mIAGnss->setCallback(callback->getAidl());
41     return checkAidlStatus(status, "IAGnssAidl setCallback() failed.");
42 }
43 
dataConnOpen(JNIEnv * env,jlong networkHandle,jstring apn,jint apnIpType)44 jboolean AGnss::dataConnOpen(JNIEnv* env, jlong networkHandle, jstring apn, jint apnIpType) {
45     ScopedJniString jniApn{env, apn};
46     auto status = mIAGnss->dataConnOpen(networkHandle, std::string(jniApn.c_str()),
47                                         static_cast<IAGnss::ApnIpType>(apnIpType));
48     return checkAidlStatus(status,
49                            "IAGnssAidl dataConnOpen() failed. APN and its IP type not set.");
50 }
51 
dataConnClosed()52 jboolean AGnss::dataConnClosed() {
53     auto status = mIAGnss->dataConnClosed();
54     return checkAidlStatus(status, "IAGnssAidl dataConnClosed() failed.");
55 }
56 
dataConnFailed()57 jboolean AGnss::dataConnFailed() {
58     auto status = mIAGnss->dataConnFailed();
59     return checkAidlStatus(status, "IAGnssAidl dataConnFailed() failed.");
60 }
61 
setServer(JNIEnv * env,jint type,jstring hostname,jint port)62 jboolean AGnss::setServer(JNIEnv* env, jint type, jstring hostname, jint port) {
63     ScopedJniString jniHostName{env, hostname};
64     auto status = mIAGnss->setServer(static_cast<AGnssType>(type), std::string(jniHostName.c_str()),
65                                      port);
66     return checkAidlStatus(status, "IAGnssAidl setServer() failed. Host name and port not set.");
67 }
68 
69 // Implementation of AGnss_V1_0
70 
AGnss_V1_0(const sp<IAGnss_V1_0> & iAGnss)71 AGnss_V1_0::AGnss_V1_0(const sp<IAGnss_V1_0>& iAGnss) : mIAGnss_V1_0(iAGnss) {
72     assert(mIAGnss_V1_0 != nullptr);
73 }
74 
setCallback(const std::unique_ptr<AGnssCallback> & callback)75 jboolean AGnss_V1_0::setCallback(const std::unique_ptr<AGnssCallback>& callback) {
76     auto result = mIAGnss_V1_0->setCallback(callback->getV1_0());
77     return checkHidlReturn(result, "IAGnss_V1_0 setCallback() failed.");
78 }
79 
dataConnOpen(JNIEnv * env,jlong,jstring apn,jint apnIpType)80 jboolean AGnss_V1_0::dataConnOpen(JNIEnv* env, jlong, jstring apn, jint apnIpType) {
81     ScopedJniString jniApn{env, apn};
82     auto result =
83             mIAGnss_V1_0->dataConnOpen(jniApn, static_cast<IAGnss_V1_0::ApnIpType>(apnIpType));
84     return checkHidlReturn(result,
85                            "IAGnss_V1_0 dataConnOpen() failed. APN and its IP type not set.");
86 }
87 
dataConnClosed()88 jboolean AGnss_V1_0::dataConnClosed() {
89     auto result = mIAGnss_V1_0->dataConnClosed();
90     return checkHidlReturn(result, "IAGnss_V1_0 dataConnClosed() failed.");
91 }
92 
dataConnFailed()93 jboolean AGnss_V1_0::dataConnFailed() {
94     auto result = mIAGnss_V1_0->dataConnFailed();
95     return checkHidlReturn(result, "IAGnss_V1_0 dataConnFailed() failed.");
96 }
97 
setServer(JNIEnv * env,jint type,jstring hostname,jint port)98 jboolean AGnss_V1_0::setServer(JNIEnv* env, jint type, jstring hostname, jint port) {
99     ScopedJniString jniHostName{env, hostname};
100     auto result = mIAGnss_V1_0->setServer(static_cast<IAGnssCallback_V1_0::AGnssType>(type),
101                                           jniHostName, port);
102     return checkHidlReturn(result, "IAGnss_V1_0 setServer() failed. Host name and port not set.");
103 }
104 
105 // Implementation of AGnss_V2_0
106 
AGnss_V2_0(const sp<IAGnss_V2_0> & iAGnss)107 AGnss_V2_0::AGnss_V2_0(const sp<IAGnss_V2_0>& iAGnss) : mIAGnss_V2_0(iAGnss) {
108     assert(mIAGnss_V2_0 != nullptr);
109 }
110 
setCallback(const std::unique_ptr<AGnssCallback> & callback)111 jboolean AGnss_V2_0::setCallback(const std::unique_ptr<AGnssCallback>& callback) {
112     auto result = mIAGnss_V2_0->setCallback(callback->getV2_0());
113     return checkHidlReturn(result, "IAGnss_V2_0 setCallback() failed.");
114 }
115 
dataConnOpen(JNIEnv * env,jlong networkHandle,jstring apn,jint apnIpType)116 jboolean AGnss_V2_0::dataConnOpen(JNIEnv* env, jlong networkHandle, jstring apn, jint apnIpType) {
117     ScopedJniString jniApn{env, apn};
118     auto result = mIAGnss_V2_0->dataConnOpen(static_cast<uint64_t>(networkHandle), jniApn,
119                                              static_cast<IAGnss_V2_0::ApnIpType>(apnIpType));
120     return checkHidlReturn(result,
121                            "IAGnss_V2_0 dataConnOpen() failed. APN and its IP type not set.");
122 }
123 
dataConnClosed()124 jboolean AGnss_V2_0::dataConnClosed() {
125     auto result = mIAGnss_V2_0->dataConnClosed();
126     return checkHidlReturn(result, "IAGnss_V2_0 dataConnClosed() failed.");
127 }
128 
dataConnFailed()129 jboolean AGnss_V2_0::dataConnFailed() {
130     auto result = mIAGnss_V2_0->dataConnFailed();
131     return checkHidlReturn(result, "IAGnss_V2_0 dataConnFailed() failed.");
132 }
133 
setServer(JNIEnv * env,jint type,jstring hostname,jint port)134 jboolean AGnss_V2_0::setServer(JNIEnv* env, jint type, jstring hostname, jint port) {
135     ScopedJniString jniHostName{env, hostname};
136     auto result = mIAGnss_V2_0->setServer(static_cast<IAGnssCallback_V2_0::AGnssType>(type),
137                                           jniHostName, port);
138     return checkHidlReturn(result, "IAGnss_V2_0 setServer() failed. Host name and port not set.");
139 }
140 
141 } // namespace android::gnss
142