Add Trunk Stable flags to Autofill

Bug: 297380045

Test: N/A; config
Change-Id: I05c3081f0a93d776039eb35ace42ab39ca9d9f69
diff --git a/services/autofill/Android.bp b/services/autofill/Android.bp
index eb23f2f..d43a219 100644
--- a/services/autofill/Android.bp
+++ b/services/autofill/Android.bp
@@ -19,4 +19,19 @@
     defaults: ["platform_service_defaults"],
     srcs: [":services.autofill-sources"],
     libs: ["services.core"],
+    static_libs: ["autofill_flags_java_lib"],
+}
+
+aconfig_declarations {
+    name: "autofill_flags",
+    package: "android.service.autofill",
+    srcs: [
+        "bugfixes.aconfig",
+        "features.aconfig",
+    ],
+}
+
+java_aconfig_library {
+    name: "autofill_flags_java_lib",
+    aconfig_declarations: "autofill_flags",
 }
diff --git a/services/autofill/bugfixes.aconfig b/services/autofill/bugfixes.aconfig
new file mode 100644
index 0000000..ef23754
--- /dev/null
+++ b/services/autofill/bugfixes.aconfig
@@ -0,0 +1,8 @@
+package: "android.service.autofill"
+
+flag {
+  name: "test"
+  namespace: "autofill"
+  description: "Test flag "
+  bug: "297380045"
+}
\ No newline at end of file
diff --git a/services/autofill/features.aconfig b/services/autofill/features.aconfig
new file mode 100644
index 0000000..1e44de6
--- /dev/null
+++ b/services/autofill/features.aconfig
@@ -0,0 +1 @@
+package: "android.service.autofill"
\ No newline at end of file
diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceShellCommand.java b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceShellCommand.java
index c66fb81..39756df 100644
--- a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceShellCommand.java
+++ b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceShellCommand.java
@@ -26,11 +26,14 @@
 import android.os.ShellCommand;
 import android.os.UserHandle;
 import android.service.autofill.AutofillFieldClassificationService.Scores;
+import android.service.autofill.Flags;
 import android.view.autofill.AutofillManager;
 
 import com.android.internal.os.IResultReceiver;
 
 import java.io.PrintWriter;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
@@ -60,6 +63,8 @@
                 return requestGet(pw);
             case "set":
                 return requestSet(pw);
+            case "flags":
+                return requestFlags(pw);
             default:
                 return handleDefaultCommands(cmd);
         }
@@ -67,7 +72,7 @@
 
     @Override
     public void onHelp() {
-        try (final PrintWriter pw = getOutPrintWriter();) {
+        try (final PrintWriter pw = getOutPrintWriter(); ) {
             pw.println("AutoFill Service (autofill) commands:");
             pw.println("  help");
             pw.println("    Prints this help text.");
@@ -109,21 +114,24 @@
             pw.println("    Sets whether binding to services provided by instant apps is allowed");
             pw.println("");
             pw.println("  set temporary-augmented-service USER_ID [COMPONENT_NAME DURATION]");
-            pw.println("    Temporarily (for DURATION ms) changes the augmented autofill service "
-                    + "implementation.");
+            pw.println(
+                    "    Temporarily (for DURATION ms) changes the augmented autofill service "
+                            + "implementation.");
             pw.println("    To reset, call with just the USER_ID argument.");
             pw.println("");
             pw.println("  set default-augmented-service-enabled USER_ID [true|false]");
             pw.println("    Enable / disable the default augmented autofill service for the user.");
             pw.println("");
             pw.println("  set temporary-detection-service USER_ID [COMPONENT_NAME DURATION]");
-            pw.println("    Temporarily (for DURATION ms) changes the autofill detection service "
-                    + "implementation.");
+            pw.println(
+                    "    Temporarily (for DURATION ms) changes the autofill detection service "
+                            + "implementation.");
             pw.println("    To reset, call with [COMPONENT_NAME 0].");
             pw.println("");
             pw.println("  get default-augmented-service-enabled USER_ID");
-            pw.println("    Checks whether the default augmented autofill service is enabled for "
-                    + "the user.");
+            pw.println(
+                    "    Checks whether the default augmented autofill service is enabled for "
+                            + "the user.");
             pw.println("");
             pw.println("  list sessions [--user USER_ID]");
             pw.println("    Lists all pending sessions.");
@@ -134,9 +142,36 @@
             pw.println("  reset");
             pw.println("    Resets all pending sessions and cached service connections.");
             pw.println("");
+            pw.println("  flags");
+            pw.println("    Prints out all autofill related flags.");
+            pw.println("");
         }
     }
 
+    private int requestFlags(PrintWriter pw) {
+
+        if (Flags.test()) {
+            pw.println("Hello Flag World!");
+            pw.println("");
+        }
+
+        try {
+            Method[] flagMethods = Flags.class.getMethods();
+            // For some reason, unreferenced flags do not show up here
+            // Maybe compiler optomized them out of bytecode?
+            for (Method method : flagMethods) {
+                if (Modifier.isPublic(method.getModifiers())) {
+                    pw.println(method.getName() + ": " + method.invoke(null));
+                }
+            }
+        } catch (Exception ex) {
+            pw.println(ex);
+            return -1;
+        }
+
+        return 0;
+    }
+
     private int requestGet(PrintWriter pw) {
         final String what = getNextArgRequired();
         switch(what) {