Merge "Bluetooth: fix issues re-enabling after crash"

This commit is contained in:
Marie Janssen
2016-12-16 22:56:58 +00:00
committed by Gerrit Code Review

View File

@@ -335,12 +335,15 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
/** /**
* Save the Bluetooth on/off state * Save the Bluetooth on/off state
*
*/ */
private void persistBluetoothSetting(int value) { private void persistBluetoothSetting(int value) {
if (DBG) Slog.d(TAG, "Persisting Bluetooth Setting: " + value);
// waive WRITE_SECURE_SETTINGS permission check
long callingIdentity = Binder.clearCallingIdentity();
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.BLUETOOTH_ON, Settings.Global.BLUETOOTH_ON,
value); value);
Binder.restoreCallingIdentity(callingIdentity);
} }
/** /**
@@ -605,20 +608,26 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
} }
/** /**
* Action taken when GattService is turned off * Action taken when GattService is turned on
*/ */
private void onBluetoothGattServiceUp() { private void onBluetoothGattServiceUp() {
if (DBG) Slog.d(TAG,"BluetoothGatt Service is Up"); if (DBG) Slog.d(TAG,"BluetoothGatt Service is Up");
try { try {
mBluetoothLock.readLock().lock(); mBluetoothLock.readLock().lock();
if (isBleAppPresent() == false && mBluetooth != null if (mBluetooth == null) {
&& mBluetooth.getState() == BluetoothAdapter.STATE_BLE_ON) { if (DBG) Slog.w(TAG, "onBluetoothServiceUp: mBluetooth is null!");
return;
}
int st = mBluetooth.getState();
if (st != BluetoothAdapter.STATE_BLE_ON) {
if (DBG) Slog.v(TAG, "onBluetoothServiceUp: state isn't BLE_ON: " +
BluetoothAdapter.nameForState(st));
return;
}
if (isBluetoothPersistedStateOnBluetooth() || !isBleAppPresent()) {
// This triggers transition to STATE_ON
mBluetooth.onLeServiceUp(); mBluetooth.onLeServiceUp();
// waive WRITE_SECURE_SETTINGS permission check
long callingIdentity = Binder.clearCallingIdentity();
persistBluetoothSetting(BLUETOOTH_ON_BLUETOOTH); persistBluetoothSetting(BLUETOOTH_ON_BLUETOOTH);
Binder.restoreCallingIdentity(callingIdentity);
} }
} catch (RemoteException e) { } catch (RemoteException e) {
Slog.e(TAG,"Unable to call onServiceUp", e); Slog.e(TAG,"Unable to call onServiceUp", e);
@@ -758,10 +767,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
synchronized(mReceiver) { synchronized(mReceiver) {
if (persist) { if (persist) {
// waive WRITE_SECURE_SETTINGS permission check
long callingIdentity = Binder.clearCallingIdentity();
persistBluetoothSetting(BLUETOOTH_OFF); persistBluetoothSetting(BLUETOOTH_OFF);
Binder.restoreCallingIdentity(callingIdentity);
} }
mEnableExternal = false; mEnableExternal = false;
sendDisableMsg(); sendDisableMsg();