• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.content.Context
19 import com.android.systemui.shared.customization.data.content.CustomizationProviderClient
20 import com.android.systemui.shared.customization.data.content.CustomizationProviderClientImpl
21 import com.android.systemui.shared.customization.data.content.CustomizationProviderContract as Contract
22 import kotlinx.coroutines.Dispatchers
23 import kotlinx.coroutines.runBlocking
24 
25 abstract class BaseFlags {
26     var customizationProviderClient: CustomizationProviderClient? = null
27     open fun isStagingBackdropContentEnabled() = false
28     open fun isWallpaperEffectEnabled() = false
29     open fun isFullscreenWallpaperPreviewEnabled(context: Context): Boolean {
30         return runBlocking { getCustomizationProviderClient(context).queryFlags() }
31             .firstOrNull { flag ->
32                 flag.name == Contract.FlagsTable.FLAG_NAME_WALLPAPER_FULLSCREEN_PREVIEW
33             }
34             ?.value == true
35     }
36     fun isUseRevampedUiEnabled(context: Context): Boolean {
37         return runBlocking { getCustomizationProviderClient(context).queryFlags() }
38             .firstOrNull { flag ->
39                 flag.name == Contract.FlagsTable.FLAG_NAME_REVAMPED_WALLPAPER_UI
40             }
41             ?.value == true
42     }
43     fun isCustomClocksEnabled(context: Context): Boolean {
44         return runBlocking { getCustomizationProviderClient(context).queryFlags() }
45             .firstOrNull { flag ->
46                 flag.name == Contract.FlagsTable.FLAG_NAME_CUSTOM_CLOCKS_ENABLED
47             }
48             ?.value == true
49     }
50     fun isMonochromaticThemeEnabled(context: Context): Boolean {
51         return runBlocking { getCustomizationProviderClient(context).queryFlags() }
52             .firstOrNull { flag -> flag.name == Contract.FlagsTable.FLAG_NAME_MONOCHROMATIC_THEME }
53             ?.value == true
54     }
55 
56     fun isAIWallpaperEnabled(context: Context): Boolean {
57         return runBlocking { getCustomizationProviderClient(context).queryFlags() }
58             .firstOrNull { flag ->
59                 flag.name == Contract.FlagsTable.FLAG_NAME_WALLPAPER_PICKER_UI_FOR_AIWP
60             }
61             ?.value == true
62     }
63 
64     private fun getCustomizationProviderClient(context: Context): CustomizationProviderClient {
65         return customizationProviderClient
66             ?: CustomizationProviderClientImpl(context, Dispatchers.IO).also {
67                 customizationProviderClient = it
68             }
69     }
70 }
71