Add support for device state based auto-rotation preferences in Settings.

- Creates new preferences that are shown when device-state rotation
  is supported.
- Hides standard preferences when device-state rotation is supported.
- Controllers/Preferences for individual folded/unfolded rotation
  settings are created and added programatically based on the settable
  device states available.

Test: Manually + Unit tests
Bug: 195757480
Change-Id: I16f50fd3664756b363c7eb79e5c35eb0d3b6df17
This commit is contained in:
Christian Göllner
2022-02-17 11:32:54 +00:00
parent a01477087c
commit ff9065ac95
24 changed files with 1106 additions and 14 deletions

View File

@@ -40,6 +40,7 @@ import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.ResolveInfoBuilder;
import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
import com.android.settings.testutils.shadow.ShadowSensorPrivacyManager;
import org.junit.Before;
@@ -53,7 +54,10 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowSensorPrivacyManager.class)
@Config(shadows = {
ShadowSensorPrivacyManager.class,
ShadowDeviceStateRotationLockSettingsManager.class
})
public class SmartAutoRotatePreferenceControllerTest {
private static final String PACKAGE_NAME = "package_name";
@@ -95,6 +99,7 @@ public class SmartAutoRotatePreferenceControllerTest {
new SmartAutoRotatePreferenceController(mContext, "smart_auto_rotate"));
when(mController.isCameraLocked()).thenReturn(false);
when(mController.isPowerSaveMode()).thenReturn(false);
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
}
@Test
@@ -199,6 +204,16 @@ public class SmartAutoRotatePreferenceControllerTest {
.UNSUPPORTED_ON_DEVICE);
}
@Test
public void getAvailabilityStatus_deviceStateRotationEnabled_returnsUnsupported() {
enableAutoRotationPreference();
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
public void isSliceableCorrectKey_returnsTrue() {
final AutoRotatePreferenceController controller =