From bd636d839155abf3b3d2114f096105bc5f70f5df Mon Sep 17 00:00:00 2001 From: Kohsuke Yatoh Date: Thu, 8 Apr 2021 12:54:29 -0700 Subject: [PATCH] Allow same version update. Bug: 184862662 Test: atest FrameworksServicesTests:UpdatableFontDirTest Test: atest UpdatableSystemFontTest Change-Id: Ic955e2713c08e4c258d61cd3b597a472e1e3298c --- .../graphics/fonts/UpdatableFontDir.java | 14 ++-- .../graphics/fonts/UpdatableFontDirTest.java | 47 +++++++++++- tests/UpdatableSystemFontTest/Android.bp | 21 ++++-- tests/UpdatableSystemFontTest/AndroidTest.xml | 10 ++- .../UpdatableSystemFontTest.java | 73 ++++++++++++------- .../testdata/Android.bp | 58 ++++++++++----- 6 files changed, 160 insertions(+), 63 deletions(-) diff --git a/services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java b/services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java index c9ec90f9cbff8..c56f386701f6c 100644 --- a/services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java +++ b/services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java @@ -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) { diff --git a/services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java b/services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java index 5c9b830f6034e..5363a17e42df2 100644 --- a/services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java +++ b/services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java @@ -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))); diff --git a/tests/UpdatableSystemFontTest/Android.bp b/tests/UpdatableSystemFontTest/Android.bp index d4f1ad317d313..8b0ae5c37baed 100644 --- a/tests/UpdatableSystemFontTest/Android.bp +++ b/tests/UpdatableSystemFontTest/Android.bp @@ -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", ], } diff --git a/tests/UpdatableSystemFontTest/AndroidTest.xml b/tests/UpdatableSystemFontTest/AndroidTest.xml index efe5d703880cb..d573e93e4a4ce 100644 --- a/tests/UpdatableSystemFontTest/AndroidTest.xml +++ b/tests/UpdatableSystemFontTest/AndroidTest.xml @@ -24,10 +24,12 @@