Merge "Properly check if BT is off when shutting down radios" into nyc-mr1-dev

This commit is contained in:
TreeHugger Robot
2016-05-27 03:08:37 +00:00
committed by Android (Google) Code Review
3 changed files with 22 additions and 2 deletions

View File

@@ -37,6 +37,7 @@ interface IBluetoothManager
boolean enable();
boolean enableNoAutoConnect();
boolean disable(boolean persist);
int getState();
IBluetoothGatt getBluetoothGatt();
boolean bindBluetoothProfileService(int profile, IBluetoothProfileServiceConnection proxy);

View File

@@ -425,6 +425,24 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
return false;
}
public int getState() {
if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
(!checkIfCallerIsForegroundUser())) {
Slog.w(TAG, "getState(): not allowed for non-active and non system user");
return BluetoothAdapter.STATE_OFF;
}
try {
mBluetoothLock.readLock().lock();
if (mBluetooth != null) return mBluetooth.getState();
} catch (RemoteException e) {
Slog.e(TAG, "getState()", e);
} finally {
mBluetoothLock.readLock().unlock();
}
return BluetoothAdapter.STATE_OFF;
}
class ClientDeathRecipient implements IBinder.DeathRecipient {
public void binderDied() {
if (DBG) Slog.d(TAG, "Binder is dead - unregister Ble App");

View File

@@ -543,7 +543,8 @@ public final class ShutdownThread extends Thread {
}
try {
bluetoothOff = bluetooth == null || !bluetooth.isEnabled();
bluetoothOff = bluetooth == null ||
bluetooth.getState() == BluetoothAdapter.STATE_OFF;
if (!bluetoothOff) {
Log.w(TAG, "Disabling Bluetooth...");
bluetooth.disable(false); // disable but don't persist new state
@@ -577,7 +578,7 @@ public final class ShutdownThread extends Thread {
if (!bluetoothOff) {
try {
bluetoothOff = !bluetooth.isEnabled();
bluetoothOff = bluetooth.getState() == BluetoothAdapter.STATE_OFF;
} catch (RemoteException ex) {
Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
bluetoothOff = true;