Files
build/tools/aconfig/templates/FeatureFlagsImpl.java.template
Zhi Dou 06a448fac7 aconfig: generate full fakefeatureflagsimpl in prod mode
This change will generate full fakefeatureflagsimpl in prod mode.
FakeFeatureFlagsImp will be the same in test mode and the prod mode.
FeatureFlagsImpl will be all unimplemented in test mode. setFlag,
resetAll are added into the interface FeatureFlags.

The reason to make this change is for project using injection pattern,
the project doesn't have to use test mode to test the flag guarded code.
The project can directly use the FakeFeatureFlagsImpl for testing.

Bug: 294838180
Test: atest AconfigJavaHostTest --host AND atest aconfig.test.java
Change-Id: Ib6d40fd3a9ef872e01594fd4f8d6c4cb10bb173a
2023-08-28 16:54:15 +00:00

34 lines
900 B
Plaintext

package {package_name};
{{ if not is_test_mode }}
{{ if is_read_write- }}
import android.provider.DeviceConfig;
{{ endif }}
public final class FeatureFlagsImpl implements FeatureFlags \{
{{ for item in class_elements}}
@Override
public boolean {item.method_name}() \{
{{ -if item.is_read_write }}
return DeviceConfig.getBoolean(
"{item.device_config_namespace}",
"{item.device_config_flag}",
{item.default_value}
);
{{ else }}
return {item.default_value};
{{ endif- }}
}
{{ endfor }}
}
{{ else }}
{#- Generate only stub if in test mode #}
public final class FeatureFlagsImpl implements FeatureFlags \{
{{ for item in class_elements}}
@Override
public boolean {item.method_name}() \{
throw new UnsupportedOperationException(
"Method is not implemented.");
}
{{ endfor }}
}
{{ endif }}