Adjust quick affordance section controller to use base flags (2/3)
The quick affordance section controller currently calls runBlocking when
initializing to query flags and check if the feature is available.
However, fragments and section controllers should be getting System UI
flags using base flags, which queries and caches the flags when a flag
is first needed. In addition, the runBlocking function is suspected to
be the cause of the reported crash within the bug.
In this CL, the quick affordance section controller, interactor &
repository are adjusted to remove the flag querying, and the flag is
read from base flags instead in the section controller.
Bug: 296856318
Bug: 290849013
Test: adjusted unit tests for this change and made sure they still pass,
verified manually that quick affordance section controller remains
Change-Id: Ic469396f4a959a339efebec7cfbaaf37f8b404e3
diff --git a/src/com/android/customization/module/DefaultCustomizationSections.java b/src/com/android/customization/module/DefaultCustomizationSections.java
index a0aef2c..460a848 100644
--- a/src/com/android/customization/module/DefaultCustomizationSections.java
+++ b/src/com/android/customization/module/DefaultCustomizationSections.java
@@ -24,7 +24,6 @@
import com.android.customization.picker.notifications.ui.viewmodel.NotificationSectionViewModel;
import com.android.customization.picker.preview.ui.section.PreviewWithClockCarouselSectionController;
import com.android.customization.picker.preview.ui.section.PreviewWithThemeSectionController;
-import com.android.customization.picker.quickaffordance.domain.interactor.KeyguardQuickAffordancePickerInteractor;
import com.android.customization.picker.quickaffordance.ui.section.KeyguardQuickAffordanceSectionController;
import com.android.customization.picker.quickaffordance.ui.viewmodel.KeyguardQuickAffordancePickerViewModel;
import com.android.customization.picker.settings.ui.section.MoreSettingsSectionController;
@@ -49,7 +48,6 @@
public final class DefaultCustomizationSections implements CustomizationSections {
private final ColorPickerViewModel.Factory mColorPickerViewModelFactory;
- private final KeyguardQuickAffordancePickerInteractor mKeyguardQuickAffordancePickerInteractor;
private final KeyguardQuickAffordancePickerViewModel.Factory
mKeyguardQuickAffordancePickerViewModelFactory;
private final NotificationSectionViewModel.Factory mNotificationSectionViewModelFactory;
@@ -63,7 +61,6 @@
public DefaultCustomizationSections(
ColorPickerViewModel.Factory colorPickerViewModelFactory,
- KeyguardQuickAffordancePickerInteractor keyguardQuickAffordancePickerInteractor,
KeyguardQuickAffordancePickerViewModel.Factory
keyguardQuickAffordancePickerViewModelFactory,
NotificationSectionViewModel.Factory notificationSectionViewModelFactory,
@@ -75,7 +72,6 @@
ThemedIconInteractor themedIconInteractor,
ColorPickerInteractor colorPickerInteractor) {
mColorPickerViewModelFactory = colorPickerViewModelFactory;
- mKeyguardQuickAffordancePickerInteractor = keyguardQuickAffordancePickerInteractor;
mKeyguardQuickAffordancePickerViewModelFactory =
keyguardQuickAffordancePickerViewModelFactory;
mNotificationSectionViewModelFactory = notificationSectionViewModelFactory;
@@ -166,7 +162,6 @@
sectionControllers.add(
new KeyguardQuickAffordanceSectionController(
sectionNavigationController,
- mKeyguardQuickAffordancePickerInteractor,
new ViewModelProvider(
activity,
mKeyguardQuickAffordancePickerViewModelFactory)
diff --git a/src/com/android/customization/module/ThemePickerInjector.kt b/src/com/android/customization/module/ThemePickerInjector.kt
index 1d16bc1..eb0b601 100644
--- a/src/com/android/customization/module/ThemePickerInjector.kt
+++ b/src/com/android/customization/module/ThemePickerInjector.kt
@@ -136,7 +136,6 @@
context = activity,
wallpaperColorsRepository = getWallpaperColorsRepository(),
),
- getKeyguardQuickAffordancePickerInteractor(activity),
getKeyguardQuickAffordancePickerViewModelFactory(activity),
NotificationSectionViewModel.Factory(
interactor = getNotificationsInteractor(activity),
@@ -256,7 +255,7 @@
val client = getKeyguardQuickAffordancePickerProviderClient(context)
val appContext = context.applicationContext
return KeyguardQuickAffordancePickerInteractor(
- KeyguardQuickAffordancePickerRepository(client, bgDispatcher),
+ KeyguardQuickAffordancePickerRepository(client),
client
) {
getKeyguardQuickAffordanceSnapshotRestorer(appContext)
diff --git a/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt b/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt
index b17af80..10473a2 100644
--- a/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt
+++ b/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt
@@ -21,11 +21,8 @@
import com.android.customization.picker.quickaffordance.shared.model.KeyguardQuickAffordancePickerSelectionModel as SelectionModel
import com.android.customization.picker.quickaffordance.shared.model.KeyguardQuickAffordancePickerSlotModel as SlotModel
import com.android.systemui.shared.customization.data.content.CustomizationProviderClient as Client
-import com.android.systemui.shared.customization.data.content.CustomizationProviderContract as Contract
-import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
-import kotlinx.coroutines.withContext
/**
* Abstracts access to application state related to functionality for selecting, picking, or setting
@@ -33,12 +30,7 @@
*/
class KeyguardQuickAffordancePickerRepository(
private val client: Client,
- private val backgroundDispatcher: CoroutineDispatcher,
) {
- /** Whether the feature is enabled. */
- val isFeatureEnabled: Flow<Boolean> =
- client.observeFlags().map { flags -> flags.isFeatureEnabled() }
-
/** List of slots available on the device. */
val slots: Flow<List<SlotModel>> =
client.observeSlots().map { slots -> slots.map { slot -> slot.toModel() } }
@@ -55,18 +47,6 @@
selections.map { selection -> selection.toModel() }
}
- suspend fun isFeatureEnabled(): Boolean {
- return withContext(backgroundDispatcher) { client.queryFlags().isFeatureEnabled() }
- }
-
- private fun List<Client.Flag>.isFeatureEnabled(): Boolean {
- return find { flag ->
- flag.name ==
- Contract.FlagsTable.FLAG_NAME_CUSTOM_LOCK_SCREEN_QUICK_AFFORDANCES_ENABLED
- }
- ?.value == true
- }
-
private fun Client.Slot.toModel(): SlotModel {
return SlotModel(
id = id,
diff --git a/src/com/android/customization/picker/quickaffordance/domain/interactor/KeyguardQuickAffordancePickerInteractor.kt b/src/com/android/customization/picker/quickaffordance/domain/interactor/KeyguardQuickAffordancePickerInteractor.kt
index f154de6..6080194 100644
--- a/src/com/android/customization/picker/quickaffordance/domain/interactor/KeyguardQuickAffordancePickerInteractor.kt
+++ b/src/com/android/customization/picker/quickaffordance/domain/interactor/KeyguardQuickAffordancePickerInteractor.kt
@@ -78,9 +78,4 @@
): Drawable {
return client.getAffordanceIcon(iconResourceId)
}
-
- /** Returns `true` if the feature is enabled; `false` otherwise. */
- suspend fun isFeatureEnabled(): Boolean {
- return repository.isFeatureEnabled()
- }
}
diff --git a/src/com/android/customization/picker/quickaffordance/ui/section/KeyguardQuickAffordanceSectionController.kt b/src/com/android/customization/picker/quickaffordance/ui/section/KeyguardQuickAffordanceSectionController.kt
index e0beeff..0c7b250 100644
--- a/src/com/android/customization/picker/quickaffordance/ui/section/KeyguardQuickAffordanceSectionController.kt
+++ b/src/com/android/customization/picker/quickaffordance/ui/section/KeyguardQuickAffordanceSectionController.kt
@@ -20,27 +20,23 @@
import android.content.Context
import android.view.LayoutInflater
import androidx.lifecycle.LifecycleOwner
-import com.android.customization.picker.quickaffordance.domain.interactor.KeyguardQuickAffordancePickerInteractor
import com.android.customization.picker.quickaffordance.ui.binder.KeyguardQuickAffordanceSectionViewBinder
import com.android.customization.picker.quickaffordance.ui.fragment.KeyguardQuickAffordancePickerFragment
import com.android.customization.picker.quickaffordance.ui.view.KeyguardQuickAffordanceSectionView
import com.android.customization.picker.quickaffordance.ui.viewmodel.KeyguardQuickAffordancePickerViewModel
import com.android.wallpaper.R
+import com.android.wallpaper.config.BaseFlags
import com.android.wallpaper.model.CustomizationSectionController
import com.android.wallpaper.model.CustomizationSectionController.CustomizationSectionNavigationController as NavigationController
-import kotlinx.coroutines.runBlocking
class KeyguardQuickAffordanceSectionController(
private val navigationController: NavigationController,
- private val interactor: KeyguardQuickAffordancePickerInteractor,
private val viewModel: KeyguardQuickAffordancePickerViewModel,
private val lifecycleOwner: LifecycleOwner,
) : CustomizationSectionController<KeyguardQuickAffordanceSectionView> {
- private val isFeatureEnabled: Boolean = runBlocking { interactor.isFeatureEnabled() }
-
override fun isAvailable(context: Context): Boolean {
- return isFeatureEnabled
+ return BaseFlags.get().isKeyguardQuickAffordanceEnabled(context)
}
override fun createView(context: Context): KeyguardQuickAffordanceSectionView {
diff --git a/tests/robotests/src/com/android/customization/model/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepositoryTest.kt b/tests/robotests/src/com/android/customization/model/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepositoryTest.kt
index 35dbadd..8a5d582 100644
--- a/tests/robotests/src/com/android/customization/model/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepositoryTest.kt
+++ b/tests/robotests/src/com/android/customization/model/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepositoryTest.kt
@@ -19,21 +19,15 @@
import androidx.test.filters.SmallTest
import com.android.customization.picker.quickaffordance.data.repository.KeyguardQuickAffordancePickerRepository
-import com.android.systemui.shared.customization.data.content.CustomizationProviderContract
import com.android.systemui.shared.customization.data.content.FakeCustomizationProviderClient
-import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.flow.toList
-import kotlinx.coroutines.launch
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.resetMain
-import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.setMain
import org.junit.After
import org.junit.Before
-import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@@ -57,7 +51,6 @@
underTest =
KeyguardQuickAffordancePickerRepository(
client = client,
- backgroundDispatcher = coroutineDispatcher,
)
}
@@ -65,36 +58,4 @@
fun tearDown() {
Dispatchers.resetMain()
}
-
- @Test
- fun `isFeatureEnabled - enabled`() =
- testScope.runTest {
- client.setFlag(
- CustomizationProviderContract.FlagsTable
- .FLAG_NAME_CUSTOM_LOCK_SCREEN_QUICK_AFFORDANCES_ENABLED,
- true,
- )
- val values = mutableListOf<Boolean>()
- val job = launch { underTest.isFeatureEnabled.toList(values) }
-
- assertThat(values.last()).isTrue()
-
- job.cancel()
- }
-
- @Test
- fun `isFeatureEnabled - not enabled`() =
- testScope.runTest {
- client.setFlag(
- CustomizationProviderContract.FlagsTable
- .FLAG_NAME_CUSTOM_LOCK_SCREEN_QUICK_AFFORDANCES_ENABLED,
- false,
- )
- val values = mutableListOf<Boolean>()
- val job = launch { underTest.isFeatureEnabled.toList(values) }
-
- assertThat(values.last()).isFalse()
-
- job.cancel()
- }
}
diff --git a/tests/robotests/src/com/android/customization/model/picker/quickaffordance/domain/interactor/KeyguardQuickAffordancePickerInteractorTest.kt b/tests/robotests/src/com/android/customization/model/picker/quickaffordance/domain/interactor/KeyguardQuickAffordancePickerInteractorTest.kt
index efe9f64..11098ec 100644
--- a/tests/robotests/src/com/android/customization/model/picker/quickaffordance/domain/interactor/KeyguardQuickAffordancePickerInteractorTest.kt
+++ b/tests/robotests/src/com/android/customization/model/picker/quickaffordance/domain/interactor/KeyguardQuickAffordancePickerInteractorTest.kt
@@ -62,7 +62,6 @@
repository =
KeyguardQuickAffordancePickerRepository(
client = client,
- backgroundDispatcher = testDispatcher,
),
client = client,
snapshotRestorer = {
diff --git a/tests/robotests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt b/tests/robotests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt
index f71bfc7..43b872e 100644
--- a/tests/robotests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt
+++ b/tests/robotests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt
@@ -86,7 +86,6 @@
repository =
KeyguardQuickAffordancePickerRepository(
client = client,
- backgroundDispatcher = testDispatcher,
),
client = client,
snapshotRestorer = {