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 17 package com.android.systemui.statusbar.phone 18 19 import android.annotation.ColorInt 20 import android.app.WallpaperManager 21 import android.graphics.Color 22 import android.os.Handler 23 import android.os.RemoteException 24 import android.view.IWindowManager 25 import com.android.systemui.CoreStartable 26 import com.android.systemui.Dumpable 27 import com.android.systemui.dagger.SysUISingleton 28 import com.android.systemui.dagger.qualifiers.Background 29 import com.android.systemui.dagger.qualifiers.Main 30 import java.io.PrintWriter 31 import java.util.concurrent.Executor 32 import javax.inject.Inject 33 34 /** Responsible for providing information about the background of letterboxed apps. */ 35 @SysUISingleton 36 class LetterboxBackgroundProvider 37 @Inject 38 constructor( 39 private val windowManager: IWindowManager, 40 @Background private val backgroundExecutor: Executor, 41 private val wallpaperManager: WallpaperManager, 42 @Main private val mainHandler: Handler, 43 ) : CoreStartable, Dumpable { 44 @ColorInt 45 var letterboxBackgroundColor: Int = Color.BLACK 46 private set 47 48 var isLetterboxBackgroundMultiColored: Boolean = false 49 private set 50 51 private val wallpaperColorsListener = 52 WallpaperManager.OnColorsChangedListener { _, _ -> 53 fetchBackgroundColorInfo() 54 } 55 56 override fun start() { 57 fetchBackgroundColorInfo() 58 wallpaperManager.addOnColorsChangedListener(wallpaperColorsListener, mainHandler) 59 } 60 61 private fun fetchBackgroundColorInfo() { 62 // Using a background executor, as binder calls to IWindowManager are blocking 63 backgroundExecutor.execute { 64 try { 65 isLetterboxBackgroundMultiColored = windowManager.isLetterboxBackgroundMultiColored 66 letterboxBackgroundColor = windowManager.letterboxBackgroundColorInArgb 67 } catch (e: RemoteException) { 68 e.rethrowFromSystemServer() 69 } 70 } 71 } 72 73 override fun dump(pw: PrintWriter, args: Array<out String>) { 74 pw.println( 75 """ 76 letterboxBackgroundColor: ${Color.valueOf(letterboxBackgroundColor)} 77 isLetterboxBackgroundMultiColored: $isLetterboxBackgroundMultiColored 78 """.trimIndent()) 79 } 80 } 81