Merge "Make updatable font files readable by apps." into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
5974b291e9
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user