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 }} {#- end of not library_exported#} 6{{ -if runtime_lookup_required }} 7import android.os.Binder; 8import android.provider.DeviceConfig; 9import android.provider.DeviceConfig.Properties; 10{{ -endif }} {#- end of runtime_lookup_required#} 11/** @hide */ 12public final class FeatureFlagsImpl implements FeatureFlags \{ 13{{ -if runtime_lookup_required }} 14{{ -for namespace_with_flags in namespace_flags }} 15 private static volatile boolean {namespace_with_flags.namespace}_is_cached = false; 16{{ -endfor- }} 17{{ for flag in flag_elements }} 18{{- if flag.is_read_write }} 19 private static boolean {flag.method_name} = {flag.default_value}; 20{{ -endif }} {#- end of is_read_write#} 21{{ -endfor }} 22{{ for namespace_with_flags in namespace_flags }} 23 private void load_overrides_{namespace_with_flags.namespace}() \{ 24 final long ident = Binder.clearCallingIdentity(); 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(Flags.FLAG_{flag.flag_name_constant_suffix}, {flag.default_value}); 31{{ -endif }} {#- end of is_read_write#} 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 } catch (SecurityException e) \{ 43 // for isolated process case, skip loading flag value from the storage, use the default 44 } finally \{ 45 Binder.restoreCallingIdentity(ident); 46 } 47 {namespace_with_flags.namespace}_is_cached = true; 48} 49{{ endfor- }} 50{{ -endif }}{#- end of runtime_lookup_required #} 51{{ -for flag in flag_elements }} 52 @Override 53{{ -if not library_exported }} 54 @com.android.aconfig.annotations.AconfigFlagAccessor 55 @UnsupportedAppUsage 56{{ -endif }}{#- end of not library_exported #} 57 public boolean {flag.method_name}() \{ 58{{ -if flag.is_read_write }} 59 if (!{flag.device_config_namespace}_is_cached) \{ 60 load_overrides_{flag.device_config_namespace}(); 61 } 62 return {flag.method_name}; 63{{ -else }} {#- else is_read_write #} 64 return {flag.default_value}; 65{{ -endif }}{#- end of is_read_write #} 66 } 67{{ endfor }} 68} 69