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

Commit 0b4cb06d authored by Chris Göllner's avatar Chris Göllner
Browse files

Prepare SysUICutoutProvider and CameraProtectionLoader for multi display

- Splits interface and Impl
- Turns them into AssistedInject

Test: SysUICutoutProviderTest
Test: CameraProtectionLoaderImplTest
Test: Manually build and run
Flag: EXEMPT no behavior changes
Bug: 362720432
Change-Id: I6461a6d95cf5ff8bfee28e5f20ca92091dcf597f
parent 117c5a00
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -22,15 +22,18 @@ import android.graphics.Rect
import android.graphics.RectF
import android.util.PathParser
import com.android.systemui.res.R
import javax.inject.Inject
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import kotlin.math.roundToInt

interface CameraProtectionLoader {
    fun loadCameraProtectionInfoList(): List<CameraProtectionInfo>
}

class CameraProtectionLoaderImpl @Inject constructor(private val context: Context) :
    CameraProtectionLoader {
class CameraProtectionLoaderImpl
@AssistedInject
constructor(@Assisted private val context: Context) : CameraProtectionLoader {

    override fun loadCameraProtectionInfoList(): List<CameraProtectionInfo> {
        val list = mutableListOf<CameraProtectionInfo>()
@@ -76,7 +79,7 @@ class CameraProtectionLoaderImpl @Inject constructor(private val context: Contex
                computed.left.roundToInt(),
                computed.top.roundToInt(),
                computed.right.roundToInt(),
                computed.bottom.roundToInt()
                computed.bottom.roundToInt(),
            )
        val displayUniqueId = context.getString(displayUniqueIdRes)
        return CameraProtectionInfo(
@@ -84,7 +87,7 @@ class CameraProtectionLoaderImpl @Inject constructor(private val context: Contex
            physicalCameraId,
            protectionPath,
            protectionBounds,
            displayUniqueId
            displayUniqueId,
        )
    }

@@ -95,4 +98,9 @@ class CameraProtectionLoaderImpl @Inject constructor(private val context: Contex
            throw IllegalArgumentException("Invalid protection path", e)
        }
    }

    @AssistedFactory
    interface Factory {
        fun create(context: Context): CameraProtectionLoaderImpl
    }
}
+12 −3
Original line number Diff line number Diff line
@@ -16,11 +16,20 @@

package com.android.systemui

import dagger.Binds
import android.content.Context
import com.android.systemui.dagger.SysUISingleton
import dagger.Module
import dagger.Provides

@Module
interface CameraProtectionModule {
object CameraProtectionModule {

    @Binds fun cameraProtectionLoaderImpl(impl: CameraProtectionLoaderImpl): CameraProtectionLoader
    @Provides
    @SysUISingleton
    fun cameraProtectionLoader(
        factory: CameraProtectionLoaderImpl.Factory,
        context: Context,
    ): CameraProtectionLoader {
        return factory.create(context)
    }
}
+28 −15
Original line number Diff line number Diff line
@@ -21,21 +21,12 @@ 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
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject

@SysUISingleton
class SysUICutoutProvider
@Inject
constructor(
    private val context: Context,
    private val cameraProtectionLoader: CameraProtectionLoader,
) {

    private val cameraProtectionList by lazy {
        cameraProtectionLoader.loadCameraProtectionInfoList()
    }
interface SysUICutoutProvider {

    /**
     * Returns the [SysUICutoutInformation] for the current display and the current rotation.
@@ -43,7 +34,21 @@ constructor(
     * This means that the bounds of the display cutout and the camera protection will be
     * adjusted/rotated for the current rotation.
     */
    fun cutoutInfoForCurrentDisplayAndRotation(): SysUICutoutInformation? {
    fun cutoutInfoForCurrentDisplayAndRotation(): SysUICutoutInformation?
}

class SysUICutoutProviderImpl
@AssistedInject
constructor(
    @Assisted private val context: Context,
    @Assisted private val cameraProtectionLoader: CameraProtectionLoader,
) : SysUICutoutProvider {

    private val cameraProtectionList by lazy {
        cameraProtectionLoader.loadCameraProtectionInfoList()
    }

    override fun cutoutInfoForCurrentDisplayAndRotation(): SysUICutoutInformation? {
        val display = context.display
        val displayCutout: DisplayCutout = display.cutout ?: return null
        return SysUICutoutInformation(displayCutout, getCameraProtectionForDisplay(display))
@@ -72,8 +77,16 @@ constructor(
            /* inOutBounds = */ rotatedBoundsOut,
            /* parentWidth = */ displayNaturalBounds.width(),
            /* parentHeight = */ displayNaturalBounds.height(),
            /* rotation = */ display.rotation
            /* rotation = */ display.rotation,
        )
        return rotatedBoundsOut
    }

    @AssistedFactory
    interface Factory {
        fun create(
            context: Context,
            cameraProtectionLoader: CameraProtectionLoader,
        ): SysUICutoutProviderImpl
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -17,8 +17,10 @@
package com.android.systemui.statusbar.dagger

import android.content.Context
import com.android.systemui.CameraProtectionLoader
import com.android.systemui.CoreStartable
import com.android.systemui.SysUICutoutProvider
import com.android.systemui.SysUICutoutProviderImpl
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogBufferFactory
@@ -112,6 +114,16 @@ abstract class StatusBarModule {
            return factory.create("OngoingCall", 75)
        }

        @Provides
        @SysUISingleton
        fun sysUiCutoutProvider(
            factory: SysUICutoutProviderImpl.Factory,
            context: Context,
            cameraProtectionLoader: CameraProtectionLoader,
        ): SysUICutoutProvider {
            return factory.create(context, cameraProtectionLoader)
        }

        @Provides
        @SysUISingleton
        fun contentInsetsProvider(
+4 −4
Original line number Diff line number Diff line
@@ -37,14 +37,14 @@ class CameraProtectionLoaderImplTest : SysuiTestCase() {
        overrideResource(R.string.config_protectedPhysicalCameraId, OUTER_CAMERA_PHYSICAL_ID)
        overrideResource(
            R.string.config_frontBuiltInDisplayCutoutProtection,
            OUTER_CAMERA_PROTECTION_PATH
            OUTER_CAMERA_PROTECTION_PATH,
        )
        overrideResource(R.string.config_protectedScreenUniqueId, OUTER_SCREEN_UNIQUE_ID)
        overrideResource(R.string.config_protectedInnerCameraId, INNER_CAMERA_LOGICAL_ID)
        overrideResource(R.string.config_protectedInnerPhysicalCameraId, INNER_CAMERA_PHYSICAL_ID)
        overrideResource(
            R.string.config_innerBuiltInDisplayCutoutProtection,
            INNER_CAMERA_PROTECTION_PATH
            INNER_CAMERA_PROTECTION_PATH,
        )
        overrideResource(R.string.config_protectedInnerScreenUniqueId, INNER_SCREEN_UNIQUE_ID)
    }
Loading