Avoid IllegalArgumentException when bluetooth is disabled

When the corresponding profile service is not available on device,
bluetoothA2dp, bluetoothHidHost and bluetoothPbap will report
IllegalArgumentException when bluetooth is disabled. This change avoid
that exception.

Bug: 127359897
Test: local test and observe there is no IllegalArgumentException when
bluetooth is disabled

Change-Id: I457e5225b8710dd5d02c405ef558892e99d1736f
(cherry picked from commit ee8371007b82ff8c6d26e8ac90c6e3d3cf6bf2a8)
This commit is contained in:
Deqiang Chen
2019-03-12 14:08:12 -07:00
parent 108b8d6e40
commit da9f738c0c
3 changed files with 12 additions and 6 deletions

View File

@@ -224,8 +224,10 @@ public final class BluetoothA2dp implements BluetoothProfile {
if (VDBG) Log.d(TAG, "Unbinding service...");
try {
mServiceLock.writeLock().lock();
mService = null;
mContext.unbindService(mConnection);
if (mService != null) {
mService = null;
mContext.unbindService(mConnection);
}
} catch (Exception re) {
Log.e(TAG, "", re);
} finally {

View File

@@ -232,8 +232,10 @@ public final class BluetoothHidHost implements BluetoothProfile {
if (VDBG) Log.d(TAG, "Unbinding service...");
synchronized (mConnection) {
try {
mService = null;
mContext.unbindService(mConnection);
if (mService != null) {
mService = null;
mContext.unbindService(mConnection);
}
} catch (Exception re) {
Log.e(TAG, "", re);
}

View File

@@ -120,8 +120,10 @@ public class BluetoothPbap implements BluetoothProfile {
log("Unbinding service...");
synchronized (mConnection) {
try {
mService = null;
mContext.unbindService(mConnection);
if (mService != null) {
mService = null;
mContext.unbindService(mConnection);
}
} catch (Exception re) {
Log.e(TAG, "", re);
}