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

Commit 8f17256d authored by JW Wang's avatar JW Wang Committed by Android (Google) Code Review
Browse files

Merge "Rewrite testNetworkFailedRollback"

parents 61094d7c eae2c7cd
Loading
Loading
Loading
Loading
+26 −5
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.content.rollback.RollbackInfo;
import android.content.rollback.RollbackManager;
import android.os.ParcelFileDescriptor;
@@ -55,6 +56,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.File;
import java.util.concurrent.TimeUnit;

/**
@@ -72,8 +74,13 @@ public class StagedRollbackTest {
            "android.net.INetworkStackConnector";
    private static final String PROPERTY_WATCHDOG_TRIGGER_FAILURE_COUNT =
            "watchdog_trigger_failure_count";
    private static final String PROPERTY_WATCHDOG_REQUEST_TIMEOUT_MILLIS =
            "watchdog_request_timeout_millis";

    private static final String MODULE_META_DATA_PACKAGE = getModuleMetadataPackageName();
    private static final TestApp NETWORK_STACK = new TestApp("NetworkStack",
            getNetworkStackPackageName(), -1, false,
            new File("/system/priv-app/NetworkStack/NetworkStack.apk"));

    /**
     * Adopts common shell permissions needed for rollback tests.
@@ -214,6 +221,7 @@ public class StagedRollbackTest {

    @Test
    public void testNetworkFailedRollback_Phase1() throws Exception {
        // Remove available rollbacks and uninstall NetworkStack on /data/
        RollbackManager rm = RollbackUtils.getRollbackManager();
        String networkStack = getNetworkStackPackageName();

@@ -222,6 +230,15 @@ public class StagedRollbackTest {

        assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(),
                        networkStack)).isNull();

        // Reduce health check deadline
        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_ROLLBACK,
                PROPERTY_WATCHDOG_REQUEST_TIMEOUT_MILLIS,
                Integer.toString(120000), false);
        // Simulate re-installation of new NetworkStack with rollbacks enabled
        installNetworkStackPackage();
        // Sleep to allow writes to disk before reboot
        Thread.sleep(TimeUnit.SECONDS.toMillis(5));
    }

    @Test
@@ -253,16 +270,20 @@ public class StagedRollbackTest {
                        getNetworkStackPackageName())).isNotNull();
    }

    private String getNetworkStackPackageName() {
    private static String getNetworkStackPackageName() {
        Intent intent = new Intent(NETWORK_STACK_CONNECTOR_CLASS);
        ComponentName comp = intent.resolveSystemService(
                InstrumentationRegistry.getContext().getPackageManager(), 0);
        return comp.getPackageName();
    }

    private void uninstallNetworkStackPackage() {
        // Since the host side use shell command to install the network stack package, uninstall
        // must be done by shell command as well. Otherwise uninstall by a different user will fail.
    private static void installNetworkStackPackage() throws Exception {
        Install.single(NETWORK_STACK).setStaged().setEnableRollback()
                .addInstallFlags(PackageManager.INSTALL_REPLACE_EXISTING).commit();
    }

    private static void uninstallNetworkStackPackage() {
        // Uninstall the package as a privileged user so we won't fail due to permission.
        runShellCommand("pm uninstall " + getNetworkStackPackageName());
    }

@@ -348,7 +369,7 @@ public class StagedRollbackTest {
                MODULE_META_DATA_PACKAGE)).isNull();
    }

    private void runShellCommand(String cmd) {
    private static void runShellCommand(String cmd) {
        ParcelFileDescriptor pfd = InstrumentationRegistry.getInstrumentation().getUiAutomation()
                .executeShellCommand(cmd);
        IoUtils.closeQuietly(pfd);
+0 −10
Original line number Diff line number Diff line
@@ -110,17 +110,7 @@ public class StagedRollbackTest extends BaseHostJUnit4Test {
        getDevice().executeShellCommand("svc wifi disable");
        getDevice().executeShellCommand("svc data disable");

        // Remove available rollbacks and uninstall NetworkStack on /data/
        runPhase("testNetworkFailedRollback_Phase1");
        // Reduce health check deadline
        getDevice().executeShellCommand("device_config put rollback "
                + "watchdog_request_timeout_millis 120000");
        // Simulate re-installation of new NetworkStack with rollbacks enabled
        getDevice().executeShellCommand("pm install -r --staged --enable-rollback "
                + "/system/priv-app/NetworkStack/NetworkStack.apk");

        // Sleep to allow writes to disk before reboot
        Thread.sleep(5000);
        // Reboot device to activate staged package
        getDevice().reboot();