Tim Malseed
07/11/2020, 5:32 AMsuspend fun getAudio(songId: Long): AudioStream? {
return withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
songRepository.getSongs(SongQuery.SongIds(listOf(songId))).firstOrNull()?.firstOrNull()?.let { song ->
val uri = Uri.parse(song.path)
if (song.path.startsWith("content://")) {
if (DocumentsContract.isDocumentUri(context, uri)) {
val documentFile = DocumentFile.fromSingleUri(context, uri)
documentFile?.let {
context.contentResolver.openInputStream(documentFile.uri)?.let { inputStream ->
AudioStream(inputStream, documentFile.length(), documentFile.type ?: "audio/*")
}
}
} else {
context.contentResolver.openInputStream(uri)?.let { inputStream ->
AudioStream(inputStream, song.size, song.mimeType)
}
}
} else {
AudioStream(File(uri.toString()).inputStream(), song.size, song.mimeType)
}
}
}
}
AS complains that openInputStream()
is an ‘inappropriate blocking call’
Is this a false positive by AS, or am I doing something wrong here?Erik
07/11/2020, 8:43 AMTim Malseed
07/11/2020, 8:56 AMwithContext(<http://Dispatchers.IO|Dispatchers.IO>)
. I think I understand the warning, but it seems potentially incorrect here.. I've read about this elsewhere but I don't feel confident that the code in my example is equivalent.Mark Murphy
07/11/2020, 12:20 PMwithContext(<http://Dispatchers.IO|Dispatchers.IO>
). See https://issuetracker.google.com/issues/160491867 for one case that I filed, where +
to chain CoroutineContext
objects together confuses that inspection.