diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/WebRtcCallService.java b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/WebRtcCallService.java index c967214765..5061e063dd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/WebRtcCallService.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/WebRtcCallService.java @@ -131,7 +131,6 @@ public final class WebRtcCallService extends Service implements BluetoothStateMa wiredHeadsetStateReceiver = null; } - unregisterNetworkReceiver(); unregisterNetworkReceiver(); TelephonyUtil.getManager(this) diff --git a/app/src/main/java/org/thoughtcrime/securesms/webrtc/audio/BluetoothStateManager.java b/app/src/main/java/org/thoughtcrime/securesms/webrtc/audio/BluetoothStateManager.java index 2794e0783d..9092f5b31d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/webrtc/audio/BluetoothStateManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/webrtc/audio/BluetoothStateManager.java @@ -44,16 +44,22 @@ public class BluetoothStateManager { private boolean wantsConnection = false; public BluetoothStateManager(@NonNull Context context, @Nullable BluetoothStateListener listener) { - this.context = context.getApplicationContext(); - this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); + this.context = context.getApplicationContext(); + + BluetoothAdapter localAdapter = BluetoothAdapter.getDefaultAdapter(); + if (localAdapter == null) { + this.bluetoothAdapter = null; + this.listener = null; + this.destroyed = new AtomicBoolean(true); + return; + } + + this.bluetoothAdapter = localAdapter; this.bluetoothScoReceiver = new BluetoothScoReceiver(); this.bluetoothConnectionReceiver = new BluetoothConnectionReceiver(); this.listener = listener; this.destroyed = new AtomicBoolean(false); - if (this.bluetoothAdapter == null) - return; - requestHeadsetProxyProfile(); this.context.registerReceiver(bluetoothConnectionReceiver, new IntentFilter(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)); @@ -226,7 +232,7 @@ public class BluetoothStateManager { } public interface BluetoothStateListener { - public void onBluetoothStateChanged(boolean isAvailable); + void onBluetoothStateChanged(boolean isAvailable); } }