Check autobrightness enabled in BrightnessTest

This cl checks if a default brightnessconfiguration exists. This will
return null if automatic brightness controller is null, which only
happens if the oem has disabled autobrightness, not just the user.
We need to give this method permission to control display brightness
before calling this method.

If abc (and therefore brightnessconfiguration) doesnt exist, the
assumption fails and the test doesnt run.

Bug: 292023923
Test: atest BrightnessTest
Change-Id: I358678d731a95510fba7d4dd9d8dc29be3d2ff5c
(cherry picked from commit 8615d69b1d98967a28e80263ba1d798924fb95ed)
diff --git a/tests/tests/display/src/android/display/cts/BrightnessTest.java b/tests/tests/display/src/android/display/cts/BrightnessTest.java
index 016a0a2..ef647bd 100644
--- a/tests/tests/display/src/android/display/cts/BrightnessTest.java
+++ b/tests/tests/display/src/android/display/cts/BrightnessTest.java
@@ -92,6 +92,14 @@
         assumeTrue(
                 numberOfSystemAppsWithPermission(Manifest.permission.BRIGHTNESS_SLIDER_USAGE) > 0);
 
+        assumeTrue(
+                numberOfSystemAppsWithPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS)
+                    > 0);
+        grantPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS);
+        BrightnessConfiguration defaultConfig = mDisplayManager.getDefaultBrightnessConfiguration();
+        // This might be null, meaning that the device doesn't support autobrightness
+        assumeNotNull(defaultConfig);
+
         int previousBrightness = getSystemSetting(Settings.System.SCREEN_BRIGHTNESS);
         int previousBrightnessMode =
                 getSystemSetting(Settings.System.SCREEN_BRIGHTNESS_MODE);
@@ -145,6 +153,14 @@
         assumeTrue(
                 numberOfSystemAppsWithPermission(Manifest.permission.BRIGHTNESS_SLIDER_USAGE) > 0);
 
+        assumeTrue(
+                numberOfSystemAppsWithPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS)
+                    > 0);
+        grantPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS);
+        BrightnessConfiguration defaultConfig = mDisplayManager.getDefaultBrightnessConfiguration();
+        // This might be null, meaning that the device doesn't support autobrightness
+        assumeNotNull(defaultConfig);
+
         int previousBrightness = getSystemSetting(Settings.System.SCREEN_BRIGHTNESS);
         int previousBrightnessMode =
                 getSystemSetting(Settings.System.SCREEN_BRIGHTNESS_MODE);
@@ -235,6 +251,11 @@
                 Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS) > 0);
 
         grantPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS);
+
+        BrightnessConfiguration defaultConfig = mDisplayManager.getDefaultBrightnessConfiguration();
+        // This might be null, meaning that the device doesn't support autobrightness
+        assumeNotNull(defaultConfig);
+
         int previousBrightness = getSystemSetting(Settings.System.SCREEN_BRIGHTNESS);
         int previousBrightnessMode =
                 getSystemSetting(Settings.System.SCREEN_BRIGHTNESS_MODE);
@@ -395,6 +416,11 @@
         // Don't run as there is no app that has permission to push curves.
         assumeTrue(numberOfSystemAppsWithPermission(
                 Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS) > 0);
+        grantPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS);
+
+        BrightnessConfiguration defaultConfig = mDisplayManager.getDefaultBrightnessConfiguration();
+        // This might be null, meaning that the device doesn't support autobrightness
+        assumeNotNull(defaultConfig);
 
         BrightnessConfiguration config =
                 new BrightnessConfiguration.Builder(
@@ -411,7 +437,6 @@
             assertEquals(Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC, mode);
 
             grantPermission(Manifest.permission.BRIGHTNESS_SLIDER_USAGE);
-            grantPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS);
 
             // Setup and remember some initial state.
             recordSliderEvents();
@@ -492,6 +517,11 @@
                 Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS) > 0);
 
         grantPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS);
+
+        BrightnessConfiguration defaultConfig = mDisplayManager.getDefaultBrightnessConfiguration();
+        // This might be null, meaning that the device doesn't support autobrightness
+        assumeNotNull(defaultConfig);
+
         grantPermission(Manifest.permission.BRIGHTNESS_SLIDER_USAGE);
 
         BrightnessConfiguration previousConfig = mDisplayManager.getBrightnessConfiguration();