update CompanionDevice Bluetooth bonding

pull/373/head
andrekir 2022-02-12 18:55:42 -03:00
rodzic 875c1542ea
commit 0f3135978c
1 zmienionych plików z 10 dodań i 8 usunięć

Wyświetl plik

@ -883,7 +883,6 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
deviceManager.associate( deviceManager.associate(
pairingRequest, pairingRequest,
object : CompanionDeviceManager.Callback() { object : CompanionDeviceManager.Callback() {
override fun onDeviceFound(chooserLauncher: IntentSender) { override fun onDeviceFound(chooserLauncher: IntentSender) {
debug("Found one device - enabling changeRadioButton") debug("Found one device - enabling changeRadioButton")
binding.changeRadioButton.isEnabled = true binding.changeRadioButton.isEnabled = true
@ -914,8 +913,6 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
updateDevicesButtons(devices) updateDevicesButtons(devices)
startCompanionScan() startCompanionScan()
} }
startCompanionScan()
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -1041,17 +1038,22 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
} }
} }
@SuppressLint("MissingPermission")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O if (hasCompanionDeviceApi && myActivity.hasConnectPermission()
&& requestCode == MainActivity.SELECT_DEVICE_REQUEST_CODE && requestCode == MainActivity.SELECT_DEVICE_REQUEST_CODE
&& resultCode == Activity.RESULT_OK && resultCode == Activity.RESULT_OK
) { ) {
val deviceToPair: BluetoothDevice = val deviceToPair: BluetoothDevice =
data?.getParcelableExtra(CompanionDeviceManager.EXTRA_DEVICE)!! data?.getParcelableExtra(CompanionDeviceManager.EXTRA_DEVICE)!!
if (deviceToPair.bondState != BOND_BONDED) { scanModel.onSelected(
deviceToPair.createBond() myActivity,
} BTScanModel.DeviceListEntry(
scanModel.changeScanSelection(myActivity, "x${deviceToPair.address}") deviceToPair.name,
"x${deviceToPair.address}",
deviceToPair.bondState == BOND_BONDED
)
)
} else { } else {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
} }