Fix NPE force close if disabling BT feature

adapter can be null in some SPs which disable bluetooth feature
from framework, so it will lead to NPE force close in these SPs.

Add null check for adapter.

Bug: 345584461

Change-Id: I3fabe94a97cc9baf7b1739fe1c9160a52b50d7d4
This commit is contained in:
hoffc
2024-06-07 10:33:27 +08:00
parent ce2a5e07e2
commit de3f413ecd

View File

@@ -72,7 +72,7 @@ class TetheredRepository(private val context: Context) {
flowOf(null), // kick an initial value flowOf(null), // kick an initial value
context.broadcastReceiverFlow(IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)), context.broadcastReceiverFlow(IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)),
).flatMapLatest { ).flatMapLatest {
if (adapter.getState() == BluetoothAdapter.STATE_ON) { if (adapter?.getState() == BluetoothAdapter.STATE_ON) {
isBluetoothPanTetheringOnFlow() isBluetoothPanTetheringOnFlow()
} else { } else {
flowOf(false) flowOf(false)
@@ -93,10 +93,10 @@ class TetheredRepository(private val context: Context) {
override fun onServiceDisconnected(profile: Int) {} override fun onServiceDisconnected(profile: Int) {}
} }
adapter.getProfileProxy(context, listener, BluetoothProfile.PAN) adapter?.getProfileProxy(context, listener, BluetoothProfile.PAN)
awaitClose { awaitClose {
connectedProxy?.let { adapter.closeProfileProxy(BluetoothProfile.PAN, it) } connectedProxy?.let { adapter?.closeProfileProxy(BluetoothProfile.PAN, it) }
} }
}.conflate().flowOn(Dispatchers.Default) }.conflate().flowOn(Dispatchers.Default)
} }