1package {package_name}; 2{{ if not library_exported- }} 3// TODO(b/303773055): Remove the annotation after access issue is resolved. 4import android.compat.annotation.UnsupportedAppUsage; 5{{ -endif }} 6{{ -if not is_test_mode }} 7{{ -if runtime_lookup_required }} 8import android.provider.DeviceConfig; 9import android.provider.DeviceConfig.Properties; 10{{ endif }} 11/** @hide */ 12public final class FeatureFlagsImpl implements FeatureFlags \{ 13{{ -if runtime_lookup_required }} 14{{ -for namespace_with_flags in namespace_flags }} 15 private static boolean {namespace_with_flags.namespace}_is_cached = false; 16{{ -endfor- }} 17 18{{ for flag in flag_elements }} 19{{- if flag.is_read_write }} 20 private static boolean {flag.method_name} = {flag.default_value}; 21{{ -endif }} 22{{ -endfor }} 23{{ for namespace_with_flags in namespace_flags }} 24 private void load_overrides_{namespace_with_flags.namespace}() \{ 25 try \{ 26 Properties properties = DeviceConfig.getProperties("{namespace_with_flags.namespace}"); 27{{ -for flag in namespace_with_flags.flags }} 28{{ -if flag.is_read_write }} 29 {flag.method_name} = 30 properties.getBoolean("{flag.device_config_flag}", {flag.default_value}); 31{{ -endif }} 32{{ -endfor }} 33 } catch (NullPointerException e) \{ 34 throw new RuntimeException( 35 "Cannot read value from namespace {namespace_with_flags.namespace} " 36 + "from DeviceConfig. It could be that the code using flag " 37 + "executed before SettingsProvider initialization. Please use " 38 + "fixed read-only flag by adding is_fixed_read_only: true in " 39 + "flag declaration.", 40 e 41 ); 42 } 43 {namespace_with_flags.namespace}_is_cached = true; 44 } 45{{ endfor- }} 46{{ -endif }}{#- end of runtime_lookup_required #} 47{{ -for flag in flag_elements }} 48 @Override 49{{ -if not library_exported }} 50 @com.android.aconfig.annotations.AconfigFlagAccessor 51 @UnsupportedAppUsage 52{{ -endif }} 53 public boolean {flag.method_name}() \{ 54{{ -if flag.is_read_write }} 55 if (!{flag.device_config_namespace}_is_cached) \{ 56 load_overrides_{flag.device_config_namespace}(); 57 } 58 return {flag.method_name}; 59{{ -else }} 60 return {flag.default_value}; 61{{ -endif }} 62 } 63{{ endfor }} 64} 65{{ else }} 66{#- Generate only stub if in test mode #} 67/** @hide */ 68public final class FeatureFlagsImpl implements FeatureFlags \{ 69{{ for flag in flag_elements }} 70 @Override 71{{ -if not library_exported }} 72 @com.android.aconfig.annotations.AconfigFlagAccessor 73 @UnsupportedAppUsage 74{{ -endif }} 75 public boolean {flag.method_name}() \{ 76 throw new UnsupportedOperationException( 77 "Method is not implemented."); 78 } 79{{ endfor- }} 80} 81{{ endif }} 82