summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/CameraProtectionLoader.kt18
-rw-r--r--packages/SystemUI/src/com/android/systemui/CameraProtectionModule.kt15
-rw-r--r--packages/SystemUI/src/com/android/systemui/SysUICutoutProvider.kt43
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/dagger/StatusBarModule.kt12
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/CameraProtectionLoaderImplTest.kt8
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/SysUICutoutProviderTest.kt46
6 files changed, 90 insertions, 52 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/CameraProtectionLoader.kt b/packages/SystemUI/src/com/android/systemui/CameraProtectionLoader.kt
index 6cee28be78f1..0c29466d8dc5 100644
--- a/packages/SystemUI/src/com/android/systemui/CameraProtectionLoader.kt
+++ b/packages/SystemUI/src/com/android/systemui/CameraProtectionLoader.kt
@@ -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
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/CameraProtectionModule.kt b/packages/SystemUI/src/com/android/systemui/CameraProtectionModule.kt
index 58680a88d670..442a1e4d60a7 100644
--- a/packages/SystemUI/src/com/android/systemui/CameraProtectionModule.kt
+++ b/packages/SystemUI/src/com/android/systemui/CameraProtectionModule.kt
@@ -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)
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/SysUICutoutProvider.kt b/packages/SystemUI/src/com/android/systemui/SysUICutoutProvider.kt
index 7309599d9c04..b4cb1033ab82 100644
--- a/packages/SystemUI/src/com/android/systemui/SysUICutoutProvider.kt
+++ b/packages/SystemUI/src/com/android/systemui/SysUICutoutProvider.kt
@@ -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
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/dagger/StatusBarModule.kt b/packages/SystemUI/src/com/android/systemui/statusbar/dagger/StatusBarModule.kt
index f6f4503b210a..f65ae67efbf1 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/dagger/StatusBarModule.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/dagger/StatusBarModule.kt
@@ -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
@@ -114,6 +116,16 @@ abstract class StatusBarModule {
@Provides
@SysUISingleton
+ fun sysUiCutoutProvider(
+ factory: SysUICutoutProviderImpl.Factory,
+ context: Context,
+ cameraProtectionLoader: CameraProtectionLoader,
+ ): SysUICutoutProvider {
+ return factory.create(context, cameraProtectionLoader)
+ }
+
+ @Provides
+ @SysUISingleton
fun contentInsetsProvider(
factory: StatusBarContentInsetsProviderImpl.Factory,
context: Context,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/CameraProtectionLoaderImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/CameraProtectionLoaderImplTest.kt
index d2a17c2ccbb4..ad58a0175a39 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/CameraProtectionLoaderImplTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/CameraProtectionLoaderImplTest.kt
@@ -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)
}
@@ -107,7 +107,7 @@ class CameraProtectionLoaderImplTest : SysuiTestCase() {
private const val OUTER_CAMERA_PHYSICAL_ID = "11"
private const val OUTER_CAMERA_PROTECTION_PATH = "M 0,0 H 10,10 V 10,10 H 0,10 Z"
private val OUTER_CAMERA_PROTECTION_BOUNDS =
- Rect(/* left = */ 0, /* top = */ 0, /* right = */ 10, /* bottom = */ 10)
+ Rect(/* left= */ 0, /* top= */ 0, /* right= */ 10, /* bottom= */ 10)
private const val OUTER_SCREEN_UNIQUE_ID = "111"
private val OUTER_CAMERA_PROTECTION_INFO =
TestableProtectionInfo(
@@ -121,7 +121,7 @@ class CameraProtectionLoaderImplTest : SysuiTestCase() {
private const val INNER_CAMERA_PHYSICAL_ID = "22"
private const val INNER_CAMERA_PROTECTION_PATH = "M 0,0 H 20,20 V 20,20 H 0,20 Z"
private val INNER_CAMERA_PROTECTION_BOUNDS =
- Rect(/* left = */ 0, /* top = */ 0, /* right = */ 20, /* bottom = */ 20)
+ Rect(/* left= */ 0, /* top= */ 0, /* right= */ 20, /* bottom= */ 20)
private const val INNER_SCREEN_UNIQUE_ID = "222"
private val INNER_CAMERA_PROTECTION_INFO =
TestableProtectionInfo(
diff --git a/packages/SystemUI/tests/src/com/android/systemui/SysUICutoutProviderTest.kt b/packages/SystemUI/tests/src/com/android/systemui/SysUICutoutProviderTest.kt
index 61c7e1d63e51..ef33210dd6b7 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/SysUICutoutProviderTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/SysUICutoutProviderTest.kt
@@ -42,7 +42,7 @@ class SysUICutoutProviderTest : SysuiTestCase() {
fun cutoutInfoForCurrentDisplay_noCutout_returnsNull() {
val noCutoutDisplay = createDisplay(cutout = null)
val noCutoutDisplayContext = context.createDisplayContext(noCutoutDisplay)
- val provider = SysUICutoutProvider(noCutoutDisplayContext, fakeProtectionLoader)
+ val provider = SysUICutoutProviderImpl(noCutoutDisplayContext, fakeProtectionLoader)
val sysUICutout = provider.cutoutInfoForCurrentDisplayAndRotation()
@@ -53,7 +53,7 @@ class SysUICutoutProviderTest : SysuiTestCase() {
fun cutoutInfoForCurrentDisplay_returnsCutout() {
val cutoutDisplay = createDisplay()
val cutoutDisplayContext = context.createDisplayContext(cutoutDisplay)
- val provider = SysUICutoutProvider(cutoutDisplayContext, fakeProtectionLoader)
+ val provider = SysUICutoutProviderImpl(cutoutDisplayContext, fakeProtectionLoader)
val sysUICutout = provider.cutoutInfoForCurrentDisplayAndRotation()!!
@@ -64,7 +64,7 @@ class SysUICutoutProviderTest : SysuiTestCase() {
fun cutoutInfoForCurrentDisplay_noAssociatedProtection_returnsNoProtection() {
val cutoutDisplay = createDisplay()
val cutoutDisplayContext = context.createDisplayContext(cutoutDisplay)
- val provider = SysUICutoutProvider(cutoutDisplayContext, fakeProtectionLoader)
+ val provider = SysUICutoutProviderImpl(cutoutDisplayContext, fakeProtectionLoader)
val sysUICutout = provider.cutoutInfoForCurrentDisplayAndRotation()!!
@@ -75,7 +75,7 @@ class SysUICutoutProviderTest : SysuiTestCase() {
fun cutoutInfoForCurrentDisplay_outerDisplay_protectionAssociated_returnsProtection() {
fakeProtectionLoader.addOuterCameraProtection(displayUniqueId = OUTER_DISPLAY_UNIQUE_ID)
val outerDisplayContext = context.createDisplayContext(OUTER_DISPLAY)
- val provider = SysUICutoutProvider(outerDisplayContext, fakeProtectionLoader)
+ val provider = SysUICutoutProviderImpl(outerDisplayContext, fakeProtectionLoader)
val sysUICutout = provider.cutoutInfoForCurrentDisplayAndRotation()!!
@@ -86,7 +86,7 @@ class SysUICutoutProviderTest : SysuiTestCase() {
fun cutoutInfoForCurrentDisplay_outerDisplay_protectionNotAvailable_returnsNullProtection() {
fakeProtectionLoader.clearProtectionInfoList()
val outerDisplayContext = context.createDisplayContext(OUTER_DISPLAY)
- val provider = SysUICutoutProvider(outerDisplayContext, fakeProtectionLoader)
+ val provider = SysUICutoutProviderImpl(outerDisplayContext, fakeProtectionLoader)
val sysUICutout = provider.cutoutInfoForCurrentDisplayAndRotation()!!
@@ -97,7 +97,7 @@ class SysUICutoutProviderTest : SysuiTestCase() {
fun cutoutInfoForCurrentDisplay_displayWithNullId_protectionsWithNoId_returnsNullProtection() {
fakeProtectionLoader.addOuterCameraProtection(displayUniqueId = "")
val displayContext = context.createDisplayContext(createDisplay(uniqueId = null))
- val provider = SysUICutoutProvider(displayContext, fakeProtectionLoader)
+ val provider = SysUICutoutProviderImpl(displayContext, fakeProtectionLoader)
val sysUICutout = provider.cutoutInfoForCurrentDisplayAndRotation()!!
@@ -108,7 +108,7 @@ class SysUICutoutProviderTest : SysuiTestCase() {
fun cutoutInfoForCurrentDisplay_displayWithEmptyId_protectionsWithNoId_returnsNullProtection() {
fakeProtectionLoader.addOuterCameraProtection(displayUniqueId = "")
val displayContext = context.createDisplayContext(createDisplay(uniqueId = ""))
- val provider = SysUICutoutProvider(displayContext, fakeProtectionLoader)
+ val provider = SysUICutoutProviderImpl(displayContext, fakeProtectionLoader)
val sysUICutout = provider.cutoutInfoForCurrentDisplayAndRotation()!!
@@ -123,15 +123,13 @@ class SysUICutoutProviderTest : SysuiTestCase() {
displayHeight = 1000,
rotation = Surface.ROTATION_0,
protectionBounds =
- Rect(/* left = */ 440, /* top = */ 10, /* right = */ 490, /* bottom = */ 110)
+ Rect(/* left= */ 440, /* top= */ 10, /* right= */ 490, /* bottom= */ 110),
)
val sysUICutout = provider.cutoutInfoForCurrentDisplayAndRotation()!!
assertThat(sysUICutout.cameraProtection!!.bounds)
- .isEqualTo(
- Rect(/* left = */ 440, /* top = */ 10, /* right = */ 490, /* bottom = */ 110)
- )
+ .isEqualTo(Rect(/* left= */ 440, /* top= */ 10, /* right= */ 490, /* bottom= */ 110))
}
@Test
@@ -142,13 +140,13 @@ class SysUICutoutProviderTest : SysuiTestCase() {
displayHeight = 1000,
rotation = Surface.ROTATION_90,
protectionBounds =
- Rect(/* left = */ 440, /* top = */ 10, /* right = */ 490, /* bottom = */ 110)
+ Rect(/* left= */ 440, /* top= */ 10, /* right= */ 490, /* bottom= */ 110),
)
val sysUICutout = provider.cutoutInfoForCurrentDisplayAndRotation()!!
assertThat(sysUICutout.cameraProtection!!.bounds)
- .isEqualTo(Rect(/* left = */ 10, /* top = */ 10, /* right = */ 110, /* bottom = */ 60))
+ .isEqualTo(Rect(/* left= */ 10, /* top= */ 10, /* right= */ 110, /* bottom= */ 60))
}
@Test
@@ -156,7 +154,7 @@ class SysUICutoutProviderTest : SysuiTestCase() {
val displayNaturalWidth = 500
val displayNaturalHeight = 1000
val originalProtectionBounds =
- Rect(/* left = */ 440, /* top = */ 10, /* right = */ 490, /* bottom = */ 110)
+ Rect(/* left= */ 440, /* top= */ 10, /* right= */ 490, /* bottom= */ 110)
// Safe copy as we don't know at which layer the mutation could happen
val originalProtectionBoundsCopy = Rect(originalProtectionBounds)
val display =
@@ -168,10 +166,10 @@ class SysUICutoutProviderTest : SysuiTestCase() {
)
fakeProtectionLoader.addOuterCameraProtection(
displayUniqueId = OUTER_DISPLAY_UNIQUE_ID,
- bounds = originalProtectionBounds
+ bounds = originalProtectionBounds,
)
val provider =
- SysUICutoutProvider(context.createDisplayContext(display), fakeProtectionLoader)
+ SysUICutoutProviderImpl(context.createDisplayContext(display), fakeProtectionLoader)
// Here we get the rotated bounds once
provider.cutoutInfoForCurrentDisplayAndRotation()
@@ -194,13 +192,13 @@ class SysUICutoutProviderTest : SysuiTestCase() {
displayHeight = 1000,
rotation = Surface.ROTATION_180,
protectionBounds =
- Rect(/* left = */ 440, /* top = */ 10, /* right = */ 490, /* bottom = */ 110)
+ Rect(/* left= */ 440, /* top= */ 10, /* right= */ 490, /* bottom= */ 110),
)
val sysUICutout = provider.cutoutInfoForCurrentDisplayAndRotation()!!
assertThat(sysUICutout.cameraProtection!!.bounds)
- .isEqualTo(Rect(/* left = */ 10, /* top = */ 890, /* right = */ 60, /* bottom = */ 990))
+ .isEqualTo(Rect(/* left= */ 10, /* top= */ 890, /* right= */ 60, /* bottom= */ 990))
}
@Test
@@ -211,15 +209,13 @@ class SysUICutoutProviderTest : SysuiTestCase() {
displayHeight = 1000,
rotation = Surface.ROTATION_270,
protectionBounds =
- Rect(/* left = */ 440, /* top = */ 10, /* right = */ 490, /* bottom = */ 110)
+ Rect(/* left= */ 440, /* top= */ 10, /* right= */ 490, /* bottom= */ 110),
)
val sysUICutout = provider.cutoutInfoForCurrentDisplayAndRotation()!!
assertThat(sysUICutout.cameraProtection!!.bounds)
- .isEqualTo(
- Rect(/* left = */ 890, /* top = */ 440, /* right = */ 990, /* bottom = */ 490)
- )
+ .isEqualTo(Rect(/* left= */ 890, /* top= */ 440, /* right= */ 990, /* bottom= */ 490))
}
private fun setUpProviderWithCameraProtection(
@@ -245,9 +241,9 @@ class SysUICutoutProviderTest : SysuiTestCase() {
)
fakeProtectionLoader.addOuterCameraProtection(
displayUniqueId = OUTER_DISPLAY_UNIQUE_ID,
- bounds = protectionBounds
+ bounds = protectionBounds,
)
- return SysUICutoutProvider(context.createDisplayContext(display), fakeProtectionLoader)
+ return SysUICutoutProviderImpl(context.createDisplayContext(display), fakeProtectionLoader)
}
companion object {
@@ -259,7 +255,7 @@ class SysUICutoutProviderTest : SysuiTestCase() {
height: Int = 1000,
@Rotation rotation: Int = Surface.ROTATION_0,
uniqueId: String? = "uniqueId",
- cutout: DisplayCutout? = mock<DisplayCutout>()
+ cutout: DisplayCutout? = mock<DisplayCutout>(),
) =
mock<Display> {
whenever(this.getDisplayInfo(any())).thenAnswer {