Make BluetoothPan inherit from BluetoothProfile.
Change-Id: Ibd3e24e391be93ebe2cf975bd075efb68e10c1ff
diff --git a/core/java/android/bluetooth/BluetoothTetheringDataTracker.java b/core/java/android/bluetooth/BluetoothTetheringDataTracker.java
index aa1adcb..c08f14f 100644
--- a/core/java/android/bluetooth/BluetoothTetheringDataTracker.java
+++ b/core/java/android/bluetooth/BluetoothTetheringDataTracker.java
@@ -96,17 +96,32 @@
public void startMonitoring(Context context, Handler target) {
mContext = context;
mCsHandler = target;
- mBluetoothPan = new BluetoothPan(mContext);
+ BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+ if (adapter != null) {
+ adapter.getProfileProxy(mContext, mProfileServiceListener, BluetoothProfile.PAN);
+ }
}
+ private BluetoothProfile.ServiceListener mProfileServiceListener =
+ new BluetoothProfile.ServiceListener() {
+ public void onServiceConnected(int profile, BluetoothProfile proxy) {
+ mBluetoothPan = (BluetoothPan) proxy;
+ }
+ public void onServiceDisconnected(int profile) {
+ mBluetoothPan = null;
+ }
+ };
+
/**
* Disable connectivity to a network
* TODO: do away with return value after making MobileDataStateTracker async
*/
public boolean teardown() {
mTeardownRequested.set(true);
- for (BluetoothDevice device: mBluetoothPan.getConnectedDevices()) {
- mBluetoothPan.disconnect(device);
+ if (mBluetoothPan != null) {
+ for (BluetoothDevice device: mBluetoothPan.getConnectedDevices()) {
+ mBluetoothPan.disconnect(device);
+ }
}
return true;
}