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

Commit b11b963e authored by Kohsuke Yatoh's avatar Kohsuke Yatoh
Browse files

Prepare switching font loading to system server.

Currently, fonts are loaded in Zygote.
This CL adds a preparation to switch it to system server and
bindApplication(), so that system server will be able to update font map
at runtime.

(1) Zygote will be initialized without fonts.
(2) System server will maintain a serialized font map in ashmem.
(3) Apps will load font map from the ashmem in bindApplication().

The change is guarded by Typeface.ENABLE_LAZY_TYPEFACE_INITIALIZATION,
and the new behavior is disabled by default.
I tested with ENABLE_LAZY_TYPEFACE_INITIALIZATION = true.

Bug: 172891184
Test: atest FrameworksCoreTests:TypefaceTest
Test: atest CtsGraphicsTestCases
Test: atest CtsTextTestCases
Test: atest CtsWidgetTestCases
Change-Id: I40832962a4b27f6160c4dc6268689c52f6a4dd33
parent da631e9a
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ import android.database.sqlite.SQLiteDebug.DbStats;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.HardwareRenderer;
import android.graphics.Typeface;
import android.hardware.display.DisplayManagerGlobal;
import android.inputmethodservice.InputMethodService;
import android.media.MediaFrameworkInitializer;
@@ -117,6 +118,7 @@ import android.os.Process;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SharedMemory;
import android.os.StatsFrameworkInitializer;
import android.os.StatsServiceManager;
import android.os.StrictMode;
@@ -844,6 +846,8 @@ public final class ActivityThread extends ClientTransactionHandler {

        long[] disabledCompatChanges;

        SharedMemory mSerializedSystemFontMap;

        @Override
        public String toString() {
            return "AppBindData{appInfo=" + appInfo + "}";
@@ -1054,7 +1058,8 @@ public final class ActivityThread extends ClientTransactionHandler {
                boolean isRestrictedBackupMode, boolean persistent, Configuration config,
                CompatibilityInfo compatInfo, Map services, Bundle coreSettings,
                String buildSerial, AutofillOptions autofillOptions,
                ContentCaptureOptions contentCaptureOptions, long[] disabledCompatChanges) {
                ContentCaptureOptions contentCaptureOptions, long[] disabledCompatChanges,
                SharedMemory serializedSystemFontMap) {
            if (services != null) {
                if (false) {
                    // Test code to make sure the app could see the passed-in services.
@@ -1103,6 +1108,7 @@ public final class ActivityThread extends ClientTransactionHandler {
            data.autofillOptions = autofillOptions;
            data.contentCaptureOptions = contentCaptureOptions;
            data.disabledCompatChanges = disabledCompatChanges;
            data.mSerializedSystemFontMap = serializedSystemFontMap;
            sendMessage(H.BIND_APPLICATION, data);
        }

@@ -6411,6 +6417,13 @@ public final class ActivityThread extends ClientTransactionHandler {
         */
        LocaleList.setDefault(data.config.getLocales());

        try {
            Typeface.setSystemFontMap(data.mSerializedSystemFontMap);
        } catch (IOException | ErrnoException e) {
            Slog.e(TAG, "Failed to parse serialized system font map");
            Typeface.loadPreinstalledSystemFontMap();
        }

        synchronized (mResourcesManager) {
            /*
             * Update the system configuration since its preloaded and might not
+3 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.os.IInterface;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.RemoteCallback;
import android.os.SharedMemory;

import com.android.internal.app.IVoiceInteractor;
import com.android.internal.content.ReferrerIntent;
@@ -75,7 +76,8 @@ oneway interface IApplicationThread {
            boolean restrictedBackupMode, boolean persistent, in Configuration config,
            in CompatibilityInfo compatInfo, in Map services,
            in Bundle coreSettings, in String buildSerial, in AutofillOptions autofillOptions,
            in ContentCaptureOptions contentCaptureOptions, in long[] disabledCompatChanges);
            in ContentCaptureOptions contentCaptureOptions, in long[] disabledCompatChanges,
            in SharedMemory serializedSystemFontMap);
    void runIsolatedEntryPoint(in String entryPoint, in String[] entryPointArgs);
    void scheduleExit();
    void scheduleServiceArgs(IBinder token, in ParceledListSlice args);
+3 −0
Original line number Diff line number Diff line
@@ -964,6 +964,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     * @hide
     */
    public static void preloadFontCache() {
        if (Typeface.ENABLE_LAZY_TYPEFACE_INITIALIZATION) {
            return;
        }
        Paint p = new Paint();
        p.setAntiAlias(true);
        // Ensure that the Typeface is loaded here.
+3 −1
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.os.Parcelable;
import android.os.PersistableBundle;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.SharedMemory;
import android.platform.test.annotations.Presubmit;
import android.view.DisplayAdjustments.FixedRotationAdjustments;
import android.view.DisplayCutout;
@@ -440,7 +441,8 @@ public class TransactionParcelTests {
                IUiAutomationConnection iUiAutomationConnection, int i, boolean b, boolean b1,
                boolean b2, boolean b3, Configuration configuration,
                CompatibilityInfo compatibilityInfo, Map map, Bundle bundle1, String s1,
                AutofillOptions ao, ContentCaptureOptions co, long[] disableCompatChanges)
                AutofillOptions ao, ContentCaptureOptions co, long[] disableCompatChanges,
                SharedMemory serializedSystemFontMap)
                throws RemoteException {
        }

+6 −1
Original line number Diff line number Diff line
@@ -81,6 +81,9 @@ public class Typeface {

    private static String TAG = "Typeface";

    /** @hide */
    public static final boolean ENABLE_LAZY_TYPEFACE_INITIALIZATION = false;

    private static final NativeAllocationRegistry sRegistry =
            NativeAllocationRegistry.createMalloced(
            Typeface.class.getClassLoader(), nativeGetReleaseFunc());
@@ -1329,8 +1332,10 @@ public class Typeface {
    }

    static {
        if (!ENABLE_LAZY_TYPEFACE_INITIALIZATION) {
            loadPreinstalledSystemFontMap();
        }
    }

    @Override
    public boolean equals(Object o) {
Loading