From 1822a71c2a80ce31dac1b8a4df25acf012171b43 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 26 Mar 2021 12:54:23 +0100 Subject: [PATCH] Do not crash when receiving video call on device w/o camera Upon accepting a video call on a device that can not establish a video track on its own (for example by not having a camera), displaying the video enable/disable button would fail. This commit defaults this button to disabled. --- .../java/eu/siacs/conversations/ui/RtpSessionActivity.java | 7 ++++++- src/main/java/eu/siacs/conversations/ui/XmppActivity.java | 6 +----- .../eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java | 2 +- src/main/res/values/strings.xml | 1 + 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java index 7f046def8..496244300 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -874,7 +874,12 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe } private void enableVideo(View view) { - requireRtpConnection().setVideoEnabled(true); + try { + requireRtpConnection().setVideoEnabled(true); + } catch (final IllegalStateException e) { + Toast.makeText(this, R.string.unable_to_enable_video, Toast.LENGTH_SHORT).show(); + return; + } updateInCallButtonConfigurationVideo(true, requireRtpConnection().isCameraSwitchable()); } diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index af57d7cc9..021ec4a5e 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -408,11 +408,7 @@ public abstract class XmppActivity extends ActionBarActivity { metrics = getResources().getDisplayMetrics(); ExceptionHelper.init(getApplicationContext()); new EmojiService(this).init(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - this.isCameraFeatureAvailable = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY); - } else { - this.isCameraFeatureAvailable = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA); - } + this.isCameraFeatureAvailable = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY); this.mTheme = findTheme(); setTheme(this.mTheme); } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java index 640776122..dca04c000 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java @@ -393,7 +393,7 @@ public class WebRTCWrapper { boolean isVideoEnabled() { final VideoTrack videoTrack = this.localVideoTrack; if (videoTrack == null) { - throw new IllegalStateException("Local video track does not exist"); + return false; } return videoTrack.enabled(); } diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index e96b62066..1b4b56e7d 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -961,4 +961,5 @@ Server does not support generating invites No active accounts support this feature The backup has been started. You’ll get a notification once it has been completed. + Unable to enable video.