1818import android .app .Activity ;
1919import android .content .Context ;
2020import android .content .res .Configuration ;
21+ import android .hardware .devicestate .DeviceStateManager ;
22+ import android .os .Build ;
2123import android .os .Bundle ;
22- import android .server .wm .jetpack .utils .SidecarUtil ;
2324import android .server .wm .jetpack .utils .ExtensionUtil ;
25+ import android .server .wm .jetpack .utils .SidecarUtil ;
2426import android .server .wm .jetpack .utils .Version ;
2527import android .util .DisplayMetrics ;
2628import android .view .Display ;
2729import android .view .WindowManager ;
2830
31+ import androidx .annotation .RequiresApi ;
32+
2933import com .android .compatibility .common .util .DeviceInfoStore ;
3034import com .android .compatibility .common .util .DummyActivity ;
3135
36+ import java .io .IOException ;
37+
3238/**
3339 * Screen device info collector.
3440 */
@@ -39,6 +45,7 @@ protected void collectDeviceInfo(DeviceInfoStore store) throws Exception {
3945 DisplayMetrics metrics = new DisplayMetrics ();
4046 WindowManager windowManager =
4147 (WindowManager ) getContext ().getSystemService (Context .WINDOW_SERVICE );
48+
4249 Display display = windowManager .getDefaultDisplay ();
4350 display .getRealMetrics (metrics );
4451
@@ -55,6 +62,11 @@ protected void collectDeviceInfo(DeviceInfoStore store) throws Exception {
5562
5663 // Add WindowManager Jetpack Library version and available display features.
5764 addDisplayFeaturesIfPresent (store );
65+
66+ // Add device states from DeviceStateManager if available.
67+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
68+ addDeviceStatesIfAvailable (store );
69+ }
5870 }
5971
6072 private void addDisplayFeaturesIfPresent (DeviceInfoStore store ) throws Exception {
@@ -85,6 +97,17 @@ private void addDisplayFeaturesIfPresent(DeviceInfoStore store) throws Exception
8597 }
8698 }
8799
100+ @ RequiresApi (Build .VERSION_CODES .S )
101+ private void addDeviceStatesIfAvailable (DeviceInfoStore store ) throws IOException {
102+ DeviceStateManager deviceStateManager = getContext ().getSystemService (
103+ DeviceStateManager .class );
104+
105+ // Get the supported device states on device if DeviceStateManager is available
106+ if (deviceStateManager != null ) {
107+ store .addArrayResult ("device_states" , deviceStateManager .getSupportedStates ());
108+ }
109+ }
110+
88111 private static String getScreenSize (Configuration configuration ) {
89112 int screenLayout = configuration .screenLayout & Configuration .SCREENLAYOUT_SIZE_MASK ;
90113 String screenSize = String .format ("0x%x" , screenLayout );
0 commit comments