summaryrefslogtreecommitdiff
path: root/core/java/android/os/FileUtils.java
diff options
context:
space:
mode:
authorManish Singh <psych@google.com>2020-12-16 22:06:48 +0000
committerZimuzo Ezeozue <zezeozue@google.com>2020-12-17 16:51:13 +0000
commit7fe47a64d2489b1db5597f0ec68d4c3ce77ad454 (patch)
treec8029f478b490508baae9ea447e10ed8cdf78eb4 /core/java/android/os/FileUtils.java
parent852446ad481a3e69118e70ae59fecbc703a97774 (diff)
Fix screenshot failure with transcoding
We currently attempt to convert transcode fds to original fds inside the platform media players. This causes screenshot failures in ExifInterface. To mitigate, we only match published videos in DCIM/Camera. Bug: 173543930 Bug: 175831095 Test: atest FileUtilsTest#testConvertToModernFd Test: Manual, tested by both taking a screenshot and video transcoding. Change-Id: I4abba3d9d36e83c5a019b32793bd38fee81d5f75
Diffstat (limited to 'core/java/android/os/FileUtils.java')
-rw-r--r--core/java/android/os/FileUtils.java21
1 files changed, 17 insertions, 4 deletions
diff --git a/core/java/android/os/FileUtils.java b/core/java/android/os/FileUtils.java
index 92fe98ca1044..c014ef682a24 100644
--- a/core/java/android/os/FileUtils.java
+++ b/core/java/android/os/FileUtils.java
@@ -83,6 +83,7 @@ import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
+import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
@@ -115,6 +116,9 @@ public final class FileUtils {
private FileUtils() {
}
+ private static final String CAMERA_DIR_LOWER_CASE = "/storage/emulated/" + UserHandle.myUserId()
+ + "/dcim/camera";
+
/** Regular expression for safe filenames: no spaces or metacharacters.
*
* Use a preload holder so that FileUtils can be compile-time initialized.
@@ -1432,18 +1436,27 @@ public final class FileUtils {
}
}
+ // TODO(b/170488060): Consider better approach
/** {@hide} */
+ @VisibleForTesting
public static FileDescriptor convertToModernFd(FileDescriptor fd) {
try {
Context context = AppGlobals.getInitialApplication();
+ File realFile = ParcelFileDescriptor.getFile(fd);
+ String fileName = realFile.getName();
+ boolean isCameraVideo = !fileName.startsWith(".") && fileName.endsWith(".mp4")
+ && contains(CAMERA_DIR_LOWER_CASE, realFile.getAbsolutePath().toLowerCase(
+ Locale.ROOT));
+
if (!SystemProperties.getBoolean("sys.fuse.transcode_enabled", false)
- || UserHandle.getAppId(Process.myUid()) == getMediaProviderAppId(context)) {
- // If transcode is enabled we optimize by default, unless explicitly disabled.
- // Never convert modern fd for MediaProvider, because this requires
+ || UserHandle.getAppId(Process.myUid()) == getMediaProviderAppId(context)
+ || !isCameraVideo) {
+ // 1. If transcode is enabled we optimize by default, unless explicitly disabled.
+ // 2. Never convert modern fd for MediaProvider, because this requires
// MediaStore#scanFile and can cause infinite loops when MediaProvider scans
+ // 3. Only convert published mp4 videos in the DCIM/Camera dir
return null;
}
- File realFile = ParcelFileDescriptor.getFile(fd);
Log.i(TAG, "Changing to modern format dataSource for: " + realFile);
ContentResolver resolver = context.getContentResolver();