From e51972868cf6645d8bc3023496e2af68272d7a35 Mon Sep 17 00:00:00 2001 From: Jack He Date: Tue, 1 Nov 2016 15:38:38 -0700 Subject: [PATCH] Fix Bluetooth pairing dialogue crash When pairing passkey is invalid, onCreate() should return early to prevent any dialog from displaying, which will then call onDestroy() to destroy the activity. However mReceiver should be registered before onDestroy() is called as onDestroy() will call unregisterReceiver(mReceiver) that will throw an IllegalArgumentException when mReceiver was not registered. This fix adds a flag that tracks whether mReceiver has been registered. In addition, this fix fails the passkey confirmation request upon invalid passkey. Bug: 32577328 Test: Test with PTS TC_SERVER_SA_BI_01_C Change-Id: Ifc047bad6bd99abca04404af9cd54d2034cd35aa (cherry picked from commit 6f8e9eda2d9ed830d47971d93327792906db2dc1) --- .../android/settings/bluetooth/BluetoothPairingDialog.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java index b176efde3ba..300451d90fd 100755 --- a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java +++ b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java @@ -96,6 +96,7 @@ public final class BluetoothPairingDialog extends AlertActivity implements @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mReceiverRegistered = false; Intent intent = getIntent(); if (!intent.getAction().equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) { @@ -129,6 +130,8 @@ public final class BluetoothPairingDialog extends AlertActivity implements intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY, BluetoothDevice.ERROR); if (passkey == BluetoothDevice.ERROR) { Log.e(TAG, "Invalid Confirmation Passkey received, not showing any dialog"); + mDevice.setPairingConfirmation(false); + finish(); return; } mPairingKey = String.format(Locale.US, "%06d", passkey); @@ -146,6 +149,7 @@ public final class BluetoothPairingDialog extends AlertActivity implements intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY, BluetoothDevice.ERROR); if (pairingKey == BluetoothDevice.ERROR) { Log.e(TAG, "Invalid Confirmation Passkey or PIN received, not showing any dialog"); + finish(); return; } if (mType == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY) { @@ -158,6 +162,8 @@ public final class BluetoothPairingDialog extends AlertActivity implements default: Log.e(TAG, "Incorrect pairing type received, not showing any dialog"); + finish(); + return; } /*