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/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 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/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" 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/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/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; } 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/TaskbarStashController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java index 22ff3bedbb..6fa55799c3 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; @@ -564,11 +565,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/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/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index ff0ab7c0d9..0e441ff934 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)) { @@ -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/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): 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/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. */ 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 diff --git a/quickstep/src/com/android/quickstep/views/TaskView.kt b/quickstep/src/com/android/quickstep/views/TaskView.kt index 0fb0bee2d6..b10d8a5e5c 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.kt +++ b/quickstep/src/com/android/quickstep/views/TaskView.kt @@ -970,7 +970,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) } } 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.. absSwipeUpHandler.onRecentsAnimationStart( - mRecentsAnimationController, mRecentsAnimationTargets, /* transitionInfo= */null)); + mRecentsAnimationController, mRecentsAnimationTargets, /* transitionInfo= */ null)); } protected static void runOnMainSync(Runnable runnable) { 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/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/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/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/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) } 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 { + @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.