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: If254220ca3018bc6ec1c4e3947375733f6816f92
This commit is contained in:
@@ -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[]{});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user