diff options
author | Julien Desprez <jdesprez@google.com> | 2017-08-23 23:51:23 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-08-23 23:51:23 +0000 |
commit | b3684adc78906e3259a9490dd35382006dd24fc7 (patch) | |
tree | 2de01031042941fa866ba46fc8b86fa7e227506b | |
parent | 83157c81e4c83f96b767393ee0890b896ae5ce89 (diff) | |
parent | 73f529d0590bab4f078426367ce204b4e0596a0e (diff) | |
download | contrib-b3684adc78906e3259a9490dd35382006dd24fc7.tar.gz |
Merge "Ensure resource are closed"
-rw-r--r-- | src/com/android/media/tests/AudioLoopbackTest.java | 22 |
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 05f14c0..8835b65 100644 --- a/src/com/android/media/tests/AudioLoopbackTest.java +++ b/src/com/android/media/tests/AudioLoopbackTest.java @@ -549,8 +549,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. @@ -830,11 +831,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); + } } } @@ -852,7 +851,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); @@ -863,11 +862,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(); } |