1 /* 2 * Copyright (C) 2023 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.ui 18 19 import android.content.Context 20 import com.android.internal.policy.SystemBarUtils 21 import com.android.systemui.dagger.qualifiers.Application 22 import com.android.systemui.res.R 23 import dagger.Binds 24 import javax.inject.Inject 25 import kotlin.math.max 26 27 /** 28 * Proxy interface to [SystemBarUtils], allowing injection of different logic for testing. 29 * 30 * Developers should almost always prefer [SystemBarUtilsState] instead. 31 */ 32 interface SystemBarUtilsProxy { getStatusBarHeightnull33 fun getStatusBarHeight(): Int 34 fun getStatusBarHeaderHeightKeyguard(): Int 35 } 36 37 class SystemBarUtilsProxyImpl 38 @Inject 39 constructor( 40 @Application private val context: Context, 41 ) : SystemBarUtilsProxy { 42 override fun getStatusBarHeight(): Int = SystemBarUtils.getStatusBarHeight(context) 43 override fun getStatusBarHeaderHeightKeyguard(): Int { 44 val cutout = context.display.cutout 45 val waterfallInsetTop = if (cutout == null) 0 else cutout.waterfallInsets.top 46 val statusBarHeaderHeightKeyguard = 47 context.resources.getDimensionPixelSize(R.dimen.status_bar_header_height_keyguard) 48 return max(getStatusBarHeight(), statusBarHeaderHeightKeyguard + waterfallInsetTop) 49 } 50 51 @dagger.Module 52 interface Module { 53 @Binds fun bindImpl(impl: SystemBarUtilsProxyImpl): SystemBarUtilsProxy 54 } 55 } 56