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

Commit 679a8247 authored by Kohsuke Yatoh's avatar Kohsuke Yatoh
Browse files

Do not actually reboot the device in VTS test.

- Sometimes reboot takes longer time and makes following tests fail.
- If the device has a screen lock, tests get stuck there.

This is not a new issue, but a recently added test (#launchApp) tries
to start an Activity and it fails when the device is still booting or at
a screen lock.

Bug: 185483743
Bug: 185576411
Test: atest FrameworksServicesTests:UpdatableFontDirTest
Test: atest UpdatableSystemFontTest
Change-Id: I86d4be1761e648114503b5f3560992a89c0b34d7
parent f0a78473
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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();
+18 −1
Original line number Diff line number Diff line
@@ -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) {
@@ -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();
@@ -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:
+7 −1
Original line number Diff line number Diff line
@@ -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
@@ -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();
+15 −0
Original line number Diff line number Diff line
@@ -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();
+2 −14
Original line number Diff line number Diff line
@@ -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);
    }
@@ -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 {