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,17 +1115,18 @@ jobject GnssAntennaInfoCallback::translateSingleGnssAntennaInfo(
env->NewObject(class_gnssAntennaInfoBuilder, method_gnssAntennaInfoBuilderCtor);
// Set fields
env->CallObjectMethod(gnssAntennaInfoBuilderObject,
method_gnssAntennaInfoBuilderSetCarrierFrequencyMHz,
gnssAntennaInfo.carrierFrequencyMHz);
env->CallObjectMethod(gnssAntennaInfoBuilderObject,
method_gnssAntennaInfoBuilderSetPhaseCenterOffset, phaseCenterOffset);
env->CallObjectMethod(gnssAntennaInfoBuilderObject,
method_gnssAntennaInfoBuilderSetPhaseCenterVariationCorrections,
phaseCenterVariationCorrections);
env->CallObjectMethod(gnssAntennaInfoBuilderObject,
method_gnssAntennaInfoBuilderSetSignalGainCorrections,
signalGainCorrections);
callObjectMethodIgnoringResult(env, gnssAntennaInfoBuilderObject,
method_gnssAntennaInfoBuilderSetCarrierFrequencyMHz,
gnssAntennaInfo.carrierFrequencyMHz);
callObjectMethodIgnoringResult(env, gnssAntennaInfoBuilderObject,
method_gnssAntennaInfoBuilderSetPhaseCenterOffset,
phaseCenterOffset);
callObjectMethodIgnoringResult(env, gnssAntennaInfoBuilderObject,
method_gnssAntennaInfoBuilderSetPhaseCenterVariationCorrections,
phaseCenterVariationCorrections);
callObjectMethodIgnoringResult(env, gnssAntennaInfoBuilderObject,
method_gnssAntennaInfoBuilderSetSignalGainCorrections,
signalGainCorrections);
// build
jobject gnssAntennaInfoObject =
@@ -2707,7 +2708,7 @@ static SingleSatCorrection_V1_0 getSingleSatCorrection_1_0_withoutConstellation(
jfloat eplMeters = env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEpl);
jfloat eplUncMeters = env->CallFloatMethod(singleSatCorrectionObj, method_correctionSatEplUnc);
uint16_t corrFlags = static_cast<uint16_t>(correctionFlags);
jobject reflectingPlaneObj;
jobject reflectingPlaneObj = nullptr;
bool has_ref_plane = (corrFlags & GnssSingleSatCorrectionFlags::HAS_REFLECTING_PLANE) != 0;
if (has_ref_plane) {
reflectingPlaneObj =
@@ -2731,6 +2732,7 @@ static SingleSatCorrection_V1_0 getSingleSatCorrection_1_0_withoutConstellation(
.azimuthDegrees = azimuthDegreeRefPlane,
};
}
env->DeleteLocalRef(reflectingPlaneObj);
SingleSatCorrection_V1_0 singleSatCorrection = {
.singleSatCorrectionFlags = corrFlags,
@@ -2762,6 +2764,7 @@ static void getSingleSatCorrectionList_1_1(JNIEnv* env, jobject singleSatCorrect
};
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),
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);
getSingleSatCorrectionList_1_0(env, singleSatCorrectionList, list);
env->DeleteLocalRef(singleSatCorrectionList);
measurementCorrections_1_0.satCorrections = list;
auto result = gnssCorrectionsIface_V1_0->setCorrections(measurementCorrections_1_0);

View File

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

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)
: env_(env), clazz_(clazz) {
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 callObjectMethodIgnoringResult(JNIEnv* env, jobject obj, jmethodID mid, ...);
template <class T>
void logHidlError(hardware::Return<T>& result, const char* errorMessage) {
ALOGE("%s HIDL transport error: %s", errorMessage, result.description().c_str());