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

Commit 89215d23 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Make updatable font files readable by apps." into sc-dev am: 5974b291

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13424198

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ibc6d1ffe5f0e7999cf19c2cf573efe447051048d
parents c70fdcd6 5974b291
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.annotation.Nullable;
import android.graphics.fonts.FontManager;
import android.graphics.fonts.SystemFonts;
import android.os.FileUtils;
import android.system.ErrnoException;
import android.system.Os;
import android.text.FontConfig;
import android.util.Base64;
import android.util.Slog;
@@ -223,6 +225,14 @@ final class UpdatableFontDir {
                        FontManager.ERROR_CODE_FAILED_TO_WRITE_FONT_FILE,
                        "Failed to create font directory.");
            }
            try {
                // Make newDir executable so that apps can access font file inside newDir.
                Os.chmod(newDir.getAbsolutePath(), 0711);
            } catch (ErrnoException e) {
                throw new SystemFontException(
                        FontManager.ERROR_CODE_FAILED_TO_WRITE_FONT_FILE,
                        "Failed to change mode to 711", e);
            }
            boolean success = false;
            try {
                File tempNewFontFile = new File(newDir, "font.ttf");
@@ -262,6 +272,14 @@ final class UpdatableFontDir {
                            FontManager.ERROR_CODE_FAILED_TO_WRITE_FONT_FILE,
                            "Failed to move verified font file.");
                }
                try {
                    // Make the font file readable by apps.
                    Os.chmod(newFontFile.getAbsolutePath(), 0644);
                } catch (ErrnoException e) {
                    throw new SystemFontException(
                            FontManager.ERROR_CODE_FAILED_TO_WRITE_FONT_FILE,
                            "Failed to change mode to 711", e);
                }
                FontFileInfo fontFileInfo = validateFontFile(newFontFile);

                // Write config file.
+5 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.Context;
import android.graphics.fonts.FontManager;
import android.os.FileUtils;
import android.platform.test.annotations.Presubmit;
import android.system.Os;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
@@ -281,6 +282,10 @@ public final class UpdatableFontDirTest {
        installFontFile(dir, "test,1", GOOD_SIGNATURE);
        assertThat(dir.getFontFileMap()).containsKey("test.ttf");
        assertThat(parser.getRevision(dir.getFontFileMap().get("test.ttf"))).isEqualTo(1);
        File fontFile = dir.getFontFileMap().get("test.ttf");
        assertThat(Os.stat(fontFile.getAbsolutePath()).st_mode & 0777).isEqualTo(0644);
        File fontDir = fontFile.getParentFile();
        assertThat(Os.stat(fontDir.getAbsolutePath()).st_mode & 0777).isEqualTo(0711);
    }

    @Test