diff options
author | 2022-02-22 15:36:51 +0000 | |
---|---|---|
committer | 2022-02-22 15:36:51 +0000 | |
commit | 07d083ea9359fb69350e214a86e10bc088bea7b0 (patch) | |
tree | 221d69915e0535f92317e783691bd6003c85274d | |
parent | eb8566ff9e2e4ebb7e21488b10d489b4f3d10b93 (diff) | |
parent | 835f63f972aa96945f518d139456cf794d041ca0 (diff) |
Merge "Fixes NPE from resolveRotation()"
-rw-r--r-- | services/core/java/com/android/server/wm/WindowOrientationListener.java | 4 | ||||
-rw-r--r-- | services/tests/servicestests/src/com/android/server/wm/WindowOrientationListenerTest.java | 11 |
2 files changed, 14 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/wm/WindowOrientationListener.java b/services/core/java/com/android/server/wm/WindowOrientationListener.java index a967ea8fbf8c..de87ab9dcce0 100644 --- a/services/core/java/com/android/server/wm/WindowOrientationListener.java +++ b/services/core/java/com/android/server/wm/WindowOrientationListener.java @@ -1167,6 +1167,10 @@ public abstract class WindowOrientationListener { if (mRotationResolverService == null) { mRotationResolverService = LocalServices.getService( RotationResolverInternal.class); + if (mRotationResolverService == null) { + finalizeRotation(reportedRotation); + return; + } } String packageName = null; diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowOrientationListenerTest.java b/services/tests/servicestests/src/com/android/server/wm/WindowOrientationListenerTest.java index 2794d4837101..c64ff9e128e6 100644 --- a/services/tests/servicestests/src/com/android/server/wm/WindowOrientationListenerTest.java +++ b/services/tests/servicestests/src/com/android/server/wm/WindowOrientationListenerTest.java @@ -114,7 +114,7 @@ public class WindowOrientationListenerTest { } @Test - public void testSensorChanged_normalCase2() { + public void testOnSensorChanged_normalCase2() { mWindowOrientationListener.mOrientationJudge.onSensorChanged(mFakeSensorEvent); mFakeRotationResolverInternal.callbackWithFailureResult( @@ -123,6 +123,15 @@ public class WindowOrientationListenerTest { assertThat(mFinalizedRotation).isEqualTo(DEFAULT_SENSOR_ROTATION); } + @Test + public void testOnSensorChanged_rotationResolverServiceIsNull_useSensorResult() { + mWindowOrientationListener.mRotationResolverService = null; + + mWindowOrientationListener.mOrientationJudge.onSensorChanged(mFakeSensorEvent); + + assertThat(mFinalizedRotation).isEqualTo(DEFAULT_SENSOR_ROTATION); + } + static final class TestableRotationResolver extends RotationResolverInternal { @Surface.Rotation RotationResolverCallbackInternal mCallback; |