On book-style foldable devices, you can enable support for tent and wedge modes.
Tent and wedge modes let you use the outer screen when the device is slightly open, as shown in the following figure:
Figure 1. Tent and wedge foldable postures.
In the tent mode, the device is partially open, using both halves to support itself like a tent. In the wedge mode, the device is propped up on its right half, which lies flat on a surface.
Android 16 and higher supports this behavior by using
BookStyleDeviceStatePolicy
as your device state policy. This policy works
on a foldable device with two screens in a book style, with the hinge located
on the left side of the device when folded.
This policy keeps the outer screen on longer when unfolding under certain conditions, for example:
- The right half of the device is mostly flat, indicating that the device is likely in wedge mode.
- The device orientation is reverse landscape, indicating that it's likely in tent mode.
- The screen orientation is landscape or reverse landscape.
- There is an app holding a screen wakelock (preventing screen timeout).
The policy doesn't introduce a separate device state for tent or wedge posture; it keeps the closed state for a wider range of hinge angles under these specific conditions.
To fully support these heuristics, the device needs:
- Hinge angle sensor reporting the angle between the two halves of the device
- Accelerometer sensor on each (left and right) halves of the device
Configure tent or wedge mode
Follow these steps to enable tent and wedge mode support on your device:
Create an implementation of
DeviceStatePolicy.Provider
that returns an instance ofBookStyleDeviceStatePolicy
. The instance must provide all the necessary dependencies, like sensor objects, to theBookStyleDeviceStatePolicy
constructor.The following example shows an implementation:
package com.example; public class MyDevicePolicyProvider implements DeviceStatePolicy.Provider { @Override public DeviceStatePolicy instantiate(@NonNull Context context) { final SensorManager sensorManager = context.getSystemService(SensorManager.class); final Sensor hingeAngleSensor = sensorManager.getDefaultSensor(Sensor.TYPE_HINGE_ANGLE, /* wakeUp= */ true); final List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL); final Sensor hallSensor = CollectionUtils.find(sensors, (sensor) -> Objects.equals(sensor.getStringType(), "com.example.hall_effect")); final Sensor rightAccelerometerSensor = CollectionUtils.find(sensors, (sensor) -> Objects.equals(sensor.getName(), "Accelerometer 0")); final Sensor leftAccelerometerSensor = CollectionUtils.find(sensors, (sensor) -> Objects.equals(sensor.getName(), "Accelerometer 1")); // You can pass a non-null value here to disable tent/wedge mode logic, // so the displays switch will always happen at the fixed hinge angle. // This might be useful, for example, when in a retail demo mode where // the hinge angle range of the device is limited. final Integer closeAngleDegrees = null; return new BookStyleDeviceStatePolicy(new FeatureFlagsImpl(), context, hingeAngleSensor, hallSensor, leftAccelerometerSensor, rightAccelerometerSensor, closeAngleDegrees); } }
Add the policy provider to system server's classpath. Start by creating a library with the device state policy provider class that you created in the previous step.
The following example shows a Soong
Android.bp
blueprint configuration:java_library { name: "my-device-services", installable: true, system_ext_specific: true, srcs: [ "src/**/*.java" ], libs: [ "services", ], }
Then, to add this library to the system server, modify the device's makefile by adding the following lines:
# Add system service libraries (they contain device-specific policies) PRODUCT_SYSTEM_SERVER_JARS += \ my-device-services PRODUCT_PACKAGES += \ my-device-services
Update
config_deviceSpecificDeviceStatePolicyProvider
to the class name of your provider in theconfig.xml
file, for example:<string translatable="false" name="config_deviceSpecificDeviceStatePolicyProvider">com.example.MyDevicePolicyProvider</string>