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

Commit b5a542f6 authored by Nick Chameyev's avatar Nick Chameyev
Browse files

Use DisplayInfo rotation instead of Display#getRotation in BookStyleClosedStatePredicate

Display#getRotation could be stale as it depends on the context
resources/configuration which could be deferred.
onDisplayChanged callback only notifies about updates
in DisplayInfo, so it doesn't notify about the configuration
change update, so BookStyleClosedStatePredicate could end up
with a stale rotation value.

This change updates querying of the rotation to DisplayInfo's
rotation field instead.

Test: manual rotate => check logs, try to enter wedge mode
Test: atest BookStyleDeviceStatePolicyTest
Bug: 326802066
Change-Id: I89514a383f5627e92b83dca110d9f850a0bb8397
(cherry picked from commit ee512f06)
parent ed6f98ac
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.os.Handler;
import android.util.ArraySet;
import android.util.Dumpable;
import android.view.Display;
import android.view.DisplayInfo;
import android.view.Surface;

import com.android.server.policy.BookStylePreferredScreenCalculator.PreferredScreen;
@@ -65,6 +66,7 @@ public class BookStyleClosedStatePredicate implements Predicate<FoldableDeviceSt
    private final Handler mHandler = new Handler();
    private final PostureEstimator mPostureEstimator;
    private final DisplayManager mDisplayManager;
    private final DisplayInfo mDefaultDisplayInfo = new DisplayInfo();

    /**
     * Creates {@link BookStyleClosedStatePredicate}. It is expected that the device has a pair
@@ -140,10 +142,11 @@ public class BookStyleClosedStatePredicate implements Predicate<FoldableDeviceSt
    public void onDisplayChanged(int displayId) {
        if (displayId == DEFAULT_DISPLAY) {
            final Display display = mDisplayManager.getDisplay(displayId);
            display.getDisplayInfo(mDefaultDisplayInfo);
            int displayState = display.getState();
            boolean isDisplayOn = displayState == Display.STATE_ON;
            mPostureEstimator.onDisplayPowerStatusChanged(isDisplayOn);
            mPostureEstimator.onDisplayRotationChanged(display.getRotation());
            mPostureEstimator.onDisplayRotationChanged(mDefaultDisplayInfo.rotation);
        }
    }

+6 −1
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.os.Handler;
import android.testing.AndroidTestingRunner;
import android.testing.TestableContext;
import android.view.Display;
import android.view.DisplayInfo;
import android.view.Surface;

import androidx.test.platform.app.InstrumentationRegistry;
@@ -629,7 +630,11 @@ public final class BookStyleDeviceStatePolicyTest {
    }

    private void sendScreenRotation(int rotation) {
        when(mDisplay.getRotation()).thenReturn(rotation);
        doAnswer(invocation -> {
            final DisplayInfo displayInfo = invocation.getArgument(0);
            displayInfo.rotation = rotation;
            return null;
        }).when(mDisplay).getDisplayInfo(any());
        mDisplayListenerCaptor.getAllValues().forEach((l) -> l.onDisplayChanged(DEFAULT_DISPLAY));
    }