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

@@ -30,6 +30,7 @@ import android.provider.Settings;
import androidx.preference.SwitchPreference;
import com.android.internal.R;
import com.android.internal.view.RotationPolicy;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.FakeFeatureFactory;
@@ -64,6 +65,7 @@ public class AutoRotatePreferenceControllerTest {
mPreference = new SwitchPreference(RuntimeEnvironment.application);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getContentResolver()).thenReturn(mContentResolver);
disableDeviceStateRotation();
mController = new AutoRotatePreferenceController(mContext, "auto_rotate");
}
@@ -111,6 +113,26 @@ public class AutoRotatePreferenceControllerTest {
.UNSUPPORTED_ON_DEVICE);
}
@Test
public void getAvailabilityStatus_deviceRotationDisabled_returnsAvailable() {
enableAutoRotationPreference();
disableDeviceStateRotation();
int availability = mController.getAvailabilityStatus();
assertThat(availability).isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void getAvailabilityStatus_deviceRotationEnabled_returnsUnsupported() {
enableAutoRotationPreference();
enableDeviceStateRotation();
int availability = mController.getAvailabilityStatus();
assertThat(availability).isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
public void testIsCheck() {
assertThat(mController.isChecked()).isFalse();
@@ -180,4 +202,15 @@ public class AutoRotatePreferenceControllerTest {
Settings.System.putIntForUser(mContentResolver,
Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT);
}
private void enableDeviceStateRotation() {
when(mContext.getResources().getStringArray(
R.array.config_perDeviceStateRotationLockDefaults)).thenReturn(
new String[]{"0:0", "1:1", "2:2"});
}
private void disableDeviceStateRotation() {
when(mContext.getResources().getStringArray(
R.array.config_perDeviceStateRotationLockDefaults)).thenReturn(new String[]{});
}
}