mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-10 08:00:57 +00:00
Rename 'MagicAudioManager' and 'MagicBluetoothManager'
It's not magic but WebRtc related. Signed-off-by: Tim Krüger <t@timkrueger.me>
This commit is contained in:
parent
e14f00fae7
commit
6e4841ae3a
@ -94,7 +94,7 @@ import com.nextcloud.talk.utils.database.user.UserUtils;
|
|||||||
import com.nextcloud.talk.utils.power.PowerManagerUtils;
|
import com.nextcloud.talk.utils.power.PowerManagerUtils;
|
||||||
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||||
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
|
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
|
||||||
import com.nextcloud.talk.webrtc.MagicAudioManager;
|
import com.nextcloud.talk.webrtc.WebRtcAudioManger;
|
||||||
import com.nextcloud.talk.webrtc.MagicWebRTCUtils;
|
import com.nextcloud.talk.webrtc.MagicWebRTCUtils;
|
||||||
import com.nextcloud.talk.webrtc.MagicWebSocketInstance;
|
import com.nextcloud.talk.webrtc.MagicWebSocketInstance;
|
||||||
import com.nextcloud.talk.webrtc.PeerConnectionWrapper;
|
import com.nextcloud.talk.webrtc.PeerConnectionWrapper;
|
||||||
@ -186,7 +186,7 @@ public class CallActivity extends CallBaseActivity {
|
|||||||
|
|
||||||
public static final String TAG = "CallActivity";
|
public static final String TAG = "CallActivity";
|
||||||
|
|
||||||
public MagicAudioManager audioManager;
|
public WebRtcAudioManger audioManager;
|
||||||
|
|
||||||
private static final String[] PERMISSIONS_CALL = {
|
private static final String[] PERMISSIONS_CALL = {
|
||||||
Manifest.permission.CAMERA,
|
Manifest.permission.CAMERA,
|
||||||
@ -449,16 +449,16 @@ public class CallActivity extends CallBaseActivity {
|
|||||||
|
|
||||||
// Create and audio manager that will take care of audio routing,
|
// Create and audio manager that will take care of audio routing,
|
||||||
// audio modes, audio device enumeration etc.
|
// audio modes, audio device enumeration etc.
|
||||||
audioManager = MagicAudioManager.create(getApplicationContext(), isVoiceOnlyCall);
|
audioManager = WebRtcAudioManger.create(getApplicationContext(), isVoiceOnlyCall);
|
||||||
// Store existing audio settings and change audio mode to
|
// Store existing audio settings and change audio mode to
|
||||||
// MODE_IN_COMMUNICATION for best possible VoIP performance.
|
// MODE_IN_COMMUNICATION for best possible VoIP performance.
|
||||||
Log.d(TAG, "Starting the audio manager...");
|
Log.d(TAG, "Starting the audio manager...");
|
||||||
audioManager.start(this::onAudioManagerDevicesChanged);
|
audioManager.start(this::onAudioManagerDevicesChanged);
|
||||||
|
|
||||||
if (isVoiceOnlyCall) {
|
if (isVoiceOnlyCall) {
|
||||||
setAudioOutputChannel(MagicAudioManager.AudioDevice.EARPIECE);
|
setAudioOutputChannel(WebRtcAudioManger.AudioDevice.EARPIECE);
|
||||||
} else {
|
} else {
|
||||||
setAudioOutputChannel(MagicAudioManager.AudioDevice.SPEAKER_PHONE);
|
setAudioOutputChannel(WebRtcAudioManger.AudioDevice.SPEAKER_PHONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
iceServers = new ArrayList<>();
|
iceServers = new ArrayList<>();
|
||||||
@ -492,14 +492,14 @@ public class CallActivity extends CallBaseActivity {
|
|||||||
microphoneInitialization();
|
microphoneInitialization();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAudioOutputChannel(MagicAudioManager.AudioDevice selectedAudioDevice) {
|
public void setAudioOutputChannel(WebRtcAudioManger.AudioDevice selectedAudioDevice) {
|
||||||
if (audioManager != null) {
|
if (audioManager != null) {
|
||||||
audioManager.selectAudioDevice(selectedAudioDevice);
|
audioManager.selectAudioDevice(selectedAudioDevice);
|
||||||
updateAudioOutputButton(audioManager.getCurrentAudioDevice());
|
updateAudioOutputButton(audioManager.getCurrentAudioDevice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateAudioOutputButton(MagicAudioManager.AudioDevice activeAudioDevice) {
|
private void updateAudioOutputButton(WebRtcAudioManger.AudioDevice activeAudioDevice) {
|
||||||
switch (activeAudioDevice) {
|
switch (activeAudioDevice) {
|
||||||
case BLUETOOTH:
|
case BLUETOOTH:
|
||||||
binding.audioOutputButton.getHierarchy().setPlaceholderImage(
|
binding.audioOutputButton.getHierarchy().setPlaceholderImage(
|
||||||
@ -793,14 +793,14 @@ public class CallActivity extends CallBaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onAudioManagerDevicesChanged(
|
private void onAudioManagerDevicesChanged(
|
||||||
final MagicAudioManager.AudioDevice currentDevice,
|
final WebRtcAudioManger.AudioDevice currentDevice,
|
||||||
final Set<MagicAudioManager.AudioDevice> availableDevices) {
|
final Set<WebRtcAudioManger.AudioDevice> availableDevices) {
|
||||||
Log.d(TAG, "onAudioManagerDevicesChanged: " + availableDevices + ", "
|
Log.d(TAG, "onAudioManagerDevicesChanged: " + availableDevices + ", "
|
||||||
+ "currentDevice: " + currentDevice);
|
+ "currentDevice: " + currentDevice);
|
||||||
|
|
||||||
final boolean shouldDisableProximityLock = (currentDevice.equals(MagicAudioManager.AudioDevice.WIRED_HEADSET)
|
final boolean shouldDisableProximityLock = (currentDevice.equals(WebRtcAudioManger.AudioDevice.WIRED_HEADSET)
|
||||||
|| currentDevice.equals(MagicAudioManager.AudioDevice.SPEAKER_PHONE)
|
|| currentDevice.equals(WebRtcAudioManger.AudioDevice.SPEAKER_PHONE)
|
||||||
|| currentDevice.equals(MagicAudioManager.AudioDevice.BLUETOOTH));
|
|| currentDevice.equals(WebRtcAudioManger.AudioDevice.BLUETOOTH));
|
||||||
|
|
||||||
if (shouldDisableProximityLock) {
|
if (shouldDisableProximityLock) {
|
||||||
powerManagerUtils.updatePhoneState(PowerManagerUtils.PhoneState.WITHOUT_PROXIMITY_SENSOR_LOCK);
|
powerManagerUtils.updatePhoneState(PowerManagerUtils.PhoneState.WITHOUT_PROXIMITY_SENSOR_LOCK);
|
||||||
|
@ -30,7 +30,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
|
|||||||
import com.nextcloud.talk.R
|
import com.nextcloud.talk.R
|
||||||
import com.nextcloud.talk.activities.CallActivity
|
import com.nextcloud.talk.activities.CallActivity
|
||||||
import com.nextcloud.talk.databinding.DialogAudioOutputBinding
|
import com.nextcloud.talk.databinding.DialogAudioOutputBinding
|
||||||
import com.nextcloud.talk.webrtc.MagicAudioManager
|
import com.nextcloud.talk.webrtc.WebRtcAudioManger
|
||||||
|
|
||||||
class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(callActivity) {
|
class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(callActivity) {
|
||||||
|
|
||||||
@ -47,26 +47,26 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateOutputDeviceList() {
|
fun updateOutputDeviceList() {
|
||||||
if (callActivity.audioManager?.audioDevices?.contains(MagicAudioManager.AudioDevice.BLUETOOTH) == false) {
|
if (callActivity.audioManager?.audioDevices?.contains(WebRtcAudioManger.AudioDevice.BLUETOOTH) == false) {
|
||||||
dialogAudioOutputBinding.audioOutputBluetooth.visibility = View.GONE
|
dialogAudioOutputBinding.audioOutputBluetooth.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
dialogAudioOutputBinding.audioOutputBluetooth.visibility = View.VISIBLE
|
dialogAudioOutputBinding.audioOutputBluetooth.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callActivity.audioManager?.audioDevices?.contains(MagicAudioManager.AudioDevice.EARPIECE) == false) {
|
if (callActivity.audioManager?.audioDevices?.contains(WebRtcAudioManger.AudioDevice.EARPIECE) == false) {
|
||||||
dialogAudioOutputBinding.audioOutputEarspeaker.visibility = View.GONE
|
dialogAudioOutputBinding.audioOutputEarspeaker.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
dialogAudioOutputBinding.audioOutputEarspeaker.visibility = View.VISIBLE
|
dialogAudioOutputBinding.audioOutputEarspeaker.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callActivity.audioManager?.audioDevices?.contains(MagicAudioManager.AudioDevice.SPEAKER_PHONE) == false) {
|
if (callActivity.audioManager?.audioDevices?.contains(WebRtcAudioManger.AudioDevice.SPEAKER_PHONE) == false) {
|
||||||
dialogAudioOutputBinding.audioOutputSpeaker.visibility = View.GONE
|
dialogAudioOutputBinding.audioOutputSpeaker.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
dialogAudioOutputBinding.audioOutputSpeaker.visibility = View.VISIBLE
|
dialogAudioOutputBinding.audioOutputSpeaker.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callActivity.audioManager?.currentAudioDevice?.equals(
|
if (callActivity.audioManager?.currentAudioDevice?.equals(
|
||||||
MagicAudioManager.AudioDevice.WIRED_HEADSET
|
WebRtcAudioManger.AudioDevice.WIRED_HEADSET
|
||||||
) == true
|
) == true
|
||||||
) {
|
) {
|
||||||
dialogAudioOutputBinding.audioOutputEarspeaker.visibility = View.GONE
|
dialogAudioOutputBinding.audioOutputEarspeaker.visibility = View.GONE
|
||||||
@ -81,7 +81,7 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
|
|||||||
|
|
||||||
private fun highlightActiveOutputChannel() {
|
private fun highlightActiveOutputChannel() {
|
||||||
when (callActivity.audioManager?.currentAudioDevice) {
|
when (callActivity.audioManager?.currentAudioDevice) {
|
||||||
MagicAudioManager.AudioDevice.BLUETOOTH -> {
|
WebRtcAudioManger.AudioDevice.BLUETOOTH -> {
|
||||||
dialogAudioOutputBinding.audioOutputBluetoothIcon.setColorFilter(
|
dialogAudioOutputBinding.audioOutputBluetoothIcon.setColorFilter(
|
||||||
ContextCompat.getColor(
|
ContextCompat.getColor(
|
||||||
context,
|
context,
|
||||||
@ -94,7 +94,7 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
MagicAudioManager.AudioDevice.SPEAKER_PHONE -> {
|
WebRtcAudioManger.AudioDevice.SPEAKER_PHONE -> {
|
||||||
dialogAudioOutputBinding.audioOutputSpeakerIcon.setColorFilter(
|
dialogAudioOutputBinding.audioOutputSpeakerIcon.setColorFilter(
|
||||||
ContextCompat.getColor(
|
ContextCompat.getColor(
|
||||||
context,
|
context,
|
||||||
@ -107,7 +107,7 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
MagicAudioManager.AudioDevice.EARPIECE -> {
|
WebRtcAudioManger.AudioDevice.EARPIECE -> {
|
||||||
dialogAudioOutputBinding.audioOutputEarspeakerIcon.setColorFilter(
|
dialogAudioOutputBinding.audioOutputEarspeakerIcon.setColorFilter(
|
||||||
ContextCompat.getColor(
|
ContextCompat.getColor(
|
||||||
context,
|
context,
|
||||||
@ -120,7 +120,7 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
MagicAudioManager.AudioDevice.WIRED_HEADSET -> {
|
WebRtcAudioManger.AudioDevice.WIRED_HEADSET -> {
|
||||||
dialogAudioOutputBinding.audioOutputWiredHeadsetIcon.setColorFilter(
|
dialogAudioOutputBinding.audioOutputWiredHeadsetIcon.setColorFilter(
|
||||||
ContextCompat.getColor(
|
ContextCompat.getColor(
|
||||||
context,
|
context,
|
||||||
@ -139,17 +139,17 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
|
|||||||
|
|
||||||
private fun initClickListeners() {
|
private fun initClickListeners() {
|
||||||
dialogAudioOutputBinding.audioOutputBluetooth.setOnClickListener {
|
dialogAudioOutputBinding.audioOutputBluetooth.setOnClickListener {
|
||||||
callActivity.setAudioOutputChannel(MagicAudioManager.AudioDevice.BLUETOOTH)
|
callActivity.setAudioOutputChannel(WebRtcAudioManger.AudioDevice.BLUETOOTH)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
dialogAudioOutputBinding.audioOutputSpeaker.setOnClickListener {
|
dialogAudioOutputBinding.audioOutputSpeaker.setOnClickListener {
|
||||||
callActivity.setAudioOutputChannel(MagicAudioManager.AudioDevice.SPEAKER_PHONE)
|
callActivity.setAudioOutputChannel(WebRtcAudioManger.AudioDevice.SPEAKER_PHONE)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
dialogAudioOutputBinding.audioOutputEarspeaker.setOnClickListener {
|
dialogAudioOutputBinding.audioOutputEarspeaker.setOnClickListener {
|
||||||
callActivity.setAudioOutputChannel(MagicAudioManager.AudioDevice.EARPIECE)
|
callActivity.setAudioOutputChannel(WebRtcAudioManger.AudioDevice.EARPIECE)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,10 +54,10 @@ import java.util.Collections;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class MagicAudioManager {
|
public class WebRtcAudioManger {
|
||||||
private static final String TAG = MagicAudioManager.class.getCanonicalName();
|
private static final String TAG = WebRtcAudioManger.class.getCanonicalName();
|
||||||
private final Context magicContext;
|
private final Context magicContext;
|
||||||
private final MagicBluetoothManager bluetoothManager;
|
private final WebRtcBluetoothManager bluetoothManager;
|
||||||
private final boolean useProximitySensor;
|
private final boolean useProximitySensor;
|
||||||
private final AudioManager audioManager;
|
private final AudioManager audioManager;
|
||||||
private AudioManagerListener audioManagerListener;
|
private AudioManagerListener audioManagerListener;
|
||||||
@ -79,12 +79,12 @@ public class MagicAudioManager {
|
|||||||
|
|
||||||
private final PowerManagerUtils powerManagerUtils;
|
private final PowerManagerUtils powerManagerUtils;
|
||||||
|
|
||||||
private MagicAudioManager(Context context, boolean useProximitySensor) {
|
private WebRtcAudioManger(Context context, boolean useProximitySensor) {
|
||||||
Log.d(TAG, "ctor");
|
Log.d(TAG, "ctor");
|
||||||
ThreadUtils.checkIsOnMainThread();
|
ThreadUtils.checkIsOnMainThread();
|
||||||
magicContext = context;
|
magicContext = context;
|
||||||
audioManager = ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE));
|
audioManager = ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE));
|
||||||
bluetoothManager = MagicBluetoothManager.create(context, this);
|
bluetoothManager = WebRtcBluetoothManager.create(context, this);
|
||||||
wiredHeadsetReceiver = new WiredHeadsetReceiver();
|
wiredHeadsetReceiver = new WiredHeadsetReceiver();
|
||||||
amState = AudioManagerState.UNINITIALIZED;
|
amState = AudioManagerState.UNINITIALIZED;
|
||||||
|
|
||||||
@ -110,8 +110,8 @@ public class MagicAudioManager {
|
|||||||
/**
|
/**
|
||||||
* Construction.
|
* Construction.
|
||||||
*/
|
*/
|
||||||
public static MagicAudioManager create(Context context, boolean useProximitySensor) {
|
public static WebRtcAudioManger create(Context context, boolean useProximitySensor) {
|
||||||
return new MagicAudioManager(context, useProximitySensor);
|
return new WebRtcAudioManger(context, useProximitySensor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startBluetoothManager() {
|
public void startBluetoothManager() {
|
||||||
@ -141,7 +141,7 @@ public class MagicAudioManager {
|
|||||||
.SENSOR_NEAR, null, null, null, null));
|
.SENSOR_NEAR, null, null, null, null));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
setAudioDeviceInternal(MagicAudioManager.AudioDevice.SPEAKER_PHONE);
|
setAudioDeviceInternal(WebRtcAudioManger.AudioDevice.SPEAKER_PHONE);
|
||||||
Log.d(TAG, "switched to SPEAKER_PHONE because userSelectedAudioDevice was SPEAKER_PHONE and proximity=far");
|
Log.d(TAG, "switched to SPEAKER_PHONE because userSelectedAudioDevice was SPEAKER_PHONE and proximity=far");
|
||||||
|
|
||||||
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
||||||
@ -416,17 +416,17 @@ public class MagicAudioManager {
|
|||||||
+ "current=" + currentAudioDevice + ", "
|
+ "current=" + currentAudioDevice + ", "
|
||||||
+ "user selected=" + userSelectedAudioDevice);
|
+ "user selected=" + userSelectedAudioDevice);
|
||||||
|
|
||||||
if (bluetoothManager.getState() == MagicBluetoothManager.State.HEADSET_AVAILABLE
|
if (bluetoothManager.getState() == WebRtcBluetoothManager.State.HEADSET_AVAILABLE
|
||||||
|| bluetoothManager.getState() == MagicBluetoothManager.State.HEADSET_UNAVAILABLE
|
|| bluetoothManager.getState() == WebRtcBluetoothManager.State.HEADSET_UNAVAILABLE
|
||||||
|| bluetoothManager.getState() == MagicBluetoothManager.State.SCO_DISCONNECTING) {
|
|| bluetoothManager.getState() == WebRtcBluetoothManager.State.SCO_DISCONNECTING) {
|
||||||
bluetoothManager.updateDevice();
|
bluetoothManager.updateDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<AudioDevice> newAudioDevices = new HashSet<>();
|
Set<AudioDevice> newAudioDevices = new HashSet<>();
|
||||||
|
|
||||||
if (bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTED
|
if (bluetoothManager.getState() == WebRtcBluetoothManager.State.SCO_CONNECTED
|
||||||
|| bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTING
|
|| bluetoothManager.getState() == WebRtcBluetoothManager.State.SCO_CONNECTING
|
||||||
|| bluetoothManager.getState() == MagicBluetoothManager.State.HEADSET_AVAILABLE) {
|
|| bluetoothManager.getState() == WebRtcBluetoothManager.State.HEADSET_AVAILABLE) {
|
||||||
newAudioDevices.add(AudioDevice.BLUETOOTH);
|
newAudioDevices.add(AudioDevice.BLUETOOTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,7 +446,7 @@ public class MagicAudioManager {
|
|||||||
|
|
||||||
// Correct user selected audio devices if needed.
|
// Correct user selected audio devices if needed.
|
||||||
if (userSelectedAudioDevice == AudioDevice.BLUETOOTH
|
if (userSelectedAudioDevice == AudioDevice.BLUETOOTH
|
||||||
&& bluetoothManager.getState() == MagicBluetoothManager.State.HEADSET_UNAVAILABLE) {
|
&& bluetoothManager.getState() == WebRtcBluetoothManager.State.HEADSET_UNAVAILABLE) {
|
||||||
userSelectedAudioDevice = AudioDevice.SPEAKER_PHONE;
|
userSelectedAudioDevice = AudioDevice.SPEAKER_PHONE;
|
||||||
}
|
}
|
||||||
if (userSelectedAudioDevice == AudioDevice.SPEAKER_PHONE && hasWiredHeadset) {
|
if (userSelectedAudioDevice == AudioDevice.SPEAKER_PHONE && hasWiredHeadset) {
|
||||||
@ -460,21 +460,21 @@ public class MagicAudioManager {
|
|||||||
// Need to start Bluetooth if it is available and user either selected it explicitly or
|
// Need to start Bluetooth if it is available and user either selected it explicitly or
|
||||||
// user did not select any output device.
|
// user did not select any output device.
|
||||||
boolean needBluetoothAudioStart =
|
boolean needBluetoothAudioStart =
|
||||||
bluetoothManager.getState() == MagicBluetoothManager.State.HEADSET_AVAILABLE
|
bluetoothManager.getState() == WebRtcBluetoothManager.State.HEADSET_AVAILABLE
|
||||||
&& (userSelectedAudioDevice == AudioDevice.NONE
|
&& (userSelectedAudioDevice == AudioDevice.NONE
|
||||||
|| userSelectedAudioDevice == AudioDevice.BLUETOOTH);
|
|| userSelectedAudioDevice == AudioDevice.BLUETOOTH);
|
||||||
|
|
||||||
// Need to stop Bluetooth audio if user selected different device and
|
// Need to stop Bluetooth audio if user selected different device and
|
||||||
// Bluetooth SCO connection is established or in the process.
|
// Bluetooth SCO connection is established or in the process.
|
||||||
boolean needBluetoothAudioStop =
|
boolean needBluetoothAudioStop =
|
||||||
(bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTED
|
(bluetoothManager.getState() == WebRtcBluetoothManager.State.SCO_CONNECTED
|
||||||
|| bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTING)
|
|| bluetoothManager.getState() == WebRtcBluetoothManager.State.SCO_CONNECTING)
|
||||||
&& (userSelectedAudioDevice != AudioDevice.NONE
|
&& (userSelectedAudioDevice != AudioDevice.NONE
|
||||||
&& userSelectedAudioDevice != AudioDevice.BLUETOOTH);
|
&& userSelectedAudioDevice != AudioDevice.BLUETOOTH);
|
||||||
|
|
||||||
if (bluetoothManager.getState() == MagicBluetoothManager.State.HEADSET_AVAILABLE
|
if (bluetoothManager.getState() == WebRtcBluetoothManager.State.HEADSET_AVAILABLE
|
||||||
|| bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTING
|
|| bluetoothManager.getState() == WebRtcBluetoothManager.State.SCO_CONNECTING
|
||||||
|| bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTED) {
|
|| bluetoothManager.getState() == WebRtcBluetoothManager.State.SCO_CONNECTED) {
|
||||||
Log.d(TAG, "Need BT audio: start=" + needBluetoothAudioStart + ", "
|
Log.d(TAG, "Need BT audio: start=" + needBluetoothAudioStart + ", "
|
||||||
+ "stop=" + needBluetoothAudioStop + ", "
|
+ "stop=" + needBluetoothAudioStop + ", "
|
||||||
+ "BT state=" + bluetoothManager.getState());
|
+ "BT state=" + bluetoothManager.getState());
|
||||||
@ -499,7 +499,7 @@ public class MagicAudioManager {
|
|||||||
// Update selected audio device.
|
// Update selected audio device.
|
||||||
AudioDevice newCurrentAudioDevice;
|
AudioDevice newCurrentAudioDevice;
|
||||||
|
|
||||||
if (bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTED) {
|
if (bluetoothManager.getState() == WebRtcBluetoothManager.State.SCO_CONNECTED) {
|
||||||
// If a Bluetooth is connected, then it should be used as output audio
|
// If a Bluetooth is connected, then it should be used as output audio
|
||||||
// device. Note that it is not sufficient that a headset is available;
|
// device. Note that it is not sufficient that a headset is available;
|
||||||
// an active SCO channel must also be up and running.
|
// an active SCO channel must also be up and running.
|
@ -58,15 +58,15 @@ import java.util.Set;
|
|||||||
|
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
|
|
||||||
public class MagicBluetoothManager {
|
public class WebRtcBluetoothManager {
|
||||||
private static final String TAG = MagicBluetoothManager.class.getCanonicalName();
|
private static final String TAG = WebRtcBluetoothManager.class.getCanonicalName();
|
||||||
|
|
||||||
// Timeout interval for starting or stopping audio to a Bluetooth SCO device.
|
// Timeout interval for starting or stopping audio to a Bluetooth SCO device.
|
||||||
private static final int BLUETOOTH_SCO_TIMEOUT_MS = 4000;
|
private static final int BLUETOOTH_SCO_TIMEOUT_MS = 4000;
|
||||||
// Maximum number of SCO connection attempts.
|
// Maximum number of SCO connection attempts.
|
||||||
private static final int MAX_SCO_CONNECTION_ATTEMPTS = 2;
|
private static final int MAX_SCO_CONNECTION_ATTEMPTS = 2;
|
||||||
private final Context apprtcContext;
|
private final Context apprtcContext;
|
||||||
private final MagicAudioManager apprtcAudioManager;
|
private final WebRtcAudioManger webRtcAudioManager;
|
||||||
private final AudioManager audioManager;
|
private final AudioManager audioManager;
|
||||||
private final Handler handler;
|
private final Handler handler;
|
||||||
private final BluetoothProfile.ServiceListener bluetoothServiceListener;
|
private final BluetoothProfile.ServiceListener bluetoothServiceListener;
|
||||||
@ -82,11 +82,11 @@ public class MagicBluetoothManager {
|
|||||||
private final Runnable bluetoothTimeoutRunnable = this::bluetoothTimeout;
|
private final Runnable bluetoothTimeoutRunnable = this::bluetoothTimeout;
|
||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
|
|
||||||
protected MagicBluetoothManager(Context context, MagicAudioManager audioManager) {
|
protected WebRtcBluetoothManager(Context context, WebRtcAudioManger audioManager) {
|
||||||
Log.d(TAG, "ctor");
|
Log.d(TAG, "ctor");
|
||||||
ThreadUtils.checkIsOnMainThread();
|
ThreadUtils.checkIsOnMainThread();
|
||||||
apprtcContext = context;
|
apprtcContext = context;
|
||||||
apprtcAudioManager = audioManager;
|
webRtcAudioManager = audioManager;
|
||||||
this.audioManager = getAudioManager(context);
|
this.audioManager = getAudioManager(context);
|
||||||
bluetoothState = State.UNINITIALIZED;
|
bluetoothState = State.UNINITIALIZED;
|
||||||
bluetoothServiceListener = new BluetoothServiceListener();
|
bluetoothServiceListener = new BluetoothServiceListener();
|
||||||
@ -97,8 +97,8 @@ public class MagicBluetoothManager {
|
|||||||
/**
|
/**
|
||||||
* Construction.
|
* Construction.
|
||||||
*/
|
*/
|
||||||
static MagicBluetoothManager create(Context context, MagicAudioManager audioManager) {
|
static WebRtcBluetoothManager create(Context context, WebRtcAudioManger audioManager) {
|
||||||
return new MagicBluetoothManager(context, audioManager);
|
return new WebRtcBluetoothManager(context, audioManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -356,7 +356,7 @@ public class MagicBluetoothManager {
|
|||||||
private void updateAudioDeviceState() {
|
private void updateAudioDeviceState() {
|
||||||
ThreadUtils.checkIsOnMainThread();
|
ThreadUtils.checkIsOnMainThread();
|
||||||
Log.d(TAG, "updateAudioDeviceState");
|
Log.d(TAG, "updateAudioDeviceState");
|
||||||
apprtcAudioManager.updateAudioDeviceState();
|
webRtcAudioManager.updateAudioDeviceState();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
Loading…
Reference in New Issue
Block a user