From 83408d065e2a93c4bf436a19086b3f04d334fd8b Mon Sep 17 00:00:00 2001 From: samrobinson Date: Mon, 29 Nov 2021 12:36:40 +0000 Subject: [PATCH] Create and write the TransformationResult to on-device text file. PiperOrigin-RevId: 412856100 --- .../transformer/mh/AndroidTestUtil.java | 49 +++++++++++++++---- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/AndroidTestUtil.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/AndroidTestUtil.java index 2f471a9dcb..824edf685f 100644 --- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/AndroidTestUtil.java +++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/AndroidTestUtil.java @@ -20,12 +20,14 @@ import static java.util.concurrent.TimeUnit.SECONDS; import android.content.Context; import android.net.Uri; +import android.os.Build; import androidx.annotation.Nullable; import androidx.test.platform.app.InstrumentationRegistry; import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.transformer.Transformer; import com.google.android.exoplayer2.util.Assertions; import java.io.File; +import java.io.FileWriter; import java.io.IOException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; @@ -40,9 +42,11 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; /** Information about the result of successfully running a transformer. */ public static final class TransformationResult { - public long outputSizeBytes; + public final String testId; + public final long outputSizeBytes; - private TransformationResult(long outputSizeBytes) { + private TransformationResult(String testId, long outputSizeBytes) { + this.testId = testId; this.outputSizeBytes = outputSizeBytes; } } @@ -83,13 +87,13 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; .build(); Uri uri = Uri.parse(uriString); - File externalCacheFile = createExternalCacheFile(context, /* filePrefix= */ testId); + File outputVideoFile = createExternalCacheFile(context, /* fileName= */ testId + "-output.mp4"); InstrumentationRegistry.getInstrumentation() .runOnMainSync( () -> { try { testTransformer.startTransformation( - MediaItem.fromUri(uri), externalCacheFile.getAbsolutePath()); + MediaItem.fromUri(uri), outputVideoFile.getAbsolutePath()); } catch (IOException e) { exceptionReference.set(e); } @@ -102,16 +106,41 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; if (exception != null) { throw exception; } - long outputSizeBytes = externalCacheFile.length(); - return new TransformationResult(outputSizeBytes); + long outputSizeBytes = outputVideoFile.length(); + + TransformationResult result = new TransformationResult(testId, outputSizeBytes); + writeTransformationResultToFile(context, result); + return result; } - private static File createExternalCacheFile(Context context, String filePrefix) + private static void writeTransformationResultToFile(Context context, TransformationResult result) throws IOException { - File file = new File(context.getExternalCacheDir(), filePrefix + "-output.mp4"); + File analysisFile = + createExternalCacheFile(context, /* fileName= */ result.testId + "-result.txt"); + FileWriter fileWriter = new FileWriter(analysisFile); + String fileContents = + "test=" + + result.testId + + ", deviceBrand=" + + Build.MANUFACTURER + + ", deviceModel=" + + Build.MODEL + + ", sdkVersion=" + + Build.VERSION.SDK_INT + + ", outputSizeBytes=" + + result.outputSizeBytes; + try { + fileWriter.write(fileContents); + } finally { + fileWriter.close(); + } + } + + private static File createExternalCacheFile(Context context, String fileName) throws IOException { + File file = new File(context.getExternalCacheDir(), fileName); Assertions.checkState( - !file.exists() || file.delete(), "Could not delete the previous transformer output file."); - Assertions.checkState(file.createNewFile(), "Could not create the transformer output file."); + !file.exists() || file.delete(), "Could not delete file: " + file.getAbsolutePath()); + Assertions.checkState(file.createNewFile(), "Could not create file: " + file.getAbsolutePath()); return file; }