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

Commit 6af8e649 authored by Will Leshner's avatar Will Leshner
Browse files

Add a flag to allow all widgets on communal hub by default.

Bug: 328261690
Flag: ACONFIG com.android.settingslib.flags.allow_all_widgets_on_lockscreen_by_default STAGING
Test: atest CommunalSettingsRepositoryImplTest
Change-Id: I5460c32cdb759614d83a2d2c2e07f0c93fb54e88

Change-Id: If0d468509b5b0d8d50b571d10eba1f1b54e6b46f
parent dbf45642
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -62,3 +62,10 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
  name: "allow_all_widgets_on_lockscreen_by_default"
  namespace: "systemui"
  description: "Allow all widgets on the lock screen by default."
  bug: "328261690"
}
+13 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.platform.test.annotations.EnableFlags
import android.provider.Settings
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.settingslib.flags.Flags.FLAG_ALLOW_ALL_WIDGETS_ON_LOCKSCREEN_BY_DEFAULT
import com.android.systemui.Flags.FLAG_COMMUNAL_HUB
import com.android.systemui.SysuiTestCase
import com.android.systemui.broadcast.broadcastDispatcher
@@ -202,6 +203,18 @@ class CommunalSettingsRepositoryImplTest : SysuiTestCase() {
                .isEqualTo(AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD)
        }

    @EnableFlags(FLAG_COMMUNAL_HUB, FLAG_ALLOW_ALL_WIDGETS_ON_LOCKSCREEN_BY_DEFAULT)
    @Test
    fun hubShowsAllWidgetsByDefaultWhenFlagEnabled() =
        testScope.runTest {
            val setting by collectLastValue(underTest.getWidgetCategories(PRIMARY_USER))
            assertThat(setting?.categories)
                .isEqualTo(
                    AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD +
                        AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN
                )
        }

    private fun setKeyguardFeaturesDisabled(user: UserInfo, disabledFlags: Int) {
        whenever(kosmos.devicePolicyManager.getKeyguardDisabledFeatures(nullable(), eq(user.id)))
            .thenReturn(disabledFlags)
+12 −4
Original line number Diff line number Diff line
@@ -17,15 +17,23 @@
package com.android.systemui.communal.data.model

import android.appwidget.AppWidgetProviderInfo
import com.android.settingslib.flags.Flags.allowAllWidgetsOnLockscreenByDefault

/**
 * 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
) {
value class CommunalWidgetCategories(val categories: Int = defaultCategories) {
    fun contains(category: Int) = (categories and category) == category

    companion object {
        val defaultCategories: Int
            get() {
                return AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD or
                    if (allowAllWidgetsOnLockscreenByDefault())
                        AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN
                    else 0
            }
    }
}
+1 −3
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ 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 android.provider.Settings
@@ -108,10 +107,9 @@ constructor(
            .onStart { emit(Unit) }
            .map {
                CommunalWidgetCategories(
                    // The default is to show only keyguard widgets.
                    secureSettings.getIntForUser(
                        GLANCEABLE_HUB_CONTENT_SETTING,
                        AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD,
                        CommunalWidgetCategories.defaultCategories,
                        user.id
                    )
                )
+1 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ constructor(
                scope = bgScope,
                // Start this eagerly since the value can be accessed synchronously.
                started = SharingStarted.Eagerly,
                initialValue = CommunalWidgetCategories().categories
                initialValue = CommunalWidgetCategories.defaultCategories
            )

    private val workProfileUserInfoCallbackFlow: Flow<UserInfo?> = conflatedCallbackFlow {