[settings] Handle auto brightness value field

Fixed: b/182478079
Test: fx test setui_service_tests

Change-Id: Ie38f57e87904ea53161aba39369553e04638cbfd
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/503554
Reviewed-by: William Xiao <wxyz@google.com>
Reviewed-by: Bryce Lee <brycelee@google.com>
Commit-Queue: Chip Fukuhara <cfukuhara@google.com>
diff --git a/garnet/bin/setui/src/agent/inspect.rs b/garnet/bin/setui/src/agent/inspect.rs
index 70ef6fe..2fa76d8 100644
--- a/garnet/bin/setui/src/agent/inspect.rs
+++ b/garnet/bin/setui/src/agent/inspect.rs
@@ -323,6 +323,7 @@
                         "00000000000000000000": {
                             request: "SetDisplayInfo(SetDisplayInfo { \
                                 manual_brightness_value: None, \
+                                auto_brightness_value: None, \
                                 auto_brightness: Some(false), \
                                 screen_enabled: None, \
                                 low_light_mode: None, \
@@ -333,6 +334,7 @@
                         "00000000000000000001": {
                             request: "SetDisplayInfo(SetDisplayInfo { \
                                 manual_brightness_value: None, \
+                                auto_brightness_value: None, \
                                 auto_brightness: Some(false), \
                                 screen_enabled: None, \
                                 low_light_mode: None, \
@@ -403,6 +405,7 @@
                         "00000000000000000000": {
                             request: "SetDisplayInfo(SetDisplayInfo { \
                                 manual_brightness_value: None, \
+                                auto_brightness_value: None, \
                                 auto_brightness: Some(false), \
                                 screen_enabled: None, \
                                 low_light_mode: None, \
@@ -413,6 +416,7 @@
                         "00000000000000000002": {
                             request: "SetDisplayInfo(SetDisplayInfo { \
                                 manual_brightness_value: None, \
+                                auto_brightness_value: None, \
                                 auto_brightness: Some(true), \
                                 screen_enabled: None, \
                                 low_light_mode: None, \
diff --git a/garnet/bin/setui/src/display/display_controller.rs b/garnet/bin/setui/src/display/display_controller.rs
index d81f65d8..7b293e0 100644
--- a/garnet/bin/setui/src/display/display_controller.rs
+++ b/garnet/bin/setui/src/display/display_controller.rs
@@ -25,14 +25,18 @@
 use lazy_static::lazy_static;
 use std::sync::Mutex;
 
+pub const DEFAULT_MANUAL_BRIGHTNESS_VALUE: f32 = 0.5;
+pub const DEFAULT_AUTO_BRIGHTNESS_VALUE: f32 = 0.5;
+
 lazy_static! {
     /// Default display used if no configuration is available.
     pub static ref DEFAULT_DISPLAY_INFO: DisplayInfo = DisplayInfo::new(
-        false,                 /*auto_brightness_enabled*/
-        0.5,                   /*brightness_value*/
-        true,                  /*screen_enabled*/
-        LowLightMode::Disable, /*low_light_mode*/
-        None,                  /*theme*/
+        false,                           /*auto_brightness_enabled*/
+        DEFAULT_MANUAL_BRIGHTNESS_VALUE, /*manual_brightness_value*/
+        DEFAULT_AUTO_BRIGHTNESS_VALUE,   /*auto_brightness_value*/
+        true,                            /*screen_enabled*/
+        LowLightMode::Disable,           /*low_light_mode*/
+        None,                            /*theme*/
     );
 }
 
@@ -77,7 +81,7 @@
 
     fn deserialize_from(value: &String) -> Self {
         Self::extract(&value)
-            .unwrap_or_else(|_| Self::from(DisplayInfoV4::deserialize_from(&value)))
+            .unwrap_or_else(|_| Self::from(DisplayInfoV5::deserialize_from(&value)))
     }
 }
 
@@ -87,17 +91,15 @@
     }
 }
 
-impl From<DisplayInfoV4> for DisplayInfo {
-    fn from(v4: DisplayInfoV4) -> Self {
+impl From<DisplayInfoV5> for DisplayInfo {
+    fn from(v5: DisplayInfoV5) -> Self {
         DisplayInfo {
-            auto_brightness: v4.auto_brightness,
-            manual_brightness_value: v4.manual_brightness_value,
-            screen_enabled: v4.screen_enabled,
-            low_light_mode: v4.low_light_mode,
-            theme: Some(Theme::new(
-                Some(v4.theme_type),
-                if v4.theme_type == ThemeType::Auto { ThemeMode::AUTO } else { ThemeMode::empty() },
-            )),
+            auto_brightness: v5.auto_brightness,
+            auto_brightness_value: DEFAULT_AUTO_BRIGHTNESS_VALUE,
+            manual_brightness_value: v5.manual_brightness_value,
+            screen_enabled: v5.screen_enabled,
+            low_light_mode: v5.low_light_mode,
+            theme: v5.theme,
         }
     }
 }
@@ -211,49 +213,6 @@
             }
             Request::SetDisplayInfo(mut set_display_info) => {
                 let display_info = self.client.read_setting::<DisplayInfo>().await;
-                if let Some(manual_brightness_value) = set_display_info.manual_brightness_value {
-                    if let (auto_brightness @ Some(true), screen_enabled)
-                    | (auto_brightness, screen_enabled @ Some(false)) =
-                        (set_display_info.auto_brightness, set_display_info.screen_enabled)
-                    {
-                        // Invalid argument combination
-                        return Some(Err(ControllerError::IncompatibleArguments {
-                            setting_type: SettingType::Display,
-                            main_arg: "manual_brightness_value".into(),
-                            other_args: "auto_brightness, screen_enabled".into(),
-                            values: format!(
-                                "{}, {:?}, {:?}",
-                                manual_brightness_value, auto_brightness, screen_enabled
-                            )
-                            .into(),
-                            reason:
-                                "When manual brightness is set, auto brightness must be off or \
-                             unset and screen must be enabled or unset"
-                                    .into(),
-                        }));
-                    }
-                    set_display_info.auto_brightness = Some(false);
-                    set_display_info.screen_enabled = Some(true);
-                } else if let Some(screen_enabled) = set_display_info.screen_enabled {
-                    // Set auto brightness to the opposite of the screen off state. If the screen is
-                    // turned off, auto brightness must be on so that the screen off component can
-                    // detect the changes. If the screen is turned on, the default behavior is to
-                    // turn it to full manual brightness.
-                    if let Some(auto_brightness) = set_display_info.auto_brightness {
-                        if screen_enabled == auto_brightness {
-                            // Invalid argument combination
-                            return Some(Err(ControllerError::IncompatibleArguments {
-                                setting_type: SettingType::Display,
-                                main_arg: "screen_enabled".into(),
-                                other_args: "auto_brightness".into(),
-                                values: format!("{}, {}", screen_enabled, auto_brightness).into(),
-                                reason: "values cannot be equal".into(),
-                            }));
-                        }
-                    } else {
-                        set_display_info.auto_brightness = Some(!screen_enabled);
-                    }
-                }
 
                 if let Some(theme) = set_display_info.theme {
                     set_display_info.theme = self.build_theme(theme, &display_info);
@@ -340,9 +299,9 @@
 
     fn default_value() -> Self {
         DisplayInfoV1::new(
-            false,                 /*auto_brightness_enabled*/
-            0.5,                   /*brightness_value*/
-            LowLightMode::Disable, /*low_light_mode*/
+            false,                           /*auto_brightness_enabled*/
+            DEFAULT_MANUAL_BRIGHTNESS_VALUE, /*brightness_value*/
+            LowLightMode::Disable,           /*low_light_mode*/
         )
     }
 }
@@ -373,10 +332,10 @@
 
     fn default_value() -> Self {
         DisplayInfoV2::new(
-            false,                 /*auto_brightness_enabled*/
-            0.5,                   /*brightness_value*/
-            LowLightMode::Disable, /*low_light_mode*/
-            ThemeModeV1::Unknown,  /*theme_mode*/
+            false,                           /*auto_brightness_enabled*/
+            DEFAULT_MANUAL_BRIGHTNESS_VALUE, /*brightness_value*/
+            LowLightMode::Disable,           /*low_light_mode*/
+            ThemeModeV1::Unknown,            /*theme_mode*/
         )
     }
 
@@ -452,11 +411,11 @@
 
     fn default_value() -> Self {
         DisplayInfoV3::new(
-            false,                 /*auto_brightness_enabled*/
-            0.5,                   /*brightness_value*/
-            true,                  /*screen_enabled*/
-            LowLightMode::Disable, /*low_light_mode*/
-            ThemeModeV1::Unknown,  /*theme_mode*/
+            false,                           /*auto_brightness_enabled*/
+            DEFAULT_MANUAL_BRIGHTNESS_VALUE, /*brightness_value*/
+            true,                            /*screen_enabled*/
+            LowLightMode::Disable,           /*low_light_mode*/
+            ThemeModeV1::Unknown,            /*theme_mode*/
         )
     }
 
@@ -525,11 +484,11 @@
 
     fn default_value() -> Self {
         DisplayInfoV4::new(
-            false,                 /*auto_brightness_enabled*/
-            0.5,                   /*brightness_value*/
-            true,                  /*screen_enabled*/
-            LowLightMode::Disable, /*low_light_mode*/
-            ThemeType::Unknown,    /*theme_type*/
+            false,                           /*auto_brightness_enabled*/
+            DEFAULT_MANUAL_BRIGHTNESS_VALUE, /*brightness_value*/
+            true,                            /*screen_enabled*/
+            LowLightMode::Disable,           /*low_light_mode*/
+            ThemeType::Unknown,              /*theme_type*/
         )
     }
 
@@ -539,6 +498,69 @@
     }
 }
 
+#[derive(PartialEq, Debug, Clone, Copy, Serialize, Deserialize)]
+#[serde(deny_unknown_fields)]
+pub struct DisplayInfoV5 {
+    /// The last brightness value that was manually set.
+    pub manual_brightness_value: f32,
+    pub auto_brightness: bool,
+    pub screen_enabled: bool,
+    pub low_light_mode: LowLightMode,
+    pub theme: Option<Theme>,
+}
+
+impl DisplayInfoV5 {
+    pub const fn new(
+        auto_brightness: bool,
+        manual_brightness_value: f32,
+        screen_enabled: bool,
+        low_light_mode: LowLightMode,
+        theme: Option<Theme>,
+    ) -> DisplayInfoV5 {
+        DisplayInfoV5 {
+            manual_brightness_value,
+            auto_brightness,
+            screen_enabled,
+            low_light_mode,
+            theme,
+        }
+    }
+}
+
+impl From<DisplayInfoV4> for DisplayInfoV5 {
+    fn from(v4: DisplayInfoV4) -> Self {
+        DisplayInfoV5 {
+            auto_brightness: v4.auto_brightness,
+            manual_brightness_value: v4.manual_brightness_value,
+            screen_enabled: v4.screen_enabled,
+            low_light_mode: v4.low_light_mode,
+            theme: Some(Theme::new(
+                Some(v4.theme_type),
+                if v4.theme_type == ThemeType::Auto { ThemeMode::AUTO } else { ThemeMode::empty() },
+            )),
+        }
+    }
+}
+
+impl DeviceStorageCompatible for DisplayInfoV5 {
+    const KEY: &'static str = "display_info";
+
+    fn default_value() -> Self {
+        DisplayInfoV5::new(
+            false,                                                          /*auto_brightness_enabled*/
+            DEFAULT_MANUAL_BRIGHTNESS_VALUE,                                /*brightness_value*/
+            true,                                                           /*screen_enabled*/
+            LowLightMode::Disable,                                          /*low_light_mode*/
+            Some(Theme::new(Some(ThemeType::Unknown), ThemeMode::empty())), /*theme_type*/
+        )
+    }
+
+    fn deserialize_from(value: &String) -> Self {
+        Self::extract(&value)
+            .unwrap_or_else(|_| Self::from(DisplayInfoV4::deserialize_from(&value)))
+    }
+}
+
 #[test]
 fn test_display_migration_v1_to_v2() {
     let v1 = DisplayInfoV1 {
@@ -612,6 +634,31 @@
 }
 
 #[test]
+fn test_display_migration_v4_to_v5() {
+    let v4 = DisplayInfoV4 {
+        manual_brightness_value: 0.7,
+        auto_brightness: true,
+        low_light_mode: LowLightMode::Enable,
+        theme_type: ThemeType::Auto,
+        screen_enabled: false,
+    };
+
+    let serialized_v4 = v4.serialize_to();
+    let v5 = DisplayInfoV5::deserialize_from(&serialized_v4);
+
+    assert_eq!(
+        v5,
+        DisplayInfoV5 {
+            manual_brightness_value: v4.manual_brightness_value,
+            auto_brightness: v4.auto_brightness,
+            low_light_mode: v4.low_light_mode,
+            theme: Some(Theme::new(Some(v4.theme_type), ThemeMode::AUTO)),
+            screen_enabled: v4.screen_enabled,
+        }
+    );
+}
+
+#[test]
 fn test_display_migration_v1_to_current() {
     let v1 = DisplayInfoV1 {
         manual_brightness_value: 0.6,
@@ -631,6 +678,7 @@
             theme: Some(Theme::new(Some(ThemeType::Unknown), ThemeMode::empty())),
             // screen_enabled was added in v3.
             screen_enabled: DisplayInfoV3::default_value().screen_enabled,
+            auto_brightness_value: DEFAULT_DISPLAY_INFO.auto_brightness_value,
         }
     );
 }
@@ -656,6 +704,7 @@
             theme: Some(Theme::new(Some(ThemeType::Light), ThemeMode::empty())),
             // screen_enabled was added in v3.
             screen_enabled: DisplayInfoV3::default_value().screen_enabled,
+            auto_brightness_value: DEFAULT_DISPLAY_INFO.auto_brightness_value,
         }
     );
 }
@@ -682,6 +731,7 @@
             theme: Some(Theme::new(Some(ThemeType::Light), ThemeMode::empty())),
             // screen_enabled was added in v3.
             screen_enabled: v3.screen_enabled,
+            auto_brightness_value: DEFAULT_DISPLAY_INFO.auto_brightness_value,
         }
     );
 }
@@ -707,6 +757,33 @@
             low_light_mode: v4.low_light_mode,
             theme: Some(Theme::new(Some(ThemeType::Light), ThemeMode::empty())),
             screen_enabled: v4.screen_enabled,
+            auto_brightness_value: DEFAULT_DISPLAY_INFO.auto_brightness_value,
+        }
+    );
+}
+
+#[test]
+fn test_display_migration_v5_to_current() {
+    let v5 = DisplayInfoV5 {
+        manual_brightness_value: 0.6,
+        auto_brightness: true,
+        low_light_mode: LowLightMode::Enable,
+        theme: Some(Theme::new(Some(ThemeType::Light), ThemeMode::AUTO)),
+        screen_enabled: false,
+    };
+
+    let serialized_v5 = v5.serialize_to();
+    let current = DisplayInfo::deserialize_from(&serialized_v5);
+
+    assert_eq!(
+        current,
+        DisplayInfo {
+            manual_brightness_value: v5.manual_brightness_value,
+            auto_brightness: v5.auto_brightness,
+            low_light_mode: v5.low_light_mode,
+            theme: Some(Theme::new(Some(ThemeType::Light), ThemeMode::AUTO)),
+            screen_enabled: v5.screen_enabled,
+            auto_brightness_value: DEFAULT_DISPLAY_INFO.auto_brightness_value,
         }
     );
 }
diff --git a/garnet/bin/setui/src/display/display_fidl_handler.rs b/garnet/bin/setui/src/display/display_fidl_handler.rs
index 2284892..1c416c2 100644
--- a/garnet/bin/setui/src/display/display_fidl_handler.rs
+++ b/garnet/bin/setui/src/display/display_fidl_handler.rs
@@ -88,18 +88,15 @@
             let mut display_settings = fidl_fuchsia_settings::DisplaySettings::EMPTY;
 
             display_settings.auto_brightness = Some(info.auto_brightness);
+            display_settings.adjusted_auto_brightness = Some(info.auto_brightness_value);
+            display_settings.brightness_value = Some(info.manual_brightness_value);
+            display_settings.screen_enabled = Some(info.screen_enabled);
             display_settings.low_light_mode = Some(match info.low_light_mode {
                 LowLightMode::Enable => FidlLowLightMode::Enable,
                 LowLightMode::Disable => FidlLowLightMode::Disable,
                 LowLightMode::DisableImmediately => FidlLowLightMode::DisableImmediately,
             });
 
-            if !info.auto_brightness {
-                display_settings.brightness_value = Some(info.manual_brightness_value);
-            }
-
-            display_settings.screen_enabled = Some(info.screen_enabled);
-
             display_settings.theme = Some(FidlTheme {
                 theme_type: match info.theme {
                     Some(Theme { theme_type: Some(theme_type), .. }) => match theme_type {
@@ -130,6 +127,7 @@
 fn to_request(settings: DisplaySettings) -> Option<Request> {
     let set_display_info = SetDisplayInfo {
         manual_brightness_value: settings.brightness_value,
+        auto_brightness_value: settings.adjusted_auto_brightness,
         auto_brightness: settings.auto_brightness,
         screen_enabled: settings.screen_enabled,
         low_light_mode: settings.low_light_mode.map(Into::into),
@@ -139,6 +137,7 @@
         // No values being set is invalid
         SetDisplayInfo {
             manual_brightness_value: None,
+            auto_brightness_value: None,
             auto_brightness: None,
             screen_enabled: None,
             low_light_mode: None,
diff --git a/garnet/bin/setui/src/display/types.rs b/garnet/bin/setui/src/display/types.rs
index 9a9c490..ba438bf 100644
--- a/garnet/bin/setui/src/display/types.rs
+++ b/garnet/bin/setui/src/display/types.rs
@@ -12,6 +12,7 @@
 pub struct DisplayInfo {
     /// The last brightness value that was manually set.
     pub manual_brightness_value: f32,
+    pub auto_brightness_value: f32,
     pub auto_brightness: bool,
     pub screen_enabled: bool,
     pub low_light_mode: LowLightMode,
@@ -22,12 +23,14 @@
     pub const fn new(
         auto_brightness: bool,
         manual_brightness_value: f32,
+        auto_brightness_value: f32,
         screen_enabled: bool,
         low_light_mode: LowLightMode,
         theme: Option<Theme>,
     ) -> DisplayInfo {
         DisplayInfo {
             manual_brightness_value,
+            auto_brightness_value,
             auto_brightness,
             screen_enabled,
             low_light_mode,
@@ -39,6 +42,7 @@
 #[derive(Debug, Default, PartialEq, Copy, Clone)]
 pub struct SetDisplayInfo {
     pub manual_brightness_value: Option<f32>,
+    pub auto_brightness_value: Option<f32>,
     pub auto_brightness: Option<bool>,
     pub screen_enabled: Option<bool>,
     pub low_light_mode: Option<LowLightMode>,
@@ -51,6 +55,9 @@
             manual_brightness_value: other
                 .manual_brightness_value
                 .unwrap_or(self.manual_brightness_value),
+            auto_brightness_value: other
+                .auto_brightness_value
+                .unwrap_or(self.auto_brightness_value),
             auto_brightness: other.auto_brightness.unwrap_or(self.auto_brightness),
             screen_enabled: other.screen_enabled.unwrap_or(self.screen_enabled),
             low_light_mode: other.low_light_mode.unwrap_or(self.low_light_mode),
diff --git a/garnet/bin/setui/src/hanging_get_handler.rs b/garnet/bin/setui/src/hanging_get_handler.rs
index 6807015..da93aad 100644
--- a/garnet/bin/setui/src/hanging_get_handler.rs
+++ b/garnet/bin/setui/src/hanging_get_handler.rs
@@ -372,6 +372,7 @@
     const ID2: f32 = 2.0;
 
     const SET_ERROR: &str = "set failure";
+    const DEFAULT_AUTO_BRIGHTNESS_VALUE: f32 = 0.5;
 
     #[derive(PartialEq, Debug, Clone)]
     struct TestStruct {
@@ -482,6 +483,7 @@
                         Payload::Response(Ok(Some(SettingInfo::Brightness(DisplayInfo::new(
                             false,
                             value,
+                            DEFAULT_AUTO_BRIGHTNESS_VALUE,
                             true,
                             LowLightMode::Disable,
                             None,
@@ -511,6 +513,7 @@
                         response = Some(Ok(Some(SettingInfo::Brightness(DisplayInfo::new(
                             false,
                             value,
+                            DEFAULT_AUTO_BRIGHTNESS_VALUE,
                             true,
                             LowLightMode::Disable,
                             None,
diff --git a/garnet/bin/setui/src/tests/display_tests.rs b/garnet/bin/setui/src/tests/display_tests.rs
index 2723032..7104f962 100644
--- a/garnet/bin/setui/src/tests/display_tests.rs
+++ b/garnet/bin/setui/src/tests/display_tests.rs
@@ -32,6 +32,7 @@
 const ENV_NAME: &str = "settings_service_display_test_environment";
 const STARTING_BRIGHTNESS: f32 = 0.5;
 const CHANGED_BRIGHTNESS: f32 = 0.8;
+const AUTO_BRIGHTNESS_LEVEL: f32 = 0.9;
 
 async fn setup_display_env() -> DisplayProxy {
     let env = EnvironmentBuilder::new(Arc::new(InMemoryStorageFactory::new()))
@@ -121,11 +122,13 @@
 
     let mut display_settings = DisplaySettings::EMPTY;
     display_settings.auto_brightness = Some(true);
+    display_settings.adjusted_auto_brightness = Some(AUTO_BRIGHTNESS_LEVEL);
     display_proxy.set(display_settings).await.expect("set completed").expect("set successful");
 
     let settings = display_proxy.watch().await.expect("watch completed");
 
     assert_eq!(settings.auto_brightness, Some(true));
+    assert_eq!(settings.adjusted_auto_brightness, Some(AUTO_BRIGHTNESS_LEVEL));
 }
 
 // Tests that the FIDL calls for auto brightness result in appropriate
@@ -136,10 +139,12 @@
 
     let mut display_settings = DisplaySettings::EMPTY;
     display_settings.auto_brightness = Some(true);
+    display_settings.adjusted_auto_brightness = Some(AUTO_BRIGHTNESS_LEVEL);
     display_proxy.set(display_settings).await.expect("set completed").expect("set successful");
 
     let settings = display_proxy.watch().await.expect("watch completed");
     assert_eq!(settings.auto_brightness, Some(true));
+    assert_eq!(settings.adjusted_auto_brightness, Some(AUTO_BRIGHTNESS_LEVEL));
 
     let auto_brightness =
         brightness_service_handle.get_auto_brightness().lock().await.expect("get successful");
@@ -412,14 +417,31 @@
 #[fuchsia_async::run_until_stalled(test)]
 async fn test_display_restore_with_storage_controller() {
     // Ensure auto-brightness value is restored correctly.
-    validate_restore_with_storage_controller(0.7, true, true, LowLightMode::Enable, None).await;
+    validate_restore_with_storage_controller(
+        0.7,
+        AUTO_BRIGHTNESS_LEVEL,
+        true,
+        true,
+        LowLightMode::Enable,
+        None,
+    )
+    .await;
 
     // Ensure manual-brightness value is restored correctly.
-    validate_restore_with_storage_controller(0.9, false, true, LowLightMode::Disable, None).await;
+    validate_restore_with_storage_controller(
+        0.9,
+        AUTO_BRIGHTNESS_LEVEL,
+        false,
+        true,
+        LowLightMode::Disable,
+        None,
+    )
+    .await;
 }
 
 async fn validate_restore_with_storage_controller(
     manual_brightness: f32,
+    auto_brightness_value: f32,
     auto_brightness: bool,
     screen_enabled: bool,
     low_light_mode: LowLightMode,
@@ -428,6 +450,7 @@
     let service_registry = ServiceRegistry::create();
     let info = DisplayInfo {
         manual_brightness_value: manual_brightness,
+        auto_brightness_value,
         auto_brightness,
         screen_enabled,
         low_light_mode,
@@ -450,6 +473,7 @@
 
     if auto_brightness {
         assert_eq!(settings.auto_brightness, Some(auto_brightness));
+        assert_eq!(settings.adjusted_auto_brightness, Some(auto_brightness_value));
     } else {
         assert_eq!(settings.brightness_value, Some(manual_brightness));
     }
@@ -459,15 +483,31 @@
 #[fuchsia_async::run_until_stalled(test)]
 async fn test_display_restore_with_brightness_controller() {
     // Ensure auto-brightness value is restored correctly.
-    validate_restore_with_brightness_controller(0.7, true, true, LowLightMode::Enable, None).await;
+    validate_restore_with_brightness_controller(
+        0.7,
+        AUTO_BRIGHTNESS_LEVEL,
+        true,
+        true,
+        LowLightMode::Enable,
+        None,
+    )
+    .await;
 
     // Ensure manual-brightness value is restored correctly.
-    validate_restore_with_brightness_controller(0.9, false, true, LowLightMode::Disable, None)
-        .await;
+    validate_restore_with_brightness_controller(
+        0.9,
+        AUTO_BRIGHTNESS_LEVEL,
+        false,
+        true,
+        LowLightMode::Disable,
+        None,
+    )
+    .await;
 }
 
 async fn validate_restore_with_brightness_controller(
     manual_brightness: f32,
+    auto_brightness_value: f32,
     auto_brightness: bool,
     screen_enabled: bool,
     low_light_mode: LowLightMode,
@@ -481,6 +521,7 @@
         .register_service(Arc::new(Mutex::new(brightness_service_handle.clone())));
     let info = DisplayInfo {
         manual_brightness_value: manual_brightness,
+        auto_brightness_value,
         auto_brightness,
         screen_enabled,
         low_light_mode,
@@ -588,6 +629,7 @@
     let settings = DisplaySettings {
         auto_brightness: Some(false),
         brightness_value: Some(0.5),
+        adjusted_auto_brightness: Some(0.5),
         low_light_mode: Some(FidlLowLightMode::Enable),
         screen_enabled: Some(true),
         theme: Some(FidlTheme {
@@ -603,19 +645,18 @@
     assert_eq!(settings_result, settings);
 }
 
-// Validate that we cannot set auto_brightness to true or screen_enabled to false
-// when a brightness value is manually set. All other combinations should be ok.
 async_property_test!(test_set_multiple_fields_brightness => [
-    error_case_1(Some(0.5), Some(true), Some(true), false),
-    error_case_2(Some(0.5), Some(true), Some(false), false),
-    error_case_3(Some(0.5), Some(false), Some(false), false),
-    success_case_1(Some(0.5), Some(false), Some(true), true),
-    success_case_2(Some(0.5), None, Some(true), true),
-    success_case_3(Some(0.5), Some(false), None, true),
-    success_case_4(Some(0.5), None, None, true),
+    success_case_1(Some(0.7), Some(AUTO_BRIGHTNESS_LEVEL), Some(false), Some(true), true),
+    success_case_2(Some(0.7), Some(AUTO_BRIGHTNESS_LEVEL), None, Some(true), true),
+    success_case_3(Some(0.7), Some(AUTO_BRIGHTNESS_LEVEL), Some(false), None, true),
+    success_case_4(Some(0.7), Some(AUTO_BRIGHTNESS_LEVEL), None, None, true),
+    success_case_5(Some(0.7), Some(AUTO_BRIGHTNESS_LEVEL), Some(true), Some(true), true),
+    success_case_6(Some(0.7), Some(AUTO_BRIGHTNESS_LEVEL), Some(true), Some(false), true),
+    success_case_7(Some(0.7), Some(AUTO_BRIGHTNESS_LEVEL), Some(false), Some(false), true),
 ]);
 async fn test_set_multiple_fields_brightness(
     brightness_value: Option<f32>,
+    adjusted_auto_brightness: Option<f32>,
     auto_brightness: Option<bool>,
     screen_enabled: Option<bool>,
     expect_success: bool,
@@ -624,6 +665,7 @@
 
     let settings = DisplaySettings {
         auto_brightness,
+        adjusted_auto_brightness,
         brightness_value,
         screen_enabled,
         ..DisplaySettings::EMPTY
@@ -635,54 +677,22 @@
         assert_eq!(
             settings,
             DisplaySettings {
-                auto_brightness: Some(false),
-                brightness_value,
-                screen_enabled: Some(true),
-                // Default values untouched.
-                low_light_mode: Some(FidlLowLightMode::Disable),
-                theme: Some(FidlTheme {
-                    theme_type: Some(FidlThemeType::Light),
-                    theme_mode: Some(FidlThemeMode::Auto),
-                    ..FidlTheme::EMPTY
-                }),
-                ..DisplaySettings::EMPTY
-            }
-        );
-    } else {
-        assert_eq!(result, Err(FidlError::Failed));
-    }
-}
-
-// Validate that we cannot set screen_enabled and auto_brightness to the same
-// value. Another other combination is ok.
-async_property_test!(test_set_multiple_fields_auto_brightness => [
-    error_case_1(Some(true), Some(true), false),
-    error_case_2(Some(false), Some(false), false),
-    success_case_1(Some(true), Some(false), true),
-    success_case_2(Some(false), Some(true), true),
-]);
-async fn test_set_multiple_fields_auto_brightness(
-    screen_enabled: Option<bool>,
-    auto_brightness: Option<bool>,
-    expect_success: bool,
-) {
-    let display_proxy = setup_display_env().await;
-
-    let settings = DisplaySettings { screen_enabled, auto_brightness, ..DisplaySettings::EMPTY };
-    let result = display_proxy.set(settings).await.expect("set completed");
-    if expect_success {
-        assert!(result.is_ok());
-        let settings = display_proxy.watch().await.expect("watch completed");
-        assert_eq!(
-            settings,
-            DisplaySettings {
-                auto_brightness,
-                screen_enabled,
-                brightness_value: auto_brightness.and_then(|auto| if auto {
-                    None
+                auto_brightness: if auto_brightness.is_none() {
+                    Some(false)
                 } else {
+                    auto_brightness
+                },
+                adjusted_auto_brightness: if adjusted_auto_brightness.is_none() {
                     Some(0.5)
-                }),
+                } else {
+                    adjusted_auto_brightness
+                },
+                brightness_value: if brightness_value.is_none() {
+                    Some(0.5)
+                } else {
+                    brightness_value
+                },
+                screen_enabled: if screen_enabled.is_none() { Some(true) } else { screen_enabled },
                 // Default values untouched.
                 low_light_mode: Some(FidlLowLightMode::Disable),
                 theme: Some(FidlTheme {