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

Commit 955ddb6c authored by Thomas Girardier's avatar Thomas Girardier Committed by Gerrit Code Review
Browse files

Merge changes If58bfedc,Ia38a3f0a,I2122e832

* changes:
  PandoraServer: Replace usage of shutdownNow with shutdown
  PandoraServer: Avoid completing grpcUnary responseObserver twice
  PandoraServer: Close HFP Profile Proxy
parents d90b07b8 12170ae2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ class Hfp(val context: Context) : HFPImplBase() {
  }

  fun deinit() {
    bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, bluetoothHfp)
    scope.cancel()
  }

+3 −4
Original line number Diff line number Diff line
@@ -108,13 +108,12 @@ class Host(private val context: Context, private val server: Server) : HostImplB

      rebootBluetooth()

      Log.i(TAG, "Shutdown the gRPC Server")
      server.shutdown()

      // The last expression is the return value.
      Empty.getDefaultInstance()
    }
      .invokeOnCompletion {
        Log.i(TAG, "Shutdown the gRPC Server")
        server.shutdownNow()
      }
  }

  override fun softReset(request: Empty, responseObserver: StreamObserver<Empty>) {
+3 −1
Original line number Diff line number Diff line
@@ -48,7 +48,9 @@ class Main : MonitoringInstrumentation() {
    val context: Context = getApplicationContext()

    while (true) {
      Server(context).awaitTermination()
      val server = Server(context)
      server.awaitTermination()
      server.deinit()
    }
  }
}
+5 −4
Original line number Diff line number Diff line
@@ -57,15 +57,16 @@ class Server(context: Context) {
    Log.d(TAG, "Pandora Server started at $GRPC_PORT")
  }

  fun shutdownNow() {
  fun shutdown() = grpcServer.shutdown()

  fun awaitTermination() = grpcServer.awaitTermination()

  fun deinit() {
    host.deinit()
    a2dp.deinit()
    avrcp.deinit()
    gatt.deinit()
    hfp.deinit()
    security.deinit()
    grpcServer.shutdownNow()
  }

  fun awaitTermination() = grpcServer.awaitTermination()
}
+4 −6
Original line number Diff line number Diff line
@@ -97,15 +97,13 @@ fun <T> grpcUnary(
  scope: CoroutineScope,
  responseObserver: StreamObserver<T>,
  timeout: Long = 60,
  block: suspend () -> T
  block: suspend CoroutineScope.() -> T
): Job {
  return scope.launch {
    try {
      withTimeout(timeout * 1000) {
        val response = block()
      val response = withTimeout(timeout * 1000, block)
      responseObserver.onNext(response)
      responseObserver.onCompleted()
      }
    } catch (e: Throwable) {
      e.printStackTrace()
      responseObserver.onError(e)