Loading tests/RollbackTest/NetworkStagedRollbackTest/src/com/android/tests/rollback/host/NetworkStagedRollbackTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.tests.rollback.host; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.testng.Assert.assertThrows; Loading Loading @@ -115,6 +116,31 @@ public class NetworkStagedRollbackTest extends BaseHostJUnit4Test { */ @Test public void testNetworkPassedDoesNotRollback() throws Exception { runPhase("testNetworkPassedDoesNotRollback_Phase1"); // Reboot device to activate staged package getDevice().reboot(); // Verify rollback was enabled runPhase("testNetworkPassedDoesNotRollback_Phase2"); // Connect to internet so network health check passes getDevice().executeShellCommand("svc wifi enable"); getDevice().executeShellCommand("svc data enable"); // Wait for device available because emulator device may restart after turning // on mobile data getDevice().waitForDeviceAvailable(); // Verify rollback was not executed after health check deadline runPhase("testNetworkPassedDoesNotRollback_Phase3"); InputStreamSource logcatStream = mReceiver.getLogcatData(); try { List<String> watchdogEvents = getWatchdogLoggingEvents(logcatStream); assertEquals(watchdogEventOccurred(watchdogEvents, null, null, REASON_EXPLICIT_HEALTH_CHECK, null), false); } finally { logcatStream.close(); } } /** Loading tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/NetworkStagedRollbackTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -150,6 +150,45 @@ public class NetworkStagedRollbackTest { runShellCommand("pm uninstall " + getNetworkStackPackageName()); } @Test public void testNetworkPassedDoesNotRollback_Phase1() throws Exception { // Remove available rollbacks and uninstall NetworkStack on /data/ RollbackManager rm = RollbackUtils.getRollbackManager(); String networkStack = getNetworkStackPackageName(); rm.expireRollbackForPackage(networkStack); uninstallNetworkStackPackage(); assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), networkStack)).isNull(); // Reduce health check deadline, here unlike the network failed case, we use // a longer deadline because joining a network can take a much longer time for // reasons external to the device than 'not joining' DeviceConfig.setProperty(DeviceConfig.NAMESPACE_ROLLBACK, PROPERTY_WATCHDOG_REQUEST_TIMEOUT_MILLIS, Integer.toString(300000), false); // Simulate re-installation of new NetworkStack with rollbacks enabled installNetworkStackPackage(); } @Test public void testNetworkPassedDoesNotRollback_Phase2() throws Exception { RollbackManager rm = RollbackUtils.getRollbackManager(); assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), getNetworkStackPackageName())).isNotNull(); } @Test public void testNetworkPassedDoesNotRollback_Phase3() throws Exception { // Sleep for > health check deadline. We expect no rollback should happen during sleeping. // If the device reboots for rollback, this device test will fail as well as the host test. Thread.sleep(TimeUnit.SECONDS.toMillis(310)); RollbackManager rm = RollbackUtils.getRollbackManager(); assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(), getNetworkStackPackageName())).isNull(); } private static void runShellCommand(String cmd) { ParcelFileDescriptor pfd = InstrumentationRegistry.getInstrumentation().getUiAutomation() .executeShellCommand(cmd); Loading tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java +0 −83 Original line number Diff line number Diff line Loading @@ -22,14 +22,11 @@ import static com.android.cts.rollback.lib.RollbackUtils.getUniqueRollbackInfoFo import static com.google.common.truth.Truth.assertThat; import android.Manifest; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInstaller; import android.content.pm.PackageManager; import android.content.rollback.RollbackInfo; import android.content.rollback.RollbackManager; import android.os.ParcelFileDescriptor; import android.os.storage.StorageManager; import android.provider.DeviceConfig; Loading @@ -44,8 +41,6 @@ import com.android.cts.rollback.lib.Rollback; import com.android.cts.rollback.lib.RollbackUtils; import com.android.internal.R; import libcore.io.IoUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; Loading @@ -65,24 +60,8 @@ import java.util.concurrent.TimeUnit; */ @RunWith(JUnit4.class) public class StagedRollbackTest { private static final String NETWORK_STACK_CONNECTOR_CLASS = "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 TestApp NETWORK_STACK = new TestApp("NetworkStack", getNetworkStackPackageName(), -1, false, findNetworkStackApk()); private static File findNetworkStackApk() { final File apk = new File("/system/priv-app/NetworkStack/NetworkStack.apk"); if (apk.isFile()) { return apk; } return new File("/system/priv-app/NetworkStackNext/NetworkStackNext.apk"); } /** * Adopts common shell permissions needed for rollback tests. Loading Loading @@ -274,23 +253,6 @@ public class StagedRollbackTest { TestApp.B)).isNotNull(); } private static String getNetworkStackPackageName() { Intent intent = new Intent(NETWORK_STACK_CONNECTOR_CLASS); ComponentName comp = intent.resolveSystemService( InstrumentationRegistry.getInstrumentation().getContext().getPackageManager(), 0); return comp.getPackageName(); } 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()); } @Test public void testPreviouslyAbandonedRollbacks_Phase1() throws Exception { Uninstall.packages(TestApp.A); Loading Loading @@ -327,45 +289,6 @@ public class StagedRollbackTest { Uninstall.packages(TestApp.A); } @Test public void testNetworkPassedDoesNotRollback_Phase1() throws Exception { // Remove available rollbacks and uninstall NetworkStack on /data/ RollbackManager rm = RollbackUtils.getRollbackManager(); String networkStack = getNetworkStackPackageName(); rm.expireRollbackForPackage(networkStack); uninstallNetworkStackPackage(); assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), networkStack)).isNull(); // Reduce health check deadline, here unlike the network failed case, we use // a longer deadline because joining a network can take a much longer time for // reasons external to the device than 'not joining' DeviceConfig.setProperty(DeviceConfig.NAMESPACE_ROLLBACK, PROPERTY_WATCHDOG_REQUEST_TIMEOUT_MILLIS, Integer.toString(300000), false); // Simulate re-installation of new NetworkStack with rollbacks enabled installNetworkStackPackage(); } @Test public void testNetworkPassedDoesNotRollback_Phase2() throws Exception { RollbackManager rm = RollbackUtils.getRollbackManager(); assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), getNetworkStackPackageName())).isNotNull(); } @Test public void testNetworkPassedDoesNotRollback_Phase3() throws Exception { // Sleep for > health check deadline. We expect no rollback should happen during sleeping. // If the device reboots for rollback, this device test will fail as well as the host test. Thread.sleep(TimeUnit.SECONDS.toMillis(310)); RollbackManager rm = RollbackUtils.getRollbackManager(); assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(), getNetworkStackPackageName())).isNull(); } private static String getModuleMetadataPackageName() { return InstrumentationRegistry.getInstrumentation().getContext() .getResources().getString(R.string.config_defaultModuleMetadataProvider); Loading Loading @@ -554,12 +477,6 @@ public class StagedRollbackTest { InstallUtils.waitForSessionReady(committed.getCommittedSessionId()); } private static void runShellCommand(String cmd) { ParcelFileDescriptor pfd = InstrumentationRegistry.getInstrumentation().getUiAutomation() .executeShellCommand(cmd); IoUtils.closeQuietly(pfd); } @Test public void isCheckpointSupported() { Context context = InstrumentationRegistry.getInstrumentation().getContext(); Loading tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java +0 −38 Original line number Diff line number Diff line Loading @@ -227,39 +227,6 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { } } /** * Tests passed network health check does not trigger watchdog staged rollbacks. */ @Test public void testNetworkPassedDoesNotRollback() throws Exception { runPhase("testNetworkPassedDoesNotRollback_Phase1"); // Reboot device to activate staged package getDevice().reboot(); // Verify rollback was enabled runPhase("testNetworkPassedDoesNotRollback_Phase2"); // Connect to internet so network health check passes getDevice().executeShellCommand("svc wifi enable"); getDevice().executeShellCommand("svc data enable"); // Wait for device available because emulator device may restart after turning // on mobile data getDevice().waitForDeviceAvailable(); // Verify rollback was not executed after health check deadline runPhase("testNetworkPassedDoesNotRollback_Phase3"); InputStreamSource logcatStream = mReceiver.getLogcatData(); try { List<String> watchdogEvents = getWatchdogLoggingEvents(logcatStream); assertEquals(watchdogEventOccurred(watchdogEvents, null, null, REASON_EXPLICIT_HEALTH_CHECK, null), false); } finally { logcatStream.close(); } } /** * Tests rolling back user data where there are multiple rollbacks for that package. */ Loading Loading @@ -489,11 +456,6 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { } } private String getNetworkStackPath() throws Exception { // Find the NetworkStack path (can be NetworkStack.apk or NetworkStackNext.apk) return getDevice().executeShellCommand("ls /system/priv-app/NetworkStack*/*.apk"); } private boolean isCheckpointSupported() throws Exception { try { runPhase("isCheckpointSupported"); Loading Loading
tests/RollbackTest/NetworkStagedRollbackTest/src/com/android/tests/rollback/host/NetworkStagedRollbackTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.tests.rollback.host; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.testng.Assert.assertThrows; Loading Loading @@ -115,6 +116,31 @@ public class NetworkStagedRollbackTest extends BaseHostJUnit4Test { */ @Test public void testNetworkPassedDoesNotRollback() throws Exception { runPhase("testNetworkPassedDoesNotRollback_Phase1"); // Reboot device to activate staged package getDevice().reboot(); // Verify rollback was enabled runPhase("testNetworkPassedDoesNotRollback_Phase2"); // Connect to internet so network health check passes getDevice().executeShellCommand("svc wifi enable"); getDevice().executeShellCommand("svc data enable"); // Wait for device available because emulator device may restart after turning // on mobile data getDevice().waitForDeviceAvailable(); // Verify rollback was not executed after health check deadline runPhase("testNetworkPassedDoesNotRollback_Phase3"); InputStreamSource logcatStream = mReceiver.getLogcatData(); try { List<String> watchdogEvents = getWatchdogLoggingEvents(logcatStream); assertEquals(watchdogEventOccurred(watchdogEvents, null, null, REASON_EXPLICIT_HEALTH_CHECK, null), false); } finally { logcatStream.close(); } } /** Loading
tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/NetworkStagedRollbackTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -150,6 +150,45 @@ public class NetworkStagedRollbackTest { runShellCommand("pm uninstall " + getNetworkStackPackageName()); } @Test public void testNetworkPassedDoesNotRollback_Phase1() throws Exception { // Remove available rollbacks and uninstall NetworkStack on /data/ RollbackManager rm = RollbackUtils.getRollbackManager(); String networkStack = getNetworkStackPackageName(); rm.expireRollbackForPackage(networkStack); uninstallNetworkStackPackage(); assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), networkStack)).isNull(); // Reduce health check deadline, here unlike the network failed case, we use // a longer deadline because joining a network can take a much longer time for // reasons external to the device than 'not joining' DeviceConfig.setProperty(DeviceConfig.NAMESPACE_ROLLBACK, PROPERTY_WATCHDOG_REQUEST_TIMEOUT_MILLIS, Integer.toString(300000), false); // Simulate re-installation of new NetworkStack with rollbacks enabled installNetworkStackPackage(); } @Test public void testNetworkPassedDoesNotRollback_Phase2() throws Exception { RollbackManager rm = RollbackUtils.getRollbackManager(); assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), getNetworkStackPackageName())).isNotNull(); } @Test public void testNetworkPassedDoesNotRollback_Phase3() throws Exception { // Sleep for > health check deadline. We expect no rollback should happen during sleeping. // If the device reboots for rollback, this device test will fail as well as the host test. Thread.sleep(TimeUnit.SECONDS.toMillis(310)); RollbackManager rm = RollbackUtils.getRollbackManager(); assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(), getNetworkStackPackageName())).isNull(); } private static void runShellCommand(String cmd) { ParcelFileDescriptor pfd = InstrumentationRegistry.getInstrumentation().getUiAutomation() .executeShellCommand(cmd); Loading
tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java +0 −83 Original line number Diff line number Diff line Loading @@ -22,14 +22,11 @@ import static com.android.cts.rollback.lib.RollbackUtils.getUniqueRollbackInfoFo import static com.google.common.truth.Truth.assertThat; import android.Manifest; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInstaller; import android.content.pm.PackageManager; import android.content.rollback.RollbackInfo; import android.content.rollback.RollbackManager; import android.os.ParcelFileDescriptor; import android.os.storage.StorageManager; import android.provider.DeviceConfig; Loading @@ -44,8 +41,6 @@ import com.android.cts.rollback.lib.Rollback; import com.android.cts.rollback.lib.RollbackUtils; import com.android.internal.R; import libcore.io.IoUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; Loading @@ -65,24 +60,8 @@ import java.util.concurrent.TimeUnit; */ @RunWith(JUnit4.class) public class StagedRollbackTest { private static final String NETWORK_STACK_CONNECTOR_CLASS = "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 TestApp NETWORK_STACK = new TestApp("NetworkStack", getNetworkStackPackageName(), -1, false, findNetworkStackApk()); private static File findNetworkStackApk() { final File apk = new File("/system/priv-app/NetworkStack/NetworkStack.apk"); if (apk.isFile()) { return apk; } return new File("/system/priv-app/NetworkStackNext/NetworkStackNext.apk"); } /** * Adopts common shell permissions needed for rollback tests. Loading Loading @@ -274,23 +253,6 @@ public class StagedRollbackTest { TestApp.B)).isNotNull(); } private static String getNetworkStackPackageName() { Intent intent = new Intent(NETWORK_STACK_CONNECTOR_CLASS); ComponentName comp = intent.resolveSystemService( InstrumentationRegistry.getInstrumentation().getContext().getPackageManager(), 0); return comp.getPackageName(); } 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()); } @Test public void testPreviouslyAbandonedRollbacks_Phase1() throws Exception { Uninstall.packages(TestApp.A); Loading Loading @@ -327,45 +289,6 @@ public class StagedRollbackTest { Uninstall.packages(TestApp.A); } @Test public void testNetworkPassedDoesNotRollback_Phase1() throws Exception { // Remove available rollbacks and uninstall NetworkStack on /data/ RollbackManager rm = RollbackUtils.getRollbackManager(); String networkStack = getNetworkStackPackageName(); rm.expireRollbackForPackage(networkStack); uninstallNetworkStackPackage(); assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), networkStack)).isNull(); // Reduce health check deadline, here unlike the network failed case, we use // a longer deadline because joining a network can take a much longer time for // reasons external to the device than 'not joining' DeviceConfig.setProperty(DeviceConfig.NAMESPACE_ROLLBACK, PROPERTY_WATCHDOG_REQUEST_TIMEOUT_MILLIS, Integer.toString(300000), false); // Simulate re-installation of new NetworkStack with rollbacks enabled installNetworkStackPackage(); } @Test public void testNetworkPassedDoesNotRollback_Phase2() throws Exception { RollbackManager rm = RollbackUtils.getRollbackManager(); assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), getNetworkStackPackageName())).isNotNull(); } @Test public void testNetworkPassedDoesNotRollback_Phase3() throws Exception { // Sleep for > health check deadline. We expect no rollback should happen during sleeping. // If the device reboots for rollback, this device test will fail as well as the host test. Thread.sleep(TimeUnit.SECONDS.toMillis(310)); RollbackManager rm = RollbackUtils.getRollbackManager(); assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(), getNetworkStackPackageName())).isNull(); } private static String getModuleMetadataPackageName() { return InstrumentationRegistry.getInstrumentation().getContext() .getResources().getString(R.string.config_defaultModuleMetadataProvider); Loading Loading @@ -554,12 +477,6 @@ public class StagedRollbackTest { InstallUtils.waitForSessionReady(committed.getCommittedSessionId()); } private static void runShellCommand(String cmd) { ParcelFileDescriptor pfd = InstrumentationRegistry.getInstrumentation().getUiAutomation() .executeShellCommand(cmd); IoUtils.closeQuietly(pfd); } @Test public void isCheckpointSupported() { Context context = InstrumentationRegistry.getInstrumentation().getContext(); Loading
tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java +0 −38 Original line number Diff line number Diff line Loading @@ -227,39 +227,6 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { } } /** * Tests passed network health check does not trigger watchdog staged rollbacks. */ @Test public void testNetworkPassedDoesNotRollback() throws Exception { runPhase("testNetworkPassedDoesNotRollback_Phase1"); // Reboot device to activate staged package getDevice().reboot(); // Verify rollback was enabled runPhase("testNetworkPassedDoesNotRollback_Phase2"); // Connect to internet so network health check passes getDevice().executeShellCommand("svc wifi enable"); getDevice().executeShellCommand("svc data enable"); // Wait for device available because emulator device may restart after turning // on mobile data getDevice().waitForDeviceAvailable(); // Verify rollback was not executed after health check deadline runPhase("testNetworkPassedDoesNotRollback_Phase3"); InputStreamSource logcatStream = mReceiver.getLogcatData(); try { List<String> watchdogEvents = getWatchdogLoggingEvents(logcatStream); assertEquals(watchdogEventOccurred(watchdogEvents, null, null, REASON_EXPLICIT_HEALTH_CHECK, null), false); } finally { logcatStream.close(); } } /** * Tests rolling back user data where there are multiple rollbacks for that package. */ Loading Loading @@ -489,11 +456,6 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { } } private String getNetworkStackPath() throws Exception { // Find the NetworkStack path (can be NetworkStack.apk or NetworkStackNext.apk) return getDevice().executeShellCommand("ls /system/priv-app/NetworkStack*/*.apk"); } private boolean isCheckpointSupported() throws Exception { try { runPhase("isCheckpointSupported"); Loading