Merge "Add blacklist for camera protection" into rvc-dev am: 85ee54cc46
Change-Id: I3abad8e0af06d08440ddc71193afbe1132cc22f4
This commit is contained in:
@@ -530,6 +530,10 @@
|
|||||||
<!-- ID for the camera that needs extra protection -->
|
<!-- ID for the camera that needs extra protection -->
|
||||||
<string translatable="false" name="config_protectedCameraId"></string>
|
<string translatable="false" name="config_protectedCameraId"></string>
|
||||||
|
|
||||||
|
<!-- Comma-separated list of packages to exclude from camera protection e.g.
|
||||||
|
"com.android.systemui,com.android.xyz" -->
|
||||||
|
<string translatable="false" name="config_cameraProtectionExcludedPackages"></string>
|
||||||
|
|
||||||
<!-- Flag to turn on the rendering of the above path or not -->
|
<!-- Flag to turn on the rendering of the above path or not -->
|
||||||
<bool name="config_enableDisplayCutoutProtection">false</bool>
|
<bool name="config_enableDisplayCutoutProtection">false</bool>
|
||||||
|
|
||||||
|
|||||||
@@ -37,20 +37,22 @@ class CameraAvailabilityListener(
|
|||||||
private val cameraManager: CameraManager,
|
private val cameraManager: CameraManager,
|
||||||
private val cutoutProtectionPath: Path,
|
private val cutoutProtectionPath: Path,
|
||||||
private val targetCameraId: String,
|
private val targetCameraId: String,
|
||||||
|
excludedPackages: String,
|
||||||
private val executor: Executor
|
private val executor: Executor
|
||||||
) {
|
) {
|
||||||
private var cutoutBounds = Rect()
|
private var cutoutBounds = Rect()
|
||||||
|
private val excludedPackageIds: Set<String>
|
||||||
private val listeners = mutableListOf<CameraTransitionCallback>()
|
private val listeners = mutableListOf<CameraTransitionCallback>()
|
||||||
private val availabilityCallback: CameraManager.AvailabilityCallback =
|
private val availabilityCallback: CameraManager.AvailabilityCallback =
|
||||||
object : CameraManager.AvailabilityCallback() {
|
object : CameraManager.AvailabilityCallback() {
|
||||||
override fun onCameraAvailable(cameraId: String) {
|
override fun onCameraClosed(cameraId: String) {
|
||||||
if (targetCameraId == cameraId) {
|
if (targetCameraId == cameraId) {
|
||||||
notifyCameraInactive()
|
notifyCameraInactive()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCameraUnavailable(cameraId: String) {
|
override fun onCameraOpened(cameraId: String, packageId: String) {
|
||||||
if (targetCameraId == cameraId) {
|
if (targetCameraId == cameraId && !isExcluded(packageId)) {
|
||||||
notifyCameraActive()
|
notifyCameraActive()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,6 +66,7 @@ class CameraAvailabilityListener(
|
|||||||
computed.top.roundToInt(),
|
computed.top.roundToInt(),
|
||||||
computed.right.roundToInt(),
|
computed.right.roundToInt(),
|
||||||
computed.bottom.roundToInt())
|
computed.bottom.roundToInt())
|
||||||
|
excludedPackageIds = excludedPackages.split(",").toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,6 +90,10 @@ class CameraAvailabilityListener(
|
|||||||
listeners.remove(callback)
|
listeners.remove(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isExcluded(packageId: String): Boolean {
|
||||||
|
return excludedPackageIds.contains(packageId)
|
||||||
|
}
|
||||||
|
|
||||||
private fun registerCameraListener() {
|
private fun registerCameraListener() {
|
||||||
cameraManager.registerAvailabilityCallback(executor, availabilityCallback)
|
cameraManager.registerAvailabilityCallback(executor, availabilityCallback)
|
||||||
}
|
}
|
||||||
@@ -118,9 +125,10 @@ class CameraAvailabilityListener(
|
|||||||
val res = context.resources
|
val res = context.resources
|
||||||
val pathString = res.getString(R.string.config_frontBuiltInDisplayCutoutProtection)
|
val pathString = res.getString(R.string.config_frontBuiltInDisplayCutoutProtection)
|
||||||
val cameraId = res.getString(R.string.config_protectedCameraId)
|
val cameraId = res.getString(R.string.config_protectedCameraId)
|
||||||
|
val excluded = res.getString(R.string.config_cameraProtectionExcludedPackages)
|
||||||
|
|
||||||
return CameraAvailabilityListener(
|
return CameraAvailabilityListener(
|
||||||
manager, pathFromString(pathString), cameraId, executor)
|
manager, pathFromString(pathString), cameraId, excluded, executor)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun pathFromString(pathString: String): Path {
|
private fun pathFromString(pathString: String): Path {
|
||||||
|
|||||||
Reference in New Issue
Block a user