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.systemui.shared.customization.data.content.CustomizationProviderClient 21 import com.android.systemui.shared.customization.data.content.CustomizationProviderClientImpl 22 import com.android.systemui.shared.customization.data.content.CustomizationProviderContract as Contract 23 import com.android.wallpaper.module.InjectorProvider 24 import kotlinx.coroutines.Dispatchers 25 import kotlinx.coroutines.runBlocking 26 27 abstract class BaseFlags { 28 var customizationProviderClient: CustomizationProviderClient? = null 29 private var cachedFlags: List<CustomizationProviderClient.Flag>? = null 30 open fun isStagingBackdropContentEnabled() = false 31 open fun isWallpaperEffectEnabled() = false 32 open fun isWallpaperEffectModelDownloadEnabled() = true 33 open fun isInterruptModelDownloadEnabled() = false 34 35 // TODO(b/285047815): Remove flag after adding wallpaper id for default static wallpaper 36 open fun isWallpaperRestorerEnabled() = false 37 38 /** 39 * Enables new preview UI if both [isMultiCropEnabled] and this flag are true. 40 * 41 * TODO(b/291761856): Create SysUI flag for new preview UI 42 */ 43 open fun isMultiCropPreviewUiEnabled() = false 44 45 open fun isMultiCropEnabled() = WallpaperManager.isMultiCropEnabled() 46 47 open fun isUseRevampedUiEnabled(context: Context): Boolean { 48 return getCachedFlags(context) 49 .firstOrNull { flag -> 50 flag.name == Contract.FlagsTable.FLAG_NAME_REVAMPED_WALLPAPER_UI 51 } 52 ?.value == true 53 } 54 open fun isCustomClocksEnabled(context: Context): Boolean { 55 return getCachedFlags(context) 56 .firstOrNull { flag -> 57 flag.name == Contract.FlagsTable.FLAG_NAME_CUSTOM_CLOCKS_ENABLED 58 } 59 ?.value == true 60 } 61 open fun isMonochromaticThemeEnabled(context: Context): Boolean { 62 return getCachedFlags(context) 63 .firstOrNull { flag -> flag.name == Contract.FlagsTable.FLAG_NAME_MONOCHROMATIC_THEME } 64 ?.value == true 65 } 66 67 open fun isAIWallpaperEnabled(context: Context): Boolean { 68 return getCachedFlags(context) 69 .firstOrNull { flag -> 70 flag.name == Contract.FlagsTable.FLAG_NAME_WALLPAPER_PICKER_UI_FOR_AIWP 71 } 72 ?.value == true 73 } 74 75 open fun isTransitClockEnabled(context: Context): Boolean { 76 return getCachedFlags(context) 77 .firstOrNull { flag -> flag.name == Contract.FlagsTable.FLAG_NAME_TRANSIT_CLOCK } 78 ?.value == true 79 } 80 81 /** 82 * This flag is to for refactoring the process of setting a wallpaper from the Wallpaper Picker, 83 * such as changes in WallpaperSetter, WallpaperPersister and WallpaperPreferences. 84 */ 85 fun isRefactorSettingWallpaper(): Boolean { 86 return false 87 } 88 89 open fun isPageTransitionsFeatureEnabled(context: Context): Boolean { 90 return getCachedFlags(context) 91 .firstOrNull { flag -> flag.name == Contract.FlagsTable.FLAG_NAME_PAGE_TRANSITIONS } 92 ?.value == true 93 } 94 95 open fun isGridApplyButtonEnabled(context: Context): Boolean { 96 return getCachedFlags(context) 97 .firstOrNull { flag -> flag.name == Contract.FlagsTable.FLAG_NAME_GRID_APPLY_BUTTON } 98 ?.value == true 99 } 100 101 open fun isPreviewLoadingAnimationEnabled(context: Context): Boolean { 102 return getCachedFlags(context) 103 .firstOrNull { flag -> 104 flag.name == Contract.FlagsTable.FLAG_NAME_WALLPAPER_PICKER_PREVIEW_ANIMATION 105 } 106 ?.value == true 107 } 108 109 private fun getCustomizationProviderClient(context: Context): CustomizationProviderClient { 110 return customizationProviderClient 111 ?: CustomizationProviderClientImpl(context.applicationContext, Dispatchers.IO).also { 112 customizationProviderClient = it 113 } 114 } 115 116 fun isQuickAffordancesEnabled(context: Context): Boolean { 117 return getCachedFlags(context) 118 .firstOrNull { flag -> 119 flag.name == 120 Contract.FlagsTable.FLAG_NAME_CUSTOM_LOCK_SCREEN_QUICK_AFFORDANCES_ENABLED 121 } 122 ?.value == true 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