Loading services/core/java/com/android/server/BluetoothManagerService.java 100755 → 100644 +56 −11 Original line number Diff line number Diff line Loading @@ -1275,24 +1275,26 @@ class BluetoothManagerService extends IBluetoothManager.Stub { mState = BluetoothAdapter.STATE_TURNING_ON; } waitForOnOff(true, false); waitForMonitoredOnOff(true, false); if (mState == BluetoothAdapter.STATE_TURNING_ON) { bluetoothStateChangeHandler(mState, BluetoothAdapter.STATE_ON); } // disable clearBleApps(); handleDisable(); // Pbap service need receive STATE_TURNING_OFF intent to close bluetoothStateChangeHandler(BluetoothAdapter.STATE_ON, BluetoothAdapter.STATE_TURNING_OFF); boolean didDisableTimeout = !waitForOnOff(false, true); boolean didDisableTimeout = !waitForMonitoredOnOff(false, true); bluetoothStateChangeHandler(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_OFF); sendBluetoothServiceDownCallback(); if(!didDisableTimeout) { try { mBluetoothLock.writeLock().lock(); if (mBluetooth != null) { Loading @@ -1304,6 +1306,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { } finally { mBluetoothLock.writeLock().unlock(); } } // // If disabling Bluetooth times out, wait for an Loading @@ -1312,6 +1315,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { // if (didDisableTimeout) { SystemClock.sleep(3000); mHandler.removeMessages(MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED); } else { SystemClock.sleep(100); } Loading Loading @@ -1574,6 +1578,47 @@ class BluetoothManagerService extends IBluetoothManager.Stub { return false; } /** * if on is true, wait for state become ON * if off is true, wait for state become OFF * if both on and off are false, wait for state not ON */ private boolean waitForMonitoredOnOff(boolean on, boolean off) { int i = 0; while (i < 16) { synchronized(mConnection) { try { if (mBluetooth == null) break; if (on) { if (mBluetooth.getState() == BluetoothAdapter.STATE_ON) return true; if (mBluetooth.getState() == BluetoothAdapter.STATE_BLE_ON) { bluetoothStateChangeHandler(BluetoothAdapter.STATE_BLE_TURNING_ON, BluetoothAdapter.STATE_BLE_ON); } } else if (off) { if (mBluetooth.getState() == BluetoothAdapter.STATE_OFF) return true; if (mBluetooth.getState() == BluetoothAdapter.STATE_BLE_ON) bluetoothStateChangeHandler(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_BLE_ON); } else { if (mBluetooth.getState() != BluetoothAdapter.STATE_ON) return true; } } catch (RemoteException e) { Slog.e(TAG, "getState()", e); break; } } if (on || off) { SystemClock.sleep(500); } else { SystemClock.sleep(30); } i++; } Slog.e(TAG,"waitForOnOff time out"); return false; } private void sendDisableMsg() { mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISABLE)); } Loading Loading
services/core/java/com/android/server/BluetoothManagerService.java 100755 → 100644 +56 −11 Original line number Diff line number Diff line Loading @@ -1275,24 +1275,26 @@ class BluetoothManagerService extends IBluetoothManager.Stub { mState = BluetoothAdapter.STATE_TURNING_ON; } waitForOnOff(true, false); waitForMonitoredOnOff(true, false); if (mState == BluetoothAdapter.STATE_TURNING_ON) { bluetoothStateChangeHandler(mState, BluetoothAdapter.STATE_ON); } // disable clearBleApps(); handleDisable(); // Pbap service need receive STATE_TURNING_OFF intent to close bluetoothStateChangeHandler(BluetoothAdapter.STATE_ON, BluetoothAdapter.STATE_TURNING_OFF); boolean didDisableTimeout = !waitForOnOff(false, true); boolean didDisableTimeout = !waitForMonitoredOnOff(false, true); bluetoothStateChangeHandler(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_OFF); sendBluetoothServiceDownCallback(); if(!didDisableTimeout) { try { mBluetoothLock.writeLock().lock(); if (mBluetooth != null) { Loading @@ -1304,6 +1306,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { } finally { mBluetoothLock.writeLock().unlock(); } } // // If disabling Bluetooth times out, wait for an Loading @@ -1312,6 +1315,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { // if (didDisableTimeout) { SystemClock.sleep(3000); mHandler.removeMessages(MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED); } else { SystemClock.sleep(100); } Loading Loading @@ -1574,6 +1578,47 @@ class BluetoothManagerService extends IBluetoothManager.Stub { return false; } /** * if on is true, wait for state become ON * if off is true, wait for state become OFF * if both on and off are false, wait for state not ON */ private boolean waitForMonitoredOnOff(boolean on, boolean off) { int i = 0; while (i < 16) { synchronized(mConnection) { try { if (mBluetooth == null) break; if (on) { if (mBluetooth.getState() == BluetoothAdapter.STATE_ON) return true; if (mBluetooth.getState() == BluetoothAdapter.STATE_BLE_ON) { bluetoothStateChangeHandler(BluetoothAdapter.STATE_BLE_TURNING_ON, BluetoothAdapter.STATE_BLE_ON); } } else if (off) { if (mBluetooth.getState() == BluetoothAdapter.STATE_OFF) return true; if (mBluetooth.getState() == BluetoothAdapter.STATE_BLE_ON) bluetoothStateChangeHandler(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_BLE_ON); } else { if (mBluetooth.getState() != BluetoothAdapter.STATE_ON) return true; } } catch (RemoteException e) { Slog.e(TAG, "getState()", e); break; } } if (on || off) { SystemClock.sleep(500); } else { SystemClock.sleep(30); } i++; } Slog.e(TAG,"waitForOnOff time out"); return false; } private void sendDisableMsg() { mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISABLE)); } Loading