summaryrefslogtreecommitdiff
path: root/services/robotests
diff options
context:
space:
mode:
authorXin Li <delphij@google.com>2020-12-02 00:38:58 -0800
committerXin Li <delphij@google.com>2020-12-02 00:38:58 -0800
commitd31ee388115d17c2fd337f2806b37390c7d29834 (patch)
treede02b2ac289fbc2077fbc652481672eeea0b18fe /services/robotests
parent88f10e63bb2ce069bffc195acee09c332aab71fd (diff)
parent07ec9b4dcb828de0f9ad15ef5c501fcc5ce21379 (diff)
Merge rvc-qpr-dev-plus-aosp-without-vendor@6881855
Bug: 172690556 Merged-In: I78222391b83a4add8e964340ec08bb8a1306e1c6 Change-Id: I28bbf40820674675ccf765c912aa8140d3f74ab2
Diffstat (limited to 'services/robotests')
-rw-r--r--services/robotests/backup/src/com/android/server/backup/keyvalue/KeyValueBackupTaskTest.java59
1 files changed, 51 insertions, 8 deletions
diff --git a/services/robotests/backup/src/com/android/server/backup/keyvalue/KeyValueBackupTaskTest.java b/services/robotests/backup/src/com/android/server/backup/keyvalue/KeyValueBackupTaskTest.java
index bd37e587aee7..b450a80f5441 100644
--- a/services/robotests/backup/src/com/android/server/backup/keyvalue/KeyValueBackupTaskTest.java
+++ b/services/robotests/backup/src/com/android/server/backup/keyvalue/KeyValueBackupTaskTest.java
@@ -123,6 +123,7 @@ import com.android.server.testing.shadows.ShadowBackupDataOutput;
import com.android.server.testing.shadows.ShadowEventLog;
import com.android.server.testing.shadows.ShadowSystemServiceRegistry;
+import com.google.common.base.Charsets;
import com.google.common.truth.IterableSubject;
import org.junit.After;
@@ -1911,7 +1912,8 @@ public class KeyValueBackupTaskTest {
}
@Test
- public void testRunTask_whenTransportReturnsError_updatesFilesAndCleansUp() throws Exception {
+ public void testRunTask_whenTransportReturnsErrorForGenericPackage_updatesFilesAndCleansUp()
+ throws Exception {
TransportMock transportMock = setUpInitializedTransport(mTransport);
when(transportMock.transport.performBackup(
argThat(packageInfo(PACKAGE_1)), any(), anyInt()))
@@ -1927,6 +1929,39 @@ public class KeyValueBackupTaskTest {
assertCleansUpFilesAndAgent(mTransport, PACKAGE_1);
}
+ /**
+ * Checks that TRANSPORT_ERROR during @pm@ backup keeps the state file untouched.
+ * http://b/144030477
+ */
+ @Test
+ public void testRunTask_whenTransportReturnsErrorForPm_updatesFilesAndCleansUp()
+ throws Exception {
+ // TODO(tobiast): Refactor this method to share code with
+ // testRunTask_whenTransportReturnsErrorForGenericPackage_updatesFilesAndCleansUp
+ // See patchset 7 of http://ag/11762961
+ final PackageData packageData = PM_PACKAGE;
+ TransportMock transportMock = setUpInitializedTransport(mTransport);
+ when(transportMock.transport.performBackup(
+ argThat(packageInfo(packageData)), any(), anyInt()))
+ .thenReturn(BackupTransport.TRANSPORT_ERROR);
+
+ byte[] pmStateBytes = "fake @pm@ state for testing".getBytes(Charsets.UTF_8);
+
+ Path pmStatePath = createPmStateFile(pmStateBytes.clone());
+ PackageManagerBackupAgent pmAgent = spy(createPmAgent());
+ KeyValueBackupTask task = createKeyValueBackupTask(transportMock, packageData);
+ runTask(task);
+ verify(pmAgent, never()).onBackup(any(), any(), any());
+
+ assertThat(Files.readAllBytes(pmStatePath)).isEqualTo(pmStateBytes.clone());
+
+ boolean existed = deletePmStateFile();
+ assertThat(existed).isTrue();
+ // unbindAgent() is skipped for @pm@. Comment in KeyValueBackupTask.java:
+ // "For PM metadata (for which applicationInfo is null) there is no agent-bound state."
+ assertCleansUpFiles(mTransport, packageData);
+ }
+
@Test
public void testRunTask_whenTransportGetBackupQuotaThrowsForPm() throws Exception {
TransportMock transportMock = setUpInitializedTransport(mTransport);
@@ -2708,21 +2743,29 @@ public class KeyValueBackupTaskTest {
* </ul>
* </ul>
*/
- private void createPmStateFile() throws IOException {
- createPmStateFile(mTransport);
+ private Path createPmStateFile() throws IOException {
+ return createPmStateFile("pmState".getBytes());
+ }
+
+ private Path createPmStateFile(byte[] bytes) throws IOException {
+ return createPmStateFile(bytes, mTransport);
+ }
+
+ private Path createPmStateFile(TransportData transport) throws IOException {
+ return createPmStateFile("pmState".getBytes(), mTransport);
}
- /** @see #createPmStateFile() */
- private void createPmStateFile(TransportData transport) throws IOException {
- Files.write(getStateFile(transport, PM_PACKAGE), "pmState".getBytes());
+ /** @see #createPmStateFile(byte[]) */
+ private Path createPmStateFile(byte[] bytes, TransportData transport) throws IOException {
+ return Files.write(getStateFile(transport, PM_PACKAGE), bytes);
}
/**
* Forces transport initialization and call to {@link
* UserBackupManagerService#resetBackupState(File)}
*/
- private void deletePmStateFile() throws IOException {
- Files.deleteIfExists(getStateFile(mTransport, PM_PACKAGE));
+ private boolean deletePmStateFile() throws IOException {
+ return Files.deleteIfExists(getStateFile(mTransport, PM_PACKAGE));
}
/**