From 2ee6ac9a0cd286ec2bfc9a4c560c6349c9431c1a Mon Sep 17 00:00:00 2001 From: Saumya Prakash Date: Wed, 28 May 2025 21:24:57 +0000 Subject: [PATCH 01/14] Ensure correct conditions for TaskbarStashControllerTest This change explicitly allows for TaskbarStashControllerTest to control whether the navigation bar is visible in setup wizard or not. This was needed because two test cases rely on the navbar being visible/not visible and would otherwise lead to a test failure. Fix: 420737945 Test: atest NexusLauncherTests:com.android.launcher3.taskbar.TaskbarStashControllerTest Flag: EXEMPT bugfix Change-Id: Ie0da668f0d37753e38cd4dcc17532aed761f0f7b --- .../launcher3/taskbar/TaskbarStashController.java | 10 ++++++---- .../launcher3/taskbar/TaskbarStashControllerTest.kt | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java index 94d348b0b3..c666dcd275 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java @@ -74,6 +74,7 @@ import com.android.quickstep.util.SystemUiFlagUtils; import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.Objects; import java.util.StringJoiner; import java.util.function.LongPredicate; @@ -297,7 +298,7 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba // Used to mark whether we are in test mode to mark whether the nav bar shows in SUW @VisibleForTesting - boolean mShouldHideNavbarForTest; + Boolean mNavbarHiddenOverrideForTest = null; public TaskbarStashController(TaskbarActivityContext activity) { mActivity = activity; @@ -557,11 +558,12 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba /** * Returns whether the navigation bar is visible during the Setup Wizard. * - * {@link #mShouldHideNavbarForTest} is only used by tests + * {@link #mNavbarHiddenOverrideForTest} is only used by tests */ private boolean isNavbarHiddeninSUW() { - return mShouldHideNavbarForTest - || mControllers.navbarButtonsViewController.isNavbarHiddenInSUW(); + // Check if a test override is active + return Objects.requireNonNullElseGet(mNavbarHiddenOverrideForTest, + () -> mControllers.navbarButtonsViewController.isNavbarHiddenInSUW()); } /** diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarStashControllerTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarStashControllerTest.kt index 22e0923fe2..956e327998 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarStashControllerTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarStashControllerTest.kt @@ -361,17 +361,19 @@ class TaskbarStashControllerTest { @TaskbarMode(PINNED) @UserSetupMode fun testGetContentHeightToReportToApps_pinnedInSetupMode_setupWizardInsets() { + stashController.mNavbarHiddenOverrideForTest = false assertThat(stashController.contentHeightToReportToApps) .isEqualTo(context.resources.getDimensionPixelSize(R.dimen.taskbar_suw_insets)) + stashController.mNavbarHiddenOverrideForTest = null } @Test @UserSetupMode fun testGetContentHeightToReportToApps_inExpressiveTheme_setupWizardInsets() { - stashController.mShouldHideNavbarForTest = true + stashController.mNavbarHiddenOverrideForTest = true assertThat(stashController.contentHeightToReportToApps) .isEqualTo(stashController.stashedHeight) - stashController.mShouldHideNavbarForTest = false + stashController.mNavbarHiddenOverrideForTest = null } @Test From afa97055fa05e0e4dfa42431619df5b9635c7c50 Mon Sep 17 00:00:00 2001 From: Shamali Patwa Date: Tue, 3 Jun 2025 17:37:40 -0700 Subject: [PATCH 02/14] Update various tests to prepare for the new picker UI - Switched the tests that probe old picker to use disabled flag - Added some more tests for new code - A test to use the tap to add listener to add widget to homescreen - Updated compose unit test to cover for expanding an item Bug: 408283627 Flag: EXEMPT independent module Test: Test changes Change-Id: I238896ec6e24596db93953a22bb43f6c7abbb9d1 --- Android.bp | 24 ++- .../launcher3/widget/AddWidgetConfigTest.kt | 154 ++++++++++++++++++ .../landing/LandingScreenSinglePaneTest.kt | 30 ++++ tests/Android.bp | 3 - .../launcher3/widget/AddConfigWidgetTest.java | 8 + .../launcher3/widget/TaplAddWidgetTest.java | 9 + .../widget/picker/WidgetPickerTest.java | 9 + 7 files changed, 233 insertions(+), 4 deletions(-) create mode 100644 compose/tests/com/android/launcher3/widget/AddWidgetConfigTest.kt diff --git a/Android.bp b/Android.bp index 250744ae8a..f2ba4e8d43 100644 --- a/Android.bp +++ b/Android.bp @@ -61,6 +61,27 @@ filegroup { ], } +filegroup { + name: "launcher-compose-test-helpers-src", + srcs: [ + "compose/tests/com/android/launcher3/helper/TestHelper.kt", + ], +} + +filegroup { + name: "launcher-compose-ui-tests-src", + srcs: [], // Placeholder for compose/tests/com/android/launcher3/ui/.. tests. +} + +// Tests for features that are enabled only when compose dependency is enabled & run as part of +// Launcher3Tests +filegroup { + name: "launcher-compose-unit-tests-src", + srcs: [ + "compose/tests/com/android/launcher3/widget/AddWidgetConfigTest.kt", + ], +} + filegroup { name: "launcher-compose-tests-src", srcs: [ @@ -260,7 +281,8 @@ launcher_compose_tests_java_defaults { soong_config_variables: { release_enable_compose_in_launcher: { srcs: [ - ":launcher-compose-tests-src", + ":launcher-compose-test-helpers-src", + ":launcher-compose-unit-tests-src", ], // Compose dependencies static_libs: [ diff --git a/compose/tests/com/android/launcher3/widget/AddWidgetConfigTest.kt b/compose/tests/com/android/launcher3/widget/AddWidgetConfigTest.kt new file mode 100644 index 0000000000..73daacd1af --- /dev/null +++ b/compose/tests/com/android/launcher3/widget/AddWidgetConfigTest.kt @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.widget + +import android.appwidget.AppWidgetManager +import android.view.View +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import androidx.test.platform.app.InstrumentationRegistry +import com.android.launcher3.AbstractFloatingView +import com.android.launcher3.Launcher +import com.android.launcher3.model.data.ItemInfo +import com.android.launcher3.model.data.LauncherAppWidgetInfo +import com.android.launcher3.testcomponent.WidgetConfigActivity +import com.android.launcher3.util.BaseLauncherActivityTest +import com.android.launcher3.util.BlockingBroadcastReceiver +import com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator +import com.android.launcher3.util.Wait +import com.android.launcher3.util.rule.ShellCommandRule +import com.android.launcher3.util.ui.PortraitLandscapeRunner.PortraitLandscape +import com.android.launcher3.util.ui.TestViewHelpers +import com.android.launcher3.util.workspace.FavoriteItemsTransaction +import com.android.launcher3.widgetpicker.listeners.WidgetPickerAddItemListener +import com.google.common.truth.Truth.assertThat +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Test verifies that when adding a widget to homescreen using [WidgetPickerAddItemListener], if the + * widget has a configuration activity, it is shown correctly. + */ +@LargeTest +@RunWith(AndroidJUnit4::class) +class AddWidgetConfigTest : BaseLauncherActivityTest() { + @get:Rule val grantWidgetRule: ShellCommandRule = ShellCommandRule.grantWidgetBind() + + private lateinit var widgetInfo: LauncherAppWidgetProviderInfo + private lateinit var appWidgetManager: AppWidgetManager + + private var widgetId = 0 + + @Before + @Throws(Exception::class) + fun setUp() { + widgetInfo = TestViewHelpers.findWidgetProvider(/* hasConfigureScreen= */ true) + appWidgetManager = AppWidgetManager.getInstance(targetContext()) + } + + @Test + @PortraitLandscape + @Throws(Throwable::class) + fun testWidgetConfig() { + runTest(acceptConfig = true) + } + + @Test + @PortraitLandscape + @Throws(Throwable::class) + fun testConfigCancelled() { + runTest(acceptConfig = false) + } + + /** @param acceptConfig accept the config activity */ + @Throws(Throwable::class) + private fun runTest(acceptConfig: Boolean) { + FavoriteItemsTransaction(targetContext()).commit() + loadLauncherSync() + + // Add widget to home screen + val monitor = WidgetConfigStartupMonitor() + launcherActivity.executeOnLauncher({ l: Launcher -> + val addItemListener = WidgetPickerAddItemListener(widgetInfo) + addItemListener.init(l, /* isHomeStarted= */ true) + }) + + uiDevice.waitForIdle() + + // Widget id for which the config activity was opened + widgetId = monitor.widgetId + + // Verify that the widget id is valid and bound + assertThat(appWidgetManager.getAppWidgetInfo(widgetId)).isNotNull() + setResult(acceptConfig) + + if (acceptConfig) { + launcherActivity.getOnceNotNull("Widget was not added") { l: Launcher -> + // Close the resize frame before searching for widget + AbstractFloatingView.closeAllOpenViews(l) + l.workspace.mapOverItems(WidgetSearchCondition()) + } + assertThat(appWidgetManager.getAppWidgetInfo(widgetId)).isNotNull() + } else { + // Verify that the widget id is deleted. + Wait.atMost( + "no widget with id", + { appWidgetManager.getAppWidgetInfo(widgetId) == null }, + ) + } + } + + private fun setResult(success: Boolean) { + InstrumentationRegistry.getInstrumentation() + .targetContext + .sendBroadcast( + WidgetConfigActivity.getCommandIntent( + WidgetConfigActivity::class.java, + if (success) "clickOK" else "clickCancel", + ) + ) + uiDevice.waitForIdle() + } + + /** Condition for searching widget id */ + private inner class WidgetSearchCondition : ItemOperator { + override fun evaluate(info: ItemInfo?, view: View): Boolean { + return info is LauncherAppWidgetInfo && + info.providerName == widgetInfo.provider && + info.appWidgetId == widgetId + } + } + + /** Broadcast receiver for receiving widget config activity status. */ + private class WidgetConfigStartupMonitor : + BlockingBroadcastReceiver(WidgetConfigActivity::class.java.name) { + @get:Throws(InterruptedException::class) + val widgetId: Int + get() { + val intent = checkNotNull(blockingGetExtraIntent()) + assertThat(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE).isEqualTo(intent.action) + val widgetId = + intent.getIntExtra( + AppWidgetManager.EXTRA_APPWIDGET_ID, + LauncherAppWidgetInfo.NO_ID, + ) + assertThat(widgetId).isNotEqualTo(LauncherAppWidgetInfo.NO_ID) + return widgetId + } + } +} diff --git a/modules/widgetpicker/tests/multivalentTests/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenSinglePaneTest.kt b/modules/widgetpicker/tests/multivalentTests/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenSinglePaneTest.kt index 7316aaa15b..4c288f56c3 100644 --- a/modules/widgetpicker/tests/multivalentTests/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenSinglePaneTest.kt +++ b/modules/widgetpicker/tests/multivalentTests/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenSinglePaneTest.kt @@ -212,4 +212,34 @@ class LandingScreenSinglePaneTest { composeTestRule.onNode(hasText(PERSONAL_TEST_APPS[0].title!!.toString())) .assertIsNotDisplayed() } + + @OptIn(ExperimentalCoroutinesApi::class) + @Test + fun clickingOnAppHeaderShowsWidgetsForThatApp() = testScope.runTest { + composeTestRule.setContent { SinglePaneTestContent() } + + runCurrent() + composeTestRule.waitForIdle() + + composeTestRule.onNode(hasTextExactly(PERSONAL_LABEL)).assertExists().performClick() + + runCurrent() + composeTestRule.waitForIdle() + + // Click on the an app header + val appTitle = PERSONAL_TEST_APPS[0].title!!.toString() + composeTestRule.onNode(hasText(appTitle)).assertExists().performClick() + + runCurrent() + composeTestRule.waitForIdle() + + // Verify the widget for that selected app is displayed + composeTestRule.onNode( + hasContentDescription( + PERSONAL_TEST_APPS[0].widgets[0].label, + substring = true + ) + ) + .assertIsDisplayed() + } } diff --git a/tests/Android.bp b/tests/Android.bp index 2570f59f4f..d627f8f624 100644 --- a/tests/Android.bp +++ b/tests/Android.bp @@ -64,9 +64,6 @@ filegroup { // Library with all the dependencies for building quickstep android_library { name: "Launcher3TestLib", - defaults: [ - "launcher_compose_tests_defaults", - ], srcs: [], asset_dirs: ["assets"], resource_dirs: ["res"], diff --git a/tests/src/com/android/launcher3/widget/AddConfigWidgetTest.java b/tests/src/com/android/launcher3/widget/AddConfigWidgetTest.java index e88a4fb19a..0acc58dd78 100644 --- a/tests/src/com/android/launcher3/widget/AddConfigWidgetTest.java +++ b/tests/src/com/android/launcher3/widget/AddConfigWidgetTest.java @@ -27,12 +27,15 @@ import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; import android.os.Process; +import android.platform.test.annotations.DisableFlags; +import android.platform.test.flag.junit.SetFlagsRule; import android.view.View; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; import com.android.launcher3.AbstractFloatingView; +import com.android.launcher3.Flags; import com.android.launcher3.Launcher; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.LauncherAppWidgetInfo; @@ -60,6 +63,9 @@ import org.junit.runner.RunWith; @LargeTest @RunWith(AndroidJUnit4.class) public class AddConfigWidgetTest extends BaseLauncherActivityTest { + @Rule + public final SetFlagsRule mSetFlagsRule = + new SetFlagsRule(SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT); @Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind(); @@ -77,12 +83,14 @@ public class AddConfigWidgetTest extends BaseLauncherActivityTest { @Test @PortraitLandscape + @DisableFlags(Flags.FLAG_ENABLE_WIDGET_PICKER_REFACTOR) public void testWidgetConfig() throws Throwable { runTest(true); } @Test @PortraitLandscape + @DisableFlags(Flags.FLAG_ENABLE_WIDGET_PICKER_REFACTOR) public void testConfigCancelled() throws Throwable { runTest(false); } diff --git a/tests/src/com/android/launcher3/widget/TaplAddWidgetTest.java b/tests/src/com/android/launcher3/widget/TaplAddWidgetTest.java index b18b6497e3..f14052612f 100644 --- a/tests/src/com/android/launcher3/widget/TaplAddWidgetTest.java +++ b/tests/src/com/android/launcher3/widget/TaplAddWidgetTest.java @@ -17,12 +17,15 @@ package com.android.launcher3.widget; import static org.junit.Assert.assertNotNull; +import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.PlatinumTest; +import android.platform.test.flag.junit.SetFlagsRule; import android.view.View; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; +import com.android.launcher3.Flags; import com.android.launcher3.Launcher; import com.android.launcher3.tapl.Widget; import com.android.launcher3.tapl.WidgetResizeFrame; @@ -44,12 +47,16 @@ import org.junit.runner.RunWith; @LargeTest @RunWith(AndroidJUnit4.class) public class TaplAddWidgetTest extends AbstractLauncherUiTest { + @Rule + public final SetFlagsRule mSetFlagsRule = + new SetFlagsRule(SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT); @Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind(); @Test @PortraitLandscape + @DisableFlags(Flags.FLAG_ENABLE_WIDGET_PICKER_REFACTOR) public void testDragIcon() throws Throwable { commitTransactionAndLoadHome(new FavoriteItemsTransaction(mTargetContext)); @@ -81,6 +88,7 @@ public class TaplAddWidgetTest extends AbstractLauncherUiTest { */ @Test @PortraitLandscape + @DisableFlags(Flags.FLAG_ENABLE_WIDGET_PICKER_REFACTOR) public void testDragCustomShortcut() throws Throwable { // TODO(b/322820039): Enable test for tablets - the picker UI has changed and test needs to // be updated to look for appropriate UI elements. @@ -99,6 +107,7 @@ public class TaplAddWidgetTest extends AbstractLauncherUiTest { */ @PlatinumTest(focusArea = "launcher") @Test + @DisableFlags(Flags.FLAG_ENABLE_WIDGET_PICKER_REFACTOR) public void testResizeWidget() throws Throwable { commitTransactionAndLoadHome(new FavoriteItemsTransaction(mTargetContext)); diff --git a/tests/src/com/android/launcher3/widget/picker/WidgetPickerTest.java b/tests/src/com/android/launcher3/widget/picker/WidgetPickerTest.java index e2f2c6b810..2bc41efe4e 100644 --- a/tests/src/com/android/launcher3/widget/picker/WidgetPickerTest.java +++ b/tests/src/com/android/launcher3/widget/picker/WidgetPickerTest.java @@ -19,6 +19,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import android.platform.test.annotations.DisableFlags; +import android.platform.test.flag.junit.SetFlagsRule; + import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.MediumTest; @@ -34,12 +37,17 @@ import org.junit.Test; import org.junit.rules.TestRule; import org.junit.runner.RunWith; +import com.android.launcher3.Flags; + /** * Make sure the basic interactions with the WidgetPicker works. */ @MediumTest @RunWith(AndroidJUnit4.class) public class WidgetPickerTest extends BaseLauncherActivityTest { + @Rule + public final SetFlagsRule mSetFlagsRule = + new SetFlagsRule(SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT); @Rule public TestRule screenRecordRule = new ScreenRecordRule(); @@ -58,6 +66,7 @@ public class WidgetPickerTest extends BaseLauncherActivityTest { @Test @ScreenRecord @PortraitLandscape + @DisableFlags(Flags.FLAG_ENABLE_WIDGET_PICKER_REFACTOR) public void testWidgets() { loadLauncherSync(); // Test opening widgets. From afeec5b51fc1eea16316afabc47afde57fba4900 Mon Sep 17 00:00:00 2001 From: Pat Manning Date: Wed, 4 Jun 2025 13:43:08 +0100 Subject: [PATCH 03/14] Do not clear offloaded task's icon if in split selection. We hide the task being split during split selection, and if a config change occurs and we need to re-init the split, we will need the icon still. Fix: 420543918 Test: Manual. Flag: EXEMPT Bugfix Change-Id: Ic4db47633b62b6cbf6b4e66f74912f4c806901e0 --- quickstep/src/com/android/quickstep/views/TaskView.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/quickstep/src/com/android/quickstep/views/TaskView.kt b/quickstep/src/com/android/quickstep/views/TaskView.kt index 05b79cc925..d9362f75b7 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.kt +++ b/quickstep/src/com/android/quickstep/views/TaskView.kt @@ -967,7 +967,10 @@ constructor( canShowAppTimer = false, clickCloseListener = null, ) - if (enableOverviewIconMenu()) { + // Do not set icon to null if we are actively in split selection. The task + // appears to have been offloaded as we remove it during split, but we still + // need the icon to show over the split task. + if (enableOverviewIconMenu() && recentsView?.isSplitSelectionActive == false) { setIconState(it, null) } } From 1dd8075f28cada875a6c9c91e980f817023daf36 Mon Sep 17 00:00:00 2001 From: Shamali Patwa Date: Wed, 4 Jun 2025 10:22:23 -0700 Subject: [PATCH 04/14] Widget picker: add test tags for major screen components Adds test tags intended to be used from UI automator tests. Bug: 408283627 Flag: EXEMPT independent module Test: Test changes Change-Id: I06b58ebb6f48906fd6e1dd1be74b011d226ce797 --- .../ui/components/LeadingIconToolbarTab.kt | 3 +- .../widgetpicker/ui/components/TestTag.kt | 33 ++++++++++++++++++- .../widgetpicker/ui/components/WidgetsGrid.kt | 4 +-- .../ui/fullcatalog/FullWidgetsCatalog.kt | 9 ++++- .../landing/LandingScreenSinglePane.kt | 15 +++++++++ .../screens/landing/LandingScreenTwoPane.kt | 18 ++++++++-- .../ui/components/WidgetInteractionsTest.kt | 2 +- 7 files changed, 76 insertions(+), 8 deletions(-) diff --git a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/LeadingIconToolbarTab.kt b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/LeadingIconToolbarTab.kt index 865a9b337a..d36eaf101e 100644 --- a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/LeadingIconToolbarTab.kt +++ b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/LeadingIconToolbarTab.kt @@ -53,6 +53,7 @@ fun LeadingIconToolbarTab( label: String, selected: Boolean, onClick: () -> Unit, + modifier: Modifier = Modifier, iconEnterTransition: EnterTransition = LeadingIconToolbarTabDefaults.iconEnterTransition, iconExitTransition: ExitTransition = LeadingIconToolbarTabDefaults.iconExitTransition, ) { @@ -65,7 +66,7 @@ fun LeadingIconToolbarTab( Row( modifier = - Modifier + modifier .fillMaxWidth() .clip(CircleShape) .selectable( diff --git a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/TestTag.kt b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/TestTag.kt index 63f4d217ef..0b9d8d204f 100644 --- a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/TestTag.kt +++ b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/TestTag.kt @@ -16,5 +16,36 @@ package com.android.launcher3.widgetpicker.ui.components +import androidx.compose.runtime.Stable +import androidx.compose.ui.Modifier +import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.semantics.testTag +import androidx.compose.ui.semantics.testTagsAsResourceId + +/** + * Adds a test tag to the modifier. + * + * The test tag is prefixed with the widget picker package name to avoid conflicts with other + * packages. This tag enables using `By.res(..)` to find UI elements in UI automator tests. See + * https://developer.android.com/develop/ui/compose/testing/interoperability#uiautomator-interop + * + * For unit testing, prefer content description, text or other content based selectors. + */ +@Stable +fun Modifier.widgetPickerTestTag(id: String): Modifier { + return this.semantics { testTag = buildWidgetPickerTestTag(id) } +} + +/** + * Mark this node as a container that contains one or more [widgetPickerTestTag] descendants. + * + * Should be used on the top level composable of a widget picker screen. + * @see [widgetPickerTestTag] for more details. + */ +@Stable +fun Modifier.widgetPickerTestTagContainer(): Modifier { + return this.then(Modifier.semantics { testTagsAsResourceId = true }) +} + /** Builds a test tag prefixed with the widget picker package name. */ -fun widgetPickerTestTag(id: String): String = "com.android.launcher3.widgetpicker:id/$id" +fun buildWidgetPickerTestTag(id: String): String = "com.android.launcher3.widgetpicker:id/$id" diff --git a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/WidgetsGrid.kt b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/WidgetsGrid.kt index 640596007d..5e0ecf8a94 100644 --- a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/WidgetsGrid.kt +++ b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/WidgetsGrid.kt @@ -188,7 +188,7 @@ private fun Previews( .fillMaxSize() .clearAndSetSemantics { traversalIndex = index.toFloat() - testTag = WIDGET_PREVIEW_TEST_TAG + testTag = buildWidgetPickerTestTag(WIDGET_PREVIEW_TEST_TAG) }, ) { WidgetPreview( @@ -444,4 +444,4 @@ private object WidgetGridDimensions { val minItemWidth = 100.dp } -private val WIDGET_PREVIEW_TEST_TAG = widgetPickerTestTag("widget_preview") +private const val WIDGET_PREVIEW_TEST_TAG = "widget_preview" diff --git a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/FullWidgetsCatalog.kt b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/FullWidgetsCatalog.kt index e411bf5aab..8bc2e8f17d 100644 --- a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/FullWidgetsCatalog.kt +++ b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/FullWidgetsCatalog.kt @@ -25,6 +25,8 @@ import com.android.launcher3.widgetpicker.ui.WidgetPickerEventListeners import com.android.launcher3.widgetpicker.ui.components.ModalBottomSheetHeightStyle import com.android.launcher3.widgetpicker.ui.components.TitledBottomSheet import com.android.launcher3.widgetpicker.ui.components.TitledBottomSheetDefaults +import com.android.launcher3.widgetpicker.ui.components.widgetPickerTestTag +import com.android.launcher3.widgetpicker.ui.components.widgetPickerTestTagContainer import com.android.launcher3.widgetpicker.ui.fullcatalog.FullWidgetsCatalogViewModel.Screen import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreen import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.search.SearchScreen @@ -61,7 +63,10 @@ class FullWidgetsCatalog @Inject constructor( TitledBottomSheet( title = viewModel.title.takeIf { !isCompactHeight }, - modifier = Modifier, + modifier = + Modifier + .widgetPickerTestTagContainer() + .widgetPickerTestTag(WIDGET_CATALOG_TEST_TAG), description = viewModel.description, heightStyle = ModalBottomSheetHeightStyle.FILL_HEIGHT, showDragHandle = true, @@ -91,3 +96,5 @@ class FullWidgetsCatalog @Inject constructor( } } } + +private const val WIDGET_CATALOG_TEST_TAG = "widgets_catalog" diff --git a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenSinglePane.kt b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenSinglePane.kt index 157f4de19c..862c9144a5 100644 --- a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenSinglePane.kt +++ b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenSinglePane.kt @@ -16,6 +16,7 @@ package com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing + import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize @@ -50,6 +51,7 @@ import com.android.launcher3.widgetpicker.ui.components.ScrollableFloatingToolba import com.android.launcher3.widgetpicker.ui.components.SinglePaneLayout import com.android.launcher3.widgetpicker.ui.components.WidgetAppHeaderStyle import com.android.launcher3.widgetpicker.ui.components.WidgetAppsList +import com.android.launcher3.widgetpicker.ui.components.widgetPickerTestTag import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.DEFAULT_SELECTED_TAB import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.FEATURED_TAB_INDEX import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.PERSONAL_TAB_INDEX @@ -61,6 +63,9 @@ import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.Landing import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.bottomTabsTopPadding import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.contentShape import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneDimens.pagerItemsSpacing +import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneTestTags.FEATURED_WIDGETS_TAB_TEST_TAG +import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneTestTags.PERSONAL_WIDGETS_TAB_TEST_TAG +import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenSinglePaneTestTags.WORK_WIDGETS_TAB_TEST_TAG import com.android.launcher3.widgetpicker.ui.theme.WidgetPickerTheme import kotlinx.coroutines.launch @@ -190,6 +195,7 @@ private fun BottomTabs( pagerState.animateScrollToPage(FEATURED_TAB_INDEX) } }, + modifier = Modifier.widgetPickerTestTag(FEATURED_WIDGETS_TAB_TEST_TAG), ) } @@ -204,6 +210,7 @@ private fun BottomTabs( pagerState.animateScrollToPage(PERSONAL_TAB_INDEX) } }, + modifier = Modifier.widgetPickerTestTag(PERSONAL_WIDGETS_TAB_TEST_TAG), ) } } else { @@ -217,6 +224,7 @@ private fun BottomTabs( pagerState.animateScrollToPage(PERSONAL_TAB_INDEX) } }, + modifier = Modifier.widgetPickerTestTag(PERSONAL_WIDGETS_TAB_TEST_TAG), ) } add { @@ -229,6 +237,7 @@ private fun BottomTabs( pagerState.animateScrollToPage(WORK_TAB_INDEX) } }, + modifier = Modifier.widgetPickerTestTag(WORK_WIDGETS_TAB_TEST_TAG), ) } } @@ -263,3 +272,9 @@ private object LandingScreenSinglePaneDimens { val bottomTabsHorizontalPadding = 32.dp val bottomTabsBottomPadding = 8.dp } + +private object LandingScreenSinglePaneTestTags { + const val FEATURED_WIDGETS_TAB_TEST_TAG = "featured_widgets_tab" + const val PERSONAL_WIDGETS_TAB_TEST_TAG = "personal_widgets_tab" + const val WORK_WIDGETS_TAB_TEST_TAG = "work_widgets_tab" +} \ No newline at end of file diff --git a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenTwoPane.kt b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenTwoPane.kt index 5a5c19bd7b..053c9e9c1a 100644 --- a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenTwoPane.kt +++ b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/fullcatalog/screens/landing/LandingScreenTwoPane.kt @@ -52,6 +52,7 @@ import com.android.launcher3.widgetpicker.ui.components.TwoPaneLayout import com.android.launcher3.widgetpicker.ui.components.WidgetAppHeaderStyle import com.android.launcher3.widgetpicker.ui.components.WidgetAppsList import com.android.launcher3.widgetpicker.ui.components.WidgetsGrid +import com.android.launcher3.widgetpicker.ui.components.widgetPickerTestTag import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneDimens.DEFAULT_SELECTED_TAB import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneDimens.PERSONAL_TAB_INDEX import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneDimens.TABS_COUNT_WITHOUT_WORK_PROFILE @@ -60,6 +61,9 @@ import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.Landing import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneDimens.contentShape import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneDimens.leftPaneContentBottomPadding import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneDimens.pagerItemsSpacing +import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneTestTags.FEATURED_WIDGETS_HEADER_TEST_TAG +import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneTestTags.PERSONAL_WIDGETS_TAB_TEST_TAG +import com.android.launcher3.widgetpicker.ui.fullcatalog.screens.landing.LandingScreenTwoPaneTestTags.WORK_WIDGETS_TAB_TEST_TAG import kotlinx.coroutines.launch /** @@ -287,7 +291,9 @@ private fun LeftPaneContent( onSelect = onFeaturedHeaderClick, count = featuredWidgetsCount, shape = contentShape, - modifier = Modifier.fillMaxWidth() + modifier = Modifier + .fillMaxWidth() + .widgetPickerTestTag(FEATURED_WIDGETS_HEADER_TEST_TAG), ) HorizontalPager( state = pagerState, @@ -419,7 +425,8 @@ private fun PersonalWorkToolbar( scope.launch { pagerState.animateScrollToPage(PERSONAL_TAB_INDEX) } - } + }, + modifier = Modifier.widgetPickerTestTag(PERSONAL_WIDGETS_TAB_TEST_TAG), ) } add { @@ -432,6 +439,7 @@ private fun PersonalWorkToolbar( pagerState.animateScrollToPage(WORK_TAB_INDEX) } }, + modifier = Modifier.widgetPickerTestTag(WORK_WIDGETS_TAB_TEST_TAG), ) } } @@ -459,3 +467,9 @@ private object LandingScreenTwoPaneDimens { const val WORK_TAB_INDEX = 1 const val DEFAULT_SELECTED_TAB = PERSONAL_TAB_INDEX } + +private object LandingScreenTwoPaneTestTags { + const val FEATURED_WIDGETS_HEADER_TEST_TAG = "featured_widgets_tab" + const val PERSONAL_WIDGETS_TAB_TEST_TAG = "personal_widgets_tab" + const val WORK_WIDGETS_TAB_TEST_TAG = "work_widgets_tab" +} diff --git a/modules/widgetpicker/tests/multivalentTests/src/com/android/launcher3/widgetpicker/ui/components/WidgetInteractionsTest.kt b/modules/widgetpicker/tests/multivalentTests/src/com/android/launcher3/widgetpicker/ui/components/WidgetInteractionsTest.kt index a4c5d2d998..6e2fb01f08 100644 --- a/modules/widgetpicker/tests/multivalentTests/src/com/android/launcher3/widgetpicker/ui/components/WidgetInteractionsTest.kt +++ b/modules/widgetpicker/tests/multivalentTests/src/com/android/launcher3/widgetpicker/ui/components/WidgetInteractionsTest.kt @@ -171,7 +171,7 @@ class WidgetInteractionsTest { WIDGET_TWO.id to TestUtils.createBitmapPreview() ) - private val PREVIEW_TEST_TAG = widgetPickerTestTag("widget_preview") + private val PREVIEW_TEST_TAG = buildWidgetPickerTestTag("widget_preview") private const val ADD_BUTTON_TEXT = "Add" private val WIDGET_ONE_ADD_BUTTON_CONTENT_DESC = "Add ${WIDGET_ONE.label} widget" private val WIDGET_TWO_ADD_BUTTON_CONTENT_DESC = "Add ${WIDGET_TWO.label} widget" From a64bc6bfa469804ae96160d5c5d2c95920ff1033 Mon Sep 17 00:00:00 2001 From: Charlie Anderson Date: Wed, 4 Jun 2025 17:52:16 +0000 Subject: [PATCH 05/14] Fix usages of BitmapInfo after converting to kotlin Bug: 421883017 Flag: EXEMPT refactor - no new logic Test: N/A Change-Id: Id48c9fefef37f71f1fc51570664918bcd845e6d6 --- .../widgetpicker/repository/WidgetAppIconsRepositoryImpl.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compose/features/com/android/launcher3/widgetpicker/repository/WidgetAppIconsRepositoryImpl.kt b/compose/features/com/android/launcher3/widgetpicker/repository/WidgetAppIconsRepositoryImpl.kt index c6d013750b..e1802b4e28 100644 --- a/compose/features/com/android/launcher3/widgetpicker/repository/WidgetAppIconsRepositoryImpl.kt +++ b/compose/features/com/android/launcher3/widgetpicker/repository/WidgetAppIconsRepositoryImpl.kt @@ -60,7 +60,7 @@ class WidgetAppIconsRepositoryImpl @Inject constructor( trySend( WidgetAppIcon( icon = AppIcon.HighResBitmapIcon(itemInfoWithIcon.bitmap.icon), - badge = itemInfoWithIcon.bitmap.badgeDrawableInfo?.let { + badge = itemInfoWithIcon.bitmap.getBadgeDrawableInfo()?.let { AppIconBadge.DrawableBadge( it.drawableRes, it.colorRes From 053d45170d5f88a2d0d64a322acd31da94408010 Mon Sep 17 00:00:00 2001 From: Schneider Victor-Tulias Date: Wed, 4 Jun 2025 13:27:57 -0400 Subject: [PATCH 06/14] Add missing nullability checks for AbsSwipeUpHandler.mRecentsView Flag: EXEMPT bug fix Fixes: 422239562 Test: AbsSwipeUpHandlerTestCase.testRecentsViewNullability Change-Id: I0e2ac2d14bf8ee6130e1349d3c776df0c46fe256 --- .../com/android/quickstep/AbsSwipeUpHandler.java | 2 +- .../android/quickstep/FallbackSwipeHandler.java | 4 +++- .../quickstep/LauncherSwipeHandlerV2.java | 13 ++++++++++--- .../window/RecentsWindowSwipeHandler.java | 6 ++++-- .../quickstep/AbsSwipeUpHandlerTestCase.java | 16 +++++++++++++++- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index ff0ab7c0d9..430bf6995c 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -597,7 +597,7 @@ public abstract class AbsSwipeUpHandler< private void onLauncherStart() { final RECENTS_CONTAINER container = mContainerInterface.getCreatedContainer(); - if (container == null || mContainer != container) { + if (container == null || mContainer != container || mRecentsView == null) { return; } if (mStateCallback.hasStates(STATE_HANDLER_INVALIDATED)) { diff --git a/quickstep/src/com/android/quickstep/FallbackSwipeHandler.java b/quickstep/src/com/android/quickstep/FallbackSwipeHandler.java index 19b63aa1e9..20df59c3d0 100644 --- a/quickstep/src/com/android/quickstep/FallbackSwipeHandler.java +++ b/quickstep/src/com/android/quickstep/FallbackSwipeHandler.java @@ -200,7 +200,9 @@ public class FallbackSwipeHandler extends } else { recentsCallback = callback; } - mRecentsView.cleanupRemoteTargets(); + if (mRecentsView != null) { + mRecentsView.cleanupRemoteTargets(); + } mRecentsAnimationController.finish( mAppCanEnterPip /* toRecents */, recentsCallback, true /* sendUserLeaveHint */); } diff --git a/quickstep/src/com/android/quickstep/LauncherSwipeHandlerV2.java b/quickstep/src/com/android/quickstep/LauncherSwipeHandlerV2.java index ed242faba9..85a677f18b 100644 --- a/quickstep/src/com/android/quickstep/LauncherSwipeHandlerV2.java +++ b/quickstep/src/com/android/quickstep/LauncherSwipeHandlerV2.java @@ -87,8 +87,13 @@ public class LauncherSwipeHandlerV2 extends AbsSwipeUpHandler< RemoteAnimationTarget runningTaskTarget, @Nullable TaskView targetTaskView) { if (mContainer == null) { - mStateCallback.addChangeListener(STATE_LAUNCHER_PRESENT | STATE_HANDLER_INVALIDATED, - isPresent -> mRecentsView.startHome()); + mStateCallback.addChangeListener( + STATE_LAUNCHER_PRESENT | STATE_HANDLER_INVALIDATED, + isPresent -> { + if (mRecentsView != null) { + mRecentsView.startHome(); + } + }); return new HomeAnimationFactory() { @Override public AnimatorPlaybackController createActivityAnimationToHome() { @@ -322,7 +327,9 @@ public class LauncherSwipeHandlerV2 extends AbsSwipeUpHandler< @Override protected void finishRecentsControllerToHome(Runnable callback) { - mRecentsView.cleanupRemoteTargets(); + if (mRecentsView != null) { + mRecentsView.cleanupRemoteTargets(); + } mRecentsAnimationController.finish( true /* toRecents */, callback, true /* sendUserLeaveHint */); } diff --git a/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowSwipeHandler.java b/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowSwipeHandler.java index 289baef349..2fd744f648 100644 --- a/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowSwipeHandler.java +++ b/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowSwipeHandler.java @@ -250,7 +250,9 @@ public class RecentsWindowSwipeHandler extends AbsSwipeUpHandler Date: Wed, 4 Jun 2025 14:45:34 -0400 Subject: [PATCH 07/14] Fix IllegalStateException in AbsSwipeUpHandler.onRecentsAnimationStart Flag: EXEMPT bug fix Fixes: 420854746 Test: AbsSwipeUpHandlerTestCase Change-Id: I534d6cb7c6d05395663cd45b0c889095b8aead4a --- .../src/com/android/quickstep/AbsSwipeUpHandler.java | 8 +++++--- .../com/android/quickstep/AbsSwipeUpHandlerTestCase.java | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index 430bf6995c..0e441ff934 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -1017,9 +1017,11 @@ public abstract class AbsSwipeUpHandler< .getOrientationState(); DeviceProfile dp = orientationState.getLauncherDeviceProfile( mGestureState.getDisplayId()); - if (targets.minimizedHomeBounds != null && primaryTaskTarget != null) { - Rect overviewStackBounds = mContainerInterface - .getOverviewWindowBounds(targets.minimizedHomeBounds, primaryTaskTarget); + Rect overviewStackBounds = mContainerInterface.getOverviewWindowBounds( + targets.minimizedHomeBounds, primaryTaskTarget); + if (overviewStackBounds != null + && !overviewStackBounds.isEmpty() + && primaryTaskTarget != null) { dp = dp.getMultiWindowProfile(mContext, new WindowBounds(overviewStackBounds, targets.homeContentInsets)); } else { diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/AbsSwipeUpHandlerTestCase.java b/quickstep/tests/multivalentTests/src/com/android/quickstep/AbsSwipeUpHandlerTestCase.java index f85b2fb49d..89181dc4d9 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/AbsSwipeUpHandlerTestCase.java +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/AbsSwipeUpHandlerTestCase.java @@ -405,8 +405,9 @@ public abstract class AbsSwipeUpHandlerTestCase< } @Test - public void testRecentsViewNullability() { - // Do not trigger onActivityInit to ensure mRecentsView is null + public void test_noActivityInit_doesNotThrowException() { + // Do not trigger onActivityInit to ensure AbsSwipeUpHandler.mRecentsView and + // AbsSwipeUpHandler.mContainer are null createSwipeUpHandlerForGesture( GestureState.GestureEndTarget.HOME, /* triggerOnActivityInit= */ false); } @@ -466,7 +467,7 @@ public abstract class AbsSwipeUpHandlerTestCase< private void onRecentsAnimationStart(SWIPE_HANDLER absSwipeUpHandler) { runOnMainSync(() -> absSwipeUpHandler.onRecentsAnimationStart( - mRecentsAnimationController, mRecentsAnimationTargets, /* transitionInfo= */null)); + mRecentsAnimationController, mRecentsAnimationTargets, /* transitionInfo= */ null)); } protected static void runOnMainSync(Runnable runnable) { From 6c3e08a35e2b97259326e75981e1e45f93224a97 Mon Sep 17 00:00:00 2001 From: Steven Ng Date: Fri, 30 May 2025 14:05:33 +0100 Subject: [PATCH 08/14] Switch to the new desk after clear all button is clicked in the recent view In connected display, when the clear all button is clicked, instead of launching home screen, this CL waits for the new desk for the display to be created and then launch to that new desk. Bug: 417944041 Flag: com.android.window.flags.enable_multiple_desktops_backend Flag: com.android.window.flags.enable_multiple_desktops_frontend Test: launch an app in connected display. Go to overview and click clear all. Confirmed the new desk is launched Test: create 2+ desks in the connected display. Go to overview. Swipe up to remove all desk one by one. Upon the last desk removal, the new desk is launched. Test: atest NexusLauncherTests:TaplTestsOverviewDesktop Change-Id: I3399274afd3fd4310fb4b1c1e6916b8386d81aaf --- .../quickstep/util/ExternalDisplays.kt | 6 ++- .../quickstep/views/RecentsDismissUtils.kt | 40 ++++++++++++++++++- .../quickstep/views/RecentsViewUtils.kt | 33 +++++++++++++++ 3 files changed, 76 insertions(+), 3 deletions(-) diff --git a/quickstep/src/com/android/quickstep/util/ExternalDisplays.kt b/quickstep/src/com/android/quickstep/util/ExternalDisplays.kt index 0aaca31f8b..e60e9f3959 100644 --- a/quickstep/src/com/android/quickstep/util/ExternalDisplays.kt +++ b/quickstep/src/com/android/quickstep/util/ExternalDisplays.kt @@ -23,7 +23,11 @@ import com.android.systemui.shared.recents.model.Task /** Whether this displayId belongs to an external display */ val Int.isExternalDisplay - get() = this != DEFAULT_DISPLAY + get() = !isDefaultDisplay + +/** Whether this displayId belongs to the default display */ +val Int.isDefaultDisplay + get() = this == DEFAULT_DISPLAY val Int?.safeDisplayId get() = diff --git a/quickstep/src/com/android/quickstep/views/RecentsDismissUtils.kt b/quickstep/src/com/android/quickstep/views/RecentsDismissUtils.kt index cc92b9a3d1..972f187680 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsDismissUtils.kt +++ b/quickstep/src/com/android/quickstep/views/RecentsDismissUtils.kt @@ -20,6 +20,7 @@ import android.app.ActivityTaskManager.INVALID_TASK_ID import android.view.View import androidx.core.graphics.toRectF import androidx.core.view.children +import androidx.core.view.contains import androidx.dynamicanimation.animation.FloatPropertyCompat import androidx.dynamicanimation.animation.FloatValueHolder import androidx.dynamicanimation.animation.SpringAnimation @@ -35,8 +36,12 @@ import com.android.launcher3.util.MSDLPlayerWrapper import com.android.launcher3.util.OverviewReleaseFlags.enableGridOnlyOverview import com.android.launcher3.views.ActivityContext import com.android.quickstep.SystemUiProxy +import com.android.quickstep.util.DesksUtils.Companion.areMultiDesksFlagsEnabled import com.android.quickstep.util.TaskGridNavHelper +import com.android.quickstep.util.isDefaultDisplay +import com.android.quickstep.util.isExternalDisplay import com.android.quickstep.views.RecentsView.RECENTS_SCALE_PROPERTY +import com.android.quickstep.views.RecentsViewUtils.OnDeskAddedListener import com.android.quickstep.views.TaskView.Companion.GRID_END_TRANSLATION_X import com.android.systemui.shared.system.ActivityManagerWrapper import com.android.systemui.shared.system.InteractionJankMonitorWrapper @@ -69,6 +74,20 @@ constructor( fun create(recentsView: RecentsView<*, *>): RecentsDismissUtils } + /** + * [OnDeskAddedListener] which launches the new desk right after it is created. + * + * This is mainly used for clearing all desks via the clear all button in the recent view or the + * removal of the last task in a desk. + */ + private val launchNewDeskListener = + object : OnDeskAddedListener { + override fun onDeskAdded(desktopTaskView: DesktopTaskView) { + desktopTaskView.launchWithAnimation() + recentsView.mUtils.removeOnDeskAddedListener(this) + } + } + /** * Runs the default spring animation when a dismissed task view in overview is released. * @@ -312,13 +331,18 @@ constructor( // tasks), and closing all tasks on a desk doesn't always necessarily mean that // the desk will be removed. So, there are no guarantees that the below call to // `ActivityManagerWrapper::removeAllRecentTasks()` will be enough. + if (areMultiDesksFlagsEnabled() && context.displayId.isExternalDisplay) { + mUtils.addOnDeskAddedListener(launchNewDeskListener) + } systemUiProxy.removeAllDesks() // Remove all the task views now finishRecentsAnimation(/* toRecents */ true, /* shouldPip */ false) { uiHelperExecutor.execute { activityManagerWrapper.removeAllRecentTasks() } removeAllTaskViews() - startHome() + if (context.displayId.isDefaultDisplay || !areMultiDesksFlagsEnabled()) { + startHome() + } } } } @@ -933,6 +957,16 @@ constructor( if (shouldRemoveTask && dismissedTaskView != null) { val groupTask = dismissedTaskView.groupTask if (groupTask != null) { + // For the multi desk case, the launcher should switch to the new desk once the + // last task of the previous desk is removed. + if ( + areMultiDesksFlagsEnabled() && + context.displayId.isExternalDisplay && + taskViewCount == 1 && + contains(dismissedTaskView) + ) { + mUtils.addOnDeskAddedListener(launchNewDeskListener) + } if (dismissedTaskView.isRunningTask) { finishRecentsAnimation(/* toRecents */ true, /* shouldPip */ false) { removeGroupTaskInternal(groupTask) @@ -1059,7 +1093,9 @@ constructor( if (dismissedTaskView === homeTaskView) { updateEmptyMessage() } else { - startHome() + if (!areMultiDesksFlagsEnabled() || context.displayId.isDefaultDisplay) { + startHome() + } } } } else { diff --git a/quickstep/src/com/android/quickstep/views/RecentsViewUtils.kt b/quickstep/src/com/android/quickstep/views/RecentsViewUtils.kt index b6ea8aa2ae..37aa7208a3 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsViewUtils.kt +++ b/quickstep/src/com/android/quickstep/views/RecentsViewUtils.kt @@ -63,6 +63,7 @@ import com.android.systemui.shared.recents.model.Task import com.android.systemui.shared.recents.model.ThumbnailData import com.android.wm.shell.shared.GroupedTaskInfo import com.android.wm.shell.shared.desktopmode.DesktopModeStatus.enableMultipleDesktops +import java.util.concurrent.CopyOnWriteArrayList import java.util.function.BiConsumer import kotlin.math.min import kotlin.reflect.KMutableProperty1 @@ -74,6 +75,18 @@ import kotlin.reflect.KMutableProperty1 class RecentsViewUtils(private val recentsView: RecentsView<*, *>) : DesktopVisibilityListener { val taskViews = TaskViewsIterable(recentsView) + /** Callback to be invoked when a new desk is added. */ + interface OnDeskAddedListener { + /** + * Called when a new desk is added. + * + * @param desktopTaskView The [DesktopTaskView] of the new desk. + */ + fun onDeskAdded(desktopTaskView: DesktopTaskView) + } + + private val onDeskAddedListeners = CopyOnWriteArrayList() + /** Takes a screenshot of all [taskView] and return map of taskId to the screenshot */ fun screenshotTasks(taskView: TaskView): Map { val recentsAnimationController = recentsView.recentsAnimationController ?: return emptyMap() @@ -332,6 +345,8 @@ class RecentsViewUtils(private val recentsView: RecentsView<*, *>) : DesktopVisi // Set Current Page based on the stored TaskView. currentTaskView?.let { setCurrentPage(indexOfChild(it)) } + + onDeskAddedListeners.forEach { it.onDeskAdded(desktopTaskView) } } } @@ -726,6 +741,24 @@ class RecentsViewUtils(private val recentsView: RecentsView<*, *>) : DesktopVisi taskViews.flatMap { it.taskContainers }.forEach { it.overlay.resetShareUI() } } + /** + * Adds a listener to be notified when a new desk is added. + * + * @param onDeskAddedListener The listener to add. + */ + fun addOnDeskAddedListener(onDeskAddedListener: OnDeskAddedListener) { + onDeskAddedListeners += onDeskAddedListener + } + + /** + * Removes a listener that was previously added to be notified when a new desk is added. + * + * @param onDeskAddedListener The listener to remove. + */ + fun removeOnDeskAddedListener(onDeskAddedListener: OnDeskAddedListener) { + onDeskAddedListeners -= onDeskAddedListener + } + companion object { class RecentsViewFloatProperty( private val utilsProperty: KMutableProperty1 From 988669d27767996ea93975280dc7e2ac1029985e Mon Sep 17 00:00:00 2001 From: Vinit Nayak Date: Wed, 4 Jun 2025 17:34:11 -0400 Subject: [PATCH 09/14] Removed obsolete test logs Flag: EXEMPT bugfix Fixes: 282963545 Test: Builds Change-Id: I18c6e95037424080d8e3446a55bd2becc6e0c07b --- .../src/com/android/launcher3/testing/shared/TestProtocol.java | 1 - .../android/launcher3/dragging/TaplUninstallRemoveTest.java | 3 --- .../com/android/launcher3/util/ui/BaseLauncherTaplTest.java | 3 --- 3 files changed, 7 deletions(-) diff --git a/shared/src/com/android/launcher3/testing/shared/TestProtocol.java b/shared/src/com/android/launcher3/testing/shared/TestProtocol.java index eccc5e7cdc..daa2e40930 100644 --- a/shared/src/com/android/launcher3/testing/shared/TestProtocol.java +++ b/shared/src/com/android/launcher3/testing/shared/TestProtocol.java @@ -174,7 +174,6 @@ public final class TestProtocol { public static final String REQUEST_MOCK_SENSOR_ROTATION = "mock-sensor-rotation"; public static final String PERMANENT_DIAG_TAG = "TaplTarget"; - public static final String ICON_MISSING = "b/282963545"; public static final String REQUEST_FLAG_ENABLE_GRID_ONLY_OVERVIEW = "enable-grid-only-overview"; public static final String REQUEST_IS_RECENTS_WINDOW_ENABLED = "recents-window-enabled"; diff --git a/tests/src/com/android/launcher3/dragging/TaplUninstallRemoveTest.java b/tests/src/com/android/launcher3/dragging/TaplUninstallRemoveTest.java index aa9098b777..c9669a0fbe 100644 --- a/tests/src/com/android/launcher3/dragging/TaplUninstallRemoveTest.java +++ b/tests/src/com/android/launcher3/dragging/TaplUninstallRemoveTest.java @@ -15,7 +15,6 @@ */ package com.android.launcher3.dragging; -import static com.android.launcher3.testing.shared.TestProtocol.ICON_MISSING; import static com.android.launcher3.util.TestConstants.AppNames.DUMMY_APP_NAME; import static com.android.launcher3.util.TestConstants.AppNames.GMAIL_APP_NAME; import static com.android.launcher3.util.TestConstants.AppNames.MAPS_APP_NAME; @@ -26,7 +25,6 @@ import static com.google.common.truth.Truth.assertThat; import android.graphics.Point; import android.platform.test.annotations.PlatinumTest; -import android.util.Log; import android.view.View; import com.android.launcher3.Launcher; @@ -134,7 +132,6 @@ public class TaplUninstallRemoveTest extends AbstractLauncherUiTest Date: Wed, 4 Jun 2025 15:21:00 -0700 Subject: [PATCH 10/14] desktop-exploded-view: Update isFocusable location As a follow up to ag/33785016, move the setting of isFocusable into enableDesktopExplodedView. Flag: com.android.launcher3.enable_desktop_exploded_view Test: manual Bug: 353949686 Change-Id: I34104592e068ee07699c719b52acf691bdfc3066 --- quickstep/src/com/android/quickstep/views/DesktopTaskView.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt b/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt index 07fc1e6904..012ed877db 100644 --- a/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt +++ b/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt @@ -401,11 +401,11 @@ class DesktopTaskView @JvmOverloads constructor(context: Context, attrs: Attribu taskContentView } if (enableDesktopExplodedView()) { - taskContentView.isFocusable = true taskContentView.setOnClickListener { launchTaskWithDesktopController(animated = true, task.key.id) } if (taskContentView is TaskContentView) { + taskContentView.isFocusable = true taskContentView.isHoverable = true } } From 98f0937787afaa163f6f34916cb6fda0235f7e73 Mon Sep 17 00:00:00 2001 From: Merissa Mitchell Date: Wed, 4 Jun 2025 14:40:28 -0700 Subject: [PATCH 11/14] [Pip] Don't reload Recents on onActivityUnpinned Invalidate the Recents list but don't reload the view immediately when PiP is dismissed. This effectively reverts commit If593c2e7271e972e96b1ab21b4396af66b1e3ea4. Bug: 416666696 Test: m Test: Presubmits Test: Manual - enter PiP, then swipe up to Overview. Dismiss PiP and verify the list is not updated. Exit Overview and re-enter Overview. Verify that the list is updated with the previously PiP-ed task. Flag: EXEMPT bug fix Change-Id: Iaa832f3b4e42404a7469b6b53a379ef42d959442 --- .../android/quickstep/views/RecentsView.java | 51 ++----------------- 1 file changed, 3 insertions(+), 48 deletions(-) diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index c152f1af72..df7d1d1493 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -80,8 +80,6 @@ import static com.android.quickstep.views.TaskView.SPLIT_ALPHA; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; -import android.animation.LayoutTransition; -import android.animation.LayoutTransition.TransitionListener; import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; import android.animation.ValueAnimator; @@ -122,7 +120,6 @@ import android.view.MotionEvent; import android.view.RemoteAnimationTarget; import android.view.View; import android.view.ViewDebug; -import android.view.ViewGroup; import android.view.ViewTreeObserver.OnScrollChangedListener; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; @@ -660,11 +657,9 @@ public abstract class RecentsView< return; } - // If PiP2 is enabled, we will trigger the reload only after the Transition is finished. - if (!PipFlags.isPip2ExperimentEnabled()) { - reloadIfNeeded(); - } - enableLayoutTransitions(); + // Only invalidate task list but don't trigger the reload, so that the list is only + // updated the next time user enters Overview + invalidateTaskList(); } @Override @@ -733,8 +728,6 @@ public abstract class RecentsView< @Nullable private PendingAnimation mPendingAnimation; - @Nullable - private LayoutTransition mLayoutTransition; @ViewDebug.ExportedProperty(category = "launcher") protected float mContentAlpha = 1; @@ -3572,34 +3565,6 @@ public abstract class RecentsView< } } - private void enableLayoutTransitions() { - if (mLayoutTransition == null) { - mLayoutTransition = new LayoutTransition(); - mLayoutTransition.enableTransitionType(LayoutTransition.APPEARING); - mLayoutTransition.setDuration(ADDITION_TASK_DURATION); - mLayoutTransition.setStartDelay(LayoutTransition.APPEARING, 0); - - mLayoutTransition.addTransitionListener(new TransitionListener() { - @Override - public void startTransition(LayoutTransition transition, ViewGroup viewGroup, - View view, int i) { - } - - @Override - public void endTransition(LayoutTransition transition, ViewGroup viewGroup, - View view, int i) { - // When the unpinned task is added, snap to first page and disable transitions - if (view instanceof TaskView) { - snapToPage(0); - setLayoutTransition(null); - } - - } - }); - } - setLayoutTransition(mLayoutTransition); - } - public void setSwipeDownShouldLaunchApp(boolean swipeDownShouldLaunchApp) { mSwipeDownShouldLaunchApp = swipeDownShouldLaunchApp; } @@ -6920,16 +6885,6 @@ public abstract class RecentsView< mRecentsView.mContainerInterface.getTaskbarController().onExpandPip(); }); } - - @Override - public void onExitPip() { - MAIN_EXECUTOR.execute(() -> { - if (mRecentsView == null || !PipFlags.isPip2ExperimentEnabled()) { - return; - } - mRecentsView.reloadIfNeeded(); - }); - } } /** Get the color used for foreground scrimming the RecentsView for sharing. */ From f9d63414580a0fe37641873637d79598374eaf26 Mon Sep 17 00:00:00 2001 From: Toni Barzic Date: Wed, 4 Jun 2025 21:29:04 +0000 Subject: [PATCH 12/14] Add tooltip for taskbar overflow button Bug: 402787161 Test: Manual Flag: com.android.window.flags.enable_taskbar_overflow Change-Id: I04704612260f17561b4d18804d792a3fe0d47313 --- quickstep/res/values/strings.xml | 2 +- .../taskbar/TaskbarHoverToolTipController.java | 2 ++ .../launcher3/taskbar/TaskbarOverflowView.java | 12 ++++++++++++ .../com/android/launcher3/taskbar/TaskbarView.java | 3 +++ .../android/launcher3/taskbar/TaskbarOverflowTest.kt | 12 ++++++++++++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/quickstep/res/values/strings.xml b/quickstep/res/values/strings.xml index 05f2397753..231970bb17 100644 --- a/quickstep/res/values/strings.xml +++ b/quickstep/res/values/strings.xml @@ -319,7 +319,7 @@ Taskbar Divider - Taskbar Overflow + Other recent apps diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarHoverToolTipController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarHoverToolTipController.java index 63d98d64a5..42ad5b2aa1 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarHoverToolTipController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarHoverToolTipController.java @@ -134,6 +134,8 @@ public class TaskbarHoverToolTipController implements View.OnHoverListener { return icon.mInfo.title.toString(); } else if (mHoverView instanceof AppPairIcon icon) { return icon.getTitleTextView().getText().toString(); + } else if (mHoverView instanceof TaskbarOverflowView icon) { + return icon.getTextForTooltipPopup(); } else { return null; } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarOverflowView.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarOverflowView.java index d909d19fb8..34787641c2 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarOverflowView.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarOverflowView.java @@ -39,6 +39,7 @@ import androidx.annotation.VisibleForTesting; import androidx.core.graphics.ColorUtils; import com.android.app.animation.Interpolators; +import com.android.launcher3.R; import com.android.launcher3.Reorderable; import com.android.launcher3.Utilities; import com.android.launcher3.icons.IconNormalizer; @@ -339,6 +340,17 @@ public class TaskbarOverflowView extends FrameLayout implements Reorderable { } } + /** + * @return Tooltip to be used for the taskbar overflow view - returns null if the view should + * not have a tooltip. + */ + public String getTextForTooltipPopup() { + if (mIsActive) { + return null; + } + return getResources().getString(R.string.taskbar_overflow_a11y_title); + } + /** * Returns the view's state (whether it shows a set of app icons or a leave-behind circle). */ diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java index 3f5e425688..25d320d55f 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java @@ -363,6 +363,9 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar mControllerCallbacks.getOverflowOnClickListener()); mTaskbarOverflowView.setOnLongClickListener( mControllerCallbacks.getOverflowOnLongClickListener()); + if (enableCursorHoverStates()) { + setHoverListenerForIcon(mTaskbarOverflowView); + } } if (ENABLE_TASKBAR_OVERFLOW.isTrue()) { diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarOverflowTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarOverflowTest.kt index 0d94a6f869..7485b3080b 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarOverflowTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/TaskbarOverflowTest.kt @@ -369,6 +369,8 @@ class TaskbarOverflowTest { createDesktopTask(createdTasks) assertThat(taskbarOverflowIconIndex).isEqualTo(initialIconCount) + assertThat(getOverflowIconTooltipText()).isEqualTo("Other recent apps") + tapOverflowIcon() // Keyboard quick switch view is shown only after list of recent task is asynchronously // retrieved from the recents model. @@ -377,9 +379,11 @@ class TaskbarOverflowTest { assertThat(getOnUiThread { keyboardQuickSwitchController.isShownFromTaskbar }).isTrue() assertThat(getOnUiThread { keyboardQuickSwitchController.shownTaskIds() }) .containsExactlyElementsIn(0.. Date: Wed, 4 Jun 2025 22:54:57 +0000 Subject: [PATCH 13/14] Move logic for stable scale factor to DisplayController When selecting grid size to use for desktop, size breakpoints are compared to the display dimensions with "stable" device density. Expose the scale factor that needs to be applied to dimensions provided in spec via DisplayController::Info, so it can be more easily faked in tests. Bug: 375643744 Test: atest DeviceProfileDumpTest Flag: com.android.launcher3.enable_scalability_for_desktop_experience Change-Id: I836430cc052f72c0f89b6cdd5ab5309a3482d94e --- .../quickstep/util/TaskViewSimulatorTest.java | 2 +- .../OrientationTouchTransformerTest.java | 3 +- .../launcher3/InvariantDeviceProfile.java | 31 ++++++++++------- .../launcher3/util/DisplayController.java | 21 +++++++++--- .../launcher3/AbstractDeviceProfileTest.kt | 33 ++++++++++++++++++- 5 files changed, 70 insertions(+), 20 deletions(-) diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/util/TaskViewSimulatorTest.java b/quickstep/tests/multivalentTests/src/com/android/quickstep/util/TaskViewSimulatorTest.java index 190a5b2d10..060f13f1e2 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/util/TaskViewSimulatorTest.java +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/util/TaskViewSimulatorTest.java @@ -202,7 +202,7 @@ public class TaskViewSimulatorTest { Context configurationContext = app.createConfigurationContext(configuration); DisplayController.Info info = new Info( - configurationContext, false, wmProxy, perDisplayBoundsCache); + configurationContext, false, wmProxy, perDisplayBoundsCache, mDensityDpi); when(mockController.getInfo()).thenReturn(info); mDeviceProfile = InvariantDeviceProfile.INSTANCE.get(app) diff --git a/quickstep/tests/src/com/android/quickstep/OrientationTouchTransformerTest.java b/quickstep/tests/src/com/android/quickstep/OrientationTouchTransformerTest.java index 82408aa5b8..cd8dd6e00c 100644 --- a/quickstep/tests/src/com/android/quickstep/OrientationTouchTransformerTest.java +++ b/quickstep/tests/src/com/android/quickstep/OrientationTouchTransformerTest.java @@ -339,7 +339,8 @@ public class OrientationTouchTransformerTest { ArrayMap> internalDisplayBounds = new ArrayMap<>(); doReturn(internalDisplayBounds).when(wmProxy).estimateInternalDisplayBounds(any()); return new DisplayController.Info( - getApplicationContext(), false, wmProxy, new ArrayMap<>()); + getApplicationContext(), false, wmProxy, new ArrayMap<>(), + DisplayMetrics.DENSITY_DEFAULT); } private float generateTouchRegionHeight(Size screenSize, int rotation) { diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index 53c8bf11de..7b186f930c 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -635,6 +635,10 @@ public class InvariantDeviceProfile { // the change in display size changes the grid size. boolean matchAgainstDefaultDpSize = displayInfo.getDeviceType() == TYPE_DESKTOP && enableScalabilityForDesktopExperience(); + float stableDensityScale = + matchAgainstDefaultDpSize + ? displayInfo.getStableDensityScaleFactor() : 1.0f; + try (XmlResourceParser parser = resourceHelper.getXml()) { final int depth = parser.getDepth(); int type; @@ -643,7 +647,7 @@ public class InvariantDeviceProfile { if ((type == XmlPullParser.START_TAG) && "GridSize".equals(parser.getName())) { gridSizes.add(new GridSize(context, Xml.asAttributeSet(parser), - matchAgainstDefaultDpSize)); + stableDensityScale)); } } } catch (IOException | XmlPullParserException e) { @@ -660,6 +664,12 @@ public class InvariantDeviceProfile { Info displayInfo) { ArrayList allAppsSizes = new ArrayList<>(); + boolean matchAgainstDefaultDpSize = displayInfo.getDeviceType() == TYPE_DESKTOP + && enableScalabilityForDesktopExperience(); + float stableDensityScale = + matchAgainstDefaultDpSize + ? displayInfo.getStableDensityScaleFactor() : 1.0f; + try (XmlResourceParser parser = resourceHelper.getXml()) { final int depth = parser.getDepth(); int type; @@ -667,7 +677,8 @@ public class InvariantDeviceProfile { || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if ((type == XmlPullParser.START_TAG) && "AllAppsSize".equals(parser.getName())) { - allAppsSizes.add(new AllAppsSize(context, Xml.asAttributeSet(parser))); + allAppsSizes.add(new AllAppsSize(context, Xml.asAttributeSet(parser), + stableDensityScale)); } } } catch (IOException | XmlPullParserException e) { @@ -1352,20 +1363,16 @@ public class InvariantDeviceProfile { final String mDbFile; final int mDefaultLayoutId; - GridSize(Context context, AttributeSet attrs, boolean matchAgainstDefaultDpSize) { + GridSize(Context context, AttributeSet attrs, float stableDensityScale) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridSize); mNumRows = (int) a.getFloat(R.styleable.GridSize_numGridRows, 0); mNumColumns = (int) a.getFloat(R.styleable.GridSize_numGridColumns, 0); - float defaultScale = - matchAgainstDefaultDpSize - ? (float) DisplayMetrics.DENSITY_DEVICE_STABLE - / DisplayMetrics.DENSITY_DEFAULT - : 1.0f; - mMinDeviceWidthPx = a.getInt(R.styleable.GridSize_minDeviceWidthPx, 0) * defaultScale; + mMinDeviceWidthPx = a.getInt(R.styleable.GridSize_minDeviceWidthPx, 0) + * stableDensityScale; mMinDeviceHeightPx = a.getInt(R.styleable.GridSize_minDeviceHeightPx, 0) - * defaultScale; + * stableDensityScale; mDbFile = a.getString(R.styleable.GridSize_dbFile); mDefaultLayoutId = a.getResourceId( @@ -1389,12 +1396,12 @@ public class InvariantDeviceProfile { // The minimum device pixel width to which the spec can be applied. final float mMinDeviceWidthPx; - AllAppsSize(Context context, AttributeSet attrs) { + AllAppsSize(Context context, AttributeSet attrs, float stableDensityScale) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AllAppsSize); mAlignWithWorkspaceRow = a.getInt(R.styleable.AllAppsSize_alignWithWorkspaceRow, -1); mMinDeviceWidthPx = a.getFloat(R.styleable.AllAppsSize_minDeviceWidthDp, 0) - * DisplayMetrics.DENSITY_DEVICE_STABLE / DisplayMetrics.DENSITY_DEFAULT; + * stableDensityScale; a.recycle(); } diff --git a/src/com/android/launcher3/util/DisplayController.java b/src/com/android/launcher3/util/DisplayController.java index ba5c996ee3..60c65e586b 100644 --- a/src/com/android/launcher3/util/DisplayController.java +++ b/src/com/android/launcher3/util/DisplayController.java @@ -42,6 +42,7 @@ import android.graphics.Rect; import android.hardware.display.DisplayManager; import android.util.ArrayMap; import android.util.ArraySet; +import android.util.DisplayMetrics; import android.util.Log; import android.util.SparseArray; import android.view.Display; @@ -435,13 +436,14 @@ public class DisplayController implements DesktopVisibilityListener { private Info getNewInfo(Info oldInfo, Context displayInfoContext) { Info newInfo = new Info(displayInfoContext, mIsDesktopFormFactor, mWMProxy, - oldInfo.mPerDisplayBounds); + oldInfo.mPerDisplayBounds, DisplayMetrics.DENSITY_DEVICE_STABLE); if (newInfo.densityDpi != oldInfo.densityDpi || newInfo.fontScale != oldInfo.fontScale || newInfo.getNavigationMode() != oldInfo.getNavigationMode()) { // Cache may not be valid anymore, recreate without cache newInfo = new Info(displayInfoContext, mIsDesktopFormFactor, mWMProxy, - mWMProxy.estimateInternalDisplayBounds(displayInfoContext)); + mWMProxy.estimateInternalDisplayBounds(displayInfoContext), + DisplayMetrics.DENSITY_DEVICE_STABLE); } return newInfo; } @@ -479,7 +481,8 @@ public class DisplayController implements DesktopVisibilityListener { } Context windowContext = mAppContext.createWindowContext(display, TYPE_APPLICATION, null); Info info = new Info(windowContext, mIsDesktopFormFactor, mWMProxy, - mWMProxy.estimateInternalDisplayBounds(windowContext)); + mWMProxy.estimateInternalDisplayBounds(windowContext), + DisplayMetrics.DENSITY_DEVICE_STABLE); perDisplayInfo = new PerDisplayInfo(displayId, windowContext, info); mPerDisplayInfo.put(displayId, perDisplayInfo); return perDisplayInfo; @@ -508,6 +511,7 @@ public class DisplayController implements DesktopVisibilityListener { // Configuration property public final float fontScale; private final int densityDpi; + private final float mStableDensityScaleFactor; private final NavigationMode navigationMode; private final PortraitSize mScreenSizeDp; @@ -534,14 +538,16 @@ public class DisplayController implements DesktopVisibilityListener { this(displayInfoContext, enableScalabilityForDesktopExperience() && displayInfoContext.getResources().getBoolean( R.bool.desktop_form_factor), - new WindowManagerProxy(), new ArrayMap<>()); + new WindowManagerProxy(), new ArrayMap<>(), + DisplayMetrics.DENSITY_DEVICE_STABLE); } // Used for testing public Info(Context displayInfoContext, boolean isDesktopFormFactor, WindowManagerProxy wmProxy, - Map> perDisplayBoundsCache) { + Map> perDisplayBoundsCache, + int defaultDensityDpi) { CachedDisplayInfo displayInfo = wmProxy.getDisplayInfo(displayInfoContext); normalizedDisplayInfo = displayInfo.normalize(wmProxy); rotation = displayInfo.rotation; @@ -551,6 +557,7 @@ public class DisplayController implements DesktopVisibilityListener { Configuration config = displayInfoContext.getResources().getConfiguration(); fontScale = config.fontScale; densityDpi = config.densityDpi; + mStableDensityScaleFactor = (float) defaultDensityDpi / DisplayMetrics.DENSITY_DEFAULT; mScreenSizeDp = new PortraitSize(config.screenHeightDp, config.screenWidthDp); navigationMode = wmProxy.getNavigationMode(displayInfoContext); mIsNightModeActive = config.isNightModeActive(); @@ -681,6 +688,10 @@ public class DisplayController implements DesktopVisibilityListener { return densityDpi; } + public float getStableDensityScaleFactor() { + return mStableDensityScaleFactor; + } + public @DeviceType int getDeviceType() { if (mIsDesktopFormFactor) { return TYPE_DESKTOP; diff --git a/tests/multivalentTests/src/com/android/launcher3/AbstractDeviceProfileTest.kt b/tests/multivalentTests/src/com/android/launcher3/AbstractDeviceProfileTest.kt index 65d55e203f..d25bfeda6a 100644 --- a/tests/multivalentTests/src/com/android/launcher3/AbstractDeviceProfileTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/AbstractDeviceProfileTest.kt @@ -173,6 +173,28 @@ abstract class AbstractDeviceProfileTest { ) } + protected fun initializeVarsForDesktop( + deviceSpec: DeviceSpec, + isLandscape: Boolean = false, + isGestureMode: Boolean = true, + gridName: String? = GRID_NAME.defaultValue, + ) { + val (naturalX, naturalY) = deviceSpec.naturalSize + val windowsBounds = tabletWindowsBounds(deviceSpec, naturalX, naturalY) + val displayInfo = CachedDisplayInfo(Point(naturalX, naturalY), Surface.ROTATION_0) + val perDisplayBoundsCache = mapOf(displayInfo to windowsBounds) + + initializeCommonVars( + perDisplayBoundsCache, + displayInfo, + rotation = if (isLandscape) Surface.ROTATION_0 else Surface.ROTATION_90, + isGestureMode, + densityDpi = deviceSpec.densityDpi, + gridName = gridName, + isDesktopFormFactor = true, + ) + } + protected fun initializeVarsForTwoPanel( deviceSpecUnfolded: DeviceSpec, deviceSpecFolded: DeviceSpec, @@ -291,6 +313,7 @@ abstract class AbstractDeviceProfileTest { isGestureMode: Boolean = true, densityDpi: Int, isFixedLandscape: Boolean = false, + isDesktopFormFactor: Boolean = false, gridName: String? = GRID_NAME.defaultValue, ) { setFlagsRule.setFlags(true, Flags.FLAG_ENABLE_TWOLINE_TOGGLE) @@ -341,7 +364,15 @@ abstract class AbstractDeviceProfileTest { } val info = - spy(DisplayController.Info(context, false, windowManagerProxy, perDisplayBoundsCache)) + spy( + DisplayController.Info( + context, + isDesktopFormFactor, + windowManagerProxy, + perDisplayBoundsCache, + densityDpi, + ) + ) whenever(displayController.info).thenReturn(info) whenever(info.isTransientTaskbar).thenReturn(isGestureMode) } From 8f29707aeeb3e0209700b805c35a22ba0a9375d5 Mon Sep 17 00:00:00 2001 From: Vinay Joglekar Date: Thu, 5 Jun 2025 13:20:56 +0100 Subject: [PATCH 14/14] Fix app tile blur when clicked on recents button rapidly. When we tap on recents, setActivityStarted set to true where setBaseSurface is called with launcher surface. When app is opened setActivityStarted is false and setBaseSurface is set to null. In subsequent calls, between where call to setBaseSurface with launcher is skipped. This causes due to race condition between removeOnDrawListener which is "asynchronously" posted from onLauncherDraw and addOnDrawListener. This makes addOnDrawListener not to get properly added. Hence mBaseSurface remains null and we do not get chance to set the blur to launcher layer to 0 and then reparent/relayer blur behind live tile. Hence blur is still over launcher layer which makes live tile blur. Added boolean that makes async removeOnDrawListener in onLauncherDraw cancellable. Fix: 387428198 Test: Rapidly tap on recents button Flag: com.android.launcher3.enable_overview_background_wallpaper_blur Change-Id: I5ed2ec198563d9edb181a723c9db47ecfe500c5d --- .../launcher3/statehandlers/DepthController.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/quickstep/src/com/android/launcher3/statehandlers/DepthController.java b/quickstep/src/com/android/launcher3/statehandlers/DepthController.java index 160344e172..8a2eb3aa05 100644 --- a/quickstep/src/com/android/launcher3/statehandlers/DepthController.java +++ b/quickstep/src/com/android/launcher3/statehandlers/DepthController.java @@ -63,6 +63,7 @@ public class DepthController extends BaseDepthController implements StateHandler // Ensure {@link mOnDrawListener} is added only once to avoid spamming DragLayer's mRunQueue // via {@link View#post(Runnable)} private boolean mIsOnDrawListenerAdded = false; + private boolean mRemoveOnDrawListenerCancelled = false; public DepthController(QuickstepLauncher launcher) { super(launcher); @@ -72,7 +73,12 @@ public class DepthController extends BaseDepthController implements StateHandler View view = mLauncher.getDragLayer(); ViewRootImpl viewRootImpl = view.getViewRootImpl(); setBaseSurface(viewRootImpl != null ? viewRootImpl.getSurfaceControl() : null); - view.post(this::removeOnDrawListener); + mRemoveOnDrawListenerCancelled = false; + view.post(() -> { + if (!mRemoveOnDrawListenerCancelled) { + removeOnDrawListener(); + } + }); } private void ensureDependencies() { @@ -178,6 +184,7 @@ public class DepthController extends BaseDepthController implements StateHandler } private void addOnDrawListener() { + mRemoveOnDrawListenerCancelled = true; if (mIsOnDrawListenerAdded) { return; } @@ -186,6 +193,7 @@ public class DepthController extends BaseDepthController implements StateHandler } private void removeOnDrawListener() { + mRemoveOnDrawListenerCancelled = true; if (!mIsOnDrawListenerAdded) { return; }