Merge changes from topic "freeze-aosp-hal" into rvc-dev

* changes:
  Freeze vintf aidl interfaces
  android.hardware.tests.extension.vibrator-update-api
  vibrator ext: use package name as module name
diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/proto/Android.bp b/automotive/vehicle/2.0/default/impl/vhal_v2_0/proto/Android.bp
index 9784f75..31ba8ab 100644
--- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/proto/Android.bp
+++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/proto/Android.bp
@@ -40,29 +40,6 @@
     ],
 }
 
-cc_library_static {
-    name: "android.hardware.automotive.vehicle@2.0-grpc",
-    vendor: true,
-    include_dirs: [
-        "external/protobuf/src",
-    ],
-    generated_headers: [
-        "DefaultVehicleHalProtoStub_h",
-    ],
-    export_generated_headers: [
-        "DefaultVehicleHalProtoStub_h",
-    ],
-    generated_sources: [
-        "DefaultVehicleHalProtoStub_cc",
-    ],
-    shared_libs: [
-        "libgrpc++_unsecure",
-    ],
-    cflags: [
-        "-Wno-unused-parameter",
-    ],
-}
-
 genrule {
     name: "DefaultVehicleHalProtoStub_h",
     tools: [
@@ -72,13 +49,10 @@
     cmd: "$(location aprotoc) -I$$(dirname $(in)) -Iexternal/protobuf/src --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-cpp-plugin) $(in) --grpc_out=$(genDir) --cpp_out=$(genDir)",
     srcs: [
         "VehicleHalProto.proto",
-        "VehicleServer.proto",
     ],
     out: [
         "VehicleHalProto.pb.h",
         "VehicleHalProto.grpc.pb.h",
-        "VehicleServer.pb.h",
-        "VehicleServer.grpc.pb.h",
     ],
 }
 
@@ -91,12 +65,9 @@
     cmd: "$(location aprotoc) -I$$(dirname $(in)) -Iexternal/protobuf/src --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-cpp-plugin) $(in) --grpc_out=$(genDir) --cpp_out=$(genDir)",
     srcs: [
         "VehicleHalProto.proto",
-        "VehicleServer.proto",
     ],
     out: [
         "VehicleHalProto.pb.cc",
         "VehicleHalProto.grpc.pb.cc",
-        "VehicleServer.pb.cc",
-        "VehicleServer.grpc.pb.cc",
     ],
 }
diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/proto/VehicleServer.proto b/automotive/vehicle/2.0/default/impl/vhal_v2_0/proto/VehicleServer.proto
deleted file mode 100644
index 6f71d65..0000000
--- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/proto/VehicleServer.proto
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-syntax = "proto3";
-
-package vhal_proto;
-
-import "google/protobuf/empty.proto";
-import "VehicleHalProto.proto";
-
-// correspond to StatusCode defined in types.hal
-enum VehicleHalStatusCode {
-    OK                                  = 0;
-    TRY_AGAIN                           = 1;
-    INVALID_ARG                         = 2;
-    NOT_AVAILABLE                       = 3;
-    ACCESS_DENIED                       = 4;
-    INTERNAL_ERROR                      = 5;
-}
-
-message VehicleHalCallStatus {
-    VehicleHalStatusCode status_code    = 1;
-}
-
-message WrappedVehiclePropValue {
-    VehiclePropValue value              = 1;
-    // An indicator on whether we should update the status of the property
-    //   - true: if the value is generated by (emulated/real) car, or;
-    //           if the value is injected to 'fake' a on car event (for debugging purpose)
-    //   - false: if the value is set by VHal (public interface), since Android
-    //            cannot change status of property on a real car
-    bool update_status                  = 2;
-}
-
-service VehicleServer {
-    rpc GetAllPropertyConfig(google.protobuf.Empty) returns (stream VehiclePropConfig) {}
-
-    // Change the property value of the vehicle
-    rpc SetProperty(WrappedVehiclePropValue) returns (VehicleHalCallStatus) {}
-
-    // Start a vehicle property value stream
-    rpc StartPropertyValuesStream(google.protobuf.Empty) returns (stream WrappedVehiclePropValue) {}
-}
-
diff --git a/compatibility_matrices/compatibility_matrix.5.xml b/compatibility_matrices/compatibility_matrix.5.xml
index ff4083f..30c1572 100644
--- a/compatibility_matrices/compatibility_matrix.5.xml
+++ b/compatibility_matrices/compatibility_matrix.5.xml
@@ -72,7 +72,7 @@
         <name>android.hardware.automotive.sv</name>
         <version>1.0</version>
         <interface>
-            <name>ISurroundViewService</name>
+            <name>ISurroundView</name>
             <instance>default</instance>
         </interface>
     </hal>
diff --git a/current.txt b/current.txt
index 2677eb1..656f5c7 100644
--- a/current.txt
+++ b/current.txt
@@ -711,7 +711,7 @@
 278817920bfd5292a7713f97f1832cca53de3de640f7670e413d97c6e7fd581c android.hardware.neuralnetworks@1.3::IDevice
 127ba11efb8220dc3aec9a8f441b59eaf1c68d7f03f577833e1824de75a36b17 android.hardware.neuralnetworks@1.3::IExecutionCallback
 6e904be0ddca5ae1de8eba020e6c38ed935ea7d80cd08f47787f137a0ca58555 android.hardware.neuralnetworks@1.3::IFencedExecutionCallback
-2b0b10d2ea7a18a4048cd0eb83d35c19a817aeee95f65807fc31f4ef21381397 android.hardware.neuralnetworks@1.3::IPreparedModel
+ee9dc34b9925b8367b1111c72bd6d9d375432735e451572ca5a665d8516a7744 android.hardware.neuralnetworks@1.3::IPreparedModel
 eee3430cc86c97c7b407495863d8fb61da6f1a64b7721e77b9b4909b11b174e9 android.hardware.neuralnetworks@1.3::IPreparedModelCallback
 acf84925f8ee0a651f2ec547ac334034de266479b93af5434f6c1f25e66aba96 android.hardware.neuralnetworks@1.3::types
 b454df853441c12f6e425e8a60dd29fda20f5e6e39b93d1103e4b37495db38aa android.hardware.radio@1.5::IRadio
diff --git a/neuralnetworks/1.3/IPreparedModel.hal b/neuralnetworks/1.3/IPreparedModel.hal
index a1814b5..e7d63f4 100644
--- a/neuralnetworks/1.3/IPreparedModel.hal
+++ b/neuralnetworks/1.3/IPreparedModel.hal
@@ -92,13 +92,11 @@
      *                            executing a {@link OperationType::WHILE}
      *                            operation. If a loop condition model does not
      *                            output false within this duration, the
-     *                            execution must be aborted. If the model
-     *                            contains a {@link OperationType::WHILE}
-     *                            operation and no loop timeout duration is
-     *                            provided, the maximum amount of time is {@link
-     *                            LoopTimeoutDurationNs::DEFAULT}. When
-     *                            provided, the duration must not exceed {@link
-     *                            LoopTimeoutDurationNs::MAXIMUM}.
+     *                            execution must be aborted. If no loop timeout
+     *                            duration is provided, the maximum amount of
+     *                            time is {@link LoopTimeoutDurationNs::DEFAULT}.
+     *                            When provided, the duration must not exceed
+     *                            {@link LoopTimeoutDurationNs::MAXIMUM}.
      * @param callback A callback object used to return the error status of
      *                 the execution, shape information of model output operands, and
      *                 duration of execution. The callback object's notify function must
@@ -170,13 +168,11 @@
      *                            executing a {@link OperationType::WHILE}
      *                            operation. If a loop condition model does not
      *                            output false within this duration, the
-     *                            execution must be aborted. If the model
-     *                            contains a {@link OperationType::WHILE}
-     *                            operation and no loop timeout duration is
-     *                            provided, the maximum amount of time is {@link
-     *                            LoopTimeoutDurationNs::DEFAULT}. When
-     *                            provided, the duration must not exceed {@link
-     *                            LoopTimeoutDurationNs::MAXIMUM}.
+     *                            execution must be aborted. If no loop timeout
+     *                            duration is provided, the maximum amount of
+     *                            time is {@link LoopTimeoutDurationNs::DEFAULT}.
+     *                            When provided, the duration must not exceed
+     *                            {@link LoopTimeoutDurationNs::MAXIMUM}.
      * @return status Error status of the execution, must be:
      *                - NONE if execution is performed successfully
      *                - DEVICE_UNAVAILABLE if driver is offline or busy
@@ -258,13 +254,11 @@
      *                            executing a {@link OperationType::WHILE}
      *                            operation. If a loop condition model does not
      *                            output false within this duration, the
-     *                            execution must be aborted. If the model
-     *                            contains a {@link OperationType::WHILE}
-     *                            operation and no loop timeout duration is
-     *                            provided, the maximum amount of time is {@link
-     *                            LoopTimeoutDurationNs::DEFAULT}. When
-     *                            provided, the duration must not exceed {@link
-     *                            LoopTimeoutDurationNs::MAXIMUM}.
+     *                            execution must be aborted. If no loop timeout
+     *                            duration is provided, the maximum amount of
+     *                            time is {@link LoopTimeoutDurationNs::DEFAULT}.
+     *                            When provided, the duration must not exceed
+     *                            {@link LoopTimeoutDurationNs::MAXIMUM}.
      * @param duration The length of time within which the execution is expected
      *                 to complete after all sync fences in waitFor are signaled.
      *                 If the execution cannot be finished within the duration,
diff --git a/radio/1.3/vts/functional/radio_hidl_hal_test.cpp b/radio/1.3/vts/functional/radio_hidl_hal_test.cpp
index 4581350..c6e5550 100644
--- a/radio/1.3/vts/functional/radio_hidl_hal_test.cpp
+++ b/radio/1.3/vts/functional/radio_hidl_hal_test.cpp
@@ -38,9 +38,6 @@
     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_3->rspInfo.type);
     EXPECT_EQ(serial, radioRsp_v1_3->rspInfo.serial);
     EXPECT_EQ(RadioError::NONE, radioRsp_v1_3->rspInfo.error);
-
-    /* Enforce Vts Testing with Sim Status Present only. */
-    EXPECT_EQ(CardState::PRESENT, cardStatus.base.cardState);
 }
 
 /*
diff --git a/sensors/2.0/multihal/android.hardware.sensors@2.0-service-multihal.rc b/sensors/2.0/multihal/android.hardware.sensors@2.0-service-multihal.rc
index a4da3b0..0b3d4c2 100644
--- a/sensors/2.0/multihal/android.hardware.sensors@2.0-service-multihal.rc
+++ b/sensors/2.0/multihal/android.hardware.sensors@2.0-service-multihal.rc
@@ -1,7 +1,7 @@
 service vendor.sensors-hal-2-0-multihal /vendor/bin/hw/android.hardware.sensors@2.0-service.multihal
     class hal
     user system
-    group system wakelock
+    group system wakelock context_hub
     writepid /dev/cpuset/system-background/tasks
     capabilities BLOCK_SUSPEND
     rlimit rtprio 10 10
diff --git a/sensors/common/default/2.X/multihal/HalProxy.cpp b/sensors/common/default/2.X/multihal/HalProxy.cpp
index 518e138..869c033 100644
--- a/sensors/common/default/2.X/multihal/HalProxy.cpp
+++ b/sensors/common/default/2.X/multihal/HalProxy.cpp
@@ -260,9 +260,14 @@
                                           RateLevel rate, configDirectReport_cb _hidl_cb) {
     if (mDirectChannelSubHal == nullptr) {
         _hidl_cb(Result::INVALID_OPERATION, -1 /* reportToken */);
+    } else if (sensorHandle == -1 && rate != RateLevel::STOP) {
+        _hidl_cb(Result::BAD_VALUE, -1 /* reportToken */);
     } else {
-        mDirectChannelSubHal->configDirectReport(clearSubHalIndex(sensorHandle), channelHandle,
-                                                 rate, _hidl_cb);
+        // -1 denotes all sensors should be disabled
+        if (sensorHandle != -1) {
+            sensorHandle = clearSubHalIndex(sensorHandle);
+        }
+        mDirectChannelSubHal->configDirectReport(sensorHandle, channelHandle, rate, _hidl_cb);
     }
     return Return<void>();
 }
diff --git a/tv/tuner/1.0/default/Frontend.cpp b/tv/tuner/1.0/default/Frontend.cpp
index bb0d8dc..2cff9be 100644
--- a/tv/tuner/1.0/default/Frontend.cpp
+++ b/tv/tuner/1.0/default/Frontend.cpp
@@ -41,6 +41,7 @@
     ALOGV("%s", __FUNCTION__);
     // Reset callback
     mCallback = nullptr;
+    mIsLocked = false;
 
     return Result::SUCCESS;
 }
@@ -64,6 +65,7 @@
     }
 
     mCallback->onEvent(FrontendEventType::LOCKED);
+    mIsLocked = false;
     return Result::SUCCESS;
 }
 
@@ -71,16 +73,35 @@
     ALOGV("%s", __FUNCTION__);
 
     mTunerService->frontendStopTune(mId);
+    mIsLocked = false;
 
     return Result::SUCCESS;
 }
 
-Return<Result> Frontend::scan(const FrontendSettings& /* settings */, FrontendScanType /* type */) {
+Return<Result> Frontend::scan(const FrontendSettings& settings, FrontendScanType type) {
     ALOGV("%s", __FUNCTION__);
 
+    if (mType != FrontendType::DVBT) {
+        return Result::UNAVAILABLE;
+    }
+
     FrontendScanMessage msg;
+
+    if (mIsLocked) {
+        msg.isEnd(true);
+        mCallback->onScanMessage(FrontendScanMessageType::END, msg);
+        return Result::SUCCESS;
+    }
+
+    uint32_t frequency = settings.dvbt().frequency;
+    if (type == FrontendScanType::SCAN_BLIND) {
+        frequency += 100;
+    }
+    msg.frequencies({frequency});
+    mCallback->onScanMessage(FrontendScanMessageType::FREQUENCY, msg);
     msg.isLocked(true);
     mCallback->onScanMessage(FrontendScanMessageType::LOCKED, msg);
+    mIsLocked = true;
 
     return Result::SUCCESS;
 }
@@ -88,6 +109,7 @@
 Return<Result> Frontend::stopScan() {
     ALOGV("%s", __FUNCTION__);
 
+    mIsLocked = false;
     return Result::SUCCESS;
 }
 
diff --git a/tv/tuner/1.0/default/Frontend.h b/tv/tuner/1.0/default/Frontend.h
index b954639..8a30b91 100644
--- a/tv/tuner/1.0/default/Frontend.h
+++ b/tv/tuner/1.0/default/Frontend.h
@@ -74,6 +74,7 @@
     sp<Tuner> mTunerService;
     FrontendType mType = FrontendType::UNDEFINED;
     FrontendId mId = 0;
+    bool mIsLocked = false;
 
     const string FRONTEND_STREAM_FILE = "/vendor/etc/dumpTs3.ts";
     std::ifstream mFrontendData;
diff --git a/tv/tuner/1.0/default/Tuner.cpp b/tv/tuner/1.0/default/Tuner.cpp
index 8fb5061..6f9a5cf 100644
--- a/tv/tuner/1.0/default/Tuner.cpp
+++ b/tv/tuner/1.0/default/Tuner.cpp
@@ -106,40 +106,54 @@
     return Void();
 }
 
-Return<void> Tuner::getFrontendInfo(FrontendId /*frontendId*/, getFrontendInfo_cb _hidl_cb) {
+Return<void> Tuner::getFrontendInfo(FrontendId frontendId, getFrontendInfo_cb _hidl_cb) {
     ALOGV("%s", __FUNCTION__);
 
-    vector<FrontendStatusType> statusCaps = {
-            FrontendStatusType::DEMOD_LOCK,
-            FrontendStatusType::SNR,
-            FrontendStatusType::FEC,
-            FrontendStatusType::MODULATION,
-            FrontendStatusType::PLP_ID,
-            FrontendStatusType::LAYER_ERROR,
-            FrontendStatusType::ATSC3_PLP_INFO,
-    };
-    FrontendInfo::FrontendCapabilities frontendCaps;
-    FrontendIsdbtCapabilities isdbtCaps{
-            .modeCap = FrontendIsdbtMode::MODE_1 | FrontendIsdbtMode::MODE_2,
-            .bandwidthCap = (unsigned int)FrontendIsdbtBandwidth::BANDWIDTH_6MHZ,
-            .modulationCap = (unsigned int)FrontendIsdbtModulation::MOD_16QAM,
-            // ISDBT shares coderate and guard interval with DVBT
-            .coderateCap = FrontendDvbtCoderate::CODERATE_4_5 | FrontendDvbtCoderate::CODERATE_6_7,
-            .guardIntervalCap = (unsigned int)FrontendDvbtGuardInterval::INTERVAL_1_128,
-    };
-    frontendCaps.isdbtCaps(isdbtCaps);
-    // assign randomly selected values for testing.
-    FrontendInfo info{
-            .type = FrontendType::ISDBT,
-            .minFrequency = 139,
-            .maxFrequency = 1139,
-            .minSymbolRate = 45,
-            .maxSymbolRate = 1145,
-            .acquireRange = 30,
-            .exclusiveGroupId = 57,
-            .statusCaps = statusCaps,
-            .frontendCaps = frontendCaps,
-    };
+    FrontendInfo info;
+    if (frontendId >= mFrontendSize) {
+        _hidl_cb(Result::INVALID_ARGUMENT, info);
+        return Void();
+    }
+
+    switch (mFrontends[frontendId]->getFrontendType()) {
+        case FrontendType::DVBT:
+            info.type = FrontendType::DVBT;
+            break;
+        default:
+            vector<FrontendStatusType> statusCaps = {
+                    FrontendStatusType::DEMOD_LOCK,
+                    FrontendStatusType::SNR,
+                    FrontendStatusType::FEC,
+                    FrontendStatusType::MODULATION,
+                    FrontendStatusType::PLP_ID,
+                    FrontendStatusType::LAYER_ERROR,
+                    FrontendStatusType::ATSC3_PLP_INFO,
+            };
+            FrontendInfo::FrontendCapabilities frontendCaps;
+            FrontendIsdbtCapabilities isdbtCaps{
+                    .modeCap = FrontendIsdbtMode::MODE_1 | FrontendIsdbtMode::MODE_2,
+                    .bandwidthCap = (unsigned int)FrontendIsdbtBandwidth::BANDWIDTH_6MHZ,
+                    .modulationCap = (unsigned int)FrontendIsdbtModulation::MOD_16QAM,
+                    // ISDBT shares coderate and guard interval with DVBT
+                    .coderateCap =
+                            FrontendDvbtCoderate::CODERATE_4_5 | FrontendDvbtCoderate::CODERATE_6_7,
+                    .guardIntervalCap = (unsigned int)FrontendDvbtGuardInterval::INTERVAL_1_128,
+            };
+            frontendCaps.isdbtCaps(isdbtCaps);
+            // assign randomly selected values for testing.
+            info = {
+                    .type = FrontendType::ISDBT,
+                    .minFrequency = 139,
+                    .maxFrequency = 1139,
+                    .minSymbolRate = 45,
+                    .maxSymbolRate = 1145,
+                    .acquireRange = 30,
+                    .exclusiveGroupId = 57,
+                    .statusCaps = statusCaps,
+                    .frontendCaps = frontendCaps,
+            };
+            break;
+    }
 
     _hidl_cb(Result::SUCCESS, info);
     return Void();
diff --git a/tv/tuner/1.0/vts/functional/VtsHalTvTunerV1_0TargetTest.cpp b/tv/tuner/1.0/vts/functional/VtsHalTvTunerV1_0TargetTest.cpp
index 8f83d82..5e98367 100644
--- a/tv/tuner/1.0/vts/functional/VtsHalTvTunerV1_0TargetTest.cpp
+++ b/tv/tuner/1.0/vts/functional/VtsHalTvTunerV1_0TargetTest.cpp
@@ -47,6 +47,7 @@
 #include "VtsHalTvTunerV1_0TestConfigurations.h"
 
 #define WAIT_TIMEOUT 3000000000
+#define INVALID_ID -1
 
 using android::Condition;
 using android::IMemory;
@@ -214,7 +215,7 @@
 
     // Helper methods
     uint32_t getTargetFrequency(FrontendSettings settings, FrontendType type);
-    void resetBlindScanStartingFrequency(FrontendConfig config, uint32_t resetingFreq);
+    void resetBlindScanStartingFrequency(FrontendConfig& config, uint32_t resetingFreq);
 
   private:
     bool mEventReceived = false;
@@ -340,7 +341,7 @@
     }
 }
 
-void FrontendCallback::resetBlindScanStartingFrequency(FrontendConfig config,
+void FrontendCallback::resetBlindScanStartingFrequency(FrontendConfig& config,
                                                        uint32_t resetingFreq) {
     switch (config.type) {
         case FrontendType::ANALOG:
@@ -856,7 +857,7 @@
 
     AssertionResult getFrontendIds();
     AssertionResult getFrontendInfo(uint32_t frontendId);
-    AssertionResult openFrontend(uint32_t frontendId);
+    AssertionResult openFrontendById(uint32_t frontendId);
     AssertionResult setFrontendCallback();
     AssertionResult scanFrontend(FrontendConfig config, FrontendScanType type);
     AssertionResult stopScanFrontend();
@@ -889,7 +890,10 @@
                                        RecordSettings recordSetting,
                                        vector<string> goldenOutputFiles);
     AssertionResult broadcastDataFlowTest(vector<string> goldenOutputFiles);
-    void broadcastFilterTest(int selectedFilter, int feId);
+
+    void broadcastSingleFilterTest(FilterConfig filterConf, FrontendConfig frontendConf);
+    void getFrontendIdByType(FrontendType feType, uint32_t& feId);
+    void scanTest(FrontendConfig frontend, FrontendScanType type);
 
     FilterEventType getFilterEventType(DemuxFilterType type);
 };
@@ -913,7 +917,7 @@
     return AssertionResult(status == Result::SUCCESS);
 }
 
-AssertionResult TunerHidlTest::openFrontend(uint32_t frontendId) {
+AssertionResult TunerHidlTest::openFrontendById(uint32_t frontendId) {
     Result status;
     mService->openFrontendById(frontendId, [&](Result result, const sp<IFrontend>& frontend) {
         mFrontend = frontend;
@@ -923,7 +927,7 @@
 }
 
 AssertionResult TunerHidlTest::setFrontendCallback() {
-    EXPECT_TRUE(mFrontend) << "Test with openFrontend first.";
+    EXPECT_TRUE(mFrontend) << "Test with openFrontendById first.";
     mFrontendCallback = new FrontendCallback();
     auto callbackStatus = mFrontend->setCallback(mFrontendCallback);
     return AssertionResult(callbackStatus.isOk());
@@ -931,7 +935,7 @@
 
 AssertionResult TunerHidlTest::scanFrontend(FrontendConfig config, FrontendScanType type) {
     EXPECT_TRUE(mFrontendCallback)
-            << "test with openFrontend/setFrontendCallback/getFrontendInfo first.";
+            << "test with openFrontendById/setFrontendCallback/getFrontendInfo first.";
 
     EXPECT_TRUE(mFrontendInfo.type == config.type)
             << "FrontendConfig does not match the frontend info of the given id.";
@@ -941,7 +945,7 @@
 }
 
 AssertionResult TunerHidlTest::stopScanFrontend() {
-    EXPECT_TRUE(mFrontend) << "Test with openFrontend first.";
+    EXPECT_TRUE(mFrontend) << "Test with openFrontendById first.";
     Result status;
     status = mFrontend->stopScan();
     return AssertionResult(status == Result::SUCCESS);
@@ -949,7 +953,7 @@
 
 AssertionResult TunerHidlTest::tuneFrontend(FrontendConfig config) {
     EXPECT_TRUE(mFrontendCallback)
-            << "test with openFrontend/setFrontendCallback/getFrontendInfo first.";
+            << "test with openFrontendById/setFrontendCallback/getFrontendInfo first.";
 
     EXPECT_TRUE(mFrontendInfo.type == config.type)
             << "FrontendConfig does not match the frontend info of the given id.";
@@ -959,14 +963,14 @@
 }
 
 AssertionResult TunerHidlTest::stopTuneFrontend() {
-    EXPECT_TRUE(mFrontend) << "Test with openFrontend first.";
+    EXPECT_TRUE(mFrontend) << "Test with openFrontendById first.";
     Result status;
     status = mFrontend->stopTune();
     return AssertionResult(status == Result::SUCCESS);
 }
 
 AssertionResult TunerHidlTest::closeFrontend() {
-    EXPECT_TRUE(mFrontend) << "Test with openFrontend first.";
+    EXPECT_TRUE(mFrontend) << "Test with openFrontendById first.";
     Result status;
     status = mFrontend->close();
     mFrontend = nullptr;
@@ -988,7 +992,7 @@
 
 AssertionResult TunerHidlTest::setDemuxFrontendDataSource(uint32_t frontendId) {
     EXPECT_TRUE(mDemux) << "Test with openDemux first.";
-    EXPECT_TRUE(mFrontend) << "Test with openFrontend first.";
+    EXPECT_TRUE(mFrontend) << "Test with openFrontendById first.";
     auto status = mDemux->setFrontendDataSource(frontendId);
     return AssertionResult(status.isOk());
 }
@@ -1184,28 +1188,6 @@
     return success();
 }
 
-void TunerHidlTest::broadcastFilterTest(int selectedFilter, int feId) {
-    ASSERT_TRUE(openFrontend(feId));
-    ASSERT_TRUE(setFrontendCallback());
-    ASSERT_TRUE(openDemux());
-    ASSERT_TRUE(setDemuxFrontendDataSource(feId));
-    ASSERT_TRUE(openFilterInDemux(filterArray[selectedFilter].type));
-    uint32_t filterId;
-    ASSERT_TRUE(getNewlyOpenedFilterId(filterId));
-    ASSERT_TRUE(configFilter(filterArray[selectedFilter].setting, filterId));
-    ASSERT_TRUE(getFilterMQDescriptor(filterId));
-    ASSERT_TRUE(startFilter(filterId));
-    // tune test
-    ASSERT_TRUE(tuneFrontend(frontendArray[DVBT]));
-    // broadcast data flow test
-    ASSERT_TRUE(broadcastDataFlowTest(goldenOutputFiles));
-    ASSERT_TRUE(stopTuneFrontend());
-    ASSERT_TRUE(stopFilter(filterId));
-    ASSERT_TRUE(closeFilter(filterId));
-    ASSERT_TRUE(closeDemux());
-    ASSERT_TRUE(closeFrontend());
-}
-
 /*
  * TODO: re-enable the tests after finalizing the test refactoring.
  */
@@ -1351,6 +1333,64 @@
 }*/
 /*========================= End Data Flow Tests Implementation =========================*/
 
+/*================================= Start Test Module =================================*/
+void TunerHidlTest::getFrontendIdByType(FrontendType feType, uint32_t& feId) {
+    ASSERT_TRUE(getFrontendIds());
+    ASSERT_TRUE(mFeIds.size() > 0);
+    for (size_t i = 0; i < mFeIds.size(); i++) {
+        ASSERT_TRUE(getFrontendInfo(mFeIds[i]));
+        if (mFrontendInfo.type != feType) {
+            continue;
+        }
+        feId = mFeIds[i];
+        return;
+    }
+    feId = INVALID_ID;
+}
+
+void TunerHidlTest::broadcastSingleFilterTest(FilterConfig filterConf,
+                                              FrontendConfig frontendConf) {
+    uint32_t feId;
+    getFrontendIdByType(frontendConf.type, feId);
+    if (feId == INVALID_ID) {
+        // TODO broadcast test on Cuttlefish needs licensed ts input,
+        // these tests are runnable on vendor device with real frontend module
+        // or with manual ts installing and use DVBT frontend.
+        return;
+    }
+    ASSERT_TRUE(openFrontendById(feId));
+    ASSERT_TRUE(setFrontendCallback());
+    ASSERT_TRUE(openDemux());
+    ASSERT_TRUE(setDemuxFrontendDataSource(feId));
+    ASSERT_TRUE(openFilterInDemux(filterConf.type));
+    uint32_t filterId;
+    ASSERT_TRUE(getNewlyOpenedFilterId(filterId));
+    ASSERT_TRUE(configFilter(filterConf.setting, filterId));
+    ASSERT_TRUE(getFilterMQDescriptor(filterId));
+    ASSERT_TRUE(startFilter(filterId));
+    // tune test
+    ASSERT_TRUE(tuneFrontend(frontendConf));
+    // broadcast data flow test
+    ASSERT_TRUE(broadcastDataFlowTest(goldenOutputFiles));
+    ASSERT_TRUE(stopTuneFrontend());
+    ASSERT_TRUE(stopFilter(filterId));
+    ASSERT_TRUE(closeFilter(filterId));
+    ASSERT_TRUE(closeDemux());
+    ASSERT_TRUE(closeFrontend());
+}
+
+void TunerHidlTest::scanTest(FrontendConfig frontendConf, FrontendScanType scanType) {
+    uint32_t feId;
+    getFrontendIdByType(frontendConf.type, feId);
+    ASSERT_TRUE(feId != INVALID_ID);
+    ASSERT_TRUE(openFrontendById(feId));
+    ASSERT_TRUE(setFrontendCallback());
+    ASSERT_TRUE(scanFrontend(frontendConf, scanType));
+    ASSERT_TRUE(stopScanFrontend());
+    ASSERT_TRUE(closeFrontend());
+}
+/*================================== End Test Module ==================================*/
+
 /*=============================== Start Helper Functions ===============================*/
 FilterEventType TunerHidlTest::getFilterEventType(DemuxFilterType type) {
     FilterEventType eventType = FilterEventType::UNDEFINED;
@@ -1403,151 +1443,49 @@
 
 /******************************** Start Test Entry **********************************/
 /*============================== Start Frontend Tests ==============================*/
-TEST_P(TunerHidlTest, getFrontendIds) {
-    description("Get Frontend ids and verify frontends exist");
-    ASSERT_TRUE(getFrontendIds());
-    ASSERT_TRUE(mFeIds.size() > 0);
-}
-
-TEST_P(TunerHidlTest, openFrontend) {
-    description("Open all the existing Frontends and close them");
-    ASSERT_TRUE(getFrontendIds());
-    ASSERT_TRUE(mFeIds.size() > 0);
-
-    for (size_t i = 0; i < mFeIds.size(); i++) {
-        ASSERT_TRUE(openFrontend(mFeIds[i]));
-        ASSERT_TRUE(closeFrontend());
-    }
-}
-
 TEST_P(TunerHidlTest, TuneFrontend) {
     description("Tune one Frontend with specific setting and check Lock event");
-    ASSERT_TRUE(getFrontendIds());
-    ASSERT_TRUE(mFeIds.size() > 0);
-    for (size_t i = 0; i < mFeIds.size(); i++) {
-        ASSERT_TRUE(getFrontendInfo(mFeIds[i]));
-        if (mFrontendInfo.type != frontendArray[DVBT].type) {
-            continue;
-        }
-        ASSERT_TRUE(openFrontend(mFeIds[i]));
-        ASSERT_TRUE(setFrontendCallback());
-        ASSERT_TRUE(tuneFrontend(frontendArray[DVBT]));
-        ASSERT_TRUE(stopTuneFrontend());
-        ASSERT_TRUE(closeFrontend());
-        break;
-    }
+    uint32_t feId;
+    getFrontendIdByType(frontendArray[DVBT].type, feId);
+    ASSERT_TRUE(feId != INVALID_ID);
+    ASSERT_TRUE(openFrontendById(feId));
+    ASSERT_TRUE(setFrontendCallback());
+    ASSERT_TRUE(tuneFrontend(frontendArray[DVBT]));
+    ASSERT_TRUE(stopTuneFrontend());
+    ASSERT_TRUE(closeFrontend());
 }
 
 TEST_P(TunerHidlTest, AutoScanFrontend) {
     description("Run an auto frontend scan with specific setting and check lock scanMessage");
-    ASSERT_TRUE(getFrontendIds());
-    ASSERT_TRUE(mFeIds.size() > 0);
-
-    for (size_t i = 0; i < mFeIds.size(); i++) {
-        ASSERT_TRUE(getFrontendInfo(mFeIds[i]));
-        if (mFrontendInfo.type != frontendScanArray[SCAN_DVBT].type) {
-            continue;
-        }
-        ASSERT_TRUE(openFrontend(mFeIds[i]));
-        ASSERT_TRUE(setFrontendCallback());
-        ASSERT_TRUE(scanFrontend(frontendScanArray[SCAN_DVBT], FrontendScanType::SCAN_AUTO));
-        ASSERT_TRUE(stopScanFrontend());
-        ASSERT_TRUE(closeFrontend());
-        break;
-    }
+    scanTest(frontendScanArray[SCAN_DVBT], FrontendScanType::SCAN_AUTO);
 }
 
 TEST_P(TunerHidlTest, BlindScanFrontend) {
     description("Run an blind frontend scan with specific setting and check lock scanMessage");
-    ASSERT_TRUE(getFrontendIds());
-    ASSERT_TRUE(mFeIds.size() > 0);
-
-    for (size_t i = 0; i < mFeIds.size(); i++) {
-        ASSERT_TRUE(getFrontendInfo(mFeIds[i]));
-        if (mFrontendInfo.type != frontendScanArray[SCAN_DVBT].type) {
-            continue;
-        }
-        ASSERT_TRUE(openFrontend(mFeIds[i]));
-        ASSERT_TRUE(setFrontendCallback());
-        ASSERT_TRUE(scanFrontend(frontendScanArray[SCAN_DVBT], FrontendScanType::SCAN_BLIND));
-        ASSERT_TRUE(stopScanFrontend());
-        ASSERT_TRUE(closeFrontend());
-        break;
-    }
+    scanTest(frontendScanArray[SCAN_DVBT], FrontendScanType::SCAN_BLIND);
 }
 /*=============================== End Frontend Tests ===============================*/
 
 /*============================ Start Demux/Filter Tests ============================*/
-TEST_P(TunerHidlTest, OpenDemuxWithFrontendDataSource) {
-    description("Open Demux with a Frontend as its data source.");
-    ASSERT_TRUE(getFrontendIds());
-    ASSERT_TRUE(mFeIds.size() > 0);
-
-    for (size_t i = 0; i < mFeIds.size(); i++) {
-        ASSERT_TRUE(getFrontendInfo(mFeIds[i]));
-        if (mFrontendInfo.type != frontendArray[DVBT].type) {
-            continue;
-        }
-        ASSERT_TRUE(openFrontend(mFeIds[i]));
-        ASSERT_TRUE(setFrontendCallback());
-        ASSERT_TRUE(openDemux());
-        ASSERT_TRUE(setDemuxFrontendDataSource(mFeIds[i]));
-        ASSERT_TRUE(closeDemux());
-        ASSERT_TRUE(closeFrontend());
-        break;
-    }
-}
-
-TEST_P(TunerHidlTest, OpenFilterInDemux) {
-    description("Open a filter in Demux.");
-    ASSERT_TRUE(getFrontendIds());
-    ASSERT_TRUE(mFeIds.size() > 0);
-
-    for (size_t i = 0; i < mFeIds.size(); i++) {
-        ASSERT_TRUE(getFrontendInfo(mFeIds[i]));
-        if (mFrontendInfo.type != frontendArray[DVBT].type) {
-            continue;
-        }
-        ASSERT_TRUE(openFrontend(mFeIds[i]));
-        ASSERT_TRUE(setFrontendCallback());
-        ASSERT_TRUE(openDemux());
-        ASSERT_TRUE(setDemuxFrontendDataSource(mFeIds[i]));
-        ASSERT_TRUE(openFilterInDemux(filterArray[TS_VIDEO0].type));
-        uint32_t filterId;
-        ASSERT_TRUE(getNewlyOpenedFilterId(filterId));
-        ASSERT_TRUE(closeFilter(filterId));
-        ASSERT_TRUE(closeDemux());
-        ASSERT_TRUE(closeFrontend());
-        break;
-    }
-}
-
 TEST_P(TunerHidlTest, StartFilterInDemux) {
     description("Open and start a filter in Demux.");
-    ASSERT_TRUE(getFrontendIds());
-    ASSERT_TRUE(mFeIds.size() > 0);
-
-    for (size_t i = 0; i < mFeIds.size(); i++) {
-        ASSERT_TRUE(getFrontendInfo(mFeIds[i]));
-        if (mFrontendInfo.type != frontendArray[DVBT].type) {
-            continue;
-        }
-        ASSERT_TRUE(openFrontend(mFeIds[i]));
-        ASSERT_TRUE(setFrontendCallback());
-        ASSERT_TRUE(openDemux());
-        ASSERT_TRUE(setDemuxFrontendDataSource(mFeIds[i]));
-        ASSERT_TRUE(openFilterInDemux(filterArray[TS_VIDEO0].type));
-        uint32_t filterId;
-        ASSERT_TRUE(getNewlyOpenedFilterId(filterId));
-        ASSERT_TRUE(configFilter(filterArray[TS_VIDEO0].setting, filterId));
-        ASSERT_TRUE(getFilterMQDescriptor(filterId));
-        ASSERT_TRUE(startFilter(filterId));
-        ASSERT_TRUE(stopFilter(filterId));
-        ASSERT_TRUE(closeFilter(filterId));
-        ASSERT_TRUE(closeDemux());
-        ASSERT_TRUE(closeFrontend());
-        break;
-    }
+    uint32_t feId;
+    getFrontendIdByType(frontendArray[DVBT].type, feId);
+    ASSERT_TRUE(feId != INVALID_ID);
+    ASSERT_TRUE(openFrontendById(feId));
+    ASSERT_TRUE(setFrontendCallback());
+    ASSERT_TRUE(openDemux());
+    ASSERT_TRUE(setDemuxFrontendDataSource(feId));
+    ASSERT_TRUE(openFilterInDemux(filterArray[TS_VIDEO0].type));
+    uint32_t filterId;
+    ASSERT_TRUE(getNewlyOpenedFilterId(filterId));
+    ASSERT_TRUE(configFilter(filterArray[TS_VIDEO0].setting, filterId));
+    ASSERT_TRUE(getFilterMQDescriptor(filterId));
+    ASSERT_TRUE(startFilter(filterId));
+    ASSERT_TRUE(stopFilter(filterId));
+    ASSERT_TRUE(closeFilter(filterId));
+    ASSERT_TRUE(closeDemux());
+    ASSERT_TRUE(closeFrontend());
 }
 /*============================ End Demux/Filter Tests ============================*/
 
@@ -1569,64 +1507,28 @@
 /*============================== Start Data Flow Tests ==============================*/
 TEST_P(TunerHidlTest, BroadcastDataFlowVideoFilterTest) {
     description("Test Video Filter functionality in Broadcast use case.");
-    ASSERT_TRUE(getFrontendIds());
-    ASSERT_TRUE(mFeIds.size() > 0);
-
-    for (size_t i = 0; i < mFeIds.size(); i++) {
-        ASSERT_TRUE(getFrontendInfo(mFeIds[i]));
-        if (mFrontendInfo.type != frontendArray[DVBT].type) {
-            continue;
-        }
-        broadcastFilterTest(TS_VIDEO1, mFeIds[i]);
-        break;
-    }
+    broadcastSingleFilterTest(filterArray[TS_VIDEO1], frontendArray[DVBS]);
 }
 
 TEST_P(TunerHidlTest, BroadcastDataFlowAudioFilterTest) {
     description("Test Audio Filter functionality in Broadcast use case.");
-    ASSERT_TRUE(getFrontendIds());
-    ASSERT_TRUE(mFeIds.size() > 0);
-
-    for (size_t i = 0; i < mFeIds.size(); i++) {
-        ASSERT_TRUE(getFrontendInfo(mFeIds[i]));
-        if (mFrontendInfo.type != frontendArray[DVBT].type) {
-            continue;
-        }
-        broadcastFilterTest(TS_AUDIO0, mFeIds[i]);
-        break;
-    }
+    broadcastSingleFilterTest(filterArray[TS_AUDIO0], frontendArray[DVBS]);
 }
 
 TEST_P(TunerHidlTest, BroadcastDataFlowTsFilterTest) {
     description("Test TS Filter functionality in Broadcast use case.");
-    ASSERT_TRUE(getFrontendIds());
-    ASSERT_TRUE(mFeIds.size() > 0);
-
-    for (size_t i = 0; i < mFeIds.size(); i++) {
-        ASSERT_TRUE(getFrontendInfo(mFeIds[i]));
-        if (mFrontendInfo.type != frontendArray[DVBT].type) {
-            continue;
-        }
-        broadcastFilterTest(TS_TS0, mFeIds[i]);
-        break;
-    }
+    broadcastSingleFilterTest(filterArray[TS_TS0], frontendArray[DVBS]);
 }
 
 TEST_P(TunerHidlTest, BroadcastDataFlowSectionFilterTest) {
     description("Test Section Filter functionality in Broadcast use case.");
-    ASSERT_TRUE(getFrontendIds());
-    ASSERT_TRUE(mFeIds.size() > 0);
-
-    for (size_t i = 0; i < mFeIds.size(); i++) {
-        ASSERT_TRUE(getFrontendInfo(mFeIds[i]));
-        if (mFrontendInfo.type != frontendArray[DVBT].type) {
-            continue;
-        }
-        broadcastFilterTest(TS_SECTION0, mFeIds[i]);
-        break;
-    }
+    broadcastSingleFilterTest(filterArray[TS_SECTION0], frontendArray[DVBS]);
 }
 
+TEST_P(TunerHidlTest, IonBufferTest) {
+    description("Test the av filter data bufferring.");
+    broadcastSingleFilterTest(filterArray[TS_VIDEO0], frontendArray[DVBS]);
+}
 /*
  * TODO: re-enable the tests after finalizing the testing stream.
  */
@@ -1710,39 +1612,6 @@
 
     ASSERT_TRUE(recordDataFlowTest(filterConf, recordSetting, goldenOutputFiles));
 }*/
-
-TEST_P(TunerHidlTest, AvBufferTest) {
-    description("Test the av filter data bufferring.");
-
-    ASSERT_TRUE(getFrontendIds());
-    ASSERT_TRUE(mFeIds.size() > 0);
-
-    for (size_t i = 0; i < mFeIds.size(); i++) {
-        ASSERT_TRUE(getFrontendInfo(mFeIds[i]));
-        if (mFrontendInfo.type != frontendArray[DVBS].type) {
-            continue;
-        }
-        ASSERT_TRUE(openFrontend(mFeIds[i]));
-        ASSERT_TRUE(setFrontendCallback());
-        ASSERT_TRUE(openDemux());
-        ASSERT_TRUE(openFilterInDemux(filterArray[TS_VIDEO0].type));
-        uint32_t filterId;
-        ASSERT_TRUE(getNewlyOpenedFilterId(filterId));
-        ASSERT_TRUE(configFilter(filterArray[TS_VIDEO0].setting, filterId));
-        ASSERT_TRUE(startFilter(filterId));
-        ASSERT_TRUE(setDemuxFrontendDataSource(mFeIds[i]));
-        // tune test
-        ASSERT_TRUE(tuneFrontend(frontendArray[DVBS]));
-        // broadcast data flow test
-        ASSERT_TRUE(broadcastDataFlowTest(goldenOutputFiles));
-        ASSERT_TRUE(stopTuneFrontend());
-        ASSERT_TRUE(stopFilter(filterId));
-        ASSERT_TRUE(closeFilter(filterId));
-        ASSERT_TRUE(closeDemux());
-        ASSERT_TRUE(closeFrontend());
-        break;
-    }
-}
 /*============================== End Data Flow Tests ==============================*/
 /******************************** End Test Entry **********************************/
 }  // namespace