Reading value from DeviceConfig may fail if the provider is not ready. Since DeciceConfig, and Settings class are static wrapper on top of the provider, it won't cause the instance initialization issue. Thus when the issue happens it means the provider is not initialized. Test: atest aconfig.test.java and manually make a change in the framework and check the exception message Bug: 299471646 Change-Id: Ic08d7a9cd32a8810a7274b6d93c249abccb50b9e
59 lines
1.7 KiB
Plaintext
59 lines
1.7 KiB
Plaintext
package {package_name};
|
|
{{ if not is_test_mode }}
|
|
{{ if is_read_write- }}
|
|
import android.provider.DeviceConfig;
|
|
{{ endif }}
|
|
/** @hide */
|
|
public final class FeatureFlagsImpl implements FeatureFlags \{
|
|
{{ for item in class_elements}}
|
|
@Override
|
|
public boolean {item.method_name}() \{
|
|
{{ -if item.is_read_write }}
|
|
return getValue(
|
|
"{item.device_config_namespace}",
|
|
"{item.device_config_flag}",
|
|
{item.default_value}
|
|
);
|
|
{{ else }}
|
|
return {item.default_value};
|
|
{{ endif- }}
|
|
}
|
|
{{ endfor }}
|
|
{{ if is_read_write- }}
|
|
private boolean getValue(String nameSpace,
|
|
String flagName, boolean defaultValue) \{
|
|
boolean value = defaultValue;
|
|
try \{
|
|
value = DeviceConfig.getBoolean(
|
|
nameSpace,
|
|
flagName,
|
|
defaultValue
|
|
);
|
|
} 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 value;
|
|
}
|
|
{{ endif- }}
|
|
}
|
|
{{ else }}
|
|
{#- Generate only stub if in test mode #}
|
|
/** @hide */
|
|
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 }}
|