mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Ignore events after BluetoothStateManager is destroyed.
Fixes crash.
This commit is contained in:
parent
ae9c53bdf8
commit
76054a9e33
@ -19,6 +19,7 @@ import org.thoughtcrime.securesms.logging.Log;
|
|||||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class BluetoothStateManager {
|
public class BluetoothStateManager {
|
||||||
|
|
||||||
@ -37,6 +38,7 @@ public class BluetoothStateManager {
|
|||||||
private BluetoothScoReceiver bluetoothScoReceiver;
|
private BluetoothScoReceiver bluetoothScoReceiver;
|
||||||
private BluetoothConnectionReceiver bluetoothConnectionReceiver;
|
private BluetoothConnectionReceiver bluetoothConnectionReceiver;
|
||||||
private final BluetoothStateListener listener;
|
private final BluetoothStateListener listener;
|
||||||
|
private final AtomicBoolean destroyed;
|
||||||
|
|
||||||
private BluetoothHeadset bluetoothHeadset = null;
|
private BluetoothHeadset bluetoothHeadset = null;
|
||||||
private ScoConnection scoConnection = ScoConnection.DISCONNECTED;
|
private ScoConnection scoConnection = ScoConnection.DISCONNECTED;
|
||||||
@ -48,6 +50,7 @@ public class BluetoothStateManager {
|
|||||||
this.bluetoothScoReceiver = new BluetoothScoReceiver();
|
this.bluetoothScoReceiver = new BluetoothScoReceiver();
|
||||||
this.bluetoothConnectionReceiver = new BluetoothConnectionReceiver();
|
this.bluetoothConnectionReceiver = new BluetoothConnectionReceiver();
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
|
this.destroyed = new AtomicBoolean(false);
|
||||||
|
|
||||||
if (this.bluetoothAdapter == null)
|
if (this.bluetoothAdapter == null)
|
||||||
return;
|
return;
|
||||||
@ -66,6 +69,8 @@ public class BluetoothStateManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
|
destroyed.set(true);
|
||||||
|
|
||||||
if (bluetoothHeadset != null && bluetoothAdapter != null) {
|
if (bluetoothHeadset != null && bluetoothAdapter != null) {
|
||||||
this.bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, bluetoothHeadset);
|
this.bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, bluetoothHeadset);
|
||||||
}
|
}
|
||||||
@ -137,6 +142,11 @@ public class BluetoothStateManager {
|
|||||||
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
|
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||||
|
if (destroyed.get()) {
|
||||||
|
Log.w(TAG, "Got bluetooth profile event after the service was destroyed. Ignoring.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (profile == BluetoothProfile.HEADSET) {
|
if (profile == BluetoothProfile.HEADSET) {
|
||||||
synchronized (LOCK) {
|
synchronized (LOCK) {
|
||||||
bluetoothHeadset = (BluetoothHeadset) proxy;
|
bluetoothHeadset = (BluetoothHeadset) proxy;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user