[CameraPipe] Handle out-of-range zoom value

  If zoom ratio is attempted to be set to larger than max zoom ratio or smaller than min zoom ratio, CameraPipe should set IllegalArgumentException with proper error message to the returned listenable future, and similar for linear zoom as well.

Bug: 262225455
Test: camera-pipe / ZoomControlDeviceTest
Change-Id: I3db21742dc47833ef6bf4426b08f07aef566925a
diff --git a/camera/camera-camera2-pipe-integration/src/main/java/androidx/camera/camera2/pipe/integration/impl/ZoomControl.kt b/camera/camera-camera2-pipe-integration/src/main/java/androidx/camera/camera2/pipe/integration/impl/ZoomControl.kt
index 3c6df78..66fbb27 100644
--- a/camera/camera-camera2-pipe-integration/src/main/java/androidx/camera/camera2/pipe/integration/impl/ZoomControl.kt
+++ b/camera/camera-camera2-pipe-integration/src/main/java/androidx/camera/camera2/pipe/integration/impl/ZoomControl.kt
@@ -109,6 +109,14 @@
     }
 
     fun setLinearZoom(linearZoom: Float): ListenableFuture<Void> {
+        if (linearZoom > 1.0f || linearZoom < 0f) {
+            val outOfRangeDesc =
+                "Requested linearZoom $linearZoom is not within valid range [0, 1]"
+            return Futures.immediateFailedFuture(
+                IllegalArgumentException(outOfRangeDesc)
+            )
+        }
+
         val zoomValue = ZoomValue(
             ZoomValue.LinearZoom(linearZoom),
             minZoomRatio,
@@ -118,6 +126,15 @@
     }
 
     fun setZoomRatio(zoomRatio: Float): ListenableFuture<Void> {
+        if (zoomRatio > maxZoomRatio || zoomRatio < minZoomRatio) {
+            val outOfRangeDesc =
+                "Requested zoomRatio $zoomRatio is not within valid range" +
+                    " [$minZoomRatio, $maxZoomRatio]"
+            return Futures.immediateFailedFuture(
+                IllegalArgumentException(outOfRangeDesc)
+            )
+        }
+
         val zoomValue = ZoomValue(
             zoomRatio,
             minZoomRatio,
diff --git a/camera/camera-camera2-pipe-integration/src/test/java/androidx/camera/camera2/pipe/integration/impl/ZoomControlTest.kt b/camera/camera-camera2-pipe-integration/src/test/java/androidx/camera/camera2/pipe/integration/impl/ZoomControlTest.kt
index f1b057a..1abf1d4 100644
--- a/camera/camera-camera2-pipe-integration/src/test/java/androidx/camera/camera2/pipe/integration/impl/ZoomControlTest.kt
+++ b/camera/camera-camera2-pipe-integration/src/test/java/androidx/camera/camera2/pipe/integration/impl/ZoomControlTest.kt
@@ -54,7 +54,7 @@
         )
     }
 
-    private val zoomCompat = FakeZoomCompat()
+    private val zoomCompat = FakeZoomCompat(1.0f, 5.0f)
     private lateinit var zoomControl: ZoomControl
 
     @Before
diff --git a/camera/integration-tests/coretestapp/src/androidTest/java/androidx/camera/integration/core/ZoomControlDeviceTest.kt b/camera/integration-tests/coretestapp/src/androidTest/java/androidx/camera/integration/core/ZoomControlDeviceTest.kt
index 0d7512c..1b89972 100644
--- a/camera/integration-tests/coretestapp/src/androidTest/java/androidx/camera/integration/core/ZoomControlDeviceTest.kt
+++ b/camera/integration-tests/coretestapp/src/androidTest/java/androidx/camera/integration/core/ZoomControlDeviceTest.kt
@@ -174,11 +174,6 @@
 
     @Test
     fun setZoomRatio_largerThanMax_zoomUnmodified() = runBlocking {
-        assumeFalse(
-            "b/262225455: CameraPipe does not yet handle zoom value outside available range",
-            implName == "CameraPipeConfig"
-        )
-
         assumeTrue(2.0f <= cameraInfo.zoomState.value!!.maxZoomRatio + DELTA)
         cameraControl.setZoomRatio(2.0f)[5, TimeUnit.SECONDS]
 
@@ -198,11 +193,6 @@
 
     @Test
     fun setZoomRatio_largerThanMax_OutOfRangeException() = runBlocking {
-        assumeFalse(
-            "b/262225455: CameraPipe does not yet handle zoom value outside available range",
-            implName == "CameraPipeConfig"
-        )
-
         val maxZoomRatio = cameraInfo.zoomState.value!!.maxZoomRatio
         val result = cameraControl.setZoomRatio(maxZoomRatio + 1.0f)
 
@@ -211,11 +201,6 @@
 
     @Test
     fun setZoomRatio_smallerThanMin_zoomUnmodified() = runBlocking {
-        assumeFalse(
-            "b/262225455: CameraPipe does not yet handle zoom value outside available range",
-            implName == "CameraPipeConfig"
-        )
-
         assumeTrue(2.0f <= cameraInfo.zoomState.value!!.maxZoomRatio + DELTA)
         cameraControl.setZoomRatio(2.0f)[5, TimeUnit.SECONDS]
 
@@ -235,11 +220,6 @@
 
     @Test
     fun setZoomRatio_smallerThanMin_OutOfRangeException() = runBlocking {
-        assumeFalse(
-            "b/262225455: CameraPipe does not yet handle zoom value outside available range",
-            implName == "CameraPipeConfig"
-        )
-
         val minZoomRatio = cameraInfo.zoomState.value!!.minZoomRatio
         val result = cameraControl.setZoomRatio(minZoomRatio - 1.0f)
 
@@ -436,11 +416,6 @@
 
     @Test
     fun setLinearZoom_largerThan1_zoomUnmodified() = runBlocking {
-        assumeFalse(
-            "b/262225455: CameraPipe does not yet handle zoom value outside available range",
-            implName == "CameraPipeConfig"
-        )
-
         cameraControl.setLinearZoom(0.5f)[5, TimeUnit.SECONDS]
 
         /**
@@ -457,11 +432,6 @@
 
     @Test
     fun setLinearZoom_largerThan1_outOfRangeException() = runBlocking {
-        assumeFalse(
-            "b/262225455: CameraPipe does not yet handle zoom value outside available range",
-            implName == "CameraPipeConfig"
-        )
-
         val result = cameraControl.setLinearZoom(1.1f)
 
         assertFutureThrowsIllegalArgumentException(result)
@@ -469,11 +439,6 @@
 
     @Test
     fun setLinearZoom_smallerThan0_zoomUnmodified() = runBlocking {
-        assumeFalse(
-            "b/262225455: CameraPipe does not yet handle zoom value outside available range",
-            implName == "CameraPipeConfig"
-        )
-
         cameraControl.setLinearZoom(0.5f)[5, TimeUnit.SECONDS]
 
         /**
@@ -490,11 +455,6 @@
 
     @Test
     fun setLinearZoom_smallerThan0_outOfRangeException() = runBlocking {
-        assumeFalse(
-            "b/262225455: CameraPipe does not yet handle zoom value outside available range",
-            implName == "CameraPipeConfig"
-        )
-
         val result = cameraControl.setLinearZoom(-0.1f)
 
         assertFutureThrowsIllegalArgumentException(result)