blob: ec8822c49cb55203f323783295a0b85dc993dac0 [file] [log] [blame]
Zhi Dou4655c962023-06-12 15:56:03 +00001package {package_name};
Zhi Dou22a90f42023-10-06 07:28:44 +00002// TODO(b/303773055): Remove the annotation after access issue is resolved.
3import android.compat.annotation.UnsupportedAppUsage;
Zhi Dou5aaeee32023-08-07 22:54:13 +00004{{ if not is_test_mode }}
Zhi Dou8ba6aa72023-06-26 21:03:40 +00005{{ if is_read_write- }}
Zhi Doueb744892023-05-10 04:02:33 +00006import android.provider.DeviceConfig;
Zhi Dou72c2a932023-10-31 22:57:30 +00007import android.provider.DeviceConfig.Properties;
Zhi Doueb744892023-05-10 04:02:33 +00008{{ endif }}
Mårten Kongstad65efa272023-09-11 12:17:25 +00009/** @hide */
Zhi Dou4655c962023-06-12 15:56:03 +000010public final class FeatureFlagsImpl implements FeatureFlags \{
Ted Bauerc3073782023-11-15 18:04:54 +000011{{- if is_read_write }}
12{{- for namespace_with_flags in namespace_flags }}
13 private static boolean {namespace_with_flags.namespace}_is_cached = false;
14{{- endfor- }}
15
16{{ for flag in flag_elements }}
17{{- if flag.is_read_write }}
18 private static boolean {flag.method_name} = {flag.default_value};
19{{- endif- }}
Zhi Dou72c2a932023-10-31 22:57:30 +000020{{ endfor }}
Ted Bauerc3073782023-11-15 18:04:54 +000021
22{{ for namespace_with_flags in namespace_flags }}
23 private void load_overrides_{namespace_with_flags.namespace}() \{
24 try \{
25 Properties properties = DeviceConfig.getProperties("{namespace_with_flags.namespace}");
26
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- }}
Zhi Dou72c2a932023-10-31 22:57:30 +000046{{ endif- }}
47
48{{ for flag in flag_elements }}
Zhi Dou4655c962023-06-12 15:56:03 +000049 @Override
Zhi Dou22a90f42023-10-06 07:28:44 +000050 @UnsupportedAppUsage
Zhi Dou72c2a932023-10-31 22:57:30 +000051 public boolean {flag.method_name}() \{
52 {{ -if flag.is_read_write }}
Ted Bauerc3073782023-11-15 18:04:54 +000053 if (!{flag.device_config_namespace}_is_cached) \{
54 load_overrides_{flag.device_config_namespace}();
Zhi Dou72c2a932023-10-31 22:57:30 +000055 }
Ted Bauerc3073782023-11-15 18:04:54 +000056 return {flag.method_name};
Zhi Dou5aaeee32023-08-07 22:54:13 +000057 {{ else }}
Zhi Dou72c2a932023-10-31 22:57:30 +000058 return {flag.default_value};
Zhi Dou5aaeee32023-08-07 22:54:13 +000059 {{ endif- }}
Zhi Doueb744892023-05-10 04:02:33 +000060 }
Zhi Dou06a448f2023-08-15 19:33:27 +000061{{ endfor }}
Zhi Dou8ba6aa72023-06-26 21:03:40 +000062}
Zhi Dou5aaeee32023-08-07 22:54:13 +000063{{ else }}
64{#- Generate only stub if in test mode #}
Mårten Kongstad65efa272023-09-11 12:17:25 +000065/** @hide */
Zhi Dou5aaeee32023-08-07 22:54:13 +000066public final class FeatureFlagsImpl implements FeatureFlags \{
Zhi Dou72c2a932023-10-31 22:57:30 +000067{{ for flag in flag_elements }}
Zhi Dou5aaeee32023-08-07 22:54:13 +000068 @Override
Zhi Dou22a90f42023-10-06 07:28:44 +000069 @UnsupportedAppUsage
Zhi Dou72c2a932023-10-31 22:57:30 +000070 public boolean {flag.method_name}() \{
Zhi Dou5aaeee32023-08-07 22:54:13 +000071 throw new UnsupportedOperationException(
72 "Method is not implemented.");
73 }
Ted Bauerc3073782023-11-15 18:04:54 +000074{{ endfor- }}
Zhi Dou5aaeee32023-08-07 22:54:13 +000075}
76{{ endif }}