Cache flag values when they are read.

Bug: 202860494
Test: manual
Change-Id: Icde45251feb344b36bddf5717b9b21c28cb85eb0
diff --git a/packages/SystemUI/src-debug/com/android/systemui/flags/FeatureFlagManager.java b/packages/SystemUI/src-debug/com/android/systemui/flags/FeatureFlagManager.java
index d096f8d..5b6845f 100644
--- a/packages/SystemUI/src-debug/com/android/systemui/flags/FeatureFlagManager.java
+++ b/packages/SystemUI/src-debug/com/android/systemui/flags/FeatureFlagManager.java
@@ -28,6 +28,7 @@
 import org.json.JSONException;
 import org.json.JSONObject;
 
+import java.util.HashMap;
 import java.util.Map;
 
 import javax.inject.Inject;
@@ -54,6 +55,8 @@
     private static final String FLAGS_PERMISSION = "com.android.systemui.permission.FLAGS";
     private final SystemPropertiesHelper mSystemPropertiesHelper;
 
+    private final Map<Integer, Boolean> mBooleanFlagCache = new HashMap<>();
+
     @Inject
     public FeatureFlagManager(SystemPropertiesHelper systemPropertiesHelper, Context context) {
         mSystemPropertiesHelper = systemPropertiesHelper;
@@ -64,9 +67,12 @@
 
     /** Return a {@link BooleanFlag}'s value. */
     public boolean isEnabled(int id, boolean defaultValue) {
+        if (!mBooleanFlagCache.containsKey(id)) {
+            Boolean result = isEnabledInternal(id);
+            mBooleanFlagCache.put(id, result == null ? defaultValue : result);
+        }
 
-        Boolean result = isEnabledInternal(id);
-        return result == null ? defaultValue : result;
+        return mBooleanFlagCache.get(id);
     }
 
     /** Returns the stored value or null if not set. */