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

Commit c146a758 authored by Nick Chameyev's avatar Nick Chameyev Committed by Android (Google) Code Review
Browse files

Merge "Use DisplayInfo rotation instead of Display#getRotation in...

Merge "Use DisplayInfo rotation instead of Display#getRotation in BookStyleClosedStatePredicate" into 24D1-dev
parents beaee655 b5a542f6
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));
    }