Make BluetoothPan implement BluetoothProfile.

This makes it consistent across all other profiles.

Change-Id: I4c0694d042d7ed1b78c92ca3be38c8d543886769
This commit is contained in:
Jaikumar Ganesh
2011-02-23 13:08:09 -08:00
parent 77bcd7e807
commit 9ad703cdb9
3 changed files with 36 additions and 10 deletions

View File

@@ -23,6 +23,7 @@ import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothPan; import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@@ -88,7 +89,12 @@ public class TetherSettings extends SettingsPreferenceFragment {
addPreferencesFromResource(R.xml.tether_prefs); addPreferencesFromResource(R.xml.tether_prefs);
final Activity activity = getActivity(); final Activity activity = getActivity();
mBluetoothPan = new BluetoothPan(activity); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
adapter.getProfileProxy(activity.getApplicationContext(), mProfileServiceListener,
BluetoothProfile.PAN);
}
mEnableWifiAp = (CheckBoxPreference) findPreference(ENABLE_WIFI_AP); mEnableWifiAp = (CheckBoxPreference) findPreference(ENABLE_WIFI_AP);
mWifiApSettings = (PreferenceScreen) findPreference(WIFI_AP_SETTINGS); mWifiApSettings = (PreferenceScreen) findPreference(WIFI_AP_SETTINGS);
@@ -119,7 +125,7 @@ public class TetherSettings extends SettingsPreferenceFragment {
if (!bluetoothAvailable) { if (!bluetoothAvailable) {
getPreferenceScreen().removePreference(mBluetoothTether); getPreferenceScreen().removePreference(mBluetoothTether);
} else { } else {
if (mBluetoothPan.isTetheringOn()) { if (mBluetoothPan != null && mBluetoothPan.isTetheringOn()) {
mBluetoothTether.setChecked(true); mBluetoothTether.setChecked(true);
} else { } else {
mBluetoothTether.setChecked(false); mBluetoothTether.setChecked(false);
@@ -130,6 +136,16 @@ public class TetherSettings extends SettingsPreferenceFragment {
mView = new WebView(activity); mView = new WebView(activity);
} }
private BluetoothProfile.ServiceListener mProfileServiceListener =
new BluetoothProfile.ServiceListener() {
public void onServiceConnected(int profile, BluetoothProfile proxy) {
mBluetoothPan = (BluetoothPan) proxy;
}
public void onServiceDisconnected(int profile) {
mBluetoothPan = null;
}
};
@Override @Override
public Dialog onCreateDialog(int id) { public Dialog onCreateDialog(int id) {
if (id == DIALOG_TETHER_HELP) { if (id == DIALOG_TETHER_HELP) {

View File

@@ -139,14 +139,14 @@ class BluetoothEventRedirector {
mManager.getCachedDeviceManager().onProfileStateChanged(device, mManager.getCachedDeviceManager().onProfileStateChanged(device,
Profile.HID, newState); Profile.HID, newState);
} else if (action.equals(BluetoothPan.ACTION_PAN_STATE_CHANGED)) { } else if (action.equals(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED)) {
final int role = intent.getIntExtra( final int role = intent.getIntExtra(
BluetoothPan.EXTRA_LOCAL_ROLE, 0); BluetoothPan.EXTRA_LOCAL_ROLE, 0);
if (role == BluetoothPan.LOCAL_PANU_ROLE) { if (role == BluetoothPan.LOCAL_PANU_ROLE) {
final int newState = intent.getIntExtra( final int newState = intent.getIntExtra(
BluetoothPan.EXTRA_PAN_STATE, 0); BluetoothPan.EXTRA_STATE, 0);
final int oldState = intent.getIntExtra( final int oldState = intent.getIntExtra(
BluetoothPan.EXTRA_PREVIOUS_PAN_STATE, 0); BluetoothPan.EXTRA_PREVIOUS_STATE, 0);
if (newState == BluetoothPan.STATE_DISCONNECTED && if (newState == BluetoothPan.STATE_DISCONNECTED &&
oldState == BluetoothPan.STATE_CONNECTING) { oldState == BluetoothPan.STATE_CONNECTING) {
Log.i(TAG, "Failed to connect BT PAN"); Log.i(TAG, "Failed to connect BT PAN");
@@ -199,7 +199,7 @@ class BluetoothEventRedirector {
filter.addAction(BluetoothDevice.ACTION_PAIRING_CANCEL); filter.addAction(BluetoothDevice.ACTION_PAIRING_CANCEL);
// Fine-grained state broadcasts // Fine-grained state broadcasts
filter.addAction(BluetoothPan.ACTION_PAN_STATE_CHANGED); filter.addAction(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED);
filter.addAction(BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED);
filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);

View File

@@ -736,12 +736,22 @@ abstract class LocalBluetoothProfileManager {
} }
} }
private static class PanProfileManager extends LocalBluetoothProfileManager { private static class PanProfileManager extends LocalBluetoothProfileManager
private final BluetoothPan mService; implements BluetoothProfile.ServiceListener {
private BluetoothPan mService;
public PanProfileManager(LocalBluetoothManager localManager) { public PanProfileManager(LocalBluetoothManager localManager) {
super(localManager); super(localManager);
mService = new BluetoothPan(localManager.getContext()); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
adapter.getProfileProxy(localManager.getContext(), this, BluetoothProfile.PAN);
}
public void onServiceConnected(int profile, BluetoothProfile proxy) {
mService = (BluetoothPan) proxy;
}
public void onServiceDisconnected(int profile) {
mService = null;
} }
@Override @Override
@@ -799,7 +809,7 @@ abstract class LocalBluetoothProfileManager {
@Override @Override
public int getConnectionStatus(BluetoothDevice device) { public int getConnectionStatus(BluetoothDevice device) {
return convertState(mService.getPanDeviceState(device)); return convertState(mService.getConnectionState(device));
} }
@Override @Override