如何在Android 7.0+中检索SD卡的序列号? [英] How can I retrieve an SD card's serial number in Android 7.0+?

查看:666
本文介绍了如何在Android 7.0+中检索SD卡的序列号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

N.B .:有关物理SD卡的序列号,而不是已安装的的UUID的问题.这是两个独立的数据.

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.

在某些版本的Android和其他版本的Linux中,可以获取已安装SD卡的序列号,例如通过读取/sys/class/mmc_host/mmc0/mmc0:0001/serial/sys/block/mmcblk0/device/serial的内容(特定数字可能会有所不同).在我的测试中,只要将SD卡插入内置SD卡插槽(未通过USB适配器安装)中,该方法就可以非常可靠地工作.

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).

但是从Android 7.0牛轧糖开始,据说 OS阻止了对的访问此信息,至少在某些设备上.我通过在新的阿尔卡特A30 GSM(Android 7.0)上运行测试应用程序对此进行了测试,实际上上述方法由于权限错误而失败:

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)

为了将来参考,我们(通过adb shell测试)具有ls -ld以下内容的权限:

For future reference, we (testing from an adb shell) have permissions to ls -ld the following:

  • /sys/class/mmc_host,但不是/sys/class/mmc_host/mmc0
  • /sys/block但不是/sys/block/mmcblk0
  • /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,

  • 还有另一种方法来获取Android 7.0或更高版本中已安装SD卡的序列号吗?

  • Is there another way to obtain the serial number of a mounted SD card in Android 7.0 or later?

是否失败,Google是否提供有关提供或不提供此功能的计划的任何文档或其他声明?我在Android 问题跟踪器,但也许我搜索不正确.

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.

仅供参考,/sbin目录似乎不可读,因此/sbin/udevadm之类的命令不是可选项.

FYI, the /sbin directory doesn't seem to be readable, so commands like /sbin/udevadm aren't an option.

推荐答案

在Android N中,对/sys nad/proc的访问受到了严格限制,这样做是为了在运行应用程序的地方提供更严格的沙箱. https://issuetracker.google.com/issues/37091475 中对此进行了有意的解释.实际上,并不是说/sys中的所有数据都是不可访问的,并且Google已打开以允许从该位置访问其他文件:

In Android N access to /sys nad /proc was significantly restricted, this was done to provide stricter sandboxes where applications run. This is explained in https://issuetracker.google.com/issues/37091475 as intentional. Actually its not said that all the data in /sys is not accessible, and Google is open to allow access to other files from this location:

如果/sys中有特定文件,您认为应为应用程序可用,但不能,请提交一个新的bug来评估请求.例如,/sys/devices/system/cpu对所有进程都可用,因此说/sys都受限制是不准确的.

If there are specific files in /sys you believe should be available to applications, but are not, please file a new bug where the request can be evaluated. For instance, /sys/devices/system/cpu is available to all processes, so it's inaccurate to say all of /sys is restricted.

我很难过,谷歌正在做出类似于苹果的更改,因为苹果不允许获得硬件ID.如果仍无法解决,则解决方案是改用Google帐户ID.但我知道这并非总是可能的,并且需要对业务逻辑(许可等)进行重大更改.

I have a bad feeling that google is making changes similar to Apple where it is not allowed to gain hardware id-s. If that is not resolved then the solution is to use google account IDs instead. But I am aware it is not always possible, and will require major changes in business logic (licensing etc.).

希望您的错误报告会得到肯定.

Hopefully your bug report will be considered positively.

我发现了另一个相关的SO: Android牛轧糖中的文件系统更改

another related SO I found : File system changes in Android Nougat

这篇关于如何在Android 7.0+中检索SD卡的序列号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆