diff options
| author | 2024-02-07 14:02:18 -0800 | |
|---|---|---|
| committer | 2024-02-15 12:07:31 -0800 | |
| commit | 9486146e511e4a9fc53dbb08b0f00702443ccc9b (patch) | |
| tree | 319fbc5216890866b56ab0bed3814572137765d9 | |
| parent | 833cf624a1e4202a05677deae8f5b98423bb68fd (diff) | |
Implement communal widget filtering based on category filter setting.
A new setting in Settings allows filtering communal widgets to either
"keyguard" or "all". This change uses that setting to pass the correct
filter key to Launcher when showing the widget picker activity.
Bug: 314804170
Test: atest SystemUiRoboTests
Flag: ACONFIG com.android.systemui.communal_hub DEVELOPMENT
Change-Id: I2d6cd4bc783ebd4f2b69a750e6f7276751830517
7 files changed, 107 insertions, 0 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/data/repository/CommunalSettingsRepositoryImplTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/data/repository/CommunalSettingsRepositoryImplTest.kt index 0aca16d9aeaa..6b2831991416 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/data/repository/CommunalSettingsRepositoryImplTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/data/repository/CommunalSettingsRepositoryImplTest.kt @@ -20,6 +20,7 @@ import android.app.admin.DevicePolicyManager import android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_FEATURES_NONE import android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_WIDGETS_ALL import android.app.admin.devicePolicyManager +import android.appwidget.AppWidgetProviderInfo import android.content.Intent import android.content.pm.UserInfo import android.platform.test.annotations.DisableFlags @@ -136,6 +137,29 @@ class CommunalSettingsRepositoryImplTest : SysuiTestCase() { ) } + @EnableFlags(FLAG_COMMUNAL_HUB) + @Test + fun hubShowsWidgetCategoriesSetByUser() = + testScope.runTest { + kosmos.fakeSettings.putIntForUser( + CommunalSettingsRepositoryImpl.GLANCEABLE_HUB_CONTENT_SETTING, + AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN, + PRIMARY_USER.id + ) + val setting by collectLastValue(underTest.getWidgetCategories(PRIMARY_USER)) + assertThat(setting?.categories) + .isEqualTo(AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN) + } + + @EnableFlags(FLAG_COMMUNAL_HUB) + @Test + fun hubShowsKeyguardWidgetsByDefault() = + testScope.runTest { + val setting by collectLastValue(underTest.getWidgetCategories(PRIMARY_USER)) + assertThat(setting?.categories) + .isEqualTo(AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) + } + private fun setKeyguardFeaturesDisabled(user: UserInfo, disabledFlags: Int) { whenever(kosmos.devicePolicyManager.getKeyguardDisabledFeatures(nullable(), eq(user.id))) .thenReturn(disabledFlags) diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt index cf727cf5e180..ddb8582913e6 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt @@ -30,6 +30,7 @@ import com.android.systemui.communal.data.repository.fakeCommunalMediaRepository import com.android.systemui.communal.data.repository.fakeCommunalTutorialRepository import com.android.systemui.communal.data.repository.fakeCommunalWidgetRepository import com.android.systemui.communal.domain.interactor.communalInteractor +import com.android.systemui.communal.domain.interactor.communalSettingsInteractor import com.android.systemui.communal.domain.model.CommunalContentModel import com.android.systemui.communal.shared.log.CommunalUiEvent import com.android.systemui.communal.shared.model.CommunalWidgetContentModel @@ -81,6 +82,7 @@ class CommunalEditModeViewModelTest : SysuiTestCase() { underTest = CommunalEditModeViewModel( kosmos.communalInteractor, + kosmos.communalSettingsInteractor, mediaHost, uiEventLogger, logcatLogBuffer("CommunalEditModeViewModelTest"), diff --git a/packages/SystemUI/src/com/android/systemui/communal/data/model/CommunalWidgetCategories.kt b/packages/SystemUI/src/com/android/systemui/communal/data/model/CommunalWidgetCategories.kt new file mode 100644 index 000000000000..03f54c8b25d7 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/communal/data/model/CommunalWidgetCategories.kt @@ -0,0 +1,31 @@ +/* + * 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.data.model + +import android.appwidget.AppWidgetProviderInfo + +/** + * The widget categories to display on communal hub (where categories is a bitfield with values that + * match those in {@link AppWidgetProviderInfo}). + */ +@JvmInline +value class CommunalWidgetCategories( + // The default is keyguard widgets. + val categories: Int = AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD +) { + fun contains(category: Int) = (categories and category) == category +} diff --git a/packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalSettingsRepository.kt b/packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalSettingsRepository.kt index 201b04927ea3..7c65d21e2814 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalSettingsRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalSettingsRepository.kt @@ -18,11 +18,13 @@ package com.android.systemui.communal.data.repository import android.app.admin.DevicePolicyManager import android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_WIDGETS_ALL +import android.appwidget.AppWidgetProviderInfo import android.content.IntentFilter import android.content.pm.UserInfo import com.android.systemui.Flags.communalHub import com.android.systemui.broadcast.BroadcastDispatcher import com.android.systemui.communal.data.model.CommunalEnabledState +import com.android.systemui.communal.data.model.CommunalWidgetCategories import com.android.systemui.communal.data.model.DisabledReason import com.android.systemui.communal.data.model.DisabledReason.DISABLED_REASON_DEVICE_POLICY import com.android.systemui.communal.data.model.DisabledReason.DISABLED_REASON_FLAG @@ -48,6 +50,12 @@ import kotlinx.coroutines.flow.onStart interface CommunalSettingsRepository { /** A [CommunalEnabledState] for the specified user. */ fun getEnabledState(user: UserInfo): Flow<CommunalEnabledState> + + /** + * A flow that reports the widget categories to show on the hub as selected by the user in + * Settings. + */ + fun getWidgetCategories(user: UserInfo): Flow<CommunalWidgetCategories> } @SysUISingleton @@ -89,6 +97,23 @@ constructor( .flowOn(bgDispatcher) } + override fun getWidgetCategories(user: UserInfo): Flow<CommunalWidgetCategories> = + secureSettings + .observerFlow(userId = user.id, names = arrayOf(GLANCEABLE_HUB_CONTENT_SETTING)) + // Force an update + .onStart { emit(Unit) } + .map { + CommunalWidgetCategories( + // The default is to show only keyguard widgets. + secureSettings.getIntForUser( + GLANCEABLE_HUB_CONTENT_SETTING, + AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD, + user.id + ) + ) + } + .flowOn(bgDispatcher) + private fun getEnabledByUser(user: UserInfo): Flow<Boolean> = secureSettings .observerFlow(userId = user.id, names = arrayOf(GLANCEABLE_HUB_ENABLED)) @@ -114,6 +139,7 @@ constructor( companion object { const val GLANCEABLE_HUB_ENABLED = "glanceable_hub_enabled" + const val GLANCEABLE_HUB_CONTENT_SETTING = "glanceable_hub_content_setting" private const val ENABLED_SETTING_DEFAULT = 1 } } diff --git a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalSettingsInteractor.kt b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalSettingsInteractor.kt index 0b096ce67fc5..20f60b79c784 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalSettingsInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalSettingsInteractor.kt @@ -17,6 +17,7 @@ package com.android.systemui.communal.domain.interactor import com.android.systemui.communal.data.model.CommunalEnabledState +import com.android.systemui.communal.data.model.CommunalWidgetCategories import com.android.systemui.communal.data.repository.CommunalSettingsRepository import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Background @@ -55,4 +56,16 @@ constructor( .map { model -> model.enabled } // Start this eagerly since the value is accessed synchronously in many places. .stateIn(scope = bgScope, started = SharingStarted.Eagerly, initialValue = false) + + /** What widget categories to show on the hub. */ + val communalWidgetCategories: StateFlow<Int> = + userInteractor.selectedUserInfo + .flatMapLatest { user -> repository.getWidgetCategories(user) } + .map { categories -> categories.categories } + .stateIn( + scope = bgScope, + // Start this eagerly since the value can be accessed synchronously. + started = SharingStarted.Eagerly, + initialValue = CommunalWidgetCategories().categories + ) } diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt index 0b355cc10db5..efbb11e824c9 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt @@ -18,6 +18,7 @@ package com.android.systemui.communal.ui.viewmodel import com.android.internal.logging.UiEventLogger import com.android.systemui.communal.domain.interactor.CommunalInteractor +import com.android.systemui.communal.domain.interactor.CommunalSettingsInteractor import com.android.systemui.communal.domain.model.CommunalContentModel import com.android.systemui.communal.shared.log.CommunalUiEvent import com.android.systemui.dagger.SysUISingleton @@ -40,6 +41,7 @@ class CommunalEditModeViewModel @Inject constructor( private val communalInteractor: CommunalInteractor, + private val communalSettingsInteractor: CommunalSettingsInteractor, @Named(MediaModule.COMMUNAL_HUB) mediaHost: MediaHost, private val uiEventLogger: UiEventLogger, @CommunalLog logBuffer: LogBuffer, @@ -84,6 +86,10 @@ constructor( uiEventLogger.log(CommunalUiEvent.COMMUNAL_HUB_REORDER_WIDGET_CANCEL) } + /** Returns the widget categories to show on communal hub. */ + val getCommunalWidgetCategories: Int + get() = communalSettingsInteractor.communalWidgetCategories.value + /** Sets whether edit mode is currently open */ fun setEditModeOpen(isOpen: Boolean) = communalInteractor.setEditModeOpen(isOpen) } diff --git a/packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt b/packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt index 337a98a30a51..a5a390d7683b 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt @@ -16,6 +16,7 @@ package com.android.systemui.communal.widgets +import android.appwidget.AppWidgetManager import android.content.Intent import android.content.pm.PackageManager import android.os.Bundle @@ -137,6 +138,10 @@ constructor( R.dimen.communal_widget_picker_desired_height ) ) + putExtra( + AppWidgetManager.EXTRA_CATEGORY_FILTER, + communalViewModel.getCommunalWidgetCategories + ) } ) } catch (e: Exception) { |