Correctly set audio mode

Fixes #4244
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2015-11-04 10:42:19 -08:00
parent 58406d6b37
commit aade4c7af3
4 changed files with 19 additions and 3 deletions

View File

@ -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) {

View File

@ -127,6 +127,6 @@ public class InitiatingCallManager extends CallManager {
masterSecret.getResponderMacKey(),
masterSecret.getResponderSrtpSailt());
this.callAudioManager.setMute(muteEnabled);
this.callAudioManager.start();
this.callAudioManager.start(context);
}
}

View File

@ -157,7 +157,7 @@ public class ResponderCallManager extends CallManager {
masterSecret.getInitiatorMacKey(),
masterSecret.getInitiatorSrtpSalt());
this.callAudioManager.setMute(muteEnabled);
this.callAudioManager.start();
this.callAudioManager.start(context);
}
}

View File

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