auto import from //branches/cupcake/...@127101

This commit is contained in:
The Android Open Source Project
2009-01-20 14:04:01 -08:00
parent 1152aff9d0
commit 01f172366c
7 changed files with 43 additions and 66 deletions

View File

@@ -69,26 +69,6 @@ public abstract class LocalBluetoothProfileManager {
return profileManager;
}
// TODO: remove once the framework has this API
public static boolean isPreferredProfile(Context context, String address, Profile profile) {
return getPreferredProfileSharedPreferences(context).getBoolean(
getPreferredProfileKey(address, profile), true);
}
public static void setPreferredProfile(Context context, String address, Profile profile,
boolean preferred) {
getPreferredProfileSharedPreferences(context).edit().putBoolean(
getPreferredProfileKey(address, profile), preferred).commit();
}
private static SharedPreferences getPreferredProfileSharedPreferences(Context context) {
return context.getSharedPreferences("bluetooth_preferred_profiles", Context.MODE_PRIVATE);
}
private static String getPreferredProfileKey(String address, Profile profile) {
return address + "_" + profile.toString();
}
/**
* Temporary method to fill profiles based on a device's class.
*
@@ -98,11 +78,11 @@ public abstract class LocalBluetoothProfileManager {
public static void fill(int btClass, List<Profile> profiles) {
profiles.clear();
if (A2dpProfileManager.doesClassMatch(btClass)) {
if (BluetoothA2dp.doesClassMatchSink(btClass)) {
profiles.add(Profile.A2DP);
}
if (HeadsetProfileManager.doesClassMatch(btClass)) {
if (BluetoothHeadset.doesClassMatch(btClass)) {
profiles.add(Profile.HEADSET);
}
}
@@ -119,6 +99,10 @@ public abstract class LocalBluetoothProfileManager {
public abstract int getSummary(String address);
public abstract boolean isPreferred(String address);
public abstract void setPreferred(String address, boolean preferred);
public boolean isConnected(String address) {
return SettingsBtStatus.isConnectionStatusConnected(getConnectionStatus(address));
}
@@ -156,26 +140,6 @@ public abstract class LocalBluetoothProfileManager {
return mService.disconnectSink(address);
}
static boolean doesClassMatch(int btClass) {
if (BluetoothClass.Service.hasService(btClass, BluetoothClass.Service.RENDER)) {
return true;
}
// By the specification A2DP sinks must indicate the RENDER service
// class, but some do not (Chordette). So match on a few more to be
// safe
switch (BluetoothClass.Device.getDevice(btClass)) {
case BluetoothClass.Device.AUDIO_VIDEO_HIFI_AUDIO:
case BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES:
case BluetoothClass.Device.AUDIO_VIDEO_LOUDSPEAKER:
case BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO:
return true;
default:
return false;
}
}
@Override
public int getConnectionStatus(String address) {
return convertState(mService.getSinkState(address));
@@ -184,7 +148,7 @@ public abstract class LocalBluetoothProfileManager {
@Override
public int getSummary(String address) {
int connectionStatus = getConnectionStatus(address);
if (SettingsBtStatus.isConnectionStatusConnected(connectionStatus)) {
return R.string.bluetooth_a2dp_profile_summary_connected;
} else {
@@ -192,6 +156,17 @@ public abstract class LocalBluetoothProfileManager {
}
}
@Override
public boolean isPreferred(String address) {
return mService.getSinkPriority(address) > BluetoothA2dp.PRIORITY_OFF;
}
@Override
public void setPreferred(String address, boolean preferred) {
mService.setSinkPriority(address,
preferred ? BluetoothA2dp.PRIORITY_AUTO : BluetoothA2dp.PRIORITY_OFF);
}
private static int convertState(int a2dpState) {
switch (a2dpState) {
case BluetoothA2dp.STATE_CONNECTED:
@@ -246,7 +221,7 @@ public abstract class LocalBluetoothProfileManager {
// Since connectHeadset fails if already connected to a headset, we
// disconnect from any headset first
mService.disconnectHeadset();
return mService.connectHeadset(address, null)
return mService.connectHeadset(address)
? BluetoothError.SUCCESS : BluetoothError.ERROR;
}
@@ -259,18 +234,6 @@ public abstract class LocalBluetoothProfileManager {
}
}
static boolean doesClassMatch(int btClass) {
switch (BluetoothClass.Device.getDevice(btClass)) {
case BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE:
case BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET:
case BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO:
return true;
default:
return false;
}
}
@Override
public int getConnectionStatus(String address) {
String headsetAddress = mService.getHeadsetAddress();
@@ -290,6 +253,17 @@ public abstract class LocalBluetoothProfileManager {
}
}
@Override
public boolean isPreferred(String address) {
return mService.getPriority(address) > BluetoothHeadset.PRIORITY_OFF;
}
@Override
public void setPreferred(String address, boolean preferred) {
mService.setPriority(address,
preferred ? BluetoothHeadset.PRIORITY_AUTO : BluetoothHeadset.PRIORITY_OFF);
}
private static int convertState(int headsetState) {
switch (headsetState) {
case BluetoothHeadset.STATE_CONNECTED:
@@ -303,5 +277,4 @@ public abstract class LocalBluetoothProfileManager {
}
}
}
}