Bug 932692 - Check for uncaught exceptions after JNI calls followed by JNI calls. r=blassey
--- a/media/webrtc/trunk/webrtc/modules/video_capture/android/device_info_android.cc
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/android/device_info_android.cc
@@ -100,17 +100,17 @@ int32_t DeviceInfoAndroid::GetDeviceName
jobject javaCmDevInfoObject = jniFrame.GetCmDevInfoObject();
// get the method ID for the Android Java GetDeviceUniqueName name.
jmethodID cid = env->GetMethodID(javaCmDevInfoClass, "GetDeviceUniqueName",
"(I)Ljava/lang/String;");
if (cid != NULL) {
jobject javaDeviceNameObj = env->CallObjectMethod(javaCmDevInfoObject,
cid, deviceNumber);
- if (javaDeviceNameObj == NULL) {
+ if (javaDeviceNameObj == NULL || jniFrame.CheckForException()) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id,
"%s: Failed to get device name for device %d.",
__FUNCTION__, (int) deviceNumber);
result = -1;
} else {
jboolean isCopy;
const char* javaDeviceNameChar = env->GetStringUTFChars(
(jstring) javaDeviceNameObj
@@ -195,17 +195,17 @@ int32_t DeviceInfoAndroid::CreateCapabil
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id,
"%s: Can't create string for method GetCapabilityArray.",
__FUNCTION__);
return -1;
}
// Call the java class and get an array with capabilities back.
jobject javaCapabilitiesObj = env->CallObjectMethod(javaCmDevInfoObject,
cid, capureIdString);
- if (!javaCapabilitiesObj) {
+ if (!javaCapabilitiesObj || jniFrame.CheckForException()) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id,
"%s: Failed to call java GetCapabilityArray.",
__FUNCTION__);
return -1;
}
jfieldID widthField = env->GetFieldID(javaCapClass, "width", "I");
jfieldID heigtField = env->GetFieldID(javaCapClass, "height", "I");
--- a/media/webrtc/trunk/webrtc/modules/video_capture/android/video_capture_android.cc
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/android/video_capture_android.cc
@@ -149,17 +149,22 @@ int32_t VideoCaptureAndroid::SetAndroidO
EARLY_WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, -1,
"%s: construct static java device object", __FUNCTION__);
// construct the object by calling the static constructor object
jobject javaCameraDeviceInfoObjLocal =
env->CallStaticObjectMethod(g_javaCmDevInfoClass,
cid, (int) -1,
javaContext);
- if (!javaCameraDeviceInfoObjLocal) {
+ bool exceptionThrown = env->ExceptionCheck();
+ if (!javaCameraDeviceInfoObjLocal || exceptionThrown) {
+ if (exceptionThrown) {
+ env->ExceptionDescribe();
+ env->ExceptionClear();
+ }
EARLY_WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideoCapture, -1,
"%s: could not create Java Capture Device info object",
__FUNCTION__);
return -1;
}
// create a reference to the object (to tell JNI that
// we are referencing it after this function has returned)
g_javaCmDevInfoObject = env->NewGlobalRef(javaCameraDeviceInfoObjLocal);
@@ -324,17 +329,17 @@ int32_t VideoCaptureAndroid::Init(const
}
jstring capureIdString = env->NewStringUTF((char*) deviceUniqueIdUTF8);
// construct the object by calling the static constructor object
jobject javaCameraObjLocal = env->CallObjectMethod(javaCmDevInfoObject,
cid, (jint) id,
(jlong) this,
capureIdString);
- if (!javaCameraObjLocal) {
+ if (!javaCameraObjLocal || jniFrame.CheckForException()) {
WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideoCapture, _id,
"%s: could not create Java Capture object", __FUNCTION__);
return -1;
}
// create a reference to the object (to tell JNI that we are referencing it
// after this function has returned)
_javaCaptureObj = env->NewGlobalRef(javaCameraObjLocal);
@@ -367,16 +372,17 @@ VideoCaptureAndroid::~VideoCaptureAndroi
jmethodID cid = env->GetStaticMethodID(g_javaCmClass,
"DeleteVideoCaptureAndroid",
"(Lorg/webrtc/videoengine/VideoCaptureAndroid;)V");
if (cid != NULL) {
WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, -1,
"%s: Call DeleteVideoCaptureAndroid", __FUNCTION__);
// Close the camera by calling the static destruct function.
env->CallStaticVoidMethod(g_javaCmClass, cid, _javaCaptureObj);
+ jniFrame.CheckForException();
// Delete global object ref to the camera.
env->DeleteGlobalRef(_javaCaptureObj);
_javaCaptureObj = NULL;
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, -1,
"%s: Failed to find DeleteVideoCaptureAndroid id",
__FUNCTION__);