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 #ifndef _ANDROID_SERVER_GNSS_GNSSANTENNAINFOCALLBACK_H 18 #define _ANDROID_SERVER_GNSS_GNSSANTENNAINFOCALLBACK_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/2.1/IGnssAntennaInfo.h> 27 #include <android/hardware/gnss/BnGnssAntennaInfoCallback.h> 28 #include <log/log.h> 29 30 #include "Utils.h" 31 #include "jni.h" 32 33 namespace android::gnss { 34 35 void GnssAntennaInfo_class_init_once(JNIEnv* env, jclass& clazz); 36 37 /* 38 * GnssAntennaInfoCallbackAidl implements the callback methods required for the 39 * android::hardware::gnss::IGnssAntennaInfo interface. 40 */ 41 class GnssAntennaInfoCallbackAidl : public android::hardware::gnss::BnGnssAntennaInfoCallback { 42 public: 43 binder::Status gnssAntennaInfoCb(const std::vector<GnssAntennaInfo>& gnssAntennaInfos) override; 44 }; 45 46 /* 47 * GnssAntennaInfoCallback implements the callback methods required for the 48 * V2_1::GnssAntennaInfo interface. 49 */ 50 class GnssAntennaInfoCallback_V2_1 51 : public android::hardware::gnss::V2_1::IGnssAntennaInfoCallback { 52 public: 53 // Methods from V2_1::GnssAntennaInfoCallback follow. 54 hardware::Return<void> gnssAntennaInfoCb( 55 const hardware::hidl_vec< 56 android::hardware::gnss::V2_1::IGnssAntennaInfoCallback::GnssAntennaInfo>& 57 gnssAntennaInfos) override; 58 }; 59 60 class GnssAntennaInfoCallback { 61 public: GnssAntennaInfoCallback()62 GnssAntennaInfoCallback() {} getAidl()63 sp<GnssAntennaInfoCallbackAidl> getAidl() { 64 if (callbackAidl == nullptr) { 65 callbackAidl = sp<GnssAntennaInfoCallbackAidl>::make(); 66 } 67 return callbackAidl; 68 } 69 getV2_1()70 sp<GnssAntennaInfoCallback_V2_1> getV2_1() { 71 if (callbackV2_1 == nullptr) { 72 callbackV2_1 = sp<GnssAntennaInfoCallback_V2_1>::make(); 73 } 74 return callbackV2_1; 75 } 76 77 private: 78 sp<GnssAntennaInfoCallbackAidl> callbackAidl; 79 sp<GnssAntennaInfoCallback_V2_1> callbackV2_1; 80 }; 81 82 struct GnssAntennaInfoCallbackUtil { 83 template <template <class...> class T_vector, class T_info> 84 static jobject translateAllGnssAntennaInfos(JNIEnv* env, 85 const T_vector<T_info>& gnssAntennaInfos); 86 87 template <class T> 88 static jobject translateSingleGnssAntennaInfo(JNIEnv* env, const T& gnssAntennaInfo); 89 90 template <class T> 91 static jobject translatePhaseCenterOffset(JNIEnv* env, const T& gnssAntennaInfo); 92 93 template <class T> 94 static jobject translatePhaseCenterVariationCorrections(JNIEnv* env, const T& gnssAntennaInfo); 95 96 template <class T> 97 static jobject translateSignalGainCorrections(JNIEnv* env, const T& gnssAntennaInfo); 98 99 template <template <class...> class T_vector, class T_info> 100 static jobjectArray translate2dDoubleArray(JNIEnv* env, const T_vector<T_info>& array); 101 102 template <template <class...> class T_vector, class T_info> 103 static void translateAndReportGnssAntennaInfo(const T_vector<T_info>& gnssAntennaInfos); 104 105 static void reportAntennaInfo(JNIEnv* env, const jobject antennaInfosArray); 106 getCarrierFrequencyMHzGnssAntennaInfoCallbackUtil107 static double getCarrierFrequencyMHz( 108 const android::hardware::gnss::IGnssAntennaInfoCallback::GnssAntennaInfo& 109 gnssAntennaInfo) { 110 return gnssAntennaInfo.carrierFrequencyHz * 1e-6; 111 }; 112 getCarrierFrequencyMHzGnssAntennaInfoCallbackUtil113 static double getCarrierFrequencyMHz( 114 const android::hardware::gnss::V2_1::IGnssAntennaInfoCallback::GnssAntennaInfo& 115 gnssAntennaInfo) { 116 return gnssAntennaInfo.carrierFrequencyMHz; 117 }; 118 }; 119 120 } // namespace android::gnss 121 122 #endif // _ANDROID_SERVER_GNSS_GNSSANTENNAINFOCALLBACK_H 123