From d2b033aeb4123ec92892495c262e0272ffb7ecdc Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Thu, 4 Jun 2015 11:46:22 -0700 Subject: [PATCH] Add a missing check for null pointer. There is a race condition when processing intents inside PairingCancelHandler.onReceive() that could trigger NPE. A speculative list of events (untested) that could trigger it: 1. Trigger Pairing Cancel for a Bluetooth device. 2. Turn Off Bluetooth This should call CachedBluetoothDeviceManager.onBluetoothStateChanged() and should remove the device from (1) from the list of cached devices 3. BluetoothEventManager.PairincCancelHander.onReceive() receives an intent about about Pairing Cancel event. Within the processing of that intent, cachedDevice.getName() is called without checking whether cachedDevice is null. In this specific example, cachedDevice could be null because of (2) Bug: 21368124 Change-Id: I86f5d5287b440d1d2e0fe147278b1c2257902e95 --- .../settingslib/bluetooth/BluetoothEventManager.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java index d3e71045c021b..9a2f71c468c5b 100755 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java @@ -348,8 +348,12 @@ public final class BluetoothEventManager { Log.e(TAG, "ACTION_PAIRING_CANCEL with no EXTRA_DEVICE"); return; } - int errorMsg = R.string.bluetooth_pairing_error_message; CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device); + if (cachedDevice == null) { + Log.e(TAG, "ACTION_PAIRING_CANCEL with no cached device"); + return; + } + int errorMsg = R.string.bluetooth_pairing_error_message; Utils.showError(context, cachedDevice.getName(), errorMsg); } }