Quick Affordances are interactive UI elements that appear on the lock screen when the device is locked. They allow the user to perform quick actions without necessarily unlocking their device. For example: opening an screen that lets them control the smart devices in their home, access their touch-to-pay credit card, turn on the flashlight, etc.
All Quick Affordances are defined in System UI code.
To implement a new Quick Affordance, a developer may add a new implementation of KeyguardQuickAffordanceConfig
in the packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance
package/directory and add it to the set defined in KeyguardDataQuickAffordanceModule
.
Tests belong in the packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance
package. This should be enough for the system to pick up the new config and make it available for selection by the user.
"Slots" is what we call the position of Quick Affordances on the lock screen. Each slot has a unique ID and a capacity denoting how many Quick Affordances can be "placed" in that slot.
By default, AOSP ships with a "bottom right" and a "bottom left" slot, each with a slot capacity of 1
, allowing only one Quick Affordance on each side of the lock screen.
OEMs may choose to override the IDs and number of slots and/or override the default capacities. This can be achieved by overridding the config_keyguardQuickAffordanceSlots
resource in packages/SystemUI/res/values/config.xml
.
OEMs may also choose to predefine default Quick Affordances for each slot. To achieve this, a developer may override the config_keyguardQuickAffordanceDefaults
resource in packages/SystemUI/res/values/config.xml
. Note that defaults only work until the user of the device selects a different quick affordance for that slot, even if they select the "None" option.
"Selections" are many-to-many relationships between slots and quick affordances. We add a selection when the user selects a quick affordance for a specific slot. We remove a selection when the user un-selects a quick affordance in a slot or when the user selects an additional quick affordance for a slot that is already at capacity. The definition of each slot tells us the maximum number of quick affordances that may be selected for each slot.
This section describes how to implement a potential picker, selector, or configuration experience for quick affordances.
Quick Affordances structured data are exposed to other applications through the KeyguardQuickAffordanceProvider
content provider which is owned by the System UI process.
To access this content provider, applications must have the android.permission.ACCESS_KEYGUARD_QUICK_AFFORDANCES
permission which is a signature and privileged permission, limiting access to system apps or apps signed by the same signature as System UI. The KeyguardQuickAffordanceProviderContract
file defines the content provider schema for consumers.
Generally speaking, there are three important tables served by the content provider: slots
, affordances
, and selections
. There is also a flags
table, but that's not important and may be ignored.
The slots
, affordances
, and selections
tables may be queried using their Uri
resulting with a Cursor
where each row represents a slot, affordance, or selection, respectively. Note that the affordance list does not include the "None" option.
The selections
table accepts insert
or delete
operations to either add or remove a quick affordance on a slot.
insert
operation on the selections
table Uri
and include the slot_id
of the slot and affordance_id
of the affordance, both in the ContentValues
delete
operation on the selections
table Uri
and include the slot_id
of the slot and the affordance_id
of the affordance to remove as the first and second selection arguments, respectivelyaffordance_id
A picker experience may:
slots
table queryaffordances
table queryselections
table queryTo see the current state of the system, you can run dumpsys
:
$ adb shell dumpsys activity service com.android.systemui/.SystemUIService KeyguardQuickAffordances
The output will spell out the current slot configuration, selections, and collection of available affordances, for example:
KeyguardQuickAffordances: ---------------------------------------------------------------------------- Slots & selections: bottom_start: home (capacity = 1) bottom_end is empty (capacity = 1) Available affordances on device: home ("Home") wallet ("Wallet") qr_code_scanner ("QR code scanner")