Loading packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +0 −7 Original line number Diff line number Diff line Loading @@ -624,17 +624,10 @@ private fun WidgetContent( modifier = modifier.align(Alignment.Center).allowGestures(allowed = !viewModel.isEditMode), factory = { context -> // The AppWidgetHostView will inherit the interaction handler from the // AppWidgetHost. So set the interaction handler here before creating the view, and // then clear it after the view is created. This is a workaround due to the fact // that the interaction handler cannot be specified when creating the view, // and there are race conditions if it is set after the view is created. model.appWidgetHost.setInteractionHandler(viewModel.getInteractionHandler()) val view = model.appWidgetHost .createViewForCommunal(context, model.appWidgetId, model.providerInfo) .apply { updateAppWidgetSize(Bundle.EMPTY, listOf(size)) } model.appWidgetHost.setInteractionHandler(null) // Remove the extra padding applied to AppWidgetHostView to allow widgets to // occupy the entire box. The added padding is now adjusted to leave only sufficient // space for displaying the outline around the box when the widget is selected. Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/ui/widgets/CommunalAppWidgetHostTest.kt +27 −19 Original line number Diff line number Diff line Loading @@ -16,35 +16,41 @@ package com.android.systemui.communal.ui.widgets import android.testing.TestableLooper import android.testing.TestableLooper.RunWithLooper import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.communal.widgets.CommunalAppWidgetHost import com.android.systemui.communal.widgets.CommunalAppWidgetHostView import com.android.systemui.kosmos.testScope import com.android.systemui.testKosmos import com.android.systemui.util.mockito.mock import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @SmallTest @RunWithLooper(setAsMainLooper = true) @RunWith(AndroidJUnit4::class) class CommunalAppWidgetHostTest : SysuiTestCase() { private val kosmos = testKosmos() private val testScope = kosmos.testScope private lateinit var testableLooper: TestableLooper private lateinit var underTest: CommunalAppWidgetHost @Before fun setUp() { underTest = CommunalAppWidgetHost(context = context, hostId = 116) testableLooper = TestableLooper.get(this) underTest = CommunalAppWidgetHost( context = context, hostId = 116, interactionHandler = mock(), looper = testableLooper.looper ) } @Test fun createViewForCommunal_returnCommunalAppWidgetView() = testScope.runTest { fun createViewForCommunal_returnCommunalAppWidgetView() { val appWidgetId = 789 val view = underTest.createViewForCommunal( Loading @@ -52,6 +58,8 @@ class CommunalAppWidgetHostTest : SysuiTestCase() { appWidgetId = appWidgetId, appWidget = null ) testableLooper.processAllMessages() assertThat(view).isInstanceOf(CommunalAppWidgetHostView::class.java) assertThat(view).isNotNull() assertThat(view.appWidgetId).isEqualTo(appWidgetId) Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt +0 −15 Original line number Diff line number Diff line Loading @@ -41,7 +41,6 @@ import com.android.systemui.testKosmos import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test Loading @@ -51,7 +50,6 @@ import org.mockito.Mockito import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations @OptIn(ExperimentalCoroutinesApi::class) @SmallTest @RunWith(AndroidJUnit4::class) class CommunalEditModeViewModelTest : SysuiTestCase() { Loading Loading @@ -133,19 +131,6 @@ class CommunalEditModeViewModelTest : SysuiTestCase() { .isInstanceOf(CommunalContentModel.CtaTileInEditMode::class.java) } @Test fun interactionHandlerIgnoresClicks() { val interactionHandler = underTest.getInteractionHandler() assertThat( interactionHandler.onInteraction( /* view = */ mock(), /* pendingIntent = */ mock(), /* response = */ mock() ) ) .isEqualTo(false) } @Test fun reorderWidget_uiEventLogging_start() { underTest.onReorderWidgetStart() Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt +0 −2 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ import com.android.systemui.communal.domain.model.CommunalContentModel import com.android.systemui.communal.shared.model.CommunalWidgetContentModel import com.android.systemui.communal.ui.viewmodel.CommunalViewModel import com.android.systemui.communal.ui.viewmodel.CommunalViewModel.Companion.POPUP_AUTO_HIDE_TIMEOUT_MS import com.android.systemui.communal.widgets.WidgetInteractionHandler import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository import com.android.systemui.media.controls.ui.MediaHierarchyManager Loading Loading @@ -90,7 +89,6 @@ class CommunalViewModelTest : SysuiTestCase() { CommunalViewModel( testScope, withDeps.communalInteractor, WidgetInteractionHandler(mock()), withDeps.tutorialInteractor, mediaHost, ) Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/WidgetInteractionHandlerTest.kt 0 → 100644 +87 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 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.systemui.communal.widgets import android.app.PendingIntent import android.content.Intent import android.view.View import android.widget.FrameLayout import android.widget.RemoteViews.RemoteResponse import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.plugins.ActivityStarter import com.android.systemui.util.mockito.eq import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.isNull import org.mockito.Mockito.notNull import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations @SmallTest @RunWith(AndroidJUnit4::class) class WidgetInteractionHandlerTest : SysuiTestCase() { @Mock private lateinit var activityStarter: ActivityStarter private lateinit var underTest: WidgetInteractionHandler private val testIntent = PendingIntent.getActivity( context, /* requestCode = */ 0, Intent("action"), PendingIntent.FLAG_IMMUTABLE ) private val testResponse = RemoteResponse.fromPendingIntent(testIntent) @Before fun setUp() { MockitoAnnotations.initMocks(this) underTest = WidgetInteractionHandler(activityStarter) } @Test fun launchAnimatorIsUsedForWidgetView() { val parent = FrameLayout(context) val view = CommunalAppWidgetHostView(context) parent.addView(view) underTest.onInteraction(view, testIntent, testResponse) verify(activityStarter) .startPendingIntentMaybeDismissingKeyguard( eq(testIntent), isNull(), notNull(), ) } @Test fun launchAnimatorIsNotUsedForRegularView() { val parent = FrameLayout(context) val view = View(context) parent.addView(view) underTest.onInteraction(view, testIntent, testResponse) verify(activityStarter) .startPendingIntentMaybeDismissingKeyguard(eq(testIntent), isNull(), isNull()) } } Loading
packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +0 −7 Original line number Diff line number Diff line Loading @@ -624,17 +624,10 @@ private fun WidgetContent( modifier = modifier.align(Alignment.Center).allowGestures(allowed = !viewModel.isEditMode), factory = { context -> // The AppWidgetHostView will inherit the interaction handler from the // AppWidgetHost. So set the interaction handler here before creating the view, and // then clear it after the view is created. This is a workaround due to the fact // that the interaction handler cannot be specified when creating the view, // and there are race conditions if it is set after the view is created. model.appWidgetHost.setInteractionHandler(viewModel.getInteractionHandler()) val view = model.appWidgetHost .createViewForCommunal(context, model.appWidgetId, model.providerInfo) .apply { updateAppWidgetSize(Bundle.EMPTY, listOf(size)) } model.appWidgetHost.setInteractionHandler(null) // Remove the extra padding applied to AppWidgetHostView to allow widgets to // occupy the entire box. The added padding is now adjusted to leave only sufficient // space for displaying the outline around the box when the widget is selected. Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/ui/widgets/CommunalAppWidgetHostTest.kt +27 −19 Original line number Diff line number Diff line Loading @@ -16,35 +16,41 @@ package com.android.systemui.communal.ui.widgets import android.testing.TestableLooper import android.testing.TestableLooper.RunWithLooper import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.communal.widgets.CommunalAppWidgetHost import com.android.systemui.communal.widgets.CommunalAppWidgetHostView import com.android.systemui.kosmos.testScope import com.android.systemui.testKosmos import com.android.systemui.util.mockito.mock import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @SmallTest @RunWithLooper(setAsMainLooper = true) @RunWith(AndroidJUnit4::class) class CommunalAppWidgetHostTest : SysuiTestCase() { private val kosmos = testKosmos() private val testScope = kosmos.testScope private lateinit var testableLooper: TestableLooper private lateinit var underTest: CommunalAppWidgetHost @Before fun setUp() { underTest = CommunalAppWidgetHost(context = context, hostId = 116) testableLooper = TestableLooper.get(this) underTest = CommunalAppWidgetHost( context = context, hostId = 116, interactionHandler = mock(), looper = testableLooper.looper ) } @Test fun createViewForCommunal_returnCommunalAppWidgetView() = testScope.runTest { fun createViewForCommunal_returnCommunalAppWidgetView() { val appWidgetId = 789 val view = underTest.createViewForCommunal( Loading @@ -52,6 +58,8 @@ class CommunalAppWidgetHostTest : SysuiTestCase() { appWidgetId = appWidgetId, appWidget = null ) testableLooper.processAllMessages() assertThat(view).isInstanceOf(CommunalAppWidgetHostView::class.java) assertThat(view).isNotNull() assertThat(view.appWidgetId).isEqualTo(appWidgetId) Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt +0 −15 Original line number Diff line number Diff line Loading @@ -41,7 +41,6 @@ import com.android.systemui.testKosmos import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test Loading @@ -51,7 +50,6 @@ import org.mockito.Mockito import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations @OptIn(ExperimentalCoroutinesApi::class) @SmallTest @RunWith(AndroidJUnit4::class) class CommunalEditModeViewModelTest : SysuiTestCase() { Loading Loading @@ -133,19 +131,6 @@ class CommunalEditModeViewModelTest : SysuiTestCase() { .isInstanceOf(CommunalContentModel.CtaTileInEditMode::class.java) } @Test fun interactionHandlerIgnoresClicks() { val interactionHandler = underTest.getInteractionHandler() assertThat( interactionHandler.onInteraction( /* view = */ mock(), /* pendingIntent = */ mock(), /* response = */ mock() ) ) .isEqualTo(false) } @Test fun reorderWidget_uiEventLogging_start() { underTest.onReorderWidgetStart() Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt +0 −2 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ import com.android.systemui.communal.domain.model.CommunalContentModel import com.android.systemui.communal.shared.model.CommunalWidgetContentModel import com.android.systemui.communal.ui.viewmodel.CommunalViewModel import com.android.systemui.communal.ui.viewmodel.CommunalViewModel.Companion.POPUP_AUTO_HIDE_TIMEOUT_MS import com.android.systemui.communal.widgets.WidgetInteractionHandler import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository import com.android.systemui.media.controls.ui.MediaHierarchyManager Loading Loading @@ -90,7 +89,6 @@ class CommunalViewModelTest : SysuiTestCase() { CommunalViewModel( testScope, withDeps.communalInteractor, WidgetInteractionHandler(mock()), withDeps.tutorialInteractor, mediaHost, ) Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/WidgetInteractionHandlerTest.kt 0 → 100644 +87 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 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.systemui.communal.widgets import android.app.PendingIntent import android.content.Intent import android.view.View import android.widget.FrameLayout import android.widget.RemoteViews.RemoteResponse import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.plugins.ActivityStarter import com.android.systemui.util.mockito.eq import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.isNull import org.mockito.Mockito.notNull import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations @SmallTest @RunWith(AndroidJUnit4::class) class WidgetInteractionHandlerTest : SysuiTestCase() { @Mock private lateinit var activityStarter: ActivityStarter private lateinit var underTest: WidgetInteractionHandler private val testIntent = PendingIntent.getActivity( context, /* requestCode = */ 0, Intent("action"), PendingIntent.FLAG_IMMUTABLE ) private val testResponse = RemoteResponse.fromPendingIntent(testIntent) @Before fun setUp() { MockitoAnnotations.initMocks(this) underTest = WidgetInteractionHandler(activityStarter) } @Test fun launchAnimatorIsUsedForWidgetView() { val parent = FrameLayout(context) val view = CommunalAppWidgetHostView(context) parent.addView(view) underTest.onInteraction(view, testIntent, testResponse) verify(activityStarter) .startPendingIntentMaybeDismissingKeyguard( eq(testIntent), isNull(), notNull(), ) } @Test fun launchAnimatorIsNotUsedForRegularView() { val parent = FrameLayout(context) val view = View(context) parent.addView(view) underTest.onInteraction(view, testIntent, testResponse) verify(activityStarter) .startPendingIntentMaybeDismissingKeyguard(eq(testIntent), isNull(), isNull()) } }