Loading packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -1138,7 +1138,7 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { private fun setCameraProtectionBounds(protectionBounds: Rect) { val protectionInfo = mock<CameraProtectionInfo> { whenever(this.cutoutBounds).thenReturn(protectionBounds) } mock<CameraProtectionInfo> { whenever(this.bounds).thenReturn(protectionBounds) } whenever(sysUICutout.cameraProtection).thenReturn(protectionInfo) } Loading packages/SystemUI/src/com/android/systemui/CameraAvailabilityListener.kt +1 −1 Original line number Diff line number Diff line Loading @@ -143,7 +143,7 @@ class CameraAvailabilityListener( private fun notifyCameraActive(info: CameraProtectionInfo) { listeners.forEach { it.onApplyCameraProtection(info.cutoutProtectionPath, info.cutoutBounds) it.onApplyCameraProtection(info.cutoutProtectionPath, info.bounds) } } Loading packages/SystemUI/src/com/android/systemui/CameraProtectionInfo.kt +1 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,6 @@ data class CameraProtectionInfo( val logicalCameraId: String, val physicalCameraId: String?, val cutoutProtectionPath: Path, val cutoutBounds: Rect, val bounds: Rect, val displayUniqueId: String?, ) packages/SystemUI/src/com/android/systemui/SysUICutoutProvider.kt +36 −4 Original line number Diff line number Diff line Loading @@ -17,8 +17,12 @@ package com.android.systemui import android.content.Context import android.graphics.Rect import android.util.RotationUtils import android.view.Display import android.view.DisplayCutout import com.android.systemui.dagger.SysUISingleton import com.android.systemui.display.naturalBounds import javax.inject.Inject @SysUISingleton Loading @@ -33,15 +37,43 @@ constructor( cameraProtectionLoader.loadCameraProtectionInfoList() } fun cutoutInfoForCurrentDisplay(): SysUICutoutInformation? { /** * Returns the [SysUICutoutInformation] for the current display and the current rotation. * * This means that the bounds of the display cutout and the camera protection will be * adjusted/rotated for the current rotation. */ fun cutoutInfoForCurrentDisplayAndRotation(): SysUICutoutInformation? { val display = context.display val displayCutout: DisplayCutout = display.cutout ?: return null return SysUICutoutInformation(displayCutout, getCameraProtectionForDisplay(display)) } private fun getCameraProtectionForDisplay(display: Display): CameraProtectionInfo? { val displayUniqueId: String? = display.uniqueId if (displayUniqueId.isNullOrEmpty()) { return SysUICutoutInformation(displayCutout, cameraProtection = null) return null } val cameraProtection: CameraProtectionInfo? = val cameraProtection: CameraProtectionInfo = cameraProtectionList.firstOrNull { it.displayUniqueId == displayUniqueId } return SysUICutoutInformation(displayCutout, cameraProtection) ?: return null val adjustedBoundsForRotation = calculateCameraProtectionBoundsForRotation(display, cameraProtection.bounds) return cameraProtection.copy(bounds = adjustedBoundsForRotation) } private fun calculateCameraProtectionBoundsForRotation( display: Display, originalProtectionBounds: Rect, ): Rect { val displayNaturalBounds = display.naturalBounds val rotatedBoundsOut = Rect(originalProtectionBounds) RotationUtils.rotateBounds( /* inOutBounds = */ rotatedBoundsOut, /* parentWidth = */ displayNaturalBounds.width(), /* parentHeight = */ displayNaturalBounds.height(), /* rotation = */ display.rotation ) return rotatedBoundsOut } } packages/SystemUI/src/com/android/systemui/display/DisplayExtensions.kt 0 → 100644 +47 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.display import android.graphics.Rect import android.view.Display import android.view.DisplayInfo val Display.naturalBounds: Rect get() { val outDisplayInfo = DisplayInfo() getDisplayInfo(outDisplayInfo) return Rect( /* left = */ 0, /* top = */ 0, /* right = */ outDisplayInfo.naturalWidth, /* bottom = */ outDisplayInfo.naturalHeight ) } val Display.naturalWidth: Int get() { val outDisplayInfo = DisplayInfo() getDisplayInfo(outDisplayInfo) return outDisplayInfo.naturalWidth } val Display.naturalHeight: Int get() { val outDisplayInfo = DisplayInfo() getDisplayInfo(outDisplayInfo) return outDisplayInfo.naturalHeight } Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -1138,7 +1138,7 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { private fun setCameraProtectionBounds(protectionBounds: Rect) { val protectionInfo = mock<CameraProtectionInfo> { whenever(this.cutoutBounds).thenReturn(protectionBounds) } mock<CameraProtectionInfo> { whenever(this.bounds).thenReturn(protectionBounds) } whenever(sysUICutout.cameraProtection).thenReturn(protectionInfo) } Loading
packages/SystemUI/src/com/android/systemui/CameraAvailabilityListener.kt +1 −1 Original line number Diff line number Diff line Loading @@ -143,7 +143,7 @@ class CameraAvailabilityListener( private fun notifyCameraActive(info: CameraProtectionInfo) { listeners.forEach { it.onApplyCameraProtection(info.cutoutProtectionPath, info.cutoutBounds) it.onApplyCameraProtection(info.cutoutProtectionPath, info.bounds) } } Loading
packages/SystemUI/src/com/android/systemui/CameraProtectionInfo.kt +1 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,6 @@ data class CameraProtectionInfo( val logicalCameraId: String, val physicalCameraId: String?, val cutoutProtectionPath: Path, val cutoutBounds: Rect, val bounds: Rect, val displayUniqueId: String?, )
packages/SystemUI/src/com/android/systemui/SysUICutoutProvider.kt +36 −4 Original line number Diff line number Diff line Loading @@ -17,8 +17,12 @@ package com.android.systemui import android.content.Context import android.graphics.Rect import android.util.RotationUtils import android.view.Display import android.view.DisplayCutout import com.android.systemui.dagger.SysUISingleton import com.android.systemui.display.naturalBounds import javax.inject.Inject @SysUISingleton Loading @@ -33,15 +37,43 @@ constructor( cameraProtectionLoader.loadCameraProtectionInfoList() } fun cutoutInfoForCurrentDisplay(): SysUICutoutInformation? { /** * Returns the [SysUICutoutInformation] for the current display and the current rotation. * * This means that the bounds of the display cutout and the camera protection will be * adjusted/rotated for the current rotation. */ fun cutoutInfoForCurrentDisplayAndRotation(): SysUICutoutInformation? { val display = context.display val displayCutout: DisplayCutout = display.cutout ?: return null return SysUICutoutInformation(displayCutout, getCameraProtectionForDisplay(display)) } private fun getCameraProtectionForDisplay(display: Display): CameraProtectionInfo? { val displayUniqueId: String? = display.uniqueId if (displayUniqueId.isNullOrEmpty()) { return SysUICutoutInformation(displayCutout, cameraProtection = null) return null } val cameraProtection: CameraProtectionInfo? = val cameraProtection: CameraProtectionInfo = cameraProtectionList.firstOrNull { it.displayUniqueId == displayUniqueId } return SysUICutoutInformation(displayCutout, cameraProtection) ?: return null val adjustedBoundsForRotation = calculateCameraProtectionBoundsForRotation(display, cameraProtection.bounds) return cameraProtection.copy(bounds = adjustedBoundsForRotation) } private fun calculateCameraProtectionBoundsForRotation( display: Display, originalProtectionBounds: Rect, ): Rect { val displayNaturalBounds = display.naturalBounds val rotatedBoundsOut = Rect(originalProtectionBounds) RotationUtils.rotateBounds( /* inOutBounds = */ rotatedBoundsOut, /* parentWidth = */ displayNaturalBounds.width(), /* parentHeight = */ displayNaturalBounds.height(), /* rotation = */ display.rotation ) return rotatedBoundsOut } }
packages/SystemUI/src/com/android/systemui/display/DisplayExtensions.kt 0 → 100644 +47 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.display import android.graphics.Rect import android.view.Display import android.view.DisplayInfo val Display.naturalBounds: Rect get() { val outDisplayInfo = DisplayInfo() getDisplayInfo(outDisplayInfo) return Rect( /* left = */ 0, /* top = */ 0, /* right = */ outDisplayInfo.naturalWidth, /* bottom = */ outDisplayInfo.naturalHeight ) } val Display.naturalWidth: Int get() { val outDisplayInfo = DisplayInfo() getDisplayInfo(outDisplayInfo) return outDisplayInfo.naturalWidth } val Display.naturalHeight: Int get() { val outDisplayInfo = DisplayInfo() getDisplayInfo(outDisplayInfo) return outDisplayInfo.naturalHeight }