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_MEASUREMENTCORRECTIONSCALLBACK_H 18 #define _ANDROID_SERVER_GNSS_MEASUREMENTCORRECTIONSCALLBACK_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/measurement_corrections/1.0/IMeasurementCorrections.h> 27 #include <android/hardware/gnss/measurement_corrections/1.1/IMeasurementCorrections.h> 28 #include <android/hardware/gnss/measurement_corrections/BnMeasurementCorrectionsCallback.h> 29 #include <log/log.h> 30 31 #include "Utils.h" 32 #include "jni.h" 33 34 namespace android::gnss { 35 36 namespace { 37 extern jmethodID method_setSubHalMeasurementCorrectionsCapabilities; 38 } 39 40 void MeasurementCorrectionsCallback_class_init_once(JNIEnv* env, jclass clazz); 41 42 /* 43 * MeasurementCorrectionsCallbackAidl class implements the callback methods required by the 44 * android::hardware::gnss::measurement_corrections::IMeasurementCorrectionsCallback interface. 45 */ 46 class MeasurementCorrectionsCallbackAidl 47 : public hardware::gnss::measurement_corrections::BnMeasurementCorrectionsCallback { 48 public: MeasurementCorrectionsCallbackAidl()49 MeasurementCorrectionsCallbackAidl() {} 50 binder::Status setCapabilitiesCb(const int capabilities) override; 51 }; 52 53 /* 54 * MeasurementCorrectionsCallbackHidl implements callback methods of 55 * IMeasurementCorrectionsCallback.hal interface. 56 */ 57 class MeasurementCorrectionsCallbackHidl : public android::hardware::gnss::measurement_corrections:: 58 V1_0::IMeasurementCorrectionsCallback { 59 public: MeasurementCorrectionsCallbackHidl()60 MeasurementCorrectionsCallbackHidl() {} 61 hardware::Return<void> setCapabilitiesCb(uint32_t capabilities) override; 62 }; 63 64 class MeasurementCorrectionsCallback { 65 public: MeasurementCorrectionsCallback()66 MeasurementCorrectionsCallback() {} getAidl()67 sp<MeasurementCorrectionsCallbackAidl> getAidl() { 68 if (callbackAidl == nullptr) { 69 callbackAidl = sp<MeasurementCorrectionsCallbackAidl>::make(); 70 } 71 return callbackAidl; 72 } 73 getHidl()74 sp<MeasurementCorrectionsCallbackHidl> getHidl() { 75 if (callbackHidl == nullptr) { 76 callbackHidl = sp<MeasurementCorrectionsCallbackHidl>::make(); 77 } 78 return callbackHidl; 79 } 80 81 private: 82 sp<MeasurementCorrectionsCallbackAidl> callbackAidl; 83 sp<MeasurementCorrectionsCallbackHidl> callbackHidl; 84 }; 85 86 struct MeasurementCorrectionsCallbackUtil { 87 static void setCapabilitiesCb(uint32_t capabilities); 88 89 private: 90 MeasurementCorrectionsCallbackUtil() = delete; 91 }; 92 93 } // namespace android::gnss 94 95 #endif // _ANDROID_SERVER_GNSS_MEASUREMENTCORRECTIONSCALLBACK_H 96