From f2f3ceebbdf724e8904712a2a21cb0e677b7ea0d Mon Sep 17 00:00:00 2001 From: Michael Chan Date: Thu, 24 Sep 2009 07:45:49 -0700 Subject: [PATCH] b/2138890 Pre-initilize Bluetooth profile managers Change-Id: I633202457ca445308ec35b99260e603a85451042 --- .../bluetooth/LocalBluetoothManager.java | 2 + .../LocalBluetoothProfileManager.java | 44 ++++++++++--------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/com/android/settings/bluetooth/LocalBluetoothManager.java b/src/com/android/settings/bluetooth/LocalBluetoothManager.java index 775b1208a03..e7be43df58b 100644 --- a/src/com/android/settings/bluetooth/LocalBluetoothManager.java +++ b/src/com/android/settings/bluetooth/LocalBluetoothManager.java @@ -79,6 +79,8 @@ public class LocalBluetoothManager { return null; } + LocalBluetoothProfileManager.init(INSTANCE); + return INSTANCE; } } diff --git a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java index 2f8fbe3c78a..f3dea8592f7 100644 --- a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java +++ b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java @@ -22,6 +22,7 @@ import android.bluetooth.BluetoothHeadset; import android.bluetooth.BluetoothUuid; import android.bluetooth.ParcelUuid; import android.os.Handler; +import android.util.Log; import com.android.settings.R; @@ -57,34 +58,35 @@ public abstract class LocalBluetoothProfileManager { protected LocalBluetoothManager mLocalManager; - public static LocalBluetoothProfileManager getProfileManager(LocalBluetoothManager localManager, - Profile profile) { - - LocalBluetoothProfileManager profileManager; - + public static void init(LocalBluetoothManager localManager) { synchronized (sProfileMap) { - profileManager = sProfileMap.get(profile); + if (sProfileMap.size() == 0) { + LocalBluetoothProfileManager profileManager; - if (profileManager == null) { - switch (profile) { - case A2DP: - profileManager = new A2dpProfileManager(localManager); - break; + profileManager = new A2dpProfileManager(localManager); + sProfileMap.put(Profile.A2DP, profileManager); - case HEADSET: - profileManager = new HeadsetProfileManager(localManager); - break; + profileManager = new HeadsetProfileManager(localManager); + sProfileMap.put(Profile.HEADSET, profileManager); - case OPP: - profileManager = new OppProfileManager(localManager); - break; - } - - sProfileMap.put(profile, profileManager); + profileManager = new OppProfileManager(localManager); + sProfileMap.put(Profile.OPP, profileManager); } } + } - return profileManager; + public static LocalBluetoothProfileManager getProfileManager(LocalBluetoothManager localManager, + Profile profile) { + // Note: This code assumes that "localManager" is same as the + // LocalBluetoothManager that was used to initialize the sProfileMap. + // If that every changes, we can't just keep one copy of sProfileMap. + synchronized (sProfileMap) { + LocalBluetoothProfileManager profileManager = sProfileMap.get(profile); + if (profileManager == null) { + Log.e(TAG, "profileManager can't be found for " + profile.toString()); + } + return profileManager; + } } /**