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

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

Support multi font update internally.

This CL make UpdatableFontDir support multi font update in transaction.
The public / shell API is TBD.

Bug: 179103383
Test: atest CtsGraphicsTestCases:FontManagerTest
Test: atest FrameworksServicesTests:PersistentSystemFontConfigTest
Test: atest FrameworksServicesTests:UpdatableFontDirTest
Test: atest UpdatableSystemFontTest
Change-Id: If9474a8ab81fe194b2d76080a4b066131fcd9e44
parent 944681ed
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -261,7 +261,7 @@ public class FontManager {
            @IntRange(from = 0) int baseVersion
    ) {
        try {
            return mIFontManager.updateFont(pfd, signature, baseVersion);
            return mIFontManager.updateFont(baseVersion, new FontUpdateRequest(pfd, signature));
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to call updateFont API", e);
            return RESULT_ERROR_REMOTE_EXCEPTION;
+1 −1
Original line number Diff line number Diff line
@@ -17,4 +17,4 @@
package android.graphics.fonts;

/** @hide */
parcelable SystemFontState;
 No newline at end of file
parcelable FontUpdateRequest;
 No newline at end of file
+78 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.graphics.fonts;

import android.annotation.NonNull;
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.Parcelable;

/**
 * Represents a font update request. Currently only font install request is supported.
 * @hide
 */
// TODO: Support font config update.
public final class FontUpdateRequest implements Parcelable {

    public static final Creator<FontUpdateRequest> CREATOR = new Creator<FontUpdateRequest>() {
        @Override
        public FontUpdateRequest createFromParcel(Parcel in) {
            return new FontUpdateRequest(in);
        }

        @Override
        public FontUpdateRequest[] newArray(int size) {
            return new FontUpdateRequest[size];
        }
    };

    @NonNull
    private final ParcelFileDescriptor mFd;
    @NonNull
    private final byte[] mSignature;

    public FontUpdateRequest(@NonNull ParcelFileDescriptor fd, @NonNull byte[] signature) {
        mFd = fd;
        mSignature = signature;
    }

    private FontUpdateRequest(Parcel in) {
        mFd = in.readParcelable(ParcelFileDescriptor.class.getClassLoader());
        mSignature = in.readBlob();
    }

    @NonNull
    public ParcelFileDescriptor getFd() {
        return mFd;
    }

    @NonNull
    public byte[] getSignature() {
        return mSignature;
    }

    @Override
    public int describeContents() {
        return Parcelable.CONTENTS_FILE_DESCRIPTOR;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(mFd, flags);
        dest.writeBlob(mSignature);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -17,8 +17,8 @@
package com.android.internal.graphics.fonts;

import android.os.ParcelFileDescriptor;
import android.graphics.fonts.FontUpdateRequest;
import android.text.FontConfig;
import android.graphics.fonts.SystemFontState;

/**
 * System private interface for talking with
@@ -28,5 +28,5 @@ import android.graphics.fonts.SystemFontState;
interface IFontManager {
    FontConfig getFontConfig();

    int updateFont(in ParcelFileDescriptor fd, in byte[] signature, int baseVersion);
    int updateFont(int baseVersion, in FontUpdateRequest request);
}
+9 −7
Original line number Diff line number Diff line
@@ -24,8 +24,8 @@ import android.graphics.Typeface;
import android.graphics.fonts.FontFamily;
import android.graphics.fonts.FontFileUtil;
import android.graphics.fonts.FontManager;
import android.graphics.fonts.FontUpdateRequest;
import android.graphics.fonts.SystemFonts;
import android.os.ParcelFileDescriptor;
import android.os.ResultReceiver;
import android.os.SharedMemory;
import android.os.ShellCallback;
@@ -54,6 +54,7 @@ import java.nio.NioUtils;
import java.nio.channels.FileChannel;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@@ -71,14 +72,15 @@ public final class FontManagerService extends IFontManager.Stub {
    }

    @Override
    public int updateFont(ParcelFileDescriptor fd, byte[] signature, int baseVersion) {
        Objects.requireNonNull(fd);
        Objects.requireNonNull(signature);
    public int updateFont(int baseVersion, @NonNull FontUpdateRequest request) {
        Objects.requireNonNull(request);
        Objects.requireNonNull(request.getFd());
        Objects.requireNonNull(request.getSignature());
        Preconditions.checkArgumentNonnegative(baseVersion);
        getContext().enforceCallingPermission(Manifest.permission.UPDATE_FONTS,
                "UPDATE_FONTS permission required.");
        try {
            installFontFile(fd.getFileDescriptor(), signature, baseVersion);
            update(baseVersion, Collections.singletonList(request));
            return FontManager.RESULT_SUCCESS;
        } catch (SystemFontException e) {
            Slog.e(TAG, "Failed to update font file", e);
@@ -249,7 +251,7 @@ public final class FontManagerService extends IFontManager.Stub {
        }
    }

    /* package */ void installFontFile(FileDescriptor fd, byte[] pkcs7Signature, int baseVersion)
    /* package */ void update(int baseVersion, List<FontUpdateRequest> requests)
            throws SystemFontException {
        if (mUpdatableFontDir == null) {
            throw new SystemFontException(
@@ -265,7 +267,7 @@ public final class FontManagerService extends IFontManager.Stub {
                        "The base config version is older than current.");
            }
            try (FontCrashDetector.MonitoredBlock ignored = mFontCrashDetector.start()) {
                mUpdatableFontDir.installFontFile(fd, pkcs7Signature);
                mUpdatableFontDir.update(requests);
                updateSerializedFontMap();
            }
        }
Loading