N.B.: This question about the serial number of the physical SD card, not the UUID of the mounted volume. These are two independent pieces of data.
In some versions of Android, and other variants of Linux, it's possible to get the serial number of a mounted SD card, e.g. by reading the contents of /sys/class/mmc_host/mmc0/mmc0:0001/serial
or /sys/block/mmcblk0/device/serial
(specific numbers may vary). In my testing this has worked pretty reliably, as long as the SD card is inserted in a built-in SD card slot (not mounted via USB adapter).
But as of Android 7.0 Nougat, the OS is said to be blocking access to this information, at least on some devices. I tested this by running a test app on a new Alcatel A30 GSM (Android 7.0), and in fact the above approach fails with a permission error:
java.io.FileNotFoundException: /sys/block/mmcblk0/device/serial (Permission denied)
at java.io.FileInputStream.open(Native Method)
For future reference, we (testing from an adb shell) have permissions to ls -ld
the following:
/sys/class/mmc_host
but not/sys/class/mmc_host/mmc0
/sys/block
but not/sys/block/mmcblk0
Since the above approach no longer works,
Is there another way to obtain the serial number of a mounted SD card in Android 7.0 or later?
Failing that, is there any documentation or other statement from Google on plans for providing or not providing this function? I haven't found anything in the Android issue tracker, but maybe I'm not searching right.
To make sure the question is clear, I'm talking about what an ordinary (non-system) app running on a non-rooted device can do, with any permissions that an app can normally request and receive.
FYI, the /sbin
directory doesn't seem to be readable, so commands like /sbin/udevadm
aren't an option.
getUuid()
onStorageVolume
. You would getStorageVolume
objects fromStorageManager
. However, I have no idea if the UUID relates to the serial number. – TrigraphgetUuid()
really returns a UUID, then it can't be exactly the chip serial number, because the latter is only 32 bits. However if it's a predictable number based on the chip's serial number, that would be OK. – Archaeornis76DE-3B41
... notable that it's only 8 digits. This was for a chip whose serial number was000fec46
. The volume UUID did not change when when we calledgetUuid()
with a different chip. So the UUID is definitely not the chip serial number. @Commonsware thanks for the idea ... that's more info than I had before. – Archaeornismount
command show anything useful? – Invaginationmount
command shows this line for the SD card:/dev/fuse on /storage/76DE-3B41 type fuse (rw,nosuid,nodev,noexec,noatime,user_id=1023,group_id=1023,default_permissions,allow_other)
. So again, it's not showing the serial number. – Archaeornisandroid.permission.READ_EXTERNAL_STORAGE
. And at your suggestion I looked again at the list of available permissions (normal and dangerous) and didn't see anything else relevant. – ArchaeornisWRITE_EXTERNAL_STORAGE
permission in the manifest. But it doesn't have read permission on the required directories (as noted in the question), let alone write permission. However I don't think the app can do anything about that. – Archaeornis