Using Libaums just to measure free drive space and then close it
See original GitHub issueLibaums has very fast methods for measuring free drive space and drive capacity, whereas Android 12 has crippled our ability to measure these through normal means. My goal is to copy files to the USB drive using the standard Android API (by getting a Uri from SAF), and then when I’m done I want to use Libaums to measure the drive space. But I’m running into a problem with this, as it seems that SAF won’t fully release control of the USB drive. In fact, trying to init the drive using Libaums corrupts many of the files that were just copied to the USB drive. Is there some way to use Libaums side-by-side with the standard Android APIs?
Here’s my method for measuring space:
fun getDriveInfoFromLibaums(): Boolean {
val deviceListFromLibaums = UsbMassStorageDevice.getMassStorageDevices(appContext)
if (deviceListFromLibaums.isNullOrEmpty()) return false
var usbMassStorageDevice: UsbMassStorageDevice? = null
try {
usbMassStorageDevice = deviceListFromLibaums[0]
val tempUsbDevice = usbMassStorageDevice.usbDevice
usbMassStorageDevice.init()
val currentFileSystem = usbMassStorageDevice.partitions[0].fileSystem
prefs.lastRecordedDriveSize = currentFileSystem.capacity
prefs.lastRecordedDriveFreeSpace = currentFileSystem.freeSpace
usbMassStorageDevice.close()
return true
} catch (throwable: Throwable) {
usbMassStorageDevice?.close()
return false
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
magnusja/libaums - GitHub
A library to access USB mass storage devices (pen drives, external HDDs, card readers) using the Android USB Host API. Currently it supports...
Read more >libaums - can a file copied to or from USB drive be corrupt if ...
The title is the question. I'm using libaums to transfer files both ways using BufferedInput/OutputStream, calling close() at the end. And then ......
Read more >Free up drive space in Windows - Microsoft Support
Learn how you can free up drive space in Windows. Keep your PC running smoothly and up to date by increasing the disk...
Read more >Free up space on your Chromebook - Google Support
Check how much storage is being used. At the bottom right, select the time. Select Settings . In the "Device" section, select Storage...
Read more >Troubleshoot Disk Space Usage on Tableau Server Nodes
Note: Disk space monitoring measures free disk space on each server node. ... in the Tableau Knowledge Base: After Running Out of Hard...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No. Libaums directly accesses the USB drive by issuing SCSI commands directly, bypassing the Linux kernel’s block device subsystem. Android does not, and it should never, since it is not in the condition of a regular unprivileged app that needs to work around limitations.
You should probably look for the source code of
ContentResolver.openAssetFileDescriptor()
, see what it does and see what changed in the latest release.It does not. However, yours doesn’t look like a great idea: there could be pending writes before the user launches your app and you’re likely to corrupt their filesystem.
How about tweaking the user experience so the user doesn’t get bored while you’re loading the disk space? Add a spinner and wait for the file descriptor in a background thread.