diff options
author | 2024-03-05 16:54:45 +0000 | |
---|---|---|
committer | 2024-03-05 16:59:26 +0000 | |
commit | ee512f06bae619d3aa5c52a37da6f6b3ec3ea79e (patch) | |
tree | f61bb2750e6b90c8613938be06f3bce2f7696032 | |
parent | 67bf528527b5e27d4eeaed0c4c9e11f433c68acd (diff) |
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
2 files changed, 10 insertions, 2 deletions
diff --git a/services/foldables/devicestateprovider/src/com/android/server/policy/BookStyleClosedStatePredicate.java b/services/foldables/devicestateprovider/src/com/android/server/policy/BookStyleClosedStatePredicate.java index 82d5247ebed8..209107e50902 100644 --- a/services/foldables/devicestateprovider/src/com/android/server/policy/BookStyleClosedStatePredicate.java +++ b/services/foldables/devicestateprovider/src/com/android/server/policy/BookStyleClosedStatePredicate.java @@ -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); } } diff --git a/services/foldables/devicestateprovider/tests/src/com/android/server/policy/BookStyleDeviceStatePolicyTest.java b/services/foldables/devicestateprovider/tests/src/com/android/server/policy/BookStyleDeviceStatePolicyTest.java index 8d01b7a9c523..901f24dd9b0b 100644 --- a/services/foldables/devicestateprovider/tests/src/com/android/server/policy/BookStyleDeviceStatePolicyTest.java +++ b/services/foldables/devicestateprovider/tests/src/com/android/server/policy/BookStyleDeviceStatePolicyTest.java @@ -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)); } |