自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
測試裝置管理
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
為確保受管理的設定檔獲得最低程度的支援,原始設備製造商 (OEM) 裝置必須包含下列必要元素:
如需完整的規定清單,請參閱「實作裝置管理」。如要測試裝置管理功能,裝置擁有者可以使用下方所述的 TestDPC 應用程式。
設定測試裝置的擁有者
請按照下列操作說明設定裝置擁有者測試環境。
- 將目標裝置恢復原廠設定。
- 確認裝置中沒有任何使用者帳戶 (例如用於登入線上服務的帳戶)。如要確認,請依序前往「設定」>「帳戶」。
- 請使用下列任一方法設定測試應用程式:
- 使用下列指令將 TestDPC 應用程式設為裝置擁有者:
adb shell dpm set-device-owner "com.afwsamples.testdpc/.DeviceAdminReceiver"
- 在裝置上完成裝置擁有者設定 (加密、選取 Wi-Fi)。
驗證裝置擁有者設定
如要確認裝置擁有者已正確設定,請依序前往「設定」>「安全性」>「裝置管理員」,確認「TestDPC」是否在清單中。確認該裝置無法停用 (這表示該裝置是裝置擁有者)。
錯誤報告和記錄
自 Android 7.0 起,裝置擁有者的裝置政策用戶端 (DPC) 可取得受管理裝置上的企業程序錯誤報告和記錄。
如要觸發錯誤報告 (即 adb bugreport
收集到的等同資料,包含 dumpsys
、dumpstate 和 logcat 資料),請使用 DevicePolicyController.requestBugReport
。收集錯誤回報後,系統會提示使用者同意傳送錯誤回報資料。結果會由 DeviceAdminReceiver.onBugreport[Failed|Shared|SharingDeclined]
接收。如要進一步瞭解錯誤報告內容,請參閱「讀取錯誤報告」。
此外,裝置擁有者 DPC 也可以收集使用者在受管理裝置上採取的動作相關記錄。所有回報 device_admin 且啟用新記錄安全性緩衝區的裝置都需要企業程序記錄功能,且只有系統伺服器可以讀取該緩衝區 (也就是 $ adb logcat -b security
無法讀取緩衝區)。ActivityManager 服務和 Keyguard 元件會將下列事件記錄到安全性緩衝區:
- 應用程式程序啟動
- 鎖定畫面動作 (例如解鎖失敗和成功)
- 向裝置發出的
adb
指令
如要選擇在重新啟動 (非冷啟動) 時保留記錄,並讓裝置擁有者 DPC 使用這些記錄,裝置必須具備啟用 pstore
和 pmsg
的核心,並在重新啟動的所有階段啟用和重新整理 DRAM,以免損毀在記憶體中保留的記錄。如要啟用支援功能,請使用 frameworks/base/core/res/res/values/config.xml
中的 config_supportPreRebootSecurityLogs
設定。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Test device management\n\nTo ensure minimal support for managed profiles, OEM devices must contain the\nfollowing essential elements:\n\n- Profile owner (as described in [Ensuring\n Compatibility with Managed Profiles](https://developer.android.com/training/enterprise/app-compatibility.html))\n- Device owner\n\nFor a complete list of requirements, see\n[Implement device\nmanagement](/docs/devices/admin/implement). To test device management features, device owners can\nuse the TestDPC application described below.\n\nSet up device owner for testing\n-------------------------------\n\nUse the following instructions to set up a device owner testing environment.\n\n1. Factory reset the target device.\n2. Ensure the device does not contain any user accounts (for example, those used to log into online services). To verify, check *Settings \\\u003e Accounts*.\n3. Set up the testing application using one of the following methods:\n - [Download\n the TestDPC application](https://play.google.com/store/apps/details?id=com.afwsamples.testdpc&hl=en) (available from Google Play).\n - [Build\n the TestDPC application](https://github.com/googlesamples/android-testdpc/) (available from github.com).\n4. Set the TestDPC app as the device owner using the following command: \n\n ```\n adb shell dpm set-device-owner \"com.afwsamples.testdpc/.DeviceAdminReceiver\"\n ```\n5. Go through device owner setup on the device (encrypt, select Wi-Fi).\n\nVerify device owner setup\n-------------------------\n\nTo verify the device owner was correctly setup, go to *Settings \\\u003e\nSecurity \\\u003e Device Administrators* and confirm TestDPC is in the\nlist. Verify it cannot be disabled (this signifies it is a device owner).\n\nBug reports and logs\n--------------------\n\nAs of Android 7.0, device owner Device Policy Client (DPCs) can get bug\nreports and view logs for enterprise processes on a managed device.\n\nTo trigger a bug report (that is, the equivalent data collected by\n`adb bugreport` containing `dumpsys`, dumpstate, and\nlogcat data), use `DevicePolicyController.requestBugReport`. After\nthe bug report is collected, the user is prompted to give consent to send the\nbug report data. Results are received by\n`DeviceAdminReceiver.onBugreport[Failed|Shared|SharingDeclined]`. For\ndetails on bug report contents, see\n[Reading bug reports](/docs/setup/read-bug-reports).\n\nIn addition, device owner DPCs can also collect logs related to actions a\nuser has taken on a managed device. Enterprise process logging is required for\nall devices that report device_admin and enabled by a new log security buffer\nreadable only by the system server (that is, `$ adb logcat -b security`\ncannot read the buffer). ActivityManager service and Keyguard components log the\nfollowing events to the security buffer:\n\n- Application processes starting\n- Keyguard actions (for example, unlock failure and success)\n- `adb` commands issued to the device\n\nTo optionally retain logs across reboots (not cold boot) and make these logs\navailable to device owner DPCs, a device must have a kernel with\n`pstore` and `pmsg` enabled, and DRAM powered and\nrefreshed through all stages of reboot to avoid corruption to the logs retained\nin memory. To enable support, use the\n`config_supportPreRebootSecurityLogs` setting in\n`frameworks/base/core/res/res/values/config.xml`."]]