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.customization.data.content.CustomizationProviderClient 23 import com.android.systemui.shared.customization.data.content.CustomizationProviderClientImpl 24 import com.android.systemui.shared.customization.data.content.CustomizationProviderContract as Contract 25 import com.android.wallpaper.Flags.magicPortraitFlag 26 import com.android.wallpaper.Flags.newPickerUiFlag 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 open fun isStagingBackdropContentEnabled() = false 37 open fun isWallpaperEffectEnabled() = false 38 open fun isWallpaperEffectModelDownloadEnabled() = true 39 open fun isInterruptModelDownloadEnabled() = false 40 open fun isWallpaperRestorerEnabled() = wallpaperRestorerFlag() 41 open fun isWallpaperCategoryRefactoringEnabled() = refactorWallpaperCategoryFlag() 42 open fun isColorContrastControlEnabled() = enableColorContrastControl() 43 open fun isMagicPortraitEnabled() = magicPortraitFlag() 44 open fun isNewPickerUi() = newPickerUiFlag() 45 open fun isClockReactiveVariantsEnabled() = clockReactiveVariants() 46 47 open fun isMultiCropEnabled() = WallpaperManager.isMultiCropEnabled() 48 49 open fun isKeyguardQuickAffordanceEnabled(context: Context): Boolean { 50 return getCachedFlags(context) 51 .firstOrNull { flag -> 52 flag.name == 53 Contract.FlagsTable.FLAG_NAME_CUSTOM_LOCK_SCREEN_QUICK_AFFORDANCES_ENABLED 54 } 55 ?.value == true 56 } 57 58 open fun isCustomClocksEnabled(context: Context): Boolean { 59 return getCachedFlags(context) 60 .firstOrNull { flag -> 61 flag.name == Contract.FlagsTable.FLAG_NAME_CUSTOM_CLOCKS_ENABLED 62 } 63 ?.value == true 64 } 65 66 open fun isMonochromaticThemeEnabled(context: Context): Boolean { 67 return getCachedFlags(context) 68 .firstOrNull { flag -> flag.name == Contract.FlagsTable.FLAG_NAME_MONOCHROMATIC_THEME } 69 ?.value == true 70 } 71 72 open fun isAIWallpaperEnabled(context: Context): Boolean { 73 return getCachedFlags(context) 74 .firstOrNull { flag -> 75 flag.name == Contract.FlagsTable.FLAG_NAME_WALLPAPER_PICKER_UI_FOR_AIWP 76 } 77 ?.value == true 78 } 79 80 open fun isTransitClockEnabled(context: Context): Boolean { 81 return getCachedFlags(context) 82 .firstOrNull { flag -> flag.name == Contract.FlagsTable.FLAG_NAME_TRANSIT_CLOCK } 83 ?.value == true 84 } 85 86 /** 87 * This flag is to for refactoring the process of setting a wallpaper from the Wallpaper Picker, 88 * such as changes in WallpaperSetter, WallpaperPersister and WallpaperPreferences. 89 */ 90 fun isRefactorSettingWallpaper(): Boolean { 91 return false 92 } 93 94 open fun isPageTransitionsFeatureEnabled(context: Context): Boolean { 95 return getCachedFlags(context) 96 .firstOrNull { flag -> flag.name == Contract.FlagsTable.FLAG_NAME_PAGE_TRANSITIONS } 97 ?.value == true 98 } 99 100 open fun isGridApplyButtonEnabled(context: Context): Boolean { 101 return getCachedFlags(context) 102 .firstOrNull { flag -> flag.name == Contract.FlagsTable.FLAG_NAME_GRID_APPLY_BUTTON } 103 ?.value == true 104 } 105 106 open fun isPreviewLoadingAnimationEnabled(context: Context): Boolean { 107 return getCachedFlags(context) 108 .firstOrNull { flag -> 109 flag.name == Contract.FlagsTable.FLAG_NAME_WALLPAPER_PICKER_PREVIEW_ANIMATION 110 } 111 ?.value == true 112 } 113 114 private fun getCustomizationProviderClient(context: Context): CustomizationProviderClient { 115 return customizationProviderClient 116 ?: CustomizationProviderClientImpl(context.applicationContext, Dispatchers.IO).also { 117 customizationProviderClient = it 118 } 119 } 120 121 open fun getCachedFlags(context: Context): List<CustomizationProviderClient.Flag> { 122 return cachedFlags 123 ?: runBlocking { getCustomizationProviderClient(context).queryFlags() } 124 .also { cachedFlags = it } 125 } 126 127 companion object { 128 @JvmStatic 129 fun get(): BaseFlags { 130 return InjectorProvider.getInjector().getFlags() 131 } 132 } 133 } 134