OEMs can configure an option on foldable devices that lets users choose how the outer screen behaves when they fold the device from an unlocked and unfolded state.
The setting is located in Settings > Display > Continue using apps on fold. The user has the following three options:
- Always: When the user folds the device, the front display always turns on and remains unlocked.
- Swipe up to continue: When the user folds the device, the device shows the keyguard without requiring authentication, unless an app is holding a wakelock, in which case the device stays awake on the app. This is the default setting.
- Never: When the user folds the device, the device locks and the front display turns off.
Figure 1. Fold lock behavior setting.
Configure fold lock behavior setting
To display the fold lock behavior setting in Settings, populate the
config_fold_lock_behavior
boolean in your device's overlay config.xml
file:
<!-- Whether to show Fold lock behavior setting feature in Settings app -->
<bool name="config_fold_lock_behavior">true</bool>
Implementation details
The fold lock behavior is controlled by a setting and several backend classes.
Setting and UI
The value of the FOLD_LOCK_BEHAVIOR
setting is persisted as a string,
which corresponds to the user's selection in Settings > Display > Continue
using apps on fold:
- Always:
stay_awake_on_fold_key
- Swipe up to continue:
selective_stay_awake_key
- Never:
sleep_on_fold_key
The setting is inflated from display_settings.xml
. The setting page UI
is implemented in the FoldLockBehaviorSettings
fragment, and the
preference is managed by FoldLockBehaviorPreferenceController
.
Backend logic
When the device is folded, LogicalDisplayMapper
and
PowerManager
control device behavior as follows:
LogicalDisplayMapper
reads theFOLD_LOCK_BEHAVIOR
setting value usingFoldSettingProvider
.- Based on the setting value:
- If the value is
stay_awake_on_fold_key
, the device remains awake. - If the value is
selective_stay_awake_key
orsleep_on_fold_key
,LogicalDisplayMapper
sends a#goToSleep
signal toPowerManager
.- For
selective_stay_awake_key
, the#goToSleep
signal includes the flagPowerManager.GO_TO_SLEEP_FLAG_SOFT_SLEEP
. This causes the device to show the keyguard without requiring authentication. - For
sleep_on_fold_key
, the#goToSleep
signal is sent without this flag, causing the device to lock.
- For
- If the value is