From d573db5bfc96c3066103ac53987b5741f61da158 Mon Sep 17 00:00:00 2001 From: Antony Sargent Date: Wed, 17 May 2017 15:46:51 -0700 Subject: [PATCH] Fix a race condition in the A2dpProfile constructor When constructing A2dpProfile objects, we were creating an A2dpServiceListener before initializing the mWrapperFactory instance variable that it depended on. If the onServiceConnected callback happens immediately after the listener is created, we'd get a null pointer exception. The fix is to move initialization of mWrapperFactory up before the construction of the A2dpServiceListener. Bug: 38391718 Test: run boot tests Change-Id: Ib0be947099862b19da7737b54b99b944241b605f --- .../src/com/android/settingslib/bluetooth/A2dpProfile.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java index db9f7b8767898..7268d00bade12 100755 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java @@ -101,9 +101,9 @@ public class A2dpProfile implements LocalBluetoothProfile { mLocalAdapter = adapter; mDeviceManager = deviceManager; mProfileManager = profileManager; + mWrapperFactory = new BluetoothA2dpWrapperImpl.Factory(); mLocalAdapter.getProfileProxy(context, new A2dpServiceListener(), BluetoothProfile.A2DP); - mWrapperFactory = new BluetoothA2dpWrapperImpl.Factory(); } @VisibleForTesting