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

Commit 9b9486eb authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add more shell command for font" into sc-dev

parents 299897e9 9387e7f4
Loading
Loading
Loading
Loading
+113 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.graphics.fonts;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
@@ -28,6 +29,8 @@ import android.util.Log;

import com.android.internal.graphics.fonts.IFontManager;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;

/**
@@ -41,6 +44,116 @@ public class FontManager {
    private static final String TAG = "FontManager";
    private final @NonNull IFontManager mIFontManager;

    /** @hide */
    @IntDef(prefix = "ERROR_CODE_",
            value = { ERROR_CODE_OK, ERROR_CODE_FAILED_TO_WRITE_FONT_FILE,
                    ERROR_CODE_VERIFICATION_FAILURE, ERROR_CODE_FONT_NAME_MISMATCH,
                    ERROR_CODE_INVALID_FONT_FILE, ERROR_CODE_MISSING_POST_SCRIPT_NAME,
                    ERROR_CODE_DOWNGRADING, ERROR_CODE_FAILED_TO_CREATE_CONFIG_FILE,
                    ERROR_CODE_FONT_UPDATER_DISABLED })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ErrorCode {}

    /**
     * Indicates an operation has processed successfully.
     * @hide
     */
    public static final int ERROR_CODE_OK = 0;

    /**
     * Indicates a failure of writing font files.
     * @hide
     */
    public static final int ERROR_CODE_FAILED_TO_WRITE_FONT_FILE = -1;

    /**
     * Indicates a failure of fs-verity setup.
     * @hide
     */
    public static final int ERROR_CODE_VERIFICATION_FAILURE = -2;

    /**
     * Indicates a failure of verifying the font name with PostScript name.
     * @hide
     */
    public static final int ERROR_CODE_FONT_NAME_MISMATCH = -3;

    /**
     * Indicates a failure of placing fonts due to unexpected font contents.
     * @hide
     */
    public static final int ERROR_CODE_INVALID_FONT_FILE = -4;

    /**
     * Indicates a failure due to missing PostScript name in name table.
     * @hide
     */
    public static final int ERROR_CODE_MISSING_POST_SCRIPT_NAME = -5;

    /**
     * Indicates a failure of placing fonts due to downgrading.
     * @hide
     */
    public static final int ERROR_CODE_DOWNGRADING = -6;

    /**
     * Indicates a failure of writing system font configuration XML file.
     * @hide
     */
    public static final int ERROR_CODE_FAILED_TO_CREATE_CONFIG_FILE = -7;

    /**
     * Indicates a failure due to disabled font updater.
     * @hide
     */
    public static final int ERROR_CODE_FONT_UPDATER_DISABLED = -8;

    /**
     * Indicates a failure of opening font file.
     *
     * This error code is only used with the shell command interaction.
     *
     * @hide
     */
    public static final int ERROR_CODE_FAILED_TO_OPEN_FONT_FILE = -10001;

    /**
     * Indicates a failure of opening signature file.
     *
     * This error code is only used with the shell command interaction.
     *
     * @hide
     */
    public static final int ERROR_CODE_FAILED_TO_OPEN_SIGNATURE_FILE = -10002;

    /**
     * Indicates a failure of invalid shell command arguments.
     *
     * This error code is only used with the shell command interaction.
     *
     * @hide
     */
    public static final int ERROR_CODE_INVALID_SHELL_ARGUMENT = -10003;

    /**
     * Indicates a failure of reading signature file.
     *
     * This error code is only used with the shell command interaction.
     *
     * @hide
     */
    public static final int ERROR_CODE_INVALID_SIGNATURE_FILE = -10004;

    /**
     * Indicates a failure due to exceeding allowed signature file size (8kb).
     *
     * This error code is only used with the shell command interaction.
     *
     * @hide
     */
    public static final int ERROR_CODE_SIGNATURE_TOO_LARGE = -10005;


    private FontManager(@NonNull IFontManager iFontManager) {
        mIFontManager = iFontManager;
    }
+31 −2
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ import java.util.List;
public final class FontConfig implements Parcelable {
    private final @NonNull List<FontFamily> mFamilies;
    private final @NonNull List<Alias> mAliases;
    private final long mLastModifiedDate;
    private final int mConfigVersion;

    /**
     * Construct a FontConfig instance.
@@ -62,9 +64,12 @@ public final class FontConfig implements Parcelable {
     *
     * @hide Only system server can create this instance and passed via IPC.
     */
    public FontConfig(@NonNull List<FontFamily> families, @NonNull List<Alias> aliases) {
    public FontConfig(@NonNull List<FontFamily> families, @NonNull List<Alias> aliases,
            long lastModifiedDate, @IntRange(from = 0) int configVersion) {
        mFamilies = families;
        mAliases = aliases;
        mLastModifiedDate = lastModifiedDate;
        mConfigVersion = configVersion;
    }

    /**
@@ -87,6 +92,26 @@ public final class FontConfig implements Parcelable {
        return mAliases;
    }

    /**
     * Returns the last modified date as Java epoch seconds.
     *
     * If there is no update, this return 0.
     * @hide
     */
    public long getLastModifiedDate() {
        return mLastModifiedDate;
    }

    /**
     * Returns the monotonically increasing config version value.
     *
     * The config version is reset to 0 when the system is restarted.
     * @hide
     */
    public @IntRange(from = 0) int getConfigVersion() {
        return mConfigVersion;
    }

    /**
     * Returns the ordered list of families included in the system fonts.
     * @deprecated Use getFontFamilies instead.
@@ -107,6 +132,8 @@ public final class FontConfig implements Parcelable {
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeParcelableList(mFamilies, flags);
        dest.writeParcelableList(mAliases, flags);
        dest.writeLong(mLastModifiedDate);
        dest.writeInt(mConfigVersion);
    }

    public static final @NonNull Creator<FontConfig> CREATOR = new Creator<FontConfig>() {
@@ -116,7 +143,9 @@ public final class FontConfig implements Parcelable {
                    FontFamily.class.getClassLoader());
            List<Alias> aliases = source.readParcelableList(new ArrayList<>(),
                    Alias.class.getClassLoader());
            return new FontConfig(families, aliases);
            long lastModifiedDate = source.readLong();
            int configVersion = source.readInt();
            return new FontConfig(families, aliases, lastModifiedDate, configVersion);
        }

        @Override
+3 −2
Original line number Diff line number Diff line
@@ -171,7 +171,8 @@ public class TypefaceSystemFallbackTest {
        FontConfig fontConfig;
        try {
            fontConfig = FontListParser.parse(
                    TEST_FONTS_XML, TEST_FONT_DIR, oemXmlPath, TEST_OEM_DIR, updatableFontMap);
                    TEST_FONTS_XML, TEST_FONT_DIR, oemXmlPath, TEST_OEM_DIR, updatableFontMap, 0,
                    0);
        } catch (IOException | XmlPullParserException e) {
            throw new RuntimeException(e);
        }
@@ -199,7 +200,7 @@ public class TypefaceSystemFallbackTest {
        FontConfig fontConfig;
        try {
            fontConfig = FontListParser.parse(
                    SYSTEM_FONTS_XML, SYSTEM_FONT_DIR, null, TEST_OEM_DIR, null);
                    SYSTEM_FONTS_XML, SYSTEM_FONT_DIR, null, TEST_OEM_DIR, null, 0, 0);
        } catch (IOException | XmlPullParserException e) {
            throw new RuntimeException(e);
        }
+1 −1
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ public class FontFallbackSetup implements AutoCloseable {

        FontConfig fontConfig;
        try {
            fontConfig = FontListParser.parse(testFontsXml, mTestFontsDir, null, null, null);
            fontConfig = FontListParser.parse(testFontsXml, mTestFontsDir, null, null, null, 0, 0);
        } catch (IOException | XmlPullParserException e) {
            throw new RuntimeException(e);
        }
+11 −5
Original line number Diff line number Diff line
@@ -51,7 +51,8 @@ public class FontListParser {
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(in, null);
        parser.nextTag();
        return readFamilies(parser, "/system/fonts/", new FontCustomizationParser.Result(), null);
        return readFamilies(parser, "/system/fonts/", new FontCustomizationParser.Result(), null,
                0, 0);
    }

    /**
@@ -71,7 +72,9 @@ public class FontListParser {
            @NonNull String systemFontDir,
            @Nullable String oemCustomizationXmlPath,
            @Nullable String productFontDir,
            @Nullable Map<String, File> updatableFontMap
            @Nullable Map<String, File> updatableFontMap,
            long lastModifiedDate,
            int configVersion
    ) throws IOException, XmlPullParserException {
        FontCustomizationParser.Result oemCustomization;
        if (oemCustomizationXmlPath != null) {
@@ -90,7 +93,8 @@ public class FontListParser {
            XmlPullParser parser = Xml.newPullParser();
            parser.setInput(is, null);
            parser.nextTag();
            return readFamilies(parser, systemFontDir, oemCustomization, updatableFontMap);
            return readFamilies(parser, systemFontDir, oemCustomization, updatableFontMap,
                    lastModifiedDate, configVersion);
        }
    }

@@ -98,7 +102,9 @@ public class FontListParser {
            @NonNull XmlPullParser parser,
            @NonNull String fontDir,
            @NonNull FontCustomizationParser.Result customization,
            @Nullable Map<String, File> updatableFontMap)
            @Nullable Map<String, File> updatableFontMap,
            long lastModifiedDate,
            int configVersion)
            throws XmlPullParserException, IOException {
        List<FontConfig.FontFamily> families = new ArrayList<>();
        List<FontConfig.Alias> aliases = new ArrayList<>(customization.getAdditionalAliases());
@@ -126,7 +132,7 @@ public class FontListParser {
        }

        families.addAll(oemNamedFamilies.values());
        return new FontConfig(families, aliases);
        return new FontConfig(families, aliases, lastModifiedDate, configVersion);
    }

    /**
Loading