Skip to content

Commit 9cdba61

Browse files
authored
Rename bidi exceptions to better match other exceptions (#6818)
1 parent 50c78c1 commit 9cdba61

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/LiveGenerativeModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import com.google.firebase.vertexai.common.APIController
2424
import com.google.firebase.vertexai.common.AppCheckHeaderProvider
2525
import com.google.firebase.vertexai.type.BidiGenerateContentClientMessage
2626
import com.google.firebase.vertexai.type.Content
27-
import com.google.firebase.vertexai.type.GeminiConnectionHandshakeFailed
2827
import com.google.firebase.vertexai.type.LiveGenerationConfig
2928
import com.google.firebase.vertexai.type.LiveSession
3029
import com.google.firebase.vertexai.type.RequestOptions
30+
import com.google.firebase.vertexai.type.ServiceConnectionHandshakeFailedException
3131
import com.google.firebase.vertexai.type.Tool
3232
import io.ktor.websocket.Frame
3333
import io.ktor.websocket.close
@@ -103,7 +103,7 @@ internal constructor(
103103
LiveSession(session = webSession, backgroundDispatcher = backgroundDispatcher)
104104
} else {
105105
webSession.close()
106-
throw GeminiConnectionHandshakeFailed()
106+
throw ServiceConnectionHandshakeFailedException()
107107
}
108108
}
109109

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/AudioHelper.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616

1717
package com.google.firebase.vertexai.type
1818

19+
import android.Manifest
1920
import android.media.AudioFormat
2021
import android.media.AudioManager
2122
import android.media.AudioRecord
2223
import android.media.AudioTrack
2324
import android.media.MediaRecorder
2425
import android.media.audiofx.AcousticEchoCanceler
26+
import androidx.annotation.RequiresPermission
2527
import kotlinx.coroutines.flow.Flow
2628
import kotlinx.coroutines.flow.flow
2729

@@ -66,7 +68,8 @@ internal class AudioHelper {
6668
}
6769
}
6870

69-
suspend fun startRecording(): Flow<ByteArray> {
71+
@RequiresPermission(Manifest.permission.RECORD_AUDIO)
72+
fun startRecording(): Flow<ByteArray> {
7073

7174
val bufferSize =
7275
AudioRecord.getMinBufferSize(
@@ -79,7 +82,9 @@ internal class AudioHelper {
7982
bufferSize == AudioRecord.ERROR_BAD_VALUE ||
8083
bufferSize <= 0
8184
) {
82-
throw AudioRecordInitializationFailedException("Audio Record buffer size is invalid")
85+
throw AudioRecordInitializationFailedException(
86+
"Audio Record buffer size is invalid (${bufferSize})"
87+
)
8388
}
8489
audioRecord =
8590
AudioRecord(
@@ -90,7 +95,9 @@ internal class AudioHelper {
9095
bufferSize
9196
)
9297
if (audioRecord.state != AudioRecord.STATE_INITIALIZED) {
93-
throw AudioRecordInitializationFailedException("Audio Record initialization has failed.")
98+
throw AudioRecordInitializationFailedException(
99+
"Audio Record initialization has failed. State: ${audioRecord.state}"
100+
)
94101
}
95102
if (AcousticEchoCanceler.isAvailable()) {
96103
val echoCanceler = AcousticEchoCanceler.create(audioRecord.audioSessionId)

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Exceptions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public class AudioRecordInitializationFailedException(message: String) :
186186
FirebaseVertexAIException(message)
187187

188188
/** Handshake failed with the server */
189-
public class GeminiConnectionHandshakeFailed :
189+
public class ServiceConnectionHandshakeFailedException :
190190
FirebaseVertexAIException("Handshake failed with the server.")
191191

192192
/** Catch all case for exceptions not explicitly expected. */

0 commit comments

Comments
 (0)