Check unused HALs on device with target FCM version 5.

On devices with target FCM version >= 5 (released in Android 11 /
Android R), enforce no unused HALs.

Note that the number 5 is hardcoded in check_vintf, not VintfObject;
this ensures the policy (5) is not mixed with mechanism (on-device libvintf).

Test: m check-vintf-all
Bug: 131717099
Bug: 139946509
Change-Id: I44a5240e82b702108196291b9d2458e1f38cf812
Merged-In: I44a5240e82b702108196291b9d2458e1f38cf812
diff --git a/check_vintf.cpp b/check_vintf.cpp
index 17e32df..f2a239a 100644
--- a/check_vintf.cpp
+++ b/check_vintf.cpp
@@ -374,7 +374,12 @@
     if (!hasFcmExt.has_value()) {
         return hasFcmExt.error();
     }
-    if (*hasFcmExt) {
+    auto deviceManifest = vintfObject->getDeviceHalManifest();
+    if (deviceManifest == nullptr) {
+        return android::base::Error(-NAME_NOT_FOUND) << "No device HAL manifest";
+    }
+    auto targetFcm = deviceManifest->level();
+    if (*hasFcmExt || (targetFcm != Level::UNSPECIFIED && targetFcm >= Level::R)) {
         return vintfObject->checkUnusedHals();
     }
     LOG(INFO) << "Skip checking unused HALs.";