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

Commit 17e532a5 authored by Abel Lucas's avatar Abel Lucas Committed by Automerger Merge Worker
Browse files

Merge "PandoraServer: report full stacktrace through gRPC" am: 05715218 am: a6f15632

parents 6350cf89 a6f15632
Loading
Loading
Loading
Loading
+17 −19
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import android.util.Log
import io.grpc.Status
import io.grpc.stub.StreamObserver
import java.io.Closeable
import java.io.PrintWriter
import java.io.StringWriter
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
@@ -91,8 +93,7 @@ class A2dp(val context: Context) : A2DPImplBase(), Closeable {
            .first()

        if (state == BluetoothProfile.STATE_DISCONNECTED) {
          Log.e(TAG, "openSource failed, A2DP has been disconnected")
          throw Status.UNKNOWN.asException()
          throw RuntimeException("openSource failed, A2DP has been disconnected")
        }
      }

@@ -124,8 +125,7 @@ class A2dp(val context: Context) : A2DPImplBase(), Closeable {
            .first()

        if (state == BluetoothProfile.STATE_DISCONNECTED) {
          Log.e(TAG, "waitSource failed, A2DP has been disconnected")
          throw Status.UNKNOWN.asException()
          throw RuntimeException("waitSource failed, A2DP has been disconnected")
        }
      }

@@ -146,8 +146,7 @@ class A2dp(val context: Context) : A2DPImplBase(), Closeable {
      Log.i(TAG, "start: device=$device")

      if (bluetoothA2dp.getConnectionState(device) != BluetoothA2dp.STATE_CONNECTED) {
        Log.e(TAG, "Device is not connected, cannot start")
        throw Status.UNKNOWN.asException()
        throw RuntimeException("Device is not connected, cannot start")
      }

      audioTrack!!.play()
@@ -171,13 +170,11 @@ class A2dp(val context: Context) : A2DPImplBase(), Closeable {
      Log.i(TAG, "suspend: device=$device")

      if (bluetoothA2dp.getConnectionState(device) != BluetoothA2dp.STATE_CONNECTED) {
        Log.e(TAG, "Device is not connected, cannot suspend")
        throw Status.UNKNOWN.asException()
        throw RuntimeException("Device is not connected, cannot suspend")
      }

      if (!bluetoothA2dp.isA2dpPlaying(device)) {
        Log.e(TAG, "Device is already suspended, cannot suspend")
        throw Status.UNKNOWN.asException()
        throw RuntimeException("Device is already suspended, cannot suspend")
      }

      val a2dpPlayingStateFlow =
@@ -201,8 +198,7 @@ class A2dp(val context: Context) : A2DPImplBase(), Closeable {
      Log.i(TAG, "isSuspended: device=$device")

      if (bluetoothA2dp.getConnectionState(device) != BluetoothA2dp.STATE_CONNECTED) {
        Log.e(TAG, "Device is not connected, cannot get suspend state")
        throw Status.UNKNOWN.asException()
        throw RuntimeException("Device is not connected, cannot get suspend state")
      }

      val isSuspended = bluetoothA2dp.isA2dpPlaying(device)
@@ -216,8 +212,7 @@ class A2dp(val context: Context) : A2DPImplBase(), Closeable {
      Log.i(TAG, "close: device=$device")

      if (bluetoothA2dp.getConnectionState(device) != BluetoothA2dp.STATE_CONNECTED) {
        Log.e(TAG, "Device is not connected, cannot close")
        throw Status.UNKNOWN.asException()
        throw RuntimeException("Device is not connected, cannot close")
      }

      val a2dpConnectionStateChangedFlow =
@@ -270,9 +265,13 @@ class A2dp(val context: Context) : A2DPImplBase(), Closeable {
          )
        }
      }
      override fun onError(t: Throwable?) {
        Log.e(TAG, t.toString())
        responseObserver.onError(t)
      override fun onError(t: Throwable) {
        t.printStackTrace()
        val sw = StringWriter()
        t.printStackTrace(PrintWriter(sw))
        responseObserver.onError(
          Status.UNKNOWN.withCause(t).withDescription(sw.toString()).asException()
        )
      }
      override fun onCompleted() {
        responseObserver.onNext(PlaybackAudioResponse.getDefaultInstance())
@@ -290,8 +289,7 @@ class A2dp(val context: Context) : A2DPImplBase(), Closeable {
      Log.i(TAG, "getAudioEncoding: device=$device")

      if (bluetoothA2dp.getConnectionState(device) != BluetoothA2dp.STATE_CONNECTED) {
        Log.e(TAG, "Device is not connected, cannot getAudioEncoding")
        throw Status.UNKNOWN.asException()
        throw RuntimeException("Device is not connected, cannot getAudioEncoding")
      }

      // For now, we only support 44100 kHz sampling rate.
+2 −5
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.content.Intent
import android.content.IntentFilter
import android.media.*
import android.util.Log
import io.grpc.Status
import io.grpc.stub.StreamObserver
import java.io.Closeable
import kotlinx.coroutines.CoroutineScope
@@ -85,8 +84,7 @@ class A2dpSink(val context: Context) : A2DPImplBase(), Closeable {
            .first()

        if (state == BluetoothProfile.STATE_DISCONNECTED) {
          Log.e(TAG, "waitStream failed, A2DP has been disconnected")
          throw Status.UNKNOWN.asException()
          throw RuntimeException("waitStream failed, A2DP has been disconnected")
        }
      }

@@ -100,8 +98,7 @@ class A2dpSink(val context: Context) : A2DPImplBase(), Closeable {
      val device = request.sink.connection.toBluetoothDevice(bluetoothAdapter)
      Log.i(TAG, "close: device=$device")
      if (bluetoothA2dpSink.getConnectionState(device) != BluetoothProfile.STATE_CONNECTED) {
        Log.e(TAG, "Device is not connected, cannot close")
        throw Status.UNKNOWN.asException()
        throw RuntimeException("Device is not connected, cannot close")
      }

      val a2dpConnectionStateChangedFlow =
+2 −5
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.util.Log
import io.grpc.Status
import io.grpc.stub.StreamObserver
import java.io.Closeable
import java.util.UUID
@@ -77,8 +76,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable {
      val mtu = request.mtu
      Log.i(TAG, "exchangeMTU MTU=$mtu")
      if (!GattInstance.get(request.connection.address).mGatt.requestMtu(mtu)) {
        Log.e(TAG, "Error on requesting MTU $mtu")
        throw Status.UNKNOWN.asException()
        throw RuntimeException("Error on requesting MTU $mtu")
      }
      ExchangeMTUResponse.newBuilder().build()
    }
@@ -383,8 +381,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable {

  private suspend fun tryDiscoverServices(gattInstance: GattInstance) {
    if (!gattInstance.servicesDiscovered() && !gattInstance.mGatt.discoverServices()) {
      Log.e(TAG, "Error on discovering services for $gattInstance")
      throw Status.UNKNOWN.asException()
      throw RuntimeException("Error on discovering services for $gattInstance")
    } else {
      gattInstance.waitForDiscoveryEnd()
    }
+4 −13
Original line number Diff line number Diff line
@@ -56,11 +56,7 @@ class GattInstance(val mDevice: BluetoothDevice, val mTransport: Int, val mConte
  ) {}
  private var mGattInstanceValuesRead = arrayListOf<GattInstanceValueRead>()

  class GattInstanceValueWrote(
    var uuid: UUID?,
    var handle: Int,
    var status: AttStatusCode
  ) {}
  class GattInstanceValueWrote(var uuid: UUID?, var handle: Int, var status: AttStatusCode) {}
  private var mGattInstanceValueWrote = GattInstanceValueWrote(null, 0, AttStatusCode.UNKNOWN_ERROR)

  companion object GattManager {
@@ -320,7 +316,8 @@ class GattInstance(val mDevice: BluetoothDevice, val mTransport: Int, val mConte
      characteristic.getInstanceId(),
      AttStatusCode.UNKNOWN_ERROR
    )
    if (mGatt.writeCharacteristic(
    if (
      mGatt.writeCharacteristic(
        characteristic,
        value,
        BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT
@@ -329,7 +326,6 @@ class GattInstance(val mDevice: BluetoothDevice, val mTransport: Int, val mConte
      waitForWriteEnd()
    }
    return mGattInstanceValueWrote

  }

  public suspend fun writeDescriptorBlocking(
@@ -341,15 +337,10 @@ class GattInstance(val mDevice: BluetoothDevice, val mTransport: Int, val mConte
      descriptor.getInstanceId(),
      AttStatusCode.UNKNOWN_ERROR
    )
    if (mGatt.writeDescriptor(
        descriptor,
        value
      ) == BluetoothStatusCodes.SUCCESS
    ) {
    if (mGatt.writeDescriptor(descriptor, value) == BluetoothStatusCodes.SUCCESS) {
      waitForWriteEnd()
    }
    return mGattInstanceValueWrote

  }

  public fun disconnectInstance() {
+7 −1
Original line number Diff line number Diff line
@@ -68,7 +68,13 @@ class GattServerManager(
            ByteArray(negociatedMtu)
          )
        } else {
          server.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, ByteArray(512 - offset))
          server.sendResponse(
            device,
            requestId,
            BluetoothGatt.GATT_SUCCESS,
            offset,
            ByteArray(512 - offset)
          )
        }
      }

Loading