Loading services/core/java/com/android/server/BluetoothManagerService.java +44 −2 Original line number Diff line number Diff line Loading @@ -1483,7 +1483,7 @@ 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); Loading @@ -1496,7 +1496,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { bluetoothStateChangeHandler(BluetoothAdapter.STATE_ON, BluetoothAdapter.STATE_TURNING_OFF); waitForOnOff(false, true); waitForMonitoredOnOff(false, true); bluetoothStateChangeHandler(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_OFF); Loading Loading @@ -1776,6 +1776,48 @@ 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 < 10) { 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) { Log.e(TAG, "getState()", e); break; } } if (on || off) { SystemClock.sleep(800); } else { SystemClock.sleep(50); } i++; } Log.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 +44 −2 Original line number Diff line number Diff line Loading @@ -1483,7 +1483,7 @@ 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); Loading @@ -1496,7 +1496,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { bluetoothStateChangeHandler(BluetoothAdapter.STATE_ON, BluetoothAdapter.STATE_TURNING_OFF); waitForOnOff(false, true); waitForMonitoredOnOff(false, true); bluetoothStateChangeHandler(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_OFF); Loading Loading @@ -1776,6 +1776,48 @@ 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 < 10) { 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) { Log.e(TAG, "getState()", e); break; } } if (on || off) { SystemClock.sleep(800); } else { SystemClock.sleep(50); } i++; } Log.e(TAG,"waitForOnOff time out"); return false; } private void sendDisableMsg() { mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISABLE)); } Loading