Aperture: Allow removing video configurations via overlays

On some devices we can't rely on aeAvailableTargetFpsRanges to tell us
what ranges will work properly for given resolution.

Change-Id: I7fc43f3e8a0cd3f7eeccd2975f8bd442e539c8dd
diff --git a/app/src/main/java/org/lineageos/aperture/camera/Camera.kt b/app/src/main/java/org/lineageos/aperture/camera/Camera.kt
index bc662f0..f8cad35 100644
--- a/app/src/main/java/org/lineageos/aperture/camera/Camera.kt
+++ b/app/src/main/java/org/lineageos/aperture/camera/Camera.kt
@@ -75,9 +75,17 @@
         videoQualityForDynamicRanges.values.flatten().toSet().associateWith {
             VideoQualityInfo(
                 it,
-                supportedVideoFrameRates.plus(
-                    cameraManager.getAdditionalVideoFrameRates(cameraId, it)
-                ),
+                supportedVideoFrameRates.toMutableSet().apply {
+                    for ((frameRate, remove) in cameraManager.getAdditionalVideoFrameRates(
+                        cameraId, it
+                    )) {
+                        if (remove) {
+                            remove(frameRate)
+                        } else {
+                            add(frameRate)
+                        }
+                    }
+                }.toSet(),
                 videoQualityForDynamicRanges.entries.filter { dynamicRangeToQualities ->
                     dynamicRangeToQualities.value.contains(it)
                 }.map { dynamicRangeToQualities -> dynamicRangeToQualities.key }.toSet()
diff --git a/app/src/main/java/org/lineageos/aperture/camera/CameraManager.kt b/app/src/main/java/org/lineageos/aperture/camera/CameraManager.kt
index 7b68c8d..79329a9 100644
--- a/app/src/main/java/org/lineageos/aperture/camera/CameraManager.kt
+++ b/app/src/main/java/org/lineageos/aperture/camera/CameraManager.kt
@@ -18,6 +18,7 @@
 import org.lineageos.aperture.models.FrameRate
 import java.util.concurrent.ExecutorService
 import java.util.concurrent.Executors
+import kotlin.math.absoluteValue
 
 /**
  * Class managing an app camera session
@@ -30,7 +31,7 @@
     val cameraExecutor: ExecutorService = Executors.newSingleThreadExecutor()
 
     private val additionalVideoConfigurations by lazy {
-        mutableMapOf<String, MutableMap<Quality, MutableSet<FrameRate>>>().apply {
+        mutableMapOf<String, MutableMap<Quality, MutableMap<FrameRate, Boolean>>>().apply {
             context.resources.getStringArray(context, R.array.config_additionalVideoConfigurations)
                 .let {
                     if (it.size % 3 != 0) {
@@ -41,8 +42,10 @@
                     for (i in it.indices step 3) {
                         val cameraId = it[i]
                         val frameRates = it[i + 2].split("|").mapNotNull { frameRate ->
-                            FrameRate.fromValue(frameRate.toInt())
-                        }
+                            FrameRate.fromValue(frameRate.toInt().absoluteValue)?.let { value ->
+                                value to frameRate.startsWith('-')
+                            }
+                        }.toMap()
 
                         it[i + 1].split("|").mapNotNull { quality ->
                             when (quality) {
@@ -57,9 +60,9 @@
                                 this[cameraId] = mutableMapOf()
                             }
                             if (!this[cameraId]!!.containsKey(quality)) {
-                                this[cameraId]!![quality] = mutableSetOf()
+                                this[cameraId]!![quality] = mutableMapOf()
                             }
-                            this[cameraId]!![quality]!!.addAll(frameRates)
+                            this[cameraId]!![quality]!!.putAll(frameRates)
                         }
                     }
                 }
diff --git a/app/src/main/res/values/config.xml b/app/src/main/res/values/config.xml
index 3fe8772..39d9698 100644
--- a/app/src/main/res/values/config.xml
+++ b/app/src/main/res/values/config.xml
@@ -46,9 +46,11 @@
           - "30"
           - "60"
           - "120"
+         Additionally you can prepend `-` to frame rate to mark it as unsupported.
          Example:
              <string-array name="config_additionalVideoConfigurations">
                  <item>0</item> <item>sd|hd|fhd</item> <item>60|120</item>
+                 <item>0</item> <item>uhd</item> <item>-60</item>
                  <item>1</item> <item>sd|hd|fhd</item> <item>60</item>
              </string-array>
     -->