• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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_GNSS_H
18 #define _ANDROID_SERVER_GNSS_GNSS_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/IGnss.h>
27 #include <android/hardware/gnss/1.1/IGnss.h>
28 #include <android/hardware/gnss/2.0/IGnss.h>
29 #include <android/hardware/gnss/2.1/IGnss.h>
30 #include <android/hardware/gnss/BnGnss.h>
31 #include <binder/IBinder.h>
32 #include <log/log.h>
33 
34 #include "AGnss.h"
35 #include "AGnssRil.h"
36 #include "GnssAntennaInfo.h"
37 #include "GnssBatching.h"
38 #include "GnssCallback.h"
39 #include "GnssConfiguration.h"
40 #include "GnssDebug.h"
41 #include "GnssGeofence.h"
42 #include "GnssMeasurement.h"
43 #include "GnssNavigationMessage.h"
44 #include "GnssPsds.h"
45 #include "GnssVisibilityControl.h"
46 #include "MeasurementCorrections.h"
47 #include "jni.h"
48 
49 namespace android::gnss {
50 
51 struct GnssDeathRecipient : virtual public hardware::hidl_death_recipient {
52     // hidl_death_recipient interface
serviceDiedGnssDeathRecipient53     virtual void serviceDied(uint64_t cookie, const wp<hidl::base::V1_0::IBase>& who) override {
54         ALOGE("GNSS HIDL service failed, trying to recover...");
55         onServiceDied();
56     }
57 
onServiceDiedGnssDeathRecipient58     static void onServiceDied() {
59         JNIEnv* env = android::AndroidRuntime::getJNIEnv();
60         env->CallVoidMethod(android::mCallbacksObj, method_reportGnssServiceDied);
61     }
62 };
63 
64 struct GnssDeathRecipientAidl : virtual public IBinder::DeathRecipient {
65     // IBinder::DeathRecipient implementation
binderDiedGnssDeathRecipientAidl66     virtual void binderDied(const wp<IBinder>& who) override {
67         ALOGE("GNSS AIDL service failed, trying to recover...");
68         GnssDeathRecipient::onServiceDied();
69     }
70 };
71 
72 class GnssHal {
73 public:
74     GnssHal();
~GnssHal()75     ~GnssHal() {}
76 
77     jboolean isSupported();
78     jboolean setCallback();
79     jboolean start();
80     jboolean stop();
81     jboolean setPositionMode(jint mode, jint recurrence, jint min_interval, jint preferred_accuracy,
82                              jint preferred_time, jboolean low_power_mode);
83     jboolean startSvStatus();
84     jboolean stopSvStatus();
85     jboolean startNmea();
86     jboolean stopNmea();
87     jint readNmea(jbyteArray& nmeaArray, jint& buffer_size);
88     void linkToDeath();
89     void close();
90     void deleteAidingData(jint flags);
91     void injectTime(jlong time, jlong timeReference, jint uncertainty);
92     void injectLocation(jint gnssLocationFlags, jdouble latitudeDegrees, jdouble longitudeDegrees,
93                         jdouble altitudeMeters, jfloat speedMetersPerSec, jfloat bearingDegrees,
94                         jfloat horizontalAccuracyMeters, jfloat verticalAccuracyMeters,
95                         jfloat speedAccuracyMetersPerSecond, jfloat bearingAccuracyDegrees,
96                         jlong timestamp, jint elapsedRealtimeFlags, jlong elapsedRealtimeNanos,
97                         jdouble elapsedRealtimeUncertaintyNanos);
98     void injectBestLocation(jint gnssLocationFlags, jdouble latitudeDegrees,
99                             jdouble longitudeDegrees, jdouble altitudeMeters,
100                             jfloat speedMetersPerSec, jfloat bearingDegrees,
101                             jfloat horizontalAccuracyMeters, jfloat verticalAccuracyMeters,
102                             jfloat speedAccuracyMetersPerSecond, jfloat bearingAccuracyDegrees,
103                             jlong timestamp, jint elapsedRealtimeFlags, jlong elapsedRealtimeNanos,
104                             jdouble elapsedRealtimeUncertaintyNanos);
105 
106     std::unique_ptr<AGnssInterface> getAGnssInterface();
107     std::unique_ptr<AGnssRilInterface> getAGnssRilInterface();
108     std::unique_ptr<GnssNavigationMessageInterface> getGnssNavigationMessageInterface();
109     std::unique_ptr<GnssMeasurementInterface> getGnssMeasurementInterface();
110     std::unique_ptr<GnssDebugInterface> getGnssDebugInterface();
111     std::unique_ptr<GnssConfigurationInterface> getGnssConfigurationInterface();
112     std::unique_ptr<GnssGeofenceInterface> getGnssGeofenceInterface();
113     std::unique_ptr<GnssBatchingInterface> getGnssBatchingInterface();
114     std::unique_ptr<MeasurementCorrectionsInterface> getMeasurementCorrectionsInterface();
115     std::unique_ptr<GnssVisibilityControlInterface> getGnssVisibilityControlInterface();
116     std::unique_ptr<GnssAntennaInfoInterface> getGnssAntennaInfoInterface();
117     std::unique_ptr<GnssPsdsInterface> getGnssPsdsInterface();
118 
119     sp<hardware::gnss::IGnssPowerIndication> getGnssPowerIndicationInterface();
120     sp<hardware::gnss::V1_0::IGnssNi> getGnssNiInterface();
121 
122 private:
123     sp<GnssDeathRecipient> gnssHalDeathRecipient = nullptr;
124     sp<GnssDeathRecipientAidl> gnssHalDeathRecipientAidl = nullptr;
125     sp<hardware::gnss::V1_0::IGnss> gnssHal = nullptr;
126     sp<hardware::gnss::V1_1::IGnss> gnssHal_V1_1 = nullptr;
127     sp<hardware::gnss::V2_0::IGnss> gnssHal_V2_0 = nullptr;
128     sp<hardware::gnss::V2_1::IGnss> gnssHal_V2_1 = nullptr;
129     sp<hardware::gnss::IGnss> gnssHalAidl = nullptr;
130 };
131 
132 } // namespace android::gnss
133 
134 #endif // _ANDROID_SERVER_GNSS_Gnss_H
135