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