am bd558e57: am 64be26fa: Merge "Check callback null condition for register/unregsiter state change callback" into klp-dev

* commit 'bd558e575cf18149def637697c67af3c951ac8bd':
  Check callback null condition for register/unregsiter state change callback
This commit is contained in:
Matthew Xie
2013-10-10 15:04:40 -07:00
committed by Android Git Automerger
8 changed files with 33 additions and 20 deletions

View File

@@ -513,7 +513,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
}
}
private ServiceConnection mConnection = new ServiceConnection() {
private final ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
if (DBG) Log.d(TAG, "Proxy object connected");
mService = IBluetoothA2dp.Stub.asInterface(service);

View File

@@ -885,7 +885,7 @@ public final class BluetoothHeadset 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, "Proxy object connected");
mService = IBluetoothHeadset.Stub.asInterface(service);

View File

@@ -519,7 +519,7 @@ public final class BluetoothHealth implements BluetoothProfile {
mServiceListener = null;
}
private ServiceConnection mConnection = new ServiceConnection() {
private final ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
if (DBG) Log.d(TAG, "Proxy object connected");
mService = IBluetoothHealth.Stub.asInterface(service);

View File

@@ -458,7 +458,7 @@ public final class BluetoothInputDevice implements BluetoothProfile {
return BluetoothProfile.PRIORITY_OFF;
}
private ServiceConnection mConnection = new ServiceConnection() {
private final ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
if (DBG) Log.d(TAG, "Proxy object connected");
mService = IBluetoothInputDevice.Stub.asInterface(service);

View File

@@ -142,7 +142,6 @@ public final class BluetoothMap implements BluetoothProfile {
try {
mService = null;
mContext.unbindService(mConnection);
mConnection = null;
} catch (Exception re) {
Log.e(TAG,"",re);
}
@@ -370,7 +369,7 @@ public final class BluetoothMap implements BluetoothProfile {
return PRIORITY_OFF;
}
private ServiceConnection mConnection = new ServiceConnection() {
private final ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
if (DBG) log("Proxy object connected");
mService = IBluetoothMap.Stub.asInterface(service);

View File

@@ -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);
}
}
synchronized (mConnection) {
if (mPanService != null) {
try {
mPanService = null;
mContext.unbindService(mConnection);
} catch (Exception re) {
Log.e(TAG,"",re);
}
}
}
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() {
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);

View File

@@ -197,7 +197,6 @@ public class BluetoothPbap {
try {
mService = null;
mContext.unbindService(mConnection);
mConnection = null;
} catch (Exception re) {
Log.e(TAG,"",re);
}
@@ -300,7 +299,7 @@ public class BluetoothPbap {
}
}
private ServiceConnection mConnection = new ServiceConnection() {
private final ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
if (DBG) log("Proxy object connected");
mService = IBluetoothPbap.Stub.asInterface(service);

View File

@@ -766,13 +766,17 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
case MESSAGE_REGISTER_STATE_CHANGE_CALLBACK:
{
IBluetoothStateChangeCallback callback = (IBluetoothStateChangeCallback) msg.obj;
mStateChangeCallbacks.register(callback);
if (callback != null) {
mStateChangeCallbacks.register(callback);
}
break;
}
case MESSAGE_UNREGISTER_STATE_CHANGE_CALLBACK:
{
IBluetoothStateChangeCallback callback = (IBluetoothStateChangeCallback) msg.obj;
mStateChangeCallbacks.unregister(callback);
if (callback != null) {
mStateChangeCallbacks.unregister(callback);
}
break;
}
case MESSAGE_BLUETOOTH_SERVICE_CONNECTED: