Merge "DO NOT MERGE: Call DeleteLocalRef on callObjectMethod's returned value" into sc-v2-dev

This commit is contained in:
TreeHugger Robot
2022-02-03 23:45:25 +00:00
committed by Android (Google) Code Review
4 changed files with 51 additions and 35 deletions

View File

@@ -1115,15 +1115,16 @@ jobject GnssAntennaInfoCallback::translateSingleGnssAntennaInfo(
env->NewObject(class_gnssAntennaInfoBuilder, method_gnssAntennaInfoBuilderCtor); env->NewObject(class_gnssAntennaInfoBuilder, method_gnssAntennaInfoBuilderCtor);
// Set fields // Set fields
env->CallObjectMethod(gnssAntennaInfoBuilderObject, callObjectMethodIgnoringResult(env, gnssAntennaInfoBuilderObject,
method_gnssAntennaInfoBuilderSetCarrierFrequencyMHz, method_gnssAntennaInfoBuilderSetCarrierFrequencyMHz,
gnssAntennaInfo.carrierFrequencyMHz); gnssAntennaInfo.carrierFrequencyMHz);
env->CallObjectMethod(gnssAntennaInfoBuilderObject, callObjectMethodIgnoringResult(env, gnssAntennaInfoBuilderObject,
method_gnssAntennaInfoBuilderSetPhaseCenterOffset, phaseCenterOffset); method_gnssAntennaInfoBuilderSetPhaseCenterOffset,
env->CallObjectMethod(gnssAntennaInfoBuilderObject, phaseCenterOffset);
callObjectMethodIgnoringResult(env, gnssAntennaInfoBuilderObject,
method_gnssAntennaInfoBuilderSetPhaseCenterVariationCorrections, method_gnssAntennaInfoBuilderSetPhaseCenterVariationCorrections,
phaseCenterVariationCorrections); phaseCenterVariationCorrections);
env->CallObjectMethod(gnssAntennaInfoBuilderObject, callObjectMethodIgnoringResult(env, gnssAntennaInfoBuilderObject,
method_gnssAntennaInfoBuilderSetSignalGainCorrections, method_gnssAntennaInfoBuilderSetSignalGainCorrections,
signalGainCorrections); signalGainCorrections);
@@ -2707,7 +2708,7 @@ static SingleSatCorrection_V1_0 getSingleSatCorrection_1_0_withoutConstellation(
jfloat eplMeters = env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEpl); jfloat eplMeters = env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEpl);
jfloat eplUncMeters = env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEplUnc); jfloat eplUncMeters = env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEplUnc);
uint16_t corrFlags = static_cast<uint16_t>(correctionFlags); uint16_t corrFlags = static_cast<uint16_t>(correctionFlags);
jobject reflectingPlaneObj; jobject reflectingPlaneObj = nullptr;
bool has_ref_plane = (corrFlags & GnssSingleSatCorrectionFlags::HAS_REFLECTING_PLANE) != 0; bool has_ref_plane = (corrFlags & GnssSingleSatCorrectionFlags::HAS_REFLECTING_PLANE) != 0;
if (has_ref_plane) { if (has_ref_plane) {
reflectingPlaneObj = reflectingPlaneObj =
@@ -2731,6 +2732,7 @@ static SingleSatCorrection_V1_0 getSingleSatCorrection_1_0_withoutConstellation(
.azimuthDegrees = azimuthDegreeRefPlane, .azimuthDegrees = azimuthDegreeRefPlane,
}; };
} }
env->DeleteLocalRef(reflectingPlaneObj);
SingleSatCorrection_V1_0 singleSatCorrection = { SingleSatCorrection_V1_0 singleSatCorrection = {
.singleSatCorrectionFlags = corrFlags, .singleSatCorrectionFlags = corrFlags,
@@ -2762,6 +2764,7 @@ static void getSingleSatCorrectionList_1_1(JNIEnv* env, jobject singleSatCorrect
}; };
list[i] = singleSatCorrection_1_1; list[i] = singleSatCorrection_1_1;
env->DeleteLocalRef(singleSatCorrectionObj);
} }
} }
@@ -2779,6 +2782,7 @@ static void getSingleSatCorrectionList_1_0(JNIEnv* env, jobject singleSatCorrect
singleSatCorrection.constellation = static_cast<GnssConstellationType_V1_0>(constType), singleSatCorrection.constellation = static_cast<GnssConstellationType_V1_0>(constType),
list[i] = singleSatCorrection; list[i] = singleSatCorrection;
env->DeleteLocalRef(singleSatCorrectionObj);
} }
} }
@@ -2849,6 +2853,7 @@ static jboolean android_location_gnss_hal_GnssNative_inject_measurement_correcti
hidl_vec<SingleSatCorrection_V1_0> list(len); hidl_vec<SingleSatCorrection_V1_0> list(len);
getSingleSatCorrectionList_1_0(env, singleSatCorrectionList, list); getSingleSatCorrectionList_1_0(env, singleSatCorrectionList, list);
env->DeleteLocalRef(singleSatCorrectionList);
measurementCorrections_1_0.satCorrections = list; measurementCorrections_1_0.satCorrections = list;
auto result = gnssCorrectionsIface_V1_0->setCorrections(measurementCorrections_1_0); auto result = gnssCorrectionsIface_V1_0->setCorrections(measurementCorrections_1_0);

View File

@@ -335,22 +335,22 @@ void GnssMeasurementCallbackAidl::translateSingleGnssMeasurement(JNIEnv* env,
satellitePvt.satClockInfo.satHardwareCodeBiasMeters, satellitePvt.satClockInfo.satHardwareCodeBiasMeters,
satellitePvt.satClockInfo.satTimeCorrectionMeters, satellitePvt.satClockInfo.satTimeCorrectionMeters,
satellitePvt.satClockInfo.satClkDriftMps); satellitePvt.satClockInfo.satClkDriftMps);
env->CallObjectMethod(satellitePvtBuilderObject, callObjectMethodIgnoringResult(env, satellitePvtBuilderObject,
method_satellitePvtBuilderSetPositionEcef, positionEcef); method_satellitePvtBuilderSetPositionEcef, positionEcef);
env->CallObjectMethod(satellitePvtBuilderObject, callObjectMethodIgnoringResult(env, satellitePvtBuilderObject,
method_satellitePvtBuilderSetVelocityEcef, velocityEcef); method_satellitePvtBuilderSetVelocityEcef, velocityEcef);
env->CallObjectMethod(satellitePvtBuilderObject, method_satellitePvtBuilderSetClockInfo, callObjectMethodIgnoringResult(env, satellitePvtBuilderObject,
clockInfo); method_satellitePvtBuilderSetClockInfo, clockInfo);
} }
if (satFlags & SatellitePvt::HAS_IONO) { if (satFlags & SatellitePvt::HAS_IONO) {
env->CallObjectMethod(satellitePvtBuilderObject, callObjectMethodIgnoringResult(env, satellitePvtBuilderObject,
method_satellitePvtBuilderSetIonoDelayMeters, method_satellitePvtBuilderSetIonoDelayMeters,
satellitePvt.ionoDelayMeters); satellitePvt.ionoDelayMeters);
} }
if (satFlags & SatellitePvt::HAS_TROPO) { if (satFlags & SatellitePvt::HAS_TROPO) {
env->CallObjectMethod(satellitePvtBuilderObject, callObjectMethodIgnoringResult(env, satellitePvtBuilderObject,
method_satellitePvtBuilderSetTropoDelayMeters, method_satellitePvtBuilderSetTropoDelayMeters,
satellitePvt.tropoDelayMeters); satellitePvt.tropoDelayMeters);
} }
@@ -380,15 +380,17 @@ void GnssMeasurementCallbackAidl::translateSingleGnssMeasurement(JNIEnv* env,
jobject correlationVectorBuilderObject = jobject correlationVectorBuilderObject =
env->NewObject(class_correlationVectorBuilder, env->NewObject(class_correlationVectorBuilder,
method_correlationVectorBuilderCtor); method_correlationVectorBuilderCtor);
env->CallObjectMethod(correlationVectorBuilderObject, callObjectMethodIgnoringResult(env, correlationVectorBuilderObject,
method_correlationVectorBuilderSetMagnitude, magnitudeArray); method_correlationVectorBuilderSetMagnitude,
env->CallObjectMethod(correlationVectorBuilderObject, magnitudeArray);
callObjectMethodIgnoringResult(
env, correlationVectorBuilderObject,
method_correlationVectorBuilderSetFrequencyOffsetMetersPerSecond, method_correlationVectorBuilderSetFrequencyOffsetMetersPerSecond,
correlationVector.frequencyOffsetMps); correlationVector.frequencyOffsetMps);
env->CallObjectMethod(correlationVectorBuilderObject, callObjectMethodIgnoringResult(env, correlationVectorBuilderObject,
method_correlationVectorBuilderSetSamplingStartMeters, method_correlationVectorBuilderSetSamplingStartMeters,
correlationVector.samplingStartM); correlationVector.samplingStartM);
env->CallObjectMethod(correlationVectorBuilderObject, callObjectMethodIgnoringResult(env, correlationVectorBuilderObject,
method_correlationVectorBuilderSetSamplingWidthMeters, method_correlationVectorBuilderSetSamplingWidthMeters,
correlationVector.samplingWidthM); correlationVector.samplingWidthM);
jobject correlationVectorObject = jobject correlationVectorObject =

View File

@@ -82,6 +82,13 @@ void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
} }
} }
void callObjectMethodIgnoringResult(JNIEnv* env, jobject obj, jmethodID mid, ...) {
va_list args;
va_start(args, mid);
env->DeleteLocalRef(env->CallObjectMethodV(obj, mid, args));
va_end(args);
}
JavaObject::JavaObject(JNIEnv* env, jclass clazz, jmethodID defaultCtor) JavaObject::JavaObject(JNIEnv* env, jclass clazz, jmethodID defaultCtor)
: env_(env), clazz_(clazz) { : env_(env), clazz_(clazz) {
object_ = env_->NewObject(clazz_, defaultCtor); object_ = env_->NewObject(clazz_, defaultCtor);

View File

@@ -48,6 +48,8 @@ jboolean checkAidlStatus(const android::binder::Status& status, const char* erro
void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName); void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
void callObjectMethodIgnoringResult(JNIEnv* env, jobject obj, jmethodID mid, ...);
template <class T> template <class T>
void logHidlError(hardware::Return<T>& result, const char* errorMessage) { void logHidlError(hardware::Return<T>& result, const char* errorMessage) {
ALOGE("%s HIDL transport error: %s", errorMessage, result.description().c_str()); ALOGE("%s HIDL transport error: %s", errorMessage, result.description().c_str());