Merge "Restrict devices shipped post-Q with Thermal HAL 2.0"
diff --git a/treble/vintf/DeviceManifestTest.cpp b/treble/vintf/DeviceManifestTest.cpp
index 737f5f6..7f12bd8 100644
--- a/treble/vintf/DeviceManifestTest.cpp
+++ b/treble/vintf/DeviceManifestTest.cpp
@@ -96,6 +96,28 @@
       << " and gnss@1.1 versions if gnss HAL package is present.";
 }
 
+// Tests that devices launching with R support thermal@2.0 or none.
+// Since thermal@2.0 extends 1.0, this test is needed to workaround
+// VINTF_ENFORCE_NO_UNUSED_HALS.
+// TODO(b/121287858): Remove this test in R when this requirement is properly
+// supported. Otherwise, it needs to be updated to reflect R version changes.
+TEST_F(DeviceManifestTest, ThermalHalVersionCompatibility) {
+  const Level q_fcm_version = kFcm2ApiLevelMap.at(29 /* Q API level */);
+  Level shipping_fcm_version = vendor_manifest_->level();
+  if (shipping_fcm_version == Level::UNSPECIFIED ||
+      shipping_fcm_version <= q_fcm_version) {
+    GTEST_SKIP();
+  }
+
+  bool has_default_thermal_1_0 = vendor_manifest_->hasInstance(
+      "android.hardware.thermal", {1, 0}, "IThermal", "default");
+  bool has_default_thermal_2_0 = vendor_manifest_->hasInstance(
+      "android.hardware.thermal", {2, 0}, "IThermal", "default");
+  ASSERT_EQ(has_default_thermal_1_0, has_default_thermal_2_0)
+      << "Devices launched with Android R must support both thermal@2.0"
+      << " and thermal@1.0 versions if thermal HAL package is present.";
+}
+
 static std::vector<HalManifestPtr> GetTestManifests() {
   return {
       VintfObject::GetDeviceHalManifest(),