Loading framework/java/android/bluetooth/BluetoothAdapter.java +0 −18 Original line number Diff line number Diff line Loading @@ -897,28 +897,10 @@ public final class BluetoothAdapter { */ @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) public boolean enable() { int state = BluetoothAdapter.STATE_OFF; if (isEnabled() == true) { if (DBG) Log.d(TAG, "enable(): BT is already enabled..!"); return true; } // Use service interface to get the exact state try { mServiceLock.readLock().lock(); if (mService != null) { state = mService.getState(); } } catch (RemoteException e) { Log.e(TAG, "", e); } finally { mServiceLock.readLock().unlock(); } if (state == BluetoothAdapter.STATE_BLE_ON) { Log.e(TAG, "BT is in BLE_ON State"); notifyUserAction(true); return true; } try { return mManagerService.enable(); } catch (RemoteException e) {Log.e(TAG, "", e);} Loading service/java/com/android/server/bluetooth/BluetoothManagerService.java +45 −14 Original line number Diff line number Diff line Loading @@ -1171,8 +1171,27 @@ class BluetoothManagerService extends IBluetoothManager.Stub { } mHandler.removeMessages(MESSAGE_RESTART_BLUETOOTH_SERVICE); mEnable = true; // Use service interface to get the exact state try { mBluetoothLock.readLock().lock(); if (mBluetooth != null) { int state = mBluetooth.getState(); if (state == BluetoothAdapter.STATE_BLE_ON) { Slog.w(TAG, "BT is in BLE_ON State"); mBluetooth.onLeServiceUp(); break; } } } catch (RemoteException e) { Slog.e(TAG, "", e); } finally { mBluetoothLock.readLock().unlock(); } mQuietEnable = (msg.arg1 == 1); if (mBluetooth == null) { handleEnable(msg.arg1 == 1); handleEnable(mQuietEnable); } else { // // We need to wait until transitioned to STATE_OFF and Loading @@ -1190,7 +1209,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub { // on the order of (2 * SERVICE_RESTART_TIME_MS). // waitForOnOff(false, true); mQuietEnable = (msg.arg1 == 1); Message restartMsg = mHandler.obtainMessage( MESSAGE_RESTART_BLUETOOTH_SERVICE); mHandler.sendMessageDelayed(restartMsg, Loading Loading @@ -1362,6 +1380,19 @@ class BluetoothManagerService extends IBluetoothManager.Stub { (mBluetooth != null) && mEnable) { recoverBluetoothServiceFromError(); } // If we tried to enable BT while BT was in the process of shutting down, // wait for the BT process to fully tear down and then force a restart // here. This is a bit of a hack (b/29363429). if ((prevState == BluetoothAdapter.STATE_BLE_TURNING_OFF) && (newState == BluetoothAdapter.STATE_OFF)) { if (mEnable) { Slog.d(TAG, "Entering STATE_OFF but mEnabled is true; restarting."); waitForOnOff(false, true); Message restartMsg = mHandler.obtainMessage( MESSAGE_RESTART_BLUETOOTH_SERVICE); mHandler.sendMessageDelayed(restartMsg, 2 * SERVICE_RESTART_TIME_MS); } } if (newState == BluetoothAdapter.STATE_ON || newState == BluetoothAdapter.STATE_BLE_ON) { // bluetooth is working, reset the counter Loading Loading @@ -1639,8 +1670,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub { boolean isStandardBroadcast = true; if (prevState != newState) { //Notify all proxy objects first of adapter state change if (newState == BluetoothAdapter.STATE_BLE_ON || newState == BluetoothAdapter.STATE_OFF) { if (newState == BluetoothAdapter.STATE_BLE_ON || newState == BluetoothAdapter.STATE_OFF) { boolean intermediate_off = (prevState == BluetoothAdapter.STATE_TURNING_OFF && newState == BluetoothAdapter.STATE_BLE_ON); Loading Loading @@ -1685,13 +1716,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub { sendBluetoothStateCallback(isUp); sendBleStateChanged(prevState, newState); } else if (newState == BluetoothAdapter.STATE_BLE_TURNING_ON || newState == BluetoothAdapter.STATE_BLE_TURNING_OFF ) { } else if (newState == BluetoothAdapter.STATE_BLE_TURNING_ON || newState == BluetoothAdapter.STATE_BLE_TURNING_OFF ) { sendBleStateChanged(prevState, newState); isStandardBroadcast = false; } else if (newState == BluetoothAdapter.STATE_TURNING_ON || newState == BluetoothAdapter.STATE_TURNING_OFF) { } else if (newState == BluetoothAdapter.STATE_TURNING_ON || newState == BluetoothAdapter.STATE_TURNING_OFF) { sendBleStateChanged(prevState, newState); } Loading Loading
framework/java/android/bluetooth/BluetoothAdapter.java +0 −18 Original line number Diff line number Diff line Loading @@ -897,28 +897,10 @@ public final class BluetoothAdapter { */ @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) public boolean enable() { int state = BluetoothAdapter.STATE_OFF; if (isEnabled() == true) { if (DBG) Log.d(TAG, "enable(): BT is already enabled..!"); return true; } // Use service interface to get the exact state try { mServiceLock.readLock().lock(); if (mService != null) { state = mService.getState(); } } catch (RemoteException e) { Log.e(TAG, "", e); } finally { mServiceLock.readLock().unlock(); } if (state == BluetoothAdapter.STATE_BLE_ON) { Log.e(TAG, "BT is in BLE_ON State"); notifyUserAction(true); return true; } try { return mManagerService.enable(); } catch (RemoteException e) {Log.e(TAG, "", e);} Loading
service/java/com/android/server/bluetooth/BluetoothManagerService.java +45 −14 Original line number Diff line number Diff line Loading @@ -1171,8 +1171,27 @@ class BluetoothManagerService extends IBluetoothManager.Stub { } mHandler.removeMessages(MESSAGE_RESTART_BLUETOOTH_SERVICE); mEnable = true; // Use service interface to get the exact state try { mBluetoothLock.readLock().lock(); if (mBluetooth != null) { int state = mBluetooth.getState(); if (state == BluetoothAdapter.STATE_BLE_ON) { Slog.w(TAG, "BT is in BLE_ON State"); mBluetooth.onLeServiceUp(); break; } } } catch (RemoteException e) { Slog.e(TAG, "", e); } finally { mBluetoothLock.readLock().unlock(); } mQuietEnable = (msg.arg1 == 1); if (mBluetooth == null) { handleEnable(msg.arg1 == 1); handleEnable(mQuietEnable); } else { // // We need to wait until transitioned to STATE_OFF and Loading @@ -1190,7 +1209,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub { // on the order of (2 * SERVICE_RESTART_TIME_MS). // waitForOnOff(false, true); mQuietEnable = (msg.arg1 == 1); Message restartMsg = mHandler.obtainMessage( MESSAGE_RESTART_BLUETOOTH_SERVICE); mHandler.sendMessageDelayed(restartMsg, Loading Loading @@ -1362,6 +1380,19 @@ class BluetoothManagerService extends IBluetoothManager.Stub { (mBluetooth != null) && mEnable) { recoverBluetoothServiceFromError(); } // If we tried to enable BT while BT was in the process of shutting down, // wait for the BT process to fully tear down and then force a restart // here. This is a bit of a hack (b/29363429). if ((prevState == BluetoothAdapter.STATE_BLE_TURNING_OFF) && (newState == BluetoothAdapter.STATE_OFF)) { if (mEnable) { Slog.d(TAG, "Entering STATE_OFF but mEnabled is true; restarting."); waitForOnOff(false, true); Message restartMsg = mHandler.obtainMessage( MESSAGE_RESTART_BLUETOOTH_SERVICE); mHandler.sendMessageDelayed(restartMsg, 2 * SERVICE_RESTART_TIME_MS); } } if (newState == BluetoothAdapter.STATE_ON || newState == BluetoothAdapter.STATE_BLE_ON) { // bluetooth is working, reset the counter Loading Loading @@ -1639,8 +1670,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub { boolean isStandardBroadcast = true; if (prevState != newState) { //Notify all proxy objects first of adapter state change if (newState == BluetoothAdapter.STATE_BLE_ON || newState == BluetoothAdapter.STATE_OFF) { if (newState == BluetoothAdapter.STATE_BLE_ON || newState == BluetoothAdapter.STATE_OFF) { boolean intermediate_off = (prevState == BluetoothAdapter.STATE_TURNING_OFF && newState == BluetoothAdapter.STATE_BLE_ON); Loading Loading @@ -1685,13 +1716,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub { sendBluetoothStateCallback(isUp); sendBleStateChanged(prevState, newState); } else if (newState == BluetoothAdapter.STATE_BLE_TURNING_ON || newState == BluetoothAdapter.STATE_BLE_TURNING_OFF ) { } else if (newState == BluetoothAdapter.STATE_BLE_TURNING_ON || newState == BluetoothAdapter.STATE_BLE_TURNING_OFF ) { sendBleStateChanged(prevState, newState); isStandardBroadcast = false; } else if (newState == BluetoothAdapter.STATE_TURNING_ON || newState == BluetoothAdapter.STATE_TURNING_OFF) { } else if (newState == BluetoothAdapter.STATE_TURNING_ON || newState == BluetoothAdapter.STATE_TURNING_OFF) { sendBleStateChanged(prevState, newState); } Loading