Before this change java codegen filter flags for exported mode in the template. This change move the filter process to commands as other codegen. Thus the codegen code will only generate code based on the passed in flags. Bug: 311152507 Test: atest aconfig.test aconfig.test.java AconfigJavaHostTest Change-Id: I74045709cde19e6c687c3eb0d94050ea40cf5042
51 lines
1.4 KiB
Plaintext
51 lines
1.4 KiB
Plaintext
package {package_name};
|
|
// TODO(b/303773055): Remove the annotation after access issue is resolved.
|
|
import android.compat.annotation.UnsupportedAppUsage;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
/** @hide */
|
|
public class FakeFeatureFlagsImpl implements FeatureFlags \{
|
|
public FakeFeatureFlagsImpl() \{
|
|
resetAll();
|
|
}
|
|
|
|
{{ for item in flag_elements}}
|
|
@Override
|
|
@UnsupportedAppUsage
|
|
public boolean {item.method_name}() \{
|
|
return getValue(Flags.FLAG_{item.flag_name_constant_suffix});
|
|
}
|
|
{{ endfor}}
|
|
public void setFlag(String flagName, boolean value) \{
|
|
if (!this.mFlagMap.containsKey(flagName)) \{
|
|
throw new IllegalArgumentException("no such flag " + flagName);
|
|
}
|
|
this.mFlagMap.put(flagName, value);
|
|
}
|
|
|
|
public void resetAll() \{
|
|
for (Map.Entry entry : mFlagMap.entrySet()) \{
|
|
entry.setValue(null);
|
|
}
|
|
}
|
|
|
|
private boolean getValue(String flagName) \{
|
|
Boolean value = this.mFlagMap.get(flagName);
|
|
if (value == null) \{
|
|
throw new IllegalArgumentException(flagName + " is not set");
|
|
}
|
|
return value;
|
|
}
|
|
|
|
private Map<String, Boolean> mFlagMap = new HashMap<>(
|
|
Map.ofEntries(
|
|
{{-for item in flag_elements}}
|
|
Map.entry(Flags.FLAG_{item.flag_name_constant_suffix}, false)
|
|
{{ -if not @last }},{{ endif }}
|
|
{{ -endfor }}
|
|
)
|
|
);
|
|
}
|