Loading services/core/java/com/android/server/wm/DeviceStateController.java +9 −0 Original line number Diff line number Diff line Loading @@ -162,6 +162,15 @@ final class DeviceStateController { } } /** * Checks if the current device is a foldable device based on if there is at least one * folded device state * @return true if this is a foldable device, false otherwise */ boolean isFoldable() { return !mFoldedDeviceStates.isEmpty(); } /** * @return true if the rotation direction on the Z axis should be reversed for the default * display. Loading services/core/java/com/android/server/wm/DisplayRotation.java +4 −8 Original line number Diff line number Diff line Loading @@ -287,7 +287,7 @@ public class DisplayRotation { mOrientationListener.setCurrentRotation(mRotation); mSettingsObserver = new SettingsObserver(uiHandler); mSettingsObserver.observe(); if (mSupportAutoRotation && isFoldable(mContext)) { if (mSupportAutoRotation && mDeviceStateController.isFoldable()) { mFoldController = new FoldController(); } else { mFoldController = null; Loading @@ -297,10 +297,6 @@ public class DisplayRotation { } } private static boolean isFoldable(Context context) { return context.getResources().getIntArray(R.array.config_foldedDeviceStates).length > 0; } private static boolean isAutoRotateSupported(@NonNull Context context) { return context.getResources().getBoolean(R.bool.config_supportAutoRotation); } Loading Loading @@ -1705,9 +1701,9 @@ public class DisplayRotation { */ @Nullable static DeviceStateAutoRotateSettingController createDeviceStateAutoRotateDependencies( Context context, DeviceStateController deviceStateController, WindowManagerService wmService) { if (!isFoldable(context) || !isAutoRotateSupported(context)) return null; @NonNull Context context, @NonNull DeviceStateController deviceStateController, @NonNull WindowManagerService wmService) { if (!deviceStateController.isFoldable() || !isAutoRotateSupported(context)) return null; if (!Flags.enableDeviceStateAutoRotateSettingLogging() && !Flags.enableDeviceStateAutoRotateSettingRefactor()) { return null; Loading services/tests/wmtests/src/com/android/server/wm/DeviceStateControllerTests.java +19 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import android.content.Context; Loading Loading @@ -195,6 +196,24 @@ public class DeviceStateControllerTests { assertEquals(mExecutor, entries.get(0).second); } @Test public void testWithFoldSupported_returnsThatDeviceIsFoldable() { initialize(true /* supportFold */, false /* supportHalfFolded */); final boolean isFoldable = mTarget.isFoldable(); assertTrue(isFoldable); } @Test public void testWithFoldNotSupported_returnsThatDeviceIsNotFoldable() { initialize(false /* supportFold */, false /* supportHalfFolded */); final boolean isFoldable = mTarget.isFoldable(); assertFalse(isFoldable); } private final List<DeviceState> mFoldedStates = new ArrayList<>( List.of(new DeviceState(new DeviceState.Configuration.Builder(0, "folded").setSystemProperties(new HashSet<>( Loading services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java +1 −4 Original line number Diff line number Diff line Loading @@ -1694,10 +1694,6 @@ public class DisplayRotationTests { com.android.internal.R.bool.config_windowManagerHalfFoldAutoRotateOverride)) .thenReturn(mSupportHalfFoldAutoRotateOverride); when(mMockContext.getResources().getIntArray( R.array.config_foldedDeviceStates)) .thenReturn(mIsFoldable ? new int[]{0} : new int[]{}); mMockDisplayRotationReversionController = mock(DisplayRotationReversionController.class); when(mMockDisplayContent.getRotationReversionController()) Loading @@ -1718,6 +1714,7 @@ public class DisplayRotationTests { .thenReturn(mMockDeviceStateManager); mDeviceStateController = mock(DeviceStateController.class); when(mDeviceStateController.isFoldable()).thenReturn(mIsFoldable); mMockDisplayContent.mAppCompatCameraPolicy = mock(AppCompatCameraPolicy.class); mTarget = new TestDisplayRotation(mMockDisplayContent, mMockDisplayAddress, mMockDisplayPolicy, mMockDisplayWindowSettings, mMockContext, Loading Loading
services/core/java/com/android/server/wm/DeviceStateController.java +9 −0 Original line number Diff line number Diff line Loading @@ -162,6 +162,15 @@ final class DeviceStateController { } } /** * Checks if the current device is a foldable device based on if there is at least one * folded device state * @return true if this is a foldable device, false otherwise */ boolean isFoldable() { return !mFoldedDeviceStates.isEmpty(); } /** * @return true if the rotation direction on the Z axis should be reversed for the default * display. Loading
services/core/java/com/android/server/wm/DisplayRotation.java +4 −8 Original line number Diff line number Diff line Loading @@ -287,7 +287,7 @@ public class DisplayRotation { mOrientationListener.setCurrentRotation(mRotation); mSettingsObserver = new SettingsObserver(uiHandler); mSettingsObserver.observe(); if (mSupportAutoRotation && isFoldable(mContext)) { if (mSupportAutoRotation && mDeviceStateController.isFoldable()) { mFoldController = new FoldController(); } else { mFoldController = null; Loading @@ -297,10 +297,6 @@ public class DisplayRotation { } } private static boolean isFoldable(Context context) { return context.getResources().getIntArray(R.array.config_foldedDeviceStates).length > 0; } private static boolean isAutoRotateSupported(@NonNull Context context) { return context.getResources().getBoolean(R.bool.config_supportAutoRotation); } Loading Loading @@ -1705,9 +1701,9 @@ public class DisplayRotation { */ @Nullable static DeviceStateAutoRotateSettingController createDeviceStateAutoRotateDependencies( Context context, DeviceStateController deviceStateController, WindowManagerService wmService) { if (!isFoldable(context) || !isAutoRotateSupported(context)) return null; @NonNull Context context, @NonNull DeviceStateController deviceStateController, @NonNull WindowManagerService wmService) { if (!deviceStateController.isFoldable() || !isAutoRotateSupported(context)) return null; if (!Flags.enableDeviceStateAutoRotateSettingLogging() && !Flags.enableDeviceStateAutoRotateSettingRefactor()) { return null; Loading
services/tests/wmtests/src/com/android/server/wm/DeviceStateControllerTests.java +19 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import android.content.Context; Loading Loading @@ -195,6 +196,24 @@ public class DeviceStateControllerTests { assertEquals(mExecutor, entries.get(0).second); } @Test public void testWithFoldSupported_returnsThatDeviceIsFoldable() { initialize(true /* supportFold */, false /* supportHalfFolded */); final boolean isFoldable = mTarget.isFoldable(); assertTrue(isFoldable); } @Test public void testWithFoldNotSupported_returnsThatDeviceIsNotFoldable() { initialize(false /* supportFold */, false /* supportHalfFolded */); final boolean isFoldable = mTarget.isFoldable(); assertFalse(isFoldable); } private final List<DeviceState> mFoldedStates = new ArrayList<>( List.of(new DeviceState(new DeviceState.Configuration.Builder(0, "folded").setSystemProperties(new HashSet<>( Loading
services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java +1 −4 Original line number Diff line number Diff line Loading @@ -1694,10 +1694,6 @@ public class DisplayRotationTests { com.android.internal.R.bool.config_windowManagerHalfFoldAutoRotateOverride)) .thenReturn(mSupportHalfFoldAutoRotateOverride); when(mMockContext.getResources().getIntArray( R.array.config_foldedDeviceStates)) .thenReturn(mIsFoldable ? new int[]{0} : new int[]{}); mMockDisplayRotationReversionController = mock(DisplayRotationReversionController.class); when(mMockDisplayContent.getRotationReversionController()) Loading @@ -1718,6 +1714,7 @@ public class DisplayRotationTests { .thenReturn(mMockDeviceStateManager); mDeviceStateController = mock(DeviceStateController.class); when(mDeviceStateController.isFoldable()).thenReturn(mIsFoldable); mMockDisplayContent.mAppCompatCameraPolicy = mock(AppCompatCameraPolicy.class); mTarget = new TestDisplayRotation(mMockDisplayContent, mMockDisplayAddress, mMockDisplayPolicy, mMockDisplayWindowSettings, mMockContext, Loading