From 02a99b8a620061bd0119cfa69a29dee901340d98 Mon Sep 17 00:00:00 2001 From: Massimo Carli Date: Tue, 21 Mar 2023 10:43:42 +0000 Subject: [PATCH] Fix NullPointerException in aspect ratio restrictions In this CL we properly clear inherited letterbox behavior of translucent activities when the ActivityRecord source or the inherited activity is removed. If this doesn't happen, onMergedOverrideConfigurationChange() is triggered on an ActivityRecord with no TaskFragment associated then the null pointer exception. Fixes: 272941700 Test: Reproduce steps on bug description Run `atest WmTests:SizeCompatTests` Change-Id: Ifeeb3042c6672e32d8cd665e9cc2f9abaf558a9c --- .../server/wm/LetterboxUiController.java | 4 ++++ .../android/server/wm/SizeCompatTests.java | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/services/core/java/com/android/server/wm/LetterboxUiController.java b/services/core/java/com/android/server/wm/LetterboxUiController.java index 54137eb41c5fd..e502caffd0897 100644 --- a/services/core/java/com/android/server/wm/LetterboxUiController.java +++ b/services/core/java/com/android/server/wm/LetterboxUiController.java @@ -327,6 +327,10 @@ final class LetterboxUiController { mLetterbox.destroy(); mLetterbox = null; } + if (mLetterboxConfigListener != null) { + mLetterboxConfigListener.onRemoved(); + mLetterboxConfigListener = null; + } } void onMovedToDisplay(int displayId) { diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java index 3e423c4d29ecf..d18e00d1d6321 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -52,6 +52,7 @@ import static com.android.internal.util.FrameworkStatsLog.APP_COMPAT_STATE_CHANG import static com.android.internal.util.FrameworkStatsLog.APP_COMPAT_STATE_CHANGED__STATE__LETTERBOXED_FOR_SIZE_COMPAT_MODE; import static com.android.internal.util.FrameworkStatsLog.APP_COMPAT_STATE_CHANGED__STATE__NOT_LETTERBOXED; import static com.android.internal.util.FrameworkStatsLog.APP_COMPAT_STATE_CHANGED__STATE__NOT_VISIBLE; +import static com.android.server.wm.ActivityRecord.State.DESTROYED; import static com.android.server.wm.ActivityRecord.State.PAUSED; import static com.android.server.wm.ActivityRecord.State.RESTARTING_PROCESS; import static com.android.server.wm.ActivityRecord.State.RESUMED; @@ -170,6 +171,26 @@ public class SizeCompatTests extends WindowTestsBase { setUpApp(builder.build()); } + @Test + public void testCleanLetterboxConfigListenerWhenTranslucentIsDestroyed() { + mWm.mLetterboxConfiguration.setTranslucentLetterboxingOverrideEnabled(true); + setUpDisplaySizeWithApp(2000, 1000); + prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT); + mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */); + // Translucent Activity + final ActivityRecord translucentActivity = new ActivityBuilder(mAtm) + .setLaunchedFromUid(mActivity.getUid()) + .setScreenOrientation(SCREEN_ORIENTATION_PORTRAIT) + .build(); + doReturn(false).when(translucentActivity).fillsParent(); + mTask.addChild(translucentActivity); + + translucentActivity.setState(DESTROYED, "testing"); + translucentActivity.removeImmediately(); + + assertFalse(translucentActivity.mLetterboxUiController.hasInheritedLetterboxBehavior()); + } + @Test public void testHorizontalReachabilityEnabledForTranslucentActivities() { setUpDisplaySizeWithApp(2500, 1000);