From 56c1b61e794cd20f01f4a20c1e4d7094eca8bfb8 Mon Sep 17 00:00:00 2001 From: Erik Wolsheimer Date: Mon, 1 Aug 2016 09:18:37 -0700 Subject: [PATCH] Fix potential NPE in BluetoothPairingDialog#onDestroy BUG: 21478473 Change-Id: I8b2b7222f6f17d27cd18a35f83f8d48125ec4091 --- .../settings/bluetooth/BluetoothPairingDialog.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java index ded7e583bbd..b176efde3ba 100755 --- a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java +++ b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java @@ -67,7 +67,7 @@ public final class BluetoothPairingDialog extends AlertActivity implements private EditText mPairingView; private Button mOkButton; private LocalBluetoothProfile mPbapClientProfile; - + private boolean mReceiverRegistered; /** * Dismiss the dialog if the bond state changes to bonded or none, @@ -98,8 +98,7 @@ public final class BluetoothPairingDialog extends AlertActivity implements super.onCreate(savedInstanceState); Intent intent = getIntent(); - if (!intent.getAction().equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) - { + if (!intent.getAction().equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) { Log.e(TAG, "Error: this activity may be started only with intent " + BluetoothDevice.ACTION_PAIRING_REQUEST); finish(); @@ -167,6 +166,7 @@ public final class BluetoothPairingDialog extends AlertActivity implements */ registerReceiver(mReceiver, new IntentFilter(BluetoothDevice.ACTION_PAIRING_CANCEL)); registerReceiver(mReceiver, new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED)); + mReceiverRegistered = true; } private void createUserEntryDialog() { @@ -373,7 +373,10 @@ public final class BluetoothPairingDialog extends AlertActivity implements @Override protected void onDestroy() { super.onDestroy(); - unregisterReceiver(mReceiver); + if (mReceiverRegistered) { + mReceiverRegistered = false; + unregisterReceiver(mReceiver); + } } public void afterTextChanged(Editable s) {