1 /*
2 * Copyright (C) 2020 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 "GnssConfigurationJni"
19
20 #include "GnssConfiguration.h"
21 #include "Utils.h"
22
23 using android::hardware::gnss::GnssConstellationType;
24 using GnssConstellationType_V1_0 = android::hardware::gnss::V1_0::GnssConstellationType;
25 using GnssConstellationType_V2_0 = android::hardware::gnss::V2_0::GnssConstellationType;
26
27 using android::binder::Status;
28 using android::hardware::hidl_vec;
29 using android::hardware::Return;
30
31 using android::hardware::gnss::IGnssConfiguration;
32 using IGnssConfiguration_V1_0 = android::hardware::gnss::V1_0::IGnssConfiguration;
33 using IGnssConfiguration_V1_1 = android::hardware::gnss::V1_1::IGnssConfiguration;
34 using IGnssConfiguration_V2_0 = android::hardware::gnss::V2_0::IGnssConfiguration;
35 using IGnssConfiguration_V2_1 = android::hardware::gnss::V2_1::IGnssConfiguration;
36
37 using android::hardware::gnss::BlocklistedSource;
38 using BlocklistedSource_V1_1 = IGnssConfiguration_V1_1::BlacklistedSource;
39 using BlocklistedSource_V2_1 = IGnssConfiguration_V2_1::BlacklistedSource;
40
41 namespace {
42
43 jclass class_gnssConfiguration_halInterfaceVersion;
44 jmethodID method_halInterfaceVersionCtor;
45
createHalInterfaceVersionJavaObject(JNIEnv * env,jint major,jint minor)46 jobject createHalInterfaceVersionJavaObject(JNIEnv* env, jint major, jint minor) {
47 return env->NewObject(class_gnssConfiguration_halInterfaceVersion,
48 method_halInterfaceVersionCtor, major, minor);
49 }
50
51 } // anonymous namespace
52
53 namespace android::gnss {
54
GnssConfiguration_class_init_once(JNIEnv * env)55 void GnssConfiguration_class_init_once(JNIEnv* env) {
56 jclass gnssConfiguration_halInterfaceVersionClass = env->FindClass(
57 "com/android/server/location/gnss/GnssConfiguration$HalInterfaceVersion");
58 class_gnssConfiguration_halInterfaceVersion =
59 (jclass)env->NewGlobalRef(gnssConfiguration_halInterfaceVersionClass);
60 method_halInterfaceVersionCtor =
61 env->GetMethodID(class_gnssConfiguration_halInterfaceVersion, "<init>", "(II)V");
62 }
63
64 // Implementation of GnssConfiguration (AIDL HAL)
65
GnssConfiguration(const sp<IGnssConfiguration> & iGnssConfiguration)66 GnssConfiguration::GnssConfiguration(const sp<IGnssConfiguration>& iGnssConfiguration)
67 : mIGnssConfiguration(iGnssConfiguration) {}
68
getVersion(JNIEnv * env)69 jobject GnssConfiguration::getVersion(JNIEnv* env) {
70 return createHalInterfaceVersionJavaObject(env, 3, mIGnssConfiguration->getInterfaceVersion());
71 }
72
setEmergencySuplPdn(jint enable)73 jboolean GnssConfiguration::setEmergencySuplPdn(jint enable) {
74 auto status = mIGnssConfiguration->setEmergencySuplPdn(enable);
75 return checkAidlStatus(status, "IGnssConfiguration setEmergencySuplPdn() failed.");
76 }
77
setSuplVersion(jint version)78 jboolean GnssConfiguration::setSuplVersion(jint version) {
79 auto status = mIGnssConfiguration->setSuplVersion(version);
80 return checkAidlStatus(status, "IGnssConfiguration setSuplVersion() failed.");
81 }
82
setSuplEs(jint enable)83 jboolean GnssConfiguration::setSuplEs(jint enable) {
84 ALOGI("Config parameter SUPL_ES is deprecated in IGnssConfiguration AIDL HAL.");
85 return JNI_FALSE;
86 }
87
setSuplMode(jint mode)88 jboolean GnssConfiguration::setSuplMode(jint mode) {
89 auto status = mIGnssConfiguration->setSuplMode(mode);
90 return checkAidlStatus(status, "IGnssConfiguration setSuplMode() failed.");
91 }
92
setGpsLock(jint gpsLock)93 jboolean GnssConfiguration::setGpsLock(jint gpsLock) {
94 ALOGI("Config parameter GPS_LOCK is not supported in IGnssConfiguration AIDL HAL.");
95 return JNI_FALSE;
96 }
97
setLppProfile(jint lppProfile)98 jboolean GnssConfiguration::setLppProfile(jint lppProfile) {
99 auto status = mIGnssConfiguration->setLppProfile(lppProfile);
100 return checkAidlStatus(status, "IGnssConfiguration setLppProfile() failed.");
101 }
102
setGlonassPositioningProtocol(jint gnssPosProtocol)103 jboolean GnssConfiguration::setGlonassPositioningProtocol(jint gnssPosProtocol) {
104 auto status = mIGnssConfiguration->setGlonassPositioningProtocol(gnssPosProtocol);
105 return checkAidlStatus(status, "IGnssConfiguration setGlonassPositioningProtocol() failed.");
106 }
107
setEsExtensionSec(jint emergencyExtensionSeconds)108 jboolean GnssConfiguration::setEsExtensionSec(jint emergencyExtensionSeconds) {
109 auto status = mIGnssConfiguration->setEsExtensionSec(emergencyExtensionSeconds);
110 return checkAidlStatus(status, "IGnssConfiguration setEsExtensionSec() failed.");
111 }
112
setBlocklist(JNIEnv * env,jintArray & constellations,jintArray & sv_ids)113 jboolean GnssConfiguration::setBlocklist(JNIEnv* env, jintArray& constellations,
114 jintArray& sv_ids) {
115 auto sources =
116 getBlocklistedSources<BlocklistedSource, GnssConstellationType>(env, constellations,
117 sv_ids);
118 auto status = mIGnssConfiguration->setBlocklist(sources);
119 return checkAidlStatus(status, "IGnssConfiguration setBlocklist() failed.");
120 }
121
122 // Implementation of GnssConfiguration_V1_0
123
GnssConfiguration_V1_0(const sp<IGnssConfiguration_V1_0> & iGnssConfiguration)124 GnssConfiguration_V1_0::GnssConfiguration_V1_0(
125 const sp<IGnssConfiguration_V1_0>& iGnssConfiguration)
126 : mIGnssConfiguration_V1_0(iGnssConfiguration) {}
127
getVersion(JNIEnv * env)128 jobject GnssConfiguration_V1_0::getVersion(JNIEnv* env) {
129 return createHalInterfaceVersionJavaObject(env, 1, 0);
130 }
131
setEmergencySuplPdn(jint enable)132 jboolean GnssConfiguration_V1_0::setEmergencySuplPdn(jint enable) {
133 auto result = mIGnssConfiguration_V1_0->setEmergencySuplPdn(enable);
134 return checkHidlReturn(result, "IGnssConfiguration setEmergencySuplPdn() failed.");
135 }
136
setSuplVersion(jint version)137 jboolean GnssConfiguration_V1_0::setSuplVersion(jint version) {
138 auto result = mIGnssConfiguration_V1_0->setSuplVersion(version);
139 return checkHidlReturn(result, "IGnssConfiguration setSuplVersion() failed.");
140 }
141
setSuplEs(jint enable)142 jboolean GnssConfiguration_V1_0::setSuplEs(jint enable) {
143 auto result = mIGnssConfiguration_V1_0->setSuplEs(enable);
144 return checkHidlReturn(result, "IGnssConfiguration setSuplEs() failed.");
145 }
146
setSuplMode(jint mode)147 jboolean GnssConfiguration_V1_0::setSuplMode(jint mode) {
148 auto result = mIGnssConfiguration_V1_0->setSuplMode(mode);
149 return checkHidlReturn(result, "IGnssConfiguration setSuplMode() failed.");
150 }
151
setGpsLock(jint gpsLock)152 jboolean GnssConfiguration_V1_0::setGpsLock(jint gpsLock) {
153 auto result = mIGnssConfiguration_V1_0->setGpsLock(gpsLock);
154 return checkHidlReturn(result, "IGnssConfiguration setGpsLock() failed.");
155 }
156
setLppProfile(jint lppProfile)157 jboolean GnssConfiguration_V1_0::setLppProfile(jint lppProfile) {
158 auto result = mIGnssConfiguration_V1_0->setLppProfile(lppProfile);
159 return checkHidlReturn(result, "IGnssConfiguration setLppProfile() failed.");
160 }
161
setGlonassPositioningProtocol(jint gnssPosProtocol)162 jboolean GnssConfiguration_V1_0::setGlonassPositioningProtocol(jint gnssPosProtocol) {
163 auto result = mIGnssConfiguration_V1_0->setGlonassPositioningProtocol(gnssPosProtocol);
164 return checkHidlReturn(result, "IGnssConfiguration setGlonassPositioningProtocol() failed.");
165 }
166
setEsExtensionSec(jint emergencyExtensionSeconds)167 jboolean GnssConfiguration_V1_0::setEsExtensionSec(jint emergencyExtensionSeconds) {
168 ALOGI("Config parameter ES_EXTENSION_SEC is not supported in IGnssConfiguration.hal"
169 " versions earlier than 2.0.");
170 return JNI_FALSE;
171 }
172
setBlocklist(JNIEnv * env,jintArray & constellations,jintArray & sv_ids)173 jboolean GnssConfiguration_V1_0::setBlocklist(JNIEnv* env, jintArray& constellations,
174 jintArray& sv_ids) {
175 ALOGI("IGnssConfiguration interface does not support satellite blocklist.");
176 return JNI_FALSE;
177 }
178
179 // Implementation of GnssConfiguration_V1_1
180
GnssConfiguration_V1_1(const sp<IGnssConfiguration_V1_1> & iGnssConfiguration)181 GnssConfiguration_V1_1::GnssConfiguration_V1_1(
182 const sp<IGnssConfiguration_V1_1>& iGnssConfiguration)
183 : GnssConfiguration_V1_0{iGnssConfiguration}, mIGnssConfiguration_V1_1(iGnssConfiguration) {}
184
getVersion(JNIEnv * env)185 jobject GnssConfiguration_V1_1::getVersion(JNIEnv* env) {
186 return createHalInterfaceVersionJavaObject(env, 1, 1);
187 }
188
setBlocklist(JNIEnv * env,jintArray & constellations,jintArray & sv_ids)189 jboolean GnssConfiguration_V1_1::setBlocklist(JNIEnv* env, jintArray& constellations,
190 jintArray& sv_ids) {
191 auto sources = getBlocklistedSources<BlocklistedSource_V1_1,
192 GnssConstellationType_V1_0>(env, constellations, sv_ids);
193 auto result = mIGnssConfiguration_V1_1->setBlacklist(sources);
194 return checkHidlReturn(result, "IGnssConfiguration setBlocklist() failed.");
195 }
196
197 // Implementation of GnssConfiguration_V2_0
198
GnssConfiguration_V2_0(const sp<IGnssConfiguration_V2_0> & iGnssConfiguration)199 GnssConfiguration_V2_0::GnssConfiguration_V2_0(
200 const sp<IGnssConfiguration_V2_0>& iGnssConfiguration)
201 : GnssConfiguration_V1_1{iGnssConfiguration}, mIGnssConfiguration_V2_0(iGnssConfiguration) {}
202
getVersion(JNIEnv * env)203 jobject GnssConfiguration_V2_0::getVersion(JNIEnv* env) {
204 return createHalInterfaceVersionJavaObject(env, 2, 0);
205 }
206
setSuplEs(jint enable)207 jboolean GnssConfiguration_V2_0::setSuplEs(jint enable) {
208 ALOGI("Config parameter SUPL_ES is deprecated in IGnssConfiguration.hal version 2.0 and "
209 "higher.");
210 return JNI_FALSE;
211 }
212
setGpsLock(jint enable)213 jboolean GnssConfiguration_V2_0::setGpsLock(jint enable) {
214 ALOGI("Config parameter GPS_LOCK is deprecated in IGnssConfiguration.hal version 2.0 and "
215 "higher.");
216 return JNI_FALSE;
217 }
218
setEsExtensionSec(jint emergencyExtensionSeconds)219 jboolean GnssConfiguration_V2_0::setEsExtensionSec(jint emergencyExtensionSeconds) {
220 auto result = mIGnssConfiguration_V2_0->setEsExtensionSec(emergencyExtensionSeconds);
221 return checkHidlReturn(result, "IGnssConfiguration setEsExtensionSec() failed.");
222 }
223
224 // Implementation of GnssConfiguration_V2_1
225
GnssConfiguration_V2_1(const sp<IGnssConfiguration_V2_1> & iGnssConfiguration)226 GnssConfiguration_V2_1::GnssConfiguration_V2_1(
227 const sp<IGnssConfiguration_V2_1>& iGnssConfiguration)
228 : GnssConfiguration_V2_0{iGnssConfiguration}, mIGnssConfiguration_V2_1(iGnssConfiguration) {}
229
getVersion(JNIEnv * env)230 jobject GnssConfiguration_V2_1::getVersion(JNIEnv* env) {
231 return createHalInterfaceVersionJavaObject(env, 2, 1);
232 }
233
setBlocklist(JNIEnv * env,jintArray & constellations,jintArray & sv_ids)234 jboolean GnssConfiguration_V2_1::setBlocklist(JNIEnv* env, jintArray& constellations,
235 jintArray& sv_ids) {
236 auto sources = getBlocklistedSources<BlocklistedSource_V2_1,
237 GnssConstellationType_V2_0>(env, constellations, sv_ids);
238 auto result = mIGnssConfiguration_V2_1->setBlacklist_2_1(sources);
239 return checkHidlReturn(result, "IGnssConfiguration setBlocklist() failed.");
240 }
241
242 } // namespace android::gnss
243