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

Commit 36ca2c4d authored by bidsharma's avatar bidsharma
Browse files

[Pandora] Add support for random addr in IsBonded

Bug: 232386811
Tag: #refactor
Test: atest avatar:SMTest.test_le_pairing__no_bonding -v

Change-Id: Idf57b81b5423664102b875684674740586d9a9fd
parent 9b6ad125
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -67,11 +67,19 @@ class SecurityStorage(private val context: Context) : SecurityStorageImplBase(),

  override fun isBonded(request: IsBondedRequest, responseObserver: StreamObserver<BoolValue>) {
    grpcUnary(globalScope, responseObserver) {
      check(request.getAddressCase() == IsBondedRequest.AddressCase.PUBLIC)
      val bluetoothDevice = request.public.toBluetoothDevice(bluetoothAdapter)
      Log.i(TAG, "isBonded: $bluetoothDevice")
      val isBonded = bluetoothDevice.getBondState() == BluetoothDevice.BOND_BONDED
      BoolValue.newBuilder().setValue(isBonded).build()
      val bondedDevices = bluetoothAdapter.getBondedDevices()
      val bondedDevice =
        when(request.getAddressCase()!!) {
          IsBondedRequest.AddressCase.PUBLIC -> bondedDevices.firstOrNull {
            it.toByteString() == request.public
          }
          IsBondedRequest.AddressCase.RANDOM ->  bondedDevices.firstOrNull {
            it.toByteString() == request.random
          }
          IsBondedRequest.AddressCase.ADDRESS_NOT_SET -> throw Status.UNKNOWN.asException()
        }
      Log.i(TAG, "isBonded: device=$bondedDevice")
      BoolValue.newBuilder().setValue(bondedDevice != null).build()
    }
  }