• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef _ANDROID_SERVER_GNSS_GNSSCONFIGURATION_H
18 #define _ANDROID_SERVER_GNSS_GNSSCONFIGURATION_H
19 
20 #pragma once
21 
22 #ifndef LOG_TAG
23 #error LOG_TAG must be defined before including this file.
24 #endif
25 
26 #include <android/hardware/gnss/1.0/IGnssConfiguration.h>
27 #include <android/hardware/gnss/1.1/IGnssConfiguration.h>
28 #include <android/hardware/gnss/2.0/IGnssConfiguration.h>
29 #include <android/hardware/gnss/2.1/IGnssConfiguration.h>
30 #include <android/hardware/gnss/BnGnssConfiguration.h>
31 #include <log/log.h>
32 
33 #include "jni.h"
34 
35 namespace android::gnss {
36 
37 void GnssConfiguration_class_init_once(JNIEnv* env);
38 
39 class GnssConfigurationInterface {
40 public:
~GnssConfigurationInterface()41     virtual ~GnssConfigurationInterface() {}
42     virtual jobject getVersion(JNIEnv* env) = 0;
43     virtual jboolean setEmergencySuplPdn(jint enable) = 0;
44     virtual jboolean setSuplVersion(jint version) = 0;
45     virtual jboolean setSuplEs(jint enable) = 0;
46     virtual jboolean setSuplMode(jint mode) = 0;
47     virtual jboolean setGpsLock(jint gpsLock) = 0;
48     virtual jboolean setLppProfile(jint lppProfile) = 0;
49     virtual jboolean setGlonassPositioningProtocol(jint gnssPosProtocol) = 0;
50     virtual jboolean setEsExtensionSec(jint emergencyExtensionSeconds) = 0;
51     virtual jboolean setBlocklist(JNIEnv* env, jintArray& constellations, jintArray& sv_ids) = 0;
52 
53 protected:
54     template <class T_BlocklistSource, class T_ConstellationType>
getBlocklistedSources(JNIEnv * env,jintArray & constellations,jintArray & sv_ids)55     hardware::hidl_vec<T_BlocklistSource> getBlocklistedSources(JNIEnv* env,
56                                                                 jintArray& constellations,
57                                                                 jintArray& sv_ids) {
58         jint* constellation_array = env->GetIntArrayElements(constellations, 0);
59         if (nullptr == constellation_array) {
60             ALOGI("GetIntArrayElements returns nullptr.");
61             return JNI_FALSE;
62         }
63 
64         jsize length = env->GetArrayLength(constellations);
65 
66         jint* sv_id_array = env->GetIntArrayElements(sv_ids, 0);
67         if (nullptr == sv_id_array) {
68             ALOGI("GetIntArrayElements returns nullptr.");
69             return JNI_FALSE;
70         }
71 
72         if (length != env->GetArrayLength(sv_ids)) {
73             ALOGI("Lengths of constellations and sv_ids are inconsistent.");
74             return JNI_FALSE;
75         }
76 
77         hardware::hidl_vec<T_BlocklistSource> sources;
78         sources.resize(length);
79 
80         for (int i = 0; i < length; i++) {
81             sources[i].constellation = static_cast<T_ConstellationType>(constellation_array[i]);
82             sources[i].svid = sv_id_array[i];
83         }
84 
85         env->ReleaseIntArrayElements(constellations, constellation_array, 0);
86         env->ReleaseIntArrayElements(sv_ids, sv_id_array, 0);
87 
88         return sources;
89     }
90 };
91 
92 class GnssConfiguration : public GnssConfigurationInterface {
93 public:
94     GnssConfiguration(const sp<android::hardware::gnss::IGnssConfiguration>& iGnssConfiguration);
95     jobject getVersion(JNIEnv* env) override;
96     jboolean setEmergencySuplPdn(jint enable) override;
97     jboolean setSuplVersion(jint version) override;
98     jboolean setSuplEs(jint enable) override;
99     jboolean setSuplMode(jint mode) override;
100     jboolean setGpsLock(jint gpsLock) override;
101     jboolean setLppProfile(jint lppProfile) override;
102     jboolean setGlonassPositioningProtocol(jint gnssPosProtocol) override;
103     jboolean setEsExtensionSec(jint emergencyExtensionSeconds) override;
104     jboolean setBlocklist(JNIEnv* env, jintArray& constellations, jintArray& sv_ids) override;
105 
106 private:
107     const sp<android::hardware::gnss::IGnssConfiguration> mIGnssConfiguration;
108 };
109 
110 class GnssConfiguration_V1_0 : public GnssConfigurationInterface {
111 public:
112     GnssConfiguration_V1_0(
113             const sp<android::hardware::gnss::V1_0::IGnssConfiguration>& iGnssConfiguration);
114     jobject getVersion(JNIEnv* env) override;
115     jboolean setEmergencySuplPdn(jint enable);
116     jboolean setSuplVersion(jint version) override;
117     jboolean setSuplEs(jint enable) override;
118     jboolean setSuplMode(jint mode) override;
119     jboolean setGpsLock(jint gpsLock) override;
120     jboolean setLppProfile(jint lppProfile);
121     jboolean setGlonassPositioningProtocol(jint gnssPosProtocol) override;
122     jboolean setEsExtensionSec(jint emergencyExtensionSeconds) override;
123     jboolean setBlocklist(JNIEnv* env, jintArray& constellations, jintArray& sv_ids) override;
124 
125 private:
126     const sp<android::hardware::gnss::V1_0::IGnssConfiguration> mIGnssConfiguration_V1_0;
127 };
128 
129 class GnssConfiguration_V1_1 : public GnssConfiguration_V1_0 {
130 public:
131     GnssConfiguration_V1_1(
132             const sp<android::hardware::gnss::V1_1::IGnssConfiguration>& iGnssConfiguration);
133 
134     jobject getVersion(JNIEnv* env) override;
135 
136     jboolean setBlocklist(JNIEnv* env, jintArray& constellations, jintArray& sv_ids) override;
137 
138 private:
139     const sp<android::hardware::gnss::V1_1::IGnssConfiguration> mIGnssConfiguration_V1_1;
140 };
141 
142 class GnssConfiguration_V2_0 : public GnssConfiguration_V1_1 {
143 public:
144     GnssConfiguration_V2_0(
145             const sp<android::hardware::gnss::V2_0::IGnssConfiguration>& iGnssConfiguration);
146     jobject getVersion(JNIEnv* env) override;
147     jboolean setSuplEs(jint enable) override;
148     jboolean setGpsLock(jint enable) override;
149     jboolean setEsExtensionSec(jint emergencyExtensionSeconds) override;
150 
151 private:
152     const sp<android::hardware::gnss::V2_0::IGnssConfiguration> mIGnssConfiguration_V2_0;
153 };
154 
155 class GnssConfiguration_V2_1 : public GnssConfiguration_V2_0 {
156 public:
157     GnssConfiguration_V2_1(
158             const sp<android::hardware::gnss::V2_1::IGnssConfiguration>& iGnssConfiguration);
159     jobject getVersion(JNIEnv* env) override;
160     jboolean setBlocklist(JNIEnv* env, jintArray& constellations, jintArray& sv_ids) override;
161 
162 private:
163     const sp<android::hardware::gnss::V2_1::IGnssConfiguration> mIGnssConfiguration_V2_1;
164 };
165 
166 } // namespace android::gnss
167 
168 #endif // _ANDROID_SERVER_GNSS_GNSSCONFIGURATION_H
169