diff --git a/src/org/thoughtcrime/redphone/audio/CallAudioManager.java b/src/org/thoughtcrime/redphone/audio/CallAudioManager.java index b66d8419c9..0c336268b4 100644 --- a/src/org/thoughtcrime/redphone/audio/CallAudioManager.java +++ b/src/org/thoughtcrime/redphone/audio/CallAudioManager.java @@ -1,8 +1,13 @@ package org.thoughtcrime.redphone.audio; +import android.content.Context; +import android.media.AudioManager; import android.os.Build; +import android.support.annotation.NonNull; import android.util.Log; +import org.thoughtcrime.securesms.util.ServiceUtil; + import java.io.FileDescriptor; import java.lang.reflect.Field; import java.net.DatagramSocket; @@ -38,7 +43,13 @@ public class CallAudioManager { setMute(handle, enabled); } - public void start() throws AudioException { + public void start(@NonNull Context context) throws AudioException { + if (Build.VERSION.SDK_INT >= 11) { + ServiceUtil.getAudioManager(context).setMode(AudioManager.MODE_IN_COMMUNICATION); + } else { + ServiceUtil.getAudioManager(context).setMode(AudioManager.MODE_IN_CALL); + } + try { start(handle); } catch (NativeAudioException | NoSuchMethodError e) { diff --git a/src/org/thoughtcrime/redphone/call/InitiatingCallManager.java b/src/org/thoughtcrime/redphone/call/InitiatingCallManager.java index 0e8f324b52..4fb3b95783 100644 --- a/src/org/thoughtcrime/redphone/call/InitiatingCallManager.java +++ b/src/org/thoughtcrime/redphone/call/InitiatingCallManager.java @@ -127,6 +127,6 @@ public class InitiatingCallManager extends CallManager { masterSecret.getResponderMacKey(), masterSecret.getResponderSrtpSailt()); this.callAudioManager.setMute(muteEnabled); - this.callAudioManager.start(); + this.callAudioManager.start(context); } } diff --git a/src/org/thoughtcrime/redphone/call/ResponderCallManager.java b/src/org/thoughtcrime/redphone/call/ResponderCallManager.java index d89f30dc9e..59b8c8c38a 100644 --- a/src/org/thoughtcrime/redphone/call/ResponderCallManager.java +++ b/src/org/thoughtcrime/redphone/call/ResponderCallManager.java @@ -157,7 +157,7 @@ public class ResponderCallManager extends CallManager { masterSecret.getInitiatorMacKey(), masterSecret.getInitiatorSrtpSalt()); this.callAudioManager.setMute(muteEnabled); - this.callAudioManager.start(); + this.callAudioManager.start(context); } } diff --git a/src/org/thoughtcrime/securesms/util/ServiceUtil.java b/src/org/thoughtcrime/securesms/util/ServiceUtil.java index 5420976d7f..d01a3d6ca6 100644 --- a/src/org/thoughtcrime/securesms/util/ServiceUtil.java +++ b/src/org/thoughtcrime/securesms/util/ServiceUtil.java @@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.util; import android.app.Activity; import android.app.NotificationManager; import android.content.Context; +import android.media.AudioManager; import android.net.ConnectivityManager; import android.telephony.TelephonyManager; import android.view.WindowManager; @@ -28,4 +29,8 @@ public class ServiceUtil { public static TelephonyManager getTelephonyManager(Context context) { return (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); } + + public static AudioManager getAudioManager(Context context) { + return (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); + } }