I'm trying to measure the free space and drive capacity of a USB drive. The below code for measuring free space works well in previous Android versions, and a similar technique can measure drive capacity:
val descriptor = contentResolver.openAssetFileDescriptor(rootUri, "r")
val stats = Os.fstatvfs(descriptor!!.fileDescriptor)
val availableSpace = stats.f_bavail * stats.f_bsize
But in Android 12 this approach is no longer viable, as calling ContentResolver.openAssetFileDescriptor() now takes way longer for some reason. Nothing in the Android 12 change list seems to be responsible for this. I've even tried to look at the source code for this method and haven't been able to find anything that changed from Android 11 to 12.
Is there some alternative for measuring drive space? Or any explanation whatsoever for why ContentResolver.openAssetFileDescriptor() takes so much longer to execute?