Add an API for setting a new brightness curve.

In addition, this also provides multiple strategies for mapping from
ambient room brightness in lux to display brightness. The default one is
the classic strategy, where we map directly from lux to backlight
brightness in an arbitrary unit. The newer and preferred strategy is to
use the physical brightness of the display, but requires that the
brightness properties of the display are appropriately configured.

Bug: 69406783
Test: atest com.android.server.display.BrightnessMappingStrategyTest &&
      atest android.hardware.display.BrightnessConfigurationTest &&
      atest android.hardware.display.PersistentDataStoreTeset

Change-Id: I60227bdb6c299d0fa92686cbf3e5994b336a3a79
diff --git a/core/java/com/android/internal/util/Preconditions.java b/core/java/com/android/internal/util/Preconditions.java
index e5d5716..91c76af 100644
--- a/core/java/com/android/internal/util/Preconditions.java
+++ b/core/java/com/android/internal/util/Preconditions.java
@@ -494,4 +494,38 @@
 
         return value;
     }
+
+    /**
+     * Ensures that all elements in the argument integer array are within the inclusive range
+     *
+     * @param value an integer array of values
+     * @param lower the lower endpoint of the inclusive range
+     * @param upper the upper endpoint of the inclusive range
+     * @param valueName the name of the argument to use if the check fails
+     *
+     * @return the validated integer array
+     *
+     * @throws IllegalArgumentException if any of the elements in {@code value} were out of range
+     * @throws NullPointerException if the {@code value} was {@code null}
+     */
+    public static int[] checkArrayElementsInRange(int[] value, int lower, int upper,
+            String valueName) {
+        checkNotNull(value, valueName + " must not be null");
+
+        for (int i = 0; i < value.length; ++i) {
+            int v = value[i];
+
+            if (v < lower) {
+                throw new IllegalArgumentException(
+                        String.format("%s[%d] is out of range of [%d, %d] (too low)",
+                                valueName, i, lower, upper));
+            } else if (v > upper) {
+                throw new IllegalArgumentException(
+                        String.format("%s[%d] is out of range of [%d, %d] (too high)",
+                                valueName, i, lower, upper));
+            }
+        }
+
+        return value;
+    }
 }