diff options
author | 2023-09-22 13:43:02 +0000 | |
---|---|---|
committer | 2023-09-22 13:43:02 +0000 | |
commit | 88c3276975cb59282ec9270aa901f81ad5983435 (patch) | |
tree | e7a6352008bf555c50ff4ca1f68d966f3226ea4b /libs | |
parent | c754bea8f575c57e6b5191d2c2a15b84dcf78aba (diff) | |
parent | 4b53956868d7e29b16062b7387bdaea89199d1fe (diff) |
Merge "[1/n] Optimize user aspect ratio button heuristic" into udc-qpr-dev am: 4b53956868
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24745370
Change-Id: Idb47ed4160b9f4ebbe31db99611a24d5e8a72376
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'libs')
5 files changed, 197 insertions, 5 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java index 0e6b20332a4f..9760350cf667 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java @@ -176,6 +176,18 @@ public class CompatUIController implements OnDisplaysChangedListener, // be shown. private boolean mKeyguardShowing; + /** + * The id of the task for the application we're currently attempting to show the user aspect + * ratio settings button for, or have most recently shown the button for. + */ + private int mTopActivityTaskId; + + /** + * Whether the user aspect ratio settings button has been shown for the current application + * associated with the task id stored in {@link CompatUIController#mTopActivityTaskId}. + */ + private boolean mHasShownUserAspectRatioSettingsButton = false; + public CompatUIController(@NonNull Context context, @NonNull ShellInit shellInit, @NonNull ShellController shellController, @@ -230,6 +242,11 @@ public class CompatUIController implements OnDisplaysChangedListener, if (taskInfo != null && !taskInfo.topActivityInSizeCompat) { mSetOfTaskIdsShowingRestartDialog.remove(taskInfo.taskId); } + + if (taskInfo != null && taskListener != null) { + updateActiveTaskInfo(taskInfo); + } + if (taskInfo.configuration == null || taskListener == null) { // Null token means the current foreground activity is not in compatibility mode. removeLayouts(taskInfo.taskId); @@ -322,6 +339,45 @@ public class CompatUIController implements OnDisplaysChangedListener, forAllLayouts(layout -> layout.updateVisibility(showOnDisplay(layout.getDisplayId()))); } + /** + * Invoked when a new task is created or the info of an existing task has changed. Updates the + * shown status of the user aspect ratio settings button and the task id it relates to. + */ + void updateActiveTaskInfo(@NonNull TaskInfo taskInfo) { + // If the activity belongs to the task we are currently tracking, don't update any variables + // as they are still relevant. Else, if the activity is visible and focused (the one the + // user can see and is using), the user aspect ratio button can potentially be displayed so + // start tracking the buttons visibility for this task. + if (mTopActivityTaskId != taskInfo.taskId && taskInfo.isVisible && taskInfo.isFocused) { + mTopActivityTaskId = taskInfo.taskId; + setHasShownUserAspectRatioSettingsButton(false); + } + } + + /** + * Informs the system that the user aspect ratio button has been displayed for the application + * associated with the task id in {@link CompatUIController#mTopActivityTaskId}. + */ + void setHasShownUserAspectRatioSettingsButton(boolean state) { + mHasShownUserAspectRatioSettingsButton = state; + } + + /** + * Returns whether the user aspect ratio settings button has been show for the application + * associated with the task id in {@link CompatUIController#mTopActivityTaskId}. + */ + boolean hasShownUserAspectRatioSettingsButton() { + return mHasShownUserAspectRatioSettingsButton; + } + + /** + * Returns the task id of the application we are currently attempting to show, of have most + * recently shown, the user aspect ratio settings button for. + */ + int getTopActivityTaskId() { + return mTopActivityTaskId; + } + private boolean showOnDisplay(int displayId) { return !mKeyguardShowing && !isImeShowingOnDisplay(displayId); } @@ -572,7 +628,8 @@ public class CompatUIController implements OnDisplaysChangedListener, return new UserAspectRatioSettingsWindowManager(context, taskInfo, mSyncQueue, taskListener, mDisplayController.getDisplayLayout(taskInfo.displayId), mCompatUIHintsState, this::launchUserAspectRatioSettings, mMainExecutor, - mDisappearTimeSupplier); + mDisappearTimeSupplier, this::hasShownUserAspectRatioSettingsButton, + this::setHasShownUserAspectRatioSettingsButton); } private void launchUserAspectRatioSettings( diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/UserAspectRatioSettingsWindowManager.java b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/UserAspectRatioSettingsWindowManager.java index 77aefc8f7e4a..96470012af03 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/UserAspectRatioSettingsWindowManager.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/UserAspectRatioSettingsWindowManager.java @@ -37,7 +37,9 @@ import com.android.wm.shell.common.SyncTransactionQueue; import com.android.wm.shell.compatui.CompatUIController.CompatUIHintsState; import java.util.function.BiConsumer; +import java.util.function.Consumer; import java.util.function.Function; +import java.util.function.Supplier; /** * Window manager for the user aspect ratio settings button which allows users to go to @@ -55,6 +57,12 @@ class UserAspectRatioSettingsWindowManager extends CompatUIWindowManagerAbstract private final ShellExecutor mShellExecutor; + @NonNull + private final Supplier<Boolean> mUserAspectRatioButtonShownChecker; + + @NonNull + private final Consumer<Boolean> mUserAspectRatioButtonStateConsumer; + @VisibleForTesting @NonNull final CompatUIHintsState mCompatUIHintsState; @@ -72,9 +80,13 @@ class UserAspectRatioSettingsWindowManager extends CompatUIWindowManagerAbstract @NonNull DisplayLayout displayLayout, @NonNull CompatUIHintsState compatUIHintsState, @NonNull BiConsumer<TaskInfo, ShellTaskOrganizer.TaskListener> onButtonClicked, @NonNull ShellExecutor shellExecutor, - @NonNull Function<Integer, Integer> disappearTimeSupplier) { + @NonNull Function<Integer, Integer> disappearTimeSupplier, + @NonNull Supplier<Boolean> userAspectRatioButtonStateChecker, + @NonNull Consumer<Boolean> userAspectRatioButtonShownConsumer) { super(context, taskInfo, syncQueue, taskListener, displayLayout); mShellExecutor = shellExecutor; + mUserAspectRatioButtonShownChecker = userAspectRatioButtonStateChecker; + mUserAspectRatioButtonStateConsumer = userAspectRatioButtonShownConsumer; mHasUserAspectRatioSettingsButton = getHasUserAspectRatioSettingsButton(taskInfo); mCompatUIHintsState = compatUIHintsState; mOnButtonClicked = onButtonClicked; @@ -185,6 +197,7 @@ class UserAspectRatioSettingsWindowManager extends CompatUIWindowManagerAbstract return; } mLayout.setUserAspectRatioButtonVisibility(true); + mUserAspectRatioButtonStateConsumer.accept(true); // Only show by default for the first time. if (!mCompatUIHintsState.mHasShownUserAspectRatioSettingsButtonHint) { mLayout.setUserAspectRatioSettingsHintVisibility(/* show= */ true); @@ -210,7 +223,8 @@ class UserAspectRatioSettingsWindowManager extends CompatUIWindowManagerAbstract private boolean getHasUserAspectRatioSettingsButton(@NonNull TaskInfo taskInfo) { return taskInfo.topActivityEligibleForUserAspectRatioButton && (taskInfo.topActivityBoundsLetterboxed - || taskInfo.isUserFullscreenOverrideEnabled); + || taskInfo.isUserFullscreenOverrideEnabled) + && !mUserAspectRatioButtonShownChecker.get(); } private long getDisappearTimeMs() { diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java index 9b9600e4a51e..3e0c853cf7dd 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java @@ -61,6 +61,7 @@ import com.android.wm.shell.transition.Transitions; import dagger.Lazy; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -523,13 +524,131 @@ public class CompatUIControllerTest extends ShellTestCase { .createLayout(anyBoolean()); } + @Test + public void testUpdateActiveTaskInfo_newTask_visibleAndFocused_updated() { + // Simulate user aspect ratio button being shown for previous task + mController.setHasShownUserAspectRatioSettingsButton(true); + Assert.assertTrue(mController.hasShownUserAspectRatioSettingsButton()); + + // Create new task + final TaskInfo taskInfo = createTaskInfo(DISPLAY_ID, TASK_ID, + /* hasSizeCompat= */ true, CAMERA_COMPAT_CONTROL_HIDDEN, /* isVisible */ true, + /* isFocused */ true); + + // Simulate new task being shown + mController.updateActiveTaskInfo(taskInfo); + + // Check topActivityTaskId is updated to the taskId of the new task and + // hasShownUserAspectRatioSettingsButton has been reset to false + Assert.assertEquals(TASK_ID, mController.getTopActivityTaskId()); + Assert.assertFalse(mController.hasShownUserAspectRatioSettingsButton()); + } + + @Test + public void testUpdateActiveTaskInfo_newTask_notVisibleOrFocused_notUpdated() { + // Create new task + final TaskInfo taskInfo = createTaskInfo(DISPLAY_ID, TASK_ID, + /* hasSizeCompat= */ true, CAMERA_COMPAT_CONTROL_HIDDEN, /* isVisible */ true, + /* isFocused */ true); + + // Simulate task being shown + mController.updateActiveTaskInfo(taskInfo); + + // Check topActivityTaskId is updated to the taskId of the new task and + // hasShownUserAspectRatioSettingsButton has been reset to false + Assert.assertEquals(TASK_ID, mController.getTopActivityTaskId()); + Assert.assertFalse(mController.hasShownUserAspectRatioSettingsButton()); + + // Simulate user aspect ratio button being shown + mController.setHasShownUserAspectRatioSettingsButton(true); + Assert.assertTrue(mController.hasShownUserAspectRatioSettingsButton()); + + final int newTaskId = TASK_ID + 1; + + // Create visible but NOT focused task + final TaskInfo taskInfo1 = createTaskInfo(DISPLAY_ID, newTaskId, + /* hasSizeCompat= */ true, CAMERA_COMPAT_CONTROL_HIDDEN, /* isVisible */ true, + /* isFocused */ false); + + // Simulate new task being shown + mController.updateActiveTaskInfo(taskInfo1); + + // Check topActivityTaskId is NOT updated and hasShownUserAspectRatioSettingsButton + // remains true + Assert.assertEquals(TASK_ID, mController.getTopActivityTaskId()); + Assert.assertTrue(mController.hasShownUserAspectRatioSettingsButton()); + + // Create focused but NOT visible task + final TaskInfo taskInfo2 = createTaskInfo(DISPLAY_ID, newTaskId, + /* hasSizeCompat= */ true, CAMERA_COMPAT_CONTROL_HIDDEN, /* isVisible */ false, + /* isFocused */ true); + + // Simulate new task being shown + mController.updateActiveTaskInfo(taskInfo2); + + // Check topActivityTaskId is NOT updated and hasShownUserAspectRatioSettingsButton + // remains true + Assert.assertEquals(TASK_ID, mController.getTopActivityTaskId()); + Assert.assertTrue(mController.hasShownUserAspectRatioSettingsButton()); + + // Create NOT focused but NOT visible task + final TaskInfo taskInfo3 = createTaskInfo(DISPLAY_ID, newTaskId, + /* hasSizeCompat= */ true, CAMERA_COMPAT_CONTROL_HIDDEN, /* isVisible */ false, + /* isFocused */ false); + + // Simulate new task being shown + mController.updateActiveTaskInfo(taskInfo3); + + // Check topActivityTaskId is NOT updated and hasShownUserAspectRatioSettingsButton + // remains true + Assert.assertEquals(TASK_ID, mController.getTopActivityTaskId()); + Assert.assertTrue(mController.hasShownUserAspectRatioSettingsButton()); + } + + @Test + public void testUpdateActiveTaskInfo_sameTask_notUpdated() { + // Create new task + final TaskInfo taskInfo = createTaskInfo(DISPLAY_ID, TASK_ID, + /* hasSizeCompat= */ true, CAMERA_COMPAT_CONTROL_HIDDEN, /* isVisible */ true, + /* isFocused */ true); + + // Simulate new task being shown + mController.updateActiveTaskInfo(taskInfo); + + // Check topActivityTaskId is updated to the taskId of the new task and + // hasShownUserAspectRatioSettingsButton has been reset to false + Assert.assertEquals(TASK_ID, mController.getTopActivityTaskId()); + Assert.assertFalse(mController.hasShownUserAspectRatioSettingsButton()); + + // Simulate user aspect ratio button being shown + mController.setHasShownUserAspectRatioSettingsButton(true); + Assert.assertTrue(mController.hasShownUserAspectRatioSettingsButton()); + + // Simulate same task being re-shown + mController.updateActiveTaskInfo(taskInfo); + + // Check topActivityTaskId is NOT updated and hasShownUserAspectRatioSettingsButton + // remains true + Assert.assertEquals(TASK_ID, mController.getTopActivityTaskId()); + Assert.assertTrue(mController.hasShownUserAspectRatioSettingsButton()); + } + private static TaskInfo createTaskInfo(int displayId, int taskId, boolean hasSizeCompat, @CameraCompatControlState int cameraCompatControlState) { + return createTaskInfo(displayId, taskId, hasSizeCompat, cameraCompatControlState, + /* isVisible */ false, /* isFocused */ false); + } + + private static TaskInfo createTaskInfo(int displayId, int taskId, boolean hasSizeCompat, + @CameraCompatControlState int cameraCompatControlState, boolean isVisible, + boolean isFocused) { RunningTaskInfo taskInfo = new RunningTaskInfo(); taskInfo.taskId = taskId; taskInfo.displayId = displayId; taskInfo.topActivityInSizeCompat = hasSizeCompat; taskInfo.cameraCompatControlState = cameraCompatControlState; + taskInfo.isVisible = isVisible; + taskInfo.isFocused = isFocused; return taskInfo; } } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/UserAspectRatioSettingsLayoutTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/UserAspectRatioSettingsLayoutTest.java index ce1290b38830..f460d1b09e34 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/UserAspectRatioSettingsLayoutTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/UserAspectRatioSettingsLayoutTest.java @@ -93,7 +93,8 @@ public class UserAspectRatioSettingsLayoutTest extends ShellTestCase { mWindowManager = new UserAspectRatioSettingsWindowManager(mContext, mTaskInfo, mSyncTransactionQueue, mTaskListener, new DisplayLayout(), new CompatUIController.CompatUIHintsState(), - mOnUserAspectRatioSettingsButtonClicked, new TestShellExecutor(), flags -> 0); + mOnUserAspectRatioSettingsButtonClicked, new TestShellExecutor(), flags -> 0, + () -> false, s -> {}); mLayout = (UserAspectRatioSettingsLayout) LayoutInflater.from(mContext).inflate( R.layout.user_aspect_ratio_settings_layout, null); diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/UserAspectRatioSettingsWindowManagerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/UserAspectRatioSettingsWindowManagerTest.java index 08cc2f763135..2a9b72a0bc49 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/UserAspectRatioSettingsWindowManagerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/UserAspectRatioSettingsWindowManagerTest.java @@ -106,7 +106,8 @@ public class UserAspectRatioSettingsWindowManagerTest extends ShellTestCase { false, /* topActivityBoundsLetterboxed */ true); mWindowManager = new UserAspectRatioSettingsWindowManager(mContext, mTaskInfo, mSyncTransactionQueue, mTaskListener, new DisplayLayout(), new CompatUIHintsState(), - mOnUserAspectRatioSettingsButtonClicked, mExecutor, flags -> 0); + mOnUserAspectRatioSettingsButtonClicked, mExecutor, flags -> 0, () -> false, + s -> {}); spyOn(mWindowManager); doReturn(mLayout).when(mWindowManager).inflateLayout(); doReturn(mViewHost).when(mWindowManager).createSurfaceViewHost(); |