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

Commit 2960a9e9 authored by Bidhya Sharma's avatar Bidhya Sharma Committed by Automerger Merge Worker
Browse files

Merge "[Pandora] Add support for random addr in IsBonded" am: 12a2a7c1 am: 86beb8e3

parents 22f000a2 86beb8e3
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()
    }
  }