自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
锁定屏幕
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在 AOSP 中,具有解锁用户选项 (keyguard) 的锁定屏幕的默认实现仅出现在主显示屏上。在 Android 9(及更低版本)中,辅助屏幕在单个外部显示屏上支持单个锁定窗口。在 Android 10 中,锁定屏幕扩展到所有公共辅助显示屏。锁定屏幕仍然很简单,但不支持从辅助屏幕解锁。

图 1. 辅助屏幕上的锁定屏幕
如果满足基本安全要求,设备制造商可以为辅助显示屏实现其自己的锁定屏幕。当设备锁定时,信息应在所有屏幕上安全地隐藏起来。对于设备锁定时应显示或隐藏哪些内容,没有相关的内置政策或控制。因此,实现受限访问的唯一安全方式是,将所有内容隐藏到锁定屏幕和锁定窗口之后。仅有的例外情况是使用 R.attr.showWhenLocked
或 Activity.setShowWhenLocked()
方法明确选择在锁定屏幕之上显示的应用。否则,信息很有可能从公共和个人屏幕泄露。
虽然屏幕可以处于不同的状态 (ON
/OFF
),但是锁定状态对所有屏幕而言是全局性的。与任何设备实现一样,应该让用户清楚地知道设备何时会锁定(或解锁)。例如,按下电源按钮通常会锁定移动设备。此外,电源按钮还应锁定所有内部和外部屏幕。
由于锁定窗口归 SystemUI 所有,因此不会放置在个人屏幕上。个人屏幕的所有者负责在设备锁定时隐藏窗口并保护内容。默认系统实现通过更改公开范围仅隐藏个人显示屏上的 activity。
实现
辅助屏幕上的锁定窗口在 KeyguardDisplayManager
中以 Presentation 窗口的形式实现。Android 10 将 KeyguardDisplayManager#mPresentations
更改为一个数组,其中包含所有辅助屏幕的所有锁定窗口。KeyguardDisplayManager
还包含一个屏幕更改监听器,可响应对可用屏幕的更改并保护所有屏幕。请务必在任何给定时间立即锁定所有连接的屏幕,这样,即使攻击者对设备进行物理访问,也无法提取用户数据。
锁定窗口会显示在所有公共辅助屏幕上(请参阅 KeyguardDisplayManager#isKeyguardShowable()
)。个人屏幕的所有者负责在设备锁定时保护内容。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-04-06。
[[["易于理解","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-04-06。"],[],[],null,["# Lock screen\n\nAOSP's default implementation of the Lock screen with affordances to unlock\nit (keyguard) appears only on the primary display. In Android 9 (and lower),\nsecondary screens supported a single *locking window* on a single external\ndisplay. In Android 10, the Lock screen is expanded to all public secondary\ndisplays. The Lock screen remains simple and doesn't support unlocking from secondary\nscreens.\n\n**Figure 1.** Lock screen on secondary display\n\nDevice manufacturers can implement their Lock screen for secondary displays,\nprovided the fundamental security requirement is fulfilled. When the device is\nlocked, information should be securely concealed on all displays. There's no\nbuilt-in policy or control over what content should be shown or hidden when device\nis locked. Therefore, the only secure way of implementing restricted access is to\nhide all content behind the Lock screen and locking windows. The only exceptions\nare apps that have explicitly opted in to be displayed on top of the Lock screen\nusing the\n[R.attr.showWhenLocked](https://developer.android.com/reference/android/R.attr.html#showWhenLocked) or\n[Activity.setShowWhenLocked()](https://developer.android.com/reference/android/app/Activity.html#setShowWhenLocked(boolean)) methods.\nOtherwise, there is strong potential to leak information from public and private\ndisplays.\n\nWhile displays can be placed in to different states (`ON`/`OFF`),\nthe locked state is global for all displays. As with any device implementation, it should\nbe obvious to a user when a device is locked (or unlocked). For example, pressing\na power button typically locks a mobile device. A power button should also lock all\ninternal and external screens.\n\nBecause the locking window is owned by SystemUI, it won't be placed on\nprivate displays. Owners of the private displays are responsible for hiding\nthe windows and protecting content when a device is locked. The default system\nimplementation *only* hides activities on private displays by changing\nvisibility.\n\nImplementation\n--------------\n\nThe locking window on secondary displays is implemented as a [Presentation](https://developer.android.com/reference/android/app/Presentation)\nwindow in `KeyguardDisplayManager`. Android 10 changed\n`KeyguardDisplayManager#mPresentations` to an array that holds all\nlocking windows for all secondary screens. `KeyguardDisplayManager` also\nhas a display-change listener to respond to changes to the available displays and\nsecure all screens. It's important to immediately lock all connected displays at\nany given time so that attackers can't extract user data even with physical access\nto the device.\n\nThe locking window is displayed on all public secondary displays (see\n`KeyguardDisplayManager#isKeyguardShowable()`). Owners of private\ndisplays are responsible for securing the content when a device is\nlocked."]]