自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
鎖定畫面
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
AOSP 預設實作方式會在主螢幕上顯示鎖定畫面,並提供解鎖功能 (鎖定畫面)。在 Android 9 (及以下版本) 中,次要螢幕支援在單一外接螢幕上顯示單一鎖定視窗。在 Android 10 中,螢幕鎖定畫面會擴展至所有公開的次要螢幕。鎖定螢幕仍保持簡單,且不支援從次要螢幕解鎖。

圖 1. 次要螢幕上的螢幕鎖定畫面
只要符合基本安全性需求,裝置製造商就可以為次要螢幕實作鎖定畫面。裝置鎖定時,所有螢幕上的資訊都應安全隱藏。系統並未內建政策或控管機制,無法控制裝置鎖定時應顯示或隱藏哪些內容。因此,實施限制存取權的唯一安全方法,就是將所有內容隱藏在鎖定畫面和鎖定視窗後方。唯一的例外狀況是,應用程式已明確選擇使用 R.attr.showWhenLocked
或 Activity.setShowWhenLocked()
方法,在螢幕鎖定畫面頂端顯示。否則,很可能會從公開和私人顯示畫面洩漏資訊。
雖然螢幕可處於不同的狀態 (ON
/OFF
),但鎖定狀態是所有螢幕的全球狀態。如同任何裝置實作方式,使用者應能清楚瞭解裝置是否已鎖定 (或解鎖)。舉例來說,按下電源鍵通常會鎖定行動裝置。電源鍵也應鎖定所有內部和外部螢幕。
由於鎖定視窗由 SystemUI 擁有,因此不會放置在私人顯示畫面上。私人螢幕的擁有者有責任在裝置鎖定時隱藏視窗並保護內容。預設的系統實作方式「只會」透過變更隱藏狀態,隱藏私人螢幕上的活動。
實作
在次要螢幕上鎖定的視窗會在 KeyguardDisplayManager
中實作為 Presentation 視窗。Android 10 將 KeyguardDisplayManager#mPresentations
變更為陣列,可保留所有次要螢幕的所有鎖定視窗。KeyguardDisplayManager
也設有顯示器變更事件監聽器,可回應可用顯示器的變更,並保護所有畫面。請務必隨時立即鎖定所有已連結的螢幕,這樣即使攻擊者可以存取裝置,也無法擷取使用者資料。
鎖定視窗會顯示在所有公開的次要螢幕上 (請參閱 KeyguardDisplayManager#isKeyguardShowable()
)。私人螢幕的擁有者負責在裝置鎖定時保護內容。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# 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."]]