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

@@ -39,7 +39,10 @@ import android.provider.Settings;
import androidx.preference.Preference;
import com.android.settings.testutils.ResolveInfoBuilder;
import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
import com.android.settings.testutils.shadow.ShadowSensorPrivacyManager;
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
import org.junit.Before;
import org.junit.Test;
@@ -63,6 +66,8 @@ public class SmartAutoRotateControllerTest {
@Mock
private Preference mPreference;
private ContentResolver mContentResolver;
private final DeviceStateRotationLockSettingsManager mDeviceStateAutoRotateSettingsManager =
DeviceStateRotationLockSettingsManager.getInstance(RuntimeEnvironment.application);
@Before
public void setUp() {
@@ -122,6 +127,34 @@ public class SmartAutoRotateControllerTest {
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
}
@Test
@Config(shadows = {
ShadowDeviceStateRotationLockSettingsManager.class,
ShadowRotationPolicy.class
})
public void getAvailabilityStatus_deviceStateRotationLocked_returnDisableDependentSetting() {
enableDeviceStateRotation();
lockDeviceStateRotation();
int availabilityStatus = mController.getAvailabilityStatus();
assertThat(availabilityStatus).isEqualTo(DISABLED_DEPENDENT_SETTING);
}
@Test
@Config(shadows = {
ShadowDeviceStateRotationLockSettingsManager.class,
ShadowRotationPolicy.class
})
public void getAvailabilityStatus_deviceStateRotationUnlocked_returnAvailable() {
enableDeviceStateRotation();
unlockDeviceStateRotation();
int availabilityStatus = mController.getAvailabilityStatus();
assertThat(availabilityStatus).isEqualTo(AVAILABLE);
}
private void enableAutoRotation() {
Settings.System.putIntForUser(mContentResolver,
Settings.System.ACCELEROMETER_ROTATION, 1, UserHandle.USER_CURRENT);
@@ -131,4 +164,23 @@ public class SmartAutoRotateControllerTest {
Settings.System.putIntForUser(mContentResolver,
Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT);
}
private void enableDeviceStateRotation() {
ShadowRotationPolicy.setRotationSupported(true);
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
}
private void lockDeviceStateRotation() {
mDeviceStateAutoRotateSettingsManager.updateSetting(
/* deviceState= */0, /* rotationLocked= */ true);
mDeviceStateAutoRotateSettingsManager.updateSetting(
/* deviceState= */1, /* rotationLocked= */ true);
}
private void unlockDeviceStateRotation() {
mDeviceStateAutoRotateSettingsManager.updateSetting(
/* deviceState= */0, /* rotationLocked= */ false);
mDeviceStateAutoRotateSettingsManager.updateSetting(
/* deviceState= */1, /* rotationLocked= */ true);
}
}