mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Save to TestStorage when saving Bitmap
PiperOrigin-RevId: 548733979
This commit is contained in:
parent
34768c2399
commit
7adc0af8a6
1 changed files with 16 additions and 0 deletions
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package androidx.media3.test.utils;
|
package androidx.media3.test.utils;
|
||||||
|
|
||||||
|
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||||
import static androidx.media3.common.util.Assertions.checkState;
|
import static androidx.media3.common.util.Assertions.checkState;
|
||||||
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
@ -42,6 +43,8 @@ import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
|
@ -342,6 +345,19 @@ public class BitmapPixelTestUtil {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "Could not write Bitmap to file path: " + file.getAbsolutePath(), e);
|
Log.e(TAG, "Could not write Bitmap to file path: " + file.getAbsolutePath(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Use reflection here as this is an experimental API that may not work for all users
|
||||||
|
Class<?> testStorageClass = Class.forName("androidx.test.services.storage.TestStorage");
|
||||||
|
Method method = testStorageClass.getMethod("openOutputFile", String.class);
|
||||||
|
Object testStorage = testStorageClass.getDeclaredConstructor().newInstance();
|
||||||
|
OutputStream outputStream = (OutputStream) method.invoke(testStorage, fileName);
|
||||||
|
bitmap.compress(Bitmap.CompressFormat.PNG, /* quality= */ 100, checkNotNull(outputStream));
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
// Do nothing
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.i(TAG, "Could not write Bitmap to test storage: " + fileName, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue