Merge "Use CoreSettingsObserver for accessing text flags" into main
diff --git a/core/java/android/text/ClientFlags.java b/core/java/android/text/ClientFlags.java
new file mode 100644
index 0000000..46fa501
--- /dev/null
+++ b/core/java/android/text/ClientFlags.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.text;
+
+import com.android.text.flags.Flags;
+
+/**
+ * An aconfig feature flags that can be accessible from application process without
+ * ContentProvider IPCs.
+ *
+ * When you add new flags, you have to add flag string to {@link TextFlags#TEXT_ACONFIGS_FLAGS}.
+ *
+ * @hide
+ */
+public class ClientFlags {
+
+    /**
+     * @see Flags#deprecateFontsXml()
+     */
+    public static boolean deprecateFontsXml() {
+        return TextFlags.isFeatureEnabled(Flags.FLAG_DEPRECATE_FONTS_XML);
+    }
+
+    /**
+     * @see Flags#noBreakNoHyphenationSpan()
+     */
+    public static boolean noBreakNoHyphenationSpan() {
+        return TextFlags.isFeatureEnabled(Flags.FLAG_NO_BREAK_NO_HYPHENATION_SPAN);
+    }
+
+    /**
+     * @see Flags#phraseStrictFallback()
+     */
+    public static boolean phraseStrictFallback() {
+        return TextFlags.isFeatureEnabled(Flags.FLAG_PHRASE_STRICT_FALLBACK);
+    }
+
+    /**
+     * @see Flags#useBoundsForWidth()
+     */
+    public static boolean useBoundsForWidth() {
+        return TextFlags.isFeatureEnabled(Flags.FLAG_USE_BOUNDS_FOR_WIDTH);
+    }
+}
diff --git a/core/java/android/text/TextFlags.java b/core/java/android/text/TextFlags.java
index 4be6a8d..536e3cc 100644
--- a/core/java/android/text/TextFlags.java
+++ b/core/java/android/text/TextFlags.java
@@ -16,6 +16,11 @@
 
 package android.text;
 
+import android.annotation.NonNull;
+import android.app.AppGlobals;
+
+import com.android.text.flags.Flags;
+
 /**
  * Flags in the "text" namespace.
  *
@@ -46,4 +51,28 @@
      */
     public static final boolean ENABLE_NEW_CONTEXT_MENU_DEFAULT = true;
 
+    /**
+     * List of text flags to be transferred to the application process.
+     */
+    public static final String[] TEXT_ACONFIGS_FLAGS = {
+            Flags.FLAG_DEPRECATE_FONTS_XML,
+            Flags.FLAG_NO_BREAK_NO_HYPHENATION_SPAN,
+            Flags.FLAG_PHRASE_STRICT_FALLBACK,
+            Flags.FLAG_USE_BOUNDS_FOR_WIDTH,
+    };
+
+    /**
+     * Get a key for the feature flag.
+     */
+    public static String getKeyForFlag(@NonNull String flag) {
+        return "text__" + flag;
+    }
+
+    /**
+     * Return true if the feature flag is enabled.
+     */
+    public static boolean isFeatureEnabled(@NonNull String flag) {
+        return AppGlobals.getIntCoreSetting(
+                getKeyForFlag(flag), 0 /* aconfig is false by default */) != 0;
+    }
 }
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index a0d0656..2c41330 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -103,6 +103,7 @@
 import android.os.UserHandle;
 import android.provider.Settings;
 import android.text.BoringLayout;
+import android.text.ClientFlags;
 import android.text.DynamicLayout;
 import android.text.Editable;
 import android.text.GetChars;
@@ -1634,7 +1635,7 @@
         }
 
         if (CompatChanges.isChangeEnabled(USE_BOUNDS_FOR_WIDTH)) {
-            mUseBoundsForWidth = false;  // TODO: Connect to the flag.
+            mUseBoundsForWidth = ClientFlags.useBoundsForWidth();
         } else {
             mUseBoundsForWidth = false;
         }
diff --git a/services/core/java/com/android/server/am/CoreSettingsObserver.java b/services/core/java/com/android/server/am/CoreSettingsObserver.java
index e84fed7..4b622f5 100644
--- a/services/core/java/com/android/server/am/CoreSettingsObserver.java
+++ b/services/core/java/com/android/server/am/CoreSettingsObserver.java
@@ -173,6 +173,16 @@
                 TextFlags.NAMESPACE, TextFlags.ENABLE_NEW_CONTEXT_MENU,
                 TextFlags.KEY_ENABLE_NEW_CONTEXT_MENU, boolean.class,
                 TextFlags.ENABLE_NEW_CONTEXT_MENU_DEFAULT));
+
+        // Register all text aconfig flags.
+        for (String flag : TextFlags.TEXT_ACONFIGS_FLAGS) {
+            sDeviceConfigEntries.add(new DeviceConfigEntry<Boolean>(
+                    TextFlags.NAMESPACE,
+                    flag,
+                    TextFlags.getKeyForFlag(flag),
+                    boolean.class,
+                    false));  // All aconfig flags are false by default.
+        }
         // add other device configs here...
     }
     private static volatile boolean sDeviceConfigContextEntriesLoaded = false;