mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Do not automatically enable bluetooth audio routing
Fixes some call volume problems Fixes #4773 Fixes #4188 Closes #4885
This commit is contained in:
parent
6ad2c4bb29
commit
0caad7f348
@ -293,14 +293,17 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
|
|||||||
AudioManager audioManager = ServiceUtil.getAudioManager(this);
|
AudioManager audioManager = ServiceUtil.getAudioManager(this);
|
||||||
AudioUtils.resetConfiguration(this);
|
AudioUtils.resetConfiguration(this);
|
||||||
|
|
||||||
audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL,
|
Log.d(TAG, "request STREAM_VOICE_CALL audio focus");
|
||||||
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
|
audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shutdownAudio() {
|
private void shutdownAudio() {
|
||||||
AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
|
Log.d(TAG, "reset audio mode and abandon focus");
|
||||||
|
AudioUtils.resetConfiguration(this);
|
||||||
|
AudioManager am = ServiceUtil.getAudioManager(this);
|
||||||
am.setMode(AudioManager.MODE_NORMAL);
|
am.setMode(AudioManager.MODE_NORMAL);
|
||||||
am.abandonAudioFocus(null);
|
am.abandonAudioFocus(null);
|
||||||
|
am.stopBluetoothSco();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getState() {
|
public int getState() {
|
||||||
|
@ -45,6 +45,7 @@ public class CallAudioManager {
|
|||||||
|
|
||||||
public void start(@NonNull Context context) throws AudioException {
|
public void start(@NonNull Context context) throws AudioException {
|
||||||
if (Build.VERSION.SDK_INT >= 11) {
|
if (Build.VERSION.SDK_INT >= 11) {
|
||||||
|
Log.d(TAG, "set MODE_IN_COMMUNICATION audio mode");
|
||||||
ServiceUtil.getAudioManager(context).setMode(AudioManager.MODE_IN_COMMUNICATION);
|
ServiceUtil.getAudioManager(context).setMode(AudioManager.MODE_IN_COMMUNICATION);
|
||||||
} else {
|
} else {
|
||||||
// ServiceUtil.getAudioManager(context).setMode(AudioManager.MODE_IN_CALL);
|
// ServiceUtil.getAudioManager(context).setMode(AudioManager.MODE_IN_CALL);
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
package org.thoughtcrime.redphone.audio;
|
package org.thoughtcrime.redphone.audio;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
@ -91,6 +90,7 @@ public class IncomingRinger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (player != null && ringerMode == AudioManager.RINGER_MODE_NORMAL ) {
|
if (player != null && ringerMode == AudioManager.RINGER_MODE_NORMAL ) {
|
||||||
|
Log.d(TAG, "set MODE_RINGTONE audio mode");
|
||||||
audioManager.setMode(AudioManager.MODE_RINGTONE);
|
audioManager.setMode(AudioManager.MODE_RINGTONE);
|
||||||
try {
|
try {
|
||||||
if(!player.isPlaying()) {
|
if(!player.isPlaying()) {
|
||||||
@ -117,6 +117,7 @@ public class IncomingRinger {
|
|||||||
Log.d(TAG, "Cancelling vibrator");
|
Log.d(TAG, "Cancelling vibrator");
|
||||||
vibrator.cancel();
|
vibrator.cancel();
|
||||||
|
|
||||||
|
Log.d(TAG, "reset audio mode");
|
||||||
AudioManager audioManager = ServiceUtil.getAudioManager(context);
|
AudioManager audioManager = ServiceUtil.getAudioManager(context);
|
||||||
audioManager.setMode(AudioManager.MODE_NORMAL);
|
audioManager.setMode(AudioManager.MODE_NORMAL);
|
||||||
}
|
}
|
||||||
@ -134,7 +135,7 @@ public class IncomingRinger {
|
|||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||||
private boolean shouldVibrateNew(Context context) {
|
private boolean shouldVibrateNew(Context context) {
|
||||||
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
AudioManager audioManager = ServiceUtil.getAudioManager(context);
|
||||||
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
|
|
||||||
if (vibrator == null || !vibrator.hasVibrator()) {
|
if (vibrator == null || !vibrator.hasVibrator()) {
|
||||||
@ -151,7 +152,7 @@ public class IncomingRinger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldVibrateOld(Context context) {
|
private boolean shouldVibrateOld(Context context) {
|
||||||
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
AudioManager audioManager = ServiceUtil.getAudioManager(context);
|
||||||
return audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER);
|
return audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import android.net.Uri;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -133,12 +134,12 @@ public class OutgoingRinger implements MediaPlayer.OnCompletionListener, MediaPl
|
|||||||
public void onPrepared(MediaPlayer mp) {
|
public void onPrepared(MediaPlayer mp) {
|
||||||
mediaPlayer.setLooping(loopEnabled);
|
mediaPlayer.setLooping(loopEnabled);
|
||||||
|
|
||||||
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
AudioManager am = ServiceUtil.getAudioManager(context);
|
||||||
|
|
||||||
if (am.isBluetoothScoAvailableOffCall()) {
|
if (am.isBluetoothScoAvailableOffCall()) {
|
||||||
|
Log.d(TAG, "bluetooth sco is available");
|
||||||
try {
|
try {
|
||||||
am.startBluetoothSco();
|
am.startBluetoothSco();
|
||||||
am.setBluetoothScoOn(true);
|
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
// Lollipop bug (https://stackoverflow.com/questions/26642218/audiomanager-startbluetoothsco-crashes-on-android-lollipop)
|
// Lollipop bug (https://stackoverflow.com/questions/26642218/audiomanager-startbluetoothsco-crashes-on-android-lollipop)
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import android.media.AudioManager;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities for manipulating device audio configuration
|
* Utilities for manipulating device audio configuration
|
||||||
*
|
*
|
||||||
@ -13,22 +15,23 @@ import android.util.Log;
|
|||||||
public class AudioUtils {
|
public class AudioUtils {
|
||||||
private static final String TAG = AudioUtils.class.getName();
|
private static final String TAG = AudioUtils.class.getName();
|
||||||
public static void enableDefaultRouting(Context context) {
|
public static void enableDefaultRouting(Context context) {
|
||||||
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
AudioManager am = ServiceUtil.getAudioManager(context);
|
||||||
am.setSpeakerphoneOn(false);
|
am.setSpeakerphoneOn(false);
|
||||||
am.setBluetoothScoOn(false);
|
am.setBluetoothScoOn(false);
|
||||||
Log.d(TAG, "Set default audio routing");
|
Log.d(TAG, "Set default audio routing");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void enableSpeakerphoneRouting(Context context) {
|
public static void enableSpeakerphoneRouting(Context context) {
|
||||||
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
AudioManager am = ServiceUtil.getAudioManager(context);
|
||||||
am.setSpeakerphoneOn(true);
|
am.setSpeakerphoneOn(true);
|
||||||
Log.d(TAG, "Set speakerphone audio routing");
|
Log.d(TAG, "Set speakerphone audio routing");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void enableBluetoothRouting(Context context) {
|
public static void enableBluetoothRouting(Context context) {
|
||||||
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
AudioManager am = ServiceUtil.getAudioManager(context);
|
||||||
am.startBluetoothSco();
|
am.startBluetoothSco();
|
||||||
am.setBluetoothScoOn(true);
|
am.setBluetoothScoOn(true);
|
||||||
|
Log.d(TAG, "Set bluetooth audio routing");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void resetConfiguration(Context context) {
|
public static void resetConfiguration(Context context) {
|
||||||
@ -42,7 +45,7 @@ public class AudioUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static AudioMode getCurrentAudioMode(Context context) {
|
public static AudioMode getCurrentAudioMode(Context context) {
|
||||||
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
AudioManager am = ServiceUtil.getAudioManager(context);
|
||||||
if (am.isBluetoothScoOn()) {
|
if (am.isBluetoothScoOn()) {
|
||||||
return AudioMode.HEADSET;
|
return AudioMode.HEADSET;
|
||||||
} else if (am.isSpeakerphoneOn()) {
|
} else if (am.isSpeakerphoneOn()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user