summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/bluetooth/PanProfile.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/settings/bluetooth/PanProfile.java')
-rwxr-xr-x[-rw-r--r--]src/com/android/settings/bluetooth/PanProfile.java37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/com/android/settings/bluetooth/PanProfile.java b/src/com/android/settings/bluetooth/PanProfile.java
index 3db4a2b..b9db77b 100644..100755
--- a/src/com/android/settings/bluetooth/PanProfile.java
+++ b/src/com/android/settings/bluetooth/PanProfile.java
@@ -22,6 +22,7 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
+import android.util.Log;
import com.android.settings.R;
@@ -32,7 +33,11 @@ import java.util.List;
* PanProfile handles Bluetooth PAN profile (NAP and PANU).
*/
final class PanProfile implements LocalBluetoothProfile {
+ private static final String TAG = "PanProfile";
+ private static boolean V = true;
+
private BluetoothPan mService;
+ private boolean mIsProfileReady;
// Tethering direction for each device
private final HashMap<BluetoothDevice, Integer> mDeviceRoleMap =
@@ -48,14 +53,21 @@ final class PanProfile implements LocalBluetoothProfile {
implements BluetoothProfile.ServiceListener {
public void onServiceConnected(int profile, BluetoothProfile proxy) {
+ if (V) Log.d(TAG,"Bluetooth service connected");
mService = (BluetoothPan) proxy;
+ mIsProfileReady=true;
}
public void onServiceDisconnected(int profile) {
- mService = null;
+ if (V) Log.d(TAG,"Bluetooth service disconnected");
+ mIsProfileReady=false;
}
}
+ public boolean isProfileReady() {
+ return mIsProfileReady;
+ }
+
PanProfile(Context context) {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
adapter.getProfileProxy(context, new PanServiceListener(),
@@ -71,6 +83,7 @@ final class PanProfile implements LocalBluetoothProfile {
}
public boolean connect(BluetoothDevice device) {
+ if (mService == null) return false;
List<BluetoothDevice> sinks = mService.getConnectedDevices();
if (sinks != null) {
for (BluetoothDevice sink : sinks) {
@@ -81,10 +94,14 @@ final class PanProfile implements LocalBluetoothProfile {
}
public boolean disconnect(BluetoothDevice device) {
+ if (mService == null) return false;
return mService.disconnect(device);
}
public int getConnectionStatus(BluetoothDevice device) {
+ if (mService == null) {
+ return BluetoothProfile.STATE_DISCONNECTED;
+ }
return mService.getConnectionState(device);
}
@@ -100,10 +117,6 @@ final class PanProfile implements LocalBluetoothProfile {
// ignore: isPreferred is always true for PAN
}
- public boolean isProfileReady() {
- return true;
- }
-
public String toString() {
return NAME;
}
@@ -121,7 +134,7 @@ final class PanProfile implements LocalBluetoothProfile {
}
public int getSummaryResourceForDevice(BluetoothDevice device) {
- int state = mService.getConnectionState(device);
+ int state = getConnectionStatus(device);
switch (state) {
case BluetoothProfile.STATE_DISCONNECTED:
return R.string.bluetooth_pan_profile_summary_use_for;
@@ -154,4 +167,16 @@ final class PanProfile implements LocalBluetoothProfile {
return false;
}
}
+
+ protected void finalize() {
+ if (V) Log.d(TAG, "finalize()");
+ if (mService != null) {
+ try {
+ BluetoothAdapter.getDefaultAdapter().closeProfileProxy(BluetoothProfile.PAN, mService);
+ mService = null;
+ }catch (Throwable t) {
+ Log.w(TAG, "Error cleaning up PAN proxy", t);
+ }
+ }
+ }
}