aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjdesprez <jdesprez@google.com>2017-08-15 13:03:22 -0700
committerjdesprez <jdesprez@google.com>2017-08-15 13:03:22 -0700
commit73f529d0590bab4f078426367ce204b4e0596a0e (patch)
tree882e2dcc6f4dd6b19a82ca1f2e7514ba892302cb /src
parent76ab9f71e30e8b18f66537d68e24643cabd9c746 (diff)
downloadcontrib-73f529d0590bab4f078426367ce204b4e0596a0e.tar.gz
Ensure resource are closed
Test: unit tests Bug: 62864604 Change-Id: Iaba692b222fb1c74679b98759da095aa3e042587
Diffstat (limited to 'src')
-rw-r--r--src/com/android/media/tests/AudioLoopbackTest.java22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/com/android/media/tests/AudioLoopbackTest.java b/src/com/android/media/tests/AudioLoopbackTest.java
index 1d9bab5..e005408 100644
--- a/src/com/android/media/tests/AudioLoopbackTest.java
+++ b/src/com/android/media/tests/AudioLoopbackTest.java
@@ -413,8 +413,9 @@ public class AudioLoopbackTest implements IDeviceTest, IRemoteTest {
} while (!data.hasLogFile(LogFileType.RESULT) && !data.isTimedOut());
// Grab logcat for iteration
- final InputStreamSource lc = getDevice().getLogcatSince(deviceTestStartTime);
- saveLogcatForIteration(data, lc, data.getIteration());
+ try (final InputStreamSource lc = getDevice().getLogcatSince(deviceTestStartTime)) {
+ saveLogcatForIteration(data, lc, data.getIteration());
+ }
// Check if test timed out. If so, don't fail the test, but return to upper logic.
// We accept certain number of individual test timeouts.
@@ -694,11 +695,9 @@ public class AudioLoopbackTest implements IDeviceTest, IRemoteTest {
CLog.e("Logfile not found for LogFileType=" + key.name());
} else {
File logFile = new File(logFilename);
- InputStreamSource iss = new FileInputStreamSource(logFile);
- listener.testLog(prefix, logDataType, iss);
-
- // cleanup
- iss.cancel();
+ try (InputStreamSource iss = new FileInputStreamSource(logFile)) {
+ listener.testLog(prefix, logDataType, iss);
+ }
}
}
@@ -716,7 +715,7 @@ public class AudioLoopbackTest implements IDeviceTest, IRemoteTest {
// Copy logcat data into temp file
Files.copy(logcat.createInputStream(), temp.toPath(), REPLACE_EXISTING);
- logcat.cancel();
+ logcat.close();
} catch (final IOException e) {
CLog.i("Error when saving logcat for iteration=" + iteration);
CLog.e(e);
@@ -727,11 +726,10 @@ public class AudioLoopbackTest implements IDeviceTest, IRemoteTest {
throws DeviceNotAvailableException, IOException {
final File csvTmpFile = File.createTempFile("audio_test_data", "csv");
mLoopbackTestHelper.writeAllResultsToCSVFile(csvTmpFile, getDevice());
- InputStreamSource iss = new FileInputStreamSource(csvTmpFile);
- listener.testLog("audio_test_data", LogDataType.JACOCO_CSV, iss);
-
+ try (InputStreamSource iss = new FileInputStreamSource(csvTmpFile)) {
+ listener.testLog("audio_test_data", LogDataType.JACOCO_CSV, iss);
+ }
// cleanup
- iss.cancel();
csvTmpFile.delete();
}