Merge "Convert soundtrigger hal test to use VtsHalHidlTargetTestEnvBase"
diff --git a/audio/effect/2.0/vts/functional/VtsHalAudioEffectV2_0TargetTest.cpp b/audio/effect/2.0/vts/functional/VtsHalAudioEffectV2_0TargetTest.cpp
index f069c46..c90c4fa 100644
--- a/audio/effect/2.0/vts/functional/VtsHalAudioEffectV2_0TargetTest.cpp
+++ b/audio/effect/2.0/vts/functional/VtsHalAudioEffectV2_0TargetTest.cpp
@@ -27,6 +27,7 @@
 #include <android/hidl/memory/1.0/IMemory.h>
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 
 using android::hardware::audio::common::V2_0::AudioDevice;
 using android::hardware::audio::common::V2_0::AudioHandleConsts;
@@ -59,13 +60,26 @@
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
 #endif
 
+// Test environment for Audio Effects Factory HIDL HAL.
+class AudioEffectsFactoryHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static AudioEffectsFactoryHidlEnvironment* Instance() {
+        static AudioEffectsFactoryHidlEnvironment* instance =
+            new AudioEffectsFactoryHidlEnvironment;
+        return instance;
+    }
+
+    virtual void registerTestServices() override { registerTestService<IEffectsFactory>(); }
+};
+
 // The main test class for Audio Effects Factory HIDL HAL.
 class AudioEffectsFactoryHidlTest : public ::testing::VtsHalHidlTargetTestBase {
  public:
   void SetUp() override {
-    effectsFactory =
-        ::testing::VtsHalHidlTargetTestBase::getService<IEffectsFactory>();
-    ASSERT_NE(effectsFactory, nullptr);
+      effectsFactory = ::testing::VtsHalHidlTargetTestBase::getService<IEffectsFactory>(
+          AudioEffectsFactoryHidlEnvironment::Instance()->getServiceName<IEffectsFactory>());
+      ASSERT_NE(effectsFactory, nullptr);
   }
 
   void TearDown() override { effectsFactory.clear(); }
@@ -824,3 +838,12 @@
   EXPECT_EQ(Result::OK, retval);
   EXPECT_EQ(gain, actualGain);
 }
+
+int main(int argc, char** argv) {
+    ::testing::AddGlobalTestEnvironment(AudioEffectsFactoryHidlEnvironment::Instance());
+    ::testing::InitGoogleTest(&argc, argv);
+    AudioEffectsFactoryHidlEnvironment::Instance()->init(&argc, argv);
+    int status = RUN_ALL_TESTS();
+    LOG(INFO) << "Test result = " << status;
+    return status;
+}
diff --git a/automotive/vehicle/2.0/default/common/src/VmsUtils.cpp b/automotive/vehicle/2.0/default/common/src/VmsUtils.cpp
index abf425f..f001a32 100644
--- a/automotive/vehicle/2.0/default/common/src/VmsUtils.cpp
+++ b/automotive/vehicle/2.0/default/common/src/VmsUtils.cpp
@@ -126,19 +126,18 @@
     return result;
 }
 
-bool verifyPropertyAndArea(const VehiclePropValue& value) {
-    return (value.prop == toInt(VehicleProperty::VEHICLE_MAP_SERVICE) &&
-            value.areaId == toInt(VehicleArea::GLOBAL));
+bool isValidVmsProperty(const VehiclePropValue& value) {
+    return (value.prop == toInt(VehicleProperty::VEHICLE_MAP_SERVICE));
 }
 
-bool verifyMessageType(const VehiclePropValue& value) {
+bool isValidVmsMessageType(const VehiclePropValue& value) {
     return (value.value.int32Values.size() > 0 &&
             value.value.int32Values[kMessageIndex] >= kFirstMessageType &&
             value.value.int32Values[kMessageIndex] <= kLastMessageType);
 }
 
 bool isValidVmsMessage(const VehiclePropValue& value) {
-    return (verifyPropertyAndArea(value) && verifyMessageType(value));
+    return (isValidVmsProperty(value) && isValidVmsMessageType(value));
 }
 
 VmsMessageType parseMessageType(const VehiclePropValue& value) {
diff --git a/automotive/vehicle/2.0/default/tests/VmsUtils_test.cpp b/automotive/vehicle/2.0/default/tests/VmsUtils_test.cpp
index c102ce8..414c5c2 100644
--- a/automotive/vehicle/2.0/default/tests/VmsUtils_test.cpp
+++ b/automotive/vehicle/2.0/default/tests/VmsUtils_test.cpp
@@ -35,7 +35,6 @@
     ASSERT_NE(message, nullptr);
     EXPECT_TRUE(isValidVmsMessage(*message));
     EXPECT_EQ(message->prop, toInt(VehicleProperty::VEHICLE_MAP_SERVICE));
-    EXPECT_EQ(message->areaId, toInt(VehicleArea::GLOBAL));
     EXPECT_EQ(message->value.int32Values.size(), 0x4ul);
     EXPECT_EQ(parseMessageType(*message), VmsMessageType::SUBSCRIBE);
 
@@ -51,7 +50,6 @@
     ASSERT_NE(message, nullptr);
     EXPECT_TRUE(isValidVmsMessage(*message));
     EXPECT_EQ(message->prop, toInt(VehicleProperty::VEHICLE_MAP_SERVICE));
-    EXPECT_EQ(message->areaId, toInt(VehicleArea::GLOBAL));
     EXPECT_EQ(message->value.int32Values.size(), 0x4ul);
     EXPECT_EQ(parseMessageType(*message), VmsMessageType::UNSUBSCRIBE);
 
@@ -67,7 +65,6 @@
     ASSERT_NE(message, nullptr);
     EXPECT_TRUE(isValidVmsMessage(*message));
     EXPECT_EQ(message->prop, toInt(VehicleProperty::VEHICLE_MAP_SERVICE));
-    EXPECT_EQ(message->areaId, toInt(VehicleArea::GLOBAL));
     EXPECT_EQ(message->value.int32Values.size(), 0x6ul);
     EXPECT_EQ(parseMessageType(*message), VmsMessageType::OFFERING);
 
@@ -91,7 +88,6 @@
     ASSERT_NE(message, nullptr);
     EXPECT_TRUE(isValidVmsMessage(*message));
     EXPECT_EQ(message->prop, toInt(VehicleProperty::VEHICLE_MAP_SERVICE));
-    EXPECT_EQ(message->areaId, toInt(VehicleArea::GLOBAL));
     EXPECT_EQ(message->value.int32Values.size(), 0x9ul);
     EXPECT_EQ(parseMessageType(*message), VmsMessageType::OFFERING);
 
@@ -117,7 +113,6 @@
     ASSERT_NE(message, nullptr);
     EXPECT_TRUE(isValidVmsMessage(*message));
     EXPECT_EQ(message->prop, toInt(VehicleProperty::VEHICLE_MAP_SERVICE));
-    EXPECT_EQ(message->areaId, toInt(VehicleArea::GLOBAL));
     EXPECT_EQ(message->value.int32Values.size(), 0x1ul);
     EXPECT_EQ(parseMessageType(*message), VmsMessageType::AVAILABILITY_REQUEST);
 }
@@ -127,7 +122,6 @@
     ASSERT_NE(message, nullptr);
     EXPECT_TRUE(isValidVmsMessage(*message));
     EXPECT_EQ(message->prop, toInt(VehicleProperty::VEHICLE_MAP_SERVICE));
-    EXPECT_EQ(message->areaId, toInt(VehicleArea::GLOBAL));
     EXPECT_EQ(message->value.int32Values.size(), 0x1ul);
     EXPECT_EQ(parseMessageType(*message), VmsMessageType::SUBSCRIPTIONS_REQUEST);
 }
@@ -138,7 +132,6 @@
     ASSERT_NE(message, nullptr);
     EXPECT_TRUE(isValidVmsMessage(*message));
     EXPECT_EQ(message->prop, toInt(VehicleProperty::VEHICLE_MAP_SERVICE));
-    EXPECT_EQ(message->areaId, toInt(VehicleArea::GLOBAL));
     EXPECT_EQ(message->value.int32Values.size(), 0x1ul);
     EXPECT_EQ(parseMessageType(*message), VmsMessageType::DATA);
     EXPECT_EQ(message->value.bytes.size(), bytes.size());
diff --git a/biometrics/fingerprint/2.1/vts/functional/VtsHalBiometricsFingerprintV2_1TargetTest.cpp b/biometrics/fingerprint/2.1/vts/functional/VtsHalBiometricsFingerprintV2_1TargetTest.cpp
index 638af9f..a7f4031 100644
--- a/biometrics/fingerprint/2.1/vts/functional/VtsHalBiometricsFingerprintV2_1TargetTest.cpp
+++ b/biometrics/fingerprint/2.1/vts/functional/VtsHalBiometricsFingerprintV2_1TargetTest.cpp
@@ -16,12 +16,13 @@
 
 #define LOG_TAG "fingerprint_hidl_hal_test"
 
+#include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <android-base/logging.h>
 #include <android/hardware/biometrics/fingerprint/2.1/IBiometricsFingerprint.h>
 #include <android/hardware/biometrics/fingerprint/2.1/IBiometricsFingerprintClientCallback.h>
 #include <hidl/HidlSupport.h>
 #include <hidl/HidlTransportSupport.h>
-#include <VtsHalHidlTargetTestBase.h>
 
 #include <cinttypes>
 #include <future>
@@ -179,10 +180,23 @@
   std::promise<void> promise;
 };
 
+// Test environment for Fingerprint HIDL HAL.
+class FingerprintHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+ public:
+  // get the test environment singleton
+  static FingerprintHidlEnvironment* Instance() {
+    static FingerprintHidlEnvironment* instance = new FingerprintHidlEnvironment;
+    return instance;
+  }
+
+  virtual void registerTestServices() override { registerTestService<IBiometricsFingerprint>(); }
+};
+
 class FingerprintHidlTest : public ::testing::VtsHalHidlTargetTestBase {
  public:
   virtual void SetUp() override {
-    mService = ::testing::VtsHalHidlTargetTestBase::getService<IBiometricsFingerprint>();
+    mService = ::testing::VtsHalHidlTargetTestBase::getService<IBiometricsFingerprint>(
+        FingerprintHidlEnvironment::Instance()->getServiceName<IBiometricsFingerprint>());
     ASSERT_FALSE(mService == nullptr);
 
     // Create an active group
@@ -454,7 +468,9 @@
 }  // anonymous namespace
 
 int main(int argc, char **argv) {
+  ::testing::AddGlobalTestEnvironment(FingerprintHidlEnvironment::Instance());
   ::testing::InitGoogleTest(&argc, argv);
+  FingerprintHidlEnvironment::Instance()->init(&argc, argv);
   int status = RUN_ALL_TESTS();
   LOG(INFO) << "Test result = " << status;
   return status;
diff --git a/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp b/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp
index 6c9aa18..b9f505d 100644
--- a/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp
+++ b/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp
@@ -25,6 +25,7 @@
 
 #include <VtsHalHidlTargetCallbackBase.h>
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <queue>
 
 using ::android::hardware::bluetooth::V1_0::IBluetoothHci;
@@ -126,6 +127,23 @@
   std::chrono::steady_clock::time_point start_time_;
 };
 
+// Test environment for Bluetooth HIDL HAL.
+class BluetoothHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+ public:
+  // get the test environment singleton
+  static BluetoothHidlEnvironment* Instance() {
+    static BluetoothHidlEnvironment* instance = new BluetoothHidlEnvironment;
+    return instance;
+  }
+
+  virtual void registerTestServices() override {
+    registerTestService<IBluetoothHci>();
+  }
+
+ private:
+  BluetoothHidlEnvironment() {}
+};
+
 // The main test class for Bluetooth HIDL HAL.
 class BluetoothHidlTest : public ::testing::VtsHalHidlTargetTestBase {
  public:
@@ -251,15 +269,6 @@
   int max_sco_data_packets;
 };
 
-// A class for test environment setup (kept since this file is a template).
-class BluetoothHidlEnvironment : public ::testing::Environment {
- public:
-  virtual void SetUp() {}
-  virtual void TearDown() {}
-
- private:
-};
-
 // Receive and check status events until a COMMAND_COMPLETE is received.
 void BluetoothHidlTest::wait_for_command_complete_event(hidl_vec<uint8_t> cmd) {
   // Allow intermediate COMMAND_STATUS events
@@ -662,8 +671,9 @@
 }
 
 int main(int argc, char** argv) {
-  ::testing::AddGlobalTestEnvironment(new BluetoothHidlEnvironment);
+  ::testing::AddGlobalTestEnvironment(BluetoothHidlEnvironment::Instance());
   ::testing::InitGoogleTest(&argc, argv);
+  BluetoothHidlEnvironment::Instance()->init(&argc, argv);
   int status = RUN_ALL_TESTS();
   ALOGI("Test result = %d", status);
   return status;
diff --git a/broadcastradio/1.2/default/Android.bp b/broadcastradio/1.1/default/Android.bp
similarity index 88%
rename from broadcastradio/1.2/default/Android.bp
rename to broadcastradio/1.1/default/Android.bp
index bd4be77..52fb45b 100644
--- a/broadcastradio/1.2/default/Android.bp
+++ b/broadcastradio/1.1/default/Android.bp
@@ -15,8 +15,8 @@
 //
 
 cc_binary {
-    name: "android.hardware.broadcastradio@1.2-service",
-    init_rc: ["android.hardware.broadcastradio@1.2-service.rc"],
+    name: "android.hardware.broadcastradio@1.1-service",
+    init_rc: ["android.hardware.broadcastradio@1.1-service.rc"],
     vendor: true,
     relative_install_path: "hw",
     cflags: [
@@ -39,7 +39,6 @@
     shared_libs: [
         "android.hardware.broadcastradio@1.0",
         "android.hardware.broadcastradio@1.1",
-        "android.hardware.broadcastradio@1.2",
         "libbase",
         "libhidlbase",
         "libhidltransport",
diff --git a/broadcastradio/1.2/default/BroadcastRadio.cpp b/broadcastradio/1.1/default/BroadcastRadio.cpp
similarity index 99%
rename from broadcastradio/1.2/default/BroadcastRadio.cpp
rename to broadcastradio/1.1/default/BroadcastRadio.cpp
index 74f6589..2933aa7 100644
--- a/broadcastradio/1.2/default/BroadcastRadio.cpp
+++ b/broadcastradio/1.1/default/BroadcastRadio.cpp
@@ -25,7 +25,7 @@
 namespace android {
 namespace hardware {
 namespace broadcastradio {
-namespace V1_2 {
+namespace V1_1 {
 namespace implementation {
 
 using V1_0::Band;
@@ -190,7 +190,7 @@
 }
 
 }  // namespace implementation
-}  // namespace V1_2
+}  // namespace V1_1
 }  // namespace broadcastradio
 }  // namespace hardware
 }  // namespace android
diff --git a/broadcastradio/1.2/default/BroadcastRadio.h b/broadcastradio/1.1/default/BroadcastRadio.h
similarity index 85%
rename from broadcastradio/1.2/default/BroadcastRadio.h
rename to broadcastradio/1.1/default/BroadcastRadio.h
index 94d62b9..bdf3b87 100644
--- a/broadcastradio/1.2/default/BroadcastRadio.h
+++ b/broadcastradio/1.1/default/BroadcastRadio.h
@@ -13,24 +13,24 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifndef ANDROID_HARDWARE_BROADCASTRADIO_V1_2_BROADCASTRADIO_H
-#define ANDROID_HARDWARE_BROADCASTRADIO_V1_2_BROADCASTRADIO_H
+#ifndef ANDROID_HARDWARE_BROADCASTRADIO_V1_1_BROADCASTRADIO_H
+#define ANDROID_HARDWARE_BROADCASTRADIO_V1_1_BROADCASTRADIO_H
 
 #include "Tuner.h"
 
 #include <android/hardware/broadcastradio/1.1/IBroadcastRadio.h>
-#include <android/hardware/broadcastradio/1.2/types.h>
+#include <android/hardware/broadcastradio/1.1/types.h>
 
 namespace android {
 namespace hardware {
 namespace broadcastradio {
-namespace V1_2 {
+namespace V1_1 {
 namespace implementation {
 
 struct AmFmBandConfig {
     V1_0::Band type;
-    uint32_t lowerLimit;  // kHz
-    uint32_t upperLimit;  // kHz
+    uint32_t lowerLimit;             // kHz
+    uint32_t upperLimit;             // kHz
     std::vector<uint32_t> spacings;  // kHz
 };
 
@@ -73,9 +73,9 @@
 };
 
 }  // namespace implementation
-}  // namespace V1_2
+}  // namespace V1_1
 }  // namespace broadcastradio
 }  // namespace hardware
 }  // namespace android
 
-#endif  // ANDROID_HARDWARE_BROADCASTRADIO_V1_2_BROADCASTRADIO_H
+#endif  // ANDROID_HARDWARE_BROADCASTRADIO_V1_1_BROADCASTRADIO_H
diff --git a/broadcastradio/1.2/default/BroadcastRadioFactory.cpp b/broadcastradio/1.1/default/BroadcastRadioFactory.cpp
similarity index 97%
rename from broadcastradio/1.2/default/BroadcastRadioFactory.cpp
rename to broadcastradio/1.1/default/BroadcastRadioFactory.cpp
index 8f17aff..aecc967 100644
--- a/broadcastradio/1.2/default/BroadcastRadioFactory.cpp
+++ b/broadcastradio/1.1/default/BroadcastRadioFactory.cpp
@@ -25,7 +25,7 @@
 namespace android {
 namespace hardware {
 namespace broadcastradio {
-namespace V1_2 {
+namespace V1_1 {
 namespace implementation {
 
 using V1_0::Class;
@@ -57,7 +57,7 @@
 }
 
 }  // namespace implementation
-}  // namespace V1_2
+}  // namespace V1_1
 }  // namespace broadcastradio
 }  // namespace hardware
 }  // namespace android
diff --git a/broadcastradio/1.2/default/BroadcastRadioFactory.h b/broadcastradio/1.1/default/BroadcastRadioFactory.h
similarity index 77%
rename from broadcastradio/1.2/default/BroadcastRadioFactory.h
rename to broadcastradio/1.1/default/BroadcastRadioFactory.h
index c365ae0..62b65bc 100644
--- a/broadcastradio/1.2/default/BroadcastRadioFactory.h
+++ b/broadcastradio/1.1/default/BroadcastRadioFactory.h
@@ -13,17 +13,17 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifndef ANDROID_HARDWARE_BROADCASTRADIO_V1_2_BROADCASTRADIOFACTORY_H
-#define ANDROID_HARDWARE_BROADCASTRADIO_V1_2_BROADCASTRADIOFACTORY_H
+#ifndef ANDROID_HARDWARE_BROADCASTRADIO_V1_1_BROADCASTRADIOFACTORY_H
+#define ANDROID_HARDWARE_BROADCASTRADIO_V1_1_BROADCASTRADIOFACTORY_H
 
 #include <android/hardware/broadcastradio/1.1/IBroadcastRadio.h>
-#include <android/hardware/broadcastradio/1.2/IBroadcastRadioFactory.h>
-#include <android/hardware/broadcastradio/1.2/types.h>
+#include <android/hardware/broadcastradio/1.1/IBroadcastRadioFactory.h>
+#include <android/hardware/broadcastradio/1.1/types.h>
 
 namespace android {
 namespace hardware {
 namespace broadcastradio {
-namespace V1_2 {
+namespace V1_1 {
 namespace implementation {
 
 struct BroadcastRadioFactory : public IBroadcastRadioFactory {
@@ -37,9 +37,9 @@
 };
 
 }  // namespace implementation
-}  // namespace V1_2
+}  // namespace V1_1
 }  // namespace broadcastradio
 }  // namespace hardware
 }  // namespace android
 
-#endif  // ANDROID_HARDWARE_BROADCASTRADIO_V1_2_BROADCASTRADIOFACTORY_H
+#endif  // ANDROID_HARDWARE_BROADCASTRADIO_V1_1_BROADCASTRADIOFACTORY_H
diff --git a/broadcastradio/1.2/default/OWNERS b/broadcastradio/1.1/default/OWNERS
similarity index 100%
rename from broadcastradio/1.2/default/OWNERS
rename to broadcastradio/1.1/default/OWNERS
diff --git a/broadcastradio/1.2/default/Tuner.cpp b/broadcastradio/1.1/default/Tuner.cpp
similarity index 93%
rename from broadcastradio/1.2/default/Tuner.cpp
rename to broadcastradio/1.1/default/Tuner.cpp
index e95a132..2be070d 100644
--- a/broadcastradio/1.2/default/Tuner.cpp
+++ b/broadcastradio/1.1/default/Tuner.cpp
@@ -17,8 +17,8 @@
 #define LOG_TAG "BroadcastRadioDefault.tuner"
 #define LOG_NDEBUG 0
 
-#include "BroadcastRadio.h"
 #include "Tuner.h"
+#include "BroadcastRadio.h"
 
 #include <broadcastradio-utils-1x/Utils.h>
 #include <log/log.h>
@@ -26,7 +26,7 @@
 namespace android {
 namespace hardware {
 namespace broadcastradio {
-namespace V1_2 {
+namespace V1_1 {
 namespace implementation {
 
 using namespace std::chrono_literals;
@@ -35,13 +35,13 @@
 using V1_0::BandConfig;
 using V1_0::Class;
 using V1_0::Direction;
+using V1_1::IdentifierType;
 using V1_1::ProgramInfo;
 using V1_1::ProgramInfoFlags;
 using V1_1::ProgramListResult;
 using V1_1::ProgramSelector;
 using V1_1::ProgramType;
 using V1_1::VendorKeyValue;
-using V1_2::IdentifierType;
 using utils::HalRevision;
 
 using std::chrono::milliseconds;
@@ -62,7 +62,6 @@
     : mClassId(classId),
       mCallback(callback),
       mCallback1_1(V1_1::ITunerCallback::castFrom(callback).withDefault(nullptr)),
-      mCallback1_2(V1_2::ITunerCallback::castFrom(callback).withDefault(nullptr)),
       mVirtualRadio(getRadio(classId)),
       mIsAnalogForced(false) {}
 
@@ -130,9 +129,7 @@
 }
 
 HalRevision Tuner::getHalRev() const {
-    if (mCallback1_2 != nullptr) {
-        return HalRevision::V1_2;
-    } else if (mCallback1_1 != nullptr) {
+    if (mCallback1_1 != nullptr) {
         return HalRevision::V1_1;
     } else {
         return HalRevision::V1_0;
@@ -282,7 +279,7 @@
             return Result::INVALID_ARGUMENTS;
         }
     } else if (programType == ProgramType::DAB) {
-        if (!utils::hasId(sel, IdentifierType::DAB_SID_EXT)) return Result::INVALID_ARGUMENTS;
+        if (!utils::hasId(sel, IdentifierType::DAB_SIDECC)) return Result::INVALID_ARGUMENTS;
     } else if (programType == ProgramType::DRMO) {
         if (!utils::hasId(sel, IdentifierType::DRMO_SERVICE_ID)) return Result::INVALID_ARGUMENTS;
     } else if (programType == ProgramType::SXM) {
@@ -386,24 +383,8 @@
     return {};
 }
 
-Return<void> Tuner::setParameters(const hidl_vec<VendorKeyValue>& /* parameters */,
-        setParameters_cb _hidl_cb) {
-    ALOGV("%s", __func__);
-
-    _hidl_cb({});
-    return {};
-}
-
-Return<void> Tuner::getParameters(const hidl_vec<hidl_string>& /* keys */,
-        getParameters_cb _hidl_cb) {
-    ALOGV("%s", __func__);
-
-    _hidl_cb({});
-    return {};
-}
-
 }  // namespace implementation
-}  // namespace V1_2
+}  // namespace V1_1
 }  // namespace broadcastradio
 }  // namespace hardware
 }  // namespace android
diff --git a/broadcastradio/1.2/default/Tuner.h b/broadcastradio/1.1/default/Tuner.h
similarity index 79%
rename from broadcastradio/1.2/default/Tuner.h
rename to broadcastradio/1.1/default/Tuner.h
index 7e68354..764d5b3 100644
--- a/broadcastradio/1.2/default/Tuner.h
+++ b/broadcastradio/1.1/default/Tuner.h
@@ -13,19 +13,19 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifndef ANDROID_HARDWARE_BROADCASTRADIO_V1_2_TUNER_H
-#define ANDROID_HARDWARE_BROADCASTRADIO_V1_2_TUNER_H
+#ifndef ANDROID_HARDWARE_BROADCASTRADIO_V1_1_TUNER_H
+#define ANDROID_HARDWARE_BROADCASTRADIO_V1_1_TUNER_H
 
 #include "VirtualRadio.h"
 
-#include <android/hardware/broadcastradio/1.2/ITuner.h>
-#include <android/hardware/broadcastradio/1.2/ITunerCallback.h>
+#include <android/hardware/broadcastradio/1.1/ITuner.h>
+#include <android/hardware/broadcastradio/1.1/ITunerCallback.h>
 #include <broadcastradio-utils/WorkerThread.h>
 
 namespace android {
 namespace hardware {
 namespace broadcastradio {
-namespace V1_2 {
+namespace V1_1 {
 namespace implementation {
 
 struct Tuner : public ITuner {
@@ -33,7 +33,7 @@
 
     void forceClose();
 
-    // V1_2::ITuner methods
+    // V1_1::ITuner methods
     virtual Return<Result> setConfiguration(const V1_0::BandConfig& config) override;
     virtual Return<void> getConfiguration(getConfiguration_cb _hidl_cb) override;
     virtual Return<Result> scan(V1_0::Direction direction, bool skipSubChannel) override;
@@ -49,10 +49,6 @@
                                         getProgramList_cb _hidl_cb) override;
     virtual Return<Result> setAnalogForced(bool isForced) override;
     virtual Return<void> isAnalogForced(isAnalogForced_cb _hidl_cb) override;
-    virtual Return<void> setParameters(const hidl_vec<V1_1::VendorKeyValue>& parameters,
-                                       setParameters_cb _hidl_cb) override;
-    virtual Return<void> getParameters(const hidl_vec<hidl_string>& keys,
-                                       getParameters_cb _hidl_cb) override;
 
    private:
     std::mutex mMut;
@@ -62,7 +58,6 @@
     V1_0::Class mClassId;
     const sp<V1_0::ITunerCallback> mCallback;
     const sp<V1_1::ITunerCallback> mCallback1_1;
-    const sp<V1_2::ITunerCallback> mCallback1_2;
 
     std::reference_wrapper<VirtualRadio> mVirtualRadio;
     bool mIsAmfmConfigSet = false;
@@ -77,9 +72,9 @@
 };
 
 }  // namespace implementation
-}  // namespace V1_2
+}  // namespace V1_1
 }  // namespace broadcastradio
 }  // namespace hardware
 }  // namespace android
 
-#endif  // ANDROID_HARDWARE_BROADCASTRADIO_V1_2_TUNER_H
+#endif  // ANDROID_HARDWARE_BROADCASTRADIO_V1_1_TUNER_H
diff --git a/broadcastradio/1.2/default/VirtualProgram.cpp b/broadcastradio/1.1/default/VirtualProgram.cpp
similarity index 97%
rename from broadcastradio/1.2/default/VirtualProgram.cpp
rename to broadcastradio/1.1/default/VirtualProgram.cpp
index 3594f64..20dc1f5 100644
--- a/broadcastradio/1.2/default/VirtualProgram.cpp
+++ b/broadcastradio/1.1/default/VirtualProgram.cpp
@@ -22,7 +22,7 @@
 namespace android {
 namespace hardware {
 namespace broadcastradio {
-namespace V1_2 {
+namespace V1_1 {
 namespace implementation {
 
 using std::vector;
@@ -30,9 +30,9 @@
 using V1_0::MetaData;
 using V1_0::MetadataKey;
 using V1_0::MetadataType;
+using V1_1::IdentifierType;
 using V1_1::ProgramInfo;
 using V1_1::VendorKeyValue;
-using V1_2::IdentifierType;
 using utils::HalRevision;
 
 static MetaData createDemoBitmap(MetadataKey key, HalRevision halRev) {
@@ -96,7 +96,7 @@
 }
 
 }  // namespace implementation
-}  // namespace V1_2
+}  // namespace V1_1
 }  // namespace broadcastradio
 }  // namespace hardware
 }  // namespace android
diff --git a/broadcastradio/1.2/default/VirtualProgram.h b/broadcastradio/1.1/default/VirtualProgram.h
similarity index 84%
rename from broadcastradio/1.2/default/VirtualProgram.h
rename to broadcastradio/1.1/default/VirtualProgram.h
index c0b20f0..fd7a5e7 100644
--- a/broadcastradio/1.2/default/VirtualProgram.h
+++ b/broadcastradio/1.1/default/VirtualProgram.h
@@ -13,16 +13,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifndef ANDROID_HARDWARE_BROADCASTRADIO_V1_2_VIRTUALPROGRAM_H
-#define ANDROID_HARDWARE_BROADCASTRADIO_V1_2_VIRTUALPROGRAM_H
+#ifndef ANDROID_HARDWARE_BROADCASTRADIO_V1_1_VIRTUALPROGRAM_H
+#define ANDROID_HARDWARE_BROADCASTRADIO_V1_1_VIRTUALPROGRAM_H
 
-#include <android/hardware/broadcastradio/1.2/types.h>
+#include <android/hardware/broadcastradio/1.1/types.h>
 #include <broadcastradio-utils-1x/Utils.h>
 
 namespace android {
 namespace hardware {
 namespace broadcastradio {
-namespace V1_2 {
+namespace V1_1 {
 namespace implementation {
 
 /**
@@ -47,9 +47,9 @@
                                                     utils::HalRevision halRev);
 
 }  // namespace implementation
-}  // namespace V1_2
+}  // namespace V1_1
 }  // namespace broadcastradio
 }  // namespace hardware
 }  // namespace android
 
-#endif  // ANDROID_HARDWARE_BROADCASTRADIO_V1_2_VIRTUALPROGRAM_H
+#endif  // ANDROID_HARDWARE_BROADCASTRADIO_V1_1_VIRTUALPROGRAM_H
diff --git a/broadcastradio/1.2/default/VirtualRadio.cpp b/broadcastradio/1.1/default/VirtualRadio.cpp
similarity index 98%
rename from broadcastradio/1.2/default/VirtualRadio.cpp
rename to broadcastradio/1.1/default/VirtualRadio.cpp
index 8988080..5b79155 100644
--- a/broadcastradio/1.2/default/VirtualRadio.cpp
+++ b/broadcastradio/1.1/default/VirtualRadio.cpp
@@ -24,7 +24,7 @@
 namespace android {
 namespace hardware {
 namespace broadcastradio {
-namespace V1_2 {
+namespace V1_1 {
 namespace implementation {
 
 using V1_0::Band;
@@ -100,7 +100,7 @@
 }
 
 }  // namespace implementation
-}  // namespace V1_2
+}  // namespace V1_1
 }  // namespace broadcastradio
 }  // namespace hardware
 }  // namespace android
diff --git a/broadcastradio/1.2/default/VirtualRadio.h b/broadcastradio/1.1/default/VirtualRadio.h
similarity index 91%
rename from broadcastradio/1.2/default/VirtualRadio.h
rename to broadcastradio/1.1/default/VirtualRadio.h
index 8cfaefe..176b1b2 100644
--- a/broadcastradio/1.2/default/VirtualRadio.h
+++ b/broadcastradio/1.1/default/VirtualRadio.h
@@ -13,8 +13,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifndef ANDROID_HARDWARE_BROADCASTRADIO_V1_2_VIRTUALRADIO_H
-#define ANDROID_HARDWARE_BROADCASTRADIO_V1_2_VIRTUALRADIO_H
+#ifndef ANDROID_HARDWARE_BROADCASTRADIO_V1_1_VIRTUALRADIO_H
+#define ANDROID_HARDWARE_BROADCASTRADIO_V1_1_VIRTUALRADIO_H
 
 #include "VirtualProgram.h"
 
@@ -24,7 +24,7 @@
 namespace android {
 namespace hardware {
 namespace broadcastradio {
-namespace V1_2 {
+namespace V1_1 {
 namespace implementation {
 
 /**
@@ -72,9 +72,9 @@
 VirtualRadio& getDigitalRadio();
 
 }  // namespace implementation
-}  // namespace V1_2
+}  // namespace V1_1
 }  // namespace broadcastradio
 }  // namespace hardware
 }  // namespace android
 
-#endif  // ANDROID_HARDWARE_BROADCASTRADIO_V1_2_VIRTUALRADIO_H
+#endif  // ANDROID_HARDWARE_BROADCASTRADIO_V1_1_VIRTUALRADIO_H
diff --git a/broadcastradio/1.2/default/android.hardware.broadcastradio@1.2-service.rc b/broadcastradio/1.1/default/android.hardware.broadcastradio@1.1-service.rc
similarity index 83%
rename from broadcastradio/1.2/default/android.hardware.broadcastradio@1.2-service.rc
rename to broadcastradio/1.1/default/android.hardware.broadcastradio@1.1-service.rc
index 3741f21..7c57135 100644
--- a/broadcastradio/1.2/default/android.hardware.broadcastradio@1.2-service.rc
+++ b/broadcastradio/1.1/default/android.hardware.broadcastradio@1.1-service.rc
@@ -1,4 +1,4 @@
-service broadcastradio-hal /vendor/bin/hw/android.hardware.broadcastradio@1.2-service
+service broadcastradio-hal /vendor/bin/hw/android.hardware.broadcastradio@1.1-service
     class hal
     user audioserver
     group audio
diff --git a/broadcastradio/1.2/default/resources.h b/broadcastradio/1.1/default/resources.h
similarity index 89%
rename from broadcastradio/1.2/default/resources.h
rename to broadcastradio/1.1/default/resources.h
index b383c27..b7e709f 100644
--- a/broadcastradio/1.2/default/resources.h
+++ b/broadcastradio/1.1/default/resources.h
@@ -13,13 +13,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifndef ANDROID_HARDWARE_BROADCASTRADIO_V1_2_RESOURCES_H
-#define ANDROID_HARDWARE_BROADCASTRADIO_V1_2_RESOURCES_H
+#ifndef ANDROID_HARDWARE_BROADCASTRADIO_V1_1_RESOURCES_H
+#define ANDROID_HARDWARE_BROADCASTRADIO_V1_1_RESOURCES_H
 
 namespace android {
 namespace hardware {
 namespace broadcastradio {
-namespace V1_2 {
+namespace V1_1 {
 namespace implementation {
 namespace resources {
 
@@ -38,9 +38,9 @@
 
 }  // namespace resources
 }  // namespace implementation
-}  // namespace V1_2
+}  // namespace V1_1
 }  // namespace broadcastradio
 }  // namespace hardware
 }  // namespace android
 
-#endif  // ANDROID_HARDWARE_BROADCASTRADIO_V1_2_RESOURCES_H
+#endif  // ANDROID_HARDWARE_BROADCASTRADIO_V1_1_RESOURCES_H
diff --git a/broadcastradio/1.2/default/service.cpp b/broadcastradio/1.1/default/service.cpp
similarity index 94%
rename from broadcastradio/1.2/default/service.cpp
rename to broadcastradio/1.1/default/service.cpp
index ea86fba..f8af0b7 100644
--- a/broadcastradio/1.2/default/service.cpp
+++ b/broadcastradio/1.1/default/service.cpp
@@ -22,7 +22,7 @@
 
 using android::hardware::configureRpcThreadpool;
 using android::hardware::joinRpcThreadpool;
-using android::hardware::broadcastradio::V1_2::implementation::BroadcastRadioFactory;
+using android::hardware::broadcastradio::V1_1::implementation::BroadcastRadioFactory;
 
 int main(int /* argc */, char** /* argv */) {
     configureRpcThreadpool(4, true);
diff --git a/broadcastradio/1.1/vts/functional/Android.bp b/broadcastradio/1.1/vts/functional/Android.bp
index 27ae4e9..9240cf0 100644
--- a/broadcastradio/1.1/vts/functional/Android.bp
+++ b/broadcastradio/1.1/vts/functional/Android.bp
@@ -21,7 +21,6 @@
     static_libs: [
         "android.hardware.broadcastradio@1.0",
         "android.hardware.broadcastradio@1.1",
-        "android.hardware.broadcastradio@1.2",  // common-utils-lib dependency
         "android.hardware.broadcastradio@common-utils-1x-lib",
         "android.hardware.broadcastradio@vts-utils-lib",
         "libgmock",
diff --git a/broadcastradio/1.2/Android.bp b/broadcastradio/1.2/Android.bp
deleted file mode 100644
index 40eb4e0..0000000
--- a/broadcastradio/1.2/Android.bp
+++ /dev/null
@@ -1,25 +0,0 @@
-// This file is autogenerated by hidl-gen -Landroidbp.
-
-hidl_interface {
-    name: "android.hardware.broadcastradio@1.2",
-    root: "android.hardware",
-    vndk: {
-        enabled: true,
-    },
-    srcs: [
-        "types.hal",
-        "IBroadcastRadioFactory.hal",
-        "ITuner.hal",
-        "ITunerCallback.hal",
-    ],
-    interfaces: [
-        "android.hardware.broadcastradio@1.0",
-        "android.hardware.broadcastradio@1.1",
-        "android.hidl.base@1.0",
-    ],
-    types: [
-        "IdentifierType",
-    ],
-    gen_java: false,
-}
-
diff --git a/broadcastradio/1.2/IBroadcastRadioFactory.hal b/broadcastradio/1.2/IBroadcastRadioFactory.hal
deleted file mode 100644
index 29f6ab3..0000000
--- a/broadcastradio/1.2/IBroadcastRadioFactory.hal
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-package android.hardware.broadcastradio@1.2;
-
-import @1.1::IBroadcastRadioFactory;
-
-/**
- * To use 1.2 features you must cast specific interfaces returned from the
- * 1.0 HAL. For example V1_0::IBroadcastRadio::openTuner() returns V1_0::ITuner,
- * which can be cast with V1_2::ITuner::castFrom() call.
- *
- * The 1.2 server must always return the 1.2 version of specific interface.
- */
-interface IBroadcastRadioFactory extends @1.1::IBroadcastRadioFactory {
-};
diff --git a/broadcastradio/1.2/ITuner.hal b/broadcastradio/1.2/ITuner.hal
deleted file mode 100644
index ba97ea0..0000000
--- a/broadcastradio/1.2/ITuner.hal
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-package android.hardware.broadcastradio@1.2;
-
-import @1.1::ITuner;
-
-interface ITuner extends @1.1::ITuner {
-    /**
-     * Generic method for setting vendor-specific parameter values.
-     * The framework does not interpret the parameters, they are passed
-     * in an opaque manner between a vendor application and HAL.
-     *
-     * Framework does not make any assumptions on the keys or values, other than
-     * ones stated in VendorKeyValue documentation (a requirement of key
-     * prefixes).
-     *
-     * For each pair in the result vector, the key must be one of the keys
-     * contained in the input (possibly with wildcards expanded), and the value
-     * must be a vendor-specific result status (i.e. the string "OK" or an error
-     * code). The implementation may choose to return an empty vector, or only
-     * return a status for a subset of the provided inputs, at its discretion.
-     *
-     * Application and HAL must not use keys with unknown prefix. In particular,
-     * it must not place a key-value pair in results vector for unknown key from
-     * parameters vector - instead, an unknown key should simply be ignored.
-     * In other words, results vector may contain a subset of parameter keys
-     * (however, the framework doesn't enforce a strict subset - the only
-     * formal requirement is vendor domain prefix for keys).
-     *
-     * @param parameters Vendor-specific key-value pairs.
-     * @return results Operation completion status for parameters being set.
-     */
-    setParameters(vec<VendorKeyValue> parameters)
-            generates (vec<VendorKeyValue> results);
-
-    /**
-     * Generic method for retrieving vendor-specific parameter values.
-     * The framework does not interpret the parameters, they are passed
-     * in an opaque manner between a vendor application and HAL.
-     *
-     * Framework does not cache set/get requests, so it's allowed for
-     * getParameter to return a different value than previous setParameter call.
-     *
-     * The syntax and semantics of keys are up to the vendor (as long as prefix
-     * rules are obeyed). For instance, vendors may include some form of
-     * wildcard support. In such case, result vector may be of different size
-     * than requested keys vector. However, wildcards are not recognized by
-     * framework and they are passed as-is to the HAL implementation.
-     *
-     * Unknown keys must be ignored and not placed into results vector.
-     *
-     * @param keys Parameter keys to fetch.
-     * @return parameters Vendor-specific key-value pairs.
-     */
-    getParameters(vec<string> keys) generates (vec<VendorKeyValue> parameters);
-};
diff --git a/broadcastradio/1.2/ITunerCallback.hal b/broadcastradio/1.2/ITunerCallback.hal
deleted file mode 100644
index 4e3d0a5..0000000
--- a/broadcastradio/1.2/ITunerCallback.hal
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-package android.hardware.broadcastradio@1.2;
-
-import @1.1::ITunerCallback;
-
-interface ITunerCallback extends @1.1::ITunerCallback {
-    /**
-     * Generic callback for passing updates to vendor-specific parameter values.
-     * The framework does not interpret the parameters, they are passed
-     * in an opaque manner between a vendor application and HAL.
-     *
-     * It's up to the HAL implementation if and how to implement this callback,
-     * as long as it obeys the prefix rule. In particular, only selected keys
-     * may be notified this way. However, setParameters must not trigger
-     * this callback, while an internal event can change parameters
-     * asynchronously.
-     *
-     * @param parameters Vendor-specific key-value pairs.
-     */
-    oneway parametersUpdated(vec<VendorKeyValue> parameters);
-};
diff --git a/broadcastradio/1.2/types.hal b/broadcastradio/1.2/types.hal
deleted file mode 100644
index 7301e13..0000000
--- a/broadcastradio/1.2/types.hal
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * Copyright 2017 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.
- */
-
-package android.hardware.broadcastradio@1.2;
-
-import @1.1::IdentifierType;
-import @1.1::Result;
-import @1.1::VendorKeyValue;
-
-typedef @1.1::Result Result;
-typedef @1.1::VendorKeyValue VendorKeyValue;
-
-enum IdentifierType : @1.1::IdentifierType {
-    /**
-     * 28bit compound primary identifier for DAB.
-     *
-     * Consists of (from the LSB):
-     * - 16bit: SId;
-     * - 8bit: ECC code;
-     * - 4bit: SCIdS (optional).
-     *
-     * SCIdS (Service Component Identifier within the Service) value
-     * of 0 represents the main service, while 1 and above represents
-     * secondary services.
-     *
-     * The remaining bits should be set to zeros when writing on the chip side
-     * and ignored when read.
-     *
-     * This identifier deprecates DAB_SIDECC and makes new primary identifier
-     * for DAB. If the hal implementation detects 1.2 client (by casting
-     * V1_0::ITunerCallback to V1_2::ITunerCallback), it must use DAB_SID_EXT
-     * as a primary identifier for DAB program type. If the hal client detects
-     * either 1.1 or 1.2 HAL, it must convert those identifiers to the
-     * correct version.
-     */
-    DAB_SID_EXT = SXM_CHANNEL + 1,
-};
diff --git a/broadcastradio/1.2/vts/OWNERS b/broadcastradio/1.2/vts/OWNERS
deleted file mode 100644
index 12adf57..0000000
--- a/broadcastradio/1.2/vts/OWNERS
+++ /dev/null
@@ -1,7 +0,0 @@
-# Automotive team
-egranata@google.com
-twasilczyk@google.com
-
-# VTS team
-yuexima@google.com
-yim@google.com
diff --git a/broadcastradio/1.2/vts/functional/Android.bp b/broadcastradio/1.2/vts/functional/Android.bp
deleted file mode 100644
index fd1c254..0000000
--- a/broadcastradio/1.2/vts/functional/Android.bp
+++ /dev/null
@@ -1,28 +0,0 @@
-//
-// Copyright (C) 2017 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.
-//
-
-cc_test {
-    name: "VtsHalBroadcastradioV1_2TargetTest",
-    defaults: ["VtsHalTargetTestDefaults"],
-    srcs: ["VtsHalBroadcastradioV1_2TargetTest.cpp"],
-    static_libs: [
-        "android.hardware.broadcastradio@1.0",
-        "android.hardware.broadcastradio@1.1",
-        "android.hardware.broadcastradio@1.2",
-        "android.hardware.broadcastradio@vts-utils-lib",
-        "libgmock",
-    ],
-}
diff --git a/broadcastradio/1.2/vts/functional/VtsHalBroadcastradioV1_2TargetTest.cpp b/broadcastradio/1.2/vts/functional/VtsHalBroadcastradioV1_2TargetTest.cpp
deleted file mode 100644
index 085206b..0000000
--- a/broadcastradio/1.2/vts/functional/VtsHalBroadcastradioV1_2TargetTest.cpp
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-#define LOG_TAG "broadcastradio.vts"
-
-#include <VtsHalHidlTargetTestBase.h>
-#include <android-base/logging.h>
-#include <android/hardware/broadcastradio/1.1/IBroadcastRadio.h>
-#include <android/hardware/broadcastradio/1.2/IBroadcastRadioFactory.h>
-#include <android/hardware/broadcastradio/1.2/ITuner.h>
-#include <android/hardware/broadcastradio/1.2/ITunerCallback.h>
-#include <android/hardware/broadcastradio/1.2/types.h>
-#include <broadcastradio-vts-utils/call-barrier.h>
-#include <broadcastradio-vts-utils/mock-timeout.h>
-#include <broadcastradio-vts-utils/pointer-utils.h>
-#include <cutils/native_handle.h>
-#include <cutils/properties.h>
-#include <gmock/gmock.h>
-#include <hidl/HidlTransportSupport.h>
-#include <utils/threads.h>
-
-#include <chrono>
-
-namespace android {
-namespace hardware {
-namespace broadcastradio {
-namespace V1_2 {
-namespace vts {
-
-using namespace std::chrono_literals;
-
-using testing::_;
-using testing::AnyNumber;
-using testing::ByMove;
-using testing::DoAll;
-using testing::Invoke;
-using testing::SaveArg;
-
-using broadcastradio::vts::CallBarrier;
-using V1_0::BandConfig;
-using V1_0::Class;
-using V1_0::MetaData;
-using V1_0::MetadataKey;
-using V1_0::MetadataType;
-using V1_1::IBroadcastRadio;
-using V1_1::ProgramInfo;
-using V1_1::ProgramListResult;
-using V1_1::ProgramSelector;
-using V1_1::Properties;
-
-using broadcastradio::vts::clearAndWait;
-
-static constexpr auto kConfigTimeout = 10s;
-static constexpr auto kConnectModuleTimeout = 1s;
-
-static void printSkipped(std::string msg) {
-    std::cout << "[  SKIPPED ] " << msg << std::endl;
-}
-
-struct TunerCallbackMock : public ITunerCallback {
-    TunerCallbackMock() { EXPECT_CALL(*this, hardwareFailure()).Times(0); }
-
-    MOCK_METHOD0(hardwareFailure, Return<void>());
-    MOCK_TIMEOUT_METHOD2(configChange, Return<void>(Result, const BandConfig&));
-    MOCK_METHOD2(tuneComplete, Return<void>(Result, const V1_0::ProgramInfo&));
-    MOCK_TIMEOUT_METHOD2(tuneComplete_1_1, Return<void>(Result, const ProgramSelector&));
-    MOCK_METHOD1(afSwitch, Return<void>(const V1_0::ProgramInfo&));
-    MOCK_METHOD1(antennaStateChange, Return<void>(bool connected));
-    MOCK_METHOD1(trafficAnnouncement, Return<void>(bool active));
-    MOCK_METHOD1(emergencyAnnouncement, Return<void>(bool active));
-    MOCK_METHOD3(newMetadata, Return<void>(uint32_t ch, uint32_t subCh, const hidl_vec<MetaData>&));
-    MOCK_METHOD1(backgroundScanAvailable, Return<void>(bool));
-    MOCK_TIMEOUT_METHOD1(backgroundScanComplete, Return<void>(ProgramListResult));
-    MOCK_METHOD0(programListChanged, Return<void>());
-    MOCK_TIMEOUT_METHOD1(currentProgramInfoChanged, Return<void>(const ProgramInfo&));
-    MOCK_METHOD1(parametersUpdated, Return<void>(const hidl_vec<VendorKeyValue>& parameters));
-};
-
-class BroadcastRadioHalTest : public ::testing::VtsHalHidlTargetTestBase,
-                              public ::testing::WithParamInterface<Class> {
-   protected:
-    virtual void SetUp() override;
-    virtual void TearDown() override;
-
-    bool openTuner();
-
-    Class radioClass;
-    bool skipped = false;
-
-    sp<IBroadcastRadio> mRadioModule;
-    sp<ITuner> mTuner;
-    sp<TunerCallbackMock> mCallback = new TunerCallbackMock();
-
-   private:
-    const BandConfig& getBand(unsigned idx);
-
-    hidl_vec<BandConfig> mBands;
-};
-
-void BroadcastRadioHalTest::SetUp() {
-    radioClass = GetParam();
-
-    // lookup HIDL service
-    auto factory = getService<IBroadcastRadioFactory>();
-    ASSERT_NE(nullptr, factory.get());
-
-    // connect radio module
-    Result connectResult;
-    CallBarrier onConnect;
-    factory->connectModule(radioClass, [&](Result ret, const sp<V1_0::IBroadcastRadio>& radio) {
-        connectResult = ret;
-        if (ret == Result::OK) mRadioModule = IBroadcastRadio::castFrom(radio);
-        onConnect.call();
-    });
-    ASSERT_TRUE(onConnect.waitForCall(kConnectModuleTimeout));
-
-    if (connectResult == Result::INVALID_ARGUMENTS) {
-        printSkipped("This device class is not supported.");
-        skipped = true;
-        return;
-    }
-    ASSERT_EQ(connectResult, Result::OK);
-    ASSERT_NE(nullptr, mRadioModule.get());
-
-    // get module properties
-    Properties prop11;
-    auto& prop10 = prop11.base;
-    auto propResult =
-        mRadioModule->getProperties_1_1([&](const Properties& properties) { prop11 = properties; });
-
-    ASSERT_TRUE(propResult.isOk());
-    EXPECT_EQ(radioClass, prop10.classId);
-    EXPECT_GT(prop10.numTuners, 0u);
-    EXPECT_GT(prop11.supportedProgramTypes.size(), 0u);
-    EXPECT_GT(prop11.supportedIdentifierTypes.size(), 0u);
-    if (radioClass == Class::AM_FM) {
-        EXPECT_GT(prop10.bands.size(), 0u);
-    }
-    mBands = prop10.bands;
-}
-
-void BroadcastRadioHalTest::TearDown() {
-    mTuner.clear();
-    mRadioModule.clear();
-    clearAndWait(mCallback, 1s);
-}
-
-bool BroadcastRadioHalTest::openTuner() {
-    EXPECT_EQ(nullptr, mTuner.get());
-
-    if (radioClass == Class::AM_FM) {
-        EXPECT_TIMEOUT_CALL(*mCallback, configChange, Result::OK, _);
-    }
-
-    Result halResult = Result::NOT_INITIALIZED;
-    auto openCb = [&](Result result, const sp<V1_0::ITuner>& tuner) {
-        halResult = result;
-        if (result != Result::OK) return;
-        mTuner = ITuner::castFrom(tuner);
-    };
-    auto hidlResult = mRadioModule->openTuner(getBand(0), true, mCallback, openCb);
-
-    EXPECT_TRUE(hidlResult.isOk());
-    EXPECT_EQ(Result::OK, halResult);
-    EXPECT_NE(nullptr, mTuner.get());
-    if (radioClass == Class::AM_FM && mTuner != nullptr) {
-        EXPECT_TIMEOUT_CALL_WAIT(*mCallback, configChange, kConfigTimeout);
-
-        BandConfig halConfig;
-        Result halResult = Result::NOT_INITIALIZED;
-        mTuner->getConfiguration([&](Result result, const BandConfig& config) {
-            halResult = result;
-            halConfig = config;
-        });
-        EXPECT_EQ(Result::OK, halResult);
-        EXPECT_TRUE(halConfig.antennaConnected);
-    }
-
-    EXPECT_NE(nullptr, mTuner.get());
-    return nullptr != mTuner.get();
-}
-
-const BandConfig& BroadcastRadioHalTest::getBand(unsigned idx) {
-    static const BandConfig dummyBandConfig = {};
-
-    if (radioClass != Class::AM_FM) {
-        ALOGD("Not AM/FM radio, returning dummy band config");
-        return dummyBandConfig;
-    }
-
-    EXPECT_GT(mBands.size(), idx);
-    if (mBands.size() <= idx) {
-        ALOGD("Band index out of bound, returning dummy band config");
-        return dummyBandConfig;
-    }
-
-    auto& band = mBands[idx];
-    ALOGD("Returning %s band", toString(band.type).c_str());
-    return band;
-}
-
-/**
- * Test IBroadcastRadio::get|setParameters() methods called with no parameters.
- *
- * Verifies that:
- *  - callback is called for empty parameters set.
- */
-TEST_P(BroadcastRadioHalTest, NoParameters) {
-    if (skipped) return;
-
-    ASSERT_TRUE(openTuner());
-
-    hidl_vec<VendorKeyValue> halResults = {};
-    bool wasCalled = false;
-    auto cb = [&](hidl_vec<VendorKeyValue> results) {
-        wasCalled = true;
-        halResults = results;
-    };
-
-    auto hidlResult = mTuner->setParameters({}, cb);
-    ASSERT_TRUE(hidlResult.isOk());
-    ASSERT_TRUE(wasCalled);
-    ASSERT_EQ(0u, halResults.size());
-
-    wasCalled = false;
-    hidlResult = mTuner->getParameters({}, cb);
-    ASSERT_TRUE(hidlResult.isOk());
-    ASSERT_TRUE(wasCalled);
-    ASSERT_EQ(0u, halResults.size());
-}
-
-/**
- * Test IBroadcastRadio::get|setParameters() methods called with unknown parameters.
- *
- * Verifies that:
- *  - unknown parameters are ignored;
- *  - callback is called also for empty results set.
- */
-TEST_P(BroadcastRadioHalTest, UnknownParameters) {
-    if (skipped) return;
-
-    ASSERT_TRUE(openTuner());
-
-    hidl_vec<VendorKeyValue> halResults = {};
-    bool wasCalled = false;
-    auto cb = [&](hidl_vec<VendorKeyValue> results) {
-        wasCalled = true;
-        halResults = results;
-    };
-
-    auto hidlResult = mTuner->setParameters({{"com.google.unknown", "dummy"}}, cb);
-    ASSERT_TRUE(hidlResult.isOk());
-    ASSERT_TRUE(wasCalled);
-    ASSERT_EQ(0u, halResults.size());
-
-    wasCalled = false;
-    hidlResult = mTuner->getParameters({{"com.google.unknown*", "dummy"}}, cb);
-    ASSERT_TRUE(hidlResult.isOk());
-    ASSERT_TRUE(wasCalled);
-    ASSERT_EQ(0u, halResults.size());
-}
-
-// TODO(b/69860743): implement VerifyIdentifiersFormat test when
-// the new program list fetching mechanism is implemented
-
-INSTANTIATE_TEST_CASE_P(BroadcastRadioHalTestCases, BroadcastRadioHalTest,
-                        ::testing::Values(Class::AM_FM, Class::SAT, Class::DT));
-
-}  // namespace vts
-}  // namespace V1_2
-}  // namespace broadcastradio
-}  // namespace hardware
-}  // namespace android
-
-int main(int argc, char** argv) {
-  ::testing::InitGoogleTest(&argc, argv);
-  int status = RUN_ALL_TESTS();
-  ALOGI("Test result = %d", status);
-  return status;
-}
diff --git a/broadcastradio/2.0/vts/functional/VtsHalBroadcastradioV2_0TargetTest.cpp b/broadcastradio/2.0/vts/functional/VtsHalBroadcastradioV2_0TargetTest.cpp
index 37095d4..2a5ec8fe 100644
--- a/broadcastradio/2.0/vts/functional/VtsHalBroadcastradioV2_0TargetTest.cpp
+++ b/broadcastradio/2.0/vts/functional/VtsHalBroadcastradioV2_0TargetTest.cpp
@@ -81,7 +81,8 @@
     TunerCallbackMock();
 
     MOCK_METHOD2(onTuneFailed, Return<void>(Result, const ProgramSelector&));
-    MOCK_TIMEOUT_METHOD1(onCurrentProgramInfoChanged, Return<void>(const ProgramInfo&));
+    MOCK_TIMEOUT_METHOD1(onCurrentProgramInfoChanged_, Return<void>(const ProgramInfo&));
+    virtual Return<void> onCurrentProgramInfoChanged(const ProgramInfo& info);
     Return<void> onProgramListUpdated(const ProgramListChunk& chunk);
     MOCK_METHOD1(onAntennaStateChange, Return<void>(bool connected));
     MOCK_METHOD1(onParametersUpdated, Return<void>(const hidl_vec<VendorKeyValue>& parameters));
@@ -122,12 +123,40 @@
 }
 
 TunerCallbackMock::TunerCallbackMock() {
-    EXPECT_TIMEOUT_CALL(*this, onCurrentProgramInfoChanged, _).Times(AnyNumber());
+    EXPECT_TIMEOUT_CALL(*this, onCurrentProgramInfoChanged_, _).Times(AnyNumber());
 
     // we expect the antenna is connected through the whole test
     EXPECT_CALL(*this, onAntennaStateChange(false)).Times(0);
 }
 
+Return<void> TunerCallbackMock::onCurrentProgramInfoChanged(const ProgramInfo& info) {
+    auto logically = utils::getType(info.logicallyTunedTo);
+    if (logically != IdentifierType::INVALID) {
+        EXPECT_TRUE(logically == IdentifierType::AMFM_FREQUENCY ||
+                    logically == IdentifierType::RDS_PI ||
+                    logically == IdentifierType::HD_STATION_ID_EXT ||
+                    logically == IdentifierType::DAB_SID_EXT ||
+                    logically == IdentifierType::DRMO_SERVICE_ID ||
+                    logically == IdentifierType::SXM_SERVICE_ID ||
+                    (logically >= IdentifierType::VENDOR_START &&
+                     logically <= IdentifierType::VENDOR_END) ||
+                    logically > IdentifierType::SXM_CHANNEL);
+    }
+
+    auto physically = utils::getType(info.physicallyTunedTo);
+    if (physically != IdentifierType::INVALID) {
+        EXPECT_TRUE(physically == IdentifierType::AMFM_FREQUENCY ||
+                    physically == IdentifierType::DAB_ENSEMBLE ||
+                    physically == IdentifierType::DRMO_FREQUENCY ||
+                    physically == IdentifierType::SXM_CHANNEL ||
+                    (physically >= IdentifierType::VENDOR_START &&
+                     physically <= IdentifierType::VENDOR_END) ||
+                    physically > IdentifierType::SXM_CHANNEL);
+    }
+
+    return onCurrentProgramInfoChanged_(info);
+}
+
 Return<void> TunerCallbackMock::onProgramListUpdated(const ProgramListChunk& chunk) {
     std::lock_guard<std::mutex> lk(mLock);
 
@@ -385,7 +414,7 @@
 
     // try tuning
     ProgramInfo infoCb = {};
-    EXPECT_TIMEOUT_CALL(*mCallback, onCurrentProgramInfoChanged,
+    EXPECT_TIMEOUT_CALL(*mCallback, onCurrentProgramInfoChanged_,
                         InfoHasId(utils::make_identifier(IdentifierType::AMFM_FREQUENCY, freq)))
         .Times(AnyNumber())
         .WillOnce(DoAll(SaveArg<0>(&infoCb), testing::Return(ByMove(Void()))));
@@ -399,7 +428,7 @@
 
     // expect a callback if it succeeds
     EXPECT_EQ(Result::OK, result);
-    EXPECT_TIMEOUT_CALL_WAIT(*mCallback, onCurrentProgramInfoChanged, timeout::tune);
+    EXPECT_TIMEOUT_CALL_WAIT(*mCallback, onCurrentProgramInfoChanged_, timeout::tune);
 
     ALOGD("current program info: %s", toString(infoCb).c_str());
 
@@ -469,15 +498,15 @@
     // TODO(b/69958777): see FmTune workaround
     std::this_thread::sleep_for(100ms);
 
-    EXPECT_TIMEOUT_CALL(*mCallback, onCurrentProgramInfoChanged, _);
+    EXPECT_TIMEOUT_CALL(*mCallback, onCurrentProgramInfoChanged_, _);
     auto result = mSession->scan(true /* up */, true /* skip subchannel */);
     EXPECT_EQ(Result::OK, result);
-    EXPECT_TIMEOUT_CALL_WAIT(*mCallback, onCurrentProgramInfoChanged, timeout::tune);
+    EXPECT_TIMEOUT_CALL_WAIT(*mCallback, onCurrentProgramInfoChanged_, timeout::tune);
 
-    EXPECT_TIMEOUT_CALL(*mCallback, onCurrentProgramInfoChanged, _);
+    EXPECT_TIMEOUT_CALL(*mCallback, onCurrentProgramInfoChanged_, _);
     result = mSession->scan(false /* down */, false /* don't skip subchannel */);
     EXPECT_EQ(Result::OK, result);
-    EXPECT_TIMEOUT_CALL_WAIT(*mCallback, onCurrentProgramInfoChanged, timeout::tune);
+    EXPECT_TIMEOUT_CALL_WAIT(*mCallback, onCurrentProgramInfoChanged_, timeout::tune);
 }
 
 /**
@@ -494,19 +523,19 @@
     // TODO(b/69958777): see FmTune workaround
     std::this_thread::sleep_for(100ms);
 
-    EXPECT_TIMEOUT_CALL(*mCallback, onCurrentProgramInfoChanged, _).Times(AnyNumber());
+    EXPECT_TIMEOUT_CALL(*mCallback, onCurrentProgramInfoChanged_, _).Times(AnyNumber());
     auto result = mSession->step(true /* up */);
     if (result == Result::NOT_SUPPORTED) {
         printSkipped("step not supported");
         return;
     }
     EXPECT_EQ(Result::OK, result);
-    EXPECT_TIMEOUT_CALL_WAIT(*mCallback, onCurrentProgramInfoChanged, timeout::tune);
+    EXPECT_TIMEOUT_CALL_WAIT(*mCallback, onCurrentProgramInfoChanged_, timeout::tune);
 
-    EXPECT_TIMEOUT_CALL(*mCallback, onCurrentProgramInfoChanged, _);
+    EXPECT_TIMEOUT_CALL(*mCallback, onCurrentProgramInfoChanged_, _);
     result = mSession->step(false /* down */);
     EXPECT_EQ(Result::OK, result);
-    EXPECT_TIMEOUT_CALL_WAIT(*mCallback, onCurrentProgramInfoChanged, timeout::tune);
+    EXPECT_TIMEOUT_CALL_WAIT(*mCallback, onCurrentProgramInfoChanged_, timeout::tune);
 }
 
 /**
@@ -768,9 +797,6 @@
     closeHandle->close();
 }
 
-// TODO(b/70939328): test ProgramInfo's currentlyTunedId and
-// currentlyTunedChannel once the program list is implemented.
-
 }  // namespace vts
 }  // namespace V2_0
 }  // namespace broadcastradio
diff --git a/broadcastradio/common/tests/Android.bp b/broadcastradio/common/tests/Android.bp
index f6a3b6f..3ba31db 100644
--- a/broadcastradio/common/tests/Android.bp
+++ b/broadcastradio/common/tests/Android.bp
@@ -33,7 +33,7 @@
         "android.hardware.broadcastradio@common-utils-2x-lib",
     ],
     shared_libs: [
-        "android.hardware.broadcastradio@1.2",
+        "android.hardware.broadcastradio@1.1",
         "android.hardware.broadcastradio@2.0",
     ],
 }
diff --git a/broadcastradio/common/utils1x/Android.bp b/broadcastradio/common/utils1x/Android.bp
index 127c15a..443dca1 100644
--- a/broadcastradio/common/utils1x/Android.bp
+++ b/broadcastradio/common/utils1x/Android.bp
@@ -28,6 +28,6 @@
     ],
     export_include_dirs: ["include"],
     shared_libs: [
-        "android.hardware.broadcastradio@1.2",
+        "android.hardware.broadcastradio@1.1",
     ],
 }
diff --git a/broadcastradio/common/utils1x/Utils.cpp b/broadcastradio/common/utils1x/Utils.cpp
index 7a59d6a..9c2cc3d 100644
--- a/broadcastradio/common/utils1x/Utils.cpp
+++ b/broadcastradio/common/utils1x/Utils.cpp
@@ -26,10 +26,10 @@
 namespace utils {
 
 using V1_0::Band;
+using V1_1::IdentifierType;
 using V1_1::ProgramIdentifier;
 using V1_1::ProgramSelector;
 using V1_1::ProgramType;
-using V1_2::IdentifierType;
 
 static bool isCompatibleProgramType(const uint32_t ia, const uint32_t ib) {
     auto a = static_cast<ProgramType>(ia);
@@ -86,7 +86,7 @@
 
             return haveEqualIds(a, b, IdentifierType::AMFM_FREQUENCY);
         case ProgramType::DAB:
-            return haveEqualIds(a, b, IdentifierType::DAB_SID_EXT);
+            return haveEqualIds(a, b, IdentifierType::DAB_SIDECC);
         case ProgramType::DRMO:
             return haveEqualIds(a, b, IdentifierType::DRMO_SERVICE_ID);
         case ProgramType::SXM:
@@ -126,35 +126,21 @@
 
 static bool maybeGetId(const ProgramSelector& sel, const IdentifierType type, uint64_t* val) {
     auto itype = static_cast<uint32_t>(type);
-    auto itypeAlt = itype;
-    if (type == IdentifierType::DAB_SIDECC) {
-        itypeAlt = static_cast<uint32_t>(IdentifierType::DAB_SID_EXT);
-    }
-    if (type == IdentifierType::DAB_SID_EXT) {
-        itypeAlt = static_cast<uint32_t>(IdentifierType::DAB_SIDECC);
-    }
 
-    if (sel.primaryId.type == itype || sel.primaryId.type == itypeAlt) {
+    if (sel.primaryId.type == itype) {
         if (val) *val = sel.primaryId.value;
         return true;
     }
 
     // not optimal, but we don't care in default impl
-    bool gotAlt = false;
     for (auto&& id : sel.secondaryIds) {
         if (id.type == itype) {
             if (val) *val = id.value;
             return true;
         }
-        // alternative identifier is a backup, we prefer original value
-        if (id.type == itypeAlt) {
-            if (val) *val = id.value;
-            gotAlt = true;
-            continue;
-        }
     }
 
-    return gotAlt;
+    return false;
 }
 
 bool hasId(const ProgramSelector& sel, const IdentifierType type) {
diff --git a/broadcastradio/common/utils1x/include/broadcastradio-utils-1x/Utils.h b/broadcastradio/common/utils1x/include/broadcastradio-utils-1x/Utils.h
index 5884b5a..d47746d 100644
--- a/broadcastradio/common/utils1x/include/broadcastradio-utils-1x/Utils.h
+++ b/broadcastradio/common/utils1x/include/broadcastradio-utils-1x/Utils.h
@@ -16,7 +16,7 @@
 #ifndef ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_1X_H
 #define ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_1X_H
 
-#include <android/hardware/broadcastradio/1.2/types.h>
+#include <android/hardware/broadcastradio/1.1/types.h>
 #include <chrono>
 #include <queue>
 #include <thread>
@@ -29,7 +29,6 @@
 enum class HalRevision : uint32_t {
     V1_0 = 1,
     V1_1,
-    V1_2,
 };
 
 /**
@@ -50,21 +49,21 @@
 bool isAm(const V1_0::Band band);
 bool isFm(const V1_0::Band band);
 
-bool hasId(const V1_1::ProgramSelector& sel, const V1_2::IdentifierType type);
+bool hasId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type);
 
 /**
  * Returns ID (either primary or secondary) for a given program selector.
  *
  * If the selector does not contain given type, returns 0 and emits a warning.
  */
-uint64_t getId(const V1_1::ProgramSelector& sel, const V1_2::IdentifierType type);
+uint64_t getId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type);
 
 /**
  * Returns ID (either primary or secondary) for a given program selector.
  *
  * If the selector does not contain given type, returns default value.
  */
-uint64_t getId(const V1_1::ProgramSelector& sel, const V1_2::IdentifierType type, uint64_t defval);
+uint64_t getId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type, uint64_t defval);
 
 V1_1::ProgramSelector make_selector(V1_0::Band band, uint32_t channel, uint32_t subChannel = 0);
 
diff --git a/camera/device/3.4/ICameraDeviceSession.hal b/camera/device/3.4/ICameraDeviceSession.hal
index 7afcf94..c41d90e 100644
--- a/camera/device/3.4/ICameraDeviceSession.hal
+++ b/camera/device/3.4/ICameraDeviceSession.hal
@@ -31,43 +31,6 @@
 interface ICameraDeviceSession extends @3.3::ICameraDeviceSession {
 
     /**
-     * constructDefaultRequestSettings_3_4:
-     *
-     * Create capture settings for standard camera use cases. Supports the
-     * new template enums added in @3.4.
-     *
-     * The device must return a settings buffer that is configured to meet the
-     * requested use case, which must be one of the CAMERA3_TEMPLATE_*
-     * enums. All request control fields must be included.
-     *
-     * Performance requirements:
-     *
-     * This must be a non-blocking call. The HAL should return from this call
-     * in 1ms, and must return from this call in 5ms.
-     *
-     * Return values:
-     * @return status Status code for the operation, one of:
-     *     OK:
-     *         On a successful construction of default settings.
-     *     INTERNAL_ERROR:
-     *         An unexpected internal error occurred, and the default settings
-     *         are not available.
-     *     ILLEGAL_ARGUMENT:
-     *         The camera HAL does not support the input template type
-     *     CAMERA_DISCONNECTED:
-     *         An external camera device has been disconnected, and is no longer
-     *         available. This camera device interface is now stale, and a new
-     *         instance must be acquired if the device is reconnected. All
-     *         subsequent calls on this interface must return
-     *         CAMERA_DISCONNECTED.
-     * @return requestTemplate The default capture request settings for the requested
-     *     use case, or an empty metadata structure if status is not OK.
-     *
-     */
-    constructDefaultRequestSettings_3_4(RequestTemplate type) generates
-            (Status status, @3.2::CameraMetadata requestTemplate);
-
-    /**
      * configureStreams_3_4:
      *
      * Identical to @3.3::ICameraDeviceSession.configureStreams, except that:
diff --git a/camera/device/3.4/default/CameraDeviceSession.cpp b/camera/device/3.4/default/CameraDeviceSession.cpp
index f6c6b2b..771197a 100644
--- a/camera/device/3.4/default/CameraDeviceSession.cpp
+++ b/camera/device/3.4/default/CameraDeviceSession.cpp
@@ -56,14 +56,6 @@
 CameraDeviceSession::~CameraDeviceSession() {
 }
 
-Return<void> CameraDeviceSession::constructDefaultRequestSettings_3_4(
-        RequestTemplate type, ICameraDeviceSession::constructDefaultRequestSettings_cb _hidl_cb)  {
-    V3_2::CameraMetadata outMetadata;
-    Status status = constructDefaultRequestSettingsRaw( (int) type, &outMetadata);
-    _hidl_cb(status, outMetadata);
-    return Void();
-}
-
 Return<void> CameraDeviceSession::configureStreams_3_4(
         const StreamConfiguration& requestedConfiguration,
         ICameraDeviceSession::configureStreams_3_4_cb _hidl_cb)  {
diff --git a/camera/device/3.4/default/ExternalCameraDevice.cpp b/camera/device/3.4/default/ExternalCameraDevice.cpp
index 569acfd..61b8921 100644
--- a/camera/device/3.4/default/ExternalCameraDevice.cpp
+++ b/camera/device/3.4/default/ExternalCameraDevice.cpp
@@ -44,9 +44,10 @@
 
 } // anonymous namespace
 
-ExternalCameraDevice::ExternalCameraDevice(const std::string& cameraId) :
+ExternalCameraDevice::ExternalCameraDevice(
+            const std::string& cameraId, const ExternalCameraConfig& cfg) :
         mCameraId(cameraId),
-        mCfg(ExternalCameraDeviceConfig::loadFromCfg()) {
+        mCfg(cfg) {
 
     status_t ret = initCameraCharacteristics();
     if (ret != OK) {
diff --git a/camera/device/3.4/default/ExternalCameraDeviceSession.cpp b/camera/device/3.4/default/ExternalCameraDeviceSession.cpp
index 51bfe36..b6728ed 100644
--- a/camera/device/3.4/default/ExternalCameraDeviceSession.cpp
+++ b/camera/device/3.4/default/ExternalCameraDeviceSession.cpp
@@ -55,7 +55,7 @@
 
 ExternalCameraDeviceSession::ExternalCameraDeviceSession(
         const sp<ICameraDeviceCallback>& callback,
-        const ExternalCameraDeviceConfig& cfg,
+        const ExternalCameraConfig& cfg,
         const std::vector<SupportedV4L2Format>& sortedFormats,
         const CroppingType& croppingType,
         const common::V1_0::helper::CameraMetadata& chars,
@@ -133,15 +133,6 @@
     return Void();
 }
 
-Return<void> ExternalCameraDeviceSession::constructDefaultRequestSettings_3_4(
-        RequestTemplate type,
-        ICameraDeviceSession::constructDefaultRequestSettings_cb _hidl_cb)  {
-    V3_2::CameraMetadata outMetadata;
-    Status status = constructDefaultRequestSettingsRaw(type, &outMetadata);
-    _hidl_cb(status, outMetadata);
-    return Void();
-}
-
 Status ExternalCameraDeviceSession::constructDefaultRequestSettingsRaw(RequestTemplate type,
         V3_2::CameraMetadata *outMetadata) {
     CameraMetadata emptyMd;
@@ -160,9 +151,7 @@
         }
         case RequestTemplate::MANUAL:
         case RequestTemplate::ZERO_SHUTTER_LAG:
-        case RequestTemplate::MOTION_TRACKING_PREVIEW:
-        case RequestTemplate::MOTION_TRACKING_BEST:
-            // Don't support MANUAL, ZSL, MOTION_TRACKING_* templates
+            // Don't support MANUAL, ZSL templates
             status = Status::ILLEGAL_ARGUMENT;
             break;
         default:
diff --git a/camera/device/3.4/default/ExternalCameraUtils.cpp b/camera/device/3.4/default/ExternalCameraUtils.cpp
index 212573a..80f296c 100644
--- a/camera/device/3.4/default/ExternalCameraUtils.cpp
+++ b/camera/device/3.4/default/ExternalCameraUtils.cpp
@@ -30,14 +30,6 @@
 namespace V3_4 {
 namespace implementation {
 
-namespace {
-    const int  kDefaultJpegBufSize = 5 << 20; // 5MB
-    const int  kDefaultNumVideoBuffer = 4;
-    const int  kDefaultNumStillBuffer = 2;
-} // anonymous namespace
-
-const char* ExternalCameraDeviceConfig::kDefaultCfgPath = "/vendor/etc/external_camera_config.xml";
-
 V4L2Frame::V4L2Frame(
         uint32_t w, uint32_t h, uint32_t fourcc,
         int bufIdx, int fd, uint32_t dataSize, uint64_t offset) :
@@ -148,10 +140,32 @@
     return 0;
 }
 
+bool isAspectRatioClose(float ar1, float ar2) {
+    const float kAspectRatioMatchThres = 0.025f; // This threshold is good enough to distinguish
+                                                // 4:3/16:9/20:9
+                                                // 1.33 / 1.78 / 2
+    return (std::abs(ar1 - ar2) < kAspectRatioMatchThres);
+}
 
-ExternalCameraDeviceConfig ExternalCameraDeviceConfig::loadFromCfg(const char* cfgPath) {
+}  // namespace implementation
+}  // namespace V3_4
+}  // namespace device
+
+
+namespace external {
+namespace common {
+
+namespace {
+    const int  kDefaultJpegBufSize = 5 << 20; // 5MB
+    const int  kDefaultNumVideoBuffer = 4;
+    const int  kDefaultNumStillBuffer = 2;
+} // anonymous namespace
+
+const char* ExternalCameraConfig::kDefaultCfgPath = "/vendor/etc/external_camera_config.xml";
+
+ExternalCameraConfig ExternalCameraConfig::loadFromCfg(const char* cfgPath) {
     using namespace tinyxml2;
-    ExternalCameraDeviceConfig ret;
+    ExternalCameraConfig ret;
 
     XMLDocument configXml;
     XMLError err = configXml.LoadFile(cfgPath);
@@ -169,6 +183,29 @@
         return ret;
     }
 
+    XMLElement *providerCfg = extCam->FirstChildElement("Provider");
+    if (providerCfg == nullptr) {
+        ALOGI("%s: no external camera provider config specified", __FUNCTION__);
+        return ret;
+    }
+
+    XMLElement *ignore = providerCfg->FirstChildElement("ignore");
+    if (ignore == nullptr) {
+        ALOGI("%s: no internal ignored device specified", __FUNCTION__);
+        return ret;
+    }
+
+    XMLElement *id = ignore->FirstChildElement("id");
+    while (id != nullptr) {
+        const char* text = id->GetText();
+        if (text != nullptr) {
+            ret.mInternalDevices.insert(text);
+            ALOGI("%s: device %s will be ignored by external camera provider",
+                    __FUNCTION__, text);
+        }
+        id = id->NextSiblingElement("id");
+    }
+
     XMLElement *deviceCfg = extCam->FirstChildElement("Device");
     if (deviceCfg == nullptr) {
         ALOGI("%s: no external camera device config specified", __FUNCTION__);
@@ -226,7 +263,7 @@
         ret.fpsLimits = limits;
     }
 
-    ALOGI("%s: external camera cfd loaded: maxJpgBufSize %d,"
+    ALOGI("%s: external camera cfg loaded: maxJpgBufSize %d,"
             " num video buffers %d, num still buffers %d",
             __FUNCTION__, ret.maxJpegBufSize,
             ret.numVideoBuffers, ret.numStillBuffers);
@@ -237,7 +274,7 @@
     return ret;
 }
 
-ExternalCameraDeviceConfig::ExternalCameraDeviceConfig() :
+ExternalCameraConfig::ExternalCameraConfig() :
         maxJpegBufSize(kDefaultJpegBufSize),
         numVideoBuffers(kDefaultNumVideoBuffer),
         numStillBuffers(kDefaultNumStillBuffer) {
@@ -247,16 +284,9 @@
     fpsLimits.push_back({/*Size*/{4096, 3072}, /*FPS upper bound*/5.0});
 }
 
-bool isAspectRatioClose(float ar1, float ar2) {
-    const float kAspectRatioMatchThres = 0.025f; // This threshold is good enough to distinguish
-                                                // 4:3/16:9/20:9
-                                                // 1.33 / 1.78 / 2
-    return (std::abs(ar1 - ar2) < kAspectRatioMatchThres);
-}
 
-}  // namespace implementation
-}  // namespace V3_4
-}  // namespace device
+}  // namespace common
+}  // namespace external
 }  // namespace camera
 }  // namespace hardware
 }  // namespace android
diff --git a/camera/device/3.4/default/include/device_v3_4_impl/CameraDeviceSession.h b/camera/device/3.4/default/include/device_v3_4_impl/CameraDeviceSession.h
index 9cd7da7..6e90ed4 100644
--- a/camera/device/3.4/default/include/device_v3_4_impl/CameraDeviceSession.h
+++ b/camera/device/3.4/default/include/device_v3_4_impl/CameraDeviceSession.h
@@ -74,11 +74,6 @@
 protected:
     // Methods from v3.3 and earlier will trampoline to inherited implementation
 
-    // New methods for v3.4
-    Return<void> constructDefaultRequestSettings_3_4(
-            RequestTemplate type,
-            ICameraDeviceSession::constructDefaultRequestSettings_cb _hidl_cb);
-
     Return<void> configureStreams_3_4(
             const StreamConfiguration& requestedConfiguration,
             ICameraDeviceSession::configureStreams_3_4_cb _hidl_cb);
@@ -163,12 +158,6 @@
             return mParent->close();
         }
 
-        virtual Return<void> constructDefaultRequestSettings_3_4(
-                RequestTemplate type,
-                ICameraDeviceSession::constructDefaultRequestSettings_cb _hidl_cb) override {
-            return mParent->constructDefaultRequestSettings_3_4(type, _hidl_cb);
-        }
-
         virtual Return<void> configureStreams_3_3(
                 const V3_2::StreamConfiguration& requestedConfiguration,
                 configureStreams_3_3_cb _hidl_cb) override {
diff --git a/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDeviceSession.h b/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDeviceSession.h
index fabf26a..a7eb121 100644
--- a/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDeviceSession.h
+++ b/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDeviceSession.h
@@ -53,7 +53,7 @@
 using ::android::hardware::camera::device::V3_2::ICameraDeviceCallback;
 using ::android::hardware::camera::device::V3_2::MsgType;
 using ::android::hardware::camera::device::V3_2::NotifyMsg;
-using ::android::hardware::camera::device::V3_4::RequestTemplate;
+using ::android::hardware::camera::device::V3_2::RequestTemplate;
 using ::android::hardware::camera::device::V3_2::Stream;
 using ::android::hardware::camera::device::V3_4::StreamConfiguration;
 using ::android::hardware::camera::device::V3_2::StreamConfigurationMode;
@@ -67,6 +67,9 @@
 using ::android::hardware::camera::common::V1_0::Status;
 using ::android::hardware::camera::common::V1_0::helper::HandleImporter;
 using ::android::hardware::camera::common::V1_0::helper::ExifUtils;
+using ::android::hardware::camera::external::common::ExternalCameraConfig;
+using ::android::hardware::camera::external::common::Size;
+using ::android::hardware::camera::external::common::SizeHasher;
 using ::android::hardware::graphics::common::V1_0::BufferUsage;
 using ::android::hardware::graphics::common::V1_0::Dataspace;
 using ::android::hardware::graphics::common::V1_0::PixelFormat;
@@ -84,7 +87,7 @@
 struct ExternalCameraDeviceSession : public virtual RefBase {
 
     ExternalCameraDeviceSession(const sp<ICameraDeviceCallback>&,
-            const ExternalCameraDeviceConfig& cfg,
+            const ExternalCameraConfig& cfg,
             const std::vector<SupportedV4L2Format>& sortedFormats,
             const CroppingType& croppingType,
             const common::V1_0::helper::CameraMetadata& chars,
@@ -110,11 +113,7 @@
     // Methods from ::android::hardware::camera::device::V3_2::ICameraDeviceSession follow
 
     Return<void> constructDefaultRequestSettings(
-            V3_2::RequestTemplate,
-            ICameraDeviceSession::constructDefaultRequestSettings_cb _hidl_cb);
-
-    Return<void> constructDefaultRequestSettings_3_4(
-            RequestTemplate type,
+            RequestTemplate,
             ICameraDeviceSession::constructDefaultRequestSettings_cb _hidl_cb);
 
     Return<void> configureStreams(
@@ -277,7 +276,7 @@
 
     mutable Mutex mLock; // Protect all private members except otherwise noted
     const sp<ICameraDeviceCallback> mCallback;
-    const ExternalCameraDeviceConfig mCfg;
+    const ExternalCameraConfig& mCfg;
     const common::V1_0::helper::CameraMetadata mCameraCharacteristics;
     const std::vector<SupportedV4L2Format> mSupportedFormats;
     const CroppingType mCroppingType;
@@ -293,7 +292,7 @@
 
     bool mV4l2Streaming = false;
     SupportedV4L2Format mV4l2StreamingFmt;
-    size_t mV4L2BufferCount;
+    size_t mV4L2BufferCount = 0;
 
     static const int kBufferWaitTimeoutSec = 3; // TODO: handle long exposure (or not allowing)
     std::mutex mV4l2BufferLock; // protect the buffer count and condition below
@@ -341,7 +340,7 @@
                 mParent(parent) {}
 
         virtual Return<void> constructDefaultRequestSettings(
-                V3_2::RequestTemplate type,
+                RequestTemplate type,
                 V3_3::ICameraDeviceSession::constructDefaultRequestSettings_cb _hidl_cb) override {
             return mParent->constructDefaultRequestSettings(type, _hidl_cb);
         }
@@ -376,12 +375,6 @@
             return mParent->close();
         }
 
-        virtual Return<void> constructDefaultRequestSettings_3_4(
-                RequestTemplate type,
-                ICameraDeviceSession::constructDefaultRequestSettings_cb _hidl_cb) override {
-            return mParent->constructDefaultRequestSettings_3_4(type, _hidl_cb);
-        }
-
         virtual Return<void> configureStreams_3_3(
                 const V3_2::StreamConfiguration& requestedConfiguration,
                 configureStreams_3_3_cb _hidl_cb) override {
diff --git a/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDevice_3_4.h b/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDevice_3_4.h
index ef4b41c..5880469 100644
--- a/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDevice_3_4.h
+++ b/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDevice_3_4.h
@@ -38,6 +38,8 @@
 using ::android::hardware::camera::common::V1_0::CameraResourceCost;
 using ::android::hardware::camera::common::V1_0::TorchMode;
 using ::android::hardware::camera::common::V1_0::Status;
+using ::android::hardware::camera::external::common::ExternalCameraConfig;
+using ::android::hardware::camera::external::common::Size;
 using ::android::hardware::Return;
 using ::android::hardware::Void;
 using ::android::hardware::hidl_vec;
@@ -54,7 +56,7 @@
     // be multiple CameraDevice trying to access the same physical camera.  Also, provider will have
     // to keep track of all CameraDevice objects in order to notify CameraDevice when the underlying
     // camera is detached.
-    ExternalCameraDevice(const std::string& cameraId);
+    ExternalCameraDevice(const std::string& cameraId, const ExternalCameraConfig& cfg);
     ~ExternalCameraDevice();
 
     // Caller must use this method to check if CameraDevice ctor failed
@@ -95,7 +97,7 @@
     Mutex mLock;
     bool mInitFailed = false;
     std::string mCameraId;
-    const ExternalCameraDeviceConfig mCfg;
+    const ExternalCameraConfig& mCfg;
     std::vector<SupportedV4L2Format> mSupportedFormats;
     CroppingType mCroppingType;
 
diff --git a/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraUtils.h b/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraUtils.h
index 849f947..e56160a 100644
--- a/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraUtils.h
+++ b/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraUtils.h
@@ -21,6 +21,7 @@
 #include "utils/LightRefBase.h"
 #include <mutex>
 #include <vector>
+#include <unordered_set>
 #include <android/hardware/graphics/mapper/2.0/IMapper.h>
 
 using android::hardware::graphics::mapper::V2_0::IMapper;
@@ -29,6 +30,60 @@
 namespace android {
 namespace hardware {
 namespace camera {
+
+namespace external {
+namespace common {
+
+struct Size {
+    uint32_t width;
+    uint32_t height;
+
+    bool operator==(const Size& other) const {
+        return (width == other.width && height == other.height);
+    }
+};
+
+struct SizeHasher {
+    size_t operator()(const Size& sz) const {
+        size_t result = 1;
+        result = 31 * result + sz.width;
+        result = 31 * result + sz.height;
+        return result;
+    }
+};
+
+struct ExternalCameraConfig {
+    static const char* kDefaultCfgPath;
+    static ExternalCameraConfig loadFromCfg(const char* cfgPath = kDefaultCfgPath);
+
+    // List of internal V4L2 video nodes external camera HAL must ignore.
+    std::unordered_set<std::string> mInternalDevices;
+
+    // Maximal size of a JPEG buffer, in bytes
+    uint32_t maxJpegBufSize;
+
+    // Maximum Size that can sustain 30fps streaming
+    Size maxVideoSize;
+
+    // Size of v4l2 buffer queue when streaming <= kMaxVideoSize
+    uint32_t numVideoBuffers;
+
+    // Size of v4l2 buffer queue when streaming > kMaxVideoSize
+    uint32_t numStillBuffers;
+
+    struct FpsLimitation {
+        Size size;
+        float fpsUpperBound;
+    };
+    std::vector<FpsLimitation> fpsLimits;
+
+private:
+    ExternalCameraConfig();
+};
+
+} // common
+} // external
+
 namespace device {
 namespace V3_4 {
 namespace implementation {
@@ -85,50 +140,6 @@
     VERTICAL = 1
 };
 
-struct Size {
-    uint32_t width;
-    uint32_t height;
-
-    bool operator==(const Size& other) const {
-        return (width == other.width && height == other.height);
-    }
-};
-
-struct SizeHasher {
-    size_t operator()(const Size& sz) const {
-        size_t result = 1;
-        result = 31 * result + sz.width;
-        result = 31 * result + sz.height;
-        return result;
-    }
-};
-
-struct ExternalCameraDeviceConfig {
-    static const char* kDefaultCfgPath;
-    static ExternalCameraDeviceConfig loadFromCfg(const char* cfgPath = kDefaultCfgPath);
-
-    // Maximal size of a JPEG buffer, in bytes
-    uint32_t maxJpegBufSize;
-
-    // Maximum Size that can sustain 30fps streaming
-    Size maxVideoSize;
-
-    // Size of v4l2 buffer queue when streaming <= kMaxVideoSize
-    uint32_t numVideoBuffers;
-
-    // Size of v4l2 buffer queue when streaming > kMaxVideoSize
-    uint32_t numStillBuffers;
-
-    struct FpsLimitation {
-        Size size;
-        float fpsUpperBound;
-    };
-    std::vector<FpsLimitation> fpsLimits;
-
-private:
-    ExternalCameraDeviceConfig();
-};
-
 // Aspect ratio is defined as width/height here and ExternalCameraDevice
 // will guarantee all supported sizes has width >= height (so aspect ratio >= 1.0)
 #define ASPECT_RATIO(sz) (static_cast<float>((sz).width) / (sz).height)
diff --git a/camera/device/3.4/types.hal b/camera/device/3.4/types.hal
index c8ebb17..5681a5c 100644
--- a/camera/device/3.4/types.hal
+++ b/camera/device/3.4/types.hal
@@ -78,36 +78,6 @@
 };
 
 /**
- * New request templates, extending the @3.2 RequestTemplate
- */
-enum RequestTemplate : @3.2::RequestTemplate {
-    /**
-     * A template for selecting camera parameters that match TEMPLATE_PREVIEW as closely as
-     * possible while improving the camera output for motion tracking use cases.
-     *
-     * This template is best used by applications that are frequently switching between motion
-     * tracking use cases and regular still capture use cases, to minimize the IQ changes
-     * when swapping use cases.
-     *
-     * This template is guaranteed to be supported on camera devices that support the
-     * REQUEST_AVAILABLE_CAPABILITIES_MOTION_TRACKING capability.
-     */
-    MOTION_TRACKING_PREVIEW = 7,
-
-    /**
-     * A template for selecting camera parameters that maximize the quality of camera output for
-     * motion tracking use cases.
-     *
-     * This template is best used by applications dedicated to motion tracking applications,
-     * which aren't concerned about fast switches between motion tracking and other use cases.
-     *
-     * This template is guaranteed to be supported on camera devices that support the
-     * REQUEST_AVAILABLE_CAPABILITIES_MOTION_TRACKING capability.
-     */
-    MOTION_TRACKING_BEST = 8,
-};
-
-/**
  * StreamConfiguration:
  *
  * Identical to @3.2::StreamConfiguration, except that it contains session
diff --git a/camera/metadata/3.3/types.hal b/camera/metadata/3.3/types.hal
index d2a5886..b70802a 100644
--- a/camera/metadata/3.3/types.hal
+++ b/camera/metadata/3.3/types.hal
@@ -94,7 +94,7 @@
 
     /** android.statistics.oisDataMode [dynamic, enum, public]
      *
-     * <p>Whether the camera device outputs the OIS data in output
+     * <p>A control for selecting whether OIS position information is included in output
      * result metadata.</p>
      */
     ANDROID_STATISTICS_OIS_DATA_MODE = android.hardware.camera.metadata@3.2::CameraMetadataTag:ANDROID_STATISTICS_END,
@@ -200,12 +200,12 @@
     ANDROID_REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA,
 };
 
-/** android.logicalMultiCamera.sensorSyncType enumeration values
- * @see ANDROID_LOGICAL_MULTI_CAMERA_SENSOR_SYNC_TYPE
+/** android.statistics.oisDataMode enumeration values
+ * @see ANDROID_STATISTICS_OIS_DATA_MODE
  */
-enum CameraMetadataEnumAndroidLogicalMultiCameraSensorSyncType : uint32_t {
-    ANDROID_LOGICAL_MULTI_CAMERA_SENSOR_SYNC_TYPE_APPROXIMATE,
-    ANDROID_LOGICAL_MULTI_CAMERA_SENSOR_SYNC_TYPE_CALIBRATED,
+enum CameraMetadataEnumAndroidStatisticsOisDataMode : uint32_t {
+    ANDROID_STATISTICS_OIS_DATA_MODE_OFF,
+    ANDROID_STATISTICS_OIS_DATA_MODE_ON,
 };
 
 /** android.info.supportedHardwareLevel enumeration values added since v3.2
@@ -216,10 +216,10 @@
     ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL,
 };
 
-/** android.statistics.oisDataMode enumeration values
- * @see ANDROID_STATISTICS_OIS_DATA_MODE
+/** android.logicalMultiCamera.sensorSyncType enumeration values
+ * @see ANDROID_LOGICAL_MULTI_CAMERA_SENSOR_SYNC_TYPE
  */
-enum CameraMetadataEnumAndroidStatisticsOisDataMode : uint32_t {
-    ANDROID_STATISTICS_OIS_DATA_MODE_OFF,
-    ANDROID_STATISTICS_OIS_DATA_MODE_ON,
+enum CameraMetadataEnumAndroidLogicalMultiCameraSensorSyncType : uint32_t {
+    ANDROID_LOGICAL_MULTI_CAMERA_SENSOR_SYNC_TYPE_APPROXIMATE,
+    ANDROID_LOGICAL_MULTI_CAMERA_SENSOR_SYNC_TYPE_CALIBRATED,
 };
diff --git a/camera/provider/2.4/default/ExternalCameraProvider.cpp b/camera/provider/2.4/default/ExternalCameraProvider.cpp
index 7657fa3..faa4e3a 100644
--- a/camera/provider/2.4/default/ExternalCameraProvider.cpp
+++ b/camera/provider/2.4/default/ExternalCameraProvider.cpp
@@ -24,7 +24,6 @@
 #include <linux/videodev2.h>
 #include "ExternalCameraProvider.h"
 #include "ExternalCameraDevice_3_4.h"
-#include "tinyxml2.h" // XML parsing
 
 namespace android {
 namespace hardware {
@@ -38,6 +37,8 @@
 const std::regex kDeviceNameRE("device@([0-9]+\\.[0-9]+)/external/(.+)");
 const int kMaxDevicePathLen = 256;
 const char* kDevicePath = "/dev/";
+constexpr char kPrefix[] = "video";
+constexpr int kPrefixLen = sizeof(kPrefix) - 1;
 
 bool matchDeviceName(const hidl_string& deviceName, std::string* deviceVersion,
                      std::string* cameraId) {
@@ -58,6 +59,7 @@
 } // anonymous namespace
 
 ExternalCameraProvider::ExternalCameraProvider() :
+        mCfg(ExternalCameraConfig::loadFromCfg()),
         mHotPlugThread(this) {
     mHotPlugThread.run("ExtCamHotPlug", PRIORITY_BACKGROUND);
 }
@@ -69,8 +71,17 @@
 
 Return<Status> ExternalCameraProvider::setCallback(
         const sp<ICameraProviderCallback>& callback) {
-    Mutex::Autolock _l(mLock);
-    mCallbacks = callback;
+    {
+        Mutex::Autolock _l(mLock);
+        mCallbacks = callback;
+    }
+    // Send a callback for all devices to initialize
+    {
+        for (const auto& pair : mCameraStatusMap) {
+            mCallbacks->cameraDeviceStatusChange(pair.first, pair.second);
+        }
+    }
+
     return Status::OK;
 }
 
@@ -82,14 +93,9 @@
 }
 
 Return<void> ExternalCameraProvider::getCameraIdList(getCameraIdList_cb _hidl_cb) {
-    std::vector<hidl_string> deviceNameList;
-    for (auto const& kvPair : mCameraStatusMap) {
-        if (kvPair.second == CameraDeviceStatus::PRESENT) {
-            deviceNameList.push_back(kvPair.first);
-        }
-    }
-    hidl_vec<hidl_string> hidlDeviceNameList(deviceNameList);
-    ALOGV("ExtCam: number of cameras is %zu", deviceNameList.size());
+    // External camera HAL always report 0 camera, and extra cameras
+    // are just reported via cameraDeviceStatusChange callbacks
+    hidl_vec<hidl_string> hidlDeviceNameList;
     _hidl_cb(Status::OK, hidlDeviceNameList);
     return Void();
 }
@@ -130,7 +136,7 @@
     sp<device::V3_2::ICameraDevice> device;
     sp<device::V3_4::implementation::ExternalCameraDevice> deviceImpl =
             new device::V3_4::implementation::ExternalCameraDevice(
-                    cameraId);
+                    cameraId, mCfg);
     if (deviceImpl == nullptr || deviceImpl->isInitFailed()) {
         ALOGE("%s: camera device %s init failed!", __FUNCTION__, cameraId.c_str());
         device = nullptr;
@@ -194,59 +200,10 @@
     }
 }
 
-std::unordered_set<std::string>
-ExternalCameraProvider::HotplugThread::initInternalDevices() {
-    std::unordered_set<std::string> ret;
-    using device::V3_4::implementation::ExternalCameraDeviceConfig;
-    const char* configPath = ExternalCameraDeviceConfig::kDefaultCfgPath;
-
-    using namespace tinyxml2;
-
-    XMLDocument configXml;
-    XMLError err = configXml.LoadFile(configPath);
-    if (err != XML_SUCCESS) {
-        ALOGE("%s: Unable to load external camera config file '%s'. Error: %s",
-                __FUNCTION__, configPath, XMLDocument::ErrorIDToName(err));
-    } else {
-        ALOGI("%s: load external camera config succeed!", __FUNCTION__);
-    }
-
-    XMLElement *extCam = configXml.FirstChildElement("ExternalCamera");
-    if (extCam == nullptr) {
-        ALOGI("%s: no external camera config specified", __FUNCTION__);
-        return ret;
-    }
-
-    XMLElement *providerCfg = extCam->FirstChildElement("Provider");
-    if (providerCfg == nullptr) {
-        ALOGI("%s: no external camera provider config specified", __FUNCTION__);
-        return ret;
-    }
-
-    XMLElement *ignore = providerCfg->FirstChildElement("ignore");
-    if (ignore == nullptr) {
-        ALOGI("%s: no internal ignored device specified", __FUNCTION__);
-        return ret;
-    }
-
-    XMLElement *id = ignore->FirstChildElement("id");
-    while (id != nullptr) {
-        const char* text = id->GetText();
-        if (text != nullptr) {
-            ret.insert(text);
-            ALOGI("%s: device %s will be ignored by external camera provider",
-                    __FUNCTION__, text);
-        }
-        id = id->NextSiblingElement("id");
-    }
-
-    return ret;
-}
-
 ExternalCameraProvider::HotplugThread::HotplugThread(ExternalCameraProvider* parent) :
         Thread(/*canCallJava*/false),
         mParent(parent),
-        mInternalDevices(initInternalDevices()) {}
+        mInternalDevices(parent->mCfg.mInternalDevices) {}
 
 ExternalCameraProvider::HotplugThread::~HotplugThread() {}
 
@@ -261,10 +218,10 @@
     struct dirent* de;
     while ((de = readdir(devdir)) != 0) {
         // Find external v4l devices that's existing before we start watching and add them
-        if (!strncmp("video", de->d_name, 5)) {
+        if (!strncmp(kPrefix, de->d_name, kPrefixLen)) {
             // TODO: This might reject some valid devices. Ex: internal is 33 and a device named 3
             //       is added.
-            std::string deviceId(de->d_name + 5);
+            std::string deviceId(de->d_name + kPrefixLen);
             if (mInternalDevices.count(deviceId) == 0) {
                 ALOGV("Non-internal v4l device %s found", de->d_name);
                 char v4l2DevicePath[kMaxDevicePathLen];
@@ -300,8 +257,8 @@
             while (offset < ret) {
                 struct inotify_event* event = (struct inotify_event*)&eventBuf[offset];
                 if (event->wd == mWd) {
-                    if (!strncmp("video", event->name, 5)) {
-                        std::string deviceId(event->name + 5);
+                    if (!strncmp(kPrefix, event->name, kPrefixLen)) {
+                        std::string deviceId(event->name + kPrefixLen);
                         if (mInternalDevices.count(deviceId) == 0) {
                             char v4l2DevicePath[kMaxDevicePathLen];
                             snprintf(v4l2DevicePath, kMaxDevicePathLen,
diff --git a/camera/provider/2.4/default/ExternalCameraProvider.h b/camera/provider/2.4/default/ExternalCameraProvider.h
index 64a8878..c83cc70 100644
--- a/camera/provider/2.4/default/ExternalCameraProvider.h
+++ b/camera/provider/2.4/default/ExternalCameraProvider.h
@@ -25,6 +25,7 @@
 #include <android/hardware/camera/provider/2.4/ICameraProvider.h>
 #include <hidl/Status.h>
 #include <hidl/MQDescriptor.h>
+#include "ExternalCameraUtils.h"
 
 namespace android {
 namespace hardware {
@@ -36,6 +37,7 @@
 using ::android::hardware::camera::common::V1_0::CameraDeviceStatus;
 using ::android::hardware::camera::common::V1_0::Status;
 using ::android::hardware::camera::common::V1_0::VendorTagSection;
+using ::android::hardware::camera::external::common::ExternalCameraConfig;
 using ::android::hardware::camera::provider::V2_4::ICameraProvider;
 using ::android::hardware::camera::provider::V2_4::ICameraProviderCallback;
 using ::android::hardware::Return;
@@ -81,8 +83,6 @@
         virtual bool threadLoop() override;
 
     private:
-        static std::unordered_set<std::string> initInternalDevices();
-
         ExternalCameraProvider* mParent = nullptr;
         const std::unordered_set<std::string> mInternalDevices;
 
@@ -93,6 +93,7 @@
     Mutex mLock;
     sp<ICameraProviderCallback> mCallbacks = nullptr;
     std::unordered_map<std::string, CameraDeviceStatus> mCameraStatusMap; // camera id -> status
+    const ExternalCameraConfig mCfg;
     HotplugThread mHotPlugThread;
 };
 
diff --git a/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp b/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp
index 193253a..053d37a 100644
--- a/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp
+++ b/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp
@@ -17,6 +17,7 @@
 #define LOG_TAG "mediacas_hidl_hal_test"
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <android-base/logging.h>
 #include <android/hardware/cas/1.0/ICas.h>
 #include <android/hardware/cas/1.0/ICasListener.h>
@@ -206,10 +207,23 @@
     EXPECT_TRUE(mEventData == eventData);
 }
 
+// Test environment for Cas HIDL HAL.
+class CasHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static CasHidlEnvironment* Instance() {
+        static CasHidlEnvironment* instance = new CasHidlEnvironment;
+        return instance;
+    }
+
+    virtual void registerTestServices() override { registerTestService<IMediaCasService>(); }
+};
+
 class MediaCasHidlTest : public ::testing::VtsHalHidlTargetTestBase {
    public:
     virtual void SetUp() override {
-        mService = ::testing::VtsHalHidlTargetTestBase::getService<IMediaCasService>();
+        mService = ::testing::VtsHalHidlTargetTestBase::getService<IMediaCasService>(
+            CasHidlEnvironment::Instance()->getServiceName<IMediaCasService>());
         ASSERT_NE(mService, nullptr);
     }
 
@@ -843,7 +857,9 @@
 }  // anonymous namespace
 
 int main(int argc, char** argv) {
+    ::testing::AddGlobalTestEnvironment(CasHidlEnvironment::Instance());
     ::testing::InitGoogleTest(&argc, argv);
+    CasHidlEnvironment::Instance()->init(&argc, argv);
     int status = RUN_ALL_TESTS();
     LOG(INFO) << "Test result = " << status;
     return status;
diff --git a/compatibility_matrices/Android.mk b/compatibility_matrices/Android.mk
index 1c86f11..71253da 100644
--- a/compatibility_matrices/Android.mk
+++ b/compatibility_matrices/Android.mk
@@ -61,8 +61,9 @@
 LOCAL_SRC_FILES := $(LOCAL_MODULE_STEM)
 LOCAL_ADD_VBMETA_VERSION := true
 LOCAL_ASSEMBLE_VINTF_ENV_VARS := \
-	POLICYVERS \
-	BOARD_SEPOLICY_VERS
+    POLICYVERS \
+    PLATFORM_SEPOLICY_VERSION \
+    PLATFORM_SEPOLICY_COMPAT_VERSIONS
 
 include $(BUILD_FRAMEWORK_COMPATIBILITY_MATRIX)
 
diff --git a/compatibility_matrices/compatibility_matrix.mk b/compatibility_matrices/compatibility_matrix.mk
index 14c60ab..96815b8 100644
--- a/compatibility_matrices/compatibility_matrix.mk
+++ b/compatibility_matrices/compatibility_matrix.mk
@@ -78,7 +78,7 @@
 
 $(GEN): PRIVATE_SRC_FILES := $(my_matrix_src_files)
 $(GEN): $(my_matrix_src_files) $(HOST_OUT_EXECUTABLES)/assemble_vintf
-	$(foreach varname,$(PRIVATE_ENV_VARS),$(varname)=$($(varname))) \
+	$(foreach varname,$(PRIVATE_ENV_VARS),$(varname)="$($(varname))") \
 		$(HOST_OUT_EXECUTABLES)/assemble_vintf \
 		-i $(call normalize-path-list,$(PRIVATE_SRC_FILES)) \
 		-o $@ \
diff --git a/configstore/1.0/vts/functional/VtsHalConfigstoreV1_0TargetTest.cpp b/configstore/1.0/vts/functional/VtsHalConfigstoreV1_0TargetTest.cpp
index e501580..a1676be 100644
--- a/configstore/1.0/vts/functional/VtsHalConfigstoreV1_0TargetTest.cpp
+++ b/configstore/1.0/vts/functional/VtsHalConfigstoreV1_0TargetTest.cpp
@@ -17,6 +17,7 @@
 #define LOG_TAG "ConfigstoreHidlHalTest"
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <android-base/logging.h>
 #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
 #include <android/hardware/configstore/1.0/types.h>
@@ -34,13 +35,25 @@
 #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
 #define EXPECT_OK(ret) EXPECT_TRUE(ret.isOk())
 
+// Test environment for Configstore HIDL HAL.
+class ConfigstoreHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static ConfigstoreHidlEnvironment* Instance() {
+        static ConfigstoreHidlEnvironment* instance = new ConfigstoreHidlEnvironment;
+        return instance;
+    }
+
+    virtual void registerTestServices() override { registerTestService<ISurfaceFlingerConfigs>(); }
+};
+
 class ConfigstoreHidlTest : public ::testing::VtsHalHidlTargetTestBase {
    public:
     sp<ISurfaceFlingerConfigs> sfConfigs;
 
     virtual void SetUp() override {
-        sfConfigs = ::testing::VtsHalHidlTargetTestBase::getService<
-            ISurfaceFlingerConfigs>();
+        sfConfigs = ::testing::VtsHalHidlTargetTestBase::getService<ISurfaceFlingerConfigs>(
+            ConfigstoreHidlEnvironment::Instance()->getServiceName<ISurfaceFlingerConfigs>());
         ASSERT_NE(sfConfigs, nullptr);
     }
 
@@ -119,7 +132,9 @@
 }
 
 int main(int argc, char** argv) {
+    ::testing::AddGlobalTestEnvironment(ConfigstoreHidlEnvironment::Instance());
     ::testing::InitGoogleTest(&argc, argv);
+    ConfigstoreHidlEnvironment::Instance()->init(&argc, argv);
     int status = RUN_ALL_TESTS();
     LOG(INFO) << "Test result = " << status;
     return status;
diff --git a/drm/1.1/IDrmPlugin.hal b/drm/1.1/IDrmPlugin.hal
index 7dd397a..2980dc2 100644
--- a/drm/1.1/IDrmPlugin.hal
+++ b/drm/1.1/IDrmPlugin.hal
@@ -26,6 +26,7 @@
 import @1.0::SecureStopId;
 import @1.1::SecureStopRelease;
 import @1.1::SecurityLevel;
+import @1.0::SessionId;
 
 /**
  * IDrmPlugin is used to interact with a specific drm plugin that was created by
@@ -34,6 +35,34 @@
  */
 interface IDrmPlugin extends @1.0::IDrmPlugin {
     /**
+     * Open a new session at a requested security level. The security level
+     * represents the robustness of the device's DRM implementation. By default,
+     * sessions are opened at the native security level of the device which is
+     * the maximum level that can be supported. Overriding the security level is
+     * necessary when the decrypted frames need to be manipulated, such as for
+     * image compositing. The security level parameter must be equal to or lower
+     * than the native level. If the requested level is not supported, the next
+     * lower supported security level must be set. The level can be queried
+     * using {@link #getSecurityLevel}. A session ID is returned.  When the
+     * drm@1.0 openSession is called, which has no securityLevel parameter, the
+     * security level is defaulted to the native security level of the device.
+     *
+     * @return status the status of the call. The status must be OK or one of
+     *     the following errors: ERROR_DRM_NOT_PROVISIONED if the device
+     *     requires provisioning before it can open a session,
+     *     ERROR_DRM_RESOURCE_BUSY if there are insufficent resources available
+     *     to open a session, ERROR_DRM_CANNOT_HANDLE if the requested security
+     *     level is higher than the native level or lower than the lowest
+     *     supported level or if openSession is not supported at the time of
+     *     the call, or ERROR_DRM_INVALID_STATE if the HAL is in a state where
+     *     a session cannot be opened.
+     * @param level the requested security level
+     * @return sessionId the session ID for the newly opened session
+     */
+    openSession_1_1(SecurityLevel securityLevel) generates (Status status,
+            SessionId sessionId);
+
+    /**
      * A key request/response exchange occurs between the app and a License
      * Server to obtain the keys required to decrypt the content.
      * getKeyRequest_1_1() is used to obtain an opaque key request blob that is
@@ -149,24 +178,6 @@
             SecurityLevel level);
 
     /**
-     * Set the security level of a session. This can be useful if specific
-     * attributes of a lower security level are needed by an application, such
-     * as image manipulation or compositing which requires non-secure decoded
-     * frames. Reducing the security level may limit decryption to lower content
-     * resolutions, depending on the license policy.
-     *
-     * @param sessionId the session id the call applies to
-     * @param level the requested security level
-     * @return status the status of the call. The status must be OK or one of
-     *         the following errors: ERROR_DRM_SESSION_NOT_OPENED if the session
-     *         is not opened, BAD_VALUE if the sessionId or security level is
-     *         invalid or ERROR_DRM_INVALID_STATE if the HAL is in a state where
-     *         the security level cannot be set.
-     */
-    setSecurityLevel(vec<uint8_t> sessionId, SecurityLevel level)
-            generates(Status status);
-
-    /**
      * Returns the plugin-specific metrics. Multiple metric groups may be
      * returned in one call to getMetrics(). The scope and definition of the
      * metrics is defined by the plugin.
diff --git a/drm/1.1/vts/functional/drm_hal_clearkey_test.cpp b/drm/1.1/vts/functional/drm_hal_clearkey_test.cpp
index 62cc8b6..a8ed0e5 100644
--- a/drm/1.1/vts/functional/drm_hal_clearkey_test.cpp
+++ b/drm/1.1/vts/functional/drm_hal_clearkey_test.cpp
@@ -158,6 +158,7 @@
     virtual void TearDown() override {}
 
     SessionId openSession();
+    SessionId openSession(SecurityLevel level);
     void closeSession(const SessionId& sessionId);
     hidl_vec<uint8_t> loadKeys(const SessionId& sessionId, const KeyType& type);
     sp<IMemory> getDecryptMemory(size_t size, size_t index);
@@ -277,6 +278,23 @@
 }
 
 /**
+ * Helper method to open as session using V1.1 API
+ */
+SessionId DrmHalClearkeyTest::openSession(SecurityLevel level) {
+    SessionId sessionId;
+
+    auto res = drmPlugin->openSession_1_1(level,
+            [&sessionId](Status status, const SessionId& id) {
+                EXPECT_EQ(Status::OK, status);
+                EXPECT_NE(0u, id.size());
+                sessionId = id;
+            });
+    EXPECT_OK(res);
+    return sessionId;
+}
+
+
+/**
  * Helper method to close a session
  */
 void DrmHalClearkeyTest::closeSession(const SessionId& sessionId) {
@@ -298,14 +316,14 @@
 }
 
 /**
- * Test that the plugin returns valid open and max session counts
+ * Test that the plugin returns default open and max session counts
  */
-TEST_F(DrmHalClearkeyTest, GetSessionCounts) {
+TEST_F(DrmHalClearkeyTest, GetDefaultSessionCounts) {
     auto res = drmPlugin->getNumberOfSessions(
             [&](Status status, uint32_t currentSessions,
                     uint32_t maxSessions) {
                 EXPECT_EQ(Status::OK, status);
-                EXPECT_GT(maxSessions, (uint32_t)0);
+                EXPECT_GE(maxSessions, (uint32_t)8);
                 EXPECT_GE(currentSessions, (uint32_t)0);
                 EXPECT_LE(currentSessions, maxSessions);
             });
@@ -313,16 +331,76 @@
 }
 
 /**
- * Test that the plugin returns a valid security level for
- * a valid session
+ * Test that the plugin returns valid open and max session counts
+ * after a session is opened.
  */
-TEST_F(DrmHalClearkeyTest, GetSecurityLevel) {
+TEST_F(DrmHalClearkeyTest, GetOpenSessionCounts) {
+    uint32_t initialSessions = 0;
+    auto res = drmPlugin->getNumberOfSessions(
+            [&](Status status, uint32_t currentSessions,
+                    uint32_t maxSessions) {
+                EXPECT_EQ(Status::OK, status);
+                EXPECT_GE(maxSessions, (uint32_t)8);
+                EXPECT_GE(currentSessions, (uint32_t)0);
+                EXPECT_LE(currentSessions, maxSessions);
+                initialSessions = currentSessions;
+            });
+    EXPECT_OK(res);
+
     SessionId session = openSession();
+    res = drmPlugin->getNumberOfSessions(
+            [&](Status status, uint32_t currentSessions,
+                    uint32_t /*maxSessions*/) {
+                EXPECT_EQ(Status::OK, status);
+                EXPECT_EQ(currentSessions, initialSessions + 1);
+            });
+    EXPECT_OK(res);
+
+    closeSession(session);
+    res = drmPlugin->getNumberOfSessions(
+            [&](Status status, uint32_t currentSessions,
+                    uint32_t /*maxSessions*/) {
+                EXPECT_EQ(Status::OK, status);
+                EXPECT_EQ(currentSessions, initialSessions);
+            });
+    EXPECT_OK(res);
+}
+
+/**
+ * Test that the plugin returns the same security level
+ * by default as when it is requested explicitly
+ */
+TEST_F(DrmHalClearkeyTest, GetDefaultSecurityLevel) {
+    SessionId session = openSession();
+    SecurityLevel defaultLevel;
     auto res = drmPlugin->getSecurityLevel(session,
             [&](Status status, SecurityLevel level) {
                 EXPECT_EQ(Status::OK, status);
-                EXPECT_GE(level, SecurityLevel::SW_SECURE_CRYPTO);
-                EXPECT_LE(level, SecurityLevel::HW_SECURE_ALL);
+                defaultLevel = level;
+            });
+    EXPECT_OK(res);
+    closeSession(session);
+
+    session = openSession(defaultLevel);
+    res = drmPlugin->getSecurityLevel(session,
+            [&](Status status, SecurityLevel level) {
+                EXPECT_EQ(Status::OK, status);
+                EXPECT_EQ(level, defaultLevel);
+            });
+    EXPECT_OK(res);
+    closeSession(session);
+}
+
+/**
+ * Test that the plugin returns the lowest security level
+ * when it is requested
+ */
+TEST_F(DrmHalClearkeyTest, GetSecurityLevel) {
+    SessionId session = openSession(SecurityLevel::SW_SECURE_CRYPTO);
+    auto res = drmPlugin->getSecurityLevel(session,
+            [&](Status status, SecurityLevel level) {
+                EXPECT_EQ(Status::OK, status);
+                EXPECT_EQ(level, SecurityLevel::SW_SECURE_CRYPTO);
             });
     EXPECT_OK(res);
     closeSession(session);
@@ -342,51 +420,6 @@
 }
 
 /**
- * Test that setting all valid security levels on a valid sessionId
- * is supported
- */
-TEST_F(DrmHalClearkeyTest, SetSecurityLevel) {
-    SessionId session = openSession();
-    for (uint32_t level = static_cast<uint32_t>(SecurityLevel::SW_SECURE_CRYPTO);
-         level <= static_cast<uint32_t>(SecurityLevel::HW_SECURE_ALL); level++) {
-        EXPECT_EQ(Status::OK, drmPlugin->setSecurityLevel(session, static_cast<SecurityLevel>(level)));
-
-        // check that the level got set
-        auto res = drmPlugin->getSecurityLevel(session,
-                [&](Status status, SecurityLevel readLevel) {
-                    EXPECT_EQ(Status::OK, status);
-                    EXPECT_EQ(level, static_cast<uint32_t>(readLevel));
-                });
-        EXPECT_OK(res);
-    }
-    closeSession(session);
-}
-
-/**
- * Test that setting an invalid security level on a valid
- * sessionId is prohibited with the documented error code.
- */
-TEST_F(DrmHalClearkeyTest, SetInvalidSecurityLevel) {
-    SessionId session = openSession();
-    SecurityLevel level = static_cast<SecurityLevel>(
-            static_cast<uint32_t>(SecurityLevel::HW_SECURE_ALL) + 1);
-    Status status = drmPlugin->setSecurityLevel(session, level);
-    EXPECT_EQ(Status::BAD_VALUE, status);
-    closeSession(session);
-}
-
-/**
- * Test that attempting to set security level on an invalid
- * (empty) sessionId is prohibited with the documented error
- * code.
- */
-TEST_F(DrmHalClearkeyTest, SetSecurityLevelInvalidSessionId) {
-    SessionId session;
-    SecurityLevel level = SecurityLevel::SW_SECURE_CRYPTO;
-    EXPECT_EQ(Status::BAD_VALUE, drmPlugin->setSecurityLevel(session, level));
-}
-
-/**
  * Test metrics are set appropriately for open and close operations.
  */
 TEST_F(DrmHalClearkeyTest, GetMetricsSuccess) {
diff --git a/dumpstate/1.0/vts/functional/VtsHalDumpstateV1_0TargetTest.cpp b/dumpstate/1.0/vts/functional/VtsHalDumpstateV1_0TargetTest.cpp
index 9e866e7..57ebf2a 100644
--- a/dumpstate/1.0/vts/functional/VtsHalDumpstateV1_0TargetTest.cpp
+++ b/dumpstate/1.0/vts/functional/VtsHalDumpstateV1_0TargetTest.cpp
@@ -24,15 +24,29 @@
 #include <log/log.h>
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 
 using ::android::hardware::dumpstate::V1_0::IDumpstateDevice;
 using ::android::hardware::Return;
 using ::android::sp;
 
+// Test environment for Dumpstate HIDL HAL.
+class DumpstateHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static DumpstateHidlEnvironment* Instance() {
+        static DumpstateHidlEnvironment* instance = new DumpstateHidlEnvironment;
+        return instance;
+    }
+
+    virtual void registerTestServices() override { registerTestService<IDumpstateDevice>(); }
+};
+
 class DumpstateHidlTest : public ::testing::VtsHalHidlTargetTestBase {
    public:
     virtual void SetUp() override {
-        dumpstate = ::testing::VtsHalHidlTargetTestBase::getService<IDumpstateDevice>();
+        dumpstate = ::testing::VtsHalHidlTargetTestBase::getService<IDumpstateDevice>(
+            DumpstateHidlEnvironment::Instance()->getServiceName<IDumpstateDevice>());
         ASSERT_NE(dumpstate, nullptr) << "Could not get HIDL instance";
     }
 
@@ -98,7 +112,9 @@
 }
 
 int main(int argc, char** argv) {
+    ::testing::AddGlobalTestEnvironment(DumpstateHidlEnvironment::Instance());
     ::testing::InitGoogleTest(&argc, argv);
+    DumpstateHidlEnvironment::Instance()->init(&argc, argv);
     int status = RUN_ALL_TESTS();
     ALOGI("Test result = %d", status);
     return status;
diff --git a/gatekeeper/1.0/vts/functional/VtsHalGatekeeperV1_0TargetTest.cpp b/gatekeeper/1.0/vts/functional/VtsHalGatekeeperV1_0TargetTest.cpp
index e9a44eb..715e9fc 100644
--- a/gatekeeper/1.0/vts/functional/VtsHalGatekeeperV1_0TargetTest.cpp
+++ b/gatekeeper/1.0/vts/functional/VtsHalGatekeeperV1_0TargetTest.cpp
@@ -33,6 +33,7 @@
 #include <log/log.h>
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 
 using ::android::hardware::hidl_string;
 using ::android::hardware::hidl_vec;
@@ -77,6 +78,20 @@
   return auth_token;
 }
 
+// Test environment for Gatekeeper HIDL HAL.
+class GatekeeperHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+ public:
+  // get the test environment singleton
+  static GatekeeperHidlEnvironment* Instance() {
+    static GatekeeperHidlEnvironment* instance = new GatekeeperHidlEnvironment;
+    return instance;
+  }
+
+  virtual void registerTestServices() override { registerTestService<IGatekeeper>(); }
+ private:
+  GatekeeperHidlEnvironment() {}
+};
+
 // The main test class for Gatekeeper HIDL HAL.
 class GatekeeperHidlTest : public ::testing::VtsHalHidlTargetTestBase {
  protected:
@@ -189,7 +204,8 @@
   GatekeeperHidlTest() : uid_(0) {}
   virtual void SetUp() override {
     GatekeeperResponse rsp;
-    gatekeeper_ = ::testing::VtsHalHidlTargetTestBase::getService<IGatekeeper>();
+    gatekeeper_ = ::testing::VtsHalHidlTargetTestBase::getService<IGatekeeper>(
+        GatekeeperHidlEnvironment::Instance()->getServiceName<IGatekeeper>());
     ASSERT_NE(nullptr, gatekeeper_.get());
     doDeleteAllUsers(rsp);
   }
@@ -433,7 +449,9 @@
 }
 
 int main(int argc, char **argv) {
+  ::testing::AddGlobalTestEnvironment(GatekeeperHidlEnvironment::Instance());
   ::testing::InitGoogleTest(&argc, argv);
+  GatekeeperHidlEnvironment::Instance()->init(&argc, argv);
   int status = RUN_ALL_TESTS();
   ALOGI("Test result = %d", status);
   return status;
diff --git a/gnss/1.0/vts/functional/VtsHalGnssV1_0TargetTest.cpp b/gnss/1.0/vts/functional/VtsHalGnssV1_0TargetTest.cpp
index b3ab594..010a46d 100644
--- a/gnss/1.0/vts/functional/VtsHalGnssV1_0TargetTest.cpp
+++ b/gnss/1.0/vts/functional/VtsHalGnssV1_0TargetTest.cpp
@@ -19,6 +19,7 @@
 #include <log/log.h>
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 
 #include <chrono>
 #include <condition_variable>
@@ -41,6 +42,21 @@
 bool sAgpsIsPresent = false;  // if SUPL or XTRA assistance available
 bool sSignalIsWeak = false;   // if GNSS signals are weak (e.g. light indoor)
 
+// Test environment for GNSS HIDL HAL.
+class GnssHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+ public:
+  // get the test environment singleton
+  static GnssHidlEnvironment* Instance() {
+    static GnssHidlEnvironment* instance = new GnssHidlEnvironment;
+    return instance;
+  }
+
+  virtual void registerTestServices() override { registerTestService<IGnss>(); }
+
+ private:
+  GnssHidlEnvironment() {}
+};
+
 // The main test class for GNSS HAL.
 class GnssHalTest : public ::testing::VtsHalHidlTargetTestBase {
  public:
@@ -51,7 +67,8 @@
     info_called_count_ = 0;
     notify_count_ = 0;
 
-    gnss_hal_ = ::testing::VtsHalHidlTargetTestBase::getService<IGnss>();
+    gnss_hal_ = ::testing::VtsHalHidlTargetTestBase::getService<IGnss>(
+        GnssHidlEnvironment::Instance()->getServiceName<IGnss>());
     ASSERT_NE(gnss_hal_, nullptr);
 
     gnss_cb_ = new GnssCallback(*this);
@@ -456,17 +473,19 @@
 }
 
 int main(int argc, char** argv) {
+  ::testing::AddGlobalTestEnvironment(GnssHidlEnvironment::Instance());
   ::testing::InitGoogleTest(&argc, argv);
+  GnssHidlEnvironment::Instance()->init(&argc, argv);
   /*
    * These arguments not used by automated VTS testing.
    * Only for use in manual testing, when wanting to run
    * stronger tests that require the presence of GPS signal.
    */
   for (int i = 1; i < argc; i++) {
-      if (strcmp(argv[i], "-agps") == 0) {
-          sAgpsIsPresent = true;
-      } else if (strcmp(argv[i], "-weak") == 0) {
-          sSignalIsWeak = true;
+    if (strcmp(argv[i], "-agps") == 0) {
+        sAgpsIsPresent = true;
+    } else if (strcmp(argv[i], "-weak") == 0) {
+        sSignalIsWeak = true;
     }
   }
   int status = RUN_ALL_TESTS();
diff --git a/gnss/1.1/vts/functional/VtsHalGnssV1_1TargetTest.cpp b/gnss/1.1/vts/functional/VtsHalGnssV1_1TargetTest.cpp
index 9b805e4..ca9eef4 100644
--- a/gnss/1.1/vts/functional/VtsHalGnssV1_1TargetTest.cpp
+++ b/gnss/1.1/vts/functional/VtsHalGnssV1_1TargetTest.cpp
@@ -13,12 +13,17 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#define LOG_TAG "VtsHalGnssV1_1TargetTest"
 
 #include <VtsHalHidlTargetTestBase.h>
 
+#include "gnss_hal_test.h"
+
 int main(int argc, char** argv) {
+    ::testing::AddGlobalTestEnvironment(GnssHidlEnvironment::Instance());
     ::testing::InitGoogleTest(&argc, argv);
+    GnssHidlEnvironment::Instance()->init(&argc, argv);
     int status = RUN_ALL_TESTS();
     ALOGI("Test result = %d", status);
     return status;
-}
\ No newline at end of file
+}
diff --git a/gnss/1.1/vts/functional/gnss_hal_test.cpp b/gnss/1.1/vts/functional/gnss_hal_test.cpp
index 7e43b92..23b7317 100644
--- a/gnss/1.1/vts/functional/gnss_hal_test.cpp
+++ b/gnss/1.1/vts/functional/gnss_hal_test.cpp
@@ -27,7 +27,8 @@
       notify_count_(0) {}
 
 void GnssHalTest::SetUp() {
-    gnss_hal_ = ::testing::VtsHalHidlTargetTestBase::getService<IGnss>();
+    gnss_hal_ = ::testing::VtsHalHidlTargetTestBase::getService<IGnss>(
+        GnssHidlEnvironment::Instance()->getServiceName<IGnss>());
     list_gnss_sv_status_.clear();
     ASSERT_NE(gnss_hal_, nullptr);
 }
diff --git a/gnss/1.1/vts/functional/gnss_hal_test.h b/gnss/1.1/vts/functional/gnss_hal_test.h
index 6aab3cb..6d5bb4c 100644
--- a/gnss/1.1/vts/functional/gnss_hal_test.h
+++ b/gnss/1.1/vts/functional/gnss_hal_test.h
@@ -17,11 +17,10 @@
 #ifndef GNSS_HAL_TEST_H_
 #define GNSS_HAL_TEST_H_
 
-#define LOG_TAG "VtsHalGnssV1_1TargetTest"
-
 #include <android/hardware/gnss/1.1/IGnss.h>
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 
 #include <condition_variable>
 #include <list>
@@ -40,6 +39,21 @@
 
 #define TIMEOUT_SEC 2  // for basic commands/responses
 
+// Test environment for GNSS HIDL HAL.
+class GnssHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static GnssHidlEnvironment* Instance() {
+        static GnssHidlEnvironment* instance = new GnssHidlEnvironment;
+        return instance;
+    }
+
+    virtual void registerTestServices() override { registerTestService<IGnss>(); }
+
+   private:
+    GnssHidlEnvironment() {}
+};
+
 // The main test class for GNSS HAL.
 class GnssHalTest : public ::testing::VtsHalHidlTargetTestBase {
    public:
diff --git a/gnss/1.1/vts/functional/gnss_hal_test_cases.cpp b/gnss/1.1/vts/functional/gnss_hal_test_cases.cpp
index 0b27922..264a11d 100644
--- a/gnss/1.1/vts/functional/gnss_hal_test_cases.cpp
+++ b/gnss/1.1/vts/functional/gnss_hal_test_cases.cpp
@@ -429,23 +429,26 @@
             EXPECT_GE(data.position.bearingDegrees, -360);
             EXPECT_LE(data.position.bearingDegrees, 360);
 
-            EXPECT_GE(data.position.horizontalAccuracyMeters, 0);
+            EXPECT_GT(data.position.horizontalAccuracyMeters, 0);
             EXPECT_LE(data.position.horizontalAccuracyMeters, 20000000);
 
-            EXPECT_GE(data.position.verticalAccuracyMeters, 0);
+            EXPECT_GT(data.position.verticalAccuracyMeters, 0);
             EXPECT_LE(data.position.verticalAccuracyMeters, 20000);
 
-            EXPECT_GE(data.position.speedAccuracyMetersPerSecond, 0);
+            EXPECT_GT(data.position.speedAccuracyMetersPerSecond, 0);
             EXPECT_LE(data.position.speedAccuracyMetersPerSecond, 500);
 
-            EXPECT_GE(data.position.bearingAccuracyDegrees, 0);
+            EXPECT_GT(data.position.bearingAccuracyDegrees, 0);
             EXPECT_LE(data.position.bearingAccuracyDegrees, 180);
 
             EXPECT_GE(data.position.ageSeconds, 0);
         }
 
         EXPECT_GE(data.time.timeEstimate, 1514764800000);  // Jan 01 2018 00:00:00
+
         EXPECT_GT(data.time.timeUncertaintyNs, 0);
+
         EXPECT_GT(data.time.frequencyUncertaintyNsPerSec, 0);
+        EXPECT_LE(data.time.frequencyUncertaintyNsPerSec, 2.0e5);  // 200 ppm
     }
 }
diff --git a/ir/1.0/vts/functional/VtsHalIrV1_0TargetTest.cpp b/ir/1.0/vts/functional/VtsHalIrV1_0TargetTest.cpp
index a017404..5fd2dd4 100644
--- a/ir/1.0/vts/functional/VtsHalIrV1_0TargetTest.cpp
+++ b/ir/1.0/vts/functional/VtsHalIrV1_0TargetTest.cpp
@@ -22,6 +22,7 @@
 #include <android/hardware/ir/1.0/types.h>
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <algorithm>
 
 using ::android::hardware::ir::V1_0::IConsumerIr;
@@ -30,11 +31,26 @@
 using ::android::hardware::Return;
 using ::android::sp;
 
+// Test environment for Ir
+class ConsumerIrHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+ public:
+  // get the test environment singleton
+  static ConsumerIrHidlEnvironment* Instance() {
+    static ConsumerIrHidlEnvironment* instance = new ConsumerIrHidlEnvironment;
+    return instance;
+  }
+
+  virtual void registerTestServices() override { registerTestService<IConsumerIr>(); }
+ private:
+  ConsumerIrHidlEnvironment() {}
+};
+
 // The main test class for IR HIDL HAL.
 class ConsumerIrHidlTest : public ::testing::VtsHalHidlTargetTestBase {
  public:
   virtual void SetUp() override {
-    ir = ::testing::VtsHalHidlTargetTestBase::getService<IConsumerIr>();
+    ir = ::testing::VtsHalHidlTargetTestBase::getService<IConsumerIr>(
+      ConsumerIrHidlEnvironment::Instance()->getServiceName<IConsumerIr>());
     ASSERT_NE(ir, nullptr);
   }
 
@@ -77,7 +93,9 @@
 }
 
 int main(int argc, char **argv) {
+  ::testing::AddGlobalTestEnvironment(ConsumerIrHidlEnvironment::Instance());
   ::testing::InitGoogleTest(&argc, argv);
+  ConsumerIrHidlEnvironment::Instance()->init(&argc, argv);
   int status = RUN_ALL_TESTS();
   LOG(INFO) << "Test result = " << status;
   return status;
diff --git a/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp b/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp
index 6abd9bf..3a181a9 100644
--- a/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp
+++ b/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp
@@ -33,19 +33,14 @@
 #include "key_param_output.h"
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 
 #include "attestation_record.h"
 #include "openssl_utils.h"
 
 using ::android::sp;
-
 using ::std::string;
 
-// This service_name will be passed to getService when retrieving the keymaster service to test.  To
-// change it from "default" specify the selected service name on the command line.  The first
-// non-gtest argument will be used as the service name.
-string service_name = "default";
-
 static bool arm_deleteAllKeys = false;
 static bool dump_Attestations = false;
 
@@ -417,6 +412,20 @@
 
 }  // namespace
 
+// Test environment for Keymaster HIDL HAL.
+class KeymasterHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static KeymasterHidlEnvironment* Instance() {
+        static KeymasterHidlEnvironment* instance = new KeymasterHidlEnvironment;
+        return instance;
+    }
+
+    virtual void registerTestServices() override { registerTestService<IKeymasterDevice>(); }
+   private:
+    KeymasterHidlEnvironment() {}
+};
+
 class KeymasterHidlTest : public ::testing::VtsHalHidlTargetTestBase {
   public:
     void TearDown() override {
@@ -428,7 +437,8 @@
 
     // SetUpTestCase runs only once per test case, not once per test.
     static void SetUpTestCase() {
-        keymaster_ = IKeymasterDevice::getService(service_name);
+        keymaster_ = ::testing::VtsHalHidlTargetTestBase::getService<IKeymasterDevice>(
+            KeymasterHidlEnvironment::Instance()->getServiceName<IKeymasterDevice>());
         ASSERT_NE(keymaster_, nullptr);
 
         ASSERT_TRUE(
@@ -4203,8 +4213,10 @@
 }  // namespace android
 
 int main(int argc, char** argv) {
+    using android::hardware::keymaster::V3_0::test::KeymasterHidlEnvironment;
+    ::testing::AddGlobalTestEnvironment(KeymasterHidlEnvironment::Instance());
     ::testing::InitGoogleTest(&argc, argv);
-    std::vector<std::string> positional_args;
+    KeymasterHidlEnvironment::Instance()->init(&argc, argv);
     for (int i = 1; i < argc; ++i) {
         if (argv[i][0] == '-') {
             if (std::string(argv[i]) == "--arm_deleteAllKeys") {
@@ -4213,14 +4225,8 @@
             if (std::string(argv[i]) == "--dump_attestations") {
                 dump_Attestations = true;
             }
-        } else {
-            positional_args.push_back(argv[i]);
         }
     }
-    if (positional_args.size()) {
-        ALOGI("Running keymaster VTS against service \"%s\"", positional_args[0].c_str());
-        service_name = positional_args[0];
-    }
     int status = RUN_ALL_TESTS();
     ALOGI("Test result = %d", status);
     return status;
diff --git a/light/2.0/vts/functional/VtsHalLightV2_0TargetTest.cpp b/light/2.0/vts/functional/VtsHalLightV2_0TargetTest.cpp
index 3405422..13290d9 100644
--- a/light/2.0/vts/functional/VtsHalLightV2_0TargetTest.cpp
+++ b/light/2.0/vts/functional/VtsHalLightV2_0TargetTest.cpp
@@ -16,12 +16,13 @@
 
 #define LOG_TAG "light_hidl_hal_test"
 
+#include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <android-base/logging.h>
 #include <android/hardware/light/2.0/ILight.h>
 #include <android/hardware/light/2.0/types.h>
-#include <VtsHalHidlTargetTestBase.h>
-#include <set>
 #include <unistd.h>
+#include <set>
 
 using ::android::hardware::light::V2_0::Brightness;
 using ::android::hardware::light::V2_0::Flash;
@@ -72,10 +73,25 @@
     Type::WIFI
 };
 
+// Test environment for Light HIDL HAL.
+class LightHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static LightHidlEnvironment* Instance() {
+        static LightHidlEnvironment* instance = new LightHidlEnvironment;
+        return instance;
+    }
+
+    virtual void registerTestServices() override { registerTestService<ILight>(); }
+   private:
+    LightHidlEnvironment() {}
+};
+
 class LightHidlTest : public ::testing::VtsHalHidlTargetTestBase {
 public:
     virtual void SetUp() override {
-        light = ::testing::VtsHalHidlTargetTestBase::getService<ILight>();
+        light = ::testing::VtsHalHidlTargetTestBase::getService<ILight>(
+            LightHidlEnvironment::Instance()->getServiceName<ILight>());
 
         ASSERT_NE(light, nullptr);
         LOG(INFO) << "Test is remote " << light->isRemote();
@@ -149,7 +165,9 @@
 }
 
 int main(int argc, char **argv) {
+    ::testing::AddGlobalTestEnvironment(LightHidlEnvironment::Instance());
     ::testing::InitGoogleTest(&argc, argv);
+    LightHidlEnvironment::Instance()->init(&argc, argv);
     int status = RUN_ALL_TESTS();
     LOG(INFO) << "Test result = " << status;
     return status;
diff --git a/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioDecTest.cpp b/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioDecTest.cpp
index 38cdcd6..42f9947 100644
--- a/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioDecTest.cpp
+++ b/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioDecTest.cpp
@@ -50,85 +50,6 @@
 #include <media_hidl_test_common.h>
 #include <fstream>
 
-// A class for test environment setup
-class ComponentTestEnvironment : public ::testing::Environment {
-   public:
-    virtual void SetUp() {}
-    virtual void TearDown() {}
-
-    ComponentTestEnvironment() : instance("default"), res("/sdcard/media/") {}
-
-    void setInstance(const char* _instance) { instance = _instance; }
-
-    void setComponent(const char* _component) { component = _component; }
-
-    void setRole(const char* _role) { role = _role; }
-
-    void setRes(const char* _res) { res = _res; }
-
-    const hidl_string getInstance() const { return instance; }
-
-    const hidl_string getComponent() const { return component; }
-
-    const hidl_string getRole() const { return role; }
-
-    const hidl_string getRes() const { return res; }
-
-    int initFromOptions(int argc, char** argv) {
-        static struct option options[] = {
-            {"instance", required_argument, 0, 'I'},
-            {"component", required_argument, 0, 'C'},
-            {"role", required_argument, 0, 'R'},
-            {"res", required_argument, 0, 'P'},
-            {0, 0, 0, 0}};
-
-        while (true) {
-            int index = 0;
-            int c = getopt_long(argc, argv, "I:C:R:P:", options, &index);
-            if (c == -1) {
-                break;
-            }
-
-            switch (c) {
-                case 'I':
-                    setInstance(optarg);
-                    break;
-                case 'C':
-                    setComponent(optarg);
-                    break;
-                case 'R':
-                    setRole(optarg);
-                    break;
-                case 'P':
-                    setRes(optarg);
-                    break;
-                case '?':
-                    break;
-            }
-        }
-
-        if (optind < argc) {
-            fprintf(stderr,
-                    "unrecognized option: %s\n\n"
-                    "usage: %s <gtest options> <test options>\n\n"
-                    "test options are:\n\n"
-                    "-I, --instance: HAL instance to test\n"
-                    "-C, --component: OMX component to test\n"
-                    "-R, --role: OMX component Role\n"
-                    "-P, --res: Resource files directory location\n",
-                    argv[optind ?: 1], argv[0]);
-            return 2;
-        }
-        return 0;
-    }
-
-   private:
-    hidl_string instance;
-    hidl_string component;
-    hidl_string role;
-    hidl_string res;
-};
-
 static ComponentTestEnvironment* gEnv = nullptr;
 
 // audio decoder test fixture class
@@ -1220,6 +1141,7 @@
     gEnv = new ComponentTestEnvironment();
     ::testing::AddGlobalTestEnvironment(gEnv);
     ::testing::InitGoogleTest(&argc, argv);
+    gEnv->init(&argc, argv);
     int status = gEnv->initFromOptions(argc, argv);
     if (status == 0) {
         status = RUN_ALL_TESTS();
diff --git a/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioEncTest.cpp b/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioEncTest.cpp
index 953dc75..d5f1f2d 100644
--- a/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioEncTest.cpp
+++ b/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioEncTest.cpp
@@ -50,85 +50,6 @@
 #include <media_hidl_test_common.h>
 #include <fstream>
 
-// A class for test environment setup
-class ComponentTestEnvironment : public ::testing::Environment {
-   public:
-    virtual void SetUp() {}
-    virtual void TearDown() {}
-
-    ComponentTestEnvironment() : instance("default"), res("/sdcard/media/") {}
-
-    void setInstance(const char* _instance) { instance = _instance; }
-
-    void setComponent(const char* _component) { component = _component; }
-
-    void setRole(const char* _role) { role = _role; }
-
-    void setRes(const char* _res) { res = _res; }
-
-    const hidl_string getInstance() const { return instance; }
-
-    const hidl_string getComponent() const { return component; }
-
-    const hidl_string getRole() const { return role; }
-
-    const hidl_string getRes() const { return res; }
-
-    int initFromOptions(int argc, char** argv) {
-        static struct option options[] = {
-            {"instance", required_argument, 0, 'I'},
-            {"component", required_argument, 0, 'C'},
-            {"role", required_argument, 0, 'R'},
-            {"res", required_argument, 0, 'P'},
-            {0, 0, 0, 0}};
-
-        while (true) {
-            int index = 0;
-            int c = getopt_long(argc, argv, "I:C:R:P:", options, &index);
-            if (c == -1) {
-                break;
-            }
-
-            switch (c) {
-                case 'I':
-                    setInstance(optarg);
-                    break;
-                case 'C':
-                    setComponent(optarg);
-                    break;
-                case 'R':
-                    setRole(optarg);
-                    break;
-                case 'P':
-                    setRes(optarg);
-                    break;
-                case '?':
-                    break;
-            }
-        }
-
-        if (optind < argc) {
-            fprintf(stderr,
-                    "unrecognized option: %s\n\n"
-                    "usage: %s <gtest options> <test options>\n\n"
-                    "test options are:\n\n"
-                    "-I, --instance: HAL instance to test\n"
-                    "-C, --component: OMX component to test\n"
-                    "-R, --role: OMX component Role\n"
-                    "-P, --res: Resource files directory location\n",
-                    argv[optind ?: 1], argv[0]);
-            return 2;
-        }
-        return 0;
-    }
-
-   private:
-    hidl_string instance;
-    hidl_string component;
-    hidl_string role;
-    hidl_string res;
-};
-
 static ComponentTestEnvironment* gEnv = nullptr;
 
 // audio encoder test fixture class
@@ -562,6 +483,7 @@
     gEnv = new ComponentTestEnvironment();
     ::testing::AddGlobalTestEnvironment(gEnv);
     ::testing::InitGoogleTest(&argc, argv);
+    gEnv->init(&argc, argv);
     int status = gEnv->initFromOptions(argc, argv);
     if (status == 0) {
         status = RUN_ALL_TESTS();
diff --git a/media/omx/1.0/vts/functional/common/media_hidl_test_common.h b/media/omx/1.0/vts/functional/common/media_hidl_test_common.h
index bec733d..c1863d5 100644
--- a/media/omx/1.0/vts/functional/common/media_hidl_test_common.h
+++ b/media/omx/1.0/vts/functional/common/media_hidl_test_common.h
@@ -21,6 +21,7 @@
 #define OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS
 #endif
 
+#include <getopt.h>
 #include <media/stagefright/foundation/ALooper.h>
 #include <utils/Condition.h>
 #include <utils/List.h>
@@ -33,6 +34,8 @@
 #include <media/openmax/OMX_AudioExt.h>
 #include <media/openmax/OMX_VideoExt.h>
 
+#include <VtsHalHidlTargetTestEnvBase.h>
+
 /* TIME OUTS (Wait time in dequeueMessage()) */
 
 /* As component is switching states (loaded<->idle<->execute), dequeueMessage()
@@ -355,4 +358,77 @@
              portreconfig fptr = nullptr, OMX_U32 kPortIndexInput = 0,
              OMX_U32 kPortIndexOutput = 1, void* args = nullptr);
 
+// A class for test environment setup
+class ComponentTestEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   private:
+    typedef ::testing::VtsHalHidlTargetTestEnvBase Super;
+
+   public:
+    virtual void registerTestServices() override { registerTestService<IOmx>(); }
+
+    ComponentTestEnvironment() : res("/sdcard/media/") {}
+
+    void setComponent(const char* _component) { component = _component; }
+
+    void setRole(const char* _role) { role = _role; }
+
+    void setRes(const char* _res) { res = _res; }
+
+    const hidl_string getInstance() { return Super::getServiceName<IOmx>(); }
+
+    const hidl_string getComponent() const { return component; }
+
+    const hidl_string getRole() const { return role; }
+
+    const hidl_string getRes() const { return res; }
+
+    int initFromOptions(int argc, char** argv) {
+        static struct option options[] = {{"component", required_argument, 0, 'C'},
+                                          {"role", required_argument, 0, 'R'},
+                                          {"res", required_argument, 0, 'P'},
+                                          {0, 0, 0, 0}};
+
+        while (true) {
+            int index = 0;
+            int c = getopt_long(argc, argv, "C:R:P:", options, &index);
+            if (c == -1) {
+                break;
+            }
+
+            switch (c) {
+                case 'C':
+                    setComponent(optarg);
+                    break;
+                case 'R':
+                    setRole(optarg);
+                    break;
+                case 'P':
+                    setRes(optarg);
+                    break;
+                case '?':
+                    break;
+            }
+        }
+
+        if (optind < argc) {
+            fprintf(stderr,
+                    "unrecognized option: %s\n\n"
+                    "usage: %s <gtest options> <test options>\n\n"
+                    "test options are:\n\n"
+                    "-C, --component: OMX component to test\n"
+                    "-R, --role: OMX component Role\n"
+                    "-P, --res: Resource files directory location\n",
+                    argv[optind ?: 1], argv[0]);
+            return 2;
+        }
+        return 0;
+    }
+
+   private:
+    hidl_string instance;
+    hidl_string component;
+    hidl_string role;
+    hidl_string res;
+};
+
 #endif  // MEDIA_HIDL_TEST_COMMON_H
diff --git a/media/omx/1.0/vts/functional/component/VtsHalMediaOmxV1_0TargetComponentTest.cpp b/media/omx/1.0/vts/functional/component/VtsHalMediaOmxV1_0TargetComponentTest.cpp
index d66136d..f7c8433 100644
--- a/media/omx/1.0/vts/functional/component/VtsHalMediaOmxV1_0TargetComponentTest.cpp
+++ b/media/omx/1.0/vts/functional/component/VtsHalMediaOmxV1_0TargetComponentTest.cpp
@@ -48,75 +48,6 @@
 #include <getopt.h>
 #include <media_hidl_test_common.h>
 
-// A class for test environment setup
-class ComponentTestEnvironment : public ::testing::Environment {
-   public:
-    virtual void SetUp() {}
-    virtual void TearDown() {}
-
-    ComponentTestEnvironment() : instance("default") {}
-
-    void setInstance(const char* _instance) { instance = _instance; }
-
-    void setComponent(const char* _component) { component = _component; }
-
-    void setRole(const char* _role) { role = _role; }
-
-    const hidl_string getInstance() const { return instance; }
-
-    const hidl_string getComponent() const { return component; }
-
-    const hidl_string getRole() const { return role; }
-
-    int initFromOptions(int argc, char** argv) {
-        static struct option options[] = {
-            {"instance", required_argument, 0, 'I'},
-            {"component", required_argument, 0, 'C'},
-            {"role", required_argument, 0, 'R'},
-            {0, 0, 0, 0}};
-
-        while (true) {
-            int index = 0;
-            int c = getopt_long(argc, argv, "I:C:R:", options, &index);
-            if (c == -1) {
-                break;
-            }
-
-            switch (c) {
-                case 'I':
-                    setInstance(optarg);
-                    break;
-                case 'C':
-                    setComponent(optarg);
-                    break;
-                case 'R':
-                    setRole(optarg);
-                    break;
-                case '?':
-                    break;
-            }
-        }
-
-        if (optind < argc) {
-            fprintf(stderr,
-                    "unrecognized option: %s\n\n"
-                    "usage: %s <gtest options> <test options>\n\n"
-                    "test options are:\n\n"
-                    "-I, --instance: HAL instance to test\n"
-                    "-C, --component: OMX component to test\n"
-                    "-R, --Role: OMX component Role\n",
-                    argv[optind ?: 1], argv[0]);
-            return 2;
-        }
-        return 0;
-    }
-
-   private:
-    hidl_string instance;
-    hidl_string component;
-    hidl_string role;
-};
-
 static ComponentTestEnvironment* gEnv = nullptr;
 
 // generic component test fixture class
@@ -1321,6 +1252,7 @@
     gEnv = new ComponentTestEnvironment();
     ::testing::AddGlobalTestEnvironment(gEnv);
     ::testing::InitGoogleTest(&argc, argv);
+    gEnv->init(&argc, argv);
     int status = gEnv->initFromOptions(argc, argv);
     if (status == 0) {
         status = RUN_ALL_TESTS();
diff --git a/media/omx/1.0/vts/functional/master/VtsHalMediaOmxV1_0TargetMasterTest.cpp b/media/omx/1.0/vts/functional/master/VtsHalMediaOmxV1_0TargetMasterTest.cpp
index 5a31d69..64abe1c 100644
--- a/media/omx/1.0/vts/functional/master/VtsHalMediaOmxV1_0TargetMasterTest.cpp
+++ b/media/omx/1.0/vts/functional/master/VtsHalMediaOmxV1_0TargetMasterTest.cpp
@@ -50,54 +50,6 @@
 #include <getopt.h>
 #include <media_hidl_test_common.h>
 
-// A class for test environment setup
-class ComponentTestEnvironment : public ::testing::Environment {
-   public:
-    virtual void SetUp() {}
-    virtual void TearDown() {}
-
-    ComponentTestEnvironment() : instance("default") {}
-
-    void setInstance(const char* _instance) { instance = _instance; }
-
-    const hidl_string getInstance() const { return instance; }
-
-    int initFromOptions(int argc, char** argv) {
-        static struct option options[] = {
-            {"instance", required_argument, 0, 'I'}, {0, 0, 0, 0}};
-
-        while (true) {
-            int index = 0;
-            int c = getopt_long(argc, argv, "I:", options, &index);
-            if (c == -1) {
-                break;
-            }
-
-            switch (c) {
-                case 'I':
-                    setInstance(optarg);
-                    break;
-                case '?':
-                    break;
-            }
-        }
-
-        if (optind < argc) {
-            fprintf(stderr,
-                    "unrecognized option: %s\n\n"
-                    "usage: %s <gtest options> <test options>\n\n"
-                    "test options are:\n\n"
-                    "-I, --instance: HAL instance to test\n",
-                    argv[optind ?: 1], argv[0]);
-            return 2;
-        }
-        return 0;
-    }
-
-   private:
-    hidl_string instance;
-};
-
 static ComponentTestEnvironment* gEnv = nullptr;
 
 class MasterHidlTest : public ::testing::VtsHalHidlTargetTestBase {
@@ -226,6 +178,7 @@
     gEnv = new ComponentTestEnvironment();
     ::testing::AddGlobalTestEnvironment(gEnv);
     ::testing::InitGoogleTest(&argc, argv);
+    gEnv->init(&argc, argv);
     int status = gEnv->initFromOptions(argc, argv);
     if (status == 0) {
         status = RUN_ALL_TESTS();
diff --git a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp
index 034992e..40e76c9 100644
--- a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp
+++ b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp
@@ -51,85 +51,6 @@
 #include <media_video_hidl_test_common.h>
 #include <fstream>
 
-// A class for test environment setup
-class ComponentTestEnvironment : public ::testing::Environment {
-   public:
-    virtual void SetUp() {}
-    virtual void TearDown() {}
-
-    ComponentTestEnvironment() : instance("default"), res("/sdcard/media/") {}
-
-    void setInstance(const char* _instance) { instance = _instance; }
-
-    void setComponent(const char* _component) { component = _component; }
-
-    void setRole(const char* _role) { role = _role; }
-
-    void setRes(const char* _res) { res = _res; }
-
-    const hidl_string getInstance() const { return instance; }
-
-    const hidl_string getComponent() const { return component; }
-
-    const hidl_string getRole() const { return role; }
-
-    const hidl_string getRes() const { return res; }
-
-    int initFromOptions(int argc, char** argv) {
-        static struct option options[] = {
-            {"instance", required_argument, 0, 'I'},
-            {"component", required_argument, 0, 'C'},
-            {"role", required_argument, 0, 'R'},
-            {"res", required_argument, 0, 'P'},
-            {0, 0, 0, 0}};
-
-        while (true) {
-            int index = 0;
-            int c = getopt_long(argc, argv, "I:C:R:P:", options, &index);
-            if (c == -1) {
-                break;
-            }
-
-            switch (c) {
-                case 'I':
-                    setInstance(optarg);
-                    break;
-                case 'C':
-                    setComponent(optarg);
-                    break;
-                case 'R':
-                    setRole(optarg);
-                    break;
-                case 'P':
-                    setRes(optarg);
-                    break;
-                case '?':
-                    break;
-            }
-        }
-
-        if (optind < argc) {
-            fprintf(stderr,
-                    "unrecognized option: %s\n\n"
-                    "usage: %s <gtest options> <test options>\n\n"
-                    "test options are:\n\n"
-                    "-I, --instance: HAL instance to test\n"
-                    "-C, --component: OMX component to test\n"
-                    "-R, --role: OMX component Role\n"
-                    "-P, --res: Resource files directory location\n",
-                    argv[optind ?: 1], argv[0]);
-            return 2;
-        }
-        return 0;
-    }
-
-   private:
-    hidl_string instance;
-    hidl_string component;
-    hidl_string role;
-    hidl_string res;
-};
-
 static ComponentTestEnvironment* gEnv = nullptr;
 
 // video decoder test fixture class
@@ -1488,6 +1409,7 @@
     gEnv = new ComponentTestEnvironment();
     ::testing::AddGlobalTestEnvironment(gEnv);
     ::testing::InitGoogleTest(&argc, argv);
+    gEnv->init(&argc, argv);
     int status = gEnv->initFromOptions(argc, argv);
     if (status == 0) {
         status = RUN_ALL_TESTS();
diff --git a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp
index 099658f..2056d9e 100644
--- a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp
+++ b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp
@@ -64,85 +64,6 @@
 #include <system/window.h>
 #include <fstream>
 
-// A class for test environment setup
-class ComponentTestEnvironment : public ::testing::Environment {
-   public:
-    virtual void SetUp() {}
-    virtual void TearDown() {}
-
-    ComponentTestEnvironment() : instance("default"), res("/sdcard/media/") {}
-
-    void setInstance(const char* _instance) { instance = _instance; }
-
-    void setComponent(const char* _component) { component = _component; }
-
-    void setRole(const char* _role) { role = _role; }
-
-    void setRes(const char* _res) { res = _res; }
-
-    const hidl_string getInstance() const { return instance; }
-
-    const hidl_string getComponent() const { return component; }
-
-    const hidl_string getRole() const { return role; }
-
-    const hidl_string getRes() const { return res; }
-
-    int initFromOptions(int argc, char** argv) {
-        static struct option options[] = {
-            {"instance", required_argument, 0, 'I'},
-            {"component", required_argument, 0, 'C'},
-            {"role", required_argument, 0, 'R'},
-            {"res", required_argument, 0, 'P'},
-            {0, 0, 0, 0}};
-
-        while (true) {
-            int index = 0;
-            int c = getopt_long(argc, argv, "I:C:R:P:", options, &index);
-            if (c == -1) {
-                break;
-            }
-
-            switch (c) {
-                case 'I':
-                    setInstance(optarg);
-                    break;
-                case 'C':
-                    setComponent(optarg);
-                    break;
-                case 'R':
-                    setRole(optarg);
-                    break;
-                case 'P':
-                    setRes(optarg);
-                    break;
-                case '?':
-                    break;
-            }
-        }
-
-        if (optind < argc) {
-            fprintf(stderr,
-                    "unrecognized option: %s\n\n"
-                    "usage: %s <gtest options> <test options>\n\n"
-                    "test options are:\n\n"
-                    "-I, --instance: HAL instance to test\n"
-                    "-C, --component: OMX component to test\n"
-                    "-R, --role: OMX component Role\n"
-                    "-P, --res: Resource files directory location\n",
-                    argv[optind ?: 1], argv[0]);
-            return 2;
-        }
-        return 0;
-    }
-
-   private:
-    hidl_string instance;
-    hidl_string component;
-    hidl_string role;
-    hidl_string res;
-};
-
 static ComponentTestEnvironment* gEnv = nullptr;
 
 // video encoder test fixture class
@@ -1580,6 +1501,7 @@
     gEnv = new ComponentTestEnvironment();
     ::testing::AddGlobalTestEnvironment(gEnv);
     ::testing::InitGoogleTest(&argc, argv);
+    gEnv->init(&argc, argv);
     int status = gEnv->initFromOptions(argc, argv);
     if (status == 0) {
         status = RUN_ALL_TESTS();
diff --git a/oemlock/1.0/vts/functional/VtsHalOemLockV1_0TargetTest.cpp b/oemlock/1.0/vts/functional/VtsHalOemLockV1_0TargetTest.cpp
index a924fec..05462a8 100644
--- a/oemlock/1.0/vts/functional/VtsHalOemLockV1_0TargetTest.cpp
+++ b/oemlock/1.0/vts/functional/VtsHalOemLockV1_0TargetTest.cpp
@@ -13,10 +13,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 #include <android/hardware/oemlock/1.0/IOemLock.h>
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 
 using ::android::hardware::oemlock::V1_0::IOemLock;
 using ::android::hardware::oemlock::V1_0::OemLockStatus;
@@ -25,9 +25,22 @@
 using ::android::hardware::hidl_vec;
 using ::android::sp;
 
+// Test environment for OemLock HIDL HAL.
+class OemLockHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static OemLockHidlEnvironment* Instance() {
+        static OemLockHidlEnvironment* instance = new OemLockHidlEnvironment;
+        return instance;
+    }
+
+    virtual void registerTestServices() override { registerTestService<IOemLock>(); }
+};
+
 struct OemLockHidlTest : public ::testing::VtsHalHidlTargetTestBase {
     virtual void SetUp() override {
-        oemlock = ::testing::VtsHalHidlTargetTestBase::getService<IOemLock>();
+        oemlock = ::testing::VtsHalHidlTargetTestBase::getService<IOemLock>(
+            OemLockHidlEnvironment::Instance()->getServiceName<IOemLock>());
         ASSERT_NE(oemlock, nullptr);
     }
 
@@ -187,3 +200,12 @@
     ASSERT_EQ(status, OemLockStatus::OK);
     ASSERT_EQ(allowed, originallyAllowed);
 };
+
+int main(int argc, char** argv) {
+    ::testing::AddGlobalTestEnvironment(OemLockHidlEnvironment::Instance());
+    ::testing::InitGoogleTest(&argc, argv);
+    OemLockHidlEnvironment::Instance()->init(&argc, argv);
+    int status = RUN_ALL_TESTS();
+    ALOGI("Test result = %d", status);
+    return status;
+}
diff --git a/radio/1.0/vts/functional/VtsHalRadioV1_0TargetTest.cpp b/radio/1.0/vts/functional/VtsHalRadioV1_0TargetTest.cpp
index a3eb54c..d53c062 100644
--- a/radio/1.0/vts/functional/VtsHalRadioV1_0TargetTest.cpp
+++ b/radio/1.0/vts/functional/VtsHalRadioV1_0TargetTest.cpp
@@ -17,7 +17,9 @@
 #include <radio_hidl_hal_utils_v1_0.h>
 
 int main(int argc, char** argv) {
+    ::testing::AddGlobalTestEnvironment(RadioHidlEnvironment::Instance());
     ::testing::InitGoogleTest(&argc, argv);
+    RadioHidlEnvironment::Instance()->init(&argc, argv);
 
     // setup seed for rand function
     int seedSrand = time(NULL);
@@ -28,4 +30,4 @@
     LOG(INFO) << "Test result = " << status;
 
     return status;
-}
\ No newline at end of file
+}
diff --git a/radio/1.0/vts/functional/VtsHalSapV1_0TargetTest.cpp b/radio/1.0/vts/functional/VtsHalSapV1_0TargetTest.cpp
index 84b67c9..859e6fb 100644
--- a/radio/1.0/vts/functional/VtsHalSapV1_0TargetTest.cpp
+++ b/radio/1.0/vts/functional/VtsHalSapV1_0TargetTest.cpp
@@ -17,7 +17,9 @@
 #include <sap_hidl_hal_utils.h>
 
 int main(int argc, char** argv) {
+    ::testing::AddGlobalTestEnvironment(SapHidlEnvironment::Instance());
     ::testing::InitGoogleTest(&argc, argv);
+    SapHidlEnvironment::Instance()->init(&argc, argv);
 
     // setup seed for rand function
     int seedSrand = time(NULL);
diff --git a/radio/1.0/vts/functional/radio_hidl_hal_test.cpp b/radio/1.0/vts/functional/radio_hidl_hal_test.cpp
index 1c7653b..d9c00ce 100644
--- a/radio/1.0/vts/functional/radio_hidl_hal_test.cpp
+++ b/radio/1.0/vts/functional/radio_hidl_hal_test.cpp
@@ -17,12 +17,13 @@
 #include <radio_hidl_hal_utils_v1_0.h>
 
 void RadioHidlTest::SetUp() {
-    radio =
-        ::testing::VtsHalHidlTargetTestBase::getService<IRadio>(hidl_string(RADIO_SERVICE_NAME));
+    radio = ::testing::VtsHalHidlTargetTestBase::getService<IRadio>(
+        RadioHidlEnvironment::Instance()->getServiceName<IRadio>(hidl_string(RADIO_SERVICE_NAME)));
     if (radio == NULL) {
         sleep(60);
         radio = ::testing::VtsHalHidlTargetTestBase::getService<IRadio>(
-            hidl_string(RADIO_SERVICE_NAME));
+            RadioHidlEnvironment::Instance()->getServiceName<IRadio>(
+                hidl_string(RADIO_SERVICE_NAME)));
     }
     ASSERT_NE(nullptr, radio.get());
 
@@ -67,4 +68,4 @@
     }
     count--;
     return status;
-}
\ No newline at end of file
+}
diff --git a/radio/1.0/vts/functional/radio_hidl_hal_utils_v1_0.h b/radio/1.0/vts/functional/radio_hidl_hal_utils_v1_0.h
index 6b95ab0..15ac0b8 100644
--- a/radio/1.0/vts/functional/radio_hidl_hal_utils_v1_0.h
+++ b/radio/1.0/vts/functional/radio_hidl_hal_utils_v1_0.h
@@ -17,6 +17,7 @@
 #include <android-base/logging.h>
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <chrono>
 #include <condition_variable>
 #include <mutex>
@@ -511,6 +512,20 @@
                             const ::android::hardware::hidl_string& reason);
 };
 
+// Test environment for Radio HIDL HAL.
+class RadioHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static RadioHidlEnvironment* Instance() {
+        static RadioHidlEnvironment* instance = new RadioHidlEnvironment;
+        return instance;
+    }
+    virtual void registerTestServices() override { registerTestService<IRadio>(); }
+
+   private:
+    RadioHidlEnvironment() {}
+};
+
 // The main test class for Radio HIDL.
 class RadioHidlTest : public ::testing::VtsHalHidlTargetTestBase {
    protected:
diff --git a/radio/1.0/vts/functional/sap_hidl_hal_test.cpp b/radio/1.0/vts/functional/sap_hidl_hal_test.cpp
index fc8cb2a..79668bb 100644
--- a/radio/1.0/vts/functional/sap_hidl_hal_test.cpp
+++ b/radio/1.0/vts/functional/sap_hidl_hal_test.cpp
@@ -17,7 +17,8 @@
 #include <sap_hidl_hal_utils.h>
 
 void SapHidlTest::SetUp() {
-    sap = ::testing::VtsHalHidlTargetTestBase::getService<ISap>(hidl_string(SAP_SERVICE_NAME));
+    sap = ::testing::VtsHalHidlTargetTestBase::getService<ISap>(
+        SapHidlEnvironment::Instance()->getServiceName<ISap>(hidl_string(SAP_SERVICE_NAME)));
     ASSERT_NE(sap, nullptr);
 
     sapCb = new SapCallback(*this);
@@ -49,4 +50,4 @@
     }
     count--;
     return status;
-}
\ No newline at end of file
+}
diff --git a/radio/1.0/vts/functional/sap_hidl_hal_utils.h b/radio/1.0/vts/functional/sap_hidl_hal_utils.h
index fb142b7..ec237dc 100644
--- a/radio/1.0/vts/functional/sap_hidl_hal_utils.h
+++ b/radio/1.0/vts/functional/sap_hidl_hal_utils.h
@@ -17,6 +17,7 @@
 #include <android-base/logging.h>
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <chrono>
 #include <condition_variable>
 #include <mutex>
@@ -79,6 +80,20 @@
     Return<void> transferProtocolResponse(int32_t token, SapResultCode resultCode);
 };
 
+// Test environment for Sap HIDL HAL.
+class SapHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static SapHidlEnvironment* Instance() {
+        static SapHidlEnvironment* instance = new SapHidlEnvironment;
+        return instance;
+    }
+    virtual void registerTestServices() override { registerTestService<ISap>(); }
+
+   private:
+    SapHidlEnvironment() {}
+};
+
 // The main test class for Sap HIDL.
 class SapHidlTest : public ::testing::VtsHalHidlTargetTestBase {
    private:
@@ -102,4 +117,4 @@
 
     /* Sap Callback object */
     sp<SapCallback> sapCb;
-};
\ No newline at end of file
+};
diff --git a/radio/1.1/vts/functional/VtsHalRadioV1_1TargetTest.cpp b/radio/1.1/vts/functional/VtsHalRadioV1_1TargetTest.cpp
index 107a9e0..83564ee 100644
--- a/radio/1.1/vts/functional/VtsHalRadioV1_1TargetTest.cpp
+++ b/radio/1.1/vts/functional/VtsHalRadioV1_1TargetTest.cpp
@@ -17,10 +17,10 @@
 #include <radio_hidl_hal_utils_v1_1.h>
 
 int main(int argc, char** argv) {
+    ::testing::AddGlobalTestEnvironment(RadioHidlEnvironment::Instance());
     ::testing::InitGoogleTest(&argc, argv);
-
+    RadioHidlEnvironment::Instance()->init(&argc, argv);
     int status = RUN_ALL_TESTS();
     LOG(INFO) << "Test result = " << status;
-
     return status;
-}
\ No newline at end of file
+}
diff --git a/radio/1.1/vts/functional/radio_hidl_hal_test.cpp b/radio/1.1/vts/functional/radio_hidl_hal_test.cpp
index 773d165..6d16cd8 100644
--- a/radio/1.1/vts/functional/radio_hidl_hal_test.cpp
+++ b/radio/1.1/vts/functional/radio_hidl_hal_test.cpp
@@ -19,11 +19,16 @@
 void RadioHidlTest_v1_1::SetUp() {
     radio_v1_1 =
         ::testing::VtsHalHidlTargetTestBase::getService<::android::hardware::radio::V1_1::IRadio>(
-            hidl_string(RADIO_SERVICE_NAME));
+            RadioHidlEnvironment::Instance()
+                ->getServiceName<::android::hardware::radio::V1_1::IRadio>(
+                    hidl_string(RADIO_SERVICE_NAME)));
     if (radio_v1_1 == NULL) {
         sleep(60);
         radio_v1_1 = ::testing::VtsHalHidlTargetTestBase::getService<
-            ::android::hardware::radio::V1_1::IRadio>(hidl_string(RADIO_SERVICE_NAME));
+            ::android::hardware::radio::V1_1::IRadio>(
+            RadioHidlEnvironment::Instance()
+                ->getServiceName<::android::hardware::radio::V1_1::IRadio>(
+                    hidl_string(RADIO_SERVICE_NAME)));
     }
     ASSERT_NE(nullptr, radio_v1_1.get());
 
diff --git a/radio/1.1/vts/functional/radio_hidl_hal_utils_v1_1.h b/radio/1.1/vts/functional/radio_hidl_hal_utils_v1_1.h
index a081ab9..36d15c7 100644
--- a/radio/1.1/vts/functional/radio_hidl_hal_utils_v1_1.h
+++ b/radio/1.1/vts/functional/radio_hidl_hal_utils_v1_1.h
@@ -17,6 +17,7 @@
 #include <android-base/logging.h>
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <chrono>
 #include <condition_variable>
 #include <mutex>
@@ -534,6 +535,22 @@
                             const ::android::hardware::hidl_string& reason);
 };
 
+// Test environment for Radio HIDL HAL.
+class RadioHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static RadioHidlEnvironment* Instance() {
+        static RadioHidlEnvironment* instance = new RadioHidlEnvironment;
+        return instance;
+    }
+    virtual void registerTestServices() override {
+        registerTestService<::android::hardware::radio::V1_1::IRadio>();
+    }
+
+   private:
+    RadioHidlEnvironment() {}
+};
+
 // The main test class for Radio HIDL.
 class RadioHidlTest_v1_1 : public ::testing::VtsHalHidlTargetTestBase {
    protected:
diff --git a/radio/1.2/Android.bp b/radio/1.2/Android.bp
index 552e33d..48ac5a1 100644
--- a/radio/1.2/Android.bp
+++ b/radio/1.2/Android.bp
@@ -19,6 +19,7 @@
         "android.hidl.base@1.0",
     ],
     types: [
+        "AccessNetwork",
         "AudioQuality",
         "Call",
         "CardStatus",
@@ -33,6 +34,7 @@
         "CellInfoGsm",
         "CellInfoLte",
         "CellInfoWcdma",
+        "DataRequestReason",
         "IncrementalResultsPeriodicityRange",
         "IndicationFilter",
         "LinkCapacityEstimate",
diff --git a/radio/1.2/vts/functional/Android.bp b/radio/1.2/vts/functional/Android.bp
index 6f8781a..a4e8c02 100644
--- a/radio/1.2/vts/functional/Android.bp
+++ b/radio/1.2/vts/functional/Android.bp
@@ -22,6 +22,7 @@
         "radio_hidl_hal_test.cpp",
         "radio_response.cpp",
         "radio_indication.cpp",
+        "VtsHalRadioV1_2TargetTest.cpp",
     ],
     static_libs: [
         "RadioVtsTestUtilBase",
diff --git a/radio/1.2/vts/functional/VtsHalRadioV1_2TargetTest.cpp b/radio/1.2/vts/functional/VtsHalRadioV1_2TargetTest.cpp
new file mode 100644
index 0000000..c1a2f3d
--- /dev/null
+++ b/radio/1.2/vts/functional/VtsHalRadioV1_2TargetTest.cpp
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#include <radio_hidl_hal_utils_v1_2.h>
+
+int main(int argc, char** argv) {
+    ::testing::AddGlobalTestEnvironment(RadioHidlEnvironment::Instance());
+    ::testing::InitGoogleTest(&argc, argv);
+    RadioHidlEnvironment::Instance()->init(&argc, argv);
+    int status = RUN_ALL_TESTS();
+    LOG(INFO) << "Test result = " << status;
+    return status;
+}
diff --git a/radio/1.2/vts/functional/radio_hidl_hal_test.cpp b/radio/1.2/vts/functional/radio_hidl_hal_test.cpp
index c1ab88b..d74d077 100644
--- a/radio/1.2/vts/functional/radio_hidl_hal_test.cpp
+++ b/radio/1.2/vts/functional/radio_hidl_hal_test.cpp
@@ -18,11 +18,13 @@
 
 void RadioHidlTest_v1_2::SetUp() {
     radio_v1_2 = ::testing::VtsHalHidlTargetTestBase::getService<V1_2::IRadio>(
-        hidl_string(RADIO_SERVICE_NAME));
+        RadioHidlEnvironment::Instance()->getServiceName<V1_2::IRadio>(
+            hidl_string(RADIO_SERVICE_NAME)));
     if (radio_v1_2 == NULL) {
         sleep(60);
         radio_v1_2 = ::testing::VtsHalHidlTargetTestBase::getService<V1_2::IRadio>(
-            hidl_string(RADIO_SERVICE_NAME));
+            RadioHidlEnvironment::Instance()->getServiceName<V1_2::IRadio>(
+                hidl_string(RADIO_SERVICE_NAME)));
     }
     ASSERT_NE(nullptr, radio_v1_2.get());
 
diff --git a/radio/1.2/vts/functional/radio_hidl_hal_utils_v1_2.h b/radio/1.2/vts/functional/radio_hidl_hal_utils_v1_2.h
index b3b53b1..781c12a 100644
--- a/radio/1.2/vts/functional/radio_hidl_hal_utils_v1_2.h
+++ b/radio/1.2/vts/functional/radio_hidl_hal_utils_v1_2.h
@@ -17,6 +17,7 @@
 #include <android-base/logging.h>
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <chrono>
 #include <condition_variable>
 #include <mutex>
@@ -525,6 +526,20 @@
                             const ::android::hardware::hidl_string& reason);
 };
 
+// Test environment for Radio HIDL HAL.
+class RadioHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static RadioHidlEnvironment* Instance() {
+        static RadioHidlEnvironment* instance = new RadioHidlEnvironment;
+        return instance;
+    }
+    virtual void registerTestServices() override { registerTestService<V1_2::IRadio>(); }
+
+   private:
+    RadioHidlEnvironment() {}
+};
+
 // The main test class for Radio HIDL.
 class RadioHidlTest_v1_2 : public ::testing::VtsHalHidlTargetTestBase {
    protected:
diff --git a/radio/config/1.0/vts/functional/Android.bp b/radio/config/1.0/vts/functional/Android.bp
index 66bfd92..aa8266e 100644
--- a/radio/config/1.0/vts/functional/Android.bp
+++ b/radio/config/1.0/vts/functional/Android.bp
@@ -22,6 +22,7 @@
         "radio_config_hidl_hal_test.cpp",
         "radio_config_response.cpp",
         "radio_config_indication.cpp",
+        "VtsHalRadioConfigV1_0TargetTest.cpp",
     ],
     static_libs: [
         "RadioVtsTestUtilBase",
diff --git a/radio/config/1.0/vts/functional/VtsHalRadioConfigV1_0TargetTest.cpp b/radio/config/1.0/vts/functional/VtsHalRadioConfigV1_0TargetTest.cpp
new file mode 100644
index 0000000..2fc6b62
--- /dev/null
+++ b/radio/config/1.0/vts/functional/VtsHalRadioConfigV1_0TargetTest.cpp
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#include <radio_config_hidl_hal_utils.h>
+
+int main(int argc, char** argv) {
+    ::testing::AddGlobalTestEnvironment(RadioConfigHidlEnvironment::Instance());
+    ::testing::InitGoogleTest(&argc, argv);
+    RadioConfigHidlEnvironment::Instance()->init(&argc, argv);
+    int status = RUN_ALL_TESTS();
+    LOG(INFO) << "Test result = " << status;
+    return status;
+}
diff --git a/radio/config/1.0/vts/functional/radio_config_hidl_hal_test.cpp b/radio/config/1.0/vts/functional/radio_config_hidl_hal_test.cpp
index 8df6842..c01dc4c 100644
--- a/radio/config/1.0/vts/functional/radio_config_hidl_hal_test.cpp
+++ b/radio/config/1.0/vts/functional/radio_config_hidl_hal_test.cpp
@@ -18,11 +18,13 @@
 
 void RadioConfigHidlTest::SetUp() {
     radioConfig = ::testing::VtsHalHidlTargetTestBase::getService<IRadioConfig>(
-        hidl_string(RADIO_SERVICE_NAME));
+        RadioConfigHidlEnvironment::Instance()->getServiceName<IRadioConfig>(
+            hidl_string(RADIO_SERVICE_NAME)));
     if (radioConfig == NULL) {
         sleep(60);
         radioConfig = ::testing::VtsHalHidlTargetTestBase::getService<IRadioConfig>(
-            hidl_string(RADIO_SERVICE_NAME));
+            RadioConfigHidlEnvironment::Instance()->getServiceName<IRadioConfig>(
+                hidl_string(RADIO_SERVICE_NAME)));
     }
     ASSERT_NE(nullptr, radioConfig.get());
 
diff --git a/radio/config/1.0/vts/functional/radio_config_hidl_hal_utils.h b/radio/config/1.0/vts/functional/radio_config_hidl_hal_utils.h
index 762cc98..e7d697a 100644
--- a/radio/config/1.0/vts/functional/radio_config_hidl_hal_utils.h
+++ b/radio/config/1.0/vts/functional/radio_config_hidl_hal_utils.h
@@ -17,6 +17,7 @@
 #include <android-base/logging.h>
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <chrono>
 #include <condition_variable>
 #include <mutex>
@@ -75,6 +76,20 @@
         RadioIndicationType type, const ::android::hardware::hidl_vec<SimSlotStatus>& slotStatus);
 };
 
+// Test environment for Radio HIDL HAL.
+class RadioConfigHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static RadioConfigHidlEnvironment* Instance() {
+        static RadioConfigHidlEnvironment* instance = new RadioConfigHidlEnvironment;
+        return instance;
+    }
+    virtual void registerTestServices() override { registerTestService<IRadioConfig>(); }
+
+   private:
+    RadioConfigHidlEnvironment() {}
+};
+
 // The main test class for Radio config HIDL.
 class RadioConfigHidlTest : public ::testing::VtsHalHidlTargetTestBase {
    protected:
diff --git a/tetheroffload/config/1.0/vts/functional/VtsHalTetheroffloadConfigV1_0TargetTest.cpp b/tetheroffload/config/1.0/vts/functional/VtsHalTetheroffloadConfigV1_0TargetTest.cpp
index bf211f0..34a95f2 100644
--- a/tetheroffload/config/1.0/vts/functional/VtsHalTetheroffloadConfigV1_0TargetTest.cpp
+++ b/tetheroffload/config/1.0/vts/functional/VtsHalTetheroffloadConfigV1_0TargetTest.cpp
@@ -17,6 +17,7 @@
 #define LOG_TAG "VtsOffloadConfigV1_0TargetTest"
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <android-base/stringprintf.h>
 #include <android-base/unique_fd.h>
 #include <android/hardware/tetheroffload/config/1.0/IOffloadConfig.h>
@@ -77,10 +78,25 @@
     return netlinkSocket(NETLINK_NETFILTER, groups);
 }
 
+// Test environment for OffloadConfig HIDL HAL.
+class OffloadConfigHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static OffloadConfigHidlEnvironment* Instance() {
+        static OffloadConfigHidlEnvironment* instance = new OffloadConfigHidlEnvironment;
+        return instance;
+    }
+
+    virtual void registerTestServices() override { registerTestService<IOffloadConfig>(); }
+   private:
+    OffloadConfigHidlEnvironment() {}
+};
+
 class OffloadConfigHidlTest : public testing::VtsHalHidlTargetTestBase {
    public:
     virtual void SetUp() override {
-        config = testing::VtsHalHidlTargetTestBase::getService<IOffloadConfig>();
+        config = testing::VtsHalHidlTargetTestBase::getService<IOffloadConfig>(
+            OffloadConfigHidlEnvironment::Instance()->getServiceName<IOffloadConfig>());
         ASSERT_NE(nullptr, config.get()) << "Could not get HIDL instance";
     }
 
@@ -175,7 +191,9 @@
 }
 
 int main(int argc, char** argv) {
-    testing::InitGoogleTest(&argc, argv);
+    ::testing::AddGlobalTestEnvironment(OffloadConfigHidlEnvironment::Instance());
+    ::testing::InitGoogleTest(&argc, argv);
+    OffloadConfigHidlEnvironment::Instance()->init(&argc, argv);
     int status = RUN_ALL_TESTS();
     ALOGE("Test result with status=%d", status);
     return status;
diff --git a/tetheroffload/control/1.0/vts/functional/VtsHalTetheroffloadControlV1_0TargetTest.cpp b/tetheroffload/control/1.0/vts/functional/VtsHalTetheroffloadControlV1_0TargetTest.cpp
index d2fa92d..4eef4ec 100644
--- a/tetheroffload/control/1.0/vts/functional/VtsHalTetheroffloadControlV1_0TargetTest.cpp
+++ b/tetheroffload/control/1.0/vts/functional/VtsHalTetheroffloadControlV1_0TargetTest.cpp
@@ -18,6 +18,7 @@
 
 #include <VtsHalHidlTargetCallbackBase.h>
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <android-base/stringprintf.h>
 #include <android-base/unique_fd.h>
 #include <android/hardware/tetheroffload/config/1.0/IOffloadConfig.h>
@@ -114,6 +115,23 @@
     NatTimeoutUpdate last_params;
 };
 
+// Test environment for OffloadControl HIDL HAL.
+class OffloadControlHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static OffloadControlHidlEnvironment* Instance() {
+        static OffloadControlHidlEnvironment* instance = new OffloadControlHidlEnvironment;
+        return instance;
+    }
+
+    virtual void registerTestServices() override {
+        registerTestService<IOffloadConfig>();
+        registerTestService<IOffloadControl>();
+    }
+   private:
+    OffloadControlHidlEnvironment() {}
+};
+
 class OffloadControlHidlTestBase : public testing::VtsHalHidlTargetTestBase {
    public:
     virtual void SetUp() override {
@@ -131,7 +149,8 @@
     // The IOffloadConfig HAL is tested more thoroughly elsewhere. He we just
     // setup everything correctly and verify basic readiness.
     void setupConfigHal() {
-        config = testing::VtsHalHidlTargetTestBase::getService<IOffloadConfig>();
+        config = testing::VtsHalHidlTargetTestBase::getService<IOffloadConfig>(
+            OffloadControlHidlEnvironment::Instance()->getServiceName<IOffloadConfig>());
         ASSERT_NE(nullptr, config.get()) << "Could not get HIDL instance";
 
         unique_fd fd1(conntrackSocket(NF_NETLINK_CONNTRACK_NEW | NF_NETLINK_CONNTRACK_DESTROY));
@@ -159,7 +178,8 @@
     }
 
     void prepareControlHal() {
-        control = testing::VtsHalHidlTargetTestBase::getService<IOffloadControl>();
+        control = testing::VtsHalHidlTargetTestBase::getService<IOffloadControl>(
+            OffloadControlHidlEnvironment::Instance()->getServiceName<IOffloadControl>());
         ASSERT_NE(nullptr, control.get()) << "Could not get HIDL instance";
 
         control_cb = new TetheringOffloadCallback();
@@ -678,7 +698,9 @@
 }
 
 int main(int argc, char** argv) {
-    testing::InitGoogleTest(&argc, argv);
+    ::testing::AddGlobalTestEnvironment(OffloadControlHidlEnvironment::Instance());
+    ::testing::InitGoogleTest(&argc, argv);
+    OffloadControlHidlEnvironment::Instance()->init(&argc, argv);
     int status = RUN_ALL_TESTS();
     ALOGE("Test result with status=%d", status);
     return status;
diff --git a/usb/1.0/vts/functional/VtsHalUsbV1_0TargetTest.cpp b/usb/1.0/vts/functional/VtsHalUsbV1_0TargetTest.cpp
index e01b974..ee7ef1b 100644
--- a/usb/1.0/vts/functional/VtsHalUsbV1_0TargetTest.cpp
+++ b/usb/1.0/vts/functional/VtsHalUsbV1_0TargetTest.cpp
@@ -22,6 +22,7 @@
 #include <android/hardware/usb/1.0/types.h>
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <log/log.h>
 #include <stdlib.h>
 #include <chrono>
@@ -48,6 +49,18 @@
 using ::android::hardware::Void;
 using ::android::sp;
 
+// Test environment for Usb HIDL HAL.
+class UsbHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+ public:
+  // get the test environment singleton
+  static UsbHidlEnvironment* Instance() {
+    static UsbHidlEnvironment* instance = new UsbHidlEnvironment;
+    return instance;
+  }
+
+  virtual void registerTestServices() override { registerTestService<IUsb>(); }
+};
+
 // The main test class for the USB hidl HAL
 class UsbHidlTest : public ::testing::VtsHalHidlTargetTestBase {
  public:
@@ -96,7 +109,8 @@
 
   virtual void SetUp() override {
     ALOGI("Setup");
-    usb = ::testing::VtsHalHidlTargetTestBase::getService<IUsb>();
+    usb = ::testing::VtsHalHidlTargetTestBase::getService<IUsb>(
+        UsbHidlEnvironment::Instance()->getServiceName<IUsb>());
     ASSERT_NE(usb, nullptr);
 
     usb_cb_2 = new UsbCallback(*this, 2);
@@ -343,7 +357,9 @@
 }
 
 int main(int argc, char** argv) {
+  ::testing::AddGlobalTestEnvironment(UsbHidlEnvironment::Instance());
   ::testing::InitGoogleTest(&argc, argv);
+  UsbHidlEnvironment::Instance()->init(&argc, argv);
   int status = RUN_ALL_TESTS();
   ALOGI("Test result = %d", status);
   return status;
diff --git a/usb/1.1/vts/functional/VtsHalUsbV1_1TargetTest.cpp b/usb/1.1/vts/functional/VtsHalUsbV1_1TargetTest.cpp
index 8a30993..c990b23 100644
--- a/usb/1.1/vts/functional/VtsHalUsbV1_1TargetTest.cpp
+++ b/usb/1.1/vts/functional/VtsHalUsbV1_1TargetTest.cpp
@@ -24,6 +24,7 @@
 
 #include <VtsHalHidlTargetCallbackBase.h>
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <log/log.h>
 #include <stdlib.h>
 #include <chrono>
@@ -113,12 +114,25 @@
     };
 };
 
+// Test environment for Usb HIDL HAL.
+class UsbHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static UsbHidlEnvironment* Instance() {
+        static UsbHidlEnvironment* instance = new UsbHidlEnvironment;
+        return instance;
+    }
+
+    virtual void registerTestServices() override { registerTestService<IUsb>(); }
+};
+
 // The main test class for the USB hidl HAL
 class UsbHidlTest : public ::testing::VtsHalHidlTargetTestBase {
    public:
     virtual void SetUp() override {
         ALOGI(__FUNCTION__);
-        usb = ::testing::VtsHalHidlTargetTestBase::getService<IUsb>();
+        usb = ::testing::VtsHalHidlTargetTestBase::getService<IUsb>(
+            UsbHidlEnvironment::Instance()->getServiceName<IUsb>());
         ASSERT_NE(usb, nullptr);
 
         usb_cb_2 = new UsbCallback(2);
@@ -169,7 +183,9 @@
 }
 
 int main(int argc, char** argv) {
+    ::testing::AddGlobalTestEnvironment(UsbHidlEnvironment::Instance());
     ::testing::InitGoogleTest(&argc, argv);
+    UsbHidlEnvironment::Instance()->init(&argc, argv);
     int status = RUN_ALL_TESTS();
     ALOGI("Test result = %d", status);
     return status;
diff --git a/vibrator/1.0/vts/functional/VtsHalVibratorV1_0TargetTest.cpp b/vibrator/1.0/vts/functional/VtsHalVibratorV1_0TargetTest.cpp
index f415ad5..a0e927b 100644
--- a/vibrator/1.0/vts/functional/VtsHalVibratorV1_0TargetTest.cpp
+++ b/vibrator/1.0/vts/functional/VtsHalVibratorV1_0TargetTest.cpp
@@ -19,9 +19,11 @@
 #include <android-base/logging.h>
 #include <android/hardware/vibrator/1.0/IVibrator.h>
 #include <android/hardware/vibrator/1.0/types.h>
-#include <VtsHalHidlTargetTestBase.h>
 #include <unistd.h>
 
+#include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
+
 using ::android::hardware::vibrator::V1_0::Effect;
 using ::android::hardware::vibrator::V1_0::EffectStrength;
 using ::android::hardware::vibrator::V1_0::IVibrator;
@@ -30,11 +32,27 @@
 using ::android::hardware::Void;
 using ::android::sp;
 
+// Test environment for Vibrator HIDL HAL.
+class VibratorHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+ public:
+  // get the test environment singleton
+  static VibratorHidlEnvironment* Instance() {
+      static VibratorHidlEnvironment* instance = new VibratorHidlEnvironment;
+      return instance;
+  }
+
+  virtual void registerTestServices() override { registerTestService<IVibrator>(); }
+
+ private:
+  VibratorHidlEnvironment() {}
+};
+
 // The main test class for VIBRATOR HIDL HAL.
 class VibratorHidlTest : public ::testing::VtsHalHidlTargetTestBase {
  public:
   virtual void SetUp() override {
-    vibrator = ::testing::VtsHalHidlTargetTestBase::getService<IVibrator>();
+    vibrator = ::testing::VtsHalHidlTargetTestBase::getService<IVibrator>(
+        VibratorHidlEnvironment::Instance()->getServiceName<IVibrator>());
     ASSERT_NE(vibrator, nullptr);
   }
 
@@ -43,15 +61,6 @@
   sp<IVibrator> vibrator;
 };
 
-// A class for test environment setup (kept since this file is a template).
-class VibratorHidlEnvironment : public ::testing::Environment {
- public:
-  virtual void SetUp() {}
-  virtual void TearDown() {}
-
- private:
-};
-
 static void validatePerformEffect(Status status, uint32_t lengthMs) {
   ASSERT_TRUE(status == Status::OK || status == Status::UNSUPPORTED_OPERATION);
   if (status == Status::OK) {
@@ -96,8 +105,9 @@
 }
 
 int main(int argc, char **argv) {
-  ::testing::AddGlobalTestEnvironment(new VibratorHidlEnvironment);
+  ::testing::AddGlobalTestEnvironment(VibratorHidlEnvironment::Instance());
   ::testing::InitGoogleTest(&argc, argv);
+  VibratorHidlEnvironment::Instance()->init(&argc, argv);
   int status = RUN_ALL_TESTS();
   LOG(INFO) << "Test result = " << status;
   return status;
diff --git a/vibrator/1.1/vts/functional/VtsHalVibratorV1_1TargetTest.cpp b/vibrator/1.1/vts/functional/VtsHalVibratorV1_1TargetTest.cpp
index 35000f8..1a47fe9 100644
--- a/vibrator/1.1/vts/functional/VtsHalVibratorV1_1TargetTest.cpp
+++ b/vibrator/1.1/vts/functional/VtsHalVibratorV1_1TargetTest.cpp
@@ -17,6 +17,7 @@
 #define LOG_TAG "vibrator_hidl_hal_test"
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <android-base/logging.h>
 #include <android/hardware/vibrator/1.1/IVibrator.h>
 #include <android/hardware/vibrator/1.1/types.h>
@@ -31,11 +32,27 @@
 using ::android::hardware::Void;
 using ::android::sp;
 
+// Test environment for Vibrator HIDL HAL.
+class VibratorHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static VibratorHidlEnvironment* Instance() {
+        static VibratorHidlEnvironment* instance = new VibratorHidlEnvironment;
+        return instance;
+    }
+
+    virtual void registerTestServices() override { registerTestService<IVibrator>(); }
+
+   private:
+    VibratorHidlEnvironment() {}
+};
+
 // The main test class for VIBRATOR HIDL HAL 1.1.
 class VibratorHidlTest_1_1 : public ::testing::VtsHalHidlTargetTestBase {
    public:
     virtual void SetUp() override {
-        vibrator = ::testing::VtsHalHidlTargetTestBase::getService<IVibrator>();
+        vibrator = ::testing::VtsHalHidlTargetTestBase::getService<IVibrator>(
+            VibratorHidlEnvironment::Instance()->getServiceName<IVibrator>());
         ASSERT_NE(vibrator, nullptr);
     }
 
@@ -61,7 +78,9 @@
 }
 
 int main(int argc, char** argv) {
+    ::testing::AddGlobalTestEnvironment(VibratorHidlEnvironment::Instance());
     ::testing::InitGoogleTest(&argc, argv);
+    VibratorHidlEnvironment::Instance()->init(&argc, argv);
     int status = RUN_ALL_TESTS();
     LOG(INFO) << "Test result = " << status;
     return status;
diff --git a/vibrator/1.2/vts/functional/VtsHalVibratorV1_2TargetTest.cpp b/vibrator/1.2/vts/functional/VtsHalVibratorV1_2TargetTest.cpp
index d07d1b7..d8df18b 100644
--- a/vibrator/1.2/vts/functional/VtsHalVibratorV1_2TargetTest.cpp
+++ b/vibrator/1.2/vts/functional/VtsHalVibratorV1_2TargetTest.cpp
@@ -17,6 +17,7 @@
 #define LOG_TAG "vibrator_hidl_hal_test"
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <android-base/logging.h>
 #include <android/hardware/vibrator/1.0/types.h>
 #include <android/hardware/vibrator/1.2/IVibrator.h>
@@ -32,11 +33,27 @@
 using ::android::hardware::Void;
 using ::android::sp;
 
+// Test environment for Vibrator HIDL HAL.
+class VibratorHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static VibratorHidlEnvironment* Instance() {
+        static VibratorHidlEnvironment* instance = new VibratorHidlEnvironment;
+        return instance;
+    }
+
+    virtual void registerTestServices() override { registerTestService<IVibrator>(); }
+
+   private:
+    VibratorHidlEnvironment() {}
+};
+
 // The main test class for VIBRATOR HIDL HAL 1.2.
 class VibratorHidlTest_1_2 : public ::testing::VtsHalHidlTargetTestBase {
    public:
     virtual void SetUp() override {
-        vibrator = ::testing::VtsHalHidlTargetTestBase::getService<IVibrator>();
+        vibrator = ::testing::VtsHalHidlTargetTestBase::getService<IVibrator>(
+            VibratorHidlEnvironment::Instance()->getServiceName<IVibrator>());
         ASSERT_NE(vibrator, nullptr);
     }
 
@@ -65,7 +82,9 @@
 }
 
 int main(int argc, char** argv) {
+    ::testing::AddGlobalTestEnvironment(VibratorHidlEnvironment::Instance());
     ::testing::InitGoogleTest(&argc, argv);
+    VibratorHidlEnvironment::Instance()->init(&argc, argv);
     int status = RUN_ALL_TESTS();
     LOG(INFO) << "Test result = " << status;
     return status;
diff --git a/vr/1.0/vts/functional/VtsHalVrV1_0TargetTest.cpp b/vr/1.0/vts/functional/VtsHalVrV1_0TargetTest.cpp
index 23f4c71..b165613 100644
--- a/vr/1.0/vts/functional/VtsHalVrV1_0TargetTest.cpp
+++ b/vr/1.0/vts/functional/VtsHalVrV1_0TargetTest.cpp
@@ -16,6 +16,7 @@
 
 #define LOG_TAG "vr_hidl_hal_test"
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <android-base/logging.h>
 #include <android/hardware/vr/1.0/IVr.h>
 #include <hardware/vr.h>
@@ -26,11 +27,24 @@
 using ::android::hardware::Void;
 using ::android::sp;
 
+// Test environment for Vr HIDL HAL.
+class VrHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+ public:
+  // get the test environment singleton
+  static VrHidlEnvironment* Instance() {
+    static VrHidlEnvironment* instance = new VrHidlEnvironment;
+    return instance;
+  }
+
+  virtual void registerTestServices() override { registerTestService<IVr>(); }
+};
+
 // The main test class for VR HIDL HAL.
 class VrHidlTest : public ::testing::VtsHalHidlTargetTestBase {
  public:
   void SetUp() override {
-    vr = ::testing::VtsHalHidlTargetTestBase::getService<IVr>();
+    vr = ::testing::VtsHalHidlTargetTestBase::getService<IVr>(
+        VrHidlEnvironment::Instance()->getServiceName<IVr>());
     ASSERT_NE(vr, nullptr);
   }
 
@@ -39,16 +53,6 @@
   sp<IVr> vr;
 };
 
-
-// A class for test environment setup (kept since this file is a template).
-class VrHidlEnvironment : public ::testing::Environment {
- public:
-  void SetUp() {}
-  void TearDown() {}
-
- private:
-};
-
 // Sanity check that Vr::init does not crash.
 TEST_F(VrHidlTest, Init) {
   EXPECT_TRUE(vr->init().isOk());
@@ -72,8 +76,9 @@
 }
 
 int main(int argc, char **argv) {
-  ::testing::AddGlobalTestEnvironment(new VrHidlEnvironment);
+  ::testing::AddGlobalTestEnvironment(VrHidlEnvironment::Instance());
   ::testing::InitGoogleTest(&argc, argv);
+  VrHidlEnvironment::Instance()->init(&argc, argv);
   int status = RUN_ALL_TESTS();
   ALOGI("Test result = %d", status);
   return status;
diff --git a/weaver/1.0/vts/functional/VtsHalWeaverV1_0TargetTest.cpp b/weaver/1.0/vts/functional/VtsHalWeaverV1_0TargetTest.cpp
index 372d787..de2a1de 100644
--- a/weaver/1.0/vts/functional/VtsHalWeaverV1_0TargetTest.cpp
+++ b/weaver/1.0/vts/functional/VtsHalWeaverV1_0TargetTest.cpp
@@ -19,6 +19,7 @@
 #include <limits>
 
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 
 using ::android::hardware::weaver::V1_0::IWeaver;
 using ::android::hardware::weaver::V1_0::WeaverConfig;
@@ -33,9 +34,22 @@
 const std::vector<uint8_t> VALUE{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
 const std::vector<uint8_t> OTHER_VALUE{0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 255, 255};
 
+// Test environment for Weaver HIDL HAL.
+class WeaverHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static WeaverHidlEnvironment* Instance() {
+        static WeaverHidlEnvironment* instance = new WeaverHidlEnvironment;
+        return instance;
+    }
+
+    virtual void registerTestServices() override { registerTestService<IWeaver>(); }
+};
+
 struct WeaverHidlTest : public ::testing::VtsHalHidlTargetTestBase {
     virtual void SetUp() override {
-        weaver = ::testing::VtsHalHidlTargetTestBase::getService<IWeaver>();
+        weaver = ::testing::VtsHalHidlTargetTestBase::getService<IWeaver>(
+            WeaverHidlEnvironment::Instance()->getServiceName<IWeaver>());
         ASSERT_NE(weaver, nullptr);
     }
 
@@ -334,3 +348,12 @@
     EXPECT_TRUE(readValue.empty());
     EXPECT_EQ(timeout, 0u);
 }
+
+int main(int argc, char** argv) {
+    ::testing::AddGlobalTestEnvironment(WeaverHidlEnvironment::Instance());
+    ::testing::InitGoogleTest(&argc, argv);
+    WeaverHidlEnvironment::Instance()->init(&argc, argv);
+    int status = RUN_ALL_TESTS();
+    ALOGI("Test result = %d", status);
+    return status;
+}
diff --git a/wifi/1.2/default/hidl_struct_util.cpp b/wifi/1.2/default/hidl_struct_util.cpp
index 2e3e0ab..33450ab 100644
--- a/wifi/1.2/default/hidl_struct_util.cpp
+++ b/wifi/1.2/default/hidl_struct_util.cpp
@@ -26,6 +26,9 @@
 namespace implementation {
 namespace hidl_struct_util {
 
+WifiChannelWidthInMhz convertLegacyWifiChannelWidthToHidl(
+    legacy_hal::wifi_channel_width type);
+
 hidl_string safeConvertChar(const char* str, size_t max_len) {
     const char* c = str;
     size_t size = 0;
@@ -2044,7 +2047,8 @@
     *hidl_struct = {};
 
     hidl_struct->channelFreq = legacy_struct.channel;
-    hidl_struct->channelBandwidth = legacy_struct.bandwidth;
+    hidl_struct->channelBandwidth = convertLegacyWifiChannelWidthToHidl(
+        (legacy_hal::wifi_channel_width)legacy_struct.bandwidth);
     hidl_struct->numSpatialStreams = legacy_struct.nss;
 
     return true;
diff --git a/wifi/1.2/types.hal b/wifi/1.2/types.hal
index 1636ae8..b962963 100644
--- a/wifi/1.2/types.hal
+++ b/wifi/1.2/types.hal
@@ -19,6 +19,7 @@
 import @1.0::MacAddress;
 import @1.0::NanDataPathConfirmInd;
 import @1.0::WifiChannelInMhz;
+import @1.0::WifiChannelWidthInMhz;
 
 /**
  * NAN configuration request parameters added in the 1.2 HAL. These are supplemental to previous
@@ -67,7 +68,7 @@
     /**
      * Channel bandwidth in MHz.
      */
-    uint32_t channelBandwidth;
+    WifiChannelWidthInMhz channelBandwidth;
     /**
      * Number of spatial streams used in the channel.
      */