summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothPan.java
diff options
context:
space:
mode:
authorfredc <fredc@broadcom.com>2012-04-24 03:59:57 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-07-16 21:24:32 -0700
commitf1f5dde555c09019c0cedb05e844adf288677bc5 (patch)
tree93b57e8157845e1f6856c92e3c88d44bf1348daf /framework/java/android/bluetooth/BluetoothPan.java
parent797a7ba64e979ce8dff1f87f39521b6e1308e715 (diff)
Fixed issue with Settings app crashing after during on/off and unpair.
Fixed issue with BluetoothAdapter.getRemoteDevice() returning null. Change-Id: Ie86813532530a6b57bde1c430c7b4875ecc7354c
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothPan.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothPan.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/framework/java/android/bluetooth/BluetoothPan.java b/framework/java/android/bluetooth/BluetoothPan.java
index 13d9078752..cae7a73bcf 100644
--- a/framework/java/android/bluetooth/BluetoothPan.java
+++ b/framework/java/android/bluetooth/BluetoothPan.java
@@ -131,6 +131,11 @@ public final class BluetoothPan implements BluetoothProfile {
mContext = context;
mServiceListener = l;
mAdapter = BluetoothAdapter.getDefaultAdapter();
+ try {
+ mAdapter.getBluetoothManager().registerStateChangeCallback(mStateChangeCallback);
+ } catch (RemoteException re) {
+ Log.w(TAG,"Unable to register BluetoothStateChangeCallback",re);
+ }
Log.d(TAG, "BluetoothPan() call bindService");
if (!context.bindService(new Intent(IBluetoothPan.class.getName()),
mConnection, 0)) {
@@ -146,8 +151,43 @@ public final class BluetoothPan implements BluetoothProfile {
mConnection = null;
}
mServiceListener = null;
+ try {
+ mAdapter.getBluetoothManager().unregisterStateChangeCallback(mStateChangeCallback);
+ } catch (RemoteException re) {
+ Log.w(TAG,"Unable to register BluetoothStateChangeCallback",re);
+ }
+ }
+
+ protected void finalize() {
+ close();
}
+ private IBluetoothStateChangeCallback mStateChangeCallback = new IBluetoothStateChangeCallback.Stub() {
+
+ @Override
+ public void onBluetoothStateChange(boolean on) throws RemoteException {
+ //Handle enable request to bind again.
+ if (on) {
+ Log.d(TAG, "onBluetoothStateChange(on) call bindService");
+ if (!mContext.bindService(new Intent(IBluetoothPan.class.getName()),
+ mConnection, 0)) {
+ Log.e(TAG, "Could not bind to Bluetooth HID Service");
+ }
+ Log.d(TAG, "BluetoothPan(), bindService called");
+ } else {
+ if (DBG) Log.d(TAG,"Unbinding service...");
+ synchronized (mConnection) {
+ try {
+ mPanService = null;
+ mContext.unbindService(mConnection);
+ } catch (Exception re) {
+ Log.e(TAG,"",re);
+ }
+ }
+ }
+ }
+ };
+
/**
* Initiate connection to a profile of the remote bluetooth device.
*