Merge "VtsHalRadioV1_4Target.setPreferredNetworkTypeBitmap" into android12L-tests-dev
diff --git a/broadcastradio/2.0/vts/OWNERS b/broadcastradio/2.0/vts/OWNERS
index 1ff7407..eb03052 100644
--- a/broadcastradio/2.0/vts/OWNERS
+++ b/broadcastradio/2.0/vts/OWNERS
@@ -1,6 +1,6 @@
 # Automotive team
-egranata@google.com
-twasilczyk@google.com
+xuweilin@google.com
+oscarazu@google.com
 
 # VTS team
 dshi@google.com
diff --git a/broadcastradio/2.0/vts/functional/VtsHalBroadcastradioV2_0TargetTest.cpp b/broadcastradio/2.0/vts/functional/VtsHalBroadcastradioV2_0TargetTest.cpp
index 362ab41..63e3b55 100644
--- a/broadcastradio/2.0/vts/functional/VtsHalBroadcastradioV2_0TargetTest.cpp
+++ b/broadcastradio/2.0/vts/functional/VtsHalBroadcastradioV2_0TargetTest.cpp
@@ -496,11 +496,66 @@
  *  - program changes exactly to what was requested.
  */
 TEST_P(BroadcastRadioHalTest, DabTune) {
+    Result halResult;
+    hidl_vec<DabTableEntry> config;
+    auto cb = [&](Result result, hidl_vec<DabTableEntry> configCb) {
+        halResult = result;
+        config = configCb;
+    };
+    auto hidlResult = mModule->getDabRegionConfig(cb);
+    ASSERT_TRUE(hidlResult.isOk());
+
+    if (halResult == Result::NOT_SUPPORTED) {
+        printSkipped("DAB not supported");
+        return;
+    }
+    ASSERT_EQ(Result::OK, halResult);
+    ASSERT_NE(config.size(), 0U);
+
     ASSERT_TRUE(openSession());
 
+    auto programList = getProgramList();
+
+    if (!programList) {
+        printSkipped("Empty Station-List, tune cannot be performed");
+        return;
+    }
+
     ProgramSelector sel = {};
-    uint64_t freq = 178352;
-    sel.primaryId = make_identifier(IdentifierType::DAB_FREQUENCY,freq);
+    uint64_t freq = 0;
+    bool dabStnPresent = false;
+
+    for (auto&& programInfo : *programList) {
+        if (utils::hasId(programInfo.selector, IdentifierType::DAB_FREQUENCY)) {
+            for (auto&& config_entry : config) {
+                if (config_entry.frequency == utils::getId(programInfo.selector,
+                    IdentifierType::DAB_FREQUENCY, 0)) {
+                    freq = config_entry.frequency;
+                    break;
+                }
+            }
+            // Do not trigger a tune request if the programList entry does not contain
+            // a valid DAB frequency
+            if (freq == 0) {
+              continue;
+            }
+            uint64_t dabSidExt = utils::getId(programInfo.selector, IdentifierType::DAB_SID_EXT, 0);
+            uint64_t dabEns = utils::getId(programInfo.selector, IdentifierType::DAB_ENSEMBLE, 0);
+            sel.primaryId = make_identifier(IdentifierType::DAB_SID_EXT, dabSidExt);
+            hidl_vec<ProgramIdentifier> secondaryIds = {
+                make_identifier(IdentifierType::DAB_ENSEMBLE, dabEns),
+                make_identifier(IdentifierType::DAB_FREQUENCY, freq)
+            };
+            sel.secondaryIds = secondaryIds;
+            dabStnPresent = true;
+            break;
+        }
+    }
+
+    if (!dabStnPresent) {
+        printSkipped("No DAB stations in the list, tune cannot be performed");
+        return;
+    }
 
     std::this_thread::sleep_for(gTuneWorkaround);