Add audio focus into the audio dance.

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2015-11-04 15:34:24 -08:00
parent 72b9c37ec8
commit 3f6cdd4133
2 changed files with 15 additions and 2 deletions

View File

@ -46,6 +46,7 @@ import org.thoughtcrime.redphone.signaling.SessionDescriptor;
import org.thoughtcrime.redphone.signaling.SignalingException; import org.thoughtcrime.redphone.signaling.SignalingException;
import org.thoughtcrime.redphone.signaling.SignalingSocket; import org.thoughtcrime.redphone.signaling.SignalingSocket;
import org.thoughtcrime.redphone.ui.NotificationBarManager; import org.thoughtcrime.redphone.ui.NotificationBarManager;
import org.thoughtcrime.redphone.util.AudioUtils;
import org.thoughtcrime.redphone.util.UncaughtExceptionHandlerManager; import org.thoughtcrime.redphone.util.UncaughtExceptionHandlerManager;
import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.events.RedPhoneEvent; import org.thoughtcrime.securesms.events.RedPhoneEvent;
@ -55,6 +56,7 @@ import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientFactory; import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.service.KeyCachingService; import org.thoughtcrime.securesms.service.KeyCachingService;
import org.thoughtcrime.securesms.util.Base64; import org.thoughtcrime.securesms.util.Base64;
import org.thoughtcrime.securesms.util.ServiceUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
import java.io.IOException; import java.io.IOException;
@ -174,6 +176,8 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
/// Intent Handlers /// Intent Handlers
private void handleIncomingCall(Intent intent) { private void handleIncomingCall(Intent intent) {
initializeAudio();
String localNumber = TextSecurePreferences.getLocalNumber(this); String localNumber = TextSecurePreferences.getLocalNumber(this);
String password = TextSecurePreferences.getPushServerPassword(this); String password = TextSecurePreferences.getPushServerPassword(this);
SessionDescriptor session = intent.getParcelableExtra(EXTRA_SESSION_DESCRIPTOR); SessionDescriptor session = intent.getParcelableExtra(EXTRA_SESSION_DESCRIPTOR);
@ -188,6 +192,8 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
} }
private void handleOutgoingCall(Intent intent) { private void handleOutgoingCall(Intent intent) {
initializeAudio();
String localNumber = TextSecurePreferences.getLocalNumber(this); String localNumber = TextSecurePreferences.getLocalNumber(this);
String password = TextSecurePreferences.getPushServerPassword(this); String password = TextSecurePreferences.getPushServerPassword(this);
@ -280,9 +286,18 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
return state == STATE_IDLE; return state == STATE_IDLE;
} }
private void initializeAudio() {
AudioManager audioManager = ServiceUtil.getAudioManager(this);
AudioUtils.resetConfiguration(this);
audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
}
private void shutdownAudio() { private void shutdownAudio() {
AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE); AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
am.setMode(AudioManager.MODE_NORMAL); am.setMode(AudioManager.MODE_NORMAL);
am.abandonAudioFocus(null);
} }
public int getState() { public int getState() {

View File

@ -75,8 +75,6 @@ public abstract class CallManager extends Thread {
this.callStateListener = callStateListener; this.callStateListener = callStateListener;
this.terminated = false; this.terminated = false;
this.context = context; this.context = context;
AudioUtils.resetConfiguration(context);
} }
@Override @Override