1 /* <lambda>null2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.wallpaper.config 17 18 import android.app.WallpaperManager 19 import android.content.Context 20 import com.android.settings.accessibility.Flags.enableColorContrastControl 21 import com.android.systemui.Flags.clockReactiveVariants 22 import com.android.systemui.shared.Flags.newCustomizationPickerUi 23 import com.android.systemui.shared.customization.data.content.CustomizationProviderClient 24 import com.android.systemui.shared.customization.data.content.CustomizationProviderClientImpl 25 import com.android.systemui.shared.customization.data.content.CustomizationProviderContract as Contract 26 import com.android.wallpaper.Flags.magicPortraitFlag 27 import com.android.wallpaper.Flags.refactorWallpaperCategoryFlag 28 import com.android.wallpaper.Flags.wallpaperRestorerFlag 29 import com.android.wallpaper.module.InjectorProvider 30 import kotlinx.coroutines.Dispatchers 31 import kotlinx.coroutines.runBlocking 32 33 abstract class BaseFlags { 34 private var customizationProviderClient: CustomizationProviderClient? = null 35 private var cachedFlags: List<CustomizationProviderClient.Flag>? = null 36 37 open fun isStagingBackdropContentEnabled() = false 38 39 open fun isWallpaperEffectEnabled() = false 40 41 open fun isWallpaperEffectModelDownloadEnabled() = true 42 43 open fun isInterruptModelDownloadEnabled() = false 44 45 open fun isWallpaperRestorerEnabled() = wallpaperRestorerFlag() 46 47 open fun isWallpaperCategoryRefactoringEnabled() = refactorWallpaperCategoryFlag() 48 49 open fun isColorContrastControlEnabled() = enableColorContrastControl() 50 51 open fun isMagicPortraitEnabled() = magicPortraitFlag() 52 53 open fun isNewPickerUi() = newCustomizationPickerUi() 54 55 open fun isClockReactiveVariantsEnabled() = clockReactiveVariants() 56 57 open fun isMultiCropEnabled() = WallpaperManager.isMultiCropEnabled() 58 59 open fun isKeyguardQuickAffordanceEnabled(context: Context): Boolean { 60 return getCachedFlags(context) 61 .firstOrNull { flag -> 62 flag.name == 63 Contract.FlagsTable.FLAG_NAME_CUSTOM_LOCK_SCREEN_QUICK_AFFORDANCES_ENABLED 64 } 65 ?.value == true 66 } 67 68 open fun isCustomClocksEnabled(context: Context): Boolean { 69 return getCachedFlags(context) 70 .firstOrNull { flag -> 71 flag.name == Contract.FlagsTable.FLAG_NAME_CUSTOM_CLOCKS_ENABLED 72 } 73 ?.value == true 74 } 75 76 open fun isMonochromaticThemeEnabled(context: Context): Boolean { 77 return getCachedFlags(context) 78 .firstOrNull { flag -> flag.name == Contract.FlagsTable.FLAG_NAME_MONOCHROMATIC_THEME } 79 ?.value == true 80 } 81 82 open fun isAIWallpaperEnabled(context: Context): Boolean { 83 return getCachedFlags(context) 84 .firstOrNull { flag -> 85 flag.name == Contract.FlagsTable.FLAG_NAME_WALLPAPER_PICKER_UI_FOR_AIWP 86 } 87 ?.value == true 88 } 89 90 /** 91 * This flag is to for refactoring the process of setting a wallpaper from the Wallpaper Picker, 92 * such as changes in WallpaperSetter, WallpaperPersister and WallpaperPreferences. 93 */ 94 fun isRefactorSettingWallpaper(): Boolean { 95 return false 96 } 97 98 open fun isPageTransitionsFeatureEnabled(context: Context): Boolean { 99 return getCachedFlags(context) 100 .firstOrNull { flag -> flag.name == Contract.FlagsTable.FLAG_NAME_PAGE_TRANSITIONS } 101 ?.value == true 102 } 103 104 open fun isGridApplyButtonEnabled(context: Context): Boolean { 105 return getCachedFlags(context) 106 .firstOrNull { flag -> flag.name == Contract.FlagsTable.FLAG_NAME_GRID_APPLY_BUTTON } 107 ?.value == true 108 } 109 110 open fun isPreviewLoadingAnimationEnabled(context: Context): Boolean { 111 return getCachedFlags(context) 112 .firstOrNull { flag -> 113 flag.name == Contract.FlagsTable.FLAG_NAME_WALLPAPER_PICKER_PREVIEW_ANIMATION 114 } 115 ?.value == true 116 } 117 118 private fun getCustomizationProviderClient(context: Context): CustomizationProviderClient { 119 return customizationProviderClient 120 ?: CustomizationProviderClientImpl(context.applicationContext, Dispatchers.IO).also { 121 customizationProviderClient = it 122 } 123 } 124 125 open fun getCachedFlags(context: Context): List<CustomizationProviderClient.Flag> { 126 return cachedFlags 127 ?: runBlocking { getCustomizationProviderClient(context).queryFlags() } 128 .also { cachedFlags = it } 129 } 130 131 companion object { 132 @JvmStatic 133 fun get(): BaseFlags { 134 return InjectorProvider.getInjector().getFlags() 135 } 136 } 137 } 138