Fix crash when bluetooth is unavailable for calling.

This commit is contained in:
Cody Henthorne 2021-04-02 13:09:06 -04:00
parent 9c59d6a69b
commit c4d317b33e
2 changed files with 12 additions and 7 deletions

View file

@ -131,7 +131,6 @@ public final class WebRtcCallService extends Service implements BluetoothStateMa
wiredHeadsetStateReceiver = null;
}
unregisterNetworkReceiver();
unregisterNetworkReceiver();
TelephonyUtil.getManager(this)

View file

@ -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);
}
}