Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7962866a authored by Nick Chameyev's avatar Nick Chameyev
Browse files

Use DeviceStateManager to detect foldable device instead of config.xml

Some devices like goldfish emulator might not configure
correct device states, even though they provided
foldable-specific configurations.

Skip initializing foldable-specific dependencies in DisplayRotation
if there are no foldable device states in the DeviceStateManager.

Bug: 418414850
Test: atest DisplayRotationTests DeviceStateControllerTests
Test: check that per device autorotate works on a foldable
Test: check that goldfish emulator boots
Flag: EXEMPT bugfix
Change-Id: Ia1244169678039c404c6467d5e8585e972fcd8ce
parent 2a85664a
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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.
+4 −8
Original line number Diff line number Diff line
@@ -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;
@@ -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);
    }
@@ -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;
+19 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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<>(
+1 −4
Original line number Diff line number Diff line
@@ -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())
@@ -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,