aconfig: Java codegen iteration 1
This change includes
- refactor generated java code to generate
- Flags.java to support the static API
- FeatureFlagsImpl.java to support injection API
- FeatureFlags.java interface
Bug: 279483816
Test: atest aconfig.test aconfig.test.java
Change-Id: If0d4baf317b9174635cd0fff3832ab7091ee52ed
diff --git a/tools/aconfig/templates/FeatureFlags.java.template b/tools/aconfig/templates/FeatureFlags.java.template
new file mode 100644
index 0000000..b9e2cc7
--- /dev/null
+++ b/tools/aconfig/templates/FeatureFlags.java.template
@@ -0,0 +1,7 @@
+package {package_name};
+
+public interface FeatureFlags \{
+ {{ for item in class_elements}}
+ boolean {item.method_name}();
+ {{ endfor }}
+}
\ No newline at end of file
diff --git a/tools/aconfig/templates/java.template b/tools/aconfig/templates/FeatureFlagsImpl.java.template
similarity index 63%
rename from tools/aconfig/templates/java.template
rename to tools/aconfig/templates/FeatureFlagsImpl.java.template
index a3d3319..2b031f1 100644
--- a/tools/aconfig/templates/java.template
+++ b/tools/aconfig/templates/FeatureFlagsImpl.java.template
@@ -1,11 +1,12 @@
-package {package};
-{{ if readwrite }}
+package {package_name};
+{{ if is_read_write }}
import android.provider.DeviceConfig;
{{ endif }}
-public final class Flags \{
+public final class FeatureFlagsImpl implements FeatureFlags \{
{{ for item in class_elements}}
- public static boolean {item.method_name}() \{
- {{ if item.readwrite- }}
+ @Override
+ public boolean {item.method_name}() \{
+ {{ if item.is_read_write- }}
return DeviceConfig.getBoolean(
"{item.device_config_namespace}",
"{item.device_config_flag}",
@@ -16,4 +17,4 @@
{{ -endif }}
}
{{ endfor }}
-}
+}
\ No newline at end of file
diff --git a/tools/aconfig/templates/Flags.java.template b/tools/aconfig/templates/Flags.java.template
new file mode 100644
index 0000000..752a469
--- /dev/null
+++ b/tools/aconfig/templates/Flags.java.template
@@ -0,0 +1,11 @@
+package {package_name};
+
+public final class Flags \{
+ {{ for item in class_elements}}
+ public static boolean {item.method_name}() \{
+ return FEATURE_FLAGS.{item.method_name}();
+ }
+ {{ endfor }}
+ private static FeatureFlags FEATURE_FLAGS = new FeatureFlagsImpl();
+
+}