1 // Copyright 2024, The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 //! Provide functionality for handling AVF build-time feature flags.
16 
17 use android_system_virtualizationservice::aidl::android::system::virtualizationservice::{
18     IVirtualizationService::FEATURE_DICE_CHANGES, IVirtualizationService::FEATURE_LLPVM_CHANGES,
19     IVirtualizationService::FEATURE_MULTI_TENANT, IVirtualizationService::FEATURE_NETWORK,
20     IVirtualizationService::FEATURE_REMOTE_ATTESTATION,
21     IVirtualizationService::FEATURE_VENDOR_MODULES,
22 };
23 use log::warn;
24 
25 /// Check if an AVF feature is enabled.
is_feature_enabled(feature: &str) -> bool26 pub fn is_feature_enabled(feature: &str) -> bool {
27     match feature {
28         FEATURE_DICE_CHANGES => cfg!(dice_changes),
29         FEATURE_LLPVM_CHANGES => cfg!(llpvm_changes),
30         FEATURE_MULTI_TENANT => cfg!(multi_tenant),
31         FEATURE_NETWORK => cfg!(network),
32         FEATURE_REMOTE_ATTESTATION => cfg!(remote_attestation),
33         FEATURE_VENDOR_MODULES => cfg!(vendor_modules),
34         _ => {
35             warn!("unknown feature {feature}");
36             false
37         }
38     }
39 }
40