Merge "Add @Nullable to BluetoothAdapter provider." into tm-qpr-dev

This commit is contained in:
Vania Januar
2023-01-03 09:21:24 +00:00
committed by Android (Google) Code Review
2 changed files with 4 additions and 3 deletions

View File

@@ -636,6 +636,7 @@ public class FrameworkServicesModule {
@Provides @Provides
@Singleton @Singleton
@Nullable
static BluetoothAdapter provideBluetoothAdapter(BluetoothManager bluetoothManager) { static BluetoothAdapter provideBluetoothAdapter(BluetoothManager bluetoothManager) {
return bluetoothManager.getAdapter(); return bluetoothManager.getAdapter();
} }

View File

@@ -38,7 +38,7 @@ class StylusManager
@Inject @Inject
constructor( constructor(
private val inputManager: InputManager, private val inputManager: InputManager,
private val bluetoothAdapter: BluetoothAdapter, private val bluetoothAdapter: BluetoothAdapter?,
@Background private val handler: Handler, @Background private val handler: Handler,
@Background private val executor: Executor, @Background private val executor: Executor,
) : InputManager.InputDeviceListener, BluetoothAdapter.OnMetadataChangedListener { ) : InputManager.InputDeviceListener, BluetoothAdapter.OnMetadataChangedListener {
@@ -141,7 +141,7 @@ constructor(
} }
private fun onStylusBluetoothConnected(btAddress: String) { private fun onStylusBluetoothConnected(btAddress: String) {
val device: BluetoothDevice = bluetoothAdapter.getRemoteDevice(btAddress) ?: return val device: BluetoothDevice = bluetoothAdapter?.getRemoteDevice(btAddress) ?: return
try { try {
bluetoothAdapter.addOnMetadataChangedListener(device, executor, this) bluetoothAdapter.addOnMetadataChangedListener(device, executor, this)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
@@ -150,7 +150,7 @@ constructor(
} }
private fun onStylusBluetoothDisconnected(btAddress: String) { private fun onStylusBluetoothDisconnected(btAddress: String) {
val device: BluetoothDevice = bluetoothAdapter.getRemoteDevice(btAddress) ?: return val device: BluetoothDevice = bluetoothAdapter?.getRemoteDevice(btAddress) ?: return
try { try {
bluetoothAdapter.removeOnMetadataChangedListener(device, this) bluetoothAdapter.removeOnMetadataChangedListener(device, this)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {