diff options
2 files changed, 33 insertions, 8 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/CommunalWidgetHostTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/CommunalWidgetHostTest.kt index 12611cbd8c63..88f5e1b85840 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/CommunalWidgetHostTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/CommunalWidgetHostTest.kt @@ -17,8 +17,10 @@ package com.android.systemui.communal.widgets import android.appwidget.AppWidgetManager +import android.appwidget.AppWidgetProviderInfo import android.content.ComponentName import android.content.pm.UserInfo +import android.os.Bundle import android.os.UserHandle import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest @@ -33,8 +35,8 @@ import com.android.systemui.user.data.repository.fakeUserRepository import com.android.systemui.user.domain.interactor.SelectedUserInteractor import com.android.systemui.user.domain.interactor.selectedUserInteractor import com.android.systemui.util.mockito.any -import com.android.systemui.util.mockito.nullable import com.android.systemui.util.mockito.whenever +import com.android.systemui.util.mockito.withArgCaptor import com.google.common.truth.Truth.assertThat import java.util.Optional import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -43,6 +45,7 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import org.mockito.ArgumentMatchers.eq import org.mockito.Mock import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations @@ -91,7 +94,7 @@ class CommunalWidgetHostTest : SysuiTestCase() { any<Int>(), any<UserHandle>(), any<ComponentName>(), - nullable() + any<Bundle>(), ) ) .thenReturn(true) @@ -100,8 +103,14 @@ class CommunalWidgetHostTest : SysuiTestCase() { val result = underTest.allocateIdAndBindWidget(provider) verify(appWidgetHost).allocateAppWidgetId() - verify(appWidgetManager).bindAppWidgetIdIfAllowed(widgetId, user, provider, null) + val bundle = + withArgCaptor<Bundle> { + verify(appWidgetManager) + .bindAppWidgetIdIfAllowed(eq(widgetId), eq(user), eq(provider), capture()) + } assertThat(result).isEqualTo(widgetId) + assertThat(bundle.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY)) + .isEqualTo(AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) } @Test @@ -117,7 +126,7 @@ class CommunalWidgetHostTest : SysuiTestCase() { any<Int>(), any<UserHandle>(), any<ComponentName>(), - nullable() + any<Bundle>() ) ) .thenReturn(true) @@ -126,8 +135,14 @@ class CommunalWidgetHostTest : SysuiTestCase() { val result = underTest.allocateIdAndBindWidget(provider, user) verify(appWidgetHost).allocateAppWidgetId() - verify(appWidgetManager).bindAppWidgetIdIfAllowed(widgetId, user, provider, null) + val bundle = + withArgCaptor<Bundle> { + verify(appWidgetManager) + .bindAppWidgetIdIfAllowed(eq(widgetId), eq(user), eq(provider), capture()) + } assertThat(result).isEqualTo(widgetId) + assertThat(bundle.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY)) + .isEqualTo(AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) } @Test @@ -144,14 +159,15 @@ class CommunalWidgetHostTest : SysuiTestCase() { any<Int>(), any<UserHandle>(), any<ComponentName>(), - nullable() + any<Bundle>() ) ) .thenReturn(false) val result = underTest.allocateIdAndBindWidget(provider, user) verify(appWidgetHost).allocateAppWidgetId() - verify(appWidgetManager).bindAppWidgetIdIfAllowed(widgetId, user, provider, null) + verify(appWidgetManager) + .bindAppWidgetIdIfAllowed(eq(widgetId), eq(user), eq(provider), any()) verify(appWidgetHost).deleteAppWidgetId(widgetId) assertThat(result).isNull() } diff --git a/packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalWidgetHost.kt b/packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalWidgetHost.kt index 080dbedcb350..93e2b37cfe87 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalWidgetHost.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalWidgetHost.kt @@ -21,6 +21,7 @@ import android.appwidget.AppWidgetProviderInfo import android.appwidget.AppWidgetProviderInfo.WIDGET_FEATURE_CONFIGURATION_OPTIONAL import android.appwidget.AppWidgetProviderInfo.WIDGET_FEATURE_RECONFIGURABLE import android.content.ComponentName +import android.os.Bundle import android.os.UserHandle import com.android.systemui.log.LogBuffer import com.android.systemui.log.core.Logger @@ -56,6 +57,7 @@ constructor( return widgetInfo.configure != null && !configurationOptional } } + private val logger = Logger(logBuffer, TAG) /** @@ -84,9 +86,16 @@ constructor( private fun bindWidget(widgetId: Int, user: UserHandle, provider: ComponentName): Boolean { if (appWidgetManager.isPresent) { + val options = + Bundle().apply { + putInt( + AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, + AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD, + ) + } return appWidgetManager .get() - .bindAppWidgetIdIfAllowed(widgetId, user, provider, /* options */ null) + .bindAppWidgetIdIfAllowed(widgetId, user, provider, options) } return false } |