Merge "Check callback null condition for register/unregsiter state change callback" into klp-dev

This commit is contained in:
Matthew Xie
2013-10-10 21:56:19 +00:00
committed by Android (Google) Code Review
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) { public void onServiceConnected(ComponentName className, IBinder service) {
if (DBG) Log.d(TAG, "Proxy object connected"); if (DBG) Log.d(TAG, "Proxy object connected");
mService = IBluetoothA2dp.Stub.asInterface(service); mService = IBluetoothA2dp.Stub.asInterface(service);

View File

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

View File

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

View File

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

View File

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

View File

@@ -155,23 +155,34 @@ public final class BluetoothPan implements BluetoothProfile {
/*package*/ void close() { /*package*/ void close() {
if (VDBG) log("close()"); if (VDBG) log("close()");
if (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); mContext.unbindService(mConnection);
mConnection = null; } catch (Exception re) {
Log.e(TAG,"",re);
}
}
} }
mServiceListener = null; mServiceListener = null;
try {
mAdapter.getBluetoothManager().unregisterStateChangeCallback(mStateChangeCallback);
} catch (RemoteException re) {
Log.w(TAG,"Unable to register BluetoothStateChangeCallback",re);
}
} }
protected void finalize() { protected void finalize() {
close(); close();
} }
private IBluetoothStateChangeCallback mStateChangeCallback = new IBluetoothStateChangeCallback.Stub() { final private IBluetoothStateChangeCallback mStateChangeCallback = new IBluetoothStateChangeCallback.Stub() {
@Override @Override
public void onBluetoothStateChange(boolean on) throws RemoteException { public void onBluetoothStateChange(boolean on) throws RemoteException {
@@ -339,7 +350,7 @@ public final class BluetoothPan implements BluetoothProfile {
return false; return false;
} }
private ServiceConnection mConnection = new ServiceConnection() { private final ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) { public void onServiceConnected(ComponentName className, IBinder service) {
if (DBG) Log.d(TAG, "BluetoothPAN Proxy object connected"); if (DBG) Log.d(TAG, "BluetoothPAN Proxy object connected");
mPanService = IBluetoothPan.Stub.asInterface(service); mPanService = IBluetoothPan.Stub.asInterface(service);

View File

@@ -197,7 +197,6 @@ public class BluetoothPbap {
try { try {
mService = null; mService = null;
mContext.unbindService(mConnection); mContext.unbindService(mConnection);
mConnection = null;
} catch (Exception re) { } catch (Exception re) {
Log.e(TAG,"",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) { public void onServiceConnected(ComponentName className, IBinder service) {
if (DBG) log("Proxy object connected"); if (DBG) log("Proxy object connected");
mService = IBluetoothPbap.Stub.asInterface(service); mService = IBluetoothPbap.Stub.asInterface(service);

View File

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