diff options
author | Matthew Xie <mattx@google.com> | 2013-10-10 15:07:22 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-10-10 15:07:22 -0700 |
commit | 0a6d99325ce7b04aa5cf491e20d9558b7535ce79 (patch) | |
tree | d6800eb57d38ffe8736e1a5085011fb6789f7231 /framework/java/android/bluetooth/BluetoothPan.java | |
parent | 9af11bdc92e2621b081d593f771c2da42fe6c935 (diff) | |
parent | 0f86e5e8f227fba40a82dde935ee8d346080c64c (diff) |
am a9a038c2: am bd558e57: am 0f86e5e8: Merge "Check callback null condition for register/unregsiter state change callback" into klp-dev
* commit 'a9a038c275dcc606a92cfe93a9b60a16aae38c4a':
Check callback null condition for register/unregsiter state change callback
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothPan.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothPan.java | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/framework/java/android/bluetooth/BluetoothPan.java b/framework/java/android/bluetooth/BluetoothPan.java index 83d4329e97..b7a37f42b3 100644 --- a/framework/java/android/bluetooth/BluetoothPan.java +++ b/framework/java/android/bluetooth/BluetoothPan.java @@ -155,23 +155,34 @@ public final class BluetoothPan implements BluetoothProfile { /*package*/ void close() { if (VDBG) log("close()"); - if (mConnection != null) { - mContext.unbindService(mConnection); - mConnection = null; + + IBluetoothManager mgr = mAdapter.getBluetoothManager(); + if (mgr != null) { + try { + mgr.unregisterStateChangeCallback(mStateChangeCallback); + } catch (RemoteException re) { + Log.w(TAG,"Unable to unregister BluetoothStateChangeCallback",re); + } } - mServiceListener = null; - try { - mAdapter.getBluetoothManager().unregisterStateChangeCallback(mStateChangeCallback); - } catch (RemoteException re) { - Log.w(TAG,"Unable to register BluetoothStateChangeCallback",re); + + synchronized (mConnection) { + if (mPanService != null) { + try { + mPanService = null; + mContext.unbindService(mConnection); + } catch (Exception re) { + Log.e(TAG,"",re); + } + } } + mServiceListener = null; } protected void finalize() { close(); } - private IBluetoothStateChangeCallback mStateChangeCallback = new IBluetoothStateChangeCallback.Stub() { + final private IBluetoothStateChangeCallback mStateChangeCallback = new IBluetoothStateChangeCallback.Stub() { @Override public void onBluetoothStateChange(boolean on) throws RemoteException { @@ -339,7 +350,7 @@ public final class BluetoothPan implements BluetoothProfile { return false; } - private ServiceConnection mConnection = new ServiceConnection() { + private final ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { if (DBG) Log.d(TAG, "BluetoothPAN Proxy object connected"); mPanService = IBluetoothPan.Stub.asInterface(service); |