Merge "Use PostScript name as a key of updated font map" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
81eb3f6ddd
@@ -225,7 +225,14 @@ public class FontListParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
String sanitizedName = FILENAME_WHITESPACE_PATTERN.matcher(filename).replaceAll("");
|
String sanitizedName = FILENAME_WHITESPACE_PATTERN.matcher(filename).replaceAll("");
|
||||||
String updatedName = findUpdatedFontFile(sanitizedName, updatableFontMap);
|
|
||||||
|
if (postScriptName == null) {
|
||||||
|
// If post script name was not provided, assume the file name is same to PostScript
|
||||||
|
// name.
|
||||||
|
postScriptName = sanitizedName.substring(0, sanitizedName.length() - 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
String updatedName = findUpdatedFontFile(postScriptName, updatableFontMap);
|
||||||
String filePath;
|
String filePath;
|
||||||
String originalPath;
|
String originalPath;
|
||||||
if (updatedName != null) {
|
if (updatedName != null) {
|
||||||
@@ -246,12 +253,7 @@ public class FontListParser {
|
|||||||
|
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
|
|
||||||
if (postScriptName == null) {
|
|
||||||
// If post script name was not provided, assume the file name is same to PostScript
|
|
||||||
// name.
|
|
||||||
String name = file.getName();
|
|
||||||
postScriptName = name.substring(0, name.length() - 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new FontConfig.Font(file,
|
return new FontConfig.Font(file,
|
||||||
originalPath == null ? null : new File(originalPath),
|
originalPath == null ? null : new File(originalPath),
|
||||||
@@ -265,10 +267,10 @@ public class FontListParser {
|
|||||||
fallbackFor);
|
fallbackFor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String findUpdatedFontFile(String name,
|
private static String findUpdatedFontFile(String psName,
|
||||||
@Nullable Map<String, File> updatableFontMap) {
|
@Nullable Map<String, File> updatableFontMap) {
|
||||||
if (updatableFontMap != null) {
|
if (updatableFontMap != null) {
|
||||||
File updatedFile = updatableFontMap.get(name);
|
File updatedFile = updatableFontMap.get(psName);
|
||||||
if (updatedFile != null) {
|
if (updatedFile != null) {
|
||||||
return updatedFile.getAbsolutePath();
|
return updatedFile.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ import java.io.PrintWriter;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.NioUtils;
|
import java.nio.NioUtils;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -249,8 +248,6 @@ public final class FontManagerService extends IFontManager.Stub {
|
|||||||
// If apk verity is supported, fs-verity should be available.
|
// If apk verity is supported, fs-verity should be available.
|
||||||
if (!VerityUtils.isFsVeritySupported()) return null;
|
if (!VerityUtils.isFsVeritySupported()) return null;
|
||||||
return new UpdatableFontDir(new File(FONT_FILES_DIR),
|
return new UpdatableFontDir(new File(FONT_FILES_DIR),
|
||||||
Arrays.asList(new File(SystemFonts.SYSTEM_FONT_DIR),
|
|
||||||
new File(SystemFonts.OEM_FONT_DIR)),
|
|
||||||
new OtfFontFileParser(), new FsverityUtilImpl());
|
new OtfFontFileParser(), new FsverityUtilImpl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,7 +320,7 @@ public final class FontManagerService extends IFontManager.Stub {
|
|||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
synchronized (mUpdatableFontDirLock) {
|
synchronized (mUpdatableFontDirLock) {
|
||||||
return mUpdatableFontDir.getFontFileMap();
|
return mUpdatableFontDir.getPostScriptMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,12 +118,12 @@ final class UpdatableFontDir {
|
|||||||
* randomized dir. The font file path would be {@code mFilesDir/~~{randomStr}/{fontFileName}}.
|
* randomized dir. The font file path would be {@code mFilesDir/~~{randomStr}/{fontFileName}}.
|
||||||
*/
|
*/
|
||||||
private final File mFilesDir;
|
private final File mFilesDir;
|
||||||
private final List<File> mPreinstalledFontDirs;
|
|
||||||
private final FontFileParser mParser;
|
private final FontFileParser mParser;
|
||||||
private final FsverityUtil mFsverityUtil;
|
private final FsverityUtil mFsverityUtil;
|
||||||
private final File mConfigFile;
|
private final File mConfigFile;
|
||||||
private final File mTmpConfigFile;
|
private final File mTmpConfigFile;
|
||||||
private final Supplier<Long> mCurrentTimeSupplier;
|
private final Supplier<Long> mCurrentTimeSupplier;
|
||||||
|
private final Function<Map<String, File>, FontConfig> mConfigSupplier;
|
||||||
|
|
||||||
private long mLastModifiedMillis;
|
private long mLastModifiedMillis;
|
||||||
private int mConfigVersion;
|
private int mConfigVersion;
|
||||||
@@ -134,22 +135,24 @@ final class UpdatableFontDir {
|
|||||||
*/
|
*/
|
||||||
private final ArrayMap<String, FontFileInfo> mFontFileInfoMap = new ArrayMap<>();
|
private final ArrayMap<String, FontFileInfo> mFontFileInfoMap = new ArrayMap<>();
|
||||||
|
|
||||||
UpdatableFontDir(File filesDir, List<File> preinstalledFontDirs, FontFileParser parser,
|
UpdatableFontDir(File filesDir, FontFileParser parser, FsverityUtil fsverityUtil) {
|
||||||
FsverityUtil fsverityUtil) {
|
this(filesDir, parser, fsverityUtil, new File(CONFIG_XML_FILE),
|
||||||
this(filesDir, preinstalledFontDirs, parser, fsverityUtil, new File(CONFIG_XML_FILE),
|
() -> System.currentTimeMillis(),
|
||||||
() -> System.currentTimeMillis());
|
(map) -> SystemFonts.getSystemFontConfig(map, 0, 0)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For unit testing
|
// For unit testing
|
||||||
UpdatableFontDir(File filesDir, List<File> preinstalledFontDirs, FontFileParser parser,
|
UpdatableFontDir(File filesDir, FontFileParser parser, FsverityUtil fsverityUtil,
|
||||||
FsverityUtil fsverityUtil, File configFile, Supplier<Long> currentTimeSupplier) {
|
File configFile, Supplier<Long> currentTimeSupplier,
|
||||||
|
Function<Map<String, File>, FontConfig> configSupplier) {
|
||||||
mFilesDir = filesDir;
|
mFilesDir = filesDir;
|
||||||
mPreinstalledFontDirs = preinstalledFontDirs;
|
|
||||||
mParser = parser;
|
mParser = parser;
|
||||||
mFsverityUtil = fsverityUtil;
|
mFsverityUtil = fsverityUtil;
|
||||||
mConfigFile = configFile;
|
mConfigFile = configFile;
|
||||||
mTmpConfigFile = new File(configFile.getAbsoluteFile() + ".tmp");
|
mTmpConfigFile = new File(configFile.getAbsoluteFile() + ".tmp");
|
||||||
mCurrentTimeSupplier = currentTimeSupplier;
|
mCurrentTimeSupplier = currentTimeSupplier;
|
||||||
|
mConfigSupplier = configSupplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -174,6 +177,7 @@ final class UpdatableFontDir {
|
|||||||
|
|
||||||
File[] dirs = mFilesDir.listFiles();
|
File[] dirs = mFilesDir.listFiles();
|
||||||
if (dirs == null) return;
|
if (dirs == null) return;
|
||||||
|
FontConfig fontConfig = getSystemFontConfig();
|
||||||
for (File dir : dirs) {
|
for (File dir : dirs) {
|
||||||
if (!dir.getName().startsWith(RANDOM_DIR_PREFIX)) {
|
if (!dir.getName().startsWith(RANDOM_DIR_PREFIX)) {
|
||||||
Slog.e(TAG, "Unexpected dir found: " + dir);
|
Slog.e(TAG, "Unexpected dir found: " + dir);
|
||||||
@@ -190,7 +194,7 @@ final class UpdatableFontDir {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FontFileInfo fontFileInfo = validateFontFile(files[0]);
|
FontFileInfo fontFileInfo = validateFontFile(files[0]);
|
||||||
addFileToMapIfSameOrNewer(fontFileInfo, true /* deleteOldFile */);
|
addFileToMapIfSameOrNewer(fontFileInfo, fontConfig, true /* deleteOldFile */);
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
@@ -302,7 +306,7 @@ final class UpdatableFontDir {
|
|||||||
* Installs a new font file, or updates an existing font file.
|
* Installs a new font file, or updates an existing font file.
|
||||||
*
|
*
|
||||||
* <p>The new font will be immediately available for new Zygote-forked processes through
|
* <p>The new font will be immediately available for new Zygote-forked processes through
|
||||||
* {@link #getFontFileMap()}. Old font files will be kept until next system server reboot,
|
* {@link #getPostScriptMap()}. Old font files will be kept until next system server reboot,
|
||||||
* because existing Zygote-forked processes have paths to old font files.
|
* because existing Zygote-forked processes have paths to old font files.
|
||||||
*
|
*
|
||||||
* @param fd A file descriptor to the font file.
|
* @param fd A file descriptor to the font file.
|
||||||
@@ -373,7 +377,8 @@ final class UpdatableFontDir {
|
|||||||
"Failed to change mode to 711", e);
|
"Failed to change mode to 711", e);
|
||||||
}
|
}
|
||||||
FontFileInfo fontFileInfo = validateFontFile(newFontFile);
|
FontFileInfo fontFileInfo = validateFontFile(newFontFile);
|
||||||
if (!addFileToMapIfSameOrNewer(fontFileInfo, false)) {
|
FontConfig fontConfig = getSystemFontConfig();
|
||||||
|
if (!addFileToMapIfSameOrNewer(fontFileInfo, fontConfig, false)) {
|
||||||
throw new SystemFontException(
|
throw new SystemFontException(
|
||||||
FontManager.RESULT_ERROR_DOWNGRADING,
|
FontManager.RESULT_ERROR_DOWNGRADING,
|
||||||
"Downgrading font file is forbidden.");
|
"Downgrading font file is forbidden.");
|
||||||
@@ -417,14 +422,15 @@ final class UpdatableFontDir {
|
|||||||
* equal to or higher than the revision of currently used font file (either in
|
* equal to or higher than the revision of currently used font file (either in
|
||||||
* {@link #mFontFileInfoMap} or {@link #mPreinstalledFontDirs}).
|
* {@link #mFontFileInfoMap} or {@link #mPreinstalledFontDirs}).
|
||||||
*/
|
*/
|
||||||
private boolean addFileToMapIfSameOrNewer(FontFileInfo fontFileInfo, boolean deleteOldFile) {
|
private boolean addFileToMapIfSameOrNewer(FontFileInfo fontFileInfo, FontConfig fontConfig,
|
||||||
|
boolean deleteOldFile) {
|
||||||
FontFileInfo existingInfo = lookupFontFileInfo(fontFileInfo.getPostScriptName());
|
FontFileInfo existingInfo = lookupFontFileInfo(fontFileInfo.getPostScriptName());
|
||||||
final boolean shouldAddToMap;
|
final boolean shouldAddToMap;
|
||||||
if (existingInfo == null) {
|
if (existingInfo == null) {
|
||||||
// We got a new updatable font. We need to check if it's newer than preinstalled fonts.
|
// We got a new updatable font. We need to check if it's newer than preinstalled fonts.
|
||||||
// Note that getPreinstalledFontRevision() returns -1 if there is no preinstalled font
|
// Note that getPreinstalledFontRevision() returns -1 if there is no preinstalled font
|
||||||
// with 'name'.
|
// with 'name'.
|
||||||
long preInstalledRev = getPreinstalledFontRevision(fontFileInfo.getFile().getName());
|
long preInstalledRev = getPreinstalledFontRevision(fontFileInfo, fontConfig);
|
||||||
shouldAddToMap = preInstalledRev <= fontFileInfo.getRevision();
|
shouldAddToMap = preInstalledRev <= fontFileInfo.getRevision();
|
||||||
} else {
|
} else {
|
||||||
shouldAddToMap = existingInfo.getRevision() <= fontFileInfo.getRevision();
|
shouldAddToMap = existingInfo.getRevision() <= fontFileInfo.getRevision();
|
||||||
@@ -442,21 +448,33 @@ final class UpdatableFontDir {
|
|||||||
return shouldAddToMap;
|
return shouldAddToMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getPreinstalledFontRevision(String name) {
|
private long getPreinstalledFontRevision(FontFileInfo info, FontConfig fontConfig) {
|
||||||
long maxRevision = -1;
|
String psName = info.getPostScriptName();
|
||||||
for (File dir : mPreinstalledFontDirs) {
|
FontConfig.Font targetFont = null;
|
||||||
File preinstalledFontFile = new File(dir, name);
|
for (int i = 0; i < fontConfig.getFontFamilies().size(); i++) {
|
||||||
if (!preinstalledFontFile.exists()) continue;
|
FontConfig.FontFamily family = fontConfig.getFontFamilies().get(i);
|
||||||
long revision = getFontRevision(preinstalledFontFile);
|
for (int j = 0; j < family.getFontList().size(); ++j) {
|
||||||
if (revision == -1) {
|
FontConfig.Font font = family.getFontList().get(j);
|
||||||
Slog.w(TAG, "Invalid preinstalled font file");
|
if (font.getPostScriptName().equals(psName)) {
|
||||||
continue;
|
targetFont = font;
|
||||||
}
|
break;
|
||||||
if (revision > maxRevision) {
|
}
|
||||||
maxRevision = revision;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return maxRevision;
|
if (targetFont == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
File preinstalledFontFile = targetFont.getOriginalFile() != null
|
||||||
|
? targetFont.getOriginalFile() : targetFont.getFile();
|
||||||
|
if (!preinstalledFontFile.exists()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
long revision = getFontRevision(preinstalledFontFile);
|
||||||
|
if (revision == -1) {
|
||||||
|
Slog.w(TAG, "Invalid preinstalled font file");
|
||||||
|
}
|
||||||
|
return revision;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -515,17 +533,17 @@ final class UpdatableFontDir {
|
|||||||
null, FontConfig.FontFamily.VARIANT_DEFAULT);
|
null, FontConfig.FontFamily.VARIANT_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, File> getFontFileMap() {
|
Map<String, File> getPostScriptMap() {
|
||||||
Map<String, File> map = new ArrayMap<>();
|
Map<String, File> map = new ArrayMap<>();
|
||||||
for (int i = 0; i < mFontFileInfoMap.size(); ++i) {
|
for (int i = 0; i < mFontFileInfoMap.size(); ++i) {
|
||||||
File file = mFontFileInfoMap.valueAt(i).getFile();
|
FontFileInfo info = mFontFileInfoMap.valueAt(i);
|
||||||
map.put(file.getName(), file);
|
map.put(info.getPostScriptName(), info.getFile());
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ FontConfig getSystemFontConfig() {
|
/* package */ FontConfig getSystemFontConfig() {
|
||||||
FontConfig config = SystemFonts.getSystemFontConfig(getFontFileMap(), 0, 0);
|
FontConfig config = mConfigSupplier.apply(getPostScriptMap());
|
||||||
PersistentSystemFontConfig.Config persistentConfig = readPersistentConfig();
|
PersistentSystemFontConfig.Config persistentConfig = readPersistentConfig();
|
||||||
List<FontUpdateRequest.Family> families = persistentConfig.fontFamilies;
|
List<FontUpdateRequest.Family> families = persistentConfig.fontFamilies;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ import static org.junit.Assert.fail;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.FontListParser;
|
import android.graphics.FontListParser;
|
||||||
import android.graphics.fonts.FontManager;
|
import android.graphics.fonts.FontManager;
|
||||||
|
import android.graphics.fonts.FontStyle;
|
||||||
import android.graphics.fonts.FontUpdateRequest;
|
import android.graphics.fonts.FontUpdateRequest;
|
||||||
|
import android.graphics.fonts.SystemFonts;
|
||||||
import android.os.FileUtils;
|
import android.os.FileUtils;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.platform.test.annotations.Presubmit;
|
import android.platform.test.annotations.Presubmit;
|
||||||
@@ -56,6 +58,7 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -73,8 +76,7 @@ public final class UpdatableFontDirTest {
|
|||||||
@Override
|
@Override
|
||||||
public String getPostScriptName(File file) throws IOException {
|
public String getPostScriptName(File file) throws IOException {
|
||||||
String content = FileUtils.readTextFile(file, 100, "");
|
String content = FileUtils.readTextFile(file, 100, "");
|
||||||
String filename = content.split(",")[0];
|
return content.split(",")[2];
|
||||||
return filename.substring(0, filename.length() - 4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -86,7 +88,6 @@ public final class UpdatableFontDirTest {
|
|||||||
@Override
|
@Override
|
||||||
public long getRevision(File file) throws IOException {
|
public long getRevision(File file) throws IOException {
|
||||||
String content = FileUtils.readTextFile(file, 100, "");
|
String content = FileUtils.readTextFile(file, 100, "");
|
||||||
android.util.Log.e("Debug", "content: " + content);
|
|
||||||
return Long.parseLong(content.split(",")[1]);
|
return Long.parseLong(content.split(",")[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,6 +136,8 @@ public final class UpdatableFontDirTest {
|
|||||||
private File mConfigFile;
|
private File mConfigFile;
|
||||||
private List<File> mPreinstalledFontDirs;
|
private List<File> mPreinstalledFontDirs;
|
||||||
private Supplier<Long> mCurrentTimeSupplier = () -> CURRENT_TIME;
|
private Supplier<Long> mCurrentTimeSupplier = () -> CURRENT_TIME;
|
||||||
|
private Function<Map<String, File>, FontConfig> mConfigSupplier =
|
||||||
|
(map) -> SystemFonts.getSystemFontConfig(map, 0, 0);
|
||||||
|
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
@Before
|
@Before
|
||||||
@@ -168,16 +171,16 @@ public final class UpdatableFontDirTest {
|
|||||||
config.lastModifiedMillis = expectedModifiedDate;
|
config.lastModifiedMillis = expectedModifiedDate;
|
||||||
writeConfig(config, mConfigFile);
|
writeConfig(config, mConfigFile);
|
||||||
UpdatableFontDir dirForPreparation = new UpdatableFontDir(
|
UpdatableFontDir dirForPreparation = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dirForPreparation.loadFontFileMap();
|
dirForPreparation.loadFontFileMap();
|
||||||
assertThat(dirForPreparation.getSystemFontConfig().getLastModifiedTimeMillis())
|
assertThat(dirForPreparation.getSystemFontConfig().getLastModifiedTimeMillis())
|
||||||
.isEqualTo(expectedModifiedDate);
|
.isEqualTo(expectedModifiedDate);
|
||||||
dirForPreparation.update(Arrays.asList(
|
dirForPreparation.update(Arrays.asList(
|
||||||
newFontUpdateRequest("foo.ttf,1", GOOD_SIGNATURE),
|
newFontUpdateRequest("foo.ttf,1,foo", GOOD_SIGNATURE),
|
||||||
newFontUpdateRequest("bar.ttf,2", GOOD_SIGNATURE),
|
newFontUpdateRequest("bar.ttf,2,bar", GOOD_SIGNATURE),
|
||||||
newFontUpdateRequest("foo.ttf,3", GOOD_SIGNATURE),
|
newFontUpdateRequest("foo.ttf,3,foo", GOOD_SIGNATURE),
|
||||||
newFontUpdateRequest("bar.ttf,4", GOOD_SIGNATURE),
|
newFontUpdateRequest("bar.ttf,4,bar", GOOD_SIGNATURE),
|
||||||
newAddFontFamilyRequest("<family name='foobar'>"
|
newAddFontFamilyRequest("<family name='foobar'>"
|
||||||
+ " <font>foo.ttf</font>"
|
+ " <font>foo.ttf</font>"
|
||||||
+ " <font>bar.ttf</font>"
|
+ " <font>bar.ttf</font>"
|
||||||
@@ -191,13 +194,13 @@ public final class UpdatableFontDirTest {
|
|||||||
.isNotEqualTo(expectedModifiedDate);
|
.isNotEqualTo(expectedModifiedDate);
|
||||||
|
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
assertThat(dir.getFontFileMap()).containsKey("foo.ttf");
|
assertThat(dir.getPostScriptMap()).containsKey("foo");
|
||||||
assertThat(parser.getRevision(dir.getFontFileMap().get("foo.ttf"))).isEqualTo(3);
|
assertThat(parser.getRevision(dir.getPostScriptMap().get("foo"))).isEqualTo(3);
|
||||||
assertThat(dir.getFontFileMap()).containsKey("bar.ttf");
|
assertThat(dir.getPostScriptMap()).containsKey("bar");
|
||||||
assertThat(parser.getRevision(dir.getFontFileMap().get("bar.ttf"))).isEqualTo(4);
|
assertThat(parser.getRevision(dir.getPostScriptMap().get("bar"))).isEqualTo(4);
|
||||||
// Outdated font dir should be deleted.
|
// Outdated font dir should be deleted.
|
||||||
assertThat(mUpdatableFontFilesDir.list()).hasLength(2);
|
assertThat(mUpdatableFontFilesDir.list()).hasLength(2);
|
||||||
assertNamedFamilyExists(dir.getSystemFontConfig(), "foobar");
|
assertNamedFamilyExists(dir.getSystemFontConfig(), "foobar");
|
||||||
@@ -205,9 +208,9 @@ public final class UpdatableFontDirTest {
|
|||||||
FontConfig.FontFamily foobar = dir.getFontFamilyMap().get("foobar");
|
FontConfig.FontFamily foobar = dir.getFontFamilyMap().get("foobar");
|
||||||
assertThat(foobar.getFontList()).hasSize(2);
|
assertThat(foobar.getFontList()).hasSize(2);
|
||||||
assertThat(foobar.getFontList().get(0).getFile())
|
assertThat(foobar.getFontList().get(0).getFile())
|
||||||
.isEqualTo(dir.getFontFileMap().get("foo.ttf"));
|
.isEqualTo(dir.getPostScriptMap().get("foo"));
|
||||||
assertThat(foobar.getFontList().get(1).getFile())
|
assertThat(foobar.getFontList().get(1).getFile())
|
||||||
.isEqualTo(dir.getFontFileMap().get("bar.ttf"));
|
.isEqualTo(dir.getPostScriptMap().get("bar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -215,10 +218,10 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
assertThat(dir.getFontFileMap()).isEmpty();
|
assertThat(dir.getPostScriptMap()).isEmpty();
|
||||||
assertThat(dir.getFontFamilyMap()).isEmpty();
|
assertThat(dir.getFontFamilyMap()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,14 +230,14 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dirForPreparation = new UpdatableFontDir(
|
UpdatableFontDir dirForPreparation = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dirForPreparation.loadFontFileMap();
|
dirForPreparation.loadFontFileMap();
|
||||||
dirForPreparation.update(Arrays.asList(
|
dirForPreparation.update(Arrays.asList(
|
||||||
newFontUpdateRequest("foo.ttf,1", GOOD_SIGNATURE),
|
newFontUpdateRequest("foo.ttf,1,foo", GOOD_SIGNATURE),
|
||||||
newFontUpdateRequest("bar.ttf,2", GOOD_SIGNATURE),
|
newFontUpdateRequest("bar.ttf,2,bar", GOOD_SIGNATURE),
|
||||||
newFontUpdateRequest("foo.ttf,3", GOOD_SIGNATURE),
|
newFontUpdateRequest("foo.ttf,3,foo", GOOD_SIGNATURE),
|
||||||
newFontUpdateRequest("bar.ttf,4", GOOD_SIGNATURE),
|
newFontUpdateRequest("bar.ttf,4,bar", GOOD_SIGNATURE),
|
||||||
newAddFontFamilyRequest("<family name='foobar'>"
|
newAddFontFamilyRequest("<family name='foobar'>"
|
||||||
+ " <font>foo.ttf</font>"
|
+ " <font>foo.ttf</font>"
|
||||||
+ " <font>bar.ttf</font>"
|
+ " <font>bar.ttf</font>"
|
||||||
@@ -243,12 +246,12 @@ public final class UpdatableFontDirTest {
|
|||||||
assertThat(mUpdatableFontFilesDir.list()).hasLength(4);
|
assertThat(mUpdatableFontFilesDir.list()).hasLength(4);
|
||||||
|
|
||||||
fakeFsverityUtil.remove(
|
fakeFsverityUtil.remove(
|
||||||
dirForPreparation.getFontFileMap().get("foo.ttf").getAbsolutePath());
|
dirForPreparation.getPostScriptMap().get("foo").getAbsolutePath());
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
assertThat(dir.getFontFileMap()).isEmpty();
|
assertThat(dir.getPostScriptMap()).isEmpty();
|
||||||
// All font dirs (including dir for "bar.ttf") should be deleted.
|
// All font dirs (including dir for "bar.ttf") should be deleted.
|
||||||
assertThat(mUpdatableFontFilesDir.list()).hasLength(0);
|
assertThat(mUpdatableFontFilesDir.list()).hasLength(0);
|
||||||
assertThat(dir.getFontFamilyMap()).isEmpty();
|
assertThat(dir.getFontFamilyMap()).isEmpty();
|
||||||
@@ -259,14 +262,14 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dirForPreparation = new UpdatableFontDir(
|
UpdatableFontDir dirForPreparation = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dirForPreparation.loadFontFileMap();
|
dirForPreparation.loadFontFileMap();
|
||||||
dirForPreparation.update(Arrays.asList(
|
dirForPreparation.update(Arrays.asList(
|
||||||
newFontUpdateRequest("foo.ttf,1", GOOD_SIGNATURE),
|
newFontUpdateRequest("foo.ttf,1,foo", GOOD_SIGNATURE),
|
||||||
newFontUpdateRequest("bar.ttf,2", GOOD_SIGNATURE),
|
newFontUpdateRequest("bar.ttf,2,bar", GOOD_SIGNATURE),
|
||||||
newFontUpdateRequest("foo.ttf,3", GOOD_SIGNATURE),
|
newFontUpdateRequest("foo.ttf,3,foo", GOOD_SIGNATURE),
|
||||||
newFontUpdateRequest("bar.ttf,4", GOOD_SIGNATURE),
|
newFontUpdateRequest("bar.ttf,4,bar", GOOD_SIGNATURE),
|
||||||
newAddFontFamilyRequest("<family name='foobar'>"
|
newAddFontFamilyRequest("<family name='foobar'>"
|
||||||
+ " <font>foo.ttf</font>"
|
+ " <font>foo.ttf</font>"
|
||||||
+ " <font>bar.ttf</font>"
|
+ " <font>bar.ttf</font>"
|
||||||
@@ -275,13 +278,13 @@ public final class UpdatableFontDirTest {
|
|||||||
assertThat(mUpdatableFontFilesDir.list()).hasLength(4);
|
assertThat(mUpdatableFontFilesDir.list()).hasLength(4);
|
||||||
|
|
||||||
// Overwrite "foo.ttf" with wrong contents.
|
// Overwrite "foo.ttf" with wrong contents.
|
||||||
FileUtils.stringToFile(dirForPreparation.getFontFileMap().get("foo.ttf"), "bar,4");
|
FileUtils.stringToFile(dirForPreparation.getPostScriptMap().get("foo"), "bar,4");
|
||||||
|
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
assertThat(dir.getFontFileMap()).isEmpty();
|
assertThat(dir.getPostScriptMap()).isEmpty();
|
||||||
// All font dirs (including dir for "bar.ttf") should be deleted.
|
// All font dirs (including dir for "bar.ttf") should be deleted.
|
||||||
assertThat(mUpdatableFontFilesDir.list()).hasLength(0);
|
assertThat(mUpdatableFontFilesDir.list()).hasLength(0);
|
||||||
assertThat(dir.getFontFamilyMap()).isEmpty();
|
assertThat(dir.getFontFamilyMap()).isEmpty();
|
||||||
@@ -291,15 +294,30 @@ public final class UpdatableFontDirTest {
|
|||||||
public void construct_olderThanPreinstalledFont() throws Exception {
|
public void construct_olderThanPreinstalledFont() throws Exception {
|
||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
|
Function<Map<String, File>, FontConfig> configSupplier = (map) -> {
|
||||||
|
FontConfig.Font fooFont = new FontConfig.Font(
|
||||||
|
new File(mPreinstalledFontDirs.get(0), "foo.ttf"), null, "foo",
|
||||||
|
new FontStyle(400, FontStyle.FONT_SLANT_UPRIGHT), 0, null, null);
|
||||||
|
FontConfig.Font barFont = new FontConfig.Font(
|
||||||
|
new File(mPreinstalledFontDirs.get(1), "bar.ttf"), null, "bar",
|
||||||
|
new FontStyle(400, FontStyle.FONT_SLANT_UPRIGHT), 0, null, null);
|
||||||
|
|
||||||
|
FontConfig.FontFamily family = new FontConfig.FontFamily(
|
||||||
|
Arrays.asList(fooFont, barFont), "sans-serif", null,
|
||||||
|
FontConfig.FontFamily.VARIANT_DEFAULT);
|
||||||
|
return new FontConfig(Collections.singletonList(family),
|
||||||
|
Collections.emptyList(), 0, 1);
|
||||||
|
};
|
||||||
|
|
||||||
UpdatableFontDir dirForPreparation = new UpdatableFontDir(
|
UpdatableFontDir dirForPreparation = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, configSupplier);
|
||||||
dirForPreparation.loadFontFileMap();
|
dirForPreparation.loadFontFileMap();
|
||||||
dirForPreparation.update(Arrays.asList(
|
dirForPreparation.update(Arrays.asList(
|
||||||
newFontUpdateRequest("foo.ttf,1", GOOD_SIGNATURE),
|
newFontUpdateRequest("foo.ttf,1,foo", GOOD_SIGNATURE),
|
||||||
newFontUpdateRequest("bar.ttf,2", GOOD_SIGNATURE),
|
newFontUpdateRequest("bar.ttf,2,bar", GOOD_SIGNATURE),
|
||||||
newFontUpdateRequest("foo.ttf,3", GOOD_SIGNATURE),
|
newFontUpdateRequest("foo.ttf,3,foo", GOOD_SIGNATURE),
|
||||||
newFontUpdateRequest("bar.ttf,4", GOOD_SIGNATURE),
|
newFontUpdateRequest("bar.ttf,4,bar", GOOD_SIGNATURE),
|
||||||
newAddFontFamilyRequest("<family name='foobar'>"
|
newAddFontFamilyRequest("<family name='foobar'>"
|
||||||
+ " <font>foo.ttf</font>"
|
+ " <font>foo.ttf</font>"
|
||||||
+ " <font>bar.ttf</font>"
|
+ " <font>bar.ttf</font>"
|
||||||
@@ -308,18 +326,18 @@ public final class UpdatableFontDirTest {
|
|||||||
assertThat(mUpdatableFontFilesDir.list()).hasLength(4);
|
assertThat(mUpdatableFontFilesDir.list()).hasLength(4);
|
||||||
|
|
||||||
// Add preinstalled fonts.
|
// Add preinstalled fonts.
|
||||||
FileUtils.stringToFile(new File(mPreinstalledFontDirs.get(0), "foo.ttf"), "foo,5");
|
FileUtils.stringToFile(new File(mPreinstalledFontDirs.get(0), "foo.ttf"), "foo,5,foo");
|
||||||
FileUtils.stringToFile(new File(mPreinstalledFontDirs.get(0), "bar.ttf"), "bar,1");
|
FileUtils.stringToFile(new File(mPreinstalledFontDirs.get(1), "bar.ttf"), "bar,1,bar");
|
||||||
FileUtils.stringToFile(new File(mPreinstalledFontDirs.get(1), "bar.ttf"), "bar,2");
|
FileUtils.stringToFile(new File(mPreinstalledFontDirs.get(1), "bar.ttf"), "bar,2,bar");
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, configSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
// For foo.ttf, preinstalled font (revision 5) should be used.
|
// For foo.ttf, preinstalled font (revision 5) should be used.
|
||||||
assertThat(dir.getFontFileMap()).doesNotContainKey("foo.ttf");
|
assertThat(dir.getPostScriptMap()).doesNotContainKey("foo");
|
||||||
// For bar.ttf, updated font (revision 4) should be used.
|
// For bar.ttf, updated font (revision 4) should be used.
|
||||||
assertThat(dir.getFontFileMap()).containsKey("bar.ttf");
|
assertThat(dir.getPostScriptMap()).containsKey("bar");
|
||||||
assertThat(parser.getRevision(dir.getFontFileMap().get("bar.ttf"))).isEqualTo(4);
|
assertThat(parser.getRevision(dir.getPostScriptMap().get("bar"))).isEqualTo(4);
|
||||||
// Outdated font dir should be deleted.
|
// Outdated font dir should be deleted.
|
||||||
// We don't delete bar.ttf in this case, because it's normal that OTA updates preinstalled
|
// We don't delete bar.ttf in this case, because it's normal that OTA updates preinstalled
|
||||||
// fonts.
|
// fonts.
|
||||||
@@ -333,10 +351,10 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
new File("/dev/null"), mCurrentTimeSupplier);
|
new File("/dev/null"), mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
assertThat(dir.getFontFileMap()).isEmpty();
|
assertThat(dir.getPostScriptMap()).isEmpty();
|
||||||
assertThat(dir.getFontFamilyMap()).isEmpty();
|
assertThat(dir.getFontFamilyMap()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,18 +363,18 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dirForPreparation = new UpdatableFontDir(
|
UpdatableFontDir dirForPreparation = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dirForPreparation.loadFontFileMap();
|
dirForPreparation.loadFontFileMap();
|
||||||
dirForPreparation.update(Arrays.asList(
|
dirForPreparation.update(Arrays.asList(
|
||||||
newFontUpdateRequest("foo.ttf,1", GOOD_SIGNATURE),
|
newFontUpdateRequest("foo.ttf,1,foo", GOOD_SIGNATURE),
|
||||||
newAddFontFamilyRequest("<family name='foobar'>"
|
newAddFontFamilyRequest("<family name='foobar'>"
|
||||||
+ " <font>foo.ttf</font>"
|
+ " <font>foo.ttf</font>"
|
||||||
+ "</family>")));
|
+ "</family>")));
|
||||||
try {
|
try {
|
||||||
dirForPreparation.update(Arrays.asList(
|
dirForPreparation.update(Arrays.asList(
|
||||||
newFontUpdateRequest("foo.ttf,2", GOOD_SIGNATURE),
|
newFontUpdateRequest("foo.ttf,2,foo", GOOD_SIGNATURE),
|
||||||
newFontUpdateRequest("bar.ttf,2", "Invalid signature"),
|
newFontUpdateRequest("bar.ttf,2,bar", "Invalid signature"),
|
||||||
newAddFontFamilyRequest("<family name='foobar'>"
|
newAddFontFamilyRequest("<family name='foobar'>"
|
||||||
+ " <font>foo.ttf</font>"
|
+ " <font>foo.ttf</font>"
|
||||||
+ " <font>bar.ttf</font>"
|
+ " <font>bar.ttf</font>"
|
||||||
@@ -367,17 +385,17 @@ public final class UpdatableFontDirTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
// The state should be rolled back as a whole if one of the update requests fail.
|
// The state should be rolled back as a whole if one of the update requests fail.
|
||||||
assertThat(dir.getFontFileMap()).containsKey("foo.ttf");
|
assertThat(dir.getPostScriptMap()).containsKey("foo");
|
||||||
assertThat(parser.getRevision(dir.getFontFileMap().get("foo.ttf"))).isEqualTo(1);
|
assertThat(parser.getRevision(dir.getPostScriptMap().get("foo"))).isEqualTo(1);
|
||||||
assertThat(dir.getFontFamilyMap()).containsKey("foobar");
|
assertThat(dir.getFontFamilyMap()).containsKey("foobar");
|
||||||
FontConfig.FontFamily foobar = dir.getFontFamilyMap().get("foobar");
|
FontConfig.FontFamily foobar = dir.getFontFamilyMap().get("foobar");
|
||||||
assertThat(foobar.getFontList()).hasSize(1);
|
assertThat(foobar.getFontList()).hasSize(1);
|
||||||
assertThat(foobar.getFontList().get(0).getFile())
|
assertThat(foobar.getFontList().get(0).getFile())
|
||||||
.isEqualTo(dir.getFontFileMap().get("foo.ttf"));
|
.isEqualTo(dir.getPostScriptMap().get("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -385,14 +403,15 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1", GOOD_SIGNATURE)));
|
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1,test",
|
||||||
assertThat(dir.getFontFileMap()).containsKey("test.ttf");
|
GOOD_SIGNATURE)));
|
||||||
File fontFile = dir.getFontFileMap().get("test.ttf");
|
assertThat(dir.getPostScriptMap()).containsKey("test");
|
||||||
|
File fontFile = dir.getPostScriptMap().get("test");
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
assertThat(dir.getFontFileMap().get("test.ttf")).isEqualTo(fontFile);
|
assertThat(dir.getPostScriptMap().get("test")).isEqualTo(fontFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -400,14 +419,15 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1", GOOD_SIGNATURE)));
|
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1,test",
|
||||||
assertThat(dir.getFontFileMap()).containsKey("test.ttf");
|
GOOD_SIGNATURE)));
|
||||||
assertThat(parser.getRevision(dir.getFontFileMap().get("test.ttf"))).isEqualTo(1);
|
assertThat(dir.getPostScriptMap()).containsKey("test");
|
||||||
File fontFile = dir.getFontFileMap().get("test.ttf");
|
assertThat(parser.getRevision(dir.getPostScriptMap().get("test"))).isEqualTo(1);
|
||||||
|
File fontFile = dir.getPostScriptMap().get("test");
|
||||||
assertThat(Os.stat(fontFile.getAbsolutePath()).st_mode & 0777).isEqualTo(0644);
|
assertThat(Os.stat(fontFile.getAbsolutePath()).st_mode & 0777).isEqualTo(0644);
|
||||||
File fontDir = fontFile.getParentFile();
|
File fontDir = fontFile.getParentFile();
|
||||||
assertThat(Os.stat(fontDir.getAbsolutePath()).st_mode & 0777).isEqualTo(0711);
|
assertThat(Os.stat(fontDir.getAbsolutePath()).st_mode & 0777).isEqualTo(0711);
|
||||||
@@ -418,22 +438,58 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1", GOOD_SIGNATURE)));
|
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1,test",
|
||||||
Map<String, File> mapBeforeUpgrade = dir.getFontFileMap();
|
GOOD_SIGNATURE)));
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,2", GOOD_SIGNATURE)));
|
Map<String, File> mapBeforeUpgrade = dir.getPostScriptMap();
|
||||||
assertThat(dir.getFontFileMap()).containsKey("test.ttf");
|
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,2,test",
|
||||||
assertThat(parser.getRevision(dir.getFontFileMap().get("test.ttf"))).isEqualTo(2);
|
GOOD_SIGNATURE)));
|
||||||
assertThat(mapBeforeUpgrade).containsKey("test.ttf");
|
assertThat(dir.getPostScriptMap()).containsKey("test");
|
||||||
|
assertThat(parser.getRevision(dir.getPostScriptMap().get("test"))).isEqualTo(2);
|
||||||
|
assertThat(mapBeforeUpgrade).containsKey("test");
|
||||||
assertWithMessage("Older fonts should not be deleted until next loadFontFileMap")
|
assertWithMessage("Older fonts should not be deleted until next loadFontFileMap")
|
||||||
.that(parser.getRevision(mapBeforeUpgrade.get("test.ttf"))).isEqualTo(1);
|
.that(parser.getRevision(mapBeforeUpgrade.get("test"))).isEqualTo(1);
|
||||||
// Check that updatedFontDirs is pruned.
|
// Check that updatedFontDirs is pruned.
|
||||||
assertWithMessage("config.updatedFontDirs should only list latest active dirs")
|
assertWithMessage("config.updatedFontDirs should only list latest active dirs")
|
||||||
.that(readConfig(mConfigFile).updatedFontDirs)
|
.that(readConfig(mConfigFile).updatedFontDirs)
|
||||||
.containsExactly(dir.getFontFileMap().get("test.ttf").getParentFile().getName());
|
.containsExactly(dir.getPostScriptMap().get("test").getParentFile().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void installFontFile_systemFontHasPSNameDifferentFromFileName() throws Exception {
|
||||||
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
|
|
||||||
|
// Setup the environment that the system installed font file named "foo.ttf" has PostScript
|
||||||
|
// name "bar".
|
||||||
|
File file = new File(mPreinstalledFontDirs.get(0), "foo.ttf");
|
||||||
|
FileUtils.stringToFile(file, "foo.ttf,1,bar");
|
||||||
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
|
mConfigFile, mCurrentTimeSupplier, (map) -> {
|
||||||
|
FontConfig.Font font = new FontConfig.Font(
|
||||||
|
file, null, "bar", new FontStyle(400, FontStyle.FONT_SLANT_UPRIGHT),
|
||||||
|
0, null, null);
|
||||||
|
FontConfig.FontFamily family = new FontConfig.FontFamily(
|
||||||
|
Collections.singletonList(font), "sans-serif", null,
|
||||||
|
FontConfig.FontFamily.VARIANT_DEFAULT);
|
||||||
|
return new FontConfig(Collections.singletonList(family),
|
||||||
|
Collections.emptyList(), 0, 1);
|
||||||
|
});
|
||||||
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
|
dir.update(Collections.singletonList(newFontUpdateRequest("bar.ttf,2,bar",
|
||||||
|
GOOD_SIGNATURE)));
|
||||||
|
assertThat(dir.getPostScriptMap()).containsKey("bar");
|
||||||
|
assertThat(dir.getPostScriptMap().size()).isEqualTo(1);
|
||||||
|
assertThat(parser.getRevision(dir.getPostScriptMap().get("bar"))).isEqualTo(2);
|
||||||
|
File fontFile = dir.getPostScriptMap().get("bar");
|
||||||
|
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
|
@Test
|
||||||
@@ -441,14 +497,16 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1", GOOD_SIGNATURE)));
|
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1,test",
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1", GOOD_SIGNATURE)));
|
GOOD_SIGNATURE)));
|
||||||
assertThat(dir.getFontFileMap()).containsKey("test.ttf");
|
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1,test",
|
||||||
assertThat(parser.getRevision(dir.getFontFileMap().get("test.ttf"))).isEqualTo(1);
|
GOOD_SIGNATURE)));
|
||||||
|
assertThat(dir.getPostScriptMap()).containsKey("test");
|
||||||
|
assertThat(parser.getRevision(dir.getPostScriptMap().get("test"))).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -456,25 +514,26 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,2", GOOD_SIGNATURE)));
|
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,2,test",
|
||||||
|
GOOD_SIGNATURE)));
|
||||||
try {
|
try {
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1",
|
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1,test",
|
||||||
GOOD_SIGNATURE)));
|
GOOD_SIGNATURE)));
|
||||||
fail("Expect SystemFontException");
|
fail("Expect SystemFontException");
|
||||||
} catch (FontManagerService.SystemFontException e) {
|
} catch (FontManagerService.SystemFontException e) {
|
||||||
assertThat(e.getErrorCode()).isEqualTo(FontManager.RESULT_ERROR_DOWNGRADING);
|
assertThat(e.getErrorCode()).isEqualTo(FontManager.RESULT_ERROR_DOWNGRADING);
|
||||||
}
|
}
|
||||||
assertThat(dir.getFontFileMap()).containsKey("test.ttf");
|
assertThat(dir.getPostScriptMap()).containsKey("test");
|
||||||
assertWithMessage("Font should not be downgraded to an older revision")
|
assertWithMessage("Font should not be downgraded to an older revision")
|
||||||
.that(parser.getRevision(dir.getFontFileMap().get("test.ttf"))).isEqualTo(2);
|
.that(parser.getRevision(dir.getPostScriptMap().get("test"))).isEqualTo(2);
|
||||||
// Check that updatedFontDirs is not updated.
|
// Check that updatedFontDirs is not updated.
|
||||||
assertWithMessage("config.updatedFontDirs should only list latest active dirs")
|
assertWithMessage("config.updatedFontDirs should only list latest active dirs")
|
||||||
.that(readConfig(mConfigFile).updatedFontDirs)
|
.that(readConfig(mConfigFile).updatedFontDirs)
|
||||||
.containsExactly(dir.getFontFileMap().get("test.ttf").getParentFile().getName());
|
.containsExactly(dir.getPostScriptMap().get("test").getParentFile().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -482,16 +541,18 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("foo.ttf,1", GOOD_SIGNATURE)));
|
dir.update(Collections.singletonList(newFontUpdateRequest("foo.ttf,1,foo",
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("bar.ttf,2", GOOD_SIGNATURE)));
|
GOOD_SIGNATURE)));
|
||||||
assertThat(dir.getFontFileMap()).containsKey("foo.ttf");
|
dir.update(Collections.singletonList(newFontUpdateRequest("bar.ttf,2,bar",
|
||||||
assertThat(parser.getRevision(dir.getFontFileMap().get("foo.ttf"))).isEqualTo(1);
|
GOOD_SIGNATURE)));
|
||||||
assertThat(dir.getFontFileMap()).containsKey("bar.ttf");
|
assertThat(dir.getPostScriptMap()).containsKey("foo");
|
||||||
assertThat(parser.getRevision(dir.getFontFileMap().get("bar.ttf"))).isEqualTo(2);
|
assertThat(parser.getRevision(dir.getPostScriptMap().get("foo"))).isEqualTo(1);
|
||||||
|
assertThat(dir.getPostScriptMap()).containsKey("bar");
|
||||||
|
assertThat(parser.getRevision(dir.getPostScriptMap().get("bar"))).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -499,17 +560,17 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
dir.update(Arrays.asList(
|
dir.update(Arrays.asList(
|
||||||
newFontUpdateRequest("foo.ttf,1", GOOD_SIGNATURE),
|
newFontUpdateRequest("foo.ttf,1,foo", GOOD_SIGNATURE),
|
||||||
newFontUpdateRequest("bar.ttf,2", GOOD_SIGNATURE)));
|
newFontUpdateRequest("bar.ttf,2,bar", GOOD_SIGNATURE)));
|
||||||
assertThat(dir.getFontFileMap()).containsKey("foo.ttf");
|
assertThat(dir.getPostScriptMap()).containsKey("foo");
|
||||||
assertThat(parser.getRevision(dir.getFontFileMap().get("foo.ttf"))).isEqualTo(1);
|
assertThat(parser.getRevision(dir.getPostScriptMap().get("foo"))).isEqualTo(1);
|
||||||
assertThat(dir.getFontFileMap()).containsKey("bar.ttf");
|
assertThat(dir.getPostScriptMap()).containsKey("bar");
|
||||||
assertThat(parser.getRevision(dir.getFontFileMap().get("bar.ttf"))).isEqualTo(2);
|
assertThat(parser.getRevision(dir.getPostScriptMap().get("bar"))).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -517,70 +578,83 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dir.update(
|
dir.update(
|
||||||
Collections.singletonList(newFontUpdateRequest("test.ttf,1",
|
Collections.singletonList(newFontUpdateRequest("test.ttf,1,test",
|
||||||
"Invalid signature")));
|
"Invalid signature")));
|
||||||
fail("Expect SystemFontException");
|
fail("Expect SystemFontException");
|
||||||
} catch (FontManagerService.SystemFontException e) {
|
} catch (FontManagerService.SystemFontException e) {
|
||||||
assertThat(e.getErrorCode())
|
assertThat(e.getErrorCode())
|
||||||
.isEqualTo(FontManager.RESULT_ERROR_VERIFICATION_FAILURE);
|
.isEqualTo(FontManager.RESULT_ERROR_VERIFICATION_FAILURE);
|
||||||
}
|
}
|
||||||
assertThat(dir.getFontFileMap()).isEmpty();
|
assertThat(dir.getPostScriptMap()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void installFontFile_preinstalled_upgrade() throws Exception {
|
public void installFontFile_preinstalled_upgrade() throws Exception {
|
||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
FileUtils.stringToFile(new File(mPreinstalledFontDirs.get(0), "test.ttf"), "test.ttf,1");
|
FileUtils.stringToFile(new File(mPreinstalledFontDirs.get(0), "test.ttf"),
|
||||||
|
"test.ttf,1,test");
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,2", GOOD_SIGNATURE)));
|
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,2,test",
|
||||||
assertThat(dir.getFontFileMap()).containsKey("test.ttf");
|
GOOD_SIGNATURE)));
|
||||||
assertThat(parser.getRevision(dir.getFontFileMap().get("test.ttf"))).isEqualTo(2);
|
assertThat(dir.getPostScriptMap()).containsKey("test");
|
||||||
|
assertThat(parser.getRevision(dir.getPostScriptMap().get("test"))).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void installFontFile_preinstalled_sameVersion() throws Exception {
|
public void installFontFile_preinstalled_sameVersion() throws Exception {
|
||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
FileUtils.stringToFile(new File(mPreinstalledFontDirs.get(0), "test.ttf"), "test.ttf,1");
|
FileUtils.stringToFile(new File(mPreinstalledFontDirs.get(0), "test.ttf"),
|
||||||
|
"test.ttf,1,test");
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1", GOOD_SIGNATURE)));
|
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1,test",
|
||||||
assertThat(dir.getFontFileMap()).containsKey("test.ttf");
|
GOOD_SIGNATURE)));
|
||||||
assertThat(parser.getRevision(dir.getFontFileMap().get("test.ttf"))).isEqualTo(1);
|
assertThat(dir.getPostScriptMap()).containsKey("test");
|
||||||
|
assertThat(parser.getRevision(dir.getPostScriptMap().get("test"))).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void installFontFile_preinstalled_downgrade() throws Exception {
|
public void installFontFile_preinstalled_downgrade() throws Exception {
|
||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
FileUtils.stringToFile(new File(mPreinstalledFontDirs.get(0), "test.ttf"), "test.ttf,2");
|
File file = new File(mPreinstalledFontDirs.get(0), "test.ttf");
|
||||||
|
FileUtils.stringToFile(file, "test.ttf,2,test");
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, (map) -> {
|
||||||
|
FontConfig.Font font = new FontConfig.Font(
|
||||||
|
file, null, "test", new FontStyle(400, FontStyle.FONT_SLANT_UPRIGHT), 0, null,
|
||||||
|
null);
|
||||||
|
FontConfig.FontFamily family = new FontConfig.FontFamily(
|
||||||
|
Collections.singletonList(font), "sans-serif", null,
|
||||||
|
FontConfig.FontFamily.VARIANT_DEFAULT);
|
||||||
|
return new FontConfig(Collections.singletonList(family), Collections.emptyList(), 0, 1);
|
||||||
|
});
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1",
|
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1,test",
|
||||||
GOOD_SIGNATURE)));
|
GOOD_SIGNATURE)));
|
||||||
fail("Expect SystemFontException");
|
fail("Expect SystemFontException");
|
||||||
} catch (FontManagerService.SystemFontException e) {
|
} catch (FontManagerService.SystemFontException e) {
|
||||||
assertThat(e.getErrorCode()).isEqualTo(FontManager.RESULT_ERROR_DOWNGRADING);
|
assertThat(e.getErrorCode()).isEqualTo(FontManager.RESULT_ERROR_DOWNGRADING);
|
||||||
}
|
}
|
||||||
assertThat(dir.getFontFileMap()).isEmpty();
|
assertThat(dir.getPostScriptMap()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -588,7 +662,8 @@ public final class UpdatableFontDirTest {
|
|||||||
long expectedModifiedDate = 1234567890;
|
long expectedModifiedDate = 1234567890;
|
||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
FileUtils.stringToFile(new File(mPreinstalledFontDirs.get(0), "test.ttf"), "test.ttf,1");
|
FileUtils.stringToFile(new File(mPreinstalledFontDirs.get(0), "test.ttf"),
|
||||||
|
"test.ttf,1,test");
|
||||||
|
|
||||||
File readonlyDir = new File(mCacheDir, "readonly");
|
File readonlyDir = new File(mCacheDir, "readonly");
|
||||||
assertThat(readonlyDir.mkdir()).isTrue();
|
assertThat(readonlyDir.mkdir()).isTrue();
|
||||||
@@ -601,13 +676,13 @@ public final class UpdatableFontDirTest {
|
|||||||
assertThat(readonlyDir.setWritable(false, false)).isTrue();
|
assertThat(readonlyDir.setWritable(false, false)).isTrue();
|
||||||
try {
|
try {
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
readonlyFile, mCurrentTimeSupplier);
|
readonlyFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dir.update(
|
dir.update(
|
||||||
Collections.singletonList(newFontUpdateRequest("test.ttf,2",
|
Collections.singletonList(newFontUpdateRequest("test.ttf,2,test",
|
||||||
GOOD_SIGNATURE)));
|
GOOD_SIGNATURE)));
|
||||||
} catch (FontManagerService.SystemFontException e) {
|
} catch (FontManagerService.SystemFontException e) {
|
||||||
assertThat(e.getErrorCode())
|
assertThat(e.getErrorCode())
|
||||||
@@ -615,7 +690,7 @@ public final class UpdatableFontDirTest {
|
|||||||
}
|
}
|
||||||
assertThat(dir.getSystemFontConfig().getLastModifiedTimeMillis())
|
assertThat(dir.getSystemFontConfig().getLastModifiedTimeMillis())
|
||||||
.isEqualTo(expectedModifiedDate);
|
.isEqualTo(expectedModifiedDate);
|
||||||
assertThat(dir.getFontFileMap()).isEmpty();
|
assertThat(dir.getPostScriptMap()).isEmpty();
|
||||||
} finally {
|
} finally {
|
||||||
assertThat(readonlyDir.setWritable(true, true)).isTrue();
|
assertThat(readonlyDir.setWritable(true, true)).isTrue();
|
||||||
}
|
}
|
||||||
@@ -625,7 +700,7 @@ public final class UpdatableFontDirTest {
|
|||||||
public void installFontFile_failedToParsePostScript() throws Exception {
|
public void installFontFile_failedToParsePostScript() throws Exception {
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs,
|
mUpdatableFontFilesDir,
|
||||||
new UpdatableFontDir.FontFileParser() {
|
new UpdatableFontDir.FontFileParser() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -642,25 +717,25 @@ public final class UpdatableFontDirTest {
|
|||||||
public long getRevision(File file) throws IOException {
|
public long getRevision(File file) throws IOException {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}, fakeFsverityUtil, mConfigFile, mCurrentTimeSupplier);
|
}, fakeFsverityUtil, mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("foo.ttf,1",
|
dir.update(Collections.singletonList(newFontUpdateRequest("foo.ttf,1,foo",
|
||||||
GOOD_SIGNATURE)));
|
GOOD_SIGNATURE)));
|
||||||
fail("Expect SystemFontException");
|
fail("Expect SystemFontException");
|
||||||
} catch (FontManagerService.SystemFontException e) {
|
} catch (FontManagerService.SystemFontException e) {
|
||||||
assertThat(e.getErrorCode())
|
assertThat(e.getErrorCode())
|
||||||
.isEqualTo(FontManager.RESULT_ERROR_INVALID_FONT_NAME);
|
.isEqualTo(FontManager.RESULT_ERROR_INVALID_FONT_NAME);
|
||||||
}
|
}
|
||||||
assertThat(dir.getFontFileMap()).isEmpty();
|
assertThat(dir.getPostScriptMap()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void installFontFile_failedToParsePostScriptName_invalidFont() throws Exception {
|
public void installFontFile_failedToParsePostScriptName_invalidFont() throws Exception {
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs,
|
mUpdatableFontFilesDir,
|
||||||
new UpdatableFontDir.FontFileParser() {
|
new UpdatableFontDir.FontFileParser() {
|
||||||
@Override
|
@Override
|
||||||
public String getPostScriptName(File file) throws IOException {
|
public String getPostScriptName(File file) throws IOException {
|
||||||
@@ -676,18 +751,18 @@ public final class UpdatableFontDirTest {
|
|||||||
public long getRevision(File file) throws IOException {
|
public long getRevision(File file) throws IOException {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}, fakeFsverityUtil, mConfigFile, mCurrentTimeSupplier);
|
}, fakeFsverityUtil, mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("foo.ttf,1",
|
dir.update(Collections.singletonList(newFontUpdateRequest("foo.ttf,1,foo",
|
||||||
GOOD_SIGNATURE)));
|
GOOD_SIGNATURE)));
|
||||||
fail("Expect SystemFontException");
|
fail("Expect SystemFontException");
|
||||||
} catch (FontManagerService.SystemFontException e) {
|
} catch (FontManagerService.SystemFontException e) {
|
||||||
assertThat(e.getErrorCode())
|
assertThat(e.getErrorCode())
|
||||||
.isEqualTo(FontManager.RESULT_ERROR_INVALID_FONT_FILE);
|
.isEqualTo(FontManager.RESULT_ERROR_INVALID_FONT_FILE);
|
||||||
}
|
}
|
||||||
assertThat(dir.getFontFileMap()).isEmpty();
|
assertThat(dir.getPostScriptMap()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -712,19 +787,19 @@ public final class UpdatableFontDirTest {
|
|||||||
};
|
};
|
||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("foo.ttf,1",
|
dir.update(Collections.singletonList(newFontUpdateRequest("foo.ttf,1,foo",
|
||||||
GOOD_SIGNATURE)));
|
GOOD_SIGNATURE)));
|
||||||
fail("Expect SystemFontException");
|
fail("Expect SystemFontException");
|
||||||
} catch (FontManagerService.SystemFontException e) {
|
} catch (FontManagerService.SystemFontException e) {
|
||||||
assertThat(e.getErrorCode())
|
assertThat(e.getErrorCode())
|
||||||
.isEqualTo(FontManager.RESULT_ERROR_FAILED_TO_WRITE_FONT_FILE);
|
.isEqualTo(FontManager.RESULT_ERROR_FAILED_TO_WRITE_FONT_FILE);
|
||||||
}
|
}
|
||||||
assertThat(dir.getFontFileMap()).isEmpty();
|
assertThat(dir.getPostScriptMap()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -732,22 +807,23 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
dir.update(Collections.singletonList(newFontUpdateRequest("foo.ttf,1", GOOD_SIGNATURE)));
|
dir.update(Collections.singletonList(newFontUpdateRequest("foo.ttf,1,foo",
|
||||||
|
GOOD_SIGNATURE)));
|
||||||
try {
|
try {
|
||||||
dir.update(Arrays.asList(
|
dir.update(Arrays.asList(
|
||||||
newFontUpdateRequest("foo.ttf,2", GOOD_SIGNATURE),
|
newFontUpdateRequest("foo.ttf,2,foo", GOOD_SIGNATURE),
|
||||||
newFontUpdateRequest("bar.ttf,2", "Invalid signature")));
|
newFontUpdateRequest("bar.ttf,2,bar", "Invalid signature")));
|
||||||
fail("Batch update with invalid signature should fail");
|
fail("Batch update with invalid signature should fail");
|
||||||
} catch (FontManagerService.SystemFontException e) {
|
} catch (FontManagerService.SystemFontException e) {
|
||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
// The state should be rolled back as a whole if one of the update requests fail.
|
// The state should be rolled back as a whole if one of the update requests fail.
|
||||||
assertThat(dir.getFontFileMap()).containsKey("foo.ttf");
|
assertThat(dir.getPostScriptMap()).containsKey("foo");
|
||||||
assertThat(parser.getRevision(dir.getFontFileMap().get("foo.ttf"))).isEqualTo(1);
|
assertThat(parser.getRevision(dir.getPostScriptMap().get("foo"))).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -755,21 +831,21 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
dir.update(Arrays.asList(
|
dir.update(Arrays.asList(
|
||||||
newFontUpdateRequest("test.ttf,1", GOOD_SIGNATURE),
|
newFontUpdateRequest("test.ttf,1,test", GOOD_SIGNATURE),
|
||||||
newAddFontFamilyRequest("<family name='test'>"
|
newAddFontFamilyRequest("<family name='test'>"
|
||||||
+ " <font>test.ttf</font>"
|
+ " <font>test.ttf</font>"
|
||||||
+ "</family>")));
|
+ "</family>")));
|
||||||
assertThat(dir.getFontFileMap()).containsKey("test.ttf");
|
assertThat(dir.getPostScriptMap()).containsKey("test");
|
||||||
assertThat(dir.getFontFamilyMap()).containsKey("test");
|
assertThat(dir.getFontFamilyMap()).containsKey("test");
|
||||||
FontConfig.FontFamily test = dir.getFontFamilyMap().get("test");
|
FontConfig.FontFamily test = dir.getFontFamilyMap().get("test");
|
||||||
assertThat(test.getFontList()).hasSize(1);
|
assertThat(test.getFontList()).hasSize(1);
|
||||||
assertThat(test.getFontList().get(0).getFile())
|
assertThat(test.getFontList().get(0).getFile())
|
||||||
.isEqualTo(dir.getFontFileMap().get("test.ttf"));
|
.isEqualTo(dir.getPostScriptMap().get("test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -777,13 +853,13 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dir.update(Arrays.asList(
|
dir.update(Arrays.asList(
|
||||||
newFontUpdateRequest("test.ttf,1", GOOD_SIGNATURE),
|
newFontUpdateRequest("test.ttf,1,test", GOOD_SIGNATURE),
|
||||||
newAddFontFamilyRequest("<family lang='en'>"
|
newAddFontFamilyRequest("<family lang='en'>"
|
||||||
+ " <font>test.ttf</font>"
|
+ " <font>test.ttf</font>"
|
||||||
+ "</family>")));
|
+ "</family>")));
|
||||||
@@ -798,8 +874,8 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -818,14 +894,14 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
// We assume we have monospace.
|
// We assume we have monospace.
|
||||||
assertNamedFamilyExists(dir.getSystemFontConfig(), "monospace");
|
assertNamedFamilyExists(dir.getSystemFontConfig(), "monospace");
|
||||||
|
|
||||||
dir.update(Arrays.asList(
|
dir.update(Arrays.asList(
|
||||||
newFontUpdateRequest("test.ttf,1", GOOD_SIGNATURE),
|
newFontUpdateRequest("test.ttf,1,test", GOOD_SIGNATURE),
|
||||||
// Updating an existing font family.
|
// Updating an existing font family.
|
||||||
newAddFontFamilyRequest("<family name='monospace'>"
|
newAddFontFamilyRequest("<family name='monospace'>"
|
||||||
+ " <font>test.ttf</font>"
|
+ " <font>test.ttf</font>"
|
||||||
@@ -839,7 +915,7 @@ public final class UpdatableFontDirTest {
|
|||||||
FontConfig.FontFamily monospace = getLastFamily(fontConfig, "monospace");
|
FontConfig.FontFamily monospace = getLastFamily(fontConfig, "monospace");
|
||||||
assertThat(monospace.getFontList()).hasSize(1);
|
assertThat(monospace.getFontList()).hasSize(1);
|
||||||
assertThat(monospace.getFontList().get(0).getFile())
|
assertThat(monospace.getFontList().get(0).getFile())
|
||||||
.isEqualTo(dir.getFontFileMap().get("test.ttf"));
|
.isEqualTo(dir.getPostScriptMap().get("test"));
|
||||||
assertNamedFamilyExists(fontConfig, "test");
|
assertNamedFamilyExists(fontConfig, "test");
|
||||||
assertThat(getLastFamily(fontConfig, "test").getFontList())
|
assertThat(getLastFamily(fontConfig, "test").getFontList())
|
||||||
.isEqualTo(monospace.getFontList());
|
.isEqualTo(monospace.getFontList());
|
||||||
@@ -850,15 +926,15 @@ public final class UpdatableFontDirTest {
|
|||||||
FakeFontFileParser parser = new FakeFontFileParser();
|
FakeFontFileParser parser = new FakeFontFileParser();
|
||||||
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
|
||||||
UpdatableFontDir dir = new UpdatableFontDir(
|
UpdatableFontDir dir = new UpdatableFontDir(
|
||||||
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
|
mUpdatableFontFilesDir, parser, fakeFsverityUtil,
|
||||||
mConfigFile, mCurrentTimeSupplier);
|
mConfigFile, mCurrentTimeSupplier, mConfigSupplier);
|
||||||
dir.loadFontFileMap();
|
dir.loadFontFileMap();
|
||||||
assertThat(dir.getSystemFontConfig().getFontFamilies()).isNotEmpty();
|
assertThat(dir.getSystemFontConfig().getFontFamilies()).isNotEmpty();
|
||||||
FontConfig.FontFamily firstFontFamily = dir.getSystemFontConfig().getFontFamilies().get(0);
|
FontConfig.FontFamily firstFontFamily = dir.getSystemFontConfig().getFontFamilies().get(0);
|
||||||
assertThat(firstFontFamily.getName()).isNotEmpty();
|
assertThat(firstFontFamily.getName()).isNotEmpty();
|
||||||
|
|
||||||
dir.update(Arrays.asList(
|
dir.update(Arrays.asList(
|
||||||
newFontUpdateRequest("test.ttf,1", GOOD_SIGNATURE),
|
newFontUpdateRequest("test.ttf,1,test", GOOD_SIGNATURE),
|
||||||
newAddFontFamilyRequest("<family name='" + firstFontFamily.getName() + "'>"
|
newAddFontFamilyRequest("<family name='" + firstFontFamily.getName() + "'>"
|
||||||
+ " <font>test.ttf</font>"
|
+ " <font>test.ttf</font>"
|
||||||
+ "</family>")));
|
+ "</family>")));
|
||||||
@@ -868,7 +944,7 @@ public final class UpdatableFontDirTest {
|
|||||||
FontConfig.FontFamily updated = getLastFamily(fontConfig, firstFontFamily.getName());
|
FontConfig.FontFamily updated = getLastFamily(fontConfig, firstFontFamily.getName());
|
||||||
assertThat(updated.getFontList()).hasSize(1);
|
assertThat(updated.getFontList()).hasSize(1);
|
||||||
assertThat(updated.getFontList().get(0).getFile())
|
assertThat(updated.getFontList().get(0).getFile())
|
||||||
.isEqualTo(dir.getFontFileMap().get("test.ttf"));
|
.isEqualTo(dir.getPostScriptMap().get("test"));
|
||||||
assertThat(updated).isNotEqualTo(firstFontFamily);
|
assertThat(updated).isNotEqualTo(firstFontFamily);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user