Skip to content

Commit

Permalink
feat: Return empty list on error for fetchDeviceMicrophones
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed Oct 21, 2023
1 parent dc7a564 commit 07f3c49
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.media.AudioDeviceInfo
import android.media.AudioManager
import android.os.Build
import android.util.Log

val ALLOWED_MICROPHONE_TYPES =
setOf(
Expand Down Expand Up @@ -52,13 +53,19 @@ data class MicrophoneInfo(
}

fun fetchDeviceMicrophones(context: Context): List<MicrophoneInfo> {
val audioManager = context.getSystemService(Context.AUDIO_SERVICE)!! as AudioManager
return (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
audioManager.availableCommunicationDevices.map(::fromDeviceInfo)
} else {
audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS).map(::fromDeviceInfo)
}).filter {
ALLOWED_MICROPHONE_TYPES.contains(it.deviceInfo.type) && it.deviceInfo.isSink
return try {
val audioManager = context.getSystemService(Context.AUDIO_SERVICE)!! as AudioManager
(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
audioManager.availableCommunicationDevices.map(::fromDeviceInfo)
} else {
audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS).map(::fromDeviceInfo)
}).filter {
ALLOWED_MICROPHONE_TYPES.contains(it.deviceInfo.type) && it.deviceInfo.isSink
}
} catch (error: Exception) {
Log.getStackTraceString(error)

emptyList()
}
}
}
Expand Down

0 comments on commit 07f3c49

Please sign in to comment.