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

Commit af4dd5d8 authored by Yeabkal Wubshit's avatar Yeabkal Wubshit
Browse files

Flag boot-time font loading optimizations

This change guards recent font loading optimizations made for the
following bug: b/282883510.

Bug: 304406888
Test: presubmit
Change-Id: I417c6d4b40bd797cc74c11e415f4fed0340d82a0
parent 78dca6fa
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -4,5 +4,7 @@ flag {
  name: "deprecate_fonts_xml"
  namespace: "text"
  description: "Feature flag for deprecating fonts.xml. By setting true for this feature flag, the new font configuration XML, /system/etc/font_fallback.xml is used. The new XML has a new syntax and flexibility of variable font declarations, but it is not compatible with the apps that reads fonts.xml. So, fonts.xml is maintained as a subset of the font_fallback.xml"
  # Make read only, as it could be used before the Settings provider is initialized.
  is_fixed_read_only: true
  bug: "281769620"
}
+11 −0
Original line number Diff line number Diff line
package: "com.android.text.flags"

flag {
  name: "use_optimized_boottime_font_loading"
  namespace: "text"
  description: "Feature flag ensuring that font is loaded once and asynchronously."
  # Make read only, as font loading is in the critical boot path which happens before the read-write
  # flags propagate to the device.
  is_fixed_read_only: true
  bug: "304406888"
}
+33 −16
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import com.android.internal.util.Preconditions;
import com.android.server.LocalServices;
import com.android.server.SystemServerInitThreadPool;
import com.android.server.SystemService;
import com.android.text.flags.Flags;

import java.io.File;
import java.io.FileDescriptor;
@@ -240,22 +241,36 @@ public final class FontManagerService extends IFontManager.Stub {
        mContext = context;
        mIsSafeMode = safeMode;

        if (Flags.useOptimizedBoottimeFontLoading()) {
            Slog.i(TAG, "Using optimized boot-time font loading.");
            SystemServerInitThreadPool.submit(() -> {
                initialize();

                // Set system font map only if there is updatable font directory.
            // If there is no updatable font directory, `initialize` will have already loaded the
            // system font map, so there's no need to set the system font map again here.
                // If there is no updatable font directory, `initialize` will have already loaded
                // the system font map, so there's no need to set the system font map again here.
                synchronized (mUpdatableFontDirLock) {
                    if  (mUpdatableFontDir != null) {
                        setSystemFontMap();
                    }
                }
                serviceStarted.complete(null);
            }, "FontManagerService_create");
        } else {
            Slog.i(TAG, "Not using optimized boot-time font loading.");
            initialize();
            setSystemFontMap();
            serviceStarted.complete(null);
        }
    }

    private void setSystemFontMap() {
        try {
            Typeface.setSystemFontMap(getCurrentFontMap());
        } catch (IOException | ErrnoException e) {
            Slog.w(TAG, "Failed to set system font map of system_server");
        }
    }
            serviceStarted.complete(null);
        }, "FontManagerService_create");
    }

    @Nullable
    private UpdatableFontDir createUpdatableFontDir() {
@@ -291,9 +306,11 @@ public final class FontManagerService extends IFontManager.Stub {
        synchronized (mUpdatableFontDirLock) {
            mUpdatableFontDir = createUpdatableFontDir();
            if (mUpdatableFontDir == null) {
                // If fs-verity is not supported, load preinstalled system font map and use it for
                // all apps.
                if (Flags.useOptimizedBoottimeFontLoading()) {
                    // If fs-verity is not supported, load preinstalled system font map and use it
                    // for all apps.
                    Typeface.loadPreinstalledSystemFontMap();
                }
                setSerializedFontMap(serializeSystemServerFontMap());
                return;
            }
+9 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import android.credentials.CredentialManager;
import android.database.sqlite.SQLiteCompatibilityWalFlags;
import android.database.sqlite.SQLiteGlobal;
import android.graphics.GraphicsStatsService;
import android.graphics.Typeface;
import android.hardware.display.DisplayManagerInternal;
import android.net.ConnectivityManager;
import android.net.ConnectivityModuleConnector;
@@ -916,6 +917,14 @@ public final class SystemServer implements Dumpable {
            SystemServerInitThreadPool tp = SystemServerInitThreadPool.start();
            mDumper.addDumpable(tp);

            // Lazily load the pre-installed system font map in SystemServer only if we're not doing
            // the optimized font loading in the FontManagerService.
            if (!com.android.text.flags.Flags.useOptimizedBoottimeFontLoading()
                    && Typeface.ENABLE_LAZY_TYPEFACE_INITIALIZATION) {
                Slog.i(TAG, "Loading pre-installed system font map.");
                Typeface.loadPreinstalledSystemFontMap();
            }

            // Attach JVMTI agent if this is a debuggable build and the system property is set.
            if (Build.IS_DEBUGGABLE) {
                // Property is of the form "library_path=parameters".