summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Stefanot <stefanot@google.com> 2018-10-04 16:16:30 +0100
committer Stefanot <stefanot@google.com> 2018-10-05 11:43:27 +0100
commit07564fa0f99137c299ea04535570d50d2654f7e4 (patch)
treebaeab4036de471c3d262855179d774412c57cbe3
parent23961c8a8057d42b8c11345dd18c87fa0748fc8c (diff)
Create stream for every call of getNextFullRestoreDataChun.
Before we where keeping the same stream for different calls, and the fileDescriptor was different so we could end up writting to an invalid file descriptor. Test: Run adb backup and restore of wallpaper package that was failing. Test: cts-tradefed run commandAndExit cts -m CtsBackupHostTestCases BUG: 117139223 Change-Id: I0d696a0e114f35427514730b0067b169f1bed08a
-rw-r--r--packages/LocalTransport/src/com/android/localtransport/LocalTransport.java20
1 files changed, 13 insertions, 7 deletions
diff --git a/packages/LocalTransport/src/com/android/localtransport/LocalTransport.java b/packages/LocalTransport/src/com/android/localtransport/LocalTransport.java
index 0bf8bc1051c2..4408ef5a2c75 100644
--- a/packages/LocalTransport/src/com/android/localtransport/LocalTransport.java
+++ b/packages/LocalTransport/src/com/android/localtransport/LocalTransport.java
@@ -95,7 +95,6 @@ public class LocalTransport extends BackupTransport {
private long mFullBackupSize;
private FileInputStream mCurFullRestoreStream;
- private FileOutputStream mFullRestoreSocketStream;
private byte[] mFullRestoreBuffer;
private final LocalTransportParameters mParameters;
@@ -195,6 +194,15 @@ public class LocalTransport extends BackupTransport {
@Override
public int performBackup(PackageInfo packageInfo, ParcelFileDescriptor data, int flags) {
+ try {
+ return performBackupInternal(packageInfo, data, flags);
+ } finally {
+ IoUtils.closeQuietly(data);
+ }
+ }
+
+ private int performBackupInternal(
+ PackageInfo packageInfo, ParcelFileDescriptor data, int flags) {
boolean isIncremental = (flags & FLAG_INCREMENTAL) != 0;
boolean isNonIncremental = (flags & FLAG_NON_INCREMENTAL) != 0;
@@ -750,7 +758,6 @@ public class LocalTransport extends BackupTransport {
private void resetFullRestoreState() {
IoUtils.closeQuietly(mCurFullRestoreStream);
mCurFullRestoreStream = null;
- mFullRestoreSocketStream = null;
mFullRestoreBuffer = null;
}
@@ -795,10 +802,11 @@ public class LocalTransport extends BackupTransport {
Log.e(TAG, "Unable to read archive for " + name);
return TRANSPORT_PACKAGE_REJECTED;
}
- mFullRestoreSocketStream = new FileOutputStream(socket.getFileDescriptor());
mFullRestoreBuffer = new byte[2*1024];
}
+ FileOutputStream stream = new FileOutputStream(socket.getFileDescriptor());
+
int nRead;
try {
nRead = mCurFullRestoreStream.read(mFullRestoreBuffer);
@@ -815,14 +823,12 @@ public class LocalTransport extends BackupTransport {
if (DEBUG) {
Log.i(TAG, " delivering restore chunk: " + nRead);
}
- mFullRestoreSocketStream.write(mFullRestoreBuffer, 0, nRead);
+ stream.write(mFullRestoreBuffer, 0, nRead);
}
} catch (IOException e) {
return TRANSPORT_ERROR; // Hard error accessing the file; shouldn't happen
} finally {
- // Most transports will need to explicitly close 'socket' here, but this transport
- // is in the same process as the caller so it can leave it up to the backup manager
- // to manage both socket fds.
+ IoUtils.closeQuietly(socket);
}
return nRead;