Merge "Allow same version update." into sc-dev

This commit is contained in:
Kohsuke Yatoh
2021-04-09 17:49:19 +00:00
committed by Android (Google) Code Review
6 changed files with 160 additions and 63 deletions

View File

@@ -184,7 +184,7 @@ final class UpdatableFontDir {
return;
}
FontFileInfo fontFileInfo = validateFontFile(files[0]);
addFileToMapIfNewer(fontFileInfo, true /* deleteOldFile */);
addFileToMapIfSameOrNewer(fontFileInfo, true /* deleteOldFile */);
}
success = true;
} catch (Throwable t) {
@@ -367,7 +367,7 @@ final class UpdatableFontDir {
"Failed to change mode to 711", e);
}
FontFileInfo fontFileInfo = validateFontFile(newFontFile);
if (!addFileToMapIfNewer(fontFileInfo, false)) {
if (!addFileToMapIfSameOrNewer(fontFileInfo, false)) {
throw new SystemFontException(
FontManager.RESULT_ERROR_DOWNGRADING,
"Downgrading font file is forbidden.");
@@ -408,10 +408,10 @@ final class UpdatableFontDir {
/**
* Add the given {@link FontFileInfo} to {@link #mFontFileInfoMap} if its font revision is
* higher than the currently used font file (either in {@link #mFontFileInfoMap} or {@link
* #mPreinstalledFontDirs}).
* equal to or higher than the revision of currently used font file (either in
* {@link #mFontFileInfoMap} or {@link #mPreinstalledFontDirs}).
*/
private boolean addFileToMapIfNewer(FontFileInfo fontFileInfo, boolean deleteOldFile) {
private boolean addFileToMapIfSameOrNewer(FontFileInfo fontFileInfo, boolean deleteOldFile) {
FontFileInfo existingInfo = lookupFontFileInfo(fontFileInfo.getPostScriptName());
final boolean shouldAddToMap;
if (existingInfo == null) {
@@ -419,9 +419,9 @@ final class UpdatableFontDir {
// Note that getPreinstalledFontRevision() returns -1 if there is no preinstalled font
// with 'name'.
long preInstalledRev = getPreinstalledFontRevision(fontFileInfo.getFile().getName());
shouldAddToMap = preInstalledRev < fontFileInfo.getRevision();
shouldAddToMap = preInstalledRev <= fontFileInfo.getRevision();
} else {
shouldAddToMap = existingInfo.getRevision() < fontFileInfo.getRevision();
shouldAddToMap = existingInfo.getRevision() <= fontFileInfo.getRevision();
}
if (shouldAddToMap) {
if (deleteOldFile && existingInfo != null) {

View File

@@ -415,6 +415,21 @@ public final class UpdatableFontDirTest {
.that(parser.getRevision(mapBeforeUpgrade.get("test.ttf"))).isEqualTo(1);
}
@Test
public void installFontFile_sameVersion() throws Exception {
FakeFontFileParser parser = new FakeFontFileParser();
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
UpdatableFontDir dir = new UpdatableFontDir(
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
mConfigFile, mCurrentTimeSupplier);
dir.loadFontFileMap();
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1", GOOD_SIGNATURE)));
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1", GOOD_SIGNATURE)));
assertThat(dir.getFontFileMap()).containsKey("test.ttf");
assertThat(parser.getRevision(dir.getFontFileMap().get("test.ttf"))).isEqualTo(1);
}
@Test
public void installFontFile_downgrade() throws Exception {
FakeFontFileParser parser = new FakeFontFileParser();
@@ -494,7 +509,7 @@ public final class UpdatableFontDirTest {
}
@Test
public void installFontFile_olderThanPreinstalledFont() throws Exception {
public void installFontFile_preinstalled_upgrade() throws Exception {
FakeFontFileParser parser = new FakeFontFileParser();
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
FileUtils.stringToFile(new File(mPreinstalledFontDirs.get(0), "test.ttf"), "test.ttf,1");
@@ -503,6 +518,36 @@ public final class UpdatableFontDirTest {
mConfigFile, mCurrentTimeSupplier);
dir.loadFontFileMap();
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,2", GOOD_SIGNATURE)));
assertThat(dir.getFontFileMap()).containsKey("test.ttf");
assertThat(parser.getRevision(dir.getFontFileMap().get("test.ttf"))).isEqualTo(2);
}
@Test
public void installFontFile_preinstalled_sameVersion() throws Exception {
FakeFontFileParser parser = new FakeFontFileParser();
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
FileUtils.stringToFile(new File(mPreinstalledFontDirs.get(0), "test.ttf"), "test.ttf,1");
UpdatableFontDir dir = new UpdatableFontDir(
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
mConfigFile, mCurrentTimeSupplier);
dir.loadFontFileMap();
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1", GOOD_SIGNATURE)));
assertThat(dir.getFontFileMap()).containsKey("test.ttf");
assertThat(parser.getRevision(dir.getFontFileMap().get("test.ttf"))).isEqualTo(1);
}
@Test
public void installFontFile_preinstalled_downgrade() throws Exception {
FakeFontFileParser parser = new FakeFontFileParser();
FakeFsverityUtil fakeFsverityUtil = new FakeFsverityUtil();
FileUtils.stringToFile(new File(mPreinstalledFontDirs.get(0), "test.ttf"), "test.ttf,2");
UpdatableFontDir dir = new UpdatableFontDir(
mUpdatableFontFilesDir, mPreinstalledFontDirs, parser, fakeFsverityUtil,
mConfigFile, mCurrentTimeSupplier);
dir.loadFontFileMap();
try {
dir.update(Collections.singletonList(newFontUpdateRequest("test.ttf,1",
GOOD_SIGNATURE)));

View File

@@ -24,18 +24,27 @@ package {
java_test_host {
name: "UpdatableSystemFontTest",
srcs: ["src/**/*.java"],
libs: ["tradefed", "compatibility-tradefed", "compatibility-host-util"],
libs: [
"tradefed",
"compatibility-tradefed",
"compatibility-host-util",
],
static_libs: [
"frameworks-base-hostutils",
],
test_suites: ["general-tests", "vts"],
test_suites: [
"general-tests",
"vts",
],
data: [
":NotoColorEmojiTtf",
":UpdatableSystemFontTestCertDer",
":UpdatableSystemFontTestNotoColorEmojiTtfFsvSig",
":UpdatableSystemFontTestNotoColorEmojiV1Ttf",
":UpdatableSystemFontTestNotoColorEmojiV1TtfFsvSig",
":UpdatableSystemFontTestNotoColorEmojiV2Ttf",
":UpdatableSystemFontTestNotoColorEmojiV2TtfFsvSig",
":UpdatableSystemFontTestNotoColorEmojiV0Ttf",
":UpdatableSystemFontTestNotoColorEmojiV0TtfFsvSig",
":UpdatableSystemFontTestNotoColorEmojiVPlus1Ttf",
":UpdatableSystemFontTestNotoColorEmojiVPlus1TtfFsvSig",
":UpdatableSystemFontTestNotoColorEmojiVPlus2Ttf",
":UpdatableSystemFontTestNotoColorEmojiVPlus2TtfFsvSig",
],
}

View File

@@ -24,10 +24,12 @@
<option name="push" value="UpdatableSystemFontTestCert.der->/data/local/tmp/UpdatableSystemFontTestCert.der" />
<option name="push" value="NotoColorEmoji.ttf->/data/local/tmp/NotoColorEmoji.ttf" />
<option name="push" value="UpdatableSystemFontTestNotoColorEmoji.ttf.fsv_sig->/data/local/tmp/UpdatableSystemFontTestNotoColorEmoji.ttf.fsv_sig" />
<option name="push" value="UpdatableSystemFontTestNotoColorEmojiV1.ttf->/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiV1.ttf" />
<option name="push" value="UpdatableSystemFontTestNotoColorEmojiV1.ttf.fsv_sig->/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiV1.ttf.fsv_sig" />
<option name="push" value="UpdatableSystemFontTestNotoColorEmojiV2.ttf->/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiV2.ttf" />
<option name="push" value="UpdatableSystemFontTestNotoColorEmojiV2.ttf.fsv_sig->/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiV2.ttf.fsv_sig" />
<option name="push" value="UpdatableSystemFontTestNotoColorEmojiV0.ttf->/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiV0.ttf" />
<option name="push" value="UpdatableSystemFontTestNotoColorEmojiV0.ttf.fsv_sig->/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiV0.ttf.fsv_sig" />
<option name="push" value="UpdatableSystemFontTestNotoColorEmojiVPlus1.ttf->/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiVPlus1.ttf" />
<option name="push" value="UpdatableSystemFontTestNotoColorEmojiVPlus1.ttf.fsv_sig->/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiVPlus1.ttf.fsv_sig" />
<option name="push" value="UpdatableSystemFontTestNotoColorEmojiVPlus2.ttf->/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiVPlus2.ttf" />
<option name="push" value="UpdatableSystemFontTestNotoColorEmojiVPlus2.ttf.fsv_sig->/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiVPlus2.ttf.fsv_sig" />
</target_preparer>
<test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" >

View File

@@ -51,18 +51,26 @@ public class UpdatableSystemFontTest extends BaseHostJUnit4Test {
private static final Pattern PATTERN_FONT = Pattern.compile("path = ([^, \n]*)");
private static final String NOTO_COLOR_EMOJI_TTF = "NotoColorEmoji.ttf";
private static final String TEST_NOTO_COLOR_EMOJI_V1_TTF =
"/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiV1.ttf";
private static final String TEST_NOTO_COLOR_EMOJI_V1_TTF_FSV_SIG =
"/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiV1.ttf.fsv_sig";
private static final String TEST_NOTO_COLOR_EMOJI_V2_TTF =
"/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiV2.ttf";
private static final String TEST_NOTO_COLOR_EMOJI_V2_TTF_FSV_SIG =
"/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiV2.ttf.fsv_sig";
private static final String ORIGINAL_NOTO_COLOR_EMOJI_TTF =
"/data/local/tmp/NotoColorEmoji.ttf";
private static final String ORIGINAL_NOTO_COLOR_EMOJI_TTF_FSV_SIG =
"/data/local/tmp/UpdatableSystemFontTestNotoColorEmoji.ttf.fsv_sig";
// A font with revision == 0.
private static final String TEST_NOTO_COLOR_EMOJI_V0_TTF =
"/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiV0.ttf";
private static final String TEST_NOTO_COLOR_EMOJI_V0_TTF_FSV_SIG =
"/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiV0.ttf.fsv_sig";
// A font with revision == original + 1
private static final String TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF =
"/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiVPlus1.ttf";
private static final String TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF_FSV_SIG =
"/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiVPlus1.ttf.fsv_sig";
// A font with revision == original + 2
private static final String TEST_NOTO_COLOR_EMOJI_VPLUS2_TTF =
"/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiVPlus2.ttf";
private static final String TEST_NOTO_COLOR_EMOJI_VPLUS2_TTF_FSV_SIG =
"/data/local/tmp/UpdatableSystemFontTestNotoColorEmojiVPlus2.ttf.fsv_sig";
@Rule
public final AddFsVerityCertRule mAddFsverityCertRule =
@@ -81,7 +89,7 @@ public class UpdatableSystemFontTest extends BaseHostJUnit4Test {
@Test
public void updateFont() throws Exception {
expectRemoteCommandToSucceed(String.format("cmd font update %s %s",
TEST_NOTO_COLOR_EMOJI_V1_TTF, TEST_NOTO_COLOR_EMOJI_V1_TTF_FSV_SIG));
TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF, TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF_FSV_SIG));
String fontPath = getFontPath(NOTO_COLOR_EMOJI_TTF);
assertThat(fontPath).startsWith("/data/fonts/files/");
}
@@ -89,19 +97,39 @@ public class UpdatableSystemFontTest extends BaseHostJUnit4Test {
@Test
public void updateFont_twice() throws Exception {
expectRemoteCommandToSucceed(String.format("cmd font update %s %s",
TEST_NOTO_COLOR_EMOJI_V1_TTF, TEST_NOTO_COLOR_EMOJI_V1_TTF_FSV_SIG));
TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF, TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF_FSV_SIG));
String fontPath = getFontPath(NOTO_COLOR_EMOJI_TTF);
expectRemoteCommandToSucceed(String.format("cmd font update %s %s",
TEST_NOTO_COLOR_EMOJI_V2_TTF, TEST_NOTO_COLOR_EMOJI_V2_TTF_FSV_SIG));
TEST_NOTO_COLOR_EMOJI_VPLUS2_TTF, TEST_NOTO_COLOR_EMOJI_VPLUS2_TTF_FSV_SIG));
String fontPath2 = getFontPath(NOTO_COLOR_EMOJI_TTF);
assertThat(fontPath2).startsWith("/data/fonts/files/");
assertThat(fontPath2).isNotEqualTo(fontPath);
}
@Test
public void updateFont_allowSameVersion() throws Exception {
// Update original font to the same version
expectRemoteCommandToSucceed(String.format("cmd font update %s %s",
ORIGINAL_NOTO_COLOR_EMOJI_TTF, ORIGINAL_NOTO_COLOR_EMOJI_TTF_FSV_SIG));
String fontPath = getFontPath(NOTO_COLOR_EMOJI_TTF);
expectRemoteCommandToSucceed(String.format("cmd font update %s %s",
TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF, TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF_FSV_SIG));
String fontPath2 = getFontPath(NOTO_COLOR_EMOJI_TTF);
// Update updated font to the same version
expectRemoteCommandToSucceed(String.format("cmd font update %s %s",
TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF, TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF_FSV_SIG));
String fontPath3 = getFontPath(NOTO_COLOR_EMOJI_TTF);
assertThat(fontPath).startsWith("/data/fonts/files/");
assertThat(fontPath2).isNotEqualTo(fontPath);
assertThat(fontPath2).startsWith("/data/fonts/files/");
assertThat(fontPath3).startsWith("/data/fonts/files/");
assertThat(fontPath3).isNotEqualTo(fontPath);
}
@Test
public void updatedFont_dataFileIsImmutableAndReadable() throws Exception {
expectRemoteCommandToSucceed(String.format("cmd font update %s %s",
TEST_NOTO_COLOR_EMOJI_V1_TTF, TEST_NOTO_COLOR_EMOJI_V1_TTF_FSV_SIG));
TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF, TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF_FSV_SIG));
String fontPath = getFontPath(NOTO_COLOR_EMOJI_TTF);
assertThat(fontPath).startsWith("/data");
@@ -112,27 +140,27 @@ public class UpdatableSystemFontTest extends BaseHostJUnit4Test {
@Test
public void updateFont_invalidCert() throws Exception {
expectRemoteCommandToFail(String.format("cmd font update %s %s",
TEST_NOTO_COLOR_EMOJI_V1_TTF, TEST_NOTO_COLOR_EMOJI_V2_TTF_FSV_SIG));
TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF, TEST_NOTO_COLOR_EMOJI_VPLUS2_TTF_FSV_SIG));
}
@Test
public void updateFont_downgradeFromSystem() throws Exception {
expectRemoteCommandToFail(String.format("cmd font update %s %s",
ORIGINAL_NOTO_COLOR_EMOJI_TTF, ORIGINAL_NOTO_COLOR_EMOJI_TTF_FSV_SIG));
TEST_NOTO_COLOR_EMOJI_V0_TTF, TEST_NOTO_COLOR_EMOJI_V0_TTF_FSV_SIG));
}
@Test
public void updateFont_downgradeFromData() throws Exception {
expectRemoteCommandToSucceed(String.format("cmd font update %s %s",
TEST_NOTO_COLOR_EMOJI_V2_TTF, TEST_NOTO_COLOR_EMOJI_V2_TTF_FSV_SIG));
TEST_NOTO_COLOR_EMOJI_VPLUS2_TTF, TEST_NOTO_COLOR_EMOJI_VPLUS2_TTF_FSV_SIG));
expectRemoteCommandToFail(String.format("cmd font update %s %s",
TEST_NOTO_COLOR_EMOJI_V1_TTF, TEST_NOTO_COLOR_EMOJI_V1_TTF_FSV_SIG));
TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF, TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF_FSV_SIG));
}
@Test
public void reboot() throws Exception {
expectRemoteCommandToSucceed(String.format("cmd font update %s %s",
TEST_NOTO_COLOR_EMOJI_V1_TTF, TEST_NOTO_COLOR_EMOJI_V1_TTF_FSV_SIG));
TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF, TEST_NOTO_COLOR_EMOJI_VPLUS1_TTF_FSV_SIG));
String fontPath = getFontPath(NOTO_COLOR_EMOJI_TTF);
assertThat(fontPath).startsWith("/data/fonts/files/");
@@ -182,17 +210,6 @@ public class UpdatableSystemFontTest extends BaseHostJUnit4Test {
});
}
private void waitUntilSystemServerIsGone() {
waitUntil(TimeUnit.SECONDS.toMillis(30), () -> {
try {
return getDevice().executeShellV2Command("pid system_server").getStatus()
== CommandStatus.FAILED;
} catch (DeviceNotAvailableException e) {
return false;
}
});
}
private void waitUntil(long timeoutMillis, Supplier<Boolean> func) {
long untilMillis = System.currentTimeMillis() + timeoutMillis;
do {

View File

@@ -38,6 +38,23 @@ filegroup {
genrule_defaults {
name: "updatable_system_font_increment_font_revision_default",
}
genrule {
name: "UpdatableSystemFontTestNotoColorEmojiV0Ttf",
srcs: [":NotoColorEmojiTtf"],
out: ["UpdatableSystemFontTestNotoColorEmojiV0.ttf"],
tools: ["update_font_metadata"],
cmd: "$(location update_font_metadata) " +
"--input=$(in) " +
"--output=$(out) " +
"--revision=0",
}
genrule {
name: "UpdatableSystemFontTestNotoColorEmojiVPlus1Ttf",
srcs: [":NotoColorEmojiTtf"],
out: ["UpdatableSystemFontTestNotoColorEmojiVPlus1.ttf"],
tools: ["update_font_metadata"],
cmd: "$(location update_font_metadata) " +
"--input=$(in) " +
@@ -46,23 +63,23 @@ genrule_defaults {
}
genrule {
name: "UpdatableSystemFontTestNotoColorEmojiV1Ttf",
defaults: ["updatable_system_font_increment_font_revision_default"],
name: "UpdatableSystemFontTestNotoColorEmojiVPlus2Ttf",
srcs: [":NotoColorEmojiTtf"],
out: ["UpdatableSystemFontTestNotoColorEmojiV1.ttf"],
}
genrule {
name: "UpdatableSystemFontTestNotoColorEmojiV2Ttf",
defaults: ["updatable_system_font_increment_font_revision_default"],
srcs: [":UpdatableSystemFontTestNotoColorEmojiV1Ttf"],
out: ["UpdatableSystemFontTestNotoColorEmojiV2.ttf"],
out: ["UpdatableSystemFontTestNotoColorEmojiVPlus2.ttf"],
tools: ["update_font_metadata"],
cmd: "$(location update_font_metadata) " +
"--input=$(in) " +
"--output=$(out) " +
"--revision=+2",
}
genrule_defaults {
name: "updatable_system_font_sig_gen_default",
tools: ["fsverity"],
tool_files: [":UpdatableSystemFontTestKeyPem", ":UpdatableSystemFontTestCertPem"],
tool_files: [
":UpdatableSystemFontTestKeyPem",
":UpdatableSystemFontTestCertPem",
],
cmd: "$(location fsverity) sign $(in) $(out) " +
"--key=$(location :UpdatableSystemFontTestKeyPem) " +
"--cert=$(location :UpdatableSystemFontTestCertPem) " +
@@ -77,15 +94,22 @@ genrule {
}
genrule {
name: "UpdatableSystemFontTestNotoColorEmojiV1TtfFsvSig",
name: "UpdatableSystemFontTestNotoColorEmojiV0TtfFsvSig",
defaults: ["updatable_system_font_sig_gen_default"],
srcs: [":UpdatableSystemFontTestNotoColorEmojiV1Ttf"],
out: ["UpdatableSystemFontTestNotoColorEmojiV1.ttf.fsv_sig"],
srcs: [":UpdatableSystemFontTestNotoColorEmojiV0Ttf"],
out: ["UpdatableSystemFontTestNotoColorEmojiV0.ttf.fsv_sig"],
}
genrule {
name: "UpdatableSystemFontTestNotoColorEmojiV2TtfFsvSig",
name: "UpdatableSystemFontTestNotoColorEmojiVPlus1TtfFsvSig",
defaults: ["updatable_system_font_sig_gen_default"],
srcs: [":UpdatableSystemFontTestNotoColorEmojiV2Ttf"],
out: ["UpdatableSystemFontTestNotoColorEmojiV2.ttf.fsv_sig"],
srcs: [":UpdatableSystemFontTestNotoColorEmojiVPlus1Ttf"],
out: ["UpdatableSystemFontTestNotoColorEmojiVPlus1.ttf.fsv_sig"],
}
genrule {
name: "UpdatableSystemFontTestNotoColorEmojiVPlus2TtfFsvSig",
defaults: ["updatable_system_font_sig_gen_default"],
srcs: [":UpdatableSystemFontTestNotoColorEmojiVPlus2Ttf"],
out: ["UpdatableSystemFontTestNotoColorEmojiVPlus2.ttf.fsv_sig"],
}