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的某些版本和Linux的其他版本中,可以获得已安装的SD卡的序列号,例如,通过读取/ sys / class / mmc_host / mmc0 / mmc0:0001 / serial或/ sys / block / mmcblk0 / device / serial的内容(具体数字可能会有所不同)。在我的测试中,只要将SD卡插入内置SD卡插槽(不通过USB适配器安装),这就非常可靠。

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:

但是从Android 7.0 Nougat开始,据说操作系统阻止访问这些信息,至少在某些设备上是这样。我通过在新的阿尔卡特A30 GSM(Android 7.0)上运行测试应用程序对此进行了测试,实际上上述方法失败并出现权限错误:

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:

为了将来参考,我们(从adb shell测试)拥有ls -ld以下权限:

  • /sys/class/mmc_host but not /sys/class/mmc_host/mmc0
  • / sys / class / mmc_host但不是/ sys / class / mmc_host / mmc0

  • /sys/block but not /sys/block/mmcblk0
  • / sys / block但不是/ 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?

    有没有其他方法可以获得Android 7.0或更高版本中安装的SD卡的序列号?

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

    如果不这样做,谷歌是否有关于提供或不提供此功能的计划的任何文件或其他声明?我没有在Android问题跟踪器中找到任何内容,但也许我没有找到正确的搜索引擎。

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.

仅供参考,/ sbin目录似乎不可读,因此像/ sbin / udevadm这样的命令不是一个选项。

3 个解决方案

#1


4

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:

在Android N中,对/ sys nad / proc的访问受到严格限制,这样做是为了提供应用程序运行的更严格的沙箱。这在https://issuetracker.google.com/issues/37091475中有意解释。实际上并没有说/ 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.

如果/ sys中存在特定文件,您认为应该可以提供给应用程序,但不是,请提交新的错误,以便评估请求。例如,/ sys / devices / system / cpu可用于所有进程,因此说/ sys受限制是不准确的。

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

我有一种不好的感觉,谷歌正在进行类似于苹果的改变,不允许获得硬件ID。如果没有解决,那么解决方案是使用谷歌帐户ID。但我知道这并不总是可行的,并且需要对业务逻辑进行重大更改(许可等)。

Hopefully your bug report will be considered positively.

希望您的错误报告将被认为是积极的。

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

另一个相关的SO我发现:Android Nougat中的文件系统更改

更多相关文章

  1. 为什么我的Android应用程序偶尔可以非常快地耗尽电池?
  2. 如何在android 5.0(L)中运行应用程序活动名称?
  3. Android应用程序启动过程上
  4. android 判断MIUI悬浮窗权限是否打开
  5. Java Android套接字连接。错误的IP地址导致应用程序停止响应
  6. Android下usb host接口插入usb设备时,如何屏蔽usb权限的提示框? 如
  7. Android 为你的应用程序添加快捷方式【优先级高的快捷方式】
  8. 添加脚本到Android应用程序
  9. 如何使用java RESTful Web服务将通知推送到Android应用程序

随机推荐

  1. [SQL SERVER系列]工作经常使用的SQL整理,
  2. MSSQL中类似MySQL的limit参数
  3. 如何找到一个具有负值而另一个具有相同正
  4. 求助,关于sql带入参数的写法问题。
  5. 参数化的Insert语句,事务抛出错误
  6. linux 上安装postgresql 并配置pgadmin i
  7. 将mysql查询转换为sql server查询
  8. 待解决 WIN7下安装完sql2005后没有服务器
  9. SQL Server 批量更新字段值为ROW_NUMBER(
  10. 窥探SQL预编译内幕