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

Commit 077c31c3 authored by Kohsuke Yatoh's avatar Kohsuke Yatoh
Browse files

Make updatable font files readable by apps.

Bug: 176939176
Test: atest FrameworksServicesTests:UpdatableFontDirTest
Change-Id: Idab19c2796cb9d4dbcfee89b110c97e89c5a6157
parent f6e8b35b
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