diff --git a/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateDetailsFragmentTest.java b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateDetailsFragmentTest.java index e5940b61432..d1c32a2281f 100644 --- a/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateDetailsFragmentTest.java +++ b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateDetailsFragmentTest.java @@ -16,16 +16,26 @@ package com.android.settings.display; +import static android.hardware.devicestate.DeviceState.PROPERTY_EMULATED_ONLY; +import static android.hardware.devicestate.DeviceState.PROPERTY_FEATURE_REAR_DISPLAY; +import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY; +import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY; +import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED; +import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN; +import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN; import static android.provider.Settings.Secure.DEVICE_STATE_ROTATION_LOCK_LOCKED; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import android.app.settings.SettingsEnums; import android.content.Context; import android.content.res.Resources; +import android.hardware.devicestate.DeviceState; +import android.hardware.devicestate.DeviceStateManager; import com.android.settings.R; import com.android.settingslib.core.AbstractPreferenceController; @@ -34,29 +44,61 @@ import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManage import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import java.util.List; +import java.util.Set; @RunWith(RobolectricTestRunner.class) public class DeviceStateAutoRotateDetailsFragmentTest { - private static final int FOLDED_STATE = 0; - private static final int HALF_FOLDED_STATE = 1; - private static final int UNFOLDED_STATE = 2; - private static final int REAR_DISPLAY_STATE = 3; + private static final DeviceState DEVICE_STATE_FOLDED = new DeviceState( + new DeviceState.Configuration.Builder(/* identifier= */ 0, "FOLDED") + .setSystemProperties(Set.of( + PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY)) + .setPhysicalProperties(Set.of( + PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED)) + .build()); + private static final DeviceState DEVICE_STATE_HALF_FOLDED = new DeviceState( + new DeviceState.Configuration.Builder(/* identifier= */ 1, "HALF_FOLDED") + .setSystemProperties(Set.of( + PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY)) + .setPhysicalProperties(Set.of( + PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN)) + .build()); + private static final DeviceState DEVICE_STATE_UNFOLDED = new DeviceState( + new DeviceState.Configuration.Builder(/* identifier= */ 2, "UNFOLDED") + .setSystemProperties(Set.of( + PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY)) + .setPhysicalProperties(Set.of( + PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN)) + .build()); + private static final DeviceState DEVICE_STATE_REAR_DISPLAY = new DeviceState( + new DeviceState.Configuration.Builder(/* identifier= */ 3, "REAR_DISPLAY") + .setSystemProperties(Set.of( + PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY, + PROPERTY_FEATURE_REAR_DISPLAY, PROPERTY_EMULATED_ONLY)) + .setPhysicalProperties(Set.of( + PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED)) + .build()); private final DeviceStateAutoRotateDetailsFragment mFragment = spy(new DeviceStateAutoRotateDetailsFragment()); private final Context mContext = spy(RuntimeEnvironment.application); private final Resources mResources = spy(mContext.getResources()); + @Mock + private DeviceStateManager mDeviceStateManager; @Before public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); when(mContext.getResources()).thenReturn(mResources); when(mContext.getApplicationContext()).thenReturn(mContext); when(mFragment.getContext()).thenReturn(mContext); when(mFragment.getResources()).thenReturn(mResources); + doReturn(mDeviceStateManager).when(mContext).getSystemService(DeviceStateManager.class); setUpPostureMappings(); } @@ -75,8 +117,10 @@ public class DeviceStateAutoRotateDetailsFragmentTest { @Test public void createPreferenceControllers_settableDeviceStates_returnsDeviceStateControllers() { enableDeviceStateSettableRotationStates( - new String[]{FOLDED_STATE + ":" + DEVICE_STATE_ROTATION_LOCK_LOCKED, - UNFOLDED_STATE + ":" + DEVICE_STATE_ROTATION_LOCK_LOCKED}, + new String[]{DEVICE_STATE_FOLDED.getIdentifier() + ":" + + DEVICE_STATE_ROTATION_LOCK_LOCKED, + DEVICE_STATE_UNFOLDED.getIdentifier() + ":" + + DEVICE_STATE_ROTATION_LOCK_LOCKED}, new String[]{"Folded", "Unfolded"}); List preferenceControllers = @@ -112,18 +156,22 @@ public class DeviceStateAutoRotateDetailsFragmentTest { .resetStateForTesting(mResources); } + // Sets up posture mappings for PosturesHelper private void setUpPostureMappings() { when(mResources.getIntArray( com.android.internal.R.array.config_foldedDeviceStates)).thenReturn( - new int[]{FOLDED_STATE}); + new int[]{DEVICE_STATE_FOLDED.getIdentifier()}); when(mResources.getIntArray( com.android.internal.R.array.config_halfFoldedDeviceStates)).thenReturn( - new int[]{HALF_FOLDED_STATE}); + new int[]{DEVICE_STATE_HALF_FOLDED.getIdentifier()}); when(mResources.getIntArray( com.android.internal.R.array.config_openDeviceStates)).thenReturn( - new int[]{UNFOLDED_STATE}); + new int[]{DEVICE_STATE_UNFOLDED.getIdentifier()}); when(mResources.getIntArray( com.android.internal.R.array.config_rearDisplayDeviceStates)).thenReturn( - new int[]{REAR_DISPLAY_STATE}); + new int[]{DEVICE_STATE_REAR_DISPLAY.getIdentifier()}); + when(mDeviceStateManager.getSupportedDeviceStates()).thenReturn( + List.of(DEVICE_STATE_FOLDED, DEVICE_STATE_HALF_FOLDED, DEVICE_STATE_UNFOLDED, + DEVICE_STATE_REAR_DISPLAY)); } } diff --git a/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateSettingControllerTest.java b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateSettingControllerTest.java index d364a3be451..cb1be85f881 100644 --- a/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateSettingControllerTest.java +++ b/tests/robotests/src/com/android/settings/display/DeviceStateAutoRotateSettingControllerTest.java @@ -21,10 +21,13 @@ import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_ import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import android.app.settings.SettingsEnums; import android.content.Context; +import android.hardware.devicestate.DeviceState; +import android.hardware.devicestate.DeviceStateManager; import androidx.preference.Preference; import androidx.preference.PreferenceManager; @@ -41,6 +44,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; @@ -56,15 +60,16 @@ import java.util.List; }) public class DeviceStateAutoRotateSettingControllerTest { - private static final int DEFAULT_DEVICE_STATE = 1; + private static final DeviceState DEFAULT_DEVICE_STATE = new DeviceState( + new DeviceState.Configuration.Builder(/* identifier= */ 1, "DEFAULT").build()); private static final String DEFAULT_DEVICE_STATE_DESCRIPTION = "Device state description"; private static final int DEFAULT_ORDER = -10; - private final Context mContext = RuntimeEnvironment.application; - private final DeviceStateRotationLockSettingsManager mAutoRotateSettingsManager = - DeviceStateRotationLockSettingsManager.getInstance(mContext); + private final Context mContext = Mockito.spy(RuntimeEnvironment.application); + private DeviceStateRotationLockSettingsManager mAutoRotateSettingsManager; @Mock private MetricsFeatureProvider mMetricsFeatureProvider; + @Mock private DeviceStateManager mDeviceStateManager; private DeviceStateAutoRotateSettingController mController; @@ -72,9 +77,15 @@ public class DeviceStateAutoRotateSettingControllerTest { public void setUp() { MockitoAnnotations.initMocks(this); + doReturn(mContext).when(mContext).getApplicationContext(); + doReturn(mDeviceStateManager).when(mContext).getSystemService(DeviceStateManager.class); + doReturn(List.of(DEFAULT_DEVICE_STATE)).when( + mDeviceStateManager).getSupportedDeviceStates(); + mAutoRotateSettingsManager = + DeviceStateRotationLockSettingsManager.getInstance(mContext); mController = new DeviceStateAutoRotateSettingController( mContext, - DEFAULT_DEVICE_STATE, + DEFAULT_DEVICE_STATE.getIdentifier(), DEFAULT_DEVICE_STATE_DESCRIPTION, DEFAULT_ORDER, mMetricsFeatureProvider @@ -128,20 +139,22 @@ public class DeviceStateAutoRotateSettingControllerTest { public void getPreferenceKey_returnsKeyBasedOnDeviceState() { String key = mController.getPreferenceKey(); - String expectedKey = "auto_rotate_device_state_" + DEFAULT_DEVICE_STATE; + String expectedKey = "auto_rotate_device_state_" + DEFAULT_DEVICE_STATE.getIdentifier(); assertThat(key).isEqualTo(expectedKey); } @Test public void isChecked_settingForStateIsUnlocked_returnsTrue() { - mAutoRotateSettingsManager.updateSetting(DEFAULT_DEVICE_STATE, /* rotationLocked= */ false); + mAutoRotateSettingsManager.updateSetting( + DEFAULT_DEVICE_STATE.getIdentifier(), /* rotationLocked= */ false); assertThat(mController.isChecked()).isTrue(); } @Test public void isChecked_settingForStateIsLocked_returnsFalse() { - mAutoRotateSettingsManager.updateSetting(DEFAULT_DEVICE_STATE, /* rotationLocked= */ true); + mAutoRotateSettingsManager.updateSetting( + DEFAULT_DEVICE_STATE.getIdentifier(), /* rotationLocked= */ true); assertThat(mController.isChecked()).isFalse(); } @@ -150,7 +163,8 @@ public class DeviceStateAutoRotateSettingControllerTest { public void setChecked_true_deviceStateSettingIsUnlocked() { mController.setChecked(true); - boolean rotationLocked = mAutoRotateSettingsManager.isRotationLocked(DEFAULT_DEVICE_STATE); + boolean rotationLocked = mAutoRotateSettingsManager.isRotationLocked( + DEFAULT_DEVICE_STATE.getIdentifier()); assertThat(rotationLocked).isFalse(); } @@ -159,7 +173,8 @@ public class DeviceStateAutoRotateSettingControllerTest { public void setChecked_false_deviceStateSettingIsLocked() { mController.setChecked(false); - boolean rotationLocked = mAutoRotateSettingsManager.isRotationLocked(DEFAULT_DEVICE_STATE); + boolean rotationLocked = mAutoRotateSettingsManager.isRotationLocked( + DEFAULT_DEVICE_STATE.getIdentifier()); assertThat(rotationLocked).isTrue(); } @@ -169,7 +184,8 @@ public class DeviceStateAutoRotateSettingControllerTest { mController.setChecked(true); verify(mMetricsFeatureProvider).action(mContext, - SettingsEnums.ACTION_ENABLE_AUTO_ROTATION_DEVICE_STATE, DEFAULT_DEVICE_STATE); + SettingsEnums.ACTION_ENABLE_AUTO_ROTATION_DEVICE_STATE, + DEFAULT_DEVICE_STATE.getIdentifier()); } @Test @@ -177,7 +193,8 @@ public class DeviceStateAutoRotateSettingControllerTest { mController.setChecked(false); verify(mMetricsFeatureProvider).action(mContext, - SettingsEnums.ACTION_DISABLE_AUTO_ROTATION_DEVICE_STATE, DEFAULT_DEVICE_STATE); + SettingsEnums.ACTION_DISABLE_AUTO_ROTATION_DEVICE_STATE, + DEFAULT_DEVICE_STATE.getIdentifier()); } @Test diff --git a/tests/robotests/src/com/android/settings/display/SmartAutoRotateControllerTest.java b/tests/robotests/src/com/android/settings/display/SmartAutoRotateControllerTest.java index 63395d177f3..e2542b0d55b 100644 --- a/tests/robotests/src/com/android/settings/display/SmartAutoRotateControllerTest.java +++ b/tests/robotests/src/com/android/settings/display/SmartAutoRotateControllerTest.java @@ -33,6 +33,8 @@ import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; +import android.hardware.devicestate.DeviceState; +import android.hardware.devicestate.DeviceStateManager; import android.os.UserHandle; import android.provider.Settings; @@ -56,6 +58,8 @@ import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.robolectric.shadow.api.Shadow; +import java.util.List; + @RunWith(RobolectricTestRunner.class) @Config(shadows = {ShadowSensorPrivacyManager.class, ShadowSystemSettings.class}) public class SmartAutoRotateControllerTest { @@ -67,21 +71,30 @@ public class SmartAutoRotateControllerTest { private PackageManager mPackageManager; @Mock private Preference mPreference; + @Mock + private DeviceStateManager mDeviceStateManager; private ContentResolver mContentResolver; - private final DeviceStateRotationLockSettingsManager mDeviceStateAutoRotateSettingsManager = - DeviceStateRotationLockSettingsManager.getInstance(RuntimeEnvironment.application); + private DeviceStateRotationLockSettingsManager mDeviceStateAutoRotateSettingsManager; @Before public void setUp() { MockitoAnnotations.initMocks(this); final Context context = Mockito.spy(RuntimeEnvironment.application); mContentResolver = RuntimeEnvironment.application.getContentResolver(); + when(context.getPackageManager()).thenReturn(mPackageManager); when(context.getContentResolver()).thenReturn(mContentResolver); doReturn(PACKAGE_NAME).when(mPackageManager).getRotationResolverPackageName(); doReturn(PackageManager.PERMISSION_GRANTED).when(mPackageManager).checkPermission( Manifest.permission.CAMERA, PACKAGE_NAME); + // Necessary for the DeviceStateRotationLockSettingsManager setup + doReturn(context).when(context).getApplicationContext(); + doReturn(mDeviceStateManager).when(context).getSystemService(DeviceStateManager.class); + doReturn(getDeviceStateList()).when(mDeviceStateManager).getSupportedDeviceStates(); + mDeviceStateAutoRotateSettingsManager = DeviceStateRotationLockSettingsManager.getInstance( + context); mController = Mockito.spy(new SmartAutoRotateController(context, "test_key")); + when(mController.isCameraLocked()).thenReturn(false); when(mController.isPowerSaveMode()).thenReturn(false); doReturn(mController.getPreferenceKey()).when(mPreference).getKey(); @@ -183,4 +196,13 @@ public class SmartAutoRotateControllerTest { Shadow.extract(mDeviceStateAutoRotateSettingsManager); shadowManager.setRotationLockedForAllStates(false); } + + /** + * Returns a list that includes a singular default {@link DeviceState}. To be returned when + * {@link DeviceStateManager#getSupportedDeviceStates()} is called. + */ + private List getDeviceStateList() { + return List.of(new DeviceState( + new DeviceState.Configuration.Builder(0 /* identifier */, "DEFAULT").build())); + } } diff --git a/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java index 3fa4582b7d6..16155384cf8 100644 --- a/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java +++ b/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java @@ -16,6 +16,13 @@ package com.android.settings.display; +import static android.hardware.devicestate.DeviceState.PROPERTY_EMULATED_ONLY; +import static android.hardware.devicestate.DeviceState.PROPERTY_FEATURE_REAR_DISPLAY; +import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY; +import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY; +import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED; +import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN; +import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN; import static android.provider.Settings.Secure.DEVICE_STATE_ROTATION_LOCK_LOCKED; import static com.android.settings.display.SmartAutoRotatePreferenceFragment.AUTO_ROTATE_MAIN_SWITCH_PREFERENCE_KEY; @@ -39,6 +46,8 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.res.Resources; +import android.hardware.devicestate.DeviceState; +import android.hardware.devicestate.DeviceStateManager; import android.view.View; import androidx.preference.Preference; @@ -61,6 +70,7 @@ import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import java.util.List; +import java.util.Set; @RunWith(RobolectricTestRunner.class) @Config(shadows = { @@ -70,10 +80,35 @@ import java.util.List; }) public class SmartAutoRotatePreferenceFragmentTest { - private static final int STATE_FOLDED = 0; - private static final int STATE_HALF_FOLDED = 1; - private static final int STATE_UNFOLDED = 2; - private static final int STATE_REAR_DISPLAY = 3; + private static final DeviceState DEVICE_STATE_FOLDED = new DeviceState( + new DeviceState.Configuration.Builder(/* identifier= */ 0, "FOLDED") + .setSystemProperties(Set.of( + PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY)) + .setPhysicalProperties(Set.of( + PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED)) + .build()); + private static final DeviceState DEVICE_STATE_HALF_FOLDED = new DeviceState( + new DeviceState.Configuration.Builder(/* identifier= */ 1, "HALF_FOLDED") + .setSystemProperties(Set.of( + PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY)) + .setPhysicalProperties(Set.of( + PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN)) + .build()); + private static final DeviceState DEVICE_STATE_UNFOLDED = new DeviceState( + new DeviceState.Configuration.Builder(/* identifier= */ 2, "UNFOLDED") + .setSystemProperties(Set.of( + PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY)) + .setPhysicalProperties(Set.of( + PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN)) + .build()); + private static final DeviceState DEVICE_STATE_REAR_DISPLAY = new DeviceState( + new DeviceState.Configuration.Builder(/* identifier= */ 3, "REAR_DISPLAY") + .setSystemProperties(Set.of( + PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY, + PROPERTY_FEATURE_REAR_DISPLAY, PROPERTY_EMULATED_ONLY)) + .setPhysicalProperties(Set.of( + PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED)) + .build()); private static final String PACKAGE_NAME = "package_name"; @@ -96,6 +131,9 @@ public class SmartAutoRotatePreferenceFragmentTest { @Mock private Preference mRotateMainSwitchPreference; + @Mock + private DeviceStateManager mDeviceStateManager; + @Before public void setUp() { MockitoAnnotations.initMocks(this); @@ -105,6 +143,7 @@ public class SmartAutoRotatePreferenceFragmentTest { when(mContext.getPackageManager()).thenReturn(mPackageManager); when(mContext.getContentResolver()).thenReturn(mContentResolver); when(mContext.getApplicationContext()).thenReturn(mContext); + doReturn(mDeviceStateManager).when(mContext).getSystemService(DeviceStateManager.class); doReturn(PACKAGE_NAME).when(mPackageManager).getRotationResolverPackageName(); doReturn(PackageManager.PERMISSION_GRANTED).when(mPackageManager).checkPermission( Manifest.permission.CAMERA, PACKAGE_NAME); @@ -130,14 +169,7 @@ public class SmartAutoRotatePreferenceFragmentTest { when(mFragment.findPreference(AUTO_ROTATE_MAIN_SWITCH_PREFERENCE_KEY)) .thenReturn(mRotateMainSwitchPreference); - when(mResources.getIntArray(com.android.internal.R.array.config_foldedDeviceStates)) - .thenReturn(new int[] {STATE_FOLDED}); - when(mResources.getIntArray(com.android.internal.R.array.config_halfFoldedDeviceStates)) - .thenReturn(new int[] {STATE_HALF_FOLDED}); - when(mResources.getIntArray(com.android.internal.R.array.config_openDeviceStates)) - .thenReturn(new int[] {STATE_UNFOLDED}); - when(mResources.getIntArray(com.android.internal.R.array.config_rearDisplayDeviceStates)) - .thenReturn(new int[] {STATE_REAR_DISPLAY}); + setUpPostureMappings(); } @Test @@ -195,8 +227,8 @@ public class SmartAutoRotatePreferenceFragmentTest { public void createPreferenceControllers_settableDeviceStates_returnsDeviceStateControllers() { enableDeviceStateSettableRotationStates( new String[] { - STATE_FOLDED + ":" + DEVICE_STATE_ROTATION_LOCK_LOCKED, - STATE_UNFOLDED + ":" + DEVICE_STATE_ROTATION_LOCK_LOCKED + DEVICE_STATE_FOLDED.getIdentifier() + ":" + DEVICE_STATE_ROTATION_LOCK_LOCKED, + DEVICE_STATE_UNFOLDED.getIdentifier() + ":" + DEVICE_STATE_ROTATION_LOCK_LOCKED }, new String[] {"Folded", "Unfolded"}); @@ -236,4 +268,23 @@ public class SmartAutoRotatePreferenceFragmentTest { DeviceStateRotationLockSettingsManager.getInstance(mContext) .resetStateForTesting(mResources); } + + // Sets up posture mappings for PosturesHelper + private void setUpPostureMappings() { + when(mResources.getIntArray( + com.android.internal.R.array.config_foldedDeviceStates)).thenReturn( + new int[]{DEVICE_STATE_FOLDED.getIdentifier()}); + when(mResources.getIntArray( + com.android.internal.R.array.config_halfFoldedDeviceStates)).thenReturn( + new int[]{DEVICE_STATE_HALF_FOLDED.getIdentifier()}); + when(mResources.getIntArray( + com.android.internal.R.array.config_openDeviceStates)).thenReturn( + new int[]{DEVICE_STATE_UNFOLDED.getIdentifier()}); + when(mResources.getIntArray( + com.android.internal.R.array.config_rearDisplayDeviceStates)).thenReturn( + new int[]{DEVICE_STATE_REAR_DISPLAY.getIdentifier()}); + when(mDeviceStateManager.getSupportedDeviceStates()).thenReturn( + List.of(DEVICE_STATE_FOLDED, DEVICE_STATE_HALF_FOLDED, DEVICE_STATE_UNFOLDED, + DEVICE_STATE_REAR_DISPLAY)); + } }