自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
不可变的设备 ID
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在 Android 6 及更高版本中,Wi-Fi 服务提供方和数据包分析器已无法再使用 Wi-Fi 堆栈通过网络请求检索设备的出厂 MAC 地址。从 Android 10 开始,系统增加了更多限制,只允许具有特权权限级别的应用访问设备标识符 (ID)。这样可保护各种设备 ID,例如:
- 电话 IMEI、MEID、ESN 和 IMSI 号码。
- build 号、SIM 卡号或 USB 序列号。
谁能访问设备 ID
对设备 ID 的访问在所有 Android 10 设备上都受限,即使应用以 Android 9 或更低版本为目标平台也不例外。可以通过以下方式访问设备 ID:
特权软件包访问权限
软件包必须具有特权才能访问设备 ID。它必须在 Manifest.permission
类中具有
READ_PRIVILEGED_PHONE_STATE
权限,且在 privapp-permission.xml
文件中列入了许可名单。如需了解许可名单流程,请参阅特许权限许可名单。
如需了解如何获取非特权软件包的唯一 ID,请参阅常见用例和适用的标识符。
受限设备 ID 和随机分配的 MAC 地址
为了进一步限制设备 ID,搭载 Android 10 的所有设备默认都会为探测请求和相关请求传输随机分配的 MAC 地址,并且必须为每个 SSID 提供不同的随机分配 MAC 地址。请勿在客户端模式、软接入点 (AP) 或 WLAN 直连用例中使用设备的出厂 MAC 地址。它不允许提供给不是特权应用且可公开访问的 API。需要返回出厂 MAC 地址的特权应用必须具有 LOCAL_MAC_ADDRESS
权限。
用户可以选择保留分配给每个 SSID 的默认随机分配 MAC 地址。可以在设置 > 网络详情中的隐私权下查看该选项。如需了解如何获取随机分配的 MAC 地址,请参阅随机分配的 MAC 地址。
图 1.MAC 地址在“网络详情”中的“隐私权”下显示为随机分配的地址
调用设备 ID API 的应用
调用设备 ID API 的应用必须满足 Android 10 的要求。否则,当它们尝试访问设备 ID 时,将返回以下内容:
- 以 Android 10 为目标平台的应用
- 以 Android 9 或更低版本为目标平台的应用
如需详细了解不可变的设备 ID,请参阅不可重置的设备标识符和唯一标识符最佳做法。
测试
必须阻止应用访问设备序列号,在适用的情况下,也要阻止应用访问 IMEI 或 MEID、SIM 卡序列号和订阅者 ID。有权访问这些 ID 的应用还必须满足谁能访问设备 ID 部分列出的条件之一。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Immutable device IDs\n\nIn Android 6 and higher, Wi-Fi service providers and packet analyzers have\nbeen restricted from retrieving a device's factory MAC address through the\nWi-Fi stack from network requests. Starting in Android 10, additional restrictions are in place that limit access to device\nidentifiers (IDs) to apps with the [privileged](/docs/core/permissions/perms-allowlist)[permission\nlevel](https://developer.android.com/reference/android/R.attr.html#protectionLevel). This protects device IDs such as\n\n- telephony IMEI, MEID, ESN, and IMSI numbers.\n- build, SIM, or USB serial numbers.\n\n### Who can access device IDs\n\nDevice IDs are restricted on all Android 10\ndevices, even if apps target Android 9 or lower. Device IDs can be accessed by:\n\n- The default SMS app.\n- Apps with both [READ_PRIVILEGED_PHONE_STATE](/docs/core/permissions/perms-allowlist#customizing-allowlists) permission in the `\n `[Manifest.permission](https://developer.android.com/reference/android/Manifest.permission) class, and allowlisting in the `privapp-permission.xml` file. These must also be loaded in the `priv-app` directory.\n- Apps with carrier privileges as defined in [UICC Carrier\n Privileges](/docs/core/connect/uicc).\n- A device owner or profile owner with [READ_PHONE_STATE](https://developer.android.com/reference/android/Manifest.permission.html#READ_PHONE_STATE) permission granted in the [Manifest.permission](https://developer.android.com/reference/android/Manifest.permission) class. (Allowlisting isn't required.)\n\n#### Privileged packages access\n\nA package must be privileged to access device IDs. It must have\n[READ_PRIVILEGED_PHONE_STATE](/docs/core/permissions/perms-allowlist#customizing-allowlists) permission in the\n`Manifest.permission` class, and be allowlisted in the\n`privapp-permission.xml` file. For information on the allowlist\nprocess, see [Privileged\nPermission Allowlisting](/docs/core/permissions/perms-allowlist).\n\nFor information on getting a unique ID for a *nonprivileged* package,\nrefer to [Common use cases and the appropriate identifier to use](https://developer.android.com/training/articles/user-data-ids#common-use-cases).\n\n#### Restricted device IDs and randomized MAC addresses\n\nTo further restrict device IDs, all devices on Android 10 transmit randomized MAC addresses by default for both\nprobe and associated requests, and must have a different randomized MAC address\nfor each SSID. Don't use the device factory MAC address in client mode, soft\naccess point (AP), or Wi-Fi Direct use cases. It must remain hidden from\npublicly accessible APIs that aren't privileged apps. Privileged apps that\nrequire the factory MAC address to be returned are required to have\n`LOCAL_MAC_ADDRESS` permission.\n\nUsers have the option to keep the *default randomized* MAC address that's assigned to each SSID.\nThe option is viewable under **Privacy** in\n**Settings** \\\u003e **Network details** . To learn about\nobtaining a randomized MAC address see [Randomized MAC addresses](https://developer.android.com/about/versions/10/privacy/changes#data-ids).\n\n**Figure 1.**MAC address shows as randomized under Privacy in Network details.\n\n#### Apps that invoke device ID APIs\n\nApps that invoke device ID APIs must meet the Android 10 requirements. Otherwise, when they try to access\ndevice IDs the following is returned:\n\n- Apps targeting Android 10\n - [SecurityException](https://developer.android.com/reference/java/lang/SecurityException) is thrown from the device ID APIs.\n- Apps targeting Android 9 or earlier\n - If they have the [READ_PHONE_STATE](https://developer.android.com/reference/android/Manifest.permission.html#READ_PHONE_STATE) permission, either a `null` response or placeholder data is returned.\n - If they don't, the device ID APIs throw [SecurityException](https://developer.android.com/reference/java/lang/SecurityException) that contains the name of the method called, and an indication that the calling app doesn't meet the requirements to access the requested ID.\n\nFor more on immutable device IDs see [Nonresettable\ndevice identifiers](https://developer.android.com/about/versions/10/privacy/changes#data-ids) and [best practices\nfor unique identifiers](https://developer.android.com/training/articles/user-data-ids).\n\n### Testing\n\nApps *must* be prevented from accessing the device serial number and,\nwhere applicable, IMEI or MEID, SIM serial number, and subscriber ID. Apps with\npermission to access these IDs must also meet one of the criteria listed under\n[Who can access device IDs](#who-access)."]]