bluetooth: Skip test if AdvMonitor API is not supported

If AdvMonitor API is not supported by the platform,
AdvertisementMonitorManager1 interface won't be exposed by
bluetoothd. In such case, skip the test and raise TestNA.

BUG=b:175626931, b:174529428, b:173153478
TEST=1. Load custom bluetoothd where it does not expose MonitorManager1
        interface, run bluetooth_AdapterAdvMonitor tests and verify tests
        do not complete and raise TestNA exceptipon.
     2. Load TOT bluetoothd, run bluetooth_AdapterAdvMonitor tests and
        verify all tests pass.

Change-Id: I5f8be72d78adc9b55ef85d5d619b03d72ecad970
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/2591821
Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Reviewed-by: Yun-Hao Chung <howardchung@google.com>
Commit-Queue: Manish Mandlik <mmandlik@chromium.org>
Tested-by: Manish Mandlik <mmandlik@chromium.org>
diff --git a/client/cros/multimedia/bluetooth_facade_native.py b/client/cros/multimedia/bluetooth_facade_native.py
index 0b7cf33..63ba703 100644
--- a/client/cros/multimedia/bluetooth_facade_native.py
+++ b/client/cros/multimedia/bluetooth_facade_native.py
@@ -2162,6 +2162,22 @@
 
         return self.dbus_cb_msg
 
+
+    def advmon_check_manager_interface_exist(self):
+        """Check if AdvertisementMonitorManager1 interface is available.
+
+        @returns: True if Manager interface is available, False otherwise.
+
+        """
+        objects = self._bluez.GetManagedObjects(
+                dbus_interface=self.BLUEZ_MANAGER_IFACE)
+        for _, ifaces in six.iteritems(objects):
+            if self.BLUEZ_ADV_MONITOR_MANAGER_IFACE in ifaces:
+                return True
+
+        return False
+
+
     def advmon_read_supported_types(self):
         """Read the Advertisement Monitor supported monitor types.
 
diff --git a/server/cros/bluetooth/bluetooth_adapter_adv_monitor_tests.py b/server/cros/bluetooth/bluetooth_adapter_adv_monitor_tests.py
index fba45b9..645ba9e 100644
--- a/server/cros/bluetooth/bluetooth_adapter_adv_monitor_tests.py
+++ b/server/cros/bluetooth/bluetooth_adapter_adv_monitor_tests.py
@@ -10,6 +10,7 @@
 
 from autotest_lib.client.bin import utils
 from autotest_lib.server.cros.bluetooth import bluetooth_adapter_tests
+from autotest_lib.client.common_lib import error
 
 
 class TestMonitor():
@@ -151,6 +152,15 @@
     test_retry_and_log = bluetooth_adapter_tests.test_retry_and_log
 
 
+    def advmon_check_manager_interface_exist(self):
+        """Check if AdvertisementMonitorManager1 interface is available.
+
+        @returns: True if Manager interface is available, False otherwise.
+
+        """
+        return self.bluetooth_facade.advmon_check_manager_interface_exist()
+
+
     def read_supported_types(self):
         """Read the Advertisement Monitor supported monitor types.
 
@@ -350,6 +360,21 @@
         return True
 
 
+    def test_is_adv_monitoring_supported(self):
+        """Check if Adv Monitor API is supported.
+
+            If AdvMonitor API is not supported by the platform,
+            AdvertisementMonitorManager1 interface won't be exposed by
+            bluetoothd. In such case, skip the test and raise TestNA.
+
+            @raises: TestNA if Adv Monitor API is not supported.
+
+        """
+        if not self.advmon_check_manager_interface_exist():
+            logging.info('Advertisement Monitor API not supported')
+            raise error.TestNAError('Advertisement Monitor API not supported')
+
+
     @test_retry_and_log(False)
     def test_exit_app(self, app_id):
         """Test exit application.
@@ -902,6 +927,8 @@
         Validate register/unregister app and create/remove monitor.
 
         """
+        self.test_is_adv_monitoring_supported()
+
         # Create a test app instance.
         app1 = self.create_app()
 
@@ -966,6 +993,8 @@
         values.
 
         """
+        self.test_is_adv_monitoring_supported()
+
         # Create a test app instance.
         app1 = self.create_app()
 
@@ -1076,6 +1105,7 @@
         different AD Data Types - Local Name Service UUID and Device Type.
 
         """
+        self.test_is_adv_monitoring_supported()
         self.test_setup_peer_devices()
 
         # Create a test app instance.
@@ -1171,6 +1201,7 @@
         Verify unset RSSI filter and filter with no matching RSSI values.
 
         """
+        self.test_is_adv_monitoring_supported()
         self.test_setup_peer_devices()
 
         # Create a test app instance.
@@ -1224,6 +1255,7 @@
         Verify RSSI filter matching with multiple peer devices.
 
         """
+        self.test_is_adv_monitoring_supported()
         self.test_setup_peer_devices()
 
         # Create a test app instance.
@@ -1288,6 +1320,7 @@
         Verify reset of RSSI timers based on advertisements.
 
         """
+        self.test_is_adv_monitoring_supported()
         self.test_setup_peer_devices()
 
         # Create a test app instance.
@@ -1355,6 +1388,7 @@
         clients and multiple monitors.
 
         """
+        self.test_is_adv_monitoring_supported()
         self.test_setup_peer_devices()
 
         # Create two test app instances.
@@ -1441,6 +1475,7 @@
         working of each other.
 
         """
+        self.test_is_adv_monitoring_supported()
         self.test_setup_peer_devices()
 
         # Create a test app instance.
@@ -1527,6 +1562,7 @@
         Verify working of background scanning with suspend/resume.
 
         """
+        self.test_is_adv_monitoring_supported()
         self.test_setup_peer_devices()
 
         # Create two test app instances.
@@ -1602,6 +1638,8 @@
     def advmon_test_interleaved_scan(self):
         """ Test cases for verifying interleave scan """
 
+        self.test_is_adv_monitoring_supported()
+
         # cycles to collect logs for tests expect no interleave scan
         EXPECT_FALSE_TEST_CYCLE = 3
 
diff --git a/server/cros/bluetooth/bluetooth_device.py b/server/cros/bluetooth/bluetooth_device.py
index 625017c..4a1fcab 100644
--- a/server/cros/bluetooth/bluetooth_device.py
+++ b/server/cros/bluetooth/bluetooth_device.py
@@ -860,6 +860,16 @@
 
 
     @proxy_thread_safe
+    def advmon_check_manager_interface_exist(self):
+        """Check if AdvertisementMonitorManager1 interface is available.
+
+        @returns: True if Manager interface is available, False otherwise.
+
+        """
+        return self._proxy.advmon_check_manager_interface_exist()
+
+
+    @proxy_thread_safe
     def advmon_read_supported_types(self):
         """Read the Advertisement Monitor supported monitor types.