In Android 12, this method call takes multiple seconds to return:
val descriptor = contentResolver.openAssetFileDescriptor(rootUri, "r")
I'm passing it a tree Uri which represents the root of a USB drive. The call takes longer depending on how much space is taken up on the root. So for 1GB, it takes about 10 seconds. This isn't the case in previous Android versions, where the call returns in just a few millis.
My goal is to measure the space on a USB drive using the code below. Is there something else I can do to make this complete in a reasonable amount of time?
val descriptor = contentResolver.openAssetFileDescriptor(rootUri, "r")
val stats = Os.fstatvfs(descriptor!!.fileDescriptor)
val availableSpace = stats.f_bavail * stats.f_bsize
contentResolver.openAssetFileDescriptor()
call. I included the rest of the code just to give context for what I'm trying to achieve. If I measure each of those three lines, the first takes multiple seconds while the other two are almost instantaneous. – Crucify