This reverts commit 257f64347d
.
Reason for revert: fix in Roboletric will subimt together with this change
Change-Id: I03c9ed627e6a4153db9c9074daf821ea6d19bc33
76 lines
2.2 KiB
Plaintext
76 lines
2.2 KiB
Plaintext
package {package_name};
|
|
// TODO(b/303773055): Remove the annotation after access issue is resolved.
|
|
import android.compat.annotation.UnsupportedAppUsage;
|
|
{{ if not is_test_mode }}
|
|
{{ if is_read_write- }}
|
|
import android.provider.DeviceConfig;
|
|
import android.provider.DeviceConfig.Properties;
|
|
{{ endif }}
|
|
/** @hide */
|
|
public final class FeatureFlagsImpl implements FeatureFlags \{
|
|
{{ if is_read_write- }}
|
|
{{ for properties in properties_set }}
|
|
private Properties {properties};
|
|
{{ endfor }}
|
|
{{ endif- }}
|
|
|
|
{{ for flag in flag_elements }}
|
|
@Override
|
|
@UnsupportedAppUsage
|
|
public boolean {flag.method_name}() \{
|
|
{{ -if flag.is_read_write }}
|
|
if ({flag.properties} == null) \{
|
|
{flag.properties} =
|
|
getProperties(
|
|
"{flag.device_config_namespace}",
|
|
"{flag.device_config_flag}"
|
|
);
|
|
}
|
|
return {flag.properties}
|
|
.getBoolean(
|
|
"{flag.device_config_flag}",
|
|
{flag.default_value}
|
|
);
|
|
{{ else }}
|
|
return {flag.default_value};
|
|
{{ endif- }}
|
|
}
|
|
{{ endfor }}
|
|
|
|
{{ -if is_read_write }}
|
|
private Properties getProperties(
|
|
String namespace,
|
|
String flagName) \{
|
|
Properties properties = null;
|
|
try \{
|
|
properties = DeviceConfig.getProperties(namespace);
|
|
} catch (NullPointerException e) \{
|
|
throw new RuntimeException(
|
|
"Cannot read value of flag " + flagName + " from DeviceConfig. "
|
|
+ "It could be that the code using flag executed "
|
|
+ "before SettingsProvider initialization. "
|
|
+ "Please use fixed read-only flag by adding "
|
|
+ "is_fixed_read_only: true in flag declaration.",
|
|
e
|
|
);
|
|
}
|
|
|
|
return properties;
|
|
}
|
|
{{ endif- }}
|
|
}
|
|
{{ else }}
|
|
{#- Generate only stub if in test mode #}
|
|
/** @hide */
|
|
public final class FeatureFlagsImpl implements FeatureFlags \{
|
|
{{ for flag in flag_elements }}
|
|
@Override
|
|
@UnsupportedAppUsage
|
|
public boolean {flag.method_name}() \{
|
|
throw new UnsupportedOperationException(
|
|
"Method is not implemented.");
|
|
}
|
|
{{ endfor }}
|
|
}
|
|
{{ endif }}
|