Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6e6f2cdc authored by Lucas Silva's avatar Lucas Silva
Browse files

Send keyguard category to widgets in GH

This informs widgets that they are being shown on the keyguard, so they
can adjust accordingly.

Fixes: 324600993
Test: atest SystemUiRoboTest:CommunalWidgetHostTest
Flag: ACONFIG com.android.systemui.communal_hub STAGING
Change-Id: Ied8fc683e780d3fc409b352f0a36b22d403eaa5c
parent ddb58a79
Loading
Loading
Loading
Loading
+23 −7
Original line number Diff line number Diff line
@@ -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()
        }
+10 −1
Original line number Diff line number Diff line
@@ -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
    }