Bug 1648123 - Add exception and nullptr checks after calling getDeviceInfo; r=ng
authorDan Minor <dminor@mozilla.com>
Fri, 26 Jun 2020 20:13:21 +0000
changeset 537678 1150d73f382c228f9c5a72de223f09d34b1e7a6b
parent 537677 f6368808c31122f911a09b55b4466d73500fd2c1
child 537679 fec02fef5e73cf4e56373bb830e8591647f192ca
push id120158
push userdminor@mozilla.com
push dateFri, 26 Jun 2020 23:45:40 +0000
treeherderautoland@1150d73f382c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersng
bugs1648123
milestone79.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1648123 - Add exception and nullptr checks after calling getDeviceInfo; r=ng Differential Revision: https://phabricator.services.mozilla.com/D81315
dom/media/systemservices/android_video_capture/device_info_android.cc
--- a/dom/media/systemservices/android_video_capture/device_info_android.cc
+++ b/dom/media/systemservices/android_video_capture/device_info_android.cc
@@ -111,21 +111,30 @@ void DeviceInfoAndroid::BuildDeviceList(
   JNIEnv* jni = ats.env();
 
   g_camera_info = new std::vector<AndroidCameraInfo>();
   jclass j_info_class = mozilla::jni::GetClassRef(
       jni, "org/webrtc/videoengine/VideoCaptureDeviceInfoAndroid");
   jclass j_cap_class = mozilla::jni::GetClassRef(
       jni, "org/webrtc/videoengine/CaptureCapabilityAndroid");
   assert(j_info_class);
-  jmethodID j_initialize = jni->GetStaticMethodID(
+  jmethodID j_get_device_info = jni->GetStaticMethodID(
       j_info_class, "getDeviceInfo",
       "()[Lorg/webrtc/videoengine/CaptureCapabilityAndroid;");
   jarray j_camera_caps = static_cast<jarray>(
-      jni->CallStaticObjectMethod(j_info_class, j_initialize));
+      jni->CallStaticObjectMethod(j_info_class, j_get_device_info));
+  if (jni->ExceptionCheck()) {
+    jni->ExceptionClear();
+    RTC_LOG(LS_INFO) << __FUNCTION__ << ": Failed to get camera capabilities.";
+    return;
+  }
+  if (j_camera_caps == nullptr) {
+    RTC_LOG(LS_INFO) << __FUNCTION__ << ": Failed to get camera capabilities.";
+    return;
+  }
 
   const jsize capLength = jni->GetArrayLength(j_camera_caps);
 
   jfieldID widthField = jni->GetFieldID(j_cap_class, "width", "[I");
   jfieldID heightField = jni->GetFieldID(j_cap_class, "height", "[I");
   jfieldID maxFpsField = jni->GetFieldID(j_cap_class, "maxMilliFPS", "I");
   jfieldID minFpsField = jni->GetFieldID(j_cap_class, "minMilliFPS", "I");
   jfieldID orientationField = jni->GetFieldID(j_cap_class, "orientation", "I");