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

Commit 5afa828d authored by Kohsuke Yatoh's avatar Kohsuke Yatoh Committed by Android (Google) Code Review
Browse files

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

parents 3c089060 bd636d83
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -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) {
+46 −1
Original line number Diff line number Diff line
@@ -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)));
+15 −6
Original line number Diff line number Diff line
@@ -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",
    ],
}
+6 −4
Original line number Diff line number Diff line
@@ -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" >
+45 −28
Original line number Diff line number Diff line
@@ -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 {
Loading