b/2138890 Pre-initilize Bluetooth profile managers
Change-Id: I633202457ca445308ec35b99260e603a85451042
This commit is contained in:
@@ -79,6 +79,8 @@ public class LocalBluetoothManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LocalBluetoothProfileManager.init(INSTANCE);
|
||||||
|
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ import android.bluetooth.BluetoothHeadset;
|
|||||||
import android.bluetooth.BluetoothUuid;
|
import android.bluetooth.BluetoothUuid;
|
||||||
import android.bluetooth.ParcelUuid;
|
import android.bluetooth.ParcelUuid;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
@@ -57,35 +58,36 @@ public abstract class LocalBluetoothProfileManager {
|
|||||||
|
|
||||||
protected LocalBluetoothManager mLocalManager;
|
protected LocalBluetoothManager mLocalManager;
|
||||||
|
|
||||||
public static LocalBluetoothProfileManager getProfileManager(LocalBluetoothManager localManager,
|
public static void init(LocalBluetoothManager localManager) {
|
||||||
Profile profile) {
|
synchronized (sProfileMap) {
|
||||||
|
if (sProfileMap.size() == 0) {
|
||||||
LocalBluetoothProfileManager profileManager;
|
LocalBluetoothProfileManager profileManager;
|
||||||
|
|
||||||
synchronized (sProfileMap) {
|
|
||||||
profileManager = sProfileMap.get(profile);
|
|
||||||
|
|
||||||
if (profileManager == null) {
|
|
||||||
switch (profile) {
|
|
||||||
case A2DP:
|
|
||||||
profileManager = new A2dpProfileManager(localManager);
|
profileManager = new A2dpProfileManager(localManager);
|
||||||
break;
|
sProfileMap.put(Profile.A2DP, profileManager);
|
||||||
|
|
||||||
case HEADSET:
|
|
||||||
profileManager = new HeadsetProfileManager(localManager);
|
profileManager = new HeadsetProfileManager(localManager);
|
||||||
break;
|
sProfileMap.put(Profile.HEADSET, profileManager);
|
||||||
|
|
||||||
case OPP:
|
|
||||||
profileManager = new OppProfileManager(localManager);
|
profileManager = new OppProfileManager(localManager);
|
||||||
break;
|
sProfileMap.put(Profile.OPP, profileManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
sProfileMap.put(profile, 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;
|
return profileManager;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Temporary method to fill profiles based on a device's class.
|
* Temporary method to fill profiles based on a device's class.
|
||||||
|
Reference in New Issue
Block a user