Merge "audio VTS: add tests for latency mode APIs"
diff --git a/audio/core/all-versions/vts/functional/7.1/AudioPrimaryHidlHalTest.cpp b/audio/core/all-versions/vts/functional/7.1/AudioPrimaryHidlHalTest.cpp
index d82d4ad..6b9b32d 100644
--- a/audio/core/all-versions/vts/functional/7.1/AudioPrimaryHidlHalTest.cpp
+++ b/audio/core/all-versions/vts/functional/7.1/AudioPrimaryHidlHalTest.cpp
@@ -47,3 +47,51 @@
     // initial state. To workaround this, destroy the HAL at the end of this test.
     ASSERT_TRUE(resetDevice());
 }
+class LatencyModeOutputStreamTest : public OutputStreamTest {
+  protected:
+    void SetUp() override {
+        OutputStreamTest::SetUp();
+
+        Result res;
+        EXPECT_OK(stream->getRecommendedLatencyModes(returnIn(res, mSupportedLatencyModes)));
+        EXPECT_RESULT(okOrNotSupported, res);
+        if (res == Result::NOT_SUPPORTED) {
+            GTEST_SKIP() << "latency mode is not supported";  // returns
+        }
+    }
+    hidl_vec<LatencyMode> mSupportedLatencyModes;
+};
+
+TEST_P(LatencyModeOutputStreamTest, GetRecommendedLatencyModes) {
+    doc::test("Verify that reported latency modes are valid when supported");
+    for (auto mode : mSupportedLatencyModes) {
+        ASSERT_TRUE(mode >= LatencyMode::FREE && mode <= LatencyMode::LOW);
+    }
+}
+
+TEST_P(LatencyModeOutputStreamTest, SetValidLatencyMode) {
+    doc::test("Verify that setting valid latency modes works when supported");
+    for (auto mode : mSupportedLatencyModes) {
+        EXPECT_OK(stream->setLatencyMode(mode));
+    }
+}
+
+TEST_P(LatencyModeOutputStreamTest, SetInValidLatencyMode) {
+    doc::test("Verify that setting invalid latency modes fails");
+    EXPECT_RESULT(invalidArgsOrNotSupported,
+            stream->setLatencyMode(static_cast<LatencyMode>(1977)));
+}
+
+/** Stub implementation of IStreamOutEventCallback **/
+class MockOutLatencyModeCallback : public IStreamOutLatencyModeCallback {
+    Return<void> onRecommendedLatencyModeChanged(
+            const hidl_vec<LatencyMode>& hidlModes __unused) override {
+        return {};
+    }
+};
+
+TEST_P(LatencyModeOutputStreamTest, SetLatencyModeCallback) {
+    doc::test("Verify that setting a latency mode callback works when supported");
+    EXPECT_OK(stream->setLatencyModeCallback(new MockOutLatencyModeCallback));
+    EXPECT_OK(stream->setLatencyModeCallback(nullptr));
+}
diff --git a/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h b/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h
index 404532a..c093b37 100644
--- a/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h
+++ b/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h
@@ -1010,6 +1010,7 @@
 
 class OutputStreamTest
     : public OpenStreamTest<::android::hardware::audio::CPP_VERSION::IStreamOut> {
+  protected:
     void SetUp() override {
         ASSERT_NO_FATAL_FAILURE(OpenStreamTest::SetUp());  // setup base
 #if MAJOR_VERSION <= 6
@@ -1035,7 +1036,6 @@
     }
 #if MAJOR_VERSION >= 4 && MAJOR_VERSION <= 6
 
-  protected:
     const SourceMetadata initMetadata = {
         { { AudioUsage::MEDIA,
             AudioContentType::MUSIC,