Loading framework/tests/util/src/BlockingBluetoothAdapter.kt +2 −2 Original line number Diff line number Diff line Loading @@ -79,8 +79,8 @@ object BlockingBluetoothAdapter { if (adapter.isBleScanAlwaysAvailable()) { break } Log.d(TAG, "Ble scan not yet available... Sleeping 20 ms $i/5") Thread.sleep(20) Log.d(TAG, "Ble scan not yet available... Sleeping 50 ms $i/5") Thread.sleep(50) } if (!adapter.isBleScanAlwaysAvailable()) { throw IllegalStateException("Could not enable BLE scan") Loading service/src/com/android/server/bluetooth/BluetoothManagerService.java +21 −23 Original line number Diff line number Diff line Loading @@ -1656,13 +1656,6 @@ class BluetoothManagerService { if (!mEnable) { waitForState(STATE_ON); onToBleOn(); waitForState( STATE_OFF, STATE_TURNING_ON, STATE_TURNING_OFF, STATE_BLE_TURNING_ON, STATE_BLE_ON, STATE_BLE_TURNING_OFF); } break; Loading Loading @@ -2015,6 +2008,7 @@ class BluetoothManagerService { } catch (RemoteException e) { Log.e(TAG, "Unable to call offToBleOn()", e); } bluetoothStateChangeHandler(STATE_OFF, STATE_BLE_TURNING_ON); } private void onToBleOn() { Loading @@ -2028,6 +2022,7 @@ class BluetoothManagerService { } catch (RemoteException e) { Log.e(TAG, "Unable to call onToBleOn()", e); } bluetoothStateChangeHandler(STATE_ON, STATE_TURNING_OFF); } private void bleOnToOn() { Loading @@ -2041,6 +2036,7 @@ class BluetoothManagerService { } catch (RemoteException e) { Log.e(TAG, "Unable to call bleOnToOn()", e); } bluetoothStateChangeHandler(STATE_BLE_ON, STATE_TURNING_ON); } private void bleOnToOff() { Loading @@ -2054,6 +2050,7 @@ class BluetoothManagerService { } catch (RemoteException e) { Log.e(TAG, "Unable to call bleOnToOff()", e); } bluetoothStateChangeHandler(STATE_BLE_ON, STATE_BLE_TURNING_OFF); } private void broadcastIntentStateChange(String action, int prevState, int newState) { Loading Loading @@ -2083,11 +2080,27 @@ class BluetoothManagerService { } private void bluetoothStateChangeHandler(int prevState, int newState) { if (prevState == newState) { // No change. Nothing to do. if (mState.oneOf(newState)) { // Already in correct state Log.d(TAG, "bluetoothStateChangeHandler: Already in state " + mState); return; } mState.set(newState); broadcastIntentStateChange(BluetoothAdapter.ACTION_BLE_STATE_CHANGED, prevState, newState); // BLE state are shown as STATE_OFF for BrEdr users final int prevBrEdrState = isBleState(prevState) ? STATE_OFF : prevState; final int newBrEdrState = isBleState(newState) ? STATE_OFF : newState; if (prevBrEdrState != newBrEdrState) { // Only broadcast when there is a BrEdr state change. if (newBrEdrState == STATE_OFF) { sendBluetoothOffCallback(); sendBrEdrDownCallback(); } broadcastIntentStateChange( BluetoothAdapter.ACTION_STATE_CHANGED, prevBrEdrState, newBrEdrState); } if (prevState == STATE_ON) { autoOnSetupTimer(); } Loading @@ -2106,21 +2119,6 @@ class BluetoothManagerService { } else if (newState == STATE_BLE_ON && prevState == STATE_BLE_TURNING_ON) { continueFromBleOnState(); } // Nothing specific to do for STATE_TURNING_<X> broadcastIntentStateChange(BluetoothAdapter.ACTION_BLE_STATE_CHANGED, prevState, newState); // BLE state are shown as STATE_OFF for BrEdr users final int prevBrEdrState = isBleState(prevState) ? STATE_OFF : prevState; final int newBrEdrState = isBleState(newState) ? STATE_OFF : newState; if (prevBrEdrState != newBrEdrState) { // Only broadcast when there is a BrEdr state change. if (newBrEdrState == STATE_OFF) { sendBluetoothOffCallback(); sendBrEdrDownCallback(); } broadcastIntentStateChange( BluetoothAdapter.ACTION_STATE_CHANGED, prevBrEdrState, newBrEdrState); } } boolean waitForManagerState(int state) { Loading service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java +4 −5 Original line number Diff line number Diff line Loading @@ -289,11 +289,6 @@ public class BluetoothManagerServiceTest { // trigger the stateChangeCallback from native btCallback.onBluetoothStateChange(STATE_BLE_TURNING_ON, STATE_BLE_ON); syncHandler(MESSAGE_BLUETOOTH_STATE_CHANGE); assertThat(mManagerService.getState()).isEqualTo(STATE_BLE_ON); // Check that we sent 2 intent, one for BLE_TURNING_ON, one for BLE_ON // TODO(b/280518177): assert the intent are the correct one verify(mContext, times(2)).sendBroadcastAsUser(any(), any(), any(), any()); return btCallback; } Loading Loading @@ -323,6 +318,10 @@ public class BluetoothManagerServiceTest { transition_offToBleOn(); // Check that we sent 2 intent, one for BLE_TURNING_ON, one for BLE_ON // TODO(b/280518177): assert the intent are the correct one verify(mContext, times(2)).sendBroadcastAsUser(any(), any(), any(), any()); // Check that there was no transition to STATE_ON verify(mAdapterBinder, times(0)).bleOnToOn(any()); assertThat(mManagerService.getState()).isEqualTo(STATE_BLE_ON); Loading Loading
framework/tests/util/src/BlockingBluetoothAdapter.kt +2 −2 Original line number Diff line number Diff line Loading @@ -79,8 +79,8 @@ object BlockingBluetoothAdapter { if (adapter.isBleScanAlwaysAvailable()) { break } Log.d(TAG, "Ble scan not yet available... Sleeping 20 ms $i/5") Thread.sleep(20) Log.d(TAG, "Ble scan not yet available... Sleeping 50 ms $i/5") Thread.sleep(50) } if (!adapter.isBleScanAlwaysAvailable()) { throw IllegalStateException("Could not enable BLE scan") Loading
service/src/com/android/server/bluetooth/BluetoothManagerService.java +21 −23 Original line number Diff line number Diff line Loading @@ -1656,13 +1656,6 @@ class BluetoothManagerService { if (!mEnable) { waitForState(STATE_ON); onToBleOn(); waitForState( STATE_OFF, STATE_TURNING_ON, STATE_TURNING_OFF, STATE_BLE_TURNING_ON, STATE_BLE_ON, STATE_BLE_TURNING_OFF); } break; Loading Loading @@ -2015,6 +2008,7 @@ class BluetoothManagerService { } catch (RemoteException e) { Log.e(TAG, "Unable to call offToBleOn()", e); } bluetoothStateChangeHandler(STATE_OFF, STATE_BLE_TURNING_ON); } private void onToBleOn() { Loading @@ -2028,6 +2022,7 @@ class BluetoothManagerService { } catch (RemoteException e) { Log.e(TAG, "Unable to call onToBleOn()", e); } bluetoothStateChangeHandler(STATE_ON, STATE_TURNING_OFF); } private void bleOnToOn() { Loading @@ -2041,6 +2036,7 @@ class BluetoothManagerService { } catch (RemoteException e) { Log.e(TAG, "Unable to call bleOnToOn()", e); } bluetoothStateChangeHandler(STATE_BLE_ON, STATE_TURNING_ON); } private void bleOnToOff() { Loading @@ -2054,6 +2050,7 @@ class BluetoothManagerService { } catch (RemoteException e) { Log.e(TAG, "Unable to call bleOnToOff()", e); } bluetoothStateChangeHandler(STATE_BLE_ON, STATE_BLE_TURNING_OFF); } private void broadcastIntentStateChange(String action, int prevState, int newState) { Loading Loading @@ -2083,11 +2080,27 @@ class BluetoothManagerService { } private void bluetoothStateChangeHandler(int prevState, int newState) { if (prevState == newState) { // No change. Nothing to do. if (mState.oneOf(newState)) { // Already in correct state Log.d(TAG, "bluetoothStateChangeHandler: Already in state " + mState); return; } mState.set(newState); broadcastIntentStateChange(BluetoothAdapter.ACTION_BLE_STATE_CHANGED, prevState, newState); // BLE state are shown as STATE_OFF for BrEdr users final int prevBrEdrState = isBleState(prevState) ? STATE_OFF : prevState; final int newBrEdrState = isBleState(newState) ? STATE_OFF : newState; if (prevBrEdrState != newBrEdrState) { // Only broadcast when there is a BrEdr state change. if (newBrEdrState == STATE_OFF) { sendBluetoothOffCallback(); sendBrEdrDownCallback(); } broadcastIntentStateChange( BluetoothAdapter.ACTION_STATE_CHANGED, prevBrEdrState, newBrEdrState); } if (prevState == STATE_ON) { autoOnSetupTimer(); } Loading @@ -2106,21 +2119,6 @@ class BluetoothManagerService { } else if (newState == STATE_BLE_ON && prevState == STATE_BLE_TURNING_ON) { continueFromBleOnState(); } // Nothing specific to do for STATE_TURNING_<X> broadcastIntentStateChange(BluetoothAdapter.ACTION_BLE_STATE_CHANGED, prevState, newState); // BLE state are shown as STATE_OFF for BrEdr users final int prevBrEdrState = isBleState(prevState) ? STATE_OFF : prevState; final int newBrEdrState = isBleState(newState) ? STATE_OFF : newState; if (prevBrEdrState != newBrEdrState) { // Only broadcast when there is a BrEdr state change. if (newBrEdrState == STATE_OFF) { sendBluetoothOffCallback(); sendBrEdrDownCallback(); } broadcastIntentStateChange( BluetoothAdapter.ACTION_STATE_CHANGED, prevBrEdrState, newBrEdrState); } } boolean waitForManagerState(int state) { Loading
service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java +4 −5 Original line number Diff line number Diff line Loading @@ -289,11 +289,6 @@ public class BluetoothManagerServiceTest { // trigger the stateChangeCallback from native btCallback.onBluetoothStateChange(STATE_BLE_TURNING_ON, STATE_BLE_ON); syncHandler(MESSAGE_BLUETOOTH_STATE_CHANGE); assertThat(mManagerService.getState()).isEqualTo(STATE_BLE_ON); // Check that we sent 2 intent, one for BLE_TURNING_ON, one for BLE_ON // TODO(b/280518177): assert the intent are the correct one verify(mContext, times(2)).sendBroadcastAsUser(any(), any(), any(), any()); return btCallback; } Loading Loading @@ -323,6 +318,10 @@ public class BluetoothManagerServiceTest { transition_offToBleOn(); // Check that we sent 2 intent, one for BLE_TURNING_ON, one for BLE_ON // TODO(b/280518177): assert the intent are the correct one verify(mContext, times(2)).sendBroadcastAsUser(any(), any(), any(), any()); // Check that there was no transition to STATE_ON verify(mAdapterBinder, times(0)).bleOnToOn(any()); assertThat(mManagerService.getState()).isEqualTo(STATE_BLE_ON); Loading