自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
测试设备管理
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
为确保为受管理个人资料提供最基本的支持,原始设备制造商 (OEM) 设备必须包含以下基本元素:
如需查看完整的要求列表,请参阅实现设备管理。如需测试设备管理功能,设备所有者可以使用 TestDPC 应用(如下所述)。
设置设备所有者以进行测试
请按照以下说明设置设备所有者测试环境。
- 将目标设备恢复出厂设置。
- 确保设备不含任何用户账号(例如,用于登录在线服务的用户账号)。要进行验证,请依次选择“设置”>“账号”。
- 使用以下某种方法设置测试应用:
- 使用以下命令将 TestDPC 应用设置为设备所有者:
adb shell dpm set-device-owner "com.afwsamples.testdpc/.DeviceAdminReceiver"
- 在设备上完成设备所有者设置(加密、选择 Wi-Fi)。
验证设备所有者设置
如需验证设备所有者是否已正确设置,请依次前往“设置”>“安全”>“设备管理员”,并确认 TestDPC 已在列表中。验证确保它无法被停用(这表明它就是设备所有者)。
错误报告和日志
自 Android 7.0 起,设备所有者 Device Policy Client (DPC) 可以获取受管理设备上企业进程的错误报告并查看日志。
如需触发 bug 报告(即由 adb bugreport
收集的对应数据,包含 dumpsys
、dumpstate 和 logcat 数据),请使用 DevicePolicyController.requestBugReport
。收集 bug 报告后,系统会提示用户同意发送 bug 报告数据。结果将由 DeviceAdminReceiver.onBugreport[Failed|Shared|SharingDeclined]
接收。如需详细了解 bug 报告内容,请参阅阅读 bug 报告。
此外,设备所有者 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 和/或其关联公司的注册商标。
最后更新时间 (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,["# 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`."]]