自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
固定裝置 ID
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
在 Android 6 以上版本中,Wi-Fi 服務供應商和封包分析器已受到限制,無法透過網路要求的 Wi-Fi 堆疊擷取裝置的出廠 MAC 位址。自 Android 10 起,我們已實施額外限制,將裝置 ID 存取權限限制給具備
特權權限層級的應用程式。這麼做可保護裝置 ID,例如
- 電話 IMEI、MEID、ESN 和 IMSI 號碼。
- 版本、SIM 卡或 USB 序號。
誰可以存取裝置 ID
即使應用程式指定 Android 9 以下版本,裝置 ID 仍會受到限制。裝置 ID 可供下列使用者存取:
特殊權限套件存取權
套件必須具備存取裝置 ID 的權限。該類別必須在 Manifest.permission
類別中具有
READ_PRIVILEGED_PHONE_STATE
權限,並在 privapp-permission.xml
檔案中列入許可清單。如要瞭解許可清單程序,請參閱「特權權限許可清單」。
如要瞭解如何取得非特權套件的專屬 ID,請參閱「
常見用途和適用的適當 ID」。
限制裝置 ID 和隨機 MAC 位址
為進一步限制裝置 ID,Android 10 上的所有裝置預設會為探測和相關聯的要求傳送隨機 MAC 位址,且每個 SSID 都必須有不同的隨機 MAC 位址。請勿在用戶端模式、軟體存取點 (AP) 或 Wi-Fi Direct 用途中使用裝置工廠 MAC 位址。它必須隱藏在非特權應用程式可公開存取的 API 中。需要返回原廠 MAC 位址的特權應用程式必須具備 LOCAL_MAC_ADDRESS
權限。
使用者可以選擇保留為每個 SSID 指派的預設隨機 MAC 位址。您可以在「設定」 >「網路詳細資料」的「隱私權」下方查看這個選項。如要瞭解如何取得隨機 MAC 位址,請參閱「
隨機 MAC 位址」。
圖 1.「隱私權」的「網路詳細資料」下方顯示 MAC 位址已隨機化。
叫用裝置 ID API 的應用程式
呼叫裝置 ID API 的應用程式必須符合 Android 10 規定。否則,當他們嘗試存取裝置 ID 時,系統會傳回以下內容:
- 鎖定 Android 10 的應用程式
- 指定 Android 9 以下版本的應用程式
如要進一步瞭解不可變動的裝置 ID,請參閱「不可重設的裝置 ID」和「專屬 ID 的最佳做法」。
測試
應用程式必須禁止存取裝置序號,以及適用情況下的 IMEI 或 MEID、SIM 卡序號和訂閱者 ID。具有存取這些 ID 權限的應用程式,也必須符合「誰可以存取裝置 ID」一節所列的其中一個條件。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間: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"]],["上次更新時間: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)."]]