Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Support Manual Pairing Code #25333

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Modify some errors
joonhaengHeo committed Mar 1, 2023
commit e656ea9013e329e2def9fdbf5f6c51c509c823ae
Original file line number Diff line number Diff line change
@@ -43,18 +43,18 @@ class BluetoothManager : BleCallback {
.toByteArray()
}

private fun getServiceDataMask(isManualPairingMode: Boolean): ByteArray {
val manualPairingMask = when(isManualPairingMode) {
private fun getServiceDataMask(isShortDiscriminator: Boolean): ByteArray {
val shortDiscriminatorMask = when(isShortDiscriminator) {
true -> 0x00 false -> 0xff
}
return intArrayOf(0xff, manualPairingMask, 0xff).map { it.toByte() }.toByteArray()
return intArrayOf(0xff, shortDiscriminatorMask, 0xff).map { it.toByte() }.toByteArray()
}

suspend fun getBluetoothDevice(context: Context, discriminator: Int): BluetoothDevice? {
return getBluetoothDevice(context, discriminator, false)
}

suspend fun getBluetoothDevice(context: Context, discriminator: Int, isManualPairingMode: Boolean): BluetoothDevice? {
suspend fun getBluetoothDevice(context: Context, discriminator: Int, isShortDiscriminator: Boolean): BluetoothDevice? {
if (! bluetoothAdapter.isEnabled) {
bluetoothAdapter.enable();
}
@@ -85,7 +85,7 @@ class BluetoothManager : BleCallback {
}

val serviceData = getServiceData(discriminator)
val serviceDataMask = getServiceDataMask(isManualPairingMode)
val serviceDataMask = getServiceDataMask(isShortDiscriminator)

val scanFilter =
ScanFilter.Builder()
Original file line number Diff line number Diff line change
@@ -183,13 +183,13 @@ class BarcodeFragment : Fragment() {

private fun handleInputQrCode(qrCode: String) {
lateinit var payload: SetupPayload
var isManualPairingCode = false
var isShortDiscriminator = false
try {
payload = SetupPayloadParser().parseQrCode(qrCode)
} catch (ex: SetupPayloadException) {
try {
payload = SetupPayloadParser().parseManualEntryCode(qrCode)
isManualPairingCode = true
isShortDiscriminator = true
} catch (ex: Exception) {
Log.e(TAG, "Unrecognized Manual Pairing Code", ex)
Toast.makeText(requireContext(), "Unrecognized Manual Pairing Code", Toast.LENGTH_SHORT).show()
@@ -199,7 +199,7 @@ class BarcodeFragment : Fragment() {
Toast.makeText(requireContext(), "Unrecognized QR Code", Toast.LENGTH_SHORT).show()
}
FragmentUtil.getHost(this@BarcodeFragment, Callback::class.java)
?.onCHIPDeviceInfoReceived(CHIPDeviceInfo.fromSetupPayload(payload))
?.onCHIPDeviceInfoReceived(CHIPDeviceInfo.fromSetupPayload(payload, isShortDiscriminator))
}

private fun handleScannedQrCode(barcode: Barcode) {