Loading services/core/java/com/android/server/graphics/fonts/FontManagerService.java +4 −0 Original line number Diff line number Diff line Loading @@ -314,6 +314,10 @@ public final class FontManagerService extends IFontManager.Stub { } } /* package */ void restart() { initialize(); } /* package */ Map<String, File> getFontFileMap() { if (mUpdatableFontDir == null) { return Collections.emptyMap(); Loading services/core/java/com/android/server/graphics/fonts/FontManagerShellCommand.java +18 −1 Original line number Diff line number Diff line Loading @@ -95,6 +95,15 @@ public class FontManagerShellCommand extends ShellCommand { w.println(); w.println("clear"); w.println(" Remove all installed font files and reset to the initial state."); w.println(); w.println("restart"); w.println(" Restart FontManagerService emulating device reboot."); w.println(" WARNING: this is not a safe operation. Other processes may misbehave if"); w.println(" they are using fonts updated by FontManagerService."); w.println(" This command exists merely for testing."); w.println(); w.println("status"); w.println(" Prints status of current system font configuration."); } /* package */ void dumpAll(@NonNull IndentingPrintWriter w) { Loading Loading @@ -368,7 +377,13 @@ public class FontManagerShellCommand extends ShellCommand { return 0; } private int status(ShellCommand shell) throws SystemFontException { private int restart(ShellCommand shell) { mService.restart(); shell.getOutPrintWriter().println("Success"); return 0; } private int status(ShellCommand shell) { final IndentingPrintWriter writer = new IndentingPrintWriter(shell.getOutPrintWriter(), " "); FontConfig config = mService.getSystemFontConfig(); Loading Loading @@ -396,6 +411,8 @@ public class FontManagerShellCommand extends ShellCommand { return update(shell); case "clear": return clear(shell); case "restart": return restart(shell); case "status": return status(shell); default: Loading services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java +7 −1 Original line number Diff line number Diff line Loading @@ -125,7 +125,7 @@ final class UpdatableFontDir { private final Supplier<Long> mCurrentTimeSupplier; private long mLastModifiedMillis; private int mConfigVersion = 1; private int mConfigVersion; /** * A mutable map containing mapping from font file name (e.g. "NotoColorEmoji.ttf") to {@link Loading @@ -152,9 +152,15 @@ final class UpdatableFontDir { mCurrentTimeSupplier = currentTimeSupplier; } /** * Loads fonts from file system, validate them, and delete obsolete font files. * Note that this method may be called by multiple times in integration tests via {@link * FontManagerService#restart()}. */ /* package */ void loadFontFileMap() { mFontFileInfoMap.clear(); mLastModifiedMillis = 0; mConfigVersion = 1; boolean success = false; try { PersistentSystemFontConfig.Config config = new PersistentSystemFontConfig.Config(); Loading services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java +15 −0 Original line number Diff line number Diff line Loading @@ -380,6 +380,21 @@ public final class UpdatableFontDirTest { .isEqualTo(dir.getFontFileMap().get("foo.ttf")); } @Test public void loadFontFileMap_twice() 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))); assertThat(dir.getFontFileMap()).containsKey("test.ttf"); File fontFile = dir.getFontFileMap().get("test.ttf"); dir.loadFontFileMap(); assertThat(dir.getFontFileMap().get("test.ttf")).isEqualTo(fontFile); } @Test public void installFontFile() throws Exception { FakeFontFileParser parser = new FakeFontFileParser(); Loading tests/UpdatableSystemFontTest/src/com/android/updatablesystemfont/UpdatableSystemFontTest.java +2 −14 Original line number Diff line number Diff line Loading @@ -196,9 +196,8 @@ public class UpdatableSystemFontTest extends BaseHostJUnit4Test { String fontPath = getFontPath(NOTO_COLOR_EMOJI_TTF); assertThat(fontPath).startsWith(DATA_FONTS_DIR); expectRemoteCommandToSucceed("stop"); expectRemoteCommandToSucceed("start"); waitUntilFontCommandIsReady(); // Emulate reboot by 'cmd font restart'. expectRemoteCommandToSucceed("cmd font restart"); String fontPathAfterReboot = getFontPath(NOTO_COLOR_EMOJI_TTF); assertThat(fontPathAfterReboot).isEqualTo(fontPath); } Loading Loading @@ -242,17 +241,6 @@ public class UpdatableSystemFontTest extends BaseHostJUnit4Test { .isNotEqualTo(CommandStatus.SUCCESS); } private void waitUntilFontCommandIsReady() { waitUntil(SECONDS.toMillis(30), () -> { try { return getDevice().executeShellV2Command("cmd font status").getStatus() == CommandStatus.SUCCESS; } catch (DeviceNotAvailableException e) { return false; } }); } private void waitUntil(long timeoutMillis, ThrowingSupplier<Boolean> func) { long untilMillis = System.currentTimeMillis() + timeoutMillis; do { Loading Loading
services/core/java/com/android/server/graphics/fonts/FontManagerService.java +4 −0 Original line number Diff line number Diff line Loading @@ -314,6 +314,10 @@ public final class FontManagerService extends IFontManager.Stub { } } /* package */ void restart() { initialize(); } /* package */ Map<String, File> getFontFileMap() { if (mUpdatableFontDir == null) { return Collections.emptyMap(); Loading
services/core/java/com/android/server/graphics/fonts/FontManagerShellCommand.java +18 −1 Original line number Diff line number Diff line Loading @@ -95,6 +95,15 @@ public class FontManagerShellCommand extends ShellCommand { w.println(); w.println("clear"); w.println(" Remove all installed font files and reset to the initial state."); w.println(); w.println("restart"); w.println(" Restart FontManagerService emulating device reboot."); w.println(" WARNING: this is not a safe operation. Other processes may misbehave if"); w.println(" they are using fonts updated by FontManagerService."); w.println(" This command exists merely for testing."); w.println(); w.println("status"); w.println(" Prints status of current system font configuration."); } /* package */ void dumpAll(@NonNull IndentingPrintWriter w) { Loading Loading @@ -368,7 +377,13 @@ public class FontManagerShellCommand extends ShellCommand { return 0; } private int status(ShellCommand shell) throws SystemFontException { private int restart(ShellCommand shell) { mService.restart(); shell.getOutPrintWriter().println("Success"); return 0; } private int status(ShellCommand shell) { final IndentingPrintWriter writer = new IndentingPrintWriter(shell.getOutPrintWriter(), " "); FontConfig config = mService.getSystemFontConfig(); Loading Loading @@ -396,6 +411,8 @@ public class FontManagerShellCommand extends ShellCommand { return update(shell); case "clear": return clear(shell); case "restart": return restart(shell); case "status": return status(shell); default: Loading
services/core/java/com/android/server/graphics/fonts/UpdatableFontDir.java +7 −1 Original line number Diff line number Diff line Loading @@ -125,7 +125,7 @@ final class UpdatableFontDir { private final Supplier<Long> mCurrentTimeSupplier; private long mLastModifiedMillis; private int mConfigVersion = 1; private int mConfigVersion; /** * A mutable map containing mapping from font file name (e.g. "NotoColorEmoji.ttf") to {@link Loading @@ -152,9 +152,15 @@ final class UpdatableFontDir { mCurrentTimeSupplier = currentTimeSupplier; } /** * Loads fonts from file system, validate them, and delete obsolete font files. * Note that this method may be called by multiple times in integration tests via {@link * FontManagerService#restart()}. */ /* package */ void loadFontFileMap() { mFontFileInfoMap.clear(); mLastModifiedMillis = 0; mConfigVersion = 1; boolean success = false; try { PersistentSystemFontConfig.Config config = new PersistentSystemFontConfig.Config(); Loading
services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java +15 −0 Original line number Diff line number Diff line Loading @@ -380,6 +380,21 @@ public final class UpdatableFontDirTest { .isEqualTo(dir.getFontFileMap().get("foo.ttf")); } @Test public void loadFontFileMap_twice() 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))); assertThat(dir.getFontFileMap()).containsKey("test.ttf"); File fontFile = dir.getFontFileMap().get("test.ttf"); dir.loadFontFileMap(); assertThat(dir.getFontFileMap().get("test.ttf")).isEqualTo(fontFile); } @Test public void installFontFile() throws Exception { FakeFontFileParser parser = new FakeFontFileParser(); Loading
tests/UpdatableSystemFontTest/src/com/android/updatablesystemfont/UpdatableSystemFontTest.java +2 −14 Original line number Diff line number Diff line Loading @@ -196,9 +196,8 @@ public class UpdatableSystemFontTest extends BaseHostJUnit4Test { String fontPath = getFontPath(NOTO_COLOR_EMOJI_TTF); assertThat(fontPath).startsWith(DATA_FONTS_DIR); expectRemoteCommandToSucceed("stop"); expectRemoteCommandToSucceed("start"); waitUntilFontCommandIsReady(); // Emulate reboot by 'cmd font restart'. expectRemoteCommandToSucceed("cmd font restart"); String fontPathAfterReboot = getFontPath(NOTO_COLOR_EMOJI_TTF); assertThat(fontPathAfterReboot).isEqualTo(fontPath); } Loading Loading @@ -242,17 +241,6 @@ public class UpdatableSystemFontTest extends BaseHostJUnit4Test { .isNotEqualTo(CommandStatus.SUCCESS); } private void waitUntilFontCommandIsReady() { waitUntil(SECONDS.toMillis(30), () -> { try { return getDevice().executeShellV2Command("cmd font status").getStatus() == CommandStatus.SUCCESS; } catch (DeviceNotAvailableException e) { return false; } }); } private void waitUntil(long timeoutMillis, ThrowingSupplier<Boolean> func) { long untilMillis = System.currentTimeMillis() + timeoutMillis; do { Loading