Do not crash when receiving video call on device w/o camera

Daniel Gultsch created

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.

Change summary

src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java     | 7 
src/main/java/eu/siacs/conversations/ui/XmppActivity.java           | 6 
src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java | 2 
src/main/res/values/strings.xml                                     | 1 
4 files changed, 9 insertions(+), 7 deletions(-)

Detailed changes

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());
     }
 

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);
     }

src/main/res/values/strings.xml 🔗

@@ -961,4 +961,5 @@
     <string name="server_does_not_support_easy_onboarding_invites">Server does not support generating invites</string>
     <string name="no_active_accounts_support_this">No active accounts support this feature</string>
     <string name="backup_started_message">The backup has been started. You’ll get a notification once it has been completed.</string>
+    <string name="unable_to_enable_video">Unable to enable video.</string>
 </resources>