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

Commit 12a2a7c1 authored by Bidhya Sharma's avatar Bidhya Sharma Committed by Gerrit Code Review
Browse files

Merge "[Pandora] Add support for random addr in IsBonded"

parents 8d60d9af 36ca2c4d
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()
    }
  }