Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1ad5378 authored by Chris Göllner's avatar Chris Göllner Committed by Android (Google) Code Review
Browse files

Merge "Camera Protection Info - Take into account rotation for bounds" into main

parents 893a4d5d f349725f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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)
    }

+1 −1
Original line number Diff line number Diff line
@@ -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)
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -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?,
)
+36 −4
Original line number Diff line number Diff line
@@ -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
@@ -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
    }
}
+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