1 /* 2 * 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.decor 18 19 import android.content.res.Resources 20 import android.util.Log 21 import android.view.Display 22 import android.view.DisplayCutout 23 import android.view.DisplayInfo 24 25 class CutoutDecorProviderFactory constructor( 26 private val res: Resources, 27 private val display: Display?, 28 ) : DecorProviderFactory() { 29 30 val displayInfo = DisplayInfo() 31 32 override val hasProviders: Boolean 33 get() { 34 display?.getDisplayInfo(displayInfo) ?: run { 35 Log.w(TAG, "display is null, can't update displayInfo") 36 } 37 return DisplayCutout.getFillBuiltInDisplayCutout(res, displayInfo.uniqueId) 38 } 39 40 override val providers: List<DecorProvider> 41 get() { 42 if (!hasProviders) { 43 return emptyList() 44 } 45 46 return ArrayList<DecorProvider>().also { list -> 47 // We need to update displayInfo before using it, but it has already updated during 48 // accessing hasProviders field 49 displayInfo.displayCutout?.getBoundBaseOnCurrentRotation()?.let { bounds -> 50 for (bound in bounds) { 51 list.add( 52 CutoutDecorProviderImpl(bound.baseOnRotation0(displayInfo.rotation)) 53 ) 54 } 55 } 56 } 57 } 58 } 59 60 private const val TAG = "CutoutDecorProviderFactory" 61