Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 49a91155 authored by Seigo Nonaka's avatar Seigo Nonaka Committed by Android (Google) Code Review
Browse files

Merge "Use CoreSettingsObserver for accessing text flags" into main

parents e9c3a96b 473adff6
Loading
Loading
Loading
Loading
+58 −0
Original line number Diff line number Diff line
/*
 * 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);
    }
}
+29 −0
Original line number Diff line number Diff line
@@ -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 final class TextFlags {
     */
    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;
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ import android.os.SystemClock;
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 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }
        if (CompatChanges.isChangeEnabled(USE_BOUNDS_FOR_WIDTH)) {
            mUseBoundsForWidth = false;  // TODO: Connect to the flag.
            mUseBoundsForWidth = ClientFlags.useBoundsForWidth();
        } else {
            mUseBoundsForWidth = false;
        }
+10 −0
Original line number Diff line number Diff line
@@ -173,6 +173,16 @@ final class CoreSettingsObserver extends ContentObserver {
                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;