Return status for the setters API

Bug: 375472716
Test: atest VtsHalMediaQualityTargetTest
Flag: android.media.tv.flags.media_quality_fw
Change-Id: I6e163c464b86263c87b3a8050118ba1432894b41
diff --git a/tv/mediaquality/aidl/android/hardware/tv/mediaquality/IMediaQuality.aidl b/tv/mediaquality/aidl/android/hardware/tv/mediaquality/IMediaQuality.aidl
index 75af9d4..3da1495 100644
--- a/tv/mediaquality/aidl/android/hardware/tv/mediaquality/IMediaQuality.aidl
+++ b/tv/mediaquality/aidl/android/hardware/tv/mediaquality/IMediaQuality.aidl
@@ -55,6 +55,9 @@
      * device as configured before.
      *
      * @param enabled True to enable the ambient backlight detection, false to disable.
+     *
+     * @return Status::ok on success
+     *         UNSUPPORTED_OPERATION if this functionality is unsupported.
      */
     void setAmbientBacklightDetectionEnabled(in boolean enabled);
 
@@ -88,6 +91,9 @@
      * parameters depends on the current content playing.
      *
      * @param enable True to enable, false to disable.
+     *
+     * @return Status::ok on success
+     *         UNSUPPORTED_OPERATION if this functionality is unsupported.
      */
     void setAutoPqEnabled(boolean enable);
 
@@ -112,6 +118,9 @@
      * lower resolution image and invent the missing pixel to make the image looks sharper.
      *
      * @param enable True to enable, false to disable.
+     *
+     * @return Status::ok on success
+     *         UNSUPPORTED_OPERATION if this functionality is unsupported.
      */
     void setAutoSrEnabled(boolean enable);
 
@@ -136,6 +145,9 @@
      * adjust the sound parameters depends on the current content playing.
      *
      * @param enable True to enable, false to disable.
+     *
+     * @return Status::ok on success
+     *         UNSUPPORTED_OPERATION if this functionality is unsupported.
      */
     void setAutoAqEnabled(boolean enable);
 
diff --git a/tv/mediaquality/aidl/default/hal/media_quality_hal_impl.rs b/tv/mediaquality/aidl/default/hal/media_quality_hal_impl.rs
index d6edf91..eeec51c 100644
--- a/tv/mediaquality/aidl/default/hal/media_quality_hal_impl.rs
+++ b/tv/mediaquality/aidl/default/hal/media_quality_hal_impl.rs
@@ -32,12 +32,14 @@
     VendorParameterIdentifier::VendorParameterIdentifier,
 };
 use binder::{Interface, Strong};
+use binder::ExceptionCode;
 use std::sync::{Arc, Mutex};
 use std::thread;
 
 /// Defined so we can implement the IMediaQuality AIDL interface.
 pub struct MediaQualityService {
     callback: Arc<Mutex<Option<Strong<dyn IMediaQualityCallback>>>>,
+    ambient_backlight_supported: Arc<Mutex<bool>>,
     ambient_backlight_enabled: Arc<Mutex<bool>>,
     ambient_backlight_detector_settings: Arc<Mutex<AmbientBacklightSettings>>,
     auto_pq_supported: Arc<Mutex<bool>>,
@@ -60,6 +62,7 @@
     pub fn new() -> Self {
         Self {
             callback: Arc::new(Mutex::new(None)),
+            ambient_backlight_supported: Arc::new(Mutex::new(false)),
             ambient_backlight_enabled: Arc::new(Mutex::new(true)),
             ambient_backlight_detector_settings:
                     Arc::new(Mutex::new(AmbientBacklightSettings::default())),
@@ -111,31 +114,37 @@
     fn setAmbientBacklightDetectionEnabled(&self, enabled: bool) -> binder::Result<()> {
         println!("Received enabled: {}", enabled);
         let mut ambient_backlight_enabled = self.ambient_backlight_enabled.lock().unwrap();
+        let ambient_backlight_supported = self.ambient_backlight_supported.lock().unwrap();
         *ambient_backlight_enabled = enabled;
-        if enabled {
-            println!("Enable Ambient Backlight detection");
-            thread::scope(|s| {
-                s.spawn(|| {
-                    let cb = self.callback.lock().unwrap();
-                    if let Some(cb) = &*cb {
-                        let enabled_event = AmbientBacklightEvent::Enabled(true);
-                        cb.notifyAmbientBacklightEvent(&enabled_event).unwrap();
-                    }
+
+        if *ambient_backlight_supported {
+            if enabled {
+                println!("Enable Ambient Backlight detection");
+                thread::scope(|s| {
+                    s.spawn(|| {
+                        let cb = self.callback.lock().unwrap();
+                        if let Some(cb) = &*cb {
+                            let enabled_event = AmbientBacklightEvent::Enabled(true);
+                            cb.notifyAmbientBacklightEvent(&enabled_event).unwrap();
+                        }
+                    });
                 });
-            });
+            } else {
+                println!("Disable Ambient Backlight detection");
+                thread::scope(|s| {
+                    s.spawn(|| {
+                        let cb = self.callback.lock().unwrap();
+                        if let Some(cb) = &*cb {
+                            let disabled_event = AmbientBacklightEvent::Enabled(false);
+                            cb.notifyAmbientBacklightEvent(&disabled_event).unwrap();
+                        }
+                    });
+                });
+            }
+            return Ok(());
         } else {
-            println!("Disable Ambient Backlight detection");
-            thread::scope(|s| {
-                s.spawn(|| {
-                    let cb = self.callback.lock().unwrap();
-                    if let Some(cb) = &*cb {
-                        let disabled_event = AmbientBacklightEvent::Enabled(false);
-                        cb.notifyAmbientBacklightEvent(&disabled_event).unwrap();
-                    }
-                });
-            });
+            return Err(ExceptionCode::UNSUPPORTED_OPERATION.into());
         }
-        Ok(())
     }
 
     fn getAmbientBacklightDetectionEnabled(&self) -> binder::Result<bool> {
@@ -155,13 +164,19 @@
 
     fn setAutoPqEnabled(&self, enabled: bool) -> binder::Result<()> {
         let mut auto_pq_enabled = self.auto_pq_enabled.lock().unwrap();
+        let auto_pq_supported = self.auto_pq_supported.lock().unwrap();
         *auto_pq_enabled = enabled;
-        if enabled {
-            println!("Enable auto picture quality");
+
+        if *auto_pq_supported {
+            if enabled {
+                println!("Enable auto picture quality");
+            } else {
+                println!("Disable auto picture quality");
+            }
+            return Ok(());
         } else {
-            println!("Disable auto picture quality");
+            return Err(ExceptionCode::UNSUPPORTED_OPERATION.into());
         }
-        Ok(())
     }
 
     fn isAutoSrSupported(&self) -> binder::Result<bool> {
@@ -176,13 +191,19 @@
 
     fn setAutoSrEnabled(&self, enabled: bool) -> binder::Result<()> {
         let mut auto_sr_enabled = self.auto_sr_enabled.lock().unwrap();
+        let auto_sr_supported = self.auto_sr_supported.lock().unwrap();
         *auto_sr_enabled = enabled;
-        if enabled {
-            println!("Enable auto super resolution");
+
+        if *auto_sr_supported {
+            if enabled {
+                println!("Enable auto super resolution");
+            } else {
+                println!("Disable auto super resolution");
+            }
+            return Ok(());
         } else {
-            println!("Disable auto super resolution");
+            return Err(ExceptionCode::UNSUPPORTED_OPERATION.into());
         }
-        Ok(())
     }
 
     fn isAutoAqSupported(&self) -> binder::Result<bool> {
@@ -197,13 +218,19 @@
 
     fn setAutoAqEnabled(&self, enabled: bool) -> binder::Result<()> {
         let mut auto_aq_enabled = self.auto_aq_enabled.lock().unwrap();
+        let auto_aq_supported = self.auto_aq_supported.lock().unwrap();
         *auto_aq_enabled = enabled;
-        if enabled {
-            println!("Enable auto audio quality");
+
+        if *auto_aq_supported {
+            if enabled {
+                println!("Enable auto audio quality");
+            } else {
+                println!("Disable auto audio quality");
+            }
+            return Ok(());
         } else {
-            println!("Disable auto audio quality");
+            return Err(ExceptionCode::UNSUPPORTED_OPERATION.into());
         }
-        Ok(())
     }
 
     fn getPictureProfileListener(&self) -> binder::Result<binder::Strong<dyn IPictureProfileChangedListener>> {