diff --git a/src/main/java/eu/siacs/conversations/services/CallIntegration.java b/src/main/java/eu/siacs/conversations/services/CallIntegration.java index 0074d7079..796368096 100644 --- a/src/main/java/eu/siacs/conversations/services/CallIntegration.java +++ b/src/main/java/eu/siacs/conversations/services/CallIntegration.java @@ -1,6 +1,7 @@ package eu.siacs.conversations.services; import android.content.Context; +import android.content.pm.PackageManager; import android.media.AudioManager; import android.media.ToneGenerator; import android.net.Uri; @@ -50,7 +51,12 @@ public class CallIntegration extends Connection { public CallIntegration(final Context context) { this.context = context.getApplicationContext(); if (selfManaged()) { - setConnectionProperties(Connection.PROPERTY_SELF_MANAGED); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + setConnectionProperties(Connection.PROPERTY_SELF_MANAGED); + } else { + throw new AssertionError( + "Trying to set connection properties on unsupported version"); + } this.appRTCAudioManager = null; } else { this.appRTCAudioManager = new AppRTCAudioManager(context); @@ -151,7 +157,11 @@ public class CallIntegration extends Connection { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { setAudioDeviceUpsideDownCake(audioDevice); } else if (selfManaged()) { - setAudioDeviceOreo(audioDevice); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + setAudioDeviceOreo(audioDevice); + } else { + throw new AssertionError("Trying to set audio devices on unsupported version"); + } } else { setAudioDeviceFallback(audioDevice); } @@ -309,7 +319,7 @@ public class CallIntegration extends Connection { @Override public void onStateChanged(final int state) { Log.d(Config.LOGTAG, "onStateChanged(" + state + ")"); - if (notSelfManaged()) { + if (notSelfManaged(context)) { if (state == STATE_DIALING) { requireAppRtcAudioManager().startRingBack(); } else { @@ -432,18 +442,24 @@ public class CallIntegration extends Connection { callback.onAudioDeviceChanged(selectedAudioDevice, availableAudioDevices); } - public static boolean selfManaged() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O; + private boolean selfManaged() { + return selfManaged(context); } - public static boolean notSelfManaged() { - return Build.VERSION.SDK_INT < Build.VERSION_CODES.O; + public static boolean selfManaged(final Context context) { + final var packageManager = context.getPackageManager(); + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O + && packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY); + } + + public static boolean notSelfManaged(final Context context) { + return !selfManaged(context); } public void setInitialAudioDevice(final AudioDevice audioDevice) { Log.d(Config.LOGTAG, "setInitialAudioDevice(" + audioDevice + ")"); this.initialAudioDevice = audioDevice; - if (CallIntegration.selfManaged()) { + if (selfManaged()) { // once the 'CallIntegration' gets added to the system we receive calls to update audio // state return; diff --git a/src/main/java/eu/siacs/conversations/services/CallIntegrationConnectionService.java b/src/main/java/eu/siacs/conversations/services/CallIntegrationConnectionService.java index 01602dc70..ce4f0eb85 100644 --- a/src/main/java/eu/siacs/conversations/services/CallIntegrationConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/CallIntegrationConnectionService.java @@ -314,7 +314,7 @@ public class CallIntegrationConnectionService extends ConnectionService { final Account account, final Jid with, final Set media) { - if (CallIntegration.selfManaged()) { + if (CallIntegration.selfManaged(service)) { final var extras = new Bundle(); extras.putParcelable( TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, getHandle(service, account)); @@ -349,7 +349,7 @@ public class CallIntegrationConnectionService extends ConnectionService { public static void addNewIncomingCall( final Context context, final AbstractJingleConnection.Id id) { - if (CallIntegration.notSelfManaged()) { + if (CallIntegration.notSelfManaged(context)) { Log.d( Config.LOGTAG, "not adding incoming call to TelecomManager on Android " diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java index e22d6574e..bd069fa8b 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -1692,7 +1692,7 @@ public class JingleRtpConnection extends AbstractJingleConnection ringingTimeoutFuture = jingleConnectionManager.schedule( this::ringingTimeout, BUSY_TIME_OUT, TimeUnit.SECONDS); - if (CallIntegration.selfManaged()) { + if (CallIntegration.selfManaged(xmppConnectionService)) { return; } xmppConnectionService.getNotificationService().startRinging(id, getMedia());