Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c3faa554 authored by Charlie Boutier's avatar Charlie Boutier Committed by Automerger Merge Worker
Browse files

Merge "PandoraServer: Add WaitDisconnection Hashset" am: 48e3fce5 am:...

Merge "PandoraServer: Add WaitDisconnection Hashset" am: 48e3fce5 am: 20bd8ddf am: 38e6917c am: f79de93e am: 9a89fe28

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2527324



Change-Id: I18ed41f3226d90114a4da91df26b832f439f6dd2
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents dd82dfca 9a89fe28
Loading
Loading
Loading
Loading
+10 −1
Original line number Original line Diff line number Diff line
@@ -171,6 +171,7 @@ class Host(


      initiatedConnection.clear()
      initiatedConnection.clear()
      waitedAclConnection.clear()
      waitedAclConnection.clear()
      waitedAclDisconnection.clear()


      bluetoothAdapter.clearBluetooth()
      bluetoothAdapter.clearBluetooth()


@@ -190,6 +191,8 @@ class Host(
      Log.i(TAG, "reset")
      Log.i(TAG, "reset")
      initiatedConnection.clear()
      initiatedConnection.clear()
      waitedAclConnection.clear()
      waitedAclConnection.clear()
      waitedAclDisconnection.clear()

      rebootBluetooth()
      rebootBluetooth()


      Empty.getDefaultInstance()
      Empty.getDefaultInstance()
@@ -311,12 +314,18 @@ class Host(
      if (!bluetoothAdapter.isEnabled) {
      if (!bluetoothAdapter.isEnabled) {
        throw RuntimeException("Bluetooth is not enabled, cannot waitDisconnection")
        throw RuntimeException("Bluetooth is not enabled, cannot waitDisconnection")
      }
      }
      if (bluetoothDevice.bondState != BluetoothDevice.BOND_NONE) {
      if (
        bluetoothDevice.bondState != BluetoothDevice.BOND_NONE &&
          !waitedAclDisconnection.contains(bluetoothDevice)
      ) {
        flow
        flow
          .filter { it.action == BluetoothDevice.ACTION_ACL_DISCONNECTED }
          .filter { it.action == BluetoothDevice.ACTION_ACL_DISCONNECTED }
          .filter { it.getBluetoothDeviceExtra() == bluetoothDevice }
          .filter { it.getBluetoothDeviceExtra() == bluetoothDevice }
          .first()
          .first()
      }
      }

      waitedAclDisconnection.add(bluetoothDevice)

      Empty.getDefaultInstance()
      Empty.getDefaultInstance()
    }
    }
  }
  }
+5 −0
Original line number Original line Diff line number Diff line
@@ -65,6 +65,7 @@ private val alphanumeric = ('A'..'Z') + ('a'..'z') + ('0'..'9')


val initiatedConnection = HashSet<BluetoothDevice>()
val initiatedConnection = HashSet<BluetoothDevice>()
val waitedAclConnection = HashSet<BluetoothDevice>()
val waitedAclConnection = HashSet<BluetoothDevice>()
val waitedAclDisconnection = HashSet<BluetoothDevice>()


fun shell(cmd: String): String {
fun shell(cmd: String): String {
  val fd = InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand(cmd)
  val fd = InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand(cmd)
@@ -85,9 +86,13 @@ fun intentFlow(context: Context, intentFilter: IntentFilter) = callbackFlow {
  val broadcastReceiver: BroadcastReceiver =
  val broadcastReceiver: BroadcastReceiver =
    object : BroadcastReceiver() {
    object : BroadcastReceiver() {
      override fun onReceive(context: Context, intent: Intent) {
      override fun onReceive(context: Context, intent: Intent) {
        if (intent.action == BluetoothDevice.ACTION_ACL_CONNECTED) {
          waitedAclDisconnection.remove(intent.getBluetoothDeviceExtra())
        }
        if (intent.action == BluetoothDevice.ACTION_ACL_DISCONNECTED) {
        if (intent.action == BluetoothDevice.ACTION_ACL_DISCONNECTED) {
          initiatedConnection.remove(intent.getBluetoothDeviceExtra())
          initiatedConnection.remove(intent.getBluetoothDeviceExtra())
          waitedAclConnection.remove(intent.getBluetoothDeviceExtra())
          waitedAclConnection.remove(intent.getBluetoothDeviceExtra())
          waitedAclDisconnection.add(intent.getBluetoothDeviceExtra())
        }
        }
        trySendBlocking(intent)
        trySendBlocking(intent)
      }
      }