Merge "Add missing "try ... finally" safeguards" into nyc-dev

This commit is contained in:
TreeHugger Robot
2016-05-25 00:09:28 +00:00
committed by Android (Google) Code Review
2 changed files with 29 additions and 20 deletions

View File

@@ -2045,12 +2045,15 @@ public final class BluetoothAdapter {
public void onBluetoothServiceDown() { public void onBluetoothServiceDown() {
if (VDBG) Log.d(TAG, "onBluetoothServiceDown: " + mService); if (VDBG) Log.d(TAG, "onBluetoothServiceDown: " + mService);
try {
mServiceLock.writeLock().lock(); mServiceLock.writeLock().lock();
mService = null; mService = null;
if (mLeScanClients != null) mLeScanClients.clear(); if (mLeScanClients != null) mLeScanClients.clear();
if (sBluetoothLeAdvertiser != null) sBluetoothLeAdvertiser.cleanup(); if (sBluetoothLeAdvertiser != null) sBluetoothLeAdvertiser.cleanup();
if (sBluetoothLeScanner != null) sBluetoothLeScanner.cleanup(); if (sBluetoothLeScanner != null) sBluetoothLeScanner.cleanup();
} finally {
mServiceLock.writeLock().unlock(); mServiceLock.writeLock().unlock();
}
synchronized (mProxyServiceStateCallbacks) { synchronized (mProxyServiceStateCallbacks) {
for (IBluetoothManagerCallback cb : mProxyServiceStateCallbacks ){ for (IBluetoothManagerCallback cb : mProxyServiceStateCallbacks ){

View File

@@ -1457,6 +1457,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
BluetoothAdapter.STATE_OFF); BluetoothAdapter.STATE_OFF);
sendBluetoothServiceDownCallback(); sendBluetoothServiceDownCallback();
try {
mBluetoothLock.writeLock().lock(); mBluetoothLock.writeLock().lock();
if (mBluetooth != null) { if (mBluetooth != null) {
mBluetooth = null; mBluetooth = null;
@@ -1464,7 +1465,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
mContext.unbindService(mConnection); mContext.unbindService(mConnection);
} }
mBluetoothGatt = null; mBluetoothGatt = null;
} finally {
mBluetoothLock.writeLock().unlock(); mBluetoothLock.writeLock().unlock();
}
SystemClock.sleep(100); SystemClock.sleep(100);
@@ -1765,6 +1768,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
sendBluetoothServiceDownCallback(); sendBluetoothServiceDownCallback();
try {
mBluetoothLock.writeLock().lock(); mBluetoothLock.writeLock().lock();
if (mBluetooth != null) { if (mBluetooth != null) {
mBluetooth = null; mBluetooth = null;
@@ -1772,7 +1776,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
mContext.unbindService(mConnection); mContext.unbindService(mConnection);
} }
mBluetoothGatt = null; mBluetoothGatt = null;
} finally {
mBluetoothLock.writeLock().unlock(); mBluetoothLock.writeLock().unlock();
}
mHandler.removeMessages(MESSAGE_BLUETOOTH_STATE_CHANGE); mHandler.removeMessages(MESSAGE_BLUETOOTH_STATE_CHANGE);
mState = BluetoothAdapter.STATE_OFF; mState = BluetoothAdapter.STATE_OFF;